Skip to main content
The current pool fee comes from pool_metadata, with PoolState.fee as the fallback for pools without metadata. PoolState.fee remains the creation fee used in the pool key. Changing the current fee leaves that key and the pool’s tick spacing unchanged. Swaps apply any authorized fee reduction before calculating the trading fee. See LP fee entitlements for how this affects earnings. Fees are expressed in parts per million. The bootstrap scripts register 100, 500, 3000, and 10000, corresponding to 0.01 percent, 0.05 percent, 0.30 percent, and 1.00 percent. The contract allows the administrator to register other u16 fee values and bind them to approved tick spacings for pool creation.

Fee split

For each swap step, compute_swap_step returns a fee amount. The program calculates:
fee_protocol may be zero or an integer from 4 through 10. A nonzero setting therefore assigns 4/16 through 10/16 of the trading fee to the protocol.

LP accounting

The LP portion is divided by active liquidity and added to the cumulative fee-growth value for the input token. That cumulative value uses 128 fractional bits in a two-limb wrapping structure. When price crosses an initialized tick, both token fee-growth-outside values are flipped against their corresponding global values. A position’s inside growth is derived from global growth and its two boundary values. Fees become an amount owed when a position settles during increase, decrease, collect, or freeze. The fee_owed helper multiplies the growth delta by position liquidity and shifts out 128 fractional bits.

Protocol accounting

The protocol share accumulates in Slot.protocol_fees0 or Slot.protocol_fees1, depending on swap direction. These values use native token base units. collect_protocol accepts requested native base-unit amounts, verifies that the pool has enough recorded protocol fees, executes public transfers, and subtracts the amounts from the slot. Only the administrator may collect protocol fees. The recipient can be a separate address, but the contract does not enforce a treasury policy or revenue split.

Rounding

Integer arithmetic leaves a fraction below one Q128 unit when fee growth is computed. The implementation discards that sub-Q128 remainder for the step. It is not carried into a later step, which prevents dust earned under one active-liquidity set from being credited after the set changes. Read Q128 fee growth and Fee entitlements before implementing independent fee reconciliation.