import { encodeFunctionData, parseEther, privateKeyToAccount } from "viem";
import axios from "axios";
// Step 1: Setup signer and smart account
const eoa7702 = privateKeyToAccount("EOA_PRIVATE_KEY");
const smartAccountImplementation = "0xdef..."; // Replace with your smart account implementation
// Step 2: Sign EIP-7702 authorization
const authorizationHash = await walletClient.signAuthorization({
account: eoa7702,
contractAddress: smartAccountImplementation,
});
// Workaround for viem and RPC compatibility
delete authorizationHash.v;
(authorizationHash as any).address = authorizationHash.contractAddress;
// Step 3: Encode batched destination chain calls
const executeCallData = encodeFunctionData({
abi,
functionName: "executeBatch",
args: [
[
{
target: eoa7702.address,
value: parseEther("0.00001"),
data: "0x",
},
{
target: eoa7702.address,
value: parseEther("0.00002"),
data: "0x",
},
],
],
});
// Step 4: Construct and send quote request
const requestData = {
user: eoa7702.address,
originChainId: 10,
destinationChainId: 42161,
originCurrency: "0x0000000000000000000000000000000000000000",
destinationCurrency: "0x0000000000000000000000000000000000000000",
recipient: eoa7702.address,
tradeType: "EXACT_OUTPUT",
amount: "1000000000000000",
useExternalLiquidity: false,
authorizationList: [authorizationHash], // You can pass in multiple authorizationHash in the authorizationList array
txs: [
{
to: "0xabc...",
value: "0",
data: executeCallData,
},
],
};