MatchingEngine

Git Source

Inherits: MorphoInternal

Author: Morpho Labs

Abstract contract with functions to promote or demote users to/from peer-to-peer.

Functions

_promoteSuppliers

Promotes suppliers on the underlying market.

function _promoteSuppliers(address underlying, uint256 amount, uint256 maxIterations)
    internal
    returns (uint256, uint256);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying market on which to promote suppliers.
amountuint256The amount of underlying to promote.
maxIterationsuint256The maximum number of iterations allowed during the matching process.

_promoteBorrowers

Promotes borrowers on the underlying market.

function _promoteBorrowers(address underlying, uint256 amount, uint256 maxIterations)
    internal
    returns (uint256, uint256);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying market on which to promote borrowers.
amountuint256The amount of underlying to promote.
maxIterationsuint256The maximum number of iterations allowed during the matching process.

_demoteSuppliers

Demotes suppliers on the underlying market.

function _demoteSuppliers(address underlying, uint256 amount, uint256 maxIterations)
    internal
    returns (uint256 demoted);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying market on which to demote suppliers.
amountuint256The amount of underlying to demote.
maxIterationsuint256The maximum number of iterations allowed during the matching process.

_demoteBorrowers

Demotes borrowers on the underlying market.

function _demoteBorrowers(address underlying, uint256 amount, uint256 maxIterations)
    internal
    returns (uint256 demoted);

Parameters

NameTypeDescription
underlyingaddressThe address of the underlying market on which to demote borrowers.
amountuint256The amount of underlying to demote.
maxIterationsuint256The maximum number of iterations allowed during the matching process.

_promoteOrDemote

Promotes or demotes users.

function _promoteOrDemote(
    LogarithmicBuckets.Buckets storage poolBuckets,
    LogarithmicBuckets.Buckets storage p2pBuckets,
    Types.MatchingEngineVars memory vars
) internal returns (uint256 processed, uint256 iterationsDone);

Parameters

NameTypeDescription
poolBucketsLogarithmicBuckets.BucketsThe pool buckets.
p2pBucketsLogarithmicBuckets.Buckets
varsTypes.MatchingEngineVarsThe required matching engine variables to perform the matching process.

_promote

Promotes a given amount in peer-to-peer.

function _promote(uint256 poolBalance, uint256 p2pBalance, Types.MarketSideIndexes256 memory indexes, uint256 remaining)
    internal
    pure
    returns (uint256 newPoolBalance, uint256 newP2PBalance, uint256 newRemaining);

Parameters

NameTypeDescription
poolBalanceuint256The scaled balance of the user on the pool.
p2pBalanceuint256The scaled balance of the user in peer-to-peer.
indexesTypes.MarketSideIndexes256The indexes of the market.
remaininguint256The remaining amount to promote.

_demote

Demotes a given amount in peer-to-peer.

function _demote(uint256 poolBalance, uint256 p2pBalance, Types.MarketSideIndexes256 memory indexes, uint256 remaining)
    internal
    pure
    returns (uint256 newPoolBalance, uint256 newP2PBalance, uint256 newRemaining);

Parameters

NameTypeDescription
poolBalanceuint256The scaled balance of the user on the pool.
p2pBalanceuint256The scaled balance of the user in peer-to-peer.
indexesTypes.MarketSideIndexes256The indexes of the market.
remaininguint256The remaining amount to demote.