@cetusprotocol/aggregator-sdk 1.4.4 → 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/README.md +46 -302
- package/bun.lock +106 -692
- package/dist/{index.mjs → index.cjs} +1217 -940
- package/dist/{index.d.mts → index.d.cts} +70 -14
- package/dist/index.d.ts +70 -14
- package/dist/index.js +1041 -1116
- package/package.json +12 -17
- package/tsconfig.json +6 -5
- package/vitest.config.ts +16 -0
- package/examples/mergeSwapExample.ts +0 -142
|
@@ -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
|
}
|
|
@@ -3446,7 +3416,7 @@ var AGGREGATOR_V3_CONFIG = {
|
|
|
3446
3416
|
};
|
|
3447
3417
|
|
|
3448
3418
|
// src/api.ts
|
|
3449
|
-
var SDK_VERSION =
|
|
3419
|
+
var SDK_VERSION = 1010405;
|
|
3450
3420
|
function parseRouterResponse(data, byAmountIn) {
|
|
3451
3421
|
let packages = /* @__PURE__ */ new Map();
|
|
3452
3422
|
if (data.packages) {
|
|
@@ -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;
|
|
@@ -3854,6 +3811,7 @@ function processErrorStatusCode(status) {
|
|
|
3854
3811
|
case 5e3:
|
|
3855
3812
|
return 1002 /* InsufficientLiquidity */;
|
|
3856
3813
|
case 5001:
|
|
3814
|
+
case 5010:
|
|
3857
3815
|
return 1007 /* NotFoundRoute */;
|
|
3858
3816
|
case 5030:
|
|
3859
3817
|
return 1008 /* ServiceUnavailable */;
|
|
@@ -6098,7 +6056,7 @@ function CalculateAmountLimitByDecimal(expectAmount, byAmountIn, slippage) {
|
|
|
6098
6056
|
var CetusRouter = class {
|
|
6099
6057
|
constructor(env, partner) {
|
|
6100
6058
|
this.globalConfig = env === 0 /* Mainnet */ ? "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f" : "0xc6273f844b4bc258952c4e477697aa12c918c8e08106fac6b934811298c9820a";
|
|
6101
|
-
this.partner = partner
|
|
6059
|
+
this.partner = partner ?? (env === 0 /* Mainnet */ ? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b" : "0xfdc30896f88f74544fd507722d3bf52e46b06412ba8241ba0e854cbc65f8d85f");
|
|
6102
6060
|
}
|
|
6103
6061
|
// By amount in
|
|
6104
6062
|
swap(txb, flattenedPath, swapContext, _extends) {
|
|
@@ -6129,7 +6087,7 @@ var CetusRouter = class {
|
|
|
6129
6087
|
txb.object(this.partner),
|
|
6130
6088
|
txb.pure.bool(swapData.direction),
|
|
6131
6089
|
txb.pure.u64(swapData.amountIn),
|
|
6132
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6090
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6133
6091
|
];
|
|
6134
6092
|
txb.moveCall({
|
|
6135
6093
|
target: `${swapData.publishedAt}::cetus::swap`,
|
|
@@ -6148,7 +6106,7 @@ var CetusRouter = class {
|
|
|
6148
6106
|
txb.pure.bool(path.direction),
|
|
6149
6107
|
txb.pure.bool(false),
|
|
6150
6108
|
// isExactIn
|
|
6151
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6109
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6152
6110
|
];
|
|
6153
6111
|
const [coinAType, coinBType] = path.direction ? [path.from, path.target] : [path.target, path.from];
|
|
6154
6112
|
const [flashReceipt, repayAmount] = txb.moveCall({
|
|
@@ -6231,7 +6189,7 @@ var KriyaV3Router = class {
|
|
|
6231
6189
|
txb.object(this.version),
|
|
6232
6190
|
txb.pure.bool(swapData.direction),
|
|
6233
6191
|
txb.pure.u64(swapData.amountIn),
|
|
6234
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6192
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6235
6193
|
];
|
|
6236
6194
|
txb.moveCall({
|
|
6237
6195
|
target: `${swapData.publishedAt}::kriya_clmm::swap`,
|
|
@@ -6278,7 +6236,7 @@ var FlowxV3Router = class {
|
|
|
6278
6236
|
txb.pure.u64(swapData.feeRate),
|
|
6279
6237
|
txb.pure.u64(swapData.amountIn),
|
|
6280
6238
|
txb.pure.bool(swapData.direction),
|
|
6281
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6239
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6282
6240
|
];
|
|
6283
6241
|
txb.moveCall({
|
|
6284
6242
|
target: `${swapData.publishedAt}::flowx_clmm::swap`,
|
|
@@ -6330,7 +6288,7 @@ var TurbosRouter = class {
|
|
|
6330
6288
|
txb.object(this.versioned),
|
|
6331
6289
|
txb.pure.bool(swapData.direction),
|
|
6332
6290
|
txb.pure.u64(swapData.amountIn),
|
|
6333
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6291
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6334
6292
|
];
|
|
6335
6293
|
txb.moveCall({
|
|
6336
6294
|
target: `${swapData.publishedAt}::turbos::swap`,
|
|
@@ -6373,7 +6331,7 @@ var BluefinRouter = class {
|
|
|
6373
6331
|
txb.object(swapData.poolId),
|
|
6374
6332
|
txb.pure.bool(swapData.direction),
|
|
6375
6333
|
txb.pure.u64(swapData.amountIn),
|
|
6376
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6334
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6377
6335
|
];
|
|
6378
6336
|
txb.moveCall({
|
|
6379
6337
|
target: `${swapData.publishedAt}::bluefin::swap`,
|
|
@@ -6416,7 +6374,7 @@ var MomentumRouter = class {
|
|
|
6416
6374
|
txb.pure.bool(swapData.direction),
|
|
6417
6375
|
txb.pure.u64(swapData.amountIn),
|
|
6418
6376
|
txb.object(this.version),
|
|
6419
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6377
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6420
6378
|
];
|
|
6421
6379
|
txb.moveCall({
|
|
6422
6380
|
target: `${swapData.publishedAt}::momentum::swap`,
|
|
@@ -6459,7 +6417,7 @@ var MagmaRouter = class {
|
|
|
6459
6417
|
txb.object(swapData.poolId),
|
|
6460
6418
|
txb.pure.bool(swapData.direction),
|
|
6461
6419
|
txb.pure.u64(swapData.amountIn),
|
|
6462
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6420
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6463
6421
|
];
|
|
6464
6422
|
txb.moveCall({
|
|
6465
6423
|
target: `${swapData.publishedAt}::magma::swap`,
|
|
@@ -6612,17 +6570,16 @@ var DeepbookV3Router = class {
|
|
|
6612
6570
|
this.executeSwapContract(txb, swapData, swapContext, _extends);
|
|
6613
6571
|
}
|
|
6614
6572
|
prepareSwapData(flattenedPath) {
|
|
6615
|
-
var _a, _b, _c, _d, _e;
|
|
6616
6573
|
if (flattenedPath.path.publishedAt == null) {
|
|
6617
6574
|
throw new Error("DeepBook V3 not set publishedAt");
|
|
6618
6575
|
}
|
|
6619
6576
|
const path = flattenedPath.path;
|
|
6620
6577
|
const [coinAType, coinBType] = path.direction ? [path.from, path.target] : [path.target, path.from];
|
|
6621
6578
|
const amountIn = flattenedPath.isLastUseOfIntermediateToken ? AGGREGATOR_V3_CONFIG.MAX_AMOUNT_IN : path.amountIn;
|
|
6622
|
-
const needAddDeepPricePoint =
|
|
6623
|
-
const referencePoolId =
|
|
6624
|
-
const referencePoolBaseType =
|
|
6625
|
-
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;
|
|
6626
6583
|
if (needAddDeepPricePoint) {
|
|
6627
6584
|
if (!referencePoolId) {
|
|
6628
6585
|
throw new Error(
|
|
@@ -6665,12 +6622,12 @@ var DeepbookV3Router = class {
|
|
|
6665
6622
|
arguments: [
|
|
6666
6623
|
txb.object(swapData.poolId),
|
|
6667
6624
|
txb.object(swapData.referencePoolId),
|
|
6668
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6625
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6669
6626
|
]
|
|
6670
6627
|
});
|
|
6671
6628
|
}
|
|
6672
6629
|
executeSwapContract(txb, swapData, swapContext, _extends) {
|
|
6673
|
-
const deepCoin =
|
|
6630
|
+
const deepCoin = _extends?.deepbookv3DeepFee || txb.moveCall({
|
|
6674
6631
|
target: "0x2::coin::zero",
|
|
6675
6632
|
typeArguments: [this.getDeepFeeType()]
|
|
6676
6633
|
});
|
|
@@ -6681,7 +6638,7 @@ var DeepbookV3Router = class {
|
|
|
6681
6638
|
txb.pure.u64(swapData.amountIn),
|
|
6682
6639
|
txb.pure.bool(swapData.direction),
|
|
6683
6640
|
deepCoin,
|
|
6684
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6641
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6685
6642
|
];
|
|
6686
6643
|
txb.moveCall({
|
|
6687
6644
|
target: `${swapData.publishedAt}::deepbookv3::swap`,
|
|
@@ -6711,7 +6668,6 @@ var AftermathRouter = class {
|
|
|
6711
6668
|
this.executeSwapContract(txb, swapData, swapContext);
|
|
6712
6669
|
}
|
|
6713
6670
|
prepareSwapData(flattenedPath) {
|
|
6714
|
-
var _a, _b;
|
|
6715
6671
|
if (flattenedPath.path.publishedAt == null) {
|
|
6716
6672
|
throw new Error("Aftermath not set publishedAt");
|
|
6717
6673
|
}
|
|
@@ -6721,7 +6677,7 @@ var AftermathRouter = class {
|
|
|
6721
6677
|
return {
|
|
6722
6678
|
coinAType,
|
|
6723
6679
|
coinBType,
|
|
6724
|
-
feeType:
|
|
6680
|
+
feeType: path.extendedDetails?.aftermath_lp_supply_type || path.extendedDetails?.aftermath_lp_supply_type || "0x2::sui::SUI",
|
|
6725
6681
|
// Use LP supply type from path (handle both camelCase and snake_case)
|
|
6726
6682
|
direction: path.direction,
|
|
6727
6683
|
amountIn,
|
|
@@ -6818,7 +6774,7 @@ var SteammCPMMRouter = class {
|
|
|
6818
6774
|
txb.object(swapData.extendedDetails.steamm_lending_market),
|
|
6819
6775
|
txb.pure.bool(swapData.direction),
|
|
6820
6776
|
txb.pure.u64(swapData.amountIn),
|
|
6821
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6777
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6822
6778
|
];
|
|
6823
6779
|
txb.moveCall({
|
|
6824
6780
|
target: `${swapData.publishedAt}::steamm_cpmm::swap`,
|
|
@@ -6877,7 +6833,7 @@ var ScallopRouter = class {
|
|
|
6877
6833
|
txb.object(this.marketData),
|
|
6878
6834
|
txb.object(swapData.scallopScoinTreasury),
|
|
6879
6835
|
txb.pure.u64(swapData.amountIn),
|
|
6880
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6836
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6881
6837
|
];
|
|
6882
6838
|
const func = swapData.direction ? "swap_a2b" : "swap_b2a";
|
|
6883
6839
|
txb.moveCall({
|
|
@@ -6993,7 +6949,7 @@ var HaedalPmmRouter = class {
|
|
|
6993
6949
|
// amount_in
|
|
6994
6950
|
txb.pure.bool(swapData.a2b),
|
|
6995
6951
|
// a2b
|
|
6996
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6952
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
6997
6953
|
// clock
|
|
6998
6954
|
];
|
|
6999
6955
|
txb.moveCall({
|
|
@@ -7067,7 +7023,7 @@ var ObricRouter = class {
|
|
|
7067
7023
|
txb.object(this.pythStateObjectId),
|
|
7068
7024
|
txb.object(swapData.coinAPriceInfoObjectId),
|
|
7069
7025
|
txb.object(swapData.coinBPriceInfoObjectId),
|
|
7070
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7026
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7071
7027
|
];
|
|
7072
7028
|
txb.moveCall({
|
|
7073
7029
|
target: `${swapData.publishedAt}::obric::swap`,
|
|
@@ -7142,7 +7098,7 @@ var SevenkRouter = class {
|
|
|
7142
7098
|
txb.object(swapData.coinAOracleId),
|
|
7143
7099
|
holder,
|
|
7144
7100
|
txb.object(swapData.coinAPriceId),
|
|
7145
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7101
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7146
7102
|
]
|
|
7147
7103
|
});
|
|
7148
7104
|
txb.moveCall({
|
|
@@ -7152,7 +7108,7 @@ var SevenkRouter = class {
|
|
|
7152
7108
|
txb.object(swapData.coinBOracleId),
|
|
7153
7109
|
holder,
|
|
7154
7110
|
txb.object(swapData.coinBPriceId),
|
|
7155
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7111
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7156
7112
|
]
|
|
7157
7113
|
});
|
|
7158
7114
|
const args = [
|
|
@@ -7249,7 +7205,7 @@ var SteammOmmRouter = class {
|
|
|
7249
7205
|
txb.object(extendedDetails.steammOracleRegistryId),
|
|
7250
7206
|
txb.object(swapData.priceInfoObjectIdA),
|
|
7251
7207
|
txb.pure.u64(extendedDetails.steammOracleIndexA),
|
|
7252
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7208
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7253
7209
|
]
|
|
7254
7210
|
});
|
|
7255
7211
|
const oraclePriceUpdateB = txb.moveCall({
|
|
@@ -7259,7 +7215,7 @@ var SteammOmmRouter = class {
|
|
|
7259
7215
|
txb.object(extendedDetails.steammOracleRegistryId),
|
|
7260
7216
|
txb.object(swapData.priceInfoObjectIdB),
|
|
7261
7217
|
txb.pure.u64(extendedDetails.steammOracleIndexB),
|
|
7262
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7218
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7263
7219
|
]
|
|
7264
7220
|
});
|
|
7265
7221
|
const args = [
|
|
@@ -7271,7 +7227,7 @@ var SteammOmmRouter = class {
|
|
|
7271
7227
|
oraclePriceUpdateA,
|
|
7272
7228
|
oraclePriceUpdateB,
|
|
7273
7229
|
txb.pure.u64(swapData.amountIn),
|
|
7274
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7230
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7275
7231
|
];
|
|
7276
7232
|
txb.moveCall({
|
|
7277
7233
|
target: `${swapData.publishedAt}::steamm_omm::${swapData.func}`,
|
|
@@ -7367,7 +7323,7 @@ var SteammOmmV2Router = class {
|
|
|
7367
7323
|
txb.object(extendedDetails.steamm_oracle_registry_id),
|
|
7368
7324
|
txb.object(swapData.priceInfoObjectIdA),
|
|
7369
7325
|
txb.pure.u64(extendedDetails.steamm_oracle_index_a),
|
|
7370
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7326
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7371
7327
|
]
|
|
7372
7328
|
});
|
|
7373
7329
|
const oraclePriceUpdateB = txb.moveCall({
|
|
@@ -7377,7 +7333,7 @@ var SteammOmmV2Router = class {
|
|
|
7377
7333
|
txb.object(extendedDetails.steamm_oracle_registry_id),
|
|
7378
7334
|
txb.object(swapData.priceInfoObjectIdB),
|
|
7379
7335
|
txb.pure.u64(extendedDetails.steamm_oracle_index_b),
|
|
7380
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7336
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7381
7337
|
]
|
|
7382
7338
|
});
|
|
7383
7339
|
const args = [
|
|
@@ -7390,7 +7346,7 @@ var SteammOmmV2Router = class {
|
|
|
7390
7346
|
oraclePriceUpdateB,
|
|
7391
7347
|
txb.pure.bool(swapData.direction),
|
|
7392
7348
|
txb.pure.u64(swapData.amountIn),
|
|
7393
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7349
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
7394
7350
|
];
|
|
7395
7351
|
txb.moveCall({
|
|
7396
7352
|
target: `${swapData.publishedAt}::steamm_omm_v2::swap`,
|
|
@@ -7494,7 +7450,7 @@ var MetastableRouter = class {
|
|
|
7494
7450
|
}
|
|
7495
7451
|
depositArgs.push(txb.object(priceId));
|
|
7496
7452
|
}
|
|
7497
|
-
depositArgs.push(txb.object(SUI_CLOCK_OBJECT_ID));
|
|
7453
|
+
depositArgs.push(txb.object(utils.SUI_CLOCK_OBJECT_ID));
|
|
7498
7454
|
break;
|
|
7499
7455
|
}
|
|
7500
7456
|
default:
|
|
@@ -7655,7 +7611,7 @@ var AfsuiRouter = class {
|
|
|
7655
7611
|
txb.object("0x5"),
|
|
7656
7612
|
// SuiSystemState
|
|
7657
7613
|
txb.object(this.referVault),
|
|
7658
|
-
txb.
|
|
7614
|
+
txb.pure.address(this.validator),
|
|
7659
7615
|
txb.pure.bool(swapData.direction),
|
|
7660
7616
|
txb.pure.u64(swapData.amountIn)
|
|
7661
7617
|
];
|
|
@@ -7745,7 +7701,7 @@ var HawalRouter = class {
|
|
|
7745
7701
|
swapContext,
|
|
7746
7702
|
txb.object(this.staking),
|
|
7747
7703
|
txb.object(swapData.poolId),
|
|
7748
|
-
txb.
|
|
7704
|
+
txb.pure.address(this.validator),
|
|
7749
7705
|
txb.pure.bool(swapData.direction),
|
|
7750
7706
|
txb.pure.u64(swapData.amountIn)
|
|
7751
7707
|
];
|
|
@@ -7865,6 +7821,221 @@ function transferOrDestroyCoin(params, txb) {
|
|
|
7865
7821
|
arguments: [coin]
|
|
7866
7822
|
});
|
|
7867
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
|
+
};
|
|
7868
8039
|
|
|
7869
8040
|
// src/utils/uuid.ts
|
|
7870
8041
|
function generateDowngradeUuid6() {
|
|
@@ -7923,7 +8094,7 @@ function extractTimestampFromDowngradeUuid6(uuid) {
|
|
|
7923
8094
|
const timestampHex = timeHigh + timeMid;
|
|
7924
8095
|
const timestamp = parseInt(timestampHex, 16);
|
|
7925
8096
|
return isNaN(timestamp) ? null : timestamp;
|
|
7926
|
-
} catch
|
|
8097
|
+
} catch {
|
|
7927
8098
|
return null;
|
|
7928
8099
|
}
|
|
7929
8100
|
}
|
|
@@ -7939,72 +8110,60 @@ function processEndpoint(endpoint) {
|
|
|
7939
8110
|
}
|
|
7940
8111
|
|
|
7941
8112
|
// src/utils/account_cap.ts
|
|
7942
|
-
function getOrCreateAccountCap(txb, client, owner) {
|
|
7943
|
-
|
|
7944
|
-
|
|
7945
|
-
if (accountCapStr !== null) {
|
|
7946
|
-
return {
|
|
7947
|
-
accountCap: txb.object(accountCapStr),
|
|
7948
|
-
isCreate: false
|
|
7949
|
-
};
|
|
7950
|
-
}
|
|
7951
|
-
const accountCap = txb.moveCall({
|
|
7952
|
-
target: `${DEEPBOOK_PUBLISHED_AT}::${DEEPBOOK_CLOB_V2_MODULE}::create_account`,
|
|
7953
|
-
typeArguments: [],
|
|
7954
|
-
arguments: []
|
|
7955
|
-
});
|
|
8113
|
+
async function getOrCreateAccountCap(txb, client, owner) {
|
|
8114
|
+
let accountCapStr = await getAccountCap(client, owner);
|
|
8115
|
+
if (accountCapStr !== null) {
|
|
7956
8116
|
return {
|
|
7957
|
-
accountCap,
|
|
7958
|
-
isCreate:
|
|
8117
|
+
accountCap: txb.object(accountCapStr),
|
|
8118
|
+
isCreate: false
|
|
7959
8119
|
};
|
|
8120
|
+
}
|
|
8121
|
+
const accountCap = txb.moveCall({
|
|
8122
|
+
target: `${DEEPBOOK_PUBLISHED_AT}::${DEEPBOOK_CLOB_V2_MODULE}::create_account`,
|
|
8123
|
+
typeArguments: [],
|
|
8124
|
+
arguments: []
|
|
7960
8125
|
});
|
|
8126
|
+
return {
|
|
8127
|
+
accountCap,
|
|
8128
|
+
isCreate: true
|
|
8129
|
+
};
|
|
7961
8130
|
}
|
|
7962
|
-
function getAccountCap(client, owner) {
|
|
7963
|
-
|
|
7964
|
-
|
|
7965
|
-
|
|
7966
|
-
|
|
7967
|
-
|
|
7968
|
-
|
|
7969
|
-
|
|
7970
|
-
|
|
7971
|
-
|
|
7972
|
-
|
|
7973
|
-
|
|
7974
|
-
module: DEEPBOOK_CUSTODIAN_V2_MODULE
|
|
7975
|
-
}
|
|
7976
|
-
}
|
|
7977
|
-
});
|
|
7978
|
-
if (ownedObjects != null && ownedObjects.data != null) {
|
|
7979
|
-
if (ownedObjects.data.length !== 0) {
|
|
7980
|
-
return ownedObjects.data[0].data.objectId;
|
|
7981
|
-
}
|
|
7982
|
-
if (ownedObjects.data.length < 50) {
|
|
7983
|
-
break;
|
|
7984
|
-
}
|
|
7985
|
-
} else {
|
|
7986
|
-
break;
|
|
7987
|
-
}
|
|
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;
|
|
7988
8143
|
}
|
|
7989
|
-
|
|
7990
|
-
|
|
8144
|
+
if (!ownedObjects.hasNextPage) {
|
|
8145
|
+
break;
|
|
8146
|
+
}
|
|
8147
|
+
cursor = ownedObjects.nextCursor ?? void 0;
|
|
8148
|
+
}
|
|
8149
|
+
return null;
|
|
7991
8150
|
}
|
|
7992
8151
|
|
|
7993
8152
|
// src/utils/config.ts
|
|
7994
8153
|
function getAggregatorV2PublishedAt(publishedAt, packages) {
|
|
7995
|
-
if (packages
|
|
8154
|
+
if (packages?.has("aggregator_v2")) {
|
|
7996
8155
|
return packages.get("aggregator_v2");
|
|
7997
8156
|
}
|
|
7998
8157
|
return publishedAt || PUBLISHED_ADDRESSES.V2.Mainnet;
|
|
7999
8158
|
}
|
|
8000
8159
|
function getAggregatorV2ExtendPublishedAt(publishedAt, packages) {
|
|
8001
|
-
if (packages
|
|
8160
|
+
if (packages?.has("aggregator_v2_extend")) {
|
|
8002
8161
|
return packages.get("aggregator_v2_extend");
|
|
8003
8162
|
}
|
|
8004
8163
|
return publishedAt || PUBLISHED_ADDRESSES.V2_EXTEND.Mainnet;
|
|
8005
8164
|
}
|
|
8006
8165
|
function getAggregatorV2Extend2PublishedAt(publishedAt, packages) {
|
|
8007
|
-
if (packages
|
|
8166
|
+
if (packages?.has("aggregator_v2_extend2")) {
|
|
8008
8167
|
return packages.get("aggregator_v2_extend2");
|
|
8009
8168
|
}
|
|
8010
8169
|
return publishedAt || PUBLISHED_ADDRESSES.V2_EXTEND2.Mainnet;
|
|
@@ -8014,8 +8173,9 @@ function getAggregatorV2Extend2PublishedAt(publishedAt, packages) {
|
|
|
8014
8173
|
var import_bn4 = __toESM(require_bn());
|
|
8015
8174
|
function extractGasMetrics(result) {
|
|
8016
8175
|
const effects = result.effects;
|
|
8017
|
-
const
|
|
8018
|
-
if (!
|
|
8176
|
+
const isSuccess = !result.error && effects.status.status === "success";
|
|
8177
|
+
if (!isSuccess) {
|
|
8178
|
+
const errorMsg = result.error ?? effects.status.error ?? "Unknown error";
|
|
8019
8179
|
return {
|
|
8020
8180
|
computationCost: "0",
|
|
8021
8181
|
storageCost: "0",
|
|
@@ -8025,27 +8185,27 @@ function extractGasMetrics(result) {
|
|
|
8025
8185
|
gasUsed: "0",
|
|
8026
8186
|
gasPrice: "0",
|
|
8027
8187
|
success: false,
|
|
8028
|
-
error:
|
|
8188
|
+
error: errorMsg
|
|
8029
8189
|
};
|
|
8030
8190
|
}
|
|
8031
8191
|
const gasUsed = effects.gasUsed;
|
|
8032
8192
|
return {
|
|
8033
|
-
computationCost: gasUsed.computationCost
|
|
8034
|
-
storageCost: gasUsed.storageCost
|
|
8035
|
-
storageRebate: gasUsed.storageRebate
|
|
8036
|
-
nonRefundableStorageFee: gasUsed.nonRefundableStorageFee
|
|
8193
|
+
computationCost: gasUsed.computationCost,
|
|
8194
|
+
storageCost: gasUsed.storageCost,
|
|
8195
|
+
storageRebate: gasUsed.storageRebate,
|
|
8196
|
+
nonRefundableStorageFee: gasUsed.nonRefundableStorageFee,
|
|
8037
8197
|
totalGasCost: calculateTotalGasCost(gasUsed),
|
|
8038
|
-
gasUsed: gasUsed.computationCost
|
|
8198
|
+
gasUsed: gasUsed.computationCost,
|
|
8039
8199
|
gasPrice: "1000",
|
|
8040
8200
|
// Standard Sui gas price in MIST
|
|
8041
8201
|
success: true
|
|
8042
8202
|
};
|
|
8043
8203
|
}
|
|
8044
8204
|
function calculateTotalGasCost(gasUsed) {
|
|
8045
|
-
const computation = new import_bn4.default(gasUsed.computationCost
|
|
8046
|
-
const storage = new import_bn4.default(gasUsed.storageCost
|
|
8047
|
-
const rebate = new import_bn4.default(gasUsed.storageRebate
|
|
8048
|
-
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);
|
|
8049
8209
|
return computation.add(storage).sub(rebate).add(nonRefundable).toString();
|
|
8050
8210
|
}
|
|
8051
8211
|
function calculateGasEfficiency(amountOut, totalGasCost) {
|
|
@@ -8087,12 +8247,12 @@ function calculateAverageGas(analyses) {
|
|
|
8087
8247
|
}
|
|
8088
8248
|
function formatGasMetrics(metrics, isEstimated) {
|
|
8089
8249
|
if (!metrics.success) {
|
|
8090
|
-
return
|
|
8250
|
+
return `Failed: ${metrics.error}`;
|
|
8091
8251
|
}
|
|
8092
8252
|
const totalGas = Number(metrics.totalGasCost);
|
|
8093
8253
|
const gasInSui = totalGas / 1e9;
|
|
8094
8254
|
const estimatedFlag = isEstimated ? " (estimated)" : "";
|
|
8095
|
-
return
|
|
8255
|
+
return `Gas: ${totalGas.toString()} MIST (${gasInSui.toString()} SUI)${estimatedFlag}`;
|
|
8096
8256
|
}
|
|
8097
8257
|
function exportToJSON(comparison) {
|
|
8098
8258
|
return JSON.stringify(comparison, null, 2);
|
|
@@ -8160,63 +8320,62 @@ function exportToCSV(comparison) {
|
|
|
8160
8320
|
// src/utils/msafe.ts
|
|
8161
8321
|
var import_bn5 = __toESM(require_bn());
|
|
8162
8322
|
var dealWithFastRouterSwapParamsForMsafe = (data) => {
|
|
8163
|
-
|
|
8164
|
-
|
|
8165
|
-
amountIn:
|
|
8166
|
-
amountOut:
|
|
8167
|
-
paths:
|
|
8168
|
-
|
|
8169
|
-
|
|
8170
|
-
amountIn:
|
|
8171
|
-
amountOut:
|
|
8172
|
-
}
|
|
8173
|
-
if (item
|
|
8174
|
-
info["initialPrice"] =
|
|
8175
|
-
}
|
|
8176
|
-
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) {
|
|
8177
8337
|
info["extendedDetails"] = {
|
|
8178
|
-
after_sqrt_price:
|
|
8338
|
+
after_sqrt_price: item?.extendedDetails?.afterSqrtPrice?.toString()
|
|
8179
8339
|
};
|
|
8180
8340
|
}
|
|
8181
8341
|
return info;
|
|
8182
8342
|
})
|
|
8183
|
-
}
|
|
8343
|
+
};
|
|
8184
8344
|
return result;
|
|
8185
8345
|
};
|
|
8186
8346
|
var restituteMsafeFastRouterSwapParams = (data) => {
|
|
8187
|
-
|
|
8188
|
-
|
|
8189
|
-
amountIn: new import_bn5.default(data
|
|
8190
|
-
amountOut: new import_bn5.default(data
|
|
8191
|
-
paths:
|
|
8192
|
-
|
|
8193
|
-
|
|
8194
|
-
|
|
8195
|
-
|
|
8196
|
-
|
|
8197
|
-
|
|
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) {
|
|
8198
8359
|
info["extendedDetails"] = {
|
|
8199
|
-
after_sqrt_price: new decimal_default(
|
|
8360
|
+
after_sqrt_price: new decimal_default(item?.extendedDetails?.after_sqrt_price?.toString())
|
|
8200
8361
|
};
|
|
8201
8362
|
}
|
|
8202
8363
|
return info;
|
|
8203
8364
|
})
|
|
8204
|
-
}
|
|
8365
|
+
};
|
|
8205
8366
|
return result;
|
|
8206
8367
|
};
|
|
8207
8368
|
|
|
8208
8369
|
// src/utils/transaction.ts
|
|
8209
|
-
function printTransaction(tx, isPrint = true) {
|
|
8210
|
-
|
|
8211
|
-
|
|
8212
|
-
|
|
8213
|
-
|
|
8214
|
-
|
|
8215
|
-
|
|
8216
|
-
|
|
8217
|
-
|
|
8218
|
-
}
|
|
8219
|
-
});
|
|
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
|
+
}
|
|
8220
8379
|
});
|
|
8221
8380
|
}
|
|
8222
8381
|
function bigIntReplacer(key, value) {
|
|
@@ -8288,7 +8447,7 @@ var HaedalHMMV2Router = class {
|
|
|
8288
8447
|
// amount_in
|
|
8289
8448
|
txb.pure.bool(swapData.a2b),
|
|
8290
8449
|
// a2b
|
|
8291
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8450
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
8292
8451
|
// clock
|
|
8293
8452
|
];
|
|
8294
8453
|
txb.moveCall({
|
|
@@ -8338,7 +8497,7 @@ var FullsailRouter = class {
|
|
|
8338
8497
|
txb.object(swapData.poolId),
|
|
8339
8498
|
txb.pure.bool(swapData.direction),
|
|
8340
8499
|
txb.pure.u64(swapData.amountIn),
|
|
8341
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8500
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
8342
8501
|
];
|
|
8343
8502
|
txb.moveCall({
|
|
8344
8503
|
target: `${swapData.publishedAt}::fullsail::swap`,
|
|
@@ -8353,7 +8512,7 @@ var CetusDlmmRouter = class {
|
|
|
8353
8512
|
throw new Error("CetusRouter only supported on mainnet");
|
|
8354
8513
|
}
|
|
8355
8514
|
this.globalConfig = "0xf31b605d117f959b9730e8c07b08b856cb05143c5e81d5751c90d2979e82f599";
|
|
8356
|
-
this.partner = partner
|
|
8515
|
+
this.partner = partner ?? "0x59ae16f6c42f578063c2da9b9c0173fe58120ceae08e40fd8212c8eceb80bb86";
|
|
8357
8516
|
this.versioned = "0x05370b2d656612dd5759cbe80463de301e3b94a921dfc72dd9daa2ecdeb2d0a8";
|
|
8358
8517
|
}
|
|
8359
8518
|
swap(txb, flattenedPath, swapContext, _extends) {
|
|
@@ -8385,7 +8544,7 @@ var CetusDlmmRouter = class {
|
|
|
8385
8544
|
txb.pure.bool(swapData.direction),
|
|
8386
8545
|
txb.pure.u64(swapData.amountIn),
|
|
8387
8546
|
txb.object(this.versioned),
|
|
8388
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8547
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
8389
8548
|
];
|
|
8390
8549
|
txb.moveCall({
|
|
8391
8550
|
target: `${swapData.publishedAt}::cetus_dlmm::swap`,
|
|
@@ -8428,7 +8587,7 @@ var FerraDlmmRouter = class {
|
|
|
8428
8587
|
txb.object(swapData.poolId),
|
|
8429
8588
|
txb.pure.bool(swapData.direction),
|
|
8430
8589
|
txb.pure.u64(swapData.amountIn),
|
|
8431
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8590
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
8432
8591
|
];
|
|
8433
8592
|
txb.moveCall({
|
|
8434
8593
|
target: `${swapData.publishedAt}::ferra_dlmm::swap`,
|
|
@@ -8471,7 +8630,7 @@ var FerraClmmRouter = class {
|
|
|
8471
8630
|
txb.object(swapData.poolId),
|
|
8472
8631
|
txb.pure.bool(swapData.direction),
|
|
8473
8632
|
txb.pure.u64(swapData.amountIn),
|
|
8474
|
-
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8633
|
+
txb.object(utils.SUI_CLOCK_OBJECT_ID)
|
|
8475
8634
|
];
|
|
8476
8635
|
txb.moveCall({
|
|
8477
8636
|
target: `${swapData.publishedAt}::ferra_clmm::swap`,
|
|
@@ -8613,17 +8772,18 @@ function findPythPriceIDs(paths) {
|
|
|
8613
8772
|
}
|
|
8614
8773
|
var _AggregatorClient = class _AggregatorClient {
|
|
8615
8774
|
constructor(params) {
|
|
8616
|
-
var _a, _b;
|
|
8617
8775
|
this.endpoint = params.endpoint ? processEndpoint(params.endpoint) : DEFAULT_ENDPOINT;
|
|
8618
|
-
|
|
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 });
|
|
8619
8779
|
this.signer = params.signer || "";
|
|
8620
8780
|
this.env = params.env || 0 /* Mainnet */;
|
|
8621
8781
|
const config2 = _AggregatorClient.CONFIG[this.env];
|
|
8622
|
-
this.
|
|
8623
|
-
this.pythClient = new SuiPythClient(
|
|
8782
|
+
this.pythAdapter = new PythAdapter(
|
|
8624
8783
|
this.client,
|
|
8625
8784
|
config2.pythStateId,
|
|
8626
|
-
config2.wormholeStateId
|
|
8785
|
+
config2.wormholeStateId,
|
|
8786
|
+
params.pythUrls ?? []
|
|
8627
8787
|
);
|
|
8628
8788
|
this.apiKey = params.apiKey || "";
|
|
8629
8789
|
this.partner = params.partner;
|
|
@@ -8642,16 +8802,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8642
8802
|
} else {
|
|
8643
8803
|
this.overlayFeeRate = 0;
|
|
8644
8804
|
}
|
|
8645
|
-
this.overlayFeeReceiver =
|
|
8646
|
-
}
|
|
8647
|
-
newPythClients(pythUrls) {
|
|
8648
|
-
if (!pythUrls.includes("https://hermes.pyth.network")) {
|
|
8649
|
-
pythUrls.push("https://hermes.pyth.network");
|
|
8650
|
-
}
|
|
8651
|
-
const connections = pythUrls.map(
|
|
8652
|
-
(url) => new SuiPriceServiceConnection(url, { timeout: 3e3 })
|
|
8653
|
-
);
|
|
8654
|
-
return connections;
|
|
8805
|
+
this.overlayFeeReceiver = params.overlayFeeReceiver ?? CLIENT_CONFIG.DEFAULT_OVERLAY_FEE_RECEIVER;
|
|
8655
8806
|
}
|
|
8656
8807
|
deepbookv3DeepFeeType() {
|
|
8657
8808
|
if (this.env === 0 /* Mainnet */) {
|
|
@@ -8660,53 +8811,43 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8660
8811
|
return DEEPBOOK_V3_DEEP_FEE_TYPES.Testnet;
|
|
8661
8812
|
}
|
|
8662
8813
|
}
|
|
8663
|
-
getDeepbookV3Config() {
|
|
8664
|
-
return
|
|
8665
|
-
return yield getDeepbookV3Config(this.endpoint);
|
|
8666
|
-
});
|
|
8814
|
+
async getDeepbookV3Config() {
|
|
8815
|
+
return await getDeepbookV3Config(this.endpoint);
|
|
8667
8816
|
}
|
|
8668
|
-
getOneCoinUsedToMerge(coinType) {
|
|
8669
|
-
|
|
8670
|
-
|
|
8671
|
-
|
|
8672
|
-
|
|
8673
|
-
|
|
8674
|
-
|
|
8675
|
-
|
|
8676
|
-
|
|
8677
|
-
return gotCoin.data[0].coinObjectId;
|
|
8678
|
-
}
|
|
8679
|
-
return null;
|
|
8680
|
-
} catch (error) {
|
|
8681
|
-
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;
|
|
8682
8826
|
}
|
|
8683
|
-
|
|
8827
|
+
return null;
|
|
8828
|
+
} catch (error) {
|
|
8829
|
+
return null;
|
|
8830
|
+
}
|
|
8684
8831
|
}
|
|
8685
|
-
findRouters(params) {
|
|
8686
|
-
return
|
|
8687
|
-
|
|
8688
|
-
|
|
8689
|
-
|
|
8690
|
-
|
|
8691
|
-
|
|
8692
|
-
|
|
8693
|
-
);
|
|
8694
|
-
});
|
|
8832
|
+
async findRouters(params) {
|
|
8833
|
+
return getRouterResult(
|
|
8834
|
+
this.endpoint,
|
|
8835
|
+
this.apiKey,
|
|
8836
|
+
params,
|
|
8837
|
+
this.overlayFeeRate,
|
|
8838
|
+
this.overlayFeeReceiver
|
|
8839
|
+
);
|
|
8695
8840
|
}
|
|
8696
|
-
findMergeSwapRouters(params) {
|
|
8697
|
-
return
|
|
8698
|
-
|
|
8699
|
-
|
|
8700
|
-
|
|
8701
|
-
|
|
8702
|
-
|
|
8703
|
-
|
|
8704
|
-
);
|
|
8705
|
-
});
|
|
8841
|
+
async findMergeSwapRouters(params) {
|
|
8842
|
+
return getMergeSwapResult(
|
|
8843
|
+
this.endpoint,
|
|
8844
|
+
this.apiKey,
|
|
8845
|
+
params,
|
|
8846
|
+
this.overlayFeeRate,
|
|
8847
|
+
this.overlayFeeReceiver
|
|
8848
|
+
);
|
|
8706
8849
|
}
|
|
8707
|
-
executeFlexibleInputSwap(txb, inputCoin, routerData, expectedAmountOut, amountLimit, pythPriceIDs, partner, deepbookv3DeepFee, packages) {
|
|
8708
|
-
return __async(this, null, function* () {
|
|
8709
|
-
});
|
|
8850
|
+
async executeFlexibleInputSwap(txb, inputCoin, routerData, expectedAmountOut, amountLimit, pythPriceIDs, partner, deepbookv3DeepFee, packages) {
|
|
8710
8851
|
}
|
|
8711
8852
|
newDexRouterV3(provider, pythPriceIDs, partner, cetusDlmmPartner) {
|
|
8712
8853
|
switch (provider) {
|
|
@@ -9092,55 +9233,53 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
9092
9233
|
);
|
|
9093
9234
|
return outputCoin;
|
|
9094
9235
|
}
|
|
9095
|
-
routerSwap(params) {
|
|
9096
|
-
|
|
9097
|
-
|
|
9098
|
-
|
|
9099
|
-
|
|
9100
|
-
|
|
9101
|
-
|
|
9102
|
-
|
|
9103
|
-
|
|
9104
|
-
|
|
9105
|
-
|
|
9106
|
-
|
|
9107
|
-
|
|
9108
|
-
|
|
9109
|
-
|
|
9110
|
-
|
|
9111
|
-
|
|
9112
|
-
|
|
9113
|
-
|
|
9114
|
-
|
|
9115
|
-
|
|
9116
|
-
|
|
9117
|
-
|
|
9118
|
-
|
|
9119
|
-
|
|
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
|
|
9120
9272
|
);
|
|
9121
|
-
|
|
9122
|
-
|
|
9123
|
-
|
|
9124
|
-
|
|
9125
|
-
|
|
9126
|
-
|
|
9127
|
-
|
|
9128
|
-
|
|
9129
|
-
|
|
9130
|
-
|
|
9131
|
-
partner != null ? partner : this.partner
|
|
9132
|
-
);
|
|
9133
|
-
} else {
|
|
9134
|
-
return this.expectOutputSwapV3(
|
|
9135
|
-
txb,
|
|
9136
|
-
inputCoin,
|
|
9137
|
-
router,
|
|
9138
|
-
amountOut.toString(),
|
|
9139
|
-
amountLimit.toString(),
|
|
9140
|
-
partner != null ? partner : this.partner
|
|
9141
|
-
);
|
|
9142
|
-
}
|
|
9143
|
-
});
|
|
9273
|
+
} else {
|
|
9274
|
+
return this.expectOutputSwapV3(
|
|
9275
|
+
txb,
|
|
9276
|
+
inputCoin,
|
|
9277
|
+
router,
|
|
9278
|
+
amountOut.toString(),
|
|
9279
|
+
amountLimit.toString(),
|
|
9280
|
+
partner ?? this.partner
|
|
9281
|
+
);
|
|
9282
|
+
}
|
|
9144
9283
|
}
|
|
9145
9284
|
/**
|
|
9146
9285
|
* Router swap with max amount in validation.
|
|
@@ -9151,434 +9290,402 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
9151
9290
|
* @returns TransactionObjectArgument - The output coin from the swap
|
|
9152
9291
|
* @throws Error if input coin amount exceeds maxAmountIn
|
|
9153
9292
|
*/
|
|
9154
|
-
routerSwapWithMaxAmountIn(params) {
|
|
9155
|
-
|
|
9156
|
-
|
|
9157
|
-
|
|
9158
|
-
|
|
9159
|
-
|
|
9160
|
-
|
|
9161
|
-
|
|
9162
|
-
|
|
9163
|
-
|
|
9164
|
-
|
|
9165
|
-
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
9171
|
-
|
|
9172
|
-
|
|
9173
|
-
|
|
9174
|
-
|
|
9175
|
-
|
|
9176
|
-
|
|
9177
|
-
|
|
9178
|
-
|
|
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
|
|
9179
9330
|
);
|
|
9180
|
-
|
|
9181
|
-
|
|
9182
|
-
|
|
9183
|
-
|
|
9184
|
-
|
|
9185
|
-
|
|
9186
|
-
|
|
9187
|
-
|
|
9188
|
-
|
|
9189
|
-
|
|
9190
|
-
|
|
9191
|
-
partner != null ? partner : this.partner
|
|
9192
|
-
);
|
|
9193
|
-
} else {
|
|
9194
|
-
return this.expectOutputSwapV3WithMaxAmountIn(
|
|
9195
|
-
txb,
|
|
9196
|
-
inputCoin,
|
|
9197
|
-
router,
|
|
9198
|
-
maxAmountIn,
|
|
9199
|
-
amountOut.toString(),
|
|
9200
|
-
amountLimit.toString(),
|
|
9201
|
-
partner != null ? partner : this.partner
|
|
9202
|
-
);
|
|
9203
|
-
}
|
|
9204
|
-
});
|
|
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
|
+
}
|
|
9205
9342
|
}
|
|
9206
9343
|
// auto build input coin
|
|
9207
9344
|
// auto merge, transfer or destory target coin.
|
|
9208
|
-
fastRouterSwap(params) {
|
|
9209
|
-
|
|
9210
|
-
|
|
9211
|
-
|
|
9212
|
-
|
|
9213
|
-
|
|
9214
|
-
|
|
9215
|
-
|
|
9216
|
-
|
|
9217
|
-
|
|
9218
|
-
|
|
9219
|
-
|
|
9220
|
-
|
|
9221
|
-
|
|
9222
|
-
router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
9223
|
-
);
|
|
9224
|
-
}
|
|
9225
|
-
const expectedAmountOut = byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
|
|
9226
|
-
const expectedAmountIn = byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
|
|
9227
|
-
const amountLimit = CalculateAmountLimit(
|
|
9228
|
-
byAmountIn ? expectedAmountOut : expectedAmountIn,
|
|
9229
|
-
byAmountIn,
|
|
9230
|
-
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()
|
|
9231
9359
|
);
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
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()
|
|
9237
9379
|
});
|
|
9238
|
-
|
|
9239
|
-
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
9243
|
-
|
|
9244
|
-
|
|
9245
|
-
|
|
9246
|
-
|
|
9247
|
-
|
|
9248
|
-
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
if (CoinUtils.isSuiCoin(targetCoinType)) {
|
|
9255
|
-
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]);
|
|
9256
9396
|
} else {
|
|
9257
|
-
|
|
9258
|
-
|
|
9259
|
-
|
|
9260
|
-
|
|
9261
|
-
|
|
9262
|
-
|
|
9263
|
-
|
|
9264
|
-
|
|
9265
|
-
packages: router.packages
|
|
9266
|
-
},
|
|
9267
|
-
txb
|
|
9268
|
-
);
|
|
9269
|
-
}
|
|
9270
|
-
}
|
|
9271
|
-
});
|
|
9272
|
-
}
|
|
9273
|
-
mergeSwap(params) {
|
|
9274
|
-
return __async(this, null, function* () {
|
|
9275
|
-
const { router, inputCoins, slippage, txb, partner } = params;
|
|
9276
|
-
if (slippage > 1 || slippage < 0) {
|
|
9277
|
-
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
|
|
9278
|
-
}
|
|
9279
|
-
if (!router.packages || !router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
9280
|
-
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
9281
|
-
}
|
|
9282
|
-
if (!router.allRoutes || router.allRoutes.length === 0) {
|
|
9283
|
-
throw new Error("No routes found in merge swap response");
|
|
9284
|
-
}
|
|
9285
|
-
const outputCoins = [];
|
|
9286
|
-
for (let i = 0; i < router.allRoutes.length && i < inputCoins.length; i++) {
|
|
9287
|
-
const route = router.allRoutes[i];
|
|
9288
|
-
const inputCoin = inputCoins[i];
|
|
9289
|
-
const routeRouter = {
|
|
9290
|
-
quoteID: router.quoteID,
|
|
9291
|
-
amountIn: route.amountIn,
|
|
9292
|
-
amountOut: route.amountOut,
|
|
9293
|
-
deviationRatio: Number(route.deviationRatio),
|
|
9294
|
-
byAmountIn: true,
|
|
9295
|
-
// Merge swap is always by amount in
|
|
9296
|
-
paths: route.paths,
|
|
9297
|
-
insufficientLiquidity: false,
|
|
9298
|
-
packages: router.packages
|
|
9299
|
-
};
|
|
9300
|
-
const routerParams = {
|
|
9301
|
-
router: routeRouter,
|
|
9302
|
-
inputCoin: inputCoin.coin,
|
|
9303
|
-
slippage,
|
|
9304
|
-
txb,
|
|
9305
|
-
partner: partner != null ? partner : this.partner
|
|
9306
|
-
};
|
|
9307
|
-
const outputCoin = yield this.routerSwap(routerParams);
|
|
9308
|
-
outputCoins.push(outputCoin);
|
|
9309
|
-
}
|
|
9310
|
-
if (outputCoins.length === 0) {
|
|
9311
|
-
throw new Error("No output coins generated from merge swap");
|
|
9312
|
-
}
|
|
9313
|
-
let finalOutputCoin = outputCoins[0];
|
|
9314
|
-
if (outputCoins.length > 1) {
|
|
9315
|
-
txb.mergeCoins(finalOutputCoin, outputCoins.slice(1));
|
|
9397
|
+
transferOrDestroyCoin(
|
|
9398
|
+
{
|
|
9399
|
+
coin: targetCoin,
|
|
9400
|
+
coinType: targetCoinType,
|
|
9401
|
+
packages: router.packages
|
|
9402
|
+
},
|
|
9403
|
+
txb
|
|
9404
|
+
);
|
|
9316
9405
|
}
|
|
9317
|
-
|
|
9318
|
-
});
|
|
9406
|
+
}
|
|
9319
9407
|
}
|
|
9320
|
-
|
|
9321
|
-
|
|
9322
|
-
|
|
9323
|
-
|
|
9324
|
-
|
|
9325
|
-
|
|
9326
|
-
|
|
9327
|
-
|
|
9328
|
-
|
|
9329
|
-
|
|
9330
|
-
|
|
9331
|
-
|
|
9332
|
-
|
|
9333
|
-
|
|
9334
|
-
|
|
9335
|
-
|
|
9336
|
-
|
|
9337
|
-
|
|
9338
|
-
|
|
9339
|
-
|
|
9340
|
-
|
|
9341
|
-
|
|
9342
|
-
|
|
9343
|
-
|
|
9344
|
-
router
|
|
9345
|
-
|
|
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,
|
|
9346
9437
|
slippage,
|
|
9347
9438
|
txb,
|
|
9348
|
-
partner: partner
|
|
9349
|
-
};
|
|
9350
|
-
const
|
|
9351
|
-
|
|
9352
|
-
|
|
9353
|
-
|
|
9354
|
-
|
|
9355
|
-
|
|
9356
|
-
|
|
9357
|
-
|
|
9358
|
-
|
|
9359
|
-
|
|
9360
|
-
|
|
9361
|
-
|
|
9362
|
-
|
|
9363
|
-
|
|
9364
|
-
|
|
9365
|
-
|
|
9366
|
-
|
|
9367
|
-
|
|
9368
|
-
|
|
9369
|
-
|
|
9370
|
-
|
|
9371
|
-
|
|
9372
|
-
const
|
|
9373
|
-
|
|
9374
|
-
|
|
9375
|
-
|
|
9376
|
-
|
|
9377
|
-
|
|
9378
|
-
)
|
|
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]);
|
|
9379
9489
|
} else {
|
|
9380
|
-
|
|
9381
|
-
|
|
9490
|
+
transferOrDestroyCoin(
|
|
9491
|
+
{
|
|
9492
|
+
coin: targetCoin,
|
|
9493
|
+
coinType: targetCoinType,
|
|
9494
|
+
packages: router.packages
|
|
9495
|
+
},
|
|
9496
|
+
txb
|
|
9382
9497
|
);
|
|
9383
9498
|
}
|
|
9384
|
-
|
|
9385
|
-
|
|
9386
|
-
|
|
9387
|
-
|
|
9388
|
-
|
|
9389
|
-
|
|
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()
|
|
9390
9508
|
);
|
|
9391
|
-
|
|
9392
|
-
|
|
9393
|
-
|
|
9394
|
-
|
|
9395
|
-
|
|
9396
|
-
|
|
9397
|
-
|
|
9398
|
-
|
|
9399
|
-
|
|
9400
|
-
|
|
9401
|
-
|
|
9402
|
-
|
|
9403
|
-
|
|
9404
|
-
|
|
9405
|
-
|
|
9406
|
-
|
|
9407
|
-
|
|
9408
|
-
|
|
9409
|
-
|
|
9410
|
-
|
|
9411
|
-
)
|
|
9412
|
-
|
|
9413
|
-
|
|
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
|
+
}
|
|
9414
9543
|
}
|
|
9415
|
-
swapInPools(params) {
|
|
9416
|
-
|
|
9417
|
-
|
|
9418
|
-
|
|
9419
|
-
|
|
9420
|
-
|
|
9421
|
-
|
|
9422
|
-
|
|
9423
|
-
|
|
9424
|
-
|
|
9425
|
-
|
|
9426
|
-
const
|
|
9427
|
-
|
|
9428
|
-
|
|
9429
|
-
|
|
9430
|
-
|
|
9431
|
-
|
|
9432
|
-
|
|
9433
|
-
|
|
9434
|
-
|
|
9435
|
-
|
|
9436
|
-
arguments: args,
|
|
9437
|
-
typeArguments
|
|
9438
|
-
});
|
|
9439
|
-
}
|
|
9440
|
-
if (!this.signer) {
|
|
9441
|
-
this.signer = "0x0";
|
|
9442
|
-
}
|
|
9443
|
-
const simulateRes = yield this.client.devInspectTransactionBlock({
|
|
9444
|
-
transactionBlock: tx,
|
|
9445
|
-
sender: this.signer
|
|
9446
|
-
});
|
|
9447
|
-
if (simulateRes.error != null) {
|
|
9448
|
-
throw new Error("Simulation error: " + simulateRes.error);
|
|
9449
|
-
}
|
|
9450
|
-
const valueData = (_a = simulateRes.events) == null ? void 0 : _a.filter((item) => {
|
|
9451
|
-
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
|
|
9452
9565
|
});
|
|
9453
|
-
|
|
9454
|
-
|
|
9455
|
-
|
|
9456
|
-
|
|
9457
|
-
|
|
9458
|
-
|
|
9459
|
-
|
|
9460
|
-
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
|
|
9464
|
-
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
|
|
9472
|
-
|
|
9473
|
-
|
|
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;
|
|
9474
9600
|
}
|
|
9475
9601
|
}
|
|
9476
|
-
|
|
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
|
-
|
|
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
|
|
9508
9635
|
}
|
|
9509
|
-
],
|
|
9510
|
-
insufficientLiquidity: false,
|
|
9511
|
-
byAmountIn: params.byAmountIn,
|
|
9512
|
-
quoteID: `degraded-${generateUUID()}`,
|
|
9513
|
-
packages: /* @__PURE__ */ new Map([
|
|
9514
|
-
[
|
|
9515
|
-
PACKAGE_NAMES.AGGREGATOR_V3,
|
|
9516
|
-
aggregatorV3PublishedAt
|
|
9517
|
-
]
|
|
9518
|
-
])
|
|
9519
|
-
};
|
|
9520
|
-
const result = {
|
|
9521
|
-
isExceed: event.is_exceed,
|
|
9522
|
-
routeData
|
|
9523
|
-
};
|
|
9524
|
-
return result;
|
|
9525
|
-
});
|
|
9526
|
-
}
|
|
9527
|
-
updatePythPriceIDs(priceIDs, txb) {
|
|
9528
|
-
return __async(this, null, function* () {
|
|
9529
|
-
let priceUpdateData = null;
|
|
9530
|
-
let lastError = null;
|
|
9531
|
-
for (const connection of this.pythConnections) {
|
|
9532
|
-
try {
|
|
9533
|
-
priceUpdateData = yield connection.getPriceFeedsUpdateData(priceIDs);
|
|
9534
|
-
break;
|
|
9535
|
-
} catch (e) {
|
|
9536
|
-
lastError = e;
|
|
9537
|
-
console.log("Error: ", e);
|
|
9538
|
-
continue;
|
|
9539
9636
|
}
|
|
9540
|
-
|
|
9541
|
-
|
|
9542
|
-
|
|
9543
|
-
|
|
9544
|
-
|
|
9545
|
-
|
|
9546
|
-
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
|
|
9550
|
-
|
|
9551
|
-
|
|
9552
|
-
|
|
9553
|
-
|
|
9554
|
-
|
|
9555
|
-
|
|
9556
|
-
);
|
|
9557
|
-
}
|
|
9558
|
-
let priceInfoObjectIdsMap = /* @__PURE__ */ new Map();
|
|
9559
|
-
for (let i = 0; i < priceIDs.length; i++) {
|
|
9560
|
-
priceInfoObjectIdsMap.set(priceIDs[i], priceInfoObjectIds[i]);
|
|
9561
|
-
}
|
|
9562
|
-
return priceInfoObjectIdsMap;
|
|
9563
|
-
});
|
|
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;
|
|
9564
9653
|
}
|
|
9565
|
-
|
|
9566
|
-
|
|
9567
|
-
|
|
9568
|
-
|
|
9569
|
-
|
|
9570
|
-
|
|
9571
|
-
|
|
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
|
|
9572
9679
|
});
|
|
9680
|
+
return res;
|
|
9573
9681
|
}
|
|
9574
|
-
sendTransaction(txb, signer) {
|
|
9575
|
-
|
|
9576
|
-
|
|
9577
|
-
|
|
9578
|
-
|
|
9579
|
-
});
|
|
9580
|
-
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 }
|
|
9581
9687
|
});
|
|
9688
|
+
return res;
|
|
9582
9689
|
}
|
|
9583
9690
|
};
|
|
9584
9691
|
_AggregatorClient.CONFIG = {
|
|
@@ -9647,4 +9754,174 @@ decimal.js/decimal.mjs:
|
|
|
9647
9754
|
*)
|
|
9648
9755
|
*/
|
|
9649
9756
|
|
|
9650
|
-
|
|
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;
|