How to repay a crypto loan, prevent automatic liquidation, and calculate your liquidation threshold
There is no bankruptcy court on the blockchain: The mechanics of automatic liquidation plus a speedrun on how (and why) to pay back your debt on Aave and Arbitrum
Level up your crypto knowledge & master the future of decentralized finance.
If you decide to embrace degenerate concepts of 30x leveraged positions, or partake in eth lending activities to borrow stablecoins to buy more eth to swap for **insert hot token here** and LP on an algorithmic lending platform that promises 90% APY by optimized yield harvesting across a collateralized variable lending pool (what?) you will soon be subject to the brutality of automatic liquidation. An event where the token’s price action puts your loan-to-value in the kill zone aka under-collateralized. In this guide, we’ll review how lending platforms execute automatic liquidations to ensure your account “remains solvent”, and walk through how to pay back your debt so it never happens to you.
📚 This guide will cover
Mechanics of automatic liquidation on lending platforms like Aave
How to pay back your debt on Aave arbitrum
Aave’s variable debt token
How tokens are minted and burn
A speed run on smart contracts
🧰 Tools you will need
A spreadsheet - I use google sheets
Aave - A borrow/lending platform on Ethereum
Arbitrum - Our layer 2 of choice for this guide
Arbiscan - blockchain explorer to assess fees and contract interaction on Arbitrum
A web wallet like metamask
Let’s take a moment and reflect on a noble truism that is understated in the web3 and defi community: Any leverage position you enter must be repaid. This is also true in the traditional finance world: mortgages, car loans, student loans, credit cards, it’s all leverage - extending the buying power of your dollar.
Unfortunately, the average American hasn’t connected the dots on debt repayment and has actively identified ways to increase their total debt position. Maybe we just don’t care or perhaps we envision a future where ‘our money makes money’ at a rate higher than the debt yield? You are the master of your destiny, but if this is your philosophy, it should be no surprise that 1/3rd of all Americans who make over $250,000 are living paycheck to paycheck.
US households savings rates are at a record low of under 5 percent
As of this writing, the SP500 is down 17% YTD
Our vision of utopia in the DeFi world: a digital world free from the shackles of traditional banking and the perpetual rat race seems to be a distant dream:
The Ethereum Network has liquidated $52 million dollars in leveraged positions in the past 24 hours
I correctly predicted eth would hit $1,200 by October 2022
Aave, Ethereum’s largest lending platform has over one billion USD of locked eth operating at ~ 52% utilization with a variable lending rate of ~6%.
The beauty of smart contracts and our vision of decentralized finance is there is no bankruptcy court. Code is the law and your agreement is defined in an immutable transaction controlled by a smart contract. If you enter into a leveraged position or take out debt only to be liquidated as a result of systematic risk parameter violations (health factor violation, liquidation threshold, LTV under-collateralization), the liquidation event is automatic.
There is no due process, judge, or bankruptcy trial. The beauty and chaos of decentralized finance. Here’s how it works.
Mechanics of automatic liquidation
Let’s speed run an example with 100 stETH. We want to lend staked eth and borrow USDC. We’ll use numbers from the 2022 crypto boom to keep things spicy:
At $6,000/stETH and 100 staked eth tokens, an equivalent of $600,000 USD is deposited. The max I can borrow is 82.5% of the deposit amount or 82.5 eth worth of USDC. With eth at $6,000 per coin, my max exposure to USDC is $495,000 (82.5 eth * $6,000 * $1.0).
The 82.5% is the “loan to value” (LTV). I now have $600,000 of staked eth (locked as collateral) and $495,000 of USDC which I can YOLO on my degen expeditions. What leveraged participants must be aware of is the relationship between the LTV and Liquidation Threshold.
The ‘Liquidation Threshold’ (LT) is the percentage at which a position is defined as under-collateralized. The LT varies by each token and we see AAVE’s current LT rate for USDC is 85%.
If eth or its staked derivatives decreases just 3 percent from the $6,000 price per coin to $5,800, LTV > LV. At current eth prices of $1,400, the person who made this trade got rekted. They were doomed from the jump.
Note: We do not have to worry about liquidation risks when we lend eth to borrow more eth. The ‘aave wrapped eth token’ (deposit token) and ‘aave wrapped variable debt eth token’ (debt token minted by aave) rise and fall at the same rate. You are subject to variable interest rate payments which have been as low as 5% and as high as 100% (immediately after the merge).
Lending platforms will automatically liquidate some of your position when the loan is under-collateralized as measured by their ‘risk parameter model’. This is the beauty of crypto, the loan agreement is embedded in the contract. There is no human counterparty risk. The code will automatically liquidate your position.
Aave’s risk parameter model is calculated using a ‘health factor metric,’ which quantifies risk based on the amount of collateralized eth, the liquidation threshold, and the total amount borrowed. This metric is displayed to the end-users, unfortunately, most apes and degens don’t know how to read; we only know number go up.
Using our 100 stETH example and USDC example with eth @ 6,000 USD, the Health Factor is calculated as:
H(f) = (100 eth * .85 ) / 82.5 eth = 1.03
Note: Aave’s risk parameter framework including its health factor and liquidation penalty are eth denominated. This the platforms metrics used to measure insolvency are measured in eth. This makes ‘sense’ when lending eth, but when borrowing a non-eth asset like USDC, the amount must first be converted back into eth denominated terms
For example: If you lend 100 staked eth at $5,000 per coin (for a total of $500,000 USD of eth) and borrow $250,000 of USDC, the amount borrowed in eth denominated terms is ($250,000 USDC / $5,000 ) is 50 eth…
…If staked eth decreases to $2,500 - you still provided 100 of staked eth liquiditiy as a lender, but the amount of eth you owe has now increased. $250,000 of USDC is now 100 eth ($250,000 / $2,500) and you will be liquidated!
Loans with health factors < 1 are subject to automatic liquidation. Consider what happened with Ethereum dropped to $5,800, just ~2%. The health factor yields a <1 value, eth at $2,000, is a catastrophe, see table below.
Moreover, lending platforms like Aave will impose a liquidation penalty on top of the liquidation event itself. To maintain solvency and restore the H(f) to > 1, Aave liquidators will repay up to 50% of the loan and receive a 5% incentive.
In the aforementioned example where the health factor is < 1 at $5,000 eth:
This is very bad:
We provided 100 staked eth of liquidity
We borrowed 495,000 USDC or 81.25 of eth
Eth dropped from $6,000 to $5,000 price per coin
Our health factor reached <1 because our LTV is > the liquidation threshold
Aave liquidated 50% or 41.25 eth of the collateralized eth to cover the downward movement
Aave imposed a liquidation penalty equal to 5% of the liquidated eth or 2.06 eth
We paid a total of 43.125 eth leaving us 56.69 eth as collateral
We are left with 41.25 eth or $206,250 USD of debt
43.125 eth at $5,000 is worth ~ $215,625. 43.125 eth at $6,000 is worth ~ $258,750. This is problematic because although we borrowed USDC, the debt and the lending platform’s health factor is denominated in ETH. More eth must be sold to cover the liquidation event.
This is something that is glossed over in degen communities, the health factor of platforms like Aave, its liquidation structure, and fees are all denominated in eth independent of what token you’ve borrowed.
A visual depiction is outlined below. Conceptually lending platforms will liquidate your position when your collateral is below a liquidation threshold (box 2 below). The liquidated amount (50% in the case of aave) plus a liquidation penalty is deducted from your collateralized amount (box 3), and the amount you owe plus the amount of eth collateralized decreases proportional to the amount liquidated.
None of this can be stopped. You cannot call your local government official and demand a moratorium on Aave liquidations. Your agreement is embedded into the Aave smart contract and automatically executed.
🤗 Are you ready to pay back your debt? Tired of liquidation fears keeping you up at night? Have you finally realized that you’re not sure how borrow/lending protocols actually work? Good.
How to pay back your debt
The actual mechanics of paying your debt back on Aave are straightforward:
Navigate to aave.com
Click the “repay” button
Click “approve to continue”
Click the “Repay the ETH” button
Initiate the repayment workflow by clicking the “repay” button…
..approve the repayment transaction, initiate the repayment, and confirm in your web wallet…
I’m using WBTC to pay off the variable eth debt:
As frontrunners, we need to better understand what actions were actually performed.
🛑 First take a moment and note the debt repayment amount in image 10 is .009526 eth, but the amount of WETH i’m actually repaying in image 11 is .09565 eth. These 2 pictures were taken two weeks apart and represent the underlying risk with respect to variable debt tokens.
When you borrow ETH, or any token on any lending platform like Aave, the Aave smart contract sends eth to your wallet to do as you please elsewhere in DeFi. To keep track of the loan you’re also given the same amount of units of a “token” called “Aave Arbitrum Variable Debt Eth”. This is an ERC20 token that represents my debt. The variable interest rate (APY = 2.26% in the aforementioned image) is applied to the “Aave Arbitrum Varable Debt eth”.
If, for example, I had “1 aave arbitrum variable debt eth” token and the APY remained constant at 2.26% for 1 year, the token’s value (and my corresponding debt) would increase from 1 to “1.026 aave arbitrum variable debt eth”.
Then, once you repay the debt, Aave sees you own “1.026 aave arbitrum variable debt eth”, so it will ask you for 1.026 real eth in order to fully pay back the loan. At that point, your debt token will be removed from your wallet, and that is how Aave knows you no longer have any debt.
⚠️ Call out - remember an ERC20 token is really just a smart contract that specifies basic functions like ‘balanceOf', ‘transferOf’, etc. You don’t really own those tokens the same way you own ETH, even though it appears that way in the Aave dashboard UI and in our web wallet.
Owning ETH is as easy as a simple “Address 0xABC123 owns 5 eth”, but owning an ERC20 token is more nuanced like “Contract 0xDEFGHI’s internal state says that address 0XABC123 has 10 tokens”. Then when you go and see how many tokens you have, you query “Contract 0xDEFGHI’s” balanceOf method with your address to see how many tokens you have at this current point in time on the blockchain” . This is how smart contracts (like Aave’s lending platform) can do all sorts of things with your balance like increase it, decrease it, without you having to do anything!
This is why when you go into blockchain explorer platforms like Arbiscan to view your wallet balance, you see Aave’s variable debt tokens under the ERC20 section.
Once the repayment workflow is completed, our assessment on arbiscan aligns with our initial take. The “Aave Arbitrum variable eth debt” token has been removed.
We perform our due diligence independent of the results on arbiscan by comparing the token balance of both the Aave Arbitrum Wrapped BTC and Aave Arbitrum variable wrapped ETH and confirm that:
.0067 WBTC has been deducted
.0954 variableDebtArbWETH has been removed
Conceptually we interact with the entire Aave ecosystem depicted below:
A user deposits money as collateral into the lending platform
Aave mints an ERC20 “aToken” representing a digital “IOU” on the amount collateralized
Aave’s lending rate oracle determines the variable yield paid on the collateralized aToken and increases the token balance pro-rata the yield amount
A user borrows eth from the lending platform
Aave mints an ERC20 “aToken” representing an obligation to the underlying debt
Aave’s lending rate oracle determines the variable debt yield on the collateralized aToken and increases the token debt balance pro-rata the debt yield amount
A user pays back the variable debt eth
Aave burns the variable debt eth token
📒On the blockchain
When we review the blockchain transactions on arbiscan - a similar story is told with smart contracts:
Wallet address 0x8f calls smart contact 0x32
8xf sends 0x32 .0067 aave arbitrum wrapped btc
0x32 burns aave arbitrum wrapped btc
0x32 sends .0067 wbtc 0xdef
0xdef sends .00669 to 0x515 (less gass fees)
0x515 sends .00954 weth back to 0xdef
0x def sends .00954 weth back to 0x32
same process is executed for the 0.00003355 + 0.00001676 transactions fees
The .0954 aave arbitrum variable debt eth is burned
0x32 sends .0954 weth to the aave wrapped eth smart contract
Recap and closing thoughts.
Yes this was a guide on how to pay back your outstanding loan on aave but the real alpha was understanding how lending platforms issue ERC20 tokens which represent the collateral and debt. Now we understand that when we view an ERC20 token balance in any UI, we’re really calling a smart contract which calls a function to display your balance. We’ve also explored the blockchain on arbiscan to better understand what smart contracts are called and how Aave’s aTokens are minted and burned in the process.
🔔 Most importantly, we now realize the risks associated with automatic liquidation and how platforms like aave “manage solvency” and make you broke in the process.
You’ve been warned.
September 22nd, 2022
San Francisco, CA
Level up your crypto knowledge & master the future of decentralized finance.
quote of the week - “I asked a text to image AI program what it thought about financial markets this year” - reddit