MatchingEngine
Inherits: MorphoUtils
Author: Morpho Labs.
Smart contract managing the matching engine.
Functions
_matchSuppliers
INTERNAL ///
Matches suppliers' liquidity waiting on Aave up to the given _amount
and moves it to peer-to-peer.
Note: This function expects Aave's exchange rate and peer-to-peer indexes to have been updated.
function _matchSuppliers(address _poolToken, uint256 _amount, uint256 _maxGasForMatching)
internal
returns (uint256 matched, uint256 gasConsumedInMatching);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market from which to match suppliers. |
_amount | uint256 | The token amount to search for (in underlying). |
_maxGasForMatching | uint256 | The maximum amount of gas to consume within a matching engine loop. |
Returns
Name | Type | Description |
---|---|---|
matched | uint256 | The amount of liquidity matched (in underlying). |
gasConsumedInMatching | uint256 | The amount of gas consumed within the matching loop. |
_unmatchSuppliers
Unmatches suppliers' liquidity in peer-to-peer up to the given _amount
and moves it to Aave.
Note: This function expects Aave's exchange rate and peer-to-peer indexes to have been updated.
function _unmatchSuppliers(address _poolToken, uint256 _amount, uint256 _maxGasForMatching)
internal
returns (uint256 unmatched);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market from which to unmatch suppliers. |
_amount | uint256 | The amount to search for (in underlying). |
_maxGasForMatching | uint256 | The maximum amount of gas to consume within a matching engine loop. |
Returns
Name | Type | Description |
---|---|---|
unmatched | uint256 | The amount unmatched (in underlying). |
_matchBorrowers
Matches borrowers' liquidity waiting on Aave up to the given _amount
and moves it to peer-to-peer.
Note: This function expects stored indexes to have been updated.
function _matchBorrowers(address _poolToken, uint256 _amount, uint256 _maxGasForMatching)
internal
returns (uint256 matched, uint256 gasConsumedInMatching);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market from which to match borrowers. |
_amount | uint256 | The amount to search for (in underlying). |
_maxGasForMatching | uint256 | The maximum amount of gas to consume within a matching engine loop. |
Returns
Name | Type | Description |
---|---|---|
matched | uint256 | The amount of liquidity matched (in underlying). |
gasConsumedInMatching | uint256 | The amount of gas consumed within the matching loop. |
_unmatchBorrowers
Unmatches borrowers' liquidity in peer-to-peer for the given _amount
and moves it to Aave.
Note: This function expects and peer-to-peer indexes to have been updated.
function _unmatchBorrowers(address _poolToken, uint256 _amount, uint256 _maxGasForMatching)
internal
returns (uint256 unmatched);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market from which to unmatch borrowers. |
_amount | uint256 | The amount to unmatch (in underlying). |
_maxGasForMatching | uint256 | The maximum amount of gas to consume within a matching engine loop. |
Returns
Name | Type | Description |
---|---|---|
unmatched | uint256 | The amount unmatched (in underlying). |
_updateSupplierInDS
Updates the given _user
's position in the supplier data structures.
function _updateSupplierInDS(address _poolToken, address _user) internal;
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market on which to update the suppliers data structure. |
_user | address | The address of the user. |
_updateBorrowerInDS
Updates the given _user
's position in the borrower data structures.
function _updateBorrowerInDS(address _poolToken, address _user) internal;
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market on which to update the borrowers data structure. |
_user | address | The address of the user. |
Events
SupplierPositionUpdated
Emitted when the position of a supplier is updated.
event SupplierPositionUpdated(
address indexed _user, address indexed _poolToken, uint256 _balanceOnPool, uint256 _balanceInP2P
);
BorrowerPositionUpdated
Emitted when the position of a borrower is updated.
event BorrowerPositionUpdated(
address indexed _user, address indexed _poolToken, uint256 _balanceOnPool, uint256 _balanceInP2P
);
Structs
UnmatchVars
STRUCTS ///
struct UnmatchVars {
uint256 p2pIndex;
uint256 toUnmatch;
uint256 poolIndex;
}
MatchVars
struct MatchVars {
uint256 p2pIndex;
uint256 toMatch;
uint256 poolIndex;
}