MorphoInternal

Git Source

Inherits: MorphoStorage

Author: Morpho Labs

Abstract contract exposing Morpho's internal functions.

Functions

_domainSeparator

Dynamically computed to use the root proxy address in a delegate call.

function _domainSeparator() internal view returns (bytes32);

_createMarket

Creates a new market for the underlying token with a given reserveFactor (in bps) and a given p2pIndexCursor (in bps).

function _createMarket(address underlying, uint16 reserveFactor, uint16 p2pIndexCursor) internal;

_claimToTreasury

Claims the fee for the underlyings and send it to the _treasuryVault. Claiming on a market where there are some rewards might steal users' rewards.

function _claimToTreasury(address[] calldata underlyings, uint256[] calldata amounts) internal;

_increaseP2PDeltas

Increases the peer-to-peer delta of amount on the underlying market.

Note that this can fail if the amount is too big. In this case, consider splitting in multiple calls/txs.

function _increaseP2PDeltas(address underlying, uint256 amount) internal;

_hashEIP712TypedData

Returns the hash of the EIP712 typed data.

function _hashEIP712TypedData(bytes32 structHash) internal view returns (bytes32);

_approveManager

Approves a manager to borrow/withdraw on behalf of the delegator.

function _approveManager(address delegator, address manager, bool isAllowed) internal;

Parameters

NameTypeDescription
delegatoraddressThe address of the delegator.
manageraddressThe address of the manager.
isAllowedboolWhether manager is allowed to manage delegator's position or not.

_getUserSupplyBalanceFromIndexes

Returns the total supply balance of user on the underlying market given indexes (in underlying).

function _getUserSupplyBalanceFromIndexes(address underlying, address user, Types.Indexes256 memory indexes)
    internal
    view
    returns (uint256);

_getUserBorrowBalanceFromIndexes

Returns the total borrow balance of user on the underlying market given indexes (in underlying).

function _getUserBorrowBalanceFromIndexes(address underlying, address user, Types.Indexes256 memory indexes)
    internal
    view
    returns (uint256);

_getUserCollateralBalanceFromIndex

Returns the collateral balance of user on the underlying market a poolSupplyIndex (in underlying).

function _getUserCollateralBalanceFromIndex(address underlying, address user, uint256 poolSupplyIndex)
    internal
    view
    returns (uint256);

_getBuckets

Returns the buckets of a particular side of a market.

function _getBuckets(address underlying, Types.Position position)
    internal
    view
    returns (LogarithmicBuckets.Buckets storage);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying asset.
positionTypes.PositionThe side of the market.

_liquidityData

Returns the liquidity data about the position of user.

function _liquidityData(address user) internal view returns (Types.LiquidityData memory liquidityData);

Parameters

NameTypeDescription
useraddressThe address of the user to get the liquidity data for.

Returns

NameTypeDescription
liquidityDataTypes.LiquidityDataThe liquidity data of the user.

_totalCollateralData

Returns the collateral data for a given set of inputs.

The total collateral data is computed looping through all user's collateral assets.

function _totalCollateralData(Types.LiquidityVars memory vars)
    internal
    view
    returns (uint256 borrowable, uint256 maxDebt);

Parameters

NameTypeDescription
varsTypes.LiquidityVarsThe liquidity variables.

Returns

NameTypeDescription
borrowableuint256The total borrowable amount of vars.user.
maxDebtuint256The total maximum debt of vars.user.

_totalDebt

Returns the debt data for a given set of inputs.

The total debt data is computed iterating through all user's borrow assets.

function _totalDebt(Types.LiquidityVars memory vars) internal view returns (uint256 debt);

Parameters

NameTypeDescription
varsTypes.LiquidityVarsThe liquidity variables.

Returns

NameTypeDescription
debtuint256The total debt of vars.user.

_collateralData

Returns the collateral data for a given set of inputs.

function _collateralData(address underlying, Types.LiquidityVars memory vars)
    internal
    view
    returns (uint256 borrowable, uint256 maxDebt);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying collateral asset.
varsTypes.LiquidityVarsThe liquidity variables.

Returns

NameTypeDescription
borrowableuint256The borrowable amount of vars.user on the underlying market.
maxDebtuint256The maximum debt of vars.user on the underlying market.

_debt

Returns the debt value for a given set of inputs.

function _debt(address underlying, Types.LiquidityVars memory vars) internal view returns (uint256 debtValue);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying asset to borrow.
varsTypes.LiquidityVarsThe liquidity variables.

Returns

NameTypeDescription
debtValueuint256The debt value of vars.user on the underlying market.

