Contracts Overview

Comptroller

The Comptroller contract is the risk management layer of the Ionise Protocol. It contains functionality central to borrowing activity in the pool like supplying and borrowing assets and liquidations.

It's responsible for listing markets, managing user's positions in markets, sanity checking liquidations, and emitting rewards. It contains setters and getters for market configuration variables such as collateral factor, close factor, and liquidation incentive. Lending actions can be be paused globally or per market from the comptroller. The Comptroller maps user balances to prices (via the Price Oracle) to risk weights (called Collateral Factors) to make its determinations. Users explicitly list which assets they would like included in their risk scoring, by calling Enter Markets and Exit Market. Each time a user interacts with an iToken, the Comptroller is asked to approve or deny the transaction.

The Unitroller is implemented as an upgradeable proxy. The Unitroller proxies all logic to the Comptroller implementation, but storage values are set on the Unitroller. To call Unitroller functions, use the Unitroller ABI on the Unitroller address.

JumpRateModel

Each market gets deployed with an interest rate model. The JumpRateModel uses a linear curve to determine interest rates based on supply and demand of the asset until it reaches the kink after which there is a sharp increase in rates.

Liquidator

When a borrow becomes insolvent it may be liquidated. The Liquidator handles this process. When a borrow is liquidated the seized amount is split between the liquidator and the treasury.

​​VTreasury

​Revenue earned by the protocol is kept in the VTreasury.

ComptrollerLens

The ComptrollerLens contains methods for fetching the liquidity of an account and the amount of tokens that can be seized for a repayable amount

SnapshotLens

The SnapshotLens contains methods for getting the details of account for a specific market or all markets where an account is active.

Core Functions

Enter Markets

Enter into a list of markets - it is not an error to enter the same market more than once. In order to supply collateral or borrow in a market, it must be entered first.

Unitroller

function enterMarkets(address[] calldata vTokens) returns (uint[] memory)
  • msg.sender: The account which shall enter the given markets.

  • vTokens: The addresses of the vToken markets to enter.

  • RETURN: For each market, returns an error code indicating whether or not it was entered. Each is 0 on success, otherwise an Error code

ethers.js

const comptroller = await ethers.getContractAt(
    "Comptroller",
    "0xA9D858508491c8c78386d6070e20e18cFA1870AE"
);
const IZIL = await ethers.getContractAt(
    "VBep20Delegator",
    "0x703990825B8612047306e8b8f0fd8b19adF56cD6"
);

const IUSDT = await ethers.getContractAt(
    "VBep20Delegator",
    "0x8811Af7e13043E032E90aFDc4b53C0F2b5809C69"
);

// You can explore the tx object for transaction status, events emitted etc
const tx = await comptroller.enterMarkets(IZIL.address, IUSDT.address);

Exit Markets

Exit a market - it is not an error to exit a market which is not currently entered. Exited markets will not count towards account liquidity calculations.

Unitroller

function exitMarket(address vToken) returns (uint)
  • msg.sender: The account which shall exit the given market.

  • vTokens: The addresses of the vToken markets to exit.

  • RETURN: 0 on success, otherwise an Error code

ethers.js

const comptroller = await ethers.getContractAt(
    "Comptroller",
    "0xA9D858508491c8c78386d6070e20e18cFA1870AE"
);
const IZIL = await ethers.getContractAt(
    "VBep20Delegator",
    "0x703990825B8612047306e8b8f0fd8b19adF56cD6"
);

// You can explore the tx object for transaction status, events emitted etc
const tx = await comptroller.exitMarket(IZIL.address);

Get Assets In

Get the list of markets an account is currently entered into. In order to supply collateral or borrow in a market, it must be entered first. Entered markets count towards account liquidity calculations.

Unitroller

function getAssetsIn(address account) view returns (address[] memory)
  • account: The account whose list of entered markets shall be queried.

  • RETURN: The address of each market which is currently entered into.

ethers.js

const comptroller = await ethers.getContractAt(
    "Comptroller",
    "0xA9D858508491c8c78386d6070e20e18cFA1870AE"
);

const tx = await comptroller.getAssetsIn(userAddress);

Get Account Liquidity

Account Liquidity represents the USD value borrowable by a user, before it reaches liquidation. Users with a shortfall (negative liquidity) are subject to liquidation, and can’t withdraw or borrow assets until Account Liquidity is positive again.

For each market the user has entered into, their supplied balance is multiplied by the market’s collateral factor, and summed; borrow balances are then subtracted, to equal Account Liquidity. Borrowing an asset reduces Account Liquidity for each USD borrowed; withdrawing an asset reduces Account Liquidity by the asset’s collateral factor times each USD withdrawn.

Because the Ionise Protocol exclusively uses unsigned integers, Account Liquidity returns either a surplus or shortfall.

Unitroller

function getAccountLiquidity(address account) view returns (uint, uint, uint)
  • account: The account whose liquidity shall be calculated.

  • RETURN: Tuple of values (error, liquidity, shortfall). The error shall be 0 on success, otherwise an Error code. A non-zero liquidity value indicates the account has available account liquidity. A non-zero shortfall value indicates the account is currently below his/her collateral requirement and is subject to liquidation. At most one of liquidity or shortfall shall be non-zero.

ethers.js

const comptroller = await ethers.getContractAt(
    "Comptroller",
    "0xA9D858508491c8c78386d6070e20e18cFA1870AE"
);

const tx = await comptroller.getAccountLiquidity(userAddress);
const {0: error, 1: liquidity, 2: shortfall} = tx;

Close Factor

The percent, ranging from 0% to 100%, of a liquidatable account's borrow that can be repaid in a single liquidate transaction. If a user has multiple borrowed assets, the closeFactor applies to any single borrowed asset, not the aggregated value of a user’s outstanding borrowing.

Unitroller

function closeFactorMantissa() view returns (uint)
  • RETURN: The closeFactor, scaled by 1e18, is multiplied by an outstanding borrow balance to determine how much could be closed.

ethers.js

const comptroller = await ethers.getContractAt(
    "Comptroller",
    "0xA9D858508491c8c78386d6070e20e18cFA1870AE"
);

const tx = await comptroller.closeFactorMantissa();

Liquidation Incentive

The additional collateral given to liquidators as an incentive to perform liquidation of underwater accounts. For example, if the liquidation incentive is 1.1, liquidators receive an extra 10% of the borrowers collateral for every unit they close.

Unitroller

function liquidationIncentiveMantissa() view returns (uint)
  • RETURN: The liquidationIncentive, scaled by 1e18, is multiplied by the closed borrow amount from the liquidator to determine how much collateral can be seized.

ethers.js

const comptroller = await ethers.getContractAt(
    "Comptroller",
    "0xA9D858508491c8c78386d6070e20e18cFA1870AE"
);

const tx = await comptroller.closeFactorMantissa();

Last updated