Comptroller

Introduction

The Comptroller is the risk management module of the JustLend DAO protocol. It determines how much collateral should users keep to avoid liquidation.

The Comptroller is implemented as an upgradable contract. The entrance is Unitroller; the implementation is Comptroller.

Solidity API

Markets

enterMarkets()

Calling this method enters a list of markets to supply or borrow.

function enterMarkets(address[] memory cTokens) public returns (uint[] memory)

Parameter description:

ParameterTypeDescription

cTokens

address[]

Address list of the markets to enter

Returns: For each market, returns 0 for success, otherwise an error code.

const result = comptroller.enterMarket(addresses).send({
  feeLimit:10_000_000_000,
  callValue:0,
  shouldPollResponse:true
});

exitMarket()

Calling this method exits a currently entered market.

function exitMarket(address cTokenAddress) external returns (uint)

Parameter description:

ParameterTypeDescription

cTokenAddress

address

Market address to quit

Returns: 0 on success, otherwise an error code.

const result = comptroller.exitMarket(address).send({
  feeLimit:10_000_000_000,
  callValue:0,
  shouldPollResponse:true
});

getAssetsIn()

Calling this method returns a list of already entered markets.

function getAssetsIn(address account) external view returns (CToken[] memory)

Parameter description:

ParameterTypeDescription

account

address

The markets this account enters will be returned

Returns: Markets have been entered by the specified address.

const result = comptroller.getAssetsIn(account).call();

markets()

Calling this method returns the status of a market(isListed, collateralFactorMantissa, comped)

function markets(address cTokenAddress) view returns (bool, uint, bool)

Parameter description:

ParameterTypeDescription

cTokenAddress

address

Market address

Return Values:

ReturnsTypeDescription

isListed

bool

Whether recognized by comptroller

collateralFactorMantissa

uint

The value can be borrowed(scaled by 1e18)

comped

bool

Whether suppliers & borrowers can get jst dividends

const {0: isListed, 1: collateralFactorMantissa, 2: isComped} = comptroller.markets(address).call();

Collateral & Liquidation

getAccountLiquidity()

Calling this method returns the liquidity and shortfall of a user.

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

Parameter description:

ParameterTypeDescription

account

address

Address to be queried

Return Values:

ReturnsTypeDescription

error

uint

0 for success, otherwise an error code

liquidity

uint

current liquidity

shortfall

uint

The shortfall value of the account's collateral requirement

const {0: error, 1: liquidity, 2: shortfall} = comptroller.getAccountLiquidity(account).call();

closeFactorMantissa()

Calling this method gets the percentage of a liquidatable account should repay in a single liquidation. The range is 0%-100%. The calculation result of this method applies to a single asset.

function closeFactorMantissa() view returns (uint256)

Returns: The close factor, scaled by 1e18

const result = comptroller.closeFactorMantissa().call();

liquidationIncentiveMantissa()

Calling this method gets liquidators' incentives. The incentive is for underwater accounts. Part of this will be given to jToken reserves according to the seize share.

function liquidationIncentiveMantissa() view returns (uint256)

Returns: The liquidation incentive, scaled by 1e18

const result = comptroller.liquidationIncentiveMantissa().call();

Key Events

EventDescription

MarketEntered(address cToken, address account)

Emits when successfully entering a market

MarketExited(address cToken, address account)

Emits when successfully exit a market

Error Codes

CodeNameDescription

0

NO_ERROR

Success

1

UNAUTHORIZED

The sender is not authorized to perform this action.

2

COMPTROLLER_MISMATCH

Liquidation cannot be performed in markets with different comptrollers.

3

INSUFFICIENT_SHORTFALL

The account does not have sufficient shortfall to perform this action.

4

INSUFFICIENT_LIQUIDITY

The account does not have sufficient liquidity to perform this action.

5

INVALID_CLOSE_FACTOR

The close factor is not valid.

6

INVALID_COLLATERAL_FACTOR

The collateral factor is not valid.

7

INVALID_LIQUIDATION_INCENTIVE

The liquidation incentive is invalid.

8

MARKET_NOT_ENTERED

The market has not been entered by the account.

9

MARKET_NOT_LISTED

The market is not currently listed by the comptroller.

10

MARKET_ALREADY_LISTED

An admin tried to list the same market more than once.

11

MATH_ERROR

A math calculation error occurred.

12

NONZERO_BORROW_BALANCE

The action cannot be performed since the account carries a borrow balance.

13

PRICE_ERROR

The comptroller could not obtain a required price of an asset.

14

REJECTION

The comptroller rejects the action requested by the market.

15

SNAPSHOT_ERROR

The comptroller could not get the account borrows and exchange rate from the market.

16

TOO_MANY_ASSETS

Attempted to enter more markets than are currently supported.

17

TOO_MUCH_REPAY

Attempted to repay more than is allowed by the protocol.

Failure Info

CodeValue

0

ACCEPT_ADMIN_PENDING_ADMIN_CHECK

1

ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK

2

EXIT_MARKET_BALANCE_OWED

3

EXIT_MARKET_REJECTION

4

SET_CLOSE_FACTOR_OWNER_CHECK

5

SET_CLOSE_FACTOR_VALIDATION

6

SET_COLLATERAL_FACTOR_OWNER_CHECK

7

SET_COLLATERAL_FACTOR_NO_EXISTS

8

SET_COLLATERAL_FACTOR_VALIDATION

9

SET_COLLATERAL_FACTOR_WITHOUT_PRICE

10

SET_IMPLEMENTATION_OWNER_CHECK

11

SET_LIQUIDATION_INCENTIVE_OWNER_CHECK

12

SET_LIQUIDATION_INCENTIVE_VALIDATION

13

SET_MAX_ASSETS_OWNER_CHECK

14

SET_PENDING_ADMIN_OWNER_CHECK

15

SET_PENDING_IMPLEMENTATION_OWNER_CHECK

16

SET_PRICE_ORACLE_OWNER_CHECK

17

SUPPORT_MARKET_EXISTS

18

SUPPORT_MARKET_OWNER_CHECK

Last updated