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

add reverting tests, fix fuzz for hooks.t.sol #548

Merged
merged 10 commits into from
May 17, 2024
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
32 changes: 16 additions & 16 deletions src/libraries/Hooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ library Hooks {
using BeforeSwapDeltaLibrary for BeforeSwapDelta;
using ParseBytes for bytes;

uint256 internal constant BEFORE_INITIALIZE_FLAG = 1 << 159;
uint256 internal constant AFTER_INITIALIZE_FLAG = 1 << 158;
uint160 internal constant BEFORE_INITIALIZE_FLAG = 1 << 159;
uint160 internal constant AFTER_INITIALIZE_FLAG = 1 << 158;

uint256 internal constant BEFORE_ADD_LIQUIDITY_FLAG = 1 << 157;
uint256 internal constant AFTER_ADD_LIQUIDITY_FLAG = 1 << 156;
uint160 internal constant BEFORE_ADD_LIQUIDITY_FLAG = 1 << 157;
uint160 internal constant AFTER_ADD_LIQUIDITY_FLAG = 1 << 156;

uint256 internal constant BEFORE_REMOVE_LIQUIDITY_FLAG = 1 << 155;
uint256 internal constant AFTER_REMOVE_LIQUIDITY_FLAG = 1 << 154;
uint160 internal constant BEFORE_REMOVE_LIQUIDITY_FLAG = 1 << 155;
uint160 internal constant AFTER_REMOVE_LIQUIDITY_FLAG = 1 << 154;

uint256 internal constant BEFORE_SWAP_FLAG = 1 << 153;
uint256 internal constant AFTER_SWAP_FLAG = 1 << 152;
uint160 internal constant BEFORE_SWAP_FLAG = 1 << 153;
uint160 internal constant AFTER_SWAP_FLAG = 1 << 152;

uint256 internal constant BEFORE_DONATE_FLAG = 1 << 151;
uint256 internal constant AFTER_DONATE_FLAG = 1 << 150;
uint160 internal constant BEFORE_DONATE_FLAG = 1 << 151;
uint160 internal constant AFTER_DONATE_FLAG = 1 << 150;

uint256 internal constant BEFORE_SWAP_RETURNS_DELTA_FLAG = 1 << 149;
uint256 internal constant AFTER_SWAP_RETURNS_DELTA_FLAG = 1 << 148;
uint256 internal constant AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG = 1 << 147;
uint256 internal constant AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG = 1 << 146;
uint160 internal constant BEFORE_SWAP_RETURNS_DELTA_FLAG = 1 << 149;
uint160 internal constant AFTER_SWAP_RETURNS_DELTA_FLAG = 1 << 148;
uint160 internal constant AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG = 1 << 147;
uint160 internal constant AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG = 1 << 146;

struct Permissions {
bool beforeInitialize;
Expand Down Expand Up @@ -318,8 +318,8 @@ library Hooks {
}
}

function hasPermission(IHooks self, uint256 flag) internal pure returns (bool) {
return uint256(uint160(address(self))) & flag != 0;
function hasPermission(IHooks self, uint160 flag) internal pure returns (bool) {
return uint160(address(self)) & flag != 0;
}

/// @notice bubble up revert if present. Else throw FailedHookCall
Expand Down
106 changes: 106 additions & 0 deletions src/test/EmptyRevertHook.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

import {IHooks} from "../interfaces/IHooks.sol";
import {PoolKey} from "../types/PoolKey.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";
import {IPoolManager} from "../interfaces/IPoolManager.sol";
import {BeforeSwapDelta} from "../types/BeforeSwapDelta.sol";

contract EmptyRevertHook is IHooks {
function beforeInitialize(
address, /* sender **/
PoolKey calldata, /* key **/
uint160, /* sqrtPriceX96 **/
bytes calldata /* hookData **/
) external virtual returns (bytes4) {
revert();
}

function afterInitialize(
address, /* sender **/
PoolKey calldata, /* key **/
uint160, /* sqrtPriceX96 **/
int24, /* tick **/
bytes calldata /* hookData **/
) external virtual returns (bytes4) {
revert();
}

function beforeAddLiquidity(
address, /* sender **/
PoolKey calldata, /* key **/
IPoolManager.ModifyLiquidityParams calldata, /* params **/
bytes calldata /* hookData **/
) external virtual returns (bytes4) {
revert();
}

function afterAddLiquidity(
address, /* sender **/
PoolKey calldata, /* key **/
IPoolManager.ModifyLiquidityParams calldata, /* params **/
BalanceDelta, /* delta **/
bytes calldata /* hookData **/
) external virtual returns (bytes4, BalanceDelta) {
revert();
}

function beforeRemoveLiquidity(
address, /* sender **/
PoolKey calldata, /* key **/
IPoolManager.ModifyLiquidityParams calldata, /* params **/
bytes calldata /* hookData **/
) external virtual returns (bytes4) {
revert();
}

function afterRemoveLiquidity(
address, /* sender **/
PoolKey calldata, /* key **/
IPoolManager.ModifyLiquidityParams calldata, /* params **/
BalanceDelta, /* delta **/
bytes calldata /* hookData **/
) external virtual returns (bytes4, BalanceDelta) {
revert();
}

function beforeSwap(
address, /* sender **/
PoolKey calldata, /* key **/
IPoolManager.SwapParams calldata, /* params **/
bytes calldata /* hookData **/
) external virtual returns (bytes4, BeforeSwapDelta, uint24) {
revert();
}

function afterSwap(
address, /* sender **/
PoolKey calldata, /* key **/
IPoolManager.SwapParams calldata, /* params **/
BalanceDelta, /* delta **/
bytes calldata /* hookData **/
) external virtual returns (bytes4, int128) {
revert();
}

function beforeDonate(
address, /* sender **/
PoolKey calldata, /* key **/
uint256, /* amount0 **/
uint256, /* amount1 **/
bytes calldata /* hookData **/
) external virtual returns (bytes4) {
revert();
}

function afterDonate(
address, /* sender **/
PoolKey calldata, /* key **/
uint256, /* amount0 **/
uint256, /* amount1 **/
bytes calldata /* hookData **/
) external virtual returns (bytes4) {
revert();
}
}
Loading
Loading