JTokens

Introduction

jToken refers to the "receipt" users get for supplying underlying assets to JustLend DAO, such as the jTRX, jUSDT, jSUN and jBTC you receive after supplying the corresponding assets. jToken is a TRC20 token in your wallet.

All assets supported by JustLend DAO, a DeFi protocol, are packed and integrated through the smart contract - jToken. Users mint jToken, which generates interest for its holders, and provide assets to the protocol. Each jToken can be swapped back into the corresponding base asset when users redeem it.

jToken shares the same properties as other TRC20 tokens, such as being transferred to others or deposited into a smart contract. Your transfer of jToken to other users or institutions constitutes a waiver of ownership over the assets you have supplied to JustLend DAO.

Solidity API

Query interface

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.

function liquidationIncentiveMantissa() view returns (uint)

Parameter description: N/A

Returns: N/A


getAccountLiquidity function

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.

getAccountLiquidity(address account) view returns (uint, uint, uint)

Parameter description:

ParameterTypeDescription

account

address

User address

Return Values:

uint256error (error code, 0 means success)

uint256

liquidity

uint256

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.


ExchangeRate

Calling this method accrues interest and returns the up-to-date exchange rate.

function exchangeRateCurrent() public nonReentrant returns (uint)

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.

function getCash() public view returns (uint)

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.

function totalBorrowsCurrent() external nonReentrant returns (uint)

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.

function borrowBalanceCurrent(address account) external nonReentrant returns (uint)

Parameter description:

ParameterTypeDescription

account

address

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.

function borrowRatePerBlock() external view returns (uint)

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.

function totalSupply() external view returns (uint256)

Parameter description: N/A

Returns: The supply of tokens.


Underlying Balance

Calling this method gets the underlying balance of the owner.

function balanceOfUnderlying(address owner) external returns (uint)

Parameter description:

ParameterTypeDescription

owner

address

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.

function supplyRatePerBlock() external view returns (uint)

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.

function totalReserves() returns (uint)

Parameter description: N/A

Returns: The total amount of reserves.


Reserve Factor

Calling this method gets the current reserve factor.

function reserveFactorMantissa() returns (uint)

Parameter description: N/A

Returns: The current reserve factor.

Modification Interface

Borrow

Calling this method borrows assets from JustLend DAO protocol to the sender's owner address.

function borrow(uint borrowAmount) external returns (uint)

Parameter description:

ParameterTypeDescription

borrowAmount

uint

The amount of the underlying asset to borrow

Returns: None, reverts on error.


repayBorrow

Calling this method repays their own borrow.

function repayBorrow(uint amount) external payable

Parameter description:

ParameterTypeDescription

amount

uint

The amount of the asset to repay

Returns: None, reverts on error.


repayBorrowBehalf

Calling this method repays a borrow belonging to borrower.

function repayBorrowBehalf(address borrower) external payable

Parameter description:

ParameterTypeDescription

borrower

address

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.

function mint() external payable

Parameter description:

ParameterTypeDescription

msg.value

The amount of TRX to supply

Returns: None, reverts on error.


Redeem

Calling this method redeems jTokens in exchange for the underlying asset and accrues interest whether or not the operation succeeds.

function redeem(uint redeemTokens) external returns (uint)

Parameter description:

ParameterTypeDescription

redeemTokens

uint

The number of jTokens to redeem into underlying

Returns: 0 for success, reverts on error.


RedeemUnderlying

Calling this method redeems jTokens in exchange for a specified amount of underlying asset.

function redeemUnderlying(uint redeemAmount) external returns (uint)

Parameter description:

ParameterTypeDescription

redeemAmount

uint

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.

function transfer(address dst, uint256 amount) external nonReentrant returns (bool)

Parameter description:

ParameterTypeDescription

dst

dst

The receiver's address

amount

uint256

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.

function liquidateBorrow(address borrower, uint repayAmount, address jTokenCollateral) returns (uint)

Parameter description:

ParameterTypeDescription

