|
| 1 | +import { Tool } from "langchain/tools"; |
| 2 | +import { SuiAgentKit } from "../../agent"; |
| 3 | +import { IUnstakingParams } from "../../types/farming"; |
| 4 | + |
| 5 | +export class SuiUnstakeSuilendTool extends Tool { |
| 6 | + name = "sui_unstake_suilend"; |
| 7 | + description = `Unstake tokens from Suilend protocol. |
| 8 | +
|
| 9 | + Inputs (input is a JSON string): |
| 10 | + amount: real number - The amount of tokens to unstake (required, e.g 0.1, 0.01, 0.001, 1, ...) |
| 11 | + symbol: string - The token symbol to unstake (required, e.g., "sSUI")`; |
| 12 | + |
| 13 | + constructor(private suiKit: SuiAgentKit) { |
| 14 | + super(); |
| 15 | + } |
| 16 | + |
| 17 | + async _call(input: string): Promise<string> { |
| 18 | + try { |
| 19 | + const parsedInput = JSON.parse(input); |
| 20 | + const params: IUnstakingParams = { |
| 21 | + type: "UNSTAKING", |
| 22 | + amount: parsedInput.amount, |
| 23 | + symbol: parsedInput.symbol, |
| 24 | + poolId: "", |
| 25 | + }; |
| 26 | + |
| 27 | + const result = await this.suiKit.unstakeSuilend(params); |
| 28 | + return JSON.stringify({ |
| 29 | + status: "success", |
| 30 | + result: { |
| 31 | + tx_hash: result.tx_hash, |
| 32 | + tx_status: result.tx_status, |
| 33 | + }, |
| 34 | + }); |
| 35 | + } catch (error: any) { |
| 36 | + return JSON.stringify({ |
| 37 | + status: "error", |
| 38 | + message: error.message, |
| 39 | + code: error.code || "UNKNOWN_ERROR", |
| 40 | + }); |
| 41 | + } |
| 42 | + } |
| 43 | +} |
0 commit comments