hermes-swap 0.6.8 → 0.6.9

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.
@@ -144,6 +144,23 @@ var _Aggregator = class {
144
144
  params: [{ txs: rawTxs, blockNumber: `0x${targetBlock.toString(16)}` }]
145
145
  };
146
146
  }
147
+ buildFlashbotsMevBundleRequestBody(rawTxs, startBlock, endBlock) {
148
+ return {
149
+ jsonrpc: "2.0",
150
+ id: 1,
151
+ method: "mev_sendBundle",
152
+ params: [
153
+ {
154
+ version: "v0.1",
155
+ inclusion: {
156
+ block: `0x${startBlock.toString(16)}`,
157
+ maxBlock: `0x${endBlock.toString(16)}`
158
+ },
159
+ body: rawTxs.map((tx) => ({ tx, canRevert: false }))
160
+ }
161
+ ]
162
+ };
163
+ }
147
164
  async sendBundle(chain, rawTxs, targetBlock, signer) {
148
165
  const builderCfg = this.getBuilderConfig(chain);
149
166
  const body = this.buildBundleRequestBody(builderCfg, rawTxs, targetBlock);
@@ -1098,11 +1115,7 @@ var _Aggregator = class {
1098
1115
  label: `Sequencer[${new URL(sequencerUrl).hostname}]`,
1099
1116
  send: async () => {
1100
1117
  var _a;
1101
- const resp = await import_axios.default.post(
1102
- sequencerUrl,
1103
- { jsonrpc: "2.0", id: 1, method: "eth_sendRawTransaction", params: [signedTx] },
1104
- { timeout: 5e3 }
1105
- );
1118
+ const resp = await import_axios.default.post(sequencerUrl, { jsonrpc: "2.0", id: 1, method: "eth_sendRawTransaction", params: [signedTx] }, { timeout: 5e3 });
1106
1119
  if ((_a = resp.data) == null ? void 0 : _a.error) {
1107
1120
  throw new Error(resp.data.error.message ?? JSON.stringify(resp.data.error));
1108
1121
  }
@@ -1141,15 +1154,16 @@ var _Aggregator = class {
1141
1154
  const broadcastTs2 = Date.now();
1142
1155
  const providers = [{ provider: mainProvider2, label: "RPC[0/主]" }];
1143
1156
  const sequencerChannel2 = this.buildSequencerChannel(chain, signedTx2);
1144
- const channels2 = [
1145
- ...providers.map(({ provider, label }) => ({ label, send: () => provider.broadcastTransaction(signedTx2) })),
1146
- ...sequencerChannel2 ? [sequencerChannel2] : []
1147
- ];
1157
+ const channels2 = [...providers.map(({ provider, label }) => ({ label, send: () => provider.broadcastTransaction(signedTx2) })), ...sequencerChannel2 ? [sequencerChannel2] : []];
1148
1158
  const receiptPromise2 = this.raceForReceipt(chain, txHash2, providers);
1149
1159
  await this.sendSignedTxToChannels(chain, signedTx2, txHash2, channels2);
1150
1160
  const receipt2 = await receiptPromise2;
1151
1161
  const blockTs2 = await this.getBlockTimestampStr(mainProvider2, receipt2.blockNumber);
1152
- _Aggregator.traceLog(chain, "log", `单RPC+排序器上链确认, txHash=${receipt2.hash}, blockNumber=${receipt2.blockNumber}, 出块时间=${blockTs2}, gasUsed=${receipt2.gasUsed}, status=${receipt2.status}, 总耗时=${Date.now() - broadcastTs2}ms`);
1162
+ _Aggregator.traceLog(
1163
+ chain,
1164
+ "log",
1165
+ `单RPC+排序器上链确认, txHash=${receipt2.hash}, blockNumber=${receipt2.blockNumber}, 出块时间=${blockTs2}, gasUsed=${receipt2.gasUsed}, status=${receipt2.status}, 总耗时=${Date.now() - broadcastTs2}ms`
1166
+ );
1153
1167
  if (receipt2.status === 0) {
1154
1168
  throw new import_types.TransactionRevertedError(receipt2.hash, receipt2.gasUsed);
1155
1169
  }
@@ -1177,10 +1191,7 @@ var _Aggregator = class {
1177
1191
  );
1178
1192
  const broadcastTs = Date.now();
1179
1193
  const sequencerChannel = this.buildSequencerChannel(chain, signedTx);
1180
- const channels = [
1181
- ...allProviders.map(({ provider, label }) => ({ label, send: () => provider.broadcastTransaction(signedTx) })),
1182
- ...sequencerChannel ? [sequencerChannel] : []
1183
- ];
1194
+ const channels = [...allProviders.map(({ provider, label }) => ({ label, send: () => provider.broadcastTransaction(signedTx) })), ...sequencerChannel ? [sequencerChannel] : []];
1184
1195
  const receiptPromise = this.raceForReceipt(chain, txHash, allProviders, ownedProviders);
1185
1196
  await this.sendSignedTxToChannels(chain, signedTx, txHash, channels);
1186
1197
  const receipt = await receiptPromise;
@@ -1234,18 +1245,38 @@ var _Aggregator = class {
1234
1245
  "log",
1235
1246
  `渠道=Builder Bundle, authType=${builderCfg.authType}, method=${builderCfg.method ?? "eth_sendBundle"}, nonce=${txReq.nonce}, gasLimit=${txReq.gasLimit}, chainId=${network.chainId}, 当前区块=${currentBlock}, 目标区块=[${targetBlocks.join(",")}], builders=[${builderNames.join(",")}](${builderNames.length}个), txHash=${txHash}`
1236
1247
  );
1237
- const signer = builderCfg.authType === "flashbots" ? this.flashbotSigner : void 0;
1238
- const headers = { "Content-Type": "application/json" };
1239
- if (builderCfg.authType === "flashbots" && signer) {
1240
- const sampleBody = this.buildBundleRequestBody(builderCfg, rawTxs, targetBlocks[0]);
1241
- headers["X-Flashbots-Signature"] = await this.signRequestBody(sampleBody, signer);
1242
- }
1243
1248
  const sendBundleTs = Date.now();
1244
1249
  let totalSent = 0;
1245
1250
  let totalFailed = 0;
1246
- const fireAndForget = targetBlocks.flatMap((block) => {
1247
- const body = this.buildBundleRequestBody(builderCfg, rawTxs, block);
1248
- return builderEntries.map(async ([name, url]) => {
1251
+ const signer = builderCfg.authType === "flashbots" ? this.flashbotSigner : void 0;
1252
+ const fireAndForget = builderEntries.flatMap(([name, url]) => {
1253
+ if (name === "flashbots" && builderCfg.authType === "flashbots" && signer) {
1254
+ return [
1255
+ (async () => {
1256
+ const body = this.buildFlashbotsMevBundleRequestBody(rawTxs, targetBlocks[0], targetBlocks[targetBlocks.length - 1]);
1257
+ const headers = {
1258
+ "Content-Type": "application/json",
1259
+ "X-Flashbots-Signature": await this.signRequestBody(body, signer)
1260
+ };
1261
+ const ts = Date.now();
1262
+ try {
1263
+ const response = await import_axios.default.post(url, body, { headers, timeout: 3e3 });
1264
+ totalSent++;
1265
+ _Aggregator.traceLog(chain, "log", `Builder[${name}] mev_sendBundle 发送成功, targetBlocks=[${targetBlocks.join(",")}], 耗时=${Date.now() - ts}ms, resp=${JSON.stringify(response.data)}`);
1266
+ } catch (error) {
1267
+ totalFailed++;
1268
+ const msg = (error == null ? void 0 : error.response) ? JSON.stringify(error.response.data) : (error == null ? void 0 : error.message) ?? String(error);
1269
+ _Aggregator.traceLog(chain, "error", `Builder[${name}] mev_sendBundle 发送失败, targetBlocks=[${targetBlocks.join(",")}], 耗时=${Date.now() - ts}ms, error=${msg}`);
1270
+ }
1271
+ })()
1272
+ ];
1273
+ }
1274
+ return targetBlocks.map(async (block) => {
1275
+ const body = this.buildBundleRequestBody(builderCfg, rawTxs, block);
1276
+ const headers = { "Content-Type": "application/json" };
1277
+ if (builderCfg.authType === "flashbots" && signer) {
1278
+ headers["X-Flashbots-Signature"] = await this.signRequestBody(body, signer);
1279
+ }
1249
1280
  const ts = Date.now();
1250
1281
  try {
1251
1282
  const response = await import_axios.default.post(url, body, { headers, timeout: 3e3 });
@@ -1415,20 +1446,17 @@ Aggregator.DEFAULT_ETH_BUILDERS = {
1415
1446
  Titan: "https://rpc.titanbuilder.xyz",
1416
1447
  flashbots: "https://relay.flashbots.net",
1417
1448
  // bloXroute: 'https://mev.api.blxrbdn.com', // 旧 api.blxrbdn.com 也行,需配置 Authorization 头
1418
- lightspeedbuilder: "https://rpc.lightspeedbuilder.info",
1449
+ lightspeedbuilder: "https://rpc.lightspeedbuilder.info"
1419
1450
  // 新增,实测直接可用
1420
1451
  // buildernet: 'https://rpc.buildernet.org', // 新增,Flashbots 生态,需签名头(同 flashbots 格式)
1421
- nfactorial: "https://rpc.nfactorial.xyz"
1422
- // 新增,支持 bundle rebate
1452
+ // nfactorial: 'https://rpc.nfactorial.xyz', // 新增,支持 bundle rebate
1423
1453
  };
1424
1454
  Aggregator.DEFAULT_SEQUENCER_RPC_BY_CHAIN = {
1425
1455
  [import_types.ChainNameEnum.ARB]: "https://arb1-sequencer.arbitrum.io/rpc",
1426
1456
  [import_types.ChainNameEnum.BASE]: "https://mainnet-sequencer.base.org",
1427
1457
  [import_types.ChainNameEnum.ETHERLINK]: "https://relay.mainnet.etherlink.com"
1428
1458
  };
1429
- Aggregator.SEQUENCER_CHAINS = new Set(
1430
- Object.keys(_Aggregator.DEFAULT_SEQUENCER_RPC_BY_CHAIN)
1431
- );
1459
+ Aggregator.SEQUENCER_CHAINS = new Set(Object.keys(_Aggregator.DEFAULT_SEQUENCER_RPC_BY_CHAIN));
1432
1460
  Aggregator.TX_CONFIRM_TIMEOUT_MS = 12e4;
1433
1461
  Aggregator.BUNDLE_INCLUSION_TIMEOUT_MS = 3e4;
1434
1462
  var aggregator_default = Aggregator;
@@ -26,6 +26,7 @@ declare class Aggregator {
26
26
  private getBuilderConfig;
27
27
  private getSequencerRpcs;
28
28
  private buildBundleRequestBody;
29
+ private buildFlashbotsMevBundleRequestBody;
29
30
  sendBundle(chain: ChainNameEnum, rawTxs: string[], targetBlock: number, signer?: ethers.Wallet): Promise<{
30
31
  sent: number;
31
32
  failed: number;
@@ -26,6 +26,7 @@ declare class Aggregator {
26
26
  private getBuilderConfig;
27
27
  private getSequencerRpcs;
28
28
  private buildBundleRequestBody;
29
+ private buildFlashbotsMevBundleRequestBody;
29
30
  sendBundle(chain: ChainNameEnum, rawTxs: string[], targetBlock: number, signer?: ethers.Wallet): Promise<{
30
31
  sent: number;
31
32
  failed: number;
@@ -236,6 +236,28 @@ var Aggregator = /*#__PURE__*/function () {
236
236
  }]
237
237
  };
238
238
  }
239
+ }, {
240
+ key: "buildFlashbotsMevBundleRequestBody",
241
+ value: function buildFlashbotsMevBundleRequestBody(rawTxs, startBlock, endBlock) {
242
+ return {
243
+ jsonrpc: '2.0',
244
+ id: 1,
245
+ method: 'mev_sendBundle',
246
+ params: [{
247
+ version: 'v0.1',
248
+ inclusion: {
249
+ block: "0x".concat(startBlock.toString(16)),
250
+ maxBlock: "0x".concat(endBlock.toString(16))
251
+ },
252
+ body: rawTxs.map(function (tx) {
253
+ return {
254
+ tx: tx,
255
+ canRevert: false
256
+ };
257
+ })
258
+ }]
259
+ };
260
+ }
239
261
  }, {
240
262
  key: "sendBundle",
241
263
  value: function () {
@@ -2520,28 +2542,28 @@ var Aggregator = /*#__PURE__*/function () {
2520
2542
  }, {
2521
2543
  key: "submitBundleTx",
2522
2544
  value: function () {
2523
- var _submitBundleTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(chain, wallet, txReq, to, data, value, bundleBlockCount) {
2545
+ var _submitBundleTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(chain, wallet, txReq, to, data, value, bundleBlockCount) {
2524
2546
  var _builderCfg$method2,
2525
2547
  _this2 = this;
2526
- var builderCfg, provider, network, baseTx, _yield$Promise$all, _yield$Promise$all2, signTx, currentBlock, rawTxs, txHash, normalizedBundleBlockCount, targetBlocks, builderNames, builderEntries, signer, headers, sampleBody, sendBundleTs, totalSent, totalFailed, fireAndForget, abortController, inclusionPromise, waitTs, _yield$Promise$all3, _yield$Promise$all4, receipt, blockTs;
2527
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2528
- while (1) switch (_context25.prev = _context25.next) {
2548
+ var builderCfg, provider, network, baseTx, _yield$Promise$all, _yield$Promise$all2, signTx, currentBlock, rawTxs, txHash, normalizedBundleBlockCount, targetBlocks, builderNames, builderEntries, sendBundleTs, totalSent, totalFailed, signer, fireAndForget, abortController, inclusionPromise, waitTs, _yield$Promise$all3, _yield$Promise$all4, receipt, blockTs;
2549
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2550
+ while (1) switch (_context26.prev = _context26.next) {
2529
2551
  case 0:
2530
2552
  if (bundleBlockCount == null) {
2531
2553
  bundleBlockCount = this.builderConfigMap.has(chain) ? 3 : 1;
2532
2554
  }
2533
2555
  builderCfg = this.getBuilderConfig(chain);
2534
2556
  if (!(builderCfg.authType === 'flashbots' && !this.flashbotSigner)) {
2535
- _context25.next = 4;
2557
+ _context26.next = 4;
2536
2558
  break;
2537
2559
  }
2538
2560
  throw new Error('flashbot signer未初始化');
2539
2561
  case 4:
2540
2562
  provider = this.providerClient.getProvider(chain);
2541
- _context25.next = 7;
2563
+ _context26.next = 7;
2542
2564
  return provider.getNetwork();
2543
2565
  case 7:
2544
- network = _context25.sent;
2566
+ network = _context26.sent;
2545
2567
  baseTx = {
2546
2568
  from: wallet.address,
2547
2569
  to: to,
@@ -2559,10 +2581,10 @@ var Aggregator = /*#__PURE__*/function () {
2559
2581
  baseTx.gasPrice = txReq.gasPrice;
2560
2582
  baseTx.type = 0;
2561
2583
  }
2562
- _context25.next = 12;
2584
+ _context26.next = 12;
2563
2585
  return Promise.all([wallet.signTransaction(baseTx), provider.getBlockNumber()]);
2564
2586
  case 12:
2565
- _yield$Promise$all = _context25.sent;
2587
+ _yield$Promise$all = _context26.sent;
2566
2588
  _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
2567
2589
  signTx = _yield$Promise$all2[0];
2568
2590
  currentBlock = _yield$Promise$all2[1];
@@ -2577,98 +2599,140 @@ var Aggregator = /*#__PURE__*/function () {
2577
2599
  builderNames = Object.keys(builderCfg.urls);
2578
2600
  builderEntries = Object.entries(builderCfg.urls);
2579
2601
  Aggregator.traceLog(chain, 'log', "\u6E20\u9053=Builder Bundle, authType=".concat(builderCfg.authType, ", method=").concat((_builderCfg$method2 = builderCfg.method) !== null && _builderCfg$method2 !== void 0 ? _builderCfg$method2 : 'eth_sendBundle', ", ") + "nonce=".concat(txReq.nonce, ", gasLimit=").concat(txReq.gasLimit, ", chainId=").concat(network.chainId, ", ") + "\u5F53\u524D\u533A\u5757=".concat(currentBlock, ", \u76EE\u6807\u533A\u5757=[").concat(targetBlocks.join(','), "], ") + "builders=[".concat(builderNames.join(','), "](").concat(builderNames.length, "\u4E2A), txHash=").concat(txHash));
2580
- signer = builderCfg.authType === 'flashbots' ? this.flashbotSigner : undefined;
2581
- headers = {
2582
- 'Content-Type': 'application/json'
2583
- };
2584
- if (!(builderCfg.authType === 'flashbots' && signer)) {
2585
- _context25.next = 30;
2586
- break;
2587
- }
2588
- sampleBody = this.buildBundleRequestBody(builderCfg, rawTxs, targetBlocks[0]);
2589
- _context25.next = 29;
2590
- return this.signRequestBody(sampleBody, signer);
2591
- case 29:
2592
- headers['X-Flashbots-Signature'] = _context25.sent;
2593
- case 30:
2594
2602
  sendBundleTs = Date.now();
2595
2603
  totalSent = 0;
2596
2604
  totalFailed = 0;
2597
- fireAndForget = targetBlocks.flatMap(function (block) {
2598
- var body = _this2.buildBundleRequestBody(builderCfg, rawTxs, block);
2599
- return builderEntries.map( /*#__PURE__*/function () {
2600
- var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(_ref14) {
2601
- var _ref16, name, url, ts, response, _error$message2, msg;
2605
+ signer = builderCfg.authType === 'flashbots' ? this.flashbotSigner : undefined;
2606
+ fireAndForget = builderEntries.flatMap(function (_ref14) {
2607
+ var _ref15 = _slicedToArray(_ref14, 2),
2608
+ name = _ref15[0],
2609
+ url = _ref15[1];
2610
+ if (name === 'flashbots' && builderCfg.authType === 'flashbots' && signer) {
2611
+ return [_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
2612
+ var body, headers, ts, response, _error$message2, msg;
2602
2613
  return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2603
2614
  while (1) switch (_context24.prev = _context24.next) {
2604
2615
  case 0:
2605
- _ref16 = _slicedToArray(_ref14, 2), name = _ref16[0], url = _ref16[1];
2616
+ body = _this2.buildFlashbotsMevBundleRequestBody(rawTxs, targetBlocks[0], targetBlocks[targetBlocks.length - 1]);
2617
+ _context24.next = 3;
2618
+ return _this2.signRequestBody(body, signer);
2619
+ case 3:
2620
+ _context24.t0 = _context24.sent;
2621
+ headers = {
2622
+ 'Content-Type': 'application/json',
2623
+ 'X-Flashbots-Signature': _context24.t0
2624
+ };
2606
2625
  ts = Date.now();
2607
- _context24.prev = 2;
2608
- _context24.next = 5;
2626
+ _context24.prev = 6;
2627
+ _context24.next = 9;
2609
2628
  return axios.post(url, body, {
2610
2629
  headers: headers,
2611
2630
  timeout: 3000
2612
2631
  });
2613
- case 5:
2632
+ case 9:
2614
2633
  response = _context24.sent;
2615
2634
  totalSent++;
2616
- Aggregator.traceLog(chain, 'log', "Builder[".concat(name, "] \u53D1\u9001\u6210\u529F, targetBlock=").concat(block, ", \u8017\u65F6=").concat(Date.now() - ts, "ms, resp=").concat(JSON.stringify(response.data)));
2617
- _context24.next = 15;
2635
+ Aggregator.traceLog(chain, 'log', "Builder[".concat(name, "] mev_sendBundle \u53D1\u9001\u6210\u529F, targetBlocks=[").concat(targetBlocks.join(','), "], \u8017\u65F6=").concat(Date.now() - ts, "ms, resp=").concat(JSON.stringify(response.data)));
2636
+ _context24.next = 19;
2618
2637
  break;
2638
+ case 14:
2639
+ _context24.prev = 14;
2640
+ _context24.t1 = _context24["catch"](6);
2641
+ totalFailed++;
2642
+ msg = _context24.t1 !== null && _context24.t1 !== void 0 && _context24.t1.response ? JSON.stringify(_context24.t1.response.data) : (_error$message2 = _context24.t1 === null || _context24.t1 === void 0 ? void 0 : _context24.t1.message) !== null && _error$message2 !== void 0 ? _error$message2 : String(_context24.t1);
2643
+ Aggregator.traceLog(chain, 'error', "Builder[".concat(name, "] mev_sendBundle \u53D1\u9001\u5931\u8D25, targetBlocks=[").concat(targetBlocks.join(','), "], \u8017\u65F6=").concat(Date.now() - ts, "ms, error=").concat(msg));
2644
+ case 19:
2645
+ case "end":
2646
+ return _context24.stop();
2647
+ }
2648
+ }, _callee24, null, [[6, 14]]);
2649
+ }))()];
2650
+ }
2651
+ return targetBlocks.map( /*#__PURE__*/function () {
2652
+ var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(block) {
2653
+ var body, headers, ts, response, _error$message3, msg;
2654
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2655
+ while (1) switch (_context25.prev = _context25.next) {
2656
+ case 0:
2657
+ body = _this2.buildBundleRequestBody(builderCfg, rawTxs, block);
2658
+ headers = {
2659
+ 'Content-Type': 'application/json'
2660
+ };
2661
+ if (!(builderCfg.authType === 'flashbots' && signer)) {
2662
+ _context25.next = 6;
2663
+ break;
2664
+ }
2665
+ _context25.next = 5;
2666
+ return _this2.signRequestBody(body, signer);
2667
+ case 5:
2668
+ headers['X-Flashbots-Signature'] = _context25.sent;
2669
+ case 6:
2670
+ ts = Date.now();
2671
+ _context25.prev = 7;
2672
+ _context25.next = 10;
2673
+ return axios.post(url, body, {
2674
+ headers: headers,
2675
+ timeout: 3000
2676
+ });
2619
2677
  case 10:
2620
- _context24.prev = 10;
2621
- _context24.t0 = _context24["catch"](2);
2678
+ response = _context25.sent;
2679
+ totalSent++;
2680
+ Aggregator.traceLog(chain, 'log', "Builder[".concat(name, "] \u53D1\u9001\u6210\u529F, targetBlock=").concat(block, ", \u8017\u65F6=").concat(Date.now() - ts, "ms, resp=").concat(JSON.stringify(response.data)));
2681
+ _context25.next = 20;
2682
+ break;
2683
+ case 15:
2684
+ _context25.prev = 15;
2685
+ _context25.t0 = _context25["catch"](7);
2622
2686
  totalFailed++;
2623
- msg = _context24.t0 !== null && _context24.t0 !== void 0 && _context24.t0.response ? JSON.stringify(_context24.t0.response.data) : (_error$message2 = _context24.t0 === null || _context24.t0 === void 0 ? void 0 : _context24.t0.message) !== null && _error$message2 !== void 0 ? _error$message2 : String(_context24.t0);
2687
+ msg = _context25.t0 !== null && _context25.t0 !== void 0 && _context25.t0.response ? JSON.stringify(_context25.t0.response.data) : (_error$message3 = _context25.t0 === null || _context25.t0 === void 0 ? void 0 : _context25.t0.message) !== null && _error$message3 !== void 0 ? _error$message3 : String(_context25.t0);
2624
2688
  Aggregator.traceLog(chain, 'error', "Builder[".concat(name, "] \u53D1\u9001\u5931\u8D25, targetBlock=").concat(block, ", \u8017\u65F6=").concat(Date.now() - ts, "ms, error=").concat(msg));
2625
- case 15:
2689
+ case 20:
2626
2690
  case "end":
2627
- return _context24.stop();
2691
+ return _context25.stop();
2628
2692
  }
2629
- }, _callee24, null, [[2, 10]]);
2693
+ }, _callee25, null, [[7, 15]]);
2630
2694
  }));
2631
2695
  return function (_x57) {
2632
- return _ref15.apply(this, arguments);
2696
+ return _ref17.apply(this, arguments);
2633
2697
  };
2634
2698
  }());
2635
2699
  });
2636
2700
  abortController = new AbortController();
2637
2701
  inclusionPromise = this.waitForBundleInclusion(provider, txHash, targetBlocks, abortController.signal);
2638
2702
  waitTs = Date.now();
2639
- _context25.next = 39;
2703
+ _context26.next = 33;
2640
2704
  return Promise.all([inclusionPromise, Promise.all(fireAndForget).then(function () {
2641
2705
  Aggregator.traceLog(chain, 'log', "Bundle\u53D1\u9001\u5B8C\u6210, \u6210\u529F=".concat(totalSent, ", \u5931\u8D25=").concat(totalFailed, ", \u603B\u8BF7\u6C42=").concat(fireAndForget.length, ", \u8017\u65F6=").concat(Date.now() - sendBundleTs, "ms, txHash=").concat(txHash));
2642
2706
  if (totalSent === 0) abortController.abort();
2643
2707
  })]);
2644
- case 39:
2645
- _yield$Promise$all3 = _context25.sent;
2708
+ case 33:
2709
+ _yield$Promise$all3 = _context26.sent;
2646
2710
  _yield$Promise$all4 = _slicedToArray(_yield$Promise$all3, 1);
2647
2711
  receipt = _yield$Promise$all4[0];
2648
2712
  if (!receipt) {
2649
- _context25.next = 49;
2713
+ _context26.next = 43;
2650
2714
  break;
2651
2715
  }
2652
- _context25.next = 45;
2716
+ _context26.next = 39;
2653
2717
  return this.getBlockTimestampStr(provider, receipt.blockNumber);
2654
- case 45:
2655
- blockTs = _context25.sent;
2718
+ case 39:
2719
+ blockTs = _context26.sent;
2656
2720
  Aggregator.traceLog(chain, 'log', "Bundle\u4E0A\u94FE\u786E\u8BA4, txHash=".concat(receipt.hash, ", blockNumber=").concat(receipt.blockNumber, ", \u51FA\u5757\u65F6\u95F4=").concat(blockTs, ", gasUsed=").concat(receipt.gasUsed, ", ") + "\u7B49\u5F85\u8017\u65F6=".concat(Date.now() - waitTs, "ms"));
2657
- _context25.next = 50;
2721
+ _context26.next = 44;
2658
2722
  break;
2659
- case 49:
2723
+ case 43:
2660
2724
  Aggregator.traceLog(chain, 'warn', "Bundle\u672A\u5728\u76EE\u6807\u533A\u5757\u4E0A\u94FE, txHash=".concat(txHash, ", \u76EE\u6807\u533A\u5757=[").concat(targetBlocks.join(','), "], \u7B49\u5F85\u8017\u65F6=").concat(Date.now() - waitTs, "ms"));
2661
- case 50:
2662
- return _context25.abrupt("return", {
2725
+ case 44:
2726
+ return _context26.abrupt("return", {
2663
2727
  receipt: receipt,
2664
2728
  txHash: txHash,
2665
2729
  targetBlocks: targetBlocks
2666
2730
  });
2667
- case 51:
2731
+ case 45:
2668
2732
  case "end":
2669
- return _context25.stop();
2733
+ return _context26.stop();
2670
2734
  }
2671
- }, _callee25, this);
2735
+ }, _callee26, this);
2672
2736
  }));
2673
2737
  function submitBundleTx(_x50, _x51, _x52, _x53, _x54, _x55, _x56) {
2674
2738
  return _submitBundleTx.apply(this, arguments);
@@ -2678,7 +2742,7 @@ var Aggregator = /*#__PURE__*/function () {
2678
2742
  }, {
2679
2743
  key: "swapByFlashbots",
2680
2744
  value: function () {
2681
- var _swapByFlashbots = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
2745
+ var _swapByFlashbots = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
2682
2746
  var _amountOut, _receipt$to4;
2683
2747
  var txReq,
2684
2748
  bundleBlockCount,
@@ -2701,12 +2765,12 @@ var Aggregator = /*#__PURE__*/function () {
2701
2765
  _step7,
2702
2766
  log,
2703
2767
  parsed,
2704
- _args26 = arguments;
2705
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2706
- while (1) switch (_context26.prev = _context26.next) {
2768
+ _args27 = arguments;
2769
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2770
+ while (1) switch (_context27.prev = _context27.next) {
2707
2771
  case 0:
2708
- txReq = _args26.length > 1 && _args26[1] !== undefined ? _args26[1] : {};
2709
- bundleBlockCount = _args26.length > 2 && _args26[2] !== undefined ? _args26[2] : 1;
2772
+ txReq = _args27.length > 1 && _args27[1] !== undefined ? _args27[1] : {};
2773
+ bundleBlockCount = _args27.length > 2 && _args27[2] !== undefined ? _args27[2] : 1;
2710
2774
  Aggregator.traceLog(params.chain, 'log', "swapByFlashbots(bundle\u8DEF\u5F84)\u5F00\u59CB, bundleBlockCount=".concat(bundleBlockCount));
2711
2775
  wallet = this.providerClient.getWallet(params.chain);
2712
2776
  aggregatorAddress = this.getAggregatorAddress(params.chain);
@@ -2722,39 +2786,39 @@ var Aggregator = /*#__PURE__*/function () {
2722
2786
  };
2723
2787
  });
2724
2788
  _txReq6 = txReq, _ignore = _txReq6.gasLimit, estimationOverrides = _objectWithoutProperties(_txReq6, _excluded7);
2725
- _context26.prev = 8;
2726
- _context26.next = 11;
2789
+ _context27.prev = 8;
2790
+ _context27.next = 11;
2727
2791
  return aggregator.swap.estimateGas(params.user, params.amountInWei, swapParams, params.minAmountOutList, estimationOverrides);
2728
2792
  case 11:
2729
- estimateGas = _context26.sent;
2730
- _context26.next = 18;
2793
+ estimateGas = _context27.sent;
2794
+ _context27.next = 18;
2731
2795
  break;
2732
2796
  case 14:
2733
- _context26.prev = 14;
2734
- _context26.t0 = _context26["catch"](8);
2735
- Aggregator.traceLog(params.chain, 'error', "swapByFlashbots estimateGas\u5931\u8D25, rpcUrl=".concat(this.getRpcUrl(params.chain), ", error=").concat(_context26.t0));
2736
- throw _context26.t0;
2797
+ _context27.prev = 14;
2798
+ _context27.t0 = _context27["catch"](8);
2799
+ Aggregator.traceLog(params.chain, 'error', "swapByFlashbots estimateGas\u5931\u8D25, rpcUrl=".concat(this.getRpcUrl(params.chain), ", error=").concat(_context27.t0));
2800
+ throw _context27.t0;
2737
2801
  case 18:
2738
2802
  Aggregator.traceLog(params.chain, 'log', "swapByFlashbots estimateGas=".concat(estimateGas));
2739
2803
  txReq = this.resolveGasLimit(txReq, estimateGas);
2740
- _context26.next = 22;
2804
+ _context27.next = 22;
2741
2805
  return this.resolveNonce(wallet.provider, wallet.address, txReq);
2742
2806
  case 22:
2743
- txReq = _context26.sent;
2744
- _context26.next = 25;
2807
+ txReq = _context27.sent;
2808
+ _context27.next = 25;
2745
2809
  return this.resolvePricing(wallet.provider, txReq);
2746
2810
  case 25:
2747
- txReq = _context26.sent;
2811
+ txReq = _context27.sent;
2748
2812
  swapCallData = this.genSwapCalldata(params);
2749
- _context26.next = 29;
2813
+ _context27.next = 29;
2750
2814
  return this.submitBundleTx(params.chain, wallet, txReq, swapCallData.to, swapCallData.data, 0n, bundleBlockCount);
2751
2815
  case 29:
2752
- _yield$this$submitBun5 = _context26.sent;
2816
+ _yield$this$submitBun5 = _context27.sent;
2753
2817
  receipt = _yield$this$submitBun5.receipt;
2754
2818
  txHash = _yield$this$submitBun5.txHash;
2755
2819
  targetBlocks = _yield$this$submitBun5.targetBlocks;
2756
2820
  if (receipt) {
2757
- _context26.next = 35;
2821
+ _context27.next = 35;
2758
2822
  break;
2759
2823
  }
2760
2824
  throw new BundleNotIncludedError("Bundle \u672A\u5728\u76EE\u6807\u533A\u5757\u4E0A\u94FE, txHash=".concat(txHash, ", targetBlocks=[").concat(targetBlocks.join(','), "]"), txHash);
@@ -2762,48 +2826,48 @@ var Aggregator = /*#__PURE__*/function () {
2762
2826
  iface = new ethers.Interface(AggregatorAbi);
2763
2827
  amountOut = null;
2764
2828
  _iterator7 = _createForOfIteratorHelper(receipt.logs);
2765
- _context26.prev = 38;
2829
+ _context27.prev = 38;
2766
2830
  _iterator7.s();
2767
2831
  case 40:
2768
2832
  if ((_step7 = _iterator7.n()).done) {
2769
- _context26.next = 54;
2833
+ _context27.next = 54;
2770
2834
  break;
2771
2835
  }
2772
2836
  log = _step7.value;
2773
2837
  if (!(log.address.toLowerCase() === aggregatorAddress.toLowerCase())) {
2774
- _context26.next = 52;
2838
+ _context27.next = 52;
2775
2839
  break;
2776
2840
  }
2777
- _context26.prev = 43;
2841
+ _context27.prev = 43;
2778
2842
  parsed = iface.parseLog(log);
2779
2843
  if (!(parsed && parsed.name === 'Swapped' && parsed.args && parsed.args.amountOut !== undefined)) {
2780
- _context26.next = 48;
2844
+ _context27.next = 48;
2781
2845
  break;
2782
2846
  }
2783
2847
  amountOut = parsed.args.amountOut;
2784
- return _context26.abrupt("break", 54);
2848
+ return _context27.abrupt("break", 54);
2785
2849
  case 48:
2786
- _context26.next = 52;
2850
+ _context27.next = 52;
2787
2851
  break;
2788
2852
  case 50:
2789
- _context26.prev = 50;
2790
- _context26.t1 = _context26["catch"](43);
2853
+ _context27.prev = 50;
2854
+ _context27.t1 = _context27["catch"](43);
2791
2855
  case 52:
2792
- _context26.next = 40;
2856
+ _context27.next = 40;
2793
2857
  break;
2794
2858
  case 54:
2795
- _context26.next = 59;
2859
+ _context27.next = 59;
2796
2860
  break;
2797
2861
  case 56:
2798
- _context26.prev = 56;
2799
- _context26.t2 = _context26["catch"](38);
2800
- _iterator7.e(_context26.t2);
2862
+ _context27.prev = 56;
2863
+ _context27.t2 = _context27["catch"](38);
2864
+ _iterator7.e(_context27.t2);
2801
2865
  case 59:
2802
- _context26.prev = 59;
2866
+ _context27.prev = 59;
2803
2867
  _iterator7.f();
2804
- return _context26.finish(59);
2868
+ return _context27.finish(59);
2805
2869
  case 62:
2806
- return _context26.abrupt("return", {
2870
+ return _context27.abrupt("return", {
2807
2871
  fromToken: params.path[0].fromCoinAddress,
2808
2872
  toToken: params.path[params.path.length - 1].toCoinAddress,
2809
2873
  amountOut: (_amountOut = amountOut) !== null && _amountOut !== void 0 ? _amountOut : 0n,
@@ -2813,9 +2877,9 @@ var Aggregator = /*#__PURE__*/function () {
2813
2877
  });
2814
2878
  case 63:
2815
2879
  case "end":
2816
- return _context26.stop();
2880
+ return _context27.stop();
2817
2881
  }
2818
- }, _callee26, this, [[8, 14], [38, 56, 59, 62], [43, 50]]);
2882
+ }, _callee27, this, [[8, 14], [38, 56, 59, 62], [43, 50]]);
2819
2883
  }));
2820
2884
  function swapByFlashbots(_x58) {
2821
2885
  return _swapByFlashbots.apply(this, arguments);
@@ -2833,32 +2897,32 @@ var Aggregator = /*#__PURE__*/function () {
2833
2897
  }, {
2834
2898
  key: "resolveNonce",
2835
2899
  value: function () {
2836
- var _resolveNonce = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(provider, from, tx) {
2837
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2838
- while (1) switch (_context27.prev = _context27.next) {
2900
+ var _resolveNonce = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(provider, from, tx) {
2901
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2902
+ while (1) switch (_context28.prev = _context28.next) {
2839
2903
  case 0:
2840
2904
  if (!(tx.nonce != null)) {
2841
- _context27.next = 2;
2905
+ _context28.next = 2;
2842
2906
  break;
2843
2907
  }
2844
- return _context27.abrupt("return", tx);
2908
+ return _context28.abrupt("return", tx);
2845
2909
  case 2:
2846
- _context27.t0 = _objectSpread;
2847
- _context27.t1 = _objectSpread({}, tx);
2848
- _context27.t2 = {};
2849
- _context27.next = 7;
2910
+ _context28.t0 = _objectSpread;
2911
+ _context28.t1 = _objectSpread({}, tx);
2912
+ _context28.t2 = {};
2913
+ _context28.next = 7;
2850
2914
  return provider.getTransactionCount(from, 'latest');
2851
2915
  case 7:
2852
- _context27.t3 = _context27.sent;
2853
- _context27.t4 = {
2854
- nonce: _context27.t3
2916
+ _context28.t3 = _context28.sent;
2917
+ _context28.t4 = {
2918
+ nonce: _context28.t3
2855
2919
  };
2856
- return _context27.abrupt("return", (0, _context27.t0)(_context27.t1, _context27.t2, _context27.t4));
2920
+ return _context28.abrupt("return", (0, _context28.t0)(_context28.t1, _context28.t2, _context28.t4));
2857
2921
  case 10:
2858
2922
  case "end":
2859
- return _context27.stop();
2923
+ return _context28.stop();
2860
2924
  }
2861
- }, _callee27);
2925
+ }, _callee28);
2862
2926
  }));
2863
2927
  function resolveNonce(_x59, _x60, _x61) {
2864
2928
  return _resolveNonce.apply(this, arguments);
@@ -2868,44 +2932,44 @@ var Aggregator = /*#__PURE__*/function () {
2868
2932
  }, {
2869
2933
  key: "resolvePricing",
2870
2934
  value: function () {
2871
- var _resolvePricing = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(provider, tx) {
2935
+ var _resolvePricing = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(provider, tx) {
2872
2936
  var fd;
2873
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2874
- while (1) switch (_context28.prev = _context28.next) {
2937
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2938
+ while (1) switch (_context29.prev = _context29.next) {
2875
2939
  case 0:
2876
2940
  if (!(tx.gasPrice != null || tx.maxFeePerGas != null || tx.maxPriorityFeePerGas != null)) {
2877
- _context28.next = 2;
2941
+ _context29.next = 2;
2878
2942
  break;
2879
2943
  }
2880
- return _context28.abrupt("return", this.sanitizePricing(tx));
2944
+ return _context29.abrupt("return", this.sanitizePricing(tx));
2881
2945
  case 2:
2882
- _context28.next = 4;
2946
+ _context29.next = 4;
2883
2947
  return provider.getFeeData();
2884
2948
  case 4:
2885
- fd = _context28.sent;
2949
+ fd = _context29.sent;
2886
2950
  if (!(fd.maxFeePerGas != null && fd.maxPriorityFeePerGas != null)) {
2887
- _context28.next = 7;
2951
+ _context29.next = 7;
2888
2952
  break;
2889
2953
  }
2890
- return _context28.abrupt("return", _objectSpread(_objectSpread({}, tx), {}, {
2954
+ return _context29.abrupt("return", _objectSpread(_objectSpread({}, tx), {}, {
2891
2955
  maxFeePerGas: fd.maxFeePerGas * 150n / 100n,
2892
2956
  maxPriorityFeePerGas: fd.maxPriorityFeePerGas
2893
2957
  }));
2894
2958
  case 7:
2895
2959
  if (!(fd.gasPrice != null)) {
2896
- _context28.next = 9;
2960
+ _context29.next = 9;
2897
2961
  break;
2898
2962
  }
2899
- return _context28.abrupt("return", _objectSpread(_objectSpread({}, tx), {}, {
2963
+ return _context29.abrupt("return", _objectSpread(_objectSpread({}, tx), {}, {
2900
2964
  gasPrice: fd.gasPrice
2901
2965
  }));
2902
2966
  case 9:
2903
- return _context28.abrupt("return", tx);
2967
+ return _context29.abrupt("return", tx);
2904
2968
  case 10:
2905
2969
  case "end":
2906
- return _context28.stop();
2970
+ return _context29.stop();
2907
2971
  }
2908
- }, _callee28, this);
2972
+ }, _callee29, this);
2909
2973
  }));
2910
2974
  function resolvePricing(_x62, _x63) {
2911
2975
  return _resolvePricing.apply(this, arguments);
@@ -2994,10 +3058,9 @@ _defineProperty(Aggregator, "DEFAULT_ETH_BUILDERS", {
2994
3058
  Titan: 'https://rpc.titanbuilder.xyz',
2995
3059
  flashbots: 'https://relay.flashbots.net',
2996
3060
  // bloXroute: 'https://mev.api.blxrbdn.com', // 旧 api.blxrbdn.com 也行,需配置 Authorization 头
2997
- lightspeedbuilder: 'https://rpc.lightspeedbuilder.info',
2998
- // 新增,实测直接可用
3061
+ lightspeedbuilder: 'https://rpc.lightspeedbuilder.info' // 新增,实测直接可用
2999
3062
  // buildernet: 'https://rpc.buildernet.org', // 新增,Flashbots 生态,需签名头(同 flashbots 格式)
3000
- nfactorial: 'https://rpc.nfactorial.xyz' // 新增,支持 bundle rebate
3063
+ // nfactorial: 'https://rpc.nfactorial.xyz', // 新增,支持 bundle rebate
3001
3064
  });
3002
3065
  _defineProperty(Aggregator, "DEFAULT_SEQUENCER_RPC_BY_CHAIN", _defineProperty(_defineProperty(_defineProperty({}, ChainNameEnum.ARB, 'https://arb1-sequencer.arbitrum.io/rpc'), ChainNameEnum.BASE, 'https://mainnet-sequencer.base.org'), ChainNameEnum.ETHERLINK, 'https://relay.mainnet.etherlink.com'));
3003
3066
  _defineProperty(Aggregator, "SEQUENCER_CHAINS", new Set(Object.keys(_class.DEFAULT_SEQUENCER_RPC_BY_CHAIN)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hermes-swap",
3
- "version": "0.6.8",
3
+ "version": "0.6.9",
4
4
  "description": "A TypeScript utility library for swap and bridge",
5
5
  "main": "dist/cjs/index.cjs",
6
6
  "module": "dist/esm/index.mjs",