Skip to content

docs: align Infinity hook code examples with CLBaseHook pattern (2026-04-20) — high-risk#80

Open
chef-eric wants to merge 1 commit into
masterfrom
doc-sync/2026-04-20-hooks-reviewed
Open

docs: align Infinity hook code examples with CLBaseHook pattern (2026-04-20) — high-risk#80
chef-eric wants to merge 1 commit into
masterfrom
doc-sync/2026-04-20-hooks-reviewed

Conversation

@chef-eric
Copy link
Copy Markdown
Contributor

Documentation Sync — 2026-04-20 (high-risk, needs review)

Force-rescan of Infinity hook code examples with a deeper manual verification pass. Supersedes closed PR #79 (which only caught the struct field names).

Drift found

The inline code examples in several hook pages diverged from two canonical sources in the same doc-site: the snippet files in docs/snippets/ (which the same pages reference as "complete source code") and CLBaseHook.sol in the infinity-hooks-template repo.

1. Permissions struct field names — ReturnsDeltaReturnDelta

The struct members in CLBaseHook.Permissions are singular: beforeSwapReturnDelta, afterSwapReturnDelta, afterAddLiquidityReturnDelta, afterRemoveLiquidityReturnDelta. Only the bitmap OFFSET constants (e.g. HOOKS_BEFORE_SWAP_RETURNS_DELTA_OFFSET) are plural. A developer copying the struct literal from the doc would hit "Member not found" at compile time.

Affected:

  • guides/develop-a-hook.mdx lines 122–125 (VeCakeSwapDiscountHook)
  • overview/custom-layer-hook.mdx lines 36–39 and 75–78
  • guides/hook-examples/overwriting-amm-curve.mdx line 32 (inline code reference)
  • guides/hook-examples/taking-fee-via-hook.mdx line 42 (inline code reference)

2. Hook override pattern — external override poolManagerOnlyinternal override

CLBaseHook exposes the external functions (beforeSwap, _beforeAddLiquidity's wrapper, etc.) and delegates to internal virtual methods named with an underscore (_beforeSwap, _beforeAddLiquidity, …). User hooks override the internal methods; the base handles the poolManagerOnly check.

The inline examples instead showed function beforeSwap(...) external override poolManagerOnly / function afterRemoveLiquidity(...) external override poolManagerOnly / function _beforeAddLiquidity(...) external override poolManagerOnly, which doesn't match the snippet files the same pages cite. _beforeAddLiquidity external in particular is a compile error against the base's internal virtual declaration.

Rewrote to:

function _beforeAddLiquidity(...) internal override returns (bytes4) { ... }
function _beforeSwap(...)         internal view override returns (bytes4, BeforeSwapDelta, uint24) { ... }
function _afterRemoveLiquidity(...) internal override returns (bytes4, BalanceDelta) { ... }

Affected:

  • guides/develop-a-hook.mdx lines 58–62 (CLCounterHook example)
  • guides/develop-a-hook.mdx lines 153–165 (VeCakeSwapDiscountHook beforeSwap)
  • guides/hook-examples/taking-fee-via-hook.mdx lines 24–31 (afterRemoveLiquidity)

Source verification

Other things verified (no drift)

  • Interface function signatures in custom-layer-hook.mdx for beforeSwap/afterSwap/afterAddLiquidity/afterRemoveLiquidity (lines 88–92, 125–128, 155–158, 170–173) — all match ICLHooks.sol.
  • LPFeeLibrary.DYNAMIC_FEE_FLAG (0x800000) and OVERRIDE_FEE_FLAG (0x400000) — exist in infinity-core.
  • BeforeSwapDeltaLibrary.ZERO_DELTA — exists.
  • PoolKey struct fields — match src/types/PoolKey.sol.
  • User-doc pages (trade/pancakeswap-infinity/hooks/README.md, hooks/dynamic-fee-hook.md) — prose-only, no code drift.

Auto-generated by doc-sync agent. Merge to apply; close to reject; comment to request changes. @cheferic @chef-miso please review.

…-04-20)

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) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pancake-developer Ready Ready Preview, Comment Apr 20, 2026 9:43am

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant