Skip to content

Commit

Permalink
Sherlock-110 (moveQuoteToken continuation): move quote token revert i…
Browse files Browse the repository at this point in the history
…f auction clearable (#919)
  • Loading branch information
grandizzy authored Jul 2, 2023
1 parent 94be5c2 commit 2af7d81
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@
- pool inflator and inflatorUpdate state

reverts on:
- block timestamp greater than expiry TransactionExpired()
- deposits locked RemoveDepositLockedByAuctionDebt()
- head auction not cleared AuctionNotCleared()
- LenderActions.moveQuoteToken():
- same index MoveToSameIndex()
- dust amount DustAmountNotExceeded()
Expand Down
21 changes: 14 additions & 7 deletions src/base/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import {
ReserveAuctionState,
Bucket,
Lender,
Borrower,
Kicker,
BurnEvent,
Liquidation
} from '../interfaces/pool/commons/IPoolState.sol';
Expand Down Expand Up @@ -188,6 +190,9 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
bool revertIfBelowLup_
) external override nonReentrant returns (uint256 fromBucketLP_, uint256 toBucketLP_, uint256 movedAmount_) {
_revertAfterExpiry(expiry_);

_revertIfAuctionClearable(auctions, loans);

PoolState memory poolState = _accruePoolInterest();

_revertIfAuctionDebtLocked(deposits, poolState.t0DebtInAuction, fromIndex_, poolState.inflator);
Expand Down Expand Up @@ -759,7 +764,7 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
address prev_,
bool alreadyTaken_
) {
Liquidation memory liquidation = auctions.liquidations[borrower_];
Liquidation storage liquidation = auctions.liquidations[borrower_];
return (
liquidation.kicker,
liquidation.bondFactor,
Expand All @@ -778,10 +783,11 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
function borrowerInfo(
address borrower_
) external view override returns (uint256, uint256, uint256) {
Borrower storage borrower = loans.borrowers[borrower_];
return (
loans.borrowers[borrower_].t0Debt,
loans.borrowers[borrower_].collateral,
loans.borrowers[borrower_].t0Np
borrower.t0Debt,
borrower.collateral,
borrower.t0Np
);
}

Expand Down Expand Up @@ -821,7 +827,7 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {

/// @inheritdoc IPoolState
function burnInfo(uint256 burnEventEpoch_) external view returns (uint256, uint256, uint256) {
BurnEvent memory burnEvent = reserveAuction.burnEvents[burnEventEpoch_];
BurnEvent storage burnEvent = reserveAuction.burnEvents[burnEventEpoch_];

return (
burnEvent.timestamp,
Expand Down Expand Up @@ -906,9 +912,10 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
function kickerInfo(
address kicker_
) external view override returns (uint256, uint256) {
Kicker storage kicker = auctions.kickers[kicker_];
return(
auctions.kickers[kicker_].claimable,
auctions.kickers[kicker_].locked
kicker.claimable,
kicker.locked
);
}

Expand Down
13 changes: 13 additions & 0 deletions tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsMisc.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@ contract ERC20PoolLiquidationsMiscTest is ERC20HelperContract {
toIndex: _i9_81
});

uint256 snapshot = vm.snapshot();
skip(73 hours);

// lender cannot move funds if auction not cleared
_assertMoveDepositAuctionNotClearedRevert({
from: _lender,
amount: 10.0 * 1e18,
fromIndex: _i9_72,
toIndex: _i9_81
});

vm.revertTo(snapshot);

// lender can add / remove liquidity in buckets that are not within liquidation debt
changePrank(_lender1);
_pool.addQuoteToken(2_000 * 1e18, 5000, block.timestamp + 1 minutes, false);
Expand Down
11 changes: 11 additions & 0 deletions tests/forge/utils/DSTestPlus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,17 @@ abstract contract DSTestPlus is Test, IPoolEvents {
_pool.moveQuoteToken(amount, fromIndex, toIndex, type(uint256).max, false);
}

function _assertMoveDepositAuctionNotClearedRevert(
address from,
uint256 amount,
uint256 fromIndex,
uint256 toIndex
) internal {
changePrank(from);
vm.expectRevert(IPoolErrors.AuctionNotCleared.selector);
_pool.moveQuoteToken(amount, fromIndex, toIndex, type(uint256).max, false);
}

function _assertMoveDepositBelowLUPRevert(
address from,
uint256 amount,
Expand Down

0 comments on commit 2af7d81

Please sign in to comment.