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)
    external
    view
    returns (uint256);

Parameters

NameTypeDescription
_useraddressThe potential liquidatee.
_poolTokenBorrowedaddressThe address of the market to repay.
_poolTokenCollateraladdressThe address of the market to seize.

Returns

NameTypeDescription
<none>uint256The maximum repayable amount (in underlying).

getCurrentSupplyBalanceInOf

Returns the balance in underlying of a given user in a given market.

function getCurrentSupplyBalanceInOf(address _poolToken, address _user)
    external
    view
    returns (uint256 balanceInP2P, uint256 balanceOnPool, uint256 totalBalance);

Parameters

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

Returns

NameTypeDescription
balanceInP2Puint256The balance in peer-to-peer of the user (in underlying).
balanceOnPooluint256The balance on pool 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)
    external
    view
    returns (uint256 balanceInP2P, uint256 balanceOnPool, uint256 totalBalance);

Parameters

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

Returns

NameTypeDescription
balanceInP2Puint256The balance in peer-to-peer of the user (in underlying).
balanceOnPooluint256The balance on pool of the user (in underlying).
totalBalanceuint256The total balance of the user (in underlying).

getUserBalanceStates

PUBLIC ///

Returns the collateral value, debt value and max debt value of a given user.

function getUserBalanceStates(address _user) public view returns (Types.LiquidityData memory);

Parameters

NameTypeDescription
_useraddressThe user to determine liquidity for.

Returns

NameTypeDescription
<none>Types.LiquidityDataThe liquidity data of the user.

getUserHypotheticalBalanceStates

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.

function getUserHypotheticalBalanceStates(
    address _user,
    address _poolToken,
    uint256 _withdrawnAmount,
    uint256 _borrowedAmount
) public view returns (Types.LiquidityData memory liquidityData);

Parameters

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

Returns

NameTypeDescription
liquidityDataTypes.LiquidityDataThe liquidity data of the user.

getUserLiquidityDataForAsset

Returns the data related to _poolToken for the _user.

function getUserLiquidityDataForAsset(address _user, address _poolToken, IPriceOracleGetter _oracle)
    public
    view
    returns (Types.AssetLiquidityData memory);

Parameters

NameTypeDescription
_useraddressThe user to determine data for.
_poolTokenaddressThe address of the market.
_oracleIPriceOracleGetterThe oracle used.

Returns

NameTypeDescription
<none>Types.AssetLiquidityDataassetData The data related to this asset.

getUserHealthFactor

Returns the health factor of a given user, using virtually updated pool & peer-to-peer indexes for all markets.

function getUserHealthFactor(address _user) public view returns (uint256);

Parameters

NameTypeDescription
_useraddressThe user of whom to get the health factor.

Returns

NameTypeDescription
<none>uint256The health factor of the given user (in wad).

getUserHypotheticalHealthFactor

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.

function getUserHypotheticalHealthFactor(
    address _user,
    address _poolToken,
    uint256 _withdrawnAmount,
    uint256 _borrowedAmount
) public view returns (uint256 healthFactor);

Parameters

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

Returns

NameTypeDescription
healthFactoruint256The health factor of the user.

isLiquidatable

Returns whether a liquidation can be performed on a given user, based on their health factor.

This function checks for the user's health factor, without treating borrow positions from deprecated market as instantly liquidatable.

function isLiquidatable(address _user) public view returns (bool);

Parameters

NameTypeDescription
_useraddressThe address of the user to check.

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) public view returns (bool);

Parameters

NameTypeDescription
_useraddressThe address of the user to check.
_poolTokenaddressThe address of the borrowed market to check.

Returns

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

_isBorrowing

INTERNAL ///

Returns wheter the given user is borrowing from the given market.

function _isBorrowing(address _user, address _market) internal view returns (bool);

Parameters

NameTypeDescription
_useraddressThe address of the user to check.
_marketaddressThe address of the market to check.

Returns

NameTypeDescription
<none>boolTrue if the user has been supplying or borrowing on this market, false otherwise.

_isSupplyingOrBorrowing

Returns whether the given user is borrowing or supplying on the given market.

function _isSupplyingOrBorrowing(bytes32 _userMarkets, address _market) internal view returns (bool);

Parameters

NameTypeDescription
_userMarketsbytes32The bytes representation of entered markets of the user to check for.
_marketaddressThe address of the market to check.

Returns

NameTypeDescription
<none>boolTrue if the user has been supplying or borrowing on this market, false otherwise.

_getCurrentSupplyBalanceInOf

Returns the balance in underlying of a given user in a given market.

function _getCurrentSupplyBalanceInOf(address _poolToken, address _user)
    internal
    view
    returns (address underlyingToken, uint256 balanceInP2P, uint256 balanceOnPool, uint256 totalBalance);

Parameters

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

Returns

NameTypeDescription
underlyingTokenaddressThe address of the underlying ERC20 token of the given market.
balanceInP2Puint256The balance in peer-to-peer of the user (in underlying).
balanceOnPooluint256The balance on pool 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)
    internal
    view
    returns (address underlyingToken, uint256 balanceInP2P, uint256 balanceOnPool, uint256 totalBalance);

Parameters

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

Returns

NameTypeDescription
underlyingTokenaddressThe address of the underlying ERC20 token of the given market.
balanceInP2Puint256The balance in peer-to-peer of the user (in underlying).
balanceOnPooluint256The balance on pool of the user (in underlying).
totalBalanceuint256The total balance of the user (in underlying).

_getSupplyBalanceInOf

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 _getSupplyBalanceInOf(address _poolToken, address _user, uint256 _p2pSupplyIndex, uint256 _poolSupplyIndex)
    internal
    view
    returns (uint256 balanceInP2P, uint256 balanceOnPool, uint256 totalBalance);

Parameters

NameTypeDescription
_poolTokenaddressThe market where to get the supply amount.
_useraddressThe address of the user.
_p2pSupplyIndexuint256The peer-to-peer supply index of the given market (in ray).
_poolSupplyIndexuint256The pool supply index of the given market (in ray).

Returns

NameTypeDescription
balanceInP2Puint256The balance in peer-to-peer of the user (in underlying).
balanceOnPooluint256The balance on pool of the user (in underlying).
totalBalanceuint256The total balance of the user (in underlying).

_getBorrowBalanceInOf

Returns the borrow balance of _user in the _poolToken market.

function _getBorrowBalanceInOf(address _poolToken, address _user, uint256 _p2pBorrowIndex, uint256 _poolBorrowIndex)
    internal
    view
    returns (uint256 balanceInP2P, uint256 balanceOnPool, uint256 totalBalance);

Parameters

NameTypeDescription
_poolTokenaddressThe market where to get the borrow amount.
_useraddressThe address of the user.
_p2pBorrowIndexuint256The peer-to-peer borrow index of the given market (in ray).
_poolBorrowIndexuint256The pool borrow index of the given market (in ray).

Returns

NameTypeDescription
balanceInP2Puint256The balance in peer-to-peer of the user (in underlying).
balanceOnPooluint256The balance on pool of the user (in underlying).
totalBalanceuint256The total balance of the user (in underlying).

_getUserHypotheticalLiquidityDataForAsset

Returns the data related to _poolToken for the _user.

function _getUserHypotheticalLiquidityDataForAsset(
    address _user,
    address _poolToken,
    IPriceOracleGetter _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.
_oracleIPriceOracleGetterThe 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.