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