PositionsManagerInternal
Inherits: MatchingEngine
Author: Morpho Labs
Abstract contract defining PositionsManager
's internal functions.
Functions
_validatePermission
Validates the manager's permission.
function _validatePermission(address delegator, address manager) internal view;
_validateInput
Validates the input.
function _validateInput(address underlying, uint256 amount, address user)
internal
view
returns (Types.Market storage market);
_validateManagerInput
Validates the manager's permission and the input.
function _validateManagerInput(address underlying, uint256 amount, address onBehalf, address receiver)
internal
view
returns (Types.Market storage market);
_validateSupply
Validates a supply action.
function _validateSupply(address underlying, uint256 amount, address user)
internal
view
returns (Types.Market storage market);
_validateSupplyCollateral
Validates a supply collateral action.
function _validateSupplyCollateral(address underlying, uint256 amount, address user) internal view;
_validateBorrow
Validates a borrow action.
function _validateBorrow(address underlying, uint256 amount, address borrower, address receiver)
internal
view
returns (Types.Market storage market);
_authorizeBorrow
Authorizes a borrow action.
function _authorizeBorrow(address underlying, uint256 amount, Types.Indexes256 memory indexes) internal view;
_validateRepay
Validates a repay action.
function _validateRepay(address underlying, uint256 amount, address user)
internal
view
returns (Types.Market storage market);
_validateWithdraw
Validates a withdraw action.
function _validateWithdraw(address underlying, uint256 amount, address supplier, address receiver)
internal
view
returns (Types.Market storage market);
_validateWithdrawCollateral
Validates a withdraw collateral action.
function _validateWithdrawCollateral(address underlying, uint256 amount, address supplier, address receiver)
internal
view
returns (Types.Market storage market);
_validateLiquidate
Validates a liquidate action.
function _validateLiquidate(address underlyingBorrowed, address underlyingCollateral, address borrower) internal view;
_authorizeLiquidate
Authorizes a liquidate action.
function _authorizeLiquidate(address underlyingBorrowed, address borrower) internal view returns (uint256);
_accountSupply
Performs the accounting of a supply action.
function _accountSupply(
address underlying,
uint256 amount,
address onBehalf,
uint256 maxIterations,
Types.Indexes256 memory indexes
) internal returns (Types.SupplyRepayVars memory vars);
_accountBorrow
Performs the accounting of a borrow action.
Note: the borrower's set of borrowed market is updated in _updateBorrowerInDS
.
function _accountBorrow(
address underlying,
uint256 amount,
address borrower,
uint256 maxIterations,
Types.Indexes256 memory indexes
) internal returns (Types.BorrowWithdrawVars memory vars);
_accountRepay
Performs the accounting of a repay action.
Note: the borrower's set of borrowed market is updated in _updateBorrowerInDS
.
function _accountRepay(
address underlying,
uint256 amount,
address onBehalf,
uint256 maxIterations,
Types.Indexes256 memory indexes
) internal returns (Types.SupplyRepayVars memory vars);
_accountWithdraw
Performs the accounting of a withdraw action.
function _accountWithdraw(
address underlying,
uint256 amount,
address supplier,
uint256 maxIterations,
Types.Indexes256 memory indexes
) internal returns (Types.BorrowWithdrawVars memory vars);
_accountSupplyCollateral
Performs the accounting of a supply action.
function _accountSupplyCollateral(address underlying, uint256 amount, address onBehalf, uint256 poolSupplyIndex)
internal
returns (uint256 collateralBalance);
_accountWithdrawCollateral
Performs the accounting of a withdraw collateral action.
function _accountWithdrawCollateral(address underlying, uint256 amount, address onBehalf, uint256 poolSupplyIndex)
internal
returns (uint256 collateralBalance);
_executeSupply
Executes a supply action.
function _executeSupply(
address underlying,
uint256 amount,
address from,
address onBehalf,
uint256 maxIterations,
Types.Indexes256 memory indexes
) internal returns (Types.SupplyRepayVars memory vars);
_executeBorrow
Executes a borrow action.
function _executeBorrow(
address underlying,
uint256 amount,
address onBehalf,
address receiver,
uint256 maxIterations,
Types.Indexes256 memory indexes
) internal returns (Types.BorrowWithdrawVars memory vars);
_executeRepay
Executes a repay action.
function _executeRepay(
address underlying,
uint256 amount,
address repayer,
address onBehalf,
uint256 maxIterations,
Types.Indexes256 memory indexes
) internal returns (Types.SupplyRepayVars memory vars);
_executeWithdraw
Executes a withdraw action.
function _executeWithdraw(
address underlying,
uint256 amount,
address onBehalf,
address receiver,
uint256 maxIterations,
Types.Indexes256 memory indexes
) internal returns (Types.BorrowWithdrawVars memory vars);
_executeSupplyCollateral
Executes a supply collateral action.
function _executeSupplyCollateral(
address underlying,
uint256 amount,
address from,
address onBehalf,
uint256 poolSupplyIndex
) internal;
_executeWithdrawCollateral
Executes a withdraw collateral action.
function _executeWithdrawCollateral(
address underlying,
uint256 amount,
address onBehalf,
address receiver,
uint256 poolSupplyIndex
) internal;
_addToPool
Given variables from a market side, calculates the amount to supply/borrow and a new on pool amount.
function _addToPool(uint256 amount, uint256 onPool, uint256 poolIndex) internal pure returns (uint256, uint256);
Parameters
Name | Type | Description |
---|---|---|
amount | uint256 | The amount to supply/borrow. |
onPool | uint256 | The current user's scaled on pool balance. |
poolIndex | uint256 | The current pool index. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The amount to supply/borrow and the new on pool amount. |
<none> | uint256 |
_subFromPool
Given variables from a market side, calculates the amount to repay/withdraw, the amount left to process, and a new on pool amount.
function _subFromPool(uint256 amount, uint256 onPool, uint256 poolIndex)
internal
pure
returns (uint256, uint256, uint256);
Parameters
Name | Type | Description |
---|---|---|
amount | uint256 | The amount to repay/withdraw. |
onPool | uint256 | The current user's scaled on pool balance. |
poolIndex | uint256 | The current pool index. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The amount left to process, the amount to repay/withdraw, and the new on pool amount. |
<none> | uint256 | |
<none> | uint256 |
_promoteRoutine
Given variables from a market side, promotes users and calculates the amount to repay/withdraw from promote, the amount left to process, and the number of iterations left.
function _promoteRoutine(
address underlying,
uint256 amount,
uint256 maxIterations,
function(address, uint256, uint256) returns (uint256, uint256) promote
) internal returns (uint256, uint256, uint256);
Parameters
Name | Type | Description |
---|---|---|
underlying | address | The underlying address. |
amount | uint256 | The amount to supply/borrow. |
maxIterations | uint256 | The maximum number of iterations to run. |
promote | function (address, uint256, uint256) returns (uint256, uint256) | The promote function. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The amount left to process, the amount to repay/withdraw from promote, and the number of iterations left. |
<none> | uint256 | |
<none> | uint256 |
_calculateAmountToSeize
Calculates the amount to seize during a liquidation process.
function _calculateAmountToSeize(
address underlyingBorrowed,
address underlyingCollateral,
uint256 maxToRepay,
address borrower,
uint256 poolSupplyIndex
) internal view returns (uint256 amountToRepay, uint256 amountToSeize);
Parameters
Name | Type | Description |
---|---|---|
underlyingBorrowed | address | The address of the underlying borrowed asset. |
underlyingCollateral | address | The address of the underlying collateral asset. |
maxToRepay | uint256 | The maximum amount of underlyingBorrowed to repay. |
borrower | address | The address of the borrower being liquidated. |
poolSupplyIndex | uint256 | The current pool supply index of the underlyingCollateral market. |
Returns
Name | Type | Description |
---|---|---|
amountToRepay | uint256 | The amount of underlyingBorrowed to repay. |
amountToSeize | uint256 | The amount of underlyingCollateral to seize. |