UNPKG

pharos-agent-kit

Version:
57 lines (53 loc) 2.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PharosERC20BalanceTool = void 0; const tools_1 = require("langchain/tools"); const zod_1 = require("zod"); const PharosERC20BalanceInputSchema = zod_1.z.object({ contract_address: zod_1.z.string().optional(), ticker: zod_1.z.string().optional(), }); class PharosERC20BalanceTool extends tools_1.StructuredTool { constructor(pharosKit) { super(); this.pharosKit = pharosKit; this.name = "pharos_erc20_balance"; this.description = `Get the balance of ETH or ERC20 tokens in a Pharos wallet. This tool retrieves token balances without requiring a wallet address (uses connected wallet). If neither parameter is provided, returns the native ETH 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-ETH token.`; this.schema = PharosERC20BalanceInputSchema; } async _call(input) { try { let balance; if (input) { let contract_address; if (input.contract_address) { contract_address = input.contract_address; } balance = await this.pharosKit.getBalance(contract_address); } else { balance = await this.pharosKit.getBalance(); } return JSON.stringify({ status: "success", balance, token: input.contract_address || input.ticker || "ETH", }); } catch (error) { return JSON.stringify({ status: "error", message: error.message, code: error.code || "UNKNOWN_ERROR", }); } } } exports.PharosERC20BalanceTool = PharosERC20BalanceTool; //# sourceMappingURL=balance.js.map