@cetusprotocol/aggregator-sdk 0.3.16 → 0.3.18
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 +1 -1
- package/dist/index.d.mts +33 -11
- package/dist/index.d.ts +33 -11
- package/dist/index.js +209 -89
- package/dist/index.mjs +204 -89
- package/dist/src/api.d.ts +2 -0
- package/dist/src/client.d.ts +25 -9
- package/dist/src/transaction/afsui.d.ts +1 -1
- package/dist/src/transaction/aftermath.d.ts +1 -1
- package/dist/src/transaction/alphafi.d.ts +7 -0
- package/dist/src/transaction/bluefin.d.ts +1 -1
- package/dist/src/transaction/bluemove.d.ts +1 -1
- package/dist/src/transaction/cetus.d.ts +3 -3
- package/dist/src/transaction/deepbook_v2.d.ts +1 -1
- package/dist/src/transaction/deepbook_v3.d.ts +1 -1
- package/dist/src/transaction/flowx_v2.d.ts +1 -1
- package/dist/src/transaction/flowx_v3.d.ts +1 -1
- package/dist/src/transaction/haedal.d.ts +1 -1
- package/dist/src/transaction/haedal_pmm.d.ts +1 -1
- package/dist/src/transaction/index.d.ts +5 -1
- package/dist/src/transaction/kriya_v2.d.ts +1 -1
- package/dist/src/transaction/kriya_v3.d.ts +1 -1
- package/dist/src/transaction/scallop.d.ts +1 -1
- package/dist/src/transaction/suilend.d.ts +1 -2
- package/dist/src/transaction/turbos.d.ts +1 -1
- package/dist/src/transaction/volo.d.ts +1 -1
- package/package.json +1 -1
- package/src/api.ts +7 -3
- package/src/client.ts +129 -42
- package/src/transaction/afsui.ts +6 -3
- package/src/transaction/aftermath.ts +6 -3
- package/src/transaction/alphafi.ts +50 -0
- package/src/transaction/bluefin.ts +6 -3
- package/src/transaction/bluemove.ts +5 -4
- package/src/transaction/cetus.ts +13 -7
- package/src/transaction/deepbook_v2.ts +5 -4
- package/src/transaction/deepbook_v3.ts +5 -3
- package/src/transaction/flowx_v2.ts +5 -4
- package/src/transaction/flowx_v3.ts +5 -3
- package/src/transaction/haedal.ts +5 -3
- package/src/transaction/haedal_pmm.ts +5 -3
- package/src/transaction/index.ts +20 -1
- package/src/transaction/kriya_v2.ts +5 -4
- package/src/transaction/kriya_v3.ts +5 -4
- package/src/transaction/scallop.ts +5 -4
- package/src/transaction/suilend.ts +6 -10
- package/src/transaction/swap.ts +1 -0
- package/src/transaction/turbos.ts +5 -4
- package/src/transaction/volo.ts +5 -3
- package/src/utils/coin.ts +20 -8
- package/tests/router.test.ts +15 -22
package/src/client.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
getDeepbookV3Config,
|
|
19
19
|
processEndpoint,
|
|
20
20
|
DeepbookV3Config,
|
|
21
|
+
getAggregatorV2PublishedAt,
|
|
21
22
|
} from "."
|
|
22
23
|
import { Aftermath } from "./transaction/aftermath"
|
|
23
24
|
import { DeepbookV2 } from "./transaction/deepbook_v2"
|
|
@@ -40,6 +41,8 @@ import { Scallop } from "./transaction/scallop"
|
|
|
40
41
|
import { Suilend } from "./transaction/suilend"
|
|
41
42
|
import { Bluefin } from "./transaction/bluefin"
|
|
42
43
|
import { HaedalPmm } from "./transaction/haedal_pmm"
|
|
44
|
+
import { Alphafi } from "./transaction/alphafi"
|
|
45
|
+
import { CoinUtils } from "./types/CoinAssist"
|
|
43
46
|
|
|
44
47
|
|
|
45
48
|
export const CETUS = "CETUS"
|
|
@@ -59,6 +62,7 @@ export const SCALLOP = "SCALLOP"
|
|
|
59
62
|
export const SUILEND = "SUILEND"
|
|
60
63
|
export const BLUEFIN = "BLUEFIN"
|
|
61
64
|
export const HAEDALPMM = "HAEDALPMM"
|
|
65
|
+
export const ALPHAFI = "ALPHAFI"
|
|
62
66
|
export const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2"
|
|
63
67
|
|
|
64
68
|
export type BuildRouterSwapParams = {
|
|
@@ -79,7 +83,26 @@ export type BuildFastRouterSwapParams = {
|
|
|
79
83
|
slippage: number
|
|
80
84
|
txb: Transaction
|
|
81
85
|
partner?: string
|
|
82
|
-
|
|
86
|
+
refreshAllCoins?: boolean
|
|
87
|
+
payDeepFeeAmount?: number
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type BuildRouterSwapParamsV2 = {
|
|
91
|
+
routers: RouterData
|
|
92
|
+
inputCoin: TransactionObjectArgument
|
|
93
|
+
slippage: number
|
|
94
|
+
txb: Transaction
|
|
95
|
+
partner?: string
|
|
96
|
+
// This parameter is used to pass the Deep token object. When using the DeepBook V3 provider,
|
|
97
|
+
// users must pay fees with Deep tokens in non-whitelisted pools.
|
|
98
|
+
deepbookv3DeepFee?: TransactionObjectArgument
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type BuildFastRouterSwapParamsV2 = {
|
|
102
|
+
routers: RouterData
|
|
103
|
+
slippage: number
|
|
104
|
+
txb: Transaction
|
|
105
|
+
partner?: string
|
|
83
106
|
refreshAllCoins?: boolean
|
|
84
107
|
payDeepFeeAmount?: number
|
|
85
108
|
}
|
|
@@ -97,6 +120,18 @@ export interface SwapInPoolsResult {
|
|
|
97
120
|
routeData?: RouterData
|
|
98
121
|
}
|
|
99
122
|
|
|
123
|
+
function isBuilderRouterSwapParams(
|
|
124
|
+
params: BuildRouterSwapParams | BuildRouterSwapParamsV2
|
|
125
|
+
): params is BuildRouterSwapParams {
|
|
126
|
+
return Array.isArray((params as BuildRouterSwapParams).routers);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function isBuilderFastRouterSwapParams(
|
|
130
|
+
params: BuildFastRouterSwapParams | BuildFastRouterSwapParamsV2
|
|
131
|
+
): params is BuildFastRouterSwapParams {
|
|
132
|
+
return Array.isArray((params as BuildFastRouterSwapParams).routers);
|
|
133
|
+
}
|
|
134
|
+
|
|
100
135
|
export class AggregatorClient {
|
|
101
136
|
public endpoint: string
|
|
102
137
|
public signer: string
|
|
@@ -170,7 +205,8 @@ export class AggregatorClient {
|
|
|
170
205
|
routers: Router[],
|
|
171
206
|
amountOutLimit: BN,
|
|
172
207
|
partner?: string,
|
|
173
|
-
deepbookv3DeepFee?: TransactionObjectArgument
|
|
208
|
+
deepbookv3DeepFee?: TransactionObjectArgument,
|
|
209
|
+
packages?: Map<string, string>
|
|
174
210
|
) {
|
|
175
211
|
if (routers.length === 0) {
|
|
176
212
|
throw new Error("No router found")
|
|
@@ -187,17 +223,21 @@ export class AggregatorClient {
|
|
|
187
223
|
let nextCoin = inputCoins[i] as TransactionObjectArgument
|
|
188
224
|
for (const path of routers[i].path) {
|
|
189
225
|
const dex = this.newDex(path.provider, partner)
|
|
190
|
-
nextCoin = await dex.swap(this, txb, path, nextCoin, deepbookv3DeepFee)
|
|
226
|
+
nextCoin = await dex.swap(this, txb, path, nextCoin, packages, deepbookv3DeepFee)
|
|
191
227
|
}
|
|
192
228
|
|
|
193
229
|
outputCoins.push(nextCoin)
|
|
194
230
|
}
|
|
195
|
-
|
|
231
|
+
|
|
232
|
+
const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(this.publishedAtV2(), packages)
|
|
233
|
+
|
|
234
|
+
this.transferOrDestoryCoin(txb, inputCoin, inputCoinType, this.publishedAtV2())
|
|
196
235
|
const mergedTargetCointhis = this.checkCoinThresholdAndMergeCoin(
|
|
197
236
|
txb,
|
|
198
237
|
outputCoins,
|
|
199
238
|
outputCoinType,
|
|
200
|
-
amountOutLimit
|
|
239
|
+
amountOutLimit,
|
|
240
|
+
aggregatorV2PublishedAt
|
|
201
241
|
)
|
|
202
242
|
return mergedTargetCointhis
|
|
203
243
|
}
|
|
@@ -206,12 +246,16 @@ export class AggregatorClient {
|
|
|
206
246
|
txb: Transaction,
|
|
207
247
|
inputCoin: TransactionObjectArgument,
|
|
208
248
|
routers: Router[],
|
|
209
|
-
partner?: string
|
|
249
|
+
partner?: string,
|
|
250
|
+
packages?: Map<string, string>
|
|
210
251
|
): Promise<TransactionObjectArgument> {
|
|
211
252
|
const returnCoins: TransactionObjectArgument[] = []
|
|
212
253
|
const receipts: TransactionObjectArgument[] = []
|
|
213
254
|
const targetCoins = []
|
|
214
255
|
const dex = new Cetus(this.env, partner)
|
|
256
|
+
|
|
257
|
+
const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(this.publishedAtV2(), packages)
|
|
258
|
+
|
|
215
259
|
for (let i = 0; i < routers.length; i++) {
|
|
216
260
|
const router = routers[i]
|
|
217
261
|
for (let j = router.path.length - 1; j >= 0; j--) {
|
|
@@ -235,7 +279,7 @@ export class AggregatorClient {
|
|
|
235
279
|
if (j === 0) {
|
|
236
280
|
inputCoin = repayResult
|
|
237
281
|
} else {
|
|
238
|
-
this.transferOrDestoryCoin(txb, repayResult, path.from)
|
|
282
|
+
this.transferOrDestoryCoin(txb, repayResult, path.from, aggregatorV2PublishedAt)
|
|
239
283
|
}
|
|
240
284
|
if (j === router.path.length - 1) {
|
|
241
285
|
targetCoins.push(nextRepayCoin)
|
|
@@ -243,7 +287,7 @@ export class AggregatorClient {
|
|
|
243
287
|
}
|
|
244
288
|
}
|
|
245
289
|
const inputCoinType = routers[0].path[0].from
|
|
246
|
-
this.transferOrDestoryCoin(txb, inputCoin, inputCoinType)
|
|
290
|
+
this.transferOrDestoryCoin(txb, inputCoin, inputCoinType, aggregatorV2PublishedAt)
|
|
247
291
|
if (targetCoins.length > 1) {
|
|
248
292
|
const vec = txb.makeMoveVec({ elements: targetCoins.slice(1) })
|
|
249
293
|
txb.moveCall({
|
|
@@ -270,39 +314,52 @@ export class AggregatorClient {
|
|
|
270
314
|
}
|
|
271
315
|
|
|
272
316
|
async routerSwap(
|
|
273
|
-
params: BuildRouterSwapParams
|
|
317
|
+
params: BuildRouterSwapParams | BuildRouterSwapParamsV2
|
|
274
318
|
): Promise<TransactionObjectArgument> {
|
|
275
319
|
const {
|
|
276
320
|
routers,
|
|
277
321
|
inputCoin,
|
|
278
322
|
slippage,
|
|
279
|
-
byAmountIn,
|
|
280
323
|
txb,
|
|
281
324
|
partner,
|
|
282
325
|
deepbookv3DeepFee,
|
|
283
326
|
} = params
|
|
284
|
-
|
|
327
|
+
|
|
328
|
+
const routerData = Array.isArray(routers) ? routers : routers.routes
|
|
329
|
+
const byAmountIn = isBuilderRouterSwapParams(params)
|
|
330
|
+
? params.byAmountIn
|
|
331
|
+
: params.routers.byAmountIn
|
|
332
|
+
|
|
333
|
+
const amountIn = routerData.reduce(
|
|
285
334
|
(acc, router) => acc.add(router.amountIn),
|
|
286
335
|
new BN(0)
|
|
287
336
|
)
|
|
288
|
-
const amountOut =
|
|
337
|
+
const amountOut = routerData.reduce(
|
|
289
338
|
(acc, router) => acc.add(router.amountOut),
|
|
290
339
|
new BN(0)
|
|
291
340
|
)
|
|
341
|
+
|
|
292
342
|
const amountLimit = CalculateAmountLimitBN(
|
|
293
343
|
byAmountIn ? amountOut : amountIn,
|
|
294
344
|
byAmountIn,
|
|
295
345
|
slippage
|
|
296
346
|
)
|
|
297
347
|
|
|
348
|
+
const packages = isBuilderRouterSwapParams(params) ? undefined : params.routers.packages
|
|
349
|
+
|
|
350
|
+
console.log("packages11", packages)
|
|
351
|
+
|
|
352
|
+
const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(this.publishedAtV2(), packages)
|
|
353
|
+
|
|
298
354
|
if (byAmountIn) {
|
|
299
355
|
const targetCoin = await this.expectInputSwap(
|
|
300
356
|
txb,
|
|
301
357
|
inputCoin,
|
|
302
|
-
|
|
358
|
+
routerData,
|
|
303
359
|
amountLimit,
|
|
304
360
|
partner,
|
|
305
|
-
deepbookv3DeepFee
|
|
361
|
+
deepbookv3DeepFee,
|
|
362
|
+
packages,
|
|
306
363
|
)
|
|
307
364
|
return targetCoin
|
|
308
365
|
}
|
|
@@ -311,11 +368,11 @@ export class AggregatorClient {
|
|
|
311
368
|
const splitedInputCoins = txb.splitCoins(inputCoin, [
|
|
312
369
|
amountLimit.toString(),
|
|
313
370
|
])
|
|
314
|
-
this.transferOrDestoryCoin(txb, inputCoin,
|
|
371
|
+
this.transferOrDestoryCoin(txb, inputCoin, routerData[0].path[0].from, aggregatorV2PublishedAt)
|
|
315
372
|
const targetCoin = await this.expectOutputSwap(
|
|
316
373
|
txb,
|
|
317
374
|
splitedInputCoins[0],
|
|
318
|
-
|
|
375
|
+
routerData,
|
|
319
376
|
partner
|
|
320
377
|
)
|
|
321
378
|
return targetCoin
|
|
@@ -323,31 +380,31 @@ export class AggregatorClient {
|
|
|
323
380
|
|
|
324
381
|
// auto build input coin
|
|
325
382
|
// auto merge, transfer or destory target coin.
|
|
326
|
-
async fastRouterSwap(params: BuildFastRouterSwapParams) {
|
|
383
|
+
async fastRouterSwap(params: BuildFastRouterSwapParams | BuildFastRouterSwapParamsV2) {
|
|
327
384
|
const {
|
|
328
385
|
routers,
|
|
329
|
-
byAmountIn,
|
|
330
386
|
slippage,
|
|
331
387
|
txb,
|
|
332
388
|
partner,
|
|
333
|
-
isMergeTragetCoin,
|
|
334
389
|
refreshAllCoins,
|
|
335
390
|
payDeepFeeAmount,
|
|
336
391
|
} = params
|
|
337
392
|
|
|
338
|
-
const
|
|
339
|
-
|
|
393
|
+
const routerData = Array.isArray(routers) ? routers : routers.routes
|
|
394
|
+
const fromCoinType = routerData[0].path[0].from
|
|
340
395
|
let fromCoins = await this.getCoins(fromCoinType, refreshAllCoins)
|
|
341
396
|
|
|
342
|
-
const targetCoinType =
|
|
343
|
-
const amountIn =
|
|
397
|
+
const targetCoinType = routerData[0].path[routerData[0].path.length - 1].target
|
|
398
|
+
const amountIn = routerData.reduce(
|
|
344
399
|
(acc, router) => acc.add(router.amountIn),
|
|
345
400
|
new BN(0)
|
|
346
401
|
)
|
|
347
|
-
const amountOut =
|
|
402
|
+
const amountOut = routerData.reduce(
|
|
348
403
|
(acc, router) => acc.add(router.amountOut),
|
|
349
404
|
new BN(0)
|
|
350
405
|
)
|
|
406
|
+
|
|
407
|
+
const byAmountIn = isBuilderFastRouterSwapParams(params) ? params.byAmountIn : params.routers.byAmountIn
|
|
351
408
|
const amountLimit = CalculateAmountLimit(
|
|
352
409
|
byAmountIn ? amountOut : amountIn,
|
|
353
410
|
byAmountIn,
|
|
@@ -372,17 +429,29 @@ export class AggregatorClient {
|
|
|
372
429
|
).targetCoin
|
|
373
430
|
}
|
|
374
431
|
|
|
375
|
-
const
|
|
376
|
-
routers,
|
|
432
|
+
const routerSwapParams = isBuilderFastRouterSwapParams(params) ? {
|
|
433
|
+
routers: routerData,
|
|
377
434
|
inputCoin: buildFromCoinRes.targetCoin,
|
|
378
435
|
slippage,
|
|
379
436
|
byAmountIn,
|
|
380
437
|
txb,
|
|
381
438
|
partner,
|
|
382
439
|
deepbookv3DeepFee: deepCoin,
|
|
383
|
-
}
|
|
440
|
+
} : {
|
|
441
|
+
routers: params.routers,
|
|
442
|
+
inputCoin: buildFromCoinRes.targetCoin,
|
|
443
|
+
slippage,
|
|
444
|
+
byAmountIn,
|
|
445
|
+
txb,
|
|
446
|
+
partner,
|
|
447
|
+
deepbookv3DeepFee: deepCoin,
|
|
448
|
+
}
|
|
384
449
|
|
|
385
|
-
|
|
450
|
+
const targetCoin = await this.routerSwap(routerSwapParams)
|
|
451
|
+
|
|
452
|
+
if (CoinUtils.isSuiCoin(targetCoinType)) {
|
|
453
|
+
txb.mergeCoins(txb.gas, [targetCoin])
|
|
454
|
+
} else {
|
|
386
455
|
let targetCoins = await this.getCoins(targetCoinType, refreshAllCoins)
|
|
387
456
|
const targetCoinRes = buildInputCoin(
|
|
388
457
|
txb,
|
|
@@ -390,24 +459,28 @@ export class AggregatorClient {
|
|
|
390
459
|
BigInt(0),
|
|
391
460
|
targetCoinType
|
|
392
461
|
)
|
|
462
|
+
|
|
463
|
+
const packages = isBuilderFastRouterSwapParams(params) ? undefined : params.routers.packages
|
|
464
|
+
const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(this.publishedAtV2(), packages)
|
|
465
|
+
|
|
393
466
|
txb.mergeCoins(targetCoinRes.targetCoin, [targetCoin])
|
|
394
467
|
if (targetCoinRes.isMintZeroCoin) {
|
|
395
468
|
this.transferOrDestoryCoin(
|
|
396
469
|
txb,
|
|
397
470
|
targetCoinRes.targetCoin,
|
|
398
|
-
targetCoinType
|
|
471
|
+
targetCoinType,
|
|
472
|
+
aggregatorV2PublishedAt
|
|
399
473
|
)
|
|
400
474
|
}
|
|
401
|
-
} else {
|
|
402
|
-
this.transferOrDestoryCoin(txb, targetCoin, targetCoinType)
|
|
403
475
|
}
|
|
404
476
|
}
|
|
405
477
|
|
|
406
478
|
// Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
|
|
407
|
-
|
|
479
|
+
publishedAtV2(): string {
|
|
408
480
|
if (this.env === Env.Mainnet) {
|
|
409
481
|
return "0x3fb42ddf908af45f9fc3c59eab227888ff24ba2e137b3b55bf80920fd47e11af" // version 6
|
|
410
|
-
// return "
|
|
482
|
+
// return "0x4069913c4953297b7f08f67f6722e3b04aa5ab2976b4e1b8a456b81590b34ab4"
|
|
483
|
+
// return "0xf182baf7eeefcdaa247cf01dbfcde920133c75a9efa75dfe3703da6a8fc6a70f" // pre
|
|
411
484
|
} else {
|
|
412
485
|
// return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637" // version 2
|
|
413
486
|
return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934"
|
|
@@ -415,15 +488,15 @@ export class AggregatorClient {
|
|
|
415
488
|
}
|
|
416
489
|
|
|
417
490
|
// Include deepbookv3, scallop, bluefin
|
|
418
|
-
|
|
491
|
+
publishedAtV2Extend(): string {
|
|
419
492
|
if (this.env === Env.Mainnet) {
|
|
420
493
|
// return "0x43811be4677f5a5de7bf2dac740c10abddfaa524aee6b18e910eeadda8a2f6ae" // version 1, deepbookv3
|
|
421
494
|
// return "0x6d70ffa7aa3f924c3f0b573d27d29895a0ee666aaff821073f75cb14af7fd01a" // version 3, deepbookv3 & scallop
|
|
422
495
|
// return "0x16d9418726c26d8cb4ce8c9dd75917fa9b1c7bf47d38d7a1a22603135f0f2a56" // version 4, add suilend
|
|
423
496
|
// return "0x3b6d71bdeb8ce5b06febfd3cfc29ecd60d50da729477c8b8038ecdae34541b91" // version 5, add bluefin
|
|
424
497
|
// return "0x81ade554cb24a7564ca43a4bfb7381b08d9e5c5f375162c95215b696ab903502" // version 6, force upgrade scallop
|
|
425
|
-
return "0x347dd58bbd11cd82c8b386b344729717c04a998da73386e82a239cc196d5706b"
|
|
426
|
-
|
|
498
|
+
// return "0x347dd58bbd11cd82c8b386b344729717c04a998da73386e82a239cc196d5706b" // version 7
|
|
499
|
+
return "0xf2fcea41dc217385019828375764fa06d9bd25e8e4726ba1962680849fb8d613" // version 8
|
|
427
500
|
} else {
|
|
428
501
|
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78"
|
|
429
502
|
}
|
|
@@ -440,10 +513,11 @@ export class AggregatorClient {
|
|
|
440
513
|
transferOrDestoryCoin(
|
|
441
514
|
txb: Transaction,
|
|
442
515
|
coin: TransactionObjectArgument,
|
|
443
|
-
coinType: string
|
|
516
|
+
coinType: string,
|
|
517
|
+
aggregatorV2PublishedAt: string
|
|
444
518
|
) {
|
|
445
519
|
txb.moveCall({
|
|
446
|
-
target: `${
|
|
520
|
+
target: `${aggregatorV2PublishedAt}::utils::transfer_or_destroy_coin`,
|
|
447
521
|
typeArguments: [coinType],
|
|
448
522
|
arguments: [coin],
|
|
449
523
|
})
|
|
@@ -453,7 +527,8 @@ export class AggregatorClient {
|
|
|
453
527
|
txb: Transaction,
|
|
454
528
|
coins: TransactionObjectArgument[],
|
|
455
529
|
coinType: string,
|
|
456
|
-
amountLimit: BN
|
|
530
|
+
amountLimit: BN,
|
|
531
|
+
aggregatorV2PublishedAt: string
|
|
457
532
|
) {
|
|
458
533
|
let targetCoin = coins[0]
|
|
459
534
|
if (coins.length > 1) {
|
|
@@ -467,7 +542,7 @@ export class AggregatorClient {
|
|
|
467
542
|
}
|
|
468
543
|
|
|
469
544
|
txb.moveCall({
|
|
470
|
-
target: `${
|
|
545
|
+
target: `${aggregatorV2PublishedAt}::utils::check_coin_threshold`,
|
|
471
546
|
typeArguments: [coinType],
|
|
472
547
|
arguments: [targetCoin, txb.pure.u64(amountLimit.toString())],
|
|
473
548
|
})
|
|
@@ -510,6 +585,8 @@ export class AggregatorClient {
|
|
|
510
585
|
return new Bluefin(this.env)
|
|
511
586
|
case HAEDALPMM:
|
|
512
587
|
return new HaedalPmm(this.env, this.client)
|
|
588
|
+
case ALPHAFI:
|
|
589
|
+
return new Alphafi(this.env)
|
|
513
590
|
default:
|
|
514
591
|
throw new Error(`Unsupported dex ${provider}`)
|
|
515
592
|
}
|
|
@@ -555,7 +632,7 @@ export class AggregatorClient {
|
|
|
555
632
|
}
|
|
556
633
|
}
|
|
557
634
|
|
|
558
|
-
export function parseRouterResponse(data: any): RouterData {
|
|
635
|
+
export function parseRouterResponse(data: any, byAmountIn: boolean): RouterData {
|
|
559
636
|
let totalDeepFee = 0
|
|
560
637
|
for (const route of data.routes) {
|
|
561
638
|
for (const path of route.path) {
|
|
@@ -565,9 +642,18 @@ export function parseRouterResponse(data: any): RouterData {
|
|
|
565
642
|
}
|
|
566
643
|
}
|
|
567
644
|
|
|
645
|
+
let packages = undefined
|
|
646
|
+
if (data.packages != null) {
|
|
647
|
+
packages = new Map<string, string>()
|
|
648
|
+
for (const [key, value] of Object.entries(data.packages)) {
|
|
649
|
+
packages.set(key, value as string)
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
568
653
|
let routerData: RouterData = {
|
|
569
654
|
amountIn: new BN(data.amount_in.toString()),
|
|
570
655
|
amountOut: new BN(data.amount_out.toString()),
|
|
656
|
+
byAmountIn,
|
|
571
657
|
insufficientLiquidity: false,
|
|
572
658
|
routes: data.routes.map((route: any) => {
|
|
573
659
|
return {
|
|
@@ -618,7 +704,8 @@ export function parseRouterResponse(data: any): RouterData {
|
|
|
618
704
|
initialPrice: new Decimal(route.initial_price.toString()),
|
|
619
705
|
}
|
|
620
706
|
}),
|
|
621
|
-
totalDeepFee
|
|
707
|
+
totalDeepFee,
|
|
708
|
+
packages,
|
|
622
709
|
}
|
|
623
710
|
|
|
624
711
|
return routerData
|
package/src/transaction/afsui.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
Transaction,
|
|
3
3
|
TransactionObjectArgument,
|
|
4
4
|
} from "@mysten/sui/transactions"
|
|
5
|
-
import { AggregatorClient, Dex, Env, Path } from ".."
|
|
5
|
+
import { AggregatorClient, Dex, Env, getAggregatorV2PublishedAt, Path } from ".."
|
|
6
6
|
|
|
7
7
|
export class Afsui implements Dex {
|
|
8
8
|
private stakedSuiVault: string
|
|
@@ -29,7 +29,8 @@ export class Afsui implements Dex {
|
|
|
29
29
|
client: AggregatorClient,
|
|
30
30
|
txb: Transaction,
|
|
31
31
|
path: Path,
|
|
32
|
-
inputCoin: TransactionObjectArgument
|
|
32
|
+
inputCoin: TransactionObjectArgument,
|
|
33
|
+
packages?: Map<string, string>
|
|
33
34
|
): Promise<TransactionObjectArgument> {
|
|
34
35
|
const { direction } = path
|
|
35
36
|
|
|
@@ -48,8 +49,10 @@ export class Afsui implements Dex {
|
|
|
48
49
|
inputCoin,
|
|
49
50
|
]
|
|
50
51
|
|
|
52
|
+
const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
|
|
53
|
+
|
|
51
54
|
const res = txb.moveCall({
|
|
52
|
-
target: `${
|
|
55
|
+
target: `${publishedAt}::afsui::${func}`,
|
|
53
56
|
typeArguments: [],
|
|
54
57
|
arguments: args,
|
|
55
58
|
}) as TransactionObjectArgument
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
Transaction,
|
|
3
3
|
TransactionObjectArgument,
|
|
4
4
|
} from "@mysten/sui/transactions"
|
|
5
|
-
import { AggregatorClient, Dex, Env, Path } from ".."
|
|
5
|
+
import { AggregatorClient, Dex, Env, getAggregatorV2PublishedAt, Path } from ".."
|
|
6
6
|
import BN from "bn.js"
|
|
7
7
|
|
|
8
8
|
export class Aftermath implements Dex {
|
|
@@ -42,7 +42,8 @@ export class Aftermath implements Dex {
|
|
|
42
42
|
client: AggregatorClient,
|
|
43
43
|
txb: Transaction,
|
|
44
44
|
path: Path,
|
|
45
|
-
inputCoin: TransactionObjectArgument
|
|
45
|
+
inputCoin: TransactionObjectArgument,
|
|
46
|
+
packages?: Map<string, string>
|
|
46
47
|
): Promise<TransactionObjectArgument> {
|
|
47
48
|
const { direction, from, target } = path
|
|
48
49
|
|
|
@@ -70,8 +71,10 @@ export class Aftermath implements Dex {
|
|
|
70
71
|
inputCoin,
|
|
71
72
|
]
|
|
72
73
|
|
|
74
|
+
const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
|
|
75
|
+
|
|
73
76
|
const res = txb.moveCall({
|
|
74
|
-
target: `${
|
|
77
|
+
target: `${publishedAt}::aftermath::${func}`,
|
|
75
78
|
typeArguments: [
|
|
76
79
|
coinAType,
|
|
77
80
|
coinBType,
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Transaction,
|
|
3
|
+
TransactionObjectArgument,
|
|
4
|
+
} from "@mysten/sui/transactions"
|
|
5
|
+
import { AggregatorClient, Dex, Env, getAggregatorV2ExtendPublishedAt, Path } from ".."
|
|
6
|
+
|
|
7
|
+
export class Alphafi implements Dex {
|
|
8
|
+
private sui_system_state: string
|
|
9
|
+
|
|
10
|
+
constructor(env: Env) {
|
|
11
|
+
if (env !== Env.Mainnet) {
|
|
12
|
+
throw new Error("Alphafi only supported on mainnet")
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
this.sui_system_state =
|
|
16
|
+
env === Env.Mainnet
|
|
17
|
+
? "0x0000000000000000000000000000000000000000000000000000000000000005"
|
|
18
|
+
: "0x0"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async swap(
|
|
22
|
+
client: AggregatorClient,
|
|
23
|
+
txb: Transaction,
|
|
24
|
+
path: Path,
|
|
25
|
+
inputCoin: TransactionObjectArgument,
|
|
26
|
+
packages?: Map<string, string>
|
|
27
|
+
): Promise<TransactionObjectArgument> {
|
|
28
|
+
const { direction, from, target } = path
|
|
29
|
+
|
|
30
|
+
const [func, stCoinType] = direction
|
|
31
|
+
? ["swap_a2b", target]
|
|
32
|
+
: ["swap_b2a", from]
|
|
33
|
+
|
|
34
|
+
const args = [
|
|
35
|
+
txb.object(path.id),
|
|
36
|
+
txb.object(this.sui_system_state),
|
|
37
|
+
inputCoin,
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
const publishedAt = getAggregatorV2ExtendPublishedAt(client.publishedAtV2Extend(), packages)
|
|
41
|
+
|
|
42
|
+
const res = txb.moveCall({
|
|
43
|
+
target: `${publishedAt}::alphafi::${func}`,
|
|
44
|
+
typeArguments: [stCoinType],
|
|
45
|
+
arguments: args,
|
|
46
|
+
}) as TransactionObjectArgument
|
|
47
|
+
|
|
48
|
+
return res
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
TransactionArgument,
|
|
4
4
|
TransactionObjectArgument,
|
|
5
5
|
} from "@mysten/sui/transactions"
|
|
6
|
-
import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, Path } from ".."
|
|
6
|
+
import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, getAggregatorV2ExtendPublishedAt, Path } from ".."
|
|
7
7
|
|
|
8
8
|
export class Bluefin implements Dex {
|
|
9
9
|
private globalConfig: string
|
|
@@ -21,7 +21,8 @@ export class Bluefin implements Dex {
|
|
|
21
21
|
client: AggregatorClient,
|
|
22
22
|
txb: Transaction,
|
|
23
23
|
path: Path,
|
|
24
|
-
inputCoin: TransactionObjectArgument
|
|
24
|
+
inputCoin: TransactionObjectArgument,
|
|
25
|
+
packages?: Map<string, string>
|
|
25
26
|
): Promise<TransactionObjectArgument> {
|
|
26
27
|
const { direction, from, target } = path
|
|
27
28
|
const [func, coinAType, coinBType] = direction
|
|
@@ -33,8 +34,10 @@ export class Bluefin implements Dex {
|
|
|
33
34
|
inputCoin,
|
|
34
35
|
txb.object(CLOCK_ADDRESS),
|
|
35
36
|
]
|
|
37
|
+
const publishedAt = getAggregatorV2ExtendPublishedAt(client.publishedAtV2Extend(), packages)
|
|
38
|
+
|
|
36
39
|
const res = txb.moveCall({
|
|
37
|
-
target: `${
|
|
40
|
+
target: `${publishedAt}::bluefin::${func}`,
|
|
38
41
|
typeArguments: [coinAType, coinBType],
|
|
39
42
|
arguments: args,
|
|
40
43
|
}) as TransactionArgument
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
Transaction,
|
|
3
3
|
TransactionObjectArgument,
|
|
4
4
|
} from "@mysten/sui/transactions"
|
|
5
|
-
import { AggregatorClient, Dex, Env, Path } from ".."
|
|
5
|
+
import { AggregatorClient, Dex, Env, getAggregatorV2PublishedAt, Path } from ".."
|
|
6
6
|
|
|
7
7
|
export class Bluemove implements Dex {
|
|
8
8
|
private dexInfo: string
|
|
@@ -20,7 +20,8 @@ export class Bluemove implements Dex {
|
|
|
20
20
|
client: AggregatorClient,
|
|
21
21
|
txb: Transaction,
|
|
22
22
|
path: Path,
|
|
23
|
-
inputCoin: TransactionObjectArgument
|
|
23
|
+
inputCoin: TransactionObjectArgument,
|
|
24
|
+
packages?: Map<string, string>
|
|
24
25
|
): Promise<TransactionObjectArgument> {
|
|
25
26
|
const { direction, from, target } = path
|
|
26
27
|
|
|
@@ -29,9 +30,9 @@ export class Bluemove implements Dex {
|
|
|
29
30
|
: ["swap_b2a", target, from]
|
|
30
31
|
|
|
31
32
|
const args = [txb.object(this.dexInfo), inputCoin]
|
|
32
|
-
|
|
33
|
+
const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
|
|
33
34
|
const res = txb.moveCall({
|
|
34
|
-
target: `${
|
|
35
|
+
target: `${publishedAt}::bluemove::${func}`,
|
|
35
36
|
typeArguments: [coinAType, coinBType],
|
|
36
37
|
arguments: args,
|
|
37
38
|
}) as TransactionObjectArgument
|
package/src/transaction/cetus.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
TransactionArgument,
|
|
4
4
|
TransactionObjectArgument,
|
|
5
5
|
} from "@mysten/sui/transactions"
|
|
6
|
-
import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, Path } from ".."
|
|
6
|
+
import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, getAggregatorV2PublishedAt, Path } from ".."
|
|
7
7
|
|
|
8
8
|
export type CetusFlashSwapResult = {
|
|
9
9
|
targetCoin: TransactionObjectArgument
|
|
@@ -32,7 +32,8 @@ export class Cetus implements Dex {
|
|
|
32
32
|
client: AggregatorClient,
|
|
33
33
|
txb: Transaction,
|
|
34
34
|
path: Path,
|
|
35
|
-
by_amount_in: boolean
|
|
35
|
+
by_amount_in: boolean,
|
|
36
|
+
packages?: Map<string, string>
|
|
36
37
|
): CetusFlashSwapResult {
|
|
37
38
|
const { direction, from, target } = path
|
|
38
39
|
const [func, coinAType, coinBType] = direction
|
|
@@ -47,8 +48,9 @@ export class Cetus implements Dex {
|
|
|
47
48
|
txb.pure.bool(by_amount_in),
|
|
48
49
|
txb.object(CLOCK_ADDRESS),
|
|
49
50
|
]
|
|
51
|
+
const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
|
|
50
52
|
const res: TransactionObjectArgument[] = txb.moveCall({
|
|
51
|
-
target: `${
|
|
53
|
+
target: `${publishedAt}::cetus::${func}`,
|
|
52
54
|
typeArguments: [coinAType, coinBType],
|
|
53
55
|
arguments: args,
|
|
54
56
|
})
|
|
@@ -64,7 +66,8 @@ export class Cetus implements Dex {
|
|
|
64
66
|
txb: Transaction,
|
|
65
67
|
path: Path,
|
|
66
68
|
inputCoin: TransactionObjectArgument,
|
|
67
|
-
receipt: TransactionArgument
|
|
69
|
+
receipt: TransactionArgument,
|
|
70
|
+
packages?: Map<string, string>
|
|
68
71
|
): TransactionObjectArgument {
|
|
69
72
|
const { direction, from, target } = path
|
|
70
73
|
const [func, coinAType, coinBType] = direction
|
|
@@ -77,8 +80,9 @@ export class Cetus implements Dex {
|
|
|
77
80
|
inputCoin,
|
|
78
81
|
receipt,
|
|
79
82
|
]
|
|
83
|
+
const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
|
|
80
84
|
const res = txb.moveCall({
|
|
81
|
-
target: `${
|
|
85
|
+
target: `${publishedAt}::cetus::${func}`,
|
|
82
86
|
typeArguments: [coinAType, coinBType],
|
|
83
87
|
arguments: args,
|
|
84
88
|
})
|
|
@@ -89,7 +93,8 @@ export class Cetus implements Dex {
|
|
|
89
93
|
client: AggregatorClient,
|
|
90
94
|
txb: Transaction,
|
|
91
95
|
path: Path,
|
|
92
|
-
inputCoin: TransactionObjectArgument
|
|
96
|
+
inputCoin: TransactionObjectArgument,
|
|
97
|
+
packages?: Map<string, string>
|
|
93
98
|
): Promise<TransactionObjectArgument> {
|
|
94
99
|
const { direction, from, target } = path
|
|
95
100
|
const [func, coinAType, coinBType] = direction
|
|
@@ -102,8 +107,9 @@ export class Cetus implements Dex {
|
|
|
102
107
|
inputCoin,
|
|
103
108
|
txb.object(CLOCK_ADDRESS),
|
|
104
109
|
]
|
|
110
|
+
const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
|
|
105
111
|
const res = txb.moveCall({
|
|
106
|
-
target: `${
|
|
112
|
+
target: `${publishedAt}::cetus::${func}`,
|
|
107
113
|
typeArguments: [coinAType, coinBType],
|
|
108
114
|
arguments: args,
|
|
109
115
|
}) as TransactionArgument
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
Transaction,
|
|
3
3
|
TransactionObjectArgument,
|
|
4
4
|
} from "@mysten/sui/transactions"
|
|
5
|
-
import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, Path } from ".."
|
|
5
|
+
import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, getAggregatorV2PublishedAt, Path } from ".."
|
|
6
6
|
import { SuiClient } from "@mysten/sui/client"
|
|
7
7
|
|
|
8
8
|
const DEEPBOOK_PACKAGE_ID =
|
|
@@ -85,7 +85,8 @@ export class DeepbookV2 implements Dex {
|
|
|
85
85
|
client: AggregatorClient,
|
|
86
86
|
txb: Transaction,
|
|
87
87
|
path: Path,
|
|
88
|
-
inputCoin: TransactionObjectArgument
|
|
88
|
+
inputCoin: TransactionObjectArgument,
|
|
89
|
+
packages?: Map<string, string>
|
|
89
90
|
): Promise<TransactionObjectArgument> {
|
|
90
91
|
const { direction, from, target } = path
|
|
91
92
|
|
|
@@ -105,9 +106,9 @@ export class DeepbookV2 implements Dex {
|
|
|
105
106
|
accountCapRes.accountCap,
|
|
106
107
|
txb.object(CLOCK_ADDRESS),
|
|
107
108
|
]
|
|
108
|
-
|
|
109
|
+
const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
|
|
109
110
|
const res = txb.moveCall({
|
|
110
|
-
target: `${
|
|
111
|
+
target: `${publishedAt}::deepbook::${func}`,
|
|
111
112
|
typeArguments: [coinAType, coinBType],
|
|
112
113
|
arguments: args,
|
|
113
114
|
}) as TransactionObjectArgument
|