borrower

address

Address of a liquidated account

repayAmount

uint256

Amount of token to be repaid in the event of liquidation (measured in the borrowed asset)

jTokenCollateral

address

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.

function liquidateBorrow(address borrower, address jTokenCollateral) payable

Parameter description:

ParameterTypeDescription

borrower

address

Address of a liquidated account

msg.value

uint256

Amount of TRX to be repaid in the event of liquidation (measured in SUN)

jTokenCollateral

address

Address of the jTRX contract to set aside the collateralized asset of a borrower

Returns: No return. If any error occurs, the transaction will be reverted.

Appendix

jToken Decimals

All jTokens on JustLend have 8 decimal places.

jToken Balance Query

We suggest you use Tronweb to query jToken balance. For example, you can follow the steps below to query jUSDT balance:

//Example 1
async function triggercontract(){
  let instance =
await tronWeb.contract().at('TXJgMdjVX5dKiQaUi9QobwNxtSQaFqccvd');
  let res = await instance.balanceOf().call();
  console.log(res);
}

triggercontract();

//Example 2
async function triggercontract(){
  let instance =
await tronWeb.contract().at('TXJgMdjVX5dKiQaUi9QobwNxtSQaFqccvd');
  let res = await instance["balanceOf"]().call();
  console.log(res);
}

triggercontract();

Key Events

EventDescription

Mint(address minter, uint mintAmount, uint mintTokens)

Emitted upon a successful Mint.

Redeem(address redeemer, uint redeemAmount, uint redeemTokens)

Emitted upon a successful Redeem.

Borrow(address borrower, uint borrowAmount, uint accountBorrows, uint totalBorrows, uint borrowIndex)

Emitted upon a successful Borrow.

RepayBorrow(address payer, address borrower, uint repayAmount, uint accountBorrows, uint totalBorrows, uint borrowIndex)

Emitted upon a successful Repay Borrow.

LiquidateBorrow(address liquidator, address borrower, uint repayAmount, address cTokenCollateral, uint seizeTokens)

Emitted upon a successful Liquidate Borrow.

Appendix

jToken Decimals

All jTokens on JustLend have 8 decimal places.

jToken Balance Query

We suggest you use Tronweb to query jToken balance. For example, you can follow the steps below to query jUSDT balance:

//Example 1
async function triggercontract(){
  let instance =
awaittronWeb.contract().at('TXJgMdjVX5dKiQaUi9QobwNxtSQaFqccvd');
  let res = await instance.balanceOf().call();
  console.log(res);
}

triggercontract();

//Example 2
async function triggercontract(){
  let instance =
awaittronWeb.contract().at('TXJgMdjVX5dKiQaUi9QobwNxtSQaFqccvd');
  let res = await instance["balanceOf"]().call();
  console.log(res);
}

triggercontract();

Error Code And Failure info

Error Codes

CodeNameDescription

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.

Failure Info

CodeName

0

ACCEPT_ADMIN_PENDING_ADMIN_CHECK

1

ACCRUE_INTEREST_ACCUMULATED_INTEREST_CALCULATION_FAILED

2

ACCRUE_INTEREST_BORROW_RATE_CALCULATION_FAILED

3

ACCRUE_INTEREST_NEW_BORROW_INDEX_CALCULATION_FAILED

4

ACCRUE_INTEREST_NEW_TOTAL_BORROWS_CALCULATION_FAILED

5

ACCRUE_INTEREST_NEW_TOTAL_RESERVES_CALCULATION_FAILED

6

ACCRUE_INTEREST_SIMPLE_INTEREST_FACTOR_CALCULATION_FAILED

7

BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED

8

BORROW_ACCRUE_INTEREST_FAILED

9

BORROW_CASH_NOT_AVAILABLE

10

BORROW_FRESHNESS_CHECK

11

BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED

12

BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED

13

BORROW_MARKET_NOT_LISTED

14

BORROW_COMPTROLLER_REJECTION

15

LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED

