RatesLens
Inherits: UsersLens
Author: Morpho Labs.
Intermediary layer exposing endpoints to query live data related to the Morpho Protocol users and their positions.
Functions
getNextUserSupplyRatePerBlock
EXTERNAL ///
Returns the supply rate per block experienced on a market after having supplied the given amount on behalf of the given user.
Note: the returned supply rate is a low estimate: when supplying through Morpho-Compound, a supplier could be matched more than once instantly or later and thus benefit from a higher supply rate.
function getNextUserSupplyRatePerBlock(address _poolToken, address _user, uint256 _amount)
external
view
returns (uint256 nextSupplyRatePerBlock, uint256 balanceOnPool, uint256 balanceInP2P, uint256 totalBalance);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market. |
_user | address | The address of the user on behalf of whom to supply. |
_amount | uint256 | The amount to supply. |
Returns
Name | Type | Description |
---|---|---|
nextSupplyRatePerBlock | uint256 | An approximation of the next supply rate per block experienced after having supplied (in wad). |
balanceOnPool | uint256 | The total balance supplied on pool after having supplied (in underlying). |
balanceInP2P | uint256 | The total balance matched peer-to-peer after having supplied (in underlying). |
totalBalance | uint256 | The total balance supplied through Morpho (in underlying). |
getNextUserBorrowRatePerBlock
Returns the borrow rate per block experienced on a market after having supplied the given amount on behalf of the given user.
Note: the returned borrow rate is a high estimate: when borrowing through Morpho-Compound, a borrower could be matched more than once instantly or later and thus benefit from a lower borrow rate.
function getNextUserBorrowRatePerBlock(address _poolToken, address _user, uint256 _amount)
external
view
returns (uint256 nextBorrowRatePerBlock, uint256 balanceOnPool, uint256 balanceInP2P, uint256 totalBalance);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market. |
_user | address | The address of the user on behalf of whom to borrow. |
_amount | uint256 | The amount to borrow. |
Returns
Name | Type | Description |
---|---|---|
nextBorrowRatePerBlock | uint256 | An approximation of the next borrow rate per block experienced after having supplied (in wad). |
balanceOnPool | uint256 | The total balance supplied on pool after having supplied (in underlying). |
balanceInP2P | uint256 | The total balance matched peer-to-peer after having supplied (in underlying). |
totalBalance | uint256 | The total balance supplied through Morpho (in underlying). |
getCurrentUserSupplyRatePerBlock
Returns the supply rate per block a given user is currently experiencing on a given market.
function getCurrentUserSupplyRatePerBlock(address _poolToken, address _user)
external
view
returns (uint256 supplyRatePerBlock);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market. |
_user | address | The user to compute the supply rate per block for. |
Returns
Name | Type | Description |
---|---|---|
supplyRatePerBlock | uint256 | The supply rate per block the user is currently experiencing (in wad). |
getCurrentUserBorrowRatePerBlock
Returns the borrow rate per block a given user is currently experiencing on a given market.
function getCurrentUserBorrowRatePerBlock(address _poolToken, address _user)
external
view
returns (uint256 borrowRatePerBlock);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market. |
_user | address | The user to compute the borrow rate per block for. |
Returns
Name | Type | Description |
---|---|---|
borrowRatePerBlock | uint256 | The borrow rate per block the user is currently experiencing (in wad). |
getAverageSupplyRatePerBlock
PUBLIC ///
Computes and returns the current supply rate per block experienced on average on a given market.
function getAverageSupplyRatePerBlock(address _poolToken)
public
view
returns (uint256 avgSupplyRatePerBlock, uint256 p2pSupplyAmount, uint256 poolSupplyAmount);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The market address. |
Returns
Name | Type | Description |
---|---|---|
avgSupplyRatePerBlock | uint256 | The market's average supply rate per block (in wad). |
p2pSupplyAmount | uint256 | The total supplied amount matched peer-to-peer, subtracting the supply delta (in underlying). |
poolSupplyAmount | uint256 | The total supplied amount on the underlying pool, adding the supply delta (in underlying). |
getAverageBorrowRatePerBlock
Computes and returns the current average borrow rate per block experienced on a given market.
function getAverageBorrowRatePerBlock(address _poolToken)
public
view
returns (uint256 avgBorrowRatePerBlock, uint256 p2pBorrowAmount, uint256 poolBorrowAmount);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The market address. |
Returns
Name | Type | Description |
---|---|---|
avgBorrowRatePerBlock | uint256 | The market's average borrow rate per block (in wad). |
p2pBorrowAmount | uint256 | The total borrowed amount matched peer-to-peer, subtracting the borrow delta (in underlying). |
poolBorrowAmount | uint256 | The total borrowed amount on the underlying pool, adding the borrow delta (in underlying). |
getRatesPerBlock
Computes and returns peer-to-peer and pool rates for a specific market.
Note: prefer using getAverageSupplyRatePerBlock & getAverageBorrowRatePerBlock to get the actual experienced supply/borrow rate.
function getRatesPerBlock(address _poolToken) external view returns (uint256, uint256, uint256, uint256);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The market address. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | p2pSupplyRate The market's peer-to-peer supply rate per block (in wad). |
<none> | uint256 | p2pBorrowRate The market's peer-to-peer borrow rate per block (in wad). |
<none> | uint256 | poolSupplyRate The market's pool supply rate per block (in wad). |
<none> | uint256 | poolBorrowRate The market's pool borrow rate per block (in wad). |
_getRatesPerBlock
Computes and returns peer-to-peer and pool rates for a specific market.
function _getRatesPerBlock(
address _poolToken,
uint256 _suppliedOnPool,
uint256 _borrowedFromPool,
uint256 _repaidOnPool,
uint256 _withdrawnFromPool
)
internal
view
returns (uint256 p2pSupplyRate, uint256 p2pBorrowRate, uint256 poolSupplyRate, uint256 poolBorrowRate);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The market address. |
_suppliedOnPool | uint256 | The amount hypothetically supplied to the underlying's pool (in underlying). |
_borrowedFromPool | uint256 | The amount hypothetically borrowed from the underlying's pool (in underlying). |
_repaidOnPool | uint256 | The amount hypothetically repaid to the underlying's pool (in underlying). |
_withdrawnFromPool | uint256 | The amount hypothetically withdrawn from the underlying's pool (in underlying). |
Returns
Name | Type | Description |
---|---|---|
p2pSupplyRate | uint256 | The market's peer-to-peer supply rate per block (in wad). |
p2pBorrowRate | uint256 | The market's peer-to-peer borrow rate per block (in wad). |
poolSupplyRate | uint256 | The market's pool supply rate per block (in wad). |
poolBorrowRate | uint256 | The market's pool borrow rate per block (in wad). |
_getMarketSupply
Computes and returns the total distribution of supply for a given market, using virtually updated indexes.
function _getMarketSupply(
address _poolToken,
uint256 _p2pSupplyIndex,
uint256 _poolSupplyIndex,
Types.Delta memory _delta
) internal view returns (uint256 p2pSupplyAmount, uint256 poolSupplyAmount);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market to check. |
_p2pSupplyIndex | uint256 | The given market's peer-to-peer supply index. |
_poolSupplyIndex | uint256 | The given market's pool supply index. |
_delta | Types.Delta | The given market's deltas. |
Returns
Name | Type | Description |
---|---|---|
p2pSupplyAmount | uint256 | The total supplied amount matched peer-to-peer, subtracting the supply delta (in underlying). |
poolSupplyAmount | uint256 | The total supplied amount on the underlying pool, adding the supply delta (in underlying). |
_getMarketBorrow
Computes and returns the total distribution of borrows for a given market, using virtually updated indexes.
function _getMarketBorrow(
address _poolToken,
uint256 _p2pBorrowIndex,
uint256 _poolBorrowIndex,
Types.Delta memory _delta
) internal view returns (uint256 p2pBorrowAmount, uint256 poolBorrowAmount);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market to check. |
_p2pBorrowIndex | uint256 | The given market's peer-to-peer borrow index. |
_poolBorrowIndex | uint256 | The given market's borrow index. |
_delta | Types.Delta | The given market's deltas. |
Returns
Name | Type | Description |
---|---|---|
p2pBorrowAmount | uint256 | The total borrowed amount matched peer-to-peer, subtracting the borrow delta (in underlying). |
poolBorrowAmount | uint256 | The total borrowed amount on the underlying pool, adding the borrow delta (in underlying). |
_getUserSupplyRatePerBlock
Returns the supply rate per block experienced on a market based on a given position distribution. The calculation takes into account the change in pool rates implied by an hypothetical supply and/or repay.
function _getUserSupplyRatePerBlock(
address _poolToken,
uint256 _balanceInP2P,
uint256 _balanceOnPool,
uint256 _suppliedOnPool,
uint256 _repaidToPool
) internal view returns (uint256, uint256);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market. |
_balanceInP2P | uint256 | The amount of balance matched peer-to-peer (in a unit common to _balanceOnPool ). |
_balanceOnPool | uint256 | The amount of balance supplied on pool (in a unit common to _balanceInP2P ). |
_suppliedOnPool | uint256 | The amount hypothetically supplied on pool (in underlying). |
_repaidToPool | uint256 | The amount hypothetically repaid to the pool (in underlying). |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The supply rate per block experienced by the given position (in wad). |
<none> | uint256 | The sum of peer-to-peer & pool balances. |
_getUserBorrowRatePerBlock
Returns the borrow rate per block experienced on a market based on a given position distribution. The calculation takes into account the change in pool rates implied by an hypothetical borrow and/or withdraw.
function _getUserBorrowRatePerBlock(
address _poolToken,
uint256 _balanceInP2P,
uint256 _balanceOnPool,
uint256 _borrowedFromPool,
uint256 _withdrawnFromPool
) internal view returns (uint256, uint256);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market. |
_balanceInP2P | uint256 | The amount of balance matched peer-to-peer (in a unit common to _balanceOnPool ). |
_balanceOnPool | uint256 | The amount of balance supplied on pool (in a unit common to _balanceInP2P ). |
_borrowedFromPool | uint256 | The amount hypothetically borrowed from the pool (in underlying). |
_withdrawnFromPool | uint256 | The amount hypothetically withdrawn from the pool (in underlying). |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The borrow rate per block experienced by the given position (in wad). |
<none> | uint256 | The sum of peer-to-peer & pool balances. |
_getWeightedRate
Returns the rate experienced based on a given pool & peer-to-peer distribution.
function _getWeightedRate(uint256 _p2pRate, uint256 _poolRate, uint256 _balanceInP2P, uint256 _balanceOnPool)
internal
pure
returns (uint256 weightedRate, uint256 totalBalance);
Parameters
Name | Type | Description |
---|---|---|
_p2pRate | uint256 | The peer-to-peer rate (in a unit common to _poolRate & weightedRate ). |
_poolRate | uint256 | The pool rate (in a unit common to _p2pRate & weightedRate ). |
_balanceInP2P | uint256 | The amount of balance matched peer-to-peer (in a unit common to _balanceOnPool ). |
_balanceOnPool | uint256 | The amount of balance supplied on pool (in a unit common to _balanceInP2P ). |
Returns
Name | Type | Description |
---|---|---|
weightedRate | uint256 | The rate experienced by the given distribution (in a unit common to _p2pRate & _poolRate ). |
totalBalance | uint256 | The sum of peer-to-peer & pool balances. |
Errors
BorrowRateFailed
ERRORS ///
error BorrowRateFailed();
Structs
PoolRatesVars
INTERNAL ///
struct PoolRatesVars {
Types.Delta delta;
Types.LastPoolIndexes lastPoolIndexes;
Types.Indexes indexes;
Types.MarketParameters params;
}