Wrap Exchange Contract
Wrap the exchange contract to execute cross-chain swap operations.
In this example, we will wrap Trader Joe's Factory contract to execute swap operations on the destination chain. Trader Joe's exchange contracts are already deployed on Fuji, which why we are choosing Fuji as the destination chain.
An example of the exchange wrapper code is provided below. This contract only allows swap operations on Trader Joe V1 pools or any other Uniswap V2-like contracts.
Walkthrough:
- The wrapper contract receives the payload via the
receiveTokens
function. - The wrapper contract transfers the tokens to itself.
- The wrapper contract gets a quote from the exchange.
- The wrapper contract casts
payload
intoSwapOptions
struct. - The wrapper contract checks if the received
amountOut
is greater than theminAmountOut
requested when the contract was called from the source chain. - The wrapper contract executes the swap operation and transfers the received asset to caller, depending on the preferred asset (wrapped token or native token).
Disclaimer: The avalanche-interchain-token-transfer contracts used in this tutorial are under active development and are not yet intended for production deployments. Use at your own risk.