Comptroller
Introduction
The Comptroller is the risk management layer of the Paribus 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 pToken, 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.
Architecture
The Comptroller is made out of two parts, ComptrollerPart1
as well as ComptrollerPart2
. This is due to block size limitations. The Comptroller is implemented as upgradeable proxy. The Unitroller proxies all logic to the Comptroller implementation, but storage values are set on the Unitroller. To call Comptroller functions, use the Comptroller ABI on the Unitroller 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.
Comptroller
msg.sender
: The account which shall enter the given markets.pTokens
: The addresses of the pToken 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.
Solidity
Web3 1.0
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.
Comptroller
msg.sender
: The account which shall exit the given market.pTokens
: The addresses of the pToken market to exit.RETURN
: 0 on success, otherwise an Error code.
Solidity
Web3 1.0
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.
Comptroller
account
: The account whose list of entered markets shall be queried.RETURN
: The address of each market which is currently entered into.
Solidity
Web3 1.0
Collateral Factor
A pToken's collateral factor can range from 0-90%, and represents the proportionate increase in liquidity (borrow limit) that an account receives by minting the pToken. 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 will be increased (or decreased) in the future through Paribus Governance.
Comptroller
pTokenAddress
: The address of the pToken to check if listed and get the collateral factor for.RETURN
: Tuple of values (isListed, collateralFactorMantissa, isComped); isListed represents whether the comptroller recognizes this pToken; 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.
Solidity
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 Paribus Protocol exclusively uses unsigned integers, Account Liquidity returns either a surplus or shortfall.
Comptroller
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.
Solidity
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.
Comptroller
RETURN
: The closeFactor, scaled by 1e18, is multiplied by an outstanding borrow balance to determine how much could be closed.
Solidity
Web3 1.0
Liquidation Incentive
The additional collateral given to liquidators as an incentive to perform liquidation of underwater accounts. A portion of this is given to the collateral pToken reserves as determined by the seize share. The seize share is assumed to be 0 if the pToken does not have a protocolSeizeShareMantissa
constant. For example, if the liquidation incentive is 1.08, and the collateral's seize share is 1.028, liquidators receive an extra 5.2% of the borrower's collateral for every unit they close, and the remaining 2.8% is added to the pToken's reserves.
Comptroller
RETURN
: The liquidationIncentive, scaled by 1e18, is multiplied by the closed borrow amount from the liquidator to determine how much collateral can be seized.
Solidity
Web3 1.0
Key Events
{: .key-events-table }
Error Codes
Failure Info
PBX Distribution Speeds
PBX Distributed Per Block (Single Borrow Market)
The Comptroller contract has a mapping called PBXBorrowSpeeds
. It maps pToken addresses to an integer of each market’s PBX distribution per Ethereum block. The integer indicates the rate at which the protocol distributes PBX to markets’ borrowers. The value is the amount of PBX (in wei), per block, allocated for the market. Note that not every market has PBX distributed to its participants (see Market Metadata). The speed indicates how much PBX goes to the borrowers. The code examples implement reading the amount of PBX distributed, per Ethereum block, to a single borrow market.
Comptroller
Solidity
Web3 1.2.6
PBX Distributed Per Block (Single Supply Market)
The Comptroller contract has a mapping called PBXSupplySpeeds
. It maps pToken addresses to an integer of each market’s PBX distribution per Ethereum block. The integer indicates the rate at which the protocol distributes PBX to markets’ suppliers. The value is the amount of PBX (in wei), per block, allocated for the market. Note that not every market has PBX distributed to its participants (see Market Metadata). The speed indicates how much PBX goes to the suppliers. The code examples implement reading the amount of PBX distributed, per Ethereum block, to a single supplier market.
Comptroller
Solidity
Web3 1.2.6
Claim PBX
Every Paribus user accrues PBX for each block they are supplying to or borrowing from the protocol. Users may call the Comptroller's claimPBX
method at any time to transfer PBX accrued to their address.
Comptroller
Solidity
Web3 1.2.6
Market Metadata
The Comptroller contract has an array called getAllMarkets
that contains the addresses of each pToken contract. Each address in the getAllMarkets
array can be used to fetch a metadata struct in the Comptroller’s markets constant. See the ComptrollerPart1 contract for the Market struct definition.
Comptroller
Solidity
Web3 1.2.6
Last updated