@cetusprotocol/aggregator-sdk 0.4.1 → 0.4.2

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.
Files changed (101) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/index.mjs +1 -1
  3. package/package.json +1 -1
  4. package/dist/src/api.d.ts +0 -104
  5. package/dist/src/client.d.ts +0 -118
  6. package/dist/src/const.d.ts +0 -8
  7. package/dist/src/errors.d.ts +0 -40
  8. package/dist/src/index.d.ts +0 -9
  9. package/dist/src/math.d.ts +0 -6
  10. package/dist/src/transaction/afsui.d.ts +0 -10
  11. package/dist/src/transaction/aftermath.d.ts +0 -13
  12. package/dist/src/transaction/alphafi.d.ts +0 -7
  13. package/dist/src/transaction/bluefin.d.ts +0 -7
  14. package/dist/src/transaction/bluemove.d.ts +0 -7
  15. package/dist/src/transaction/cetus.d.ts +0 -15
  16. package/dist/src/transaction/deepbook_v2.d.ts +0 -14
  17. package/dist/src/transaction/deepbook_v3.d.ts +0 -12
  18. package/dist/src/transaction/flowx_v2.d.ts +0 -7
  19. package/dist/src/transaction/flowx_v3.d.ts +0 -8
  20. package/dist/src/transaction/haedal.d.ts +0 -6
  21. package/dist/src/transaction/haedal_pmm.d.ts +0 -7
  22. package/dist/src/transaction/index.d.ts +0 -10
  23. package/dist/src/transaction/kriya_v2.d.ts +0 -6
  24. package/dist/src/transaction/kriya_v3.d.ts +0 -7
  25. package/dist/src/transaction/metastable.d.ts +0 -8
  26. package/dist/src/transaction/obric.d.ts +0 -8
  27. package/dist/src/transaction/scallop.d.ts +0 -8
  28. package/dist/src/transaction/steamm.d.ts +0 -6
  29. package/dist/src/transaction/suilend.d.ts +0 -7
  30. package/dist/src/transaction/swap.d.ts +0 -4
  31. package/dist/src/transaction/turbos.d.ts +0 -7
  32. package/dist/src/transaction/volo.d.ts +0 -8
  33. package/dist/src/types/CoinAssist.d.ts +0 -122
  34. package/dist/src/types/sui.d.ts +0 -112
  35. package/dist/src/utils/api.d.ts +0 -1
  36. package/dist/src/utils/coin.d.ts +0 -11
  37. package/dist/src/utils/contracts.d.ts +0 -16
  38. package/dist/src/utils/index.d.ts +0 -5
  39. package/dist/src/utils/msafe.d.ts +0 -2
  40. package/dist/src/utils/transaction.d.ts +0 -3
  41. package/dist/tests/math.test.d.ts +0 -1
  42. package/dist/tests/router/alphafi.test.d.ts +0 -2
  43. package/dist/tests/router/metastable.test.d.ts +0 -2
  44. package/dist/tests/router/obric.test.d.ts +0 -2
  45. package/dist/tests/router/scallop.test.d.ts +0 -2
  46. package/dist/tests/router/steamm.test.d.ts +0 -2
  47. package/dist/tests/router.test.d.ts +0 -2
  48. package/dist/tests/test_data.test.d.ts +0 -18
  49. package/dist/tests/wallet.test.d.ts +0 -1
  50. package/example/package.json +0 -17
  51. package/example/swap.ts +0 -21
  52. package/example/tsconfig.json +0 -12
  53. package/jest.config.mjs +0 -13
  54. package/src/api.ts +0 -325
  55. package/src/client.ts +0 -1081
  56. package/src/const.ts +0 -15
  57. package/src/errors.ts +0 -77
  58. package/src/index.ts +0 -10
  59. package/src/math.ts +0 -66
  60. package/src/transaction/afsui.ts +0 -62
  61. package/src/transaction/aftermath.ts +0 -88
  62. package/src/transaction/alphafi.ts +0 -50
  63. package/src/transaction/bluefin.ts +0 -46
  64. package/src/transaction/bluemove.ts +0 -42
  65. package/src/transaction/cetus.ts +0 -118
  66. package/src/transaction/deepbook_v2.ts +0 -122
  67. package/src/transaction/deepbook_v3.ts +0 -60
  68. package/src/transaction/flowx_v2.ts +0 -42
  69. package/src/transaction/flowx_v3.ts +0 -52
  70. package/src/transaction/haedal.ts +0 -33
  71. package/src/transaction/haedal_pmm.ts +0 -80
  72. package/src/transaction/index.ts +0 -42
  73. package/src/transaction/kriya_v2.ts +0 -37
  74. package/src/transaction/kriya_v3.ts +0 -47
  75. package/src/transaction/metastable.ts +0 -141
  76. package/src/transaction/obric.ts +0 -90
  77. package/src/transaction/scallop.ts +0 -64
  78. package/src/transaction/steamm.ts +0 -77
  79. package/src/transaction/suilend.ts +0 -48
  80. package/src/transaction/swap.ts +0 -162
  81. package/src/transaction/turbos.ts +0 -56
  82. package/src/transaction/volo.ts +0 -53
  83. package/src/types/CoinAssist.ts +0 -217
  84. package/src/types/sui.ts +0 -148
  85. package/src/utils/api.ts +0 -6
  86. package/src/utils/coin.ts +0 -136
  87. package/src/utils/contracts.ts +0 -136
  88. package/src/utils/index.ts +0 -5
  89. package/src/utils/msafe.ts +0 -40
  90. package/src/utils/transaction.ts +0 -20
  91. package/tests/math.test.ts +0 -21
  92. package/tests/router/alphafi.test.ts +0 -132
  93. package/tests/router/metastable.test.ts +0 -383
  94. package/tests/router/obric.test.ts +0 -203
  95. package/tests/router/scallop.test.ts +0 -133
  96. package/tests/router/steamm.test.ts +0 -130
  97. package/tests/router.test.ts +0 -379
  98. package/tests/test_data.test.ts +0 -28
  99. package/tests/wallet.test.ts +0 -21
  100. package/tsup.config.ts +0 -23
  101. package/version.mjs +0 -28
