Pool
Introduction
The Pool
smart contract is the protocol's main user-facing contract, as most user interactions with Mystic occur via the Pool contract. It exposes the liquidity management methods that can be invoked using either Solidity or Web3 libraries.
Pool
is covered by a proxy contract and is owned by the PoolAddressesProvider
of any given market. All admin functions are callable by the PoolConfigurator
contract defined in the PoolAddressesProvider
. By interacting with Pool
, users can:
Supply
Withdraw
Borrow
Repay
Enable/disable supplied assets as collateral
Liquidate positions
Methods
Supply
```
function supply(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode
) public virtual override
```
This method supplies a certain amount of an asset into the protocol, minting the same amount of corresponding myTokens and transferring them to the onBehalfOf
address. For example, if a user supplies 100 USDC and onBehalfOf
address is the same as msg.sender
, they will get 100 myUSDC in return.
When supplying, the Pool
contract must have allowance()
to spend funds on behalf of msg.sender
for at least the amount for the asset being supplied. This can be done via the standard ERC20 `approve()
` method on the underlying token contract.
Input Parameters:
This code is used to register the integrator originating the operation, for potential rewards. 0 if the action is executed directly by the user, without any middle-men.
Withdraw
```
function withdraw(
address asset,
uint256 amount,
address to
) public virtual override
```
This method withdraws an amount of underlying asset from the reserve, burning the equivalent myTokens owned. For example, if a user has 100 myUSDC and calls withdraw()
, they will receive 100 USDC, burning the 100 myUSDC.
If user has any existing debt backed by the underlying token, then the maximum amount available to withdraw is the amount that will not leave the user's health factor < 1 after withdrawal.
When withdrawing to another address, msg.sender
should have myTokens to they may be burned by Pool
.
Input Parameters:
Borrow
```
function borrow(
address asset,
uint256 amount,
uint256 interestRateMode,
uint16 referralCode,
address onBehalfOf
) public virtual override
```
This method allows users to borrow a specific amount of the reserve underlying asset, provided the borrower has already supplied enough collateral, or they were given enough allowance by a credit delegator on the corresponding debt token (myVariableLoanToken). For example, if a user borrows 100 USDC passing their own address as onBehalfOf
, they will receive 100 USDC into their wallet and 100 variable debt tokens.
NOTE: If onBehalfOf
is not the same as msg.sender
, then onBehalfOf
must have supplied enough collateral via supply()
and have delegated credit to msg.sender
via approveDelegation()
.
Mystic's referral program isn't active at the moment, meaning you can pass 0 as referralCode
. This program may be activated in the future.
Input Parameters:
Repay
```
function repay(
address asset,
uint256 amount,
uint256 interestRateMode,
address onBehalfOf
) public virtual override
```
Repays a borrowed amount on a specific reserve, burning the equivalent debt tokens owned. For example, if a user repays 100 USDC, the 100 variable debt tokens owned by the onBehalfOf
address will be burned.
When repaying, the Pool
contract must have allowance to spend funds on behalf of msg.sender
for at least the amount for the asset you are repaying with. This can be done via the standard ERC20 approve()
method on the underlying token contract. Please note you cannot call repay()
multiple times in the same block.
Input Parameters:
setUserUseReserveAsCollateral
```
function setUserUseReserveAsCollateral(
address asset,
bool useAsCollateral
) public virtual override
```
This method allows suppliers to enable/disable a specific supplied asset as collateral, as it sets the asset of msg.sender
to be used as collateral or not. Do note, an asset in Isolation Mode can only be enabled to use as collateral if no other asset is already enabled to use as collateral.
The user won’t be able to disable an asset as collateral if they have an outstanding debt position which could be left with the Health Factor < HEALTH_FACTOR_LIQUIDATION_THRESHOLD
.
Input Parameters:
liquidationCall
```
function liquidationCall(
address collateralAsset,
address debtAsset,
address user,
uint256 debtToCover,
bool receiveAToken
) public virtual override
```
This method liquidates a non-healthy position collateral-wise, meaning one with a Health Factor below 1. To expand on this - when the health factor of a position is below 1, the caller (liquidator) repays the debtToCover
amount of debt of the user getting liquidated. This is part or all of the outstanding borrowed amount on behalf of the borrower. The caller then receives a proportional amount of the collateralAsset
(discounted amount of collateral) plus a liquidation bonus to cover market risk.
Liquidators can decide if they want to receive an equivalent amount of collateral myTokens instead of the underlying asset. When the liquidation is completed successfully, the health factor of the position is increased, bringing the health factor above 1.
Liquidators can only close a certain amount of collateral defined by a close factor. Currently the close factor is 0.5. In other words, liquidators can only liquidate a maximum of 50% of the amount pending to be repaid in a position. The liquidation discount applies to this amount.
In most scenarios, profitable liquidators will choose to liquidate as much as they can (50% of the user position). If you wish to do this, the debtToCover
parameter can be set to uint(-1) and the protocol will proceed with the highest possible liquidation allowed by the close factor. To check a user's health factor, use [getUserAccountData()]
.
Liquidators must approve()
the Pool
contract to use debtToCover
of the underlying ERC20 of the asset used for the liquidation.
Input Parameters:
getUserAccountData
```
function getUserAccountData(address user) external view virtual override returns (
uint256 totalCollateralBase,
uint256 totalDebtBase,
uint256 availableBorrowsBase,
uint256 currentLiquidationThreshold,
uint256 ltv,
uint256 healthFactor
)
```
Returns the user account data across all the reserves.
Input Parameters:
Return Values:
getUserConfiguration
```
function getUserConfiguration(
address user
) external view virtual override
returns (
DataTypes.UserConfigurationMap memory
)
```
Returns the configuration of the user across all the reserves.
Input Parameters:
Return Values:
The DataTypes.UserConfigurationMap
struct is composed of the following fields:
getReservesList
```
function getReservesList(
)external view virtual override
returns (
address[] memory
)
```
Returns the list of the underlying assets of all the initialized reserves. It does not include dropped reserves.
Return Values:
Last updated