Appearance
Solidity API
BaseHook
abstract contract for hook implementations
NotSelf
solidity
error NotSelf()InvalidPool
solidity
error InvalidPool()LockFailure
solidity
error LockFailure()HookNotImplemented
solidity
error HookNotImplemented()selfOnly
solidity
modifier selfOnly()Only this address may call this function
onlyValidPools
solidity
modifier onlyValidPools(contract IHooks hooks)Only pools with hooks set to this contract may call this function
getHookPermissions
solidity
function getHookPermissions() public pure virtual returns (struct Hooks.Permissions)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
validateHookAddress
solidity
function validateHookAddress(contract BaseHook _this) internal pure virtualValidates 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
_unlockCallback
solidity
function _unlockCallback(bytes data) internal virtual returns (bytes)beforeInitialize
solidity
function beforeInitialize(address, struct PoolKey, uint160) external virtual returns (bytes4)The hook called before the state of a pool is initialized
Parameters
| Name | Type | Description |
|---|---|---|
| address | ||
| struct PoolKey | ||
| uint160 |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | bytes4 | bytes4 The function selector for the hook |
afterInitialize
solidity
function afterInitialize(address, struct PoolKey, uint160, int24) external virtual returns (bytes4)The hook called after the state of a pool is initialized
Parameters
| Name | Type | Description |
|---|---|---|
| address | ||
| struct PoolKey | ||
| uint160 | ||
| int24 |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | bytes4 | bytes4 The function selector for the hook |
beforeAddLiquidity
solidity
function beforeAddLiquidity(address, struct PoolKey, struct IPoolManager.ModifyLiquidityParams, bytes) external virtual returns (bytes4)The hook called before liquidity is added
Parameters
| Name | Type | Description |
|---|---|---|
| address | ||
| struct PoolKey | ||
| struct IPoolManager.ModifyLiquidityParams | ||
| bytes |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | bytes4 | bytes4 The function selector for the hook |
beforeRemoveLiquidity
solidity
function beforeRemoveLiquidity(address, struct PoolKey, struct IPoolManager.ModifyLiquidityParams, bytes) external virtual returns (bytes4)The hook called before liquidity is removed
Parameters
| Name | Type | Description |
|---|---|---|
| address | ||
| struct PoolKey | ||
| struct IPoolManager.ModifyLiquidityParams | ||
| bytes |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | bytes4 | bytes4 The function selector for the hook |
afterAddLiquidity
solidity
function afterAddLiquidity(address, struct PoolKey, struct IPoolManager.ModifyLiquidityParams, BalanceDelta, BalanceDelta, bytes) external virtual returns (bytes4, BalanceDelta)The hook called after liquidity is added
Parameters
| Name | Type | Description |
|---|---|---|
| address | ||
| struct PoolKey | ||
| struct IPoolManager.ModifyLiquidityParams | ||
| BalanceDelta | ||
| BalanceDelta | ||
| bytes |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | bytes4 | bytes4 The function selector for the hook |
| [1] | BalanceDelta | BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency |
afterRemoveLiquidity
solidity
function afterRemoveLiquidity(address, struct PoolKey, struct IPoolManager.ModifyLiquidityParams, BalanceDelta, BalanceDelta, bytes) external virtual returns (bytes4, BalanceDelta)The hook called after liquidity is removed
Parameters
| Name | Type | Description |
|---|---|---|
| address | ||
| struct PoolKey | ||
| struct IPoolManager.ModifyLiquidityParams | ||
| BalanceDelta | ||
| BalanceDelta | ||
| bytes |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | bytes4 | bytes4 The function selector for the hook |
| [1] | BalanceDelta | BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency |
beforeSwap
solidity
function beforeSwap(address, struct PoolKey, struct IPoolManager.SwapParams, bytes) external virtual returns (bytes4, BeforeSwapDelta, uint24)The hook called before a swap
Parameters
| Name | Type | Description |
|---|---|---|
| address | ||
| struct PoolKey | ||
| struct IPoolManager.SwapParams | ||
| bytes |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | bytes4 | bytes4 The function selector for the hook |
| [1] | BeforeSwapDelta | BeforeSwapDelta The hook's delta in specified and unspecified currencies. Positive: the hook is owed/took currency, negative: the hook owes/sent currency |
| [2] | uint24 | uint24 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) |
afterSwap
solidity
function afterSwap(address, struct PoolKey, struct IPoolManager.SwapParams, BalanceDelta, bytes) external virtual returns (bytes4, int128)The hook called after a swap
Parameters
| Name | Type | Description |
|---|---|---|
| address | ||
| struct PoolKey | ||
| struct IPoolManager.SwapParams | ||
| BalanceDelta | ||
| bytes |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | bytes4 | bytes4 The function selector for the hook |
| [1] | int128 | int128 The hook's delta in unspecified currency. Positive: the hook is owed/took currency, negative: the hook owes/sent currency |
beforeDonate
solidity
function beforeDonate(address, struct PoolKey, uint256, uint256, bytes) external virtual returns (bytes4)The hook called before donate
Parameters
| Name | Type | Description |
|---|---|---|
| address | ||
| struct PoolKey | ||
| uint256 | ||
| uint256 | ||
| bytes |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | bytes4 | bytes4 The function selector for the hook |
afterDonate
solidity
function afterDonate(address, struct PoolKey, uint256, uint256, bytes) external virtual returns (bytes4)The hook called after donate
Parameters
| Name | Type | Description |
|---|---|---|
| address | ||
| struct PoolKey | ||
| uint256 | ||
| uint256 | ||
| bytes |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | bytes4 | bytes4 The function selector for the hook |