Skip to content

Pool lifecycle hooks

Attach bounded policies to a pool without handing over token settlement.

A grapl pool can bind one hook program and an explicit set of callbacks. The core validates the operation, invokes enabled callbacks, and retains control of CLMM accounting and token transfers. A hook may serve several pools with separate configuration.

Pools also work without a hook: bitmap 0 and the System Program sentinel. Allowlist, dynamic-fee schedule, trading-window, lifecycle, and rewards programs are optional examples in examples/hooks; none is a default policy or requirement of the core library/program. Universal account and accounting checks still apply to no-hook pools.

The Hooks section covers policy configuration, authentication, and composition. Start with Design your first hook to select a responsibility and implement the callback contract.

Five operation pairs

The current core dispatches before/after callbacks for initialize, add liquidity, remove liquidity, swap, and donate. The callback catalog specifies all ten phases and the exact state/amounts they see.

Opening or closing a position and collecting fees have no callbacks. Curve graduation uses BeforeAddLiquidity and AfterAddLiquidity around the creation of the bootstrap CLMM position; it has no separate callback pair. Custom accounting and return-delta permissions reject.

Bound policy and authority

PolicyOnly permits a decision; DynamicFee also requires a bounded fee from BeforeSwap. Only the core's pool-scoped callback PDA signs the hook CPI. The pool stays read-only. Extra accounts have explicit owner/class checks and per-phase read/write ceilings; the hook never receives the actor's signer privilege or vault authority.

HookInvocation.actor is trusted only through that authenticated core call. It identifies the authority validated by the core, which may be a PDA in a routed context; it is not universal proof of the original human wallet. See authentication.

Compose rules inside one hook

One selected program can combine eligibility, fee decisions, reward issuance, and its own state. The core provides typed operation context and bounded account access; rule order and economics belong to that program. Stateful effects remain provisional until the whole transaction succeeds. The reward example builds on settled output and optional gates without making those rules mandatory for other pools.

Scope and governance

A pool hook affects operations in its bound pool. A Token-2022 transfer hook is invoked by a token program for a mint's transfers. Implementing a pool policy does not restrict transfers or other venues.

A fixed program address does not make upgradeable code immutable. Hook/core upgrade authorities are separate governance decisions. A removal hook can reject withdrawals, and no emergency escape is implemented. The three economic examples enable only BeforeSwap; the lifecycle probe exercises the broader phase set.

Continue with permissions, configuration and bootstrap, and the ABI reference.