Skip to content

MarketFacet

This facet contract contains functions regarding markets

Indicator that this is a Comptroller contract (for inspection)

function isComptroller() public pure returns (bool)

Returns the vToken markets an account has entered in the Core Pool

function getAssetsIn(address account) external view returns (contract VToken[])
NameTypeDescription
accountaddressThe address of the account to query
NameTypeDescription
[0]contract VToken[]assets A dynamic array of vToken markets the account has entered

Return all of the markets

function getAllMarkets() external view returns (contract VToken[])
NameTypeDescription
[0]contract VToken[]The list of market addresses

Calculate number of tokens of collateral asset to seize given an underlying amount

function liquidateCalculateSeizeTokens(address vTokenBorrowed, address vTokenCollateral, uint256 actualRepayAmount) external view returns (uint256, uint256)
NameTypeDescription
vTokenBorrowedaddressThe address of the borrowed vToken
vTokenCollateraladdressThe address of the collateral vToken
actualRepayAmountuint256The amount of vTokenBorrowed underlying to convert into vTokenCollateral tokens
NameTypeDescription
[0]uint256(errorCode, number of vTokenCollateral tokens to be seized in a liquidation)
[1]uint256

Calculate number of tokens of collateral asset to seize given an underlying amount

function liquidateCalculateSeizeTokens(address borrower, address vTokenBorrowed, address vTokenCollateral, uint256 actualRepayAmount) external view returns (uint256, uint256)
NameTypeDescription
borroweraddressAddress of borrower whose collateral is being seized
vTokenBorrowedaddressThe address of the borrowed vToken
vTokenCollateraladdressThe address of the collateral vToken
actualRepayAmountuint256The amount of vTokenBorrowed underlying to convert into vTokenCollateral tokens
NameTypeDescription
[0]uint256(errorCode, number of vTokenCollateral tokens to be seized in a liquidation)
[1]uint256

Calculate number of tokens of collateral asset to seize given an underlying amount

function liquidateVAICalculateSeizeTokens(address vTokenCollateral, uint256 actualRepayAmount) external view returns (uint256, uint256)
NameTypeDescription
vTokenCollateraladdressThe address of the collateral vToken
actualRepayAmountuint256The amount of vTokenBorrowed underlying to convert into vTokenCollateral tokens
NameTypeDescription
[0]uint256(errorCode, number of vTokenCollateral tokens to be seized in a liquidation)
[1]uint256

Returns whether the given account has entered the specified vToken market in the Core Pool

function checkMembership(address account, contract VToken vToken) external view returns (bool)
NameTypeDescription
accountaddressThe address of the account to check
vTokencontract VTokenThe vToken to check
NameTypeDescription
[0]boolTrue if the account is in the asset, otherwise false

Checks whether the given vToken market is listed in the Core Pool (poolId = 0)

function isMarketListed(contract VToken vToken) external view returns (bool)
NameTypeDescription
vTokencontract VTokenThe vToken Address of the market to check
NameTypeDescription
[0]boollisted True if the (Core Pool, vToken) market is listed, otherwise false

Add assets to be included in account liquidity calculation

function enterMarkets(address[] vTokens) external returns (uint256[])
NameTypeDescription
vTokensaddress[]The list of addresses of the vToken markets to be enabled
NameTypeDescription
[0]uint256[]Success indicator for whether each corresponding market was entered

Add assets to be included in account liquidity calculation

function enterMarketBehalf(address onBehalf, address vToken) external returns (uint256)
NameTypeDescription
onBehalfaddressThe address of the account entering the market
vTokenaddressThe address of the vToken market to enable for the account
NameTypeDescription
[0]uint256uint256 indicating the result (0 = success, non-zero = failure)
  • NotAnApprovedDelegate thrown if msg.sender is not the account itself or an approved delegate

Unlists the given vToken market from the Core Pool (poolId = 0) by setting isListed to false

function unlistMarket(address market) external returns (uint256)
NameTypeDescription
marketaddressThe address of the market (vToken) to unlist
NameTypeDescription
[0]uint256uint256 0=success, otherwise a failure (See enum Error for details)

Removes asset from sender’s account liquidity calculation

