UNPKG

sei-agent-kit

Version:

A package for building AI agents on the SEI blockchain

89 lines 3.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SeiGetBorrowBalanceTool = exports.SeiGetRedeemableAmountTool = void 0; const zod_1 = require("zod"); const tools_1 = require("langchain/tools"); const SeiGetRedeemableAmountInputSchema = zod_1.z.object({ ticker: zod_1.z .string() .describe("The token ticker (e.g., 'USDC', 'SEI')"), userAddress: zod_1.z .string() .optional() .describe("Optional: The address of the user to check. Defaults to the agent's wallet address"), }); /** * LangChain tool for querying redeemable amounts in Takara Protocol */ class SeiGetRedeemableAmountTool extends tools_1.StructuredTool { constructor(seiKit) { super(); this.seiKit = seiKit; this.name = "get_takara_redeemable_amount"; this.description = "Calculates the amount of underlying tokens that can be redeemed by a user in the Takara Protocol."; this.schema = SeiGetRedeemableAmountInputSchema; } async _call({ ticker, userAddress }) { try { const result = await this.seiKit.getRedeemableAmount(ticker, userAddress); return JSON.stringify({ status: "success", tTokenBalance: result.tTokenBalance, exchangeRate: result.exchangeRate, redeemableUnderlying: result.redeemableUnderlying, safeMaxRedeemable: result.safeMaxRedeemable, underlyingDecimals: result.underlyingDecimals, underlyingTokenAddress: result.underlyingTokenAddress, }); } catch (error) { return JSON.stringify({ status: "error", message: error.message, code: error.code || "UNKNOWN_ERROR", }); } } } exports.SeiGetRedeemableAmountTool = SeiGetRedeemableAmountTool; const SeiGetBorrowBalanceInputSchema = zod_1.z.object({ ticker: zod_1.z .string() .describe("The token ticker (e.g., 'USDC', 'SEI')"), userAddress: zod_1.z .string() .optional() .describe("Optional: The address of the user to check. Defaults to the agent's wallet address"), }); /** * LangChain tool for querying borrow balances in Takara Protocol */ class SeiGetBorrowBalanceTool extends tools_1.StructuredTool { constructor(seiKit) { super(); this.seiKit = seiKit; this.name = "get_takara_borrow_balance"; this.description = "Retrieves the current borrow balance for a user in the Takara Protocol."; this.schema = SeiGetBorrowBalanceInputSchema; } async _call({ ticker, userAddress }) { try { const result = await this.seiKit.getBorrowBalance(ticker, userAddress); return JSON.stringify({ status: "success", borrowBalance: result.borrowBalance, underlyingDecimals: result.underlyingDecimals, underlyingTokenAddress: result.underlyingTokenAddress, }); } catch (error) { return JSON.stringify({ status: "error", message: error.message, code: error.code || "UNKNOWN_ERROR", }); } } } exports.SeiGetBorrowBalanceTool = SeiGetBorrowBalanceTool; //# sourceMappingURL=query.js.map