Skip to content

Commit

Permalink
Fix for Borrower won't be able to pull his entitled NFT collateral fr…
Browse files Browse the repository at this point in the history
…om pool after take / bucketTake
  • Loading branch information
grandizzy committed Jan 19, 2023
1 parent c645a05 commit 4b4c2d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/libraries/external/Auctions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@ library Auctions {
result_.poolDebt = poolState_.debt;
(
result_.newLup,
result_.settledAuction
result_.settledAuction,
result_.remainingCollateral
) = _takeLoan(
auctions_,
buckets_,
Expand Down Expand Up @@ -576,7 +577,8 @@ library Auctions {
result_.poolDebt = poolState_.debt;
(
result_.newLup,
result_.settledAuction
result_.settledAuction,
result_.remainingCollateral
) = _takeLoan(
auctions_,
buckets_,
Expand Down Expand Up @@ -1002,11 +1004,12 @@ library Auctions {
* @notice If borrower becomes recollateralized then auction is settled. Update loan's state.
* @dev reverts on:
* - borrower debt less than pool min debt AmountLTMinDebt()
* @param borrower_ Struct containing pool details.
* @param borrower_ The borrower details owning loan that is taken.
* @param borrowerAddress_ The address of the borrower.
* @return newLup_ The new LUP of pool (after debt is repaid).
* @return settledAuction_ True if auction is settled by the take action.
* @param borrower_ Struct containing pool details.
* @param borrower_ The borrower details owning loan that is taken.
* @param borrowerAddress_ The address of the borrower.
* @return newLup_ The new LUP of pool (after debt is repaid).
* @return settledAuction_ True if auction is settled by the take action. (NFT take: rebalance borrower collateral in pool if true)
* @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 @@ -1018,7 +1021,8 @@ library Auctions {
address borrowerAddress_
) internal returns (
uint256 newLup_,
bool settledAuction_
bool settledAuction_,
uint256 remainingCollateral_
) {

uint256 borrowerDebt = Maths.wmul(borrower_.t0Debt, poolState_.inflator);
Expand All @@ -1038,14 +1042,16 @@ library Auctions {
settledAuction_ = true;

// 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_;
}

// update loan state, stamp borrower t0Np only when exiting from auction
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 pull collateral from 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 4b4c2d3

Please sign in to comment.