UNPKG

sei-agent-kit

Version:

A package for building AI agents on the SEI blockchain

61 lines (57 loc) 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SeiERC20BalanceTool = void 0; const tools_1 = require("langchain/tools"); const tools_2 = require("../../tools"); const zod_1 = require("zod"); const SeiERC20BalanceInputSchema = zod_1.z.object({ contract_address: zod_1.z.string().optional(), ticker: zod_1.z.string().optional(), }); class SeiERC20BalanceTool extends tools_1.StructuredTool { constructor(seiKit) { super(); this.seiKit = seiKit; this.name = "sei_erc20_balance"; this.description = `Get the balance of ERC20 tokens in a Sei wallet. This tool retrieves token balances without requiring a wallet address (uses connected wallet). If neither parameter is provided, returns the native SEI token balance. Parameters: - contract_address: Optional. The contract address of the token. - ticker: Optional. The token symbol/ticker (e.g., "USDC"). One of these parameters can be used to specify a non-SEI token.`; this.schema = SeiERC20BalanceInputSchema; } async _call(input) { try { var balance; if (input) { let contract_address; if (input.ticker) { contract_address = await (0, tools_2.getTokenAddressFromTicker)(input.ticker); } else if (input.contract_address) { contract_address = input.contract_address; } balance = await this.seiKit.getERC20Balance(contract_address); } else { balance = await this.seiKit.getERC20Balance(); } return JSON.stringify({ status: "success", balance, token: input || "SEI", }); } catch (error) { return JSON.stringify({ status: "error", message: error.message, code: error.code || "UNKNOWN_ERROR", }); } } } exports.SeiERC20BalanceTool = SeiERC20BalanceTool; //# sourceMappingURL=balance.js.map