UNPKG

sei-agent-kit

Version:

A package for building AI agents on the SEI blockchain

44 lines (43 loc) 1.76 kB
import { StructuredTool } from "langchain/tools"; import { z } from "zod"; const SwapInputSchema = z.object({ amount: z.string().min(1, "Amount must not be empty"), tokenInTicker: z.string().min(1, "Token input ticker must not be empty"), tokenOutTicker: z.string().min(1, "Token output ticker must not be empty"), }); export class SeiSwapTool extends StructuredTool { seiKit; name = "sei_swap"; description = `Swap tokens using the Symphony aggregator. Parameters: - amount: The amount of tokens to swap as a string (e.g., "1.5"). - tokenInTicker: The ticker symbol of the token to swap from (e.g., "SEI"). - tokenOutTicker: The ticker symbol of the token to swap to (e.g., "USDC").`; schema = SwapInputSchema; constructor(seiKit) { super(); this.seiKit = seiKit; } async _call(input) { try { const tokenInAddress = input.tokenInTicker === "SEI" ? "0x0" : await this.seiKit.getTokenAddressFromTicker(input.tokenInTicker); const tokenOutAddress = input.tokenOutTicker === "SEI" ? "0x0" : await this.seiKit.getTokenAddressFromTicker(input.tokenOutTicker); const result = await this.seiKit.swap(input.amount, tokenInAddress, tokenOutAddress); return JSON.stringify({ status: "success", result, fromToken: input.tokenInTicker, toToken: input.tokenOutTicker, amount: input.amount, }); } catch (error) { return JSON.stringify({ status: "error", message: error.message, code: error.code || "UNKNOWN_ERROR", }); } } } //# sourceMappingURL=swap.js.map