UsersLens

Git Source

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

NameTypeDescription
_useraddressThe address of the user.

Returns

NameTypeDescription
enteredMarketsaddress[]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

NameTypeDescription
_useraddressThe user to determine the capacities for.
_poolTokenaddressThe address of the market.

Returns

NameTypeDescription
withdrawableuint256The maximum withdrawable amount of underlying token allowed (in underlying).
borrowableuint256The 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

NameTypeDescription
_useraddressThe potential liquidatee.
_poolTokenBorrowedaddressThe address of the market to repay.
_poolTokenCollateraladdressThe address of the market to seize.
_updatedMarketsaddress[]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

NameTypeDescription
_useraddressThe user of whom to get the health factor.
_updatedMarketsaddress[]The list of markets of which to compute virtually updated pool and peer-to-peer indexes.

Returns

NameTypeDescription
<none>uint256The 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

NameTypeDescription
_useraddressThe user to determine liquidity for.
_poolTokenaddressThe market to hypothetically withdraw/borrow in.
_withdrawnAmountuint256The amount to hypothetically withdraw from the given market (in underlying).
_borrowedAmountuint256The amount to hypothetically borrow from the given market (in underlying).

Returns

NameTypeDescription
debtUsduint256The current debt value of the user (in wad).
maxDebtUsduint256The 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

NameTypeDescription
_useraddressThe user to determine liquidity for.
_updatedMarketsaddress[]The list of markets of which to compute virtually updated pool and peer-to-peer indexes.

Returns

NameTypeDescription
collateralUsduint256The collateral value of the user (in wad).
debtUsduint256The current debt value of the user (in wad).
maxDebtUsduint256The 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

NameTypeDescription
_poolTokenaddressThe address of the market.
_useraddressThe user to determine balances of.

Returns

NameTypeDescription
balanceOnPooluint256The balance on pool of the user (in underlying).
balanceInP2Puint256The balance in peer-to-peer of the user (in underlying).
totalBalanceuint256The 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

NameTypeDescription
_poolTokenaddressThe address of the market.
_useraddressThe user to determine balances of.

Returns

NameTypeDescription
balanceOnPooluint256The balance on pool of the user (in underlying).
balanceInP2Puint256The balance in peer-to-peer of the user (in underlying).
totalBalanceuint256The 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

NameTypeDescription
_useraddressThe user to determine data for.
_poolTokenaddressThe address of the market.
_getUpdatedIndexesboolWhether to compute virtually updated pool and peer-to-peer indexes.
_oracleICompoundOracleThe oracle used.

Returns

NameTypeDescription
<none>Types.AssetLiquidityDataassetData 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

NameTypeDescription
_useraddressThe address of the user to check.
_updatedMarketsaddress[]The list of markets of which to compute virtually updated pool and peer-to-peer indexes.

Returns

NameTypeDescription
<none>boolwhether 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

NameTypeDescription
_useraddressThe address of the user to check.
_poolTokenaddressThe address of the borrowed market to check.
_updatedMarketsaddress[]The list of markets of which to compute virtually updated pool and peer-to-peer indexes.

Returns

NameTypeDescription
<none>boolwhether 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

NameTypeDescription
_poolTokenaddressThe market where to get the supply amount.
_useraddressThe address of the user.
_p2pSupplyIndexuint256
_poolSupplyIndexuint256

Returns

NameTypeDescription
<none>uint256The 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

NameTypeDescription
_poolTokenaddressThe market where to get the borrow amount.
_useraddressThe address of the user.
_p2pBorrowIndexuint256
_poolBorrowIndexuint256

Returns

NameTypeDescription
<none>uint256The 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

NameTypeDescription
_useraddressThe user to determine data for.
_poolTokenaddressThe address of the market.
_getUpdatedIndexesboolWhether to compute virtually updated pool and peer-to-peer indexes.
_oracleICompoundOracleThe oracle used.
_withdrawnAmountuint256The amount to hypothetically withdraw from the given market (in underlying).
_borrowedAmountuint256The amount to hypothetically borrow from the given market (in underlying).

Returns

NameTypeDescription
assetDataTypes.AssetLiquidityDataThe 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

NameTypeDescription
_useraddressThe address of the user to check.
_poolTokenDeprecatedaddressThe address of the deprecated borrowed market to check.
_updatedMarketsaddress[]The list of markets of which to compute virtually updated pool and peer-to-peer indexes.

Returns

NameTypeDescription
<none>boolwhether or not the user is liquidatable.

Errors

CompoundOracleFailed

ERRORS ///

Thrown when the Compound's oracle failed.

error CompoundOracleFailed();