How to Generate Calldata for Invoking an Intent Adapter
This guide will walk you through the steps for generating calldata for invoking any intent adapter. It supports both same-chain and cross-chain operations, with flexible adapter integration.
This section explains how to adjust this code to work with your specific adapter and configuration. Follow the steps below to set up the API as per your adapter.
1. Set Your Adapter Contract Address
The adapter contract address needs to be provided in the getAdapterData
function. You will find this part in the target
variable in the getAdapterData
function. Replace the empty string with the correct address of your adapter contract.
Example: If your adapter is deployed at 0x123456789abcdef, you would replace the line with:
2. Create the calldata
in getAdapterData
calldata
in getAdapterData
In the getAdapterData
function, the calldata
is generated by encoding the function arguments. You need to ensure that the encoding matches the parameters your adapter smart contract requires in execute
function.
Note 1: The receiver/refund address should be mandatorily added in the calldata for every adapter in order to avoid any fund loss.
Note 2: If your adapter is the last one to be called in the sequence of adapters then the amount in calldata should be
uint256Max
.
Example - If the adapter needs receiver address and amount of the token, it would be encoded like this:
3. Set the User's Wallet Address
You will find this under the userAddress variable inside the main function. You can either replace this with a hardcoded wallet address or make it dynamic by passing the address as an argument to the main function.
4. Update Source and Destination Tokens
You can modify the source and destination tokens by editing the sourceToken
and destToken
objects in the main function.
Source Token: The
sourceToken
is the token that the user provides. Update the following fields:
Destination Token: The
destToken
is the token that is needed by the adapter on the destination chain. Update it in the same way as the sourceToken:
5. Adjust the Source and Destination Chain IDs
Ensure the chain IDs match the chains you're working with for both the source and destination tokens. These are used to determine if the operation is on the same chain or cross-chain.
6. Adjust the Source token amount
This is the amount of source tokens provided by the user. Update the amount in string format. Please ensure it's value amounts greater than $12 to avoid transaction failures.
Sample Script
In the aforementioned file, you can find the sample calldata generation code for our Pendle adapter deployed on Arbitrum.
Last updated