MorphoUtils
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
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market to check. |
getMarketsCreated
EXTERNAL ///
Returns all created markets.
function getMarketsCreated() external view returns (address[] memory);
Returns
Name | Type | Description |
---|---|---|
<none> | address[] | marketsCreated_ 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
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market from which to get the head. |
_positionType | Types.PositionType | The type of user from which to get the head. |
Returns
Name | Type | Description |
---|---|---|
head | address | The 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
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market from which to get the user. |
_positionType | Types.PositionType | The type of user from which to get the next user. |
_user | address | The address of the user from which to get the next user. |
Returns
Name | Type | Description |
---|---|---|
next | address | The next user in the data structure. |
updateIndexes
Updates the peer-to-peer indexes and pool indexes (only stored locally).
function updateIndexes(address _poolToken) external isMarketCreated(_poolToken);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market to update. |
_isSupplyingOrBorrowing
INTERNAL ///
Returns if a user has been borrowing or supplying on a given market.
function _isSupplyingOrBorrowing(bytes32 _userMarkets, bytes32 _borrowMask) internal pure returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_userMarkets | bytes32 | The bitmask encoding the markets entered by the user. |
_borrowMask | bytes32 | The borrow mask of the market to check. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True if the user has been supplying or borrowing on this market, false otherwise. |
_isBorrowing
Returns if a user is borrowing on a given market.
function _isBorrowing(bytes32 _userMarkets, bytes32 _borrowMask) internal pure returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_userMarkets | bytes32 | The bitmask encoding the markets entered by the user. |
_borrowMask | bytes32 | The borrow mask of the market to check. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True if the user has been borrowing on this market, false otherwise. |
_isSupplying
Returns if a user is supplying on a given market.
function _isSupplying(bytes32 _userMarkets, bytes32 _borrowMask) internal pure returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_userMarkets | bytes32 | The bitmask encoding the markets entered by the user. |
_borrowMask | bytes32 | The borrow mask of the market to check. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True if the user has been supplying on this market, false otherwise. |
_isBorrowingAny
Returns if a user has been borrowing from any market.
function _isBorrowingAny(bytes32 _userMarkets) internal pure returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_userMarkets | bytes32 | The bitmask encoding the markets entered by the user. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True if the user has been borrowing on any market, false otherwise. |
_isBorrowingAndSupplying
Returns if a user is borrowing on a given market and supplying on another given market.
function _isBorrowingAndSupplying(bytes32 _userMarkets, bytes32 _borrowedBorrowMask, bytes32 _suppliedBorrowMask)
internal
pure
returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_userMarkets | bytes32 | The bitmask encoding the markets entered by the user. |
_borrowedBorrowMask | bytes32 | The borrow mask of the market to check whether the user is borrowing. |
_suppliedBorrowMask | bytes32 | The borrow mask of the market to check whether the user is supplying. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True if the user is borrowing on the given market and supplying on the other given market, false otherwise. |
_setBorrowing
Sets if the user is borrowing on a market.
function _setBorrowing(address _user, bytes32 _borrowMask, bool _borrowing) internal;
Parameters
Name | Type | Description |
---|---|---|
_user | address | The user to set for. |
_borrowMask | bytes32 | The borrow mask of the market to mark as borrowed. |
_borrowing | bool | True if the user is borrowing, false otherwise. |
_setSupplying
Sets if the user is supplying on a market.
function _setSupplying(address _user, bytes32 _borrowMask, bool _supplying) internal;
Parameters
Name | Type | Description |
---|---|---|
_user | address | The user to set for. |
_borrowMask | bytes32 | The borrow mask of the market to mark as supplied. |
_supplying | bool | True if the user is supplying, false otherwise. |
_updateIndexes
Updates the peer-to-peer indexes and pool indexes (only stored locally).
function _updateIndexes(address _poolToken) internal;
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market to update. |
_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
Name | Type | Description |
---|---|---|
_poolToken | address | The market where to get the supply amount. |
_user | address | The address of the user. |
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.
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
Name | Type | Description |
---|---|---|
_poolToken | address | The market where to get the borrow amount. |
_user | address | The address of the user. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The borrow balance of the user (in underlying). |
_collateralValue
Calculates the value of the collateral.
function _collateralValue(address _poolToken, address _user, uint256 _underlyingPrice, uint256 _tokenUnit)
internal
view
returns (uint256 collateral);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The pool token to calculate the value for. |
_user | address | The user address. |
_underlyingPrice | uint256 | The underlying price. |
_tokenUnit | uint256 | The token unit. |
_debtValue
Calculates the value of the debt.
function _debtValue(address _poolToken, address _user, uint256 _underlyingPrice, uint256 _tokenUnit)
internal
view
returns (uint256 debt);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The pool token to calculate the value for. |
_user | address | The user address. |
_underlyingPrice | uint256 | The underlying price. |
_tokenUnit | uint256 | The token unit. |
_liquidityData
Calculates the total value of the collateral, debt, and LTV/LT value depending on the calculation type.
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 _amountWithdrawn
to be less than or equal to the given user's supply on the given market.
function _liquidityData(address _user, address _poolToken, uint256 _amountWithdrawn, uint256 _amountBorrowed)
internal
returns (Types.LiquidityData memory values);
Parameters
Name | Type | Description |
---|---|---|
_user | address | The user address. |
_poolToken | address | The pool token that is being borrowed or withdrawn. |
_amountWithdrawn | uint256 | The amount that is being withdrawn. |
_amountBorrowed | uint256 | The amount that is being borrowed. |
Returns
Name | Type | Description |
---|---|---|
values | Types.LiquidityData | The struct containing health factor, collateral, debt, ltv, liquidation threshold values. |
Errors
MarketNotCreated
ERRORS ///
Thrown when the market is not created yet.
error MarketNotCreated();
Structs
LiquidityVars
STRUCTS ///
struct LiquidityVars {
address poolToken;
uint256 poolTokensLength;
bytes32 userMarkets;
bytes32 borrowMask;
address underlyingToken;
uint256 underlyingPrice;
}