function exitMarket(address vTokenAddress) external returns (uint256)
NameTypeDescription
vTokenAddressaddressThe address of the asset to be removed
NameTypeDescription
[0]uint256Whether or not the account successfully exited the market

Alias to _supportMarket to support the Isolated Lending Comptroller Interface

function supportMarket(contract VToken vToken) external returns (uint256)
NameTypeDescription
vTokencontract VTokenThe address of the market (token) to list
NameTypeDescription
[0]uint256uint256 0=success, otherwise a failure. (See enum Error for details)

Adds the given vToken market to the Core Pool (poolId = 0) and marks it as listed

function _supportMarket(contract VToken vToken) external returns (uint256)
NameTypeDescription
vTokencontract VTokenThe address of the vToken market to list in the Core Pool
NameTypeDescription
[0]uint256uint256 0=success, otherwise a failure. (See enum Error for details)

Grants or revokes the borrowing or redeeming delegate rights to / from an account If allowed, the delegate will be able to borrow funds on behalf of the sender Upon a delegated borrow, the delegate will receive the funds, and the borrower will see the debt on their account Upon a delegated redeem, the delegate will receive the redeemed amount and the approver will see a deduction in his vToken balance

function updateDelegate(address delegate, bool approved) external
NameTypeDescription
delegateaddressThe address to update the rights for
approvedboolWhether to grant (true) or revoke (false) the borrowing or redeeming rights

Allows a user to switch to a new pool (e.g., e-mode).

function enterPool(uint96 poolId) external
NameTypeDescription
poolIduint96The ID of the pool the user wants to enter.
  • PoolSelected Emitted after a successful pool switch.
  • PoolDoesNotExist The specified pool ID does not exist.
  • AlreadyInSelectedPool The user is already in the target pool.
  • IncompatibleBorrowedAssets The user’s current borrows are incompatible with the new pool.
  • LiquidityCheckFailed The user’s liquidity is insufficient after switching pools.
  • InactivePool The user is trying to enter inactive pool.

Creates a new pool with the given label.

function createPool(string label) external returns (uint96)
NameTypeDescription
labelstringname for the pool (must be non-empty).
NameTypeDescription
[0]uint96poolId The incremental unique identifier of the newly created pool.
  • PoolCreated Emitted after successfully creating a new pool.
  • EmptyPoolLabel Reverts if the provided label is an empty string.

Batch initializes market entries with basic config.

function addPoolMarkets(uint96[] poolIds, address[] vTokens) external
NameTypeDescription
poolIdsuint96[]Array of pool IDs.
vTokensaddress[]Array of market (vToken) addresses.
  • PoolMarketInitialized Emitted after successfully initializing a market in a pool.
  • ArrayLengthMismatch Reverts if poolIds and vTokens arrays have different lengths or if the length is zero.
  • InvalidOperationForCorePool Reverts when attempting to call pool-specific methods on the Core Pool.
  • PoolDoesNotExist Reverts if the target pool ID does not exist.
  • MarketNotListedInCorePool Reverts if the market is not listed in the core pool.
  • MarketAlreadyListed Reverts if the given market is already listed in the specified pool.
  • InactivePool Reverts if attempted to add markets to an inactive pool.

Removes a market (vToken) from the specified pool.

function removePoolMarket(uint96 poolId, address vToken) external
NameTypeDescription
poolIduint96The ID of the pool from which the market should be removed.
vTokenaddressThe address of the market token to remove.
  • PoolMarketRemoved Emitted after a market is successfully removed from a pool.
  • InvalidOperationForCorePool Reverts if called on the Core Pool.
  • PoolMarketNotFound Reverts if the market is not listed in the pool.

Get the core pool collateral factor for a vToken

function getCollateralFactor(address vToken) external view returns (uint256)
NameTypeDescription
vTokenaddressThe address of the vToken to get the collateral factor for
NameTypeDescription
[0]uint256The collateral factor for the vToken, scaled by 1e18

Get the core pool liquidation threshold for a vToken

function getLiquidationThreshold(address vToken) external view returns (uint256)
NameTypeDescription
vTokenaddressThe address of the vToken to get the liquidation threshold for
NameTypeDescription
[0]uint256The liquidation threshold for the vToken, scaled by 1e18

Get the core pool liquidation Incentive for a vToken