_assetLiquidityData

Returns the liquidity data for a given set of inputs.

function _assetLiquidityData(address underlying, Types.LiquidityVars memory vars)
    internal
    view
    returns (uint256 underlyingPrice, uint256 ltv, uint256 liquidationThreshold, uint256 underlyingUnit);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying asset.
varsTypes.LiquidityVarsThe liquidity variables.

Returns

NameTypeDescription
underlyingPriceuint256The price of the underlying asset (in base currency).
ltvuint256The loan to value of the underlying asset.
liquidationThresholduint256The liquidation threshold of the underlying asset.
underlyingUnituint256The token unit of the underlying asset.

_updateRewards

Prompts the rewards manager (if set) to accrue a user's rewards.

function _updateRewards(address user, address poolToken, uint256 formerOnPool) internal;

Parameters

NameTypeDescription
useraddressThe address of the user to accrue rewards for.
poolTokenaddressThe address of the pool token related to this market (aToken or variable debt token address).
formerOnPooluint256The former scaled balance on pool of the user.

_updateInDS

Updates a user's position in the data structure.

function _updateInDS(
    address poolToken,
    address user,
    LogarithmicBuckets.Buckets storage poolBuckets,
    LogarithmicBuckets.Buckets storage p2pBuckets,
    uint256 onPool,
    uint256 inP2P,
    bool demoting
) internal returns (uint256, uint256);

Parameters

NameTypeDescription
poolTokenaddressThe address of the pool token related to this market (aToken or variable debt token address).
useraddressThe address of the user to update.
poolBucketsLogarithmicBuckets.BucketsThe pool buckets.
p2pBucketsLogarithmicBuckets.BucketsThe peer-to-peer buckets.
onPooluint256The new scaled balance on pool of the user.
inP2Puint256The new scaled balance in peer-to-peer of the user.
demotingboolWhether the update is happening during a demoting process or not.

Returns

NameTypeDescription
<none>uint256The actual new scaled balance on pool and in peer-to-peer of the user after accounting for dust.
<none>uint256

_updateSupplierInDS

Updates a user's supply position in the data structure.

function _updateSupplierInDS(address underlying, address user, uint256 onPool, uint256 inP2P, bool demoting)
    internal
    returns (uint256, uint256);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying asset.
useraddressThe address of the user to update.
onPooluint256The new scaled balance on pool of the user.
inP2Puint256The new scaled balance in peer-to-peer of the user.
demotingboolWhether the update is happening during a demoting process or not.

Returns

NameTypeDescription
<none>uint256The actual new scaled balance on pool and in peer-to-peer of the user after accounting for dust.
<none>uint256

_updateBorrowerInDS

Updates a user's borrow position in the data structure.

function _updateBorrowerInDS(address underlying, address user, uint256 onPool, uint256 inP2P, bool demoting)
    internal
    returns (uint256, uint256);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying asset.
useraddressThe address of the user to update.
onPooluint256The new scaled balance on pool of the user.
inP2Puint256The new scaled balance in peer-to-peer of the user.
demotingboolWhether the update is happening during a demoting process or not.

Returns

NameTypeDescription
<none>uint256The actual new scaled balance on pool and in peer-to-peer of the user after accounting for dust.
<none>uint256

_setPauseStatus

Sets globally the pause status to isPaused on the underlying market.

function _setPauseStatus(address underlying, bool isPaused) internal;

_updateIndexes

Updates the indexes of the underlying market and returns them.

function _updateIndexes(address underlying) internal returns (Types.Indexes256 memory indexes);

_computeIndexes

Computes the updated indexes of the underlying market and returns them.

function _computeIndexes(address underlying) internal view returns (Types.Indexes256 memory indexes);

_getUserHealthFactor

Returns the user's health factor.

function _getUserHealthFactor(address user) internal view returns (uint256);

_assetData

Returns data relative to the given asset and its configuration, according to a given oracle.

function _assetData(
    address asset,
    IAaveOracle oracle,
    DataTypes.ReserveConfigurationMap memory config,
    address priceSource
) internal view returns (bool, uint256, uint256);

Returns

NameTypeDescription
<none>boolWhether the given asset is part of Morpho's e-mode category.
<none>uint256The asset's price or the price of the given e-mode price source if the asset is in the e-mode category, according to the given oracle.
<none>uint256The asset's unit.

_isInEModeCategory

Returns whether Morpho is in an e-mode category and the given asset configuration is in the same e-mode category.

function _isInEModeCategory(DataTypes.ReserveConfigurationMap memory config) internal view returns (bool);