kiban-agent-kit
Version:
Open-source framework connecting AI agents to Katana ecosystem protocols
100 lines (99 loc) • 3.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TokenAllowanceTool = exports.TokenApprovalTool = exports.TokenInfoTool = void 0;
const tools_1 = require("@langchain/core/tools");
const zod_1 = require("zod");
const token_1 = require("../tools/token");
/**
* LangChain tool for checking ERC20 token information and balance
*/
class TokenInfoTool extends tools_1.StructuredTool {
constructor(agent) {
super();
this.name = "check_token_info";
this.description = "Get information about an ERC20 token including name, symbol, decimals and balance";
this.schema = zod_1.z.object({
tokenAddress: zod_1.z.string().describe("The ERC20 token contract address"),
walletAddress: zod_1.z
.string()
.optional()
.describe("Optional wallet address to check balance for"),
});
this.service = new token_1.TokenService(agent);
}
async _call(input) {
try {
const tokenInfo = await this.service.getTokenInfo(input.tokenAddress);
return JSON.stringify({
name: tokenInfo.name,
symbol: tokenInfo.symbol,
decimals: tokenInfo.decimals,
balance: tokenInfo.balance,
}, null, 2);
}
catch (error) {
return `Error getting token info: ${error.message}`;
}
}
}
exports.TokenInfoTool = TokenInfoTool;
/**
* LangChain tool for approving token spending
*/
class TokenApprovalTool extends tools_1.StructuredTool {
constructor(agent) {
super();
this.name = "approve_token_spending";
this.description = "Approve a spender to use a specific amount of your ERC20 tokens";
this.schema = zod_1.z.object({
tokenAddress: zod_1.z.string().describe("The ERC20 token contract address"),
spenderAddress: zod_1.z.string().describe("The address to approve as spender"),
amount: zod_1.z.string().describe("The amount to approve"),
});
this.service = new token_1.TokenService(agent);
}
async _call(input) {
try {
const result = await this.service.approveSpending({
token: input.tokenAddress,
spender: input.spenderAddress,
amount: input.amount,
});
return `Approval transaction sent: ${result.hash}`;
}
catch (error) {
return `Error approving token spending: ${error.message}`;
}
}
}
exports.TokenApprovalTool = TokenApprovalTool;
/**
* LangChain tool for checking token allowance
*/
class TokenAllowanceTool extends tools_1.StructuredTool {
constructor(agent) {
super();
this.name = "check_token_allowance";
this.description = "Check how much of a token a spender is allowed to use on behalf of an owner";
this.schema = zod_1.z.object({
tokenAddress: zod_1.z.string().describe("The ERC20 token contract address"),
ownerAddress: zod_1.z.string().describe("The token owner's address"),
spenderAddress: zod_1.z.string().describe("The spender's address"),
});
this.service = new token_1.TokenService(agent);
}
async _call(input) {
try {
const allowance = await this.service.getAllowance({
token: input.tokenAddress,
owner: input.ownerAddress,
spender: input.spenderAddress,
});
return `Allowance: ${allowance.toString()}`;
}
catch (error) {
return `Error checking allowance: ${error.message}`;
}
}
}
exports.TokenAllowanceTool = TokenAllowanceTool;