@cetusprotocol/aggregator-sdk 0.3.0 → 0.3.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/dist/index.d.mts +46 -4
- package/dist/index.d.ts +46 -4
- package/dist/index.js +156 -25
- package/dist/index.mjs +145 -24
- package/dist/src/api.d.ts +20 -0
- package/dist/src/client.d.ts +10 -3
- package/dist/src/transaction/deepbook_v3.d.ts +12 -0
- package/dist/src/transaction/index.d.ts +1 -1
- package/dist/src/utils/api.d.ts +1 -0
- package/dist/src/utils/index.d.ts +3 -0
- package/dist/tests/test_data.test.d.ts +4 -0
- package/package.json +1 -1
- package/src/api.ts +40 -7
- package/src/client.ts +87 -15
- package/src/transaction/afsui.ts +0 -1
- package/src/transaction/aftermath.ts +0 -2
- package/src/transaction/deepbook_v2.ts +0 -1
- package/src/transaction/deepbook_v3.ts +58 -0
- package/src/transaction/index.ts +2 -1
- package/src/transaction/swap.ts +6 -0
- package/src/transaction/volo.ts +0 -1
- package/src/utils/api.ts +6 -0
- package/src/utils/coin.ts +2 -2
- package/src/utils/index.ts +3 -0
- package/test.json +5 -0
- package/tests/router.test.ts +37 -46
- package/tests/test_data.test.ts +4 -0
package/src/client.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Decimal from "decimal.js"
|
|
2
|
-
import { SuiClient } from "@mysten/sui/client"
|
|
2
|
+
import { getFullnodeUrl, SuiClient } from "@mysten/sui/client"
|
|
3
3
|
import {
|
|
4
4
|
Transaction,
|
|
5
5
|
TransactionObjectArgument,
|
|
@@ -15,6 +15,9 @@ import {
|
|
|
15
15
|
getRouterResult,
|
|
16
16
|
Router,
|
|
17
17
|
RouterData,
|
|
18
|
+
getDeepbookV3Config,
|
|
19
|
+
processEndpoint,
|
|
20
|
+
DeepbookV3Config,
|
|
18
21
|
} from "."
|
|
19
22
|
import { Aftermath } from "./transaction/aftermath"
|
|
20
23
|
import { DeepbookV2 } from "./transaction/deepbook_v2"
|
|
@@ -32,6 +35,7 @@ import { Volo } from "./transaction/volo"
|
|
|
32
35
|
import { Bluemove } from "./transaction/bluemove"
|
|
33
36
|
import { CoinAsset } from "./types/sui"
|
|
34
37
|
import { buildInputCoin } from "./utils/coin"
|
|
38
|
+
import { DeepbookV3 } from "./transaction/deepbook_v3"
|
|
35
39
|
|
|
36
40
|
export const CETUS = "CETUS"
|
|
37
41
|
export const DEEPBOOKV2 = "DEEPBOOK"
|
|
@@ -45,6 +49,9 @@ export const HAEDAL = "HAEDAL"
|
|
|
45
49
|
export const VOLO = "VOLO"
|
|
46
50
|
export const AFSUI = "AFSUI"
|
|
47
51
|
export const BLUEMOVE = "BLUEMOVE"
|
|
52
|
+
export const DEEPBOOKV3 = "DEEPBOOKV3"
|
|
53
|
+
|
|
54
|
+
export const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2"
|
|
48
55
|
|
|
49
56
|
export type BuildRouterSwapParams = {
|
|
50
57
|
routers: Router[]
|
|
@@ -53,6 +60,9 @@ export type BuildRouterSwapParams = {
|
|
|
53
60
|
slippage: number
|
|
54
61
|
txb: Transaction
|
|
55
62
|
partner?: string
|
|
63
|
+
// This parameter is used to pass the Deep token object. When using the DeepBook V3 provider,
|
|
64
|
+
// users must pay fees with Deep tokens in non-whitelisted pools.
|
|
65
|
+
deepbookv3DeepFee?: TransactionObjectArgument
|
|
56
66
|
}
|
|
57
67
|
|
|
58
68
|
export type BuildFastRouterSwapParams = {
|
|
@@ -63,6 +73,7 @@ export type BuildFastRouterSwapParams = {
|
|
|
63
73
|
partner?: string
|
|
64
74
|
isMergeTragetCoin?: boolean
|
|
65
75
|
refreshAllCoins?: boolean
|
|
76
|
+
payDeepFeeAmount?: number
|
|
66
77
|
}
|
|
67
78
|
|
|
68
79
|
export interface SwapInPoolsParams {
|
|
@@ -85,15 +96,19 @@ export class AggregatorClient {
|
|
|
85
96
|
public env: Env
|
|
86
97
|
private allCoins: CoinAsset[]
|
|
87
98
|
|
|
88
|
-
constructor(endpoint
|
|
89
|
-
this.endpoint = endpoint
|
|
90
|
-
this.client = client
|
|
91
|
-
this.signer = signer
|
|
92
|
-
this.env = env
|
|
99
|
+
constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env) {
|
|
100
|
+
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT
|
|
101
|
+
this.client = client || new SuiClient({url: getFullnodeUrl('mainnet')})
|
|
102
|
+
this.signer = signer || ""
|
|
103
|
+
this.env = env || Env.Mainnet
|
|
93
104
|
this.allCoins = []
|
|
94
105
|
}
|
|
95
106
|
|
|
96
107
|
async getAllCoins(): Promise<CoinAsset[]> {
|
|
108
|
+
if (this.signer === "") {
|
|
109
|
+
throw new Error("Signer is required, but not provided.")
|
|
110
|
+
}
|
|
111
|
+
|
|
97
112
|
let cursor = null
|
|
98
113
|
let limit = 50
|
|
99
114
|
const allCoins: CoinAsset[] = []
|
|
@@ -127,7 +142,8 @@ export class AggregatorClient {
|
|
|
127
142
|
inputCoin: TransactionObjectArgument,
|
|
128
143
|
routers: Router[],
|
|
129
144
|
amountOutLimit: BN,
|
|
130
|
-
partner?: string
|
|
145
|
+
partner?: string,
|
|
146
|
+
deepbookv3DeepFee?: TransactionObjectArgument,
|
|
131
147
|
) {
|
|
132
148
|
if (routers.length === 0) {
|
|
133
149
|
throw new Error("No router found")
|
|
@@ -144,7 +160,7 @@ export class AggregatorClient {
|
|
|
144
160
|
let nextCoin = inputCoins[i] as TransactionObjectArgument
|
|
145
161
|
for (const path of routers[i].path) {
|
|
146
162
|
const dex = this.newDex(path.provider, partner)
|
|
147
|
-
nextCoin = await dex.swap(this, txb, path, nextCoin)
|
|
163
|
+
nextCoin = await dex.swap(this, txb, path, nextCoin, deepbookv3DeepFee)
|
|
148
164
|
}
|
|
149
165
|
|
|
150
166
|
outputCoins.push(nextCoin)
|
|
@@ -229,7 +245,7 @@ export class AggregatorClient {
|
|
|
229
245
|
async routerSwap(
|
|
230
246
|
params: BuildRouterSwapParams
|
|
231
247
|
): Promise<TransactionObjectArgument> {
|
|
232
|
-
const { routers, inputCoin, slippage, byAmountIn, txb, partner } = params
|
|
248
|
+
const { routers, inputCoin, slippage, byAmountIn, txb, partner, deepbookv3DeepFee } = params
|
|
233
249
|
const amountIn = routers.reduce(
|
|
234
250
|
(acc, router) => acc.add(router.amountIn),
|
|
235
251
|
new BN(0)
|
|
@@ -250,7 +266,8 @@ export class AggregatorClient {
|
|
|
250
266
|
inputCoin,
|
|
251
267
|
routers,
|
|
252
268
|
new BN(amountLimit),
|
|
253
|
-
partner
|
|
269
|
+
partner,
|
|
270
|
+
deepbookv3DeepFee
|
|
254
271
|
)
|
|
255
272
|
return targetCoin
|
|
256
273
|
}
|
|
@@ -280,6 +297,7 @@ export class AggregatorClient {
|
|
|
280
297
|
partner,
|
|
281
298
|
isMergeTragetCoin,
|
|
282
299
|
refreshAllCoins,
|
|
300
|
+
payDeepFeeAmount,
|
|
283
301
|
} = params
|
|
284
302
|
if (refreshAllCoins || this.allCoins.length === 0) {
|
|
285
303
|
this.allCoins = await this.getAllCoins()
|
|
@@ -306,6 +324,17 @@ export class AggregatorClient {
|
|
|
306
324
|
BigInt(amount.toString()),
|
|
307
325
|
fromCoinType
|
|
308
326
|
)
|
|
327
|
+
|
|
328
|
+
let deepCoin
|
|
329
|
+
if (payDeepFeeAmount && payDeepFeeAmount > 0) {
|
|
330
|
+
deepCoin = buildInputCoin(
|
|
331
|
+
txb,
|
|
332
|
+
this.allCoins,
|
|
333
|
+
BigInt(payDeepFeeAmount),
|
|
334
|
+
this.deepbookv3DeepFeeType()
|
|
335
|
+
).targetCoin
|
|
336
|
+
}
|
|
337
|
+
|
|
309
338
|
const targetCoin = await this.routerSwap({
|
|
310
339
|
routers,
|
|
311
340
|
inputCoin: buildFromCoinRes.targetCoin,
|
|
@@ -313,6 +342,7 @@ export class AggregatorClient {
|
|
|
313
342
|
byAmountIn,
|
|
314
343
|
txb,
|
|
315
344
|
partner,
|
|
345
|
+
deepbookv3DeepFee: deepCoin,
|
|
316
346
|
})
|
|
317
347
|
|
|
318
348
|
if (isMergeTragetCoin) {
|
|
@@ -335,11 +365,29 @@ export class AggregatorClient {
|
|
|
335
365
|
}
|
|
336
366
|
}
|
|
337
367
|
|
|
368
|
+
// Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
|
|
338
369
|
publishedAt(): string {
|
|
339
370
|
if (this.env === Env.Mainnet) {
|
|
340
|
-
return "
|
|
371
|
+
return "0xf98ed029af555e4a103febf26243dc33ac09a7ea1b2da7e414c728b25b729086" // version 3
|
|
372
|
+
} else {
|
|
373
|
+
return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637"
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// Include deepbookv3
|
|
378
|
+
publishedAtV2(): string {
|
|
379
|
+
if (this.env === Env.Mainnet) {
|
|
380
|
+
return "0x43811be4677f5a5de7bf2dac740c10abddfaa524aee6b18e910eeadda8a2f6ae" // version 1
|
|
341
381
|
} else {
|
|
342
|
-
return "
|
|
382
|
+
return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637"
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
deepbookv3DeepFeeType(): string {
|
|
387
|
+
if (this.env === Env.Mainnet) {
|
|
388
|
+
return "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP"
|
|
389
|
+
} else {
|
|
390
|
+
return "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"
|
|
343
391
|
}
|
|
344
392
|
}
|
|
345
393
|
|
|
@@ -372,7 +420,7 @@ export class AggregatorClient {
|
|
|
372
420
|
targetCoin = coins[0]
|
|
373
421
|
}
|
|
374
422
|
|
|
375
|
-
|
|
423
|
+
txb.moveCall({
|
|
376
424
|
target: `${this.publishedAt()}::utils::check_coin_threshold`,
|
|
377
425
|
typeArguments: [coinType],
|
|
378
426
|
arguments: [targetCoin, txb.pure.u64(amountLimit.toString())],
|
|
@@ -386,6 +434,8 @@ export class AggregatorClient {
|
|
|
386
434
|
return new Cetus(this.env, partner)
|
|
387
435
|
case DEEPBOOKV2:
|
|
388
436
|
return new DeepbookV2(this.env)
|
|
437
|
+
case DEEPBOOKV3:
|
|
438
|
+
return new DeepbookV3(this.env)
|
|
389
439
|
case KRIYA:
|
|
390
440
|
return new KriyaV2(this.env)
|
|
391
441
|
case KRIYAV3:
|
|
@@ -441,10 +491,27 @@ export class AggregatorClient {
|
|
|
441
491
|
})
|
|
442
492
|
return res
|
|
443
493
|
}
|
|
494
|
+
|
|
495
|
+
async getDeepbookV3Config(): Promise<DeepbookV3Config | null> {
|
|
496
|
+
const res = await getDeepbookV3Config(this.endpoint)
|
|
497
|
+
if (res) {
|
|
498
|
+
return res.data
|
|
499
|
+
}
|
|
500
|
+
return null
|
|
501
|
+
}
|
|
444
502
|
}
|
|
445
503
|
|
|
446
504
|
export function parseRouterResponse(data: any): RouterData {
|
|
447
|
-
|
|
505
|
+
let totalDeepFee = 0
|
|
506
|
+
for (const route of data.routes) {
|
|
507
|
+
for (const path of route.path) {
|
|
508
|
+
if (path.extended_details && path.extended_details.deepbookv3_deep_fee) {
|
|
509
|
+
totalDeepFee += Number(path.extended_details.deepbookv3_deep_fee)
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
let routerData: RouterData = {
|
|
448
515
|
amountIn: new BN(data.amount_in.toString()),
|
|
449
516
|
amountOut: new BN(data.amount_out.toString()),
|
|
450
517
|
insufficientLiquidity: false,
|
|
@@ -461,13 +528,15 @@ export function parseRouterResponse(data: any): RouterData {
|
|
|
461
528
|
if (
|
|
462
529
|
path.provider === TURBOS ||
|
|
463
530
|
path.provider === AFTERMATH ||
|
|
464
|
-
path.provider === CETUS
|
|
531
|
+
path.provider === CETUS ||
|
|
532
|
+
path.provider === DEEPBOOKV3
|
|
465
533
|
) {
|
|
466
534
|
extendedDetails = {
|
|
467
535
|
aftermathLpSupplyType:
|
|
468
536
|
path.extended_details?.aftermath_lp_supply_type,
|
|
469
537
|
turbosFeeType: path.extended_details?.turbos_fee_type,
|
|
470
538
|
afterSqrtPrice: path.extended_details?.after_sqrt_price,
|
|
539
|
+
deepbookv3DeepFee: path.extended_details?.deepbookv3_deep_fee,
|
|
471
540
|
}
|
|
472
541
|
}
|
|
473
542
|
|
|
@@ -489,5 +558,8 @@ export function parseRouterResponse(data: any): RouterData {
|
|
|
489
558
|
initialPrice: new Decimal(route.initial_price.toString()),
|
|
490
559
|
}
|
|
491
560
|
}),
|
|
561
|
+
totalDeepFee: totalDeepFee,
|
|
492
562
|
}
|
|
563
|
+
|
|
564
|
+
return routerData
|
|
493
565
|
}
|
package/src/transaction/afsui.ts
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Transaction,
|
|
3
|
+
TransactionArgument,
|
|
4
|
+
TransactionObjectArgument,
|
|
5
|
+
} from "@mysten/sui/transactions"
|
|
6
|
+
import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, Path } from ".."
|
|
7
|
+
import { mintZeroCoin } from "~/utils/coin"
|
|
8
|
+
|
|
9
|
+
export type CetusFlashSwapResult = {
|
|
10
|
+
targetCoin: TransactionObjectArgument
|
|
11
|
+
flashReceipt: TransactionObjectArgument
|
|
12
|
+
payAmount: TransactionArgument
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class DeepbookV3 implements Dex {
|
|
16
|
+
private deepbookV3Config: string
|
|
17
|
+
|
|
18
|
+
constructor(env: Env) {
|
|
19
|
+
this.deepbookV3Config =
|
|
20
|
+
env === Env.Mainnet
|
|
21
|
+
? "0xe4099d0cda04f3aa80028fac91a9b3dbe50d08f2ff42aa2c29473926e34ca48c"
|
|
22
|
+
: "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async swap(
|
|
26
|
+
client: AggregatorClient,
|
|
27
|
+
txb: Transaction,
|
|
28
|
+
path: Path,
|
|
29
|
+
inputCoin: TransactionObjectArgument,
|
|
30
|
+
deepbookv3DeepFee?: TransactionObjectArgument
|
|
31
|
+
): Promise<TransactionObjectArgument> {
|
|
32
|
+
const { direction, from, target } = path
|
|
33
|
+
const [func, coinAType, coinBType] = direction
|
|
34
|
+
? ["swap_a2b", from, target]
|
|
35
|
+
: ["swap_b2a", target, from]
|
|
36
|
+
|
|
37
|
+
let deepFee
|
|
38
|
+
if (deepbookv3DeepFee) {
|
|
39
|
+
deepFee = deepbookv3DeepFee
|
|
40
|
+
} else {
|
|
41
|
+
deepFee = mintZeroCoin(txb, client.deepbookv3DeepFeeType())
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const args = [
|
|
45
|
+
txb.object(this.deepbookV3Config),
|
|
46
|
+
txb.object(path.id),
|
|
47
|
+
inputCoin,
|
|
48
|
+
deepFee,
|
|
49
|
+
txb.object(CLOCK_ADDRESS),
|
|
50
|
+
]
|
|
51
|
+
const res = txb.moveCall({
|
|
52
|
+
target: `${client.publishedAtV2()}::deepbookv3::${func}`,
|
|
53
|
+
typeArguments: [coinAType, coinBType],
|
|
54
|
+
arguments: args,
|
|
55
|
+
}) as TransactionArgument
|
|
56
|
+
return res
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/transaction/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export interface Dex {
|
|
|
12
12
|
client: AggregatorClient,
|
|
13
13
|
ptb: Transaction,
|
|
14
14
|
path: Path,
|
|
15
|
-
inputCoin: TransactionObjectArgument
|
|
15
|
+
inputCoin: TransactionObjectArgument,
|
|
16
|
+
deepbookv3DeepFee?: TransactionObjectArgument
|
|
16
17
|
): Promise<TransactionObjectArgument>
|
|
17
18
|
}
|
package/src/transaction/swap.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { checkInvalidSuiAddress } from "~/utils/transaction"
|
|
|
7
7
|
import { SuiClient } from "@mysten/sui/client"
|
|
8
8
|
import { BN } from "bn.js"
|
|
9
9
|
import { sqrtPriceX64ToPrice } from "~/math"
|
|
10
|
+
import { error } from "console"
|
|
10
11
|
|
|
11
12
|
export async function swapInPools(
|
|
12
13
|
client: SuiClient,
|
|
@@ -25,6 +26,10 @@ export async function swapInPools(
|
|
|
25
26
|
const coinB = direction ? targetCoin : fromCoin
|
|
26
27
|
|
|
27
28
|
const typeArguments = [coinA, coinB]
|
|
29
|
+
console.log("typeArguments", typeArguments)
|
|
30
|
+
|
|
31
|
+
console.log("pools", pools)
|
|
32
|
+
|
|
28
33
|
for (let i = 0; i < pools.length; i++) {
|
|
29
34
|
const args = [
|
|
30
35
|
tx.object(pools[i]),
|
|
@@ -51,6 +56,7 @@ export async function swapInPools(
|
|
|
51
56
|
sender,
|
|
52
57
|
})
|
|
53
58
|
if (simulateRes.error != null) {
|
|
59
|
+
console.log("simulateRes.error", simulateRes.error)
|
|
54
60
|
throw new AggregateError(
|
|
55
61
|
"Aggregator package not set",
|
|
56
62
|
ConfigErrorCode.SimulateError
|
package/src/transaction/volo.ts
CHANGED
package/src/utils/api.ts
ADDED
package/src/utils/coin.ts
CHANGED
|
@@ -76,8 +76,8 @@ export function buildInputCoin(
|
|
|
76
76
|
let totalCoinBalance = CoinUtils.calculateTotalBalance(usedCoinAsests)
|
|
77
77
|
if (totalCoinBalance < amount) {
|
|
78
78
|
throw new AggregateError(
|
|
79
|
-
"Insufficient balance when build merge coin",
|
|
80
|
-
TransactionErrorCode.InsufficientBalance
|
|
79
|
+
"Insufficient balance when build merge coin, coinType: " + coinType,
|
|
80
|
+
TransactionErrorCode.InsufficientBalance + coinType
|
|
81
81
|
)
|
|
82
82
|
}
|
|
83
83
|
|
package/src/utils/index.ts
CHANGED
package/test.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
[
|
|
2
|
+
[Path { id: "0x0d1b1746d220bd5ebac5231c7685480a16f1c707a46306095a4c67dc7ce4dcae", edge_id: "0x0d1b1746d220bd5ebac5231c7685480a16f1c707a46306095a4c67dc7ce4dcae", provider: "DEEPBOOKV3", from: "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP", target: "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI", direction: true, fee_rate: Decimal(0), lot_size: 1000000, amount_in: 0, amount_out: 0, max_depth: 3, extended_details: None, allow_bidirection: true
|
|
3
|
+
}
|
|
4
|
+
]
|
|
5
|
+
]
|
package/tests/router.test.ts
CHANGED
|
@@ -4,10 +4,14 @@ import { AggregatorClient } from "~/client"
|
|
|
4
4
|
import {
|
|
5
5
|
M_CETUS,
|
|
6
6
|
M_HASUI,
|
|
7
|
+
M_MICHI,
|
|
7
8
|
M_NAVI,
|
|
8
9
|
M_SSWP,
|
|
9
10
|
M_SUI,
|
|
10
11
|
M_USDC,
|
|
12
|
+
T_DBUSDC,
|
|
13
|
+
T_DBUSDT,
|
|
14
|
+
T_DEEP,
|
|
11
15
|
} from "./test_data.test"
|
|
12
16
|
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
|
|
13
17
|
import { printTransaction } from "~/utils/transaction"
|
|
@@ -44,37 +48,25 @@ describe("router module", () => {
|
|
|
44
48
|
|
|
45
49
|
// console.log("wallet", wallet, "\n", wallet.toString())
|
|
46
50
|
|
|
51
|
+
// const wallet =
|
|
52
|
+
// "0x2a6174f94a2c1d648de290297be27867527a6aaa263a4e0a567c9cd7656d3651"
|
|
47
53
|
const wallet =
|
|
48
54
|
"0xfba94aa36e93ccc7d84a6a57040fc51983223f1b522a8d0be3c3bf2c98977ebb"
|
|
49
55
|
// const wallet =
|
|
50
|
-
// "0xa459702162b73204eed77420d93d9453b7a7b893a0edea1e268607cf7fa76e03"
|
|
51
|
-
// const wallet =
|
|
52
56
|
// "0xaabf2fedcb36146db164bec930b74a47969c4df98216e049342a3c49b6d11580"
|
|
53
57
|
// const wallet = "0x410456cfc689666936b6bf80fbec958b69499b9f7183ecba07de577c17248a44"
|
|
54
58
|
// const wallet = "0xca171941521153181ff729d53489eaae7e99c3f4692884afd7cca61154e4cec4"
|
|
55
59
|
console.log("wallet: ", wallet)
|
|
56
60
|
|
|
57
|
-
const aggregatorPackage = {
|
|
58
|
-
packageName: "aggregator",
|
|
59
|
-
packageId:
|
|
60
|
-
"0x640d44dbdc0ede165c7cc417d7f57f1b09648083109de7132c6b3fb15861f5ee",
|
|
61
|
-
publishedAt:
|
|
62
|
-
"0x640d44dbdc0ede165c7cc417d7f57f1b09648083109de7132c6b3fb15861f5ee",
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const integratePackage = {
|
|
66
|
-
packageName: "integrate",
|
|
67
|
-
packageId:
|
|
68
|
-
"0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",
|
|
69
|
-
publishedAt:
|
|
70
|
-
"0x8faab90228e4c4df91c41626bbaefa19fc25c514405ac64de54578dec9e6f5ee",
|
|
71
|
-
}
|
|
72
61
|
const endpoint =
|
|
73
62
|
"https://api-sui-cloudfront.cetus.zone/router_v2/find_routes"
|
|
63
|
+
// const endpoint =
|
|
64
|
+
// "https://api-sui.devcetus.com/router_v2/find_routes"
|
|
65
|
+
|
|
74
66
|
const suiClient = new SuiClient({
|
|
75
|
-
url: "https://
|
|
67
|
+
url: "https://cetus-mainnet-rpc.blockvision.org:443/2R8NDfQ1v3UAqVAY8PwWQdB4FIb",
|
|
76
68
|
})
|
|
77
|
-
client = new AggregatorClient(endpoint, wallet, suiClient, Env.
|
|
69
|
+
client = new AggregatorClient(endpoint, wallet, suiClient, Env.Testnet)
|
|
78
70
|
})
|
|
79
71
|
|
|
80
72
|
test("Get all coins", () => {
|
|
@@ -84,19 +76,21 @@ describe("router module", () => {
|
|
|
84
76
|
})
|
|
85
77
|
|
|
86
78
|
test("Downgrade swap in route", async () => {
|
|
87
|
-
const amount =
|
|
88
|
-
const byAmountIn =
|
|
79
|
+
const amount = 100000000
|
|
80
|
+
const byAmountIn = true
|
|
89
81
|
|
|
90
82
|
const res: any = await client.swapInPools({
|
|
91
|
-
from:
|
|
92
|
-
target:
|
|
83
|
+
from: "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
|
|
84
|
+
target: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
|
|
93
85
|
amount: new BN(amount),
|
|
94
86
|
byAmountIn,
|
|
95
87
|
pools: [
|
|
96
|
-
|
|
88
|
+
'0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab', '0x03d7739b33fe221a830ff101042fa81fd19188feca04a335f7dea4e37c0fca81', '0xb8d7d9e66a60c239e7a60110efcf8de6c705580ed924d0dde141f4a0e2c90105'
|
|
97
89
|
],
|
|
98
90
|
})
|
|
99
91
|
|
|
92
|
+
console.log("res", res)
|
|
93
|
+
|
|
100
94
|
if (res != null) {
|
|
101
95
|
console.log(JSON.stringify(res, null, 2))
|
|
102
96
|
const txb = new Transaction()
|
|
@@ -112,7 +106,7 @@ describe("router module", () => {
|
|
|
112
106
|
let result = await client.devInspectTransactionBlock(txb)
|
|
113
107
|
console.log("🚀 ~ file: router.test.ts:114 ~ test ~ result:", result)
|
|
114
108
|
}
|
|
115
|
-
},
|
|
109
|
+
}, 60000)
|
|
116
110
|
|
|
117
111
|
test("Find router", async () => {
|
|
118
112
|
const amount = "4239267610000000000"
|
|
@@ -135,15 +129,9 @@ describe("router module", () => {
|
|
|
135
129
|
|
|
136
130
|
test("Build router tx", async () => {
|
|
137
131
|
const byAmountIn = true
|
|
138
|
-
const amount = "
|
|
139
|
-
|
|
140
|
-
const from =
|
|
141
|
-
// const target =
|
|
142
|
-
// "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
143
|
-
// const target =
|
|
144
|
-
// "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"
|
|
145
|
-
|
|
146
|
-
const target = M_USDC
|
|
132
|
+
const amount = "32"
|
|
133
|
+
const target = M_SUI
|
|
134
|
+
const from = M_MICHI
|
|
147
135
|
|
|
148
136
|
const res = await client.findRouters({
|
|
149
137
|
from,
|
|
@@ -152,14 +140,14 @@ describe("router module", () => {
|
|
|
152
140
|
byAmountIn,
|
|
153
141
|
depth: 3,
|
|
154
142
|
providers: [
|
|
155
|
-
|
|
143
|
+
"CETUS",
|
|
144
|
+
// "DEEPBOOKV3",
|
|
156
145
|
// "DEEPBOOK",
|
|
157
146
|
// "AFTERMATH",
|
|
158
147
|
// "FLOWX",
|
|
159
148
|
// "KRIYA",
|
|
160
149
|
// "KRIYAV3",
|
|
161
150
|
// "TURBOS",
|
|
162
|
-
"BLUEMOVE",
|
|
163
151
|
],
|
|
164
152
|
})
|
|
165
153
|
|
|
@@ -181,6 +169,7 @@ describe("router module", () => {
|
|
|
181
169
|
slippage: 0.01,
|
|
182
170
|
isMergeTragetCoin: false,
|
|
183
171
|
refreshAllCoins: true,
|
|
172
|
+
payDeepFeeAmount: 0,
|
|
184
173
|
})
|
|
185
174
|
|
|
186
175
|
printTransaction(txb)
|
|
@@ -188,13 +177,13 @@ describe("router module", () => {
|
|
|
188
177
|
let result = await client.devInspectTransactionBlock(txb)
|
|
189
178
|
console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
|
|
190
179
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
180
|
+
if (result.effects.status.status === "success") {
|
|
181
|
+
// console.log("Sim exec transaction success")
|
|
182
|
+
const result = await client.signAndExecuteTransaction(txb, keypair)
|
|
183
|
+
console.log("result", result)
|
|
184
|
+
} else {
|
|
185
|
+
console.log("result", result)
|
|
186
|
+
}
|
|
198
187
|
}
|
|
199
188
|
}, 600000)
|
|
200
189
|
|
|
@@ -348,9 +337,6 @@ describe("router module", () => {
|
|
|
348
337
|
console.log(JSON.stringify(res, null, 2))
|
|
349
338
|
}
|
|
350
339
|
|
|
351
|
-
console.log("amount in", res?.amountIn.toString())
|
|
352
|
-
console.log("amount out", res?.amountOut.toString())
|
|
353
|
-
|
|
354
340
|
const txb = new Transaction()
|
|
355
341
|
|
|
356
342
|
if (res != null) {
|
|
@@ -378,4 +364,9 @@ describe("router module", () => {
|
|
|
378
364
|
// }
|
|
379
365
|
}
|
|
380
366
|
}, 600000)
|
|
367
|
+
|
|
368
|
+
test("Get deepbook v3 config", async () => {
|
|
369
|
+
const config = await client.getDeepbookV3Config()
|
|
370
|
+
console.log("config", config)
|
|
371
|
+
}, 60000)
|
|
381
372
|
})
|
package/tests/test_data.test.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// Testnet
|
|
2
2
|
export const T_USDC = ""
|
|
3
|
+
export const T_DEEP = "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"
|
|
4
|
+
export const T_DBUSDC = "0xf7152c05930480cd740d7311b5b8b45c6f488e3a53a11c3f74a6fac36a52e0d7::DBUSDC::DBUSDC"
|
|
5
|
+
export const T_DBUSDT = "0xf7152c05930480cd740d7311b5b8b45c6f488e3a53a11c3f74a6fac36a52e0d7::DBUSDT::DBUSDT"
|
|
3
6
|
|
|
4
7
|
// Mainnet
|
|
5
8
|
export const M_USDC =
|
|
@@ -17,3 +20,4 @@ export const M_HASUI =
|
|
|
17
20
|
"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
18
21
|
export const M_SSWP =
|
|
19
22
|
"0x361dd589b98e8fcda9a7ee53b85efabef3569d00416640d2faa516e3801d7ffc::TOKEN::TOKEN"
|
|
23
|
+
export const M_MICHI = "0x50d796fde5709a97883e29e00bf511d66f2656de958ea0c2ce4c1147cdd20a23::MICHI::MICHI"
|