Skip to content

Commit

Permalink
103.md: Remaining collateral used by ERC721Pool is missed in Auctions…
Browse files Browse the repository at this point in the history
… take and bucketTake return structures
  • Loading branch information
grandizzy committed Jan 31, 2023
1 parent 8c801a4 commit 1685713
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/libraries/external/Auctions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,8 @@ library Auctions {
result_.poolDebt,
result_.newLup,
result_.t0DebtInAuctionChange,
result_.settledAuction
result_.settledAuction,
result_.remainingCollateral
) = _takeLoan(
auctions_,
buckets_,
Expand Down Expand Up @@ -580,7 +581,8 @@ library Auctions {
result_.poolDebt,
result_.newLup,
result_.t0DebtInAuctionChange,
result_.settledAuction
result_.settledAuction,
result_.remainingCollateral
) = _takeLoan(
auctions_,
buckets_,
Expand Down Expand Up @@ -989,6 +991,7 @@ library Auctions {
* @return newLup_ The new LUP of pool (after debt is repaid).
* @return t0DebtInAuctionChange_ The overall debt in auction change (remaining borrower debt if auction settled, repaid debt otherwise).
* @return settledAuction_ True if auction is settled by the take action.
* @return remainingCollateral_ Borrower collateral remaining after take action. (NFT take: collateral to be rebalanced in case of NFT settlement)
*/
function _takeLoan(
AuctionsState storage auctions_,
Expand All @@ -1003,7 +1006,8 @@ library Auctions {
uint256 poolDebt_,
uint256 newLup_,
uint256 t0DebtInAuctionChange_,
bool settledAuction_
bool settledAuction_,
uint256 remainingCollateral_
) {

TakeLoanLocalVars memory vars;
Expand Down Expand Up @@ -1031,14 +1035,16 @@ library Auctions {
t0DebtInAuctionChange_ = borrower_.t0Debt;

// settle auction and update borrower's collateral with value after settlement
borrower_.collateral = _settleAuction(
remainingCollateral_ = _settleAuction(
auctions_,
buckets_,
deposits_,
borrowerAddress_,
borrower_.collateral,
poolState_.poolType
);

borrower_.collateral = remainingCollateral_;
} else {
// the overall debt in auction change is the amount of partially repaid debt
t0DebtInAuctionChange_ = t0RepaidDebt_;
Expand Down
9 changes: 9 additions & 0 deletions tests/forge/ERC721Pool/ERC721PoolLiquidationsTake.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,15 @@ contract ERC721PoolLiquidationsTakeTest is ERC721HelperContract {
borrowerCollateralization: 1 * 1e18
});

// borrower should be able to remove collateral in the pool
_repayDebtNoLupCheck({
from: _borrower,
borrower: _borrower,
amountToRepay: 0,
amountRepaid: 0,
collateralToPull: 1
});

vm.revertTo(snapshot);

// borrower repays part of debt, but not enough to exit from auction
Expand Down

0 comments on commit 1685713

Please sign in to comment.