Skip to content

Comptroller

Itamar Reif edited this page Nov 12, 2021 · 1 revision

The risk management layer. It determines how much collateral a user is required to maintain, and whether (and by how much) a user can be liquidated. Each time a user interacts with a cToken, the Comptroller is asked to approve or deny the transaction.

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.

enterMarkets(TList(TAddress))

Exit Market

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.

exitMarket(cToken: TAddress)

Update asset price

In order to perform liquidity calculation, Comptroller requires an up-to-date price of operable assets. The price info is received from third-party price oracle. The price info is valid for 5 blocks after it has been updated.

updateAssetPrice(asset)

asset: TAddress - CToken market address

Update Account Liquidity

Updates stored liquidity for the given account. In order to perform the calculation, the following requirements should be fulfilled:

  • updateAssetPrice() should be executed within 5 blocks prior to this call, for all markets entered by the account
  • accrueInterest() should be executed within 5 blocks prior to this call, for all markets entered by the account

Execution of this function is required to perform operations in the markets. The updated value is valid for 5 blocks or until the market operation was executed. The execution of market operation invalidates stored account liquidity value.

updateAccountLiquidity(account)

account: TAddress - The account to calculate liquidity for

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.

getHypoAccountLiquidity(params)

params: TRecord
            data: TAccountLiquidityParams
                cTokenModify: TAddress - The market to hypothetically redeem/borrow in
                account: TAddress - The account to determine liquidity for
                redeemTokens: TNat - The number of tokens to hypothetically redeem
                borrowAmount: TNat - The amount of underlying to hypothetically borrow
            callback: TContract(TInt) - callback to send result to

If the value returned to the callback is lower than 0, it indicates the account is currently below his/her collateral requirement and is subject to liquidation.