Skip to content
LogoLogo

BaseHook

Git Source

Inherits: IHooks, ImmutableState

Title: Base Hook

abstract contract for hook implementations

Functions

constructor

constructor(IPoolManager _manager) ImmutableState(_manager);

Parameters

NameTypeDescription
_managerIPoolManager

getHookPermissions

Returns a struct of permissions to signal which hook functions are to be implemented

Used at deployment to validate the address correctly represents the expected permissions

function getHookPermissions() public pure virtual returns (Hooks.Permissions memory);

Returns

NameTypeDescription
<none>Hooks.Permissions

validateHookAddress

Validates the deployed hook address agrees with the expected permissions of the hook

Virtual so tests can override it, deploy an implementation at any address, and etch the bytecode at the permission-encoded address.

function validateHookAddress(BaseHook _this) internal pure virtual;

Parameters

NameTypeDescription
_thisBaseHook

beforeInitialize

The hook called before the state of a pool is initialized

function beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)
        external
        onlyPoolManager
        returns (bytes4);

Parameters

NameTypeDescription
senderaddressThe initial msg.sender for the initialize call
keyPoolKeyThe key for the pool being initialized
sqrtPriceX96uint160The sqrt(price) of the pool as a Q64.96

Returns

NameTypeDescription
<none>bytes4bytes4 The function selector for the hook

_beforeInitialize

function _beforeInitialize(address, PoolKey calldata, uint160) internal virtual returns (bytes4);

Parameters

NameTypeDescription
_address
_PoolKey
_uint160

Returns

NameTypeDescription
<none>bytes4

afterInitialize

The hook called after the state of a pool is initialized

function afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)
        external
        onlyPoolManager
        returns (bytes4);

Parameters

NameTypeDescription
senderaddressThe initial msg.sender for the initialize call
keyPoolKeyThe key for the pool being initialized
sqrtPriceX96uint160The sqrt(price) of the pool as a Q64.96
tickint24The current tick after the state of a pool is initialized

Returns

NameTypeDescription
<none>bytes4bytes4 The function selector for the hook

_afterInitialize

function _afterInitialize(address, PoolKey calldata, uint160, int24) internal virtual returns (bytes4);

Parameters

NameTypeDescription
_address
_PoolKey
_uint160
_int24

Returns

NameTypeDescription
<none>bytes4

beforeAddLiquidity

The hook called before liquidity is added

function beforeAddLiquidity(
        address sender,
        PoolKey calldata key,
        ModifyLiquidityParams calldata params,
        bytes calldata hookData
    ) external onlyPoolManager returns (bytes4);

Parameters

NameTypeDescription
senderaddressThe initial msg.sender for the add liquidity call
keyPoolKeyThe key for the pool
paramsModifyLiquidityParamsThe parameters for adding liquidity
hookDatabytesArbitrary data handed into the PoolManager by the liquidity provider to be passed on to the hook

Returns

NameTypeDescription
<none>bytes4bytes4 The function selector for the hook

_beforeAddLiquidity

function _beforeAddLiquidity(address, PoolKey calldata, ModifyLiquidityParams calldata, bytes calldata)
        internal
        virtual
        returns (bytes4);

Parameters

NameTypeDescription
_address
_PoolKey
_ModifyLiquidityParams
_bytes

Returns

NameTypeDescription
<none>bytes4

beforeRemoveLiquidity

The hook called before liquidity is removed

function beforeRemoveLiquidity(
        address sender,
        PoolKey calldata key,
        ModifyLiquidityParams calldata params,
        bytes calldata hookData
    ) external onlyPoolManager returns (bytes4);

Parameters

NameTypeDescription
senderaddressThe initial msg.sender for the remove liquidity call
keyPoolKeyThe key for the pool
paramsModifyLiquidityParamsThe parameters for removing liquidity
hookDatabytesArbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook

Returns

NameTypeDescription
<none>bytes4bytes4 The function selector for the hook

_beforeRemoveLiquidity

function _beforeRemoveLiquidity(address, PoolKey calldata, ModifyLiquidityParams calldata, bytes calldata)
        internal
        virtual
        returns (bytes4);

Parameters

NameTypeDescription
_address
_PoolKey
_ModifyLiquidityParams
_bytes

Returns

NameTypeDescription
<none>bytes4

afterAddLiquidity

The hook called after liquidity is added

function afterAddLiquidity(
        address sender,
        PoolKey calldata key,
        ModifyLiquidityParams calldata params,
        BalanceDelta delta,
        BalanceDelta feesAccrued,
        bytes calldata hookData
    ) external onlyPoolManager returns (bytes4, BalanceDelta);

Parameters

NameTypeDescription
senderaddressThe initial msg.sender for the add liquidity call
keyPoolKeyThe key for the pool
paramsModifyLiquidityParamsThe parameters for adding liquidity
deltaBalanceDeltaThe caller's balance delta after adding liquidity; the sum of principal delta, fees accrued, and hook delta
feesAccruedBalanceDeltaThe fees accrued since the last time fees were collected from this position
hookDatabytesArbitrary data handed into the PoolManager by the liquidity provider to be passed on to the hook

Returns

NameTypeDescription
<none>bytes4bytes4 The function selector for the hook
<none>BalanceDeltaBalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency

_afterAddLiquidity

function _afterAddLiquidity(
        address,
        PoolKey calldata,
        ModifyLiquidityParams calldata,
        BalanceDelta,
        BalanceDelta,
        bytes calldata
    ) internal virtual returns (bytes4, BalanceDelta);

Parameters

NameTypeDescription
_address
_PoolKey
_ModifyLiquidityParams
_BalanceDelta
_BalanceDelta
_bytes

Returns

NameTypeDescription
<none>bytes4
<none>BalanceDelta

afterRemoveLiquidity

