MarketLib

Git Source

Author: Morpho Labs

Library used to ease market reads and writes.

Functions

isCreated

Returns whether the market is created or not.

function isCreated(Types.Market storage market) internal view returns (bool);

isSupplyPaused

Returns whether supply is paused on market or not.

function isSupplyPaused(Types.Market storage market) internal view returns (bool);

isSupplyCollateralPaused

Returns whether supply collateral is paused on market or not.

function isSupplyCollateralPaused(Types.Market storage market) internal view returns (bool);

isBorrowPaused

Returns whether borrow is paused on market or not.

function isBorrowPaused(Types.Market storage market) internal view returns (bool);

isRepayPaused

Returns whether repay is paused on market or not.

function isRepayPaused(Types.Market storage market) internal view returns (bool);

isWithdrawPaused

Returns whether withdraw is paused on market or not.

function isWithdrawPaused(Types.Market storage market) internal view returns (bool);

isWithdrawCollateralPaused

Returns whether withdraw collateral is paused on market or not.

function isWithdrawCollateralPaused(Types.Market storage market) internal view returns (bool);

isLiquidateCollateralPaused

Returns whether liquidate collateral is paused on market or not.

function isLiquidateCollateralPaused(Types.Market storage market) internal view returns (bool);

isLiquidateBorrowPaused

Returns whether liquidate borrow is paused on market or not.

function isLiquidateBorrowPaused(Types.Market storage market) internal view returns (bool);

isDeprecated

Returns whether the market is deprecated or not.

function isDeprecated(Types.Market storage market) internal view returns (bool);

isP2PDisabled

Returns whether the peer-to-peer is disabled on market or not.

function isP2PDisabled(Types.Market storage market) internal view returns (bool);

setAssetIsCollateral

Sets the market as isCollateral on Morpho.

function setAssetIsCollateral(Types.Market storage market, bool isCollateral) internal;

setIsSupplyPaused

Sets the market supply pause status as isPaused on Morpho.

function setIsSupplyPaused(Types.Market storage market, bool isPaused) internal;

setIsSupplyCollateralPaused

Sets the market supply collateral pause status as isPaused on Morpho.

function setIsSupplyCollateralPaused(Types.Market storage market, bool isPaused) internal;

setIsBorrowPaused

Sets the market borrow pause status as isPaused on Morpho.

function setIsBorrowPaused(Types.Market storage market, bool isPaused) internal;

setIsRepayPaused

Sets the market repay pause status as isPaused on Morpho.

function setIsRepayPaused(Types.Market storage market, bool isPaused) internal;

setIsWithdrawPaused

Sets the market withdraw pause status as isPaused on Morpho.

function setIsWithdrawPaused(Types.Market storage market, bool isPaused) internal;

setIsWithdrawCollateralPaused

Sets the market withdraw collateral pause status as isPaused on Morpho.

function setIsWithdrawCollateralPaused(Types.Market storage market, bool isPaused) internal;

setIsLiquidateCollateralPaused

Sets the market liquidate collateral pause status as isPaused on Morpho.

function setIsLiquidateCollateralPaused(Types.Market storage market, bool isPaused) internal;

setIsLiquidateBorrowPaused

Sets the market liquidate borrow pause status as isPaused on Morpho.

function setIsLiquidateBorrowPaused(Types.Market storage market, bool isPaused) internal;

setIsDeprecated

Sets the market as deprecated on Morpho.

function setIsDeprecated(Types.Market storage market, bool deprecated) internal;

setIsP2PDisabled

Sets the market peer-to-peer as p2pDisabled on Morpho.

function setIsP2PDisabled(Types.Market storage market, bool p2pDisabled) internal;

setReserveFactor

Sets the market peer-to-peer reserve factor to reserveFactor.

function setReserveFactor(Types.Market storage market, uint16 reserveFactor) internal;

setP2PIndexCursor

Sets the market peer-to-peer index cursor to p2pIndexCursor.

function setP2PIndexCursor(Types.Market storage market, uint16 p2pIndexCursor) internal;

setIndexes

Sets the market indexes to indexes.

function setIndexes(Types.Market storage market, Types.Indexes256 memory indexes) internal;

getSupplyIndexes

Returns the supply indexes of market.

function getSupplyIndexes(Types.Market storage market)
    internal
    view
    returns (Types.MarketSideIndexes256 memory supplyIndexes);

getBorrowIndexes

Returns the borrow indexes of market.

function getBorrowIndexes(Types.Market storage market)
    internal
    view
    returns (Types.MarketSideIndexes256 memory borrowIndexes);

getIndexes

Returns the indexes of market.

function getIndexes(Types.Market storage market) internal view returns (Types.Indexes256 memory indexes);

getProportionIdle

Returns the proportion of idle supply in market over the total peer-to-peer amount in supply.

function getProportionIdle(Types.Market storage market) internal view returns (uint256);

increaseIdle

Increases the idle supply if the supply cap is reached in a breaking repay, and returns a new toSupply amount.

function increaseIdle(
    Types.Market storage market,
    address underlying,
    uint256 amount,
    DataTypes.ReserveData memory reserve,
    Types.Indexes256 memory indexes
) internal returns (uint256, uint256);

Parameters

NameTypeDescription
marketTypes.MarketThe market storage.
underlyingaddressThe underlying address.
amountuint256The amount to repay. (by supplying on pool)
reserveDataTypes.ReserveDataThe reserve data for the market.
indexesTypes.Indexes256

Returns

NameTypeDescription
<none>uint256The amount to supply to stay below the supply cap and the amount the idle supply was increased by.
<none>uint256

decreaseIdle

Decreases the idle supply.

function decreaseIdle(Types.Market storage market, address underlying, uint256 amount)
    internal
    returns (uint256, uint256);

Parameters

NameTypeDescription
marketTypes.MarketThe market storage.
underlyingaddressThe underlying address.
amountuint256The amount to borrow.

Returns

NameTypeDescription
<none>uint256The amount left to process and the processed amount.
<none>uint256

trueP2PSupply

Calculates the total quantity of underlyings truly supplied peer-to-peer on the given market.

function trueP2PSupply(Types.Market storage market, Types.Indexes256 memory indexes) internal view returns (uint256);

Parameters

NameTypeDescription
marketTypes.Market
indexesTypes.Indexes256The current indexes.

Returns

NameTypeDescription
<none>uint256The total peer-to-peer supply (total peer-to-peer supply - supply delta - idle supply).

trueP2PBorrow

Calculates the total quantity of underlyings truly borrowed peer-to-peer on the given market.

function trueP2PBorrow(Types.Market storage market, Types.Indexes256 memory indexes) internal view returns (uint256);

Parameters

NameTypeDescription
marketTypes.Market
indexesTypes.Indexes256The current indexes.

Returns

NameTypeDescription
<none>uint256The total peer-to-peer borrow (total peer-to-peer borrow - borrow delta).

repayFee

Calculates & deducts the reserve fee to repay from the given amount, updating the total peer-to-peer amount.

function repayFee(Types.Market storage market, uint256 amount, Types.Indexes256 memory indexes)
    internal
    returns (uint256);

Parameters

NameTypeDescription
marketTypes.Market
amountuint256The amount to repay (in underlying).
indexesTypes.Indexes256The current indexes.

Returns

NameTypeDescription
<none>uint256The new amount left to process (in underlying).