-
Notifications
You must be signed in to change notification settings - Fork 11
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
HPB bankruptcy on settle #675
Conversation
- if there's only a tiny amount of deposit (2) backed by 2 LPs in HPB then the collateralUsed to settle is calculated as 0 due to rounding (vars.collateralUsed = Maths.wdiv(vars.scaledDeposit, vars.price)) - this results in removing deposit (2) and not adding any collateral into bucket, leaving an amount of 2 LPs that is not backed by any asset - fixed by declaring bucket bankruptcy in case settle leaves bucket with 0 collateral, 0 deposit but LPs > 0 - added check for deposit to remove to be min of available deposit in bucket / calculated deposit for settle in order to prevent any potential underflow - unit 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.
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.
LGTM
uint256 depositToRemove; // [WAD] deposit used by settle auction | ||
uint256 hpbCollateral; // [WAD] amount of collateral in HPB bucket | ||
uint256 hpbUnscaledDeposit; // [WAD] unscaled amount of of quote tokens in HPB bucket before settle | ||
uint256 hpbLPs; // [WAD] amount of LPs in HPB bucket |
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.
note to self: 3 new local vars lines 111-113
vars.hpbCollateral = hpb.collateral + vars.collateralUsed; | ||
|
||
// set amount to remove as min of calculated amount and available deposit (to prevent rounding issues) | ||
vars.unscaledDeposit = Maths.min(vars.hpbUnscaledDeposit, vars.unscaledDeposit); |
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: alignment of Maths.min
call
|
||
Deposits.unscaledRemove(deposits_, vars.index, vars.unscaledDeposit); // remove amount to settle debt from bucket (could be entire deposit or only the settled debt) | ||
} | ||
Bucket storage hpb = buckets_[vars.index]; |
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.
Appreciate naming this hpb
and not settlementBucket
. I reviewed and confirmed this is always the HPB; the user cannot specify the index.
vars.collateralUsed = Maths.wdiv(vars.scaledDeposit, vars.price)
)