Skip to main content

Aave V2 & V3 & Forks

OperationsLending → Aave V2 & V3 (Composer)

Aave V2 and V3 behave very similar for all operations. The caller only needs to distinguish them via LenderIds, the rest is handled by the contract logic.

Deposit

Deposit the underlying to the lender for the given pool.

If amount=0, we use the contract balance via underlying.balanceOf(address(this)). This is recommended when executing this operation after a swap.

OffsetLength (bytes)Description
020underlying address
2016amount uint128
3620receiver address
7620pool address

Withdraw

Withdraw for the lender. Note that this requires that the caller approved the composer to spend aToken on their behalf.

If amount=0xffffffffffffffffffffffffffff, we read underlying.balanceOf(callerAddress) and withdraw the full balance without leaving dust.

OffsetLength (bytes)Description
020underlying address
2016amount uint128
3620receiver address
7620aToken address
9620pool address

Borrow

Borrow from the lender. The prerequisite is that the caller approved the composer contract to borrow on their behalf via debtToken.approveDelegation(...).

It is important that the mode is provided here, most Aave forks only support mode=2 (variable). If the selector without mode is used, one needs to set mode=0.

OffsetLength (bytes)Description
020underlying address
2016amount uint128
3620receiver address
761mode uint8
7720pool address

Repay

Repay to the lender. In this case, use amount=0 to repay underlying.balanceOf(address(this)), the contract balance, if amount=0xffffffffffffffffffffffffffff, repay the minimum of the contract balance and the caller debt.

OffsetLength (bytes)Description
020underlying address
2016amount uint128
3620receiver address
761mode uint8
7720debtToken address
9720pool address