Controller
Introduction
The Contoller is the risk management layer of the Ram 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 rToken, the Controller is asked to approve or deny the transaction.
The Controller 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.
Architecture
The Controller is implemented as an upgradeable proxy. The ControllerProxy proxies all logic to the Controller implementation, but storage values are set on the ControllerProxy. To call Controller functions, use the Controller ABI on the ControllerProxy address.
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.
Controller
msg.sender: The account which shall enter the given markets.
rTokens: The addresses of the rToken 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.
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.
Controller
msg.sender: The account which shall exit the given market.
rTokens: The addresses of the rToken market to exit.
RETURN: 0 on success, otherwise an Error code.
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.
Controller
account: The account whose list of entered markets shall be queried.
RETURN: The address of each market which is currently entered into.
Web3 1.0
Collateral Factor
A rToken's collateral factor can range from 0-90%, and represents the proportionate increase in liquidity (borrow limit) that an account receives by minting the rToken.
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.
Collateral factors can be increased (or decreased) through admin, as market conditions change.
Controller
rTokenAddress: The address of the rToken to check if listed and get the collateral factor for.
RETURN: Tuple of values (isListed, collateralFactorMantissa, isRammed); isListed represents whether the controller recognizes this rToken; collateralFactorMantissa, scaled by 1e18, is multiplied by a supply balance to determine how much value can be borrowed. The isRammed boolean indicates whether or not suppliers and borrowers are distributed RAM tokens.
Web3 1.0
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 Ram Protocol exclusively uses unsigned integers, Account Liquidity returns either a surplus or shortfall.
Controller
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.
Web3 1.0
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.
Controller
RETURN: The closeFactor, scaled by 1e18, is multiplied by an outstanding borrow balance to determine how much could be closed.
Web3 1.0
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.
Controller
RETURN: The liquidationIncentive, scaled by 1e18, is multiplied by the closed borrow amount from the liquidator to determine how much collateral can be seized.
Web3 1.0
Key Events
Error Codes
Failure Info
RAM Distribution Speeds
RAM Speed
The "RAM speed" unique to each market is an unsigned integer that specifies the amount of RAM that is distributed, per block, to suppliers and borrowers in each market. This number can be changed for individual markets by calling the _setRamSpeed method through admin or auto decay.
The following is the formula for calculating the rate that RAM is distributed to each supported market.
RAM Distributed Per Block (All Markets)
The Controller contract’s ramRate is an unsigned integer that indicates the rate at which the protocol distributes RAM to markets’ suppliers or borrowers, every ThunderCore block. The value is the amount of RAM (in wei), per block, allocated for the markets. Note that not every market has RAM distributed to its participants (see Market Metadata).
The ramRate indicates how much RAM goes to the suppliers or borrowers, so doubling this number shows how much RAM goes to all suppliers and borrowers combined. The code examples implement reading the amount of RAM distributed, per ThunderCore block, to all markets.
Controller
Web3 1.2.6
RAM Distributed Per Block (Single Market)
The Controller contract has a mapping called ramSpeeds. It maps rToken addresses to an integer of each market’s RAM distribution per ThunderCore block. The integer indicates the rate at which the protocol distributes RAM to markets’ suppliers or borrowers. The value is the amount of RAM (in wei), per block, allocated for the market. Note that not every market has RAM distributed to its participants (see Market Metadata).
The speed indicates how much RAM goes to the suppliers or the borrowers, so doubling this number shows how much RAM goes to market suppliers and borrowers combined. The code examples implement reading the amount of RAM distributed, per ThunderCore block, to a single market.
Controller
Web3 1.2.6
Claim RAM
Every Ram user accrues RAM for each block they are supplying to or borrowing from the protocol. Users may call the Controller's claimRam method at any time to transfer RAM accrued to their address.
Controller
Web3 1.2.6
Market Metadata
The Controller contract has an array called getAllMarkets that contains the addresses of each rToken contract. Each address in the getAllMarkets array can be used to fetch a metadata struct in the Controller’s markets constant.
Controller
Web3 1.2.6
Last updated