Skip to content

Commit 91f2caa

Browse files
committed
feat: add tool suilend unstaking
1 parent 5f91587 commit 91f2caa

File tree

5 files changed

+100
-3
lines changed

5 files changed

+100
-3
lines changed

src/actions/agent/unstakeSuilend.ts

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Action } from "../../types/action";
2+
import { SuiAgentKit } from "../../agent";
3+
import { z } from "zod";
4+
import { unstaking_suilend } from "../../tools/suilend";
5+
import { IUnstakingParams } from "../../types/farming";
6+
7+
const unstakeSuilend: Action = {
8+
name: "UNSTAKE_SUILEND",
9+
similes: ["unstake suilend", "unstake from suilend", "suilend unstake"],
10+
description: "Unstake tokens from Suilend protocol",
11+
examples: [
12+
[
13+
{
14+
input: {
15+
amount: 1,
16+
symbol: "sSUI",
17+
},
18+
output: {
19+
status: "success",
20+
result: {
21+
tx_hash: "5JvBtQveYFsZFYxXMfSxYzUJgzGfyRgkH9YuZxpvuR9Y",
22+
tx_status: "success",
23+
},
24+
},
25+
explanation: "Successfully unstaked 1 sSUI from Suilend protocol",
26+
},
27+
],
28+
],
29+
schema: z.object({
30+
amount: z.number().positive(),
31+
symbol: z.string(),
32+
}),
33+
handler: async (agent: SuiAgentKit, input: Record<string, any>) => {
34+
const params: IUnstakingParams = {
35+
type: "UNSTAKING",
36+
amount: input.amount,
37+
symbol: input.symbol,
38+
poolId: "",
39+
};
40+
41+
const result = await unstaking_suilend(agent, params);
42+
43+
return {
44+
status: "success",
45+
result,
46+
};
47+
},
48+
};
49+
50+
export default unstakeSuilend;

src/langchain/agent/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ export * from "./create_pool_cetus_clmm";
1010
export * from "./transfer_token";
1111
export * from "./register_sns";
1212
export * from "./get_sns_name_record";
13+
export * from "./stake_suilend";
14+
export * from "./unstake_suilend";

src/langchain/agent/stake_suilend.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export class SuiStakeSuilendTool extends Tool {
77
description = `Stake tokens into Suilend protocol.
88
99
Inputs (input is a JSON string):
10-
amount: number - The amount of tokens to stake (must be positive and not specified minimum amount)
11-
symbol: string - The token symbol to stake (e.g., "sSUI")
10+
amount: number - The amount of tokens to stake (required, e.g 0.1, 0.01, 0.001, 1, ...)
11+
symbol: string - The token symbol to stake (required, e.g., "sSUI")
1212
isStakeAndDeposit: boolean - When user want to deposit, set to true (optional)`;
1313

1414
constructor(private suiKit: SuiAgentKit) {
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
}

src/langchain/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import {
1414
SuiSwapTool,
1515
SuiRegisterSnsTool,
1616
SuiGetSnsNameRecordTool,
17+
SuiStakeSuilendTool,
18+
SuiUnstakeSuilendTool,
1719
} from "./agent";
18-
import { SuiStakeSuilendTool } from "./agent/stake_suilend";
1920

2021
export function createSuiTools(suiKit: SuiAgentKit) {
2122
return [
@@ -32,5 +33,6 @@ export function createSuiTools(suiKit: SuiAgentKit) {
3233
new SuiRegisterSnsTool(suiKit),
3334
new SuiGetSnsNameRecordTool(suiKit),
3435
new SuiStakeSuilendTool(suiKit),
36+
new SuiUnstakeSuilendTool(suiKit),
3537
];
3638
}

0 commit comments

Comments
 (0)