Skip to main content

Dynamic Swap Pricing

Once 90% of reserves have been lent out, Dynamic Swap Pricing will kick in to start to add a premium to trades taking the scarce liquidity and a discount for those bringing it. This essentially puts a throttle on swap transactions depleting the threatened assets. These adjustments start small and gradually increase as the health of the liquidity deteriorates. You can think of the adjustment to the invariant curves behavior similar to how Curve handles the depletion of assets as the stable invariant (x+y=kx+y = k) as the pool becomes unbalanced.

During Dynamic Swap Pricing, instead of quoting trades using the invariant KK (calculated with the primary reserves in the contract ignoring the lent out XX and YY) the calculation of the invariant would be adjusted to add a premium or discount to swaps. This premium would increase as the health of the reserves deplete. This can be achieved by modifying the inputs, XX and YY, prior to calculating KK.

In the typical invariant XY=KX \cdot Y = K, As XX or YY approaches zero, the cost to buy the other asset goes up. In our case, we accelerate the rate at which XX or YY approaches zero once only some buffer (5%) of what should be there remains.

In the case that asset XX is depleting we modify the value being used in XY=KX\cdot Y=K. Let XX be the virtual reserves, the quantity that would be in the pool if there was nothing being lent. Let XMX_M be the quality of the asset that is missing due to lending. Let B be the buffer (95%) of assets remaining of XX, and XAX_A be the adjusted value of XX passed to our invariant function XY=KX \cdot Y=K .

XA={Xif XMBXkBYMXXM1Bif XM<X<XMBX(1B)+YMXkif kBYM<X\begin{equation*} X_A = \begin{cases} X & \text{if } \frac{X_M}{B} & \le X & \le \frac{k \cdot B}{Y_M} \\ \frac{X - X_M}{1-B} & \text {if } X_M & < X & < \frac{X_M}{B} \\ \frac{X}{(1-B) + \frac{Y_M\cdot X}{k}} & \text{if } \frac{k \cdot B}{Y_M} & < X \end{cases} \end{equation*}

To show this by example take a look at the Desmos chart showing YXA=kY \cdot X_A = k in green.

This essentially creates a premium for the asset that is depleting. There is no quantity of XX or YY that could be swapped to take all of the liquidity out of the contract. Similarly, a discount is given to swaps that bring in the asset that is at risk of being depleted by reversing the order of the calculations.

With Dynamic Swap Pricing, backup reserves can never be completely depleted without the rate of exchange effectively reaching 0 or \infty.

To see what this would look like in practice, let's consider the ETH-USDC Uniswap v2 pair contract. At time of writing it held 59,589,000 USDC and 36,852 ETH. Consider the case where 90% of ETH has been lent out.

Traders will not make these trades unless the swap with the premium is at or below the external market rate. As such, Swap sizes and volume will likely be far lower than that of our competitors when reserve health is low. But the goal in a death spiral is not to have the highest swap volume, it's to have protect our novel financial primitive from exploding. It is hard to imagine a market scenario that could sustain the deteriorated state of the reserves for an extended period of time. The outstanding loan principal of the scarce asset would be both appreciating in value and costing double and triple percentages annualized. At the same time, the collateral would be depreciating. Loans would be forced to be repaid or liquidated. All of these factors persisting long term, although possible, don't seem probable. But if crypto has taught us anything, the most unimaginably strange things can occur in the market. If the unimaginable did occur, this design would still still be able to fill swaps, even when -j order book became a ghost town and the Uniswap V3 pair got stuck.