The hook called after liquidity is removed

function afterRemoveLiquidity(
        address sender,
        PoolKey calldata key,
        ModifyLiquidityParams calldata params,
        BalanceDelta delta,
        BalanceDelta feesAccrued,
        bytes calldata hookData
    ) external onlyPoolManager returns (bytes4, BalanceDelta);

Parameters

NameTypeDescription
senderaddressThe initial msg.sender for the remove liquidity call
keyPoolKeyThe key for the pool
paramsModifyLiquidityParamsThe parameters for removing liquidity
deltaBalanceDeltaThe caller's balance delta after removing liquidity; the sum of principal delta, fees accrued, and hook delta
feesAccruedBalanceDeltaThe fees accrued since the last time fees were collected from this position
hookDatabytesArbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook

Returns

NameTypeDescription
<none>bytes4bytes4 The function selector for the hook
<none>BalanceDeltaBalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency

_afterRemoveLiquidity

function _afterRemoveLiquidity(
        address,
        PoolKey calldata,
        ModifyLiquidityParams calldata,
        BalanceDelta,
        BalanceDelta,
        bytes calldata
    ) internal virtual returns (bytes4, BalanceDelta);

Parameters

NameTypeDescription
_address
_PoolKey
_ModifyLiquidityParams
_BalanceDelta
_BalanceDelta
_bytes

Returns

NameTypeDescription
<none>bytes4
<none>BalanceDelta

beforeSwap

The hook called before a swap

function beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)
        external
        onlyPoolManager
        returns (bytes4, BeforeSwapDelta, uint24);

Parameters

NameTypeDescription
senderaddressThe initial msg.sender for the swap call
keyPoolKeyThe key for the pool
paramsSwapParamsThe parameters for the swap
hookDatabytesArbitrary data handed into the PoolManager by the swapper to be be passed on to the hook

Returns

NameTypeDescription
<none>bytes4bytes4 The function selector for the hook
<none>BeforeSwapDeltaBeforeSwapDelta The hook's delta in specified and unspecified currencies. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
<none>uint24uint24 Optionally override the lp fee, only used if three conditions are met: 1. the Pool has a dynamic fee, 2. the value's 2nd highest bit is set (23rd bit, 0x400000), and 3. the value is less than or equal to the maximum fee (1 million)

_beforeSwap

function _beforeSwap(address, PoolKey calldata, SwapParams calldata, bytes calldata)
        internal
        virtual
        returns (bytes4, BeforeSwapDelta, uint24);

Parameters

NameTypeDescription
_address
_PoolKey
_SwapParams
_bytes

Returns

NameTypeDescription
<none>bytes4
<none>BeforeSwapDelta
<none>uint24

afterSwap

The hook called after a swap

function afterSwap(
        address sender,
        PoolKey calldata key,
        SwapParams calldata params,
        BalanceDelta delta,
        bytes calldata hookData
    ) external onlyPoolManager returns (bytes4, int128);

Parameters

NameTypeDescription
senderaddressThe initial msg.sender for the swap call
keyPoolKeyThe key for the pool
paramsSwapParamsThe parameters for the swap
deltaBalanceDeltaThe amount owed to the caller (positive) or owed to the pool (negative)
hookDatabytesArbitrary data handed into the PoolManager by the swapper to be be passed on to the hook

Returns

NameTypeDescription
<none>bytes4bytes4 The function selector for the hook
<none>int128int128 The hook's delta in unspecified currency. Positive: the hook is owed/took currency, negative: the hook owes/sent currency

_afterSwap

function _afterSwap(address, PoolKey calldata, SwapParams calldata, BalanceDelta, bytes calldata)
        internal
        virtual
        returns (bytes4, int128);

Parameters

NameTypeDescription
_address
_PoolKey
_SwapParams
_BalanceDelta
_bytes

Returns

NameTypeDescription
<none>bytes4
<none>int128

beforeDonate

The hook called before donate

function beforeDonate(
        address sender,
        PoolKey calldata key,
        uint256 amount0,
        uint256 amount1,
        bytes calldata hookData
    ) external onlyPoolManager returns (bytes4);

Parameters

NameTypeDescription
senderaddressThe initial msg.sender for the donate call
keyPoolKeyThe key for the pool
amount0uint256The amount of token0 being donated
amount1uint256The amount of token1 being donated
hookDatabytesArbitrary data handed into the PoolManager by the donor to be be passed on to the hook

Returns

NameTypeDescription
<none>bytes4bytes4 The function selector for the hook

_beforeDonate

function _beforeDonate(address, PoolKey calldata, uint256, uint256, bytes calldata)
        internal
        virtual
        returns (bytes4);

Parameters

NameTypeDescription
_address
_PoolKey
_uint256
_uint256
_bytes

Returns

NameTypeDescription
<none>bytes4

afterDonate

The hook called after donate

function afterDonate(
        address sender,
        PoolKey calldata key,
        uint256 amount0,
        uint256 amount1,
        bytes calldata hookData
    ) external onlyPoolManager returns (bytes4);

Parameters

NameTypeDescription
senderaddressThe initial msg.sender for the donate call
keyPoolKeyThe key for the pool
amount0uint256The amount of token0 being donated
amount1uint256The amount of token1 being donated
hookDatabytesArbitrary data handed into the PoolManager by the donor to be be passed on to the hook

Returns

NameTypeDescription
<none>bytes4bytes4 The function selector for the hook

_afterDonate

function _afterDonate(address, PoolKey calldata, uint256, uint256, bytes calldata)
        internal
        virtual
        returns (bytes4);

Parameters

NameTypeDescription
_address
_PoolKey
_uint256
_uint256
_bytes

Returns

NameTypeDescription
<none>bytes4

Errors

HookNotImplemented

error HookNotImplemented();