16

LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED

17

LIQUIDATE_COLLATERAL_FRESHNESS_CHECK

18

LIQUIDATE_COMPTROLLER_REJECTION

19

LIQUIDATE_COMPTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED

20

LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX

21

LIQUIDATE_CLOSE_AMOUNT_IS_ZERO

22

LIQUIDATE_FRESHNESS_CHECK

23

LIQUIDATE_LIQUIDATOR_IS_BORROWER

24

LIQUIDATE_REPAY_BORROW_FRESH_FAILED

25

LIQUIDATE_SEIZE_BALANCE_INCREMENT_FAILED

26

LIQUIDATE_SEIZE_BALANCE_DECREMENT_FAILED

27

LIQUIDATE_SEIZE_COMPTROLLER_REJECTION

28

LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER

29

LIQUIDATE_SEIZE_TOO_MUCH

30

MINT_ACCRUE_INTEREST_FAILED

31

MINT_COMPTROLLER_REJECTION

32

MINT_EXCHANGE_CALCULATION_FAILED

33

MINT_EXCHANGE_RATE_READ_FAILED

34

MINT_FRESHNESS_CHECK

35

MINT_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED

36

MINT_NEW_TOTAL_SUPPLY_CALCULATION_FAILED

37

MINT_TRANSFER_IN_FAILED

38

MINT_TRANSFER_IN_NOT_POSSIBLE

39

REDEEM_ACCRUE_INTEREST_FAILED

40

REDEEM_COMPTROLLER_REJECTION

41

REDEEM_EXCHANGE_TOKENS_CALCULATION_FAILED

42

REDEEM_EXCHANGE_AMOUNT_CALCULATION_FAILED

43

REDEEM_EXCHANGE_RATE_READ_FAILED

44

REDEEM_FRESHNESS_CHECK

45

REDEEM_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED

46

REDEEM_NEW_TOTAL_SUPPLY_CALCULATION_FAILED

47

REDEEM_TRANSFER_OUT_NOT_POSSIBLE

48

REDUCE_RESERVES_ACCRUE_INTEREST_FAILED

49

REDUCE_RESERVES_ADMIN_CHECK

50

REDUCE_RESERVES_CASH_NOT_AVAILABLE

51

REDUCE_RESERVES_FRESH_CHECK

52

REDUCE_RESERVES_VALIDATION

53

REPAY_BEHALF_ACCRUE_INTEREST_FAILED

54

REPAY_BORROW_ACCRUE_INTEREST_FAILED

55

REPAY_BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED

56

REPAY_BORROW_COMPTROLLER_REJECTION

57

REPAY_BORROW_FRESHNESS_CHECK

58

REPAY_BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED

59

REPAY_BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED

60

REPAY_BORROW_TRANSFER_IN_NOT_POSSIBLE

61

SET_COLLATERAL_FACTOR_OWNER_CHECK

62

SET_COLLATERAL_FACTOR_VALIDATION

63

SET_COMPTROLLER_OWNER_CHECK

64

SET_INTEREST_RATE_MODEL_ACCRUE_INTEREST_FAILED

65

SET_INTEREST_RATE_MODEL_FRESH_CHECK

66

SET_INTEREST_RATE_MODEL_OWNER_CHECK

67

SET_MAX_ASSETS_OWNER_CHECK

68

SET_ORACLE_MARKET_NOT_LISTED

69

SET_PENDING_ADMIN_OWNER_CHECK

70

SET_RESERVE_FACTOR_ACCRUE_INTEREST_FAILED

71

SET_RESERVE_FACTOR_ADMIN_CHECK

72

SET_RESERVE_FACTOR_FRESH_CHECK

73

SET_RESERVE_FACTOR_BOUNDS_CHECK

74

TRANSFER_COMPTROLLER_REJECTION

75

TRANSFER_NOT_ALLOWED

76

TRANSFER_NOT_ENOUGH

77

TRANSFER_TOO_MUCH

Last updated