Aave V3 Swap Contracts
The Aave Labs interface offers several swap-based features, detailed below.
Swap Tokens
The Swap Tokens feature enables users to swap between tokens using ParaSwap or CoW Protocol as the swap provider, depending on network availability. Tokens traded using CoW Protocol will incur a fee depending on the token pair and swap type:
- Debt Swap: 0 bps fee across all pairs.
- All other swap operations: a discounted fee of 15 bps is applied to swaps between correlated assets (e.g. ETH/wstETH); for all other swaps a fee of 25 bps is applied.
The list of correlated assets is reviewed and updated periodically:
- Stablecoin asset group: USDC, USDT, DAI, GHO, EURC, USDbC, USDe, USDS, sUSDe, RLUSD, PYUSD, LUSD, sDAI, crvUSD, USD₮0, USDC.e, EURe, xDAI, wxDAI
- ETH correlated asset group: weETH, ETH, WETH, wstETH, cbETH, ezETH, wrsETH, osETH, rETH, ETHx
- BTC correlated asset group: cbBTC, WBTC, LBTC, tBTC, eBTC
Swap Adapter Contracts
The swap adapter contracts integrate Aave’s Flash Loans and the ParaSwap DEX aggregator to facilitate advanced actions such as repaying borrow positions using collateral, swapping collateral assets, swapping borrow positions, and withdrawing and swapping assets. They allow users to perform complex operations in a single transaction, leveraging the liquidity of the Aave protocol and the atomic swapping capabilities of decentralized exchanges.
The table below outlines swap feature availability across V3 markets on the Aave Labs interface:
| Market | Token Swap | Repay With Collateral | Collateral Swap | Debt Swap | Withdraw & Swap |
|---|---|---|---|---|---|
| Ethereum Core | |||||
| Ethereum Prime | |||||
| Ethereum EtherFi | |||||
| Arbitrum | |||||
| Avalanche | |||||
| Base | |||||
| BNB | |||||
| Optimism | |||||
| Polygon | |||||
| Gnosis | |||||
| Sonic | |||||
| Metis | |||||
| Scroll | |||||
| ZKsync | |||||
| Celo | |||||
| Soneium | |||||
| Linea | |||||
| Plasma | |||||
| Ink |
Repay With Collateral
The Para contract enables users to repay their borrow positions on Aave using their supplied collateral directly, without the need to unwind their positions or provide additional liquidity. It leverages Aave’s Flash Loans and the ParaSwap DEX aggregator to swap the user’s collateral for the borrowed asset and repay the borrow position in a single atomic transaction.
Uses flash loans and ParaSwap to repay debt with collateral in one transaction.
The source code is available on GitHub.
Reference Integration: useCollateralRepaySwap.tsx
executeOperation
function executeOperation(
address asset,
uint256 amount,
uint256 premium,
address initiator,
bytes calldata params
) external override nonReentrant returns (bool)
Uses the received funds from the flash loan to repay a borrow position on the protocol on behalf of the user. Then, pulls the collateral from the user and swaps it to the debt asset to repay the flash loan.
The user should give this contract allowance to pull the aTokens in order to withdraw the underlying asset, swap it, and repay the flash loan.
Supports only one asset on the flash loan.
The params parameter should be the ABI-encoded values of the following:
IERC20: The address of the borrow position assetDetailed debt Asset uint256 debt: The amount of the borrow position to be repaidRepay Amount uint256 buy: Offset in the ParaSwap calldata if swapping all balanceAll Balance Offset uint256 rate: The rate mode of the borrow position to be repaid. Must be 2 (variable).Mode bytes paraswap: Data for the ParaSwap AdapterData Permit: Struct containing the permit signature, set to zeroes if not usedSignature permit Signature
Input Parameters:
| Name | Type | Description |
|---|---|---|
| asset | address | The address of the flash-borrowed asset |
| amount | uint256 | The amount of the flash-borrowed asset |
| premium | uint256 | The fee of the flash-borrowed asset |
| initiator | address | The address of the flash loan initiator |
| params | bytes | The byte-encoded parameters passed when initiating the flash loan |
Return Values:
| Type | Description |
|---|---|
bool | True if the execution of the operation succeeds, false otherwise |
swapAndRepay
function swapAndRepay(
IERC20Detailed collateralAsset,
IERC20Detailed debtAsset,
uint256 collateralAmount,
uint256 debtRepayAmount,
uint256 debtRateMode,
uint256 buyAllBalanceOffset,
bytes calldata paraswapData,
PermitSignature calldata permitSignature
) external nonReentrant
Swaps the user’s collateral for the debt asset and then repays the borrow position on the protocol on behalf of the user without using flash loans. This method can be used when the temporary transfer of the collateral asset to this contract does not affect the user’s position.
The user should give this contract allowance to pull the aTokens in order to withdraw the underlying asset.
Input Parameters:
| Name | Type | Description |
|---|---|---|
| collateralAsset | IERC20 | The address of the collateral asset to be swapped |
| debtAsset | IERC20 | The address of the debt asset |
| collateralAmount | uint256 | The maximum amount of the collateral to be swapped |
| debtRepayAmount | uint256 | The amount of the borrow position to be repaid, or maximum amount when repaying all |
| debtRateMode | uint256 | The rate mode of the borrow position to be repaid. Must be 2 (variable). |
| buyAllBalanceOffset | uint256 | Offset in the ParaSwap calldata if swapping all balance, otherwise 0 |
| paraswapData | bytes | Data for the ParaSwap Adapter |
| permitSignature | Permit | Struct containing the permit signature, set to zeroes if not used |
PermitSignature Struct
struct PermitSignature {
uint256 deadline;
uint8 v;
bytes32 r;
bytes32 s;
}
Members:
| Name | Type | Description |
|---|---|---|
| deadline | uint256 | The deadline timestamp for the permit signature |
| v | uint8 | The V parameter of the ECDSA signature |
| r | bytes32 | The R parameter of the ECDSA signature |
| s | bytes32 | The S parameter of the ECDSA signature |
Collateral Swap
The Para contract allows users to swap their supplied collateral from one asset to another in a single transaction using Aave’s Flash Loans and the ParaSwap DEX aggregator.
This adapter enables users to rebalance their collateral positions without needing to withdraw and re-supply assets manually. By leveraging flash loans, the user can swap their existing collateral to a new asset and supply it back into the Aave protocol in a single transaction.
The source code is available on GitHub.
Reference Integration: useCollateralSwap.tsx
executeOperation
function executeOperation(
address asset,
uint256 amount,
uint256 premium,
address initiator,
bytes calldata params
) external override nonReentrant returns (bool)
Swaps the received amount from the flash loan into the specified asset. The received funds from the swap are then supplied into the protocol on behalf of the user.
The user should give this contract allowance to pull the aTokens in order to withdraw the underlying asset and repay the flash loan.
The params parameter should be the ABI-encoded values of the following:
IERC20: The address of the underlying asset to be swapped to and suppliedDetailed asset To Swap To uint256 min: The minimum amount to be received from the swapAmount To Receive uint256 swap: Offset in the Augustus calldata if swapping all balance, otherwise 0All Balance Offset bytes swap: Calldata for ParaSwap’s Augustus Swapper contractCalldata IPara: Address of ParaSwap’s Augustus Swapper contractSwap Augustus augustus Permit: Struct containing the permit signature, set to zeroes if not usedSignature permit Params
Input Parameters:
| Name | Type | Description |
|---|---|---|
| asset | address | The address of the flash-borrowed asset |
| amount | uint256 | The amount of the flash-borrowed asset |
| premium | uint256 | The fee of the flash-borrowed asset |
| initiator | address | The address of the flash loan initiator |
| params | bytes | The byte-encoded parameters passed when initiating the flash loan |
Return Values:
| Type | Description |
|---|---|
bool | True if the execution of the operation succeeds, false otherwise |
swapAndDeposit
function swapAndDeposit(
IERC20Detailed assetToSwapFrom,
IERC20Detailed assetToSwapTo,
uint256 amountToSwap,
uint256 minAmountToReceive,
uint256 swapAllBalanceOffset,
bytes calldata swapCalldata,
IParaSwapAugustus augustus,
PermitSignature calldata permitParams
) external nonReentrant
Swaps an amount of an asset to another and supplies the new asset amount on behalf of the user without using a flash loan. This method can be used when the temporary transfer of the collateral asset to this contract does not affect the user’s position.
The user should give this contract allowance to pull the aTokens in order to withdraw the underlying asset and perform the swap.
Input Parameters:
| Name | Type | Description |
|---|---|---|
| assetToSwapFrom | IERC20 | The address of the underlying asset to be swapped from |
| assetToSwapTo | IERC20 | The address of the underlying asset to be swapped to and supplied |
| amountToSwap | uint256 | Amount to be swapped, or maximum amount when swapping all balance |
| minAmountToReceive | uint256 | Minimum amount to be received from the swap |
| swapAllBalanceOffset | uint256 | Offset in Augustus calldata if swapping all balance, otherwise 0 |
| swapCalldata | bytes | Calldata for ParaSwap’s Augustus Swapper contract |
| augustus | IPara | Address of ParaSwap’s Augustus Swapper contract |
| permitParams | Permit | Struct containing the permit signature, set to zeroes if not used |
Debt Swap
The Para contracts allow users to swap their borrow positions from one asset to another. They leverage Aave’s Flash Loans and the ParaSwap DEX aggregator to perform the swap in a single atomic transaction.
There are two versions of the adapter:
-
Para: The standard version that supports swapping any borrow position asset.Swap Debt Swap Adapter V3 - Source Code: GitHub
- Reference Integration: useDebtSwitch.tsx
-
Para: A specialized version that supports GHO, where GHO can be flash minted via the ERC-3156 interface.Swap Debt Swap Adapter V3 GHO - Source Code: GitHub
- Reference Integration: useDebtSwitch.tsx
ParaSwapDebtSwapAdapterV3
The Para contract allows users to swap their borrow positions from one asset to another, enabling borrow position refinancing on the Aave protocol.
This adapter leverages Aave’s Flash Loans and the ParaSwap DEX aggregator to perform the borrow position swap in a single transaction.
executeOperation
function executeOperation(
address[] calldata assets,
uint256[] calldata amounts,
uint256[] calldata,
address initiator,
bytes calldata params
) external returns (bool)
Performs the swap and repay operation using the borrowed funds from the flash loan, and then re-borrows the new borrow position asset to maintain the overall borrow position.
The params parameter should be the ABI-encoded Flash struct:
address debt: the borrow position asset to repayAsset uint256 debt: the amount of debt to repayRepay Amount uint256 debt: the rate mode of the debt to repayRate Mode address nested: the new debt asset when extra collateral is flashed, otherwise the zero addressFlashloan Debt Asset uint256 nested: the new debt amount for the nested flash loanFlashloan Debt Amount bytes paraswap: ParaSwap swap dataData uint256 offset: offset in the ParaSwap calldata if swapping all balanceaddress user: the user whose debt is swapped
Input Parameters:
| Name | Type | Description |
|---|---|---|
| assets | address[] | The addresses of the assets being borrowed in the flash loan |
| amounts | uint256[] | The amounts of the assets being borrowed |
| premiums | uint256[] | The fees for the flash loans |
| initiator | address | The address of the flash loan initiator |
| params | bytes | Arbitrary data containing the parameters needed for the operation |
Return Values:
| Type | Description |
|---|---|
bool | True if the execution of the operation succeeds, false otherwise |
ParaSwapDebtSwapAdapterV3GHO
The Para contract is a specialized version of the borrow position swap adapter that supports GHO, allowing users to swap their borrow positions involving GHO. It utilizes the ERC-3156 flash mint interface for GHO.
Performs the swap and repay operation using the borrowed funds from the flash loan, and then re-borrows the borrow position asset to maintain the overall borrow position.
onFlashLoan
function onFlashLoan(
address initiator,
address token,
uint256 amount,
uint256 fee,
bytes calldata data
) external override returns (bytes32)
This is the ERC-3156 Flash Loan callback function that gets called when the contract receives a flash loan (in this case, flash mint) from the GHO Flash Minter.
Input Parameters:
| Name | Type | Description |
|---|---|---|
| initiator | address | The initiator of the flash loan |
| token | address | The address of the token being borrowed |
| amount | uint256 | The amount of tokens being borrowed |
| fee | uint256 | The fee for the flash loan |
| data | bytes | Arbitrary data containing the parameters needed for the operation |
Return Values:
| Type | Description |
|---|---|
bytes32 | The keccak256 hash of the string 'ERC3156FlashBorrower.onFlashLoan' |
Withdraw & Swap
The Para contract allows users to withdraw their supplied assets from Aave and swap them to another asset in a single transaction using the ParaSwap DEX aggregator.
Withdraws and swaps in one transaction.
The source code is available on GitHub.
Reference Integration: WithdrawAndSwitchActions.tsx
execute reverts with NOT_.
withdrawAndSwap
function withdrawAndSwap(
IERC20Detailed assetToSwapFrom,
IERC20Detailed assetToSwapTo,
uint256 amountToSwap,
uint256 minAmountToReceive,
uint256 swapAllBalanceOffset,
bytes calldata swapCalldata,
IParaSwapAugustus augustus,
PermitSignature calldata permitParams
) external nonReentrant
Swaps an amount of an asset to another after a withdrawal and transfers the new asset to the user. The user should give this contract allowance to pull the aTokens in order to withdraw the underlying asset and perform the swap.
Input Parameters:
| Name | Type | Description |
|---|---|---|
| assetToSwapFrom | IERC20 | The address of the underlying asset to be swapped from |
| assetToSwapTo | IERC20 | The address of the underlying asset to be swapped to |
| amountToSwap | uint256 | Amount to be swapped, or maximum amount when swapping all balance |
| minAmountToReceive | uint256 | Minimum amount to be received from the swap |
| swapAllBalanceOffset | uint256 | Offset in Augustus calldata if swapping all balance, otherwise 0 |
| swapCalldata | bytes | Calldata for ParaSwap’s Augustus Swapper contract |
| augustus | IPara | Address of ParaSwap’s Augustus Swapper contract |
| permitParams | Permit | Struct containing the permit signature, set to zeroes if not used |