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 () as the pool becomes unbalanced.
During Dynamic Swap Pricing, instead of quoting trades using the invariant (calculated with the primary reserves in the contract ignoring the lent out and ) 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, and , prior to calculating .
In the typical invariant , As or approaches zero, the cost to buy the other asset goes up. In our case, we accelerate the rate at which or approaches zero once only some buffer (5%) of what should be there remains.
In the case that asset is depleting we modify the value being used in . Let be the virtual reserves, the quantity that would be in the pool if there was nothing being lent. Let be the quality of the asset that is missing due to lending. Let B be the buffer (95%) of assets remaining of , and be the adjusted value of passed to our invariant function .
To show this by example take a look at the Desmos chart showing in green.
This essentially creates a premium for the asset that is depleting. There is no quantity of or 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 .
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.