@cetusprotocol/aggregator-sdk 0.3.31 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,127 @@
1
+ import { describe, test } from "@jest/globals"
2
+ import dotenv from "dotenv"
3
+ import { AggregatorClient } from "~/client"
4
+ import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
5
+ import { printTransaction } from "~/utils/transaction"
6
+ import BN from "bn.js"
7
+ import { fromB64 } from "@mysten/sui/utils"
8
+ import { SuiClient } from "@mysten/sui/client"
9
+ import { Env } from "~/index"
10
+ import { Transaction } from "@mysten/sui/transactions"
11
+
12
+ dotenv.config()
13
+
14
+ export function buildTestAccount(): Ed25519Keypair {
15
+ const mnemonics = process.env.SUI_WALLET_MNEMONICS || ""
16
+ const testAccountObject = Ed25519Keypair.deriveKeypair(mnemonics)
17
+ return testAccountObject
18
+ }
19
+
20
+ describe("Test scallop provider", () => {
21
+ let client: AggregatorClient
22
+ let keypair: Ed25519Keypair
23
+
24
+ const T_HASUI = "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
25
+ const T_SHASUI = "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI"
26
+
27
+ const T_SUI = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
28
+ const T_SSUI = "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI"
29
+
30
+ beforeAll(() => {
31
+ const fullNodeURL = process.env.SUI_RPC!
32
+ const aggregatorURL = process.env.CETUS_AGGREGATOR!
33
+ const secret = process.env.SUI_WALLET_SECRET!
34
+
35
+ if (secret) {
36
+ keypair = Ed25519Keypair.fromSecretKey(fromB64(secret).slice(1, 33))
37
+ } else {
38
+ keypair = buildTestAccount()
39
+ }
40
+
41
+ // const wallet = keypair.getPublicKey().toSuiAddress()
42
+ const wallet =
43
+ "0xf077fa7f67b1f2d417bbe977b3cbc113b078907f74e04120f623b87b23e93963"
44
+
45
+ console.log("wallet: ", wallet)
46
+
47
+ const endpoint = aggregatorURL
48
+
49
+ const suiClient = new SuiClient({
50
+ url: fullNodeURL,
51
+ })
52
+
53
+ client = new AggregatorClient(endpoint, wallet, suiClient, Env.Mainnet)
54
+ })
55
+
56
+ test("Find Routers", async () => {
57
+ const amounts = ["1000", "1000000", "100000000", "5000000000", "1000000000000000000000000000"]
58
+
59
+ while (true) {
60
+ const res = await client.findRouters({
61
+ from: T_SUI,
62
+ target: T_SSUI,
63
+ amount: new BN("1000000000000000000000000000"),
64
+ byAmountIn: true,
65
+ depth: 3,
66
+ splitCount: 1,
67
+ providers: ["SCALLOP"],
68
+ })
69
+
70
+ if (res != null) {
71
+ console.log(JSON.stringify(res, null, 2))
72
+ }
73
+ console.log("amount in", res?.amountIn.toString())
74
+ console.log("amount out", res?.amountOut.toString())
75
+ }
76
+ }, 6000000)
77
+
78
+ test("Build Router TX", async () => {
79
+ const amount = "10000000"
80
+
81
+ const res = await client.findRouters({
82
+ from: T_HASUI,
83
+ target: T_SHASUI,
84
+ amount: new BN(amount),
85
+ byAmountIn: true,
86
+ depth: 3,
87
+ providers: ["SCALLOP"],
88
+ })
89
+
90
+ console.log("amount in", res?.amountIn.toString())
91
+ console.log("amount out", res?.amountOut.toString())
92
+
93
+ const txb = new Transaction()
94
+
95
+ if (res != null) {
96
+ console.log(JSON.stringify(res, null, 2))
97
+ await client.fastRouterSwap({
98
+ routers: res,
99
+ txb,
100
+ slippage: 0.01,
101
+ refreshAllCoins: true,
102
+ payDeepFeeAmount: 0,
103
+ })
104
+
105
+ txb.setSender(client.signer)
106
+ const buildTxb = await txb.build({ client: client.client })
107
+ // const buildTxb = await txb.getData()
108
+
109
+ console.log("buildTxb", buildTxb)
110
+
111
+ printTransaction(txb)
112
+
113
+ let result = await client.devInspectTransactionBlock(txb)
114
+ console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
115
+ for (const event of result.events) {
116
+ console.log("event", JSON.stringify(event, null, 2))
117
+ }
118
+
119
+ if (result.effects.status.status === "success") {
120
+ const result = await client.signAndExecuteTransaction(txb, keypair)
121
+ console.log("result", result)
122
+ } else {
123
+ console.log("result", result)
124
+ }
125
+ }
126
+ }, 600000)
127
+ })