Comptroller
[Draft version] the risk management layer of the Lendland protocol
The Comptroller is the risk management layer of the Lendland
protocol; 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 eToken, the Comptroller is asked to approve or deny the transaction.
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.
Enter Markets
Enter into a list of markets. In order to supply collateral or borrow in a market, it must be entered first.
function enterMarkets(address[] memory eTokens) public returns (uint[] memory)
msg.sender: The account which shall enter the given markets.
eTokens: The addresses of the eToken markets to enter.
RETURN: For each market, returns an error code indicating whether or not it was entered. Each is 0 on success,
Exit Market
Exited markets will not count towards account liquidity calculations.
function exitMarket(address eTokenAddress) external returns (uint)
msg.sender: The account which shall exit the given market.
eTokens: The addresses of the eToken market to exit.
RETURN: 0 on success
Collateral Factor
A eToken's collateral factor can range from 0-90%, and represents the proportionate increase in liquidity (borrow limit) that an account receives by minting the eToken.
Generally, large or liquid assets have high collateral factors, while small or illiquid assets have low collateral factors. If an asset has a 0% collateral factor, it can't be used as collateral (or seized in liquidation), though it can still be borrowed.
function markets(address eTokenAddress) view returns (bool, uint, bool)
eTokenAddress: The address of the cToken to check if listed and get the collateral factor for.
RETURN: Tuple of values (isListed, collateralFactorMantissa, isComped); isListed represents whether the comptroller recognizes this cToken; collateralFactorMantissa, scaled by 1e18, is multiplied by a supply balance to determine how much value can be borrowed. The isComped boolean indicates whether or not suppliers and borrowers are distributed COMP tokens
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 Lendland Protocol exclusively uses unsigned integers, Account Liquidity returns either a surplus or shortfall.
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.
Close Factor
The percent, ranging from 0% to 100%, of a liquidable 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.
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.
Last updated
Was this helpful?