Swap
The Portal provides functionality for integrating decentralized exchange (DEX) aggregators into the protocol stack.
Overview
This module contains a collection of contracts implemented using the diamond pattern to enable seamless integration with various DEX aggregators. The diamond pattern allows for modular and upgradeable smart contract architecture.
Key Features
- Integration with multiple DEX aggregators
- Modular and upgradeable design using diamond pattern
- Efficient token swapping functionality to be used in the protocol
- Integrating ERC2771 and permit / permit2 functionnalities
Usage
swap
This function is used to swap two assets. It is used in the protocol to swap assets before executing a deposit or a withdraw from a vault to another asset than the one in the vault.
function swap(
bool _sourceIsVault,
bool _targetIsVault,
uint8 _route,
address _receiver,
address _approvalAddress,
address _sourceAsset,
address _targetAsset,
uint256 _amount,
bytes memory _permitParams,
bytes calldata _data
) external payable;
Where:
sourceIsVault
: if true, the source asset is the vault, so the portal will withdraw the asset from the vaulttargetIsVault
: if true, the target asset is the vault, so the portal will deposit the asset to the vault_route
: the DEX routerId to use for the swap_receiver
: the receiver of the swap_approvalAddress
: the address to approve the swap (the entrypoint address of the DEX aggregator)_sourceAsset
: the source asset address_targetAsset
: the target asset address_amount
: the amount to swap_permitParams
: the permit payload if the user want to use permit to make his approval on his vault shares_data
: the data to pass to the DEX aggregator
majoraBlockSwap
This function is used to swap two assets too but its interface is simplified to be used in a block context with swap dynamic parameters.
function strategBlockSwap(
uint8 _route,
address _approvalAddress,
address _sourceAsset,
address _targetAsset,
uint256 _amount,
bytes calldata _data
) external payable;
Where:
_route
: the DEX routerId to use for the swap_approvalAddress
: the address to approve the swap (the entrypoint address of the DEX aggregator)_sourceAsset
: the source asset address_targetAsset
: the target asset address_amount
: the amount to swap_data
: the data to pass to the DEX aggregator
swapAndBridge
This function is used to swap two assets and bridge them to another chain. This is typiccaly used with a bridge like LiFi or DeBridge to bridge the asset to a different chain.
function swapAndBridge(
bool sourceIsVault,
bool targetIsVault,
uint8 _route,
address _approvalAddress,
address _sourceAsset,
address _targetAsset,
uint256 _amount,
uint256 _targetChain,
bytes memory _permitParams,
bytes calldata _data
) external payable;
Where:
sourceIsVault
: if true, the source asset is the vault, so the portal will withdraw the asset from the vaulttargetIsVault
: if true, the target asset is the vault, so the portal will deposit the asset to the vault_route
: the DEX routerId to use for the swap_approvalAddress
: the address to approve the swap (the entrypoint address of the DEX aggregator)_sourceAsset
: the source asset address_targetAsset
: the target asset address_amount
: the amount to swap_targetChain
: the target chain to bridge to_permitParams
: the permit payload if the user want to use permit to make his approval on his vault shares_data
: the data to pass to the DEX aggregator