UNPKG

interchain-token-sdk

Version:

SDK for deploying and managing interchain tokens across multiple chains using Axelar network

51 lines (50 loc) 2.22 kB
import { encodeFunctionData } from 'viem'; import { INTERCHAIN_PROXY_CONTRACT_ABI } from '../constants/constants.js'; import { estimateRemoteDeploymentGas as baseEstimateGas } from '../actions/interchainTokenManager.js'; import { validateChain } from '../config/chains.js'; import { generateRandomSalt } from '../utils/salt.js'; /** * Estimates gas required for deploying a new token to a remote chain * @param sourceChainName - Name of the source chain (e.g., "base-sepolia") * @param destinationChain - Name of the destination chain * @returns Estimated gas amount in wei */ export async function estimateNewTokenDeploymentGas(sourceChainName, destinationChain) { validateChain(destinationChain); // Generate a random salt for gas estimation const salt = generateRandomSalt(); // Encode the deployment function data // Note: For gas estimation, we only need the basic parameters // The actual deployment will handle the full token details const executeData = encodeFunctionData({ abi: INTERCHAIN_PROXY_CONTRACT_ABI, functionName: 'deployRemoteInterchainToken', args: [ salt, // Use the generated bytes32 salt destinationChain, BigInt(0) // gas value ] }); return baseEstimateGas(sourceChainName, destinationChain, executeData); } /** * Estimates gas required for deploying an existing token to a remote chain * @param sourceChainName - Name of the source chain (e.g., "base-sepolia") * @param destinationChain - Name of the destination chain * @param tokenAddress - Address of the existing token to be deployed * @returns Estimated gas amount in wei */ export async function estimateExistingTokenDeploymentGas(sourceChainName, destinationChain, tokenAddress) { validateChain(destinationChain); // Encode the deployment function data const executeData = encodeFunctionData({ abi: INTERCHAIN_PROXY_CONTRACT_ABI, functionName: 'deployRemoteCanonicalInterchainToken', args: [ tokenAddress, destinationChain, BigInt(0) // placeholder gas value ] }); return baseEstimateGas(sourceChainName, destinationChain, executeData); }