jToken Integration

What is jToken?

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.

Usage Scenario

User A supplies 100 TRX on JustLend DAO and receives 10,000 jTRX (jToken) as a receipt, after which A transfers 6,000 jTRX to User B. Now, A only has 4,000 jTRX left (equivalent to a 40 TRX supply on JustLend DAO), while B gets 6,000 jTRX (from A's transfer, which is equivalent to a 60 TRX supply on JustLend DAO). If B does not transfer jToken back to A, A will no longer own the 6000 jTRX (60 TRX). (The example exchange rate here is 1 TRX = 100 jTRX).

jToken acts as a key means to interact with the JustLend DAO protocol. While each jToken contract creates its own token market, users use jToken contracts to mint, redeem, borrow loans, repay loans, liquidate loans or transfer jToken.

How do jTokens earn interest?

Each market has its own Supply interest rate (APR). Interest isn't distributed; instead, simply by holding jTokens, you'll earn interest.

jTokens accumulates interest through their exchange rate — over time, each jToken becomes convertible into an increasing amount of it's underlying asset, even while the number of jTokens in your wallet stays the same.

Smart Contract Addresses

NameContract Address

Unitroller

TGjYzgCyPobsNS9n6WcbdLVR9dH7mWqFx7

jTRX

TE2RzoSV3wFK99w6J9UnnZ4vLfXYoxvRwP

jUSDD

TX7kybeP6UwTBRHLNPYmswFESHfyjm9bAS

jUSDT

TXJgMdjVX5dKiQaUi9QobwNxtSQaFqccvd

jUSDJ

TL5x9MtSnDy537FXKx53yAaHRRNdg9TkkA

jSUNOLD

TGBr8uh9jBVHJhhkwSJvQN2ZAKzVkxDmno

jSUN

TPXDpkg9e3eZzxqxAUyke9S4z4pGJBJw9e

jWIN

TRg6MnpsFXc82ymUPgf5qbj59ibxiEDWvv

jBTC

TLeEu311Cbw63BcmMHDgDLu7fnk9fqGcqT

jETH

TR7BUFRQeq1w5jAZf1FKx85SHuX6PfMqsV

jJST

TWQhCXaWz4eHK4Kd1ErSDHjMFPoPc9czts

jWBTT

TUY54PVeH6WCcYCd6ZXXoBDsHytN9V5PXt

jTUSD

TSXv71Fy5XdL3Rh2QfBoUu3NAaM4sMif8R

jUSDC

TNSBA6KvSvMoTqQcEgpVK7VhHT3z7wifxy

jNFT

TFpPyDCKvNFgos3g3WVsAqMrdqhB81JXHE

jBTT

TUaUHU9Dy8x5yNi1pKnFYqHWojot61Jfto

jBUSD

TLHASseQymmpGQdfAyNjkMXFTJh8nzR2x2

Query interface

Liquidation Incentive

function liquidationIncentiveMantissa() view returns (uint)

Feature description: 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:

getAccountLiquidity function

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

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

Feature description: 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:

ParameterTypeDescription

account

address

User address

Return value:

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

function exchangeRateCurrent() public nonReentrant returns (uint)

Feature description: 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

function getCash() public view returns (uint)

Feature description: 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

function totalBorrowsCurrent() external nonReentrant returns (uint)

Feature description: 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

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

Feature description: Calling this method accrues interest to the updated borrowIndex and then calculates the account's borrow balance using the updated borrowIndex

Parameter description:

ParameterTypeDescription

account

address

The address whose balance should be calculated after updating borrowIndex

Returns:

The calculated balance

Borrow Rate

function borrowRatePerBlock() external view returns (uint)

Feature description: 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

function totalSupply() external view returns (uint256)

Feature description: Calling this method gets the total number of tokens in circulation

Parameter description: N/A

Returns:

The supply of tokens

Underlying Balance

function balanceOfUnderlying(address owner) external returns (uint)

Feature description: Calling this method gets the underlying balance of the owner

Parameter description:

ParameterTypeDescription

owner

address

The address of the account

Returns:

The amount of underlying owned by owner

Supply Rate

function supplyRatePerBlock() external view returns (uint)

Feature description: 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

function totalReserves() returns (uint)

Feature description: 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

function reserveFactorMantissa() returns (uint)

Feature description: Calling this method gets the current reserve factor.

Parameter description: N/A

Returns:

The current reserve factor

Modification Interface

Borrow

function borrow(uint borrowAmount) external returns (uint)

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

Parameter description:

ParameterTypeDescription

borrowAmount

uint

The amount of the underlying asset to borrow

Returns:

None, reverts on error.

repayBorrow

function repayBorrow(uint amount) external payable

Feature description: Calling this method repays their own borrow

Parameter description:

ParameterTypeDescription

amount

uint

The amount of the asset to repay

Returns:

None, reverts on error.

repayBorrowBehalf

function repayBorrowBehalf(address borrower) external payable

Feature description: Calling this method repays a borrow belonging to borrower

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

function mint() external payable

Feature description: Calling this method supplies assets into the market and receives jTokens in exchange

Parameter description:

ParameterTypeDescription

msg.value

The amount of TRX to supply

Returns:

None, reverts on error.

Redeem

function redeem(uint redeemTokens) external returns (uint)

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

Parameter description:

ParameterTypeDescription

redeemTokens

uint

The number of jTokens to redeem into underlying

Returns:

0 for success, reverts on error.

RedeemUnderlying

function redeemUnderlying(uint redeemAmount) external returns (uint)

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

Parameter description:

ParameterTypeDescription

redeemAmount

uint

The amount of underlying to redeem

Returns:

0 for success, reverts on error.

Transfer

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

Feature description: 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:

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)

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

Feature description: 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:

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:

Liquidate Borrow(jTRX)

function liquidateBorrow(address borrower, address jTokenCollateral) payable

Function description: 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:

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();

Last updated