From 168571357d15efa030af07d5b092c4523a9719ce Mon Sep 17 00:00:00 2001 From: grandizzy Date: Tue, 31 Jan 2023 09:41:21 +0200 Subject: [PATCH] 103.md: Remaining collateral used by ERC721Pool is missed in Auctions take and bucketTake return structures --- src/libraries/external/Auctions.sol | 14 ++++++++++---- .../ERC721Pool/ERC721PoolLiquidationsTake.t.sol | 9 +++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/libraries/external/Auctions.sol b/src/libraries/external/Auctions.sol index cd7cc022b..4b8c0e298 100644 --- a/src/libraries/external/Auctions.sol +++ b/src/libraries/external/Auctions.sol @@ -514,7 +514,8 @@ library Auctions { result_.poolDebt, result_.newLup, result_.t0DebtInAuctionChange, - result_.settledAuction + result_.settledAuction, + result_.remainingCollateral ) = _takeLoan( auctions_, buckets_, @@ -580,7 +581,8 @@ library Auctions { result_.poolDebt, result_.newLup, result_.t0DebtInAuctionChange, - result_.settledAuction + result_.settledAuction, + result_.remainingCollateral ) = _takeLoan( auctions_, buckets_, @@ -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_, @@ -1003,7 +1006,8 @@ library Auctions { uint256 poolDebt_, uint256 newLup_, uint256 t0DebtInAuctionChange_, - bool settledAuction_ + bool settledAuction_, + uint256 remainingCollateral_ ) { TakeLoanLocalVars memory vars; @@ -1031,7 +1035,7 @@ library Auctions { t0DebtInAuctionChange_ = borrower_.t0Debt; // settle auction and update borrower's collateral with value after settlement - borrower_.collateral = _settleAuction( + remainingCollateral_ = _settleAuction( auctions_, buckets_, deposits_, @@ -1039,6 +1043,8 @@ library Auctions { borrower_.collateral, poolState_.poolType ); + + borrower_.collateral = remainingCollateral_; } else { // the overall debt in auction change is the amount of partially repaid debt t0DebtInAuctionChange_ = t0RepaidDebt_; diff --git a/tests/forge/ERC721Pool/ERC721PoolLiquidationsTake.t.sol b/tests/forge/ERC721Pool/ERC721PoolLiquidationsTake.t.sol index 92db05ada..4c611d29e 100644 --- a/tests/forge/ERC721Pool/ERC721PoolLiquidationsTake.t.sol +++ b/tests/forge/ERC721Pool/ERC721PoolLiquidationsTake.t.sol @@ -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