@cetusprotocol/aggregator-sdk 0.0.0-experimental-20250829185106 → 0.0.0-experimental-20250903180855
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 +7 -52
- package/dist/index.d.ts +7 -52
- package/dist/index.js +49 -276
- package/dist/index.mjs +50 -276
- package/package.json +1 -1
- package/test.json +267 -0
- package/benchmark-results/benchmark-results-2025-07-17T12-03-15-563Z.csv +0 -3
- package/benchmark-results/benchmark-results-2025-07-17T12-03-15-563Z.json +0 -56
- package/benchmark-results/benchmark-results-2025-07-17T12-03-34-148Z.csv +0 -3
- package/benchmark-results/benchmark-results-2025-07-17T12-03-34-148Z.json +0 -56
- package/benchmark-results/benchmark-results-2025-07-21T03-31-59-263Z.csv +0 -21
- package/benchmark-results/benchmark-results-2025-07-21T03-31-59-263Z.json +0 -444
- package/benchmark-results/benchmark-results-2025-07-21T07-54-54-916Z.csv +0 -21
- package/benchmark-results/benchmark-results-2025-07-21T07-54-54-916Z.json +0 -503
- package/benchmark-results/error-report-2025-07-17T12-03-34-148Z.md +0 -18
- package/benchmark-results/error-report-2025-07-21T03-31-59-263Z.md +0 -18
- package/benchmark-results/error-report-2025-07-21T07-54-54-916Z.md +0 -18
- package/benchmark-results/gas-analysis-report-2025-07-17T12-03-15-563Z.md +0 -80
- package/benchmark-results/gas-analysis-report-2025-07-17T12-03-34-148Z.md +0 -80
- package/benchmark-results/gas-analysis-report-2025-07-21T03-31-59-263Z.md +0 -296
- package/benchmark-results/gas-analysis-report-2025-07-21T07-54-54-916Z.md +0 -323
- package/examples/mergeSwapExample.ts +0 -142
package/dist/index.mjs
CHANGED
|
@@ -3334,7 +3334,7 @@ var SuiZeroCoinFn = "0x2::coin::zero";
|
|
|
3334
3334
|
var DEEPBOOK_PACKAGE_ID = "0x000000000000000000000000000000000000000000000000000000000000dee9";
|
|
3335
3335
|
var DEEPBOOK_PUBLISHED_AT = "0x000000000000000000000000000000000000000000000000000000000000dee9";
|
|
3336
3336
|
var CETUS_PUBLISHED_AT = "0x70968826ad1b4ba895753f634b0aea68d0672908ca1075a2abdf0fc9e0b2fc6a";
|
|
3337
|
-
var CETUS_V3_PUBLISHED_AT = "
|
|
3337
|
+
var CETUS_V3_PUBLISHED_AT = "0x73a9bcf98bd1f4602bd4bb76f235b20253a17722cda3438d1710b70c831168af";
|
|
3338
3338
|
var MAINNET_CETUS_GLOBAL_CONFIG_ID = "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f";
|
|
3339
3339
|
var TESTNET_CETUS_GLOBAL_CONFIG_ID = "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
|
|
3340
3340
|
var MAINNET_FLOWX_AMM_CONTAINER_ID = "0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511";
|
|
@@ -3405,7 +3405,8 @@ var CLIENT_CONFIG = {
|
|
|
3405
3405
|
PYTH_UNAVAILABLE: "All Pyth price nodes are unavailable. Cannot fetch price data. Please switch to or add new available Pyth nodes",
|
|
3406
3406
|
QUOTE_ID_REQUIRED: "Quote ID is required",
|
|
3407
3407
|
AGGREGATOR_V3_PACKAGE_REQUIRED: "Aggregator V3 package is required",
|
|
3408
|
-
PACKAGES_REQUIRED: "Packages are required"
|
|
3408
|
+
PACKAGES_REQUIRED: "Packages are required",
|
|
3409
|
+
OVERLAY_FEE_RECEIVER_REQUIRED: "Overlay fee rate is set, but overlay fee receiver is not set"
|
|
3409
3410
|
}
|
|
3410
3411
|
};
|
|
3411
3412
|
var AGGREGATOR_V3_CONFIG = {
|
|
@@ -3414,7 +3415,7 @@ var AGGREGATOR_V3_CONFIG = {
|
|
|
3414
3415
|
// 10%
|
|
3415
3416
|
MAX_AMOUNT_IN: U64_MAX,
|
|
3416
3417
|
DEFAULT_PUBLISHED_AT: {
|
|
3417
|
-
Mainnet: "
|
|
3418
|
+
Mainnet: "0x0422e3239f174320760dd675ba3835cf4b1c511be4a36e819cb61fab7d5d404a",
|
|
3418
3419
|
Testnet: "0x0"
|
|
3419
3420
|
}
|
|
3420
3421
|
};
|
|
@@ -3438,6 +3439,7 @@ function parseRouterResponse(data, byAmountIn) {
|
|
|
3438
3439
|
amountOut: new import_bn2.default(data.amount_out.toString()),
|
|
3439
3440
|
byAmountIn,
|
|
3440
3441
|
insufficientLiquidity: false,
|
|
3442
|
+
deviationRatio: data.deviation_ratio,
|
|
3441
3443
|
packages,
|
|
3442
3444
|
paths: data.paths.map((path) => ({
|
|
3443
3445
|
id: path.id,
|
|
@@ -3454,50 +3456,6 @@ function parseRouterResponse(data, byAmountIn) {
|
|
|
3454
3456
|
}))
|
|
3455
3457
|
};
|
|
3456
3458
|
}
|
|
3457
|
-
function parseMergeSwapResponse(data) {
|
|
3458
|
-
var _a;
|
|
3459
|
-
let packages = /* @__PURE__ */ new Map();
|
|
3460
|
-
if (data.packages) {
|
|
3461
|
-
if (data.packages instanceof Map) {
|
|
3462
|
-
packages = data.packages;
|
|
3463
|
-
} else if (typeof data.packages === "object") {
|
|
3464
|
-
Object.entries(data.packages).forEach(([key, value]) => {
|
|
3465
|
-
packages.set(key, value);
|
|
3466
|
-
});
|
|
3467
|
-
}
|
|
3468
|
-
}
|
|
3469
|
-
const allRoutes = [];
|
|
3470
|
-
if (data.all_routes) {
|
|
3471
|
-
for (const route of data.all_routes) {
|
|
3472
|
-
const mergeRoute = {
|
|
3473
|
-
amountIn: new import_bn2.default(route.amount_in.toString()),
|
|
3474
|
-
amountOut: new import_bn2.default(route.amount_out.toString()),
|
|
3475
|
-
deviationRatio: route.deviation_ratio,
|
|
3476
|
-
paths: route.paths.map((path) => ({
|
|
3477
|
-
id: path.id,
|
|
3478
|
-
direction: path.direction,
|
|
3479
|
-
provider: path.provider,
|
|
3480
|
-
from: path.from,
|
|
3481
|
-
target: path.target,
|
|
3482
|
-
feeRate: path.fee_rate,
|
|
3483
|
-
amountIn: path.amount_in.toString(),
|
|
3484
|
-
amountOut: path.amount_out.toString(),
|
|
3485
|
-
version: path.version,
|
|
3486
|
-
publishedAt: path.published_at,
|
|
3487
|
-
extendedDetails: path.extended_details
|
|
3488
|
-
}))
|
|
3489
|
-
};
|
|
3490
|
-
allRoutes.push(mergeRoute);
|
|
3491
|
-
}
|
|
3492
|
-
}
|
|
3493
|
-
return {
|
|
3494
|
-
quoteID: data.request_id || "",
|
|
3495
|
-
totalAmountOut: new import_bn2.default(((_a = data.total_amount_out) == null ? void 0 : _a.toString()) || "0"),
|
|
3496
|
-
allRoutes,
|
|
3497
|
-
packages,
|
|
3498
|
-
gas: data.gas
|
|
3499
|
-
};
|
|
3500
|
-
}
|
|
3501
3459
|
function getRouterResult(endpoint, apiKey, params, overlayFee, overlayFeeReceiver) {
|
|
3502
3460
|
return __async(this, null, function* () {
|
|
3503
3461
|
let response;
|
|
@@ -3626,7 +3584,6 @@ function getRouter(endpoint, apiKey, params) {
|
|
|
3626
3584
|
url += `&apiKey=${apiKey}`;
|
|
3627
3585
|
}
|
|
3628
3586
|
url += `&v=${SDK_VERSION}`;
|
|
3629
|
-
console.log("url", url);
|
|
3630
3587
|
const response = yield fetch(url);
|
|
3631
3588
|
return response;
|
|
3632
3589
|
} catch (error) {
|
|
@@ -3686,94 +3643,6 @@ function postRouterWithLiquidityChanges(endpoint, params) {
|
|
|
3686
3643
|
}
|
|
3687
3644
|
});
|
|
3688
3645
|
}
|
|
3689
|
-
function getMergeSwapRouter(endpoint, apiKey, params) {
|
|
3690
|
-
return __async(this, null, function* () {
|
|
3691
|
-
try {
|
|
3692
|
-
const { target, byAmountIn, depth, providers, froms } = params;
|
|
3693
|
-
const targetCoin = completionCoin(target);
|
|
3694
|
-
let url = `${endpoint}/multi_find_routes?target=${targetCoin}&by_amount_in=${byAmountIn}`;
|
|
3695
|
-
if (depth) {
|
|
3696
|
-
url += `&depth=${depth}`;
|
|
3697
|
-
}
|
|
3698
|
-
if (providers && providers.length > 0) {
|
|
3699
|
-
url += `&providers=${providers.join(",")}`;
|
|
3700
|
-
}
|
|
3701
|
-
if (apiKey.length > 0) {
|
|
3702
|
-
url += `&apiKey=${apiKey}`;
|
|
3703
|
-
}
|
|
3704
|
-
url += `&v=${SDK_VERSION}`;
|
|
3705
|
-
const fromsData = froms.map((from) => ({
|
|
3706
|
-
coin_type: completionCoin(from.coinType),
|
|
3707
|
-
amount: Number(from.amount.toString())
|
|
3708
|
-
}));
|
|
3709
|
-
url += `&froms=${encodeURIComponent(JSON.stringify(fromsData))}`;
|
|
3710
|
-
const response = yield fetch(url);
|
|
3711
|
-
return response;
|
|
3712
|
-
} catch (error) {
|
|
3713
|
-
console.error(error);
|
|
3714
|
-
return null;
|
|
3715
|
-
}
|
|
3716
|
-
});
|
|
3717
|
-
}
|
|
3718
|
-
function getMergeSwapResult(endpoint, apiKey, params, overlayFee, overlayFeeReceiver) {
|
|
3719
|
-
return __async(this, null, function* () {
|
|
3720
|
-
const response = yield getMergeSwapRouter(endpoint, apiKey, params);
|
|
3721
|
-
if (!response) {
|
|
3722
|
-
return null;
|
|
3723
|
-
}
|
|
3724
|
-
if (!response.ok) {
|
|
3725
|
-
let errorCode = 1e3 /* NumberTooLarge */;
|
|
3726
|
-
if (response.status === 429) {
|
|
3727
|
-
errorCode = 1001 /* RateLimitExceeded */;
|
|
3728
|
-
}
|
|
3729
|
-
return {
|
|
3730
|
-
quoteID: "",
|
|
3731
|
-
totalAmountOut: ZERO,
|
|
3732
|
-
allRoutes: [],
|
|
3733
|
-
error: {
|
|
3734
|
-
code: errorCode,
|
|
3735
|
-
msg: getAggregatorServerErrorMessage(errorCode)
|
|
3736
|
-
}
|
|
3737
|
-
};
|
|
3738
|
-
}
|
|
3739
|
-
const responseText = yield response.text();
|
|
3740
|
-
const data = JSONbig.parse(responseText);
|
|
3741
|
-
data.msg === "liquidity is not enough";
|
|
3742
|
-
if (data.msg && data.msg.indexOf("HoneyPot scam") > -1) {
|
|
3743
|
-
return {
|
|
3744
|
-
quoteID: "",
|
|
3745
|
-
totalAmountOut: ZERO,
|
|
3746
|
-
allRoutes: [],
|
|
3747
|
-
error: {
|
|
3748
|
-
code: 1003 /* HoneyPot */,
|
|
3749
|
-
msg: getAggregatorServerErrorMessage(
|
|
3750
|
-
1003 /* HoneyPot */
|
|
3751
|
-
)
|
|
3752
|
-
}
|
|
3753
|
-
};
|
|
3754
|
-
}
|
|
3755
|
-
if (data.data != null) {
|
|
3756
|
-
const res = parseMergeSwapResponse(data.data);
|
|
3757
|
-
if (overlayFee > 0 && overlayFeeReceiver !== "0x0" && params.byAmountIn) {
|
|
3758
|
-
const overlayFeeAmount = res.totalAmountOut.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3759
|
-
res.totalAmountOut = res.totalAmountOut.sub(overlayFeeAmount);
|
|
3760
|
-
for (const route of res.allRoutes) {
|
|
3761
|
-
const routeFee = route.amountOut.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3762
|
-
route.amountOut = route.amountOut.sub(routeFee);
|
|
3763
|
-
}
|
|
3764
|
-
}
|
|
3765
|
-
if (!res.packages) {
|
|
3766
|
-
res.packages = /* @__PURE__ */ new Map();
|
|
3767
|
-
}
|
|
3768
|
-
return res;
|
|
3769
|
-
}
|
|
3770
|
-
return {
|
|
3771
|
-
quoteID: "",
|
|
3772
|
-
totalAmountOut: ZERO,
|
|
3773
|
-
allRoutes: []
|
|
3774
|
-
};
|
|
3775
|
-
});
|
|
3776
|
-
}
|
|
3777
3646
|
function getDeepbookV3Config(endpoint) {
|
|
3778
3647
|
return __async(this, null, function* () {
|
|
3779
3648
|
const url = `${endpoint}/deepbookv3_config`;
|
|
@@ -3805,7 +3674,6 @@ function processFlattenRoutes(routerData) {
|
|
|
3805
3674
|
flattenedPaths[i].isLastUseOfIntermediateToken = true;
|
|
3806
3675
|
}
|
|
3807
3676
|
}
|
|
3808
|
-
console.log("flattenedPaths", flattenedPaths);
|
|
3809
3677
|
return {
|
|
3810
3678
|
quoteID: routerData.quoteID || "",
|
|
3811
3679
|
amountIn: routerData.amountIn,
|
|
@@ -8392,6 +8260,11 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8392
8260
|
return DEEPBOOK_V3_DEEP_FEE_TYPES.Testnet;
|
|
8393
8261
|
}
|
|
8394
8262
|
}
|
|
8263
|
+
getDeepbookV3Config() {
|
|
8264
|
+
return __async(this, null, function* () {
|
|
8265
|
+
return yield getDeepbookV3Config(this.endpoint);
|
|
8266
|
+
});
|
|
8267
|
+
}
|
|
8395
8268
|
getOneCoinUsedToMerge(coinType) {
|
|
8396
8269
|
return __async(this, null, function* () {
|
|
8397
8270
|
try {
|
|
@@ -8420,17 +8293,6 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8420
8293
|
);
|
|
8421
8294
|
});
|
|
8422
8295
|
}
|
|
8423
|
-
findMergeSwapRouters(params) {
|
|
8424
|
-
return __async(this, null, function* () {
|
|
8425
|
-
return getMergeSwapResult(
|
|
8426
|
-
this.endpoint,
|
|
8427
|
-
this.apiKey,
|
|
8428
|
-
params,
|
|
8429
|
-
this.overlayFeeRate,
|
|
8430
|
-
this.overlayFeeReceiver
|
|
8431
|
-
);
|
|
8432
|
-
});
|
|
8433
|
-
}
|
|
8434
8296
|
executeFlexibleInputSwap(txb, inputCoin, routerData, expectedAmountOut, amountLimit, pythPriceIDs, partner, deepbookv3DeepFee, packages) {
|
|
8435
8297
|
return __async(this, null, function* () {
|
|
8436
8298
|
});
|
|
@@ -8653,20 +8515,22 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8653
8515
|
}
|
|
8654
8516
|
routerSwap(params) {
|
|
8655
8517
|
return __async(this, null, function* () {
|
|
8656
|
-
const { router, inputCoin, slippage, txb,
|
|
8518
|
+
const { router, inputCoin, slippage, txb, partner } = params;
|
|
8657
8519
|
if (slippage > 1 || slippage < 0) {
|
|
8658
8520
|
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
|
|
8659
8521
|
}
|
|
8522
|
+
if (!params.router.packages || !params.router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
8523
|
+
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
8524
|
+
}
|
|
8660
8525
|
const byAmountIn = params.router.byAmountIn;
|
|
8661
8526
|
const amountIn = router.amountIn;
|
|
8662
8527
|
const amountOut = router.amountOut;
|
|
8528
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
8663
8529
|
let overlayFee = new import_bn6.default(0);
|
|
8664
|
-
if (
|
|
8665
|
-
|
|
8666
|
-
|
|
8667
|
-
|
|
8668
|
-
overlayFee = amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
8669
|
-
}
|
|
8530
|
+
if (byAmountIn) {
|
|
8531
|
+
overlayFee = amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
8532
|
+
} else {
|
|
8533
|
+
overlayFee = amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
8670
8534
|
}
|
|
8671
8535
|
const expectedAmountOut = byAmountIn ? amountOut.sub(overlayFee) : amountOut;
|
|
8672
8536
|
const expectedAmountIn = byAmountIn ? amountIn : amountIn.add(overlayFee);
|
|
@@ -8675,9 +8539,6 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8675
8539
|
byAmountIn,
|
|
8676
8540
|
slippage
|
|
8677
8541
|
);
|
|
8678
|
-
if (!params.router.packages || !params.router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
8679
|
-
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
8680
|
-
}
|
|
8681
8542
|
const priceIDs = findPythPriceIDs(router.paths);
|
|
8682
8543
|
const priceInfoObjectIds = priceIDs.length > 0 ? yield this.updatePythPriceIDs(priceIDs, txb) : /* @__PURE__ */ new Map();
|
|
8683
8544
|
if (byAmountIn) {
|
|
@@ -8710,17 +8571,16 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8710
8571
|
const fromCoinType = router.paths[0].from;
|
|
8711
8572
|
const targetCoinType = router.paths[router.paths.length - 1].target;
|
|
8712
8573
|
const byAmountIn = router.byAmountIn;
|
|
8574
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
8713
8575
|
let overlayFee = 0;
|
|
8714
|
-
if (
|
|
8715
|
-
|
|
8716
|
-
|
|
8717
|
-
|
|
8718
|
-
|
|
8719
|
-
|
|
8720
|
-
|
|
8721
|
-
|
|
8722
|
-
);
|
|
8723
|
-
}
|
|
8576
|
+
if (byAmountIn) {
|
|
8577
|
+
overlayFee = Number(
|
|
8578
|
+
router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
8579
|
+
);
|
|
8580
|
+
} else {
|
|
8581
|
+
overlayFee = Number(
|
|
8582
|
+
router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
8583
|
+
);
|
|
8724
8584
|
}
|
|
8725
8585
|
const expectedAmountOut = byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
|
|
8726
8586
|
const expectedAmountIn = byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
|
|
@@ -8770,116 +8630,19 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8770
8630
|
}
|
|
8771
8631
|
});
|
|
8772
8632
|
}
|
|
8773
|
-
mergeSwap(params) {
|
|
8774
|
-
return __async(this, null, function* () {
|
|
8775
|
-
const { router, inputCoins, slippage, txb, partner } = params;
|
|
8776
|
-
if (slippage > 1 || slippage < 0) {
|
|
8777
|
-
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
|
|
8778
|
-
}
|
|
8779
|
-
if (!router.packages || !router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
8780
|
-
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
8781
|
-
}
|
|
8782
|
-
if (!router.allRoutes || router.allRoutes.length === 0) {
|
|
8783
|
-
throw new Error("No routes found in merge swap response");
|
|
8784
|
-
}
|
|
8785
|
-
const outputCoins = [];
|
|
8786
|
-
for (let i = 0; i < router.allRoutes.length && i < inputCoins.length; i++) {
|
|
8787
|
-
const route = router.allRoutes[i];
|
|
8788
|
-
const inputCoin = inputCoins[i];
|
|
8789
|
-
const routeRouter = {
|
|
8790
|
-
quoteID: router.quoteID,
|
|
8791
|
-
amountIn: route.amountIn,
|
|
8792
|
-
amountOut: route.amountOut,
|
|
8793
|
-
byAmountIn: true,
|
|
8794
|
-
// Merge swap is always by amount in
|
|
8795
|
-
paths: route.paths,
|
|
8796
|
-
insufficientLiquidity: false,
|
|
8797
|
-
packages: router.packages
|
|
8798
|
-
};
|
|
8799
|
-
const routerParams = {
|
|
8800
|
-
router: routeRouter,
|
|
8801
|
-
inputCoin: inputCoin.coin,
|
|
8802
|
-
slippage,
|
|
8803
|
-
txb,
|
|
8804
|
-
partner: partner != null ? partner : this.partner
|
|
8805
|
-
};
|
|
8806
|
-
const outputCoin = yield this.routerSwap(routerParams);
|
|
8807
|
-
outputCoins.push(outputCoin);
|
|
8808
|
-
}
|
|
8809
|
-
if (outputCoins.length === 0) {
|
|
8810
|
-
throw new Error("No output coins generated from merge swap");
|
|
8811
|
-
}
|
|
8812
|
-
let finalOutputCoin = outputCoins[0];
|
|
8813
|
-
if (outputCoins.length > 1) {
|
|
8814
|
-
txb.mergeCoins(finalOutputCoin, outputCoins.slice(1));
|
|
8815
|
-
}
|
|
8816
|
-
return finalOutputCoin;
|
|
8817
|
-
});
|
|
8818
|
-
}
|
|
8819
|
-
fastMergeSwap(params) {
|
|
8820
|
-
return __async(this, null, function* () {
|
|
8821
|
-
const { router, slippage, txb, partner } = params;
|
|
8822
|
-
if (!router || !router.allRoutes || router.allRoutes.length === 0) {
|
|
8823
|
-
throw new Error("Invalid router: no routes found");
|
|
8824
|
-
}
|
|
8825
|
-
const firstRoute = router.allRoutes[0];
|
|
8826
|
-
const targetCoinType = firstRoute.paths[firstRoute.paths.length - 1].target;
|
|
8827
|
-
const inputCoins = [];
|
|
8828
|
-
const coinTypeSet = /* @__PURE__ */ new Set();
|
|
8829
|
-
for (const route of router.allRoutes) {
|
|
8830
|
-
const firstCoinType = route.paths[0].from;
|
|
8831
|
-
if (coinTypeSet.has(firstCoinType)) {
|
|
8832
|
-
continue;
|
|
8833
|
-
}
|
|
8834
|
-
coinTypeSet.add(firstCoinType);
|
|
8835
|
-
const coin = coinWithBalance({
|
|
8836
|
-
balance: BigInt(route.amountIn.toString()),
|
|
8837
|
-
useGasCoin: CoinUtils.isSuiCoin(firstCoinType),
|
|
8838
|
-
type: firstCoinType
|
|
8839
|
-
});
|
|
8840
|
-
inputCoins.push({ coinType: firstCoinType, coin });
|
|
8841
|
-
}
|
|
8842
|
-
const mergeSwapParams = {
|
|
8843
|
-
router,
|
|
8844
|
-
inputCoins,
|
|
8845
|
-
slippage,
|
|
8846
|
-
txb,
|
|
8847
|
-
partner: partner != null ? partner : this.partner
|
|
8848
|
-
};
|
|
8849
|
-
const targetCoin = yield this.mergeSwap(mergeSwapParams);
|
|
8850
|
-
if (CoinUtils.isSuiCoin(targetCoinType)) {
|
|
8851
|
-
txb.mergeCoins(txb.gas, [targetCoin]);
|
|
8852
|
-
} else {
|
|
8853
|
-
const targetCoinObjID = yield this.getOneCoinUsedToMerge(targetCoinType);
|
|
8854
|
-
if (targetCoinObjID != null) {
|
|
8855
|
-
txb.mergeCoins(txb.object(targetCoinObjID), [targetCoin]);
|
|
8856
|
-
} else {
|
|
8857
|
-
transferOrDestroyCoin(
|
|
8858
|
-
{
|
|
8859
|
-
coin: targetCoin,
|
|
8860
|
-
coinType: targetCoinType,
|
|
8861
|
-
packages: router.packages
|
|
8862
|
-
},
|
|
8863
|
-
txb
|
|
8864
|
-
);
|
|
8865
|
-
}
|
|
8866
|
-
}
|
|
8867
|
-
});
|
|
8868
|
-
}
|
|
8869
8633
|
fixableRouterSwapV3(params) {
|
|
8870
8634
|
return __async(this, null, function* () {
|
|
8871
|
-
const { router, inputCoin, slippage, txb,
|
|
8635
|
+
const { router, inputCoin, slippage, txb, partner } = params;
|
|
8636
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
8872
8637
|
let overlayFee = 0;
|
|
8873
|
-
if (
|
|
8874
|
-
|
|
8875
|
-
|
|
8876
|
-
|
|
8877
|
-
|
|
8878
|
-
|
|
8879
|
-
|
|
8880
|
-
|
|
8881
|
-
);
|
|
8882
|
-
}
|
|
8638
|
+
if (router.byAmountIn) {
|
|
8639
|
+
overlayFee = Number(
|
|
8640
|
+
router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
8641
|
+
);
|
|
8642
|
+
} else {
|
|
8643
|
+
overlayFee = Number(
|
|
8644
|
+
router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
8645
|
+
);
|
|
8883
8646
|
}
|
|
8884
8647
|
const expectedAmountOut = router.byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
|
|
8885
8648
|
const expectedAmountIn = router.byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
|
|
@@ -8988,6 +8751,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8988
8751
|
const routeData = {
|
|
8989
8752
|
amountIn,
|
|
8990
8753
|
amountOut: new import_bn6.default((_d = event.amount_out) != null ? _d : 0),
|
|
8754
|
+
deviationRatio: 0,
|
|
8991
8755
|
paths: [
|
|
8992
8756
|
{
|
|
8993
8757
|
id: pools[tempIndex],
|
|
@@ -9105,6 +8869,16 @@ function recordFirstCoinIndex(paths) {
|
|
|
9105
8869
|
}
|
|
9106
8870
|
return newCoinRecord;
|
|
9107
8871
|
}
|
|
8872
|
+
function checkOverlayFeeConfig(overlayFeeRate, overlayFeeReceiver) {
|
|
8873
|
+
if (overlayFeeRate > CLIENT_CONFIG.MAX_OVERLAY_FEE_RATE) {
|
|
8874
|
+
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_OVERLAY_FEE_RATE);
|
|
8875
|
+
}
|
|
8876
|
+
if (overlayFeeReceiver === "0x0" && overlayFeeRate > 0) {
|
|
8877
|
+
throw new Error(
|
|
8878
|
+
CLIENT_CONFIG.ERRORS.OVERLAY_FEE_RECEIVER_REQUIRED
|
|
8879
|
+
);
|
|
8880
|
+
}
|
|
8881
|
+
}
|
|
9108
8882
|
|
|
9109
8883
|
// src/types/sui.ts
|
|
9110
8884
|
var getDefaultSuiInputType = (value) => {
|
|
@@ -9131,4 +8905,4 @@ decimal.js/decimal.mjs:
|
|
|
9131
8905
|
*)
|
|
9132
8906
|
*/
|
|
9133
8907
|
|
|
9134
|
-
export { AFSUI, AFTERMATH, AFTERMATH_AMM, AFTERMATH_MODULE, AGGREGATOR, AGGREGATOR_V3_CONFIG, ALL_DEXES, ALPHAFI, AggregatorClient, AggregatorConfig, AggregatorError, AggregatorServerErrorCode, BLUEFIN, BLUEMOVE, CETUS, CETUS_DEX, CETUS_MODULE, CETUS_PUBLISHED_AT, CETUS_V3_PUBLISHED_AT, CHECK_COINS_THRESHOLD_FUNC, CLIENT_CONFIG, CLOCK_ADDRESS, CoinInfoAddress, CoinStoreAddress, CoinUtils, ConfigErrorCode, DEEPBOOKV2, DEEPBOOKV3, DEEPBOOK_CLOB_V2_MODULE, DEEPBOOK_CUSTODIAN_V2_MODULE, DEEPBOOK_DEX, DEEPBOOK_MODULE, DEEPBOOK_PACKAGE_ID, DEEPBOOK_PUBLISHED_AT, DEEPBOOK_V3_DEEP_FEE_TYPES, DEFAULT_AGG_V2_ENDPOINT, DEFAULT_AGG_V3_ENDPOINT, DEFAULT_ENDPOINT, DEFAULT_GAS_BUDGET_FOR_MERGE, DEFAULT_GAS_BUDGET_FOR_SPLIT, DEFAULT_GAS_BUDGET_FOR_STAKE, DEFAULT_GAS_BUDGET_FOR_TRANSFER, DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI, DEFAULT_NFT_TRANSFER_GAS_FEE, Env, FLOWXV2, FLOWXV3, FLOWX_AMM, FLOWX_AMM_MODULE, FULLSAIL, FlashSwapA2BFunc, FlashSwapB2AFunc, FlashSwapFunc, FlashSwapWithPartnerA2BFunc, FlashSwapWithPartnerB2AFunc, FlashSwapWithPartnerFunc, GAS_SYMBOL, GAS_TYPE_ARG, GAS_TYPE_ARG_LONG, HAEDAL, HAEDALHMMV2, HAEDALPMM, HAWAL, INTEGRATE, JOIN_FUNC, KRIYA, KRIYAV3, KRIYA_DEX, KRIYA_MODULE, MAGMA, MAINNET_AFTERMATH_INSURANCE_FUND_ID, MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, MAINNET_AFTERMATH_REFERRAL_VAULT_ID, MAINNET_AFTERMATH_REGISTRY_ID, MAINNET_AFTERMATH_TREASURY_ID, MAINNET_CETUS_GLOBAL_CONFIG_ID, MAINNET_FLOWX_AMM_CONTAINER_ID, METASTABLE, MOMENTUM, OBRIC, ONE, PACKAGE_NAMES, PAY_MODULE, POOL_MODULT, PUBLISHED_ADDRESSES, PYTH_CONFIG, REPAY_FLASH_SWAP_A2B_FUNC, REPAY_FLASH_SWAP_B2A_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC, RepayFalshSwapFunc, RepayFlashSwapWithPartnerFunc, SCALLOP, SEVENK, SPRINGSUI, STEAMM, STEAMM_OMM, STEAMM_OMM_V2, SUILEND, SUI_SYSTEM_STATE_OBJECT_ID, SWAP_A2B_FUNC, SWAP_B2A_FUNC, SuiZeroCoinFn, TEN_POW_NINE, TESTNET_AFTERMATH_INSURANCE_FUND_ID, TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, TESTNET_AFTERMATH_REFERRAL_VAULT_ID, TESTNET_AFTERMATH_REGISTRY_ID, TESTNET_AFTERMATH_TREASURY_ID, TESTNET_CETUS_GLOBAL_CONFIG_ID, TESTNET_FLOWX_AMM_CONTAINER_ID, TRANSFER_ACCOUNT_CAP, TRANSFER_OR_DESTORY_COIN_FUNC, TURBOS, TURBOS_DEX, TURBOS_MODULE, TURBOS_VERSIONED, TWO, TransactionErrorCode, TypesErrorCode, U128, U64_MAX, U64_MAX_BN, UTILS_MODULE, VOLO, ZERO, buildInputCoin, calculateGasEfficiency, calculatePriceImpact, checkInvalidSuiAddress, compareCoins, compareGasMetrics, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, exportToCSV, exportToJSON, extractAddressFromType, extractGasMetrics, extractStructTagFromType, extractTimestampFromDowngradeUuid6, fixSuiObjectId, formatGasMetrics, generateDowngradeUuid6, generateSimpleDowngradeUuid6, getAggregatorServerErrorMessage, getAggregatorV2Extend2PublishedAt, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getAllProviders, getDeepbookV3Config, getDefaultSuiInputType,
|
|
8908
|
+
export { AFSUI, AFTERMATH, AFTERMATH_AMM, AFTERMATH_MODULE, AGGREGATOR, AGGREGATOR_V3_CONFIG, ALL_DEXES, ALPHAFI, AggregatorClient, AggregatorConfig, AggregatorError, AggregatorServerErrorCode, BLUEFIN, BLUEMOVE, CETUS, CETUS_DEX, CETUS_MODULE, CETUS_PUBLISHED_AT, CETUS_V3_PUBLISHED_AT, CHECK_COINS_THRESHOLD_FUNC, CLIENT_CONFIG, CLOCK_ADDRESS, CoinInfoAddress, CoinStoreAddress, CoinUtils, ConfigErrorCode, DEEPBOOKV2, DEEPBOOKV3, DEEPBOOK_CLOB_V2_MODULE, DEEPBOOK_CUSTODIAN_V2_MODULE, DEEPBOOK_DEX, DEEPBOOK_MODULE, DEEPBOOK_PACKAGE_ID, DEEPBOOK_PUBLISHED_AT, DEEPBOOK_V3_DEEP_FEE_TYPES, DEFAULT_AGG_V2_ENDPOINT, DEFAULT_AGG_V3_ENDPOINT, DEFAULT_ENDPOINT, DEFAULT_GAS_BUDGET_FOR_MERGE, DEFAULT_GAS_BUDGET_FOR_SPLIT, DEFAULT_GAS_BUDGET_FOR_STAKE, DEFAULT_GAS_BUDGET_FOR_TRANSFER, DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI, DEFAULT_NFT_TRANSFER_GAS_FEE, Env, FLOWXV2, FLOWXV3, FLOWX_AMM, FLOWX_AMM_MODULE, FULLSAIL, FlashSwapA2BFunc, FlashSwapB2AFunc, FlashSwapFunc, FlashSwapWithPartnerA2BFunc, FlashSwapWithPartnerB2AFunc, FlashSwapWithPartnerFunc, GAS_SYMBOL, GAS_TYPE_ARG, GAS_TYPE_ARG_LONG, HAEDAL, HAEDALHMMV2, HAEDALPMM, HAWAL, INTEGRATE, JOIN_FUNC, KRIYA, KRIYAV3, KRIYA_DEX, KRIYA_MODULE, MAGMA, MAINNET_AFTERMATH_INSURANCE_FUND_ID, MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, MAINNET_AFTERMATH_REFERRAL_VAULT_ID, MAINNET_AFTERMATH_REGISTRY_ID, MAINNET_AFTERMATH_TREASURY_ID, MAINNET_CETUS_GLOBAL_CONFIG_ID, MAINNET_FLOWX_AMM_CONTAINER_ID, METASTABLE, MOMENTUM, OBRIC, ONE, PACKAGE_NAMES, PAY_MODULE, POOL_MODULT, PUBLISHED_ADDRESSES, PYTH_CONFIG, REPAY_FLASH_SWAP_A2B_FUNC, REPAY_FLASH_SWAP_B2A_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC, RepayFalshSwapFunc, RepayFlashSwapWithPartnerFunc, SCALLOP, SEVENK, SPRINGSUI, STEAMM, STEAMM_OMM, STEAMM_OMM_V2, SUILEND, SUI_SYSTEM_STATE_OBJECT_ID, SWAP_A2B_FUNC, SWAP_B2A_FUNC, SuiZeroCoinFn, TEN_POW_NINE, TESTNET_AFTERMATH_INSURANCE_FUND_ID, TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, TESTNET_AFTERMATH_REFERRAL_VAULT_ID, TESTNET_AFTERMATH_REGISTRY_ID, TESTNET_AFTERMATH_TREASURY_ID, TESTNET_CETUS_GLOBAL_CONFIG_ID, TESTNET_FLOWX_AMM_CONTAINER_ID, TRANSFER_ACCOUNT_CAP, TRANSFER_OR_DESTORY_COIN_FUNC, TURBOS, TURBOS_DEX, TURBOS_MODULE, TURBOS_VERSIONED, TWO, TransactionErrorCode, TypesErrorCode, U128, U64_MAX, U64_MAX_BN, UTILS_MODULE, VOLO, ZERO, buildInputCoin, calculateGasEfficiency, calculatePriceImpact, checkInvalidSuiAddress, compareCoins, compareGasMetrics, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, exportToCSV, exportToJSON, extractAddressFromType, extractGasMetrics, extractStructTagFromType, extractTimestampFromDowngradeUuid6, fixSuiObjectId, formatGasMetrics, generateDowngradeUuid6, generateSimpleDowngradeUuid6, getAggregatorServerErrorMessage, getAggregatorV2Extend2PublishedAt, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getAllProviders, getDeepbookV3Config, getDefaultSuiInputType, getOrCreateAccountCap, getProvidersExcluding, getProvidersIncluding, getRouterResult, isSortedSymbols, isValidDowngradeUuid6, mintZeroCoin, normalizeCoinType, parseAftermathFeeType, parseTurbosPoolFeeType, patchFixSuiObjectId, printTransaction, processEndpoint, processFlattenRoutes, restituteMsafeFastRouterSwapParams };
|