-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnavi.ts
106 lines (97 loc) · 2.62 KB
/
navi.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { tool } from "ai";
import { z } from "zod";
import { instantiateAccount } from "./sui-utils";
import { NAVISDKClient } from "navi-sdk";
export const naviTool = tool({
description: "Interact with NAVI protocol to supply tokens, withdraw tokens, borrow, repay or claim rewards",
parameters: z.object({
action: z
.enum(["supply", "withdraw", "borrow", "repay", "claim"])
.describe("Action to perform on NAVI"),
coinType: z
.enum([
"Sui",
"NAVX",
"vSui",
"USDT",
"USDC",
"WETH",
"CETUS",
"haSui",
"WBTC",
"AUSD",
])
.optional()
.describe("Coin type to interact with"),
amount: z.string().optional().describe("Amount in base units"),
}),
execute: async (args) => {
const keypair = await instantiateAccount(process.env.SUI_PRIVATE_KEY);
const client = new NAVISDKClient({
privateKeyList: [keypair.getSecretKey().toString()],
});
const account = client.accounts[0];
const {
Sui,
NAVX,
vSui,
USDT,
WETH,
CETUS,
haSui,
WBTC,
AUSD,
wUSDC,
} = await import("navi-sdk");
const coinMap: { [key: string]: any } = {
Sui,
NAVX,
vSui,
USDT,
WETH,
CETUS,
haSui,
WBTC,
AUSD,
wUSDC,
};
let result;
switch (args.action) {
case "supply":
if (!args.coinType || !args.amount) {
throw new Error("Coin type and amount required for supply");
}
result = await account.depositToNavi(
coinMap[args.coinType],
Number(args.amount)
);
return result;
case "withdraw":
if (!args.coinType || !args.amount) {
throw new Error("Coin type and amount required for withdraw");
}
result = await account.withdraw(
coinMap[args.coinType],
Number(args.amount)
);
return result;
case "borrow":
if (!args.coinType || !args.amount) {
throw new Error("Coin type and amount required for borrow");
}
result = await account.borrow(coinMap[args.coinType], Number(args.amount));
return result;
case "repay":
if (!args.coinType || !args.amount) {
throw new Error("Coin type and amount required for repay");
}
result = await account.repay(coinMap[args.coinType], Number(args.amount));
return result;
case "claim":
result = await account.claimAllRewards();
return result;
default:
throw new Error("Invalid action specified");
}
},
});