-
Notifications
You must be signed in to change notification settings - Fork 184
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
Conversation
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>
…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>
@@ -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) { |
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.
Liquidatable needs access to this internal method to get the price for a specific liquidation time
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.
that's a good point. needs to get it at dispute time.
}); | ||
}); | ||
|
||
describe("Emergency shutdown", () => { |
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 test and the next one replace expiry logic with emergency-shutdown logic
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.
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) { |
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.
that's a good point. needs to get it at dispute time.
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. |
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.
@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 |
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", |
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.
Need to increase heap size, similar to the coverage
job`, to accomodate more tests: lerna/lerna#2226 (comment)
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:
_getOraclePrice(timestamp)
back toPerpetualPositionManager
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)?
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