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