@@ -1,383 +0,0 @@
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 metastable provider", () => {
21
- let client: AggregatorClient
22
- let keypair: Ed25519Keypair
23
-
24
- const T_SUPER_SUI = "0x790f258062909e3a0ffc78b3c53ac2f62d7084c3bab95644bdeb05add7250001::super_sui::SUPER_SUI"
25
- const T_SUI = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
26
- const AF_SUI = "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"
27
-
28
- const WH_USDC = "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN"
29
- const T_USDC = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
30
- const M_USDC = "0xe44df51c0b21a27ab915fa1fe2ca610cd3eaa6d9666fe5e62b988bf7f0bd8722::musd::MUSD"
31
-
32
- const METH = "0xccd628c2334c5ed33e6c47d6c21bb664f8b6307b2ac32c2462a61f69a31ebcee::meth::METH"
33
- const ETH = "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH"
34
- const WEHT = "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN"
35
-
36
- beforeAll(() => {
37
- const fullNodeURL = process.env.SUI_RPC!
38
- const aggregatorURL = process.env.CETUS_AGGREGATOR!
39
- const secret = process.env.SUI_WALLET_SECRET!
40
-
41
- if (secret) {
42
- keypair = Ed25519Keypair.fromSecretKey(fromB64(secret).slice(1, 33))
43
- } else {
44
- keypair = buildTestAccount()
45
- }
46
-
47
- // const wallet = keypair.getPublicKey().toSuiAddress()
48
- // const wallet =
49
- // "0x5cade8f29891e04c5f6e5ad3a020583fda51c8267f1b0c0fa5a85158d486ac3b" // has 1 meth
50
-
51
- const wallet = "0x80cda5d0baa1e33ad073f590f8e6dc00a8d3657663ce06ce08c18ecbb0e47031" // has 80 eth
52
-
53
- console.log("wallet: ", wallet)
54
-
55
- const endpoint = aggregatorURL
56
-
57
- const suiClient = new SuiClient({
58
- url: fullNodeURL,
59
- })
60
- client = new AggregatorClient({
61
- endpoint,
62
- signer: wallet,
63
- client: suiClient,
64
- env: Env.Mainnet,
65
- pythUrls: ["https://cetus-pythnet-a648.mainnet.pythnet.rpcpool.com/219cf7a8-6d75-432d-a648-d487a6dd5dc3/hermes"],
66
- })
67
- })
68
-
69
- test("Find Routers --> SUI -> SUPER_SUI", async () => {
70
- // const amounts = ["1000", "1000000", "100000000", "5000000000", "10000000000000"]
71
- const amounts = ["999000000", "5000000000"]
72
-
73
- for (const amount of amounts) {
74
- const res = await client.findRouters({
75
- from: T_SUI,
76
- target: T_SUPER_SUI,
77
- amount: new BN(amount),
78
- byAmountIn: true,
79
- depth: 3,
80
- splitCount: 1,
81
- providers: ["METASTABLE"],
82
- })
83
-
84
- if (res != null) {
85
- console.log(JSON.stringify(res, null, 2))
86
- }
87
- console.log("amount in", res?.amountIn.toString())
88
- console.log("amount out", res?.amountOut.toString())
89
-
90
- const txb = new Transaction()
91
-
92
- if (res != null) {
93
- console.log(JSON.stringify(res, null, 2))
94
- await client.fastRouterSwap({
95
- routers: res,
96
- txb,
97
- slippage: 0.01,
98
- refreshAllCoins: true,
99
- payDeepFeeAmount: 0,
100
- })
101
-
102
- txb.setSender(client.signer)
103
- const buildTxb = await txb.build({ client: client.client })
104
- // const buildTxb = await txb.getData()
105
-
106
- console.log("buildTxb", buildTxb)
107
- // printTransaction(txb)
108
-
109
- let result = await client.devInspectTransactionBlock(txb)
110
- console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
111
- for (const event of result.events) {
112
- console.log("event", JSON.stringify(event, null, 2))
113
- }
114
- }
115
- }
116
- })
117
-
118
- test("Find Routers --> SUPER_SUI --> SUI", async () => {
119
- // const amounts = ["1000", "1000000", "100000000", "5000000000", "10000000000000"]
120
- const amounts = ["1000", "1000000", "900000000"]
121
-
122
- for (const amount of amounts) {
123
- const res = await client.findRouters({
124
- from: T_SUPER_SUI,
125
- target: T_SUI,
126
- amount: new BN(amount),
127
- byAmountIn: true,
128
- depth: 3,
129
- splitCount: 1,
130
- providers: ["METASTABLE"],
131
- })
132
-
133
- if (res != null) {
134
- console.log(JSON.stringify(res, null, 2))
135
- }
136
- console.log("amount in", res?.amountIn.toString())
137
- console.log("amount out", res?.amountOut.toString())
138
-
139
- const txb = new Transaction()
140
-
141
- if (res != null) {
142
- console.log(JSON.stringify(res, null, 2))
143
- await client.fastRouterSwap({
144
- routers: res,
145
- txb,
146
- slippage: 0.01,
147
- refreshAllCoins: true,
148
- payDeepFeeAmount: 0,
149
- })
150
-
151
- txb.setSender(client.signer)
152
- const buildTxb = await txb.build({ client: client.client })
153
- // const buildTxb = await txb.getData()
154
-
155
- // printTransaction(txb)
156
-
157
- let result = await client.devInspectTransactionBlock(txb)
158
- console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
159
- for (const event of result.events) {
160
- console.log("event", JSON.stringify(event, null, 2))
161
- }
162
- }
163
- }
164
- })
165
-
166
- test("Find Routers --> USDC -> MUSDC", async () => {
167
- const amounts = ["1000000", "30000000"]
168
-
169
- for (const amount of amounts) {
170
- const res = await client.findRouters({
171
- from: T_USDC,
172
- target: M_USDC,
173
- amount: new BN(amount),
174
- byAmountIn: true,
175
- depth: 3,
176
- splitCount: 1,
177
- providers: ["METASTABLE"],
178
- })
179
-
180
- if (res != null) {
181
- console.log(JSON.stringify(res, null, 2))
182
- }
183
- console.log("amount in", res?.amountIn.toString())
184
- console.log("amount out", res?.amountOut.toString())
185
-
186
- const txb = new Transaction()
187
-
188
- if (res != null) {
189
- console.log(JSON.stringify(res, null, 2))
190
- await client.fastRouterSwap({
191
- routers: res,
192
- txb,
193
- slippage: 0.01,
194
- refreshAllCoins: true,
195
- payDeepFeeAmount: 0,
196
- })
197
- txb.setSender(client.signer)
198
-
199
- let result = await client.devInspectTransactionBlock(txb)
200
- console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
201
- for (const event of result.events) {
202
- console.log("event", JSON.stringify(event, null, 2))
203
- }
204
- }
205
- }
206
- })
207
-
208
- test("Find Routers --> MUSDC -> USDC", async () => {
209
- // const amounts = ["1000", "1000000", "100000000", "5000000000", "10000000000000"]
210
- const amounts = ["1000000", "1000000000"]
211
-
212
- for (const amount of amounts) {
213
- const res = await client.findRouters({
214
- from: M_USDC,
215
- target: T_USDC,
216
- amount: new BN(amount),
217
- byAmountIn: true,
218
- depth: 3,
219
- splitCount: 1,
220
- providers: ["METASTABLE"],
221
- })
222
-
223
- if (res != null) {
224
- console.log(JSON.stringify(res, null, 2))
225
- }
226
- console.log("amount in", res?.amountIn.toString())
227
- console.log("amount out", res?.amountOut.toString())
228
-
229
- const txb = new Transaction()
230
-
231
- if (res != null) {
232
- console.log(JSON.stringify(res, null, 2))
233
- await client.fastRouterSwap({
234
- routers: res,
235
- txb,
236
- slippage: 0.01,
237
- refreshAllCoins: true,
238
- payDeepFeeAmount: 0,
239
- })
240
- txb.setSender(client.signer)
241
-
242
- let result = await client.devInspectTransactionBlock(txb)
243
- console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
244
- for (const event of result.events) {
245
- console.log("event", JSON.stringify(event, null, 2))
246
- }
247
- }
248
-
249
- }
250
- })
251
-
252
- test("Find Routers --> METH -> ETH", async () => {
253
- const amounts = ["5000000", "100000000"]
254
-
255
- for (const amount of amounts) {
256
- const res = await client.findRouters({
257
- from: METH,
258
- target: ETH,
259
- amount: new BN(amount),
260
- byAmountIn: true,
261
- depth: 3,
262
- splitCount: 1,
263
- providers: ["METASTABLE"],
264
- })
265
-
266
- if (res != null) {
267
- console.log(JSON.stringify(res, null, 2))
268
- }
269
- console.log("amount in", res?.amountIn.toString())
270
- console.log("amount out", res?.amountOut.toString())
271
-
272
- const txb = new Transaction()
273
-
274
- if (res != null) {
275
- console.log(JSON.stringify(res, null, 2))
276
- await client.fastRouterSwap({
277
- routers: res,
278
- txb,
279
- slippage: 0.01,
280
- refreshAllCoins: true,
281
- payDeepFeeAmount: 0,
282
- })
283
- txb.setSender(client.signer)
284
-
285
- let result = await client.devInspectTransactionBlock(txb)
286
- console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
287
- for (const event of result.events) {
288
- console.log("event", JSON.stringify(event, null, 2))
289
- }
290
- }
291
- }
292
- })
293
-
294
- test("Find Routers --> ETH -> METH", async () => {
295
- const amounts = ["10000000", "5000000000"]
296
-
297
- for (const amount of amounts) {
298
- const res = await client.findRouters({
299
- from: ETH,
300
- target: METH,
301
- amount: new BN(amount),
302
- byAmountIn: true,
303
- depth: 3,
304
- splitCount: 1,
305
- providers: ["METASTABLE"],
306
- })
307
-
308
- if (res != null) {
309
- console.log(JSON.stringify(res, null, 2))
310
- }
311
- console.log("amount in", res?.amountIn.toString())
312
- console.log("amount out", res?.amountOut.toString())
313
-
314
- const txb = new Transaction()
315
- if (res != null) {
316
- console.log(JSON.stringify(res, null, 2))
317
- await client.fastRouterSwap({
318
- routers: res,
319
- txb,
320
- slippage: 0.01,
321
- refreshAllCoins: true,
322
- payDeepFeeAmount: 0,
323
- })
324
- txb.setSender(client.signer)
325
-
326
- let result = await client.devInspectTransactionBlock(txb)
327
- console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
328
- for (const event of result.events) {
329
- console.log("event", JSON.stringify(event, null, 2))
330
- }
331
- }
332
- }
333
- })
334
-
335
- test("Build Router TX", async () => {
336
- const amount = "10000000"
337
-
338
- const res = await client.findRouters({
339
- from: T_USDC,
340
- target: M_USDC,
341
- amount: new BN(amount),
342
- byAmountIn: true,
343
- depth: 3,
344
- providers: ["METASTABLE"],
345
- })
346
-
347
- console.log("amount in", res?.amountIn.toString())
348
- console.log("amount out", res?.amountOut.toString())
349
-
350
- const txb = new Transaction()
351
-
352
- if (res != null) {
353
- console.log(JSON.stringify(res, null, 2))
354
- await client.fastRouterSwap({
355
- routers: res,
356
- txb,
357
- slippage: 0.01,
358
- refreshAllCoins: true,
359
- payDeepFeeAmount: 0,
360
- })
361
-
362
- txb.setSender(client.signer)
363
- const buildTxb = await txb.build({ client: client.client })
364
- // const buildTxb = await txb.getData()
365
-
366
- console.log("buildTxb", buildTxb)
367
- // printTransaction(txb)
368
-
369
- let result = await client.devInspectTransactionBlock(txb)
370
- console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
371
- for (const event of result.events) {
372
- console.log("event", JSON.stringify(event, null, 2))
373
- }
374
-
375
- // if (result.effects.status.status === "success") {
376
- // const result = await client.signAndExecuteTransaction(txb, keypair)
377
- // console.log("result", result)
378
- // } else {
379
- // console.log("result", result)
380
- // }
381
- }
382
- }, 600000)
383
- })
@@ -1,203 +0,0 @@
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 obric provider", () => {
21
- let client: AggregatorClient
22
- let keypair: Ed25519Keypair
23
-
24
- const T_SUI = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
25
- const WH_USDC = "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN"
26
- const T_USDC = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
27
-
28
- beforeAll(() => {
29
- const fullNodeURL = process.env.SUI_RPC!
30
- const aggregatorURL = process.env.CETUS_AGGREGATOR!
31
- const secret = process.env.SUI_WALLET_SECRET!
32
-
33
- if (secret) {
34
- keypair = Ed25519Keypair.fromSecretKey(fromB64(secret).slice(1, 33))
35
- } else {
36
- keypair = buildTestAccount()
37
- }
38
-
39
- // const wallet = keypair.getPublicKey().toSuiAddress()
40
-
41
- const wallet = "0x935029ca5219502a47ac9b69f556ccf6e2198b5e7815cf50f68846f723739cbd" // has 80 eth
42
- console.log("wallet: ", wallet)
43
-
44
- const endpoint = aggregatorURL
45
-
46
- const suiClient = new SuiClient({
47
- url: fullNodeURL,
48
- })
49
- client = new AggregatorClient({
50
- endpoint,
51
- signer: wallet,
52
- client: suiClient,
53
- env: Env.Mainnet,
54
- pythUrls: ["https://cetus-pythnet-a648.mainnet.pythnet.rpcpool.com/219cf7a8-6d75-432d-a648-d487a6dd5dc3/hermes"],
55
- })
56
- })
57
-
58
- test("Find Routers --> SUI -> USDC, locked", async () => {
59
- // const amounts = ["1000", "1000000", "100000000", "5000000000", "10000000000000"]
60
- const amounts = ["9990", "5000000000"]
61
-
62
- for (const amount of amounts) {
63
- const res = await client.findRouters({
64
- from: T_SUI,
65
- target: WH_USDC,
66
- amount: new BN(amount),
67
- byAmountIn: true,
68
- depth: 3,
69
- splitCount: 1,
70
- providers: ["OBRIC"],
71
- })
72
-
73
- if (res != null) {
74
- console.log(JSON.stringify(res, null, 2))
75
- }
76
- console.log("amount in", res?.amountIn.toString())
77
- console.log("amount out", res?.amountOut.toString())
78
-
79
- const txb = new Transaction()
80
-
81
- if (res != null) {
82
- console.log(JSON.stringify(res, null, 2))
83
- await client.fastRouterSwap({
84
- routers: res,
85
- txb,
86
- slippage: 0.01,
87
- refreshAllCoins: true,
88
- payDeepFeeAmount: 0,
89
- })
90
-
91
- txb.setSender(client.signer)
92
- const buildTxb = await txb.build({ client: client.client })
93
- // const buildTxb = await txb.getData()
94
-
95
- console.log("buildTxb", buildTxb)
96
- printTransaction(txb)
97
-
98
- let result = await client.devInspectTransactionBlock(txb)
99
- console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
100
- for (const event of result.events) {
101
- console.log("event", JSON.stringify(event, null, 2))
102
- }
103
- }
104
- }
105
- }, 50000)
106
-
107
- test("Find Routers --> WUSDC --> SUI, no pyth mode", async () => {
108
- // const amounts = ["1000", "1000000", "100000000", "5000000000", "10000000000000"]
109
- // const amounts = ["1000", "1000000", "900000000"]
110
- const amounts = ["90000000"]
111
-
112
- for (const amount of amounts) {
113
- const res = await client.findRouters({
114
- from: T_USDC,
115
- target: T_SUI,
116
- amount: new BN(amount),
117
- byAmountIn: true,
118
- depth: 3,
119
- splitCount: 1,
120
- providers: ["OBRIC"],
121
- })
122
-
123
- if (res != null) {
124
- console.log(JSON.stringify(res, null, 2))
125
- }
126
- console.log("amount in", res?.amountIn.toString())
127
- console.log("amount out", res?.amountOut.toString())
128
-
129
- const txb = new Transaction()
130
-
131
- if (res != null) {
132
- await client.fastRouterSwap({
133
- routers: res,
134
- txb,
135
- slippage: 0.001,
136
- refreshAllCoins: true,
137
- payDeepFeeAmount: 0,
138
- })
139
-
140
- txb.setSender(client.signer)
141
- const buildTxb = await txb.build({ client: client.client })
142
- // const buildTxb = await txb.getData()
143
-
144
- // printTransaction(txb)
145
-
146
- let result = await client.devInspectTransactionBlock(txb)
147
- console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
148
- for (const event of result.events) {
149
- console.log("event", JSON.stringify(event, null, 2))
150
- }
151
- }
152
- }
153
- })
154
-
155
- test("Build Router TX", async () => {
156
- const amount = "1000000"
157
-
158
- const res = await client.findRouters({
159
- from: T_USDC,
160
- target: T_SUI,
161
- amount: new BN(amount),
162
- byAmountIn: true,
163
- depth: 3,
164
- providers: ["OBRIC"],
165
- })
166
-
167
- console.log("amount in", res?.amountIn.toString())
168
- console.log("amount out", res?.amountOut.toString())
169
-
170
- const txb = new Transaction()
171
-
172
- if (res != null) {
173
- console.log(JSON.stringify(res, null, 2))
174
- await client.fastRouterSwap({
175
- routers: res,
176
- txb,
177
- slippage: 0.01,
178
- refreshAllCoins: true,
179
- payDeepFeeAmount: 0,
180
- })
181
-
182
- txb.setSender(client.signer)
183
- const buildTxb = await txb.build({ client: client.client })
184
- // const buildTxb = await txb.getData()
185
-
186
- console.log("buildTxb", buildTxb)
187
- // printTransaction(txb)
188
-
189
- let result = await client.devInspectTransactionBlock(txb)
190
- console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
191
- for (const event of result.events) {
192
- console.log("event", JSON.stringify(event, null, 2))
193
- }
194
-
195
- // if (result.effects.status.status === "success") {
196
- // const result = await client.signAndExecuteTransaction(txb, keypair)
197
- // console.log("result", result)
198
- // } else {
199
- // console.log("result", result)
200
- // }
201
- }
202
- }, 600000)
203
- })