SBM
Introduction
The JustLend DAO Supply and Borrow Market (SBM) is a decentralized liquidity pool where users can participate as suppliers, borrowers or liquidators. Suppliers provide liquidity to a market and can earn interest on the assets provided, where borrowers are able to borrow in a collateralize assets way.
The SBM contract is the main user-facing contract. Most user interactions with the JustLend DAO Protocol occur via the Ctoken contract. It exposes the liquidity management methods that can be invoked using either Solidity or Web3 libraries.
Ctoken.sol
allows users to:
Supply
Borrow
Withdraw
Repay
Liquidation
The source code is available on Github.
Query Interface
ExchangeRate
Calling this method accrues interest and returns the up-to-date exchange rate.
Parameter description: N/A
Returns: calculated exchange rate scaled by 1e18.
Get Cash
Calling this method gets the total amount of underlying balance currently available to this market.
Parameter description: N/A
Returns: The quantity of underlying assets owned by this contract.
Total Borrows
Calling this method gets the sum of the currently loaned-outs and the accrued interests.
Parameter description: N/A
Returns: The total borrows with interest.
Borrow Balance
Calling this method accrues interest to the updated borrowIndex and then calculates the account's borrow balance using the updated borrowIndex.
Parameter description:
account
: the address whose balance should be calculated after updating borrowIndex.
Returns: The calculated balance.
Borrow Rate
Calling this method gets the current per-block borrow interest rate for this jToken.
Parameter description: N/A
Returns: The borrow interest rate per block, scaled by 1e18.
Total Supply
Calling this method gets the total number of tokens in circulation.
Parameter description: N/A
Returns: The supply of tokens.
Underlying Balance
Calling this method gets the underlying balance of the owner.
Parameter description:
owner
: the address of the account.
Returns: The amount of underlying owned by owner.
Supply Rate
Calling this method gets the current per-block supply interest rate for this jToken.
Parameter description: N/A
Returns: the supply interest rate per block, scaled by 1e18.
Total Reserves
Calling this method gets the reserves. Reserve represents a portion of historical interest set aside as cash which can be withdrawn or transferred through the protocol's governance.
Parameter description: N/A
Returns: the total amount of reserves.
Reserve Factor
Calling this method gets the current reserve factor.
Parameter description: N/A
Returns: The current reserve factor.
Liquidation Incentive
By calling the liquidationIncentiveMantissa function of the Unitroller contract, liquidation incentives can be inquired. Liquidators will be given a proportion of the borrower's collateral as an incentive, which is defined as liquidation incentive. This is to encourage liquidators to perform liquidation of underwater accounts.
Parameter description: N/A
Returns: N/A
Get Account Liquidity
By calling the getAccountLiquidity function of the Unitroller contract, account information can be accessed through an account's address to determine whether the account should be liquidated or not.
Parameter description:
account
: user address.
Returns:
error
: error code, 0 means success.liquidity
: liquidity.shortfall
: When the value is bigger than 0, the current account does not meet the market requirement for collateralization and needs to be liquidated.
Note: There should be at most one non-zero value between liquidity and shortfall.
Wtite Interface
Borrow
Calling this method borrows assets from JustLend DAO protocol to the sender's owner address.
Parameter description:
borrowAmount
: the amount of the underlying asset to borrow.
Returns: None, reverts on error.
📅 Event
Emits when user successfully borrow.
borrower
: address of borrow assets account;borrowAmount
: the amount of borrowed assets;accountBorrows
: the account borrow the assets;totalBorrows
: total borrow assets form the account;borrowIndex
: the index of this borrow order.
repayBorrow
Calling this method repays their own borrow.
Parameter description:
amount
: the amount of the asset to repay.
Returns: None, reverts on error.
📅 Event
Emits when user successfully repay borrow.
payer
: operate repay borrow;borrower
: address of borrow assets account;repayAmount
: the amount of repaid assets;accountBorrows
: the account borrow the assets;totalBorrows
: total borrow assets form the account;borrowIndex
: the index of this borrow order.
repayBorrowBehalf
Calling this method repays a borrow belonging to borrower.
Parameter description:
borrower
: the account with the debt being payed off.msg.value
: the amount to repay.
Returns: None, reverts on error.
Mint
Calling this method supplies assets into the market and receives jTokens in exchange.
Parameter description:
msg.value
: the amount of TRX to supply.
Returns: None, reverts on error.
📅 Event
Emits when user successfully mint.
minter
: operate supply assets into the market;mintAmount
: the amount of supplied assets;mintTokens
: the tokens need to mint.
Redeem
Calling this method redeems jTokens in exchange for the underlying asset and accrues interest whether or not the operation succeeds.
Parameter description:
redeemTokens: the number of jTokens to redeem into underlying.
Returns: 0 for success, reverts on error.
📅 Event
Emits when user successfully redeem.
redeemer
: operate redeem jTokens;redeemAmount
: the amount of redeem assets;redeemTokens
: the tokens need to redeem.
RedeemUnderlying
Calling this method redeems jTokens in exchange for a specified amount of underlying asset.
Parameter description:
redeemAmount: the amount of underlying to redeem.
Returns: 0 for success, reverts on error.
Transfer
Calling this method transfers a specified amount of jtokens to the destination. This action will fail if the account's liquidity become negative due to the transfer.
Parameter description:
dst
: the receiver's address.amount
: amount of token to be transferred.
Returns: A boolean value indicating whether or not the transfer succeeded.
Liquidate Borrow(jTrc20)
By calling liquidateBorrow function of the corresponding jTrc20 contract (e.g. jUSDT), accounts whose liquidity does not meet the market requirement for collateralization will be liquidated by other users to restore the account liquidity to a normal level (i.e. higher than the market requirement for collateralization). In the event of liquidation, liquidators may repay part or 50% of the loan for the borrower. Liquidators will be given a proportion of the borrower's collateral as an incentive.
Parameter description:
borrower: address of a liquidated account.
repayAmount: amount of token to be repaid in the event of liquidation (measured in the borrowed asset).
jTokenCollateral: address of the jTOKEN contract to set aside the collateralized asset of a borrower.
Returns: None, reverts on error.
Liquidate Borrow(jTRX)
By calling the liquidateBorrow function of the jTRX contract, accounts whose liquidity does not meet the market requirement for collateralization will be liquidated by other users to restore the account liquidity to a normal level (i.e., higher than the market requirement for collateralization). In the event of liquidation, liquidators may repay part or 50% of the loan for the borrower. Liquidators will be given a proportion of the borrower's collateral as an incentive.
Parameter description:
borrower
: address of a liquidated account.jTokenCollateral
: address of the jTRX contract to set aside the collateralized asset of a borrower.msg.value
: amount of TRX to be repaid in the event of liquidation (measured in SUN).
Returns: No return. If any error occurs, the transaction will be reverted.
📅 Event
Emits when user successfully liquidate borrow order.
liquidator
: operate liquidation;borrower
: address of a liquidated account;repayAmount
: the amount of repaid assets;cTokenCollateral
: address of the jTRX contract to set aside the collateralized asset of a borrower.seizeTokens
: the tokens need to be liquidated.
Error Code And Failure info
0
NO_ERROR
Not a failure.
1
UNAUTHORIZED
The sender is not authorized to perform this action.
2
BAD_INPUT
An invalid argument was supplied by the caller.
3
COMPTROLLER_REJECTION
The action would violate the comptroller policy.
4
COMPTROLLER_CALCULATION_ERROR
An internal calculation has failed in the comptroller.
5
INTEREST_RATE_MODEL_ERROR
The interest rate model returned an invalid value.
6
INVALID_ACCOUNT_PAIR
The specified combination of accounts is invalid.
7
INVALID_CLOSE_AMOUNT_REQUESTED
The amount to liquidate is invalid.
8
INVALID_COLLATERAL_FACTOR
The collateral factor is invalid.
9
MATH_ERROR
A math calculation error occurred.
10
MARKET_NOT_FRESH
Interest has not been properly accrued.
11
MARKET_NOT_LISTED
The market is not currently listed by its comptroller.
12
TOKEN_INSUFFICIENT_ALLOWANCE
ERC-20 contract must allow Money Market contract to call transferFrom. The current allowance is either 0 or less than the requested supply, repayBorrow or liquidate amount.
13
TOKEN_INSUFFICIENT_BALANCE
Caller does not have sufficient balance in the ERC-20 contract to complete the desired action.
14
TOKEN_INSUFFICIENT_CASH
The market does not have a sufficient cash balance to complete the transaction. You may attempt this transaction again later.
15
TOKEN_TRANSFER_IN_FAILED
Failure in ERC-20 when transfering token into the market.
16
TOKEN_TRANSFER_OUT_FAILED
Failure in ERC-20 when transfering token out of the market.
Last updated