What is JUSD
JUSD is a stable coin developed by JOJO system to support multi-collateralization. This features allows users to use other non-stable coin assets (BTC, ETH, etc.) as margin for trading. JUSD works like DAI and users can mint JUSD by staking other ERC20 tokens as collateral. JUSD can be freely traded, however, its price is not guaranteed to be equal to Primary asset in the open market.
How to get JUSD
- Users can deposit registered collateral to borrow JUSD.
- Users can also use USDC to buy JUSD directly in the JOJO system.
JUSDBank is a mortgage system that allows users to deposit ERC20 tokens and borrow JUSD. And the borrowed JUSD will be automatically transferred to the trading system, so users can use JUSD as margin to trade. JUSDBank is the core of the multi-collateralization feature, which allows the margin for perpetual trading to be other ERC20 tokens.
Users can deposit collaterals by calling
IJUSDBank#deposit(), the collateral must be already registered in the system.
/// @notice deposit function: users deposit their collateral
/// @param from: deposit from which account
/// @param collateral: deposit collateral type
/// @param amount: collateral amount
/// @param to: account that users want to deposit to
function deposit(address from, address collateral, uint256 amount, address to) external;
The number of JUSD loans available is based on the amount of user's deposited collaterals. The maximum number of user loans available is calculated using this formula
/// @notice borrow function: get JUSD based on the amount of user's collaterals
/// @param amount: borrow JUSD amount
/// @param to: is the address receiving JUSD
/// @param isDepositToJOJO: whether deposit to JOJO account
function borrow(uint256 amount, address to, bool isDepositToJOJO) external;
The price of collateral will fluctuate with the market, in order to ensure that the collateral deposited will not be liquidated, users need to return JUSD in time. There are two ways to return JUSD:
- Transfer JUSD from JOJO system to return it.
- Buy JUSD directly in the market through USDC then return it.
/// @notice repay function: repay the JUSD in order to avoid account liquidation by liquidators
/// @param amount: repay JUSD amount
/// @param to: repay to whom
function repay(uint256 amount, address to) external returns (uint256);
After withdrawal, JUSDBank determines if the account is safe. If the account becomes unsafe after the withdrawal, then the transaction will revert. This formula is used to determine whether the account is safe or not and only the account is safe then users can withdraw collateral.
/// @notice withdraw function: users can withdraw their collateral
/// @param collateral: withdraw collateral type
/// @param amount: withdraw amount
/// @param to: is the address receiving asset
/// @param from: who want to withdraw asset
function withdraw(address collateral, uint256 amount, address to, address from) external;
When the value of borrowed JUSD > the value of deposited collaterals, then the trader will be liquidated. The start liquidation formula is
During the liquidation process, the system attempts to sell collateral at a discounted price based on the marked price, and anyone interested in the collateral can participate in the liquidation. Liquidators can take all or part of the liquidated's collateral and help them repay JUSD.
The liquidation process can be divided into three parts. The first part involves calculating the amount of collateral to be liquidated, determining how much JUSD the liquidator needs to repay on behalf of the liquidated, how much USDC to collect as insurance fee, and if there is any remaining collateral for liquidated, how much to return to them. The second part involves the liquidator executing specific operations such as repaying JUSD by calling JOJOFlashLoan function. The third part involves price protection, ensuring that the liquidator correctly repays JUSD and insurance.
Among these three operations, liquidators can implement the code for external calls related to JOJOFlashLoan by themselves. Currently, JOJO officially provides liquidation code examples, which can be found in
FlashLoanLiquidate.sol. The main implementation process involves selling the collateral obtained from liquidation and dividing the resulting USDC into three parts: one for repaying JUSD, another for paying insurance, and if the liquidated's collateral still has a remainder, transferring it to the liquidated party in the form of USDC.
/// @notice liquidate function: The price of user mortgage assets fluctuates.
/// If the value of the mortgage collaterals cannot handle the value of JUSD borrowed, the collaterals may be liquidated
/// @param liquidatedTrader: is the trader to be liquidated
/// @param liquidationCollateral: is the liquidated collateral type
/// @param liquidationAmount: is the collateral amount liqidator want to take
/// @oaram external function JOJOFlashloan's param
/// @param expectPrice: expect liquidate amount
bytes memory param,
) external returns (DataTypes.LiquidateData memory liquidateData);