Liquidation mechanism

If the value of the collateral associated with a user's Loan Module experiences a significant decline and the user fails to timely settle interest payments or bolster collateral funds, triggering a drop below the stipulated minimum pledge rate, Keepers have the authority to submit a liquidation request to the Loan Module []. Keepers simply need to adhere to the liquidation amount broadcasted by the Insurance Module, along with the corresponding Module's address. They can then execute a direct transfer to this address. Upon consensus agreement from the Indexer, the Module undergoes unlocking, transforming into a White Module. Subsequently, the Keeper initiates a withdrawal request, securing the escalated collateral. The clearing fee, configured within the Insurance contract script by the Yala Foundation, presents an opportunity for Keepers to acquire collateral at a discounted rate, capitalizing on arbitrage gains.

AMM for liquidation

Facing the high volatility of the BTC market, we explored ways to mitigate borrowers' losses when asset depreciation triggers liquidation.

The Auto Market Maker[@], widely adopted in decentralized exchanges (DEX), offers a solution by automatically setting buy and sell prices through basic algorithms, functioning like an automated trader. This innovation addresses the cost and efficiency challenges of transitioning from traditional exchanges to DEXs, facilitating seamless, unauthorized, and decentralized trading of digital assets.

Curve's novel approach employs a reverse AMM within their latest protocol, Curve Stablecoin[] , to tackle liquidation more effectively than traditional stablecoin or lending protocols like MakerDAO, Liquity, and Compound. By leveraging its AMM, Curve stablecoin enhances liquidation efficiency, significantly lowering the risk of accruing bad debts. Furthermore, the AMM aids in absorbing liquidated assets, thereby dampening market volatility induced by mass asset sales. This represents a key advancement over older stablecoin and lending models, offering a more resilient solution to liquidation challenges.

Under the BRC-20 modular protocol, there are several issues to consider when using AMM for clearing, including the black module cannot withdraw when the conditions are not met, and the flexibility of Defi under ERC cannot be realized within the module. So we design the progressive AMM clearing process applicable to Yala Finance.

As shown in the above figure, the collateral price within the module AMM changes with the market price, pbp_b is the total value of the collateral when the borrower initiates the Loan Module, and the system does not do anything when the value of the collateral rises above pbp_b. plp_l is the liquidation line set by Yala Foundation for collateral in advance according to the quotation of the prediction machine. When the market price of collateral is in the interval from plp_l to pbp_b, the collateral price in AMM and the market price are equal, so that pap_a is the collateral price in AMM, and pmp_m is the market price of collateral, which satisfies the function pa=pmp_a = p_m.

The AMM liquidation mechanism is triggered when pm<plp_m < p_l, i.e., the market price is below the liquidation line and the borrower has not yet repaid the loan. Set

plpb=α,(1)\frac{p_l}{p_b} = \alpha , (1)

where α\alpha is a constant set at Loan Module creation, i.e., the liquidation rate, that satisfies 0<α<10 < \alpha < 1. AMM for Liquidation satisfies a constant equation similar to uniswap v3[@]:

(x+f)(y+g)=k,(2)(x+f)(y+g) = k, (2)

where xx denotes the total amount of $YU in the Loan Module and yy denotes the outstanding collateral balance. As in Uniswap V3, the price (collateral price) in the AMM can be expressed like this:

Pa=x+fg+y.(3)P_a= \frac{x+f}{g+y}. (3)

Unlike Uniswap V3, both f and g in the above equation are dynamic variables and are correlated with the external price pmp_m. Under the BRC-20 modularization standard, it is not appropriate to consider the condition of automatic buyback of collateral, which is cleared when pmp_m is in the interval (0,pl)(0, p_l). The clearing process is initiated by the keeper who initiates the bidding of the collateral by the TRANSFER inscription, and only when the clearing is complete is the clearing of all TRANSFERS carried out, otherwise, once the collateral rises again to a healthy level, i.e., PmplP_m \geq p_l, all transfer inscriptions are returned to revert PaP_a to the healthy curve after a delay of one prophet-safe time.

