@cetusprotocol/aggregator-sdk 0.0.0-experimental-20250722120312 → 0.0.0-experimental-20250724183511
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +8 -197
- package/dist/index.d.ts +8 -197
- package/dist/index.js +258 -115
- package/dist/index.mjs +257 -86
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4995,36 +4995,36 @@ var Env = /* @__PURE__ */ ((Env2) => {
|
|
|
4995
4995
|
Env2[Env2["Testnet"] = 1] = "Testnet";
|
|
4996
4996
|
return Env2;
|
|
4997
4997
|
})(Env || {});
|
|
4998
|
-
var Dex = /* @__PURE__ */ ((
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
return
|
|
4998
|
+
var Dex = /* @__PURE__ */ ((Dex2) => {
|
|
4999
|
+
Dex2["CETUS"] = "CETUS";
|
|
5000
|
+
Dex2["KRIYA"] = "KRIYA";
|
|
5001
|
+
Dex2["FLOWX"] = "FLOWX";
|
|
5002
|
+
Dex2["TURBOS"] = "TURBOS";
|
|
5003
|
+
Dex2["AFTERMATH"] = "AFTERMATH";
|
|
5004
|
+
Dex2["DEEPBOOK"] = "DEEPBOOK";
|
|
5005
|
+
Dex2["DEEPBOOKV3"] = "DEEPBOOKV3";
|
|
5006
|
+
Dex2["BLUEMOVE"] = "BLUEMOVE";
|
|
5007
|
+
Dex2["BLUEFIN"] = "BLUEFIN";
|
|
5008
|
+
Dex2["MOMENTUM"] = "MOMENTUM";
|
|
5009
|
+
Dex2["MAGMA"] = "MAGMA";
|
|
5010
|
+
Dex2["SCALLOP"] = "SCALLOP";
|
|
5011
|
+
Dex2["STEAMM"] = "STEAMM";
|
|
5012
|
+
Dex2["KRIYAV3"] = "KRIYAV3";
|
|
5013
|
+
Dex2["FLOWXV3"] = "FLOWXV3";
|
|
5014
|
+
Dex2["SUILEND"] = "SUILEND";
|
|
5015
|
+
Dex2["SPRINGSUI"] = "SPRINGSUI";
|
|
5016
|
+
Dex2["HAEDALPMM"] = "HAEDALPMM";
|
|
5017
|
+
Dex2["OBRIC"] = "OBRIC";
|
|
5018
|
+
Dex2["SEVENK"] = "SEVENK";
|
|
5019
|
+
Dex2["STEAMM_OMM"] = "STEAMM_OMM";
|
|
5020
|
+
Dex2["STEAMM_OMM_V2"] = "STEAMM_OMM_V2";
|
|
5021
|
+
Dex2["METASTABLE"] = "METASTABLE";
|
|
5022
|
+
Dex2["ALPHAFI"] = "ALPHAFI";
|
|
5023
|
+
Dex2["VOLO"] = "VOLO";
|
|
5024
|
+
Dex2["AFSUI"] = "AFSUI";
|
|
5025
|
+
Dex2["HAEDAL"] = "HAEDAL";
|
|
5026
|
+
Dex2["HAWAL"] = "HAWAL";
|
|
5027
|
+
return Dex2;
|
|
5028
5028
|
})(Dex || {});
|
|
5029
5029
|
var AggregatorConfig = class {
|
|
5030
5030
|
constructor(endpoint, fullNodeUrl, signer, packages, env) {
|
|
@@ -5191,6 +5191,7 @@ var SuiZeroCoinFn = "0x2::coin::zero";
|
|
|
5191
5191
|
var DEEPBOOK_PACKAGE_ID = "0x000000000000000000000000000000000000000000000000000000000000dee9";
|
|
5192
5192
|
var DEEPBOOK_PUBLISHED_AT = "0x000000000000000000000000000000000000000000000000000000000000dee9";
|
|
5193
5193
|
var CETUS_PUBLISHED_AT = "0x70968826ad1b4ba895753f634b0aea68d0672908ca1075a2abdf0fc9e0b2fc6a";
|
|
5194
|
+
var CETUS_V3_PUBLISHED_AT = "0xb85d33ef69a8308f7b1ae341e48bd8817476c144f14344d3ce612c16480d16f2";
|
|
5194
5195
|
var MAINNET_CETUS_GLOBAL_CONFIG_ID = "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f";
|
|
5195
5196
|
var TESTNET_CETUS_GLOBAL_CONFIG_ID = "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
|
|
5196
5197
|
var MAINNET_FLOWX_AMM_CONTAINER_ID = "0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511";
|
|
@@ -5359,7 +5360,7 @@ var AGGREGATOR_V3_CONFIG = {
|
|
|
5359
5360
|
"SCALLOP",
|
|
5360
5361
|
"SUILEND",
|
|
5361
5362
|
"SPRINGSUI",
|
|
5362
|
-
// Phase 4: Oracle-driven Routers
|
|
5363
|
+
// Phase 4: Oracle-driven Routers
|
|
5363
5364
|
"HAEDALPMM",
|
|
5364
5365
|
"OBRIC",
|
|
5365
5366
|
"SEVENK",
|
|
@@ -6448,7 +6449,7 @@ function sortAndFlattenRoutes(routerData) {
|
|
|
6448
6449
|
lastOccurrenceIndex.set(from, i);
|
|
6449
6450
|
}
|
|
6450
6451
|
}
|
|
6451
|
-
for (const [
|
|
6452
|
+
for (const [_tokenType, lastIndex] of lastOccurrenceIndex) {
|
|
6452
6453
|
flattenedPaths[lastIndex].isLastUseOfIntermediateToken = true;
|
|
6453
6454
|
}
|
|
6454
6455
|
return {
|
|
@@ -6514,6 +6515,44 @@ function topologicalSortKahn(dependencies) {
|
|
|
6514
6515
|
return result;
|
|
6515
6516
|
}
|
|
6516
6517
|
|
|
6518
|
+
// src/utils/aggregator-config.ts
|
|
6519
|
+
var AggregatorConfig2 = class {
|
|
6520
|
+
static setEnv(env) {
|
|
6521
|
+
this.currentEnv = env;
|
|
6522
|
+
}
|
|
6523
|
+
static getEnv() {
|
|
6524
|
+
return this.currentEnv;
|
|
6525
|
+
}
|
|
6526
|
+
static getPublishedAtV2(env) {
|
|
6527
|
+
const targetEnv = env != null ? env : this.currentEnv;
|
|
6528
|
+
return this.publishedAtV2Map.get(targetEnv) || "";
|
|
6529
|
+
}
|
|
6530
|
+
static getPublishedAtV2Extend(env) {
|
|
6531
|
+
const targetEnv = env != null ? env : this.currentEnv;
|
|
6532
|
+
return this.publishedAtV2ExtendMap.get(targetEnv) || "";
|
|
6533
|
+
}
|
|
6534
|
+
static getPublishedAtV2Extend2(env) {
|
|
6535
|
+
const targetEnv = env != null ? env : this.currentEnv;
|
|
6536
|
+
return this.publishedAtV2Extend2Map.get(targetEnv) || "";
|
|
6537
|
+
}
|
|
6538
|
+
};
|
|
6539
|
+
AggregatorConfig2.publishedAtV2Map = /* @__PURE__ */ new Map([
|
|
6540
|
+
[0 /* Mainnet */, "0x8ae871505a80d8bf6bf9c05906cda6edfeea460c85bebe2e26a4313f5e67874a"],
|
|
6541
|
+
// version 12
|
|
6542
|
+
[1 /* Testnet */, "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934"]
|
|
6543
|
+
]);
|
|
6544
|
+
AggregatorConfig2.publishedAtV2ExtendMap = /* @__PURE__ */ new Map([
|
|
6545
|
+
[0 /* Mainnet */, "0x8a2f7a5b20665eeccc79de3aa37c3b6c473eca233ada1e1cd4678ec07d4d4073"],
|
|
6546
|
+
// version 17
|
|
6547
|
+
[1 /* Testnet */, "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78"]
|
|
6548
|
+
]);
|
|
6549
|
+
AggregatorConfig2.publishedAtV2Extend2Map = /* @__PURE__ */ new Map([
|
|
6550
|
+
[0 /* Mainnet */, "0x5cb7499fc49c2642310e24a4ecffdbee00133f97e80e2b45bca90c64d55de880"],
|
|
6551
|
+
// version 8
|
|
6552
|
+
[1 /* Testnet */, "0x0"]
|
|
6553
|
+
]);
|
|
6554
|
+
AggregatorConfig2.currentEnv = 0 /* Mainnet */;
|
|
6555
|
+
|
|
6517
6556
|
// src/transaction/aftermath.ts
|
|
6518
6557
|
var import_bn5 = __toESM(require_bn());
|
|
6519
6558
|
var Aftermath = class {
|
|
@@ -6554,7 +6593,7 @@ var Aftermath = class {
|
|
|
6554
6593
|
inputCoin
|
|
6555
6594
|
];
|
|
6556
6595
|
const publishedAt = getAggregatorV2PublishedAt(
|
|
6557
|
-
|
|
6596
|
+
AggregatorConfig2.getPublishedAtV2(),
|
|
6558
6597
|
packages
|
|
6559
6598
|
);
|
|
6560
6599
|
const res = txb.moveCall({
|
|
@@ -6878,21 +6917,29 @@ var Cetus = class {
|
|
|
6878
6917
|
var import_bn7 = __toESM(require_bn());
|
|
6879
6918
|
|
|
6880
6919
|
// src/math.ts
|
|
6881
|
-
__toESM(require_bn());
|
|
6920
|
+
var import_bn6 = __toESM(require_bn());
|
|
6882
6921
|
function CalculateAmountLimit(expectAmount, byAmountIn, slippage) {
|
|
6883
|
-
|
|
6884
|
-
|
|
6885
|
-
|
|
6886
|
-
|
|
6887
|
-
|
|
6888
|
-
|
|
6889
|
-
|
|
6922
|
+
return Number(
|
|
6923
|
+
CalculateAmountLimitByDecimal(
|
|
6924
|
+
new decimal_default(expectAmount.toString()),
|
|
6925
|
+
byAmountIn,
|
|
6926
|
+
slippage
|
|
6927
|
+
).toFixed(0)
|
|
6928
|
+
);
|
|
6890
6929
|
}
|
|
6891
6930
|
function CalculateAmountLimitBN(expectAmount, byAmountIn, slippage) {
|
|
6931
|
+
const amountLimit = CalculateAmountLimitByDecimal(
|
|
6932
|
+
new decimal_default(expectAmount.toString()),
|
|
6933
|
+
byAmountIn,
|
|
6934
|
+
slippage
|
|
6935
|
+
);
|
|
6936
|
+
return new import_bn6.default(amountLimit.toFixed(0));
|
|
6937
|
+
}
|
|
6938
|
+
function CalculateAmountLimitByDecimal(expectAmount, byAmountIn, slippage) {
|
|
6892
6939
|
if (byAmountIn) {
|
|
6893
|
-
return expectAmount.
|
|
6940
|
+
return expectAmount.mul(1 - slippage);
|
|
6894
6941
|
} else {
|
|
6895
|
-
return expectAmount.
|
|
6942
|
+
return expectAmount.mul(1 + slippage);
|
|
6896
6943
|
}
|
|
6897
6944
|
}
|
|
6898
6945
|
function sqrtPriceX64ToPrice(sqrtPriceStr, decimalsA, decimalsB) {
|
|
@@ -7374,13 +7421,13 @@ var SteammCPMM = class {
|
|
|
7374
7421
|
if (path.extendedDetails.steamm_lending_market_type == null) {
|
|
7375
7422
|
throw new Error("Steamm lending market type not supported");
|
|
7376
7423
|
}
|
|
7377
|
-
if (path.extendedDetails.
|
|
7424
|
+
if (path.extendedDetails.steamm_btoken_a_type == null) {
|
|
7378
7425
|
throw new Error("Steamm b coin a type not supported");
|
|
7379
7426
|
}
|
|
7380
|
-
if (path.extendedDetails.
|
|
7427
|
+
if (path.extendedDetails.steamm_btoken_b_type == null) {
|
|
7381
7428
|
throw new Error("Steamm b coin b type not supported");
|
|
7382
7429
|
}
|
|
7383
|
-
if (path.extendedDetails.
|
|
7430
|
+
if (path.extendedDetails.steamm_lp_token_type == null) {
|
|
7384
7431
|
throw new Error("Steamm lp token not supported");
|
|
7385
7432
|
}
|
|
7386
7433
|
}
|
|
@@ -7402,9 +7449,9 @@ var SteammCPMM = class {
|
|
|
7402
7449
|
path.extendedDetails.steamm_lending_market_type,
|
|
7403
7450
|
coinAType,
|
|
7404
7451
|
coinBType,
|
|
7405
|
-
path.extendedDetails.
|
|
7406
|
-
path.extendedDetails.
|
|
7407
|
-
path.extendedDetails.
|
|
7452
|
+
path.extendedDetails.steamm_btoken_a_type,
|
|
7453
|
+
path.extendedDetails.steamm_btoken_b_type,
|
|
7454
|
+
path.extendedDetails.steamm_lp_token_type
|
|
7408
7455
|
],
|
|
7409
7456
|
arguments: args
|
|
7410
7457
|
});
|
|
@@ -7440,13 +7487,13 @@ var SteammOmm = class {
|
|
|
7440
7487
|
if (path.extendedDetails.steamm_lending_market_type == null) {
|
|
7441
7488
|
throw new Error("Steamm lending market type not supported");
|
|
7442
7489
|
}
|
|
7443
|
-
if (path.extendedDetails.
|
|
7490
|
+
if (path.extendedDetails.steamm_btoken_a_type == null) {
|
|
7444
7491
|
throw new Error("Steamm b coin a type not supported");
|
|
7445
7492
|
}
|
|
7446
|
-
if (path.extendedDetails.
|
|
7493
|
+
if (path.extendedDetails.steamm_btoken_b_type == null) {
|
|
7447
7494
|
throw new Error("Steamm b coin b type not supported");
|
|
7448
7495
|
}
|
|
7449
|
-
if (path.extendedDetails.
|
|
7496
|
+
if (path.extendedDetails.steamm_lp_token_type == null) {
|
|
7450
7497
|
throw new Error("Steamm lp token not supported");
|
|
7451
7498
|
}
|
|
7452
7499
|
if (path.extendedDetails.steamm_oracle_registry_id == null) {
|
|
@@ -7515,9 +7562,9 @@ var SteammOmm = class {
|
|
|
7515
7562
|
path.extendedDetails.steamm_lending_market_type,
|
|
7516
7563
|
coinAType,
|
|
7517
7564
|
coinBType,
|
|
7518
|
-
path.extendedDetails.
|
|
7519
|
-
path.extendedDetails.
|
|
7520
|
-
path.extendedDetails.
|
|
7565
|
+
path.extendedDetails.steamm_btoken_a_type,
|
|
7566
|
+
path.extendedDetails.steamm_btoken_b_type,
|
|
7567
|
+
path.extendedDetails.steamm_lp_token_type
|
|
7521
7568
|
],
|
|
7522
7569
|
arguments: args
|
|
7523
7570
|
});
|
|
@@ -7798,13 +7845,13 @@ var SteammOmmV2 = class {
|
|
|
7798
7845
|
if (path.extendedDetails.steamm_lending_market_type == null) {
|
|
7799
7846
|
throw new Error("Steamm lending market type not supported");
|
|
7800
7847
|
}
|
|
7801
|
-
if (path.extendedDetails.
|
|
7848
|
+
if (path.extendedDetails.steamm_btoken_a_type == null) {
|
|
7802
7849
|
throw new Error("Steamm b coin a type not supported");
|
|
7803
7850
|
}
|
|
7804
|
-
if (path.extendedDetails.
|
|
7851
|
+
if (path.extendedDetails.steamm_btoken_b_type == null) {
|
|
7805
7852
|
throw new Error("Steamm b coin b type not supported");
|
|
7806
7853
|
}
|
|
7807
|
-
if (path.extendedDetails.
|
|
7854
|
+
if (path.extendedDetails.steamm_lp_token_type == null) {
|
|
7808
7855
|
throw new Error("Steamm lp token not supported");
|
|
7809
7856
|
}
|
|
7810
7857
|
if (path.extendedDetails.steamm_oracle_registry_id == null) {
|
|
@@ -7873,9 +7920,9 @@ var SteammOmmV2 = class {
|
|
|
7873
7920
|
path.extendedDetails.steamm_lending_market_type,
|
|
7874
7921
|
coinAType,
|
|
7875
7922
|
coinBType,
|
|
7876
|
-
path.extendedDetails.
|
|
7877
|
-
path.extendedDetails.
|
|
7878
|
-
path.extendedDetails.
|
|
7923
|
+
path.extendedDetails.steamm_btoken_a_type,
|
|
7924
|
+
path.extendedDetails.steamm_btoken_b_type,
|
|
7925
|
+
path.extendedDetails.steamm_lp_token_type
|
|
7879
7926
|
],
|
|
7880
7927
|
arguments: args
|
|
7881
7928
|
});
|
|
@@ -8033,6 +8080,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8033
8080
|
this.signer = params.signer || "";
|
|
8034
8081
|
this.env = params.env || 0 /* Mainnet */;
|
|
8035
8082
|
this.allCoins = /* @__PURE__ */ new Map();
|
|
8083
|
+
AggregatorConfig2.setEnv(this.env);
|
|
8036
8084
|
const config2 = _AggregatorClient.CONFIG[this.env];
|
|
8037
8085
|
this.pythConnections = this.newPythClients((_a = params.pythUrls) != null ? _a : []);
|
|
8038
8086
|
this.pythClient = new pythSuiJs.SuiPythClient(
|
|
@@ -8553,26 +8601,14 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8553
8601
|
}
|
|
8554
8602
|
// Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
|
|
8555
8603
|
publishedAtV2() {
|
|
8556
|
-
|
|
8557
|
-
return "0x8ae871505a80d8bf6bf9c05906cda6edfeea460c85bebe2e26a4313f5e67874a";
|
|
8558
|
-
} else {
|
|
8559
|
-
return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934";
|
|
8560
|
-
}
|
|
8604
|
+
return AggregatorConfig2.getPublishedAtV2(this.env);
|
|
8561
8605
|
}
|
|
8562
8606
|
// Include deepbookv3, scallop, bluefin
|
|
8563
8607
|
publishedAtV2Extend() {
|
|
8564
|
-
|
|
8565
|
-
return "0x8a2f7a5b20665eeccc79de3aa37c3b6c473eca233ada1e1cd4678ec07d4d4073";
|
|
8566
|
-
} else {
|
|
8567
|
-
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
|
|
8568
|
-
}
|
|
8608
|
+
return AggregatorConfig2.getPublishedAtV2Extend(this.env);
|
|
8569
8609
|
}
|
|
8570
8610
|
publishedAtV2Extend2() {
|
|
8571
|
-
|
|
8572
|
-
return "0x5cb7499fc49c2642310e24a4ecffdbee00133f97e80e2b45bca90c64d55de880";
|
|
8573
|
-
} else {
|
|
8574
|
-
return "0x0";
|
|
8575
|
-
}
|
|
8611
|
+
return AggregatorConfig2.getPublishedAtV2Extend2(this.env);
|
|
8576
8612
|
}
|
|
8577
8613
|
deepbookv3DeepFeeType() {
|
|
8578
8614
|
if (this.env === 0 /* Mainnet */) {
|
|
@@ -8777,7 +8813,7 @@ _AggregatorClient.CONFIG = {
|
|
|
8777
8813
|
pythStateId: "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"
|
|
8778
8814
|
}
|
|
8779
8815
|
};
|
|
8780
|
-
var
|
|
8816
|
+
var AggregatorClient = _AggregatorClient;
|
|
8781
8817
|
function findPythPriceIDs(routes) {
|
|
8782
8818
|
const priceIDs = /* @__PURE__ */ new Set();
|
|
8783
8819
|
for (const route of routes) {
|
|
@@ -9528,7 +9564,7 @@ var ScallopRouter = class {
|
|
|
9528
9564
|
if (flattenedPath.path.publishedAt == null) {
|
|
9529
9565
|
throw new Error("Scallop not set publishedAt");
|
|
9530
9566
|
}
|
|
9531
|
-
const [coinAType, coinBType] = path.direction ? [path.from, path.target] : [path.
|
|
9567
|
+
const [coinAType, coinBType] = path.direction ? [path.from, path.target] : [path.from, path.target];
|
|
9532
9568
|
const amountIn = flattenedPath.isLastUseOfIntermediateToken ? AGGREGATOR_V3_CONFIG.MAX_AMOUNT_IN : path.amountIn;
|
|
9533
9569
|
if (path.extendedDetails == null) {
|
|
9534
9570
|
throw new Error("Extended details not supported");
|
|
@@ -10556,7 +10592,7 @@ function transfer_or_destroy_coin(params, txb) {
|
|
|
10556
10592
|
arguments: [coin]
|
|
10557
10593
|
});
|
|
10558
10594
|
}
|
|
10559
|
-
var AggregatorClientV3 = class extends
|
|
10595
|
+
var AggregatorClientV3 = class extends AggregatorClient {
|
|
10560
10596
|
constructor(params) {
|
|
10561
10597
|
var _a;
|
|
10562
10598
|
const v3Params = __spreadProps(__spreadValues({}, params), {
|
|
@@ -10649,6 +10685,8 @@ var AggregatorClientV3 = class extends AggregatorClient28 {
|
|
|
10649
10685
|
throw new Error(CLIENT_CONFIG.ERRORS.QUOTE_ID_REQUIRED);
|
|
10650
10686
|
}
|
|
10651
10687
|
const processedData = sortAndFlattenRoutes(routerData);
|
|
10688
|
+
console.log("expectAmountOut", expectAmountOut);
|
|
10689
|
+
console.log("amountOutLimit", amountOutLimit);
|
|
10652
10690
|
const swapCtx = newSwapContext(
|
|
10653
10691
|
{
|
|
10654
10692
|
quoteID: processedData.quoteID,
|
|
@@ -10785,6 +10823,9 @@ var AggregatorClientV3 = class extends AggregatorClient28 {
|
|
|
10785
10823
|
byAmountIn,
|
|
10786
10824
|
slippage
|
|
10787
10825
|
);
|
|
10826
|
+
console.log("expectedAmountOut", expectedAmountOut.toString());
|
|
10827
|
+
console.log("expectedAmountIn", expectedAmountIn.toString());
|
|
10828
|
+
console.log("amountLimit", amountLimit.toString());
|
|
10788
10829
|
if (!params.routers.packages || !params.routers.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
10789
10830
|
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
10790
10831
|
}
|
|
@@ -10973,13 +11014,143 @@ var AggregatorClientV3 = class extends AggregatorClient28 {
|
|
|
10973
11014
|
return this.fixableRouterSwapV3(params);
|
|
10974
11015
|
});
|
|
10975
11016
|
}
|
|
11017
|
+
swapInPools(params) {
|
|
11018
|
+
return __async(this, null, function* () {
|
|
11019
|
+
let result;
|
|
11020
|
+
try {
|
|
11021
|
+
result = yield this.swapInPoolsV3(params);
|
|
11022
|
+
} catch (e) {
|
|
11023
|
+
console.error("swapInPoolsV3 error:", e);
|
|
11024
|
+
return null;
|
|
11025
|
+
}
|
|
11026
|
+
return result;
|
|
11027
|
+
});
|
|
11028
|
+
}
|
|
11029
|
+
swapInPoolsV3(params) {
|
|
11030
|
+
return __async(this, null, function* () {
|
|
11031
|
+
var _a, _b, _c, _d, _e;
|
|
11032
|
+
const { from, target, amount, byAmountIn, pools } = params;
|
|
11033
|
+
const fromCoin = completionCoin(from);
|
|
11034
|
+
const targetCoin = completionCoin(target);
|
|
11035
|
+
const tx = new transactions.Transaction();
|
|
11036
|
+
const direction = compareCoins(fromCoin, targetCoin);
|
|
11037
|
+
const coinA = direction ? fromCoin : targetCoin;
|
|
11038
|
+
const coinB = direction ? targetCoin : fromCoin;
|
|
11039
|
+
const typeArguments = [coinA, coinB];
|
|
11040
|
+
const integratePublishedAt = this.env === 0 /* Mainnet */ ? "0xb2db7142fa83210a7d78d9c12ac49c043b3cbbd482224fea6e3da00aa5a5ae2d" : "0x4f920e1ef6318cfba77e20a0538a419a5a504c14230169438b99aba485db40a6";
|
|
11041
|
+
for (let i = 0; i < pools.length; i++) {
|
|
11042
|
+
const args = [
|
|
11043
|
+
tx.object(pools[i]),
|
|
11044
|
+
tx.pure.bool(direction),
|
|
11045
|
+
tx.pure.bool(byAmountIn),
|
|
11046
|
+
tx.pure.u64(amount.toString())
|
|
11047
|
+
];
|
|
11048
|
+
tx.moveCall({
|
|
11049
|
+
target: `${integratePublishedAt}::fetcher_script::calculate_swap_result`,
|
|
11050
|
+
arguments: args,
|
|
11051
|
+
typeArguments
|
|
11052
|
+
});
|
|
11053
|
+
}
|
|
11054
|
+
if (!this.signer) {
|
|
11055
|
+
this.signer = "0x0";
|
|
11056
|
+
}
|
|
11057
|
+
const simulateRes = yield this.client.devInspectTransactionBlock({
|
|
11058
|
+
transactionBlock: tx,
|
|
11059
|
+
sender: this.signer
|
|
11060
|
+
});
|
|
11061
|
+
if (simulateRes.error != null) {
|
|
11062
|
+
console.log("simulateRes.error", simulateRes.error);
|
|
11063
|
+
throw new Error("Simulation error: " + simulateRes.error);
|
|
11064
|
+
}
|
|
11065
|
+
const valueData = (_a = simulateRes.events) == null ? void 0 : _a.filter((item) => {
|
|
11066
|
+
return item.type.includes("CalculatedSwapResultEvent");
|
|
11067
|
+
});
|
|
11068
|
+
if (valueData.length === 0 || valueData.length !== pools.length) {
|
|
11069
|
+
throw new Error("Simulate event result error");
|
|
11070
|
+
}
|
|
11071
|
+
let tempMaxAmount = byAmountIn ? new import_bn9.default(0) : new import_bn9.default(U64_MAX);
|
|
11072
|
+
let tempIndex = 0;
|
|
11073
|
+
for (let i = 0; i < valueData.length; i += 1) {
|
|
11074
|
+
if (valueData[i].parsedJson.data.is_exceed) {
|
|
11075
|
+
continue;
|
|
11076
|
+
}
|
|
11077
|
+
if (params.byAmountIn) {
|
|
11078
|
+
const amount2 = new import_bn9.default(valueData[i].parsedJson.data.amount_out);
|
|
11079
|
+
if (amount2.gt(tempMaxAmount)) {
|
|
11080
|
+
tempIndex = i;
|
|
11081
|
+
tempMaxAmount = amount2;
|
|
11082
|
+
}
|
|
11083
|
+
} else {
|
|
11084
|
+
const amount2 = new import_bn9.default(valueData[i].parsedJson.data.amount_out);
|
|
11085
|
+
if (amount2.lt(tempMaxAmount)) {
|
|
11086
|
+
tempIndex = i;
|
|
11087
|
+
tempMaxAmount = amount2;
|
|
11088
|
+
}
|
|
11089
|
+
}
|
|
11090
|
+
}
|
|
11091
|
+
const event = valueData[tempIndex].parsedJson.data;
|
|
11092
|
+
const currentSqrtPrice = event.step_results[0].current_sqrt_price;
|
|
11093
|
+
const [decimalA, decimalB] = yield Promise.all([
|
|
11094
|
+
this.client.getCoinMetadata({ coinType: coinA }).then((metadata) => metadata == null ? void 0 : metadata.decimals),
|
|
11095
|
+
this.client.getCoinMetadata({ coinType: coinB }).then((metadata) => metadata == null ? void 0 : metadata.decimals)
|
|
11096
|
+
]);
|
|
11097
|
+
if (decimalA == null || decimalB == null) {
|
|
11098
|
+
throw new Error("Cannot get coin decimals");
|
|
11099
|
+
}
|
|
11100
|
+
const sqrtPriceNum = new import_bn9.default(currentSqrtPrice);
|
|
11101
|
+
const price = sqrtPriceNum.mul(sqrtPriceNum).div(new import_bn9.default(2).pow(new import_bn9.default(128)));
|
|
11102
|
+
const priceScale = new import_bn9.default(10).pow(new import_bn9.default(decimalB - decimalA));
|
|
11103
|
+
const initialPriceNum = price.div(priceScale).toNumber();
|
|
11104
|
+
const initialPrice = new decimal_default(initialPriceNum);
|
|
11105
|
+
const feeRate = Number(event.fee_rate) / 1e6;
|
|
11106
|
+
const pureAmountIn = new import_bn9.default((_b = event.amount_in) != null ? _b : 0);
|
|
11107
|
+
const feeAmount = new import_bn9.default((_c = event.fee_amount) != null ? _c : 0);
|
|
11108
|
+
const amountIn = pureAmountIn.add(feeAmount);
|
|
11109
|
+
const routeData = {
|
|
11110
|
+
amountIn,
|
|
11111
|
+
amountOut: new import_bn9.default((_d = event.amount_out) != null ? _d : 0),
|
|
11112
|
+
routes: [
|
|
11113
|
+
{
|
|
11114
|
+
path: [
|
|
11115
|
+
{
|
|
11116
|
+
id: pools[tempIndex],
|
|
11117
|
+
direction,
|
|
11118
|
+
provider: CETUS,
|
|
11119
|
+
from: fromCoin,
|
|
11120
|
+
target: targetCoin,
|
|
11121
|
+
feeRate,
|
|
11122
|
+
amountIn: amountIn.toString(),
|
|
11123
|
+
amountOut: event.amount_out,
|
|
11124
|
+
publishedAt: CETUS_V3_PUBLISHED_AT,
|
|
11125
|
+
extendedDetails: {
|
|
11126
|
+
afterSqrtPrice: event.after_sqrt_price
|
|
11127
|
+
}
|
|
11128
|
+
}
|
|
11129
|
+
],
|
|
11130
|
+
amountIn,
|
|
11131
|
+
amountOut: new import_bn9.default((_e = event.amount_out) != null ? _e : 0),
|
|
11132
|
+
initialPrice
|
|
11133
|
+
}
|
|
11134
|
+
],
|
|
11135
|
+
insufficientLiquidity: false,
|
|
11136
|
+
byAmountIn: params.byAmountIn,
|
|
11137
|
+
quoteID: "cetus-pools-fallback",
|
|
11138
|
+
packages: /* @__PURE__ */ new Map([
|
|
11139
|
+
[
|
|
11140
|
+
PACKAGE_NAMES.AGGREGATOR_V3,
|
|
11141
|
+
AGGREGATOR_V3_CONFIG.DEFAULT_PUBLISHED_AT.Mainnet
|
|
11142
|
+
]
|
|
11143
|
+
])
|
|
11144
|
+
};
|
|
11145
|
+
const result = {
|
|
11146
|
+
isExceed: event.is_exceed,
|
|
11147
|
+
routeData
|
|
11148
|
+
};
|
|
11149
|
+
return result;
|
|
11150
|
+
});
|
|
11151
|
+
}
|
|
10976
11152
|
};
|
|
10977
11153
|
|
|
10978
|
-
// src/transaction/index.ts
|
|
10979
|
-
var AGGREGATOR_V2 = "aggregator_v2";
|
|
10980
|
-
var AGGREGATOR_V2_EXTEND = "aggregator_v2_extend";
|
|
10981
|
-
var AGGREGATOR_V2_EXTEND2 = "aggregator_v2_extend2";
|
|
10982
|
-
|
|
10983
11154
|
// src/types/sui.ts
|
|
10984
11155
|
var getDefaultSuiInputType = (value) => {
|
|
10985
11156
|
if (typeof value === "string" && value.startsWith("0x")) {
|
|
@@ -11010,32 +11181,24 @@ exports.AFTERMATH = AFTERMATH;
|
|
|
11010
11181
|
exports.AFTERMATH_AMM = AFTERMATH_AMM;
|
|
11011
11182
|
exports.AFTERMATH_MODULE = AFTERMATH_MODULE;
|
|
11012
11183
|
exports.AGGREGATOR = AGGREGATOR;
|
|
11013
|
-
exports.AGGREGATOR_V2 = AGGREGATOR_V2;
|
|
11014
|
-
exports.AGGREGATOR_V2_EXTEND = AGGREGATOR_V2_EXTEND;
|
|
11015
|
-
exports.AGGREGATOR_V2_EXTEND2 = AGGREGATOR_V2_EXTEND2;
|
|
11016
11184
|
exports.AGGREGATOR_V3_CONFIG = AGGREGATOR_V3_CONFIG;
|
|
11017
11185
|
exports.ALL_DEXES = ALL_DEXES;
|
|
11018
11186
|
exports.ALPHAFI = ALPHAFI;
|
|
11019
|
-
exports.
|
|
11020
|
-
exports.Aftermath = Aftermath;
|
|
11021
|
-
exports.AggregatorClient = AggregatorClient28;
|
|
11187
|
+
exports.AggregatorClient = AggregatorClient;
|
|
11022
11188
|
exports.AggregatorClientV3 = AggregatorClientV3;
|
|
11023
11189
|
exports.AggregatorConfig = AggregatorConfig;
|
|
11024
11190
|
exports.AggregatorError = AggregatorError;
|
|
11025
11191
|
exports.AggregatorServerErrorCode = AggregatorServerErrorCode;
|
|
11026
|
-
exports.Alphafi = Alphafi;
|
|
11027
11192
|
exports.BLUEFIN = BLUEFIN;
|
|
11028
11193
|
exports.BLUEMOVE = BLUEMOVE;
|
|
11029
|
-
exports.Bluefin = Bluefin;
|
|
11030
|
-
exports.Bluemove = Bluemove;
|
|
11031
11194
|
exports.CETUS = CETUS;
|
|
11032
11195
|
exports.CETUS_DEX = CETUS_DEX;
|
|
11033
11196
|
exports.CETUS_MODULE = CETUS_MODULE;
|
|
11034
11197
|
exports.CETUS_PUBLISHED_AT = CETUS_PUBLISHED_AT;
|
|
11198
|
+
exports.CETUS_V3_PUBLISHED_AT = CETUS_V3_PUBLISHED_AT;
|
|
11035
11199
|
exports.CHECK_COINS_THRESHOLD_FUNC = CHECK_COINS_THRESHOLD_FUNC;
|
|
11036
11200
|
exports.CLIENT_CONFIG = CLIENT_CONFIG;
|
|
11037
11201
|
exports.CLOCK_ADDRESS = CLOCK_ADDRESS;
|
|
11038
|
-
exports.Cetus = Cetus;
|
|
11039
11202
|
exports.CoinInfoAddress = CoinInfoAddress;
|
|
11040
11203
|
exports.CoinStoreAddress = CoinStoreAddress;
|
|
11041
11204
|
exports.CoinUtils = CoinUtils;
|
|
@@ -11057,8 +11220,6 @@ exports.DEFAULT_GAS_BUDGET_FOR_STAKE = DEFAULT_GAS_BUDGET_FOR_STAKE;
|
|
|
11057
11220
|
exports.DEFAULT_GAS_BUDGET_FOR_TRANSFER = DEFAULT_GAS_BUDGET_FOR_TRANSFER;
|
|
11058
11221
|
exports.DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI = DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI;
|
|
11059
11222
|
exports.DEFAULT_NFT_TRANSFER_GAS_FEE = DEFAULT_NFT_TRANSFER_GAS_FEE;
|
|
11060
|
-
exports.DeepbookV2 = DeepbookV2;
|
|
11061
|
-
exports.DeepbookV3 = DeepbookV3;
|
|
11062
11223
|
exports.Dex = Dex;
|
|
11063
11224
|
exports.Env = Env;
|
|
11064
11225
|
exports.FLOWXV2 = FLOWXV2;
|
|
@@ -11071,25 +11232,18 @@ exports.FlashSwapFunc = FlashSwapFunc;
|
|
|
11071
11232
|
exports.FlashSwapWithPartnerA2BFunc = FlashSwapWithPartnerA2BFunc;
|
|
11072
11233
|
exports.FlashSwapWithPartnerB2AFunc = FlashSwapWithPartnerB2AFunc;
|
|
11073
11234
|
exports.FlashSwapWithPartnerFunc = FlashSwapWithPartnerFunc;
|
|
11074
|
-
exports.FlowxV2 = FlowxV2;
|
|
11075
|
-
exports.FlowxV3 = FlowxV3;
|
|
11076
11235
|
exports.GAS_SYMBOL = GAS_SYMBOL;
|
|
11077
11236
|
exports.GAS_TYPE_ARG = GAS_TYPE_ARG;
|
|
11078
11237
|
exports.GAS_TYPE_ARG_LONG = GAS_TYPE_ARG_LONG;
|
|
11079
11238
|
exports.HAEDAL = HAEDAL;
|
|
11080
11239
|
exports.HAEDALPMM = HAEDALPMM;
|
|
11081
11240
|
exports.HAWAL = HAWAL;
|
|
11082
|
-
exports.HaWAL = HaWAL;
|
|
11083
|
-
exports.Haedal = Haedal;
|
|
11084
|
-
exports.HaedalPmm = HaedalPmm;
|
|
11085
11241
|
exports.INTEGRATE = INTEGRATE;
|
|
11086
11242
|
exports.JOIN_FUNC = JOIN_FUNC;
|
|
11087
11243
|
exports.KRIYA = KRIYA;
|
|
11088
11244
|
exports.KRIYAV3 = KRIYAV3;
|
|
11089
11245
|
exports.KRIYA_DEX = KRIYA_DEX;
|
|
11090
11246
|
exports.KRIYA_MODULE = KRIYA_MODULE;
|
|
11091
|
-
exports.KriyaV2 = KriyaV2;
|
|
11092
|
-
exports.KriyaV3 = KriyaV3;
|
|
11093
11247
|
exports.MAGMA = MAGMA;
|
|
11094
11248
|
exports.MAINNET_AFTERMATH_INSURANCE_FUND_ID = MAINNET_AFTERMATH_INSURANCE_FUND_ID;
|
|
11095
11249
|
exports.MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID = MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID;
|
|
@@ -11100,12 +11254,8 @@ exports.MAINNET_CETUS_GLOBAL_CONFIG_ID = MAINNET_CETUS_GLOBAL_CONFIG_ID;
|
|
|
11100
11254
|
exports.MAINNET_FLOWX_AMM_CONTAINER_ID = MAINNET_FLOWX_AMM_CONTAINER_ID;
|
|
11101
11255
|
exports.METASTABLE = METASTABLE;
|
|
11102
11256
|
exports.MOMENTUM = MOMENTUM;
|
|
11103
|
-
exports.Magma = Magma;
|
|
11104
|
-
exports.Metastable = Metastable;
|
|
11105
|
-
exports.Momentum = Momentum;
|
|
11106
11257
|
exports.OBRIC = OBRIC;
|
|
11107
11258
|
exports.ONE = ONE;
|
|
11108
|
-
exports.Obric = Obric;
|
|
11109
11259
|
exports.PACKAGE_NAMES = PACKAGE_NAMES;
|
|
11110
11260
|
exports.PAY_MODULE = PAY_MODULE;
|
|
11111
11261
|
exports.POOL_MODULT = POOL_MODULT;
|
|
@@ -11127,13 +11277,7 @@ exports.SUILEND = SUILEND;
|
|
|
11127
11277
|
exports.SUI_SYSTEM_STATE_OBJECT_ID = SUI_SYSTEM_STATE_OBJECT_ID;
|
|
11128
11278
|
exports.SWAP_A2B_FUNC = SWAP_A2B_FUNC;
|
|
11129
11279
|
exports.SWAP_B2A_FUNC = SWAP_B2A_FUNC;
|
|
11130
|
-
exports.Scallop = Scallop;
|
|
11131
|
-
exports.Sevenk = Sevenk;
|
|
11132
|
-
exports.SteammCPMM = SteammCPMM;
|
|
11133
|
-
exports.SteammOmm = SteammOmm;
|
|
11134
|
-
exports.SteammOmmV2 = SteammOmmV2;
|
|
11135
11280
|
exports.SuiZeroCoinFn = SuiZeroCoinFn;
|
|
11136
|
-
exports.Suilend = Suilend;
|
|
11137
11281
|
exports.TEN_POW_NINE = TEN_POW_NINE;
|
|
11138
11282
|
exports.TESTNET_AFTERMATH_INSURANCE_FUND_ID = TESTNET_AFTERMATH_INSURANCE_FUND_ID;
|
|
11139
11283
|
exports.TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID = TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID;
|
|
@@ -11150,14 +11294,12 @@ exports.TURBOS_MODULE = TURBOS_MODULE;
|
|
|
11150
11294
|
exports.TURBOS_VERSIONED = TURBOS_VERSIONED;
|
|
11151
11295
|
exports.TWO = TWO;
|
|
11152
11296
|
exports.TransactionErrorCode = TransactionErrorCode;
|
|
11153
|
-
exports.Turbos = Turbos;
|
|
11154
11297
|
exports.TypesErrorCode = TypesErrorCode;
|
|
11155
11298
|
exports.U128 = U128;
|
|
11156
11299
|
exports.U64_MAX = U64_MAX;
|
|
11157
11300
|
exports.U64_MAX_BN = U64_MAX_BN;
|
|
11158
11301
|
exports.UTILS_MODULE = UTILS_MODULE;
|
|
11159
11302
|
exports.VOLO = VOLO;
|
|
11160
|
-
exports.Volo = Volo;
|
|
11161
11303
|
exports.ZERO = ZERO;
|
|
11162
11304
|
exports.buildInputCoin = buildInputCoin;
|
|
11163
11305
|
exports.calculateGasEfficiency = calculateGasEfficiency;
|
|
@@ -11198,3 +11340,4 @@ exports.printTransaction = printTransaction;
|
|
|
11198
11340
|
exports.processEndpoint = processEndpoint;
|
|
11199
11341
|
exports.restituteMsafeFastRouterSwapParams = restituteMsafeFastRouterSwapParams;
|
|
11200
11342
|
exports.sortAndFlattenRoutes = sortAndFlattenRoutes;
|
|
11343
|
+
exports.swapInPools = swapInPools;
|