1. Background
In Staple's pricing mechanism, the oracle price serves as the basis for determining the trading rate of a token pair, which is then adjusted by the parameter on the price adjustment curve. When the oracle price remains unchanged, the trading price is entirely dependent on - a higher leads to a lower trading price.
However, any of the following actions: liquidity allocation, liquidity deallocation, and swapping in a Virtual Trading Pair (VTP), can alter the value of the VTP (as described in Towards Capital Efficiency - Staple's LP Architecture and Mechanism), thereby affecting the swap price for subsequent transactions. As a result, through actions like liquidity allocation or deallocation, a trader can to some extent control the parameter of a VTP, creating opportunities for arbitrage profit by exploiting these price variations.
In specific, the following operations could give rise to an arbitrage opportunity that is detrimental to LP's assets:
-
A trader swaps for to move up .
-
The trader then allocates liquidity to or deallocates liquidity from the same VTP, driving even higher.
-
The same trader swaps the same amount of he received in step 1 back to .
Notice:
-
Without step 2, the trader should get in step 3 the exact amount of he spent in step 1 (See Staple's Pricing Mechanism).
-
In step 2, moving upwards results in a lower trading price for to and, conversely, a higher trading price for the trading direction from to . This increased price ratio of to enables the trader to swap back more than what was spent in step 1, leading to an arbitrage profit at the expense of the LP's assets.
With the same definition as in "Staple's Pricing Mechanism":
-
The asset liabity ratio of ;
-
The asset liabity ratio of ,
We clarify the four allocation and deallocation patterns that result in a higher , potentially creating arbitrage opportunities that can be detrimental to LP assets in the aforementioned step 2.
-
, Deallocate
eg. , deallocate 100 , goes up.
-
, Allocate
eg. , allocate 100 , goes up.
-
, Allocate
eg. , allocate 100 , goes down.
-
, Deallocate
eg. , deallocate 100 , goes down.
To prevent the harmful arbitrages described above, fees should be applied to liquidity allocation and deallocation. These fees are charged on LPs when is within a certain range (), beyond which LPs are exempt from the fees. However, transactions conducted outside this range will incur an additional price penalty.
It's important to note that the example provided above only considers the trading direction from to . In the opposite trading direction, there are equivalent allocation and deallocation patterns that will increase , and fees will also be charged for these actions. As a result, fees are applied to any allocation or deallocation action, regardless of the trading direction.
- , Deallocate
- , Allocate
- , Allocate
- , Deallocate
For the sake of simplicity in the following analysis, we will focus on the trading direction from to .
2. Definition & Pre-calculation
-
The amount of liability of .
-
The amount of liability of .
-
The amount of asset of .
-
The amount of asset of .
-
The asset liabity ratio of .
-
The asset liabity ratio of .
-
The oracle price of .
-
The oracle price of .
-
The ratio of the asset
liability ratios: to . -
The ratio of
the asset liability ratios: to . -
The adjusted starting price from to
before a transaction takes place - oracle price adjusted
by the current . -
The adjusted starting price from to
before a transaction takes place - oracle price adjusted
by the current . -
The adjusted end price from to
when a transaction is finished. -
The adjusted end price from to
when a transaction is finished. -
The average trading price of this transaction
from to - - is the weighted average
between and . -
The trading price of a transaction from to
. -
an ' is superscripted to a parameter to denote the new status of this parameter following a transaction
In line with the price calculation derived in Staple's Pricing Mechanism, the table below demonstrates the arbitrage process:
start | step 1 | step 2 | step 3 | |
---|---|---|---|---|
swap to | (de)allocate | swap to | ||
or | ||||
swap price | ||||
To symplify the calculation, we further define the parameter :
-
is the product of trading prices of step 1 and step 3 defined in the above table. (De)allocation fee applies only if , which indicates profit is gained from the above arbitrage.
-
Arbitrage earning rate - the earning rate of (de)allocating or during the above arbitrage, assuming a swap of was initiated.
A trader will benefit from the above arbitrage. Therefore
To discourage the harmful arbitrage, the (de)allocation fee should be charged in a way to cancel out . Therefore, to calculate the (de)allocation fee, we need to express the maximal value of in known parameters. Since the starting point of (de)allocation in the above arbitrage is when a swap of is finished, the maximal value of should be expressed with the known parameters at the point the swap is finished. Below we list the relation for some parameters before and after the swap to ease the calculation of (de)allocation fees.
- Liability:
- Assets:
- RAS: (See Reasonable Swap Amount for details.)
Before we get into the calculation of (de)allocation fees, we express , and in terms of ratio of asset-liability ratios to ease the subsequent calculation.
3. Fee Calculation for the 4 (de)allocation patterns
The fees are only needed when the transactions take place within the first segment of the price adjustment curve, beyond which price penalty will turn the arbitrage invalid. Therefore the following condition holds:
Within the range of (see Reasonable Swap Amount for details), the (de)allocation fee is typically in the range of 0.0001% - 0.02% of the amount of token to sell, depending on how close the current is to . Note that in the following calculation, all the (de)allocation charge is expressed in the amount of the token to be (de)allocated.
3.1 , Deallocate