@cetusprotocol/aggregator-sdk 1.4.5 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bun.lock +30 -36
- package/dist/{index.mjs → index.cjs} +1226 -940
- package/dist/{index.d.mts → index.d.cts} +120 -13
- package/dist/index.d.ts +120 -13
- package/dist/index.js +1050 -1116
- package/package.json +5 -4
- package/tsconfig.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,38 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var pythSuiJs = require('@pythnetwork/pyth-sui-js');
|
|
8
|
-
|
|
9
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
|
|
11
|
-
var JSONbig__default = /*#__PURE__*/_interopDefault(JSONbig);
|
|
1
|
+
import { coinWithBalance, Transaction } from '@mysten/sui/transactions';
|
|
2
|
+
import JSONbig from 'json-bigint';
|
|
3
|
+
import { normalizeSuiObjectId, SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils';
|
|
4
|
+
import { SuiGrpcClient } from '@mysten/sui/grpc';
|
|
5
|
+
import { HermesClient } from '@pythnetwork/hermes-client';
|
|
6
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
12
7
|
|
|
13
8
|
var __create = Object.create;
|
|
14
9
|
var __defProp = Object.defineProperty;
|
|
15
|
-
var __defProps = Object.defineProperties;
|
|
16
10
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
17
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
18
11
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
19
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
20
12
|
var __getProtoOf = Object.getPrototypeOf;
|
|
21
13
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
22
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
23
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
24
|
-
var __spreadValues = (a, b) => {
|
|
25
|
-
for (var prop in b || (b = {}))
|
|
26
|
-
if (__hasOwnProp.call(b, prop))
|
|
27
|
-
__defNormalProp(a, prop, b[prop]);
|
|
28
|
-
if (__getOwnPropSymbols)
|
|
29
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
30
|
-
if (__propIsEnum.call(b, prop))
|
|
31
|
-
__defNormalProp(a, prop, b[prop]);
|
|
32
|
-
}
|
|
33
|
-
return a;
|
|
34
|
-
};
|
|
35
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
36
14
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
37
15
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
38
16
|
}) : x)(function(x) {
|
|
@@ -55,29 +33,9 @@ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__
|
|
|
55
33
|
// file that has been converted to a CommonJS file using a Babel-
|
|
56
34
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
57
35
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
58
|
-
|
|
36
|
+
__defProp(target, "default", { value: mod2, enumerable: true }) ,
|
|
59
37
|
mod2
|
|
60
38
|
));
|
|
61
|
-
var __async = (__this, __arguments, generator) => {
|
|
62
|
-
return new Promise((resolve, reject) => {
|
|
63
|
-
var fulfilled = (value) => {
|
|
64
|
-
try {
|
|
65
|
-
step(generator.next(value));
|
|
66
|
-
} catch (e) {
|
|
67
|
-
reject(e);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
var rejected = (value) => {
|
|
71
|
-
try {
|
|
72
|
-
step(generator.throw(value));
|
|
73
|
-
} catch (e) {
|
|
74
|
-
reject(e);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
78
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
39
|
|
|
82
40
|
// node_modules/bn.js/lib/bn.js
|
|
83
41
|
var require_bn = __commonJS({
|
|
@@ -2947,17 +2905,17 @@ function extractAddressFromType(type) {
|
|
|
2947
2905
|
return type.split("::")[0];
|
|
2948
2906
|
}
|
|
2949
2907
|
function extractStructTagFromType(type) {
|
|
2950
|
-
var _a;
|
|
2951
2908
|
try {
|
|
2952
2909
|
let _type = type.replace(/\s/g, "");
|
|
2953
2910
|
const genericsString = _type.match(/(<.+>)$/);
|
|
2954
|
-
const generics =
|
|
2911
|
+
const generics = genericsString?.[0]?.match(/(\w+::\w+::\w+)(?:<.*?>(?!>))?/g);
|
|
2955
2912
|
if (generics) {
|
|
2956
2913
|
_type = _type.slice(0, _type.indexOf("<"));
|
|
2957
2914
|
const tag2 = extractStructTagFromType(_type);
|
|
2958
|
-
const structTag2 =
|
|
2915
|
+
const structTag2 = {
|
|
2916
|
+
...tag2,
|
|
2959
2917
|
type_arguments: generics.map((item) => extractStructTagFromType(item).source_address)
|
|
2960
|
-
}
|
|
2918
|
+
};
|
|
2961
2919
|
structTag2.type_arguments = structTag2.type_arguments.map((item) => {
|
|
2962
2920
|
return CoinUtils.isSuiCoin(item) ? item : extractStructTagFromType(item).source_address;
|
|
2963
2921
|
});
|
|
@@ -2968,7 +2926,7 @@ function extractStructTagFromType(type) {
|
|
|
2968
2926
|
const isSuiCoin = _type === GAS_TYPE_ARG || _type === GAS_TYPE_ARG_LONG;
|
|
2969
2927
|
const structTag = {
|
|
2970
2928
|
full_address: _type,
|
|
2971
|
-
address: isSuiCoin ? "0x2" :
|
|
2929
|
+
address: isSuiCoin ? "0x2" : normalizeSuiObjectId(parts[0]),
|
|
2972
2930
|
module: parts[1],
|
|
2973
2931
|
name: parts[2],
|
|
2974
2932
|
type_arguments: [],
|
|
@@ -2993,7 +2951,7 @@ function normalizeCoinType(coinType) {
|
|
|
2993
2951
|
}
|
|
2994
2952
|
function fixSuiObjectId(value) {
|
|
2995
2953
|
if (value.toLowerCase().startsWith("0x")) {
|
|
2996
|
-
return
|
|
2954
|
+
return normalizeSuiObjectId(value);
|
|
2997
2955
|
}
|
|
2998
2956
|
return value;
|
|
2999
2957
|
}
|
|
@@ -3488,7 +3446,6 @@ function parseRouterResponse(data, byAmountIn) {
|
|
|
3488
3446
|
};
|
|
3489
3447
|
}
|
|
3490
3448
|
function parseMergeSwapResponse(data) {
|
|
3491
|
-
var _a;
|
|
3492
3449
|
let packages = /* @__PURE__ */ new Map();
|
|
3493
3450
|
if (data.packages) {
|
|
3494
3451
|
if (data.packages instanceof Map) {
|
|
@@ -3525,133 +3482,85 @@ function parseMergeSwapResponse(data) {
|
|
|
3525
3482
|
}
|
|
3526
3483
|
return {
|
|
3527
3484
|
quoteID: data.request_id || "",
|
|
3528
|
-
totalAmountOut: new import_bn2.default(
|
|
3485
|
+
totalAmountOut: new import_bn2.default(data.total_amount_out?.toString() || "0"),
|
|
3529
3486
|
allRoutes,
|
|
3530
3487
|
packages,
|
|
3531
3488
|
gas: data.gas
|
|
3532
3489
|
};
|
|
3533
3490
|
}
|
|
3534
|
-
function getRouterResult(endpoint, apiKey, params, overlayFee, overlayFeeReceiver) {
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
errorCode = 1001 /* RateLimitExceeded */;
|
|
3549
|
-
}
|
|
3550
|
-
return {
|
|
3551
|
-
quoteID: "",
|
|
3552
|
-
amountIn: ZERO,
|
|
3553
|
-
amountOut: ZERO,
|
|
3554
|
-
paths: [],
|
|
3555
|
-
byAmountIn: params.byAmountIn,
|
|
3556
|
-
insufficientLiquidity: false,
|
|
3557
|
-
deviationRatio: 0,
|
|
3558
|
-
error: {
|
|
3559
|
-
code: errorCode,
|
|
3560
|
-
msg: getAggregatorServerErrorMessage(errorCode)
|
|
3561
|
-
}
|
|
3562
|
-
};
|
|
3563
|
-
}
|
|
3564
|
-
const data = JSONbig__default.default.parse(yield response.text());
|
|
3565
|
-
if (data.data != null) {
|
|
3566
|
-
const res = parseRouterResponse(data.data, params.byAmountIn);
|
|
3567
|
-
if (overlayFee > 0 && overlayFeeReceiver !== "0x0") {
|
|
3568
|
-
if (params.byAmountIn) {
|
|
3569
|
-
const overlayFeeAmount = res.amountOut.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3570
|
-
res.overlayFee = Number(overlayFeeAmount.toString());
|
|
3571
|
-
res.amountOut = res.amountOut.sub(overlayFeeAmount);
|
|
3572
|
-
} else {
|
|
3573
|
-
const overlayFeeAmount = res.amountIn.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3574
|
-
res.overlayFee = Number(overlayFeeAmount.toString());
|
|
3575
|
-
res.amountIn = res.amountIn.add(overlayFeeAmount);
|
|
3576
|
-
}
|
|
3577
|
-
}
|
|
3578
|
-
if (!res.packages) {
|
|
3579
|
-
res.packages = /* @__PURE__ */ new Map();
|
|
3580
|
-
}
|
|
3581
|
-
if (!res.packages.has("aggregator_v3")) {
|
|
3582
|
-
res.packages.set(
|
|
3583
|
-
"aggregator_v3",
|
|
3584
|
-
"0x3864c7c59a4889fec05d1aae4bc9dba5a0e0940594b424fbed44cb3f6ac4c032"
|
|
3585
|
-
);
|
|
3586
|
-
}
|
|
3587
|
-
return res;
|
|
3491
|
+
async function getRouterResult(endpoint, apiKey, params, overlayFee, overlayFeeReceiver) {
|
|
3492
|
+
let response;
|
|
3493
|
+
if (params.liquidityChanges && params.liquidityChanges.length > 0) {
|
|
3494
|
+
response = await postRouterWithLiquidityChanges(endpoint, params);
|
|
3495
|
+
} else {
|
|
3496
|
+
response = await getRouter(endpoint, apiKey, params);
|
|
3497
|
+
}
|
|
3498
|
+
if (!response) {
|
|
3499
|
+
return null;
|
|
3500
|
+
}
|
|
3501
|
+
if (!response.ok) {
|
|
3502
|
+
let errorCode = 1004 /* BadRequest */;
|
|
3503
|
+
if (response.status === 429) {
|
|
3504
|
+
errorCode = 1001 /* RateLimitExceeded */;
|
|
3588
3505
|
}
|
|
3589
|
-
const code = processErrorStatusCode(data.code);
|
|
3590
|
-
const msg = getAggregatorServerErrorMessage(code, data.msg);
|
|
3591
|
-
const insufficientLiquidity = msg.includes("Insufficient liquidity");
|
|
3592
3506
|
return {
|
|
3593
3507
|
quoteID: "",
|
|
3594
3508
|
amountIn: ZERO,
|
|
3595
3509
|
amountOut: ZERO,
|
|
3596
3510
|
paths: [],
|
|
3597
|
-
insufficientLiquidity,
|
|
3598
3511
|
byAmountIn: params.byAmountIn,
|
|
3512
|
+
insufficientLiquidity: false,
|
|
3599
3513
|
deviationRatio: 0,
|
|
3600
3514
|
error: {
|
|
3601
|
-
code,
|
|
3602
|
-
msg
|
|
3515
|
+
code: errorCode,
|
|
3516
|
+
msg: getAggregatorServerErrorMessage(errorCode)
|
|
3603
3517
|
}
|
|
3604
3518
|
};
|
|
3605
|
-
}
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
splitCount,
|
|
3619
|
-
providers
|
|
3620
|
-
} = params;
|
|
3621
|
-
const fromCoin = completionCoin(from);
|
|
3622
|
-
const targetCoin = completionCoin(target);
|
|
3623
|
-
let url = `${endpoint}/find_routes?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
|
|
3624
|
-
if (depth) {
|
|
3625
|
-
url += `&depth=${depth}`;
|
|
3626
|
-
}
|
|
3627
|
-
if (splitAlgorithm) {
|
|
3628
|
-
url += `&split_algorithm=${splitAlgorithm}`;
|
|
3629
|
-
}
|
|
3630
|
-
if (splitFactor) {
|
|
3631
|
-
url += `&split_factor=${splitFactor}`;
|
|
3632
|
-
}
|
|
3633
|
-
if (splitCount) {
|
|
3634
|
-
url += `&split_count=${splitCount}`;
|
|
3635
|
-
}
|
|
3636
|
-
if (providers) {
|
|
3637
|
-
if (providers.length > 0) {
|
|
3638
|
-
url += `&providers=${providers.join(",")}`;
|
|
3639
|
-
}
|
|
3640
|
-
}
|
|
3641
|
-
if (apiKey.length > 0) {
|
|
3642
|
-
url += `&apiKey=${apiKey}`;
|
|
3519
|
+
}
|
|
3520
|
+
const data = JSONbig.parse(await response.text());
|
|
3521
|
+
if (data.data != null) {
|
|
3522
|
+
const res = parseRouterResponse(data.data, params.byAmountIn);
|
|
3523
|
+
if (overlayFee > 0 && overlayFeeReceiver !== "0x0") {
|
|
3524
|
+
if (params.byAmountIn) {
|
|
3525
|
+
const overlayFeeAmount = res.amountOut.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3526
|
+
res.overlayFee = Number(overlayFeeAmount.toString());
|
|
3527
|
+
res.amountOut = res.amountOut.sub(overlayFeeAmount);
|
|
3528
|
+
} else {
|
|
3529
|
+
const overlayFeeAmount = res.amountIn.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3530
|
+
res.overlayFee = Number(overlayFeeAmount.toString());
|
|
3531
|
+
res.amountIn = res.amountIn.add(overlayFeeAmount);
|
|
3643
3532
|
}
|
|
3644
|
-
url += `&v=${SDK_VERSION}`;
|
|
3645
|
-
const response = yield fetch(url);
|
|
3646
|
-
return response;
|
|
3647
|
-
} catch (error) {
|
|
3648
|
-
console.error(error);
|
|
3649
|
-
return null;
|
|
3650
3533
|
}
|
|
3651
|
-
|
|
3534
|
+
if (!res.packages) {
|
|
3535
|
+
res.packages = /* @__PURE__ */ new Map();
|
|
3536
|
+
}
|
|
3537
|
+
if (!res.packages.has("aggregator_v3")) {
|
|
3538
|
+
res.packages.set(
|
|
3539
|
+
"aggregator_v3",
|
|
3540
|
+
"0x3864c7c59a4889fec05d1aae4bc9dba5a0e0940594b424fbed44cb3f6ac4c032"
|
|
3541
|
+
);
|
|
3542
|
+
}
|
|
3543
|
+
return res;
|
|
3544
|
+
}
|
|
3545
|
+
const code = processErrorStatusCode(data.code);
|
|
3546
|
+
const msg = getAggregatorServerErrorMessage(code, data.msg);
|
|
3547
|
+
const insufficientLiquidity = msg.includes("Insufficient liquidity");
|
|
3548
|
+
return {
|
|
3549
|
+
quoteID: "",
|
|
3550
|
+
amountIn: ZERO,
|
|
3551
|
+
amountOut: ZERO,
|
|
3552
|
+
paths: [],
|
|
3553
|
+
insufficientLiquidity,
|
|
3554
|
+
byAmountIn: params.byAmountIn,
|
|
3555
|
+
deviationRatio: 0,
|
|
3556
|
+
error: {
|
|
3557
|
+
code,
|
|
3558
|
+
msg
|
|
3559
|
+
}
|
|
3560
|
+
};
|
|
3652
3561
|
}
|
|
3653
|
-
function
|
|
3654
|
-
|
|
3562
|
+
async function getRouter(endpoint, apiKey, params) {
|
|
3563
|
+
try {
|
|
3655
3564
|
const {
|
|
3656
3565
|
from,
|
|
3657
3566
|
target,
|
|
@@ -3661,154 +3570,190 @@ function postRouterWithLiquidityChanges(endpoint, params) {
|
|
|
3661
3570
|
splitAlgorithm,
|
|
3662
3571
|
splitFactor,
|
|
3663
3572
|
splitCount,
|
|
3664
|
-
providers
|
|
3665
|
-
liquidityChanges
|
|
3573
|
+
providers
|
|
3666
3574
|
} = params;
|
|
3667
3575
|
const fromCoin = completionCoin(from);
|
|
3668
3576
|
const targetCoin = completionCoin(target);
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
from: fromCoin,
|
|
3673
|
-
target: targetCoin,
|
|
3674
|
-
amount: Number(amount.toString()),
|
|
3675
|
-
by_amount_in: byAmountIn,
|
|
3676
|
-
depth,
|
|
3677
|
-
split_algorithm: splitAlgorithm,
|
|
3678
|
-
split_factor: splitFactor,
|
|
3679
|
-
split_count: splitCount,
|
|
3680
|
-
providers: providersStr,
|
|
3681
|
-
liquidity_changes: liquidityChanges.map((change) => ({
|
|
3682
|
-
pool: change.poolID,
|
|
3683
|
-
tick_lower: change.ticklower,
|
|
3684
|
-
tick_upper: change.tickUpper,
|
|
3685
|
-
delta_liquidity: change.deltaLiquidity
|
|
3686
|
-
})),
|
|
3687
|
-
v: SDK_VERSION
|
|
3688
|
-
};
|
|
3689
|
-
try {
|
|
3690
|
-
const response = yield fetch(url, {
|
|
3691
|
-
method: "POST",
|
|
3692
|
-
headers: {
|
|
3693
|
-
"Content-Type": "application/json"
|
|
3694
|
-
},
|
|
3695
|
-
body: JSON.stringify(requestData)
|
|
3696
|
-
});
|
|
3697
|
-
return response;
|
|
3698
|
-
} catch (error) {
|
|
3699
|
-
console.error("Error:", error);
|
|
3700
|
-
return null;
|
|
3577
|
+
let url = `${endpoint}/find_routes?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
|
|
3578
|
+
if (depth) {
|
|
3579
|
+
url += `&depth=${depth}`;
|
|
3701
3580
|
}
|
|
3702
|
-
|
|
3703
|
-
}
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
if (providers && providers.length > 0) {
|
|
3581
|
+
if (splitAlgorithm) {
|
|
3582
|
+
url += `&split_algorithm=${splitAlgorithm}`;
|
|
3583
|
+
}
|
|
3584
|
+
if (splitFactor) {
|
|
3585
|
+
url += `&split_factor=${splitFactor}`;
|
|
3586
|
+
}
|
|
3587
|
+
if (splitCount) {
|
|
3588
|
+
url += `&split_count=${splitCount}`;
|
|
3589
|
+
}
|
|
3590
|
+
if (providers) {
|
|
3591
|
+
if (providers.length > 0) {
|
|
3714
3592
|
url += `&providers=${providers.join(",")}`;
|
|
3715
3593
|
}
|
|
3716
|
-
if (apiKey.length > 0) {
|
|
3717
|
-
url += `&apiKey=${apiKey}`;
|
|
3718
|
-
}
|
|
3719
|
-
url += `&v=${SDK_VERSION}`;
|
|
3720
|
-
const fromsData = froms.map((from) => ({
|
|
3721
|
-
coin_type: completionCoin(from.coinType),
|
|
3722
|
-
amount: Number(from.amount.toString())
|
|
3723
|
-
}));
|
|
3724
|
-
url += `&froms=${encodeURIComponent(JSON.stringify(fromsData))}`;
|
|
3725
|
-
const response = yield fetch(url);
|
|
3726
|
-
console.log("response", response);
|
|
3727
|
-
return response;
|
|
3728
|
-
} catch (error) {
|
|
3729
|
-
console.error(error);
|
|
3730
|
-
return null;
|
|
3731
3594
|
}
|
|
3732
|
-
|
|
3733
|
-
}
|
|
3734
|
-
function getMergeSwapResult(endpoint, apiKey, params, overlayFee, overlayFeeReceiver) {
|
|
3735
|
-
return __async(this, null, function* () {
|
|
3736
|
-
const response = yield getMergeSwapRouter(endpoint, apiKey, params);
|
|
3737
|
-
if (!response) {
|
|
3738
|
-
return null;
|
|
3595
|
+
if (apiKey.length > 0) {
|
|
3596
|
+
url += `&apiKey=${apiKey}`;
|
|
3739
3597
|
}
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3598
|
+
url += `&v=${SDK_VERSION}`;
|
|
3599
|
+
const response = await fetch(url);
|
|
3600
|
+
return response;
|
|
3601
|
+
} catch (error) {
|
|
3602
|
+
console.error(error);
|
|
3603
|
+
return null;
|
|
3604
|
+
}
|
|
3605
|
+
}
|
|
3606
|
+
async function postRouterWithLiquidityChanges(endpoint, params) {
|
|
3607
|
+
const {
|
|
3608
|
+
from,
|
|
3609
|
+
target,
|
|
3610
|
+
amount,
|
|
3611
|
+
byAmountIn,
|
|
3612
|
+
depth,
|
|
3613
|
+
splitAlgorithm,
|
|
3614
|
+
splitFactor,
|
|
3615
|
+
splitCount,
|
|
3616
|
+
providers,
|
|
3617
|
+
liquidityChanges
|
|
3618
|
+
} = params;
|
|
3619
|
+
const fromCoin = completionCoin(from);
|
|
3620
|
+
const targetCoin = completionCoin(target);
|
|
3621
|
+
const url = `${endpoint}/find_routes`;
|
|
3622
|
+
const providersStr = providers?.join(",");
|
|
3623
|
+
const requestData = {
|
|
3624
|
+
from: fromCoin,
|
|
3625
|
+
target: targetCoin,
|
|
3626
|
+
amount: Number(amount.toString()),
|
|
3627
|
+
by_amount_in: byAmountIn,
|
|
3628
|
+
depth,
|
|
3629
|
+
split_algorithm: splitAlgorithm,
|
|
3630
|
+
split_factor: splitFactor,
|
|
3631
|
+
split_count: splitCount,
|
|
3632
|
+
providers: providersStr,
|
|
3633
|
+
liquidity_changes: liquidityChanges.map((change) => ({
|
|
3634
|
+
pool: change.poolID,
|
|
3635
|
+
tick_lower: change.ticklower,
|
|
3636
|
+
tick_upper: change.tickUpper,
|
|
3637
|
+
delta_liquidity: change.deltaLiquidity
|
|
3638
|
+
})),
|
|
3639
|
+
v: SDK_VERSION
|
|
3640
|
+
};
|
|
3641
|
+
try {
|
|
3642
|
+
const response = await fetch(url, {
|
|
3643
|
+
method: "POST",
|
|
3644
|
+
headers: {
|
|
3645
|
+
"Content-Type": "application/json"
|
|
3646
|
+
},
|
|
3647
|
+
body: JSON.stringify(requestData)
|
|
3648
|
+
});
|
|
3649
|
+
return response;
|
|
3650
|
+
} catch (error) {
|
|
3651
|
+
console.error("Error:", error);
|
|
3652
|
+
return null;
|
|
3653
|
+
}
|
|
3654
|
+
}
|
|
3655
|
+
async function getMergeSwapRouter(endpoint, apiKey, params) {
|
|
3656
|
+
try {
|
|
3657
|
+
const { target, byAmountIn, depth, providers, froms } = params;
|
|
3658
|
+
const targetCoin = completionCoin(target);
|
|
3659
|
+
let url = `${endpoint}/multi_find_routes?target=${targetCoin}&by_amount_in=${byAmountIn}`;
|
|
3660
|
+
if (depth) {
|
|
3661
|
+
url += `&depth=${depth}`;
|
|
3662
|
+
}
|
|
3663
|
+
if (providers && providers.length > 0) {
|
|
3664
|
+
url += `&providers=${providers.join(",")}`;
|
|
3665
|
+
}
|
|
3666
|
+
if (apiKey.length > 0) {
|
|
3667
|
+
url += `&apiKey=${apiKey}`;
|
|
3668
|
+
}
|
|
3669
|
+
url += `&v=${SDK_VERSION}`;
|
|
3670
|
+
const fromsData = froms.map((from) => ({
|
|
3671
|
+
coin_type: completionCoin(from.coinType),
|
|
3672
|
+
amount: Number(from.amount.toString())
|
|
3673
|
+
}));
|
|
3674
|
+
url += `&froms=${encodeURIComponent(JSON.stringify(fromsData))}`;
|
|
3675
|
+
const response = await fetch(url);
|
|
3676
|
+
console.log("response", response);
|
|
3677
|
+
return response;
|
|
3678
|
+
} catch (error) {
|
|
3679
|
+
console.error(error);
|
|
3680
|
+
return null;
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
async function getMergeSwapResult(endpoint, apiKey, params, overlayFee, overlayFeeReceiver) {
|
|
3684
|
+
const response = await getMergeSwapRouter(endpoint, apiKey, params);
|
|
3685
|
+
if (!response) {
|
|
3686
|
+
return null;
|
|
3687
|
+
}
|
|
3688
|
+
if (!response.ok) {
|
|
3689
|
+
let errorCode = 1004 /* BadRequest */;
|
|
3690
|
+
if (response.status === 429) {
|
|
3691
|
+
errorCode = 1001 /* RateLimitExceeded */;
|
|
3754
3692
|
}
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
totalAmountOut: ZERO,
|
|
3763
|
-
allRoutes: [],
|
|
3764
|
-
error: {
|
|
3765
|
-
code: code2,
|
|
3766
|
-
msg: msg2
|
|
3767
|
-
}
|
|
3768
|
-
};
|
|
3769
|
-
}
|
|
3770
|
-
const responseText = yield response.text();
|
|
3771
|
-
const data = JSONbig__default.default.parse(responseText);
|
|
3772
|
-
if (data.data != null) {
|
|
3773
|
-
console.log("data.data not null", data.data);
|
|
3774
|
-
const res = parseMergeSwapResponse(data.data);
|
|
3775
|
-
if (overlayFee > 0 && overlayFeeReceiver !== "0x0" && params.byAmountIn) {
|
|
3776
|
-
const overlayFeeAmount = res.totalAmountOut.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3777
|
-
res.totalAmountOut = res.totalAmountOut.sub(overlayFeeAmount);
|
|
3778
|
-
for (const route of res.allRoutes) {
|
|
3779
|
-
const routeFee = route.amountOut.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3780
|
-
route.amountOut = route.amountOut.sub(routeFee);
|
|
3781
|
-
}
|
|
3782
|
-
}
|
|
3783
|
-
if (!res.packages) {
|
|
3784
|
-
res.packages = /* @__PURE__ */ new Map();
|
|
3693
|
+
return {
|
|
3694
|
+
quoteID: "",
|
|
3695
|
+
totalAmountOut: ZERO,
|
|
3696
|
+
allRoutes: [],
|
|
3697
|
+
error: {
|
|
3698
|
+
code: errorCode,
|
|
3699
|
+
msg: getAggregatorServerErrorMessage(errorCode)
|
|
3785
3700
|
}
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
const
|
|
3701
|
+
};
|
|
3702
|
+
}
|
|
3703
|
+
if (!response.ok) {
|
|
3704
|
+
const code2 = processErrorStatusCode(response.status);
|
|
3705
|
+
const responseText2 = await response.text();
|
|
3706
|
+
const data2 = JSONbig.parse(responseText2);
|
|
3707
|
+
const msg2 = getAggregatorServerErrorMessage(code2, data2.msg);
|
|
3790
3708
|
return {
|
|
3791
3709
|
quoteID: "",
|
|
3792
3710
|
totalAmountOut: ZERO,
|
|
3793
3711
|
allRoutes: [],
|
|
3794
3712
|
error: {
|
|
3795
|
-
code,
|
|
3796
|
-
msg
|
|
3713
|
+
code: code2,
|
|
3714
|
+
msg: msg2
|
|
3797
3715
|
}
|
|
3798
3716
|
};
|
|
3799
|
-
}
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3717
|
+
}
|
|
3718
|
+
const responseText = await response.text();
|
|
3719
|
+
const data = JSONbig.parse(responseText);
|
|
3720
|
+
if (data.data != null) {
|
|
3721
|
+
console.log("data.data not null", data.data);
|
|
3722
|
+
const res = parseMergeSwapResponse(data.data);
|
|
3723
|
+
if (overlayFee > 0 && overlayFeeReceiver !== "0x0" && params.byAmountIn) {
|
|
3724
|
+
const overlayFeeAmount = res.totalAmountOut.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3725
|
+
res.totalAmountOut = res.totalAmountOut.sub(overlayFeeAmount);
|
|
3726
|
+
for (const route of res.allRoutes) {
|
|
3727
|
+
const routeFee = route.amountOut.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
|
|
3728
|
+
route.amountOut = route.amountOut.sub(routeFee);
|
|
3729
|
+
}
|
|
3810
3730
|
}
|
|
3811
|
-
|
|
3731
|
+
if (!res.packages) {
|
|
3732
|
+
res.packages = /* @__PURE__ */ new Map();
|
|
3733
|
+
}
|
|
3734
|
+
return res;
|
|
3735
|
+
}
|
|
3736
|
+
const code = processErrorStatusCode(data.code);
|
|
3737
|
+
const msg = getAggregatorServerErrorMessage(code, data.msg);
|
|
3738
|
+
return {
|
|
3739
|
+
quoteID: "",
|
|
3740
|
+
totalAmountOut: ZERO,
|
|
3741
|
+
allRoutes: [],
|
|
3742
|
+
error: {
|
|
3743
|
+
code,
|
|
3744
|
+
msg
|
|
3745
|
+
}
|
|
3746
|
+
};
|
|
3747
|
+
}
|
|
3748
|
+
async function getDeepbookV3Config(endpoint) {
|
|
3749
|
+
const url = `${endpoint}/deepbookv3_config`;
|
|
3750
|
+
try {
|
|
3751
|
+
const response = await fetch(url);
|
|
3752
|
+
return response.json();
|
|
3753
|
+
} catch (error) {
|
|
3754
|
+
console.error("Error:", error);
|
|
3755
|
+
return null;
|
|
3756
|
+
}
|
|
3812
3757
|
}
|
|
3813
3758
|
function processFlattenRoutes(routerData) {
|
|
3814
3759
|
const paths = routerData.paths;
|
|
@@ -6105,7 +6050,7 @@ function CalculateAmountLimitByDecimal(expectAmount, byAmountIn, slippage) {
|
|
|
6105
6050
|
var CetusRouter = class {
|
|
6106
6051
|
constructor(env, partner) {
|
|
6107
6052
|
this.globalConfig = env === 0 /* Mainnet */ ? "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f" : "0xc6273f844b4bc258952c4e477697aa12c918c8e08106fac6b934811298c9820a";
|
|
6108
|
-
this.partner = partner
|
|
6053
|
+
this.partner = partner ?? (env === 0 /* Mainnet */ ? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b" : "0xfdc30896f88f74544fd507722d3bf52e46b06412ba8241ba0e854cbc65f8d85f");
|
|
6109
6054
|
}
|
|
6110
6055
|
// By amount in
|
|
6111
6056
|
swap(txb, flattenedPath, swapContext, _extends) {
|
|
@@ -6136,7 +6081,7 @@ var CetusRouter = class {
|
|
|
6136
6081
|
txb.object(this.partner),
|
|
6137
6082
|
txb.pure.bool(swapData.direction),
|
|
6138
6083
|
txb.pure.u64(swapData.amountIn),
|
|
6139
|
-
txb.object(
|
|
6084
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6140
6085
|
];
|
|
6141
6086
|
txb.moveCall({
|
|
6142
6087
|
target: `${swapData.publishedAt}::cetus::swap`,
|
|
@@ -6155,7 +6100,7 @@ var CetusRouter = class {
|
|
|
6155
6100
|
txb.pure.bool(path.direction),
|
|
6156
6101
|
txb.pure.bool(false),
|
|
6157
6102
|
// isExactIn
|
|
6158
|
-
txb.object(
|
|
6103
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6159
6104
|
];
|
|
6160
6105
|
const [coinAType, coinBType] = path.direction ? [path.from, path.target] : [path.target, path.from];
|
|
6161
6106
|
const [flashReceipt, repayAmount] = txb.moveCall({
|
|
@@ -6238,7 +6183,7 @@ var KriyaV3Router = class {
|
|
|
6238
6183
|
txb.object(this.version),
|
|
6239
6184
|
txb.pure.bool(swapData.direction),
|
|
6240
6185
|
txb.pure.u64(swapData.amountIn),
|
|
6241
|
-
txb.object(
|
|
6186
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6242
6187
|
];
|
|
6243
6188
|
txb.moveCall({
|
|
6244
6189
|
target: `${swapData.publishedAt}::kriya_clmm::swap`,
|
|
@@ -6285,7 +6230,7 @@ var FlowxV3Router = class {
|
|
|
6285
6230
|
txb.pure.u64(swapData.feeRate),
|
|
6286
6231
|
txb.pure.u64(swapData.amountIn),
|
|
6287
6232
|
txb.pure.bool(swapData.direction),
|
|
6288
|
-
txb.object(
|
|
6233
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6289
6234
|
];
|
|
6290
6235
|
txb.moveCall({
|
|
6291
6236
|
target: `${swapData.publishedAt}::flowx_clmm::swap`,
|
|
@@ -6337,7 +6282,7 @@ var TurbosRouter = class {
|
|
|
6337
6282
|
txb.object(this.versioned),
|
|
6338
6283
|
txb.pure.bool(swapData.direction),
|
|
6339
6284
|
txb.pure.u64(swapData.amountIn),
|
|
6340
|
-
txb.object(
|
|
6285
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6341
6286
|
];
|
|
6342
6287
|
txb.moveCall({
|
|
6343
6288
|
target: `${swapData.publishedAt}::turbos::swap`,
|
|
@@ -6380,7 +6325,7 @@ var BluefinRouter = class {
|
|
|
6380
6325
|
txb.object(swapData.poolId),
|
|
6381
6326
|
txb.pure.bool(swapData.direction),
|
|
6382
6327
|
txb.pure.u64(swapData.amountIn),
|
|
6383
|
-
txb.object(
|
|
6328
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6384
6329
|
];
|
|
6385
6330
|
txb.moveCall({
|
|
6386
6331
|
target: `${swapData.publishedAt}::bluefin::swap`,
|
|
@@ -6423,7 +6368,7 @@ var MomentumRouter = class {
|
|
|
6423
6368
|
txb.pure.bool(swapData.direction),
|
|
6424
6369
|
txb.pure.u64(swapData.amountIn),
|
|
6425
6370
|
txb.object(this.version),
|
|
6426
|
-
txb.object(
|
|
6371
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6427
6372
|
];
|
|
6428
6373
|
txb.moveCall({
|
|
6429
6374
|
target: `${swapData.publishedAt}::momentum::swap`,
|
|
@@ -6466,7 +6411,7 @@ var MagmaRouter = class {
|
|
|
6466
6411
|
txb.object(swapData.poolId),
|
|
6467
6412
|
txb.pure.bool(swapData.direction),
|
|
6468
6413
|
txb.pure.u64(swapData.amountIn),
|
|
6469
|
-
txb.object(
|
|
6414
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6470
6415
|
];
|
|
6471
6416
|
txb.moveCall({
|
|
6472
6417
|
target: `${swapData.publishedAt}::magma::swap`,
|
|
@@ -6619,17 +6564,16 @@ var DeepbookV3Router = class {
|
|
|
6619
6564
|
this.executeSwapContract(txb, swapData, swapContext, _extends);
|
|
6620
6565
|
}
|
|
6621
6566
|
prepareSwapData(flattenedPath) {
|
|
6622
|
-
var _a, _b, _c, _d, _e;
|
|
6623
6567
|
if (flattenedPath.path.publishedAt == null) {
|
|
6624
6568
|
throw new Error("DeepBook V3 not set publishedAt");
|
|
6625
6569
|
}
|
|
6626
6570
|
const path = flattenedPath.path;
|
|
6627
6571
|
const [coinAType, coinBType] = path.direction ? [path.from, path.target] : [path.target, path.from];
|
|
6628
6572
|
const amountIn = flattenedPath.isLastUseOfIntermediateToken ? AGGREGATOR_V3_CONFIG.MAX_AMOUNT_IN : path.amountIn;
|
|
6629
|
-
const needAddDeepPricePoint =
|
|
6630
|
-
const referencePoolId =
|
|
6631
|
-
const referencePoolBaseType =
|
|
6632
|
-
const referencePoolQuoteType =
|
|
6573
|
+
const needAddDeepPricePoint = path.extendedDetails?.deepbookv3_need_add_deep_price_point ?? false;
|
|
6574
|
+
const referencePoolId = path.extendedDetails?.deepbookv3_reference_pool_id;
|
|
6575
|
+
const referencePoolBaseType = path.extendedDetails?.deepbookv3_reference_pool_base_type;
|
|
6576
|
+
const referencePoolQuoteType = path.extendedDetails?.deepbookv3_reference_pool_quote_type;
|
|
6633
6577
|
if (needAddDeepPricePoint) {
|
|
6634
6578
|
if (!referencePoolId) {
|
|
6635
6579
|
throw new Error(
|
|
@@ -6672,12 +6616,12 @@ var DeepbookV3Router = class {
|
|
|
6672
6616
|
arguments: [
|
|
6673
6617
|
txb.object(swapData.poolId),
|
|
6674
6618
|
txb.object(swapData.referencePoolId),
|
|
6675
|
-
txb.object(
|
|
6619
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6676
6620
|
]
|
|
6677
6621
|
});
|
|
6678
6622
|
}
|
|
6679
6623
|
executeSwapContract(txb, swapData, swapContext, _extends) {
|
|
6680
|
-
const deepCoin =
|
|
6624
|
+
const deepCoin = _extends?.deepbookv3DeepFee || txb.moveCall({
|
|
6681
6625
|
target: "0x2::coin::zero",
|
|
6682
6626
|
typeArguments: [this.getDeepFeeType()]
|
|
6683
6627
|
});
|
|
@@ -6688,7 +6632,7 @@ var DeepbookV3Router = class {
|
|
|
6688
6632
|
txb.pure.u64(swapData.amountIn),
|
|
6689
6633
|
txb.pure.bool(swapData.direction),
|
|
6690
6634
|
deepCoin,
|
|
6691
|
-
txb.object(
|
|
6635
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6692
6636
|
];
|
|
6693
6637
|
txb.moveCall({
|
|
6694
6638
|
target: `${swapData.publishedAt}::deepbookv3::swap`,
|
|
@@ -6718,7 +6662,6 @@ var AftermathRouter = class {
|
|
|
6718
6662
|
this.executeSwapContract(txb, swapData, swapContext);
|
|
6719
6663
|
}
|
|
6720
6664
|
prepareSwapData(flattenedPath) {
|
|
6721
|
-
var _a, _b;
|
|
6722
6665
|
if (flattenedPath.path.publishedAt == null) {
|
|
6723
6666
|
throw new Error("Aftermath not set publishedAt");
|
|
6724
6667
|
}
|
|
@@ -6728,7 +6671,7 @@ var AftermathRouter = class {
|
|
|
6728
6671
|
return {
|
|
6729
6672
|
coinAType,
|
|
6730
6673
|
coinBType,
|
|
6731
|
-
feeType:
|
|
6674
|
+
feeType: path.extendedDetails?.aftermath_lp_supply_type || path.extendedDetails?.aftermath_lp_supply_type || "0x2::sui::SUI",
|
|
6732
6675
|
// Use LP supply type from path (handle both camelCase and snake_case)
|
|
6733
6676
|
direction: path.direction,
|
|
6734
6677
|
amountIn,
|
|
@@ -6825,7 +6768,7 @@ var SteammCPMMRouter = class {
|
|
|
6825
6768
|
txb.object(swapData.extendedDetails.steamm_lending_market),
|
|
6826
6769
|
txb.pure.bool(swapData.direction),
|
|
6827
6770
|
txb.pure.u64(swapData.amountIn),
|
|
6828
|
-
txb.object(
|
|
6771
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6829
6772
|
];
|
|
6830
6773
|
txb.moveCall({
|
|
6831
6774
|
target: `${swapData.publishedAt}::steamm_cpmm::swap`,
|
|
@@ -6884,7 +6827,7 @@ var ScallopRouter = class {
|
|
|
6884
6827
|
txb.object(this.marketData),
|
|
6885
6828
|
txb.object(swapData.scallopScoinTreasury),
|
|
6886
6829
|
txb.pure.u64(swapData.amountIn),
|
|
6887
|
-
txb.object(
|
|
6830
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
6888
6831
|
];
|
|
6889
6832
|
const func = swapData.direction ? "swap_a2b" : "swap_b2a";
|
|
6890
6833
|
txb.moveCall({
|
|
@@ -7000,7 +6943,7 @@ var HaedalPmmRouter = class {
|
|
|
7000
6943
|
// amount_in
|
|
7001
6944
|
txb.pure.bool(swapData.a2b),
|
|
7002
6945
|
// a2b
|
|
7003
|
-
txb.object(
|
|
6946
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7004
6947
|
// clock
|
|
7005
6948
|
];
|
|
7006
6949
|
txb.moveCall({
|
|
@@ -7074,7 +7017,7 @@ var ObricRouter = class {
|
|
|
7074
7017
|
txb.object(this.pythStateObjectId),
|
|
7075
7018
|
txb.object(swapData.coinAPriceInfoObjectId),
|
|
7076
7019
|
txb.object(swapData.coinBPriceInfoObjectId),
|
|
7077
|
-
txb.object(
|
|
7020
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7078
7021
|
];
|
|
7079
7022
|
txb.moveCall({
|
|
7080
7023
|
target: `${swapData.publishedAt}::obric::swap`,
|
|
@@ -7149,7 +7092,7 @@ var SevenkRouter = class {
|
|
|
7149
7092
|
txb.object(swapData.coinAOracleId),
|
|
7150
7093
|
holder,
|
|
7151
7094
|
txb.object(swapData.coinAPriceId),
|
|
7152
|
-
txb.object(
|
|
7095
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7153
7096
|
]
|
|
7154
7097
|
});
|
|
7155
7098
|
txb.moveCall({
|
|
@@ -7159,7 +7102,7 @@ var SevenkRouter = class {
|
|
|
7159
7102
|
txb.object(swapData.coinBOracleId),
|
|
7160
7103
|
holder,
|
|
7161
7104
|
txb.object(swapData.coinBPriceId),
|
|
7162
|
-
txb.object(
|
|
7105
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7163
7106
|
]
|
|
7164
7107
|
});
|
|
7165
7108
|
const args = [
|
|
@@ -7256,7 +7199,7 @@ var SteammOmmRouter = class {
|
|
|
7256
7199
|
txb.object(extendedDetails.steammOracleRegistryId),
|
|
7257
7200
|
txb.object(swapData.priceInfoObjectIdA),
|
|
7258
7201
|
txb.pure.u64(extendedDetails.steammOracleIndexA),
|
|
7259
|
-
txb.object(
|
|
7202
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7260
7203
|
]
|
|
7261
7204
|
});
|
|
7262
7205
|
const oraclePriceUpdateB = txb.moveCall({
|
|
@@ -7266,7 +7209,7 @@ var SteammOmmRouter = class {
|
|
|
7266
7209
|
txb.object(extendedDetails.steammOracleRegistryId),
|
|
7267
7210
|
txb.object(swapData.priceInfoObjectIdB),
|
|
7268
7211
|
txb.pure.u64(extendedDetails.steammOracleIndexB),
|
|
7269
|
-
txb.object(
|
|
7212
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7270
7213
|
]
|
|
7271
7214
|
});
|
|
7272
7215
|
const args = [
|
|
@@ -7278,7 +7221,7 @@ var SteammOmmRouter = class {
|
|
|
7278
7221
|
oraclePriceUpdateA,
|
|
7279
7222
|
oraclePriceUpdateB,
|
|
7280
7223
|
txb.pure.u64(swapData.amountIn),
|
|
7281
|
-
txb.object(
|
|
7224
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7282
7225
|
];
|
|
7283
7226
|
txb.moveCall({
|
|
7284
7227
|
target: `${swapData.publishedAt}::steamm_omm::${swapData.func}`,
|
|
@@ -7374,7 +7317,7 @@ var SteammOmmV2Router = class {
|
|
|
7374
7317
|
txb.object(extendedDetails.steamm_oracle_registry_id),
|
|
7375
7318
|
txb.object(swapData.priceInfoObjectIdA),
|
|
7376
7319
|
txb.pure.u64(extendedDetails.steamm_oracle_index_a),
|
|
7377
|
-
txb.object(
|
|
7320
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7378
7321
|
]
|
|
7379
7322
|
});
|
|
7380
7323
|
const oraclePriceUpdateB = txb.moveCall({
|
|
@@ -7384,7 +7327,7 @@ var SteammOmmV2Router = class {
|
|
|
7384
7327
|
txb.object(extendedDetails.steamm_oracle_registry_id),
|
|
7385
7328
|
txb.object(swapData.priceInfoObjectIdB),
|
|
7386
7329
|
txb.pure.u64(extendedDetails.steamm_oracle_index_b),
|
|
7387
|
-
txb.object(
|
|
7330
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7388
7331
|
]
|
|
7389
7332
|
});
|
|
7390
7333
|
const args = [
|
|
@@ -7397,7 +7340,7 @@ var SteammOmmV2Router = class {
|
|
|
7397
7340
|
oraclePriceUpdateB,
|
|
7398
7341
|
txb.pure.bool(swapData.direction),
|
|
7399
7342
|
txb.pure.u64(swapData.amountIn),
|
|
7400
|
-
txb.object(
|
|
7343
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
7401
7344
|
];
|
|
7402
7345
|
txb.moveCall({
|
|
7403
7346
|
target: `${swapData.publishedAt}::steamm_omm_v2::swap`,
|
|
@@ -7501,7 +7444,7 @@ var MetastableRouter = class {
|
|
|
7501
7444
|
}
|
|
7502
7445
|
depositArgs.push(txb.object(priceId));
|
|
7503
7446
|
}
|
|
7504
|
-
depositArgs.push(txb.object(
|
|
7447
|
+
depositArgs.push(txb.object(SUI_CLOCK_OBJECT_ID));
|
|
7505
7448
|
break;
|
|
7506
7449
|
}
|
|
7507
7450
|
default:
|
|
@@ -7662,7 +7605,7 @@ var AfsuiRouter = class {
|
|
|
7662
7605
|
txb.object("0x5"),
|
|
7663
7606
|
// SuiSystemState
|
|
7664
7607
|
txb.object(this.referVault),
|
|
7665
|
-
txb.
|
|
7608
|
+
txb.pure.address(this.validator),
|
|
7666
7609
|
txb.pure.bool(swapData.direction),
|
|
7667
7610
|
txb.pure.u64(swapData.amountIn)
|
|
7668
7611
|
];
|
|
@@ -7752,7 +7695,7 @@ var HawalRouter = class {
|
|
|
7752
7695
|
swapContext,
|
|
7753
7696
|
txb.object(this.staking),
|
|
7754
7697
|
txb.object(swapData.poolId),
|
|
7755
|
-
txb.
|
|
7698
|
+
txb.pure.address(this.validator),
|
|
7756
7699
|
txb.pure.bool(swapData.direction),
|
|
7757
7700
|
txb.pure.u64(swapData.amountIn)
|
|
7758
7701
|
];
|
|
@@ -7872,6 +7815,229 @@ function transferOrDestroyCoin(params, txb) {
|
|
|
7872
7815
|
arguments: [coin]
|
|
7873
7816
|
});
|
|
7874
7817
|
}
|
|
7818
|
+
var MAX_ARGUMENT_SIZE = 16 * 1024;
|
|
7819
|
+
var PythAdapter = class {
|
|
7820
|
+
constructor(client, pythStateId, wormholeStateId, hermesUrls) {
|
|
7821
|
+
this.priceFeedObjectIdCache = /* @__PURE__ */ new Map();
|
|
7822
|
+
this.client = client;
|
|
7823
|
+
this.pythStateId = pythStateId;
|
|
7824
|
+
this.wormholeStateId = wormholeStateId;
|
|
7825
|
+
const urls = [...hermesUrls];
|
|
7826
|
+
if (!urls.includes("https://hermes.pyth.network")) {
|
|
7827
|
+
urls.push("https://hermes.pyth.network");
|
|
7828
|
+
}
|
|
7829
|
+
this.hermesClients = urls.map(
|
|
7830
|
+
(url) => new HermesClient(url, { timeout: 3e3 })
|
|
7831
|
+
);
|
|
7832
|
+
}
|
|
7833
|
+
async getPriceFeedsUpdateData(priceIDs) {
|
|
7834
|
+
let lastError = null;
|
|
7835
|
+
for (const hermes of this.hermesClients) {
|
|
7836
|
+
try {
|
|
7837
|
+
const response = await hermes.getLatestPriceUpdates(priceIDs, {
|
|
7838
|
+
encoding: "hex"
|
|
7839
|
+
});
|
|
7840
|
+
return response.binary.data.map((hex) => Buffer.from(hex, "hex"));
|
|
7841
|
+
} catch (e) {
|
|
7842
|
+
lastError = e;
|
|
7843
|
+
continue;
|
|
7844
|
+
}
|
|
7845
|
+
}
|
|
7846
|
+
throw new Error(
|
|
7847
|
+
`All Pyth Hermes endpoints are unavailable. Detailed error: ${lastError?.message}`
|
|
7848
|
+
);
|
|
7849
|
+
}
|
|
7850
|
+
async getBaseUpdateFee() {
|
|
7851
|
+
if (this.baseUpdateFee !== void 0) {
|
|
7852
|
+
return this.baseUpdateFee;
|
|
7853
|
+
}
|
|
7854
|
+
const { object } = await this.client.getObject({
|
|
7855
|
+
objectId: this.pythStateId,
|
|
7856
|
+
include: { json: true }
|
|
7857
|
+
});
|
|
7858
|
+
const json = object.json;
|
|
7859
|
+
if (!json) {
|
|
7860
|
+
throw new Error("Unable to fetch pyth state object");
|
|
7861
|
+
}
|
|
7862
|
+
this.baseUpdateFee = Number(json.base_update_fee);
|
|
7863
|
+
return this.baseUpdateFee;
|
|
7864
|
+
}
|
|
7865
|
+
async getPackageId(objectId) {
|
|
7866
|
+
const { object } = await this.client.getObject({
|
|
7867
|
+
objectId,
|
|
7868
|
+
include: { json: true }
|
|
7869
|
+
});
|
|
7870
|
+
const json = object.json;
|
|
7871
|
+
if (!json) {
|
|
7872
|
+
throw new Error(`Cannot fetch package id for object ${objectId}`);
|
|
7873
|
+
}
|
|
7874
|
+
if ("upgrade_cap" in json) {
|
|
7875
|
+
return json.upgrade_cap.package;
|
|
7876
|
+
}
|
|
7877
|
+
throw new Error("upgrade_cap not found");
|
|
7878
|
+
}
|
|
7879
|
+
async getWormholePackageId() {
|
|
7880
|
+
if (!this.wormholePackageId) {
|
|
7881
|
+
this.wormholePackageId = await this.getPackageId(this.wormholeStateId);
|
|
7882
|
+
}
|
|
7883
|
+
return this.wormholePackageId;
|
|
7884
|
+
}
|
|
7885
|
+
async getPythPackageId() {
|
|
7886
|
+
if (!this.pythPackageId) {
|
|
7887
|
+
this.pythPackageId = await this.getPackageId(this.pythStateId);
|
|
7888
|
+
}
|
|
7889
|
+
return this.pythPackageId;
|
|
7890
|
+
}
|
|
7891
|
+
async getPriceFeedObjectId(feedId) {
|
|
7892
|
+
const normalizedFeedId = feedId.replace("0x", "");
|
|
7893
|
+
if (this.priceFeedObjectIdCache.has(normalizedFeedId)) {
|
|
7894
|
+
return this.priceFeedObjectIdCache.get(normalizedFeedId);
|
|
7895
|
+
}
|
|
7896
|
+
const { id: tableId, fieldType } = await this.getPriceTableInfo();
|
|
7897
|
+
const feedIdBytes = Buffer.from(normalizedFeedId, "hex");
|
|
7898
|
+
try {
|
|
7899
|
+
const PriceIdentifier = bcs.struct("PriceIdentifier", {
|
|
7900
|
+
bytes: bcs.vector(bcs.u8())
|
|
7901
|
+
});
|
|
7902
|
+
const bcsBytes = PriceIdentifier.serialize({ bytes: Array.from(feedIdBytes) }).toBytes();
|
|
7903
|
+
const result = await this.client.getDynamicField({
|
|
7904
|
+
parentId: tableId,
|
|
7905
|
+
name: {
|
|
7906
|
+
type: fieldType,
|
|
7907
|
+
bcs: bcsBytes
|
|
7908
|
+
}
|
|
7909
|
+
});
|
|
7910
|
+
const valueBcs = result.dynamicField.value.bcs;
|
|
7911
|
+
const valueBytes = valueBcs instanceof Uint8Array ? valueBcs : new Uint8Array(Object.values(valueBcs));
|
|
7912
|
+
const objectId = "0x" + Array.from(valueBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
7913
|
+
this.priceFeedObjectIdCache.set(normalizedFeedId, objectId);
|
|
7914
|
+
return objectId;
|
|
7915
|
+
} catch {
|
|
7916
|
+
return void 0;
|
|
7917
|
+
}
|
|
7918
|
+
}
|
|
7919
|
+
async getPriceTableInfo() {
|
|
7920
|
+
if (this.priceTableInfo !== void 0) {
|
|
7921
|
+
return this.priceTableInfo;
|
|
7922
|
+
}
|
|
7923
|
+
let cursor = null;
|
|
7924
|
+
let hasNextPage = true;
|
|
7925
|
+
while (hasNextPage) {
|
|
7926
|
+
const dynamicFields = await this.client.listDynamicFields({
|
|
7927
|
+
parentId: this.pythStateId,
|
|
7928
|
+
cursor
|
|
7929
|
+
});
|
|
7930
|
+
for (const field of dynamicFields.dynamicFields) {
|
|
7931
|
+
if (field.name.type === "vector<u8>") {
|
|
7932
|
+
const objectId = field.$kind === "DynamicObject" && field.childId ? field.childId : field.fieldId;
|
|
7933
|
+
const fieldObj = await this.client.getObject({
|
|
7934
|
+
objectId,
|
|
7935
|
+
include: { json: true }
|
|
7936
|
+
});
|
|
7937
|
+
const type = fieldObj.object.type;
|
|
7938
|
+
if (type.includes("table::Table")) {
|
|
7939
|
+
const innerTypes = type.replace(/.*table::Table</, "").replace(/>$/, "");
|
|
7940
|
+
const fieldType = innerTypes.split(",")[0].trim();
|
|
7941
|
+
this.priceTableInfo = { id: fieldObj.object.objectId, fieldType };
|
|
7942
|
+
return this.priceTableInfo;
|
|
7943
|
+
}
|
|
7944
|
+
}
|
|
7945
|
+
}
|
|
7946
|
+
hasNextPage = dynamicFields.hasNextPage;
|
|
7947
|
+
cursor = dynamicFields.cursor;
|
|
7948
|
+
}
|
|
7949
|
+
throw new Error(
|
|
7950
|
+
"Price Table not found, contract may not be initialized"
|
|
7951
|
+
);
|
|
7952
|
+
}
|
|
7953
|
+
extractVaaBytesFromAccumulatorMessage(accumulatorMessage) {
|
|
7954
|
+
const trailingPayloadSize = accumulatorMessage.readUint8(6);
|
|
7955
|
+
const vaaSizeOffset = 7 + trailingPayloadSize + 1;
|
|
7956
|
+
const vaaSize = accumulatorMessage.readUint16BE(vaaSizeOffset);
|
|
7957
|
+
const vaaOffset = vaaSizeOffset + 2;
|
|
7958
|
+
return accumulatorMessage.subarray(vaaOffset, vaaOffset + vaaSize);
|
|
7959
|
+
}
|
|
7960
|
+
async verifyVaas(vaas, tx) {
|
|
7961
|
+
const wormholePackageId = await this.getWormholePackageId();
|
|
7962
|
+
const verifiedVaas = [];
|
|
7963
|
+
for (const vaa of vaas) {
|
|
7964
|
+
const [verifiedVaa] = tx.moveCall({
|
|
7965
|
+
target: `${wormholePackageId}::vaa::parse_and_verify`,
|
|
7966
|
+
arguments: [
|
|
7967
|
+
tx.object(this.wormholeStateId),
|
|
7968
|
+
tx.pure(
|
|
7969
|
+
bcs.vector(bcs.u8()).serialize(Array.from(vaa), { maxSize: MAX_ARGUMENT_SIZE }).toBytes()
|
|
7970
|
+
),
|
|
7971
|
+
tx.object(SUI_CLOCK_OBJECT_ID)
|
|
7972
|
+
]
|
|
7973
|
+
});
|
|
7974
|
+
verifiedVaas.push(verifiedVaa);
|
|
7975
|
+
}
|
|
7976
|
+
return verifiedVaas;
|
|
7977
|
+
}
|
|
7978
|
+
async verifyVaasAndGetHotPotato(tx, updates, packageId) {
|
|
7979
|
+
if (updates.length > 1) {
|
|
7980
|
+
throw new Error(
|
|
7981
|
+
"SDK does not support sending multiple accumulator messages in a single transaction"
|
|
7982
|
+
);
|
|
7983
|
+
}
|
|
7984
|
+
const vaa = this.extractVaaBytesFromAccumulatorMessage(updates[0]);
|
|
7985
|
+
const verifiedVaas = await this.verifyVaas([vaa], tx);
|
|
7986
|
+
const [priceUpdatesHotPotato] = tx.moveCall({
|
|
7987
|
+
target: `${packageId}::pyth::create_authenticated_price_infos_using_accumulator`,
|
|
7988
|
+
arguments: [
|
|
7989
|
+
tx.object(this.pythStateId),
|
|
7990
|
+
tx.pure(
|
|
7991
|
+
bcs.vector(bcs.u8()).serialize(Array.from(updates[0]), { maxSize: MAX_ARGUMENT_SIZE }).toBytes()
|
|
7992
|
+
),
|
|
7993
|
+
verifiedVaas[0],
|
|
7994
|
+
tx.object(SUI_CLOCK_OBJECT_ID)
|
|
7995
|
+
]
|
|
7996
|
+
});
|
|
7997
|
+
return priceUpdatesHotPotato;
|
|
7998
|
+
}
|
|
7999
|
+
async updatePriceFeeds(tx, updates, feedIds) {
|
|
8000
|
+
const packageId = await this.getPythPackageId();
|
|
8001
|
+
let priceUpdatesHotPotato = await this.verifyVaasAndGetHotPotato(
|
|
8002
|
+
tx,
|
|
8003
|
+
updates,
|
|
8004
|
+
packageId
|
|
8005
|
+
);
|
|
8006
|
+
const baseUpdateFee = await this.getBaseUpdateFee();
|
|
8007
|
+
const coins = tx.splitCoins(
|
|
8008
|
+
tx.gas,
|
|
8009
|
+
feedIds.map(() => tx.pure.u64(baseUpdateFee))
|
|
8010
|
+
);
|
|
8011
|
+
const priceInfoObjects = [];
|
|
8012
|
+
let coinId = 0;
|
|
8013
|
+
for (const feedId of feedIds) {
|
|
8014
|
+
const priceInfoObjectId = await this.getPriceFeedObjectId(feedId);
|
|
8015
|
+
if (!priceInfoObjectId) {
|
|
8016
|
+
throw new Error(
|
|
8017
|
+
`Price feed ${feedId} not found, please create it first`
|
|
8018
|
+
);
|
|
8019
|
+
}
|
|
8020
|
+
priceInfoObjects.push(priceInfoObjectId);
|
|
8021
|
+
[priceUpdatesHotPotato] = tx.moveCall({
|
|
8022
|
+
target: `${packageId}::pyth::update_single_price_feed`,
|
|
8023
|
+
arguments: [
|
|
8024
|
+
tx.object(this.pythStateId),
|
|
8025
|
+
priceUpdatesHotPotato,
|
|
8026
|
+
tx.object(priceInfoObjectId),
|
|
8027
|
+
coins[coinId],
|
|
8028
|
+
tx.object(SUI_CLOCK_OBJECT_ID)
|
|
8029
|
+
]
|
|
8030
|
+
});
|
|
8031
|
+
coinId++;
|
|
8032
|
+
}
|
|
8033
|
+
tx.moveCall({
|
|
8034
|
+
target: `${packageId}::hot_potato_vector::destroy`,
|
|
8035
|
+
arguments: [priceUpdatesHotPotato],
|
|
8036
|
+
typeArguments: [`${packageId}::price_info::PriceInfo`]
|
|
8037
|
+
});
|
|
8038
|
+
return priceInfoObjects;
|
|
8039
|
+
}
|
|
8040
|
+
};
|
|
7875
8041
|
|
|
7876
8042
|
// src/utils/uuid.ts
|
|
7877
8043
|
function generateDowngradeUuid6() {
|
|
@@ -7930,7 +8096,7 @@ function extractTimestampFromDowngradeUuid6(uuid) {
|
|
|
7930
8096
|
const timestampHex = timeHigh + timeMid;
|
|
7931
8097
|
const timestamp = parseInt(timestampHex, 16);
|
|
7932
8098
|
return isNaN(timestamp) ? null : timestamp;
|
|
7933
|
-
} catch
|
|
8099
|
+
} catch {
|
|
7934
8100
|
return null;
|
|
7935
8101
|
}
|
|
7936
8102
|
}
|
|
@@ -7946,72 +8112,60 @@ function processEndpoint(endpoint) {
|
|
|
7946
8112
|
}
|
|
7947
8113
|
|
|
7948
8114
|
// src/utils/account_cap.ts
|
|
7949
|
-
function getOrCreateAccountCap(txb, client, owner) {
|
|
7950
|
-
|
|
7951
|
-
|
|
7952
|
-
if (accountCapStr !== null) {
|
|
7953
|
-
return {
|
|
7954
|
-
accountCap: txb.object(accountCapStr),
|
|
7955
|
-
isCreate: false
|
|
7956
|
-
};
|
|
7957
|
-
}
|
|
7958
|
-
const accountCap = txb.moveCall({
|
|
7959
|
-
target: `${DEEPBOOK_PUBLISHED_AT}::${DEEPBOOK_CLOB_V2_MODULE}::create_account`,
|
|
7960
|
-
typeArguments: [],
|
|
7961
|
-
arguments: []
|
|
7962
|
-
});
|
|
8115
|
+
async function getOrCreateAccountCap(txb, client, owner) {
|
|
8116
|
+
let accountCapStr = await getAccountCap(client, owner);
|
|
8117
|
+
if (accountCapStr !== null) {
|
|
7963
8118
|
return {
|
|
7964
|
-
accountCap,
|
|
7965
|
-
isCreate:
|
|
8119
|
+
accountCap: txb.object(accountCapStr),
|
|
8120
|
+
isCreate: false
|
|
7966
8121
|
};
|
|
8122
|
+
}
|
|
8123
|
+
const accountCap = txb.moveCall({
|
|
8124
|
+
target: `${DEEPBOOK_PUBLISHED_AT}::${DEEPBOOK_CLOB_V2_MODULE}::create_account`,
|
|
8125
|
+
typeArguments: [],
|
|
8126
|
+
arguments: []
|
|
7967
8127
|
});
|
|
8128
|
+
return {
|
|
8129
|
+
accountCap,
|
|
8130
|
+
isCreate: true
|
|
8131
|
+
};
|
|
7968
8132
|
}
|
|
7969
|
-
function getAccountCap(client, owner) {
|
|
7970
|
-
|
|
7971
|
-
|
|
7972
|
-
|
|
7973
|
-
|
|
7974
|
-
|
|
7975
|
-
|
|
7976
|
-
|
|
7977
|
-
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
module: DEEPBOOK_CUSTODIAN_V2_MODULE
|
|
7982
|
-
}
|
|
7983
|
-
}
|
|
7984
|
-
});
|
|
7985
|
-
if (ownedObjects != null && ownedObjects.data != null) {
|
|
7986
|
-
if (ownedObjects.data.length !== 0) {
|
|
7987
|
-
return ownedObjects.data[0].data.objectId;
|
|
7988
|
-
}
|
|
7989
|
-
if (ownedObjects.data.length < 50) {
|
|
7990
|
-
break;
|
|
7991
|
-
}
|
|
7992
|
-
} else {
|
|
7993
|
-
break;
|
|
7994
|
-
}
|
|
8133
|
+
async function getAccountCap(client, owner) {
|
|
8134
|
+
const limit = 50;
|
|
8135
|
+
let cursor = null;
|
|
8136
|
+
while (true) {
|
|
8137
|
+
const ownedObjects = await client.listOwnedObjects({
|
|
8138
|
+
owner,
|
|
8139
|
+
cursor,
|
|
8140
|
+
limit,
|
|
8141
|
+
type: `${DEEPBOOK_PACKAGE_ID}::${DEEPBOOK_CUSTODIAN_V2_MODULE}::AccountCap`
|
|
8142
|
+
});
|
|
8143
|
+
if (ownedObjects.objects.length !== 0) {
|
|
8144
|
+
return ownedObjects.objects[0].objectId;
|
|
7995
8145
|
}
|
|
7996
|
-
|
|
7997
|
-
|
|
8146
|
+
if (!ownedObjects.hasNextPage) {
|
|
8147
|
+
break;
|
|
8148
|
+
}
|
|
8149
|
+
cursor = ownedObjects.cursor;
|
|
8150
|
+
}
|
|
8151
|
+
return null;
|
|
7998
8152
|
}
|
|
7999
8153
|
|
|
8000
8154
|
// src/utils/config.ts
|
|
8001
8155
|
function getAggregatorV2PublishedAt(publishedAt, packages) {
|
|
8002
|
-
if (packages
|
|
8156
|
+
if (packages?.has("aggregator_v2")) {
|
|
8003
8157
|
return packages.get("aggregator_v2");
|
|
8004
8158
|
}
|
|
8005
8159
|
return publishedAt || PUBLISHED_ADDRESSES.V2.Mainnet;
|
|
8006
8160
|
}
|
|
8007
8161
|
function getAggregatorV2ExtendPublishedAt(publishedAt, packages) {
|
|
8008
|
-
if (packages
|
|
8162
|
+
if (packages?.has("aggregator_v2_extend")) {
|
|
8009
8163
|
return packages.get("aggregator_v2_extend");
|
|
8010
8164
|
}
|
|
8011
8165
|
return publishedAt || PUBLISHED_ADDRESSES.V2_EXTEND.Mainnet;
|
|
8012
8166
|
}
|
|
8013
8167
|
function getAggregatorV2Extend2PublishedAt(publishedAt, packages) {
|
|
8014
|
-
if (packages
|
|
8168
|
+
if (packages?.has("aggregator_v2_extend2")) {
|
|
8015
8169
|
return packages.get("aggregator_v2_extend2");
|
|
8016
8170
|
}
|
|
8017
8171
|
return publishedAt || PUBLISHED_ADDRESSES.V2_EXTEND2.Mainnet;
|
|
@@ -8020,9 +8174,10 @@ function getAggregatorV2Extend2PublishedAt(publishedAt, packages) {
|
|
|
8020
8174
|
// src/utils/gas.ts
|
|
8021
8175
|
var import_bn4 = __toESM(require_bn());
|
|
8022
8176
|
function extractGasMetrics(result) {
|
|
8023
|
-
const
|
|
8024
|
-
const
|
|
8025
|
-
if (!success) {
|
|
8177
|
+
const txResult = result.Transaction ?? result.FailedTransaction;
|
|
8178
|
+
const effects = txResult?.effects;
|
|
8179
|
+
if (!effects || !effects.status.success) {
|
|
8180
|
+
const errorMsg = effects?.status.success === false ? effects.status.error.message : "Unknown error";
|
|
8026
8181
|
return {
|
|
8027
8182
|
computationCost: "0",
|
|
8028
8183
|
storageCost: "0",
|
|
@@ -8032,27 +8187,27 @@ function extractGasMetrics(result) {
|
|
|
8032
8187
|
gasUsed: "0",
|
|
8033
8188
|
gasPrice: "0",
|
|
8034
8189
|
success: false,
|
|
8035
|
-
error:
|
|
8190
|
+
error: errorMsg
|
|
8036
8191
|
};
|
|
8037
8192
|
}
|
|
8038
8193
|
const gasUsed = effects.gasUsed;
|
|
8039
8194
|
return {
|
|
8040
|
-
computationCost: gasUsed.computationCost
|
|
8041
|
-
storageCost: gasUsed.storageCost
|
|
8042
|
-
storageRebate: gasUsed.storageRebate
|
|
8043
|
-
nonRefundableStorageFee: gasUsed.nonRefundableStorageFee
|
|
8195
|
+
computationCost: gasUsed.computationCost,
|
|
8196
|
+
storageCost: gasUsed.storageCost,
|
|
8197
|
+
storageRebate: gasUsed.storageRebate,
|
|
8198
|
+
nonRefundableStorageFee: gasUsed.nonRefundableStorageFee,
|
|
8044
8199
|
totalGasCost: calculateTotalGasCost(gasUsed),
|
|
8045
|
-
gasUsed: gasUsed.computationCost
|
|
8200
|
+
gasUsed: gasUsed.computationCost,
|
|
8046
8201
|
gasPrice: "1000",
|
|
8047
8202
|
// Standard Sui gas price in MIST
|
|
8048
8203
|
success: true
|
|
8049
8204
|
};
|
|
8050
8205
|
}
|
|
8051
8206
|
function calculateTotalGasCost(gasUsed) {
|
|
8052
|
-
const computation = new import_bn4.default(gasUsed.computationCost
|
|
8053
|
-
const storage = new import_bn4.default(gasUsed.storageCost
|
|
8054
|
-
const rebate = new import_bn4.default(gasUsed.storageRebate
|
|
8055
|
-
const nonRefundable = new import_bn4.default(gasUsed.nonRefundableStorageFee
|
|
8207
|
+
const computation = new import_bn4.default(gasUsed.computationCost);
|
|
8208
|
+
const storage = new import_bn4.default(gasUsed.storageCost);
|
|
8209
|
+
const rebate = new import_bn4.default(gasUsed.storageRebate);
|
|
8210
|
+
const nonRefundable = new import_bn4.default(gasUsed.nonRefundableStorageFee);
|
|
8056
8211
|
return computation.add(storage).sub(rebate).add(nonRefundable).toString();
|
|
8057
8212
|
}
|
|
8058
8213
|
function calculateGasEfficiency(amountOut, totalGasCost) {
|
|
@@ -8094,12 +8249,12 @@ function calculateAverageGas(analyses) {
|
|
|
8094
8249
|
}
|
|
8095
8250
|
function formatGasMetrics(metrics, isEstimated) {
|
|
8096
8251
|
if (!metrics.success) {
|
|
8097
|
-
return
|
|
8252
|
+
return `Failed: ${metrics.error}`;
|
|
8098
8253
|
}
|
|
8099
8254
|
const totalGas = Number(metrics.totalGasCost);
|
|
8100
8255
|
const gasInSui = totalGas / 1e9;
|
|
8101
8256
|
const estimatedFlag = isEstimated ? " (estimated)" : "";
|
|
8102
|
-
return
|
|
8257
|
+
return `Gas: ${totalGas.toString()} MIST (${gasInSui.toString()} SUI)${estimatedFlag}`;
|
|
8103
8258
|
}
|
|
8104
8259
|
function exportToJSON(comparison) {
|
|
8105
8260
|
return JSON.stringify(comparison, null, 2);
|
|
@@ -8167,63 +8322,62 @@ function exportToCSV(comparison) {
|
|
|
8167
8322
|
// src/utils/msafe.ts
|
|
8168
8323
|
var import_bn5 = __toESM(require_bn());
|
|
8169
8324
|
var dealWithFastRouterSwapParamsForMsafe = (data) => {
|
|
8170
|
-
|
|
8171
|
-
|
|
8172
|
-
amountIn:
|
|
8173
|
-
amountOut:
|
|
8174
|
-
paths:
|
|
8175
|
-
|
|
8176
|
-
|
|
8177
|
-
amountIn:
|
|
8178
|
-
amountOut:
|
|
8179
|
-
}
|
|
8180
|
-
if (item
|
|
8181
|
-
info["initialPrice"] =
|
|
8182
|
-
}
|
|
8183
|
-
if (
|
|
8325
|
+
const result = {
|
|
8326
|
+
...data,
|
|
8327
|
+
amountIn: data?.amountIn?.toString(),
|
|
8328
|
+
amountOut: data?.amountIn?.toString(),
|
|
8329
|
+
paths: data?.paths?.map((item) => {
|
|
8330
|
+
const info = {
|
|
8331
|
+
...item,
|
|
8332
|
+
amountIn: item?.amountIn?.toString(),
|
|
8333
|
+
amountOut: item?.amountOut?.toString()
|
|
8334
|
+
};
|
|
8335
|
+
if (item?.initialPrice) {
|
|
8336
|
+
info["initialPrice"] = item?.initialPrice?.toString();
|
|
8337
|
+
}
|
|
8338
|
+
if (item?.extendedDetails?.after_sqrt_price) {
|
|
8184
8339
|
info["extendedDetails"] = {
|
|
8185
|
-
after_sqrt_price:
|
|
8340
|
+
after_sqrt_price: item?.extendedDetails?.afterSqrtPrice?.toString()
|
|
8186
8341
|
};
|
|
8187
8342
|
}
|
|
8188
8343
|
return info;
|
|
8189
8344
|
})
|
|
8190
|
-
}
|
|
8345
|
+
};
|
|
8191
8346
|
return result;
|
|
8192
8347
|
};
|
|
8193
8348
|
var restituteMsafeFastRouterSwapParams = (data) => {
|
|
8194
|
-
|
|
8195
|
-
|
|
8196
|
-
amountIn: new import_bn5.default(data
|
|
8197
|
-
amountOut: new import_bn5.default(data
|
|
8198
|
-
paths:
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
|
|
8202
|
-
|
|
8203
|
-
|
|
8204
|
-
|
|
8349
|
+
const result = {
|
|
8350
|
+
...data,
|
|
8351
|
+
amountIn: new import_bn5.default(data?.amountIn),
|
|
8352
|
+
amountOut: new import_bn5.default(data?.amountIn),
|
|
8353
|
+
paths: data?.paths?.map((item) => {
|
|
8354
|
+
const info = {
|
|
8355
|
+
...item
|
|
8356
|
+
};
|
|
8357
|
+
if (item?.initialPrice) {
|
|
8358
|
+
info["initialPrice"] = new decimal_default(item?.initialPrice?.toString());
|
|
8359
|
+
}
|
|
8360
|
+
if (item?.extendedDetails?.after_sqrt_price) {
|
|
8205
8361
|
info["extendedDetails"] = {
|
|
8206
|
-
after_sqrt_price: new decimal_default(
|
|
8362
|
+
after_sqrt_price: new decimal_default(item?.extendedDetails?.after_sqrt_price?.toString())
|
|
8207
8363
|
};
|
|
8208
8364
|
}
|
|
8209
8365
|
return info;
|
|
8210
8366
|
})
|
|
8211
|
-
}
|
|
8367
|
+
};
|
|
8212
8368
|
return result;
|
|
8213
8369
|
};
|
|
8214
8370
|
|
|
8215
8371
|
// src/utils/transaction.ts
|
|
8216
|
-
function printTransaction(tx, isPrint = true) {
|
|
8217
|
-
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
|
|
8221
|
-
|
|
8222
|
-
|
|
8223
|
-
|
|
8224
|
-
|
|
8225
|
-
}
|
|
8226
|
-
});
|
|
8372
|
+
async function printTransaction(tx, isPrint = true) {
|
|
8373
|
+
console.log(`inputs`, tx.getData().inputs);
|
|
8374
|
+
tx.getData().commands.forEach((item, index) => {
|
|
8375
|
+
if (isPrint) {
|
|
8376
|
+
console.log(
|
|
8377
|
+
`transaction ${index}: `,
|
|
8378
|
+
JSON.stringify(item, bigIntReplacer, 2)
|
|
8379
|
+
);
|
|
8380
|
+
}
|
|
8227
8381
|
});
|
|
8228
8382
|
}
|
|
8229
8383
|
function bigIntReplacer(key, value) {
|
|
@@ -8295,7 +8449,7 @@ var HaedalHMMV2Router = class {
|
|
|
8295
8449
|
// amount_in
|
|
8296
8450
|
txb.pure.bool(swapData.a2b),
|
|
8297
8451
|
// a2b
|
|
8298
|
-
txb.object(
|
|
8452
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8299
8453
|
// clock
|
|
8300
8454
|
];
|
|
8301
8455
|
txb.moveCall({
|
|
@@ -8345,7 +8499,7 @@ var FullsailRouter = class {
|
|
|
8345
8499
|
txb.object(swapData.poolId),
|
|
8346
8500
|
txb.pure.bool(swapData.direction),
|
|
8347
8501
|
txb.pure.u64(swapData.amountIn),
|
|
8348
|
-
txb.object(
|
|
8502
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8349
8503
|
];
|
|
8350
8504
|
txb.moveCall({
|
|
8351
8505
|
target: `${swapData.publishedAt}::fullsail::swap`,
|
|
@@ -8360,7 +8514,7 @@ var CetusDlmmRouter = class {
|
|
|
8360
8514
|
throw new Error("CetusRouter only supported on mainnet");
|
|
8361
8515
|
}
|
|
8362
8516
|
this.globalConfig = "0xf31b605d117f959b9730e8c07b08b856cb05143c5e81d5751c90d2979e82f599";
|
|
8363
|
-
this.partner = partner
|
|
8517
|
+
this.partner = partner ?? "0x59ae16f6c42f578063c2da9b9c0173fe58120ceae08e40fd8212c8eceb80bb86";
|
|
8364
8518
|
this.versioned = "0x05370b2d656612dd5759cbe80463de301e3b94a921dfc72dd9daa2ecdeb2d0a8";
|
|
8365
8519
|
}
|
|
8366
8520
|
swap(txb, flattenedPath, swapContext, _extends) {
|
|
@@ -8392,7 +8546,7 @@ var CetusDlmmRouter = class {
|
|
|
8392
8546
|
txb.pure.bool(swapData.direction),
|
|
8393
8547
|
txb.pure.u64(swapData.amountIn),
|
|
8394
8548
|
txb.object(this.versioned),
|
|
8395
|
-
txb.object(
|
|
8549
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8396
8550
|
];
|
|
8397
8551
|
txb.moveCall({
|
|
8398
8552
|
target: `${swapData.publishedAt}::cetus_dlmm::swap`,
|
|
@@ -8435,7 +8589,7 @@ var FerraDlmmRouter = class {
|
|
|
8435
8589
|
txb.object(swapData.poolId),
|
|
8436
8590
|
txb.pure.bool(swapData.direction),
|
|
8437
8591
|
txb.pure.u64(swapData.amountIn),
|
|
8438
|
-
txb.object(
|
|
8592
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8439
8593
|
];
|
|
8440
8594
|
txb.moveCall({
|
|
8441
8595
|
target: `${swapData.publishedAt}::ferra_dlmm::swap`,
|
|
@@ -8478,7 +8632,7 @@ var FerraClmmRouter = class {
|
|
|
8478
8632
|
txb.object(swapData.poolId),
|
|
8479
8633
|
txb.pure.bool(swapData.direction),
|
|
8480
8634
|
txb.pure.u64(swapData.amountIn),
|
|
8481
|
-
txb.object(
|
|
8635
|
+
txb.object(SUI_CLOCK_OBJECT_ID)
|
|
8482
8636
|
];
|
|
8483
8637
|
txb.moveCall({
|
|
8484
8638
|
target: `${swapData.publishedAt}::ferra_clmm::swap`,
|
|
@@ -8620,17 +8774,18 @@ function findPythPriceIDs(paths) {
|
|
|
8620
8774
|
}
|
|
8621
8775
|
var _AggregatorClient = class _AggregatorClient {
|
|
8622
8776
|
constructor(params) {
|
|
8623
|
-
var _a, _b;
|
|
8624
8777
|
this.endpoint = params.endpoint ? processEndpoint(params.endpoint) : DEFAULT_ENDPOINT;
|
|
8625
|
-
|
|
8778
|
+
const network = params.env === 1 /* Testnet */ ? "testnet" : "mainnet";
|
|
8779
|
+
const grpcUrl = params.env === 1 /* Testnet */ ? "https://fullnode.testnet.sui.io:443" : "https://fullnode.mainnet.sui.io:443";
|
|
8780
|
+
this.client = params.client ?? new SuiGrpcClient({ network, baseUrl: grpcUrl });
|
|
8626
8781
|
this.signer = params.signer || "";
|
|
8627
8782
|
this.env = params.env || 0 /* Mainnet */;
|
|
8628
8783
|
const config2 = _AggregatorClient.CONFIG[this.env];
|
|
8629
|
-
this.
|
|
8630
|
-
this.pythClient = new pythSuiJs.SuiPythClient(
|
|
8784
|
+
this.pythAdapter = new PythAdapter(
|
|
8631
8785
|
this.client,
|
|
8632
8786
|
config2.pythStateId,
|
|
8633
|
-
config2.wormholeStateId
|
|
8787
|
+
config2.wormholeStateId,
|
|
8788
|
+
params.pythUrls ?? []
|
|
8634
8789
|
);
|
|
8635
8790
|
this.apiKey = params.apiKey || "";
|
|
8636
8791
|
this.partner = params.partner;
|
|
@@ -8649,16 +8804,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8649
8804
|
} else {
|
|
8650
8805
|
this.overlayFeeRate = 0;
|
|
8651
8806
|
}
|
|
8652
|
-
this.overlayFeeReceiver =
|
|
8653
|
-
}
|
|
8654
|
-
newPythClients(pythUrls) {
|
|
8655
|
-
if (!pythUrls.includes("https://hermes.pyth.network")) {
|
|
8656
|
-
pythUrls.push("https://hermes.pyth.network");
|
|
8657
|
-
}
|
|
8658
|
-
const connections = pythUrls.map(
|
|
8659
|
-
(url) => new pythSuiJs.SuiPriceServiceConnection(url, { timeout: 3e3 })
|
|
8660
|
-
);
|
|
8661
|
-
return connections;
|
|
8807
|
+
this.overlayFeeReceiver = params.overlayFeeReceiver ?? CLIENT_CONFIG.DEFAULT_OVERLAY_FEE_RECEIVER;
|
|
8662
8808
|
}
|
|
8663
8809
|
deepbookv3DeepFeeType() {
|
|
8664
8810
|
if (this.env === 0 /* Mainnet */) {
|
|
@@ -8667,53 +8813,43 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8667
8813
|
return DEEPBOOK_V3_DEEP_FEE_TYPES.Testnet;
|
|
8668
8814
|
}
|
|
8669
8815
|
}
|
|
8670
|
-
getDeepbookV3Config() {
|
|
8671
|
-
return
|
|
8672
|
-
return yield getDeepbookV3Config(this.endpoint);
|
|
8673
|
-
});
|
|
8816
|
+
async getDeepbookV3Config() {
|
|
8817
|
+
return await getDeepbookV3Config(this.endpoint);
|
|
8674
8818
|
}
|
|
8675
|
-
getOneCoinUsedToMerge(coinType) {
|
|
8676
|
-
|
|
8677
|
-
|
|
8678
|
-
|
|
8679
|
-
|
|
8680
|
-
|
|
8681
|
-
|
|
8682
|
-
|
|
8683
|
-
|
|
8684
|
-
return gotCoin.data[0].coinObjectId;
|
|
8685
|
-
}
|
|
8686
|
-
return null;
|
|
8687
|
-
} catch (error) {
|
|
8688
|
-
return null;
|
|
8819
|
+
async getOneCoinUsedToMerge(coinType) {
|
|
8820
|
+
try {
|
|
8821
|
+
const gotCoin = await this.client.listCoins({
|
|
8822
|
+
owner: this.signer,
|
|
8823
|
+
coinType,
|
|
8824
|
+
limit: 1
|
|
8825
|
+
});
|
|
8826
|
+
if (gotCoin.objects.length === 1) {
|
|
8827
|
+
return gotCoin.objects[0].objectId;
|
|
8689
8828
|
}
|
|
8690
|
-
|
|
8829
|
+
return null;
|
|
8830
|
+
} catch (error) {
|
|
8831
|
+
return null;
|
|
8832
|
+
}
|
|
8691
8833
|
}
|
|
8692
|
-
findRouters(params) {
|
|
8693
|
-
return
|
|
8694
|
-
|
|
8695
|
-
|
|
8696
|
-
|
|
8697
|
-
|
|
8698
|
-
|
|
8699
|
-
|
|
8700
|
-
);
|
|
8701
|
-
});
|
|
8834
|
+
async findRouters(params) {
|
|
8835
|
+
return getRouterResult(
|
|
8836
|
+
this.endpoint,
|
|
8837
|
+
this.apiKey,
|
|
8838
|
+
params,
|
|
8839
|
+
this.overlayFeeRate,
|
|
8840
|
+
this.overlayFeeReceiver
|
|
8841
|
+
);
|
|
8702
8842
|
}
|
|
8703
|
-
findMergeSwapRouters(params) {
|
|
8704
|
-
return
|
|
8705
|
-
|
|
8706
|
-
|
|
8707
|
-
|
|
8708
|
-
|
|
8709
|
-
|
|
8710
|
-
|
|
8711
|
-
);
|
|
8712
|
-
});
|
|
8843
|
+
async findMergeSwapRouters(params) {
|
|
8844
|
+
return getMergeSwapResult(
|
|
8845
|
+
this.endpoint,
|
|
8846
|
+
this.apiKey,
|
|
8847
|
+
params,
|
|
8848
|
+
this.overlayFeeRate,
|
|
8849
|
+
this.overlayFeeReceiver
|
|
8850
|
+
);
|
|
8713
8851
|
}
|
|
8714
|
-
executeFlexibleInputSwap(txb, inputCoin, routerData, expectedAmountOut, amountLimit, pythPriceIDs, partner, deepbookv3DeepFee, packages) {
|
|
8715
|
-
return __async(this, null, function* () {
|
|
8716
|
-
});
|
|
8852
|
+
async executeFlexibleInputSwap(txb, inputCoin, routerData, expectedAmountOut, amountLimit, pythPriceIDs, partner, deepbookv3DeepFee, packages) {
|
|
8717
8853
|
}
|
|
8718
8854
|
newDexRouterV3(provider, pythPriceIDs, partner, cetusDlmmPartner) {
|
|
8719
8855
|
switch (provider) {
|
|
@@ -9099,55 +9235,53 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
9099
9235
|
);
|
|
9100
9236
|
return outputCoin;
|
|
9101
9237
|
}
|
|
9102
|
-
routerSwap(params) {
|
|
9103
|
-
|
|
9104
|
-
|
|
9105
|
-
|
|
9106
|
-
|
|
9107
|
-
|
|
9108
|
-
|
|
9109
|
-
|
|
9110
|
-
|
|
9111
|
-
|
|
9112
|
-
|
|
9113
|
-
|
|
9114
|
-
|
|
9115
|
-
|
|
9116
|
-
|
|
9117
|
-
|
|
9118
|
-
|
|
9119
|
-
|
|
9120
|
-
|
|
9121
|
-
|
|
9122
|
-
|
|
9123
|
-
|
|
9124
|
-
|
|
9125
|
-
|
|
9126
|
-
|
|
9238
|
+
async routerSwap(params) {
|
|
9239
|
+
const { router, inputCoin, slippage, txb, partner } = params;
|
|
9240
|
+
if (slippage > 1 || slippage < 0) {
|
|
9241
|
+
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
|
|
9242
|
+
}
|
|
9243
|
+
if (!params.router.packages || !params.router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
9244
|
+
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
9245
|
+
}
|
|
9246
|
+
const byAmountIn = params.router.byAmountIn;
|
|
9247
|
+
const amountIn = router.amountIn;
|
|
9248
|
+
const amountOut = router.amountOut;
|
|
9249
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
9250
|
+
let overlayFee = new import_bn6.default(0);
|
|
9251
|
+
if (byAmountIn) {
|
|
9252
|
+
overlayFee = amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
9253
|
+
} else {
|
|
9254
|
+
overlayFee = amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
9255
|
+
}
|
|
9256
|
+
const expectedAmountOut = byAmountIn ? amountOut.sub(overlayFee) : amountOut;
|
|
9257
|
+
const expectedAmountIn = byAmountIn ? amountIn : amountIn.add(overlayFee);
|
|
9258
|
+
const amountLimit = CalculateAmountLimitBN(
|
|
9259
|
+
byAmountIn ? expectedAmountOut : expectedAmountIn,
|
|
9260
|
+
byAmountIn,
|
|
9261
|
+
slippage
|
|
9262
|
+
);
|
|
9263
|
+
const priceIDs = findPythPriceIDs(router.paths);
|
|
9264
|
+
const priceInfoObjectIds = priceIDs.length > 0 ? await this.updatePythPriceIDs(priceIDs, txb) : /* @__PURE__ */ new Map();
|
|
9265
|
+
if (byAmountIn) {
|
|
9266
|
+
return this.expectInputSwapV3(
|
|
9267
|
+
txb,
|
|
9268
|
+
inputCoin,
|
|
9269
|
+
router,
|
|
9270
|
+
amountOut.toString(),
|
|
9271
|
+
amountLimit.toString(),
|
|
9272
|
+
priceInfoObjectIds,
|
|
9273
|
+
partner ?? this.partner
|
|
9127
9274
|
);
|
|
9128
|
-
|
|
9129
|
-
|
|
9130
|
-
|
|
9131
|
-
|
|
9132
|
-
|
|
9133
|
-
|
|
9134
|
-
|
|
9135
|
-
|
|
9136
|
-
|
|
9137
|
-
|
|
9138
|
-
partner != null ? partner : this.partner
|
|
9139
|
-
);
|
|
9140
|
-
} else {
|
|
9141
|
-
return this.expectOutputSwapV3(
|
|
9142
|
-
txb,
|
|
9143
|
-
inputCoin,
|
|
9144
|
-
router,
|
|
9145
|
-
amountOut.toString(),
|
|
9146
|
-
amountLimit.toString(),
|
|
9147
|
-
partner != null ? partner : this.partner
|
|
9148
|
-
);
|
|
9149
|
-
}
|
|
9150
|
-
});
|
|
9275
|
+
} else {
|
|
9276
|
+
return this.expectOutputSwapV3(
|
|
9277
|
+
txb,
|
|
9278
|
+
inputCoin,
|
|
9279
|
+
router,
|
|
9280
|
+
amountOut.toString(),
|
|
9281
|
+
amountLimit.toString(),
|
|
9282
|
+
partner ?? this.partner
|
|
9283
|
+
);
|
|
9284
|
+
}
|
|
9151
9285
|
}
|
|
9152
9286
|
/**
|
|
9153
9287
|
* Router swap with max amount in validation.
|
|
@@ -9158,434 +9292,404 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
9158
9292
|
* @returns TransactionObjectArgument - The output coin from the swap
|
|
9159
9293
|
* @throws Error if input coin amount exceeds maxAmountIn
|
|
9160
9294
|
*/
|
|
9161
|
-
routerSwapWithMaxAmountIn(params) {
|
|
9162
|
-
|
|
9163
|
-
|
|
9164
|
-
|
|
9165
|
-
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
9171
|
-
|
|
9172
|
-
|
|
9173
|
-
|
|
9174
|
-
|
|
9175
|
-
|
|
9176
|
-
|
|
9177
|
-
|
|
9178
|
-
|
|
9179
|
-
|
|
9180
|
-
|
|
9181
|
-
|
|
9182
|
-
|
|
9183
|
-
|
|
9184
|
-
|
|
9185
|
-
|
|
9295
|
+
async routerSwapWithMaxAmountIn(params) {
|
|
9296
|
+
const { router, inputCoin, slippage, txb, partner, maxAmountIn } = params;
|
|
9297
|
+
if (slippage > 1 || slippage < 0) {
|
|
9298
|
+
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
|
|
9299
|
+
}
|
|
9300
|
+
if (!params.router.packages || !params.router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
9301
|
+
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
9302
|
+
}
|
|
9303
|
+
const byAmountIn = params.router.byAmountIn;
|
|
9304
|
+
const amountIn = router.amountIn;
|
|
9305
|
+
const amountOut = router.amountOut;
|
|
9306
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
9307
|
+
let overlayFee = new import_bn6.default(0);
|
|
9308
|
+
if (byAmountIn) {
|
|
9309
|
+
overlayFee = amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
9310
|
+
} else {
|
|
9311
|
+
overlayFee = amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
9312
|
+
}
|
|
9313
|
+
const expectedAmountOut = byAmountIn ? amountOut.sub(overlayFee) : amountOut;
|
|
9314
|
+
const expectedAmountIn = byAmountIn ? amountIn : amountIn.add(overlayFee);
|
|
9315
|
+
const amountLimit = CalculateAmountLimitBN(
|
|
9316
|
+
byAmountIn ? expectedAmountOut : expectedAmountIn,
|
|
9317
|
+
byAmountIn,
|
|
9318
|
+
slippage
|
|
9319
|
+
);
|
|
9320
|
+
const priceIDs = findPythPriceIDs(router.paths);
|
|
9321
|
+
const priceInfoObjectIds = priceIDs.length > 0 ? await this.updatePythPriceIDs(priceIDs, txb) : /* @__PURE__ */ new Map();
|
|
9322
|
+
if (byAmountIn) {
|
|
9323
|
+
return this.expectInputSwapV3WithMaxAmountIn(
|
|
9324
|
+
txb,
|
|
9325
|
+
inputCoin,
|
|
9326
|
+
router,
|
|
9327
|
+
maxAmountIn,
|
|
9328
|
+
amountOut.toString(),
|
|
9329
|
+
amountLimit.toString(),
|
|
9330
|
+
priceInfoObjectIds,
|
|
9331
|
+
partner ?? this.partner
|
|
9186
9332
|
);
|
|
9187
|
-
|
|
9188
|
-
|
|
9189
|
-
|
|
9190
|
-
|
|
9191
|
-
|
|
9192
|
-
|
|
9193
|
-
|
|
9194
|
-
|
|
9195
|
-
|
|
9196
|
-
|
|
9197
|
-
|
|
9198
|
-
partner != null ? partner : this.partner
|
|
9199
|
-
);
|
|
9200
|
-
} else {
|
|
9201
|
-
return this.expectOutputSwapV3WithMaxAmountIn(
|
|
9202
|
-
txb,
|
|
9203
|
-
inputCoin,
|
|
9204
|
-
router,
|
|
9205
|
-
maxAmountIn,
|
|
9206
|
-
amountOut.toString(),
|
|
9207
|
-
amountLimit.toString(),
|
|
9208
|
-
partner != null ? partner : this.partner
|
|
9209
|
-
);
|
|
9210
|
-
}
|
|
9211
|
-
});
|
|
9333
|
+
} else {
|
|
9334
|
+
return this.expectOutputSwapV3WithMaxAmountIn(
|
|
9335
|
+
txb,
|
|
9336
|
+
inputCoin,
|
|
9337
|
+
router,
|
|
9338
|
+
maxAmountIn,
|
|
9339
|
+
amountOut.toString(),
|
|
9340
|
+
amountLimit.toString(),
|
|
9341
|
+
partner ?? this.partner
|
|
9342
|
+
);
|
|
9343
|
+
}
|
|
9212
9344
|
}
|
|
9213
9345
|
// auto build input coin
|
|
9214
9346
|
// auto merge, transfer or destory target coin.
|
|
9215
|
-
fastRouterSwap(params) {
|
|
9216
|
-
|
|
9217
|
-
|
|
9218
|
-
|
|
9219
|
-
|
|
9220
|
-
|
|
9221
|
-
|
|
9222
|
-
|
|
9223
|
-
|
|
9224
|
-
|
|
9225
|
-
router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
9226
|
-
);
|
|
9227
|
-
} else {
|
|
9228
|
-
overlayFee = Number(
|
|
9229
|
-
router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
9230
|
-
);
|
|
9231
|
-
}
|
|
9232
|
-
const expectedAmountOut = byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
|
|
9233
|
-
const expectedAmountIn = byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
|
|
9234
|
-
const amountLimit = CalculateAmountLimit(
|
|
9235
|
-
byAmountIn ? expectedAmountOut : expectedAmountIn,
|
|
9236
|
-
byAmountIn,
|
|
9237
|
-
slippage
|
|
9347
|
+
async fastRouterSwap(params) {
|
|
9348
|
+
const { router, slippage, txb, partner, payDeepFeeAmount } = params;
|
|
9349
|
+
const fromCoinType = router.paths[0].from;
|
|
9350
|
+
const targetCoinType = router.paths[router.paths.length - 1].target;
|
|
9351
|
+
const byAmountIn = router.byAmountIn;
|
|
9352
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
9353
|
+
let overlayFee = 0;
|
|
9354
|
+
if (byAmountIn) {
|
|
9355
|
+
overlayFee = Number(
|
|
9356
|
+
router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
9238
9357
|
);
|
|
9239
|
-
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
9243
|
-
|
|
9358
|
+
} else {
|
|
9359
|
+
overlayFee = Number(
|
|
9360
|
+
router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
9361
|
+
);
|
|
9362
|
+
}
|
|
9363
|
+
const expectedAmountOut = byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
|
|
9364
|
+
const expectedAmountIn = byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
|
|
9365
|
+
const amountLimit = CalculateAmountLimit(
|
|
9366
|
+
byAmountIn ? expectedAmountOut : expectedAmountIn,
|
|
9367
|
+
byAmountIn,
|
|
9368
|
+
slippage
|
|
9369
|
+
);
|
|
9370
|
+
const amount = byAmountIn ? expectedAmountIn : amountLimit;
|
|
9371
|
+
let inputCoin = coinWithBalance({
|
|
9372
|
+
balance: BigInt(amount.toString()),
|
|
9373
|
+
useGasCoin: true,
|
|
9374
|
+
type: fromCoinType
|
|
9375
|
+
});
|
|
9376
|
+
let deepCoin;
|
|
9377
|
+
if (payDeepFeeAmount && payDeepFeeAmount > 0) {
|
|
9378
|
+
deepCoin = coinWithBalance({
|
|
9379
|
+
balance: BigInt(payDeepFeeAmount),
|
|
9380
|
+
type: this.deepbookv3DeepFeeType()
|
|
9244
9381
|
});
|
|
9245
|
-
|
|
9246
|
-
|
|
9247
|
-
|
|
9248
|
-
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
|
|
9255
|
-
|
|
9256
|
-
|
|
9257
|
-
|
|
9258
|
-
|
|
9259
|
-
|
|
9260
|
-
|
|
9261
|
-
if (CoinUtils.isSuiCoin(targetCoinType)) {
|
|
9262
|
-
txb.mergeCoins(txb.gas, [targetCoin]);
|
|
9382
|
+
}
|
|
9383
|
+
const routerSwapParams = {
|
|
9384
|
+
router,
|
|
9385
|
+
inputCoin,
|
|
9386
|
+
slippage,
|
|
9387
|
+
txb,
|
|
9388
|
+
partner: partner ?? this.partner,
|
|
9389
|
+
deepbookv3DeepFee: deepCoin
|
|
9390
|
+
};
|
|
9391
|
+
const targetCoin = await this.routerSwap(routerSwapParams);
|
|
9392
|
+
if (CoinUtils.isSuiCoin(targetCoinType)) {
|
|
9393
|
+
txb.mergeCoins(txb.gas, [targetCoin]);
|
|
9394
|
+
} else {
|
|
9395
|
+
const targetCoinObjID = await this.getOneCoinUsedToMerge(targetCoinType);
|
|
9396
|
+
if (targetCoinObjID != null) {
|
|
9397
|
+
txb.mergeCoins(txb.object(targetCoinObjID), [targetCoin]);
|
|
9263
9398
|
} else {
|
|
9264
|
-
|
|
9265
|
-
|
|
9266
|
-
|
|
9267
|
-
|
|
9268
|
-
|
|
9269
|
-
|
|
9270
|
-
|
|
9271
|
-
|
|
9272
|
-
packages: router.packages
|
|
9273
|
-
},
|
|
9274
|
-
txb
|
|
9275
|
-
);
|
|
9276
|
-
}
|
|
9277
|
-
}
|
|
9278
|
-
});
|
|
9279
|
-
}
|
|
9280
|
-
mergeSwap(params) {
|
|
9281
|
-
return __async(this, null, function* () {
|
|
9282
|
-
const { router, inputCoins, slippage, txb, partner } = params;
|
|
9283
|
-
if (slippage > 1 || slippage < 0) {
|
|
9284
|
-
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
|
|
9285
|
-
}
|
|
9286
|
-
if (!router.packages || !router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
9287
|
-
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
9288
|
-
}
|
|
9289
|
-
if (!router.allRoutes || router.allRoutes.length === 0) {
|
|
9290
|
-
throw new Error("No routes found in merge swap response");
|
|
9291
|
-
}
|
|
9292
|
-
const outputCoins = [];
|
|
9293
|
-
for (let i = 0; i < router.allRoutes.length && i < inputCoins.length; i++) {
|
|
9294
|
-
const route = router.allRoutes[i];
|
|
9295
|
-
const inputCoin = inputCoins[i];
|
|
9296
|
-
const routeRouter = {
|
|
9297
|
-
quoteID: router.quoteID,
|
|
9298
|
-
amountIn: route.amountIn,
|
|
9299
|
-
amountOut: route.amountOut,
|
|
9300
|
-
deviationRatio: Number(route.deviationRatio),
|
|
9301
|
-
byAmountIn: true,
|
|
9302
|
-
// Merge swap is always by amount in
|
|
9303
|
-
paths: route.paths,
|
|
9304
|
-
insufficientLiquidity: false,
|
|
9305
|
-
packages: router.packages
|
|
9306
|
-
};
|
|
9307
|
-
const routerParams = {
|
|
9308
|
-
router: routeRouter,
|
|
9309
|
-
inputCoin: inputCoin.coin,
|
|
9310
|
-
slippage,
|
|
9311
|
-
txb,
|
|
9312
|
-
partner: partner != null ? partner : this.partner
|
|
9313
|
-
};
|
|
9314
|
-
const outputCoin = yield this.routerSwap(routerParams);
|
|
9315
|
-
outputCoins.push(outputCoin);
|
|
9316
|
-
}
|
|
9317
|
-
if (outputCoins.length === 0) {
|
|
9318
|
-
throw new Error("No output coins generated from merge swap");
|
|
9319
|
-
}
|
|
9320
|
-
let finalOutputCoin = outputCoins[0];
|
|
9321
|
-
if (outputCoins.length > 1) {
|
|
9322
|
-
txb.mergeCoins(finalOutputCoin, outputCoins.slice(1));
|
|
9399
|
+
transferOrDestroyCoin(
|
|
9400
|
+
{
|
|
9401
|
+
coin: targetCoin,
|
|
9402
|
+
coinType: targetCoinType,
|
|
9403
|
+
packages: router.packages
|
|
9404
|
+
},
|
|
9405
|
+
txb
|
|
9406
|
+
);
|
|
9323
9407
|
}
|
|
9324
|
-
|
|
9325
|
-
});
|
|
9408
|
+
}
|
|
9326
9409
|
}
|
|
9327
|
-
|
|
9328
|
-
|
|
9329
|
-
|
|
9330
|
-
|
|
9331
|
-
|
|
9332
|
-
|
|
9333
|
-
|
|
9334
|
-
|
|
9335
|
-
|
|
9336
|
-
|
|
9337
|
-
|
|
9338
|
-
|
|
9339
|
-
|
|
9340
|
-
|
|
9341
|
-
|
|
9342
|
-
|
|
9343
|
-
|
|
9344
|
-
|
|
9345
|
-
|
|
9346
|
-
|
|
9347
|
-
|
|
9348
|
-
|
|
9349
|
-
|
|
9350
|
-
|
|
9351
|
-
router
|
|
9352
|
-
|
|
9410
|
+
async mergeSwap(params) {
|
|
9411
|
+
const { router, inputCoins, slippage, txb, partner } = params;
|
|
9412
|
+
if (slippage > 1 || slippage < 0) {
|
|
9413
|
+
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
|
|
9414
|
+
}
|
|
9415
|
+
if (!router.packages || !router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
9416
|
+
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
9417
|
+
}
|
|
9418
|
+
if (!router.allRoutes || router.allRoutes.length === 0) {
|
|
9419
|
+
throw new Error("No routes found in merge swap response");
|
|
9420
|
+
}
|
|
9421
|
+
const outputCoins = [];
|
|
9422
|
+
for (let i = 0; i < router.allRoutes.length && i < inputCoins.length; i++) {
|
|
9423
|
+
const route = router.allRoutes[i];
|
|
9424
|
+
const inputCoin = inputCoins[i];
|
|
9425
|
+
const routeRouter = {
|
|
9426
|
+
quoteID: router.quoteID,
|
|
9427
|
+
amountIn: route.amountIn,
|
|
9428
|
+
amountOut: route.amountOut,
|
|
9429
|
+
deviationRatio: Number(route.deviationRatio),
|
|
9430
|
+
byAmountIn: true,
|
|
9431
|
+
// Merge swap is always by amount in
|
|
9432
|
+
paths: route.paths,
|
|
9433
|
+
insufficientLiquidity: false,
|
|
9434
|
+
packages: router.packages
|
|
9435
|
+
};
|
|
9436
|
+
const routerParams = {
|
|
9437
|
+
router: routeRouter,
|
|
9438
|
+
inputCoin: inputCoin.coin,
|
|
9353
9439
|
slippage,
|
|
9354
9440
|
txb,
|
|
9355
|
-
partner: partner
|
|
9356
|
-
};
|
|
9357
|
-
const
|
|
9358
|
-
|
|
9359
|
-
|
|
9360
|
-
|
|
9361
|
-
|
|
9362
|
-
|
|
9363
|
-
|
|
9364
|
-
|
|
9365
|
-
|
|
9366
|
-
|
|
9367
|
-
|
|
9368
|
-
|
|
9369
|
-
|
|
9370
|
-
|
|
9371
|
-
|
|
9372
|
-
|
|
9373
|
-
|
|
9374
|
-
|
|
9375
|
-
|
|
9376
|
-
|
|
9377
|
-
|
|
9378
|
-
|
|
9379
|
-
const
|
|
9380
|
-
|
|
9381
|
-
|
|
9382
|
-
|
|
9383
|
-
|
|
9384
|
-
|
|
9385
|
-
)
|
|
9441
|
+
partner: partner ?? this.partner
|
|
9442
|
+
};
|
|
9443
|
+
const outputCoin = await this.routerSwap(routerParams);
|
|
9444
|
+
outputCoins.push(outputCoin);
|
|
9445
|
+
}
|
|
9446
|
+
if (outputCoins.length === 0) {
|
|
9447
|
+
throw new Error("No output coins generated from merge swap");
|
|
9448
|
+
}
|
|
9449
|
+
let finalOutputCoin = outputCoins[0];
|
|
9450
|
+
if (outputCoins.length > 1) {
|
|
9451
|
+
txb.mergeCoins(finalOutputCoin, outputCoins.slice(1));
|
|
9452
|
+
}
|
|
9453
|
+
return finalOutputCoin;
|
|
9454
|
+
}
|
|
9455
|
+
async fastMergeSwap(params) {
|
|
9456
|
+
const { router, slippage, txb, partner } = params;
|
|
9457
|
+
if (!router || !router.allRoutes || router.allRoutes.length === 0) {
|
|
9458
|
+
throw new Error("Invalid router: no routes found");
|
|
9459
|
+
}
|
|
9460
|
+
const firstRoute = router.allRoutes[0];
|
|
9461
|
+
const targetCoinType = firstRoute.paths[firstRoute.paths.length - 1].target;
|
|
9462
|
+
const inputCoins = [];
|
|
9463
|
+
const coinTypeSet = /* @__PURE__ */ new Set();
|
|
9464
|
+
for (const route of router.allRoutes) {
|
|
9465
|
+
const firstCoinType = route.paths[0].from;
|
|
9466
|
+
if (coinTypeSet.has(firstCoinType)) {
|
|
9467
|
+
continue;
|
|
9468
|
+
}
|
|
9469
|
+
coinTypeSet.add(firstCoinType);
|
|
9470
|
+
const coin = coinWithBalance({
|
|
9471
|
+
balance: BigInt(route.amountIn.toString()),
|
|
9472
|
+
useGasCoin: CoinUtils.isSuiCoin(firstCoinType),
|
|
9473
|
+
type: firstCoinType
|
|
9474
|
+
});
|
|
9475
|
+
inputCoins.push({ coinType: firstCoinType, coin });
|
|
9476
|
+
}
|
|
9477
|
+
const mergeSwapParams = {
|
|
9478
|
+
router,
|
|
9479
|
+
inputCoins,
|
|
9480
|
+
slippage,
|
|
9481
|
+
txb,
|
|
9482
|
+
partner: partner ?? this.partner
|
|
9483
|
+
};
|
|
9484
|
+
const targetCoin = await this.mergeSwap(mergeSwapParams);
|
|
9485
|
+
if (CoinUtils.isSuiCoin(targetCoinType)) {
|
|
9486
|
+
txb.mergeCoins(txb.gas, [targetCoin]);
|
|
9487
|
+
} else {
|
|
9488
|
+
const targetCoinObjID = await this.getOneCoinUsedToMerge(targetCoinType);
|
|
9489
|
+
if (targetCoinObjID != null) {
|
|
9490
|
+
txb.mergeCoins(txb.object(targetCoinObjID), [targetCoin]);
|
|
9386
9491
|
} else {
|
|
9387
|
-
|
|
9388
|
-
|
|
9492
|
+
transferOrDestroyCoin(
|
|
9493
|
+
{
|
|
9494
|
+
coin: targetCoin,
|
|
9495
|
+
coinType: targetCoinType,
|
|
9496
|
+
packages: router.packages
|
|
9497
|
+
},
|
|
9498
|
+
txb
|
|
9389
9499
|
);
|
|
9390
9500
|
}
|
|
9391
|
-
|
|
9392
|
-
|
|
9393
|
-
|
|
9394
|
-
|
|
9395
|
-
|
|
9396
|
-
|
|
9501
|
+
}
|
|
9502
|
+
}
|
|
9503
|
+
async fixableRouterSwapV3(params) {
|
|
9504
|
+
const { router, inputCoin, slippage, txb, partner } = params;
|
|
9505
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
9506
|
+
let overlayFee = 0;
|
|
9507
|
+
if (router.byAmountIn) {
|
|
9508
|
+
overlayFee = Number(
|
|
9509
|
+
router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
9397
9510
|
);
|
|
9398
|
-
|
|
9399
|
-
|
|
9400
|
-
|
|
9401
|
-
|
|
9402
|
-
|
|
9403
|
-
|
|
9404
|
-
|
|
9405
|
-
|
|
9406
|
-
|
|
9407
|
-
|
|
9408
|
-
|
|
9409
|
-
|
|
9410
|
-
|
|
9411
|
-
|
|
9412
|
-
|
|
9413
|
-
|
|
9414
|
-
|
|
9415
|
-
|
|
9416
|
-
|
|
9417
|
-
|
|
9418
|
-
)
|
|
9419
|
-
|
|
9420
|
-
|
|
9511
|
+
} else {
|
|
9512
|
+
overlayFee = Number(
|
|
9513
|
+
router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
9514
|
+
);
|
|
9515
|
+
}
|
|
9516
|
+
const expectedAmountOut = router.byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
|
|
9517
|
+
const expectedAmountIn = router.byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
|
|
9518
|
+
const amountLimit = CalculateAmountLimitBN(
|
|
9519
|
+
router.byAmountIn ? expectedAmountOut : expectedAmountIn,
|
|
9520
|
+
router.byAmountIn,
|
|
9521
|
+
slippage
|
|
9522
|
+
);
|
|
9523
|
+
const priceIDs = findPythPriceIDs(router.paths);
|
|
9524
|
+
const priceInfoObjectIds = priceIDs.length > 0 ? await this.updatePythPriceIDs(priceIDs, txb) : /* @__PURE__ */ new Map();
|
|
9525
|
+
if (router.byAmountIn) {
|
|
9526
|
+
return this.expectInputSwapV3(
|
|
9527
|
+
txb,
|
|
9528
|
+
inputCoin,
|
|
9529
|
+
router,
|
|
9530
|
+
expectedAmountOut.toString(),
|
|
9531
|
+
amountLimit.toString(),
|
|
9532
|
+
priceInfoObjectIds,
|
|
9533
|
+
partner ?? this.partner
|
|
9534
|
+
);
|
|
9535
|
+
} else {
|
|
9536
|
+
return this.expectOutputSwapV3(
|
|
9537
|
+
txb,
|
|
9538
|
+
inputCoin,
|
|
9539
|
+
router,
|
|
9540
|
+
expectedAmountOut.toString(),
|
|
9541
|
+
amountLimit.toString(),
|
|
9542
|
+
partner ?? this.partner
|
|
9543
|
+
);
|
|
9544
|
+
}
|
|
9421
9545
|
}
|
|
9422
|
-
swapInPools(params) {
|
|
9423
|
-
|
|
9424
|
-
|
|
9425
|
-
|
|
9426
|
-
|
|
9427
|
-
|
|
9428
|
-
|
|
9429
|
-
|
|
9430
|
-
|
|
9431
|
-
|
|
9432
|
-
|
|
9433
|
-
const
|
|
9434
|
-
|
|
9435
|
-
|
|
9436
|
-
|
|
9437
|
-
|
|
9438
|
-
|
|
9439
|
-
|
|
9440
|
-
|
|
9441
|
-
|
|
9442
|
-
|
|
9443
|
-
arguments: args,
|
|
9444
|
-
typeArguments
|
|
9445
|
-
});
|
|
9446
|
-
}
|
|
9447
|
-
if (!this.signer) {
|
|
9448
|
-
this.signer = "0x0";
|
|
9449
|
-
}
|
|
9450
|
-
const simulateRes = yield this.client.devInspectTransactionBlock({
|
|
9451
|
-
transactionBlock: tx,
|
|
9452
|
-
sender: this.signer
|
|
9453
|
-
});
|
|
9454
|
-
if (simulateRes.error != null) {
|
|
9455
|
-
throw new Error("Simulation error: " + simulateRes.error);
|
|
9456
|
-
}
|
|
9457
|
-
const valueData = (_a = simulateRes.events) == null ? void 0 : _a.filter((item) => {
|
|
9458
|
-
return item.type.includes("CalculatedSwapResultEvent");
|
|
9546
|
+
async swapInPools(params) {
|
|
9547
|
+
const { from, target, amount, byAmountIn, pools } = params;
|
|
9548
|
+
const fromCoin = completionCoin(from);
|
|
9549
|
+
const targetCoin = completionCoin(target);
|
|
9550
|
+
const tx = new Transaction();
|
|
9551
|
+
const direction = compareCoins(fromCoin, targetCoin);
|
|
9552
|
+
const coinA = direction ? fromCoin : targetCoin;
|
|
9553
|
+
const coinB = direction ? targetCoin : fromCoin;
|
|
9554
|
+
const typeArguments = [coinA, coinB];
|
|
9555
|
+
const integratePublishedAt = this.env === 0 /* Mainnet */ ? "0xfbb32ac0fa89a3cb0c56c745b688c6d2a53ac8e43447119ad822763997ffb9c3" : "0xab2d58dd28ff0dc19b18ab2c634397b785a38c342a8f5065ade5f53f9dbffa1c";
|
|
9556
|
+
for (let i = 0; i < pools.length; i++) {
|
|
9557
|
+
const args = [
|
|
9558
|
+
tx.object(pools[i]),
|
|
9559
|
+
tx.pure.bool(direction),
|
|
9560
|
+
tx.pure.bool(byAmountIn),
|
|
9561
|
+
tx.pure.u64(amount.toString())
|
|
9562
|
+
];
|
|
9563
|
+
tx.moveCall({
|
|
9564
|
+
target: `${integratePublishedAt}::fetcher_script::calculate_swap_result`,
|
|
9565
|
+
arguments: args,
|
|
9566
|
+
typeArguments
|
|
9459
9567
|
});
|
|
9460
|
-
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
|
|
9464
|
-
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
|
|
9472
|
-
|
|
9473
|
-
|
|
9474
|
-
|
|
9475
|
-
|
|
9476
|
-
|
|
9477
|
-
|
|
9478
|
-
|
|
9479
|
-
|
|
9480
|
-
|
|
9568
|
+
}
|
|
9569
|
+
tx.setSenderIfNotSet(this.signer || "0x0");
|
|
9570
|
+
const simulateRes = await this.client.simulateTransaction({
|
|
9571
|
+
transaction: tx,
|
|
9572
|
+
include: { events: true, effects: true }
|
|
9573
|
+
});
|
|
9574
|
+
const txResult = simulateRes.Transaction ?? simulateRes.FailedTransaction;
|
|
9575
|
+
if (!txResult || simulateRes.$kind === "FailedTransaction") {
|
|
9576
|
+
const errorMsg = txResult?.status.success === false ? txResult.status.error.message : "Unknown error";
|
|
9577
|
+
throw new Error("Simulation error: " + errorMsg);
|
|
9578
|
+
}
|
|
9579
|
+
const events = txResult.events ?? [];
|
|
9580
|
+
const valueData = events.filter((item) => {
|
|
9581
|
+
return item.eventType.includes("CalculatedSwapResultEvent");
|
|
9582
|
+
});
|
|
9583
|
+
if (valueData.length === 0 || valueData.length !== pools.length) {
|
|
9584
|
+
throw new Error("Simulate event result error");
|
|
9585
|
+
}
|
|
9586
|
+
let tempMaxAmount = byAmountIn ? new import_bn6.default(0) : new import_bn6.default(U64_MAX);
|
|
9587
|
+
let tempIndex = 0;
|
|
9588
|
+
for (let i = 0; i < valueData.length; i += 1) {
|
|
9589
|
+
const eventJson2 = valueData[i].json;
|
|
9590
|
+
if (eventJson2?.data?.is_exceed) {
|
|
9591
|
+
continue;
|
|
9592
|
+
}
|
|
9593
|
+
if (params.byAmountIn) {
|
|
9594
|
+
const amount2 = new import_bn6.default(eventJson2?.data?.amount_out ?? 0);
|
|
9595
|
+
if (amount2.gt(tempMaxAmount)) {
|
|
9596
|
+
tempIndex = i;
|
|
9597
|
+
tempMaxAmount = amount2;
|
|
9598
|
+
}
|
|
9599
|
+
} else {
|
|
9600
|
+
const amount2 = new import_bn6.default(eventJson2?.data?.amount_out ?? 0);
|
|
9601
|
+
if (amount2.lt(tempMaxAmount)) {
|
|
9602
|
+
tempIndex = i;
|
|
9603
|
+
tempMaxAmount = amount2;
|
|
9481
9604
|
}
|
|
9482
9605
|
}
|
|
9483
|
-
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
9492
|
-
|
|
9493
|
-
|
|
9494
|
-
|
|
9495
|
-
|
|
9496
|
-
|
|
9497
|
-
|
|
9498
|
-
|
|
9499
|
-
|
|
9500
|
-
|
|
9501
|
-
|
|
9502
|
-
|
|
9503
|
-
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
|
|
9508
|
-
|
|
9509
|
-
|
|
9510
|
-
|
|
9511
|
-
|
|
9512
|
-
|
|
9513
|
-
|
|
9514
|
-
|
|
9606
|
+
}
|
|
9607
|
+
const eventJson = valueData[tempIndex].json;
|
|
9608
|
+
const eventData = eventJson?.data;
|
|
9609
|
+
const [decimalA, decimalB] = await Promise.all([
|
|
9610
|
+
this.client.getCoinMetadata({ coinType: coinA }).then((res) => res.coinMetadata?.decimals ?? null),
|
|
9611
|
+
this.client.getCoinMetadata({ coinType: coinB }).then((res) => res.coinMetadata?.decimals ?? null)
|
|
9612
|
+
]);
|
|
9613
|
+
if (decimalA == null || decimalB == null) {
|
|
9614
|
+
throw new Error("Cannot get coin decimals");
|
|
9615
|
+
}
|
|
9616
|
+
const feeRate = Number(eventData?.fee_rate ?? 0) / 1e6;
|
|
9617
|
+
const pureAmountIn = new import_bn6.default(eventData?.amount_in ?? 0);
|
|
9618
|
+
const feeAmount = new import_bn6.default(eventData?.fee_amount ?? 0);
|
|
9619
|
+
const amountIn = pureAmountIn.add(feeAmount);
|
|
9620
|
+
const cetusRouterV3PublishedAt = this.env === 0 /* Mainnet */ ? MAINNET_CETUS_V3_PUBLISHED_AT : TESTNET_CETUS_V3_PUBLISHED_AT;
|
|
9621
|
+
const aggregatorV3PublishedAt = this.env === 0 /* Mainnet */ ? AGGREGATOR_V3_CONFIG.DEFAULT_PUBLISHED_AT.Mainnet : AGGREGATOR_V3_CONFIG.DEFAULT_PUBLISHED_AT.Testnet;
|
|
9622
|
+
const routeData = {
|
|
9623
|
+
amountIn,
|
|
9624
|
+
amountOut: new import_bn6.default(eventData?.amount_out ?? 0),
|
|
9625
|
+
deviationRatio: 0,
|
|
9626
|
+
paths: [
|
|
9627
|
+
{
|
|
9628
|
+
id: pools[tempIndex],
|
|
9629
|
+
direction,
|
|
9630
|
+
provider: CETUS,
|
|
9631
|
+
from: fromCoin,
|
|
9632
|
+
target: targetCoin,
|
|
9633
|
+
feeRate,
|
|
9634
|
+
amountIn: amountIn.toString(),
|
|
9635
|
+
amountOut: eventData?.amount_out ?? "0",
|
|
9636
|
+
publishedAt: cetusRouterV3PublishedAt,
|
|
9637
|
+
extendedDetails: {
|
|
9638
|
+
afterSqrtPrice: eventData?.after_sqrt_price
|
|
9515
9639
|
}
|
|
9516
|
-
],
|
|
9517
|
-
insufficientLiquidity: false,
|
|
9518
|
-
byAmountIn: params.byAmountIn,
|
|
9519
|
-
quoteID: `degraded-${generateUUID()}`,
|
|
9520
|
-
packages: /* @__PURE__ */ new Map([
|
|
9521
|
-
[
|
|
9522
|
-
PACKAGE_NAMES.AGGREGATOR_V3,
|
|
9523
|
-
aggregatorV3PublishedAt
|
|
9524
|
-
]
|
|
9525
|
-
])
|
|
9526
|
-
};
|
|
9527
|
-
const result = {
|
|
9528
|
-
isExceed: event.is_exceed,
|
|
9529
|
-
routeData
|
|
9530
|
-
};
|
|
9531
|
-
return result;
|
|
9532
|
-
});
|
|
9533
|
-
}
|
|
9534
|
-
updatePythPriceIDs(priceIDs, txb) {
|
|
9535
|
-
return __async(this, null, function* () {
|
|
9536
|
-
let priceUpdateData = null;
|
|
9537
|
-
let lastError = null;
|
|
9538
|
-
for (const connection of this.pythConnections) {
|
|
9539
|
-
try {
|
|
9540
|
-
priceUpdateData = yield connection.getPriceFeedsUpdateData(priceIDs);
|
|
9541
|
-
break;
|
|
9542
|
-
} catch (e) {
|
|
9543
|
-
lastError = e;
|
|
9544
|
-
console.log("Error: ", e);
|
|
9545
|
-
continue;
|
|
9546
9640
|
}
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
|
|
9550
|
-
|
|
9551
|
-
|
|
9552
|
-
|
|
9553
|
-
|
|
9554
|
-
|
|
9555
|
-
|
|
9556
|
-
|
|
9557
|
-
|
|
9558
|
-
|
|
9559
|
-
|
|
9560
|
-
|
|
9561
|
-
|
|
9562
|
-
|
|
9563
|
-
);
|
|
9564
|
-
}
|
|
9565
|
-
let priceInfoObjectIdsMap = /* @__PURE__ */ new Map();
|
|
9566
|
-
for (let i = 0; i < priceIDs.length; i++) {
|
|
9567
|
-
priceInfoObjectIdsMap.set(priceIDs[i], priceInfoObjectIds[i]);
|
|
9568
|
-
}
|
|
9569
|
-
return priceInfoObjectIdsMap;
|
|
9570
|
-
});
|
|
9641
|
+
],
|
|
9642
|
+
insufficientLiquidity: false,
|
|
9643
|
+
byAmountIn: params.byAmountIn,
|
|
9644
|
+
quoteID: `degraded-${generateUUID()}`,
|
|
9645
|
+
packages: /* @__PURE__ */ new Map([
|
|
9646
|
+
[
|
|
9647
|
+
PACKAGE_NAMES.AGGREGATOR_V3,
|
|
9648
|
+
aggregatorV3PublishedAt
|
|
9649
|
+
]
|
|
9650
|
+
])
|
|
9651
|
+
};
|
|
9652
|
+
const result = {
|
|
9653
|
+
isExceed: eventData?.is_exceed ?? false,
|
|
9654
|
+
routeData
|
|
9655
|
+
};
|
|
9656
|
+
return result;
|
|
9571
9657
|
}
|
|
9572
|
-
|
|
9573
|
-
|
|
9574
|
-
|
|
9575
|
-
|
|
9576
|
-
|
|
9577
|
-
|
|
9578
|
-
|
|
9658
|
+
async updatePythPriceIDs(priceIDs, txb) {
|
|
9659
|
+
const priceUpdateData = await this.pythAdapter.getPriceFeedsUpdateData(priceIDs);
|
|
9660
|
+
let priceInfoObjectIds;
|
|
9661
|
+
try {
|
|
9662
|
+
priceInfoObjectIds = await this.pythAdapter.updatePriceFeeds(
|
|
9663
|
+
txb,
|
|
9664
|
+
priceUpdateData,
|
|
9665
|
+
priceIDs
|
|
9666
|
+
);
|
|
9667
|
+
} catch (e) {
|
|
9668
|
+
throw new Error(
|
|
9669
|
+
`Failed to update Pyth price feeds. Ensure pythUrls are configured correctly. Detailed error: ${e}`
|
|
9670
|
+
);
|
|
9671
|
+
}
|
|
9672
|
+
const priceInfoObjectIdsMap = /* @__PURE__ */ new Map();
|
|
9673
|
+
for (let i = 0; i < priceIDs.length; i++) {
|
|
9674
|
+
priceInfoObjectIdsMap.set(priceIDs[i], priceInfoObjectIds[i]);
|
|
9675
|
+
}
|
|
9676
|
+
return priceInfoObjectIdsMap;
|
|
9677
|
+
}
|
|
9678
|
+
async devInspectTransactionBlock(txb) {
|
|
9679
|
+
txb.setSenderIfNotSet(this.signer || "0x0");
|
|
9680
|
+
const res = await this.client.simulateTransaction({
|
|
9681
|
+
transaction: txb,
|
|
9682
|
+
include: { events: true, effects: true }
|
|
9579
9683
|
});
|
|
9684
|
+
return res;
|
|
9580
9685
|
}
|
|
9581
|
-
sendTransaction(txb, signer) {
|
|
9582
|
-
|
|
9583
|
-
|
|
9584
|
-
|
|
9585
|
-
|
|
9586
|
-
});
|
|
9587
|
-
return res;
|
|
9686
|
+
async sendTransaction(txb, signer) {
|
|
9687
|
+
const res = await this.client.signAndExecuteTransaction({
|
|
9688
|
+
transaction: txb,
|
|
9689
|
+
signer,
|
|
9690
|
+
include: { effects: true, events: true, balanceChanges: true }
|
|
9588
9691
|
});
|
|
9692
|
+
return res;
|
|
9589
9693
|
}
|
|
9590
9694
|
};
|
|
9591
9695
|
_AggregatorClient.CONFIG = {
|
|
@@ -9654,174 +9758,4 @@ decimal.js/decimal.mjs:
|
|
|
9654
9758
|
*)
|
|
9655
9759
|
*/
|
|
9656
9760
|
|
|
9657
|
-
|
|
9658
|
-
exports.AFTERMATH = AFTERMATH;
|
|
9659
|
-
exports.AFTERMATH_AMM = AFTERMATH_AMM;
|
|
9660
|
-
exports.AFTERMATH_MODULE = AFTERMATH_MODULE;
|
|
9661
|
-
exports.AGGREGATOR = AGGREGATOR;
|
|
9662
|
-
exports.AGGREGATOR_V3_CONFIG = AGGREGATOR_V3_CONFIG;
|
|
9663
|
-
exports.ALL_DEXES = ALL_DEXES;
|
|
9664
|
-
exports.ALPHAFI = ALPHAFI;
|
|
9665
|
-
exports.AggregatorClient = AggregatorClient;
|
|
9666
|
-
exports.AggregatorConfig = AggregatorConfig;
|
|
9667
|
-
exports.AggregatorError = AggregatorError;
|
|
9668
|
-
exports.AggregatorServerErrorCode = AggregatorServerErrorCode;
|
|
9669
|
-
exports.BLUEFIN = BLUEFIN;
|
|
9670
|
-
exports.BLUEMOVE = BLUEMOVE;
|
|
9671
|
-
exports.CETUS = CETUS;
|
|
9672
|
-
exports.CETUSDLMM = CETUSDLMM;
|
|
9673
|
-
exports.CETUS_DEX = CETUS_DEX;
|
|
9674
|
-
exports.CETUS_MODULE = CETUS_MODULE;
|
|
9675
|
-
exports.CETUS_PUBLISHED_AT = CETUS_PUBLISHED_AT;
|
|
9676
|
-
exports.CHECK_COINS_THRESHOLD_FUNC = CHECK_COINS_THRESHOLD_FUNC;
|
|
9677
|
-
exports.CLIENT_CONFIG = CLIENT_CONFIG;
|
|
9678
|
-
exports.CLOCK_ADDRESS = CLOCK_ADDRESS;
|
|
9679
|
-
exports.CoinInfoAddress = CoinInfoAddress;
|
|
9680
|
-
exports.CoinStoreAddress = CoinStoreAddress;
|
|
9681
|
-
exports.CoinUtils = CoinUtils;
|
|
9682
|
-
exports.ConfigErrorCode = ConfigErrorCode;
|
|
9683
|
-
exports.DEEPBOOKV2 = DEEPBOOKV2;
|
|
9684
|
-
exports.DEEPBOOKV3 = DEEPBOOKV3;
|
|
9685
|
-
exports.DEEPBOOK_CLOB_V2_MODULE = DEEPBOOK_CLOB_V2_MODULE;
|
|
9686
|
-
exports.DEEPBOOK_CUSTODIAN_V2_MODULE = DEEPBOOK_CUSTODIAN_V2_MODULE;
|
|
9687
|
-
exports.DEEPBOOK_DEX = DEEPBOOK_DEX;
|
|
9688
|
-
exports.DEEPBOOK_MODULE = DEEPBOOK_MODULE;
|
|
9689
|
-
exports.DEEPBOOK_PACKAGE_ID = DEEPBOOK_PACKAGE_ID;
|
|
9690
|
-
exports.DEEPBOOK_PUBLISHED_AT = DEEPBOOK_PUBLISHED_AT;
|
|
9691
|
-
exports.DEEPBOOK_V3_DEEP_FEE_TYPES = DEEPBOOK_V3_DEEP_FEE_TYPES;
|
|
9692
|
-
exports.DEFAULT_AGG_V2_ENDPOINT = DEFAULT_AGG_V2_ENDPOINT;
|
|
9693
|
-
exports.DEFAULT_AGG_V3_ENDPOINT = DEFAULT_AGG_V3_ENDPOINT;
|
|
9694
|
-
exports.DEFAULT_ENDPOINT = DEFAULT_ENDPOINT;
|
|
9695
|
-
exports.DEFAULT_GAS_BUDGET_FOR_MERGE = DEFAULT_GAS_BUDGET_FOR_MERGE;
|
|
9696
|
-
exports.DEFAULT_GAS_BUDGET_FOR_SPLIT = DEFAULT_GAS_BUDGET_FOR_SPLIT;
|
|
9697
|
-
exports.DEFAULT_GAS_BUDGET_FOR_STAKE = DEFAULT_GAS_BUDGET_FOR_STAKE;
|
|
9698
|
-
exports.DEFAULT_GAS_BUDGET_FOR_TRANSFER = DEFAULT_GAS_BUDGET_FOR_TRANSFER;
|
|
9699
|
-
exports.DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI = DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI;
|
|
9700
|
-
exports.DEFAULT_NFT_TRANSFER_GAS_FEE = DEFAULT_NFT_TRANSFER_GAS_FEE;
|
|
9701
|
-
exports.Env = Env;
|
|
9702
|
-
exports.FERRACLMM = FERRACLMM;
|
|
9703
|
-
exports.FERRADLMM = FERRADLMM;
|
|
9704
|
-
exports.FLOWXV2 = FLOWXV2;
|
|
9705
|
-
exports.FLOWXV3 = FLOWXV3;
|
|
9706
|
-
exports.FLOWX_AMM = FLOWX_AMM;
|
|
9707
|
-
exports.FLOWX_AMM_MODULE = FLOWX_AMM_MODULE;
|
|
9708
|
-
exports.FULLSAIL = FULLSAIL;
|
|
9709
|
-
exports.FlashSwapA2BFunc = FlashSwapA2BFunc;
|
|
9710
|
-
exports.FlashSwapB2AFunc = FlashSwapB2AFunc;
|
|
9711
|
-
exports.FlashSwapFunc = FlashSwapFunc;
|
|
9712
|
-
exports.FlashSwapWithPartnerA2BFunc = FlashSwapWithPartnerA2BFunc;
|
|
9713
|
-
exports.FlashSwapWithPartnerB2AFunc = FlashSwapWithPartnerB2AFunc;
|
|
9714
|
-
exports.FlashSwapWithPartnerFunc = FlashSwapWithPartnerFunc;
|
|
9715
|
-
exports.GAS_SYMBOL = GAS_SYMBOL;
|
|
9716
|
-
exports.GAS_TYPE_ARG = GAS_TYPE_ARG;
|
|
9717
|
-
exports.GAS_TYPE_ARG_LONG = GAS_TYPE_ARG_LONG;
|
|
9718
|
-
exports.HAEDAL = HAEDAL;
|
|
9719
|
-
exports.HAEDALHMMV2 = HAEDALHMMV2;
|
|
9720
|
-
exports.HAEDALPMM = HAEDALPMM;
|
|
9721
|
-
exports.HAWAL = HAWAL;
|
|
9722
|
-
exports.INTEGRATE = INTEGRATE;
|
|
9723
|
-
exports.JOIN_FUNC = JOIN_FUNC;
|
|
9724
|
-
exports.KRIYA = KRIYA;
|
|
9725
|
-
exports.KRIYAV3 = KRIYAV3;
|
|
9726
|
-
exports.KRIYA_DEX = KRIYA_DEX;
|
|
9727
|
-
exports.KRIYA_MODULE = KRIYA_MODULE;
|
|
9728
|
-
exports.MAGMA = MAGMA;
|
|
9729
|
-
exports.MAINNET_AFTERMATH_INSURANCE_FUND_ID = MAINNET_AFTERMATH_INSURANCE_FUND_ID;
|
|
9730
|
-
exports.MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID = MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID;
|
|
9731
|
-
exports.MAINNET_AFTERMATH_REFERRAL_VAULT_ID = MAINNET_AFTERMATH_REFERRAL_VAULT_ID;
|
|
9732
|
-
exports.MAINNET_AFTERMATH_REGISTRY_ID = MAINNET_AFTERMATH_REGISTRY_ID;
|
|
9733
|
-
exports.MAINNET_AFTERMATH_TREASURY_ID = MAINNET_AFTERMATH_TREASURY_ID;
|
|
9734
|
-
exports.MAINNET_CETUS_V3_PUBLISHED_AT = MAINNET_CETUS_V3_PUBLISHED_AT;
|
|
9735
|
-
exports.MAINNET_FLOWX_AMM_CONTAINER_ID = MAINNET_FLOWX_AMM_CONTAINER_ID;
|
|
9736
|
-
exports.METASTABLE = METASTABLE;
|
|
9737
|
-
exports.MOMENTUM = MOMENTUM;
|
|
9738
|
-
exports.OBRIC = OBRIC;
|
|
9739
|
-
exports.ONE = ONE;
|
|
9740
|
-
exports.PACKAGE_NAMES = PACKAGE_NAMES;
|
|
9741
|
-
exports.PAY_MODULE = PAY_MODULE;
|
|
9742
|
-
exports.POOL_MODULT = POOL_MODULT;
|
|
9743
|
-
exports.PUBLISHED_ADDRESSES = PUBLISHED_ADDRESSES;
|
|
9744
|
-
exports.PYTH_CONFIG = PYTH_CONFIG;
|
|
9745
|
-
exports.REPAY_FLASH_SWAP_A2B_FUNC = REPAY_FLASH_SWAP_A2B_FUNC;
|
|
9746
|
-
exports.REPAY_FLASH_SWAP_B2A_FUNC = REPAY_FLASH_SWAP_B2A_FUNC;
|
|
9747
|
-
exports.REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC = REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC;
|
|
9748
|
-
exports.REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC = REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC;
|
|
9749
|
-
exports.RepayFalshSwapFunc = RepayFalshSwapFunc;
|
|
9750
|
-
exports.RepayFlashSwapWithPartnerFunc = RepayFlashSwapWithPartnerFunc;
|
|
9751
|
-
exports.SCALLOP = SCALLOP;
|
|
9752
|
-
exports.SEVENK = SEVENK;
|
|
9753
|
-
exports.SPRINGSUI = SPRINGSUI;
|
|
9754
|
-
exports.STEAMM = STEAMM;
|
|
9755
|
-
exports.STEAMM_OMM = STEAMM_OMM;
|
|
9756
|
-
exports.STEAMM_OMM_V2 = STEAMM_OMM_V2;
|
|
9757
|
-
exports.SUILEND = SUILEND;
|
|
9758
|
-
exports.SUI_SYSTEM_STATE_OBJECT_ID = SUI_SYSTEM_STATE_OBJECT_ID;
|
|
9759
|
-
exports.SWAP_A2B_FUNC = SWAP_A2B_FUNC;
|
|
9760
|
-
exports.SWAP_B2A_FUNC = SWAP_B2A_FUNC;
|
|
9761
|
-
exports.SuiZeroCoinFn = SuiZeroCoinFn;
|
|
9762
|
-
exports.TEN_POW_NINE = TEN_POW_NINE;
|
|
9763
|
-
exports.TESTNET_AFTERMATH_INSURANCE_FUND_ID = TESTNET_AFTERMATH_INSURANCE_FUND_ID;
|
|
9764
|
-
exports.TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID = TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID;
|
|
9765
|
-
exports.TESTNET_AFTERMATH_REFERRAL_VAULT_ID = TESTNET_AFTERMATH_REFERRAL_VAULT_ID;
|
|
9766
|
-
exports.TESTNET_AFTERMATH_REGISTRY_ID = TESTNET_AFTERMATH_REGISTRY_ID;
|
|
9767
|
-
exports.TESTNET_AFTERMATH_TREASURY_ID = TESTNET_AFTERMATH_TREASURY_ID;
|
|
9768
|
-
exports.TESTNET_CETUS_V3_PUBLISHED_AT = TESTNET_CETUS_V3_PUBLISHED_AT;
|
|
9769
|
-
exports.TESTNET_FLOWX_AMM_CONTAINER_ID = TESTNET_FLOWX_AMM_CONTAINER_ID;
|
|
9770
|
-
exports.TRANSFER_ACCOUNT_CAP = TRANSFER_ACCOUNT_CAP;
|
|
9771
|
-
exports.TRANSFER_OR_DESTORY_COIN_FUNC = TRANSFER_OR_DESTORY_COIN_FUNC;
|
|
9772
|
-
exports.TURBOS = TURBOS;
|
|
9773
|
-
exports.TURBOS_DEX = TURBOS_DEX;
|
|
9774
|
-
exports.TURBOS_MODULE = TURBOS_MODULE;
|
|
9775
|
-
exports.TURBOS_VERSIONED = TURBOS_VERSIONED;
|
|
9776
|
-
exports.TWO = TWO;
|
|
9777
|
-
exports.TransactionErrorCode = TransactionErrorCode;
|
|
9778
|
-
exports.TypesErrorCode = TypesErrorCode;
|
|
9779
|
-
exports.U128 = U128;
|
|
9780
|
-
exports.U64_MAX = U64_MAX;
|
|
9781
|
-
exports.U64_MAX_BN = U64_MAX_BN;
|
|
9782
|
-
exports.UTILS_MODULE = UTILS_MODULE;
|
|
9783
|
-
exports.VOLO = VOLO;
|
|
9784
|
-
exports.ZERO = ZERO;
|
|
9785
|
-
exports.buildInputCoin = buildInputCoin;
|
|
9786
|
-
exports.calculateGasEfficiency = calculateGasEfficiency;
|
|
9787
|
-
exports.calculatePriceImpact = calculatePriceImpact;
|
|
9788
|
-
exports.checkInvalidSuiAddress = checkInvalidSuiAddress;
|
|
9789
|
-
exports.compareCoins = compareCoins;
|
|
9790
|
-
exports.compareGasMetrics = compareGasMetrics;
|
|
9791
|
-
exports.completionCoin = completionCoin;
|
|
9792
|
-
exports.composeType = composeType;
|
|
9793
|
-
exports.createTarget = createTarget;
|
|
9794
|
-
exports.dealWithFastRouterSwapParamsForMsafe = dealWithFastRouterSwapParamsForMsafe;
|
|
9795
|
-
exports.exportToCSV = exportToCSV;
|
|
9796
|
-
exports.exportToJSON = exportToJSON;
|
|
9797
|
-
exports.extractAddressFromType = extractAddressFromType;
|
|
9798
|
-
exports.extractGasMetrics = extractGasMetrics;
|
|
9799
|
-
exports.extractStructTagFromType = extractStructTagFromType;
|
|
9800
|
-
exports.extractTimestampFromDowngradeUuid6 = extractTimestampFromDowngradeUuid6;
|
|
9801
|
-
exports.fixSuiObjectId = fixSuiObjectId;
|
|
9802
|
-
exports.formatGasMetrics = formatGasMetrics;
|
|
9803
|
-
exports.generateDowngradeUuid6 = generateDowngradeUuid6;
|
|
9804
|
-
exports.generateSimpleDowngradeUuid6 = generateSimpleDowngradeUuid6;
|
|
9805
|
-
exports.getAggregatorServerErrorMessage = getAggregatorServerErrorMessage;
|
|
9806
|
-
exports.getAggregatorV2Extend2PublishedAt = getAggregatorV2Extend2PublishedAt;
|
|
9807
|
-
exports.getAggregatorV2ExtendPublishedAt = getAggregatorV2ExtendPublishedAt;
|
|
9808
|
-
exports.getAggregatorV2PublishedAt = getAggregatorV2PublishedAt;
|
|
9809
|
-
exports.getAllProviders = getAllProviders;
|
|
9810
|
-
exports.getDeepbookV3Config = getDeepbookV3Config;
|
|
9811
|
-
exports.getDefaultSuiInputType = getDefaultSuiInputType;
|
|
9812
|
-
exports.getMergeSwapResult = getMergeSwapResult;
|
|
9813
|
-
exports.getOrCreateAccountCap = getOrCreateAccountCap;
|
|
9814
|
-
exports.getProvidersExcluding = getProvidersExcluding;
|
|
9815
|
-
exports.getProvidersIncluding = getProvidersIncluding;
|
|
9816
|
-
exports.getRouterResult = getRouterResult;
|
|
9817
|
-
exports.isSortedSymbols = isSortedSymbols;
|
|
9818
|
-
exports.isValidDowngradeUuid6 = isValidDowngradeUuid6;
|
|
9819
|
-
exports.mintZeroCoin = mintZeroCoin;
|
|
9820
|
-
exports.normalizeCoinType = normalizeCoinType;
|
|
9821
|
-
exports.parseAftermathFeeType = parseAftermathFeeType;
|
|
9822
|
-
exports.parseTurbosPoolFeeType = parseTurbosPoolFeeType;
|
|
9823
|
-
exports.patchFixSuiObjectId = patchFixSuiObjectId;
|
|
9824
|
-
exports.printTransaction = printTransaction;
|
|
9825
|
-
exports.processEndpoint = processEndpoint;
|
|
9826
|
-
exports.processFlattenRoutes = processFlattenRoutes;
|
|
9827
|
-
exports.restituteMsafeFastRouterSwapParams = restituteMsafeFastRouterSwapParams;
|
|
9761
|
+
export { AFSUI, AFTERMATH, AFTERMATH_AMM, AFTERMATH_MODULE, AGGREGATOR, AGGREGATOR_V3_CONFIG, ALL_DEXES, ALPHAFI, AggregatorClient, AggregatorConfig, AggregatorError, AggregatorServerErrorCode, BLUEFIN, BLUEMOVE, CETUS, CETUSDLMM, CETUS_DEX, CETUS_MODULE, CETUS_PUBLISHED_AT, CHECK_COINS_THRESHOLD_FUNC, CLIENT_CONFIG, CLOCK_ADDRESS, CoinInfoAddress, CoinStoreAddress, CoinUtils, ConfigErrorCode, DEEPBOOKV2, DEEPBOOKV3, DEEPBOOK_CLOB_V2_MODULE, DEEPBOOK_CUSTODIAN_V2_MODULE, DEEPBOOK_DEX, DEEPBOOK_MODULE, DEEPBOOK_PACKAGE_ID, DEEPBOOK_PUBLISHED_AT, DEEPBOOK_V3_DEEP_FEE_TYPES, DEFAULT_AGG_V2_ENDPOINT, DEFAULT_AGG_V3_ENDPOINT, DEFAULT_ENDPOINT, DEFAULT_GAS_BUDGET_FOR_MERGE, DEFAULT_GAS_BUDGET_FOR_SPLIT, DEFAULT_GAS_BUDGET_FOR_STAKE, DEFAULT_GAS_BUDGET_FOR_TRANSFER, DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI, DEFAULT_NFT_TRANSFER_GAS_FEE, Env, FERRACLMM, FERRADLMM, FLOWXV2, FLOWXV3, FLOWX_AMM, FLOWX_AMM_MODULE, FULLSAIL, FlashSwapA2BFunc, FlashSwapB2AFunc, FlashSwapFunc, FlashSwapWithPartnerA2BFunc, FlashSwapWithPartnerB2AFunc, FlashSwapWithPartnerFunc, GAS_SYMBOL, GAS_TYPE_ARG, GAS_TYPE_ARG_LONG, HAEDAL, HAEDALHMMV2, HAEDALPMM, HAWAL, INTEGRATE, JOIN_FUNC, KRIYA, KRIYAV3, KRIYA_DEX, KRIYA_MODULE, MAGMA, MAINNET_AFTERMATH_INSURANCE_FUND_ID, MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, MAINNET_AFTERMATH_REFERRAL_VAULT_ID, MAINNET_AFTERMATH_REGISTRY_ID, MAINNET_AFTERMATH_TREASURY_ID, MAINNET_CETUS_V3_PUBLISHED_AT, MAINNET_FLOWX_AMM_CONTAINER_ID, METASTABLE, MOMENTUM, OBRIC, ONE, PACKAGE_NAMES, PAY_MODULE, POOL_MODULT, PUBLISHED_ADDRESSES, PYTH_CONFIG, REPAY_FLASH_SWAP_A2B_FUNC, REPAY_FLASH_SWAP_B2A_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC, RepayFalshSwapFunc, RepayFlashSwapWithPartnerFunc, SCALLOP, SEVENK, SPRINGSUI, STEAMM, STEAMM_OMM, STEAMM_OMM_V2, SUILEND, SUI_SYSTEM_STATE_OBJECT_ID, SWAP_A2B_FUNC, SWAP_B2A_FUNC, SuiZeroCoinFn, TEN_POW_NINE, TESTNET_AFTERMATH_INSURANCE_FUND_ID, TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, TESTNET_AFTERMATH_REFERRAL_VAULT_ID, TESTNET_AFTERMATH_REGISTRY_ID, TESTNET_AFTERMATH_TREASURY_ID, TESTNET_CETUS_V3_PUBLISHED_AT, TESTNET_FLOWX_AMM_CONTAINER_ID, TRANSFER_ACCOUNT_CAP, TRANSFER_OR_DESTORY_COIN_FUNC, TURBOS, TURBOS_DEX, TURBOS_MODULE, TURBOS_VERSIONED, TWO, TransactionErrorCode, TypesErrorCode, U128, U64_MAX, U64_MAX_BN, UTILS_MODULE, VOLO, ZERO, buildInputCoin, calculateGasEfficiency, calculatePriceImpact, checkInvalidSuiAddress, compareCoins, compareGasMetrics, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, exportToCSV, exportToJSON, extractAddressFromType, extractGasMetrics, extractStructTagFromType, extractTimestampFromDowngradeUuid6, fixSuiObjectId, formatGasMetrics, generateDowngradeUuid6, generateSimpleDowngradeUuid6, getAggregatorServerErrorMessage, getAggregatorV2Extend2PublishedAt, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getAllProviders, getDeepbookV3Config, getDefaultSuiInputType, getMergeSwapResult, getOrCreateAccountCap, getProvidersExcluding, getProvidersIncluding, getRouterResult, isSortedSymbols, isValidDowngradeUuid6, mintZeroCoin, normalizeCoinType, parseAftermathFeeType, parseTurbosPoolFeeType, patchFixSuiObjectId, printTransaction, processEndpoint, processFlattenRoutes, restituteMsafeFastRouterSwapParams };
|