From 1d081c60416d90342f0f6072d0a6dc05f4faf1a6 Mon Sep 17 00:00:00 2001 From: ChefEric <173023571+chef-eric@users.noreply.github.com> Date: Mon, 20 Apr 2026 17:42:38 +0800 Subject: [PATCH] docs: align Infinity hook code examples with CLBaseHook pattern (2026-04-20) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deep-pass rescan of hook code examples. Inline examples in the doc pages diverged from the snippet files in docs/snippets/ and from CLBaseHook in the infinity-hooks-template repo. Four files updated: 1. Permissions struct field names: `beforeSwapReturnsDelta` (and the three siblings) → `beforeSwapReturnDelta`. The struct members in CLBaseHook are singular; only the bitmap OFFSET constants are plural. Affected: develop-a-hook.mdx, custom-layer-hook.mdx, overwriting-amm-curve.mdx, taking-fee-via-hook.mdx. 2. Hook method override visibility: examples showed `function beforeSwap(...) external override poolManagerOnly` (and likewise for _beforeAddLiquidity, afterRemoveLiquidity). The template pattern has `beforeSwap` as the external wrapper and `_beforeSwap` as the internal virtual that user hooks override. Updated to `function _beforeSwap(...) internal override` to match the canonical snippet files (VeCakeSwapDiscountHook.sol, LiquidityRemovalFeeHook.sol) that the same pages reference as "complete source code". Sources: - infinity-hooks-template/src/pool-cl/CLBaseHook.sol (struct Permissions and external/internal pattern) - infinity-hooks-template/src/pool-cl/CLCounterHook.sol - docs/snippets/VeCakeSwapDiscountHook.sol - docs/snippets/LiquidityRemovalFeeHook.sol Co-Authored-By: Claude Opus 4.7 (1M context) --- .../contracts/infinity/guides/develop-a-hook.mdx | 14 +++++++------- .../hook-examples/overwriting-amm-curve.mdx | 2 +- .../guides/hook-examples/taking-fee-via-hook.mdx | 6 +++--- .../infinity/overview/custom-layer-hook.mdx | 16 ++++++++-------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/pages/contracts/infinity/guides/develop-a-hook.mdx b/docs/pages/contracts/infinity/guides/develop-a-hook.mdx index ab112de..34780b4 100644 --- a/docs/pages/contracts/infinity/guides/develop-a-hook.mdx +++ b/docs/pages/contracts/infinity/guides/develop-a-hook.mdx @@ -56,7 +56,7 @@ contract CLCounterHook is CLBaseHook { // 2. For each callback required, overwrite the method function _beforeAddLiquidity(address, PoolKey calldata key, ICLPoolManager.ModifyLiquidityParams calldata, bytes calldata) - external override poolManagerOnly returns (bytes4) { + internal override returns (bytes4) { // implement hook logic and then return selector return this.beforeAddLiquidity.selector; } @@ -119,10 +119,10 @@ contract VeCakeSwapDiscountHook is CLBaseHook { // [!code focus] afterSwap: false, beforeDonate: false, afterDonate: false, - beforeSwapReturnsDelta: false, - afterSwapReturnsDelta: false, - afterAddLiquidityReturnsDelta: false, - afterRemoveLiquidityReturnsDelta: false + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false }) ); } @@ -151,8 +151,8 @@ function setLpFee(PoolKey calldata key, uint24 lpFee) external { Note the return value need to include `LPFeeLibrary.OVERRIDE_FEE_FLAG` so pool manager knows the intention is to override swap fee. ```solidity -function beforeSwap(address, PoolKey calldata key, ICLPoolManager.SwapParams calldata, bytes calldata) - external view override poolManagerOnly returns (bytes4, BeforeSwapDelta, uint24) +function _beforeSwap(address, PoolKey calldata key, ICLPoolManager.SwapParams calldata, bytes calldata) + internal view override returns (bytes4, BeforeSwapDelta, uint24) { uint24 lpFee = poolIdToLpFee[key.toId()]; diff --git a/docs/pages/contracts/infinity/guides/hook-examples/overwriting-amm-curve.mdx b/docs/pages/contracts/infinity/guides/hook-examples/overwriting-amm-curve.mdx index 1b4d43a..b8413bd 100644 --- a/docs/pages/contracts/infinity/guides/hook-examples/overwriting-amm-curve.mdx +++ b/docs/pages/contracts/infinity/guides/hook-examples/overwriting-amm-curve.mdx @@ -29,7 +29,7 @@ For example if the user swap `exactIn 100 token0 for token1` with `-100 amountSp Take note of -1. The hook permission which includes `beforeSwapReturnsDelta` as the hook modify the delta in beforeSwap. +1. The hook permission which includes `beforeSwapReturnDelta` as the hook modify the delta in beforeSwap. 2. How the hook take/settle the currency and the BeforeSwapDelta returned.
diff --git a/docs/pages/contracts/infinity/guides/hook-examples/taking-fee-via-hook.mdx b/docs/pages/contracts/infinity/guides/hook-examples/taking-fee-via-hook.mdx index 310adc9..ba00a87 100644 --- a/docs/pages/contracts/infinity/guides/hook-examples/taking-fee-via-hook.mdx +++ b/docs/pages/contracts/infinity/guides/hook-examples/taking-fee-via-hook.mdx @@ -21,14 +21,14 @@ In the `afterRemoveLiquidity()` callback, we calculate the fee based on the amou ```solidity /// @param delta The caller's balance delta after removing liquidity; the sum of principal delta, fees accrued, and hook delta -function afterRemoveLiquidity +function _afterRemoveLiquidity (address sender, PoolKey calldata key, ICLPoolManager.ModifyLiquidityParams calldata params, BalanceDelta delta, BalanceDelta feesAccrued, bytes calldata hookData -) external override poolManagerOnly returns (bytes4, BalanceDelta) { +) internal override returns (bytes4, BalanceDelta) { // calculate how much fee uint128 amt0Fee = uint128(delta.amount0()) / 10; @@ -39,7 +39,7 @@ function afterRemoveLiquidity Take note of -1. The hook permission which includes `afterRemoveLiquidityReturnsDelta` as the hook modify the delta in afterRemoveLiquidity(). +1. The hook permission which includes `afterRemoveLiquidityReturnDelta` as the hook modify the delta in afterRemoveLiquidity().
View complete source code here diff --git a/docs/pages/contracts/infinity/overview/custom-layer-hook.mdx b/docs/pages/contracts/infinity/overview/custom-layer-hook.mdx index 98e9cc5..c72c9d9 100644 --- a/docs/pages/contracts/infinity/overview/custom-layer-hook.mdx +++ b/docs/pages/contracts/infinity/overview/custom-layer-hook.mdx @@ -33,10 +33,10 @@ function getHooksRegistrationBitmap() external pure override returns (uint16) { afterDonate: false, // Hook return delta (documented below) - beforeSwapReturnsDelta: false, - afterSwapReturnsDelta: false, - afterAddLiquidityReturnsDelta: false, - afterRemoveLiquidityReturnsDelta: false + beforeSwapReturnDelta: false, + afterSwapReturnDelta: false, + afterAddLiquidityReturnDelta: false, + afterRemoveLiquidityReturnDelta: false }) ); } @@ -72,10 +72,10 @@ function getHooksRegistrationBitmap() external pure override returns (uint16) { Permissions({ // The 4 permissions around modifying return delta - beforeSwapReturnsDelta: false, // during beforeSwap - afterSwapReturnsDelta: false, // during afterSwap - afterAddLiquidityReturnsDelta: false, // during afterAddLiquidity - afterRemoveLiquidityReturnsDelta: false // during afterRemoveLiquidity + beforeSwapReturnDelta: false, // during beforeSwap + afterSwapReturnDelta: false, // during afterSwap + afterAddLiquidityReturnDelta: false, // during afterAddLiquidity + afterRemoveLiquidityReturnDelta: false // during afterRemoveLiquidity }) ); }