Skip to content
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

Merged
merged 1 commit into from
Aug 14, 2020

Conversation

nicholaspai
Copy link
Member

@nicholaspai nicholaspai commented Aug 12, 2020

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

…+ unit tests

Signed-off-by: Nick Pai <npai.nyc@gmail.com>
@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.683% when pulling 9c0be75 on npai/contracts-gcr into 7778e7a on master.

Copy link
Member

@mrice32 mrice32 left a 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.

Comment on lines +412 to +416
require(
(_checkCollateralization(
_getFeeAdjustedCollateral(positionData.rawCollateral).add(collateralAmount),
positionData.tokensOutstanding.add(numTokens)
) || _checkCollateralization(collateralAmount, numTokens)),
Copy link
Member

@mrice32 mrice32 Aug 12, 2020

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")

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can experiment

Copy link
Member Author

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

Copy link
Member Author

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"
        );

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

@daywiss
Copy link
Contributor

daywiss commented Aug 13, 2020

what is the reason you can't just check the resultant CR > GCR and skip the first check?

@nicholaspai
Copy link
Member Author

nicholaspai commented Aug 13, 2020

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

Copy link
Member

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@chrismaree chrismaree left a 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 })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EMP create should relax GCR constraint
5 participants