Dynamic fees
Most AMMs charge a flat fee on every swap. ClearPortX instead charges a two-component fee: a fixed base fee plus a variable dynamic fee that grows with realized volatility. This page explains the mechanism and the math.
Why dynamic fees
Section titled “Why dynamic fees”Canton structurally prevents MEV, so the usual motivation for dynamic fees — penalizing sandwich attacks — does not apply here. Instead, ClearPortX uses dynamic fees for a different reason: LP income optimization.
During periods of high volatility, liquidity providers bear more impermanent loss. A larger fee during turbulent periods compensates them for that risk and keeps them willing to provide depth when it is most needed. During calm periods, the variable fee drops to near zero and trading is cheap.
The formula
Section titled “The formula”The total fee rate on a swap is:
The base fee is a constant set at pool creation:
The variable fee scales with the square of the volatility accumulator:
where s is the bin step, v_a is the volatility accumulator, C is a control parameter, and K is a normalization constant. Because the expression is quadratic, small movements produce small fees and large movements produce disproportionately larger fees.
The volatility accumulator
Section titled “The volatility accumulator”The volatility accumulator has two components — a persistent reference that decays between swaps, and an instantaneous value computed during each swap:
Between swaps, the reference v_r decays based on elapsed time. If more than the decay period has passed, it resets to zero. During a swap crossing k bins, the accumulator grows linearly with k — which means the quadratic variable fee grows with k².
Full pseudocode and test vectors are documented in Developers · SDK.