@cetusprotocol/aggregator-sdk 0.0.0-experimental-20241011180351 → 0.0.0-experimental-20241011205228
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 +3 -39
- package/dist/index.d.ts +3 -39
- package/dist/index.js +19 -148
- package/dist/index.mjs +19 -139
- package/dist/src/api.d.ts +0 -16
- package/dist/src/client.d.ts +2 -7
- package/dist/src/transaction/index.d.ts +1 -1
- package/dist/src/utils/index.d.ts +0 -3
- package/dist/tests/test_data.test.d.ts +0 -3
- package/package.json +1 -1
- package/src/api.ts +7 -33
- package/src/client.ts +11 -78
- package/src/transaction/afsui.ts +1 -0
- package/src/transaction/aftermath.ts +2 -0
- package/src/transaction/deepbook_v2.ts +1 -0
- package/src/transaction/index.ts +1 -2
- package/src/utils/index.ts +0 -3
- package/tests/router.test.ts +27 -29
- package/tests/test_data.test.ts +0 -3
- package/dist/src/transaction/deepbook_v3.d.ts +0 -13
- package/dist/src/utils/api.d.ts +0 -1
- package/src/transaction/deepbook_v3.ts +0 -68
- package/src/utils/api.ts +0 -6
- package/test.json +0 -5
package/src/client.ts
CHANGED
|
@@ -15,11 +15,6 @@ import {
|
|
|
15
15
|
getRouterResult,
|
|
16
16
|
Router,
|
|
17
17
|
RouterData,
|
|
18
|
-
getDeepbookV3Config,
|
|
19
|
-
DeepbookV3ConfigResponse,
|
|
20
|
-
processEndpoint,
|
|
21
|
-
DeepbookV3Config,
|
|
22
|
-
ZERO,
|
|
23
18
|
} from "."
|
|
24
19
|
import { Aftermath } from "./transaction/aftermath"
|
|
25
20
|
import { DeepbookV2 } from "./transaction/deepbook_v2"
|
|
@@ -37,7 +32,6 @@ import { Volo } from "./transaction/volo"
|
|
|
37
32
|
import { Bluemove } from "./transaction/bluemove"
|
|
38
33
|
import { CoinAsset } from "./types/sui"
|
|
39
34
|
import { buildInputCoin } from "./utils/coin"
|
|
40
|
-
import { DeepbookV3 } from "./transaction/deepbook_v3"
|
|
41
35
|
|
|
42
36
|
export const CETUS = "CETUS"
|
|
43
37
|
export const DEEPBOOKV2 = "DEEPBOOK"
|
|
@@ -51,7 +45,6 @@ export const HAEDAL = "HAEDAL"
|
|
|
51
45
|
export const VOLO = "VOLO"
|
|
52
46
|
export const AFSUI = "AFSUI"
|
|
53
47
|
export const BLUEMOVE = "BLUEMOVE"
|
|
54
|
-
export const DEEPBOOKV3 = "DEEPBOOKV3"
|
|
55
48
|
|
|
56
49
|
export type BuildRouterSwapParams = {
|
|
57
50
|
routers: Router[]
|
|
@@ -60,9 +53,6 @@ export type BuildRouterSwapParams = {
|
|
|
60
53
|
slippage: number
|
|
61
54
|
txb: Transaction
|
|
62
55
|
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
|
|
66
56
|
}
|
|
67
57
|
|
|
68
58
|
export type BuildFastRouterSwapParams = {
|
|
@@ -73,7 +63,6 @@ export type BuildFastRouterSwapParams = {
|
|
|
73
63
|
partner?: string
|
|
74
64
|
isMergeTragetCoin?: boolean
|
|
75
65
|
refreshAllCoins?: boolean
|
|
76
|
-
payDeepFeeAmount?: number
|
|
77
66
|
}
|
|
78
67
|
|
|
79
68
|
export interface SwapInPoolsParams {
|
|
@@ -97,7 +86,7 @@ export class AggregatorClient {
|
|
|
97
86
|
private allCoins: CoinAsset[]
|
|
98
87
|
|
|
99
88
|
constructor(endpoint: string, signer: string, client: SuiClient, env: Env) {
|
|
100
|
-
this.endpoint =
|
|
89
|
+
this.endpoint = endpoint
|
|
101
90
|
this.client = client
|
|
102
91
|
this.signer = signer
|
|
103
92
|
this.env = env
|
|
@@ -138,8 +127,7 @@ export class AggregatorClient {
|
|
|
138
127
|
inputCoin: TransactionObjectArgument,
|
|
139
128
|
routers: Router[],
|
|
140
129
|
amountOutLimit: BN,
|
|
141
|
-
partner?: string
|
|
142
|
-
deepbookv3DeepFee?: TransactionObjectArgument,
|
|
130
|
+
partner?: string
|
|
143
131
|
) {
|
|
144
132
|
if (routers.length === 0) {
|
|
145
133
|
throw new Error("No router found")
|
|
@@ -156,15 +144,12 @@ export class AggregatorClient {
|
|
|
156
144
|
let nextCoin = inputCoins[i] as TransactionObjectArgument
|
|
157
145
|
for (const path of routers[i].path) {
|
|
158
146
|
const dex = this.newDex(path.provider, partner)
|
|
159
|
-
nextCoin = await dex.swap(this, txb, path, nextCoin
|
|
147
|
+
nextCoin = await dex.swap(this, txb, path, nextCoin)
|
|
160
148
|
}
|
|
161
149
|
|
|
162
150
|
outputCoins.push(nextCoin)
|
|
163
151
|
}
|
|
164
152
|
this.transferOrDestoryCoin(txb, inputCoin, inputCoinType)
|
|
165
|
-
if (deepbookv3DeepFee) {
|
|
166
|
-
this.transferOrDestoryCoin(txb, deepbookv3DeepFee, this.deepbookv3DeepFeeType())
|
|
167
|
-
}
|
|
168
153
|
const mergedTargetCointhis = this.checkCoinThresholdAndMergeCoin(
|
|
169
154
|
txb,
|
|
170
155
|
outputCoins,
|
|
@@ -244,7 +229,7 @@ export class AggregatorClient {
|
|
|
244
229
|
async routerSwap(
|
|
245
230
|
params: BuildRouterSwapParams
|
|
246
231
|
): Promise<TransactionObjectArgument> {
|
|
247
|
-
const { routers, inputCoin, slippage, byAmountIn, txb, partner
|
|
232
|
+
const { routers, inputCoin, slippage, byAmountIn, txb, partner } = params
|
|
248
233
|
const amountIn = routers.reduce(
|
|
249
234
|
(acc, router) => acc.add(router.amountIn),
|
|
250
235
|
new BN(0)
|
|
@@ -265,8 +250,7 @@ export class AggregatorClient {
|
|
|
265
250
|
inputCoin,
|
|
266
251
|
routers,
|
|
267
252
|
new BN(amountLimit),
|
|
268
|
-
partner
|
|
269
|
-
deepbookv3DeepFee
|
|
253
|
+
partner
|
|
270
254
|
)
|
|
271
255
|
return targetCoin
|
|
272
256
|
}
|
|
@@ -296,7 +280,6 @@ export class AggregatorClient {
|
|
|
296
280
|
partner,
|
|
297
281
|
isMergeTragetCoin,
|
|
298
282
|
refreshAllCoins,
|
|
299
|
-
payDeepFeeAmount,
|
|
300
283
|
} = params
|
|
301
284
|
if (refreshAllCoins || this.allCoins.length === 0) {
|
|
302
285
|
this.allCoins = await this.getAllCoins()
|
|
@@ -323,24 +306,6 @@ export class AggregatorClient {
|
|
|
323
306
|
BigInt(amount.toString()),
|
|
324
307
|
fromCoinType
|
|
325
308
|
)
|
|
326
|
-
|
|
327
|
-
let buildDeepFeeCoinRes
|
|
328
|
-
if (payDeepFeeAmount && payDeepFeeAmount > 0) {
|
|
329
|
-
buildDeepFeeCoinRes = buildInputCoin(
|
|
330
|
-
txb,
|
|
331
|
-
this.allCoins,
|
|
332
|
-
BigInt(payDeepFeeAmount),
|
|
333
|
-
this.deepbookv3DeepFeeType()
|
|
334
|
-
)
|
|
335
|
-
} else {
|
|
336
|
-
buildDeepFeeCoinRes = buildInputCoin(
|
|
337
|
-
txb,
|
|
338
|
-
this.allCoins,
|
|
339
|
-
BigInt(0),
|
|
340
|
-
this.deepbookv3DeepFeeType()
|
|
341
|
-
)
|
|
342
|
-
}
|
|
343
|
-
|
|
344
309
|
const targetCoin = await this.routerSwap({
|
|
345
310
|
routers,
|
|
346
311
|
inputCoin: buildFromCoinRes.targetCoin,
|
|
@@ -348,7 +313,6 @@ export class AggregatorClient {
|
|
|
348
313
|
byAmountIn,
|
|
349
314
|
txb,
|
|
350
315
|
partner,
|
|
351
|
-
deepbookv3DeepFee: buildDeepFeeCoinRes.targetCoin,
|
|
352
316
|
})
|
|
353
317
|
|
|
354
318
|
if (isMergeTragetCoin) {
|
|
@@ -373,17 +337,10 @@ export class AggregatorClient {
|
|
|
373
337
|
|
|
374
338
|
publishedAt(): string {
|
|
375
339
|
if (this.env === Env.Mainnet) {
|
|
376
|
-
return "0x764b8132a94d35abc9dfd91b23a0757b2a717d5ecb04c03098794aa2a508db91"
|
|
340
|
+
// return "0x764b8132a94d35abc9dfd91b23a0757b2a717d5ecb04c03098794aa2a508db91"
|
|
341
|
+
return "0x7eb2f30d541c06fa7bcf26444845df56361647df0e778b82e5707fb26754c398"
|
|
377
342
|
} else {
|
|
378
|
-
return "
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
deepbookv3DeepFeeType(): string {
|
|
383
|
-
if (this.env === Env.Mainnet) {
|
|
384
|
-
return "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"
|
|
385
|
-
} else {
|
|
386
|
-
return "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP"
|
|
343
|
+
return "0x6cbaa3e9fbe902d90191b12f315932bc58079cba422bafbd4b4369f80e61f595"
|
|
387
344
|
}
|
|
388
345
|
}
|
|
389
346
|
|
|
@@ -416,7 +373,7 @@ export class AggregatorClient {
|
|
|
416
373
|
targetCoin = coins[0]
|
|
417
374
|
}
|
|
418
375
|
|
|
419
|
-
txb.moveCall({
|
|
376
|
+
const res = txb.moveCall({
|
|
420
377
|
target: `${this.publishedAt()}::utils::check_coin_threshold`,
|
|
421
378
|
typeArguments: [coinType],
|
|
422
379
|
arguments: [targetCoin, txb.pure.u64(amountLimit.toString())],
|
|
@@ -430,8 +387,6 @@ export class AggregatorClient {
|
|
|
430
387
|
return new Cetus(this.env, partner)
|
|
431
388
|
case DEEPBOOKV2:
|
|
432
389
|
return new DeepbookV2(this.env)
|
|
433
|
-
case DEEPBOOKV3:
|
|
434
|
-
return new DeepbookV3(this.env)
|
|
435
390
|
case KRIYA:
|
|
436
391
|
return new KriyaV2(this.env)
|
|
437
392
|
case KRIYAV3:
|
|
@@ -487,27 +442,10 @@ export class AggregatorClient {
|
|
|
487
442
|
})
|
|
488
443
|
return res
|
|
489
444
|
}
|
|
490
|
-
|
|
491
|
-
async getDeepbookV3Config(): Promise<DeepbookV3Config | null> {
|
|
492
|
-
const res = await getDeepbookV3Config(this.endpoint)
|
|
493
|
-
if (res) {
|
|
494
|
-
return res.data
|
|
495
|
-
}
|
|
496
|
-
return null
|
|
497
|
-
}
|
|
498
445
|
}
|
|
499
446
|
|
|
500
447
|
export function parseRouterResponse(data: any): RouterData {
|
|
501
|
-
|
|
502
|
-
for (const route of data.routes) {
|
|
503
|
-
for (const path of route.path) {
|
|
504
|
-
if (path.extended_details && path.extended_details.deepbookv3_deep_fee) {
|
|
505
|
-
totalDeepFee += Number(path.extended_details.deepbookv3_deep_fee)
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
let routerData: RouterData = {
|
|
448
|
+
return {
|
|
511
449
|
amountIn: new BN(data.amount_in.toString()),
|
|
512
450
|
amountOut: new BN(data.amount_out.toString()),
|
|
513
451
|
insufficientLiquidity: false,
|
|
@@ -524,15 +462,13 @@ export function parseRouterResponse(data: any): RouterData {
|
|
|
524
462
|
if (
|
|
525
463
|
path.provider === TURBOS ||
|
|
526
464
|
path.provider === AFTERMATH ||
|
|
527
|
-
path.provider === CETUS
|
|
528
|
-
path.provider === DEEPBOOKV3
|
|
465
|
+
path.provider === CETUS
|
|
529
466
|
) {
|
|
530
467
|
extendedDetails = {
|
|
531
468
|
aftermathLpSupplyType:
|
|
532
469
|
path.extended_details?.aftermath_lp_supply_type,
|
|
533
470
|
turbosFeeType: path.extended_details?.turbos_fee_type,
|
|
534
471
|
afterSqrtPrice: path.extended_details?.after_sqrt_price,
|
|
535
|
-
deepbookv3DeepFee: path.extended_details?.deepbookv3_deep_fee,
|
|
536
472
|
}
|
|
537
473
|
}
|
|
538
474
|
|
|
@@ -554,8 +490,5 @@ export function parseRouterResponse(data: any): RouterData {
|
|
|
554
490
|
initialPrice: new Decimal(route.initial_price.toString()),
|
|
555
491
|
}
|
|
556
492
|
}),
|
|
557
|
-
totalDeepFee: totalDeepFee,
|
|
558
493
|
}
|
|
559
|
-
|
|
560
|
-
return routerData
|
|
561
494
|
}
|
package/src/transaction/afsui.ts
CHANGED
package/src/transaction/index.ts
CHANGED
|
@@ -12,7 +12,6 @@ export interface Dex {
|
|
|
12
12
|
client: AggregatorClient,
|
|
13
13
|
ptb: Transaction,
|
|
14
14
|
path: Path,
|
|
15
|
-
inputCoin: TransactionObjectArgument
|
|
16
|
-
deepbookv3DeepFee?: TransactionObjectArgument
|
|
15
|
+
inputCoin: TransactionObjectArgument
|
|
17
16
|
): Promise<TransactionObjectArgument>
|
|
18
17
|
}
|
package/src/utils/index.ts
CHANGED
package/tests/router.test.ts
CHANGED
|
@@ -8,9 +8,6 @@ import {
|
|
|
8
8
|
M_SSWP,
|
|
9
9
|
M_SUI,
|
|
10
10
|
M_USDC,
|
|
11
|
-
T_DBUSDC,
|
|
12
|
-
T_DBUSDT,
|
|
13
|
-
T_DEEP,
|
|
14
11
|
} from "./test_data.test"
|
|
15
12
|
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
|
|
16
13
|
import { printTransaction } from "~/utils/transaction"
|
|
@@ -43,12 +40,12 @@ describe("router module", () => {
|
|
|
43
40
|
keypair = buildTestAccount()
|
|
44
41
|
}
|
|
45
42
|
|
|
46
|
-
const wallet = keypair.getPublicKey().toSuiAddress()
|
|
43
|
+
// const wallet = keypair.getPublicKey().toSuiAddress()
|
|
47
44
|
|
|
48
45
|
// console.log("wallet", wallet, "\n", wallet.toString())
|
|
49
46
|
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
const wallet =
|
|
48
|
+
"0xfba94aa36e93ccc7d84a6a57040fc51983223f1b522a8d0be3c3bf2c98977ebb"
|
|
52
49
|
// const wallet =
|
|
53
50
|
// "0xa459702162b73204eed77420d93d9453b7a7b893a0edea1e268607cf7fa76e03"
|
|
54
51
|
// const wallet =
|
|
@@ -72,15 +69,12 @@ describe("router module", () => {
|
|
|
72
69
|
publishedAt:
|
|
73
70
|
"0x8faab90228e4c4df91c41626bbaefa19fc25c514405ac64de54578dec9e6f5ee",
|
|
74
71
|
}
|
|
75
|
-
// const endpoint =
|
|
76
|
-
// "https://api-sui-cloudfront.cetus.zone/router_v2/find_routes"
|
|
77
72
|
const endpoint =
|
|
78
|
-
"https://api-sui.
|
|
79
|
-
|
|
73
|
+
"https://api-sui-cloudfront.cetus.zone/router_v2/find_routes"
|
|
80
74
|
const suiClient = new SuiClient({
|
|
81
|
-
url: "https://fullnode.
|
|
75
|
+
url: "https://fullnode.mainnet.sui.io:443",
|
|
82
76
|
})
|
|
83
|
-
client = new AggregatorClient(endpoint, wallet, suiClient, Env.
|
|
77
|
+
client = new AggregatorClient(endpoint, wallet, suiClient, Env.Mainnet)
|
|
84
78
|
})
|
|
85
79
|
|
|
86
80
|
test("Get all coins", () => {
|
|
@@ -141,9 +135,15 @@ describe("router module", () => {
|
|
|
141
135
|
|
|
142
136
|
test("Build router tx", async () => {
|
|
143
137
|
const byAmountIn = true
|
|
144
|
-
const amount = "
|
|
145
|
-
|
|
146
|
-
const
|
|
138
|
+
const amount = "1000000000"
|
|
139
|
+
|
|
140
|
+
const from = M_SUI
|
|
141
|
+
// const target =
|
|
142
|
+
// "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
143
|
+
// const target =
|
|
144
|
+
// "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"
|
|
145
|
+
|
|
146
|
+
const target = M_USDC
|
|
147
147
|
|
|
148
148
|
const res = await client.findRouters({
|
|
149
149
|
from,
|
|
@@ -152,14 +152,14 @@ describe("router module", () => {
|
|
|
152
152
|
byAmountIn,
|
|
153
153
|
depth: 3,
|
|
154
154
|
providers: [
|
|
155
|
-
"CETUS",
|
|
156
|
-
"DEEPBOOKV3",
|
|
155
|
+
// "CETUS",
|
|
157
156
|
// "DEEPBOOK",
|
|
158
157
|
// "AFTERMATH",
|
|
159
158
|
// "FLOWX",
|
|
160
159
|
// "KRIYA",
|
|
161
160
|
// "KRIYAV3",
|
|
162
161
|
// "TURBOS",
|
|
162
|
+
"BLUEMOVE",
|
|
163
163
|
],
|
|
164
164
|
})
|
|
165
165
|
|
|
@@ -188,13 +188,13 @@ describe("router module", () => {
|
|
|
188
188
|
let result = await client.devInspectTransactionBlock(txb)
|
|
189
189
|
console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
|
|
190
190
|
|
|
191
|
-
if (result.effects.status.status === "success") {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
} else {
|
|
196
|
-
|
|
197
|
-
}
|
|
191
|
+
// if (result.effects.status.status === "success") {
|
|
192
|
+
// console.log("Sim exec transaction success")
|
|
193
|
+
// const result = await client.signAndExecuteTransaction(txb, keypair)
|
|
194
|
+
// // console.log("result", result)
|
|
195
|
+
// } else {
|
|
196
|
+
// console.log("result", result)
|
|
197
|
+
// }
|
|
198
198
|
}
|
|
199
199
|
}, 600000)
|
|
200
200
|
|
|
@@ -348,6 +348,9 @@ describe("router module", () => {
|
|
|
348
348
|
console.log(JSON.stringify(res, null, 2))
|
|
349
349
|
}
|
|
350
350
|
|
|
351
|
+
console.log("amount in", res?.amountIn.toString())
|
|
352
|
+
console.log("amount out", res?.amountOut.toString())
|
|
353
|
+
|
|
351
354
|
const txb = new Transaction()
|
|
352
355
|
|
|
353
356
|
if (res != null) {
|
|
@@ -375,9 +378,4 @@ describe("router module", () => {
|
|
|
375
378
|
// }
|
|
376
379
|
}
|
|
377
380
|
}, 600000)
|
|
378
|
-
|
|
379
|
-
test("Get deepbook v3 config", async () => {
|
|
380
|
-
const config = await client.getDeepbookV3Config()
|
|
381
|
-
console.log("config", config)
|
|
382
|
-
}, 60000)
|
|
383
381
|
})
|
package/tests/test_data.test.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
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"
|
|
6
3
|
|
|
7
4
|
// Mainnet
|
|
8
5
|
export const M_USDC =
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Transaction, TransactionArgument, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
-
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
3
|
-
export type CetusFlashSwapResult = {
|
|
4
|
-
targetCoin: TransactionObjectArgument;
|
|
5
|
-
flashReceipt: TransactionObjectArgument;
|
|
6
|
-
payAmount: TransactionArgument;
|
|
7
|
-
};
|
|
8
|
-
export declare class DeepbookV3 implements Dex {
|
|
9
|
-
private deepbookV3Config;
|
|
10
|
-
private deepCoinType;
|
|
11
|
-
constructor(env: Env);
|
|
12
|
-
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
13
|
-
}
|
package/dist/src/utils/api.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function processEndpoint(endpoint: string): string;
|
|
@@ -1,68 +0,0 @@
|
|
|
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
|
-
private deepCoinType: string
|
|
18
|
-
|
|
19
|
-
constructor(env: Env) {
|
|
20
|
-
this.deepbookV3Config =
|
|
21
|
-
env === Env.Mainnet
|
|
22
|
-
? "0x0"
|
|
23
|
-
: "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa"
|
|
24
|
-
this.deepCoinType =
|
|
25
|
-
env === Env.Mainnet
|
|
26
|
-
? "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP"
|
|
27
|
-
: "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async swap(
|
|
31
|
-
client: AggregatorClient,
|
|
32
|
-
txb: Transaction,
|
|
33
|
-
path: Path,
|
|
34
|
-
inputCoin: TransactionObjectArgument,
|
|
35
|
-
deepbookv3DeepFee?: TransactionObjectArgument
|
|
36
|
-
): Promise<TransactionObjectArgument> {
|
|
37
|
-
const { direction, from, target } = path
|
|
38
|
-
const [func, coinAType, coinBType] = direction
|
|
39
|
-
? ["swap_a2b", from, target]
|
|
40
|
-
: ["swap_b2a", target, from]
|
|
41
|
-
|
|
42
|
-
let deepFee
|
|
43
|
-
if (deepbookv3DeepFee) {
|
|
44
|
-
if (path.extendedDetails?.deepbookv3DeepFee && path.extendedDetails?.deepbookv3DeepFee > 0) {
|
|
45
|
-
const splitAmounts = [path.extendedDetails?.deepbookv3DeepFee]
|
|
46
|
-
deepFee = txb.splitCoins(deepbookv3DeepFee, splitAmounts)[0] as TransactionObjectArgument
|
|
47
|
-
} else {
|
|
48
|
-
deepFee = mintZeroCoin(txb, this.deepCoinType)
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
deepFee = mintZeroCoin(txb, this.deepCoinType)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const args = [
|
|
55
|
-
txb.object(this.deepbookV3Config),
|
|
56
|
-
txb.object(path.id),
|
|
57
|
-
inputCoin,
|
|
58
|
-
deepFee,
|
|
59
|
-
txb.object(CLOCK_ADDRESS),
|
|
60
|
-
]
|
|
61
|
-
const res = txb.moveCall({
|
|
62
|
-
target: `${client.publishedAt()}::deepbookv3::${func}`,
|
|
63
|
-
typeArguments: [coinAType, coinBType],
|
|
64
|
-
arguments: args,
|
|
65
|
-
}) as TransactionArgument
|
|
66
|
-
return res
|
|
67
|
-
}
|
|
68
|
-
}
|
package/src/utils/api.ts
DELETED
package/test.json
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
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
|
-
]
|