Skip to content

Commit

Permalink
Sherlock 105.md: ERC721Pool's mergeOrRemoveCollateral allows to remov…
Browse files Browse the repository at this point in the history
…e collateral while auction is clearable (#571)

- check _revertIfAuctionClearable in mergeOrRemoveCollateral function
- update tests: add _assertMergeRemoveCollateralAuctionNotClearedRevert and assert in ERC721 mergeOrRemove unit tests
  • Loading branch information
grandizzy committed Feb 8, 2023
1 parent 466f245 commit 252a612
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ERC721Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool {
uint256 noOfNFTsToRemove_,
uint256 toIndex_
) external override nonReentrant returns (uint256 collateralMerged_, uint256 bucketLPs_) {
_revertIfAuctionClearable(auctions, loans);

PoolState memory poolState = _accruePoolInterest();
uint256 collateralAmount = Maths.wad(noOfNFTsToRemove_);

Expand Down
11 changes: 11 additions & 0 deletions tests/forge/ERC721Pool/ERC721DSTestPlus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,17 @@ abstract contract ERC721DSTestPlus is DSTestPlus, IERC721PoolEvents {
ERC721Pool(address(_pool)).drawDebt(from, amount, indexLimit, emptyArray);
}

function _assertMergeRemoveCollateralAuctionNotClearedRevert(
address from,
uint256 toIndex,
uint256 noOfNFTsToRemove,
uint256[] memory removeCollateralAtIndex
) internal {
changePrank(from);
vm.expectRevert(abi.encodeWithSignature('AuctionNotCleared()'));
ERC721Pool(address(_pool)).mergeOrRemoveCollateral(removeCollateralAtIndex, noOfNFTsToRemove, toIndex);
}

function _assertCannotMergeToHigherPriceRevert(
address from,
uint256 toIndex,
Expand Down
16 changes: 16 additions & 0 deletions tests/forge/ERC721Pool/ERC721PoolLiquidationsSettle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ contract ERC721PoolLiquidationsSettleTest is ERC721HelperContract {
})
);

// revert if auction is not settled
_assertMergeRemoveCollateralAuctionNotClearedRevert({
from: _lender,
toIndex: MAX_FENWICK_INDEX,
noOfNFTsToRemove: 2,
removeCollateralAtIndex: new uint256[](0)
});

_settle({
from: _lender,
borrower: _borrower2,
Expand All @@ -227,6 +235,14 @@ contract ERC721PoolLiquidationsSettleTest is ERC721HelperContract {
})
);

// revert if auction is not settled
_assertMergeRemoveCollateralAuctionNotClearedRevert({
from: _lender,
toIndex: MAX_FENWICK_INDEX,
noOfNFTsToRemove: 2,
removeCollateralAtIndex: new uint256[](0)
});

// settle borrower
_settle({
from: _lender,
Expand Down

0 comments on commit 252a612

Please sign in to comment.