UsersLens
Inherits: IndexesLens
Author: Morpho Labs.
Intermediary layer exposing endpoints to query live data related to the Morpho Protocol users and their positions.
Functions
getEnteredMarkets
EXTERNAL ///
Returns all markets entered by a given user.
function getEnteredMarkets(address _user) external view returns (address[] memory enteredMarkets);
Parameters
Name | Type | Description |
---|---|---|
_user | address | The address of the user. |
Returns
Name | Type | Description |
---|---|---|
enteredMarkets | address[] | The list of markets entered by this user. |
getUserMaxCapacitiesForAsset
Returns the maximum amount available to withdraw & borrow for a given user, on a given market.
function getUserMaxCapacitiesForAsset(address _user, address _poolToken)
external
view
returns (uint256 withdrawable, uint256 borrowable);
Parameters
Name | Type | Description |
---|---|---|
_user | address | The user to determine the capacities for. |
_poolToken | address | The address of the market. |
Returns
Name | Type | Description |
---|---|---|
withdrawable | uint256 | The maximum withdrawable amount of underlying token allowed (in underlying). |
borrowable | uint256 | The maximum borrowable amount of underlying token allowed (in underlying). |
computeLiquidationRepayAmount
Computes the maximum repayable amount for a potential liquidation.
function computeLiquidationRepayAmount(
address _user,
address _poolTokenBorrowed,
address _poolTokenCollateral,
address[] calldata _updatedMarkets
) external view returns (uint256 toRepay);
Parameters
Name | Type | Description |
---|---|---|
_user | address | The potential liquidatee. |
_poolTokenBorrowed | address | The address of the market to repay. |
_poolTokenCollateral | address | The address of the market to seize. |
_updatedMarkets | address[] | The list of markets of which to compute virtually updated pool and peer-to-peer indexes. |
getUserHealthFactor
Computes the health factor of a given user, given a list of markets of which to compute virtually updated pool & peer-to-peer indexes.
function getUserHealthFactor(address _user, address[] calldata _updatedMarkets) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_user | address | The user of whom to get the health factor. |
_updatedMarkets | address[] | The list of markets of which to compute virtually updated pool and peer-to-peer indexes. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The health factor of the given user (in wad). |
getUserHypotheticalBalanceStates
Returns the debt value, max debt value of a given user.
function getUserHypotheticalBalanceStates(
address _user,
address _poolToken,
uint256 _withdrawnAmount,
uint256 _borrowedAmount
) external view returns (uint256 debtUsd, uint256 maxDebtUsd);
Parameters
Name | Type | Description |
---|---|---|
_user | address | The user to determine liquidity for. |
_poolToken | address | The market to hypothetically withdraw/borrow in. |
_withdrawnAmount | uint256 | The amount to hypothetically withdraw from the given market (in underlying). |
_borrowedAmount | uint256 | The amount to hypothetically borrow from the given market (in underlying). |
Returns
Name | Type | Description |
---|---|---|
debtUsd | uint256 | The current debt value of the user (in wad). |
maxDebtUsd | uint256 | The maximum debt value possible of the user (in wad). |
getUserBalanceStates
PUBLIC ///
Returns the collateral value, debt value and max debt value of a given user.
function getUserBalanceStates(address _user, address[] calldata _updatedMarkets)
public
view
returns (uint256 collateralUsd, uint256 debtUsd, uint256 maxDebtUsd);
Parameters
Name | Type | Description |
---|---|---|
_user | address | The user to determine liquidity for. |
_updatedMarkets | address[] | The list of markets of which to compute virtually updated pool and peer-to-peer indexes. |
Returns
Name | Type | Description |
---|---|---|
collateralUsd | uint256 | The collateral value of the user (in wad). |
debtUsd | uint256 | The current debt value of the user (in wad). |
maxDebtUsd | uint256 | The maximum possible debt value of the user (in wad). |
getCurrentSupplyBalanceInOf
Returns the balance in underlying of a given user in a given market.
function getCurrentSupplyBalanceInOf(address _poolToken, address _user)
public
view
returns (uint256 balanceOnPool, uint256 balanceInP2P, uint256 totalBalance);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market. |
_user | address | The user to determine balances of. |
Returns
Name | Type | Description |
---|---|---|
balanceOnPool | uint256 | The balance on pool of the user (in underlying). |
balanceInP2P | uint256 | The balance in peer-to-peer of the user (in underlying). |
totalBalance | uint256 | The total balance of the user (in underlying). |
getCurrentBorrowBalanceInOf
Returns the borrow balance in underlying of a given user in a given market.
function getCurrentBorrowBalanceInOf(address _poolToken, address _user)
public
view
returns (uint256 balanceOnPool, uint256 balanceInP2P, uint256 totalBalance);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market. |
_user | address | The user to determine balances of. |
Returns
Name | Type | Description |
---|---|---|
balanceOnPool | uint256 | The balance on pool of the user (in underlying). |
balanceInP2P | uint256 | The balance in peer-to-peer of the user (in underlying). |
totalBalance | uint256 | The total balance of the user (in underlying). |
getUserLiquidityDataForAsset
Returns the data related to _poolToken
for the _user
, by optionally computing virtually updated pool and peer-to-peer indexes.
function getUserLiquidityDataForAsset(
address _user,
address _poolToken,
bool _getUpdatedIndexes,
ICompoundOracle _oracle
) public view returns (Types.AssetLiquidityData memory);
Parameters
Name | Type | Description |
---|---|---|
_user | address | The user to determine data for. |
_poolToken | address | The address of the market. |
_getUpdatedIndexes | bool | Whether to compute virtually updated pool and peer-to-peer indexes. |
_oracle | ICompoundOracle | The oracle used. |
Returns
Name | Type | Description |
---|---|---|
<none> | Types.AssetLiquidityData | assetData The data related to this asset. |
isLiquidatable
Returns whether a liquidation can be performed on a given user.
This function checks for the user's health factor, without treating borrow positions from deprecated market as instantly liquidatable.
function isLiquidatable(address _user, address[] memory _updatedMarkets) public view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_user | address | The address of the user to check. |
_updatedMarkets | address[] | The list of markets of which to compute virtually updated pool and peer-to-peer indexes. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | whether or not the user is liquidatable. |
isLiquidatable
Returns whether a liquidation can be performed on a given user borrowing from a given market.
This function checks for the user's health factor as well as whether the given market is deprecated & the user is borrowing from it.
function isLiquidatable(address _user, address _poolToken, address[] memory _updatedMarkets)
public
view
returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_user | address | The address of the user to check. |
_poolToken | address | The address of the borrowed market to check. |
_updatedMarkets | address[] | The list of markets of which to compute virtually updated pool and peer-to-peer indexes. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | whether or not the user is liquidatable. |
_getUserSupplyBalanceInOf
INTERNAL ///
Returns the supply balance of _user
in the _poolToken
market.
Note: Computes the result with the stored indexes, which are not always the most up to date ones.
function _getUserSupplyBalanceInOf(address _poolToken, address _user, uint256 _p2pSupplyIndex, uint256 _poolSupplyIndex)
internal
view
returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The market where to get the supply amount. |
_user | address | The address of the user. |
_p2pSupplyIndex | uint256 | |
_poolSupplyIndex | uint256 |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The supply balance of the user (in underlying). |
_getUserBorrowBalanceInOf
Returns the borrow balance of _user
in the _poolToken
market.
function _getUserBorrowBalanceInOf(address _poolToken, address _user, uint256 _p2pBorrowIndex, uint256 _poolBorrowIndex)
internal
view
returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The market where to get the borrow amount. |
_user | address | The address of the user. |
_p2pBorrowIndex | uint256 | |
_poolBorrowIndex | uint256 |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The borrow balance of the user (in underlying). |
_getUserHypotheticalLiquidityDataForAsset
Returns the data related to _poolToken
for the _user
, by optionally computing virtually updated pool and peer-to-peer indexes.
function _getUserHypotheticalLiquidityDataForAsset(
address _user,
address _poolToken,
bool _getUpdatedIndexes,
ICompoundOracle _oracle,
uint256 _withdrawnAmount,
uint256 _borrowedAmount
) internal view returns (Types.AssetLiquidityData memory assetData);
Parameters
Name | Type | Description |
---|---|---|
_user | address | The user to determine data for. |
_poolToken | address | The address of the market. |
_getUpdatedIndexes | bool | Whether to compute virtually updated pool and peer-to-peer indexes. |
_oracle | ICompoundOracle | The oracle used. |
_withdrawnAmount | uint256 | The amount to hypothetically withdraw from the given market (in underlying). |
_borrowedAmount | uint256 | The amount to hypothetically borrow from the given market (in underlying). |
Returns
Name | Type | Description |
---|---|---|
assetData | Types.AssetLiquidityData | The data related to this asset. |
_isLiquidatable
Returns whether a liquidation can be performed on the given user. This function checks for the user's health factor as well as whether the user is borrowing from the given deprecated market.
function _isLiquidatable(address _user, address _poolTokenDeprecated, address[] memory _updatedMarkets)
internal
view
returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_user | address | The address of the user to check. |
_poolTokenDeprecated | address | The address of the deprecated borrowed market to check. |
_updatedMarkets | address[] | The list of markets of which to compute virtually updated pool and peer-to-peer indexes. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | whether or not the user is liquidatable. |
Errors
CompoundOracleFailed
ERRORS ///
Thrown when the Compound's oracle failed.
error CompoundOracleFailed();