Next, we discuss the computation of the clearing function for the interval (0,pl)(0, p_l), and we refer to the existing results of the LLAMMA algorithm to obtain the optimal AMM price function:

Pa=Pm3pb2.(4)P_a = \frac{P_m^3}{p_b^2}. (4)

At this point there is the function:

k=Pm3y02(pbpl)2,(5)k = \frac{P_m^3y_0^2}{(p_b-p_l)^2}, (5)

where y0y_0 is the total amount of collateral, the amount of collateral y = y0y_0, and the amount of $YU x = 0 when the Loan Module has just been depolymerized, at which point Pm=pbP_m = p_b, and

k=Pm3y02(pbpl)2=Pmy02(1α)2,(6)k = \frac{P_m^3y_0^2}{(p_b-p_l)^2} = \frac{P_my_0^2}{(1-\alpha)^2} ,(6)

substituting into Eq. (1) and Eq. (2), we get

{f(y0+g)=kPm=pb=fy0+g(7)\begin{cases} f(y_0 + g) = k \\ P_m = p_b = \frac{f}{y_0 + g} \end{cases} (7)

solves to:

f=kpb=Pmy02(1α)2Pm3pb2=Pm6y02pb2(1α)2=Pm2y0pb(1α)=Pm2y0pb(1α),\begin{align*} f & = \sqrt{kp_b} \\ & = \sqrt{\frac{P_my_0^2}{(1-\alpha)^2}\cdot \frac{P_m^3}{p_b^2}} \\ & = \sqrt{\frac{P_m^6y_0^2}{p_b^2(1-\alpha)^2}} \\ & = \frac{P_m^2y_0}{{p_b}(1-\alpha)} \\ & = \frac{P_m^2y_0}{p_b(1-\alpha)} , \\\end{align*}


g=αpbPm(1α)y0.g = \frac{\alpha p_b}{P_m(1-\alpha)} y_0 .

The complete AMM constant product formula is then obtained:

(x+Pm2y0pb(1α))(y+αpbPm(1α)y0)=Pmy02(1α)2.(9)(x + \frac{P_m^2y_0}{p_b(1 -\alpha)} )(y + \frac{\alpha p_b}{P_m(1-\alpha)} y_0 ) = \frac{P_my_0^2}{(1-\alpha)^2} . (9)

This yields y0y_0 that can be solved for from the current x, y values:

y0=αpbPmx+α(1α)pbPm+((1α)Pm2pby)2+4(1α)Pmxy2p0.(10)y_0 = \frac{\frac{\alpha p_b}{P_m}x + \sqrt{\frac{\alpha (1 - \alpha)p_b}{P_m} +\frac{((1 - \alpha)P_m^2}{p_b}y )^2 + 4(1 - \alpha)P_mxy } }{2p_0} .(10)

Estimated at the beginning of the user's deploy Loan Module until the liquidation is complete: when the collateral market price PmP_m decreases, the quantity obtained after all collateral in the Loan Module is traded into $YU, which we will denote as xendx_{end}, is assumed:

The external price changes at an extremely slow rate, which means that the spread between the external price and the internal price of the Module at a given time is negligibly small.

The internal price of the Module follows the external price, and since the spread between the internal and external prices of the AMM is negligible, the keepers do not incur losses due to the spread during the trading process.

According to Uniswap V3 (6.13), we can get the liquidation completion point estimation function:

xend=x+Δx=x+kΔPa=x+yplPax_{end} = x + \Delta x = x + \sqrt{k} \cdot \Delta \sqrt{P_a} = x + y\sqrt{p_l \cdot P_a}

The whole AMM clearing process is controlled by the clearing script pointed within the Loan Module, when clearing starts, each keeper can send transfer inscription to the Loan Module for clearing queue, the clearing script will recursively check the bids of the keeper in order, when it satisfies iΔxi=pby0\sum_i \Delta x_i = p_b \cdot y_0 when. Unlike LLAMMA, Yala Finance's liquidation process is continuous and does not include band rounds. Because under the volatile BTC market, the plunge of inscriptions may generate bad debts extremely easily, the gradual liquidation can share the risk for the keeper, and also allow the keeper to compete for arbitrage and accelerate the liquidation.

Last updated