Skip to main content

BaseHook

Git Source - Generated with forge doc

Inherits: IHooks, ImmutableState

abstract contract for hook implementations

Functions

constructor

constructor(IPoolManager _manager) ImmutableState(_manager);

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);

validateHookAddress

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

this function is virtual so that we can override it during testing, which allows us to deploy an implementation to any address and then etch the bytecode into the correct address

function validateHookAddress(BaseHook _this) internal pure virtual;

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);

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);

beforeAddLiquidity

The hook called before liquidity is added

function beforeAddLiquidity(
address sender,
PoolKey calldata key,
IPoolManager.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
paramsIPoolManager.ModifyLiquidityParamsThe 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, IPoolManager.ModifyLiquidityParams calldata, bytes calldata)
internal
virtual
returns (bytes4);

beforeRemoveLiquidity

The hook called before liquidity is removed

function beforeRemoveLiquidity(
address sender,
PoolKey calldata key,
IPoolManager.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
paramsIPoolManager.ModifyLiquidityParamsThe 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, IPoolManager.ModifyLiquidityParams calldata, bytes calldata)
internal
virtual
returns (bytes4);

afterAddLiquidity

The hook called after liquidity is added

function afterAddLiquidity(
address sender,
PoolKey calldata key,
IPoolManager.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
paramsIPoolManager.ModifyLiquidityParamsThe 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,
IPoolManager.ModifyLiquidityParams calldata,
BalanceDelta,
BalanceDelta,
bytes calldata
) internal virtual returns (bytes4, BalanceDelta);

afterRemoveLiquidity

The hook called after liquidity is removed

function afterRemoveLiquidity(
address sender,
PoolKey calldata key,
IPoolManager.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
paramsIPoolManager.ModifyLiquidityParamsThe 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,
IPoolManager.ModifyLiquidityParams calldata,
BalanceDelta,
BalanceDelta,
bytes calldata
) internal virtual returns (bytes4, BalanceDelta);

beforeSwap

The hook called before a swap

function beforeSwap(
address sender,
PoolKey calldata key,
IPoolManager.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
paramsIPoolManager.SwapParamsThe 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, IPoolManager.SwapParams calldata, bytes calldata)
internal
virtual
returns (bytes4, BeforeSwapDelta, uint24);

afterSwap

The hook called after a swap

function afterSwap(
address sender,
PoolKey calldata key,
IPoolManager.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
paramsIPoolManager.SwapParamsThe 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, IPoolManager.SwapParams calldata, BalanceDelta, bytes calldata)
internal
virtual
returns (bytes4, 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);

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);

Errors

HookNotImplemented

error HookNotImplemented();