How It Works
Leverage Trading (Margin Trading) is not complicated. It is a trading strategy that simply borrows money from other parties, and buys more underlying assets with the borrowed funds (if you are taking a long position) or sells them first intending to buy back at a cheaper price later(if you are taking a long position).
Please keep in mind that you need to pay back the borrowed funds no matter what happens. You may actively close your position or passively get liquidated if the market makes an unfavorable move to a certain threshold.
In Defrost V2, this whole process is coded in smart contracts.
Let's take a closer look with an example:
Suppose there are two users on Defrost V2, Tom and Jerry. Both hold $1000 USDC.
Tom is bullish on AVAX and intends to open a 3x long position on AVAX against USDC.
Jerry is bearish on AVAX and intends to open a 3x short position on AVAX against USDC.
Tom chooses to open a 3x long position on AVAX against USDC with $1000 USDC as collateral.
Jerry chooses to open a 3x short position on AVAX against USDC with $1000 USDC as collateral.
Tom triggers the contract to borrow $2000 USDC from the USDC super vault, which works as a lending pool. In total, Tom now holds $3000 USDC in the smart contract, with $2000 USDC borrowing as his debt. This gives him 3x ($3000/$1000) leverage.
Jerry also triggers the contract to borrow $2000 AVAX from the AVAX super vault, ending up with $1000 USDC and $2000 AVAX in the smart contract, with $2000 AVAX borrowing as his debt. This gives him 3x ($3000/$1000) leverage.
The smart contract will automatically trade $3000 USDC for the equivalent amount of AVAX for Tom. The slippage and transaction cost depends on the liquidity and pool settings of the AVAX/USDC pair on the relevant DEXs.
The smart contract will automatically trade $2000 AVAX for the equivalent amount of USDC for Jerry, again with the same caveats regarding slippage and transaction costs.
All of the assets the contracts hold for traders are regarded as collaterals.
The contracts now hold $3000 AVAX for Tom, and they are all treated as collateral for Tom's 3x long position. More specifically, they are the collateral for Tom's $2000 USDC borrowing, ensuring Tom can repay the funds back no matter what happens.
When the AVAX's price changes, the value of Tom's collateral changes. If AVAX's price goes up, the collateral's value becomes larger and Tom will have profits. If AVAX's price goes down, the collateral's value becomes small and Tom will have deficits.
The same goes for Jerry. The contracts now hold $3000 USDC for him, underpinning his3x short position and making sure the funds can be paid back.
When the AVAX's price changes, the value of Jerry's borrowing/debt changes. If AVAX's price goes down, the borrowing/debt's value becomes smaller and he will have profits. If AVAX's price goes up, the borrowing/debt's value becomes larger and Jerry will incur a loss, as he will need to pay more to buy these AVAX back and repay the debt.
Both Tom and Jerry need to maintain the collateral ratio (Value of Collateral/Value of Debt) above the minimum requirement, in order not to get liquidated.
Traders may choose to close their leverage positions at any time, provided they maintain the collateral ratio at a healthy level. When closing positions, a series of transactions will be triggered and executed by the smart contracts.
To simplify the process, let us suppose there's no transaction cost or slippage when making transactions on the DEX. Of course, in real cases, DEXes will charge some small transaction fees and there will be some slippage.
Tom chooses to close his AVAX long position, when the AVAX price rises by 20% from $20 to $24. As the price of AVAX grows, the total value of AVAX assets the Defrost contracts hold for Tom grows from $3000 to $3600 while the USDC borrowed stays stable at $2000. When closing the position, the smart contracts sell $3600 AVAX on Trader Joe for $3600 USDC. Then, it repays the USDC loan together with some interest. The total repayment could be $2010 USDC ($2000 principal + $10 interest). The remaining $1590 USDC will be claimable at Tom's address.
Jerry chooses instead to close his AVAX short position when the AVAX price drops by 20% from $20 to $16. As the price of AVAX sinks, the total value of USDC assets the Defrost contracts hold for Jerry stays unchanged at $3000, while the AVAX borrowed drops from $2000 to $1600. When closing the position, the smart contracts buy back $1610 AVAX on Trader Joe with $1610 USDC. Then, it repays the AVAX loan together with some interest. The total repayment is $1610 AVAX ($1600 principal + $10 interest). The remaining $1390 AVAX will be Jerry's.
To make sure that leverage traders can always repay their debts, the Defrost V2 deploys liquidation contracts and sets a minimum collateral ratio. If a user fails to maintain the collateral ratio above the minimum requirement, a third party may liquidate his/her position and get a liquidation bonus. Whatever remains after liquidation will be refunded to the user.
In our example, if Tom or Jerry fails to maintain the minimum collateral ratio above the minimum level, he will get liquidated. The liquidation follows a similar process to closing a position. But it is triggered automatically and executed by a third party. There are incentives to the liquidator and therefore an extra loss to users that get liquidated.
To prevent liquidation in unfavorable market conditions, Tom or Jerry may choose to adjust his leverage or close his position before the collateral ratio drops to the liquidation threshold or add collaterals to maintain a healthy collateral ratio.
The liquidation price is calculated based on whether you are longing or shorting an asset, the leverage you are taking and the price when opening the position.
Please note that the price is fed by Chainlink, rather than the DEX's spot price. Therefore, liquidation will not be affected by the short-time abnormality that may occur on DEXs like Trader Joe.
Last modified 1yr ago