Fee accounting
Last modified:
CenturionDEX v3 charges a fee on the input token of each trade. The contract may also specify a protocol fee, namely a fixed fraction of the trading fee retained by the protocol rather than distributed to liquidity providers. This parameter is fixed at pool creation.
For clarity, we assume throughout this section that the protocol fee is zero. This assumption does not affect the structure of the accounting rules; it only removes one layer of proportional rescaling from the fee-growth variables.
To determine the fees earned by an individual position, it is useful to decompose cumulative fee growth relative to each boundary tick.
Fee growth above and below a tick
Let be an initialized tick index, and let . We define:
- : cumulative fee growth per unit liquidity above tick , that is, over the interval
- : cumulative fee growth per unit liquidity below tick , that is, over the interval
Because stores the fee growth in the outer interval, the values of and depend on the relative position of the current price with respect to tick . Specifically,
and
These formulas are the basic bridge between global fee accounting and position-level fee accounting.
For a position with lower/upper boundary ticks , the fee growth inside the position range is
Example (Evolution of fee-accounting variables)
Consider a CenturionDEX v3 pool with initialized ticks
and focus on the fee-accounting variables associated with the middle tick . We track the global fee-growth variables
and the tick-level quantities
where denotes the tick index of .
Assume that the pool begins with the current price below , and that the following sequence of events occurs:
- a trade below generates units of fee growth in token ;
- the price crosses upward;
- a trade above generates units of fee growth in token ;
- another trade above generates units of fee growth in token ;
- the price crosses downward;
- a trade below generates units of fee growth in token .
The resulting evolution of the variables is shown in the table below.
Table. Example of updates of , , , and for
| Step | Price location | Collected fee | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Initial state | below | - | ||||||||
| Trade 1 | below | |||||||||
| Tick cross | above | - | ||||||||
| Trade 2 | above | |||||||||
| Trade 3 | above | |||||||||
| Tick cross | below | - | ||||||||
| Trade 4 | below |
This table illustrates the logic of the bookkeeping:
- the global variables and increase whenever fees are collected;
- the outside-fee variables and change only when the price crosses the tracked tick;
- the above-fee and below-fee quantities are then recovered from the global and outside values according to the piecewise formulas stated above.
These variables are the ingredients from which the fee growth inside a position range is subsequently computed, and therefore they form the core of the position-level fee-accounting mechanism in CenturionDEX v3.