@cetusprotocol/aggregator-sdk 1.4.5 → 1.4.7
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/bun.lock +30 -36
- package/dist/{index.mjs → index.cjs} +1226 -940
- package/dist/{index.d.mts → index.d.cts} +120 -13
- package/dist/index.d.ts +120 -13
- package/dist/index.js +1050 -1116
- package/package.json +5 -4
- package/tsconfig.json +5 -5
|
@@ -1,32 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var transactions = require('@mysten/sui/transactions');
|
|
4
|
+
var JSONbig = require('json-bigint');
|
|
5
|
+
var utils = require('@mysten/sui/utils');
|
|
6
|
+
var grpc = require('@mysten/sui/grpc');
|
|
7
|
+
var hermesClient = require('@pythnetwork/hermes-client');
|
|
8
|
+
var bcs = require('@mysten/sui/bcs');
|
|
9
|
+
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var JSONbig__default = /*#__PURE__*/_interopDefault(JSONbig);
|
|
6
13
|
|
|
7
14
|
var __create = Object.create;
|
|
8
15
|
var __defProp = Object.defineProperty;
|
|
9
|
-
var __defProps = Object.defineProperties;
|
|
10
16
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
12
17
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
14
18
|
var __getProtoOf = Object.getPrototypeOf;
|
|
15
19
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
17
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
18
|
-
var __spreadValues = (a, b) => {
|
|
19
|
-
for (var prop in b || (b = {}))
|
|
20
|
-
if (__hasOwnProp.call(b, prop))
|
|
21
|
-
__defNormalProp(a, prop, b[prop]);
|
|
22
|
-
if (__getOwnPropSymbols)
|
|
23
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
24
|
-
if (__propIsEnum.call(b, prop))
|
|
25
|
-
__defNormalProp(a, prop, b[prop]);
|
|
26
|
-
}
|
|
27
|
-
return a;
|
|
28
|
-
};
|
|
29
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
30
20
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
31
21
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
32
22
|
}) : x)(function(x) {
|
|
@@ -49,29 +39,9 @@ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__
|
|
|
49
39
|
// file that has been converted to a CommonJS file using a Babel-
|
|
50
40
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
51
41
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
52
|
-
|
|
42
|
+
__defProp(target, "default", { value: mod2, enumerable: true }) ,
|
|
53
43
|
mod2
|
|
54
44
|
));
|
|
55
|
-
var __async = (__this, __arguments, generator) => {
|
|
56
|
-
return new Promise((resolve, reject) => {
|
|
57
|
-
var fulfilled = (value) => {
|
|
58
|
-
try {
|
|
59
|
-
step(generator.next(value));
|
|
60
|
-
} catch (e) {
|
|
61
|
-
reject(e);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
var rejected = (value) => {
|
|
65
|
-
try {
|
|
66
|
-
step(generator.throw(value));
|
|
67
|
-
} catch (e) {
|
|
68
|
-
reject(e);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
72
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
45
|
|
|
76
46
|
// node_modules/bn.js/lib/bn.js
|
|
77
47
|
var require_bn = __commonJS({
|
|
@@ -2941,17 +2911,17 @@ function extractAddressFromType(type) {
|
|
|
2941
2911
|
return type.split("::")[0];
|
|
2942
2912
|
}
|
|
2943
2913
|
function extractStructTagFromType(type) {
|
|
2944
|
-
var _a;
|
|
2945
2914
|
try {
|
|
2946
2915
|
let _type = type.replace(/\s/g, "");
|
|
2947
2916
|
const genericsString = _type.match(/(<.+>)$/);
|
|
2948
|
-
const generics =
|
|
2917
|
+
const generics = genericsString?.[0]?.match(/(\w+::\w+::\w+)(?:<.*?>(?!>))?/g);
|
|
2949
2918
|
if (generics) {
|
|
2950
2919
|
_type = _type.slice(0, _type.indexOf("<"));
|
|
2951
2920
|
const tag2 = extractStructTagFromType(_type);
|
|
2952
|
-
const structTag2 =
|
|
2921
|
+
const structTag2 = {
|
|
2922
|
+
...tag2,
|
|
2953
2923
|
type_arguments: generics.map((item) => extractStructTagFromType(item).source_address)
|
|
2954
|
-
}
|
|
2924
|
+
};
|
|
2955
2925
|
structTag2.type_arguments = structTag2.type_arguments.map((item) => {
|
|
2956
2926
|
return CoinUtils.isSuiCoin(item) ? item : extractStructTagFromType(item).source_address;
|
|
2957
2927
|
});
|
|
@@ -2962,7 +2932,7 @@ function extractStructTagFromType(type) {
|
|
|
2962
2932
|
const isSuiCoin = _type === GAS_TYPE_ARG || _type === GAS_TYPE_ARG_LONG;
|
|
2963
2933
|
const structTag = {
|
|
2964
2934
|
full_address: _type,
|
|
2965
|
-
address: isSuiCoin ? "0x2" : normalizeSuiObjectId(parts[0]),
|
|
2935
|
+
address: isSuiCoin ? "0x2" : utils.normalizeSuiObjectId(parts[0]),
|
|
2966
2936
|
module: parts[1],
|
|
2967
2937
|
name: parts[2],
|
|
2968
2938
|
type_arguments: [],
|
|
@@ -2987,7 +2957,7 @@ function normalizeCoinType(coinType) {
|
|
|
2987
2957
|
}
|
|
2988
2958
|
function fixSuiObjectId(value) {
|
|
2989
2959
|
if (value.toLowerCase().startsWith("0x")) {
|
|
2990
|
-
return normalizeSuiObjectId(value);
|
|
2960
|
+
return utils.normalizeSuiObjectId(value);
|
|
2991
2961
|
}
|
|
2992
2962
|
return value;
|
|
2993
2963
|
}
|
|
@@ -3482,7 +3452,6 @@ function parseRouterResponse(data, byAmountIn) {
|
|
|
3482
3452
|
};
|
|
3483
3453
|
}
|
|
3484
3454
|
function parseMergeSwapResponse(data) {
|
|
3485
|
-
var _a;
|
|
3486
3455
|
let packages = /* @__PURE__ */ new Map();
|
|
3487
3456
|
if (data.packages) {
|
|
3488
3457
|
if (data.packages instanceof Map) {
|
|
@@ -3519,133 +3488,85 @@ function parseMergeSwapResponse(data) {
|
|
|
3519
3488
|
}
|
|
3520
3489
|
return {
|
|
3521
3490
|
quoteID: data.request_id || "",
|
|
3522
|
-
totalAmountOut: new import_bn2.default(
|
|
3491
|
+
totalAmountOut: new import_bn2.default(data.total_amount_out?.toString() || "0"),
|
|
3523
3492
|
allRoutes,
|
|
3524
3493
|
packages,
|
|
3525
3494
|
gas: data.gas
|
|
3526
3495
|
};
|
|
3527
3496
|
}
|
|
3528
|
-
function getRouterResult(endpoint, apiKey, params, overlayFee, overlayFeeReceiver) {
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
errorCode = 1001 /* RateLimitExceeded */;
|
|
3543
|
-
}
|
|
3544
|
-
return {
|
|
3545
|
-
quoteID: "",
|
|
3546
|
-
amountIn: ZERO,
|
|
3547
|
-
amountOut: ZERO,
|
|
3548
|
-
paths: [],
|
|
3549
|
-
byAmountIn: params.byAmountIn,
|
|
3550
|
-
insufficientLiquidity: false,
|
|
3551
|
-
deviationRatio: 0,
|
|
3552
|
-
error: {
|
|
3553
|
-
code: errorCode,
|
|
3554
|
-
msg: getAggregatorServerErrorMessage(errorCode)
|
|
3555
|
-
}
|
|
3556
|
-
};
|
|
3557
|
-
}
|
|
3558
|
-
const data = JSONbig.parse(yield response.text());
|
|
3559
|
-
if (data.data != null) {
|
|
3560
|
-
const res = parseRouterResponse(data.data, params.byAmountIn);
|
|
3561
|
-
if (overlayFee > 0 && overlayFeeReceiver !== "0x0") {
|
|
3562
|
-
if (params.byAmountIn) {
|
|
3563
|
-
const overlayFeeAmount = res.amountOut.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3564
|
-
res.overlayFee = Number(overlayFeeAmount.toString());
|
|
3565
|
-
res.amountOut = res.amountOut.sub(overlayFeeAmount);
|
|
3566
|
-
} else {
|
|
3567
|
-
const overlayFeeAmount = res.amountIn.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3568
|
-
res.overlayFee = Number(overlayFeeAmount.toString());
|
|
3569
|
-
res.amountIn = res.amountIn.add(overlayFeeAmount);
|
|
3570
|
-
}
|
|
3571
|
-
}
|
|
3572
|
-
if (!res.packages) {
|
|
3573
|
-
res.packages = /* @__PURE__ */ new Map();
|
|
3574
|
-
}
|
|
3575
|
-
if (!res.packages.has("aggregator_v3")) {
|
|
3576
|
-
res.packages.set(
|
|
3577
|
-
"aggregator_v3",
|
|
3578
|
-
"0x3864c7c59a4889fec05d1aae4bc9dba5a0e0940594b424fbed44cb3f6ac4c032"
|
|
3579
|
-
);
|
|
3580
|
-
}
|
|
3581
|
-
return res;
|
|
3497
|
+
async function getRouterResult(endpoint, apiKey, params, overlayFee, overlayFeeReceiver) {
|
|
3498
|
+
let response;
|
|
3499
|
+
if (params.liquidityChanges && params.liquidityChanges.length > 0) {
|
|
3500
|
+
response = await postRouterWithLiquidityChanges(endpoint, params);
|
|
3501
|
+
} else {
|
|
3502
|
+
response = await getRouter(endpoint, apiKey, params);
|
|
3503
|
+
}
|
|
3504
|
+
if (!response) {
|
|
3505
|
+
return null;
|
|
3506
|
+
}
|
|
3507
|
+
if (!response.ok) {
|
|
3508
|
+
let errorCode = 1004 /* BadRequest */;
|
|
3509
|
+
if (response.status === 429) {
|
|
3510
|
+
errorCode = 1001 /* RateLimitExceeded */;
|
|
3582
3511
|
}
|
|
3583
|
-
const code = processErrorStatusCode(data.code);
|
|
3584
|
-
const msg = getAggregatorServerErrorMessage(code, data.msg);
|
|
3585
|
-
const insufficientLiquidity = msg.includes("Insufficient liquidity");
|
|
3586
3512
|
return {
|
|
3587
3513
|
quoteID: "",
|
|
3588
3514
|
amountIn: ZERO,
|
|
3589
3515
|
amountOut: ZERO,
|
|
3590
3516
|
paths: [],
|
|
3591
|
-
insufficientLiquidity,
|
|
3592
3517
|
byAmountIn: params.byAmountIn,
|
|
3518
|
+
insufficientLiquidity: false,
|
|
3593
3519
|
deviationRatio: 0,
|
|
3594
3520
|
error: {
|
|
3595
|
-
code,
|
|
3596
|
-
msg
|
|
3521
|
+
code: errorCode,
|
|
3522
|
+
msg: getAggregatorServerErrorMessage(errorCode)
|
|
3597
3523
|
}
|
|
3598
3524
|
};
|
|
3599
|
-
}
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
splitCount,
|
|
3613
|
-
providers
|
|
3614
|
-
} = params;
|
|
3615
|
-
const fromCoin = completionCoin(from);
|
|
3616
|
-
const targetCoin = completionCoin(target);
|
|
3617
|
-
let url = `${endpoint}/find_routes?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
|
|
3618
|
-
if (depth) {
|
|
3619
|
-
url += `&depth=${depth}`;
|
|
3620
|
-
}
|
|
3621
|
-
if (splitAlgorithm) {
|
|
3622
|
-
url += `&split_algorithm=${splitAlgorithm}`;
|
|
3623
|
-
}
|
|
3624
|
-
if (splitFactor) {
|
|
3625
|
-
url += `&split_factor=${splitFactor}`;
|
|
3626
|
-
}
|
|
3627
|
-
if (splitCount) {
|
|
3628
|
-
url += `&split_count=${splitCount}`;
|
|
3629
|
-
}
|
|
3630
|
-
if (providers) {
|
|
3631
|
-
if (providers.length > 0) {
|
|
3632
|
-
url += `&providers=${providers.join(",")}`;
|
|
3633
|
-
}
|
|
3634
|
-
}
|
|
3635
|
-
if (apiKey.length > 0) {
|
|
3636
|
-
url += `&apiKey=${apiKey}`;
|
|
3525
|
+
}
|
|
3526
|
+
const data = JSONbig__default.default.parse(await response.text());
|
|
3527
|
+
if (data.data != null) {
|
|
3528
|
+
const res = parseRouterResponse(data.data, params.byAmountIn);
|
|
3529
|
+
if (overlayFee > 0 && overlayFeeReceiver !== "0x0") {
|
|
3530
|
+
if (params.byAmountIn) {
|
|
3531
|
+
const overlayFeeAmount = res.amountOut.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3532
|
+
res.overlayFee = Number(overlayFeeAmount.toString());
|
|
3533
|
+
res.amountOut = res.amountOut.sub(overlayFeeAmount);
|
|
3534
|
+
} else {
|
|
3535
|
+
const overlayFeeAmount = res.amountIn.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3536
|
+
res.overlayFee = Number(overlayFeeAmount.toString());
|
|
3537
|
+
res.amountIn = res.amountIn.add(overlayFeeAmount);
|
|
3637
3538
|
}
|
|
3638
|
-
url += `&v=${SDK_VERSION}`;
|
|
3639
|
-
const response = yield fetch(url);
|
|
3640
|
-
return response;
|
|
3641
|
-
} catch (error) {
|
|
3642
|
-
console.error(error);
|
|
3643
|
-
return null;
|
|
3644
3539
|
}
|
|
3645
|
-
|
|
3540
|
+
if (!res.packages) {
|
|
3541
|
+
res.packages = /* @__PURE__ */ new Map();
|
|
3542
|
+
}
|
|
3543
|
+
if (!res.packages.has("aggregator_v3")) {
|
|
3544
|
+
res.packages.set(
|
|
3545
|
+
"aggregator_v3",
|
|
3546
|
+
"0x3864c7c59a4889fec05d1aae4bc9dba5a0e0940594b424fbed44cb3f6ac4c032"
|
|
3547
|
+
);
|
|
3548
|
+
}
|
|
3549
|
+
return res;
|
|
3550
|
+
}
|
|
3551
|
+
const code = processErrorStatusCode(data.code);
|
|
3552
|
+
const msg = getAggregatorServerErrorMessage(code, data.msg);
|
|
3553
|
+
const insufficientLiquidity = msg.includes("Insufficient liquidity");
|
|
3554
|
+
return {
|
|
3555
|
+
quoteID: "",
|
|
3556
|
+
amountIn: ZERO,
|
|
3557
|
+
amountOut: ZERO,
|
|
3558
|
+
paths: [],
|
|
3559
|
+
insufficientLiquidity,
|
|
3560
|
+
byAmountIn: params.byAmountIn,
|
|
3561
|
+
deviationRatio: 0,
|
|
3562
|
+
error: {
|
|
3563
|
+
code,
|
|
3564
|
+
msg
|
|
3565
|
+
}
|
|
3566
|
+
};
|
|
3646
3567
|
}
|
|
3647
|
-
function
|
|
3648
|
-
|
|
3568
|
+
async function getRouter(endpoint, apiKey, params) {
|
|
3569
|
+
try {
|
|
3649
3570
|
const {
|
|
3650
3571
|
from,
|
|
3651
3572
|
target,
|
|
@@ -3655,154 +3576,190 @@ function postRouterWithLiquidityChanges(endpoint, params) {
|
|
|
3655
3576
|
splitAlgorithm,
|
|
3656
3577
|
splitFactor,
|
|
3657
3578
|
splitCount,
|
|
3658
|
-
providers
|
|
3659
|
-
liquidityChanges
|
|
3579
|
+
providers
|
|
3660
3580
|
} = params;
|
|
3661
3581
|
const fromCoin = completionCoin(from);
|
|
3662
3582
|
const targetCoin = completionCoin(target);
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
from: fromCoin,
|
|
3667
|
-
target: targetCoin,
|
|
3668
|
-
amount: Number(amount.toString()),
|
|
3669
|
-
by_amount_in: byAmountIn,
|
|
3670
|
-
depth,
|
|
3671
|
-
split_algorithm: splitAlgorithm,
|
|
3672
|
-
split_factor: splitFactor,
|
|
3673
|
-
split_count: splitCount,
|
|
3674
|
-
providers: providersStr,
|
|
3675
|
-
liquidity_changes: liquidityChanges.map((change) => ({
|
|
3676
|
-
pool: change.poolID,
|
|
3677
|
-
tick_lower: change.ticklower,
|
|
3678
|
-
tick_upper: change.tickUpper,
|
|
3679
|
-
delta_liquidity: change.deltaLiquidity
|
|
3680
|
-
})),
|
|
3681
|
-
v: SDK_VERSION
|
|
3682
|
-
};
|
|
3683
|
-
try {
|
|
3684
|
-
const response = yield fetch(url, {
|
|
3685
|
-
method: "POST",
|
|
3686
|
-
headers: {
|
|
3687
|
-
"Content-Type": "application/json"
|
|
3688
|
-
},
|
|
3689
|
-
body: JSON.stringify(requestData)
|
|
3690
|
-
});
|
|
3691
|
-
return response;
|
|
3692
|
-
} catch (error) {
|
|
3693
|
-
console.error("Error:", error);
|
|
3694
|
-
return null;
|
|
3583
|
+
let url = `${endpoint}/find_routes?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
|
|
3584
|
+
if (depth) {
|
|
3585
|
+
url += `&depth=${depth}`;
|
|
3695
3586
|
}
|
|
3696
|
-
|
|
3697
|
-
}
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
if (providers && providers.length > 0) {
|
|
3587
|
+
if (splitAlgorithm) {
|
|
3588
|
+
url += `&split_algorithm=${splitAlgorithm}`;
|
|
3589
|
+
}
|
|
3590
|
+
if (splitFactor) {
|
|
3591
|
+
url += `&split_factor=${splitFactor}`;
|
|
3592
|
+
}
|
|
3593
|
+
if (splitCount) {
|
|
3594
|
+
url += `&split_count=${splitCount}`;
|
|
3595
|
+
}
|
|
3596
|
+
if (providers) {
|
|
3597
|
+
if (providers.length > 0) {
|
|
3708
3598
|
url += `&providers=${providers.join(",")}`;
|
|
3709
3599
|
}
|
|
3710
|
-
if (apiKey.length > 0) {
|
|
3711
|
-
url += `&apiKey=${apiKey}`;
|
|
3712
|
-
}
|
|
3713
|
-
url += `&v=${SDK_VERSION}`;
|
|
3714
|
-
const fromsData = froms.map((from) => ({
|
|
3715
|
-
coin_type: completionCoin(from.coinType),
|
|
3716
|
-
amount: Number(from.amount.toString())
|
|
3717
|
-
}));
|
|
3718
|
-
url += `&froms=${encodeURIComponent(JSON.stringify(fromsData))}`;
|
|
3719
|
-
const response = yield fetch(url);
|
|
3720
|
-
console.log("response", response);
|
|
3721
|
-
return response;
|
|
3722
|
-
} catch (error) {
|
|
3723
|
-
console.error(error);
|
|
3724
|
-
return null;
|
|
3725
3600
|
}
|
|
3726
|
-
|
|
3727
|
-
}
|
|
3728
|
-
function getMergeSwapResult(endpoint, apiKey, params, overlayFee, overlayFeeReceiver) {
|
|
3729
|
-
return __async(this, null, function* () {
|
|
3730
|
-
const response = yield getMergeSwapRouter(endpoint, apiKey, params);
|
|
3731
|
-
if (!response) {
|
|
3732
|
-
return null;
|
|
3601
|
+
if (apiKey.length > 0) {
|
|
3602
|
+
url += `&apiKey=${apiKey}`;
|
|
3733
3603
|
}
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3604
|
+
url += `&v=${SDK_VERSION}`;
|
|
3605
|
+
const response = await fetch(url);
|
|
3606
|
+
return response;
|
|
3607
|
+
} catch (error) {
|
|
3608
|
+
console.error(error);
|
|
3609
|
+
return null;
|
|
3610
|
+
}
|
|
3611
|
+
}
|
|
3612
|
+
async function postRouterWithLiquidityChanges(endpoint, params) {
|
|
3613
|
+
const {
|
|
3614
|
+
from,
|
|
3615
|
+
target,
|
|
3616
|
+
amount,
|
|
3617
|
+
byAmountIn,
|
|
3618
|
+
depth,
|
|
3619
|
+
splitAlgorithm,
|
|
3620
|
+
splitFactor,
|
|
3621
|
+
splitCount,
|
|
3622
|
+
providers,
|
|
3623
|
+
liquidityChanges
|
|
3624
|
+
} = params;
|
|
3625
|
+
const fromCoin = completionCoin(from);
|
|
3626
|
+
const targetCoin = completionCoin(target);
|
|
3627
|
+
const url = `${endpoint}/find_routes`;
|
|
3628
|
+
const providersStr = providers?.join(",");
|
|
3629
|
+
const requestData = {
|
|
3630
|
+
from: fromCoin,
|
|
3631
|
+
target: targetCoin,
|
|
3632
|
+
amount: Number(amount.toString()),
|
|
3633
|
+
by_amount_in: byAmountIn,
|
|
3634
|
+
depth,
|
|
3635
|
+
split_algorithm: splitAlgorithm,
|
|
3636
|
+
split_factor: splitFactor,
|
|
3637
|
+
split_count: splitCount,
|
|
3638
|
+
providers: providersStr,
|
|
3639
|
+
liquidity_changes: liquidityChanges.map((change) => ({
|
|
3640
|
+
pool: change.poolID,
|
|
3641
|
+
tick_lower: change.ticklower,
|
|
3642
|
+
tick_upper: change.tickUpper,
|
|
3643
|
+
delta_liquidity: change.deltaLiquidity
|
|
3644
|
+
})),
|
|
3645
|
+
v: SDK_VERSION
|
|
3646
|
+
};
|
|
3647
|
+
try {
|
|
3648
|
+
const response = await fetch(url, {
|
|
3649
|
+
method: "POST",
|
|
3650
|
+
headers: {
|
|
3651
|
+
"Content-Type": "application/json"
|
|
3652
|
+
},
|
|
3653
|
+
body: JSON.stringify(requestData)
|
|
3654
|
+
});
|
|
3655
|
+
return response;
|
|
3656
|
+
} catch (error) {
|
|
3657
|
+
console.error("Error:", error);
|
|
3658
|
+
return null;
|
|
3659
|
+
}
|
|
3660
|
+
}
|
|
3661
|
+
async function getMergeSwapRouter(endpoint, apiKey, params) {
|
|
3662
|
+
try {
|
|
3663
|
+
const { target, byAmountIn, depth, providers, froms } = params;
|
|
3664
|
+
const targetCoin = completionCoin(target);
|
|
3665
|
+
let url = `${endpoint}/multi_find_routes?target=${targetCoin}&by_amount_in=${byAmountIn}`;
|
|
3666
|
+
if (depth) {
|
|
3667
|
+
url += `&depth=${depth}`;
|
|
3668
|
+
}
|
|
3669
|
+
if (providers && providers.length > 0) {
|
|
3670
|
+
url += `&providers=${providers.join(",")}`;
|
|
3671
|
+
}
|
|
3672
|
+
if (apiKey.length > 0) {
|
|
3673
|
+
url += `&apiKey=${apiKey}`;
|
|
3674
|
+
}
|
|
3675
|
+
url += `&v=${SDK_VERSION}`;
|
|
3676
|
+
const fromsData = froms.map((from) => ({
|
|
3677
|
+
coin_type: completionCoin(from.coinType),
|
|
3678
|
+
amount: Number(from.amount.toString())
|
|
3679
|
+
}));
|
|
3680
|
+
url += `&froms=${encodeURIComponent(JSON.stringify(fromsData))}`;
|
|
3681
|
+
const response = await fetch(url);
|
|
3682
|
+
console.log("response", response);
|
|
3683
|
+
return response;
|
|
3684
|
+
} catch (error) {
|
|
3685
|
+
console.error(error);
|
|
3686
|
+
return null;
|
|
3687
|
+
}
|
|
3688
|
+
}
|
|
3689
|
+
async function getMergeSwapResult(endpoint, apiKey, params, overlayFee, overlayFeeReceiver) {
|
|
3690
|
+
const response = await getMergeSwapRouter(endpoint, apiKey, params);
|
|
3691
|
+
if (!response) {
|
|
3692
|
+
return null;
|
|
3693
|
+
}
|
|
3694
|
+
if (!response.ok) {
|
|
3695
|
+
let errorCode = 1004 /* BadRequest */;
|
|
3696
|
+
if (response.status === 429) {
|
|
3697
|
+
errorCode = 1001 /* RateLimitExceeded */;
|
|
3748
3698
|
}
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
totalAmountOut: ZERO,
|
|
3757
|
-
allRoutes: [],
|
|
3758
|
-
error: {
|
|
3759
|
-
code: code2,
|
|
3760
|
-
msg: msg2
|
|
3761
|
-
}
|
|
3762
|
-
};
|
|
3763
|
-
}
|
|
3764
|
-
const responseText = yield response.text();
|
|
3765
|
-
const data = JSONbig.parse(responseText);
|
|
3766
|
-
if (data.data != null) {
|
|
3767
|
-
console.log("data.data not null", data.data);
|
|
3768
|
-
const res = parseMergeSwapResponse(data.data);
|
|
3769
|
-
if (overlayFee > 0 && overlayFeeReceiver !== "0x0" && params.byAmountIn) {
|
|
3770
|
-
const overlayFeeAmount = res.totalAmountOut.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3771
|
-
res.totalAmountOut = res.totalAmountOut.sub(overlayFeeAmount);
|
|
3772
|
-
for (const route of res.allRoutes) {
|
|
3773
|
-
const routeFee = route.amountOut.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3774
|
-
route.amountOut = route.amountOut.sub(routeFee);
|
|
3775
|
-
}
|
|
3776
|
-
}
|
|
3777
|
-
if (!res.packages) {
|
|
3778
|
-
res.packages = /* @__PURE__ */ new Map();
|
|
3699
|
+
return {
|
|
3700
|
+
quoteID: "",
|
|
3701
|
+
totalAmountOut: ZERO,
|
|
3702
|
+
allRoutes: [],
|
|
3703
|
+
error: {
|
|
3704
|
+
code: errorCode,
|
|
3705
|
+
msg: getAggregatorServerErrorMessage(errorCode)
|
|
3779
3706
|
}
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
const
|
|
3707
|
+
};
|
|
3708
|
+
}
|
|
3709
|
+
if (!response.ok) {
|
|
3710
|
+
const code2 = processErrorStatusCode(response.status);
|
|
3711
|
+
const responseText2 = await response.text();
|
|
3712
|
+
const data2 = JSONbig__default.default.parse(responseText2);
|
|
3713
|
+
const msg2 = getAggregatorServerErrorMessage(code2, data2.msg);
|
|
3784
3714
|
return {
|
|
3785
3715
|
quoteID: "",
|
|
3786
3716
|
totalAmountOut: ZERO,
|
|
3787
3717
|
allRoutes: [],
|
|
3788
3718
|
error: {
|
|
3789
|
-
code,
|
|
3790
|
-
msg
|
|
3719
|
+
code: code2,
|
|
3720
|
+
msg: msg2
|
|
3791
3721
|
}
|
|
3792
3722
|
};
|
|
3793
|
-
}
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3723
|
+
}
|
|
3724
|
+
const responseText = await response.text();
|
|
3725
|
+
const data = JSONbig__default.default.parse(responseText);
|
|
3726
|
+
if (data.data != null) {
|
|
3727
|
+
console.log("data.data not null", data.data);
|
|
3728
|
+
const res = parseMergeSwapResponse(data.data);
|
|
3729
|
+
if (overlayFee > 0 && overlayFeeReceiver !== "0x0" && params.byAmountIn) {
|
|
3730
|
+
const overlayFeeAmount = res.totalAmountOut.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3731
|
+
res.totalAmountOut = res.totalAmountOut.sub(overlayFeeAmount);
|
|
3732
|
+
for (const route of res.allRoutes) {
|
|
3733
|
+
const routeFee = route.amountOut.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3734
|
+
route.amountOut = route.amountOut.sub(routeFee);
|
|
3735
|
+
}
|
|
3804
3736
|
}
|
|
3805
|
-
|
|
3737
|
+
if (!res.packages) {
|
|
3738
|
+
res.packages = /* @__PURE__ */ new Map();
|
|
3739
|
+
}
|
|
3740
|
+
return res;
|
|
3741
|
+
}
|
|
3742
|
+
const code = processErrorStatusCode(data.code);
|
|
3743
|
+
const msg = getAggregatorServerErrorMessage(code, data.msg);
|
|
3744
|
+
return {
|
|
3745
|
+
quoteID: "",
|
|
3746
|
+
totalAmountOut: ZERO,
|
|
3747
|
+
allRoutes: [],
|
|
3748
|
+
error: {
|
|
3749
|
+
code,
|
|
3750
|
+
msg
|
|
3751
|
+
}
|
|
3752
|
+
};
|
|
3753
|
+
}
|
|
3754
|
+
async function getDeepbookV3Config(endpoint) {
|
|
3755
|
+
const url = `${endpoint}/deepbookv3_config`;
|
|
3756
|
+
try {
|
|
3757
|
+
const response = await fetch(url);
|
|
3758
|
+
return response.json();
|
|
3759
|
+
} catch (error) {
|
|
3760
|
+
console.error("Error:", error);
|
|
3761
|
+
return null;
|
|
3762
|
+
}
|
|
3806
3763
|
}
|
|
3807
3764
|
function processFlattenRoutes(routerData) {
|
|
3808
3765
|
const paths = routerData.paths;
|
|
@@ -6099,7 +6056,7 @@ function CalculateAmountLimitByDecimal(expectAmount, byAmountIn, slippage) {
|
|
|
6099
6056
|
var CetusRouter = class {
|
|
6100
6057
|
constructor(env, partner) {
|
|
6101
6058
|
this.globalConfig = env === 0 /* Mainnet */ ? "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f" : "0xc6273f844b4bc258952c4e477697aa12c918c8e08106fac6b934811298c9820a";
|
|
6102
|
-
this.partner = partner
|
|
6059
|
+
this.partner = partner ?? (env === 0 /* Mainnet */ ? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b" : "0xfdc30896f88f74544fd507722d3bf52e46b06412ba8241ba0e854cbc65f8d85f");
|
|
6103
6060
|
}
|
|
6104
6061
|
// By amount in
|
|
6105
6062
|
swap(txb, flattenedPath, swapContext, _extends) {
|
|
@@ -6130,7 +6087,7 @@ var CetusRouter = class {
|
|
|
6130
6087
|
txb.object(this.partner),
|
|
6131
6088
|
txb.pure.bool(swapData.direction),
|
|
6132
6089
|
txb.pure.u64(swapData.amountIn),
|
|
6133
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6090
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6134
6091
|
];
|
|
6135
6092
|
txb.moveCall({
|
|
6136
6093
|
target: `${swapData.publishedAt}::cetus::swap`,
|
|
@@ -6149,7 +6106,7 @@ var CetusRouter = class {
|
|
|
6149
6106
|
txb.pure.bool(path.direction),
|
|
6150
6107
|
txb.pure.bool(false),
|
|
6151
6108
|
// isExactIn
|
|
6152
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6109
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6153
6110
|
];
|
|
6154
6111
|
const [coinAType, coinBType] = path.direction ? [path.from, path.target] : [path.target, path.from];
|
|
6155
6112
|
const [flashReceipt, repayAmount] = txb.moveCall({
|
|
@@ -6232,7 +6189,7 @@ var KriyaV3Router = class {
|
|
|
6232
6189
|
txb.object(this.version),
|
|
6233
6190
|
txb.pure.bool(swapData.direction),
|
|
6234
6191
|
txb.pure.u64(swapData.amountIn),
|
|
6235
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6192
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6236
6193
|
];
|
|
6237
6194
|
txb.moveCall({
|
|
6238
6195
|
target: `${swapData.publishedAt}::kriya_clmm::swap`,
|
|
@@ -6279,7 +6236,7 @@ var FlowxV3Router = class {
|
|
|
6279
6236
|
txb.pure.u64(swapData.feeRate),
|
|
6280
6237
|
txb.pure.u64(swapData.amountIn),
|
|
6281
6238
|
txb.pure.bool(swapData.direction),
|
|
6282
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6239
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6283
6240
|
];
|
|
6284
6241
|
txb.moveCall({
|
|
6285
6242
|
target: `${swapData.publishedAt}::flowx_clmm::swap`,
|
|
@@ -6331,7 +6288,7 @@ var TurbosRouter = class {
|
|
|
6331
6288
|
txb.object(this.versioned),
|
|
6332
6289
|
txb.pure.bool(swapData.direction),
|
|
6333
6290
|
txb.pure.u64(swapData.amountIn),
|
|
6334
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6291
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6335
6292
|
];
|
|
6336
6293
|
txb.moveCall({
|
|
6337
6294
|
target: `${swapData.publishedAt}::turbos::swap`,
|
|
@@ -6374,7 +6331,7 @@ var BluefinRouter = class {
|
|
|
6374
6331
|
txb.object(swapData.poolId),
|
|
6375
6332
|
txb.pure.bool(swapData.direction),
|
|
6376
6333
|
txb.pure.u64(swapData.amountIn),
|
|
6377
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6334
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6378
6335
|
];
|
|
6379
6336
|
txb.moveCall({
|
|
6380
6337
|
target: `${swapData.publishedAt}::bluefin::swap`,
|
|
@@ -6417,7 +6374,7 @@ var MomentumRouter = class {
|
|
|
6417
6374
|
txb.pure.bool(swapData.direction),
|
|
6418
6375
|
txb.pure.u64(swapData.amountIn),
|
|
6419
6376
|
txb.object(this.version),
|
|
6420
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6377
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6421
6378
|
];
|
|
6422
6379
|
txb.moveCall({
|
|
6423
6380
|
target: `${swapData.publishedAt}::momentum::swap`,
|
|
@@ -6460,7 +6417,7 @@ var MagmaRouter = class {
|
|
|
6460
6417
|
txb.object(swapData.poolId),
|
|
6461
6418
|
txb.pure.bool(swapData.direction),
|
|
6462
6419
|
txb.pure.u64(swapData.amountIn),
|
|
6463
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6420
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6464
6421
|
];
|
|
6465
6422
|
txb.moveCall({
|
|
6466
6423
|
target: `${swapData.publishedAt}::magma::swap`,
|
|
@@ -6613,17 +6570,16 @@ var DeepbookV3Router = class {
|
|
|
6613
6570
|
this.executeSwapContract(txb, swapData, swapContext, _extends);
|
|
6614
6571
|
}
|
|
6615
6572
|
prepareSwapData(flattenedPath) {
|
|
6616
|
-
var _a, _b, _c, _d, _e;
|
|
6617
6573
|
if (flattenedPath.path.publishedAt == null) {
|
|
6618
6574
|
throw new Error("DeepBook V3 not set publishedAt");
|
|
6619
6575
|
}
|
|
6620
6576
|
const path = flattenedPath.path;
|
|
6621
6577
|
const [coinAType, coinBType] = path.direction ? [path.from, path.target] : [path.target, path.from];
|
|
6622
6578
|
const amountIn = flattenedPath.isLastUseOfIntermediateToken ? AGGREGATOR_V3_CONFIG.MAX_AMOUNT_IN : path.amountIn;
|
|
6623
|
-
const needAddDeepPricePoint =
|
|
6624
|
-
const referencePoolId =
|
|
6625
|
-
const referencePoolBaseType =
|
|
6626
|
-
const referencePoolQuoteType =
|
|
6579
|
+
const needAddDeepPricePoint = path.extendedDetails?.deepbookv3_need_add_deep_price_point ?? false;
|
|
6580
|
+
const referencePoolId = path.extendedDetails?.deepbookv3_reference_pool_id;
|
|
6581
|
+
const referencePoolBaseType = path.extendedDetails?.deepbookv3_reference_pool_base_type;
|
|
6582
|
+
const referencePoolQuoteType = path.extendedDetails?.deepbookv3_reference_pool_quote_type;
|
|
6627
6583
|
if (needAddDeepPricePoint) {
|
|
6628
6584
|
if (!referencePoolId) {
|
|
6629
6585
|
throw new Error(
|
|
@@ -6666,12 +6622,12 @@ var DeepbookV3Router = class {
|
|
|
6666
6622
|
arguments: [
|
|
6667
6623
|
txb.object(swapData.poolId),
|
|
6668
6624
|
txb.object(swapData.referencePoolId),
|
|
6669
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6625
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6670
6626
|
]
|
|
6671
6627
|
});
|
|
6672
6628
|
}
|
|
6673
6629
|
executeSwapContract(txb, swapData, swapContext, _extends) {
|
|
6674
|
-
const deepCoin =
|
|
6630
|
+
const deepCoin = _extends?.deepbookv3DeepFee || txb.moveCall({
|
|
6675
6631
|
target: "0x2::coin::zero",
|
|
6676
6632
|
typeArguments: [this.getDeepFeeType()]
|
|
6677
6633
|
});
|
|
@@ -6682,7 +6638,7 @@ var DeepbookV3Router = class {
|
|
|
6682
6638
|
txb.pure.u64(swapData.amountIn),
|
|
6683
6639
|
txb.pure.bool(swapData.direction),
|
|
6684
6640
|
deepCoin,
|
|
6685
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6641
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6686
6642
|
];
|
|
6687
6643
|
txb.moveCall({
|
|
6688
6644
|
target: `${swapData.publishedAt}::deepbookv3::swap`,
|
|
@@ -6712,7 +6668,6 @@ var AftermathRouter = class {
|
|
|
6712
6668
|
this.executeSwapContract(txb, swapData, swapContext);
|
|
6713
6669
|
}
|
|
6714
6670
|
prepareSwapData(flattenedPath) {
|
|
6715
|
-
var _a, _b;
|
|
6716
6671
|
if (flattenedPath.path.publishedAt == null) {
|
|
6717
6672
|
throw new Error("Aftermath not set publishedAt");
|
|
6718
6673
|
}
|
|
@@ -6722,7 +6677,7 @@ var AftermathRouter = class {
|
|
|
6722
6677
|
return {
|
|
6723
6678
|
coinAType,
|
|
6724
6679
|
coinBType,
|
|
6725
|
-
feeType:
|
|
6680
|
+
feeType: path.extendedDetails?.aftermath_lp_supply_type || path.extendedDetails?.aftermath_lp_supply_type || "0x2::sui::SUI",
|
|
6726
6681
|
// Use LP supply type from path (handle both camelCase and snake_case)
|
|
6727
6682
|
direction: path.direction,
|
|
6728
6683
|
amountIn,
|
|
@@ -6819,7 +6774,7 @@ var SteammCPMMRouter = class {
|
|
|
6819
6774
|
txb.object(swapData.extendedDetails.steamm_lending_market),
|
|
6820
6775
|
txb.pure.bool(swapData.direction),
|
|
6821
6776
|
txb.pure.u64(swapData.amountIn),
|
|
6822
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6777
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6823
6778
|
];
|
|
6824
6779
|
txb.moveCall({
|
|
6825
6780
|
target: `${swapData.publishedAt}::steamm_cpmm::swap`,
|
|
@@ -6878,7 +6833,7 @@ var ScallopRouter = class {
|
|
|
6878
6833
|
txb.object(this.marketData),
|
|
6879
6834
|
txb.object(swapData.scallopScoinTreasury),
|
|
6880
6835
|
txb.pure.u64(swapData.amountIn),
|
|
6881
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6836
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6882
6837
|
];
|
|
6883
6838
|
const func = swapData.direction ? "swap_a2b" : "swap_b2a";
|
|
6884
6839
|
txb.moveCall({
|
|
@@ -6994,7 +6949,7 @@ var HaedalPmmRouter = class {
|
|
|
6994
6949
|
// amount_in
|
|
6995
6950
|
txb.pure.bool(swapData.a2b),
|
|
6996
6951
|
// a2b
|
|
6997
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6952
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6998
6953
|
// clock
|
|
6999
6954
|
];
|
|
7000
6955
|
txb.moveCall({
|
|
@@ -7068,7 +7023,7 @@ var ObricRouter = class {
|
|
|
7068
7023
|
txb.object(this.pythStateObjectId),
|
|
7069
7024
|
txb.object(swapData.coinAPriceInfoObjectId),
|
|
7070
7025
|
txb.object(swapData.coinBPriceInfoObjectId),
|
|
7071
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7026
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7072
7027
|
];
|
|
7073
7028
|
txb.moveCall({
|
|
7074
7029
|
target: `${swapData.publishedAt}::obric::swap`,
|
|
@@ -7143,7 +7098,7 @@ var SevenkRouter = class {
|
|
|
7143
7098
|
txb.object(swapData.coinAOracleId),
|
|
7144
7099
|
holder,
|
|
7145
7100
|
txb.object(swapData.coinAPriceId),
|
|
7146
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7101
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7147
7102
|
]
|
|
7148
7103
|
});
|
|
7149
7104
|
txb.moveCall({
|
|
@@ -7153,7 +7108,7 @@ var SevenkRouter = class {
|
|
|
7153
7108
|
txb.object(swapData.coinBOracleId),
|
|
7154
7109
|
holder,
|
|
7155
7110
|
txb.object(swapData.coinBPriceId),
|
|
7156
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7111
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7157
7112
|
]
|
|
7158
7113
|
});
|
|
7159
7114
|
const args = [
|
|
@@ -7250,7 +7205,7 @@ var SteammOmmRouter = class {
|
|
|
7250
7205
|
txb.object(extendedDetails.steammOracleRegistryId),
|
|
7251
7206
|
txb.object(swapData.priceInfoObjectIdA),
|
|
7252
7207
|
txb.pure.u64(extendedDetails.steammOracleIndexA),
|
|
7253
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7208
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7254
7209
|
]
|
|
7255
7210
|
});
|
|
7256
7211
|
const oraclePriceUpdateB = txb.moveCall({
|
|
@@ -7260,7 +7215,7 @@ var SteammOmmRouter = class {
|
|
|
7260
7215
|
txb.object(extendedDetails.steammOracleRegistryId),
|
|
7261
7216
|
txb.object(swapData.priceInfoObjectIdB),
|
|
7262
7217
|
txb.pure.u64(extendedDetails.steammOracleIndexB),
|
|
7263
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7218
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7264
7219
|
]
|
|
7265
7220
|
});
|
|
7266
7221
|
const args = [
|
|
@@ -7272,7 +7227,7 @@ var SteammOmmRouter = class {
|
|
|
7272
7227
|
oraclePriceUpdateA,
|
|
7273
7228
|
oraclePriceUpdateB,
|
|
7274
7229
|
txb.pure.u64(swapData.amountIn),
|
|
7275
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7230
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7276
7231
|
];
|
|
7277
7232
|
txb.moveCall({
|
|
7278
7233
|
target: `${swapData.publishedAt}::steamm_omm::${swapData.func}`,
|
|
@@ -7368,7 +7323,7 @@ var SteammOmmV2Router = class {
|
|
|
7368
7323
|
txb.object(extendedDetails.steamm_oracle_registry_id),
|
|
7369
7324
|
txb.object(swapData.priceInfoObjectIdA),
|
|
7370
7325
|
txb.pure.u64(extendedDetails.steamm_oracle_index_a),
|
|
7371
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7326
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7372
7327
|
]
|
|
7373
7328
|
});
|
|
7374
7329
|
const oraclePriceUpdateB = txb.moveCall({
|
|
@@ -7378,7 +7333,7 @@ var SteammOmmV2Router = class {
|
|
|
7378
7333
|
txb.object(extendedDetails.steamm_oracle_registry_id),
|
|
7379
7334
|
txb.object(swapData.priceInfoObjectIdB),
|
|
7380
7335
|
txb.pure.u64(extendedDetails.steamm_oracle_index_b),
|
|
7381
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7336
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7382
7337
|
]
|
|
7383
7338
|
});
|
|
7384
7339
|
const args = [
|
|
@@ -7391,7 +7346,7 @@ var SteammOmmV2Router = class {
|
|
|
7391
7346
|
oraclePriceUpdateB,
|
|
7392
7347
|
txb.pure.bool(swapData.direction),
|
|
7393
7348
|
txb.pure.u64(swapData.amountIn),
|
|
7394
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7349
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7395
7350
|
];
|
|
7396
7351
|
txb.moveCall({
|
|
7397
7352
|
target: `${swapData.publishedAt}::steamm_omm_v2::swap`,
|
|
@@ -7495,7 +7450,7 @@ var MetastableRouter = class {
|
|
|
7495
7450
|
}
|
|
7496
7451
|
depositArgs.push(txb.object(priceId));
|
|
7497
7452
|
}
|
|
7498
|
-
depositArgs.push(txb.object(SUI_CLOCK_OBJECT_ID));
|
|
7453
|
+
depositArgs.push(txb.object(utils.SUI_CLOCK_OBJECT_ID));
|
|
7499
7454
|
break;
|
|
7500
7455
|
}
|
|
7501
7456
|
default:
|
|
@@ -7656,7 +7611,7 @@ var AfsuiRouter = class {
|
|
|
7656
7611
|
txb.object("0x5"),
|
|
7657
7612
|
// SuiSystemState
|
|
7658
7613
|
txb.object(this.referVault),
|
|
7659
|
-
txb.
|
|
7614
|
+
txb.pure.address(this.validator),
|
|
7660
7615
|
txb.pure.bool(swapData.direction),
|
|
7661
7616
|
txb.pure.u64(swapData.amountIn)
|
|
7662
7617
|
];
|
|
@@ -7746,7 +7701,7 @@ var HawalRouter = class {
|
|
|
7746
7701
|
swapContext,
|
|
7747
7702
|
txb.object(this.staking),
|
|
7748
7703
|
txb.object(swapData.poolId),
|
|
7749
|
-
txb.
|
|
7704
|
+
txb.pure.address(this.validator),
|
|
7750
7705
|
txb.pure.bool(swapData.direction),
|
|
7751
7706
|
txb.pure.u64(swapData.amountIn)
|
|
7752
7707
|
];
|
|
@@ -7866,6 +7821,229 @@ function transferOrDestroyCoin(params, txb) {
|
|
|
7866
7821
|
arguments: [coin]
|
|
7867
7822
|
});
|
|
7868
7823
|
}
|
|
7824
|
+
var MAX_ARGUMENT_SIZE = 16 * 1024;
|
|
7825
|
+
var PythAdapter = class {
|
|
7826
|
+
constructor(client, pythStateId, wormholeStateId, hermesUrls) {
|
|
7827
|
+
this.priceFeedObjectIdCache = /* @__PURE__ */ new Map();
|
|
7828
|
+
this.client = client;
|
|
7829
|
+
this.pythStateId = pythStateId;
|
|
7830
|
+
this.wormholeStateId = wormholeStateId;
|
|
7831
|
+
const urls = [...hermesUrls];
|
|
7832
|
+
if (!urls.includes("https://hermes.pyth.network")) {
|
|
7833
|
+
urls.push("https://hermes.pyth.network");
|
|
7834
|
+
}
|
|
7835
|
+
this.hermesClients = urls.map(
|
|
7836
|
+
(url) => new hermesClient.HermesClient(url, { timeout: 3e3 })
|
|
7837
|
+
);
|
|
7838
|
+
}
|
|
7839
|
+
async getPriceFeedsUpdateData(priceIDs) {
|
|
7840
|
+
let lastError = null;
|
|
7841
|
+
for (const hermes of this.hermesClients) {
|
|
7842
|
+
try {
|
|
7843
|
+
const response = await hermes.getLatestPriceUpdates(priceIDs, {
|
|
7844
|
+
encoding: "hex"
|
|
7845
|
+
});
|
|
7846
|
+
return response.binary.data.map((hex) => Buffer.from(hex, "hex"));
|
|
7847
|
+
} catch (e) {
|
|
7848
|
+
lastError = e;
|
|
7849
|
+
continue;
|
|
7850
|
+
}
|
|
7851
|
+
}
|
|
7852
|
+
throw new Error(
|
|
7853
|
+
`All Pyth Hermes endpoints are unavailable. Detailed error: ${lastError?.message}`
|
|
7854
|
+
);
|
|
7855
|
+
}
|
|
7856
|
+
async getBaseUpdateFee() {
|
|
7857
|
+
if (this.baseUpdateFee !== void 0) {
|
|
7858
|
+
return this.baseUpdateFee;
|
|
7859
|
+
}
|
|
7860
|
+
const { object } = await this.client.getObject({
|
|
7861
|
+
objectId: this.pythStateId,
|
|
7862
|
+
include: { json: true }
|
|
7863
|
+
});
|
|
7864
|
+
const json = object.json;
|
|
7865
|
+
if (!json) {
|
|
7866
|
+
throw new Error("Unable to fetch pyth state object");
|
|
7867
|
+
}
|
|
7868
|
+
this.baseUpdateFee = Number(json.base_update_fee);
|
|
7869
|
+
return this.baseUpdateFee;
|
|
7870
|
+
}
|
|
7871
|
+
async getPackageId(objectId) {
|
|
7872
|
+
const { object } = await this.client.getObject({
|
|
7873
|
+
objectId,
|
|
7874
|
+
include: { json: true }
|
|
7875
|
+
});
|
|
7876
|
+
const json = object.json;
|
|
7877
|
+
if (!json) {
|
|
7878
|
+
throw new Error(`Cannot fetch package id for object ${objectId}`);
|
|
7879
|
+
}
|
|
7880
|
+
if ("upgrade_cap" in json) {
|
|
7881
|
+
return json.upgrade_cap.package;
|
|
7882
|
+
}
|
|
7883
|
+
throw new Error("upgrade_cap not found");
|
|
7884
|
+
}
|
|
7885
|
+
async getWormholePackageId() {
|
|
7886
|
+
if (!this.wormholePackageId) {
|
|
7887
|
+
this.wormholePackageId = await this.getPackageId(this.wormholeStateId);
|
|
7888
|
+
}
|
|
7889
|
+
return this.wormholePackageId;
|
|
7890
|
+
}
|
|
7891
|
+
async getPythPackageId() {
|
|
7892
|
+
if (!this.pythPackageId) {
|
|
7893
|
+
this.pythPackageId = await this.getPackageId(this.pythStateId);
|
|
7894
|
+
}
|
|
7895
|
+
return this.pythPackageId;
|
|
7896
|
+
}
|
|
7897
|
+
async getPriceFeedObjectId(feedId) {
|
|
7898
|
+
const normalizedFeedId = feedId.replace("0x", "");
|
|
7899
|
+
if (this.priceFeedObjectIdCache.has(normalizedFeedId)) {
|
|
7900
|
+
return this.priceFeedObjectIdCache.get(normalizedFeedId);
|
|
7901
|
+
}
|
|
7902
|
+
const { id: tableId, fieldType } = await this.getPriceTableInfo();
|
|
7903
|
+
const feedIdBytes = Buffer.from(normalizedFeedId, "hex");
|
|
7904
|
+
try {
|
|
7905
|
+
const PriceIdentifier = bcs.bcs.struct("PriceIdentifier", {
|
|
7906
|
+
bytes: bcs.bcs.vector(bcs.bcs.u8())
|
|
7907
|
+
});
|
|
7908
|
+
const bcsBytes = PriceIdentifier.serialize({ bytes: Array.from(feedIdBytes) }).toBytes();
|
|
7909
|
+
const result = await this.client.getDynamicField({
|
|
7910
|
+
parentId: tableId,
|
|
7911
|
+
name: {
|
|
7912
|
+
type: fieldType,
|
|
7913
|
+
bcs: bcsBytes
|
|
7914
|
+
}
|
|
7915
|
+
});
|
|
7916
|
+
const valueBcs = result.dynamicField.value.bcs;
|
|
7917
|
+
const valueBytes = valueBcs instanceof Uint8Array ? valueBcs : new Uint8Array(Object.values(valueBcs));
|
|
7918
|
+
const objectId = "0x" + Array.from(valueBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
7919
|
+
this.priceFeedObjectIdCache.set(normalizedFeedId, objectId);
|
|
7920
|
+
return objectId;
|
|
7921
|
+
} catch {
|
|
7922
|
+
return void 0;
|
|
7923
|
+
}
|
|
7924
|
+
}
|
|
7925
|
+
async getPriceTableInfo() {
|
|
7926
|
+
if (this.priceTableInfo !== void 0) {
|
|
7927
|
+
return this.priceTableInfo;
|
|
7928
|
+
}
|
|
7929
|
+
let cursor = null;
|
|
7930
|
+
let hasNextPage = true;
|
|
7931
|
+
while (hasNextPage) {
|
|
7932
|
+
const dynamicFields = await this.client.listDynamicFields({
|
|
7933
|
+
parentId: this.pythStateId,
|
|
7934
|
+
cursor
|
|
7935
|
+
});
|
|
7936
|
+
for (const field of dynamicFields.dynamicFields) {
|
|
7937
|
+
if (field.name.type === "vector<u8>") {
|
|
7938
|
+
const objectId = field.$kind === "DynamicObject" && field.childId ? field.childId : field.fieldId;
|
|
7939
|
+
const fieldObj = await this.client.getObject({
|
|
7940
|
+
objectId,
|
|
7941
|
+
include: { json: true }
|
|
7942
|
+
});
|
|
7943
|
+
const type = fieldObj.object.type;
|
|
7944
|
+
if (type.includes("table::Table")) {
|
|
7945
|
+
const innerTypes = type.replace(/.*table::Table</, "").replace(/>$/, "");
|
|
7946
|
+
const fieldType = innerTypes.split(",")[0].trim();
|
|
7947
|
+
this.priceTableInfo = { id: fieldObj.object.objectId, fieldType };
|
|
7948
|
+
return this.priceTableInfo;
|
|
7949
|
+
}
|
|
7950
|
+
}
|
|
7951
|
+
}
|
|
7952
|
+
hasNextPage = dynamicFields.hasNextPage;
|
|
7953
|
+
cursor = dynamicFields.cursor;
|
|
7954
|
+
}
|
|
7955
|
+
throw new Error(
|
|
7956
|
+
"Price Table not found, contract may not be initialized"
|
|
7957
|
+
);
|
|
7958
|
+
}
|
|
7959
|
+
extractVaaBytesFromAccumulatorMessage(accumulatorMessage) {
|
|
7960
|
+
const trailingPayloadSize = accumulatorMessage.readUint8(6);
|
|
7961
|
+
const vaaSizeOffset = 7 + trailingPayloadSize + 1;
|
|
7962
|
+
const vaaSize = accumulatorMessage.readUint16BE(vaaSizeOffset);
|
|
7963
|
+
const vaaOffset = vaaSizeOffset + 2;
|
|
7964
|
+
return accumulatorMessage.subarray(vaaOffset, vaaOffset + vaaSize);
|
|
7965
|
+
}
|
|
7966
|
+
async verifyVaas(vaas, tx) {
|
|
7967
|
+
const wormholePackageId = await this.getWormholePackageId();
|
|
7968
|
+
const verifiedVaas = [];
|
|
7969
|
+
for (const vaa of vaas) {
|
|
7970
|
+
const [verifiedVaa] = tx.moveCall({
|
|
7971
|
+
target: `${wormholePackageId}::vaa::parse_and_verify`,
|
|
7972
|
+
arguments: [
|
|
7973
|
+
tx.object(this.wormholeStateId),
|
|
7974
|
+
tx.pure(
|
|
7975
|
+
bcs.bcs.vector(bcs.bcs.u8()).serialize(Array.from(vaa), { maxSize: MAX_ARGUMENT_SIZE }).toBytes()
|
|
7976
|
+
),
|
|
7977
|
+
tx.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7978
|
+
]
|
|
7979
|
+
});
|
|
7980
|
+
verifiedVaas.push(verifiedVaa);
|
|
7981
|
+
}
|
|
7982
|
+
return verifiedVaas;
|
|
7983
|
+
}
|
|
7984
|
+
async verifyVaasAndGetHotPotato(tx, updates, packageId) {
|
|
7985
|
+
if (updates.length > 1) {
|
|
7986
|
+
throw new Error(
|
|
7987
|
+
"SDK does not support sending multiple accumulator messages in a single transaction"
|
|
7988
|
+
);
|
|
7989
|
+
}
|
|
7990
|
+
const vaa = this.extractVaaBytesFromAccumulatorMessage(updates[0]);
|
|
7991
|
+
const verifiedVaas = await this.verifyVaas([vaa], tx);
|
|
7992
|
+
const [priceUpdatesHotPotato] = tx.moveCall({
|
|
7993
|
+
target: `${packageId}::pyth::create_authenticated_price_infos_using_accumulator`,
|
|
7994
|
+
arguments: [
|
|
7995
|
+
tx.object(this.pythStateId),
|
|
7996
|
+
tx.pure(
|
|
7997
|
+
bcs.bcs.vector(bcs.bcs.u8()).serialize(Array.from(updates[0]), { maxSize: MAX_ARGUMENT_SIZE }).toBytes()
|
|
7998
|
+
),
|
|
7999
|
+
verifiedVaas[0],
|
|
8000
|
+
tx.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
8001
|
+
]
|
|
8002
|
+
});
|
|
8003
|
+
return priceUpdatesHotPotato;
|
|
8004
|
+
}
|
|
8005
|
+
async updatePriceFeeds(tx, updates, feedIds) {
|
|
8006
|
+
const packageId = await this.getPythPackageId();
|
|
8007
|
+
let priceUpdatesHotPotato = await this.verifyVaasAndGetHotPotato(
|
|
8008
|
+
tx,
|
|
8009
|
+
updates,
|
|
8010
|
+
packageId
|
|
8011
|
+
);
|
|
8012
|
+
const baseUpdateFee = await this.getBaseUpdateFee();
|
|
8013
|
+
const coins = tx.splitCoins(
|
|
8014
|
+
tx.gas,
|
|
8015
|
+
feedIds.map(() => tx.pure.u64(baseUpdateFee))
|
|
8016
|
+
);
|
|
8017
|
+
const priceInfoObjects = [];
|
|
8018
|
+
let coinId = 0;
|
|
8019
|
+
for (const feedId of feedIds) {
|
|
8020
|
+
const priceInfoObjectId = await this.getPriceFeedObjectId(feedId);
|
|
8021
|
+
if (!priceInfoObjectId) {
|
|
8022
|
+
throw new Error(
|
|
8023
|
+
`Price feed ${feedId} not found, please create it first`
|
|
8024
|
+
);
|
|
8025
|
+
}
|
|
8026
|
+
priceInfoObjects.push(priceInfoObjectId);
|
|
8027
|
+
[priceUpdatesHotPotato] = tx.moveCall({
|
|
8028
|
+
target: `${packageId}::pyth::update_single_price_feed`,
|
|
8029
|
+
arguments: [
|
|
8030
|
+
tx.object(this.pythStateId),
|
|
8031
|
+
priceUpdatesHotPotato,
|
|
8032
|
+
tx.object(priceInfoObjectId),
|
|
8033
|
+
coins[coinId],
|
|
8034
|
+
tx.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
8035
|
+
]
|
|
8036
|
+
});
|
|
8037
|
+
coinId++;
|
|
8038
|
+
}
|
|
8039
|
+
tx.moveCall({
|
|
8040
|
+
target: `${packageId}::hot_potato_vector::destroy`,
|
|
8041
|
+
arguments: [priceUpdatesHotPotato],
|
|
8042
|
+
typeArguments: [`${packageId}::price_info::PriceInfo`]
|
|
8043
|
+
});
|
|
8044
|
+
return priceInfoObjects;
|
|
8045
|
+
}
|
|
8046
|
+
};
|
|
7869
8047
|
|
|
7870
8048
|
// src/utils/uuid.ts
|
|
7871
8049
|
function generateDowngradeUuid6() {
|
|
@@ -7924,7 +8102,7 @@ function extractTimestampFromDowngradeUuid6(uuid) {
|
|
|
7924
8102
|
const timestampHex = timeHigh + timeMid;
|
|
7925
8103
|
const timestamp = parseInt(timestampHex, 16);
|
|
7926
8104
|
return isNaN(timestamp) ? null : timestamp;
|
|
7927
|
-
} catch
|
|
8105
|
+
} catch {
|
|
7928
8106
|
return null;
|
|
7929
8107
|
}
|
|
7930
8108
|
}
|
|
@@ -7940,72 +8118,60 @@ function processEndpoint(endpoint) {
|
|
|
7940
8118
|
}
|
|
7941
8119
|
|
|
7942
8120
|
// src/utils/account_cap.ts
|
|
7943
|
-
function getOrCreateAccountCap(txb, client, owner) {
|
|
7944
|
-
|
|
7945
|
-
|
|
7946
|
-
if (accountCapStr !== null) {
|
|
7947
|
-
return {
|
|
7948
|
-
accountCap: txb.object(accountCapStr),
|
|
7949
|
-
isCreate: false
|
|
7950
|
-
};
|
|
7951
|
-
}
|
|
7952
|
-
const accountCap = txb.moveCall({
|
|
7953
|
-
target: `${DEEPBOOK_PUBLISHED_AT}::${DEEPBOOK_CLOB_V2_MODULE}::create_account`,
|
|
7954
|
-
typeArguments: [],
|
|
7955
|
-
arguments: []
|
|
7956
|
-
});
|
|
8121
|
+
async function getOrCreateAccountCap(txb, client, owner) {
|
|
8122
|
+
let accountCapStr = await getAccountCap(client, owner);
|
|
8123
|
+
if (accountCapStr !== null) {
|
|
7957
8124
|
return {
|
|
7958
|
-
accountCap,
|
|
7959
|
-
isCreate:
|
|
8125
|
+
accountCap: txb.object(accountCapStr),
|
|
8126
|
+
isCreate: false
|
|
7960
8127
|
};
|
|
8128
|
+
}
|
|
8129
|
+
const accountCap = txb.moveCall({
|
|
8130
|
+
target: `${DEEPBOOK_PUBLISHED_AT}::${DEEPBOOK_CLOB_V2_MODULE}::create_account`,
|
|
8131
|
+
typeArguments: [],
|
|
8132
|
+
arguments: []
|
|
7961
8133
|
});
|
|
8134
|
+
return {
|
|
8135
|
+
accountCap,
|
|
8136
|
+
isCreate: true
|
|
8137
|
+
};
|
|
7962
8138
|
}
|
|
7963
|
-
function getAccountCap(client, owner) {
|
|
7964
|
-
|
|
7965
|
-
|
|
7966
|
-
|
|
7967
|
-
|
|
7968
|
-
|
|
7969
|
-
|
|
7970
|
-
|
|
7971
|
-
|
|
7972
|
-
|
|
7973
|
-
|
|
7974
|
-
|
|
7975
|
-
module: DEEPBOOK_CUSTODIAN_V2_MODULE
|
|
7976
|
-
}
|
|
7977
|
-
}
|
|
7978
|
-
});
|
|
7979
|
-
if (ownedObjects != null && ownedObjects.data != null) {
|
|
7980
|
-
if (ownedObjects.data.length !== 0) {
|
|
7981
|
-
return ownedObjects.data[0].data.objectId;
|
|
7982
|
-
}
|
|
7983
|
-
if (ownedObjects.data.length < 50) {
|
|
7984
|
-
break;
|
|
7985
|
-
}
|
|
7986
|
-
} else {
|
|
7987
|
-
break;
|
|
7988
|
-
}
|
|
8139
|
+
async function getAccountCap(client, owner) {
|
|
8140
|
+
const limit = 50;
|
|
8141
|
+
let cursor = null;
|
|
8142
|
+
while (true) {
|
|
8143
|
+
const ownedObjects = await client.listOwnedObjects({
|
|
8144
|
+
owner,
|
|
8145
|
+
cursor,
|
|
8146
|
+
limit,
|
|
8147
|
+
type: `${DEEPBOOK_PACKAGE_ID}::${DEEPBOOK_CUSTODIAN_V2_MODULE}::AccountCap`
|
|
8148
|
+
});
|
|
8149
|
+
if (ownedObjects.objects.length !== 0) {
|
|
8150
|
+
return ownedObjects.objects[0].objectId;
|
|
7989
8151
|
}
|
|
7990
|
-
|
|
7991
|
-
|
|
8152
|
+
if (!ownedObjects.hasNextPage) {
|
|
8153
|
+
break;
|
|
8154
|
+
}
|
|
8155
|
+
cursor = ownedObjects.cursor;
|
|
8156
|
+
}
|
|
8157
|
+
return null;
|
|
7992
8158
|
}
|
|
7993
8159
|
|
|
7994
8160
|
// src/utils/config.ts
|
|
7995
8161
|
function getAggregatorV2PublishedAt(publishedAt, packages) {
|
|
7996
|
-
if (packages
|
|
8162
|
+
if (packages?.has("aggregator_v2")) {
|
|
7997
8163
|
return packages.get("aggregator_v2");
|
|
7998
8164
|
}
|
|
7999
8165
|
return publishedAt || PUBLISHED_ADDRESSES.V2.Mainnet;
|
|
8000
8166
|
}
|
|
8001
8167
|
function getAggregatorV2ExtendPublishedAt(publishedAt, packages) {
|
|
8002
|
-
if (packages
|
|
8168
|
+
if (packages?.has("aggregator_v2_extend")) {
|
|
8003
8169
|
return packages.get("aggregator_v2_extend");
|
|
8004
8170
|
}
|
|
8005
8171
|
return publishedAt || PUBLISHED_ADDRESSES.V2_EXTEND.Mainnet;
|
|
8006
8172
|
}
|
|
8007
8173
|
function getAggregatorV2Extend2PublishedAt(publishedAt, packages) {
|
|
8008
|
-
if (packages
|
|
8174
|
+
if (packages?.has("aggregator_v2_extend2")) {
|
|
8009
8175
|
return packages.get("aggregator_v2_extend2");
|
|
8010
8176
|
}
|
|
8011
8177
|
return publishedAt || PUBLISHED_ADDRESSES.V2_EXTEND2.Mainnet;
|
|
@@ -8014,9 +8180,10 @@ function getAggregatorV2Extend2PublishedAt(publishedAt, packages) {
|
|
|
8014
8180
|
// src/utils/gas.ts
|
|
8015
8181
|
var import_bn4 = __toESM(require_bn());
|
|
8016
8182
|
function extractGasMetrics(result) {
|
|
8017
|
-
const
|
|
8018
|
-
const
|
|
8019
|
-
if (!success) {
|
|
8183
|
+
const txResult = result.Transaction ?? result.FailedTransaction;
|
|
8184
|
+
const effects = txResult?.effects;
|
|
8185
|
+
if (!effects || !effects.status.success) {
|
|
8186
|
+
const errorMsg = effects?.status.success === false ? effects.status.error.message : "Unknown error";
|
|
8020
8187
|
return {
|
|
8021
8188
|
computationCost: "0",
|
|
8022
8189
|
storageCost: "0",
|
|
@@ -8026,27 +8193,27 @@ function extractGasMetrics(result) {
|
|
|
8026
8193
|
gasUsed: "0",
|
|
8027
8194
|
gasPrice: "0",
|
|
8028
8195
|
success: false,
|
|
8029
|
-
error:
|
|
8196
|
+
error: errorMsg
|
|
8030
8197
|
};
|
|
8031
8198
|
}
|
|
8032
8199
|
const gasUsed = effects.gasUsed;
|
|
8033
8200
|
return {
|
|
8034
|
-
computationCost: gasUsed.computationCost
|
|
8035
|
-
storageCost: gasUsed.storageCost
|
|
8036
|
-
storageRebate: gasUsed.storageRebate
|
|
8037
|
-
nonRefundableStorageFee: gasUsed.nonRefundableStorageFee
|
|
8201
|
+
computationCost: gasUsed.computationCost,
|
|
8202
|
+
storageCost: gasUsed.storageCost,
|
|
8203
|
+
storageRebate: gasUsed.storageRebate,
|
|
8204
|
+
nonRefundableStorageFee: gasUsed.nonRefundableStorageFee,
|
|
8038
8205
|
totalGasCost: calculateTotalGasCost(gasUsed),
|
|
8039
|
-
gasUsed: gasUsed.computationCost
|
|
8206
|
+
gasUsed: gasUsed.computationCost,
|
|
8040
8207
|
gasPrice: "1000",
|
|
8041
8208
|
// Standard Sui gas price in MIST
|
|
8042
8209
|
success: true
|
|
8043
8210
|
};
|
|
8044
8211
|
}
|
|
8045
8212
|
function calculateTotalGasCost(gasUsed) {
|
|
8046
|
-
const computation = new import_bn4.default(gasUsed.computationCost
|
|
8047
|
-
const storage = new import_bn4.default(gasUsed.storageCost
|
|
8048
|
-
const rebate = new import_bn4.default(gasUsed.storageRebate
|
|
8049
|
-
const nonRefundable = new import_bn4.default(gasUsed.nonRefundableStorageFee
|
|
8213
|
+
const computation = new import_bn4.default(gasUsed.computationCost);
|
|
8214
|
+
const storage = new import_bn4.default(gasUsed.storageCost);
|
|
8215
|
+
const rebate = new import_bn4.default(gasUsed.storageRebate);
|
|
8216
|
+
const nonRefundable = new import_bn4.default(gasUsed.nonRefundableStorageFee);
|
|
8050
8217
|
return computation.add(storage).sub(rebate).add(nonRefundable).toString();
|
|
8051
8218
|
}
|
|
8052
8219
|
function calculateGasEfficiency(amountOut, totalGasCost) {
|
|
@@ -8088,12 +8255,12 @@ function calculateAverageGas(analyses) {
|
|
|
8088
8255
|
}
|
|
8089
8256
|
function formatGasMetrics(metrics, isEstimated) {
|
|
8090
8257
|
if (!metrics.success) {
|
|
8091
|
-
return
|
|
8258
|
+
return `Failed: ${metrics.error}`;
|
|
8092
8259
|
}
|
|
8093
8260
|
const totalGas = Number(metrics.totalGasCost);
|
|
8094
8261
|
const gasInSui = totalGas / 1e9;
|
|
8095
8262
|
const estimatedFlag = isEstimated ? " (estimated)" : "";
|
|
8096
|
-
return
|
|
8263
|
+
return `Gas: ${totalGas.toString()} MIST (${gasInSui.toString()} SUI)${estimatedFlag}`;
|
|
8097
8264
|
}
|
|
8098
8265
|
function exportToJSON(comparison) {
|
|
8099
8266
|
return JSON.stringify(comparison, null, 2);
|
|
@@ -8161,63 +8328,62 @@ function exportToCSV(comparison) {
|
|
|
8161
8328
|
// src/utils/msafe.ts
|
|
8162
8329
|
var import_bn5 = __toESM(require_bn());
|
|
8163
8330
|
var dealWithFastRouterSwapParamsForMsafe = (data) => {
|
|
8164
|
-
|
|
8165
|
-
|
|
8166
|
-
amountIn:
|
|
8167
|
-
amountOut:
|
|
8168
|
-
paths:
|
|
8169
|
-
|
|
8170
|
-
|
|
8171
|
-
amountIn:
|
|
8172
|
-
amountOut:
|
|
8173
|
-
}
|
|
8174
|
-
if (item
|
|
8175
|
-
info["initialPrice"] =
|
|
8176
|
-
}
|
|
8177
|
-
if (
|
|
8331
|
+
const result = {
|
|
8332
|
+
...data,
|
|
8333
|
+
amountIn: data?.amountIn?.toString(),
|
|
8334
|
+
amountOut: data?.amountIn?.toString(),
|
|
8335
|
+
paths: data?.paths?.map((item) => {
|
|
8336
|
+
const info = {
|
|
8337
|
+
...item,
|
|
8338
|
+
amountIn: item?.amountIn?.toString(),
|
|
8339
|
+
amountOut: item?.amountOut?.toString()
|
|
8340
|
+
};
|
|
8341
|
+
if (item?.initialPrice) {
|
|
8342
|
+
info["initialPrice"] = item?.initialPrice?.toString();
|
|
8343
|
+
}
|
|
8344
|
+
if (item?.extendedDetails?.after_sqrt_price) {
|
|
8178
8345
|
info["extendedDetails"] = {
|
|
8179
|
-
after_sqrt_price:
|
|
8346
|
+
after_sqrt_price: item?.extendedDetails?.afterSqrtPrice?.toString()
|
|
8180
8347
|
};
|
|
8181
8348
|
}
|
|
8182
8349
|
return info;
|
|
8183
8350
|
})
|
|
8184
|
-
}
|
|
8351
|
+
};
|
|
8185
8352
|
return result;
|
|
8186
8353
|
};
|
|
8187
8354
|
var restituteMsafeFastRouterSwapParams = (data) => {
|
|
8188
|
-
|
|
8189
|
-
|
|
8190
|
-
amountIn: new import_bn5.default(data
|
|
8191
|
-
amountOut: new import_bn5.default(data
|
|
8192
|
-
paths:
|
|
8193
|
-
|
|
8194
|
-
|
|
8195
|
-
|
|
8196
|
-
|
|
8197
|
-
|
|
8198
|
-
|
|
8355
|
+
const result = {
|
|
8356
|
+
...data,
|
|
8357
|
+
amountIn: new import_bn5.default(data?.amountIn),
|
|
8358
|
+
amountOut: new import_bn5.default(data?.amountIn),
|
|
8359
|
+
paths: data?.paths?.map((item) => {
|
|
8360
|
+
const info = {
|
|
8361
|
+
...item
|
|
8362
|
+
};
|
|
8363
|
+
if (item?.initialPrice) {
|
|
8364
|
+
info["initialPrice"] = new decimal_default(item?.initialPrice?.toString());
|
|
8365
|
+
}
|
|
8366
|
+
if (item?.extendedDetails?.after_sqrt_price) {
|
|
8199
8367
|
info["extendedDetails"] = {
|
|
8200
|
-
after_sqrt_price: new decimal_default(
|
|
8368
|
+
after_sqrt_price: new decimal_default(item?.extendedDetails?.after_sqrt_price?.toString())
|
|
8201
8369
|
};
|
|
8202
8370
|
}
|
|
8203
8371
|
return info;
|
|
8204
8372
|
})
|
|
8205
|
-
}
|
|
8373
|
+
};
|
|
8206
8374
|
return result;
|
|
8207
8375
|
};
|
|
8208
8376
|
|
|
8209
8377
|
// src/utils/transaction.ts
|
|
8210
|
-
function printTransaction(tx, isPrint = true) {
|
|
8211
|
-
|
|
8212
|
-
|
|
8213
|
-
|
|
8214
|
-
|
|
8215
|
-
|
|
8216
|
-
|
|
8217
|
-
|
|
8218
|
-
|
|
8219
|
-
}
|
|
8220
|
-
});
|
|
8378
|
+
async function printTransaction(tx, isPrint = true) {
|
|
8379
|
+
console.log(`inputs`, tx.getData().inputs);
|
|
8380
|
+
tx.getData().commands.forEach((item, index) => {
|
|
8381
|
+
if (isPrint) {
|
|
8382
|
+
console.log(
|
|
8383
|
+
`transaction ${index}: `,
|
|
8384
|
+
JSON.stringify(item, bigIntReplacer, 2)
|
|
8385
|
+
);
|
|
8386
|
+
}
|
|
8221
8387
|
});
|
|
8222
8388
|
}
|
|
8223
8389
|
function bigIntReplacer(key, value) {
|
|
@@ -8289,7 +8455,7 @@ var HaedalHMMV2Router = class {
|
|
|
8289
8455
|
// amount_in
|
|
8290
8456
|
txb.pure.bool(swapData.a2b),
|
|
8291
8457
|
// a2b
|
|
8292
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8458
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
8293
8459
|
// clock
|
|
8294
8460
|
];
|
|
8295
8461
|
txb.moveCall({
|
|
@@ -8339,7 +8505,7 @@ var FullsailRouter = class {
|
|
|
8339
8505
|
txb.object(swapData.poolId),
|
|
8340
8506
|
txb.pure.bool(swapData.direction),
|
|
8341
8507
|
txb.pure.u64(swapData.amountIn),
|
|
8342
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8508
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
8343
8509
|
];
|
|
8344
8510
|
txb.moveCall({
|
|
8345
8511
|
target: `${swapData.publishedAt}::fullsail::swap`,
|
|
@@ -8354,7 +8520,7 @@ var CetusDlmmRouter = class {
|
|
|
8354
8520
|
throw new Error("CetusRouter only supported on mainnet");
|
|
8355
8521
|
}
|
|
8356
8522
|
this.globalConfig = "0xf31b605d117f959b9730e8c07b08b856cb05143c5e81d5751c90d2979e82f599";
|
|
8357
|
-
this.partner = partner
|
|
8523
|
+
this.partner = partner ?? "0x59ae16f6c42f578063c2da9b9c0173fe58120ceae08e40fd8212c8eceb80bb86";
|
|
8358
8524
|
this.versioned = "0x05370b2d656612dd5759cbe80463de301e3b94a921dfc72dd9daa2ecdeb2d0a8";
|
|
8359
8525
|
}
|
|
8360
8526
|
swap(txb, flattenedPath, swapContext, _extends) {
|
|
@@ -8386,7 +8552,7 @@ var CetusDlmmRouter = class {
|
|
|
8386
8552
|
txb.pure.bool(swapData.direction),
|
|
8387
8553
|
txb.pure.u64(swapData.amountIn),
|
|
8388
8554
|
txb.object(this.versioned),
|
|
8389
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8555
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
8390
8556
|
];
|
|
8391
8557
|
txb.moveCall({
|
|
8392
8558
|
target: `${swapData.publishedAt}::cetus_dlmm::swap`,
|
|
@@ -8429,7 +8595,7 @@ var FerraDlmmRouter = class {
|
|
|
8429
8595
|
txb.object(swapData.poolId),
|
|
8430
8596
|
txb.pure.bool(swapData.direction),
|
|
8431
8597
|
txb.pure.u64(swapData.amountIn),
|
|
8432
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8598
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
8433
8599
|
];
|
|
8434
8600
|
txb.moveCall({
|
|
8435
8601
|
target: `${swapData.publishedAt}::ferra_dlmm::swap`,
|
|
@@ -8472,7 +8638,7 @@ var FerraClmmRouter = class {
|
|
|
8472
8638
|
txb.object(swapData.poolId),
|
|
8473
8639
|
txb.pure.bool(swapData.direction),
|
|
8474
8640
|
txb.pure.u64(swapData.amountIn),
|
|
8475
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8641
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
8476
8642
|
];
|
|
8477
8643
|
txb.moveCall({
|
|
8478
8644
|
target: `${swapData.publishedAt}::ferra_clmm::swap`,
|
|
@@ -8614,17 +8780,18 @@ function findPythPriceIDs(paths) {
|
|
|
8614
8780
|
}
|
|
8615
8781
|
var _AggregatorClient = class _AggregatorClient {
|
|
8616
8782
|
constructor(params) {
|
|
8617
|
-
var _a, _b;
|
|
8618
8783
|
this.endpoint = params.endpoint ? processEndpoint(params.endpoint) : DEFAULT_ENDPOINT;
|
|
8619
|
-
|
|
8784
|
+
const network = params.env === 1 /* Testnet */ ? "testnet" : "mainnet";
|
|
8785
|
+
const grpcUrl = params.env === 1 /* Testnet */ ? "https://fullnode.testnet.sui.io:443" : "https://fullnode.mainnet.sui.io:443";
|
|
8786
|
+
this.client = params.client ?? new grpc.SuiGrpcClient({ network, baseUrl: grpcUrl });
|
|
8620
8787
|
this.signer = params.signer || "";
|
|
8621
8788
|
this.env = params.env || 0 /* Mainnet */;
|
|
8622
8789
|
const config2 = _AggregatorClient.CONFIG[this.env];
|
|
8623
|
-
this.
|
|
8624
|
-
this.pythClient = new SuiPythClient(
|
|
8790
|
+
this.pythAdapter = new PythAdapter(
|
|
8625
8791
|
this.client,
|
|
8626
8792
|
config2.pythStateId,
|
|
8627
|
-
config2.wormholeStateId
|
|
8793
|
+
config2.wormholeStateId,
|
|
8794
|
+
params.pythUrls ?? []
|
|
8628
8795
|
);
|
|
8629
8796
|
this.apiKey = params.apiKey || "";
|
|
8630
8797
|
this.partner = params.partner;
|
|
@@ -8643,16 +8810,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8643
8810
|
} else {
|
|
8644
8811
|
this.overlayFeeRate = 0;
|
|
8645
8812
|
}
|
|
8646
|
-
this.overlayFeeReceiver =
|
|
8647
|
-
}
|
|
8648
|
-
newPythClients(pythUrls) {
|
|
8649
|
-
if (!pythUrls.includes("https://hermes.pyth.network")) {
|
|
8650
|
-
pythUrls.push("https://hermes.pyth.network");
|
|
8651
|
-
}
|
|
8652
|
-
const connections = pythUrls.map(
|
|
8653
|
-
(url) => new SuiPriceServiceConnection(url, { timeout: 3e3 })
|
|
8654
|
-
);
|
|
8655
|
-
return connections;
|
|
8813
|
+
this.overlayFeeReceiver = params.overlayFeeReceiver ?? CLIENT_CONFIG.DEFAULT_OVERLAY_FEE_RECEIVER;
|
|
8656
8814
|
}
|
|
8657
8815
|
deepbookv3DeepFeeType() {
|
|
8658
8816
|
if (this.env === 0 /* Mainnet */) {
|
|
@@ -8661,53 +8819,43 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8661
8819
|
return DEEPBOOK_V3_DEEP_FEE_TYPES.Testnet;
|
|
8662
8820
|
}
|
|
8663
8821
|
}
|
|
8664
|
-
getDeepbookV3Config() {
|
|
8665
|
-
return
|
|
8666
|
-
return yield getDeepbookV3Config(this.endpoint);
|
|
8667
|
-
});
|
|
8822
|
+
async getDeepbookV3Config() {
|
|
8823
|
+
return await getDeepbookV3Config(this.endpoint);
|
|
8668
8824
|
}
|
|
8669
|
-
getOneCoinUsedToMerge(coinType) {
|
|
8670
|
-
|
|
8671
|
-
|
|
8672
|
-
|
|
8673
|
-
|
|
8674
|
-
|
|
8675
|
-
|
|
8676
|
-
|
|
8677
|
-
|
|
8678
|
-
return gotCoin.data[0].coinObjectId;
|
|
8679
|
-
}
|
|
8680
|
-
return null;
|
|
8681
|
-
} catch (error) {
|
|
8682
|
-
return null;
|
|
8825
|
+
async getOneCoinUsedToMerge(coinType) {
|
|
8826
|
+
try {
|
|
8827
|
+
const gotCoin = await this.client.listCoins({
|
|
8828
|
+
owner: this.signer,
|
|
8829
|
+
coinType,
|
|
8830
|
+
limit: 1
|
|
8831
|
+
});
|
|
8832
|
+
if (gotCoin.objects.length === 1) {
|
|
8833
|
+
return gotCoin.objects[0].objectId;
|
|
8683
8834
|
}
|
|
8684
|
-
|
|
8835
|
+
return null;
|
|
8836
|
+
} catch (error) {
|
|
8837
|
+
return null;
|
|
8838
|
+
}
|
|
8685
8839
|
}
|
|
8686
|
-
findRouters(params) {
|
|
8687
|
-
return
|
|
8688
|
-
|
|
8689
|
-
|
|
8690
|
-
|
|
8691
|
-
|
|
8692
|
-
|
|
8693
|
-
|
|
8694
|
-
);
|
|
8695
|
-
});
|
|
8840
|
+
async findRouters(params) {
|
|
8841
|
+
return getRouterResult(
|
|
8842
|
+
this.endpoint,
|
|
8843
|
+
this.apiKey,
|
|
8844
|
+
params,
|
|
8845
|
+
this.overlayFeeRate,
|
|
8846
|
+
this.overlayFeeReceiver
|
|
8847
|
+
);
|
|
8696
8848
|
}
|
|
8697
|
-
findMergeSwapRouters(params) {
|
|
8698
|
-
return
|
|
8699
|
-
|
|
8700
|
-
|
|
8701
|
-
|
|
8702
|
-
|
|
8703
|
-
|
|
8704
|
-
|
|
8705
|
-
);
|
|
8706
|
-
});
|
|
8849
|
+
async findMergeSwapRouters(params) {
|
|
8850
|
+
return getMergeSwapResult(
|
|
8851
|
+
this.endpoint,
|
|
8852
|
+
this.apiKey,
|
|
8853
|
+
params,
|
|
8854
|
+
this.overlayFeeRate,
|
|
8855
|
+
this.overlayFeeReceiver
|
|
8856
|
+
);
|
|
8707
8857
|
}
|
|
8708
|
-
executeFlexibleInputSwap(txb, inputCoin, routerData, expectedAmountOut, amountLimit, pythPriceIDs, partner, deepbookv3DeepFee, packages) {
|
|
8709
|
-
return __async(this, null, function* () {
|
|
8710
|
-
});
|
|
8858
|
+
async executeFlexibleInputSwap(txb, inputCoin, routerData, expectedAmountOut, amountLimit, pythPriceIDs, partner, deepbookv3DeepFee, packages) {
|
|
8711
8859
|
}
|
|
8712
8860
|
newDexRouterV3(provider, pythPriceIDs, partner, cetusDlmmPartner) {
|
|
8713
8861
|
switch (provider) {
|
|
@@ -9093,55 +9241,53 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
9093
9241
|
);
|
|
9094
9242
|
return outputCoin;
|
|
9095
9243
|
}
|
|
9096
|
-
routerSwap(params) {
|
|
9097
|
-
|
|
9098
|
-
|
|
9099
|
-
|
|
9100
|
-
|
|
9101
|
-
|
|
9102
|
-
|
|
9103
|
-
|
|
9104
|
-
|
|
9105
|
-
|
|
9106
|
-
|
|
9107
|
-
|
|
9108
|
-
|
|
9109
|
-
|
|
9110
|
-
|
|
9111
|
-
|
|
9112
|
-
|
|
9113
|
-
|
|
9114
|
-
|
|
9115
|
-
|
|
9116
|
-
|
|
9117
|
-
|
|
9118
|
-
|
|
9119
|
-
|
|
9120
|
-
|
|
9244
|
+
async routerSwap(params) {
|
|
9245
|
+
const { router, inputCoin, slippage, txb, partner } = params;
|
|
9246
|
+
if (slippage > 1 || slippage < 0) {
|
|
9247
|
+
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
|
|
9248
|
+
}
|
|
9249
|
+
if (!params.router.packages || !params.router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
9250
|
+
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
9251
|
+
}
|
|
9252
|
+
const byAmountIn = params.router.byAmountIn;
|
|
9253
|
+
const amountIn = router.amountIn;
|
|
9254
|
+
const amountOut = router.amountOut;
|
|
9255
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
9256
|
+
let overlayFee = new import_bn6.default(0);
|
|
9257
|
+
if (byAmountIn) {
|
|
9258
|
+
overlayFee = amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
9259
|
+
} else {
|
|
9260
|
+
overlayFee = amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
9261
|
+
}
|
|
9262
|
+
const expectedAmountOut = byAmountIn ? amountOut.sub(overlayFee) : amountOut;
|
|
9263
|
+
const expectedAmountIn = byAmountIn ? amountIn : amountIn.add(overlayFee);
|
|
9264
|
+
const amountLimit = CalculateAmountLimitBN(
|
|
9265
|
+
byAmountIn ? expectedAmountOut : expectedAmountIn,
|
|
9266
|
+
byAmountIn,
|
|
9267
|
+
slippage
|
|
9268
|
+
);
|
|
9269
|
+
const priceIDs = findPythPriceIDs(router.paths);
|
|
9270
|
+
const priceInfoObjectIds = priceIDs.length > 0 ? await this.updatePythPriceIDs(priceIDs, txb) : /* @__PURE__ */ new Map();
|
|
9271
|
+
if (byAmountIn) {
|
|
9272
|
+
return this.expectInputSwapV3(
|
|
9273
|
+
txb,
|
|
9274
|
+
inputCoin,
|
|
9275
|
+
router,
|
|
9276
|
+
amountOut.toString(),
|
|
9277
|
+
amountLimit.toString(),
|
|
9278
|
+
priceInfoObjectIds,
|
|
9279
|
+
partner ?? this.partner
|
|
9121
9280
|
);
|
|
9122
|
-
|
|
9123
|
-
|
|
9124
|
-
|
|
9125
|
-
|
|
9126
|
-
|
|
9127
|
-
|
|
9128
|
-
|
|
9129
|
-
|
|
9130
|
-
|
|
9131
|
-
|
|
9132
|
-
partner != null ? partner : this.partner
|
|
9133
|
-
);
|
|
9134
|
-
} else {
|
|
9135
|
-
return this.expectOutputSwapV3(
|
|
9136
|
-
txb,
|
|
9137
|
-
inputCoin,
|
|
9138
|
-
router,
|
|
9139
|
-
amountOut.toString(),
|
|
9140
|
-
amountLimit.toString(),
|
|
9141
|
-
partner != null ? partner : this.partner
|
|
9142
|
-
);
|
|
9143
|
-
}
|
|
9144
|
-
});
|
|
9281
|
+
} else {
|
|
9282
|
+
return this.expectOutputSwapV3(
|
|
9283
|
+
txb,
|
|
9284
|
+
inputCoin,
|
|
9285
|
+
router,
|
|
9286
|
+
amountOut.toString(),
|
|
9287
|
+
amountLimit.toString(),
|
|
9288
|
+
partner ?? this.partner
|
|
9289
|
+
);
|
|
9290
|
+
}
|
|
9145
9291
|
}
|
|
9146
9292
|
/**
|
|
9147
9293
|
* Router swap with max amount in validation.
|
|
@@ -9152,434 +9298,404 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
9152
9298
|
* @returns TransactionObjectArgument - The output coin from the swap
|
|
9153
9299
|
* @throws Error if input coin amount exceeds maxAmountIn
|
|
9154
9300
|
*/
|
|
9155
|
-
routerSwapWithMaxAmountIn(params) {
|
|
9156
|
-
|
|
9157
|
-
|
|
9158
|
-
|
|
9159
|
-
|
|
9160
|
-
|
|
9161
|
-
|
|
9162
|
-
|
|
9163
|
-
|
|
9164
|
-
|
|
9165
|
-
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
9171
|
-
|
|
9172
|
-
|
|
9173
|
-
|
|
9174
|
-
|
|
9175
|
-
|
|
9176
|
-
|
|
9177
|
-
|
|
9178
|
-
|
|
9179
|
-
|
|
9301
|
+
async routerSwapWithMaxAmountIn(params) {
|
|
9302
|
+
const { router, inputCoin, slippage, txb, partner, maxAmountIn } = params;
|
|
9303
|
+
if (slippage > 1 || slippage < 0) {
|
|
9304
|
+
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
|
|
9305
|
+
}
|
|
9306
|
+
if (!params.router.packages || !params.router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
9307
|
+
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
9308
|
+
}
|
|
9309
|
+
const byAmountIn = params.router.byAmountIn;
|
|
9310
|
+
const amountIn = router.amountIn;
|
|
9311
|
+
const amountOut = router.amountOut;
|
|
9312
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
9313
|
+
let overlayFee = new import_bn6.default(0);
|
|
9314
|
+
if (byAmountIn) {
|
|
9315
|
+
overlayFee = amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
9316
|
+
} else {
|
|
9317
|
+
overlayFee = amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
9318
|
+
}
|
|
9319
|
+
const expectedAmountOut = byAmountIn ? amountOut.sub(overlayFee) : amountOut;
|
|
9320
|
+
const expectedAmountIn = byAmountIn ? amountIn : amountIn.add(overlayFee);
|
|
9321
|
+
const amountLimit = CalculateAmountLimitBN(
|
|
9322
|
+
byAmountIn ? expectedAmountOut : expectedAmountIn,
|
|
9323
|
+
byAmountIn,
|
|
9324
|
+
slippage
|
|
9325
|
+
);
|
|
9326
|
+
const priceIDs = findPythPriceIDs(router.paths);
|
|
9327
|
+
const priceInfoObjectIds = priceIDs.length > 0 ? await this.updatePythPriceIDs(priceIDs, txb) : /* @__PURE__ */ new Map();
|
|
9328
|
+
if (byAmountIn) {
|
|
9329
|
+
return this.expectInputSwapV3WithMaxAmountIn(
|
|
9330
|
+
txb,
|
|
9331
|
+
inputCoin,
|
|
9332
|
+
router,
|
|
9333
|
+
maxAmountIn,
|
|
9334
|
+
amountOut.toString(),
|
|
9335
|
+
amountLimit.toString(),
|
|
9336
|
+
priceInfoObjectIds,
|
|
9337
|
+
partner ?? this.partner
|
|
9180
9338
|
);
|
|
9181
|
-
|
|
9182
|
-
|
|
9183
|
-
|
|
9184
|
-
|
|
9185
|
-
|
|
9186
|
-
|
|
9187
|
-
|
|
9188
|
-
|
|
9189
|
-
|
|
9190
|
-
|
|
9191
|
-
|
|
9192
|
-
partner != null ? partner : this.partner
|
|
9193
|
-
);
|
|
9194
|
-
} else {
|
|
9195
|
-
return this.expectOutputSwapV3WithMaxAmountIn(
|
|
9196
|
-
txb,
|
|
9197
|
-
inputCoin,
|
|
9198
|
-
router,
|
|
9199
|
-
maxAmountIn,
|
|
9200
|
-
amountOut.toString(),
|
|
9201
|
-
amountLimit.toString(),
|
|
9202
|
-
partner != null ? partner : this.partner
|
|
9203
|
-
);
|
|
9204
|
-
}
|
|
9205
|
-
});
|
|
9339
|
+
} else {
|
|
9340
|
+
return this.expectOutputSwapV3WithMaxAmountIn(
|
|
9341
|
+
txb,
|
|
9342
|
+
inputCoin,
|
|
9343
|
+
router,
|
|
9344
|
+
maxAmountIn,
|
|
9345
|
+
amountOut.toString(),
|
|
9346
|
+
amountLimit.toString(),
|
|
9347
|
+
partner ?? this.partner
|
|
9348
|
+
);
|
|
9349
|
+
}
|
|
9206
9350
|
}
|
|
9207
9351
|
// auto build input coin
|
|
9208
9352
|
// auto merge, transfer or destory target coin.
|
|
9209
|
-
fastRouterSwap(params) {
|
|
9210
|
-
|
|
9211
|
-
|
|
9212
|
-
|
|
9213
|
-
|
|
9214
|
-
|
|
9215
|
-
|
|
9216
|
-
|
|
9217
|
-
|
|
9218
|
-
|
|
9219
|
-
router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
9220
|
-
);
|
|
9221
|
-
} else {
|
|
9222
|
-
overlayFee = Number(
|
|
9223
|
-
router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
9224
|
-
);
|
|
9225
|
-
}
|
|
9226
|
-
const expectedAmountOut = byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
|
|
9227
|
-
const expectedAmountIn = byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
|
|
9228
|
-
const amountLimit = CalculateAmountLimit(
|
|
9229
|
-
byAmountIn ? expectedAmountOut : expectedAmountIn,
|
|
9230
|
-
byAmountIn,
|
|
9231
|
-
slippage
|
|
9353
|
+
async fastRouterSwap(params) {
|
|
9354
|
+
const { router, slippage, txb, partner, payDeepFeeAmount } = params;
|
|
9355
|
+
const fromCoinType = router.paths[0].from;
|
|
9356
|
+
const targetCoinType = router.paths[router.paths.length - 1].target;
|
|
9357
|
+
const byAmountIn = router.byAmountIn;
|
|
9358
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
9359
|
+
let overlayFee = 0;
|
|
9360
|
+
if (byAmountIn) {
|
|
9361
|
+
overlayFee = Number(
|
|
9362
|
+
router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
9232
9363
|
);
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
9364
|
+
} else {
|
|
9365
|
+
overlayFee = Number(
|
|
9366
|
+
router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
9367
|
+
);
|
|
9368
|
+
}
|
|
9369
|
+
const expectedAmountOut = byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
|
|
9370
|
+
const expectedAmountIn = byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
|
|
9371
|
+
const amountLimit = CalculateAmountLimit(
|
|
9372
|
+
byAmountIn ? expectedAmountOut : expectedAmountIn,
|
|
9373
|
+
byAmountIn,
|
|
9374
|
+
slippage
|
|
9375
|
+
);
|
|
9376
|
+
const amount = byAmountIn ? expectedAmountIn : amountLimit;
|
|
9377
|
+
let inputCoin = transactions.coinWithBalance({
|
|
9378
|
+
balance: BigInt(amount.toString()),
|
|
9379
|
+
useGasCoin: true,
|
|
9380
|
+
type: fromCoinType
|
|
9381
|
+
});
|
|
9382
|
+
let deepCoin;
|
|
9383
|
+
if (payDeepFeeAmount && payDeepFeeAmount > 0) {
|
|
9384
|
+
deepCoin = transactions.coinWithBalance({
|
|
9385
|
+
balance: BigInt(payDeepFeeAmount),
|
|
9386
|
+
type: this.deepbookv3DeepFeeType()
|
|
9238
9387
|
});
|
|
9239
|
-
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
9243
|
-
|
|
9244
|
-
|
|
9245
|
-
|
|
9246
|
-
|
|
9247
|
-
|
|
9248
|
-
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
|
|
9255
|
-
if (CoinUtils.isSuiCoin(targetCoinType)) {
|
|
9256
|
-
txb.mergeCoins(txb.gas, [targetCoin]);
|
|
9388
|
+
}
|
|
9389
|
+
const routerSwapParams = {
|
|
9390
|
+
router,
|
|
9391
|
+
inputCoin,
|
|
9392
|
+
slippage,
|
|
9393
|
+
txb,
|
|
9394
|
+
partner: partner ?? this.partner,
|
|
9395
|
+
deepbookv3DeepFee: deepCoin
|
|
9396
|
+
};
|
|
9397
|
+
const targetCoin = await this.routerSwap(routerSwapParams);
|
|
9398
|
+
if (CoinUtils.isSuiCoin(targetCoinType)) {
|
|
9399
|
+
txb.mergeCoins(txb.gas, [targetCoin]);
|
|
9400
|
+
} else {
|
|
9401
|
+
const targetCoinObjID = await this.getOneCoinUsedToMerge(targetCoinType);
|
|
9402
|
+
if (targetCoinObjID != null) {
|
|
9403
|
+
txb.mergeCoins(txb.object(targetCoinObjID), [targetCoin]);
|
|
9257
9404
|
} else {
|
|
9258
|
-
|
|
9259
|
-
|
|
9260
|
-
|
|
9261
|
-
|
|
9262
|
-
|
|
9263
|
-
|
|
9264
|
-
|
|
9265
|
-
|
|
9266
|
-
packages: router.packages
|
|
9267
|
-
},
|
|
9268
|
-
txb
|
|
9269
|
-
);
|
|
9270
|
-
}
|
|
9271
|
-
}
|
|
9272
|
-
});
|
|
9273
|
-
}
|
|
9274
|
-
mergeSwap(params) {
|
|
9275
|
-
return __async(this, null, function* () {
|
|
9276
|
-
const { router, inputCoins, slippage, txb, partner } = params;
|
|
9277
|
-
if (slippage > 1 || slippage < 0) {
|
|
9278
|
-
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
|
|
9279
|
-
}
|
|
9280
|
-
if (!router.packages || !router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
9281
|
-
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
9282
|
-
}
|
|
9283
|
-
if (!router.allRoutes || router.allRoutes.length === 0) {
|
|
9284
|
-
throw new Error("No routes found in merge swap response");
|
|
9285
|
-
}
|
|
9286
|
-
const outputCoins = [];
|
|
9287
|
-
for (let i = 0; i < router.allRoutes.length && i < inputCoins.length; i++) {
|
|
9288
|
-
const route = router.allRoutes[i];
|
|
9289
|
-
const inputCoin = inputCoins[i];
|
|
9290
|
-
const routeRouter = {
|
|
9291
|
-
quoteID: router.quoteID,
|
|
9292
|
-
amountIn: route.amountIn,
|
|
9293
|
-
amountOut: route.amountOut,
|
|
9294
|
-
deviationRatio: Number(route.deviationRatio),
|
|
9295
|
-
byAmountIn: true,
|
|
9296
|
-
// Merge swap is always by amount in
|
|
9297
|
-
paths: route.paths,
|
|
9298
|
-
insufficientLiquidity: false,
|
|
9299
|
-
packages: router.packages
|
|
9300
|
-
};
|
|
9301
|
-
const routerParams = {
|
|
9302
|
-
router: routeRouter,
|
|
9303
|
-
inputCoin: inputCoin.coin,
|
|
9304
|
-
slippage,
|
|
9305
|
-
txb,
|
|
9306
|
-
partner: partner != null ? partner : this.partner
|
|
9307
|
-
};
|
|
9308
|
-
const outputCoin = yield this.routerSwap(routerParams);
|
|
9309
|
-
outputCoins.push(outputCoin);
|
|
9310
|
-
}
|
|
9311
|
-
if (outputCoins.length === 0) {
|
|
9312
|
-
throw new Error("No output coins generated from merge swap");
|
|
9313
|
-
}
|
|
9314
|
-
let finalOutputCoin = outputCoins[0];
|
|
9315
|
-
if (outputCoins.length > 1) {
|
|
9316
|
-
txb.mergeCoins(finalOutputCoin, outputCoins.slice(1));
|
|
9405
|
+
transferOrDestroyCoin(
|
|
9406
|
+
{
|
|
9407
|
+
coin: targetCoin,
|
|
9408
|
+
coinType: targetCoinType,
|
|
9409
|
+
packages: router.packages
|
|
9410
|
+
},
|
|
9411
|
+
txb
|
|
9412
|
+
);
|
|
9317
9413
|
}
|
|
9318
|
-
|
|
9319
|
-
});
|
|
9414
|
+
}
|
|
9320
9415
|
}
|
|
9321
|
-
|
|
9322
|
-
|
|
9323
|
-
|
|
9324
|
-
|
|
9325
|
-
|
|
9326
|
-
|
|
9327
|
-
|
|
9328
|
-
|
|
9329
|
-
|
|
9330
|
-
|
|
9331
|
-
|
|
9332
|
-
|
|
9333
|
-
|
|
9334
|
-
|
|
9335
|
-
|
|
9336
|
-
|
|
9337
|
-
|
|
9338
|
-
|
|
9339
|
-
|
|
9340
|
-
|
|
9341
|
-
|
|
9342
|
-
|
|
9343
|
-
|
|
9344
|
-
|
|
9345
|
-
router
|
|
9346
|
-
|
|
9416
|
+
async mergeSwap(params) {
|
|
9417
|
+
const { router, inputCoins, slippage, txb, partner } = params;
|
|
9418
|
+
if (slippage > 1 || slippage < 0) {
|
|
9419
|
+
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
|
|
9420
|
+
}
|
|
9421
|
+
if (!router.packages || !router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
9422
|
+
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
9423
|
+
}
|
|
9424
|
+
if (!router.allRoutes || router.allRoutes.length === 0) {
|
|
9425
|
+
throw new Error("No routes found in merge swap response");
|
|
9426
|
+
}
|
|
9427
|
+
const outputCoins = [];
|
|
9428
|
+
for (let i = 0; i < router.allRoutes.length && i < inputCoins.length; i++) {
|
|
9429
|
+
const route = router.allRoutes[i];
|
|
9430
|
+
const inputCoin = inputCoins[i];
|
|
9431
|
+
const routeRouter = {
|
|
9432
|
+
quoteID: router.quoteID,
|
|
9433
|
+
amountIn: route.amountIn,
|
|
9434
|
+
amountOut: route.amountOut,
|
|
9435
|
+
deviationRatio: Number(route.deviationRatio),
|
|
9436
|
+
byAmountIn: true,
|
|
9437
|
+
// Merge swap is always by amount in
|
|
9438
|
+
paths: route.paths,
|
|
9439
|
+
insufficientLiquidity: false,
|
|
9440
|
+
packages: router.packages
|
|
9441
|
+
};
|
|
9442
|
+
const routerParams = {
|
|
9443
|
+
router: routeRouter,
|
|
9444
|
+
inputCoin: inputCoin.coin,
|
|
9347
9445
|
slippage,
|
|
9348
9446
|
txb,
|
|
9349
|
-
partner: partner
|
|
9350
|
-
};
|
|
9351
|
-
const
|
|
9352
|
-
|
|
9353
|
-
|
|
9354
|
-
|
|
9355
|
-
|
|
9356
|
-
|
|
9357
|
-
|
|
9358
|
-
|
|
9359
|
-
|
|
9360
|
-
|
|
9361
|
-
|
|
9362
|
-
|
|
9363
|
-
|
|
9364
|
-
|
|
9365
|
-
|
|
9366
|
-
|
|
9367
|
-
|
|
9368
|
-
|
|
9369
|
-
|
|
9370
|
-
|
|
9371
|
-
|
|
9372
|
-
|
|
9373
|
-
const
|
|
9374
|
-
|
|
9375
|
-
|
|
9376
|
-
|
|
9377
|
-
|
|
9378
|
-
|
|
9379
|
-
)
|
|
9447
|
+
partner: partner ?? this.partner
|
|
9448
|
+
};
|
|
9449
|
+
const outputCoin = await this.routerSwap(routerParams);
|
|
9450
|
+
outputCoins.push(outputCoin);
|
|
9451
|
+
}
|
|
9452
|
+
if (outputCoins.length === 0) {
|
|
9453
|
+
throw new Error("No output coins generated from merge swap");
|
|
9454
|
+
}
|
|
9455
|
+
let finalOutputCoin = outputCoins[0];
|
|
9456
|
+
if (outputCoins.length > 1) {
|
|
9457
|
+
txb.mergeCoins(finalOutputCoin, outputCoins.slice(1));
|
|
9458
|
+
}
|
|
9459
|
+
return finalOutputCoin;
|
|
9460
|
+
}
|
|
9461
|
+
async fastMergeSwap(params) {
|
|
9462
|
+
const { router, slippage, txb, partner } = params;
|
|
9463
|
+
if (!router || !router.allRoutes || router.allRoutes.length === 0) {
|
|
9464
|
+
throw new Error("Invalid router: no routes found");
|
|
9465
|
+
}
|
|
9466
|
+
const firstRoute = router.allRoutes[0];
|
|
9467
|
+
const targetCoinType = firstRoute.paths[firstRoute.paths.length - 1].target;
|
|
9468
|
+
const inputCoins = [];
|
|
9469
|
+
const coinTypeSet = /* @__PURE__ */ new Set();
|
|
9470
|
+
for (const route of router.allRoutes) {
|
|
9471
|
+
const firstCoinType = route.paths[0].from;
|
|
9472
|
+
if (coinTypeSet.has(firstCoinType)) {
|
|
9473
|
+
continue;
|
|
9474
|
+
}
|
|
9475
|
+
coinTypeSet.add(firstCoinType);
|
|
9476
|
+
const coin = transactions.coinWithBalance({
|
|
9477
|
+
balance: BigInt(route.amountIn.toString()),
|
|
9478
|
+
useGasCoin: CoinUtils.isSuiCoin(firstCoinType),
|
|
9479
|
+
type: firstCoinType
|
|
9480
|
+
});
|
|
9481
|
+
inputCoins.push({ coinType: firstCoinType, coin });
|
|
9482
|
+
}
|
|
9483
|
+
const mergeSwapParams = {
|
|
9484
|
+
router,
|
|
9485
|
+
inputCoins,
|
|
9486
|
+
slippage,
|
|
9487
|
+
txb,
|
|
9488
|
+
partner: partner ?? this.partner
|
|
9489
|
+
};
|
|
9490
|
+
const targetCoin = await this.mergeSwap(mergeSwapParams);
|
|
9491
|
+
if (CoinUtils.isSuiCoin(targetCoinType)) {
|
|
9492
|
+
txb.mergeCoins(txb.gas, [targetCoin]);
|
|
9493
|
+
} else {
|
|
9494
|
+
const targetCoinObjID = await this.getOneCoinUsedToMerge(targetCoinType);
|
|
9495
|
+
if (targetCoinObjID != null) {
|
|
9496
|
+
txb.mergeCoins(txb.object(targetCoinObjID), [targetCoin]);
|
|
9380
9497
|
} else {
|
|
9381
|
-
|
|
9382
|
-
|
|
9498
|
+
transferOrDestroyCoin(
|
|
9499
|
+
{
|
|
9500
|
+
coin: targetCoin,
|
|
9501
|
+
coinType: targetCoinType,
|
|
9502
|
+
packages: router.packages
|
|
9503
|
+
},
|
|
9504
|
+
txb
|
|
9383
9505
|
);
|
|
9384
9506
|
}
|
|
9385
|
-
|
|
9386
|
-
|
|
9387
|
-
|
|
9388
|
-
|
|
9389
|
-
|
|
9390
|
-
|
|
9507
|
+
}
|
|
9508
|
+
}
|
|
9509
|
+
async fixableRouterSwapV3(params) {
|
|
9510
|
+
const { router, inputCoin, slippage, txb, partner } = params;
|
|
9511
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
9512
|
+
let overlayFee = 0;
|
|
9513
|
+
if (router.byAmountIn) {
|
|
9514
|
+
overlayFee = Number(
|
|
9515
|
+
router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
9391
9516
|
);
|
|
9392
|
-
|
|
9393
|
-
|
|
9394
|
-
|
|
9395
|
-
|
|
9396
|
-
|
|
9397
|
-
|
|
9398
|
-
|
|
9399
|
-
|
|
9400
|
-
|
|
9401
|
-
|
|
9402
|
-
|
|
9403
|
-
|
|
9404
|
-
|
|
9405
|
-
|
|
9406
|
-
|
|
9407
|
-
|
|
9408
|
-
|
|
9409
|
-
|
|
9410
|
-
|
|
9411
|
-
|
|
9412
|
-
)
|
|
9413
|
-
|
|
9414
|
-
|
|
9517
|
+
} else {
|
|
9518
|
+
overlayFee = Number(
|
|
9519
|
+
router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
9520
|
+
);
|
|
9521
|
+
}
|
|
9522
|
+
const expectedAmountOut = router.byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
|
|
9523
|
+
const expectedAmountIn = router.byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
|
|
9524
|
+
const amountLimit = CalculateAmountLimitBN(
|
|
9525
|
+
router.byAmountIn ? expectedAmountOut : expectedAmountIn,
|
|
9526
|
+
router.byAmountIn,
|
|
9527
|
+
slippage
|
|
9528
|
+
);
|
|
9529
|
+
const priceIDs = findPythPriceIDs(router.paths);
|
|
9530
|
+
const priceInfoObjectIds = priceIDs.length > 0 ? await this.updatePythPriceIDs(priceIDs, txb) : /* @__PURE__ */ new Map();
|
|
9531
|
+
if (router.byAmountIn) {
|
|
9532
|
+
return this.expectInputSwapV3(
|
|
9533
|
+
txb,
|
|
9534
|
+
inputCoin,
|
|
9535
|
+
router,
|
|
9536
|
+
expectedAmountOut.toString(),
|
|
9537
|
+
amountLimit.toString(),
|
|
9538
|
+
priceInfoObjectIds,
|
|
9539
|
+
partner ?? this.partner
|
|
9540
|
+
);
|
|
9541
|
+
} else {
|
|
9542
|
+
return this.expectOutputSwapV3(
|
|
9543
|
+
txb,
|
|
9544
|
+
inputCoin,
|
|
9545
|
+
router,
|
|
9546
|
+
expectedAmountOut.toString(),
|
|
9547
|
+
amountLimit.toString(),
|
|
9548
|
+
partner ?? this.partner
|
|
9549
|
+
);
|
|
9550
|
+
}
|
|
9415
9551
|
}
|
|
9416
|
-
swapInPools(params) {
|
|
9417
|
-
|
|
9418
|
-
|
|
9419
|
-
|
|
9420
|
-
|
|
9421
|
-
|
|
9422
|
-
|
|
9423
|
-
|
|
9424
|
-
|
|
9425
|
-
|
|
9426
|
-
|
|
9427
|
-
const
|
|
9428
|
-
|
|
9429
|
-
|
|
9430
|
-
|
|
9431
|
-
|
|
9432
|
-
|
|
9433
|
-
|
|
9434
|
-
|
|
9435
|
-
|
|
9436
|
-
|
|
9437
|
-
arguments: args,
|
|
9438
|
-
typeArguments
|
|
9439
|
-
});
|
|
9440
|
-
}
|
|
9441
|
-
if (!this.signer) {
|
|
9442
|
-
this.signer = "0x0";
|
|
9443
|
-
}
|
|
9444
|
-
const simulateRes = yield this.client.devInspectTransactionBlock({
|
|
9445
|
-
transactionBlock: tx,
|
|
9446
|
-
sender: this.signer
|
|
9447
|
-
});
|
|
9448
|
-
if (simulateRes.error != null) {
|
|
9449
|
-
throw new Error("Simulation error: " + simulateRes.error);
|
|
9450
|
-
}
|
|
9451
|
-
const valueData = (_a = simulateRes.events) == null ? void 0 : _a.filter((item) => {
|
|
9452
|
-
return item.type.includes("CalculatedSwapResultEvent");
|
|
9552
|
+
async swapInPools(params) {
|
|
9553
|
+
const { from, target, amount, byAmountIn, pools } = params;
|
|
9554
|
+
const fromCoin = completionCoin(from);
|
|
9555
|
+
const targetCoin = completionCoin(target);
|
|
9556
|
+
const tx = new transactions.Transaction();
|
|
9557
|
+
const direction = compareCoins(fromCoin, targetCoin);
|
|
9558
|
+
const coinA = direction ? fromCoin : targetCoin;
|
|
9559
|
+
const coinB = direction ? targetCoin : fromCoin;
|
|
9560
|
+
const typeArguments = [coinA, coinB];
|
|
9561
|
+
const integratePublishedAt = this.env === 0 /* Mainnet */ ? "0xfbb32ac0fa89a3cb0c56c745b688c6d2a53ac8e43447119ad822763997ffb9c3" : "0xab2d58dd28ff0dc19b18ab2c634397b785a38c342a8f5065ade5f53f9dbffa1c";
|
|
9562
|
+
for (let i = 0; i < pools.length; i++) {
|
|
9563
|
+
const args = [
|
|
9564
|
+
tx.object(pools[i]),
|
|
9565
|
+
tx.pure.bool(direction),
|
|
9566
|
+
tx.pure.bool(byAmountIn),
|
|
9567
|
+
tx.pure.u64(amount.toString())
|
|
9568
|
+
];
|
|
9569
|
+
tx.moveCall({
|
|
9570
|
+
target: `${integratePublishedAt}::fetcher_script::calculate_swap_result`,
|
|
9571
|
+
arguments: args,
|
|
9572
|
+
typeArguments
|
|
9453
9573
|
});
|
|
9454
|
-
|
|
9455
|
-
|
|
9456
|
-
|
|
9457
|
-
|
|
9458
|
-
|
|
9459
|
-
|
|
9460
|
-
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
|
|
9464
|
-
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
|
|
9472
|
-
|
|
9473
|
-
|
|
9474
|
-
|
|
9574
|
+
}
|
|
9575
|
+
tx.setSenderIfNotSet(this.signer || "0x0");
|
|
9576
|
+
const simulateRes = await this.client.simulateTransaction({
|
|
9577
|
+
transaction: tx,
|
|
9578
|
+
include: { events: true, effects: true }
|
|
9579
|
+
});
|
|
9580
|
+
const txResult = simulateRes.Transaction ?? simulateRes.FailedTransaction;
|
|
9581
|
+
if (!txResult || simulateRes.$kind === "FailedTransaction") {
|
|
9582
|
+
const errorMsg = txResult?.status.success === false ? txResult.status.error.message : "Unknown error";
|
|
9583
|
+
throw new Error("Simulation error: " + errorMsg);
|
|
9584
|
+
}
|
|
9585
|
+
const events = txResult.events ?? [];
|
|
9586
|
+
const valueData = events.filter((item) => {
|
|
9587
|
+
return item.eventType.includes("CalculatedSwapResultEvent");
|
|
9588
|
+
});
|
|
9589
|
+
if (valueData.length === 0 || valueData.length !== pools.length) {
|
|
9590
|
+
throw new Error("Simulate event result error");
|
|
9591
|
+
}
|
|
9592
|
+
let tempMaxAmount = byAmountIn ? new import_bn6.default(0) : new import_bn6.default(U64_MAX);
|
|
9593
|
+
let tempIndex = 0;
|
|
9594
|
+
for (let i = 0; i < valueData.length; i += 1) {
|
|
9595
|
+
const eventJson2 = valueData[i].json;
|
|
9596
|
+
if (eventJson2?.data?.is_exceed) {
|
|
9597
|
+
continue;
|
|
9598
|
+
}
|
|
9599
|
+
if (params.byAmountIn) {
|
|
9600
|
+
const amount2 = new import_bn6.default(eventJson2?.data?.amount_out ?? 0);
|
|
9601
|
+
if (amount2.gt(tempMaxAmount)) {
|
|
9602
|
+
tempIndex = i;
|
|
9603
|
+
tempMaxAmount = amount2;
|
|
9604
|
+
}
|
|
9605
|
+
} else {
|
|
9606
|
+
const amount2 = new import_bn6.default(eventJson2?.data?.amount_out ?? 0);
|
|
9607
|
+
if (amount2.lt(tempMaxAmount)) {
|
|
9608
|
+
tempIndex = i;
|
|
9609
|
+
tempMaxAmount = amount2;
|
|
9475
9610
|
}
|
|
9476
9611
|
}
|
|
9477
|
-
|
|
9478
|
-
|
|
9479
|
-
|
|
9480
|
-
|
|
9481
|
-
|
|
9482
|
-
|
|
9483
|
-
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
9492
|
-
|
|
9493
|
-
|
|
9494
|
-
|
|
9495
|
-
|
|
9496
|
-
|
|
9497
|
-
|
|
9498
|
-
|
|
9499
|
-
|
|
9500
|
-
|
|
9501
|
-
|
|
9502
|
-
|
|
9503
|
-
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
|
|
9508
|
-
|
|
9612
|
+
}
|
|
9613
|
+
const eventJson = valueData[tempIndex].json;
|
|
9614
|
+
const eventData = eventJson?.data;
|
|
9615
|
+
const [decimalA, decimalB] = await Promise.all([
|
|
9616
|
+
this.client.getCoinMetadata({ coinType: coinA }).then((res) => res.coinMetadata?.decimals ?? null),
|
|
9617
|
+
this.client.getCoinMetadata({ coinType: coinB }).then((res) => res.coinMetadata?.decimals ?? null)
|
|
9618
|
+
]);
|
|
9619
|
+
if (decimalA == null || decimalB == null) {
|
|
9620
|
+
throw new Error("Cannot get coin decimals");
|
|
9621
|
+
}
|
|
9622
|
+
const feeRate = Number(eventData?.fee_rate ?? 0) / 1e6;
|
|
9623
|
+
const pureAmountIn = new import_bn6.default(eventData?.amount_in ?? 0);
|
|
9624
|
+
const feeAmount = new import_bn6.default(eventData?.fee_amount ?? 0);
|
|
9625
|
+
const amountIn = pureAmountIn.add(feeAmount);
|
|
9626
|
+
const cetusRouterV3PublishedAt = this.env === 0 /* Mainnet */ ? MAINNET_CETUS_V3_PUBLISHED_AT : TESTNET_CETUS_V3_PUBLISHED_AT;
|
|
9627
|
+
const aggregatorV3PublishedAt = this.env === 0 /* Mainnet */ ? AGGREGATOR_V3_CONFIG.DEFAULT_PUBLISHED_AT.Mainnet : AGGREGATOR_V3_CONFIG.DEFAULT_PUBLISHED_AT.Testnet;
|
|
9628
|
+
const routeData = {
|
|
9629
|
+
amountIn,
|
|
9630
|
+
amountOut: new import_bn6.default(eventData?.amount_out ?? 0),
|
|
9631
|
+
deviationRatio: 0,
|
|
9632
|
+
paths: [
|
|
9633
|
+
{
|
|
9634
|
+
id: pools[tempIndex],
|
|
9635
|
+
direction,
|
|
9636
|
+
provider: CETUS,
|
|
9637
|
+
from: fromCoin,
|
|
9638
|
+
target: targetCoin,
|
|
9639
|
+
feeRate,
|
|
9640
|
+
amountIn: amountIn.toString(),
|
|
9641
|
+
amountOut: eventData?.amount_out ?? "0",
|
|
9642
|
+
publishedAt: cetusRouterV3PublishedAt,
|
|
9643
|
+
extendedDetails: {
|
|
9644
|
+
afterSqrtPrice: eventData?.after_sqrt_price
|
|
9509
9645
|
}
|
|
9510
|
-
],
|
|
9511
|
-
insufficientLiquidity: false,
|
|
9512
|
-
byAmountIn: params.byAmountIn,
|
|
9513
|
-
quoteID: `degraded-${generateUUID()}`,
|
|
9514
|
-
packages: /* @__PURE__ */ new Map([
|
|
9515
|
-
[
|
|
9516
|
-
PACKAGE_NAMES.AGGREGATOR_V3,
|
|
9517
|
-
aggregatorV3PublishedAt
|
|
9518
|
-
]
|
|
9519
|
-
])
|
|
9520
|
-
};
|
|
9521
|
-
const result = {
|
|
9522
|
-
isExceed: event.is_exceed,
|
|
9523
|
-
routeData
|
|
9524
|
-
};
|
|
9525
|
-
return result;
|
|
9526
|
-
});
|
|
9527
|
-
}
|
|
9528
|
-
updatePythPriceIDs(priceIDs, txb) {
|
|
9529
|
-
return __async(this, null, function* () {
|
|
9530
|
-
let priceUpdateData = null;
|
|
9531
|
-
let lastError = null;
|
|
9532
|
-
for (const connection of this.pythConnections) {
|
|
9533
|
-
try {
|
|
9534
|
-
priceUpdateData = yield connection.getPriceFeedsUpdateData(priceIDs);
|
|
9535
|
-
break;
|
|
9536
|
-
} catch (e) {
|
|
9537
|
-
lastError = e;
|
|
9538
|
-
console.log("Error: ", e);
|
|
9539
|
-
continue;
|
|
9540
9646
|
}
|
|
9541
|
-
|
|
9542
|
-
|
|
9543
|
-
|
|
9544
|
-
|
|
9545
|
-
|
|
9546
|
-
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
|
|
9550
|
-
|
|
9551
|
-
|
|
9552
|
-
|
|
9553
|
-
|
|
9554
|
-
|
|
9555
|
-
|
|
9556
|
-
|
|
9557
|
-
);
|
|
9558
|
-
}
|
|
9559
|
-
let priceInfoObjectIdsMap = /* @__PURE__ */ new Map();
|
|
9560
|
-
for (let i = 0; i < priceIDs.length; i++) {
|
|
9561
|
-
priceInfoObjectIdsMap.set(priceIDs[i], priceInfoObjectIds[i]);
|
|
9562
|
-
}
|
|
9563
|
-
return priceInfoObjectIdsMap;
|
|
9564
|
-
});
|
|
9647
|
+
],
|
|
9648
|
+
insufficientLiquidity: false,
|
|
9649
|
+
byAmountIn: params.byAmountIn,
|
|
9650
|
+
quoteID: `degraded-${generateUUID()}`,
|
|
9651
|
+
packages: /* @__PURE__ */ new Map([
|
|
9652
|
+
[
|
|
9653
|
+
PACKAGE_NAMES.AGGREGATOR_V3,
|
|
9654
|
+
aggregatorV3PublishedAt
|
|
9655
|
+
]
|
|
9656
|
+
])
|
|
9657
|
+
};
|
|
9658
|
+
const result = {
|
|
9659
|
+
isExceed: eventData?.is_exceed ?? false,
|
|
9660
|
+
routeData
|
|
9661
|
+
};
|
|
9662
|
+
return result;
|
|
9565
9663
|
}
|
|
9566
|
-
|
|
9567
|
-
|
|
9568
|
-
|
|
9569
|
-
|
|
9570
|
-
|
|
9571
|
-
|
|
9572
|
-
|
|
9664
|
+
async updatePythPriceIDs(priceIDs, txb) {
|
|
9665
|
+
const priceUpdateData = await this.pythAdapter.getPriceFeedsUpdateData(priceIDs);
|
|
9666
|
+
let priceInfoObjectIds;
|
|
9667
|
+
try {
|
|
9668
|
+
priceInfoObjectIds = await this.pythAdapter.updatePriceFeeds(
|
|
9669
|
+
txb,
|
|
9670
|
+
priceUpdateData,
|
|
9671
|
+
priceIDs
|
|
9672
|
+
);
|
|
9673
|
+
} catch (e) {
|
|
9674
|
+
throw new Error(
|
|
9675
|
+
`Failed to update Pyth price feeds. Ensure pythUrls are configured correctly. Detailed error: ${e}`
|
|
9676
|
+
);
|
|
9677
|
+
}
|
|
9678
|
+
const priceInfoObjectIdsMap = /* @__PURE__ */ new Map();
|
|
9679
|
+
for (let i = 0; i < priceIDs.length; i++) {
|
|
9680
|
+
priceInfoObjectIdsMap.set(priceIDs[i], priceInfoObjectIds[i]);
|
|
9681
|
+
}
|
|
9682
|
+
return priceInfoObjectIdsMap;
|
|
9683
|
+
}
|
|
9684
|
+
async devInspectTransactionBlock(txb) {
|
|
9685
|
+
txb.setSenderIfNotSet(this.signer || "0x0");
|
|
9686
|
+
const res = await this.client.simulateTransaction({
|
|
9687
|
+
transaction: txb,
|
|
9688
|
+
include: { events: true, effects: true }
|
|
9573
9689
|
});
|
|
9690
|
+
return res;
|
|
9574
9691
|
}
|
|
9575
|
-
sendTransaction(txb, signer) {
|
|
9576
|
-
|
|
9577
|
-
|
|
9578
|
-
|
|
9579
|
-
|
|
9580
|
-
});
|
|
9581
|
-
return res;
|
|
9692
|
+
async sendTransaction(txb, signer) {
|
|
9693
|
+
const res = await this.client.signAndExecuteTransaction({
|
|
9694
|
+
transaction: txb,
|
|
9695
|
+
signer,
|
|
9696
|
+
include: { effects: true, events: true, balanceChanges: true }
|
|
9582
9697
|
});
|
|
9698
|
+
return res;
|
|
9583
9699
|
}
|
|
9584
9700
|
};
|
|
9585
9701
|
_AggregatorClient.CONFIG = {
|
|
@@ -9648,4 +9764,174 @@ decimal.js/decimal.mjs:
|
|
|
9648
9764
|
*)
|
|
9649
9765
|
*/
|
|
9650
9766
|
|
|
9651
|
-
|
|
9767
|
+
exports.AFSUI = AFSUI;
|
|
9768
|
+
exports.AFTERMATH = AFTERMATH;
|
|
9769
|
+
exports.AFTERMATH_AMM = AFTERMATH_AMM;
|
|
9770
|
+
exports.AFTERMATH_MODULE = AFTERMATH_MODULE;
|
|
9771
|
+
exports.AGGREGATOR = AGGREGATOR;
|
|
9772
|
+
exports.AGGREGATOR_V3_CONFIG = AGGREGATOR_V3_CONFIG;
|
|
9773
|
+
exports.ALL_DEXES = ALL_DEXES;
|
|
9774
|
+
exports.ALPHAFI = ALPHAFI;
|
|
9775
|
+
exports.AggregatorClient = AggregatorClient;
|
|
9776
|
+
exports.AggregatorConfig = AggregatorConfig;
|
|
9777
|
+
exports.AggregatorError = AggregatorError;
|
|
9778
|
+
exports.AggregatorServerErrorCode = AggregatorServerErrorCode;
|
|
9779
|
+
exports.BLUEFIN = BLUEFIN;
|
|
9780
|
+
exports.BLUEMOVE = BLUEMOVE;
|
|
9781
|
+
exports.CETUS = CETUS;
|
|
9782
|
+
exports.CETUSDLMM = CETUSDLMM;
|
|
9783
|
+
exports.CETUS_DEX = CETUS_DEX;
|
|
9784
|
+
exports.CETUS_MODULE = CETUS_MODULE;
|
|
9785
|
+
exports.CETUS_PUBLISHED_AT = CETUS_PUBLISHED_AT;
|
|
9786
|
+
exports.CHECK_COINS_THRESHOLD_FUNC = CHECK_COINS_THRESHOLD_FUNC;
|
|
9787
|
+
exports.CLIENT_CONFIG = CLIENT_CONFIG;
|
|
9788
|
+
exports.CLOCK_ADDRESS = CLOCK_ADDRESS;
|
|
9789
|
+
exports.CoinInfoAddress = CoinInfoAddress;
|
|
9790
|
+
exports.CoinStoreAddress = CoinStoreAddress;
|
|
9791
|
+
exports.CoinUtils = CoinUtils;
|
|
9792
|
+
exports.ConfigErrorCode = ConfigErrorCode;
|
|
9793
|
+
exports.DEEPBOOKV2 = DEEPBOOKV2;
|
|
9794
|
+
exports.DEEPBOOKV3 = DEEPBOOKV3;
|
|
9795
|
+
exports.DEEPBOOK_CLOB_V2_MODULE = DEEPBOOK_CLOB_V2_MODULE;
|
|
9796
|
+
exports.DEEPBOOK_CUSTODIAN_V2_MODULE = DEEPBOOK_CUSTODIAN_V2_MODULE;
|
|
9797
|
+
exports.DEEPBOOK_DEX = DEEPBOOK_DEX;
|
|
9798
|
+
exports.DEEPBOOK_MODULE = DEEPBOOK_MODULE;
|
|
9799
|
+
exports.DEEPBOOK_PACKAGE_ID = DEEPBOOK_PACKAGE_ID;
|
|
9800
|
+
exports.DEEPBOOK_PUBLISHED_AT = DEEPBOOK_PUBLISHED_AT;
|
|
9801
|
+
exports.DEEPBOOK_V3_DEEP_FEE_TYPES = DEEPBOOK_V3_DEEP_FEE_TYPES;
|
|
9802
|
+
exports.DEFAULT_AGG_V2_ENDPOINT = DEFAULT_AGG_V2_ENDPOINT;
|
|
9803
|
+
exports.DEFAULT_AGG_V3_ENDPOINT = DEFAULT_AGG_V3_ENDPOINT;
|
|
9804
|
+
exports.DEFAULT_ENDPOINT = DEFAULT_ENDPOINT;
|
|
9805
|
+
exports.DEFAULT_GAS_BUDGET_FOR_MERGE = DEFAULT_GAS_BUDGET_FOR_MERGE;
|
|
9806
|
+
exports.DEFAULT_GAS_BUDGET_FOR_SPLIT = DEFAULT_GAS_BUDGET_FOR_SPLIT;
|
|
9807
|
+
exports.DEFAULT_GAS_BUDGET_FOR_STAKE = DEFAULT_GAS_BUDGET_FOR_STAKE;
|
|
9808
|
+
exports.DEFAULT_GAS_BUDGET_FOR_TRANSFER = DEFAULT_GAS_BUDGET_FOR_TRANSFER;
|
|
9809
|
+
exports.DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI = DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI;
|
|
9810
|
+
exports.DEFAULT_NFT_TRANSFER_GAS_FEE = DEFAULT_NFT_TRANSFER_GAS_FEE;
|
|
9811
|
+
exports.Env = Env;
|
|
9812
|
+
exports.FERRACLMM = FERRACLMM;
|
|
9813
|
+
exports.FERRADLMM = FERRADLMM;
|
|
9814
|
+
exports.FLOWXV2 = FLOWXV2;
|
|
9815
|
+
exports.FLOWXV3 = FLOWXV3;
|
|
9816
|
+
exports.FLOWX_AMM = FLOWX_AMM;
|
|
9817
|
+
exports.FLOWX_AMM_MODULE = FLOWX_AMM_MODULE;
|
|
9818
|
+
exports.FULLSAIL = FULLSAIL;
|
|
9819
|
+
exports.FlashSwapA2BFunc = FlashSwapA2BFunc;
|
|
9820
|
+
exports.FlashSwapB2AFunc = FlashSwapB2AFunc;
|
|
9821
|
+
exports.FlashSwapFunc = FlashSwapFunc;
|
|
9822
|
+
exports.FlashSwapWithPartnerA2BFunc = FlashSwapWithPartnerA2BFunc;
|
|
9823
|
+
exports.FlashSwapWithPartnerB2AFunc = FlashSwapWithPartnerB2AFunc;
|
|
9824
|
+
exports.FlashSwapWithPartnerFunc = FlashSwapWithPartnerFunc;
|
|
9825
|
+
exports.GAS_SYMBOL = GAS_SYMBOL;
|
|
9826
|
+
exports.GAS_TYPE_ARG = GAS_TYPE_ARG;
|
|
9827
|
+
exports.GAS_TYPE_ARG_LONG = GAS_TYPE_ARG_LONG;
|
|
9828
|
+
exports.HAEDAL = HAEDAL;
|
|
9829
|
+
exports.HAEDALHMMV2 = HAEDALHMMV2;
|
|
9830
|
+
exports.HAEDALPMM = HAEDALPMM;
|
|
9831
|
+
exports.HAWAL = HAWAL;
|
|
9832
|
+
exports.INTEGRATE = INTEGRATE;
|
|
9833
|
+
exports.JOIN_FUNC = JOIN_FUNC;
|
|
9834
|
+
exports.KRIYA = KRIYA;
|
|
9835
|
+
exports.KRIYAV3 = KRIYAV3;
|
|
9836
|
+
exports.KRIYA_DEX = KRIYA_DEX;
|
|
9837
|
+
exports.KRIYA_MODULE = KRIYA_MODULE;
|
|
9838
|
+
exports.MAGMA = MAGMA;
|
|
9839
|
+
exports.MAINNET_AFTERMATH_INSURANCE_FUND_ID = MAINNET_AFTERMATH_INSURANCE_FUND_ID;
|
|
9840
|
+
exports.MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID = MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID;
|
|
9841
|
+
exports.MAINNET_AFTERMATH_REFERRAL_VAULT_ID = MAINNET_AFTERMATH_REFERRAL_VAULT_ID;
|
|
9842
|
+
exports.MAINNET_AFTERMATH_REGISTRY_ID = MAINNET_AFTERMATH_REGISTRY_ID;
|
|
9843
|
+
exports.MAINNET_AFTERMATH_TREASURY_ID = MAINNET_AFTERMATH_TREASURY_ID;
|
|
9844
|
+
exports.MAINNET_CETUS_V3_PUBLISHED_AT = MAINNET_CETUS_V3_PUBLISHED_AT;
|
|
9845
|
+
exports.MAINNET_FLOWX_AMM_CONTAINER_ID = MAINNET_FLOWX_AMM_CONTAINER_ID;
|
|
9846
|
+
exports.METASTABLE = METASTABLE;
|
|
9847
|
+
exports.MOMENTUM = MOMENTUM;
|
|
9848
|
+
exports.OBRIC = OBRIC;
|
|
9849
|
+
exports.ONE = ONE;
|
|
9850
|
+
exports.PACKAGE_NAMES = PACKAGE_NAMES;
|
|
9851
|
+
exports.PAY_MODULE = PAY_MODULE;
|
|
9852
|
+
exports.POOL_MODULT = POOL_MODULT;
|
|
9853
|
+
exports.PUBLISHED_ADDRESSES = PUBLISHED_ADDRESSES;
|
|
9854
|
+
exports.PYTH_CONFIG = PYTH_CONFIG;
|
|
9855
|
+
exports.REPAY_FLASH_SWAP_A2B_FUNC = REPAY_FLASH_SWAP_A2B_FUNC;
|
|
9856
|
+
exports.REPAY_FLASH_SWAP_B2A_FUNC = REPAY_FLASH_SWAP_B2A_FUNC;
|
|
9857
|
+
exports.REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC = REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC;
|
|
9858
|
+
exports.REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC = REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC;
|
|
9859
|
+
exports.RepayFalshSwapFunc = RepayFalshSwapFunc;
|
|
9860
|
+
exports.RepayFlashSwapWithPartnerFunc = RepayFlashSwapWithPartnerFunc;
|
|
9861
|
+
exports.SCALLOP = SCALLOP;
|
|
9862
|
+
exports.SEVENK = SEVENK;
|
|
9863
|
+
exports.SPRINGSUI = SPRINGSUI;
|
|
9864
|
+
exports.STEAMM = STEAMM;
|
|
9865
|
+
exports.STEAMM_OMM = STEAMM_OMM;
|
|
9866
|
+
exports.STEAMM_OMM_V2 = STEAMM_OMM_V2;
|
|
9867
|
+
exports.SUILEND = SUILEND;
|
|
9868
|
+
exports.SUI_SYSTEM_STATE_OBJECT_ID = SUI_SYSTEM_STATE_OBJECT_ID;
|
|
9869
|
+
exports.SWAP_A2B_FUNC = SWAP_A2B_FUNC;
|
|
9870
|
+
exports.SWAP_B2A_FUNC = SWAP_B2A_FUNC;
|
|
9871
|
+
exports.SuiZeroCoinFn = SuiZeroCoinFn;
|
|
9872
|
+
exports.TEN_POW_NINE = TEN_POW_NINE;
|
|
9873
|
+
exports.TESTNET_AFTERMATH_INSURANCE_FUND_ID = TESTNET_AFTERMATH_INSURANCE_FUND_ID;
|
|
9874
|
+
exports.TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID = TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID;
|
|
9875
|
+
exports.TESTNET_AFTERMATH_REFERRAL_VAULT_ID = TESTNET_AFTERMATH_REFERRAL_VAULT_ID;
|
|
9876
|
+
exports.TESTNET_AFTERMATH_REGISTRY_ID = TESTNET_AFTERMATH_REGISTRY_ID;
|
|
9877
|
+
exports.TESTNET_AFTERMATH_TREASURY_ID = TESTNET_AFTERMATH_TREASURY_ID;
|
|
9878
|
+
exports.TESTNET_CETUS_V3_PUBLISHED_AT = TESTNET_CETUS_V3_PUBLISHED_AT;
|
|
9879
|
+
exports.TESTNET_FLOWX_AMM_CONTAINER_ID = TESTNET_FLOWX_AMM_CONTAINER_ID;
|
|
9880
|
+
exports.TRANSFER_ACCOUNT_CAP = TRANSFER_ACCOUNT_CAP;
|
|
9881
|
+
exports.TRANSFER_OR_DESTORY_COIN_FUNC = TRANSFER_OR_DESTORY_COIN_FUNC;
|
|
9882
|
+
exports.TURBOS = TURBOS;
|
|
9883
|
+
exports.TURBOS_DEX = TURBOS_DEX;
|
|
9884
|
+
exports.TURBOS_MODULE = TURBOS_MODULE;
|
|
9885
|
+
exports.TURBOS_VERSIONED = TURBOS_VERSIONED;
|
|
9886
|
+
exports.TWO = TWO;
|
|
9887
|
+
exports.TransactionErrorCode = TransactionErrorCode;
|
|
9888
|
+
exports.TypesErrorCode = TypesErrorCode;
|
|
9889
|
+
exports.U128 = U128;
|
|
9890
|
+
exports.U64_MAX = U64_MAX;
|
|
9891
|
+
exports.U64_MAX_BN = U64_MAX_BN;
|
|
9892
|
+
exports.UTILS_MODULE = UTILS_MODULE;
|
|
9893
|
+
exports.VOLO = VOLO;
|
|
9894
|
+
exports.ZERO = ZERO;
|
|
9895
|
+
exports.buildInputCoin = buildInputCoin;
|
|
9896
|
+
exports.calculateGasEfficiency = calculateGasEfficiency;
|
|
9897
|
+
exports.calculatePriceImpact = calculatePriceImpact;
|
|
9898
|
+
exports.checkInvalidSuiAddress = checkInvalidSuiAddress;
|
|
9899
|
+
exports.compareCoins = compareCoins;
|
|
9900
|
+
exports.compareGasMetrics = compareGasMetrics;
|
|
9901
|
+
exports.completionCoin = completionCoin;
|
|
9902
|
+
exports.composeType = composeType;
|
|
9903
|
+
exports.createTarget = createTarget;
|
|
9904
|
+
exports.dealWithFastRouterSwapParamsForMsafe = dealWithFastRouterSwapParamsForMsafe;
|
|
9905
|
+
exports.exportToCSV = exportToCSV;
|
|
9906
|
+
exports.exportToJSON = exportToJSON;
|
|
9907
|
+
exports.extractAddressFromType = extractAddressFromType;
|
|
9908
|
+
exports.extractGasMetrics = extractGasMetrics;
|
|
9909
|
+
exports.extractStructTagFromType = extractStructTagFromType;
|
|
9910
|
+
exports.extractTimestampFromDowngradeUuid6 = extractTimestampFromDowngradeUuid6;
|
|
9911
|
+
exports.fixSuiObjectId = fixSuiObjectId;
|
|
9912
|
+
exports.formatGasMetrics = formatGasMetrics;
|
|
9913
|
+
exports.generateDowngradeUuid6 = generateDowngradeUuid6;
|
|
9914
|
+
exports.generateSimpleDowngradeUuid6 = generateSimpleDowngradeUuid6;
|
|
9915
|
+
exports.getAggregatorServerErrorMessage = getAggregatorServerErrorMessage;
|
|
9916
|
+
exports.getAggregatorV2Extend2PublishedAt = getAggregatorV2Extend2PublishedAt;
|
|
9917
|
+
exports.getAggregatorV2ExtendPublishedAt = getAggregatorV2ExtendPublishedAt;
|
|
9918
|
+
exports.getAggregatorV2PublishedAt = getAggregatorV2PublishedAt;
|
|
9919
|
+
exports.getAllProviders = getAllProviders;
|
|
9920
|
+
exports.getDeepbookV3Config = getDeepbookV3Config;
|
|
9921
|
+
exports.getDefaultSuiInputType = getDefaultSuiInputType;
|
|
9922
|
+
exports.getMergeSwapResult = getMergeSwapResult;
|
|
9923
|
+
exports.getOrCreateAccountCap = getOrCreateAccountCap;
|
|
9924
|
+
exports.getProvidersExcluding = getProvidersExcluding;
|
|
9925
|
+
exports.getProvidersIncluding = getProvidersIncluding;
|
|
9926
|
+
exports.getRouterResult = getRouterResult;
|
|
9927
|
+
exports.isSortedSymbols = isSortedSymbols;
|
|
9928
|
+
exports.isValidDowngradeUuid6 = isValidDowngradeUuid6;
|
|
9929
|
+
exports.mintZeroCoin = mintZeroCoin;
|
|
9930
|
+
exports.normalizeCoinType = normalizeCoinType;
|
|
9931
|
+
exports.parseAftermathFeeType = parseAftermathFeeType;
|
|
9932
|
+
exports.parseTurbosPoolFeeType = parseTurbosPoolFeeType;
|
|
9933
|
+
exports.patchFixSuiObjectId = patchFixSuiObjectId;
|
|
9934
|
+
exports.printTransaction = printTransaction;
|
|
9935
|
+
exports.processEndpoint = processEndpoint;
|
|
9936
|
+
exports.processFlattenRoutes = processFlattenRoutes;
|
|
9937
|
+
exports.restituteMsafeFastRouterSwapParams = restituteMsafeFastRouterSwapParams;
|