ExitPositionsManager
Inherits: IExitPositionsManager, PositionsManagerUtils
Author: Morpho Labs.
Morpho's exit points: withdraw, repay and liquidate.
Functions
withdrawLogic
LOGIC ///
Implements withdraw logic with security checks.
function withdrawLogic(
address _poolToken,
uint256 _amount,
address _supplier,
address _receiver,
uint256 _maxGasForMatching
) external;
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market the user wants to interact with. |
_amount | uint256 | The amount of token (in underlying). |
_supplier | address | The address of the supplier. |
_receiver | address | The address of the user who will receive the tokens. |
_maxGasForMatching | uint256 | The maximum amount of gas to consume within a matching engine loop. |
repayLogic
Implements repay logic with security checks.
function repayLogic(
address _poolToken,
address _repayer,
address _onBehalf,
uint256 _amount,
uint256 _maxGasForMatching
) external;
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market the user wants to interact with. |
_repayer | address | The address of the account repaying the debt. |
_onBehalf | address | The address of the account whose debt is repaid. |
_amount | uint256 | The amount of token (in underlying). |
_maxGasForMatching | uint256 | The maximum amount of gas to consume within a matching engine loop. |
liquidateLogic
Liquidates a position.
function liquidateLogic(address _poolTokenBorrowed, address _poolTokenCollateral, address _borrower, uint256 _amount)
external;
Parameters
Name | Type | Description |
---|---|---|
_poolTokenBorrowed | address | The address of the pool token the liquidator wants to repay. |
_poolTokenCollateral | address | The address of the collateral pool token the liquidator wants to seize. |
_borrower | address | The address of the borrower to liquidate. |
_amount | uint256 | The amount of token (in underlying) to repay. |
increaseP2PDeltasLogic
Implements increaseP2PDeltas logic.
The current Morpho supply on the pool might not be enough to borrow _amount
before resupplying it.
In this case, consider calling this function multiple times.
function increaseP2PDeltasLogic(address _poolToken, uint256 _amount) external isMarketCreated(_poolToken);
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market on which to increase deltas. |
_amount | uint256 | The maximum amount to add to the deltas (in underlying). |
_unsafeWithdrawLogic
INTERNAL ///
Implements withdraw logic without security checks.
function _unsafeWithdrawLogic(
address _poolToken,
uint256 _amount,
address _supplier,
address _receiver,
uint256 _maxGasForMatching
) internal;
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market the user wants to interact with. |
_amount | uint256 | The amount of token (in underlying). |
_supplier | address | The address of the supplier. |
_receiver | address | The address of the user who will receive the tokens. |
_maxGasForMatching | uint256 | The maximum amount of gas to consume within a matching engine loop. |
_unsafeRepayLogic
Pool withdraw /// Transfer withdraw /// Breaking withdraw ///
Implements repay logic without security checks.
function _unsafeRepayLogic(
address _poolToken,
address _repayer,
address _onBehalf,
uint256 _amount,
uint256 _maxGasForMatching
) internal;
Parameters
Name | Type | Description |
---|---|---|
_poolToken | address | The address of the market the user wants to interact with. |
_repayer | address | The address of the account repaying the debt. |
_onBehalf | address | The address of the account whose debt is repaid. |
_amount | uint256 | The amount of token (in underlying). |
_maxGasForMatching | uint256 | The maximum amount of gas to consume within a matching engine loop. |
_getUserHealthFactor
Pool repay /// Transfer repay /// Breaking repay ///
Returns the health factor of the user.
function _getUserHealthFactor(address _user, address _poolToken, uint256 _withdrawnAmount) internal returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_user | address | The user to determine liquidity for. |
_poolToken | address | The market to hypothetically withdraw from. |
_withdrawnAmount | uint256 | The number of tokens to hypothetically withdraw (in underlying). |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The health factor of the user. |
_withdrawAllowed
Checks whether the user can withdraw or not.
function _withdrawAllowed(address _user, address _poolToken, uint256 _withdrawnAmount) internal returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_user | address | The user to determine liquidity for. |
_poolToken | address | The market to hypothetically withdraw/borrow in. |
_withdrawnAmount | uint256 | The number of tokens to hypothetically withdraw (in underlying). |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Whether the withdraw is allowed or not. |
_liquidationAllowed
Returns whether a given user is liquidatable and the applicable close factor, given the deprecated status of the borrowed market.
function _liquidationAllowed(address _user, bool _isDeprecated)
internal
returns (bool liquidationAllowed, uint256 closeFactor);
Parameters
Name | Type | Description |
---|---|---|
_user | address | The user to check. |
_isDeprecated | bool | Whether the borrowed market is deprecated or not. |
Returns
Name | Type | Description |
---|---|---|
liquidationAllowed | bool | Whether the liquidation is allowed or not. |
closeFactor | uint256 | The close factor to apply. |
Events
Withdrawn
EVENTS ///
Emitted when a withdrawal happens.
event Withdrawn(
address indexed _supplier,
address indexed _receiver,
address indexed _poolToken,
uint256 _amount,
uint256 _balanceOnPool,
uint256 _balanceInP2P
);
Repaid
Emitted when a repayment happens.
event Repaid(
address indexed _repayer,
address indexed _onBehalf,
address indexed _poolToken,
uint256 _amount,
uint256 _balanceOnPool,
uint256 _balanceInP2P
);
Liquidated
Emitted when a liquidation happens.
event Liquidated(
address _liquidator,
address indexed _liquidated,
address indexed _poolTokenBorrowed,
uint256 _amountRepaid,
address indexed _poolTokenCollateral,
uint256 _amountSeized
);
P2PDeltasIncreased
Emitted when the peer-to-peer deltas are increased by the governance.
event P2PDeltasIncreased(address indexed _poolToken, uint256 _amount);
Errors
UserNotMemberOfMarket
ERRORS ///
Thrown when user is not a member of the market.
error UserNotMemberOfMarket();
UnauthorisedWithdraw
Thrown when the user does not have enough remaining collateral to withdraw.
error UnauthorisedWithdraw();
UnauthorisedLiquidate
Thrown when the positions of the user is not liquidatable.
error UnauthorisedLiquidate();
WithdrawIsPaused
Thrown when someone tries to withdraw but the withdraw is paused.
error WithdrawIsPaused();
RepayIsPaused
Thrown when someone tries to repay but the repay is paused.
error RepayIsPaused();
LiquidateCollateralIsPaused
Thrown when someone tries to liquidate but the liquidation with this asset as collateral is paused.
error LiquidateCollateralIsPaused();
LiquidateBorrowIsPaused
Thrown when someone tries to liquidate but the liquidation with this asset as debt is paused.
error LiquidateBorrowIsPaused();
Structs
WithdrawVars
STRUCTS ///
struct WithdrawVars {
uint256 remainingGasForMatching;
uint256 remainingToWithdraw;
uint256 poolSupplyIndex;
uint256 p2pSupplyIndex;
uint256 onPoolSupply;
uint256 toWithdraw;
}
RepayVars
struct RepayVars {
uint256 remainingGasForMatching;
uint256 remainingToRepay;
uint256 poolSupplyIndex;
uint256 poolBorrowIndex;
uint256 p2pSupplyIndex;
uint256 p2pBorrowIndex;
uint256 borrowedOnPool;
uint256 feeToRepay;
uint256 toRepay;
}
LiquidateVars
struct LiquidateVars {
uint256 liquidationBonus;
uint256 collateralReserveDecimals;
uint256 collateralTokenUnit;
uint256 collateralBalance;
uint256 collateralPrice;
uint256 amountToSeize;
uint256 borrowedReserveDecimals;
uint256 borrowedTokenUnit;
uint256 borrowedTokenPrice;
uint256 amountToLiquidate;
uint256 closeFactor;
bool liquidationAllowed;
}