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. |
getEnteredMarkets
EXTERNAL ///
Returns all markets entered by a given user.
function getEnteredMarkets(address _user) external view returns (address[] memory);
Parameters
Name | Type | Description |
---|---|---|
_user | address | The address of the user. |
Returns
Name | Type | Description |
---|---|---|
<none> | address[] | The list of markets entered by this user. |
getAllMarkets
Returns all created markets.
function getAllMarkets() external view returns (address[] memory);
Returns
Name | Type | Description |
---|---|---|
<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
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. |
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
Name | Type | Description |
---|---|---|
_poolToken | address | The 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
Name | Type | Description |
---|---|---|
_poolToken | address | The 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
Name | Type | Description |
---|---|---|
_user | address | The user to check. |
_poolToken | address | The market to hypothetically withdraw/borrow in. |
_withdrawnAmount | uint256 | The amount of tokens to hypothetically withdraw (in underlying). |
_borrowedAmount | uint256 | The 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
Name | Type | Description |
---|---|---|
_user | address | The user to determine data for. |
_poolToken | address | The address of the market. |
_oracle | ICompoundOracle | The oracle used. |
Returns
Name | Type | Description |
---|---|---|
assetData | Types.AssetLiquidityData | The 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
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). |
_getUnderlying
Returns the underlying ERC20 token related to the pool token.
function _getUnderlying(address _poolToken) internal view returns (ERC20);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the pool token. |
Returns
Name | Type | Description |
---|---|---|
<none> | ERC20 | The 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();