Lens
The lens is a stateless contract that exposes view helpers to format data from the Optimizers' storage. They can be used to ease the integration on top of the Optimizers.
Lens Functions
getTotalSupply
function getTotalSupply()
external
view
returns (
uint256 p2pSupplyAmount,
uint256 poolSupplyAmount,
uint256 totalSupplyAmount
);
Return values:
Name | Type | Description |
---|
p2pSupplyAmount | uint256 | The total supplied amount matched peer-to-peer, subtracting the supply delta (in USD, 18 decimals). |
poolSupplyAmount | uint256 | The total supplied amount on the underlying pool, adding the supply delta (in USD, 18 decimals). |
totalSupplyAmount | uint256 | The total amount supplied through Morpho (in USD, 18 decimals). |
getTotalBorrow
function getTotalBorrow()
external
view
returns (
uint256 p2pBorrowAmount,
uint256 poolBorrowAmount,
uint256 totalBorrowAmount
);
Return values:
Name | Type | Description |
---|
p2pBorrowAmount | uint256 | The total borrowed amount matched peer-to-peer, subtracting the borrow delta (in USD, 18 decimals). |
poolBorrowAmount | uint256 | The total borrowed amount on the underlying pool, adding the borrow delta (in USD, 18 decimals). |
totalBorrowAmount | uint256 | The total amount borrowed through Morpho (in USD, 18 decimals). |
Rewards Lens Functions
These functions are specific to Morpho CompoundV2 Optimizer.
getUserUnclaimedRewards
function getUserUnclaimedRewards(address[] calldata _poolTokens, address _user)
external
view
returns (uint256);
Returns the unclaimed COMP rewards for the given cToken addresses.
Parameters:
Name | Type | Description |
---|
_poolTokens | address[] | The cToken addresses for which to compute the rewards. |
_user | address | The user to compute the rewards for. |
Return values:
Name | Type | Description |
---|
unclaimedRewards | uint256 | The unclaimed COMP rewards for the given cToken addresses. |
getAccruedSupplierComp
function getAccruedSupplierComp(
address _supplier,
address _poolToken
) external view returns (uint256);
Returns the accrued COMP rewards of a user since the last update.
Parameters:
Name | Type | Description |
---|
_supplier | address | The user to compute the rewards for. |
_poolToken | address | The cToken address for which to compute the rewards. |
Return values:
Name | Type | Description |
---|
accruedSupplierComp | uint256 | The accrued COMP rewards. |
getAccruedBorrowerComp
function getAccruedBorrowerComp(
address _supplier,
address _poolToken
) external view returns (uint256);
Returns the accrued COMP rewards of a user since the last update.
Parameters:
Name | Type | Description |
---|
_supplier | address | The user to compute the rewards for. |
_poolToken | address | The cToken address for which to compute the rewards. |
Return values:
Name | Type | Description |
---|
accruedBorrowerComp | uint256 | The accrued COMP rewards. |
getCurrentCompSupplyIndex
function getCurrentCompSupplyIndex(address _poolToken) external view returns (uint256);
Returns the updated COMP supply index.
Parameters:
Name | Type | Description |
---|
_poolToken | address | The cToken address for which to compute the rewards. |
Return values:
Name | Type | Description |
---|
supplyIndex | uint256 | The updated COMP supply index. |
getCurrentCompBorrowIndex
function getCurrentCompBorrowIndex(address _poolToken) external view returns (uint256);
Returns the updated COMP borrow index.
Parameters:
Name | Type | Description |
---|
_poolToken | address | The cToken address for which to compute the rewards. |
Return values:
Name | Type | Description |
---|
supplyIndex | uint256 | The updated COMP borrow index. |
Market Lens Functions
isMarketCreated
function isMarketCreated(address _poolToken) external view returns (bool);
Checks if a market is created.
Parameters:
Name | Type | Description |
---|
_poolToken | address | The address of the market to check. |
Return values:
Name | Type | Description |
---|
isCreated | bool | True if the market is created. |
getAllMarkets
function getAllMarkets() external view returns (address[] memory);
Returns the list of all markets created.
Return values:
Name | Type | Description |
---|
markets | address[] | The list of all markets created. |
getMainMarketData
function getMainMarketData(address _poolToken)
external
view
returns (
uint256 avgSupplyRatePerBlock,
uint256 avgBorrowRatePerBlock,
uint256 p2pSupplyAmount,
uint256 p2pBorrowAmount,
uint256 poolSupplyAmount,
uint256 poolBorrowAmount
);
For a given market, returns the average supply/borrow rates and amounts of underlying asset supplied and borrowed through Morpho Optimizer, on the underlying pool and matched peer-to-peer.
Parameters:
Name | Type | Description |
---|
_poolToken | address | The address of the market to check. |
Return values:
Name | Type | Description |
---|
avgSupplyRatePerBlock | uint256 | The average supply rate experienced on the given market (in wad). |
avgBorrowRatePerBlock | uint256 | The average borrow rate experienced on the given market (in wad). |
p2pSupplyAmount | uint256 | The total supplied amount matched peer-to-peer, subtracting the supply delta (in underlying). |
p2pBorrowAmount | uint256 | The total borrowed amount matched peer-to-peer, subtracting the borrow delta (in underlying). |
poolSupplyAmount | uint256 | The total supplied amount on the underlying pool, adding the supply delta (in underlying). |
poolBorrowAmount | uint256 | The total borrowed amount on the underlying pool, adding the borrow delta (in underlying). |
getAdvancedMarketData
struct Indexes {
uint256 p2pSupplyIndex;
uint256 p2pBorrowIndex;
uint256 poolSupplyIndex;
uint256 poolBorrowIndex;
}
function getAdvancedMarketData(address _poolToken)
external
view
returns (
Indexes memory indexes,
uint32 lastUpdateBlockNumber,
uint256 p2pSupplyDelta,
uint256 p2pBorrowDelta
);
Returns non-updated indexes, the block at which they were last updated and the total deltas of a given market.
Parameters:
Name | Type | Description |
---|
_poolToken | address | The address of the market to check. |
Return values:
Name | Type | Description |
---|
indexes | Indexes | The indexes of the given market. |
lastUpdateBlockNumber | uint32 | The block at which pool indexes were last updated. |
p2pSupplyDelta | uint256 | The total supply delta (in underlying). |
p2pBorrowDelta | uint256 | The total borrow delta (in underlying). |
getMarketConfiguration
function getMarketConfiguration(address _poolToken)
external
view
returns (
address underlying,
bool isCreated,
bool isP2PDisabled,
bool isPaused,
bool isPartiallyPaused,
uint16 reserveFactor,
uint16 p2pIndexCursor,
uint256 collateralFactor
);
Returns the given market's configuration.
Parameters:
Name | Type | Description |
---|
_poolToken | address | The address of the market of which to get the configuration. |
Return values:
The return value is a tuple containing the following values:
Name | Type | Description |
---|
underlying | address | The underlying token address. |
isCreated | bool | Whether the market is created or not. |
isP2PDisabled | bool | Whether the peer-to-peer market is enabled or not. |
isPaused | bool | Deprecated |
isPartiallyPaused | bool | Deprecated |
reserveFactor | uint16 | The reserve factor applied to this market. |
p2pIndexCursor | uint16 | The p2p index cursor applied to this market. |
collateralFactor | uint256 | The pool collateral factor also used by Morpho (in wad). |
getMarketPauseStatus
struct MarketPauseStatus {
bool isSupplyPaused;
bool isBorrowPaused;
bool isWithdrawPaused;
bool isRepayPaused;
bool isLiquidateCollateralPaused;
bool isLiquidateBorrowPaused;
bool isDeprecated;
}
function getMarketPauseStatus(address _poolToken)
external
view
returns (MarketPauseStatus memory);
Returns the given market's pause statuses.
Parameters:
Name | Type | Description |
---|
_poolToken | address | The address of the market of which to get pause statuses. |
Return values:
Name | Type | Description |
---|
marketPauseStatus | MarketPauseStatus | The market status struct. |
getTotalMarketSupply
function getTotalMarketSupply(address _poolToken)
external
view
returns (uint256 p2pSupplyAmount, uint256 poolSupplyAmount);
Computes and returns the total distribution of supply for a given market, using virtually updated indexes.
Parameters:
Name | Type | Description |
---|
_poolToken | address | The address of the market to check. |
Return values:
Name | Type | Description |
---|
p2pSupplyAmount | uint256 | The total supplied amount matched peer-to-peer, subtracting the supply delta (in underlying). |
poolSupplyAmount | uint256 | The total supplied amount on the underlying pool, adding the supply delta (in underlying). |
getTotalMarketBorrow
function getTotalMarketBorrow(address _poolToken)
external
view
returns (uint256 p2pBorrowAmount, uint256 poolBorrowAmount);
Computes and returns the total distribution of borrow for a given market, using virtually updated indexes.
Parameters:
Name | Type | Description |
---|
_poolToken | address | The address of the market to check. |
Return values:
Name | Type | Description |
---|
p2pBorrowAmount | uint256 | The total borrowed amount matched peer-to-peer, subtracting the borrow delta (in underlying). |
poolBorrowAmount | uint256 | The total borrowed amount on the underlying pool, adding the borrow delta (in underlying). |
Rates Lens Functions
getNextUserSupplyRatePerBlock
function getNextUserSupplyRatePerBlock(
address _poolToken,
address _user,
uint256 _amount
)
external
view
returns (
uint256 nextSupplyRatePerBlock,
uint256 balanceInP2P,
uint256 balanceOnPool,
uint256 totalBalance
);
Returns the supply rate per block experienced on a market after having supplied the given amount on behalf of the given user.
The returned supply rate is a low estimate: when supplying through Morpho CompoundV2 Optimizer, a supplier could be matched more than once instantly or later and thus benefit from a higher supply rate.
Parameters:
Name | Type | Description |
---|
_poolToken | address | The address of the market. |
_user | address | The address of the user on behalf of whom to supply. |
_amount | uint256 | The amount to supply. |
Return values:
Name | Type | Description |
---|
nextSupplyRatePerBlock | uint256 | An approximation of the next supply rate per block experienced after having supplied (in wad). |
balanceInP2P | uint256 | The total balance matched peer-to-peer after having supplied (in underlying). |
balanceOnPool | uint256 | The total balance supplied on pool after having supplied (in underlying). |
totalBalance | uint256 | The total balance supplied through Morpho (in underlying). |
getNextUserBorrowRatePerYear
function getNextUserBorrowRatePerBlock(
address _poolToken,
address _user,
uint256 _amount
)
external
view
returns (
uint256 nextBorrowRatePerBlock,
uint256 balanceInP2P,
uint256 balanceOnPool,
uint256 totalBalance
);
Returns the borrow rate per block experienced on a market after having borrowed the given amount on behalf of the given user.
the returned borrow rate is a high estimate: when borrowing through Morpho CompoundV2 Optimizer, a borrower could be matched more than once instantly or later and thus benefit from a lower borrow rate.
Parameters:
Name | Type | Description |
---|
_poolToken | address | The address of the market. |
_user | address | The address of the user on behalf of whom to borrow. |
_amount | uint256 | The amount to borrow. |
Return values:
Name | Type | Description |
---|
nextBorrowRatePerBlock | uint256 | An approximation of the next borrow rate per block experienced after having borrowed (in wad). |
balanceInP2P | uint256 | The total balance matched peer-to-peer after having borrowed (in underlying). |
balanceOnPool | uint256 | The total balance borrowed on pool after having borrowed (in underlying). |
totalBalance | uint256 | The total balance borrowed through Morpho (in underlying). |
getCurrentUserSupplyRatePerBlock
function getCurrentUserSupplyRatePerBlock(address _poolToken, address _user)
external
view
returns (uint256 supplyRatePerBlock);
Returns the supply rate per block a given user is currently experiencing on a given market.
Parameters:
Name | Type | Description |
---|
_poolToken | address | The address of the market. |
_user | address | The user to compute the supply rate per block for. |
Return values:
Name | Type | Description |
---|
supplyRatePerBlock | uint256 | The supply rate per block the user is currently experiencing (in wad). |
getCurrentUserBorrowRatePerBlock
function getCurrentUserBorrowRatePerBlock(address _poolToken, address _user)
external
view
returns (uint256 borrowRatePerBlock);
Returns the borrow rate per block a given user is currently experiencing on a given market.
Parameters:
Name | Type | Description |
---|
_poolToken | address | The address of the market. |
_user | address | The user to compute the borrow rate per block for. |
Return values:
Name | Type | Description |
---|
borrowRatePerBlock | uint256 | The borrow rate per block the user is currently experiencing (in wad). |
getAverageSupplyRatePerYear
function getAverageSupplyRatePerBlock(address _poolToken)
public
view
returns (
uint256 avgSupplyRatePerBlock,
uint256 p2pSupplyAmount,
uint256 poolSupplyAmount
);
Computes and returns the current supply rate per block experienced on average on a given market.
Parameters:
Name | Type | Description |
---|
_poolToken | address | The address of the market. |
Return values:
Name | Type | Description |
---|
avgSupplyRatePerBlock | uint256 | The market's average supply rate per block (in wad). |
p2pSupplyAmount | uint256 | The total supplied amount matched peer-to-peer, subtracting the supply delta (in underlying). |
poolSupplyAmount | uint256 | The total supplied amount on the underlying pool, adding the supply delta (in underlying). |
getAverageBorrowRatePerBlock
function getAverageBorrowRatePerBlock(address _poolToken)
public
view
returns (
uint256 avgBorrowRatePerBlock,
uint256 p2pBorrowAmount,
uint256 poolBorrowAmount
);
Computes and returns the current borrow rate per block experienced on average on a given market.
Parameters:
Name | Type | Description |
---|
_poolToken | address | The address of the market. |
Return values:
Name | Type | Description |
---|
avgBorrowRatePerBlock | uint256 | The market's average borrow rate per block (in wad). |
p2pBorrowAmount | uint256 | The total borrowed amount matched peer-to-peer, subtracting the borrow delta (in underlying). |
poolBorrowAmount | uint256 | The total borrowed amount on the underlying pool, adding the borrow delta (in underlying). |
getRatesPerYear
function getRatesPerBlock(address _poolToken)
public
view
returns (
uint256 p2pSupplyRate,
uint256 p2pBorrowRate,
uint256 poolSupplyRate,
uint256 poolBorrowRate
);
Computes and returns peer-to-peer and pool rates for a specific market.
Prefer using getAverageSupplyRatePerBlock & getAverageBorrowRatePerBlock to get the actual experienced supply/borrow rate.
Parameters:
Name | Type | Description |
---|
_poolToken | address | The address of the market. |
Return values:
Name | Type | Description |
---|
p2pSupplyRate | uint256 | The market's peer-to-peer supply rate per block (in wad). |
p2pBorrowRate | uint256 | The market's peer-to-peer borrow rate per block (in wad). |
poolSupplyRate | uint256 | The market's pool supply rate per block (in wad). |
poolBorrowRate | uint256 | The market's pool borrow rate per block (in wad). |
User Lens Functions
getEnteredMarkets
function getEnteredMarkets(address _user)
external
view
returns (address[] memory enteredMarkets);
Returns all markets entered by a given user.
Parameters:
Name | Type | Description |
---|
_user | address | The address of the user to check. |
Return values:
Name | Type | Description |
---|
enteredMarkets | address[] | The list of all markets entered by the user. |
getUserMaxCapacitiesForAsset
function getUserMaxCapacitiesForAsset(address _user, address _poolToken)
external
view
returns (uint256 withdrawable, uint256 borrowable);
Returns the maximum amount available to withdraw & borrow for a given user, on a given market.
Parameters:
Name | Type | Description |
---|
_user | address | The address of the user to check. |
_poolToken | address | The address of the market to check. |
Return values:
Name | Type | Description |
---|
withdrawable | uint256 | The maximum amount available to withdraw. |
borrowable | uint256 | The maximum amount available to borrow. |
computeLiquidationRepayAmount
function computeLiquidationRepayAmount(
address _user,
address _poolTokenBorrowed,
address _poolTokenCollateral
) external view returns (uint256);
Computes the maximum repayable amount for a potential liquidation.
Parameters:
Name | Type | Description |
---|
_user | address | The address of the user to check. |
_poolTokenBorrowed | address | The address of the market to repay. |
_poolTokenCollateral | address | The address of the market to seize. |
Return values:
Name | Type | Description |
---|
repayAmount | uint256 | The maximum repayable amount (in underlying). |
getCurrentSupplyBalanceInOf
function getCurrentSupplyBalanceInOf(address _poolToken, address _user)
external
view
returns (
uint256 balanceInP2P,
uint256 balanceOnPool,
uint256 totalBalance
);
Returns the balance in underlying of a given user in a given market.
Parameters:
Name | Type | Description |
---|
_poolToken | address | The address of the market. |
_user | address | The address of the user to check. |
Return values:
Name | Type | Description |
---|
balanceInP2P | uint256 | The total balance matched peer-to-peer (in underlying). |
balanceOnPool | uint256 | The total balance on the underlying pool (in underlying). |
totalBalance | uint256 | The total balance supplied through Morpho (in underlying). |
getCurrentBorrowBalanceInOf
function getCurrentBorrowBalanceInOf(address _poolToken, address _user)
external
view
returns (
uint256 balanceInP2P,
uint256 balanceOnPool,
uint256 totalBalance
);
Returns the balance in underlying of a given user in a given market.
Parameters:
Name | Type | Description |
---|
_poolToken | address | The address of the market. |
_user | address | The address of the user to check. |
Return values:
Name | Type | Description |
---|
balanceInP2P | uint256 | The total balance matched peer-to-peer (in underlying). |
balanceOnPool | uint256 | The total balance on the underlying pool (in underlying). |
totalBalance | uint256 | The total balance borrowed through Morpho (in underlying). |
getUserBalanceStates
struct LiquidityData {
uint256 collateralEth;
uint256 borrowableEth;
uint256 maxDebtEth;
uint256 debtEth;
}
function getUserBalanceStates(address _user) public view returns (LiquidityData memory);
Returns the collateral value, debt value and max debt value of a given user.
Parameters:
Name | Type | Description |
---|
_user | address | The address of the user to check. |
Return values:
Name | Type | Description |
---|
liquidityData | LiquidityData | The liquidity data struct. |
getUserHypotheticalBalanceStates
struct LiquidityData {
uint256 collateralEth;
uint256 borrowableEth;
uint256 maxDebtEth;
uint256 debtEth;
}
function getUserHypotheticalBalanceStates(
address _user,
address _poolToken,
uint256 _withdrawnAmount,
uint256 _borrowedAmount
) public view returns (LiquidityData memory liquidityData);
Returns the aggregated position of a given user, following an hypothetical borrow/withdraw on a given market, using virtually updated pool & peer-to-peer indexes for all markets.
Parameters:
Name | Type | Description |
---|
_user | address | The address of the user to check. |
_poolToken | address | The address of the market. |
_withdrawnAmount | uint256 | The number of tokens to hypothetically withdraw from the given market (in underlying). |
_borrowedAmount | uint256 | The amount of tokens to hypothetically borrow from the given market (in underlying). |
Return values:
Name | Type | Description |
---|
liquidityData | LiquidityData | The liquidity data struct. |
getUserHealthFactor
function getUserHealthFactor(address _user) public view returns (uint256);
Returns the health factor of a given user.
Parameters:
Name | Type | Description |
---|
_user | address | The address of the user to check. |
Return values:
Name | Type | Description |
---|
healthFactor | uint256 | The health factor of the given user. |
getUserHypotheticalHealthFactor
function getUserHypotheticalHealthFactor(
address _user,
address _poolToken,
uint256 _withdrawnAmount,
uint256 _borrowedAmount
) public view returns (uint256 healthFactor);
Returns the hypothetical health factor of a user, following an hypothetical borrow/withdraw on a given market, using virtually updated pool & peer-to-peer indexes for all markets.
Parameters:
Name | Type | Description |
---|
_user | address | The address of the user to check. |
_poolToken | address | The address of the market. |
_withdrawnAmount | uint256 | The number of tokens to hypothetically withdraw from the given market (in underlying). |
_borrowedAmount | uint256 | The amount of tokens to hypothetically borrow from the given market (in underlying). |
Return values:
Name | Type | Description |
---|
healthFactor | uint256 | The health factor of the given user. |
isLiquidatable
function isLiquidatable(address _user) public view returns (bool);
Checks if a given user is liquidatable.
Parameters:
Name | Type | Description |
---|
_user | address | The address of the user to check. |
Return values:
Name | Type | Description |
---|
isLiquidatable | bool | True if the user is liquidatable. |