Skip to main content

Morpho AaveV3 Optimizer

Github code

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:

NameTypeDescription
underlyingaddressThe address of the market the user wants to interact with.
amountuint256The amount of token (in underlying) to supply.
onBehalfaddressThe address of the account whose positions will be updated.
maxIterationsuint256The maximum number of iterations allowed during the matching process. Using 4 was shown to be efficient in Morpho Labs' simulations.

Return values:

NameTypeDescription
supplieduint256The 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:

NameTypeDescription
underlyingaddressThe address of the market the user wants to interact with.
amountuint256The amount of token (in underlying) to supply.
onBehalfaddressThe address of the account whose positions will be updated.
maxIterationsuint256The maximum number of iterations allowed during the matching process. Using 4 was shown to be efficient in Morpho Labs' simulations.
deadlineuint256The deadline after which the permit will be invalid.
signatureSignatureThe permit signature.

Return values:

NameTypeDescription
supplieduint256The 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:

NameTypeDescription
underlyingaddressThe address of the market the user wants to interact with.
amountuint256The amount of token (in underlying) to supply.
onBehalfaddressThe address of the account whose positions will be updated.

Return values:

NameTypeDescription
supplieduint256The 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:

NameTypeDescription
underlyingaddressThe address of the market the user wants to interact with.
amountuint256The amount of token (in underlying) to supply.
onBehalfaddressThe address of the account whose positions will be updated.
deadlineuint256The deadline after which the permit will be invalid.
signatureSignatureThe permit signature.

Return values:

NameTypeDescription
supplieduint256The 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:

NameTypeDescription
underlyingaddressThe address of the market the user wants to interact with.
amountuint256The amount of token (in underlying) to borrow.
onBehalfaddressThe address of the account whose positions will be updated.
receiveraddressThe address of the account that will receive the borrowed tokens.
maxIterationsuint256The maximum number of iterations allowed during the matching process. Using 4 was shown to be efficient in Morpho Labs' simulations.

Return values:

NameTypeDescription
borroweduint256The 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:

NameTypeDescription
underlyingaddressThe address of the market the user wants to interact with.
amountuint256The amount of token (in underlying) to repay.
onBehalfaddressThe address of the account whose positions will be updated.

Return values:

NameTypeDescription
repaiduint256The 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:

NameTypeDescription
underlyingaddressThe address of the market the user wants to interact with.
amountuint256The amount of token (in underlying) to repay.
onBehalfaddressThe address of the account whose positions will be updated.
deadlineuint256The deadline after which the permit will be invalid.
signatureSignatureThe 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:

NameTypeDescription
underlyingaddressThe address of the market the user wants to interact with.
amountuint256The amount of token (in underlying) to withdraw.
onBehalfaddressThe address of the account whose positions will be updated.
receiveraddressThe address of the account that will receive the withdrawn tokens.
maxIterationsuint256The maximum number of iterations allowed during the matching process. If it is less than _defaultIterations.withdraw, the latter will be used.

Return values:

NameTypeDescription
withdrawnuint256The 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:

NameTypeDescription
underlyingaddressThe address of the market the user wants to interact with.
amountuint256The amount of token (in underlying) to withdraw.
onBehalfaddressThe address of the account whose positions will be updated.
receiveraddressThe address of the account that will receive the withdrawn tokens.

Return values:

NameTypeDescription
withdrawnuint256The amount withdrawn (in underlying).

liquidate

function liquidate(address underlyingBorrowed, address underlyingCollateral, address user, uint256 amount)
external
returns (
uint256 debtRepaid,
uint256 collateralSeized
);

Liquidates user.

Parameters:

NameTypeDescription
underlyingBorrowedaddressThe address of the underlying borrowed to repay.
underlyingCollateraladdressThe address of the underlying collateral to seize.
useraddressThe address of the account to liquidate.
amountuint256The amount of underlyingBorrowed to repay.

Return values:

NameTypeDescription
debtRepaiduint256The amount of underlyingBorrowed repaid.
collateralSeizeduint256The amount of underlyingCollateral seized.

approveManager

function approveManager(address manager, bool isAllowed) external;

Approves a manager to borrow/withdraw on behalf of the sender.

Parameters:

NameTypeDescription
manageraddressThe address of the manager to approve.
isAllowedboolWhether 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:

NameTypeDescription
delegatoraddressThe address of the account whose positions will be updated.
manageraddressThe address of the manager to approve.
isAllowedboolWhether manager is allowed to manage delegator's position or not.
nonceuint256The nonce of the delegator's permit.
deadlineuint256The deadline after which the permit will be invalid.
signatureSignatureThe 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.