πŸ‘€
Lens
This contract exposes an interface to query on-chain data related to the Morpho Protocol, its markets, and its users.
Morpho's Lens exposes generic information about the protocol, its markets and its users, such as the total supply in USD for example. Anyone can query it off-chain through Etherscan or with ethers.js, or on-chain using a Smart Contract. Learn more with examples here.
Compound requires supply & borrow indexes of each market to be manually updated. This implies that taking into account accrued interests since each last market's index update requires additional gas for each market and cannot be done in a view. Morpho-Compound simulates this update (with exact precision) and thus sometimes require a list of markets to be passed as argument (of which to virtually update supply & borrow indexes; the more you provide, the higher the gas cost of calling such a function).
Providing an empty array or an array with unknown addresses (such as address(0)) will not compute any virtual index update.

Rates

Querying supply/borrow rates on Morpho is straight-forward. Though, one must understand that a Morpho user can be either on the underlying pool or matched peer-to-peer.
Hence, users benefit from a custom rate, depending on the proportion of their liquidity matched peer-to-peer. Their rate is thus located somewhere between the underlying pool's rate and Morpho's peer-to-peer rate.
Remark that the worse case scenario for the user is when all its liquidity is on the pool, at the pool rate. Conversely, the best case scenario is when the user's liquidity is fully matched peer-to-peer, at Morpho's peer-to-peer rate.
On Morpho-Compound, rates are given per block (as on Compound), meaning that computing a yearly rate should be done using the following formulas:
APR=ratePerBlockΓ—nbBlocksPerYearAPR = ratePerBlock \times nbBlocksPerYear
APY=(1+ratePerBlock)nbBlocksPerYearβˆ’1APY = (1 + ratePerBlock) ^{nbBlocksPerYear} - 1
The value of nbBlocksPerYear is yet to be chosen by the developer, though assuming 4 blocks / minute is a minimum blockchain velocity, nbBlocksPerYear should at least be 2,102,400.
Comparing Morpho-Compound's rates per block to Compound's rates per block is much easier, as they are both expressed in the same unit. For example:
lens.getAverageSupplyRatePerBlock(cDai) > cDai.supplyRatePerBlock() reflects that a supplier on Morpho is on average benefitting from a better yield through Morpho-Compound than on Compound.
On Morpho-AaveV2, rates are given per year, non-compounding (as on Aave V2), meaning that computing a yearly rate should be done using the following formula:
APY=(1+ratePerYearsecondsPerYear)secondsPerYearβˆ’1APY = (1 + \frac{ratePerYear}{secondsPerYear}) ^{secondsPerYear} - 1
Comparing Morpho-AaveV2's rates per block to AaveV2's rates per block is much easier, as they are both expressed in the same unit. For example:
lens.getAverageSupplyRatePerBlock(aDai) > pool.getReserveData(dai).currentLiquidityRate reflects that a supplier on Morpho is on average benefitting from a better yield through Morpho-AaveV2 than on Aave V2.

getAverageSupplyRatePerBlock()

On Morpho-AaveV2: getAverageSupplyRatePerYear()
Computes and returns the current supply rate per block (in WAD) experienced by Morpho users on average on a given market.
This function is recommended for data platforms and strategists, as it reflects the real rate you can expect to have on Morpho as a supplier.
The keyword average is used because each Morpho supplier benefits from a custom supply rate, depending on the proportion of their liquidity matched peer-to-peer; thus higher than the underlying protocol's pool supply rate but may be lower than Morpho's peer-to-peer supply rate. Note again that, in the worst case, a user experiences the pool supply rate.
function getAverageSupplyRatePerBlock(
address _poolTokenAddress
)
view
returns (
uint256 avgSupplyRatePerBlock,
uint256 p2pSupplyAmount,
uint256 poolSupplyAmount
)
Input parameter
Input type
Description
_poolTokenAddress
address
The address of the underlying protocol's pool token of which to query the average supply rate.
Return value
Return type
Description
avgSupplyRatePerBlock
uint256
The supply rate per block experienced on average on the given market (in WAD).
p2pSupplyAmount
uint256
The total amount of underlying ERC20 tokens supplied through Morpho matched peer-to-peer on the given market.
poolSupplyAmount
uint256
The total amount of underlying ERC20 tokens supplied through Morpho on the pool.

getAverageBorrowRatePerBlock()

On Morpho-AaveV2: getAverageBorrowRatePerYear()
Computes and returns the current borrow rate per block (in WAD) experienced on average on a given market.
This function is recommended for data platforms and strategists, as it reflects the real rate you can expect to have on Morpho as a borrower.
The keyword average is used because a Morpho Borrower benefits from a custom supply rate, depending on the proportion of their liquidity matched peer-to-peer; thus lower than the underlying protocol's pool borrow rate but may be higher than Morpho's peer-to-peer borrow rate.
function getAverageBorrowRatePerBlock(
address _poolTokenAddress
)
view
returns (
uint256 avgBorrowRatePerBlock,
uint256 p2pBorrowAmount,
uint256 poolBorrowAmount
)
Input parameter
Input type
Description
_poolTokenAddress
address
The address of the underlying protocol's pool token of which to query the average borrow rate.
Return value
Return type
Description
avgBorrowRatePerBlock
uint256
The borrowing rate per block experienced on average on the given market (in WAD).
p2pBorrowAmount
uint256
The total amount of underlying ERC20 tokens borrowed through Morpho and matched peer-to-peer on the given market.
poolBorrowAmount
uint256
The total amount of underlying ERC20 tokens borrowed through Morpho from the underlying pool.

getNextUserSupplyRatePerBlock()

On Morpho-AaveV2: getNextUserSupplyRatePerYear()
Computes and returns the minimum supply rate per block (in WAD) a supplier could experience on a given market if they were to supply a given amount. This function simulates parts of Morpho's matching engine, matching the supplier with the first borrower waiting to be matched through Morpho and/or with a borrow delta, if there is one. Note that if a supplier is not matched instantly, he can be matched later - eg. when new borrowers come in - and will thus experience a higher rate.
The simulated supply rate is a lower bound, meaning that if the user was to supply the given amount on the given market, they would at worst benefit from the returned supply rate but may also benefit from a higher supply rate if they are matched with more than the first borrower; or if they are automatically matched with a borrower later.
function getNextUserSupplyRatePerBlock(
address _poolTokenAddress,
address _user,
uint256 _amount
)
view
returns (
uint256 nextSupplyRatePerBlock,
uint256 balanceOnPool,
uint256 balanceInP2P,
uint256 totalBalance
)
On Morpho-AaveV2, the peer-to-peer-related data is always returned first:
function getNextUserSupplyRatePerYear(
address _poolTokenAddress,
address _user,
uint256 _amount
)
view
returns (
uint256 nextSupplyRatePerYear,
uint256 balanceInP2P,
uint256 balanceOnPool,
uint256 totalBalance
)
Input parameter
Input type
Description
_poolTokenAddress
address
The address of the underlying protocol's pool token to hypothetically supply to.
_user
address
The address of the hypothetical supplier.
_amount
uint256
The amount of underlying ERC20 tokens to hypothetically supply.
Return value
Return type
Description
nextSupplyRatePerBlock
uint256
The hypothetical supply rate per block experienced by the user on the given market (in WAD).
balanceOnPool
uint256
The hypothetical total amount of underlying ERC20 tokens supplied through Morpho on the underlying pool after the simulation.
balanceInP2P
uint256
The hypothetical total amount of underlying ERC20 tokens supplied through Morpho and matched peer-to-peer after the simulation.
totalBalance
uint256
Equals balanceOnPool + balanceInP2P, only used for gas savings.

getNextUserBorrowRatePerBlock()

On Morpho-AaveV2: getNextUserBorrowRatePerYear()
Computes and returns the maximum borrow rate per block (in WAD) a borrower could experience on a given market if they were to borrow a given amount. This function simulates parts of Morpho's matching engine, matching the borrower with the first supplier waiting to be matched through Morpho and/or with a supply delta (if there is one).
The simulated borrow rate is an upper bound, meaning that if the user was to borrow the given amount on the given market, they would at worst benefit from the returned borrow rate but may also benefit from a lower borrow rate if they are matched with more than the first supplier; or if they are automatically matched with a supplier later.
function getNextUserBorrowRatePerBlock(
address _poolTokenAddress,
address _user,
uint256 _amount
)
view
returns (
uint256 nextBorrowRatePerBlock,
uint256 balanceOnPool,
uint256 balanceInP2P,
uint256 totalBalance
)
On Morpho-AaveV2, the peer-to-peer-related data is always returned first:
function getNextUserBorrowRatePerYear(
address _poolTokenAddress,
address _user,
uint256 _amount
)
view
returns (
uint256 nextBorrowRatePerYear,
uint256 balanceInP2P,
uint256 balanceOnPool,
uint256 totalBalance
)
Input parameter
Input type
Description
_poolTokenAddress
address
The address of the underlying protocol's pool token to hypothetically borrow from.
_user
address
The address of the hypothetical borrower.
_amount
uint256
The amount of underlying ERC20 tokens to hypothetically borrow.
Return value
Return type
Description
nextBorrowRatePerBlock
uint256
The hypothetical borrow rate per block experienced by the user on the given market (in WAD).
balanceOnPool
uint256
The hypothetical total amount of underlying ERC20 tokens borrowed through Morpho from the underlying pool after the simulation.
balanceInP2P
uint256
The hypothetical total amount of underlying ERC20 tokens borrowed through Morpho and matched peer-to-peer after the simulation.
totalBalance
uint256
Equals balanceOnPool + balanceInP2P, only used for gas savings.

getCurrentUserSupplyRatePerBlock()

On Morpho-AaveV2: getCurrentUserSupplyRatePerYear()
Computes and returns the current supply rate experienced by a user on a given market on Morpho.
function getCurrentUserSupplyRatePerBlock(
address _poolTokenAddress,
address _user
)
view
returns (
uint256 supplyRatePerBlock
)
Input parameter
Input type
Description
_poolTokenAddress
address
The address of the underlying protocol's pool token of which to get the experienced supply rate.
_user
address
The address of the user to query the supply rate for.
Return value
Return type
Description
supplyRatePerBlock
uint256
The experienced supply rate per block of the given user on the given market (in wad).

getCurrentUserBorrowRatePerBlock()

On Morpho-AaveV2: getCurrentUserBorrowRatePerYear()
Computes and returns the current borrow rate experienced by a user on a given market on Morpho.
function getCurrentUserBorrowRatePerBlock(
address _poolTokenAddress,
address _user
)
view
returns (
uint256 borrowRatePerBlock
)
Input parameter
Input type
Description
_poolTokenAddress
address
The address of the underlying protocol's pool token of which to get the experienced borrow rate.
_user
address
The address of the user to query the supply rate for.
Return value
Return type
Description
borrowRatePerBlock
uint256
The experienced borrow rate per block of the given user on the given market (in wad).

getRatesPerBlock()

On Morpho-AaveV2: getRatesPerYear()
Computes and returns supply and borrowing rates from the underlying protocol's pool and peer-to-peer rates of a given market.
This should only be used for advanced usage. Please refer to getAverageSupplyRatePerBlock() and getAverageBorrowRatePerBlock() for more straight-forward market rates.
function getRatesPerBlock(
address _poolTokenAddress
)
view
returns (
uint256 p2pSupplyRate,
uint256 p2pBorrowRate,
uint256 poolSupplyRate,
uint256 poolBorrowRate
)
Input parameter
Input type
Description
_poolTokenAddress
address
The address of the underlying protocol's pool token of which to get rates.
Return value
Return type
Description
p2pSupplyRate
uint256
The peer-to-peer supply rate per block of the given market (in WAD).
p2pBorrowRate
uint256
The peer-to-peer borrow rate per block of the given market (in WAD).
poolSupplyRate
uint256
The underlying pool's supply rate per block of the given market (in WAD).
poolBorrowRate
uint256
The underlying pool's borrow rate per block of the given market (in WAD).

Markets

isMarketCreated()

Returns whether a given underlying protocol's pool token corresponds to a created market on Morpho.
function isMarketCreated(
address _poolTokenAddress
)
view
returns (bool)
Input parameter
Input type
Description
_poolTokenAddress
address
The address of the underlying protocol's pool token.
Return value
Return type
Description
isMarketCreated
bool
Whether the given pool token corresponds to a market created on Morpho.

isMarketCreatedAndNotPaused()

Returns whether a given underlying protocol's pool token corresponds to a created, not fully paused market on Morpho.
function isMarketCreatedAndNotPaused(
address _poolTokenAddress
)
view
returns (bool)
Input parameter
Input type
Description
_poolTokenAddress
address
The address of the underlying protocol's pool token.
Return value
Return type
Description
isMarketCreated
bool
Whether the given pool token corresponds to a market created and not entirely paused on Morpho.

isMarketCreatedAndNotPausedNorPartiallyPaused()

Returns whether a given underlying protocol's pool token corresponds to a created and unpaused market on Morpho.
function isMarketCreatedAndNotPausedNorPartiallyPaused(
address _poolTokenAddress
)
view
returns (bool)
Input parameter
Input type
Description
_poolTokenAddress
address
The address of the underlying protocol's pool token.
Return value
Return type
Description
isMarketCreated
bool
Whether the given pool token corresponds to a market created and unpaused on Morpho.

getAllMarkets()

Returns the list of pool token addresses corresponding to created markets on Morpho.
function getAllMarkets()
view
returns (address[] memory marketsCreated)
Return value
Return type
Description
marketsCreated
address[]
The list of pool token addresses corresponding to created markets on Morpho.

getMainMarketData()

Returns main market data related to the state of a given market.
function getMainMarketData(
address _poolTokenAddress
)
view
returns (
uint256 avgSupplyRatePerBlock,
uint256 avgBorrowRatePerBlock,
uint256 p2pSupplyAmount,
uint256 p2pBorrowAmount,
uint256 poolSupplyAmount,
uint256 poolBorrowAmount
)
Input parameter
Input type
Description
_poolTokenAddress
address
The address of the underlying protocol's pool token.
Return value
Return type
Description
avgSupplyRatePerBlock
uint256
The supply rate per block experienced on average on the given market (in WAD).
avgBorrowRatePerBlock
uint256
The borrow rate per block experienced on average on the given market (in WAD).
p2pSupplyAmount
uint256
The total amount of underlying ERC20 tokens supplied through Morpho and matched peer-to-peer, on the given market.
p2pBorrowAmount
uint256
The total amount of underlying ERC20 tokens borrowed through Morpho and matched peer-to-peer, on the given market.
poolSupplyAmount
uint256
The total amount of underlying ERC20 tokens supplied through Morpho on the underlying pool.
poolBorrowAmount
uint256
The total amount of underlying ERC20 tokens borrowed through Morpho from the underlying pool.

getAdvancedMarketData()

Returns advanced market data related to the state of a given market.
function getAdvancedMarketData(
address _poolTokenAddress
)
view
returns (
uint256 p2pSupplyIndex,
uint256 p2pBorrowIndex,
uint256 poolSupplyIndex,
uint256 poolBorrowIndex,
uint32 lastUpdateBlockNumber,
uint256 p2pSupplyDelta,
uint256 p2pBorrowDelta
)
On Morpho-AaveV2, lastUpdateBlockNumber is replaced with lastUpdateTimestamp.
Input parameter
Input type
Description
_poolTokenAddress
address
The address of the underlying protocol's pool token.
Return value
Return type
Description
p2pSupplyIndex
uint256
The peer-to-peer supply index used to track supply interests accrued on the given market.
p2pBorrowIndex
uint256
The peer-to-peer supply index used to track borrow interests accrued on the given market.
poolSupplyIndex
uint256
The underlying protocol's pool supply index (e.g. on Compound: cToken's exchange rate).
poolBorrowIndex
uint256
The underlying protocol's pool borrow index.
lastUpdateBlockNumber
uint32
The block number of the last time indexes were last updated on Morpho. On Morpho-AaveV2, this is replaced with lastUpdateTimestamp: the block.timestamp of the last indexes update.
p2pSupplyDelta
uint256
The total amount of underlying ERC20 tokens supplied through Morpho, stored as matched peer-to-peer but supplied on the underlying pool (cf. Delta mechanism for further details).
p2pBorrowDelta
uint256
The total amount of underlying ERC20 tokens borrow through Morpho, stored as matched peer-to-peer but borrowed from the underlying pool (cf. Delta mechanism for further details).

getMarketConfiguration()

Returns advanced market data related to the state of a given market.
function getMarketConfiguration(
address _poolTokenAddress
)
view
returns (
address underlying,
bool isCreated,
bool p2pDisabled,
bool isPaused,
bool isPartiallyPaused,
uint16 reserveFactor,
uint16 p2pIndexCursor,
uint256 collateralFactor
)
On Morpho-AaveV2, collateralFactor is not returned. You can instead query loanToValue and liquidationThreshold from Aave V2 with pool.getConfiguration.
Input parameter
Input type
Description
_poolTokenAddress
address
The address of the underlying protocol's pool token.
Return value
Return type
Description
underlying
address
The address of the underlying ERC20 token of the given market.
isCreated
bool
Whether the market is created on Morpho.
p2pDisabled
bool
Whether the market has peer-to-peer matches disabled (in case accruing rewards from the underlying protocol's pool is more profitable).
isPaused
bool
Whether the market is fully paused (no interaction allowed) on Morpho.
isPartiallyPaused
bool
Whether the market is partially paused (only repay and withdraw are allowed) on Morpho.
reserveFactor
uint16
The percentage of interests accrued taken out to Morpho's reserve (in bps).
p2pIndexCursor
uint16
The peer-to-peer central rate's position between the underlying pool's supply rate and its borrow rate (in bps, 0% = supply rate, 100% = borrow rate).
collateralFactor
uint256
The collateral factor used on the given market (same as the underlying protocol's pool).

getTotalMarketSupply()

Computes and returns the sum of all the underlying ERC20 supplied through Morpho, matched peer-to-peer and supplied to the underlying protocol's pool.
function getTotalMarketSupply(
address _poolTokenAddress
)
view
returns (
uint256 p2pSupplyAmount,
uint256 poolSupplyAmount,
uint256 supplyDeltaAmount
)
Input parameter
Input type
Description
_poolTokenAddress
address
The address of the underlying protocol's pool token.
Return value
Return type
Description
p2pSupplyAmount
uint256
The amount of underlying ERC20 tokens supplied through Morpho and matched peer-to-peer.
poolSupplyAmount
uint256
The amount of underlying ERC20 tokens supplied through Morpho to the underlying pool.

getTotalMarketBorrow()

Computes and returns the sum of all the underlying ERC20 borrowed through Morpho, matched peer-to-peer and borrowed from the underlying protocol's pool.
function getTotalMarketBorrow(
address _poolTokenAddress
)
view
returns (
uint256 p2pBorrowAmount,
uint256 poolBorrowAmount,
uint256 borrowDeltaAmount
)
Input parameter
Input type
Description
_poolTokenAddress
address
The address of the underlying protocol's pool token.
Return value
Return type
Description
p2pBorrowAmount
uint256
The amount of underlying ERC20 tokens borrowed through Morpho and matched peer-to-peer.
poolBorrowAmount
uint256
The amount of underlying ERC20 tokens borrowed through Morpho from the underlying pool.

Users

getEnteredMarkets()

Returns the list of markets a given user is currently supplying to or borrowing from.
function getEnteredMarkets(
address _user
)
view
returns (
address[] memory enteredMarkets
)
Input parameter
Input type
Description
_user
address
The address of the user of whom to query entered markets.
Return value
Return type
Description
enteredMarkets
address[]
The list of markets the given user is currently supplying to or borrowing from.

getUserMaxCapacitiesForAsset()

considering
function getUserMaxCapacitiesForAsset(
address _user,
address _poolTokenAddress
)
view
returns (
uint256 withdrawable,
uint256 borrowable
)
Input parameter
Input type
Description
_user
address
The address of the user of whom to query max capacities.
_poolTokenAddress
address
The address of the underlying protocol's pool token of which to query the given user's max capacities.
Return value
Return type
Description
withdrawable
uint256
The maximum amount of underlying ERC20 tokens the user can withdraw, without getting liquidated.
borrowable
uint256
The maximum amount of underlying ERC20 tokens the user can currently borrow, without getting liquidated.

getUserHealthFactor()

Computes and returns the health factor (in WAD) of a given user, taking into account accrued interests on the markets optionally passed. Liquidation should occur as soon as the returned health factor is less than 1 WAD = 1 ether = 1e18.
The health factor is calculated at the protocol level, across all entered markets: the list of markets passed as argument is only used to virtually update the market's supply & borrow indexes, to take into account accrued interests since each last market's index update (the more you provide, the higher the gas cost of calling this function).
Providing an empty array or an array with unknown addresses (such as address(0)) will not compute any virtual index update.
function getUserHealthFactor(
address _user,
address[] calldata _updatedMarkets
)
view
returns (
uint256 healthFactor
)
Input parameter
Input type
Description
_user
address
The address of the user.
_updatedMarkets
address[]
The list of markets to virtually update during computation to take into account interests accrued by the user.
Return value
Return type
Description
healthFactor
uint256
The current health factor of the user (in WAD).

isLiquidatable()

Returns whether the given user is liquidatable, taking into account accrued interests on the markets optionally passed.
function isLiquidatable(
address _user,
address[] calldata _updatedMarkets
)
view
returns (
bool
)
Input parameter
Input type
Description
_user
address
The address of the user.
_updatedMarkets
address[]
The list of markets to virtually update during computation to consider interests accrued by the user. Borrowed & collateral markets are always appended.
Return value
Return type
Description
isLiquidatable
bool
Whether the given user is liquidatable.

computeLiquidationRepayAmount()

Computes the maximum amount a liquidator could hypothetically repay on behalf of a given user (in this case, the liquidatee). The amount is zero if the given user is not liquidatable on the given market.
function computeLiquidationRepayAmount(
address _user,
address _poolTokenBorrowedAddress,
address _poolTokenCollateralAddress,
address[] calldata _updatedMarkets
)
view
returns (
uint256 toRepay
)
Input parameter
Input type
Description
_user
address
The address of the hypothetical liquidatee.
_poolTokenBorrowedAddress
address
The address of the underlying protocol's pool token borrowed by the user to repay.
_poolTokenCollateralAddress
address
The address of the underlying protocol's pool token used as collateral to seize to the liquidator.
_updatedMarkets
address[]
The list of markets to virtually update during computation to consider interests accrued by the user. Borrowed & collateral markets are always appended.
Return value
Return type
Description
toRepay
uint256
The maximum amount of underlying ERC20 tokens a liquidator can repay on behalf of the liquidatee per transaction.

getUserHypotheticalBalanceStates()

​
function getUserHypotheticalBalanceStates(
address _user,
address _poolTokenAddress,
uint256 _withdrawnAmount,
uint256 _borrowedAmount
)
view
returns (
uint256 debtValue, uint256 maxDebtValue
)
Input parameter
Input type
Description
_user
address
The address of the user.
_poolTokenAddress
address
The address of the underlying protocol's pool token.
_withdrawnAmount
uint256
The hypothetical amount of underlying ERC20 tokens the user withdraws from the market. Pass 0 to get updated balances.
_borrowedAmount
uint256
The hypothetical amount of underlying ERC20 tokens the user borrows from the market. Pass 0 to get updated balances.
Return value
Return type
Description
debtValue
uint256
The current debt value of the user (in USD, 18 decimals).
maxDebtValue
uint256
The maximum debt value the user can have (in USD, 18 decimals).

getCurrentSupplyBalanceInOf()

Computes and returns the total amount of underlying ERC20 token a given user has supplied through Morpho on a given market, taking into account interests accrued.
function getCurrentSupplyBalanceInOf(
address _poolTokenAddress,
address _user
)
view
returns (
uint256 balanceOnPool,
uint256 balanceInP2P,
uint256 totalBalance
)
On Morpho-AaveV2, the peer-to-peer balance is always returned first:
function getCurrentSupplyBalanceInOf(
address _poolTokenAddress,
address _user
)
view
returns (
uint256 balanceInP2P,
uint256 balanceOnPool,
uint256 totalBalance
)
Input parameter
Input type
Description
_user
address
The address of the user.
_poolTokenAddress
address
The address of the underlying protocol's pool token.
Return value
Return type
Description
balanceOnPool
uint256
The total amount of underlying ERC20 tokens the user has supplied through Morpho on the underlying protocol's pool.
balanceInP2P
uint256
The total amount of underlying ERC20 tokens the user has supplied through Morpho that is matched peer-to-peer.
totalBalance
uint256
Equals balanceOnPool + balanceInP2P, only used for gas savings.

getCurrentBorrowBalanceInOf()

Computes and returns the total amount of underlying ERC20 token a given user has borrowed through Morpho from a given market, taking into account the accrued interests.
function getCurrentBorrowBalanceInOf(
address _poolTokenAddress,
address _user
)
view
returns (
uint256 balanceOnPool,
uint256 balanceInP2P,
uint256 totalBalance
)
On Morpho-AaveV2, the peer-to-peer balance is always returned first:
function getCurrentBorrowBalanceInOf(
address _poolTokenAddress,
address _user
)
view
returns (
uint256 balanceInP2P,
uint256 balanceOnPool,
uint256 totalBalance
)
Input parameter
Input type
Description
_user
address
The address of the user.
_poolTokenAddress
address
The address of the underlying protocol's pool token.
Return value
Return type
Description
balanceOnPool
uint256
The total amount of underlying ERC20 tokens the user has borrowed through Morpho from the underlying protocol's pool.
balanceInP2P
uint256
The total amount of underlying ERC20 tokens the user has borrowed through Morpho is matched peer-to-peer.
totalBalance
uint256
Equals balanceOnPool + balanceInP2P, only used for gas savings.

Rewards

getUserUnclaimedRewards()

Computes and returns the total amount of unclaimed rewards a given user accrued on a given market list.
function getUserUnclaimedRewards(
address[] calldata _poolTokenAddresses,
address _user
)
view
returns (
uint256 unclaimedRewards
)
On Morpho-AaveV2, this function is not available as no rewards are currently distributed by Aave V2.
Input parameter
Input type
Description
_poolTokenAddresses
address[]
The list of addresses of the underlying protocol's pools to query unclaimed rewards.
_user
address
The address of the user to whom to query unclaimed rewards.
Return value
Return type
Description
unclaimedRewards
uint256
The total amount of ERC20 reward tokens accrued by the given user on the market.

Indexes

getCurrentP2PSupplyIndex()

Computes and returns Morpho's virtually updated peer-to-peer supply index. It is used to calculate updated supply balances on Morpho.
function getCurrentP2PSupplyIndex(
address _poolTokenAddress
)
view
returns (
uint256 currentP2PSupplyIndex
)
Input parameter
Input type
Description
_poolTokenAddress
address
The underlying protocol's pool token address.
Return value
Return type
Description
currentP2PSupplyIndex
uint256
The current, virtually updated peer-to-peer supply index.

getCurrentP2PBorrowIndex()

Computes and returns Morpho's virtually updated peer-to-peer borrow index. It is used to calculate updated borrow balances on Morpho.
function getCurrentP2PBorrowIndex(
address _poolTokenAddress
)
view
returns (
uint256 currentP2PBorrowIndex
)
Input parameter
Input type
Description
_poolTokenAddress
address
The underlying protocol's pool token address.
Return value
Return type
Description
currentP2PBorrowIndex
uint256
The current, virtually updated peer-to-peer borrow index.

getCurrentPoolIndexes()

Computes and returns virtually updated pool indexes. It is used to calculate updated supply and borrow balances on the underlying pool.
function getCurrentPoolIndexes(
address _poolTokenAddress
)
view
returns (
uint256 currentPoolSupplyIndex,
uint256 currentPoolBorrowIndex
)
On Morpho-AaveV2, this function is not available as you can selectively query the index you're interested in, without having to virtually update it: pool.getReserveNormalizedIncome(dai) and pool.getReserveNormalizedVariableDebt(dai).
Input parameter
Input type
Description
_poolTokenAddress
address
The underlying protocol's pool token address.
Return value
Return type
Description
currentPoolSupplyIndex
uint256
The current, virtually updated supply index of the underlying protocol's pool.
currentPoolBorrowIndex
uint256
The current, virtually updated borrow index of the underlying protocol's pool.

getIndexes()

Computes and returns Morpho's optionally updated peer-to-peer supply & borrow indexes and the underlying protocol's pool supply & borrow indexes.
function getIndexes(
address _poolTokenAddress,
bool _computeUpdatedIndexes
)
view
returns (
uint256 newP2PSupplyIndex,
uint256 newP2PBorrowIndex,
uint256 newPoolSupplyIndex,
uint256 newPoolBorrowIndex
)
Input parameter
Input type
Description
_poolTokenAddress
address
The underlying protocol's pool token address.
_computeUpdatedIndexes
bool
Whether to compute updated market indexes
Return value
Return type
Description
newP2PSupplyIndex
uint256
The optionally updated peer-to-peer supply index.
newP2PBorrowIndex
uint256
The optionally updated peer-to-peer borrow index.
newPoolSupplyIndex
uint256
The optionally updated pool supply index.
newPoolBorrowIndex
uint256
The optionally updated pool borrow index.
Copy link
On this page
Rates
getAverageSupplyRatePerBlock()
getAverageBorrowRatePerBlock()
getNextUserSupplyRatePerBlock()
getNextUserBorrowRatePerBlock()
getCurrentUserSupplyRatePerBlock()
getCurrentUserBorrowRatePerBlock()
getRatesPerBlock()
Markets
isMarketCreated()
isMarketCreatedAndNotPaused()
isMarketCreatedAndNotPausedNorPartiallyPaused()
getAllMarkets()
getMainMarketData()
getAdvancedMarketData()
getMarketConfiguration()
getTotalMarketSupply()
getTotalMarketBorrow()
Users
getEnteredMarkets()
getUserMaxCapacitiesForAsset()
getUserHealthFactor()
isLiquidatable()
computeLiquidationRepayAmount()
getUserHypotheticalBalanceStates()
getCurrentSupplyBalanceInOf()
getCurrentBorrowBalanceInOf()
Rewards
getUserUnclaimedRewards()
Indexes
getCurrentP2PSupplyIndex()
getCurrentP2PBorrowIndex()
getCurrentPoolIndexes()
getIndexes()