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

Revert if encumbered collateral is calculated as zero for non zero debt #673

Merged
merged 1 commit into from
Mar 8, 2023

Conversation

grandizzy
Copy link
Contributor

  • 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
Copy link
Contributor

@mattcushman mattcushman left a 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);
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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

Copy link
Contributor

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);
Copy link
Contributor

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

Copy link
Contributor

@ith-harvey ith-harvey left a comment

Choose a reason for hiding this comment

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

LGTM

@grandizzy grandizzy merged commit 51643b3 into develop Mar 8, 2023
@grandizzy grandizzy deleted the fix-zero-encumbered-withdebt branch March 8, 2023 17:48
@godsflaw godsflaw mentioned this pull request Dec 8, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants