-
Notifications
You must be signed in to change notification settings - Fork 175
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
feat(EMP contracts) Create callable if new position CR is above GCR #1844
Conversation
…+ unit tests Signed-off-by: Nick Pai <npai.nyc@gmail.com>
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.
Looks awesome! One nit.
require( | ||
(_checkCollateralization( | ||
_getFeeAdjustedCollateral(positionData.rawCollateral).add(collateralAmount), | ||
positionData.tokensOutstanding.add(numTokens) | ||
) || _checkCollateralization(collateralAmount, numTokens)), |
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.
nit: if it doesn't increase the bytecode size (that's a big if :)), do you think this would be a little more readable if we separated this into intermediate variables?
bool newTokensAboveGCR = ...;
bool resultingPositionAboveGCR = ...;
require(newTokensAboveGCR || resultingPositionAboveGCR, "Must meet GCR")
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 will definitely increase the bytecode but would make it easier to read. Curious how much it increase it by.
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 can experiment
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 increased bytecode by 30
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.
// Either the new create ratio or the resultant position CR must be above the current GCR.
bool resultantPositionCRGreaterThanGCR = _checkCollateralization(
_getFeeAdjustedCollateral(positionData.rawCollateral).add(collateralAmount),
positionData.tokensOutstanding.add(numTokens)
);
bool creationCRGreaterThanGCR = _checkCollateralization(collateralAmount, numTokens);
require(
(resultantPositionCRGreaterThanGCR || creationCRGreaterThanGCR),
"New CR below GCR"
);
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.
Not super opinionated here, but I'd probably err on the side of saving bytecode and making it a little less readable, just for the sake of making things easier down the road.
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.
agreed
what is the reason you can't just check the resultant CR > GCR and skip the first check? |
@daywiss Imagine that the GCR is 3.0 and your CR is 2.0 (and the liquidation ratio is 1.2). In this situation, the (CR > GCR) check would require a lot of capital for you to get your CR > GCR. So, we should still enable the previous check (creation CR > GCR) for such sponsors since it can only increase the position CR. In other words, we should only allow a position's CR to decrease IFF the resultant position's CR > GCR |
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.
LGTM!
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 looks great! nice and simple. Clean implementation and tests. Good work @nicholaspai
// resultant CR would be 25/10+6 = 156.3%. | ||
assert( | ||
await didContractThrow( | ||
pricelessPositionManager.create({ rawValue: toWei("0") }, { rawValue: toWei("6") }, { from: other }) |
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.
+1
Motivation
#1843
Summary
The GCR
require
statement was turned into an OR condition including the current condition (where create CR > GCR) and adding a new one (where resultant position CR > GCR).Details
GCR unit tests updated as well.
I tested a deployment on Kovan of the updated EMPLib and the bytecode deployed fine. The
deployedBytecode
increased by 116 bytes from my local calculation.Issue(s)
Fixes #1843