Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block addqt above auction price #997

Merged
merged 17 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/base/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ import {
import {
_revertIfAuctionDebtLocked,
_revertIfAuctionClearable,
_revertAfterExpiry
_revertAfterExpiry,
_revertIfAuctionPriceBelow
} from '../libraries/helpers/RevertsHelper.sol';

import { Buckets } from '../libraries/internal/Buckets.sol';
Expand Down Expand Up @@ -158,6 +159,8 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {

_revertIfAuctionClearable(auctions, loans);

_revertIfAuctionPriceBelow(index_, auctions);

PoolState memory poolState = _accruePoolInterest();

// round to token precision
Expand Down Expand Up @@ -192,6 +195,8 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {

_revertIfAuctionClearable(auctions, loans);

_revertIfAuctionPriceBelow(toIndex_, auctions);

PoolState memory poolState = _accruePoolInterest();

_revertIfAuctionDebtLocked(deposits, poolState.t0DebtInAuction, fromIndex_, poolState.inflator);
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/pool/commons/IPoolErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ interface IPoolErrors {
/*** Common Pool Errors ***/
/**************************/

/**
* @notice Adding liquidity above current auction price.
*/
error AddAboveAuctionPrice();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing trailing blankline

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved -> d5d0ca7

/**
* @notice `LP` allowance is already set by the owner.
*/
Expand Down
8 changes: 5 additions & 3 deletions src/libraries/external/KickerActions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ library KickerActions {
// record liquidation info
liquidation_.kicker = msg.sender;
liquidation_.kickTime = uint96(block.timestamp);
liquidation_.referencePrice = SafeCast.toUint96(referencePrice_);
liquidation_.bondSize = SafeCast.toUint160(bondSize_);
liquidation_.bondFactor = SafeCast.toUint96(bondFactor_);
liquidation_.neutralPrice = SafeCast.toUint96(neutralPrice_);
Expand All @@ -422,11 +421,14 @@ library KickerActions {
// update auctions queue
if (auctions_.head != address(0)) {
// other auctions in queue, liquidation doesn't exist or overwriting.
auctions_.liquidations[auctions_.tail].next = borrowerAddress_;
liquidation_.prev = auctions_.tail;
address tail = auctions_.tail;
auctions_.liquidations[tail].next = borrowerAddress_;
liquidation_.prev = tail;
liquidation_.referencePrice = SafeCast.toUint96(Maths.max(referencePrice_, auctions_.liquidations[tail].referencePrice));
} else {
// first auction in queue
auctions_.head = borrowerAddress_;
liquidation_.referencePrice = SafeCast.toUint96(referencePrice_);
}
// update liquidation with the new ordering
auctions_.tail = borrowerAddress_;
Expand Down
21 changes: 20 additions & 1 deletion src/libraries/helpers/RevertsHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
PoolBalancesState
} from '../../interfaces/pool/commons/IPoolState.sol';

import { _minDebtAmount, _priceAt } from './PoolHelper.sol';
import { _minDebtAmount, _priceAt, _auctionPrice } from './PoolHelper.sol';

import { Loans } from '../internal/Loans.sol';
import { Deposits } from '../internal/Deposits.sol';
Expand All @@ -23,6 +23,7 @@ import { Maths } from '../internal/Maths.sol';
error LimitIndexExceeded();
error RemoveDepositLockedByAuctionDebt();
error TransactionExpired();
error AddAboveAuctionPrice();

/**
* @notice Called by `LP` removal functions assess whether or not `LP` is locked.
Expand Down Expand Up @@ -75,6 +76,24 @@ import { Maths } from '../internal/Maths.sol';
if (newPrice_ < _priceAt(limitIndex_)) revert LimitIndexExceeded();
}

/**
* @notice Check if provided price is above current auction price.
* @notice Prevents manipulative deposir and arb takes.
ith-harvey marked this conversation as resolved.
Show resolved Hide resolved
* @dev Reverts with `AddAboveAuctionPrice` if price is above head of auction queue.
* @param index_ Identifies bucket price to be compared with current auction price.
* @param auctions_ Auctions data.
*/
function _revertIfAuctionPriceBelow(
uint256 index_,
AuctionsState storage auctions_
) view {
address head = auctions_.head;
if (head != address(0)) {
uint256 auctionPrice = _auctionPrice(auctions_.liquidations[head].referencePrice, auctions_.liquidations[head].kickTime);
if (_priceAt(index_) >= auctionPrice) revert AddAboveAuctionPrice();
}
}

/**
* @notice Check if expiration provided by user has met or exceeded current block height timestamp.
* @notice Prevents stale transactions interacting with the pool at potentially unfavorable prices.
Expand Down
Loading
Loading