@cetusprotocol/aggregator-sdk 0.0.0-experimental-20250829185106 → 0.0.0-experimental-20250903203111
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 +8 -52
- package/dist/index.d.ts +8 -52
- package/dist/index.js +51 -276
- package/dist/index.mjs +52 -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.js
CHANGED
|
@@ -3340,7 +3340,7 @@ var SuiZeroCoinFn = "0x2::coin::zero";
|
|
|
3340
3340
|
var DEEPBOOK_PACKAGE_ID = "0x000000000000000000000000000000000000000000000000000000000000dee9";
|
|
3341
3341
|
var DEEPBOOK_PUBLISHED_AT = "0x000000000000000000000000000000000000000000000000000000000000dee9";
|
|
3342
3342
|
var CETUS_PUBLISHED_AT = "0x70968826ad1b4ba895753f634b0aea68d0672908ca1075a2abdf0fc9e0b2fc6a";
|
|
3343
|
-
var CETUS_V3_PUBLISHED_AT = "
|
|
3343
|
+
var CETUS_V3_PUBLISHED_AT = "0x73a9bcf98bd1f4602bd4bb76f235b20253a17722cda3438d1710b70c831168af";
|
|
3344
3344
|
var MAINNET_CETUS_GLOBAL_CONFIG_ID = "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f";
|
|
3345
3345
|
var TESTNET_CETUS_GLOBAL_CONFIG_ID = "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
|
|
3346
3346
|
var MAINNET_FLOWX_AMM_CONTAINER_ID = "0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511";
|
|
@@ -3398,6 +3398,7 @@ var CLIENT_CONFIG = {
|
|
|
3398
3398
|
DEFAULT_PYTH_URL: "https://hermes.pyth.network",
|
|
3399
3399
|
PYTH_TIMEOUT: 3e3,
|
|
3400
3400
|
MAX_OVERLAY_FEE_RATE: 0.1,
|
|
3401
|
+
MAX_OVERLAY_FEE_RATE_NUMERATOR: 1e5,
|
|
3401
3402
|
FEE_RATE_MULTIPLIER: 1e6,
|
|
3402
3403
|
DEFAULT_OVERLAY_FEE_RECEIVER: "0x0",
|
|
3403
3404
|
// Error Messages
|
|
@@ -3411,7 +3412,8 @@ var CLIENT_CONFIG = {
|
|
|
3411
3412
|
PYTH_UNAVAILABLE: "All Pyth price nodes are unavailable. Cannot fetch price data. Please switch to or add new available Pyth nodes",
|
|
3412
3413
|
QUOTE_ID_REQUIRED: "Quote ID is required",
|
|
3413
3414
|
AGGREGATOR_V3_PACKAGE_REQUIRED: "Aggregator V3 package is required",
|
|
3414
|
-
PACKAGES_REQUIRED: "Packages are required"
|
|
3415
|
+
PACKAGES_REQUIRED: "Packages are required",
|
|
3416
|
+
OVERLAY_FEE_RECEIVER_REQUIRED: "Overlay fee rate is set, but overlay fee receiver is not set"
|
|
3415
3417
|
}
|
|
3416
3418
|
};
|
|
3417
3419
|
var AGGREGATOR_V3_CONFIG = {
|
|
@@ -3420,7 +3422,7 @@ var AGGREGATOR_V3_CONFIG = {
|
|
|
3420
3422
|
// 10%
|
|
3421
3423
|
MAX_AMOUNT_IN: U64_MAX,
|
|
3422
3424
|
DEFAULT_PUBLISHED_AT: {
|
|
3423
|
-
Mainnet: "
|
|
3425
|
+
Mainnet: "0x0422e3239f174320760dd675ba3835cf4b1c511be4a36e819cb61fab7d5d404a",
|
|
3424
3426
|
Testnet: "0x0"
|
|
3425
3427
|
}
|
|
3426
3428
|
};
|
|
@@ -3444,6 +3446,7 @@ function parseRouterResponse(data, byAmountIn) {
|
|
|
3444
3446
|
amountOut: new import_bn2.default(data.amount_out.toString()),
|
|
3445
3447
|
byAmountIn,
|
|
3446
3448
|
insufficientLiquidity: false,
|
|
3449
|
+
deviationRatio: data.deviation_ratio,
|
|
3447
3450
|
packages,
|
|
3448
3451
|
paths: data.paths.map((path) => ({
|
|
3449
3452
|
id: path.id,
|
|
@@ -3460,50 +3463,6 @@ function parseRouterResponse(data, byAmountIn) {
|
|
|
3460
3463
|
}))
|
|
3461
3464
|
};
|
|
3462
3465
|
}
|
|
3463
|
-
function parseMergeSwapResponse(data) {
|
|
3464
|
-
var _a;
|
|
3465
|
-
let packages = /* @__PURE__ */ new Map();
|
|
3466
|
-
if (data.packages) {
|
|
3467
|
-
if (data.packages instanceof Map) {
|
|
3468
|
-
packages = data.packages;
|
|
3469
|
-
} else if (typeof data.packages === "object") {
|
|
3470
|
-
Object.entries(data.packages).forEach(([key, value]) => {
|
|
3471
|
-
packages.set(key, value);
|
|
3472
|
-
});
|
|
3473
|
-
}
|
|
3474
|
-
}
|
|
3475
|
-
const allRoutes = [];
|
|
3476
|
-
if (data.all_routes) {
|
|
3477
|
-
for (const route of data.all_routes) {
|
|
3478
|
-
const mergeRoute = {
|
|
3479
|
-
amountIn: new import_bn2.default(route.amount_in.toString()),
|
|
3480
|
-
amountOut: new import_bn2.default(route.amount_out.toString()),
|
|
3481
|
-
deviationRatio: route.deviation_ratio,
|
|
3482
|
-
paths: route.paths.map((path) => ({
|
|
3483
|
-
id: path.id,
|
|
3484
|
-
direction: path.direction,
|
|
3485
|
-
provider: path.provider,
|
|
3486
|
-
from: path.from,
|
|
3487
|
-
target: path.target,
|
|
3488
|
-
feeRate: path.fee_rate,
|
|
3489
|
-
amountIn: path.amount_in.toString(),
|
|
3490
|
-
amountOut: path.amount_out.toString(),
|
|
3491
|
-
version: path.version,
|
|
3492
|
-
publishedAt: path.published_at,
|
|
3493
|
-
extendedDetails: path.extended_details
|
|
3494
|
-
}))
|
|
3495
|
-
};
|
|
3496
|
-
allRoutes.push(mergeRoute);
|
|
3497
|
-
}
|
|
3498
|
-
}
|
|
3499
|
-
return {
|
|
3500
|
-
quoteID: data.request_id || "",
|
|
3501
|
-
totalAmountOut: new import_bn2.default(((_a = data.total_amount_out) == null ? void 0 : _a.toString()) || "0"),
|
|
3502
|
-
allRoutes,
|
|
3503
|
-
packages,
|
|
3504
|
-
gas: data.gas
|
|
3505
|
-
};
|
|
3506
|
-
}
|
|
3507
3466
|
function getRouterResult(endpoint, apiKey, params, overlayFee, overlayFeeReceiver) {
|
|
3508
3467
|
return __async(this, null, function* () {
|
|
3509
3468
|
let response;
|
|
@@ -3632,7 +3591,6 @@ function getRouter(endpoint, apiKey, params) {
|
|
|
3632
3591
|
url += `&apiKey=${apiKey}`;
|
|
3633
3592
|
}
|
|
3634
3593
|
url += `&v=${SDK_VERSION}`;
|
|
3635
|
-
console.log("url", url);
|
|
3636
3594
|
const response = yield fetch(url);
|
|
3637
3595
|
return response;
|
|
3638
3596
|
} catch (error) {
|
|
@@ -3692,94 +3650,6 @@ function postRouterWithLiquidityChanges(endpoint, params) {
|
|
|
3692
3650
|
}
|
|
3693
3651
|
});
|
|
3694
3652
|
}
|
|
3695
|
-
function getMergeSwapRouter(endpoint, apiKey, params) {
|
|
3696
|
-
return __async(this, null, function* () {
|
|
3697
|
-
try {
|
|
3698
|
-
const { target, byAmountIn, depth, providers, froms } = params;
|
|
3699
|
-
const targetCoin = completionCoin(target);
|
|
3700
|
-
let url = `${endpoint}/multi_find_routes?target=${targetCoin}&by_amount_in=${byAmountIn}`;
|
|
3701
|
-
if (depth) {
|
|
3702
|
-
url += `&depth=${depth}`;
|
|
3703
|
-
}
|
|
3704
|
-
if (providers && providers.length > 0) {
|
|
3705
|
-
url += `&providers=${providers.join(",")}`;
|
|
3706
|
-
}
|
|
3707
|
-
if (apiKey.length > 0) {
|
|
3708
|
-
url += `&apiKey=${apiKey}`;
|
|
3709
|
-
}
|
|
3710
|
-
url += `&v=${SDK_VERSION}`;
|
|
3711
|
-
const fromsData = froms.map((from) => ({
|
|
3712
|
-
coin_type: completionCoin(from.coinType),
|
|
3713
|
-
amount: Number(from.amount.toString())
|
|
3714
|
-
}));
|
|
3715
|
-
url += `&froms=${encodeURIComponent(JSON.stringify(fromsData))}`;
|
|
3716
|
-
const response = yield fetch(url);
|
|
3717
|
-
return response;
|
|
3718
|
-
} catch (error) {
|
|
3719
|
-
console.error(error);
|
|
3720
|
-
return null;
|
|
3721
|
-
}
|
|
3722
|
-
});
|
|
3723
|
-
}
|
|
3724
|
-
function getMergeSwapResult(endpoint, apiKey, params, overlayFee, overlayFeeReceiver) {
|
|
3725
|
-
return __async(this, null, function* () {
|
|
3726
|
-
const response = yield getMergeSwapRouter(endpoint, apiKey, params);
|
|
3727
|
-
if (!response) {
|
|
3728
|
-
return null;
|
|
3729
|
-
}
|
|
3730
|
-
if (!response.ok) {
|
|
3731
|
-
let errorCode = 1e3 /* NumberTooLarge */;
|
|
3732
|
-
if (response.status === 429) {
|
|
3733
|
-
errorCode = 1001 /* RateLimitExceeded */;
|
|
3734
|
-
}
|
|
3735
|
-
return {
|
|
3736
|
-
quoteID: "",
|
|
3737
|
-
totalAmountOut: ZERO,
|
|
3738
|
-
allRoutes: [],
|
|
3739
|
-
error: {
|
|
3740
|
-
code: errorCode,
|
|
3741
|
-
msg: getAggregatorServerErrorMessage(errorCode)
|
|
3742
|
-
}
|
|
3743
|
-
};
|
|
3744
|
-
}
|
|
3745
|
-
const responseText = yield response.text();
|
|
3746
|
-
const data = JSONbig__default.default.parse(responseText);
|
|
3747
|
-
data.msg === "liquidity is not enough";
|
|
3748
|
-
if (data.msg && data.msg.indexOf("HoneyPot scam") > -1) {
|
|
3749
|
-
return {
|
|
3750
|
-
quoteID: "",
|
|
3751
|
-
totalAmountOut: ZERO,
|
|
3752
|
-
allRoutes: [],
|
|
3753
|
-
error: {
|
|
3754
|
-
code: 1003 /* HoneyPot */,
|
|
3755
|
-
msg: getAggregatorServerErrorMessage(
|
|
3756
|
-
1003 /* HoneyPot */
|
|
3757
|
-
)
|
|
3758
|
-
}
|
|
3759
|
-
};
|
|
3760
|
-
}
|
|
3761
|
-
if (data.data != null) {
|
|
3762
|
-
const res = parseMergeSwapResponse(data.data);
|
|
3763
|
-
if (overlayFee > 0 && overlayFeeReceiver !== "0x0" && params.byAmountIn) {
|
|
3764
|
-
const overlayFeeAmount = res.totalAmountOut.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3765
|
-
res.totalAmountOut = res.totalAmountOut.sub(overlayFeeAmount);
|
|
3766
|
-
for (const route of res.allRoutes) {
|
|
3767
|
-
const routeFee = route.amountOut.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3768
|
-
route.amountOut = route.amountOut.sub(routeFee);
|
|
3769
|
-
}
|
|
3770
|
-
}
|
|
3771
|
-
if (!res.packages) {
|
|
3772
|
-
res.packages = /* @__PURE__ */ new Map();
|
|
3773
|
-
}
|
|
3774
|
-
return res;
|
|
3775
|
-
}
|
|
3776
|
-
return {
|
|
3777
|
-
quoteID: "",
|
|
3778
|
-
totalAmountOut: ZERO,
|
|
3779
|
-
allRoutes: []
|
|
3780
|
-
};
|
|
3781
|
-
});
|
|
3782
|
-
}
|
|
3783
3653
|
function getDeepbookV3Config(endpoint) {
|
|
3784
3654
|
return __async(this, null, function* () {
|
|
3785
3655
|
const url = `${endpoint}/deepbookv3_config`;
|
|
@@ -3811,7 +3681,6 @@ function processFlattenRoutes(routerData) {
|
|
|
3811
3681
|
flattenedPaths[i].isLastUseOfIntermediateToken = true;
|
|
3812
3682
|
}
|
|
3813
3683
|
}
|
|
3814
|
-
console.log("flattenedPaths", flattenedPaths);
|
|
3815
3684
|
return {
|
|
3816
3685
|
quoteID: routerData.quoteID || "",
|
|
3817
3686
|
amountIn: routerData.amountIn,
|
|
@@ -8369,6 +8238,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8369
8238
|
if (params.overlayFeeRate) {
|
|
8370
8239
|
if (params.overlayFeeRate > 0 && params.overlayFeeRate <= CLIENT_CONFIG.MAX_OVERLAY_FEE_RATE) {
|
|
8371
8240
|
this.overlayFeeRate = params.overlayFeeRate * AGGREGATOR_V3_CONFIG.FEE_DENOMINATOR;
|
|
8241
|
+
console.log("this.overlayFeeRate", this.overlayFeeRate);
|
|
8372
8242
|
if (this.overlayFeeRate > AGGREGATOR_V3_CONFIG.MAX_FEE_RATE) {
|
|
8373
8243
|
throw new Error(
|
|
8374
8244
|
CLIENT_CONFIG.ERRORS.INVALID_OVERLAY_FEE_RATE
|
|
@@ -8398,6 +8268,11 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8398
8268
|
return DEEPBOOK_V3_DEEP_FEE_TYPES.Testnet;
|
|
8399
8269
|
}
|
|
8400
8270
|
}
|
|
8271
|
+
getDeepbookV3Config() {
|
|
8272
|
+
return __async(this, null, function* () {
|
|
8273
|
+
return yield getDeepbookV3Config(this.endpoint);
|
|
8274
|
+
});
|
|
8275
|
+
}
|
|
8401
8276
|
getOneCoinUsedToMerge(coinType) {
|
|
8402
8277
|
return __async(this, null, function* () {
|
|
8403
8278
|
try {
|
|
@@ -8426,17 +8301,6 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8426
8301
|
);
|
|
8427
8302
|
});
|
|
8428
8303
|
}
|
|
8429
|
-
findMergeSwapRouters(params) {
|
|
8430
|
-
return __async(this, null, function* () {
|
|
8431
|
-
return getMergeSwapResult(
|
|
8432
|
-
this.endpoint,
|
|
8433
|
-
this.apiKey,
|
|
8434
|
-
params,
|
|
8435
|
-
this.overlayFeeRate,
|
|
8436
|
-
this.overlayFeeReceiver
|
|
8437
|
-
);
|
|
8438
|
-
});
|
|
8439
|
-
}
|
|
8440
8304
|
executeFlexibleInputSwap(txb, inputCoin, routerData, expectedAmountOut, amountLimit, pythPriceIDs, partner, deepbookv3DeepFee, packages) {
|
|
8441
8305
|
return __async(this, null, function* () {
|
|
8442
8306
|
});
|
|
@@ -8659,20 +8523,22 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8659
8523
|
}
|
|
8660
8524
|
routerSwap(params) {
|
|
8661
8525
|
return __async(this, null, function* () {
|
|
8662
|
-
const { router, inputCoin, slippage, txb,
|
|
8526
|
+
const { router, inputCoin, slippage, txb, partner } = params;
|
|
8663
8527
|
if (slippage > 1 || slippage < 0) {
|
|
8664
8528
|
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
|
|
8665
8529
|
}
|
|
8530
|
+
if (!params.router.packages || !params.router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
8531
|
+
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
8532
|
+
}
|
|
8666
8533
|
const byAmountIn = params.router.byAmountIn;
|
|
8667
8534
|
const amountIn = router.amountIn;
|
|
8668
8535
|
const amountOut = router.amountOut;
|
|
8536
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
8669
8537
|
let overlayFee = new import_bn6.default(0);
|
|
8670
|
-
if (
|
|
8671
|
-
|
|
8672
|
-
|
|
8673
|
-
|
|
8674
|
-
overlayFee = amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
8675
|
-
}
|
|
8538
|
+
if (byAmountIn) {
|
|
8539
|
+
overlayFee = amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
8540
|
+
} else {
|
|
8541
|
+
overlayFee = amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
8676
8542
|
}
|
|
8677
8543
|
const expectedAmountOut = byAmountIn ? amountOut.sub(overlayFee) : amountOut;
|
|
8678
8544
|
const expectedAmountIn = byAmountIn ? amountIn : amountIn.add(overlayFee);
|
|
@@ -8681,9 +8547,6 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8681
8547
|
byAmountIn,
|
|
8682
8548
|
slippage
|
|
8683
8549
|
);
|
|
8684
|
-
if (!params.router.packages || !params.router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
8685
|
-
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
8686
|
-
}
|
|
8687
8550
|
const priceIDs = findPythPriceIDs(router.paths);
|
|
8688
8551
|
const priceInfoObjectIds = priceIDs.length > 0 ? yield this.updatePythPriceIDs(priceIDs, txb) : /* @__PURE__ */ new Map();
|
|
8689
8552
|
if (byAmountIn) {
|
|
@@ -8716,17 +8579,16 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8716
8579
|
const fromCoinType = router.paths[0].from;
|
|
8717
8580
|
const targetCoinType = router.paths[router.paths.length - 1].target;
|
|
8718
8581
|
const byAmountIn = router.byAmountIn;
|
|
8582
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
8719
8583
|
let overlayFee = 0;
|
|
8720
|
-
if (
|
|
8721
|
-
|
|
8722
|
-
|
|
8723
|
-
|
|
8724
|
-
|
|
8725
|
-
|
|
8726
|
-
|
|
8727
|
-
|
|
8728
|
-
);
|
|
8729
|
-
}
|
|
8584
|
+
if (byAmountIn) {
|
|
8585
|
+
overlayFee = Number(
|
|
8586
|
+
router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
8587
|
+
);
|
|
8588
|
+
} else {
|
|
8589
|
+
overlayFee = Number(
|
|
8590
|
+
router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
8591
|
+
);
|
|
8730
8592
|
}
|
|
8731
8593
|
const expectedAmountOut = byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
|
|
8732
8594
|
const expectedAmountIn = byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
|
|
@@ -8776,116 +8638,19 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8776
8638
|
}
|
|
8777
8639
|
});
|
|
8778
8640
|
}
|
|
8779
|
-
mergeSwap(params) {
|
|
8780
|
-
return __async(this, null, function* () {
|
|
8781
|
-
const { router, inputCoins, slippage, txb, partner } = params;
|
|
8782
|
-
if (slippage > 1 || slippage < 0) {
|
|
8783
|
-
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
|
|
8784
|
-
}
|
|
8785
|
-
if (!router.packages || !router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
8786
|
-
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
8787
|
-
}
|
|
8788
|
-
if (!router.allRoutes || router.allRoutes.length === 0) {
|
|
8789
|
-
throw new Error("No routes found in merge swap response");
|
|
8790
|
-
}
|
|
8791
|
-
const outputCoins = [];
|
|
8792
|
-
for (let i = 0; i < router.allRoutes.length && i < inputCoins.length; i++) {
|
|
8793
|
-
const route = router.allRoutes[i];
|
|
8794
|
-
const inputCoin = inputCoins[i];
|
|
8795
|
-
const routeRouter = {
|
|
8796
|
-
quoteID: router.quoteID,
|
|
8797
|
-
amountIn: route.amountIn,
|
|
8798
|
-
amountOut: route.amountOut,
|
|
8799
|
-
byAmountIn: true,
|
|
8800
|
-
// Merge swap is always by amount in
|
|
8801
|
-
paths: route.paths,
|
|
8802
|
-
insufficientLiquidity: false,
|
|
8803
|
-
packages: router.packages
|
|
8804
|
-
};
|
|
8805
|
-
const routerParams = {
|
|
8806
|
-
router: routeRouter,
|
|
8807
|
-
inputCoin: inputCoin.coin,
|
|
8808
|
-
slippage,
|
|
8809
|
-
txb,
|
|
8810
|
-
partner: partner != null ? partner : this.partner
|
|
8811
|
-
};
|
|
8812
|
-
const outputCoin = yield this.routerSwap(routerParams);
|
|
8813
|
-
outputCoins.push(outputCoin);
|
|
8814
|
-
}
|
|
8815
|
-
if (outputCoins.length === 0) {
|
|
8816
|
-
throw new Error("No output coins generated from merge swap");
|
|
8817
|
-
}
|
|
8818
|
-
let finalOutputCoin = outputCoins[0];
|
|
8819
|
-
if (outputCoins.length > 1) {
|
|
8820
|
-
txb.mergeCoins(finalOutputCoin, outputCoins.slice(1));
|
|
8821
|
-
}
|
|
8822
|
-
return finalOutputCoin;
|
|
8823
|
-
});
|
|
8824
|
-
}
|
|
8825
|
-
fastMergeSwap(params) {
|
|
8826
|
-
return __async(this, null, function* () {
|
|
8827
|
-
const { router, slippage, txb, partner } = params;
|
|
8828
|
-
if (!router || !router.allRoutes || router.allRoutes.length === 0) {
|
|
8829
|
-
throw new Error("Invalid router: no routes found");
|
|
8830
|
-
}
|
|
8831
|
-
const firstRoute = router.allRoutes[0];
|
|
8832
|
-
const targetCoinType = firstRoute.paths[firstRoute.paths.length - 1].target;
|
|
8833
|
-
const inputCoins = [];
|
|
8834
|
-
const coinTypeSet = /* @__PURE__ */ new Set();
|
|
8835
|
-
for (const route of router.allRoutes) {
|
|
8836
|
-
const firstCoinType = route.paths[0].from;
|
|
8837
|
-
if (coinTypeSet.has(firstCoinType)) {
|
|
8838
|
-
continue;
|
|
8839
|
-
}
|
|
8840
|
-
coinTypeSet.add(firstCoinType);
|
|
8841
|
-
const coin = transactions.coinWithBalance({
|
|
8842
|
-
balance: BigInt(route.amountIn.toString()),
|
|
8843
|
-
useGasCoin: CoinUtils.isSuiCoin(firstCoinType),
|
|
8844
|
-
type: firstCoinType
|
|
8845
|
-
});
|
|
8846
|
-
inputCoins.push({ coinType: firstCoinType, coin });
|
|
8847
|
-
}
|
|
8848
|
-
const mergeSwapParams = {
|
|
8849
|
-
router,
|
|
8850
|
-
inputCoins,
|
|
8851
|
-
slippage,
|
|
8852
|
-
txb,
|
|
8853
|
-
partner: partner != null ? partner : this.partner
|
|
8854
|
-
};
|
|
8855
|
-
const targetCoin = yield this.mergeSwap(mergeSwapParams);
|
|
8856
|
-
if (CoinUtils.isSuiCoin(targetCoinType)) {
|
|
8857
|
-
txb.mergeCoins(txb.gas, [targetCoin]);
|
|
8858
|
-
} else {
|
|
8859
|
-
const targetCoinObjID = yield this.getOneCoinUsedToMerge(targetCoinType);
|
|
8860
|
-
if (targetCoinObjID != null) {
|
|
8861
|
-
txb.mergeCoins(txb.object(targetCoinObjID), [targetCoin]);
|
|
8862
|
-
} else {
|
|
8863
|
-
transferOrDestroyCoin(
|
|
8864
|
-
{
|
|
8865
|
-
coin: targetCoin,
|
|
8866
|
-
coinType: targetCoinType,
|
|
8867
|
-
packages: router.packages
|
|
8868
|
-
},
|
|
8869
|
-
txb
|
|
8870
|
-
);
|
|
8871
|
-
}
|
|
8872
|
-
}
|
|
8873
|
-
});
|
|
8874
|
-
}
|
|
8875
8641
|
fixableRouterSwapV3(params) {
|
|
8876
8642
|
return __async(this, null, function* () {
|
|
8877
|
-
const { router, inputCoin, slippage, txb,
|
|
8643
|
+
const { router, inputCoin, slippage, txb, partner } = params;
|
|
8644
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
8878
8645
|
let overlayFee = 0;
|
|
8879
|
-
if (
|
|
8880
|
-
|
|
8881
|
-
|
|
8882
|
-
|
|
8883
|
-
|
|
8884
|
-
|
|
8885
|
-
|
|
8886
|
-
|
|
8887
|
-
);
|
|
8888
|
-
}
|
|
8646
|
+
if (router.byAmountIn) {
|
|
8647
|
+
overlayFee = Number(
|
|
8648
|
+
router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
8649
|
+
);
|
|
8650
|
+
} else {
|
|
8651
|
+
overlayFee = Number(
|
|
8652
|
+
router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
8653
|
+
);
|
|
8889
8654
|
}
|
|
8890
8655
|
const expectedAmountOut = router.byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
|
|
8891
8656
|
const expectedAmountIn = router.byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
|
|
@@ -8994,6 +8759,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8994
8759
|
const routeData = {
|
|
8995
8760
|
amountIn,
|
|
8996
8761
|
amountOut: new import_bn6.default((_d = event.amount_out) != null ? _d : 0),
|
|
8762
|
+
deviationRatio: 0,
|
|
8997
8763
|
paths: [
|
|
8998
8764
|
{
|
|
8999
8765
|
id: pools[tempIndex],
|
|
@@ -9111,6 +8877,16 @@ function recordFirstCoinIndex(paths) {
|
|
|
9111
8877
|
}
|
|
9112
8878
|
return newCoinRecord;
|
|
9113
8879
|
}
|
|
8880
|
+
function checkOverlayFeeConfig(overlayFeeRate, overlayFeeReceiver) {
|
|
8881
|
+
if (overlayFeeRate > CLIENT_CONFIG.MAX_OVERLAY_FEE_RATE_NUMERATOR) {
|
|
8882
|
+
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_OVERLAY_FEE_RATE);
|
|
8883
|
+
}
|
|
8884
|
+
if (overlayFeeReceiver === "0x0" && overlayFeeRate > 0) {
|
|
8885
|
+
throw new Error(
|
|
8886
|
+
CLIENT_CONFIG.ERRORS.OVERLAY_FEE_RECEIVER_REQUIRED
|
|
8887
|
+
);
|
|
8888
|
+
}
|
|
8889
|
+
}
|
|
9114
8890
|
|
|
9115
8891
|
// src/types/sui.ts
|
|
9116
8892
|
var getDefaultSuiInputType = (value) => {
|
|
@@ -9290,7 +9066,6 @@ exports.getAggregatorV2PublishedAt = getAggregatorV2PublishedAt;
|
|
|
9290
9066
|
exports.getAllProviders = getAllProviders;
|
|
9291
9067
|
exports.getDeepbookV3Config = getDeepbookV3Config;
|
|
9292
9068
|
exports.getDefaultSuiInputType = getDefaultSuiInputType;
|
|
9293
|
-
exports.getMergeSwapResult = getMergeSwapResult;
|
|
9294
9069
|
exports.getOrCreateAccountCap = getOrCreateAccountCap;
|
|
9295
9070
|
exports.getProvidersExcluding = getProvidersExcluding;
|
|
9296
9071
|
exports.getProvidersIncluding = getProvidersIncluding;
|