sei-agent-kit
Version:
A package for building AI agents on the SEI blockchain
47 lines (46 loc) • 1.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SeiSwapTool = void 0;
const tools_1 = require("langchain/tools");
const zod_1 = require("zod");
const SwapInputSchema = zod_1.z.object({
amount: zod_1.z.string().min(1, "Amount must not be empty"),
tokenInTicker: zod_1.z.string().min(1, "Token input ticker must not be empty"),
tokenOutTicker: zod_1.z.string().min(1, "Token output ticker must not be empty"),
});
class SeiSwapTool extends tools_1.StructuredTool {
constructor(seiKit) {
super();
this.seiKit = seiKit;
this.name = "sei_swap";
this.description = `Swap tokens using the Symphony aggregator.
Parameters:
- amount: The amount of tokens to swap as a string (e.g., "1.5").
- tokenInTicker: The ticker symbol of the token to swap from (e.g., "SEI").
- tokenOutTicker: The ticker symbol of the token to swap to (e.g., "USDC").`;
this.schema = SwapInputSchema;
}
async _call(input) {
try {
const tokenInAddress = input.tokenInTicker === "SEI" ? "0x0" : await this.seiKit.getTokenAddressFromTicker(input.tokenInTicker);
const tokenOutAddress = input.tokenOutTicker === "SEI" ? "0x0" : await this.seiKit.getTokenAddressFromTicker(input.tokenOutTicker);
const result = await this.seiKit.swap(input.amount, tokenInAddress, tokenOutAddress);
return JSON.stringify({
status: "success",
result,
fromToken: input.tokenInTicker,
toToken: input.tokenOutTicker,
amount: input.amount,
});
}
catch (error) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
exports.SeiSwapTool = SeiSwapTool;
//# sourceMappingURL=swap.js.map