function getLiquidationIncentive(address vToken) external view returns (uint256)
NameTypeDescription
vTokenaddressThe address of the vToken to get the liquidation Incentive for
NameTypeDescription
[0]uint256liquidationIncentive The liquidation incentive for the vToken, scaled by 1e18

Get the effective loan-to-value factor (collateral factor or liquidation threshold) for a given account and market.

function getEffectiveLtvFactor(address account, address vToken, enum WeightFunction weightingStrategy) external view returns (uint256)
NameTypeDescription
accountaddressThe account whose pool is used to determine the market’s risk parameters.
vTokenaddressThe address of the vToken market.
weightingStrategyenum WeightFunctionThe weighting strategy to use: - WeightFunction.USE_COLLATERAL_FACTOR to use collateral factor - WeightFunction.USE_LIQUIDATION_THRESHOLD to use liquidation threshold
NameTypeDescription
[0]uint256factor The effective loan-to-value factor, scaled by 1e18.

Get the Effective Liquidation Incentive for a given account and market

function getEffectiveLiquidationIncentive(address account, address vToken) external view returns (uint256)
NameTypeDescription
accountaddressThe account whose pool is used to determine the market’s risk parameters
vTokenaddressThe address of the vToken market
NameTypeDescription
[0]uint256The liquidation Incentive for the vToken, scaled by 1e18

Returns the full list of vTokens for a given pool ID.

function getPoolVTokens(uint96 poolId) external view returns (address[])
NameTypeDescription
poolIduint96The ID of the pool whose vTokens are being queried.
NameTypeDescription
[0]address[]An array of vToken addresses associated with the pool.
  • PoolDoesNotExist Reverts if the given pool ID do not exist.
  • InvalidOperationForCorePool Reverts if called on the Core Pool.

Returns the market configuration for a vToken in the core pool (poolId = 0).

function markets(address vToken) external view returns (bool isListed, uint256 collateralFactorMantissa, bool isVenus, uint256 liquidationThresholdMantissa, uint256 liquidationIncentiveMantissa, uint96 marketPoolId, bool isBorrowAllowed)
NameTypeDescription
vTokenaddressThe address of the vToken whose market configuration is to be fetched.
NameTypeDescription
isListedboolWhether the market is listed and enabled.
collateralFactorMantissauint256The maximum borrowable percentage of collateral, in mantissa.
isVenusboolWhether this market is eligible for VENUS rewards.
liquidationThresholdMantissauint256The threshold at which liquidation is triggered, in mantissa.
liquidationIncentiveMantissauint256The max liquidation incentive allowed for this market, in mantissa.
marketPoolIduint96The pool ID this market belongs to.
isBorrowAllowedboolWhether borrowing is allowed in this market.

Returns the market configuration for a vToken from _poolMarkets.

function poolMarkets(uint96 poolId, address vToken) public view returns (bool isListed, uint256 collateralFactorMantissa, bool isVenus, uint256 liquidationThresholdMantissa, uint256 liquidationIncentiveMantissa, uint96 marketPoolId, bool isBorrowAllowed)
NameTypeDescription
poolIduint96The ID of the pool whose market configuration is being queried.
vTokenaddressThe address of the vToken whose market configuration is to be fetched.
NameTypeDescription
isListedboolWhether the market is listed and enabled.
collateralFactorMantissauint256The maximum borrowable percentage of collateral, in mantissa.
isVenusboolWhether this market is eligible for XVS rewards.
liquidationThresholdMantissauint256The threshold at which liquidation is triggered, in mantissa.
liquidationIncentiveMantissauint256The liquidation incentive allowed for this market, in mantissa.
marketPoolIduint96The pool ID this market belongs to.
isBorrowAllowedboolWhether borrowing is allowed in this market.
  • PoolDoesNotExist Reverts if the given pool ID do not exist.

Returns true if the user can switch to the given target pool, i.e., all markets they have borrowed from are also borrowable in the target pool.

function hasValidPoolBorrows(address account, uint96 targetPoolId) public view returns (bool)
NameTypeDescription
accountaddressThe address of the user attempting to switch pools.
targetPoolIduint96The pool ID the user wants to switch into.
NameTypeDescription
[0]boolbool True if the switch is allowed, otherwise False.