-
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
Revert if encumbered collateral is calculated as zero for non zero debt #673
Conversation
grandizzy
commented
Mar 8, 2023
- encumbered collateral can be calculated as zero when tiny debt and a big LUP (encumbered = debt / LUP)
- in such case borrower could pull collateral leaving pool in a state where borrower has debt but not reflected in loans heap or auction queue
- fix scenario by reverting when encumbered collateral is 0 but debt is greater than 0
- encumbered collateral can be calculated as zero when tiny debt and a big LUP (encumbered = debt / LUP) - in such case borrower could pull collateral leaving pool in a state where borrower has debt but not reflected in loans heap or auction queue - fix scenario by reverting when encumbered collateral is 0 but debt is greater than 0
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
function testPullBorrowerWithDebtCollateralEncumberedCalculatedAsZero() external { | ||
address actor = makeAddr("actor"); | ||
|
||
_mintCollateralAndApproveTokens(actor, 1000000000 * 1e18); |
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.
instead of creating a new actor here shouldn't we just give _lender
more quote and collateral?
Keeps things tidy?
_mintQuoteAndApproveTokens(actor, 1000000000000 * 1e18); | ||
|
||
changePrank(actor); | ||
_pool.addQuoteToken(200, 2572, block.timestamp + 100); |
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.
should we do an addInitialLiquidity
call?
|
||
changePrank(actor); | ||
_pool.addQuoteToken(200, 2572, block.timestamp + 100); | ||
ERC20Pool(address(_pool)).drawDebt(actor, 100, 7388, 1); |
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.
_drawDebt
call?
changePrank(actor); | ||
_pool.addQuoteToken(200, 2572, block.timestamp + 100); | ||
ERC20Pool(address(_pool)).drawDebt(actor, 100, 7388, 1); | ||
|
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.
suggest we add an _assertPool
here
ERC20Pool(address(_pool)).repayDebt(actor, 0, 1, actor, 7388); | ||
|
||
// borrower should be able to repay and pull collateral | ||
ERC20Pool(address(_pool)).repayDebt(actor, 120, 1, actor, 7388); |
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.
should do a _assertPool
after action as well IMO
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