tensaikit
Version:
An autonomous DeFi AI Agent Kit on Katana enabling AI agents to plan and execute on-chain financial operations.
30 lines (29 loc) • 1.42 kB
TypeScript
import { ViemWalletProvider } from "../../../walletProviders";
/**
* Prepares and sends a token swap transaction via the SushiSwap module using the provided wallet provider.
*
* This function handles the full lifecycle of a swap:
* 1. Validates network and chain information from the wallet provider.
* 2. Fetches token metadata to convert the input amount into base units.
* 3. Checks and sets token allowance if needed.
* 4. Fetches the swap calldata from the SushiSwap module.
* 5. Simulates the transaction using Viem’s `publicClient.call` (for dry-run).
* 6. Sends the transaction using the wallet provider and waits for confirmation.
*
* @param walletProvider - A Viem-compatible wallet provider to interact with the blockchain.
* @param args - Swap details:
* - tokenIn: Address of the input token.
* - tokenOut: Address of the output token.
* - maxSlippage: Maximum allowed slippage for the trade (in percent).
* - amount: Human-readable input amount (e.g., 1.5 ETH).
*
* @returns A promise resolving to the transaction hash if successful.
* If approval fails, returns an error string.
* @throws Throws a formatted error if any stage in the swap process fails.
*/
export declare const prepareAndSendSwapTransaction: (walletProvider: ViemWalletProvider, args: {
tokenIn: string;
tokenOut: string;
maxSlippage: number;
amount: number;
}) => Promise<string>;