@cetusprotocol/aggregator-sdk 1.4.5 → 1.4.6
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} +1215 -939
- package/dist/{index.d.mts → index.d.cts} +70 -14
- package/dist/index.d.ts +70 -14
- package/dist/index.js +1039 -1115
- 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 jsonRpc = require('@mysten/sui/jsonRpc');
|
|
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,221 @@ 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 res = await this.client.getObject({
|
|
7861
|
+
id: this.pythStateId,
|
|
7862
|
+
options: { showContent: true }
|
|
7863
|
+
});
|
|
7864
|
+
const content = res.data?.content;
|
|
7865
|
+
const json = content && "fields" in content ? content.fields : null;
|
|
7866
|
+
if (!json) {
|
|
7867
|
+
throw new Error("Unable to fetch pyth state object");
|
|
7868
|
+
}
|
|
7869
|
+
this.baseUpdateFee = Number(json.base_update_fee);
|
|
7870
|
+
return this.baseUpdateFee;
|
|
7871
|
+
}
|
|
7872
|
+
async getPackageId(objectId) {
|
|
7873
|
+
const res = await this.client.getObject({
|
|
7874
|
+
id: objectId,
|
|
7875
|
+
options: { showContent: true }
|
|
7876
|
+
});
|
|
7877
|
+
const content = res.data?.content;
|
|
7878
|
+
const json = content && "fields" in content ? content.fields : null;
|
|
7879
|
+
if (!json) {
|
|
7880
|
+
throw new Error(`Cannot fetch package id for object ${objectId}`);
|
|
7881
|
+
}
|
|
7882
|
+
if ("upgrade_cap" in json) {
|
|
7883
|
+
const upgradeCap = json.upgrade_cap;
|
|
7884
|
+
const packageId = upgradeCap?.fields?.package;
|
|
7885
|
+
if (typeof packageId === "string") {
|
|
7886
|
+
return packageId;
|
|
7887
|
+
}
|
|
7888
|
+
}
|
|
7889
|
+
throw new Error("upgrade_cap not found");
|
|
7890
|
+
}
|
|
7891
|
+
async getWormholePackageId() {
|
|
7892
|
+
if (!this.wormholePackageId) {
|
|
7893
|
+
this.wormholePackageId = await this.getPackageId(this.wormholeStateId);
|
|
7894
|
+
}
|
|
7895
|
+
return this.wormholePackageId;
|
|
7896
|
+
}
|
|
7897
|
+
async getPythPackageId() {
|
|
7898
|
+
if (!this.pythPackageId) {
|
|
7899
|
+
this.pythPackageId = await this.getPackageId(this.pythStateId);
|
|
7900
|
+
}
|
|
7901
|
+
return this.pythPackageId;
|
|
7902
|
+
}
|
|
7903
|
+
async getPriceFeedObjectId(feedId) {
|
|
7904
|
+
const normalizedFeedId = feedId.replace("0x", "");
|
|
7905
|
+
if (this.priceFeedObjectIdCache.has(normalizedFeedId)) {
|
|
7906
|
+
return this.priceFeedObjectIdCache.get(normalizedFeedId);
|
|
7907
|
+
}
|
|
7908
|
+
const { id: tableId, fieldType } = await this.getPriceTableInfo();
|
|
7909
|
+
const feedIdBytes = Buffer.from(normalizedFeedId, "hex");
|
|
7910
|
+
try {
|
|
7911
|
+
const result = await this.client.getDynamicFieldObject({
|
|
7912
|
+
parentId: tableId,
|
|
7913
|
+
name: {
|
|
7914
|
+
type: `${fieldType}::price_identifier::PriceIdentifier`,
|
|
7915
|
+
value: { bytes: Array.from(feedIdBytes) }
|
|
7916
|
+
}
|
|
7917
|
+
});
|
|
7918
|
+
const content = result.data?.content;
|
|
7919
|
+
const json = content && "fields" in content ? content.fields : null;
|
|
7920
|
+
const objectId = typeof json?.value === "string" ? json.value : void 0;
|
|
7921
|
+
if (!objectId) {
|
|
7922
|
+
return void 0;
|
|
7923
|
+
}
|
|
7924
|
+
this.priceFeedObjectIdCache.set(normalizedFeedId, objectId);
|
|
7925
|
+
return objectId;
|
|
7926
|
+
} catch {
|
|
7927
|
+
return void 0;
|
|
7928
|
+
}
|
|
7929
|
+
}
|
|
7930
|
+
async getPriceTableInfo() {
|
|
7931
|
+
if (this.priceTableInfo !== void 0) {
|
|
7932
|
+
return this.priceTableInfo;
|
|
7933
|
+
}
|
|
7934
|
+
const result = await this.client.getDynamicFieldObject({
|
|
7935
|
+
parentId: this.pythStateId,
|
|
7936
|
+
name: {
|
|
7937
|
+
type: "vector<u8>",
|
|
7938
|
+
value: "price_info"
|
|
7939
|
+
}
|
|
7940
|
+
});
|
|
7941
|
+
if (!result.data?.type) {
|
|
7942
|
+
throw new Error(
|
|
7943
|
+
"Price Table not found, contract may not be initialized"
|
|
7944
|
+
);
|
|
7945
|
+
}
|
|
7946
|
+
let type = result.data.type.replace("0x2::table::Table<", "");
|
|
7947
|
+
type = type.replace("::price_identifier::PriceIdentifier, 0x2::object::ID>", "");
|
|
7948
|
+
this.priceTableInfo = { id: result.data.objectId, fieldType: type };
|
|
7949
|
+
return this.priceTableInfo;
|
|
7950
|
+
}
|
|
7951
|
+
extractVaaBytesFromAccumulatorMessage(accumulatorMessage) {
|
|
7952
|
+
const trailingPayloadSize = accumulatorMessage.readUint8(6);
|
|
7953
|
+
const vaaSizeOffset = 7 + trailingPayloadSize + 1;
|
|
7954
|
+
const vaaSize = accumulatorMessage.readUint16BE(vaaSizeOffset);
|
|
7955
|
+
const vaaOffset = vaaSizeOffset + 2;
|
|
7956
|
+
return accumulatorMessage.subarray(vaaOffset, vaaOffset + vaaSize);
|
|
7957
|
+
}
|
|
7958
|
+
async verifyVaas(vaas, tx) {
|
|
7959
|
+
const wormholePackageId = await this.getWormholePackageId();
|
|
7960
|
+
const verifiedVaas = [];
|
|
7961
|
+
for (const vaa of vaas) {
|
|
7962
|
+
const [verifiedVaa] = tx.moveCall({
|
|
7963
|
+
target: `${wormholePackageId}::vaa::parse_and_verify`,
|
|
7964
|
+
arguments: [
|
|
7965
|
+
tx.object(this.wormholeStateId),
|
|
7966
|
+
tx.pure(
|
|
7967
|
+
bcs.bcs.vector(bcs.bcs.u8()).serialize(Array.from(vaa), { maxSize: MAX_ARGUMENT_SIZE }).toBytes()
|
|
7968
|
+
),
|
|
7969
|
+
tx.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7970
|
+
]
|
|
7971
|
+
});
|
|
7972
|
+
verifiedVaas.push(verifiedVaa);
|
|
7973
|
+
}
|
|
7974
|
+
return verifiedVaas;
|
|
7975
|
+
}
|
|
7976
|
+
async verifyVaasAndGetHotPotato(tx, updates, packageId) {
|
|
7977
|
+
if (updates.length > 1) {
|
|
7978
|
+
throw new Error(
|
|
7979
|
+
"SDK does not support sending multiple accumulator messages in a single transaction"
|
|
7980
|
+
);
|
|
7981
|
+
}
|
|
7982
|
+
const vaa = this.extractVaaBytesFromAccumulatorMessage(updates[0]);
|
|
7983
|
+
const verifiedVaas = await this.verifyVaas([vaa], tx);
|
|
7984
|
+
const [priceUpdatesHotPotato] = tx.moveCall({
|
|
7985
|
+
target: `${packageId}::pyth::create_authenticated_price_infos_using_accumulator`,
|
|
7986
|
+
arguments: [
|
|
7987
|
+
tx.object(this.pythStateId),
|
|
7988
|
+
tx.pure(
|
|
7989
|
+
bcs.bcs.vector(bcs.bcs.u8()).serialize(Array.from(updates[0]), { maxSize: MAX_ARGUMENT_SIZE }).toBytes()
|
|
7990
|
+
),
|
|
7991
|
+
verifiedVaas[0],
|
|
7992
|
+
tx.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7993
|
+
]
|
|
7994
|
+
});
|
|
7995
|
+
return priceUpdatesHotPotato;
|
|
7996
|
+
}
|
|
7997
|
+
async updatePriceFeeds(tx, updates, feedIds) {
|
|
7998
|
+
const packageId = await this.getPythPackageId();
|
|
7999
|
+
let priceUpdatesHotPotato = await this.verifyVaasAndGetHotPotato(
|
|
8000
|
+
tx,
|
|
8001
|
+
updates,
|
|
8002
|
+
packageId
|
|
8003
|
+
);
|
|
8004
|
+
const baseUpdateFee = await this.getBaseUpdateFee();
|
|
8005
|
+
const coins = tx.splitCoins(
|
|
8006
|
+
tx.gas,
|
|
8007
|
+
feedIds.map(() => tx.pure.u64(baseUpdateFee))
|
|
8008
|
+
);
|
|
8009
|
+
const priceInfoObjects = [];
|
|
8010
|
+
let coinId = 0;
|
|
8011
|
+
for (const feedId of feedIds) {
|
|
8012
|
+
const priceInfoObjectId = await this.getPriceFeedObjectId(feedId);
|
|
8013
|
+
if (!priceInfoObjectId) {
|
|
8014
|
+
throw new Error(
|
|
8015
|
+
`Price feed ${feedId} not found, please create it first`
|
|
8016
|
+
);
|
|
8017
|
+
}
|
|
8018
|
+
priceInfoObjects.push(priceInfoObjectId);
|
|
8019
|
+
[priceUpdatesHotPotato] = tx.moveCall({
|
|
8020
|
+
target: `${packageId}::pyth::update_single_price_feed`,
|
|
8021
|
+
arguments: [
|
|
8022
|
+
tx.object(this.pythStateId),
|
|
8023
|
+
priceUpdatesHotPotato,
|
|
8024
|
+
tx.object(priceInfoObjectId),
|
|
8025
|
+
coins[coinId],
|
|
8026
|
+
tx.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
8027
|
+
]
|
|
8028
|
+
});
|
|
8029
|
+
coinId++;
|
|
8030
|
+
}
|
|
8031
|
+
tx.moveCall({
|
|
8032
|
+
target: `${packageId}::hot_potato_vector::destroy`,
|
|
8033
|
+
arguments: [priceUpdatesHotPotato],
|
|
8034
|
+
typeArguments: [`${packageId}::price_info::PriceInfo`]
|
|
8035
|
+
});
|
|
8036
|
+
return priceInfoObjects;
|
|
8037
|
+
}
|
|
8038
|
+
};
|
|
7869
8039
|
|
|
7870
8040
|
// src/utils/uuid.ts
|
|
7871
8041
|
function generateDowngradeUuid6() {
|
|
@@ -7924,7 +8094,7 @@ function extractTimestampFromDowngradeUuid6(uuid) {
|
|
|
7924
8094
|
const timestampHex = timeHigh + timeMid;
|
|
7925
8095
|
const timestamp = parseInt(timestampHex, 16);
|
|
7926
8096
|
return isNaN(timestamp) ? null : timestamp;
|
|
7927
|
-
} catch
|
|
8097
|
+
} catch {
|
|
7928
8098
|
return null;
|
|
7929
8099
|
}
|
|
7930
8100
|
}
|
|
@@ -7940,72 +8110,60 @@ function processEndpoint(endpoint) {
|
|
|
7940
8110
|
}
|
|
7941
8111
|
|
|
7942
8112
|
// 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
|
-
});
|
|
8113
|
+
async function getOrCreateAccountCap(txb, client, owner) {
|
|
8114
|
+
let accountCapStr = await getAccountCap(client, owner);
|
|
8115
|
+
if (accountCapStr !== null) {
|
|
7957
8116
|
return {
|
|
7958
|
-
accountCap,
|
|
7959
|
-
isCreate:
|
|
8117
|
+
accountCap: txb.object(accountCapStr),
|
|
8118
|
+
isCreate: false
|
|
7960
8119
|
};
|
|
8120
|
+
}
|
|
8121
|
+
const accountCap = txb.moveCall({
|
|
8122
|
+
target: `${DEEPBOOK_PUBLISHED_AT}::${DEEPBOOK_CLOB_V2_MODULE}::create_account`,
|
|
8123
|
+
typeArguments: [],
|
|
8124
|
+
arguments: []
|
|
7961
8125
|
});
|
|
8126
|
+
return {
|
|
8127
|
+
accountCap,
|
|
8128
|
+
isCreate: true
|
|
8129
|
+
};
|
|
7962
8130
|
}
|
|
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
|
-
}
|
|
8131
|
+
async function getAccountCap(client, owner) {
|
|
8132
|
+
const limit = 50;
|
|
8133
|
+
let cursor = void 0;
|
|
8134
|
+
while (true) {
|
|
8135
|
+
const ownedObjects = await client.getOwnedObjects({
|
|
8136
|
+
owner,
|
|
8137
|
+
cursor,
|
|
8138
|
+
limit,
|
|
8139
|
+
filter: { StructType: `${DEEPBOOK_PACKAGE_ID}::${DEEPBOOK_CUSTODIAN_V2_MODULE}::AccountCap` }
|
|
8140
|
+
});
|
|
8141
|
+
if (ownedObjects.data.length !== 0) {
|
|
8142
|
+
return ownedObjects.data[0].data?.objectId ?? null;
|
|
7989
8143
|
}
|
|
7990
|
-
|
|
7991
|
-
|
|
8144
|
+
if (!ownedObjects.hasNextPage) {
|
|
8145
|
+
break;
|
|
8146
|
+
}
|
|
8147
|
+
cursor = ownedObjects.nextCursor ?? void 0;
|
|
8148
|
+
}
|
|
8149
|
+
return null;
|
|
7992
8150
|
}
|
|
7993
8151
|
|
|
7994
8152
|
// src/utils/config.ts
|
|
7995
8153
|
function getAggregatorV2PublishedAt(publishedAt, packages) {
|
|
7996
|
-
if (packages
|
|
8154
|
+
if (packages?.has("aggregator_v2")) {
|
|
7997
8155
|
return packages.get("aggregator_v2");
|
|
7998
8156
|
}
|
|
7999
8157
|
return publishedAt || PUBLISHED_ADDRESSES.V2.Mainnet;
|
|
8000
8158
|
}
|
|
8001
8159
|
function getAggregatorV2ExtendPublishedAt(publishedAt, packages) {
|
|
8002
|
-
if (packages
|
|
8160
|
+
if (packages?.has("aggregator_v2_extend")) {
|
|
8003
8161
|
return packages.get("aggregator_v2_extend");
|
|
8004
8162
|
}
|
|
8005
8163
|
return publishedAt || PUBLISHED_ADDRESSES.V2_EXTEND.Mainnet;
|
|
8006
8164
|
}
|
|
8007
8165
|
function getAggregatorV2Extend2PublishedAt(publishedAt, packages) {
|
|
8008
|
-
if (packages
|
|
8166
|
+
if (packages?.has("aggregator_v2_extend2")) {
|
|
8009
8167
|
return packages.get("aggregator_v2_extend2");
|
|
8010
8168
|
}
|
|
8011
8169
|
return publishedAt || PUBLISHED_ADDRESSES.V2_EXTEND2.Mainnet;
|
|
@@ -8015,8 +8173,9 @@ function getAggregatorV2Extend2PublishedAt(publishedAt, packages) {
|
|
|
8015
8173
|
var import_bn4 = __toESM(require_bn());
|
|
8016
8174
|
function extractGasMetrics(result) {
|
|
8017
8175
|
const effects = result.effects;
|
|
8018
|
-
const
|
|
8019
|
-
if (!
|
|
8176
|
+
const isSuccess = !result.error && effects.status.status === "success";
|
|
8177
|
+
if (!isSuccess) {
|
|
8178
|
+
const errorMsg = result.error ?? effects.status.error ?? "Unknown error";
|
|
8020
8179
|
return {
|
|
8021
8180
|
computationCost: "0",
|
|
8022
8181
|
storageCost: "0",
|
|
@@ -8026,27 +8185,27 @@ function extractGasMetrics(result) {
|
|
|
8026
8185
|
gasUsed: "0",
|
|
8027
8186
|
gasPrice: "0",
|
|
8028
8187
|
success: false,
|
|
8029
|
-
error:
|
|
8188
|
+
error: errorMsg
|
|
8030
8189
|
};
|
|
8031
8190
|
}
|
|
8032
8191
|
const gasUsed = effects.gasUsed;
|
|
8033
8192
|
return {
|
|
8034
|
-
computationCost: gasUsed.computationCost
|
|
8035
|
-
storageCost: gasUsed.storageCost
|
|
8036
|
-
storageRebate: gasUsed.storageRebate
|
|
8037
|
-
nonRefundableStorageFee: gasUsed.nonRefundableStorageFee
|
|
8193
|
+
computationCost: gasUsed.computationCost,
|
|
8194
|
+
storageCost: gasUsed.storageCost,
|
|
8195
|
+
storageRebate: gasUsed.storageRebate,
|
|
8196
|
+
nonRefundableStorageFee: gasUsed.nonRefundableStorageFee,
|
|
8038
8197
|
totalGasCost: calculateTotalGasCost(gasUsed),
|
|
8039
|
-
gasUsed: gasUsed.computationCost
|
|
8198
|
+
gasUsed: gasUsed.computationCost,
|
|
8040
8199
|
gasPrice: "1000",
|
|
8041
8200
|
// Standard Sui gas price in MIST
|
|
8042
8201
|
success: true
|
|
8043
8202
|
};
|
|
8044
8203
|
}
|
|
8045
8204
|
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
|
|
8205
|
+
const computation = new import_bn4.default(gasUsed.computationCost);
|
|
8206
|
+
const storage = new import_bn4.default(gasUsed.storageCost);
|
|
8207
|
+
const rebate = new import_bn4.default(gasUsed.storageRebate);
|
|
8208
|
+
const nonRefundable = new import_bn4.default(gasUsed.nonRefundableStorageFee);
|
|
8050
8209
|
return computation.add(storage).sub(rebate).add(nonRefundable).toString();
|
|
8051
8210
|
}
|
|
8052
8211
|
function calculateGasEfficiency(amountOut, totalGasCost) {
|
|
@@ -8088,12 +8247,12 @@ function calculateAverageGas(analyses) {
|
|
|
8088
8247
|
}
|
|
8089
8248
|
function formatGasMetrics(metrics, isEstimated) {
|
|
8090
8249
|
if (!metrics.success) {
|
|
8091
|
-
return
|
|
8250
|
+
return `Failed: ${metrics.error}`;
|
|
8092
8251
|
}
|
|
8093
8252
|
const totalGas = Number(metrics.totalGasCost);
|
|
8094
8253
|
const gasInSui = totalGas / 1e9;
|
|
8095
8254
|
const estimatedFlag = isEstimated ? " (estimated)" : "";
|
|
8096
|
-
return
|
|
8255
|
+
return `Gas: ${totalGas.toString()} MIST (${gasInSui.toString()} SUI)${estimatedFlag}`;
|
|
8097
8256
|
}
|
|
8098
8257
|
function exportToJSON(comparison) {
|
|
8099
8258
|
return JSON.stringify(comparison, null, 2);
|
|
@@ -8161,63 +8320,62 @@ function exportToCSV(comparison) {
|
|
|
8161
8320
|
// src/utils/msafe.ts
|
|
8162
8321
|
var import_bn5 = __toESM(require_bn());
|
|
8163
8322
|
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 (
|
|
8323
|
+
const result = {
|
|
8324
|
+
...data,
|
|
8325
|
+
amountIn: data?.amountIn?.toString(),
|
|
8326
|
+
amountOut: data?.amountIn?.toString(),
|
|
8327
|
+
paths: data?.paths?.map((item) => {
|
|
8328
|
+
const info = {
|
|
8329
|
+
...item,
|
|
8330
|
+
amountIn: item?.amountIn?.toString(),
|
|
8331
|
+
amountOut: item?.amountOut?.toString()
|
|
8332
|
+
};
|
|
8333
|
+
if (item?.initialPrice) {
|
|
8334
|
+
info["initialPrice"] = item?.initialPrice?.toString();
|
|
8335
|
+
}
|
|
8336
|
+
if (item?.extendedDetails?.after_sqrt_price) {
|
|
8178
8337
|
info["extendedDetails"] = {
|
|
8179
|
-
after_sqrt_price:
|
|
8338
|
+
after_sqrt_price: item?.extendedDetails?.afterSqrtPrice?.toString()
|
|
8180
8339
|
};
|
|
8181
8340
|
}
|
|
8182
8341
|
return info;
|
|
8183
8342
|
})
|
|
8184
|
-
}
|
|
8343
|
+
};
|
|
8185
8344
|
return result;
|
|
8186
8345
|
};
|
|
8187
8346
|
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
|
-
|
|
8347
|
+
const result = {
|
|
8348
|
+
...data,
|
|
8349
|
+
amountIn: new import_bn5.default(data?.amountIn),
|
|
8350
|
+
amountOut: new import_bn5.default(data?.amountIn),
|
|
8351
|
+
paths: data?.paths?.map((item) => {
|
|
8352
|
+
const info = {
|
|
8353
|
+
...item
|
|
8354
|
+
};
|
|
8355
|
+
if (item?.initialPrice) {
|
|
8356
|
+
info["initialPrice"] = new decimal_default(item?.initialPrice?.toString());
|
|
8357
|
+
}
|
|
8358
|
+
if (item?.extendedDetails?.after_sqrt_price) {
|
|
8199
8359
|
info["extendedDetails"] = {
|
|
8200
|
-
after_sqrt_price: new decimal_default(
|
|
8360
|
+
after_sqrt_price: new decimal_default(item?.extendedDetails?.after_sqrt_price?.toString())
|
|
8201
8361
|
};
|
|
8202
8362
|
}
|
|
8203
8363
|
return info;
|
|
8204
8364
|
})
|
|
8205
|
-
}
|
|
8365
|
+
};
|
|
8206
8366
|
return result;
|
|
8207
8367
|
};
|
|
8208
8368
|
|
|
8209
8369
|
// src/utils/transaction.ts
|
|
8210
|
-
function printTransaction(tx, isPrint = true) {
|
|
8211
|
-
|
|
8212
|
-
|
|
8213
|
-
|
|
8214
|
-
|
|
8215
|
-
|
|
8216
|
-
|
|
8217
|
-
|
|
8218
|
-
|
|
8219
|
-
}
|
|
8220
|
-
});
|
|
8370
|
+
async function printTransaction(tx, isPrint = true) {
|
|
8371
|
+
console.log(`inputs`, tx.getData().inputs);
|
|
8372
|
+
tx.getData().commands.forEach((item, index) => {
|
|
8373
|
+
if (isPrint) {
|
|
8374
|
+
console.log(
|
|
8375
|
+
`transaction ${index}: `,
|
|
8376
|
+
JSON.stringify(item, bigIntReplacer, 2)
|
|
8377
|
+
);
|
|
8378
|
+
}
|
|
8221
8379
|
});
|
|
8222
8380
|
}
|
|
8223
8381
|
function bigIntReplacer(key, value) {
|
|
@@ -8289,7 +8447,7 @@ var HaedalHMMV2Router = class {
|
|
|
8289
8447
|
// amount_in
|
|
8290
8448
|
txb.pure.bool(swapData.a2b),
|
|
8291
8449
|
// a2b
|
|
8292
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8450
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
8293
8451
|
// clock
|
|
8294
8452
|
];
|
|
8295
8453
|
txb.moveCall({
|
|
@@ -8339,7 +8497,7 @@ var FullsailRouter = class {
|
|
|
8339
8497
|
txb.object(swapData.poolId),
|
|
8340
8498
|
txb.pure.bool(swapData.direction),
|
|
8341
8499
|
txb.pure.u64(swapData.amountIn),
|
|
8342
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8500
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
8343
8501
|
];
|
|
8344
8502
|
txb.moveCall({
|
|
8345
8503
|
target: `${swapData.publishedAt}::fullsail::swap`,
|
|
@@ -8354,7 +8512,7 @@ var CetusDlmmRouter = class {
|
|
|
8354
8512
|
throw new Error("CetusRouter only supported on mainnet");
|
|
8355
8513
|
}
|
|
8356
8514
|
this.globalConfig = "0xf31b605d117f959b9730e8c07b08b856cb05143c5e81d5751c90d2979e82f599";
|
|
8357
|
-
this.partner = partner
|
|
8515
|
+
this.partner = partner ?? "0x59ae16f6c42f578063c2da9b9c0173fe58120ceae08e40fd8212c8eceb80bb86";
|
|
8358
8516
|
this.versioned = "0x05370b2d656612dd5759cbe80463de301e3b94a921dfc72dd9daa2ecdeb2d0a8";
|
|
8359
8517
|
}
|
|
8360
8518
|
swap(txb, flattenedPath, swapContext, _extends) {
|
|
@@ -8386,7 +8544,7 @@ var CetusDlmmRouter = class {
|
|
|
8386
8544
|
txb.pure.bool(swapData.direction),
|
|
8387
8545
|
txb.pure.u64(swapData.amountIn),
|
|
8388
8546
|
txb.object(this.versioned),
|
|
8389
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8547
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
8390
8548
|
];
|
|
8391
8549
|
txb.moveCall({
|
|
8392
8550
|
target: `${swapData.publishedAt}::cetus_dlmm::swap`,
|
|
@@ -8429,7 +8587,7 @@ var FerraDlmmRouter = class {
|
|
|
8429
8587
|
txb.object(swapData.poolId),
|
|
8430
8588
|
txb.pure.bool(swapData.direction),
|
|
8431
8589
|
txb.pure.u64(swapData.amountIn),
|
|
8432
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8590
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
8433
8591
|
];
|
|
8434
8592
|
txb.moveCall({
|
|
8435
8593
|
target: `${swapData.publishedAt}::ferra_dlmm::swap`,
|
|
@@ -8472,7 +8630,7 @@ var FerraClmmRouter = class {
|
|
|
8472
8630
|
txb.object(swapData.poolId),
|
|
8473
8631
|
txb.pure.bool(swapData.direction),
|
|
8474
8632
|
txb.pure.u64(swapData.amountIn),
|
|
8475
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8633
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
8476
8634
|
];
|
|
8477
8635
|
txb.moveCall({
|
|
8478
8636
|
target: `${swapData.publishedAt}::ferra_clmm::swap`,
|
|
@@ -8614,17 +8772,18 @@ function findPythPriceIDs(paths) {
|
|
|
8614
8772
|
}
|
|
8615
8773
|
var _AggregatorClient = class _AggregatorClient {
|
|
8616
8774
|
constructor(params) {
|
|
8617
|
-
var _a, _b;
|
|
8618
8775
|
this.endpoint = params.endpoint ? processEndpoint(params.endpoint) : DEFAULT_ENDPOINT;
|
|
8619
|
-
|
|
8776
|
+
const network = params.env === 1 /* Testnet */ ? "testnet" : "mainnet";
|
|
8777
|
+
const rpcUrl = params.env === 1 /* Testnet */ ? "https://fullnode.testnet.sui.io:443" : "https://fullnode.mainnet.sui.io:443";
|
|
8778
|
+
this.client = params.client ?? new jsonRpc.SuiJsonRpcClient({ network, url: rpcUrl });
|
|
8620
8779
|
this.signer = params.signer || "";
|
|
8621
8780
|
this.env = params.env || 0 /* Mainnet */;
|
|
8622
8781
|
const config2 = _AggregatorClient.CONFIG[this.env];
|
|
8623
|
-
this.
|
|
8624
|
-
this.pythClient = new SuiPythClient(
|
|
8782
|
+
this.pythAdapter = new PythAdapter(
|
|
8625
8783
|
this.client,
|
|
8626
8784
|
config2.pythStateId,
|
|
8627
|
-
config2.wormholeStateId
|
|
8785
|
+
config2.wormholeStateId,
|
|
8786
|
+
params.pythUrls ?? []
|
|
8628
8787
|
);
|
|
8629
8788
|
this.apiKey = params.apiKey || "";
|
|
8630
8789
|
this.partner = params.partner;
|
|
@@ -8643,16 +8802,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8643
8802
|
} else {
|
|
8644
8803
|
this.overlayFeeRate = 0;
|
|
8645
8804
|
}
|
|
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;
|
|
8805
|
+
this.overlayFeeReceiver = params.overlayFeeReceiver ?? CLIENT_CONFIG.DEFAULT_OVERLAY_FEE_RECEIVER;
|
|
8656
8806
|
}
|
|
8657
8807
|
deepbookv3DeepFeeType() {
|
|
8658
8808
|
if (this.env === 0 /* Mainnet */) {
|
|
@@ -8661,53 +8811,43 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8661
8811
|
return DEEPBOOK_V3_DEEP_FEE_TYPES.Testnet;
|
|
8662
8812
|
}
|
|
8663
8813
|
}
|
|
8664
|
-
getDeepbookV3Config() {
|
|
8665
|
-
return
|
|
8666
|
-
return yield getDeepbookV3Config(this.endpoint);
|
|
8667
|
-
});
|
|
8814
|
+
async getDeepbookV3Config() {
|
|
8815
|
+
return await getDeepbookV3Config(this.endpoint);
|
|
8668
8816
|
}
|
|
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;
|
|
8817
|
+
async getOneCoinUsedToMerge(coinType) {
|
|
8818
|
+
try {
|
|
8819
|
+
const gotCoin = await this.client.getCoins({
|
|
8820
|
+
owner: this.signer,
|
|
8821
|
+
coinType,
|
|
8822
|
+
limit: 1
|
|
8823
|
+
});
|
|
8824
|
+
if (gotCoin.data.length === 1) {
|
|
8825
|
+
return gotCoin.data[0].coinObjectId;
|
|
8683
8826
|
}
|
|
8684
|
-
|
|
8827
|
+
return null;
|
|
8828
|
+
} catch (error) {
|
|
8829
|
+
return null;
|
|
8830
|
+
}
|
|
8685
8831
|
}
|
|
8686
|
-
findRouters(params) {
|
|
8687
|
-
return
|
|
8688
|
-
|
|
8689
|
-
|
|
8690
|
-
|
|
8691
|
-
|
|
8692
|
-
|
|
8693
|
-
|
|
8694
|
-
);
|
|
8695
|
-
});
|
|
8832
|
+
async findRouters(params) {
|
|
8833
|
+
return getRouterResult(
|
|
8834
|
+
this.endpoint,
|
|
8835
|
+
this.apiKey,
|
|
8836
|
+
params,
|
|
8837
|
+
this.overlayFeeRate,
|
|
8838
|
+
this.overlayFeeReceiver
|
|
8839
|
+
);
|
|
8696
8840
|
}
|
|
8697
|
-
findMergeSwapRouters(params) {
|
|
8698
|
-
return
|
|
8699
|
-
|
|
8700
|
-
|
|
8701
|
-
|
|
8702
|
-
|
|
8703
|
-
|
|
8704
|
-
|
|
8705
|
-
);
|
|
8706
|
-
});
|
|
8841
|
+
async findMergeSwapRouters(params) {
|
|
8842
|
+
return getMergeSwapResult(
|
|
8843
|
+
this.endpoint,
|
|
8844
|
+
this.apiKey,
|
|
8845
|
+
params,
|
|
8846
|
+
this.overlayFeeRate,
|
|
8847
|
+
this.overlayFeeReceiver
|
|
8848
|
+
);
|
|
8707
8849
|
}
|
|
8708
|
-
executeFlexibleInputSwap(txb, inputCoin, routerData, expectedAmountOut, amountLimit, pythPriceIDs, partner, deepbookv3DeepFee, packages) {
|
|
8709
|
-
return __async(this, null, function* () {
|
|
8710
|
-
});
|
|
8850
|
+
async executeFlexibleInputSwap(txb, inputCoin, routerData, expectedAmountOut, amountLimit, pythPriceIDs, partner, deepbookv3DeepFee, packages) {
|
|
8711
8851
|
}
|
|
8712
8852
|
newDexRouterV3(provider, pythPriceIDs, partner, cetusDlmmPartner) {
|
|
8713
8853
|
switch (provider) {
|
|
@@ -9093,55 +9233,53 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
9093
9233
|
);
|
|
9094
9234
|
return outputCoin;
|
|
9095
9235
|
}
|
|
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
|
-
|
|
9236
|
+
async routerSwap(params) {
|
|
9237
|
+
const { router, inputCoin, slippage, txb, partner } = params;
|
|
9238
|
+
if (slippage > 1 || slippage < 0) {
|
|
9239
|
+
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
|
|
9240
|
+
}
|
|
9241
|
+
if (!params.router.packages || !params.router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
9242
|
+
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
9243
|
+
}
|
|
9244
|
+
const byAmountIn = params.router.byAmountIn;
|
|
9245
|
+
const amountIn = router.amountIn;
|
|
9246
|
+
const amountOut = router.amountOut;
|
|
9247
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
9248
|
+
let overlayFee = new import_bn6.default(0);
|
|
9249
|
+
if (byAmountIn) {
|
|
9250
|
+
overlayFee = amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
9251
|
+
} else {
|
|
9252
|
+
overlayFee = amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
9253
|
+
}
|
|
9254
|
+
const expectedAmountOut = byAmountIn ? amountOut.sub(overlayFee) : amountOut;
|
|
9255
|
+
const expectedAmountIn = byAmountIn ? amountIn : amountIn.add(overlayFee);
|
|
9256
|
+
const amountLimit = CalculateAmountLimitBN(
|
|
9257
|
+
byAmountIn ? expectedAmountOut : expectedAmountIn,
|
|
9258
|
+
byAmountIn,
|
|
9259
|
+
slippage
|
|
9260
|
+
);
|
|
9261
|
+
const priceIDs = findPythPriceIDs(router.paths);
|
|
9262
|
+
const priceInfoObjectIds = priceIDs.length > 0 ? await this.updatePythPriceIDs(priceIDs, txb) : /* @__PURE__ */ new Map();
|
|
9263
|
+
if (byAmountIn) {
|
|
9264
|
+
return this.expectInputSwapV3(
|
|
9265
|
+
txb,
|
|
9266
|
+
inputCoin,
|
|
9267
|
+
router,
|
|
9268
|
+
amountOut.toString(),
|
|
9269
|
+
amountLimit.toString(),
|
|
9270
|
+
priceInfoObjectIds,
|
|
9271
|
+
partner ?? this.partner
|
|
9121
9272
|
);
|
|
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
|
-
});
|
|
9273
|
+
} else {
|
|
9274
|
+
return this.expectOutputSwapV3(
|
|
9275
|
+
txb,
|
|
9276
|
+
inputCoin,
|
|
9277
|
+
router,
|
|
9278
|
+
amountOut.toString(),
|
|
9279
|
+
amountLimit.toString(),
|
|
9280
|
+
partner ?? this.partner
|
|
9281
|
+
);
|
|
9282
|
+
}
|
|
9145
9283
|
}
|
|
9146
9284
|
/**
|
|
9147
9285
|
* Router swap with max amount in validation.
|
|
@@ -9152,434 +9290,402 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
9152
9290
|
* @returns TransactionObjectArgument - The output coin from the swap
|
|
9153
9291
|
* @throws Error if input coin amount exceeds maxAmountIn
|
|
9154
9292
|
*/
|
|
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
|
-
|
|
9293
|
+
async routerSwapWithMaxAmountIn(params) {
|
|
9294
|
+
const { router, inputCoin, slippage, txb, partner, maxAmountIn } = params;
|
|
9295
|
+
if (slippage > 1 || slippage < 0) {
|
|
9296
|
+
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
|
|
9297
|
+
}
|
|
9298
|
+
if (!params.router.packages || !params.router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
9299
|
+
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
9300
|
+
}
|
|
9301
|
+
const byAmountIn = params.router.byAmountIn;
|
|
9302
|
+
const amountIn = router.amountIn;
|
|
9303
|
+
const amountOut = router.amountOut;
|
|
9304
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
9305
|
+
let overlayFee = new import_bn6.default(0);
|
|
9306
|
+
if (byAmountIn) {
|
|
9307
|
+
overlayFee = amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
9308
|
+
} else {
|
|
9309
|
+
overlayFee = amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
9310
|
+
}
|
|
9311
|
+
const expectedAmountOut = byAmountIn ? amountOut.sub(overlayFee) : amountOut;
|
|
9312
|
+
const expectedAmountIn = byAmountIn ? amountIn : amountIn.add(overlayFee);
|
|
9313
|
+
const amountLimit = CalculateAmountLimitBN(
|
|
9314
|
+
byAmountIn ? expectedAmountOut : expectedAmountIn,
|
|
9315
|
+
byAmountIn,
|
|
9316
|
+
slippage
|
|
9317
|
+
);
|
|
9318
|
+
const priceIDs = findPythPriceIDs(router.paths);
|
|
9319
|
+
const priceInfoObjectIds = priceIDs.length > 0 ? await this.updatePythPriceIDs(priceIDs, txb) : /* @__PURE__ */ new Map();
|
|
9320
|
+
if (byAmountIn) {
|
|
9321
|
+
return this.expectInputSwapV3WithMaxAmountIn(
|
|
9322
|
+
txb,
|
|
9323
|
+
inputCoin,
|
|
9324
|
+
router,
|
|
9325
|
+
maxAmountIn,
|
|
9326
|
+
amountOut.toString(),
|
|
9327
|
+
amountLimit.toString(),
|
|
9328
|
+
priceInfoObjectIds,
|
|
9329
|
+
partner ?? this.partner
|
|
9180
9330
|
);
|
|
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
|
-
});
|
|
9331
|
+
} else {
|
|
9332
|
+
return this.expectOutputSwapV3WithMaxAmountIn(
|
|
9333
|
+
txb,
|
|
9334
|
+
inputCoin,
|
|
9335
|
+
router,
|
|
9336
|
+
maxAmountIn,
|
|
9337
|
+
amountOut.toString(),
|
|
9338
|
+
amountLimit.toString(),
|
|
9339
|
+
partner ?? this.partner
|
|
9340
|
+
);
|
|
9341
|
+
}
|
|
9206
9342
|
}
|
|
9207
9343
|
// auto build input coin
|
|
9208
9344
|
// auto merge, transfer or destory target coin.
|
|
9209
|
-
fastRouterSwap(params) {
|
|
9210
|
-
|
|
9211
|
-
|
|
9212
|
-
|
|
9213
|
-
|
|
9214
|
-
|
|
9215
|
-
|
|
9216
|
-
|
|
9217
|
-
|
|
9218
|
-
|
|
9219
|
-
|
|
9220
|
-
|
|
9221
|
-
|
|
9222
|
-
|
|
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
|
|
9345
|
+
async fastRouterSwap(params) {
|
|
9346
|
+
const { router, slippage, txb, partner, payDeepFeeAmount } = params;
|
|
9347
|
+
const fromCoinType = router.paths[0].from;
|
|
9348
|
+
const targetCoinType = router.paths[router.paths.length - 1].target;
|
|
9349
|
+
const byAmountIn = router.byAmountIn;
|
|
9350
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
9351
|
+
let overlayFee = 0;
|
|
9352
|
+
if (byAmountIn) {
|
|
9353
|
+
overlayFee = Number(
|
|
9354
|
+
router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
9355
|
+
);
|
|
9356
|
+
} else {
|
|
9357
|
+
overlayFee = Number(
|
|
9358
|
+
router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
9232
9359
|
);
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
9360
|
+
}
|
|
9361
|
+
const expectedAmountOut = byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
|
|
9362
|
+
const expectedAmountIn = byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
|
|
9363
|
+
const amountLimit = CalculateAmountLimit(
|
|
9364
|
+
byAmountIn ? expectedAmountOut : expectedAmountIn,
|
|
9365
|
+
byAmountIn,
|
|
9366
|
+
slippage
|
|
9367
|
+
);
|
|
9368
|
+
const amount = byAmountIn ? expectedAmountIn : amountLimit;
|
|
9369
|
+
let inputCoin = transactions.coinWithBalance({
|
|
9370
|
+
balance: BigInt(amount.toString()),
|
|
9371
|
+
useGasCoin: true,
|
|
9372
|
+
type: fromCoinType
|
|
9373
|
+
});
|
|
9374
|
+
let deepCoin;
|
|
9375
|
+
if (payDeepFeeAmount && payDeepFeeAmount > 0) {
|
|
9376
|
+
deepCoin = transactions.coinWithBalance({
|
|
9377
|
+
balance: BigInt(payDeepFeeAmount),
|
|
9378
|
+
type: this.deepbookv3DeepFeeType()
|
|
9238
9379
|
});
|
|
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]);
|
|
9380
|
+
}
|
|
9381
|
+
const routerSwapParams = {
|
|
9382
|
+
router,
|
|
9383
|
+
inputCoin,
|
|
9384
|
+
slippage,
|
|
9385
|
+
txb,
|
|
9386
|
+
partner: partner ?? this.partner,
|
|
9387
|
+
deepbookv3DeepFee: deepCoin
|
|
9388
|
+
};
|
|
9389
|
+
const targetCoin = await this.routerSwap(routerSwapParams);
|
|
9390
|
+
if (CoinUtils.isSuiCoin(targetCoinType)) {
|
|
9391
|
+
txb.mergeCoins(txb.gas, [targetCoin]);
|
|
9392
|
+
} else {
|
|
9393
|
+
const targetCoinObjID = await this.getOneCoinUsedToMerge(targetCoinType);
|
|
9394
|
+
if (targetCoinObjID != null) {
|
|
9395
|
+
txb.mergeCoins(txb.object(targetCoinObjID), [targetCoin]);
|
|
9257
9396
|
} 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));
|
|
9397
|
+
transferOrDestroyCoin(
|
|
9398
|
+
{
|
|
9399
|
+
coin: targetCoin,
|
|
9400
|
+
coinType: targetCoinType,
|
|
9401
|
+
packages: router.packages
|
|
9402
|
+
},
|
|
9403
|
+
txb
|
|
9404
|
+
);
|
|
9317
9405
|
}
|
|
9318
|
-
|
|
9319
|
-
});
|
|
9406
|
+
}
|
|
9320
9407
|
}
|
|
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
|
-
|
|
9408
|
+
async mergeSwap(params) {
|
|
9409
|
+
const { router, inputCoins, slippage, txb, partner } = params;
|
|
9410
|
+
if (slippage > 1 || slippage < 0) {
|
|
9411
|
+
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
|
|
9412
|
+
}
|
|
9413
|
+
if (!router.packages || !router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
9414
|
+
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
9415
|
+
}
|
|
9416
|
+
if (!router.allRoutes || router.allRoutes.length === 0) {
|
|
9417
|
+
throw new Error("No routes found in merge swap response");
|
|
9418
|
+
}
|
|
9419
|
+
const outputCoins = [];
|
|
9420
|
+
for (let i = 0; i < router.allRoutes.length && i < inputCoins.length; i++) {
|
|
9421
|
+
const route = router.allRoutes[i];
|
|
9422
|
+
const inputCoin = inputCoins[i];
|
|
9423
|
+
const routeRouter = {
|
|
9424
|
+
quoteID: router.quoteID,
|
|
9425
|
+
amountIn: route.amountIn,
|
|
9426
|
+
amountOut: route.amountOut,
|
|
9427
|
+
deviationRatio: Number(route.deviationRatio),
|
|
9428
|
+
byAmountIn: true,
|
|
9429
|
+
// Merge swap is always by amount in
|
|
9430
|
+
paths: route.paths,
|
|
9431
|
+
insufficientLiquidity: false,
|
|
9432
|
+
packages: router.packages
|
|
9433
|
+
};
|
|
9434
|
+
const routerParams = {
|
|
9435
|
+
router: routeRouter,
|
|
9436
|
+
inputCoin: inputCoin.coin,
|
|
9347
9437
|
slippage,
|
|
9348
9438
|
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
|
-
)
|
|
9439
|
+
partner: partner ?? this.partner
|
|
9440
|
+
};
|
|
9441
|
+
const outputCoin = await this.routerSwap(routerParams);
|
|
9442
|
+
outputCoins.push(outputCoin);
|
|
9443
|
+
}
|
|
9444
|
+
if (outputCoins.length === 0) {
|
|
9445
|
+
throw new Error("No output coins generated from merge swap");
|
|
9446
|
+
}
|
|
9447
|
+
let finalOutputCoin = outputCoins[0];
|
|
9448
|
+
if (outputCoins.length > 1) {
|
|
9449
|
+
txb.mergeCoins(finalOutputCoin, outputCoins.slice(1));
|
|
9450
|
+
}
|
|
9451
|
+
return finalOutputCoin;
|
|
9452
|
+
}
|
|
9453
|
+
async fastMergeSwap(params) {
|
|
9454
|
+
const { router, slippage, txb, partner } = params;
|
|
9455
|
+
if (!router || !router.allRoutes || router.allRoutes.length === 0) {
|
|
9456
|
+
throw new Error("Invalid router: no routes found");
|
|
9457
|
+
}
|
|
9458
|
+
const firstRoute = router.allRoutes[0];
|
|
9459
|
+
const targetCoinType = firstRoute.paths[firstRoute.paths.length - 1].target;
|
|
9460
|
+
const inputCoins = [];
|
|
9461
|
+
const coinTypeSet = /* @__PURE__ */ new Set();
|
|
9462
|
+
for (const route of router.allRoutes) {
|
|
9463
|
+
const firstCoinType = route.paths[0].from;
|
|
9464
|
+
if (coinTypeSet.has(firstCoinType)) {
|
|
9465
|
+
continue;
|
|
9466
|
+
}
|
|
9467
|
+
coinTypeSet.add(firstCoinType);
|
|
9468
|
+
const coin = transactions.coinWithBalance({
|
|
9469
|
+
balance: BigInt(route.amountIn.toString()),
|
|
9470
|
+
useGasCoin: CoinUtils.isSuiCoin(firstCoinType),
|
|
9471
|
+
type: firstCoinType
|
|
9472
|
+
});
|
|
9473
|
+
inputCoins.push({ coinType: firstCoinType, coin });
|
|
9474
|
+
}
|
|
9475
|
+
const mergeSwapParams = {
|
|
9476
|
+
router,
|
|
9477
|
+
inputCoins,
|
|
9478
|
+
slippage,
|
|
9479
|
+
txb,
|
|
9480
|
+
partner: partner ?? this.partner
|
|
9481
|
+
};
|
|
9482
|
+
const targetCoin = await this.mergeSwap(mergeSwapParams);
|
|
9483
|
+
if (CoinUtils.isSuiCoin(targetCoinType)) {
|
|
9484
|
+
txb.mergeCoins(txb.gas, [targetCoin]);
|
|
9485
|
+
} else {
|
|
9486
|
+
const targetCoinObjID = await this.getOneCoinUsedToMerge(targetCoinType);
|
|
9487
|
+
if (targetCoinObjID != null) {
|
|
9488
|
+
txb.mergeCoins(txb.object(targetCoinObjID), [targetCoin]);
|
|
9380
9489
|
} else {
|
|
9381
|
-
|
|
9382
|
-
|
|
9490
|
+
transferOrDestroyCoin(
|
|
9491
|
+
{
|
|
9492
|
+
coin: targetCoin,
|
|
9493
|
+
coinType: targetCoinType,
|
|
9494
|
+
packages: router.packages
|
|
9495
|
+
},
|
|
9496
|
+
txb
|
|
9383
9497
|
);
|
|
9384
9498
|
}
|
|
9385
|
-
|
|
9386
|
-
|
|
9387
|
-
|
|
9388
|
-
|
|
9389
|
-
|
|
9390
|
-
|
|
9499
|
+
}
|
|
9500
|
+
}
|
|
9501
|
+
async fixableRouterSwapV3(params) {
|
|
9502
|
+
const { router, inputCoin, slippage, txb, partner } = params;
|
|
9503
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
9504
|
+
let overlayFee = 0;
|
|
9505
|
+
if (router.byAmountIn) {
|
|
9506
|
+
overlayFee = Number(
|
|
9507
|
+
router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
9391
9508
|
);
|
|
9392
|
-
|
|
9393
|
-
|
|
9394
|
-
|
|
9395
|
-
|
|
9396
|
-
|
|
9397
|
-
|
|
9398
|
-
|
|
9399
|
-
|
|
9400
|
-
|
|
9401
|
-
|
|
9402
|
-
|
|
9403
|
-
|
|
9404
|
-
|
|
9405
|
-
|
|
9406
|
-
|
|
9407
|
-
|
|
9408
|
-
|
|
9409
|
-
|
|
9410
|
-
|
|
9411
|
-
|
|
9412
|
-
)
|
|
9413
|
-
|
|
9414
|
-
|
|
9509
|
+
} else {
|
|
9510
|
+
overlayFee = Number(
|
|
9511
|
+
router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
9512
|
+
);
|
|
9513
|
+
}
|
|
9514
|
+
const expectedAmountOut = router.byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
|
|
9515
|
+
const expectedAmountIn = router.byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
|
|
9516
|
+
const amountLimit = CalculateAmountLimitBN(
|
|
9517
|
+
router.byAmountIn ? expectedAmountOut : expectedAmountIn,
|
|
9518
|
+
router.byAmountIn,
|
|
9519
|
+
slippage
|
|
9520
|
+
);
|
|
9521
|
+
const priceIDs = findPythPriceIDs(router.paths);
|
|
9522
|
+
const priceInfoObjectIds = priceIDs.length > 0 ? await this.updatePythPriceIDs(priceIDs, txb) : /* @__PURE__ */ new Map();
|
|
9523
|
+
if (router.byAmountIn) {
|
|
9524
|
+
return this.expectInputSwapV3(
|
|
9525
|
+
txb,
|
|
9526
|
+
inputCoin,
|
|
9527
|
+
router,
|
|
9528
|
+
expectedAmountOut.toString(),
|
|
9529
|
+
amountLimit.toString(),
|
|
9530
|
+
priceInfoObjectIds,
|
|
9531
|
+
partner ?? this.partner
|
|
9532
|
+
);
|
|
9533
|
+
} else {
|
|
9534
|
+
return this.expectOutputSwapV3(
|
|
9535
|
+
txb,
|
|
9536
|
+
inputCoin,
|
|
9537
|
+
router,
|
|
9538
|
+
expectedAmountOut.toString(),
|
|
9539
|
+
amountLimit.toString(),
|
|
9540
|
+
partner ?? this.partner
|
|
9541
|
+
);
|
|
9542
|
+
}
|
|
9415
9543
|
}
|
|
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");
|
|
9544
|
+
async swapInPools(params) {
|
|
9545
|
+
const { from, target, amount, byAmountIn, pools } = params;
|
|
9546
|
+
const fromCoin = completionCoin(from);
|
|
9547
|
+
const targetCoin = completionCoin(target);
|
|
9548
|
+
const tx = new transactions.Transaction();
|
|
9549
|
+
const direction = compareCoins(fromCoin, targetCoin);
|
|
9550
|
+
const coinA = direction ? fromCoin : targetCoin;
|
|
9551
|
+
const coinB = direction ? targetCoin : fromCoin;
|
|
9552
|
+
const typeArguments = [coinA, coinB];
|
|
9553
|
+
const integratePublishedAt = this.env === 0 /* Mainnet */ ? "0xfbb32ac0fa89a3cb0c56c745b688c6d2a53ac8e43447119ad822763997ffb9c3" : "0xab2d58dd28ff0dc19b18ab2c634397b785a38c342a8f5065ade5f53f9dbffa1c";
|
|
9554
|
+
for (let i = 0; i < pools.length; i++) {
|
|
9555
|
+
const args = [
|
|
9556
|
+
tx.object(pools[i]),
|
|
9557
|
+
tx.pure.bool(direction),
|
|
9558
|
+
tx.pure.bool(byAmountIn),
|
|
9559
|
+
tx.pure.u64(amount.toString())
|
|
9560
|
+
];
|
|
9561
|
+
tx.moveCall({
|
|
9562
|
+
target: `${integratePublishedAt}::fetcher_script::calculate_swap_result`,
|
|
9563
|
+
arguments: args,
|
|
9564
|
+
typeArguments
|
|
9453
9565
|
});
|
|
9454
|
-
|
|
9455
|
-
|
|
9456
|
-
|
|
9457
|
-
|
|
9458
|
-
|
|
9459
|
-
|
|
9460
|
-
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
|
|
9464
|
-
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
|
|
9472
|
-
|
|
9473
|
-
|
|
9474
|
-
|
|
9566
|
+
}
|
|
9567
|
+
tx.setSenderIfNotSet(this.signer || "0x0");
|
|
9568
|
+
const simulateRes = await this.client.devInspectTransactionBlock({
|
|
9569
|
+
sender: this.signer || "0x0",
|
|
9570
|
+
transactionBlock: tx
|
|
9571
|
+
});
|
|
9572
|
+
if (simulateRes.error) {
|
|
9573
|
+
throw new Error("Simulation error: " + simulateRes.error);
|
|
9574
|
+
}
|
|
9575
|
+
const events = simulateRes.events ?? [];
|
|
9576
|
+
const valueData = events.filter((item) => {
|
|
9577
|
+
return item.type.includes("CalculatedSwapResultEvent");
|
|
9578
|
+
});
|
|
9579
|
+
if (valueData.length === 0 || valueData.length !== pools.length) {
|
|
9580
|
+
throw new Error("Simulate event result error");
|
|
9581
|
+
}
|
|
9582
|
+
let tempMaxAmount = byAmountIn ? new import_bn6.default(0) : new import_bn6.default(U64_MAX);
|
|
9583
|
+
let tempIndex = 0;
|
|
9584
|
+
for (let i = 0; i < valueData.length; i += 1) {
|
|
9585
|
+
const eventJson2 = valueData[i].parsedJson;
|
|
9586
|
+
if (eventJson2?.data?.is_exceed) {
|
|
9587
|
+
continue;
|
|
9588
|
+
}
|
|
9589
|
+
if (params.byAmountIn) {
|
|
9590
|
+
const amount2 = new import_bn6.default(eventJson2?.data?.amount_out ?? 0);
|
|
9591
|
+
if (amount2.gt(tempMaxAmount)) {
|
|
9592
|
+
tempIndex = i;
|
|
9593
|
+
tempMaxAmount = amount2;
|
|
9594
|
+
}
|
|
9595
|
+
} else {
|
|
9596
|
+
const amount2 = new import_bn6.default(eventJson2?.data?.amount_out ?? 0);
|
|
9597
|
+
if (amount2.lt(tempMaxAmount)) {
|
|
9598
|
+
tempIndex = i;
|
|
9599
|
+
tempMaxAmount = amount2;
|
|
9475
9600
|
}
|
|
9476
9601
|
}
|
|
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
|
-
|
|
9602
|
+
}
|
|
9603
|
+
const eventJson = valueData[tempIndex].parsedJson;
|
|
9604
|
+
const eventData = eventJson?.data;
|
|
9605
|
+
const [decimalA, decimalB] = await Promise.all([
|
|
9606
|
+
this.client.getCoinMetadata({ coinType: coinA }).then((res) => res?.decimals ?? null),
|
|
9607
|
+
this.client.getCoinMetadata({ coinType: coinB }).then((res) => res?.decimals ?? null)
|
|
9608
|
+
]);
|
|
9609
|
+
if (decimalA == null || decimalB == null) {
|
|
9610
|
+
throw new Error("Cannot get coin decimals");
|
|
9611
|
+
}
|
|
9612
|
+
const feeRate = Number(eventData?.fee_rate ?? 0) / 1e6;
|
|
9613
|
+
const pureAmountIn = new import_bn6.default(eventData?.amount_in ?? 0);
|
|
9614
|
+
const feeAmount = new import_bn6.default(eventData?.fee_amount ?? 0);
|
|
9615
|
+
const amountIn = pureAmountIn.add(feeAmount);
|
|
9616
|
+
const cetusRouterV3PublishedAt = this.env === 0 /* Mainnet */ ? MAINNET_CETUS_V3_PUBLISHED_AT : TESTNET_CETUS_V3_PUBLISHED_AT;
|
|
9617
|
+
const aggregatorV3PublishedAt = this.env === 0 /* Mainnet */ ? AGGREGATOR_V3_CONFIG.DEFAULT_PUBLISHED_AT.Mainnet : AGGREGATOR_V3_CONFIG.DEFAULT_PUBLISHED_AT.Testnet;
|
|
9618
|
+
const routeData = {
|
|
9619
|
+
amountIn,
|
|
9620
|
+
amountOut: new import_bn6.default(eventData?.amount_out ?? 0),
|
|
9621
|
+
deviationRatio: 0,
|
|
9622
|
+
paths: [
|
|
9623
|
+
{
|
|
9624
|
+
id: pools[tempIndex],
|
|
9625
|
+
direction,
|
|
9626
|
+
provider: CETUS,
|
|
9627
|
+
from: fromCoin,
|
|
9628
|
+
target: targetCoin,
|
|
9629
|
+
feeRate,
|
|
9630
|
+
amountIn: amountIn.toString(),
|
|
9631
|
+
amountOut: eventData?.amount_out ?? "0",
|
|
9632
|
+
publishedAt: cetusRouterV3PublishedAt,
|
|
9633
|
+
extendedDetails: {
|
|
9634
|
+
afterSqrtPrice: eventData?.after_sqrt_price
|
|
9509
9635
|
}
|
|
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
9636
|
}
|
|
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
|
-
});
|
|
9637
|
+
],
|
|
9638
|
+
insufficientLiquidity: false,
|
|
9639
|
+
byAmountIn: params.byAmountIn,
|
|
9640
|
+
quoteID: `degraded-${generateUUID()}`,
|
|
9641
|
+
packages: /* @__PURE__ */ new Map([
|
|
9642
|
+
[
|
|
9643
|
+
PACKAGE_NAMES.AGGREGATOR_V3,
|
|
9644
|
+
aggregatorV3PublishedAt
|
|
9645
|
+
]
|
|
9646
|
+
])
|
|
9647
|
+
};
|
|
9648
|
+
const result = {
|
|
9649
|
+
isExceed: eventData?.is_exceed ?? false,
|
|
9650
|
+
routeData
|
|
9651
|
+
};
|
|
9652
|
+
return result;
|
|
9565
9653
|
}
|
|
9566
|
-
|
|
9567
|
-
|
|
9568
|
-
|
|
9569
|
-
|
|
9570
|
-
|
|
9571
|
-
|
|
9572
|
-
|
|
9654
|
+
async updatePythPriceIDs(priceIDs, txb) {
|
|
9655
|
+
const priceUpdateData = await this.pythAdapter.getPriceFeedsUpdateData(priceIDs);
|
|
9656
|
+
let priceInfoObjectIds;
|
|
9657
|
+
try {
|
|
9658
|
+
priceInfoObjectIds = await this.pythAdapter.updatePriceFeeds(
|
|
9659
|
+
txb,
|
|
9660
|
+
priceUpdateData,
|
|
9661
|
+
priceIDs
|
|
9662
|
+
);
|
|
9663
|
+
} catch (e) {
|
|
9664
|
+
throw new Error(
|
|
9665
|
+
`Failed to update Pyth price feeds. Ensure pythUrls are configured correctly. Detailed error: ${e}`
|
|
9666
|
+
);
|
|
9667
|
+
}
|
|
9668
|
+
const priceInfoObjectIdsMap = /* @__PURE__ */ new Map();
|
|
9669
|
+
for (let i = 0; i < priceIDs.length; i++) {
|
|
9670
|
+
priceInfoObjectIdsMap.set(priceIDs[i], priceInfoObjectIds[i]);
|
|
9671
|
+
}
|
|
9672
|
+
return priceInfoObjectIdsMap;
|
|
9673
|
+
}
|
|
9674
|
+
async devInspectTransactionBlock(txb) {
|
|
9675
|
+
txb.setSenderIfNotSet(this.signer || "0x0");
|
|
9676
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
9677
|
+
sender: this.signer || "0x0",
|
|
9678
|
+
transactionBlock: txb
|
|
9573
9679
|
});
|
|
9680
|
+
return res;
|
|
9574
9681
|
}
|
|
9575
|
-
sendTransaction(txb, signer) {
|
|
9576
|
-
|
|
9577
|
-
|
|
9578
|
-
|
|
9579
|
-
|
|
9580
|
-
});
|
|
9581
|
-
return res;
|
|
9682
|
+
async sendTransaction(txb, signer) {
|
|
9683
|
+
const res = await this.client.signAndExecuteTransaction({
|
|
9684
|
+
transaction: txb,
|
|
9685
|
+
signer,
|
|
9686
|
+
options: { showEffects: true, showEvents: true, showBalanceChanges: true }
|
|
9582
9687
|
});
|
|
9688
|
+
return res;
|
|
9583
9689
|
}
|
|
9584
9690
|
};
|
|
9585
9691
|
_AggregatorClient.CONFIG = {
|
|
@@ -9648,4 +9754,174 @@ decimal.js/decimal.mjs:
|
|
|
9648
9754
|
*)
|
|
9649
9755
|
*/
|
|
9650
9756
|
|
|
9651
|
-
|
|
9757
|
+
exports.AFSUI = AFSUI;
|
|
9758
|
+
exports.AFTERMATH = AFTERMATH;
|
|
9759
|
+
exports.AFTERMATH_AMM = AFTERMATH_AMM;
|
|
9760
|
+
exports.AFTERMATH_MODULE = AFTERMATH_MODULE;
|
|
9761
|
+
exports.AGGREGATOR = AGGREGATOR;
|
|
9762
|
+
exports.AGGREGATOR_V3_CONFIG = AGGREGATOR_V3_CONFIG;
|
|
9763
|
+
exports.ALL_DEXES = ALL_DEXES;
|
|
9764
|
+
exports.ALPHAFI = ALPHAFI;
|
|
9765
|
+
exports.AggregatorClient = AggregatorClient;
|
|
9766
|
+
exports.AggregatorConfig = AggregatorConfig;
|
|
9767
|
+
exports.AggregatorError = AggregatorError;
|
|
9768
|
+
exports.AggregatorServerErrorCode = AggregatorServerErrorCode;
|
|
9769
|
+
exports.BLUEFIN = BLUEFIN;
|
|
9770
|
+
exports.BLUEMOVE = BLUEMOVE;
|
|
9771
|
+
exports.CETUS = CETUS;
|
|
9772
|
+
exports.CETUSDLMM = CETUSDLMM;
|
|
9773
|
+
exports.CETUS_DEX = CETUS_DEX;
|
|
9774
|
+
exports.CETUS_MODULE = CETUS_MODULE;
|
|
9775
|
+
exports.CETUS_PUBLISHED_AT = CETUS_PUBLISHED_AT;
|
|
9776
|
+
exports.CHECK_COINS_THRESHOLD_FUNC = CHECK_COINS_THRESHOLD_FUNC;
|
|
9777
|
+
exports.CLIENT_CONFIG = CLIENT_CONFIG;
|
|
9778
|
+
exports.CLOCK_ADDRESS = CLOCK_ADDRESS;
|
|
9779
|
+
exports.CoinInfoAddress = CoinInfoAddress;
|
|
9780
|
+
exports.CoinStoreAddress = CoinStoreAddress;
|
|
9781
|
+
exports.CoinUtils = CoinUtils;
|
|
9782
|
+
exports.ConfigErrorCode = ConfigErrorCode;
|
|
9783
|
+
exports.DEEPBOOKV2 = DEEPBOOKV2;
|
|
9784
|
+
exports.DEEPBOOKV3 = DEEPBOOKV3;
|
|
9785
|
+
exports.DEEPBOOK_CLOB_V2_MODULE = DEEPBOOK_CLOB_V2_MODULE;
|
|
9786
|
+
exports.DEEPBOOK_CUSTODIAN_V2_MODULE = DEEPBOOK_CUSTODIAN_V2_MODULE;
|
|
9787
|
+
exports.DEEPBOOK_DEX = DEEPBOOK_DEX;
|
|
9788
|
+
exports.DEEPBOOK_MODULE = DEEPBOOK_MODULE;
|
|
9789
|
+
exports.DEEPBOOK_PACKAGE_ID = DEEPBOOK_PACKAGE_ID;
|
|
9790
|
+
exports.DEEPBOOK_PUBLISHED_AT = DEEPBOOK_PUBLISHED_AT;
|
|
9791
|
+
exports.DEEPBOOK_V3_DEEP_FEE_TYPES = DEEPBOOK_V3_DEEP_FEE_TYPES;
|
|
9792
|
+
exports.DEFAULT_AGG_V2_ENDPOINT = DEFAULT_AGG_V2_ENDPOINT;
|
|
9793
|
+
exports.DEFAULT_AGG_V3_ENDPOINT = DEFAULT_AGG_V3_ENDPOINT;
|
|
9794
|
+
exports.DEFAULT_ENDPOINT = DEFAULT_ENDPOINT;
|
|
9795
|
+
exports.DEFAULT_GAS_BUDGET_FOR_MERGE = DEFAULT_GAS_BUDGET_FOR_MERGE;
|
|
9796
|
+
exports.DEFAULT_GAS_BUDGET_FOR_SPLIT = DEFAULT_GAS_BUDGET_FOR_SPLIT;
|
|
9797
|
+
exports.DEFAULT_GAS_BUDGET_FOR_STAKE = DEFAULT_GAS_BUDGET_FOR_STAKE;
|
|
9798
|
+
exports.DEFAULT_GAS_BUDGET_FOR_TRANSFER = DEFAULT_GAS_BUDGET_FOR_TRANSFER;
|
|
9799
|
+
exports.DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI = DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI;
|
|
9800
|
+
exports.DEFAULT_NFT_TRANSFER_GAS_FEE = DEFAULT_NFT_TRANSFER_GAS_FEE;
|
|
9801
|
+
exports.Env = Env;
|
|
9802
|
+
exports.FERRACLMM = FERRACLMM;
|
|
9803
|
+
exports.FERRADLMM = FERRADLMM;
|
|
9804
|
+
exports.FLOWXV2 = FLOWXV2;
|
|
9805
|
+
exports.FLOWXV3 = FLOWXV3;
|
|
9806
|
+
exports.FLOWX_AMM = FLOWX_AMM;
|
|
9807
|
+
exports.FLOWX_AMM_MODULE = FLOWX_AMM_MODULE;
|
|
9808
|
+
exports.FULLSAIL = FULLSAIL;
|
|
9809
|
+
exports.FlashSwapA2BFunc = FlashSwapA2BFunc;
|
|
9810
|
+
exports.FlashSwapB2AFunc = FlashSwapB2AFunc;
|
|
9811
|
+
exports.FlashSwapFunc = FlashSwapFunc;
|
|
9812
|
+
exports.FlashSwapWithPartnerA2BFunc = FlashSwapWithPartnerA2BFunc;
|
|
9813
|
+
exports.FlashSwapWithPartnerB2AFunc = FlashSwapWithPartnerB2AFunc;
|
|
9814
|
+
exports.FlashSwapWithPartnerFunc = FlashSwapWithPartnerFunc;
|
|
9815
|
+
exports.GAS_SYMBOL = GAS_SYMBOL;
|
|
9816
|
+
exports.GAS_TYPE_ARG = GAS_TYPE_ARG;
|
|
9817
|
+
exports.GAS_TYPE_ARG_LONG = GAS_TYPE_ARG_LONG;
|
|
9818
|
+
exports.HAEDAL = HAEDAL;
|
|
9819
|
+
exports.HAEDALHMMV2 = HAEDALHMMV2;
|
|
9820
|
+
exports.HAEDALPMM = HAEDALPMM;
|
|
9821
|
+
exports.HAWAL = HAWAL;
|
|
9822
|
+
exports.INTEGRATE = INTEGRATE;
|
|
9823
|
+
exports.JOIN_FUNC = JOIN_FUNC;
|
|
9824
|
+
exports.KRIYA = KRIYA;
|
|
9825
|
+
exports.KRIYAV3 = KRIYAV3;
|
|
9826
|
+
exports.KRIYA_DEX = KRIYA_DEX;
|
|
9827
|
+
exports.KRIYA_MODULE = KRIYA_MODULE;
|
|
9828
|
+
exports.MAGMA = MAGMA;
|
|
9829
|
+
exports.MAINNET_AFTERMATH_INSURANCE_FUND_ID = MAINNET_AFTERMATH_INSURANCE_FUND_ID;
|
|
9830
|
+
exports.MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID = MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID;
|
|
9831
|
+
exports.MAINNET_AFTERMATH_REFERRAL_VAULT_ID = MAINNET_AFTERMATH_REFERRAL_VAULT_ID;
|
|
9832
|
+
exports.MAINNET_AFTERMATH_REGISTRY_ID = MAINNET_AFTERMATH_REGISTRY_ID;
|
|
9833
|
+
exports.MAINNET_AFTERMATH_TREASURY_ID = MAINNET_AFTERMATH_TREASURY_ID;
|
|
9834
|
+
exports.MAINNET_CETUS_V3_PUBLISHED_AT = MAINNET_CETUS_V3_PUBLISHED_AT;
|
|
9835
|
+
exports.MAINNET_FLOWX_AMM_CONTAINER_ID = MAINNET_FLOWX_AMM_CONTAINER_ID;
|
|
9836
|
+
exports.METASTABLE = METASTABLE;
|
|
9837
|
+
exports.MOMENTUM = MOMENTUM;
|
|
9838
|
+
exports.OBRIC = OBRIC;
|
|
9839
|
+
exports.ONE = ONE;
|
|
9840
|
+
exports.PACKAGE_NAMES = PACKAGE_NAMES;
|
|
9841
|
+
exports.PAY_MODULE = PAY_MODULE;
|
|
9842
|
+
exports.POOL_MODULT = POOL_MODULT;
|
|
9843
|
+
exports.PUBLISHED_ADDRESSES = PUBLISHED_ADDRESSES;
|
|
9844
|
+
exports.PYTH_CONFIG = PYTH_CONFIG;
|
|
9845
|
+
exports.REPAY_FLASH_SWAP_A2B_FUNC = REPAY_FLASH_SWAP_A2B_FUNC;
|
|
9846
|
+
exports.REPAY_FLASH_SWAP_B2A_FUNC = REPAY_FLASH_SWAP_B2A_FUNC;
|
|
9847
|
+
exports.REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC = REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC;
|
|
9848
|
+
exports.REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC = REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC;
|
|
9849
|
+
exports.RepayFalshSwapFunc = RepayFalshSwapFunc;
|
|
9850
|
+
exports.RepayFlashSwapWithPartnerFunc = RepayFlashSwapWithPartnerFunc;
|
|
9851
|
+
exports.SCALLOP = SCALLOP;
|
|
9852
|
+
exports.SEVENK = SEVENK;
|
|
9853
|
+
exports.SPRINGSUI = SPRINGSUI;
|
|
9854
|
+
exports.STEAMM = STEAMM;
|
|
9855
|
+
exports.STEAMM_OMM = STEAMM_OMM;
|
|
9856
|
+
exports.STEAMM_OMM_V2 = STEAMM_OMM_V2;
|
|
9857
|
+
exports.SUILEND = SUILEND;
|
|
9858
|
+
exports.SUI_SYSTEM_STATE_OBJECT_ID = SUI_SYSTEM_STATE_OBJECT_ID;
|
|
9859
|
+
exports.SWAP_A2B_FUNC = SWAP_A2B_FUNC;
|
|
9860
|
+
exports.SWAP_B2A_FUNC = SWAP_B2A_FUNC;
|
|
9861
|
+
exports.SuiZeroCoinFn = SuiZeroCoinFn;
|
|
9862
|
+
exports.TEN_POW_NINE = TEN_POW_NINE;
|
|
9863
|
+
exports.TESTNET_AFTERMATH_INSURANCE_FUND_ID = TESTNET_AFTERMATH_INSURANCE_FUND_ID;
|
|
9864
|
+
exports.TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID = TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID;
|
|
9865
|
+
exports.TESTNET_AFTERMATH_REFERRAL_VAULT_ID = TESTNET_AFTERMATH_REFERRAL_VAULT_ID;
|
|
9866
|
+
exports.TESTNET_AFTERMATH_REGISTRY_ID = TESTNET_AFTERMATH_REGISTRY_ID;
|
|
9867
|
+
exports.TESTNET_AFTERMATH_TREASURY_ID = TESTNET_AFTERMATH_TREASURY_ID;
|
|
9868
|
+
exports.TESTNET_CETUS_V3_PUBLISHED_AT = TESTNET_CETUS_V3_PUBLISHED_AT;
|
|
9869
|
+
exports.TESTNET_FLOWX_AMM_CONTAINER_ID = TESTNET_FLOWX_AMM_CONTAINER_ID;
|
|
9870
|
+
exports.TRANSFER_ACCOUNT_CAP = TRANSFER_ACCOUNT_CAP;
|
|
9871
|
+
exports.TRANSFER_OR_DESTORY_COIN_FUNC = TRANSFER_OR_DESTORY_COIN_FUNC;
|
|
9872
|
+
exports.TURBOS = TURBOS;
|
|
9873
|
+
exports.TURBOS_DEX = TURBOS_DEX;
|
|
9874
|
+
exports.TURBOS_MODULE = TURBOS_MODULE;
|
|
9875
|
+
exports.TURBOS_VERSIONED = TURBOS_VERSIONED;
|
|
9876
|
+
exports.TWO = TWO;
|
|
9877
|
+
exports.TransactionErrorCode = TransactionErrorCode;
|
|
9878
|
+
exports.TypesErrorCode = TypesErrorCode;
|
|
9879
|
+
exports.U128 = U128;
|
|
9880
|
+
exports.U64_MAX = U64_MAX;
|
|
9881
|
+
exports.U64_MAX_BN = U64_MAX_BN;
|
|
9882
|
+
exports.UTILS_MODULE = UTILS_MODULE;
|
|
9883
|
+
exports.VOLO = VOLO;
|
|
9884
|
+
exports.ZERO = ZERO;
|
|
9885
|
+
exports.buildInputCoin = buildInputCoin;
|
|
9886
|
+
exports.calculateGasEfficiency = calculateGasEfficiency;
|
|
9887
|
+
exports.calculatePriceImpact = calculatePriceImpact;
|
|
9888
|
+
exports.checkInvalidSuiAddress = checkInvalidSuiAddress;
|
|
9889
|
+
exports.compareCoins = compareCoins;
|
|
9890
|
+
exports.compareGasMetrics = compareGasMetrics;
|
|
9891
|
+
exports.completionCoin = completionCoin;
|
|
9892
|
+
exports.composeType = composeType;
|
|
9893
|
+
exports.createTarget = createTarget;
|
|
9894
|
+
exports.dealWithFastRouterSwapParamsForMsafe = dealWithFastRouterSwapParamsForMsafe;
|
|
9895
|
+
exports.exportToCSV = exportToCSV;
|
|
9896
|
+
exports.exportToJSON = exportToJSON;
|
|
9897
|
+
exports.extractAddressFromType = extractAddressFromType;
|
|
9898
|
+
exports.extractGasMetrics = extractGasMetrics;
|
|
9899
|
+
exports.extractStructTagFromType = extractStructTagFromType;
|
|
9900
|
+
exports.extractTimestampFromDowngradeUuid6 = extractTimestampFromDowngradeUuid6;
|
|
9901
|
+
exports.fixSuiObjectId = fixSuiObjectId;
|
|
9902
|
+
exports.formatGasMetrics = formatGasMetrics;
|
|
9903
|
+
exports.generateDowngradeUuid6 = generateDowngradeUuid6;
|
|
9904
|
+
exports.generateSimpleDowngradeUuid6 = generateSimpleDowngradeUuid6;
|
|
9905
|
+
exports.getAggregatorServerErrorMessage = getAggregatorServerErrorMessage;
|
|
9906
|
+
exports.getAggregatorV2Extend2PublishedAt = getAggregatorV2Extend2PublishedAt;
|
|
9907
|
+
exports.getAggregatorV2ExtendPublishedAt = getAggregatorV2ExtendPublishedAt;
|
|
9908
|
+
exports.getAggregatorV2PublishedAt = getAggregatorV2PublishedAt;
|
|
9909
|
+
exports.getAllProviders = getAllProviders;
|
|
9910
|
+
exports.getDeepbookV3Config = getDeepbookV3Config;
|
|
9911
|
+
exports.getDefaultSuiInputType = getDefaultSuiInputType;
|
|
9912
|
+
exports.getMergeSwapResult = getMergeSwapResult;
|
|
9913
|
+
exports.getOrCreateAccountCap = getOrCreateAccountCap;
|
|
9914
|
+
exports.getProvidersExcluding = getProvidersExcluding;
|
|
9915
|
+
exports.getProvidersIncluding = getProvidersIncluding;
|
|
9916
|
+
exports.getRouterResult = getRouterResult;
|
|
9917
|
+
exports.isSortedSymbols = isSortedSymbols;
|
|
9918
|
+
exports.isValidDowngradeUuid6 = isValidDowngradeUuid6;
|
|
9919
|
+
exports.mintZeroCoin = mintZeroCoin;
|
|
9920
|
+
exports.normalizeCoinType = normalizeCoinType;
|
|
9921
|
+
exports.parseAftermathFeeType = parseAftermathFeeType;
|
|
9922
|
+
exports.parseTurbosPoolFeeType = parseTurbosPoolFeeType;
|
|
9923
|
+
exports.patchFixSuiObjectId = patchFixSuiObjectId;
|
|
9924
|
+
exports.printTransaction = printTransaction;
|
|
9925
|
+
exports.processEndpoint = processEndpoint;
|
|
9926
|
+
exports.processFlattenRoutes = processFlattenRoutes;
|
|
9927
|
+
exports.restituteMsafeFastRouterSwapParams = restituteMsafeFastRouterSwapParams;
|