MorphoUtils

Git Source

Inherits: MorphoStorage

Author: Morpho Labs.

Modifiers, getters and other util functions for Morpho.

Functions

isMarketCreated

MODIFIERS ///

Prevents to update a market not created yet.

modifier isMarketCreated(address _poolToken);

Parameters

NameTypeDescription
_poolTokenaddressThe address of the market to check.

getEnteredMarkets

EXTERNAL ///

Returns all markets entered by a given user.

function getEnteredMarkets(address _user) external view returns (address[] memory);

Parameters

NameTypeDescription
_useraddressThe address of the user.

Returns

NameTypeDescription
<none>address[]The list of markets entered by this user.

getAllMarkets

Returns all created markets.

function getAllMarkets() external view returns (address[] memory);

Returns

NameTypeDescription
<none>address[]The list of market addresses.

getHead

Gets the head of the data structure on a specific market (for UI).

function getHead(address _poolToken, Types.PositionType _positionType) external view returns (address head);

Parameters

NameTypeDescription
_poolTokenaddressThe address of the market from which to get the head.
_positionTypeTypes.PositionTypeThe type of user from which to get the head.

Returns

NameTypeDescription
headaddressThe head in the data structure.

getNext

Gets the next user after _user in the data structure on a specific market (for UI).

Beware that this function does not give the account with the highest liquidity.

function getNext(address _poolToken, Types.PositionType _positionType, address _user)
    external
    view
    returns (address next);

Parameters

NameTypeDescription
_poolTokenaddressThe address of the market from which to get the user.
_positionTypeTypes.PositionTypeThe type of user from which to get the next user.
_useraddressThe address of the user from which to get the next user.

Returns

NameTypeDescription
nextaddressThe next user in the data structure.

updateP2PIndexes

Updates the peer-to-peer indexes.

Note: This function updates the exchange rate on Compound. As a consequence only a call to exchangeRateStored() is necessary to get the most up to date exchange rate.

function updateP2PIndexes(address _poolToken) external isMarketCreated(_poolToken);

Parameters

NameTypeDescription
_poolTokenaddressThe address of the market to update.

_updateP2PIndexes

INTERNAL ///

Updates the peer-to-peer indexes.

Note: This function updates the exchange rate on Compound. As a consequence only a call to exchangeRateStored() is necessary to get the most up to date exchange rate.

function _updateP2PIndexes(address _poolToken) internal;

Parameters

NameTypeDescription
_poolTokenaddressThe address of the market to update.

_isLiquidatable

Checks whether the user has enough collateral to maintain such a borrow position.

Expects the given user's entered markets to include the given market.

Expects the given market's pool & peer-to-peer indexes to have been updated.

Expects _withdrawnAmount to be less than or equal to the given user's supply on the given market.

function _isLiquidatable(address _user, address _poolToken, uint256 _withdrawnAmount, uint256 _borrowedAmount)
    internal
    view
    returns (bool);

Parameters

NameTypeDescription
_useraddressThe user to check.
_poolTokenaddressThe market to hypothetically withdraw/borrow in.
_withdrawnAmountuint256The amount of tokens to hypothetically withdraw (in underlying).
_borrowedAmountuint256The amount of tokens to hypothetically borrow (in underlying).

_getUserLiquidityDataForAsset

Returns the data related to _poolToken for the _user.

Note: Must be called after calling _updateP2PIndexes() to have the most up-to-date indexes.

function _getUserLiquidityDataForAsset(address _user, address _poolToken, ICompoundOracle _oracle)
    internal
    view
    returns (Types.AssetLiquidityData memory assetData);

Parameters

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

Returns

NameTypeDescription
assetDataTypes.AssetLiquidityDataThe data related to this asset.

_getUserSupplyBalanceInOf

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

Parameters

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

Returns

NameTypeDescription
<none>uint256The supply balance of the user (in underlying).

_getUserBorrowBalanceInOf

Returns the borrow 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 _getUserBorrowBalanceInOf(address _poolToken, address _user) internal view returns (uint256);

Parameters

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

Returns

NameTypeDescription
<none>uint256The borrow balance of the user (in underlying).

_getUnderlying

Returns the underlying ERC20 token related to the pool token.

function _getUnderlying(address _poolToken) internal view returns (ERC20);

Parameters

NameTypeDescription
_poolTokenaddressThe address of the pool token.

Returns

NameTypeDescription
<none>ERC20The underlying ERC20 token.

Errors

CompoundOracleFailed

ERRORS ///

Thrown when the Compound's oracle failed.

error CompoundOracleFailed();

MarketNotCreated

Thrown when the market is not created yet.

error MarketNotCreated();