sei-agent-kit
Version:
A package for building AI agents on the SEI blockchain
86 lines • 3.05 kB
JavaScript
import { z } from "zod";
import { StructuredTool } from "langchain/tools";
const SeiGetRedeemableAmountInputSchema = z.object({
ticker: z
.string()
.describe("The token ticker (e.g., 'USDC', 'SEI')"),
userAddress: 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
*/
export class SeiGetRedeemableAmountTool extends StructuredTool {
seiKit;
name = "get_takara_redeemable_amount";
description = "Calculates the amount of underlying tokens that can be redeemed by a user in the Takara Protocol.";
schema = SeiGetRedeemableAmountInputSchema;
constructor(seiKit) {
super();
this.seiKit = seiKit;
}
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",
});
}
}
}
const SeiGetBorrowBalanceInputSchema = z.object({
ticker: z
.string()
.describe("The token ticker (e.g., 'USDC', 'SEI')"),
userAddress: 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
*/
export class SeiGetBorrowBalanceTool extends StructuredTool {
seiKit;
name = "get_takara_borrow_balance";
description = "Retrieves the current borrow balance for a user in the Takara Protocol.";
schema = SeiGetBorrowBalanceInputSchema;
constructor(seiKit) {
super();
this.seiKit = seiKit;
}
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",
});
}
}
}
//# sourceMappingURL=query.js.map