Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions src/periphery/validationHooks/MaxBidPriceValidationHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {IERC165} from '@openzeppelin/contracts/utils/introspection/IERC165.sol';
/// @title IMaxBidPriceValidationHook
interface IMaxBidPriceValidationHook is IValidationHookIntrospection {
/// @notice The maximum bid price allowed for a continuous clearing auction
/// @return the max bid price allowed, in Q96 form
/// @dev A value of 0 means no effective cap: implementations MUST treat it as "unset" and accept
/// every bid price. A literal cap of 0 is unreachable anyway, since a bid must price strictly
/// above the clearing price, which starts at a floor of at least `ConstantsLib.MIN_FLOOR_PRICE`.
/// @return the max bid price allowed, in Q96 form, or 0 for no cap
function maxBidPrice() external view returns (uint256);
}

Expand All @@ -17,6 +20,7 @@ interface IMaxBidPriceValidationHook is IValidationHookIntrospection {
/// @dev Since CCA requires all bids to be strictly above the current clearing price, using this hook
/// will prevent new bids from being placed once the maximum bid price is reached. All existing
/// bids will remain active and partially fill for the remaining supply of tokens.
/// @dev Constructing with `_maxBidPrice = 0` disables the cap rather than rejecting every bid.
contract MaxBidPriceValidationHook is IMaxBidPriceValidationHook, ValidationHookIntrospection {
uint256 public immutable maxBidPrice;

Expand All @@ -29,7 +33,7 @@ contract MaxBidPriceValidationHook is IMaxBidPriceValidationHook, ValidationHook

/// @inheritdoc IValidationHook
function validate(uint256 maxPrice, uint128, address, address, bytes calldata) external view {
if (maxPrice > maxBidPrice) revert MaxBidPriceExceeded();
if (maxBidPrice != 0 && maxPrice > maxBidPrice) revert MaxBidPriceExceeded();
}

/// @inheritdoc IERC165
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,34 @@ contract MaxBidPriceValidationHookTest is BttBase {
assertEq(hook.maxBidPrice(), _maxBidPrice);
}

function test_WhenMaxBidPriceIsZero(
uint256 _maxPrice,
uint128 _amount,
address _owner,
address _sender,
bytes calldata _hookData
) external {
// it does not revert

MaxBidPriceValidationHook hook = new MaxBidPriceValidationHook(0);
hook.validate(_maxPrice, _amount, _owner, _sender, _hookData);
}

modifier whenMaxBidPriceIsNotZero() {
_;
}

function test_WhenMaxPriceGTMaxBidPrice(
uint256 _maxBidPrice,
uint256 _maxPrice,
uint128 _amount,
address _owner,
address _sender,
bytes calldata _hookData
) external {
) external whenMaxBidPriceIsNotZero {
// it reverts with {MaxBidPriceExceeded}

_maxBidPrice = bound(_maxBidPrice, 0, type(uint256).max - 1);
_maxBidPrice = bound(_maxBidPrice, 1, type(uint256).max - 1);
_maxPrice = bound(_maxPrice, _maxBidPrice + 1, type(uint256).max);

MaxBidPriceValidationHook hook = new MaxBidPriceValidationHook(_maxBidPrice);
Expand All @@ -46,9 +63,11 @@ contract MaxBidPriceValidationHookTest is BttBase {
address _owner,
address _sender,
bytes calldata _hookData
) external whenMaxPriceLTEMaxBidPrice {
) external whenMaxBidPriceIsNotZero whenMaxPriceLTEMaxBidPrice {
// it does not revert

_maxBidPrice = bound(_maxBidPrice, 1, type(uint256).max);

MaxBidPriceValidationHook hook = new MaxBidPriceValidationHook(_maxBidPrice);
hook.validate(_maxBidPrice, _amount, _owner, _sender, _hookData);
}
Expand All @@ -60,7 +79,7 @@ contract MaxBidPriceValidationHookTest is BttBase {
address _owner,
address _sender,
bytes calldata _hookData
) external whenMaxPriceLTEMaxBidPrice {
) external whenMaxBidPriceIsNotZero whenMaxPriceLTEMaxBidPrice {
// it does not revert

_maxBidPrice = bound(_maxBidPrice, 1, type(uint256).max);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ MaxBidPriceValidationHookTest
├── constructor
│ └── it sets maxBidPrice
├── validate
│ ├── when maxPrice GT maxBidPrice
│ │ └── it reverts with {MaxBidPriceExceeded}
│ └── when maxPrice LTE maxBidPrice
│ ├── when maxPrice EQ maxBidPrice
│ │ └── it does not revert
│ └── when maxPrice LT maxBidPrice
│ └── it does not revert
│ ├── when maxBidPrice is 0
│ │ └── it does not revert
│ └── when maxBidPrice is not 0
│ ├── when maxPrice GT maxBidPrice
│ │ └── it reverts with {MaxBidPriceExceeded}
│ └── when maxPrice LTE maxBidPrice
│ ├── when maxPrice EQ maxBidPrice
│ │ └── it does not revert
│ └── when maxPrice LT maxBidPrice
│ └── it does not revert
└── supportsInterface
├── when interface is supported
│ └── it returns true
Expand Down
Loading