hermes-swap 0.6.2 → 0.6.3
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/cjs/aggregator.cjs +50 -54
- package/dist/cjs/index.cjs +3 -1
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/types.cjs +12 -2
- package/dist/cjs/types.d.ts +5 -0
- package/dist/esm/aggregator.mjs +168 -130
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/types.d.ts +5 -0
- package/dist/esm/types.mjs +16 -0
- package/package.json +1 -1
package/dist/cjs/aggregator.cjs
CHANGED
|
@@ -168,11 +168,7 @@ var _Aggregator = class {
|
|
|
168
168
|
this.validateParams(params);
|
|
169
169
|
const useBundle = this.shouldUseBundle(params.chain, txReq);
|
|
170
170
|
const pathDesc = params.path.map((p) => `${p.dexType}:${p.poolAddress.slice(0, 10)}`).join("→");
|
|
171
|
-
_Aggregator.traceLog(
|
|
172
|
-
params.chain,
|
|
173
|
-
"log",
|
|
174
|
-
`swapByPath开始, user=${params.user}, amountIn=${params.amountInWei}, path=[${pathDesc}], useBundle=${useBundle}`
|
|
175
|
-
);
|
|
171
|
+
_Aggregator.traceLog(params.chain, "log", `swapByPath开始, user=${params.user}, amountIn=${params.amountInWei}, path=[${pathDesc}], useBundle=${useBundle}`);
|
|
176
172
|
const startTs = Date.now();
|
|
177
173
|
let txHash;
|
|
178
174
|
try {
|
|
@@ -345,11 +341,18 @@ var _Aggregator = class {
|
|
|
345
341
|
let receipt;
|
|
346
342
|
if (useBundle) {
|
|
347
343
|
const calldata = iface.encodeFunctionData("multiSwapAndBridge", args);
|
|
348
|
-
const {
|
|
344
|
+
const {
|
|
345
|
+
receipt: flashbotsReceipt,
|
|
346
|
+
txHash: bundleTxHash,
|
|
347
|
+
targetBlocks
|
|
348
|
+
} = await this.submitBundleTx(params.chain, wallet, txReq, aggregatorAddress, calldata, txReq.value ?? 0n, bundleBlockCount);
|
|
349
349
|
txHash = bundleTxHash;
|
|
350
350
|
if (!flashbotsReceipt) {
|
|
351
351
|
throw new import_types.BundleNotIncludedError(`Bundle 未在目标区块上链, txHash=${bundleTxHash}, targetBlocks=[${targetBlocks.join(",")}]`, bundleTxHash);
|
|
352
352
|
}
|
|
353
|
+
if (flashbotsReceipt.status === 0) {
|
|
354
|
+
throw new import_types.TransactionRevertedError(flashbotsReceipt.hash, flashbotsReceipt.gasUsed);
|
|
355
|
+
}
|
|
353
356
|
receipt = flashbotsReceipt;
|
|
354
357
|
} else {
|
|
355
358
|
receipt = await this.sendContractTx(params.chain, aggregator, "multiSwapAndBridge", args, txReq);
|
|
@@ -380,11 +383,7 @@ var _Aggregator = class {
|
|
|
380
383
|
const fromTokenAddress = ((_a = pathStart == null ? void 0 : pathStart[0]) == null ? void 0 : _a.fromCoinAddress) ?? "";
|
|
381
384
|
const toTokenAddress = ((_b = pathEnd == null ? void 0 : pathEnd[pathEnd.length - 1]) == null ? void 0 : _b.toCoinAddress) ?? "";
|
|
382
385
|
const totalAmountInFromEvent = amountInList.reduce((sum, amount) => sum + amount, 0n);
|
|
383
|
-
_Aggregator.traceLog(
|
|
384
|
-
params.chain,
|
|
385
|
-
"log",
|
|
386
|
-
`swapAndBridge完成, txHash=${receipt.hash}, amountOut=${amountOut}, useBundle=${useBundle}, 总耗时=${Date.now() - startTs}ms`
|
|
387
|
-
);
|
|
386
|
+
_Aggregator.traceLog(params.chain, "log", `swapAndBridge完成, txHash=${receipt.hash}, amountOut=${amountOut}, useBundle=${useBundle}, 总耗时=${Date.now() - startTs}ms`);
|
|
388
387
|
return {
|
|
389
388
|
hash: receipt.hash,
|
|
390
389
|
from: receipt.from,
|
|
@@ -400,11 +399,7 @@ var _Aggregator = class {
|
|
|
400
399
|
async multiSwap(params, txReq = {}) {
|
|
401
400
|
var _a;
|
|
402
401
|
const useBundle = this.shouldUseBundle(params.chain, txReq);
|
|
403
|
-
_Aggregator.traceLog(
|
|
404
|
-
params.chain,
|
|
405
|
-
"log",
|
|
406
|
-
`multiSwap开始, user=${params.user}, pathsCount=${params.paths.length}, amountInWeis=[${params.amountInWeis.join(",")}], useBundle=${useBundle}`
|
|
407
|
-
);
|
|
402
|
+
_Aggregator.traceLog(params.chain, "log", `multiSwap开始, user=${params.user}, pathsCount=${params.paths.length}, amountInWeis=[${params.amountInWeis.join(",")}], useBundle=${useBundle}`);
|
|
408
403
|
const startTs = Date.now();
|
|
409
404
|
let txHash;
|
|
410
405
|
try {
|
|
@@ -458,11 +453,18 @@ var _Aggregator = class {
|
|
|
458
453
|
let receipt;
|
|
459
454
|
if (useBundle) {
|
|
460
455
|
const calldata = iface.encodeFunctionData("multiSwap", [params.user, params.amountInWeis, swapParamsList, params.minAmountOutLists, params.totalMinAmountOut]);
|
|
461
|
-
const {
|
|
456
|
+
const {
|
|
457
|
+
receipt: flashbotsReceipt,
|
|
458
|
+
txHash: bundleTxHash,
|
|
459
|
+
targetBlocks
|
|
460
|
+
} = await this.submitBundleTx(params.chain, wallet, txReq, aggregatorAddress, calldata, txReq.value ?? 0n, bundleBlockCount);
|
|
462
461
|
txHash = bundleTxHash;
|
|
463
462
|
if (!flashbotsReceipt) {
|
|
464
463
|
throw new import_types.BundleNotIncludedError(`Bundle 未在目标区块上链, txHash=${bundleTxHash}, targetBlocks=[${targetBlocks.join(",")}]`, bundleTxHash);
|
|
465
464
|
}
|
|
465
|
+
if (flashbotsReceipt.status === 0) {
|
|
466
|
+
throw new import_types.TransactionRevertedError(flashbotsReceipt.hash, flashbotsReceipt.gasUsed);
|
|
467
|
+
}
|
|
466
468
|
receipt = flashbotsReceipt;
|
|
467
469
|
} else {
|
|
468
470
|
receipt = await this.sendContractTx(params.chain, aggregator, "multiSwap", [params.user, params.amountInWeis, swapParamsList, params.minAmountOutLists, params.totalMinAmountOut], txReq);
|
|
@@ -483,11 +485,7 @@ var _Aggregator = class {
|
|
|
483
485
|
}
|
|
484
486
|
if (!amountOutList)
|
|
485
487
|
throw new Error(`MultiSwapped event not found: ${receipt.hash}`);
|
|
486
|
-
_Aggregator.traceLog(
|
|
487
|
-
params.chain,
|
|
488
|
-
"log",
|
|
489
|
-
`multiSwap完成, txHash=${receipt.hash}, amountOutList=[${amountOutList.join(",")}], useBundle=${useBundle}, 总耗时=${Date.now() - startTs}ms`
|
|
490
|
-
);
|
|
488
|
+
_Aggregator.traceLog(params.chain, "log", `multiSwap完成, txHash=${receipt.hash}, amountOutList=[${amountOutList.join(",")}], useBundle=${useBundle}, 总耗时=${Date.now() - startTs}ms`);
|
|
491
489
|
return {
|
|
492
490
|
hash: receipt.hash,
|
|
493
491
|
from: receipt.from,
|
|
@@ -553,11 +551,18 @@ var _Aggregator = class {
|
|
|
553
551
|
let receipt;
|
|
554
552
|
if (useBundle) {
|
|
555
553
|
const calldata = iface.encodeFunctionData("batchMultiSwap", [params.users, params.amountInWeis, swapParamsList, params.minAmountOutLists]);
|
|
556
|
-
const {
|
|
554
|
+
const {
|
|
555
|
+
receipt: flashbotsReceipt,
|
|
556
|
+
txHash: bundleTxHash,
|
|
557
|
+
targetBlocks
|
|
558
|
+
} = await this.submitBundleTx(params.chain, wallet, txReq, aggregatorAddress, calldata, txReq.value ?? 0n, bundleBlockCount);
|
|
557
559
|
txHash = bundleTxHash;
|
|
558
560
|
if (!flashbotsReceipt) {
|
|
559
561
|
throw new import_types.BundleNotIncludedError(`Bundle 未在目标区块上链, txHash=${bundleTxHash}, targetBlocks=[${targetBlocks.join(",")}]`, bundleTxHash);
|
|
560
562
|
}
|
|
563
|
+
if (flashbotsReceipt.status === 0) {
|
|
564
|
+
throw new import_types.TransactionRevertedError(flashbotsReceipt.hash, flashbotsReceipt.gasUsed);
|
|
565
|
+
}
|
|
561
566
|
receipt = flashbotsReceipt;
|
|
562
567
|
} else {
|
|
563
568
|
receipt = await this.sendContractTx(params.chain, aggregator, "batchMultiSwap", [params.users, params.amountInWeis, swapParamsList, params.minAmountOutLists], txReq);
|
|
@@ -585,11 +590,7 @@ var _Aggregator = class {
|
|
|
585
590
|
if (userList.length !== params.users.length || amountOutList.length !== params.users.length) {
|
|
586
591
|
throw new Error(`MultiSwapped event length mismatch: ${receipt.hash}`);
|
|
587
592
|
}
|
|
588
|
-
_Aggregator.traceLog(
|
|
589
|
-
params.chain,
|
|
590
|
-
"log",
|
|
591
|
-
`batchMultiSwap完成, txHash=${receipt.hash}, amountOutList=[${amountOutList.join(",")}], useBundle=${useBundle}, 总耗时=${Date.now() - startTs}ms`
|
|
592
|
-
);
|
|
593
|
+
_Aggregator.traceLog(params.chain, "log", `batchMultiSwap完成, txHash=${receipt.hash}, amountOutList=[${amountOutList.join(",")}], useBundle=${useBundle}, 总耗时=${Date.now() - startTs}ms`);
|
|
593
594
|
return {
|
|
594
595
|
hash: receipt.hash,
|
|
595
596
|
from: receipt.from,
|
|
@@ -684,21 +685,24 @@ var _Aggregator = class {
|
|
|
684
685
|
if (useBundle) {
|
|
685
686
|
const iface = new import_ethers.ethers.Interface(import_aggregator.default);
|
|
686
687
|
const calldata = iface.encodeFunctionData("bridge", [params.user, bridgeArgs]);
|
|
687
|
-
const {
|
|
688
|
+
const {
|
|
689
|
+
receipt: flashbotsReceipt,
|
|
690
|
+
txHash: bundleTxHash,
|
|
691
|
+
targetBlocks
|
|
692
|
+
} = await this.submitBundleTx(params.chain, wallet, txReq, aggregatorAddress, calldata, txReq.value ?? 0n, bundleBlockCount);
|
|
688
693
|
txHash = bundleTxHash;
|
|
689
694
|
if (!flashbotsReceipt) {
|
|
690
695
|
throw new import_types.BundleNotIncludedError(`Bundle 未在目标区块上链, txHash=${bundleTxHash}, targetBlocks=[${targetBlocks.join(",")}]`, bundleTxHash);
|
|
691
696
|
}
|
|
697
|
+
if (flashbotsReceipt.status === 0) {
|
|
698
|
+
throw new import_types.TransactionRevertedError(flashbotsReceipt.hash, flashbotsReceipt.gasUsed);
|
|
699
|
+
}
|
|
692
700
|
txReceipt = flashbotsReceipt;
|
|
693
701
|
} else {
|
|
694
702
|
txReceipt = await this.sendContractTx(params.chain, aggregator, "bridge", [params.user, bridgeArgs], txReq);
|
|
695
703
|
txHash = txReceipt.hash;
|
|
696
704
|
}
|
|
697
|
-
_Aggregator.traceLog(
|
|
698
|
-
params.chain,
|
|
699
|
-
"log",
|
|
700
|
-
`bridge完成, txHash=${txReceipt.hash}, useBundle=${useBundle}, 总耗时=${Date.now() - startTs}ms`
|
|
701
|
-
);
|
|
705
|
+
_Aggregator.traceLog(params.chain, "log", `bridge完成, txHash=${txReceipt.hash}, useBundle=${useBundle}, 总耗时=${Date.now() - startTs}ms`);
|
|
702
706
|
return {
|
|
703
707
|
fromToken: params.tokenAddress,
|
|
704
708
|
toToken: params.tokenAddress,
|
|
@@ -954,7 +958,10 @@ var _Aggregator = class {
|
|
|
954
958
|
const receipt2 = await txResponse.wait();
|
|
955
959
|
const singleProvider = this.providerClient.getProvider(chain);
|
|
956
960
|
const blockTs2 = await this.getBlockTimestampStr(singleProvider, receipt2.blockNumber);
|
|
957
|
-
_Aggregator.traceLog(chain, "log", `单RPC上链确认, txHash=${receipt2.hash}, blockNumber=${receipt2.blockNumber}, 出块时间=${blockTs2}, gasUsed=${receipt2.gasUsed}`);
|
|
961
|
+
_Aggregator.traceLog(chain, "log", `单RPC上链确认, txHash=${receipt2.hash}, blockNumber=${receipt2.blockNumber}, 出块时间=${blockTs2}, gasUsed=${receipt2.gasUsed}, status=${receipt2.status}`);
|
|
962
|
+
if (receipt2.status === 0) {
|
|
963
|
+
throw new import_types.TransactionRevertedError(receipt2.hash, receipt2.gasUsed);
|
|
964
|
+
}
|
|
958
965
|
return receipt2;
|
|
959
966
|
}
|
|
960
967
|
const wallet = this.providerClient.getWallet(chain);
|
|
@@ -970,10 +977,7 @@ var _Aggregator = class {
|
|
|
970
977
|
provider: new import_ethers.ethers.JsonRpcProvider(url),
|
|
971
978
|
label: `RPC[${i + 1}/${new URL(url).hostname}]`
|
|
972
979
|
}));
|
|
973
|
-
const allProviders = [
|
|
974
|
-
{ provider: mainProvider, label: "RPC[0/主]" },
|
|
975
|
-
...extraProviders
|
|
976
|
-
];
|
|
980
|
+
const allProviders = [{ provider: mainProvider, label: "RPC[0/主]" }, ...extraProviders];
|
|
977
981
|
const ownedProviders = extraProviders.map((e) => e.provider);
|
|
978
982
|
_Aggregator.traceLog(
|
|
979
983
|
chain,
|
|
@@ -987,8 +991,11 @@ var _Aggregator = class {
|
|
|
987
991
|
_Aggregator.traceLog(
|
|
988
992
|
chain,
|
|
989
993
|
"log",
|
|
990
|
-
`多RPC广播上链确认, txHash=${receipt.hash}, blockNumber=${receipt.blockNumber}, 出块时间=${blockTs}, gasUsed=${receipt.gasUsed}, 总耗时=${Date.now() - broadcastTs}ms`
|
|
994
|
+
`多RPC广播上链确认, txHash=${receipt.hash}, blockNumber=${receipt.blockNumber}, 出块时间=${blockTs}, gasUsed=${receipt.gasUsed}, status=${receipt.status}, 总耗时=${Date.now() - broadcastTs}ms`
|
|
991
995
|
);
|
|
996
|
+
if (receipt.status === 0) {
|
|
997
|
+
throw new import_types.TransactionRevertedError(receipt.hash, receipt.gasUsed);
|
|
998
|
+
}
|
|
992
999
|
return receipt;
|
|
993
1000
|
}
|
|
994
1001
|
async submitBundleTx(chain, wallet, txReq, to, data, value, bundleBlockCount) {
|
|
@@ -1018,10 +1025,7 @@ var _Aggregator = class {
|
|
|
1018
1025
|
baseTx.gasPrice = txReq.gasPrice;
|
|
1019
1026
|
baseTx.type = 0;
|
|
1020
1027
|
}
|
|
1021
|
-
const [signTx, currentBlock] = await Promise.all([
|
|
1022
|
-
wallet.signTransaction(baseTx),
|
|
1023
|
-
provider.getBlockNumber()
|
|
1024
|
-
]);
|
|
1028
|
+
const [signTx, currentBlock] = await Promise.all([wallet.signTransaction(baseTx), provider.getBlockNumber()]);
|
|
1025
1029
|
const rawTxs = [signTx];
|
|
1026
1030
|
const txHash = import_ethers.ethers.keccak256(rawTxs[0]);
|
|
1027
1031
|
const normalizedBundleBlockCount = this.normalizeBundleBlockCount(bundleBlockCount);
|
|
@@ -1064,11 +1068,7 @@ var _Aggregator = class {
|
|
|
1064
1068
|
const [receipt] = await Promise.all([
|
|
1065
1069
|
inclusionPromise,
|
|
1066
1070
|
Promise.all(fireAndForget).then(() => {
|
|
1067
|
-
_Aggregator.traceLog(
|
|
1068
|
-
chain,
|
|
1069
|
-
"log",
|
|
1070
|
-
`Bundle发送完成, 成功=${totalSent}, 失败=${totalFailed}, 总请求=${fireAndForget.length}, 耗时=${Date.now() - sendBundleTs}ms, txHash=${txHash}`
|
|
1071
|
-
);
|
|
1071
|
+
_Aggregator.traceLog(chain, "log", `Bundle发送完成, 成功=${totalSent}, 失败=${totalFailed}, 总请求=${fireAndForget.length}, 耗时=${Date.now() - sendBundleTs}ms, txHash=${txHash}`);
|
|
1072
1072
|
if (totalSent === 0)
|
|
1073
1073
|
abortController.abort();
|
|
1074
1074
|
})
|
|
@@ -1081,11 +1081,7 @@ var _Aggregator = class {
|
|
|
1081
1081
|
`Bundle上链确认, txHash=${receipt.hash}, blockNumber=${receipt.blockNumber}, 出块时间=${blockTs}, gasUsed=${receipt.gasUsed}, 等待耗时=${Date.now() - waitTs}ms`
|
|
1082
1082
|
);
|
|
1083
1083
|
} else {
|
|
1084
|
-
_Aggregator.traceLog(
|
|
1085
|
-
chain,
|
|
1086
|
-
"warn",
|
|
1087
|
-
`Bundle未在目标区块上链, txHash=${txHash}, 目标区块=[${targetBlocks.join(",")}], 等待耗时=${Date.now() - waitTs}ms`
|
|
1088
|
-
);
|
|
1084
|
+
_Aggregator.traceLog(chain, "warn", `Bundle未在目标区块上链, txHash=${txHash}, 目标区块=[${targetBlocks.join(",")}], 等待耗时=${Date.now() - waitTs}ms`);
|
|
1089
1085
|
}
|
|
1090
1086
|
return { receipt, txHash, targetBlocks };
|
|
1091
1087
|
}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -40,6 +40,7 @@ __export(src_exports, {
|
|
|
40
40
|
LayerZeroV1ChainNameMap: () => import_types.LayerZeroV1ChainNameMap,
|
|
41
41
|
LayerZeroV2ChainIdMap: () => import_types.LayerZeroV2ChainIdMap,
|
|
42
42
|
LayerZeroV2ChainNameMap: () => import_types.LayerZeroV2ChainNameMap,
|
|
43
|
+
TransactionRevertedError: () => import_types2.TransactionRevertedError,
|
|
43
44
|
default: () => src_default
|
|
44
45
|
});
|
|
45
46
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -144,5 +145,6 @@ var src_default = Hermes;
|
|
|
144
145
|
LayerZeroV1ChainIdMap,
|
|
145
146
|
LayerZeroV1ChainNameMap,
|
|
146
147
|
LayerZeroV2ChainIdMap,
|
|
147
|
-
LayerZeroV2ChainNameMap
|
|
148
|
+
LayerZeroV2ChainNameMap,
|
|
149
|
+
TransactionRevertedError
|
|
148
150
|
});
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import type { HermesTxRequest, IBatchMultiSwapParams, IBatchExpectParams, ISwapB
|
|
|
2
2
|
import { ChainNameEnum, AddressConst, DexType, BridgeType, IEstimateType, LayerZeroV1ChainIdMap, LayerZeroV1ChainNameMap, LayerZeroV2ChainIdMap, LayerZeroV2ChainNameMap } from './types.js';
|
|
3
3
|
import { TransactionRequest } from 'ethers';
|
|
4
4
|
export type { HermesTxRequest, IBatchMultiSwapAndBridgeParams, IExpectSplitOrderParams, IExpectSplitOrderResp, IMultiSwapParams, IBatchMultiSwapParams, IBatchExpectParams, IBatchReceipt, ISwapByPathParams as ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, IBuilderConfig, IExpectPayload, IRouterPath, SupportContracts, IHermesSignalResponse, IHermesSignalRoute, };
|
|
5
|
-
import { BundleNotIncludedError } from './types.js';
|
|
6
|
-
export { ChainNameEnum, AddressConst, DexType, BridgeType, IEstimateType, LayerZeroV1ChainIdMap, LayerZeroV1ChainNameMap, LayerZeroV2ChainIdMap, LayerZeroV2ChainNameMap, BundleNotIncludedError };
|
|
5
|
+
import { BundleNotIncludedError, TransactionRevertedError } from './types.js';
|
|
6
|
+
export { ChainNameEnum, AddressConst, DexType, BridgeType, IEstimateType, LayerZeroV1ChainIdMap, LayerZeroV1ChainNameMap, LayerZeroV2ChainIdMap, LayerZeroV2ChainNameMap, BundleNotIncludedError, TransactionRevertedError };
|
|
7
7
|
declare class Hermes {
|
|
8
8
|
private readonly config;
|
|
9
9
|
private readonly providerClient;
|
package/dist/cjs/types.cjs
CHANGED
|
@@ -28,7 +28,8 @@ __export(types_exports, {
|
|
|
28
28
|
LayerZeroV1ChainIdMap: () => LayerZeroV1ChainIdMap,
|
|
29
29
|
LayerZeroV1ChainNameMap: () => LayerZeroV1ChainNameMap,
|
|
30
30
|
LayerZeroV2ChainIdMap: () => LayerZeroV2ChainIdMap,
|
|
31
|
-
LayerZeroV2ChainNameMap: () => LayerZeroV2ChainNameMap
|
|
31
|
+
LayerZeroV2ChainNameMap: () => LayerZeroV2ChainNameMap,
|
|
32
|
+
TransactionRevertedError: () => TransactionRevertedError
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(types_exports);
|
|
34
35
|
var import_lz_definitions = require("@layerzerolabs/lz-definitions");
|
|
@@ -1050,6 +1051,14 @@ var BundleNotIncludedError = class extends Error {
|
|
|
1050
1051
|
this.txHash = txHash;
|
|
1051
1052
|
}
|
|
1052
1053
|
};
|
|
1054
|
+
var TransactionRevertedError = class extends Error {
|
|
1055
|
+
constructor(txHash, gasUsed) {
|
|
1056
|
+
super(`Transaction reverted: ${txHash}, gasUsed=${gasUsed}`);
|
|
1057
|
+
this.name = "TransactionRevertedError";
|
|
1058
|
+
this.txHash = txHash;
|
|
1059
|
+
this.gasUsed = gasUsed;
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1053
1062
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1054
1063
|
0 && (module.exports = {
|
|
1055
1064
|
AddressConst,
|
|
@@ -1061,5 +1070,6 @@ var BundleNotIncludedError = class extends Error {
|
|
|
1061
1070
|
LayerZeroV1ChainIdMap,
|
|
1062
1071
|
LayerZeroV1ChainNameMap,
|
|
1063
1072
|
LayerZeroV2ChainIdMap,
|
|
1064
|
-
LayerZeroV2ChainNameMap
|
|
1073
|
+
LayerZeroV2ChainNameMap,
|
|
1074
|
+
TransactionRevertedError
|
|
1065
1075
|
});
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -516,3 +516,8 @@ export declare class BundleNotIncludedError extends Error {
|
|
|
516
516
|
readonly txHash: string;
|
|
517
517
|
constructor(message: string, txHash: string);
|
|
518
518
|
}
|
|
519
|
+
export declare class TransactionRevertedError extends Error {
|
|
520
|
+
readonly txHash: string;
|
|
521
|
+
readonly gasUsed: bigint;
|
|
522
|
+
constructor(txHash: string, gasUsed: bigint);
|
|
523
|
+
}
|
package/dist/esm/aggregator.mjs
CHANGED
|
@@ -34,7 +34,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
34
34
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
35
35
|
import { AbiCoder, Contract, ethers } from 'ethers';
|
|
36
36
|
import axios from 'axios';
|
|
37
|
-
import { ChainNameEnum, IEstimateType, BundleNotIncludedError } from "./types.mjs";
|
|
37
|
+
import { ChainNameEnum, IEstimateType, BundleNotIncludedError, TransactionRevertedError } from "./types.mjs";
|
|
38
38
|
import AggregatorAbi from "./abis/aggregator.mjs";
|
|
39
39
|
import Provider from "./provider.mjs";
|
|
40
40
|
import Quoter from "./quoter.mjs";
|
|
@@ -681,7 +681,7 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
681
681
|
txReq = _context7.sent;
|
|
682
682
|
iface = new ethers.Interface(AggregatorAbi);
|
|
683
683
|
if (!useBundle) {
|
|
684
|
-
_context7.next =
|
|
684
|
+
_context7.next = 54;
|
|
685
685
|
break;
|
|
686
686
|
}
|
|
687
687
|
calldata = iface.encodeFunctionData('multiSwapAndBridge', args);
|
|
@@ -699,69 +699,75 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
699
699
|
}
|
|
700
700
|
throw new BundleNotIncludedError("Bundle \u672A\u5728\u76EE\u6807\u533A\u5757\u4E0A\u94FE, txHash=".concat(bundleTxHash, ", targetBlocks=[").concat(targetBlocks.join(','), "]"), bundleTxHash);
|
|
701
701
|
case 49:
|
|
702
|
+
if (!(flashbotsReceipt.status === 0)) {
|
|
703
|
+
_context7.next = 51;
|
|
704
|
+
break;
|
|
705
|
+
}
|
|
706
|
+
throw new TransactionRevertedError(flashbotsReceipt.hash, flashbotsReceipt.gasUsed);
|
|
707
|
+
case 51:
|
|
702
708
|
receipt = flashbotsReceipt;
|
|
703
|
-
_context7.next =
|
|
709
|
+
_context7.next = 58;
|
|
704
710
|
break;
|
|
705
|
-
case 52:
|
|
706
|
-
_context7.next = 54;
|
|
707
|
-
return this.sendContractTx(params.chain, aggregator, 'multiSwapAndBridge', args, txReq);
|
|
708
711
|
case 54:
|
|
712
|
+
_context7.next = 56;
|
|
713
|
+
return this.sendContractTx(params.chain, aggregator, 'multiSwapAndBridge', args, txReq);
|
|
714
|
+
case 56:
|
|
709
715
|
receipt = _context7.sent;
|
|
710
716
|
txHash = receipt.hash;
|
|
711
|
-
case
|
|
717
|
+
case 58:
|
|
712
718
|
receiptUser = null;
|
|
713
719
|
amountInList = null;
|
|
714
720
|
amountOut = null;
|
|
715
721
|
_iterator2 = _createForOfIteratorHelper(receipt.logs);
|
|
716
|
-
_context7.prev =
|
|
722
|
+
_context7.prev = 62;
|
|
717
723
|
_iterator2.s();
|
|
718
|
-
case
|
|
724
|
+
case 64:
|
|
719
725
|
if ((_step2 = _iterator2.n()).done) {
|
|
720
|
-
_context7.next =
|
|
726
|
+
_context7.next = 80;
|
|
721
727
|
break;
|
|
722
728
|
}
|
|
723
729
|
log = _step2.value;
|
|
724
730
|
if (!(log.address.toLowerCase() === aggregatorAddress.toLowerCase())) {
|
|
725
|
-
_context7.next =
|
|
731
|
+
_context7.next = 78;
|
|
726
732
|
break;
|
|
727
733
|
}
|
|
728
|
-
_context7.prev =
|
|
734
|
+
_context7.prev = 67;
|
|
729
735
|
parsed = iface.parseLog(log);
|
|
730
736
|
if (!(parsed && parsed.name === 'MultiSwapAndBridge' && parsed.args)) {
|
|
731
|
-
_context7.next =
|
|
737
|
+
_context7.next = 74;
|
|
732
738
|
break;
|
|
733
739
|
}
|
|
734
740
|
receiptUser = parsed.args.user;
|
|
735
741
|
amountInList = parsed.args.amountInList;
|
|
736
742
|
amountOut = parsed.args.amountOut;
|
|
737
|
-
return _context7.abrupt("break",
|
|
738
|
-
case 72:
|
|
739
|
-
_context7.next = 76;
|
|
740
|
-
break;
|
|
743
|
+
return _context7.abrupt("break", 80);
|
|
741
744
|
case 74:
|
|
742
|
-
_context7.
|
|
743
|
-
_context7.t1 = _context7["catch"](65);
|
|
744
|
-
case 76:
|
|
745
|
-
_context7.next = 62;
|
|
745
|
+
_context7.next = 78;
|
|
746
746
|
break;
|
|
747
|
+
case 76:
|
|
748
|
+
_context7.prev = 76;
|
|
749
|
+
_context7.t1 = _context7["catch"](67);
|
|
747
750
|
case 78:
|
|
748
|
-
_context7.next =
|
|
751
|
+
_context7.next = 64;
|
|
749
752
|
break;
|
|
750
753
|
case 80:
|
|
751
|
-
_context7.
|
|
752
|
-
|
|
754
|
+
_context7.next = 85;
|
|
755
|
+
break;
|
|
756
|
+
case 82:
|
|
757
|
+
_context7.prev = 82;
|
|
758
|
+
_context7.t2 = _context7["catch"](62);
|
|
753
759
|
_iterator2.e(_context7.t2);
|
|
754
|
-
case
|
|
755
|
-
_context7.prev =
|
|
760
|
+
case 85:
|
|
761
|
+
_context7.prev = 85;
|
|
756
762
|
_iterator2.f();
|
|
757
|
-
return _context7.finish(
|
|
758
|
-
case
|
|
763
|
+
return _context7.finish(85);
|
|
764
|
+
case 88:
|
|
759
765
|
if (!(!receiptUser || !amountInList || amountOut == null)) {
|
|
760
|
-
_context7.next =
|
|
766
|
+
_context7.next = 90;
|
|
761
767
|
break;
|
|
762
768
|
}
|
|
763
769
|
throw new Error("MultiSwapAndBridge event not found: ".concat(receipt.hash));
|
|
764
|
-
case
|
|
770
|
+
case 90:
|
|
765
771
|
pathStart = params.paths[0];
|
|
766
772
|
pathEnd = params.paths[params.paths.length - 1];
|
|
767
773
|
fromTokenAddress = (_pathStart$0$fromCoin = pathStart === null || pathStart === void 0 || (_pathStart$ = pathStart[0]) === null || _pathStart$ === void 0 ? void 0 : _pathStart$.fromCoinAddress) !== null && _pathStart$0$fromCoin !== void 0 ? _pathStart$0$fromCoin : '';
|
|
@@ -783,16 +789,16 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
783
789
|
}],
|
|
784
790
|
receipt: receipt
|
|
785
791
|
});
|
|
786
|
-
case
|
|
787
|
-
_context7.prev =
|
|
792
|
+
case 99:
|
|
793
|
+
_context7.prev = 99;
|
|
788
794
|
_context7.t3 = _context7["catch"](4);
|
|
789
795
|
Aggregator.traceLog(params.chain, 'error', "swapAndBridge\u5F02\u5E38, rpcUrl=".concat(this.getRpcUrl(params.chain), ", txHash=").concat((_txHash2 = txHash) !== null && _txHash2 !== void 0 ? _txHash2 : 'N/A', ", \u603B\u8017\u65F6=").concat(Date.now() - startTs, "ms, error=").concat(_context7.t3));
|
|
790
796
|
throw _context7.t3;
|
|
791
|
-
case
|
|
797
|
+
case 103:
|
|
792
798
|
case "end":
|
|
793
799
|
return _context7.stop();
|
|
794
800
|
}
|
|
795
|
-
}, _callee7, this, [[4,
|
|
801
|
+
}, _callee7, this, [[4, 99], [20, 26], [62, 82, 85, 88], [67, 76]]);
|
|
796
802
|
}));
|
|
797
803
|
function swapAndBridge(_x17) {
|
|
798
804
|
return _swapAndBridge.apply(this, arguments);
|
|
@@ -944,7 +950,7 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
944
950
|
txReq = _context8.sent;
|
|
945
951
|
iface = new ethers.Interface(AggregatorAbi);
|
|
946
952
|
if (!useBundle) {
|
|
947
|
-
_context8.next =
|
|
953
|
+
_context8.next = 69;
|
|
948
954
|
break;
|
|
949
955
|
}
|
|
950
956
|
calldata = iface.encodeFunctionData('multiSwap', [params.user, params.amountInWeis, swapParamsList, params.minAmountOutLists, params.totalMinAmountOut]);
|
|
@@ -962,65 +968,71 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
962
968
|
}
|
|
963
969
|
throw new BundleNotIncludedError("Bundle \u672A\u5728\u76EE\u6807\u533A\u5757\u4E0A\u94FE, txHash=".concat(bundleTxHash, ", targetBlocks=[").concat(targetBlocks.join(','), "]"), bundleTxHash);
|
|
964
970
|
case 64:
|
|
971
|
+
if (!(flashbotsReceipt.status === 0)) {
|
|
972
|
+
_context8.next = 66;
|
|
973
|
+
break;
|
|
974
|
+
}
|
|
975
|
+
throw new TransactionRevertedError(flashbotsReceipt.hash, flashbotsReceipt.gasUsed);
|
|
976
|
+
case 66:
|
|
965
977
|
receipt = flashbotsReceipt;
|
|
966
|
-
_context8.next =
|
|
978
|
+
_context8.next = 73;
|
|
967
979
|
break;
|
|
968
|
-
case 67:
|
|
969
|
-
_context8.next = 69;
|
|
970
|
-
return this.sendContractTx(params.chain, aggregator, 'multiSwap', [params.user, params.amountInWeis, swapParamsList, params.minAmountOutLists, params.totalMinAmountOut], txReq);
|
|
971
980
|
case 69:
|
|
981
|
+
_context8.next = 71;
|
|
982
|
+
return this.sendContractTx(params.chain, aggregator, 'multiSwap', [params.user, params.amountInWeis, swapParamsList, params.minAmountOutLists, params.totalMinAmountOut], txReq);
|
|
983
|
+
case 71:
|
|
972
984
|
receipt = _context8.sent;
|
|
973
985
|
txHash = receipt.hash;
|
|
974
|
-
case
|
|
986
|
+
case 73:
|
|
975
987
|
amountOutList = null;
|
|
976
988
|
_iterator3 = _createForOfIteratorHelper(receipt.logs);
|
|
977
|
-
_context8.prev =
|
|
989
|
+
_context8.prev = 75;
|
|
978
990
|
_iterator3.s();
|
|
979
|
-
case
|
|
991
|
+
case 77:
|
|
980
992
|
if ((_step3 = _iterator3.n()).done) {
|
|
981
|
-
_context8.next =
|
|
993
|
+
_context8.next = 91;
|
|
982
994
|
break;
|
|
983
995
|
}
|
|
984
996
|
log = _step3.value;
|
|
985
997
|
if (!(log.address.toLowerCase() === aggregatorAddress.toLowerCase())) {
|
|
986
|
-
_context8.next =
|
|
998
|
+
_context8.next = 89;
|
|
987
999
|
break;
|
|
988
1000
|
}
|
|
989
|
-
_context8.prev =
|
|
1001
|
+
_context8.prev = 80;
|
|
990
1002
|
parsed = iface.parseLog(log);
|
|
991
1003
|
if (!(parsed && parsed.name === 'MultiSwapped' && parsed.args)) {
|
|
992
|
-
_context8.next =
|
|
1004
|
+
_context8.next = 85;
|
|
993
1005
|
break;
|
|
994
1006
|
}
|
|
995
1007
|
amountOutList = parsed.args.amountOutList;
|
|
996
|
-
return _context8.abrupt("break",
|
|
997
|
-
case 83:
|
|
998
|
-
_context8.next = 87;
|
|
999
|
-
break;
|
|
1008
|
+
return _context8.abrupt("break", 91);
|
|
1000
1009
|
case 85:
|
|
1001
|
-
_context8.
|
|
1002
|
-
_context8.t1 = _context8["catch"](78);
|
|
1003
|
-
case 87:
|
|
1004
|
-
_context8.next = 75;
|
|
1010
|
+
_context8.next = 89;
|
|
1005
1011
|
break;
|
|
1012
|
+
case 87:
|
|
1013
|
+
_context8.prev = 87;
|
|
1014
|
+
_context8.t1 = _context8["catch"](80);
|
|
1006
1015
|
case 89:
|
|
1007
|
-
_context8.next =
|
|
1016
|
+
_context8.next = 77;
|
|
1008
1017
|
break;
|
|
1009
1018
|
case 91:
|
|
1010
|
-
_context8.
|
|
1011
|
-
|
|
1019
|
+
_context8.next = 96;
|
|
1020
|
+
break;
|
|
1021
|
+
case 93:
|
|
1022
|
+
_context8.prev = 93;
|
|
1023
|
+
_context8.t2 = _context8["catch"](75);
|
|
1012
1024
|
_iterator3.e(_context8.t2);
|
|
1013
|
-
case
|
|
1014
|
-
_context8.prev =
|
|
1025
|
+
case 96:
|
|
1026
|
+
_context8.prev = 96;
|
|
1015
1027
|
_iterator3.f();
|
|
1016
|
-
return _context8.finish(
|
|
1017
|
-
case
|
|
1028
|
+
return _context8.finish(96);
|
|
1029
|
+
case 99:
|
|
1018
1030
|
if (amountOutList) {
|
|
1019
|
-
_context8.next =
|
|
1031
|
+
_context8.next = 101;
|
|
1020
1032
|
break;
|
|
1021
1033
|
}
|
|
1022
1034
|
throw new Error("MultiSwapped event not found: ".concat(receipt.hash));
|
|
1023
|
-
case
|
|
1035
|
+
case 101:
|
|
1024
1036
|
Aggregator.traceLog(params.chain, 'log', "multiSwap\u5B8C\u6210, txHash=".concat(receipt.hash, ", amountOutList=[").concat(amountOutList.join(','), "], useBundle=").concat(useBundle, ", \u603B\u8017\u65F6=").concat(Date.now() - startTs, "ms"));
|
|
1025
1037
|
return _context8.abrupt("return", {
|
|
1026
1038
|
hash: receipt.hash,
|
|
@@ -1038,16 +1050,16 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
1038
1050
|
}),
|
|
1039
1051
|
receipt: receipt
|
|
1040
1052
|
});
|
|
1041
|
-
case
|
|
1042
|
-
_context8.prev =
|
|
1053
|
+
case 105:
|
|
1054
|
+
_context8.prev = 105;
|
|
1043
1055
|
_context8.t3 = _context8["catch"](4);
|
|
1044
1056
|
Aggregator.traceLog(params.chain, 'error', "multiSwap\u5F02\u5E38, rpcUrl=".concat(this.getRpcUrl(params.chain), ", txHash=").concat((_txHash3 = txHash) !== null && _txHash3 !== void 0 ? _txHash3 : 'N/A', ", \u603B\u8017\u65F6=").concat(Date.now() - startTs, "ms, error=").concat(_context8.t3));
|
|
1045
1057
|
throw _context8.t3;
|
|
1046
|
-
case
|
|
1058
|
+
case 109:
|
|
1047
1059
|
case "end":
|
|
1048
1060
|
return _context8.stop();
|
|
1049
1061
|
}
|
|
1050
|
-
}, _callee8, this, [[4,
|
|
1062
|
+
}, _callee8, this, [[4, 105], [35, 41], [75, 93, 96, 99], [80, 87]]);
|
|
1051
1063
|
}));
|
|
1052
1064
|
function multiSwap(_x18) {
|
|
1053
1065
|
return _multiSwap.apply(this, arguments);
|
|
@@ -1155,7 +1167,7 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
1155
1167
|
txReq = _context9.sent;
|
|
1156
1168
|
iface = new ethers.Interface(AggregatorAbi);
|
|
1157
1169
|
if (!useBundle) {
|
|
1158
|
-
_context9.next =
|
|
1170
|
+
_context9.next = 51;
|
|
1159
1171
|
break;
|
|
1160
1172
|
}
|
|
1161
1173
|
calldata = iface.encodeFunctionData('batchMultiSwap', [params.users, params.amountInWeis, swapParamsList, params.minAmountOutLists]);
|
|
@@ -1173,75 +1185,81 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
1173
1185
|
}
|
|
1174
1186
|
throw new BundleNotIncludedError("Bundle \u672A\u5728\u76EE\u6807\u533A\u5757\u4E0A\u94FE, txHash=".concat(bundleTxHash, ", targetBlocks=[").concat(targetBlocks.join(','), "]"), bundleTxHash);
|
|
1175
1187
|
case 46:
|
|
1188
|
+
if (!(flashbotsReceipt.status === 0)) {
|
|
1189
|
+
_context9.next = 48;
|
|
1190
|
+
break;
|
|
1191
|
+
}
|
|
1192
|
+
throw new TransactionRevertedError(flashbotsReceipt.hash, flashbotsReceipt.gasUsed);
|
|
1193
|
+
case 48:
|
|
1176
1194
|
receipt = flashbotsReceipt;
|
|
1177
|
-
_context9.next =
|
|
1195
|
+
_context9.next = 55;
|
|
1178
1196
|
break;
|
|
1179
|
-
case 49:
|
|
1180
|
-
_context9.next = 51;
|
|
1181
|
-
return this.sendContractTx(params.chain, aggregator, 'batchMultiSwap', [params.users, params.amountInWeis, swapParamsList, params.minAmountOutLists], txReq);
|
|
1182
1197
|
case 51:
|
|
1198
|
+
_context9.next = 53;
|
|
1199
|
+
return this.sendContractTx(params.chain, aggregator, 'batchMultiSwap', [params.users, params.amountInWeis, swapParamsList, params.minAmountOutLists], txReq);
|
|
1200
|
+
case 53:
|
|
1183
1201
|
receipt = _context9.sent;
|
|
1184
1202
|
txHash = receipt.hash;
|
|
1185
|
-
case
|
|
1203
|
+
case 55:
|
|
1186
1204
|
userList = null;
|
|
1187
1205
|
amountInList = null;
|
|
1188
1206
|
amountOutList = null;
|
|
1189
1207
|
_iterator4 = _createForOfIteratorHelper(receipt.logs);
|
|
1190
|
-
_context9.prev =
|
|
1208
|
+
_context9.prev = 59;
|
|
1191
1209
|
_iterator4.s();
|
|
1192
|
-
case
|
|
1210
|
+
case 61:
|
|
1193
1211
|
if ((_step4 = _iterator4.n()).done) {
|
|
1194
|
-
_context9.next =
|
|
1212
|
+
_context9.next = 77;
|
|
1195
1213
|
break;
|
|
1196
1214
|
}
|
|
1197
1215
|
log = _step4.value;
|
|
1198
1216
|
if (!(log.address.toLowerCase() === aggregatorAddress.toLowerCase())) {
|
|
1199
|
-
_context9.next =
|
|
1217
|
+
_context9.next = 75;
|
|
1200
1218
|
break;
|
|
1201
1219
|
}
|
|
1202
|
-
_context9.prev =
|
|
1220
|
+
_context9.prev = 64;
|
|
1203
1221
|
parsed = iface.parseLog(log);
|
|
1204
1222
|
if (!(parsed && parsed.name === 'BatchMultiSwapped' && parsed.args)) {
|
|
1205
|
-
_context9.next =
|
|
1223
|
+
_context9.next = 71;
|
|
1206
1224
|
break;
|
|
1207
1225
|
}
|
|
1208
1226
|
userList = parsed.args.userList;
|
|
1209
1227
|
amountInList = parsed.args.amountInList;
|
|
1210
1228
|
amountOutList = parsed.args.amountOutList;
|
|
1211
|
-
return _context9.abrupt("break",
|
|
1212
|
-
case 69:
|
|
1213
|
-
_context9.next = 73;
|
|
1214
|
-
break;
|
|
1229
|
+
return _context9.abrupt("break", 77);
|
|
1215
1230
|
case 71:
|
|
1216
|
-
_context9.
|
|
1217
|
-
_context9.t1 = _context9["catch"](62);
|
|
1218
|
-
case 73:
|
|
1219
|
-
_context9.next = 59;
|
|
1231
|
+
_context9.next = 75;
|
|
1220
1232
|
break;
|
|
1233
|
+
case 73:
|
|
1234
|
+
_context9.prev = 73;
|
|
1235
|
+
_context9.t1 = _context9["catch"](64);
|
|
1221
1236
|
case 75:
|
|
1222
|
-
_context9.next =
|
|
1237
|
+
_context9.next = 61;
|
|
1223
1238
|
break;
|
|
1224
1239
|
case 77:
|
|
1225
|
-
_context9.
|
|
1226
|
-
|
|
1240
|
+
_context9.next = 82;
|
|
1241
|
+
break;
|
|
1242
|
+
case 79:
|
|
1243
|
+
_context9.prev = 79;
|
|
1244
|
+
_context9.t2 = _context9["catch"](59);
|
|
1227
1245
|
_iterator4.e(_context9.t2);
|
|
1228
|
-
case
|
|
1229
|
-
_context9.prev =
|
|
1246
|
+
case 82:
|
|
1247
|
+
_context9.prev = 82;
|
|
1230
1248
|
_iterator4.f();
|
|
1231
|
-
return _context9.finish(
|
|
1232
|
-
case
|
|
1249
|
+
return _context9.finish(82);
|
|
1250
|
+
case 85:
|
|
1233
1251
|
if (!(!userList || !amountInList || !amountOutList)) {
|
|
1234
|
-
_context9.next =
|
|
1252
|
+
_context9.next = 87;
|
|
1235
1253
|
break;
|
|
1236
1254
|
}
|
|
1237
1255
|
throw new Error("MultiSwapped event not found: ".concat(receipt.hash));
|
|
1238
|
-
case
|
|
1256
|
+
case 87:
|
|
1239
1257
|
if (!(userList.length !== params.users.length || amountOutList.length !== params.users.length)) {
|
|
1240
|
-
_context9.next =
|
|
1258
|
+
_context9.next = 89;
|
|
1241
1259
|
break;
|
|
1242
1260
|
}
|
|
1243
1261
|
throw new Error("MultiSwapped event length mismatch: ".concat(receipt.hash));
|
|
1244
|
-
case
|
|
1262
|
+
case 89:
|
|
1245
1263
|
Aggregator.traceLog(params.chain, 'log', "batchMultiSwap\u5B8C\u6210, txHash=".concat(receipt.hash, ", amountOutList=[").concat(amountOutList.join(','), "], useBundle=").concat(useBundle, ", \u603B\u8017\u65F6=").concat(Date.now() - startTs, "ms"));
|
|
1246
1264
|
return _context9.abrupt("return", {
|
|
1247
1265
|
hash: receipt.hash,
|
|
@@ -1259,16 +1277,16 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
1259
1277
|
}),
|
|
1260
1278
|
receipt: receipt
|
|
1261
1279
|
});
|
|
1262
|
-
case
|
|
1263
|
-
_context9.prev =
|
|
1280
|
+
case 93:
|
|
1281
|
+
_context9.prev = 93;
|
|
1264
1282
|
_context9.t3 = _context9["catch"](4);
|
|
1265
1283
|
Aggregator.traceLog(params.chain, 'error', "batchMultiSwap\u5F02\u5E38, rpcUrl=".concat(this.getRpcUrl(params.chain), ", txHash=").concat((_txHash4 = txHash) !== null && _txHash4 !== void 0 ? _txHash4 : 'N/A', ", \u603B\u8017\u65F6=").concat(Date.now() - startTs, "ms, error=").concat(_context9.t3));
|
|
1266
1284
|
throw _context9.t3;
|
|
1267
|
-
case
|
|
1285
|
+
case 97:
|
|
1268
1286
|
case "end":
|
|
1269
1287
|
return _context9.stop();
|
|
1270
1288
|
}
|
|
1271
|
-
}, _callee9, this, [[4,
|
|
1289
|
+
}, _callee9, this, [[4, 93], [17, 23], [59, 79, 82, 85], [64, 73]]);
|
|
1272
1290
|
}));
|
|
1273
1291
|
function batchMultiSwap(_x19) {
|
|
1274
1292
|
return _batchMultiSwap.apply(this, arguments);
|
|
@@ -1445,7 +1463,7 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
1445
1463
|
case 39:
|
|
1446
1464
|
txReq = _context11.sent;
|
|
1447
1465
|
if (!useBundle) {
|
|
1448
|
-
_context11.next =
|
|
1466
|
+
_context11.next = 57;
|
|
1449
1467
|
break;
|
|
1450
1468
|
}
|
|
1451
1469
|
iface = new ethers.Interface(AggregatorAbi);
|
|
@@ -1464,16 +1482,22 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
1464
1482
|
}
|
|
1465
1483
|
throw new BundleNotIncludedError("Bundle \u672A\u5728\u76EE\u6807\u533A\u5757\u4E0A\u94FE, txHash=".concat(bundleTxHash, ", targetBlocks=[").concat(targetBlocks.join(','), "]"), bundleTxHash);
|
|
1466
1484
|
case 52:
|
|
1485
|
+
if (!(flashbotsReceipt.status === 0)) {
|
|
1486
|
+
_context11.next = 54;
|
|
1487
|
+
break;
|
|
1488
|
+
}
|
|
1489
|
+
throw new TransactionRevertedError(flashbotsReceipt.hash, flashbotsReceipt.gasUsed);
|
|
1490
|
+
case 54:
|
|
1467
1491
|
txReceipt = flashbotsReceipt;
|
|
1468
|
-
_context11.next =
|
|
1492
|
+
_context11.next = 61;
|
|
1469
1493
|
break;
|
|
1470
|
-
case 55:
|
|
1471
|
-
_context11.next = 57;
|
|
1472
|
-
return this.sendContractTx(params.chain, aggregator, 'bridge', [params.user, bridgeArgs], txReq);
|
|
1473
1494
|
case 57:
|
|
1495
|
+
_context11.next = 59;
|
|
1496
|
+
return this.sendContractTx(params.chain, aggregator, 'bridge', [params.user, bridgeArgs], txReq);
|
|
1497
|
+
case 59:
|
|
1474
1498
|
txReceipt = _context11.sent;
|
|
1475
1499
|
txHash = txReceipt.hash;
|
|
1476
|
-
case
|
|
1500
|
+
case 61:
|
|
1477
1501
|
Aggregator.traceLog(params.chain, 'log', "bridge\u5B8C\u6210, txHash=".concat(txReceipt.hash, ", useBundle=").concat(useBundle, ", \u603B\u8017\u65F6=").concat(Date.now() - startTs, "ms"));
|
|
1478
1502
|
return _context11.abrupt("return", {
|
|
1479
1503
|
fromToken: params.tokenAddress,
|
|
@@ -1483,16 +1507,16 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
1483
1507
|
from: txReceipt.from,
|
|
1484
1508
|
to: (_txReceipt$to = txReceipt.to) !== null && _txReceipt$to !== void 0 ? _txReceipt$to : ''
|
|
1485
1509
|
});
|
|
1486
|
-
case
|
|
1487
|
-
_context11.prev =
|
|
1510
|
+
case 65:
|
|
1511
|
+
_context11.prev = 65;
|
|
1488
1512
|
_context11.t1 = _context11["catch"](4);
|
|
1489
1513
|
Aggregator.traceLog(params.chain, 'error', "bridge\u5F02\u5E38, rpcUrl=".concat(this.getRpcUrl(params.chain), ", txHash=").concat((_txHash5 = txHash) !== null && _txHash5 !== void 0 ? _txHash5 : 'N/A', ", \u603B\u8017\u65F6=").concat(Date.now() - startTs, "ms, error=").concat(_context11.t1));
|
|
1490
1514
|
throw _context11.t1;
|
|
1491
|
-
case
|
|
1515
|
+
case 69:
|
|
1492
1516
|
case "end":
|
|
1493
1517
|
return _context11.stop();
|
|
1494
1518
|
}
|
|
1495
|
-
}, _callee11, this, [[4,
|
|
1519
|
+
}, _callee11, this, [[4, 65], [23, 29]]);
|
|
1496
1520
|
}));
|
|
1497
1521
|
function bridge(_x21) {
|
|
1498
1522
|
return _bridge.apply(this, arguments);
|
|
@@ -1887,7 +1911,9 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
1887
1911
|
var p = _step6.value;
|
|
1888
1912
|
try {
|
|
1889
1913
|
p.destroy();
|
|
1890
|
-
} catch (_unused8) {
|
|
1914
|
+
} catch (_unused8) {
|
|
1915
|
+
/* ignore */
|
|
1916
|
+
}
|
|
1891
1917
|
}
|
|
1892
1918
|
} catch (err) {
|
|
1893
1919
|
_iterator6.e(err);
|
|
@@ -1953,7 +1979,7 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
1953
1979
|
case 0:
|
|
1954
1980
|
extraUrls = this.broadcastRpcsMap.get(chain);
|
|
1955
1981
|
if (!(!extraUrls || extraUrls.length === 0)) {
|
|
1956
|
-
_context16.next =
|
|
1982
|
+
_context16.next = 19;
|
|
1957
1983
|
break;
|
|
1958
1984
|
}
|
|
1959
1985
|
Aggregator.traceLog(chain, 'log', "\u6E20\u9053=\u5355RPC\u76F4\u53D1, method=".concat(method, ", nonce=").concat(txReq.nonce, ", gasLimit=").concat(txReq.gasLimit));
|
|
@@ -1972,29 +1998,35 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
1972
1998
|
return this.getBlockTimestampStr(singleProvider, _receipt.blockNumber);
|
|
1973
1999
|
case 14:
|
|
1974
2000
|
_blockTs = _context16.sent;
|
|
1975
|
-
Aggregator.traceLog(chain, 'log', "\u5355RPC\u4E0A\u94FE\u786E\u8BA4, txHash=".concat(_receipt.hash, ", blockNumber=").concat(_receipt.blockNumber, ", \u51FA\u5757\u65F6\u95F4=").concat(_blockTs, ", gasUsed=").concat(_receipt.gasUsed));
|
|
2001
|
+
Aggregator.traceLog(chain, 'log', "\u5355RPC\u4E0A\u94FE\u786E\u8BA4, txHash=".concat(_receipt.hash, ", blockNumber=").concat(_receipt.blockNumber, ", \u51FA\u5757\u65F6\u95F4=").concat(_blockTs, ", gasUsed=").concat(_receipt.gasUsed, ", status=").concat(_receipt.status));
|
|
2002
|
+
if (!(_receipt.status === 0)) {
|
|
2003
|
+
_context16.next = 18;
|
|
2004
|
+
break;
|
|
2005
|
+
}
|
|
2006
|
+
throw new TransactionRevertedError(_receipt.hash, _receipt.gasUsed);
|
|
2007
|
+
case 18:
|
|
1976
2008
|
return _context16.abrupt("return", _receipt);
|
|
1977
|
-
case
|
|
2009
|
+
case 19:
|
|
1978
2010
|
wallet = this.providerClient.getWallet(chain);
|
|
1979
|
-
_context16.next =
|
|
2011
|
+
_context16.next = 22;
|
|
1980
2012
|
return (_method = contract[method]).populateTransaction.apply(_method, _toConsumableArray(args).concat([txReq]));
|
|
1981
|
-
case
|
|
2013
|
+
case 22:
|
|
1982
2014
|
populated = _context16.sent;
|
|
1983
2015
|
delete populated.from;
|
|
1984
|
-
_context16.next =
|
|
2016
|
+
_context16.next = 26;
|
|
1985
2017
|
return wallet.provider.getNetwork();
|
|
1986
|
-
case
|
|
2018
|
+
case 26:
|
|
1987
2019
|
network = _context16.sent;
|
|
1988
2020
|
populated.chainId = network.chainId;
|
|
1989
|
-
_context16.next =
|
|
2021
|
+
_context16.next = 30;
|
|
1990
2022
|
return wallet.signTransaction(populated);
|
|
1991
|
-
case
|
|
2023
|
+
case 30:
|
|
1992
2024
|
signedTx = _context16.sent;
|
|
1993
2025
|
txHash = ethers.keccak256(signedTx);
|
|
1994
2026
|
mainProvider = wallet.provider;
|
|
1995
|
-
_context16.next =
|
|
2027
|
+
_context16.next = 35;
|
|
1996
2028
|
return mainProvider.getBlockNumber();
|
|
1997
|
-
case
|
|
2029
|
+
case 35:
|
|
1998
2030
|
currentBlock = _context16.sent;
|
|
1999
2031
|
extraProviders = extraUrls.map(function (url, i) {
|
|
2000
2032
|
return {
|
|
@@ -2012,17 +2044,23 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
2012
2044
|
Aggregator.traceLog(chain, 'log', "\u6E20\u9053=\u591ARPC\u5E7F\u64AD, method=".concat(method, ", nonce=").concat(txReq.nonce, ", gasLimit=").concat(txReq.gasLimit, ", ") + "\u5F53\u524D\u533A\u5757=".concat(currentBlock, ", \u671F\u671B\u4E0A\u94FE\u533A\u5757=").concat(currentBlock + 1, ", txHash=").concat(txHash, ", ") + "RPC\u6570\u91CF=".concat(allProviders.length, "(\u4E3B1+\u526F").concat(extraUrls.length, ")"));
|
|
2013
2045
|
broadcastTs = Date.now();
|
|
2014
2046
|
this.broadcastToAll(chain, signedTx, txHash, allProviders);
|
|
2015
|
-
_context16.next =
|
|
2047
|
+
_context16.next = 44;
|
|
2016
2048
|
return this.raceForReceipt(chain, txHash, allProviders, ownedProviders);
|
|
2017
|
-
case
|
|
2049
|
+
case 44:
|
|
2018
2050
|
receipt = _context16.sent;
|
|
2019
|
-
_context16.next =
|
|
2051
|
+
_context16.next = 47;
|
|
2020
2052
|
return this.getBlockTimestampStr(mainProvider, receipt.blockNumber);
|
|
2021
|
-
case
|
|
2053
|
+
case 47:
|
|
2022
2054
|
blockTs = _context16.sent;
|
|
2023
|
-
Aggregator.traceLog(chain, 'log', "\u591ARPC\u5E7F\u64AD\u4E0A\u94FE\u786E\u8BA4, txHash=".concat(receipt.hash, ", blockNumber=").concat(receipt.blockNumber, ", \u51FA\u5757\u65F6\u95F4=").concat(blockTs, ", gasUsed=").concat(receipt.gasUsed, ", ") + "\u603B\u8017\u65F6=".concat(Date.now() - broadcastTs, "ms"));
|
|
2055
|
+
Aggregator.traceLog(chain, 'log', "\u591ARPC\u5E7F\u64AD\u4E0A\u94FE\u786E\u8BA4, txHash=".concat(receipt.hash, ", blockNumber=").concat(receipt.blockNumber, ", \u51FA\u5757\u65F6\u95F4=").concat(blockTs, ", gasUsed=").concat(receipt.gasUsed, ", status=").concat(receipt.status, ", ") + "\u603B\u8017\u65F6=".concat(Date.now() - broadcastTs, "ms"));
|
|
2056
|
+
if (!(receipt.status === 0)) {
|
|
2057
|
+
_context16.next = 51;
|
|
2058
|
+
break;
|
|
2059
|
+
}
|
|
2060
|
+
throw new TransactionRevertedError(receipt.hash, receipt.gasUsed);
|
|
2061
|
+
case 51:
|
|
2024
2062
|
return _context16.abrupt("return", receipt);
|
|
2025
|
-
case
|
|
2063
|
+
case 52:
|
|
2026
2064
|
case "end":
|
|
2027
2065
|
return _context16.stop();
|
|
2028
2066
|
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import type { HermesTxRequest, IBatchMultiSwapParams, IBatchExpectParams, ISwapB
|
|
|
2
2
|
import { ChainNameEnum, AddressConst, DexType, BridgeType, IEstimateType, LayerZeroV1ChainIdMap, LayerZeroV1ChainNameMap, LayerZeroV2ChainIdMap, LayerZeroV2ChainNameMap } from './types.js';
|
|
3
3
|
import { TransactionRequest } from 'ethers';
|
|
4
4
|
export type { HermesTxRequest, IBatchMultiSwapAndBridgeParams, IExpectSplitOrderParams, IExpectSplitOrderResp, IMultiSwapParams, IBatchMultiSwapParams, IBatchExpectParams, IBatchReceipt, ISwapByPathParams as ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, IBuilderConfig, IExpectPayload, IRouterPath, SupportContracts, IHermesSignalResponse, IHermesSignalRoute, };
|
|
5
|
-
import { BundleNotIncludedError } from './types.js';
|
|
6
|
-
export { ChainNameEnum, AddressConst, DexType, BridgeType, IEstimateType, LayerZeroV1ChainIdMap, LayerZeroV1ChainNameMap, LayerZeroV2ChainIdMap, LayerZeroV2ChainNameMap, BundleNotIncludedError };
|
|
5
|
+
import { BundleNotIncludedError, TransactionRevertedError } from './types.js';
|
|
6
|
+
export { ChainNameEnum, AddressConst, DexType, BridgeType, IEstimateType, LayerZeroV1ChainIdMap, LayerZeroV1ChainNameMap, LayerZeroV2ChainIdMap, LayerZeroV2ChainNameMap, BundleNotIncludedError, TransactionRevertedError };
|
|
7
7
|
declare class Hermes {
|
|
8
8
|
private readonly config;
|
|
9
9
|
private readonly providerClient;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -15,8 +15,8 @@ import Provider from "./provider.mjs";
|
|
|
15
15
|
|
|
16
16
|
// 导出所有类型定义,方便用户使用
|
|
17
17
|
|
|
18
|
-
import { BundleNotIncludedError } from "./types.mjs";
|
|
19
|
-
export { ChainNameEnum, AddressConst, DexType, BridgeType, IEstimateType, LayerZeroV1ChainIdMap, LayerZeroV1ChainNameMap, LayerZeroV2ChainIdMap, LayerZeroV2ChainNameMap, BundleNotIncludedError };
|
|
18
|
+
import { BundleNotIncludedError, TransactionRevertedError } from "./types.mjs";
|
|
19
|
+
export { ChainNameEnum, AddressConst, DexType, BridgeType, IEstimateType, LayerZeroV1ChainIdMap, LayerZeroV1ChainNameMap, LayerZeroV2ChainIdMap, LayerZeroV2ChainNameMap, BundleNotIncludedError, TransactionRevertedError };
|
|
20
20
|
var Hermes = /*#__PURE__*/function () {
|
|
21
21
|
function Hermes(config) {
|
|
22
22
|
_classCallCheck(this, Hermes);
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -516,3 +516,8 @@ export declare class BundleNotIncludedError extends Error {
|
|
|
516
516
|
readonly txHash: string;
|
|
517
517
|
constructor(message: string, txHash: string);
|
|
518
518
|
}
|
|
519
|
+
export declare class TransactionRevertedError extends Error {
|
|
520
|
+
readonly txHash: string;
|
|
521
|
+
readonly gasUsed: bigint;
|
|
522
|
+
constructor(txHash: string, gasUsed: bigint);
|
|
523
|
+
}
|
package/dist/esm/types.mjs
CHANGED
|
@@ -443,4 +443,20 @@ export var BundleNotIncludedError = /*#__PURE__*/function (_Error) {
|
|
|
443
443
|
return _this;
|
|
444
444
|
}
|
|
445
445
|
return _createClass(BundleNotIncludedError);
|
|
446
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
447
|
+
export var TransactionRevertedError = /*#__PURE__*/function (_Error2) {
|
|
448
|
+
_inherits(TransactionRevertedError, _Error2);
|
|
449
|
+
var _super2 = _createSuper(TransactionRevertedError);
|
|
450
|
+
function TransactionRevertedError(txHash, gasUsed) {
|
|
451
|
+
var _this2;
|
|
452
|
+
_classCallCheck(this, TransactionRevertedError);
|
|
453
|
+
_this2 = _super2.call(this, "Transaction reverted: ".concat(txHash, ", gasUsed=").concat(gasUsed));
|
|
454
|
+
_defineProperty(_assertThisInitialized(_this2), "txHash", void 0);
|
|
455
|
+
_defineProperty(_assertThisInitialized(_this2), "gasUsed", void 0);
|
|
456
|
+
_this2.name = 'TransactionRevertedError';
|
|
457
|
+
_this2.txHash = txHash;
|
|
458
|
+
_this2.gasUsed = gasUsed;
|
|
459
|
+
return _this2;
|
|
460
|
+
}
|
|
461
|
+
return _createClass(TransactionRevertedError);
|
|
446
462
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|