The Elastic Fees Concept Explained

A new approach to calculating commissions depending on the price-impact.

Algebra
8 min readNov 18, 2022

Introduction

Swaps with large amounts of crypto on DEXs can cause dramatic price changes, leading to higher risks for liquidity providers and resulting in increased volatility of assets. That is the moment when the idea of changing the approach in which swap commissions are calculated appears, so that higher risks for liquidity providers are compensated by higher fees.

One of the possible solutions is to make the commission size depend on the price-impact or on the price deviation over a certain period of time. In this case, larger swaps will have a higher commission, while smaller swaps will be taxed with lower commission. Hence, there is a need to determine the criterion for the “value” of the swap, as well as the type and form of the commission function.

In order to take into account the proportions of price changes, we should firstly rely on the deviations of the prices’ logarithms, as it allows one to get comparable results for pools with different amounts of liquidity and different initial prices. For liquidity providers, and hence for the commission, it seems to be more important to track how many times the price has changed relative to the previous price, than the absolute value of the change.

Another important subject is the independence of the commission function’s behavior from the splitting of a trade into smaller ones. The case in which traders who split one trade into several smaller trades within one block (or some period of time) pay less commission than traders who make one complete swap, will lead to inefficiency of the commission received, because it generates so-called “unfair” strategies, affecting the commission paid for a trade.

Commission Calculation

Subject to the use of the function of a constant production, aimed at calculating swaps on AMM, the formulas for the relation between price changes and changes in token reserves can be expressed as the following: If x — stands for change in token reserve 0, y — is change in token reserve 1, p — denotes price, and L — liquidity, then:

1
2

In an AMM with concentrated liquidity, the price curve is divided into discrete sections with fixed liquidity, the so- called ticks. The left boundary of each tick i is determined by the formula:

On the other hand, for each price value a tick value can be obtained with this formula:

In practice, for the sake of convenience, the implementation of smart contracts requires the transition to a different kind of formula:

3

Further, for more convenience, we will take into account the division of the tick by two and use the following formula:

4

In this case, formulas (1) and (2) can be expressed in tick formulas, which allows us to tie the commission calculations to the logarithms of prices.

Calculation for the ∆y case

The following transformations can be made when expressing prices through logarithms:

5

This leads us to an expression for the y, that is needed to change the price corresponding to a certain change in the tick t:

6

The value ofy, corresponds to the price shift from a certain tick tm = t0 + mt t, and can be expressed as follows:

7

Hence, the y needed to shift by n t:

8

Formula (8) can be reformulated to find the y, required to shift the price from tick tn d to tn:

9

In this case, the limit transition at t → 0 allows us to go to an integral of the following kind:

10

The obtained formulas (8–10) allow us to complete the calculation of commission, which depends on the deviation of the price tick. The first step towards the final formula can be represented as follows: when each discrete tick crosses, the value of commission changes according to a certain tendency. Then the total number of tokens to be paid in form of commission can be obtained by the following formula:

11

Where φ(x) — is a function, displaying the dependence of the commission on the deviation of the price’s logarithm.

A linear function of the following kind can be used as φ(x):

In this case, the non-constant component of the commission can be obtained as follows:

Which leads us to the following:

After introducing notations:

The final formula can be reduced to such form:

12

Taking into account formula (1), the commission expression can be derived from formula (12) as a multiplier rather than an absolute value:

13

Calculation for the ∆x case

In the case ofx instead ofy the reasoning can be repeated with a few differences. As follows from the formula (2):

From this we can obtain an expression for the x, needed to change the price corresponding to the change in tick t:

Hence, the x needed to shift by n ∆t can be found as follows:

Then the x, required to shift the price from tick tn d to tn can be expressed as:

Which, in the limit, reduces to an integral:

Eventually, the transformations lead to the analog of formula (12):

14

And, accordingly, to the analog of the following formula (13):

15

Practical value of the obtained formulas

The formulas 12, 13, 14, and 15 can be used to calculate the fee, taking into account the set tasks and restrictions. The formulas above have the so-called “integral nature” (which is expressed in continuous change of commission depending on price deviation). It allows us to solve the problem with splitting trades into smaller ones: due to the “additivity feature”, the process of splitting trades does not bring any profit to a trader.

In practice, t0 in formulas can be set equal to a tick at the beginning of a certain block, or to the average tick for the specified time interval. In this case, t1 can be set as a current tick in the pool, and t2 as a final tick, to which the pool will pass once the trade is completed. Hence, the calculated value of the fee will correspond to the price deviation, which is caused by the particular trade. Thanks to that, splitting the trade into smaller ones will not change the amount of commission paid.

On the other hand, the so-called “logarithmic nature” of formulas allows us to calculate the commission equally for different starting and ending prices.

Calculation of commissions for price movements

We should note the fact that the formulas for the commission calculations obtained in the previous section depend on price movement. On the other hand, in the current DEX implementation, the price shift depends on the number of tokens remaining after the commission is withdrawn:

Which is not a problem when using a standard “flat” commission of the following type:

But it makes it much more difficult to obtain the exact solution when substituting formulas 12 and 14, respectively:

Direct analytical solution of these equations is possible, but is also highly energy-consuming and difficult to implement in the EVM smart contract.

On the other hand, neglecting the influence of the commission on the price movement may lead to a significant error in the calculation of the fee itself. That is why it may make practical sense to build an iterative algorithm to find the best solution:

Conclusion

The obtained formulas allow one to calculate the commission, which depends on the price changes and cannot be affected in any way by splitting a trade to smaller ones. The independence from splitting of transactions, mentioned above, can be realized within a single block or within a certain time interval. In addition, the present function is independent of the absolute price change, which leads to comparable behavior under different liquidity amounts and prices of assets.

Nevertheless, obtaining accurate values can lead to a complication of the smart contracts code and make it difficult to determine the commission prior to the direct completion of a swap.

About Algebra

Algebra is a breakthrough AMM, and a concentrated liquidity protocol for decentralized exchanges, running on adaptive fees. Providing projects with more user-friendly, fresh solutions and implementing the most efficient technologies, it reforms the DeFi field as we know it.

Telegram | Twitter | Discord | YouTube

--

--

Algebra

Algebra is a breakthrough AMM, and a concentrated liquidity protocol for decentralized exchanges, running on adaptive fees.