@cetusprotocol/aggregator-sdk 0.3.1 → 0.3.3
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 +45 -4
- package/dist/index.d.ts +45 -4
- package/dist/index.js +128 -30
- package/dist/index.mjs +119 -30
- package/dist/src/api.d.ts +20 -0
- package/dist/src/client.d.ts +9 -3
- package/dist/src/transaction/deepbook_v3.d.ts +1 -2
- 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 +38 -8
- package/src/client.ts +83 -14
- package/src/transaction/afsui.ts +0 -1
- package/src/transaction/aftermath.ts +0 -2
- package/src/transaction/cetus.ts +3 -2
- package/src/transaction/deepbook_v3.ts +13 -11
- 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/tests/router.test.ts +38 -47
- 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"
|
|
@@ -47,6 +50,9 @@ export const VOLO = "VOLO"
|
|
|
47
50
|
export const AFSUI = "AFSUI"
|
|
48
51
|
export const BLUEMOVE = "BLUEMOVE"
|
|
49
52
|
export const DEEPBOOKV3 = "DEEPBOOKV3"
|
|
53
|
+
|
|
54
|
+
export const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2"
|
|
55
|
+
|
|
50
56
|
export type BuildRouterSwapParams = {
|
|
51
57
|
routers: Router[]
|
|
52
58
|
byAmountIn: boolean
|
|
@@ -54,6 +60,9 @@ export type BuildRouterSwapParams = {
|
|
|
54
60
|
slippage: number
|
|
55
61
|
txb: Transaction
|
|
56
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
|
|
57
66
|
}
|
|
58
67
|
|
|
59
68
|
export type BuildFastRouterSwapParams = {
|
|
@@ -64,6 +73,7 @@ export type BuildFastRouterSwapParams = {
|
|
|
64
73
|
partner?: string
|
|
65
74
|
isMergeTragetCoin?: boolean
|
|
66
75
|
refreshAllCoins?: boolean
|
|
76
|
+
payDeepFeeAmount?: number
|
|
67
77
|
}
|
|
68
78
|
|
|
69
79
|
export interface SwapInPoolsParams {
|
|
@@ -86,15 +96,19 @@ export class AggregatorClient {
|
|
|
86
96
|
public env: Env
|
|
87
97
|
private allCoins: CoinAsset[]
|
|
88
98
|
|
|
89
|
-
constructor(endpoint
|
|
90
|
-
this.endpoint = endpoint
|
|
91
|
-
this.client = client
|
|
92
|
-
this.signer = signer
|
|
93
|
-
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
|
|
94
104
|
this.allCoins = []
|
|
95
105
|
}
|
|
96
106
|
|
|
97
107
|
async getAllCoins(): Promise<CoinAsset[]> {
|
|
108
|
+
if (this.signer === "") {
|
|
109
|
+
throw new Error("Signer is required, but not provided.")
|
|
110
|
+
}
|
|
111
|
+
|
|
98
112
|
let cursor = null
|
|
99
113
|
let limit = 50
|
|
100
114
|
const allCoins: CoinAsset[] = []
|
|
@@ -128,7 +142,8 @@ export class AggregatorClient {
|
|
|
128
142
|
inputCoin: TransactionObjectArgument,
|
|
129
143
|
routers: Router[],
|
|
130
144
|
amountOutLimit: BN,
|
|
131
|
-
partner?: string
|
|
145
|
+
partner?: string,
|
|
146
|
+
deepbookv3DeepFee?: TransactionObjectArgument,
|
|
132
147
|
) {
|
|
133
148
|
if (routers.length === 0) {
|
|
134
149
|
throw new Error("No router found")
|
|
@@ -145,7 +160,7 @@ export class AggregatorClient {
|
|
|
145
160
|
let nextCoin = inputCoins[i] as TransactionObjectArgument
|
|
146
161
|
for (const path of routers[i].path) {
|
|
147
162
|
const dex = this.newDex(path.provider, partner)
|
|
148
|
-
nextCoin = await dex.swap(this, txb, path, nextCoin)
|
|
163
|
+
nextCoin = await dex.swap(this, txb, path, nextCoin, deepbookv3DeepFee)
|
|
149
164
|
}
|
|
150
165
|
|
|
151
166
|
outputCoins.push(nextCoin)
|
|
@@ -230,7 +245,7 @@ export class AggregatorClient {
|
|
|
230
245
|
async routerSwap(
|
|
231
246
|
params: BuildRouterSwapParams
|
|
232
247
|
): Promise<TransactionObjectArgument> {
|
|
233
|
-
const { routers, inputCoin, slippage, byAmountIn, txb, partner } = params
|
|
248
|
+
const { routers, inputCoin, slippage, byAmountIn, txb, partner, deepbookv3DeepFee } = params
|
|
234
249
|
const amountIn = routers.reduce(
|
|
235
250
|
(acc, router) => acc.add(router.amountIn),
|
|
236
251
|
new BN(0)
|
|
@@ -251,7 +266,8 @@ export class AggregatorClient {
|
|
|
251
266
|
inputCoin,
|
|
252
267
|
routers,
|
|
253
268
|
new BN(amountLimit),
|
|
254
|
-
partner
|
|
269
|
+
partner,
|
|
270
|
+
deepbookv3DeepFee
|
|
255
271
|
)
|
|
256
272
|
return targetCoin
|
|
257
273
|
}
|
|
@@ -281,6 +297,7 @@ export class AggregatorClient {
|
|
|
281
297
|
partner,
|
|
282
298
|
isMergeTragetCoin,
|
|
283
299
|
refreshAllCoins,
|
|
300
|
+
payDeepFeeAmount,
|
|
284
301
|
} = params
|
|
285
302
|
if (refreshAllCoins || this.allCoins.length === 0) {
|
|
286
303
|
this.allCoins = await this.getAllCoins()
|
|
@@ -307,6 +324,17 @@ export class AggregatorClient {
|
|
|
307
324
|
BigInt(amount.toString()),
|
|
308
325
|
fromCoinType
|
|
309
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
|
+
|
|
310
338
|
const targetCoin = await this.routerSwap({
|
|
311
339
|
routers,
|
|
312
340
|
inputCoin: buildFromCoinRes.targetCoin,
|
|
@@ -314,6 +342,7 @@ export class AggregatorClient {
|
|
|
314
342
|
byAmountIn,
|
|
315
343
|
txb,
|
|
316
344
|
partner,
|
|
345
|
+
deepbookv3DeepFee: deepCoin,
|
|
317
346
|
})
|
|
318
347
|
|
|
319
348
|
if (isMergeTragetCoin) {
|
|
@@ -336,11 +365,29 @@ export class AggregatorClient {
|
|
|
336
365
|
}
|
|
337
366
|
}
|
|
338
367
|
|
|
368
|
+
// Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
|
|
339
369
|
publishedAt(): string {
|
|
340
370
|
if (this.env === Env.Mainnet) {
|
|
341
|
-
return "0xf98ed029af555e4a103febf26243dc33ac09a7ea1b2da7e414c728b25b729086"
|
|
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
|
|
342
381
|
} else {
|
|
343
|
-
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"
|
|
344
391
|
}
|
|
345
392
|
}
|
|
346
393
|
|
|
@@ -444,10 +491,27 @@ export class AggregatorClient {
|
|
|
444
491
|
})
|
|
445
492
|
return res
|
|
446
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
|
+
}
|
|
447
502
|
}
|
|
448
503
|
|
|
449
504
|
export function parseRouterResponse(data: any): RouterData {
|
|
450
|
-
|
|
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 = {
|
|
451
515
|
amountIn: new BN(data.amount_in.toString()),
|
|
452
516
|
amountOut: new BN(data.amount_out.toString()),
|
|
453
517
|
insufficientLiquidity: false,
|
|
@@ -464,13 +528,15 @@ export function parseRouterResponse(data: any): RouterData {
|
|
|
464
528
|
if (
|
|
465
529
|
path.provider === TURBOS ||
|
|
466
530
|
path.provider === AFTERMATH ||
|
|
467
|
-
path.provider === CETUS
|
|
531
|
+
path.provider === CETUS ||
|
|
532
|
+
path.provider === DEEPBOOKV3
|
|
468
533
|
) {
|
|
469
534
|
extendedDetails = {
|
|
470
535
|
aftermathLpSupplyType:
|
|
471
536
|
path.extended_details?.aftermath_lp_supply_type,
|
|
472
537
|
turbosFeeType: path.extended_details?.turbos_fee_type,
|
|
473
538
|
afterSqrtPrice: path.extended_details?.after_sqrt_price,
|
|
539
|
+
deepbookv3DeepFee: path.extended_details?.deepbookv3_deep_fee,
|
|
474
540
|
}
|
|
475
541
|
}
|
|
476
542
|
|
|
@@ -492,5 +558,8 @@ export function parseRouterResponse(data: any): RouterData {
|
|
|
492
558
|
initialPrice: new Decimal(route.initial_price.toString()),
|
|
493
559
|
}
|
|
494
560
|
}),
|
|
561
|
+
totalDeepFee: totalDeepFee,
|
|
495
562
|
}
|
|
563
|
+
|
|
564
|
+
return routerData
|
|
496
565
|
}
|
package/src/transaction/afsui.ts
CHANGED
package/src/transaction/cetus.ts
CHANGED
|
@@ -22,9 +22,10 @@ export class Cetus implements Dex {
|
|
|
22
22
|
: "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a"
|
|
23
23
|
|
|
24
24
|
this.partner =
|
|
25
|
-
partner ??
|
|
25
|
+
partner ??
|
|
26
|
+
(env === Env.Mainnet
|
|
26
27
|
? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b"
|
|
27
|
-
: "0x8e0b7668a79592f70fbfb1ae0aebaf9e2019a7049783b9a4b6fe7c6ae038b528"
|
|
28
|
+
: "0x8e0b7668a79592f70fbfb1ae0aebaf9e2019a7049783b9a4b6fe7c6ae038b528")
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
flash_swap(
|
|
@@ -14,40 +14,42 @@ export type CetusFlashSwapResult = {
|
|
|
14
14
|
|
|
15
15
|
export class DeepbookV3 implements Dex {
|
|
16
16
|
private deepbookV3Config: string
|
|
17
|
-
private deepCoinType: string
|
|
18
17
|
|
|
19
18
|
constructor(env: Env) {
|
|
20
19
|
this.deepbookV3Config =
|
|
21
20
|
env === Env.Mainnet
|
|
22
|
-
? "
|
|
23
|
-
: "
|
|
24
|
-
this.deepCoinType =
|
|
25
|
-
env === Env.Mainnet
|
|
26
|
-
? "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP"
|
|
27
|
-
: "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"
|
|
21
|
+
? "0xe4099d0cda04f3aa80028fac91a9b3dbe50d08f2ff42aa2c29473926e34ca48c"
|
|
22
|
+
: "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa"
|
|
28
23
|
}
|
|
29
24
|
|
|
30
25
|
async swap(
|
|
31
26
|
client: AggregatorClient,
|
|
32
27
|
txb: Transaction,
|
|
33
28
|
path: Path,
|
|
34
|
-
inputCoin: TransactionObjectArgument
|
|
29
|
+
inputCoin: TransactionObjectArgument,
|
|
30
|
+
deepbookv3DeepFee?: TransactionObjectArgument
|
|
35
31
|
): Promise<TransactionObjectArgument> {
|
|
36
32
|
const { direction, from, target } = path
|
|
37
33
|
const [func, coinAType, coinBType] = direction
|
|
38
34
|
? ["swap_a2b", from, target]
|
|
39
35
|
: ["swap_b2a", target, from]
|
|
40
36
|
|
|
41
|
-
|
|
37
|
+
let deepFee
|
|
38
|
+
if (deepbookv3DeepFee) {
|
|
39
|
+
deepFee = deepbookv3DeepFee
|
|
40
|
+
} else {
|
|
41
|
+
deepFee = mintZeroCoin(txb, client.deepbookv3DeepFeeType())
|
|
42
|
+
}
|
|
43
|
+
|
|
42
44
|
const args = [
|
|
43
45
|
txb.object(this.deepbookV3Config),
|
|
44
46
|
txb.object(path.id),
|
|
45
47
|
inputCoin,
|
|
46
|
-
|
|
48
|
+
deepFee,
|
|
47
49
|
txb.object(CLOCK_ADDRESS),
|
|
48
50
|
]
|
|
49
51
|
const res = txb.moveCall({
|
|
50
|
-
target: `${client.
|
|
52
|
+
target: `${client.publishedAtV2()}::deepbookv3::${func}`,
|
|
51
53
|
typeArguments: [coinAType, coinBType],
|
|
52
54
|
arguments: args,
|
|
53
55
|
}) as TransactionArgument
|
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/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
|
|
|
47
|
-
const wallet =
|
|
48
|
-
"0xf7b8d77dd06a6bb51c37ad3ce69e0a44c6f1064f52ac54606ef47763c8a71be6"
|
|
49
51
|
// const wallet =
|
|
50
|
-
|
|
52
|
+
// "0x2a6174f94a2c1d648de290297be27867527a6aaa263a4e0a567c9cd7656d3651"
|
|
53
|
+
const wallet =
|
|
54
|
+
"0xfba94aa36e93ccc7d84a6a57040fc51983223f1b522a8d0be3c3bf2c98977ebb"
|
|
51
55
|
// 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"
|