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(perpetual-liquidatable) Implement Liquidatable and replace expiry logic with emergency-shutdown logic #2076

Merged
merged 17 commits into from
Oct 13, 2020

Conversation

nicholaspai
Copy link
Member

Motivation

#2024, #2048

Summary

This PR copies the ExpiringMultiparty's Liquidatable contract and strips out expiry logic. This contract imports all of the logic from the PerpetualPositionManager introduced in #2072. Unit tests were also copied from ExpiringMultiparty and minimal changes were made to replace expiry logic with emergency shutdown logic.

Details

Major changes:

  • Add _getOraclePrice(timestamp) back to PerpetualPositionManager because the Liquidatable contract needs to call it on the liquidation-timestamp.
  • createLiquidation should be blocked during an emergency shutdown, for the EMP it is blocked post-expiry.

Issue(s)

Initial implementation of #2024
close #2048

A Follow up PR will change the _settle logic to incorporate a cumulativeFundingRateMultiplier, but this is likely blocked until an initial implementation for #2030 is built.

Open Questions
Is there any reason to disable Disputes and withdrawals of liquidation/dispute rewards following an emergency shutdown (for the perpetual contract)?

  • Cons to Disabling: If someone gets liquidated incorrectly right before shutdown, then they cannot recover their funds
  • Pros: Guarantees that no collateral leaves the contract in a shutdown

I’m inclined to follow the EMP pattern and allow disputes/withdrawal of liquidation/dispute rewards. This implies that once a sponsor is liquidated, their collateral has already “left the contract” so we should not freeze these funds

chrismaree and others added 16 commits October 7, 2020 11:30
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
…ty/PositionManager.sol

Co-authored-by: nicholaspai <9457025+nicholaspai@users.noreply.github.com>
…ty/PositionManager.sol

Co-authored-by: nicholaspai <9457025+nicholaspai@users.noreply.github.com>
…sitionManager.js

Co-authored-by: nicholaspai <9457025+nicholaspai@users.noreply.github.com>
…sitionManager.js

Co-authored-by: nicholaspai <9457025+nicholaspai@users.noreply.github.com>
…sitionManager.js

Co-authored-by: nicholaspai <9457025+nicholaspai@users.noreply.github.com>
…sitionManager.js

Co-authored-by: nicholaspai <9457025+nicholaspai@users.noreply.github.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
…rotocol/protocol into chrismaree/initial-position-manager
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
@@ -719,12 +719,11 @@ contract PerpetualPositionManager is FeePayer, AdministrateeInterface {
}

// Fetches a resolved Oracle price from the Oracle. Reverts if the Oracle hasn't resolved for this request.
function _getOracleEmergencyShutdownPrice() internal view returns (FixedPoint.Unsigned memory) {
function _getOraclePrice(uint256 requestedTime) internal view returns (FixedPoint.Unsigned memory) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Liquidatable needs access to this internal method to get the price for a specific liquidation time

Copy link
Member

Choose a reason for hiding this comment

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

that's a good point. needs to get it at dispute time.

});
});

describe("Emergency shutdown", () => {
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 test and the next one replace expiry logic with emergency-shutdown logic

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.

Great PR @nicholaspai! very simple in that we basically had to change only one modifier to get this to work with the perpetual contract. Tests are also 99.9% the same as before except for one small refactor. I'm happy with it :)

@@ -719,12 +719,11 @@ contract PerpetualPositionManager is FeePayer, AdministrateeInterface {
}

// Fetches a resolved Oracle price from the Oracle. Reverts if the Oracle hasn't resolved for this request.
function _getOracleEmergencyShutdownPrice() internal view returns (FixedPoint.Unsigned memory) {
function _getOraclePrice(uint256 requestedTime) internal view returns (FixedPoint.Unsigned memory) {
Copy link
Member

Choose a reason for hiding this comment

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

that's a good point. needs to get it at dispute time.

@chrismaree
Copy link
Member

Regarding your open question, as discussed offline, I think it best to keep the same EMP logic as a sponsor could be incorrectly liquidated right before the contract is emergency shutdown.

@coveralls
Copy link

coveralls commented Oct 8, 2020

Coverage Status

Coverage increased (+1.4%) to 93.15% when pulling dbcff0f on npai/initial-liquidatable into 3129fc8 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.

@nicholaspai thoughts on copying the contract over in a separate PR? That way, we can tell what parts changed and need to be reviewed? Otherwise, we'll probably miss the parts you changed.

@nicholaspai
Copy link
Member Author

@nicholaspai thoughts on copying the contract over in a separate PR? That way, we can tell what parts changed and need to be reviewed? Otherwise, we'll probably miss the parts you changed.

Normally i'd say yes, but there are very few changes. I'd recommend using a diff checker tool to see that I only removed the expirationTimestamp from the constructor and replaced the one onlyPreExpiry() modifier in front of createLiquidation() with notEmergencyShutdown

Signed-off-by: Nick Pai <npai.nyc@gmail.com>
@@ -9,7 +9,7 @@
"lint-fix": "npm run eslint -- --fix && npm run prettier -- --write",
"eslint": "eslint './**/*.js'",
"prettier": "prettier './**/*.js' './**/*.sol' './**/*.md'",
"test": "lerna run --stream --concurrency=1 test",
"test": "node --max-old-space-size=4096 ./node_modules/.bin/lerna run --stream --concurrency=1 test",
Copy link
Member Author

Choose a reason for hiding this comment

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

Need to increase heap size, similar to the coverage job`, to accomodate more tests: lerna/lerna#2226 (comment)

@nicholaspai nicholaspai merged commit 15a4b83 into master Oct 13, 2020
@nicholaspai nicholaspai deleted the npai/initial-liquidatable branch October 13, 2020 13:41
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.

Liquidatable: remove modifiers that reference expiration (but still handle emergency shutdown).
5 participants