-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve(create): Prevent rounding errors that unintentionally break the GCR restraint on-chain #177
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,7 @@ const Create = () => { | |
// We want to round down the number for better UI display, but we don't actually want the collateral | ||
// amount to round down since we want the minimum amount of collateral to pass the GCR constraint. So, | ||
// we'll add a tiny amount of collateral to avoid accidentally rounding too low. | ||
setCollateral((minBackingCollateral + 0.00005).toFixed(4)); | ||
setCollateral(Math.ceil(minBackingCollateral).toString()); | ||
} | ||
}; | ||
|
||
|
@@ -141,7 +141,7 @@ const Create = () => { | |
const maxTokensToCreate = _gcr > 0 ? collateral / _gcr - startingTokens : 0; | ||
// Unlike the min collateral, we're ok if we round down the tokens slightly as round down | ||
// can only increase the position's CR and maintain it above the GCR constraint. | ||
setTokens((maxTokensToCreate - 0.0001).toFixed(4)); | ||
setTokens(Math.floor(maxTokensToCreate).toString()); | ||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, if you FLOOR the tokens to create, the GCR will always be below your desired ratio |
||
const setTokensToMax = ( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eng pls double check my math. If you CEIL the backing collateral, then the GCR check should always succeed right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how many decimal points will this be
CEIL
ing to?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, that makes sense! SGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you give an example of what these could should be? I don't understand how this can even work without big numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems okay to me... but I think ceiling to the nearest 1BTC or 1 WETH kinda defeats the point of these buttons. If we're ceiling to the nearest full unit of collateral, the max and min buttons seem like they add complexity to the dapp without adding a lot of value.
It seems like all of these issues are basically coming out of the fact that we're doing very high precision math with plain JS floating point numbers. Is it difficult to move all of these to BNs? Or is that super annoying?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh shoot I didn't even think about the fact that 1 BTC and 1 WETH are very large numbers. This seems like a good fix for the
tokens
side of things, but not the collateral