Morpho AaveV3 Optimizer
Entrypoint of the Morpho Optimizer protocol build on top of AaveV3.
Functions
supply
function supply(address underlying, uint256 amount, address onBehalf, uint256 maxIterations)
external
returns (uint256);
Supplies amount
of underlying
on behalf of onBehalf
. The supplied amount cannot be used as collateral but is eligible for the peer-to-peer matching.
Parameters:
Name | Type | Description |
---|---|---|
underlying | address | The address of the market the user wants to interact with. |
amount | uint256 | The amount of token (in underlying) to supply. |
onBehalf | address | The address of the account whose positions will be updated. |
maxIterations | uint256 | The maximum number of iterations allowed during the matching process. Using 4 was shown to be efficient in Morpho Labs' simulations. |
Return values:
Name | Type | Description |
---|---|---|
supplied | uint256 | The amount supplied (in underlying). |
supplyWithPermit
struct Signature {
uint8 v;
bytes32 r;
bytes32 s;
}
function supplyWithPermit(
address underlying,
uint256 amount,
address onBehalf,
uint256 maxIterations,
uint256 deadline,
Signature calldata signature
) external returns (uint256);
Supplies amount
of underlying
of onBehalf
using permit2 in a single tx. The supplied amount cannot be used as collateral but is eligible for the peer-to-peer matching.
Parameters:
Name | Type | Description |
---|---|---|
underlying | address | The address of the market the user wants to interact with. |
amount | uint256 | The amount of token (in underlying) to supply. |
onBehalf | address | The address of the account whose positions will be updated. |
maxIterations | uint256 | The maximum number of iterations allowed during the matching process. Using 4 was shown to be efficient in Morpho Labs' simulations. |
deadline | uint256 | The deadline after which the permit will be invalid. |
signature | Signature | The permit signature. |
Return values:
Name | Type | Description |
---|---|---|
supplied | uint256 | The amount supplied (in underlying). |
supplyCollateral
function supplyCollateral(address underlying, uint256 amount, address onBehalf) external returns (uint256);
Supplies amount
of underlying
collateral to the pool on behalf of onBehalf
. The supplied amount cannot be matched peer-to-peer but can be used as collateral.
Parameters:
Name | Type | Description |
---|---|---|
underlying | address | The address of the market the user wants to interact with. |
amount | uint256 | The amount of token (in underlying) to supply. |
onBehalf | address | The address of the account whose positions will be updated. |
Return values:
Name | Type | Description |
---|---|---|
supplied | uint256 | The collateral amount supplied (in underlying). |
supplyCollateralWithPermit
struct Signature {
uint8 v;
bytes32 r;
bytes32 s;
}
function supplyCollateralWithPermit(
address underlying,
uint256 amount,
address onBehalf,
uint256 deadline,
Signature calldata signature
) external returns (uint256);
Supplies amount
of underlying
collateral to the pool on behalf of onBehalf
using permit2 in a single tx. The supplied amount cannot be matched peer-to-peer but can be used as collateral.
Parameters:
Name | Type | Description |
---|---|---|
underlying | address | The address of the market the user wants to interact with. |
amount | uint256 | The amount of token (in underlying) to supply. |
onBehalf | address | The address of the account whose positions will be updated. |
deadline | uint256 | The deadline after which the permit will be invalid. |
signature | Signature | The permit signature. |
Return values:
Name | Type | Description |
---|---|---|
supplied | uint256 | The collateral amount supplied (in underlying). |
borrow
function borrow(address underlying, uint256 amount, address onBehalf, address receiver, uint256 maxIterations);
Borrows amount
of underlying
on behalf of onBehalf
. If sender is not onBehalf
, sender must have previously been approved by onBehalf
using approveManager
.
Parameters:
Name | Type | Description |
---|---|---|
underlying | address | The address of the market the user wants to interact with. |
amount | uint256 | The amount of token (in underlying) to borrow. |
onBehalf | address | The address of the account whose positions will be updated. |
receiver | address | The address of the account that will receive the borrowed tokens. |
maxIterations | uint256 | The maximum number of iterations allowed during the matching process. Using 4 was shown to be efficient in Morpho Labs' simulations. |
Return values:
Name | Type | Description |
---|---|---|
borrowed | uint256 | The amount borrowed (in underlying). |
repay
function repay(address underlying, uint256 amount, address onBehalf) external returns (uint256);
Repay amount
of underlying
on behalf of onBehalf
.
Parameters:
Name | Type | Description |
---|---|---|
underlying | address | The address of the market the user wants to interact with. |
amount | uint256 | The amount of token (in underlying) to repay. |
onBehalf | address | The address of the account whose positions will be updated. |
Return values:
Name | Type | Description |
---|---|---|
repaid | uint256 | The amount repaid (in underlying). |
repayWithPermit
struct Signature {
uint8 v;
bytes32 r;
bytes32 s;
}
function repayWithPermit(
address underlying,
uint256 amount,
address onBehalf,
uint256 deadline,
Signature calldata signature
) external returns (uint256);
Repays amount
of underlying
on behalf of onBehalf
using permit2 in a single tx.
When repaying all, one should pass type(uint160).max
as amount
because Permit2 does not support approvals larger than 160 bits.
Parameters:
Name | Type | Description |
---|---|---|
underlying | address | The address of the market the user wants to interact with. |
amount | uint256 | The amount of token (in underlying) to repay. |
onBehalf | address | The address of the account whose positions will be updated. |
deadline | uint256 | The deadline after which the permit will be invalid. |
signature | Signature | The permit signature. |
withdraw
function withdraw(address underlying, uint256 amount, address onBehalf, address receiver, uint256 maxIterations);
Withdraws amount
of underlying
on behalf of onBehalf
. If sender is not onBehalf
, sender must have previously been approved by onBehalf
using approveManager
.
Parameters:
Name | Type | Description |
---|---|---|
underlying | address | The address of the market the user wants to interact with. |
amount | uint256 | The amount of token (in underlying) to withdraw. |
onBehalf | address | The address of the account whose positions will be updated. |
receiver | address | The address of the account that will receive the withdrawn tokens. |
maxIterations | uint256 | The maximum number of iterations allowed during the matching process. If it is less than _defaultIterations.withdraw , the latter will be used. |
Return values:
Name | Type | Description |
---|---|---|
withdrawn | uint256 | The amount withdrawn (in underlying). |
withdrawCollateral
function withdrawCollateral(address underlying, uint256 amount, address onBehalf, address receiver)
external
returns (uint256);
Withdraws amount
of underlying
collateral on behalf of onBehalf
. If sender is not onBehalf
, sender must have previously been approved by onBehalf
using approveManager
.
Parameters:
Name | Type | Description |
---|---|---|
underlying | address | The address of the market the user wants to interact with. |
amount | uint256 | The amount of token (in underlying) to withdraw. |
onBehalf | address | The address of the account whose positions will be updated. |
receiver | address | The address of the account that will receive the withdrawn tokens. |
Return values:
Name | Type | Description |
---|---|---|
withdrawn | uint256 | The amount withdrawn (in underlying). |
liquidate
function liquidate(address underlyingBorrowed, address underlyingCollateral, address user, uint256 amount)
external
returns (
uint256 debtRepaid,
uint256 collateralSeized
);
Liquidates user
.
Parameters:
Name | Type | Description |
---|---|---|
underlyingBorrowed | address | The address of the underlying borrowed to repay. |
underlyingCollateral | address | The address of the underlying collateral to seize. |
user | address | The address of the account to liquidate. |
amount | uint256 | The amount of underlyingBorrowed to repay. |
Return values:
Name | Type | Description |
---|---|---|
debtRepaid | uint256 | The amount of underlyingBorrowed repaid. |
collateralSeized | uint256 | The amount of underlyingCollateral seized. |
approveManager
function approveManager(address manager, bool isAllowed) external;
Approves a manager
to borrow/withdraw on behalf of the sender.
Parameters:
Name | Type | Description |
---|---|---|
manager | address | The address of the manager to approve. |
isAllowed | bool | Whether manager is allowed to manage msg.sender 's position or not. |
approveManagerWithSig
struct Signature {
uint8 v;
bytes32 r;
bytes32 s;
}
function approveManagerWithSig(
address delegator,
address manager,
bool isAllowed,
uint256 nonce,
uint256 deadline,
Signature calldata signature
) external;
Approves a manager
to manage the position of msg.sender
using EIP712 signature in a single tx.
Parameters:
Name | Type | Description |
---|---|---|
delegator | address | The address of the account whose positions will be updated. |
manager | address | The address of the manager to approve. |
isAllowed | bool | Whether manager is allowed to manage delegator 's position or not. |
nonce | uint256 | The nonce of the delegator's permit. |
deadline | uint256 | The deadline after which the permit will be invalid. |
signature | Signature | The permit signature. |
Getter functions
scaledPoolSupplyBalance
function scaledPoolSupplyBalance(address underlying, address user) external view returns (uint256);
Returns the scaled balance of user
on the underlying
market, supplied on pool (with underlying
decimals).
scaledP2PSupplyBalance
function scaledP2PSupplyBalance(address underlying, address user) external view returns (uint256);
Returns the scaled balance of user
on the underlying
market, supplied peer-to-peer (with underlying
decimals).
scaledPoolBorrowBalance
function scaledPoolBorrowBalance(address underlying, address user) external view returns (uint256);
Returns the scaled balance of user
on the underlying
market, borrowed on pool (with underlying
decimals).
scaledP2PBorrowBalance
function scaledP2PBorrowBalance(address underlying, address user) external view returns (uint256);
Returns the scaled balance of user
on the underlying
market, borrowed peer-to-peer (with underlying
decimals).
scaledCollateralBalance
function scaledCollateralBalance(address underlying, address user) external view returns (uint256);
Returns the scaled balance of user
on the underlying
market, supplied on pool & used as collateral (with underlying
decimals).
supplyBalance
function supplyBalance(address underlying, address user) external view returns (uint256);
Returns the total supply balance of user
on the underlying
market (in underlying).
borrowBalance
function borrowBalance(address underlying, address user) external view returns (uint256);
Returns the total borrow balance of user
on the underlying
market (in underlying).
collateralBalance
function collateralBalance(address underlying, address user) external view returns (uint256);
Returns the total collateral balance of user
on the underlying
market (in underlying).
liquidityData
struct LiquidityData {
uint256 borrowable; // The maximum debt value allowed to borrow (in base currency).
uint256 maxDebt; // The maximum debt value allowed before being liquidatable (in base currency).
uint256 debt; // The debt value (in base currency).
}
function liquidityData(address user) external view returns (LiquidityData memory);
Returns the liquidity data about the position of user
.