@across-protocol/sdk 4.1.10-beta.0 → 4.1.11

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.
Files changed (65) hide show
  1. package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +0 -1
  2. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +77 -79
  3. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  4. package/dist/cjs/clients/HubPoolClient.d.ts +2 -2
  5. package/dist/cjs/clients/HubPoolClient.js +2 -6
  6. package/dist/cjs/clients/HubPoolClient.js.map +1 -1
  7. package/dist/cjs/clients/SpokePoolClient.d.ts +1 -3
  8. package/dist/cjs/clients/SpokePoolClient.js +20 -15
  9. package/dist/cjs/clients/SpokePoolClient.js.map +1 -1
  10. package/dist/cjs/interfaces/HubPool.d.ts +1 -4
  11. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +3 -2
  12. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  13. package/dist/cjs/utils/CachingUtils.js +3 -3
  14. package/dist/cjs/utils/CachingUtils.js.map +1 -1
  15. package/dist/cjs/utils/LogUtils.d.ts +0 -1
  16. package/dist/cjs/utils/LogUtils.js +1 -7
  17. package/dist/cjs/utils/LogUtils.js.map +1 -1
  18. package/dist/cjs/utils/Multicall.js +1 -0
  19. package/dist/cjs/utils/Multicall.js.map +1 -1
  20. package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +0 -1
  21. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +70 -73
  22. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  23. package/dist/esm/clients/HubPoolClient.d.ts +2 -2
  24. package/dist/esm/clients/HubPoolClient.js +2 -6
  25. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  26. package/dist/esm/clients/SpokePoolClient.d.ts +3 -5
  27. package/dist/esm/clients/SpokePoolClient.js +23 -18
  28. package/dist/esm/clients/SpokePoolClient.js.map +1 -1
  29. package/dist/esm/interfaces/HubPool.d.ts +1 -4
  30. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +2 -1
  31. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  32. package/dist/esm/utils/CachingUtils.js +1 -1
  33. package/dist/esm/utils/CachingUtils.js.map +1 -1
  34. package/dist/esm/utils/LogUtils.d.ts +0 -7
  35. package/dist/esm/utils/LogUtils.js +0 -11
  36. package/dist/esm/utils/LogUtils.js.map +1 -1
  37. package/dist/esm/utils/Multicall.js +1 -0
  38. package/dist/esm/utils/Multicall.js.map +1 -1
  39. package/dist/esm/utils/abi/typechain/Multicall3.d.ts +4 -1
  40. package/dist/esm/utils/abi/typechain/factories/Multicall3__factory.js.map +1 -1
  41. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +0 -1
  42. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  43. package/dist/types/clients/HubPoolClient.d.ts +2 -2
  44. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  45. package/dist/types/clients/SpokePoolClient.d.ts +3 -5
  46. package/dist/types/clients/SpokePoolClient.d.ts.map +1 -1
  47. package/dist/types/interfaces/HubPool.d.ts +1 -4
  48. package/dist/types/interfaces/HubPool.d.ts.map +1 -1
  49. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
  50. package/dist/types/utils/LogUtils.d.ts +0 -7
  51. package/dist/types/utils/LogUtils.d.ts.map +1 -1
  52. package/dist/types/utils/Multicall.d.ts.map +1 -1
  53. package/dist/types/utils/abi/typechain/Multicall3.d.ts +4 -1
  54. package/dist/types/utils/abi/typechain/Multicall3.d.ts.map +1 -1
  55. package/dist/types/utils/abi/typechain/common.d.ts.map +1 -1
  56. package/dist/types/utils/abi/typechain/factories/Multicall3__factory.d.ts.map +1 -1
  57. package/package.json +1 -1
  58. package/src/clients/BundleDataClient/BundleDataClient.ts +104 -107
  59. package/src/clients/HubPoolClient.ts +12 -9
  60. package/src/clients/SpokePoolClient.ts +11 -16
  61. package/src/interfaces/HubPool.ts +1 -4
  62. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +1 -1
  63. package/src/utils/CachingUtils.ts +1 -1
  64. package/src/utils/LogUtils.ts +0 -12
  65. package/src/utils/Multicall.ts +1 -0
@@ -1,3 +1,4 @@
1
+ import assert from "assert";
1
2
  import _ from "lodash";
2
3
  import {
3
4
  ProposedRootBundle,
@@ -24,7 +25,6 @@ import {
24
25
  bnZero,
25
26
  queryHistoricalDepositForFill,
26
27
  assign,
27
- assert,
28
28
  fixedPointAdjustment,
29
29
  isDefined,
30
30
  toBN,
@@ -239,19 +239,6 @@ export class BundleDataClient {
239
239
  );
240
240
  }
241
241
 
242
- private async getBundleDataFromArweave(blockRangesForChains: number[][]) {
243
- const persistedData = await this.clients.arweaveClient.getByTopic(
244
- this.getArweaveBundleDataClientKey(blockRangesForChains),
245
- BundleDataSS
246
- );
247
- // If there is no data or the data is empty, return undefined because we couldn't
248
- // pull info from the Arweave persistence layer.
249
- if (!isDefined(persistedData) || persistedData.length < 1) {
250
- return undefined;
251
- }
252
- return persistedData;
253
- }
254
-
255
242
  private async loadPersistedDataFromArweave(
256
243
  blockRangesForChains: number[][]
257
244
  ): Promise<LoadDataReturnValue | undefined> {
@@ -259,8 +246,13 @@ export class BundleDataClient {
259
246
  return undefined;
260
247
  }
261
248
  const start = performance.now();
262
- const persistedData = await this.getBundleDataFromArweave(blockRangesForChains);
263
- if (!isDefined(persistedData)) {
249
+ const persistedData = await this.clients.arweaveClient.getByTopic(
250
+ this.getArweaveBundleDataClientKey(blockRangesForChains),
251
+ BundleDataSS
252
+ );
253
+ // If there is no data or the data is empty, return undefined because we couldn't
254
+ // pull info from the Arweave persistence layer.
255
+ if (!isDefined(persistedData) || persistedData.length < 1) {
264
256
  return undefined;
265
257
  }
266
258
 
@@ -399,7 +391,7 @@ export class BundleDataClient {
399
391
  const fill = await verifyFillRepayment(
400
392
  _fill,
401
393
  this.spokePoolClients[_fill.destinationChainId].spokePool.provider,
402
- matchingDeposit!,
394
+ matchingDeposit,
403
395
  this.clients.hubPoolClient
404
396
  );
405
397
  if (!isDefined(fill)) {
@@ -410,7 +402,7 @@ export class BundleDataClient {
410
402
  this.clients.hubPoolClient,
411
403
  blockRanges,
412
404
  this.chainIdListForBundleEvaluationBlockNumbers,
413
- matchingDeposit!.fromLiteChain // Use ! because we've already asserted that matchingDeposit is defined.
405
+ matchingDeposit.fromLiteChain
414
406
  );
415
407
  // Assume that lp fees are 0 for the sake of speed. In the future we could batch compute
416
408
  // these or make hardcoded assumptions based on the origin-repayment chain direction. This might result
@@ -811,16 +803,20 @@ export class BundleDataClient {
811
803
  slowFillRequest: undefined,
812
804
  };
813
805
  } else {
814
- v3RelayHashes[relayDataHash].deposits!.push(deposit);
806
+ const { deposits } = v3RelayHashes[relayDataHash];
807
+ assert(isDefined(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary.");
808
+ deposits.push(deposit);
815
809
  }
816
810
 
817
811
  // Account for duplicate deposits by concatenating the relayDataHash with the count of the number of times
818
812
  // we have seen it so far.
819
- const newBundleDepositHash = `${relayDataHash}@${v3RelayHashes[relayDataHash].deposits!.length - 1}`;
813
+ const { deposits } = v3RelayHashes[relayDataHash];
814
+ assert(isDefined(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary.");
815
+ const newBundleDepositHash = `${relayDataHash}@${deposits.length - 1}`;
820
816
  const decodedBundleDepositHash = decodeBundleDepositHash(newBundleDepositHash);
821
817
  assert(
822
818
  decodedBundleDepositHash.relayDataHash === relayDataHash &&
823
- decodedBundleDepositHash.index === v3RelayHashes[relayDataHash].deposits!.length - 1,
819
+ decodedBundleDepositHash.index === deposits.length - 1,
824
820
  "Not using correct bundle deposit hash key"
825
821
  );
826
822
  if (deposit.blockNumber >= originChainBlockRange[0]) {
@@ -889,7 +885,60 @@ export class BundleDataClient {
889
885
  fillCounter++;
890
886
  const relayDataHash = getRelayEventKey(fill);
891
887
  if (v3RelayHashes[relayDataHash]) {
892
- if (v3RelayHashes[relayDataHash].fill) {
888
+ if (!v3RelayHashes[relayDataHash].fill) {
889
+ const { deposits } = v3RelayHashes[relayDataHash];
890
+ assert(isDefined(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary.");
891
+ v3RelayHashes[relayDataHash].fill = fill;
892
+ if (fill.blockNumber >= destinationChainBlockRange[0]) {
893
+ const fillToRefund = await verifyFillRepayment(
894
+ fill,
895
+ destinationClient.spokePool.provider,
896
+ deposits[0],
897
+ this.clients.hubPoolClient
898
+ );
899
+ if (!isDefined(fillToRefund)) {
900
+ bundleUnrepayableFillsV3.push(fill);
901
+ // We don't return here yet because we still need to mark unexecutable slow fill leaves
902
+ // or duplicate deposits. However, we won't issue a fast fill refund.
903
+ } else {
904
+ v3RelayHashes[relayDataHash].fill = fillToRefund;
905
+ validatedBundleV3Fills.push({
906
+ ...fillToRefund,
907
+ quoteTimestamp: deposits[0].quoteTimestamp,
908
+ });
909
+
910
+ // Now that we know this deposit has been filled on-chain, identify any duplicate deposits
911
+ // sent for this fill and refund them to the filler, because this value would not be paid out
912
+ // otherwise. These deposits can no longer expire and get refunded as an expired deposit,
913
+ // and they won't trigger a pre-fill refund because the fill is in this bundle.
914
+ // Pre-fill refunds only happen when deposits are sent in this bundle and the
915
+ // fill is from a prior bundle. Paying out the filler keeps the behavior consistent for how
916
+ // we deal with duplicate deposits regardless if the deposit is matched with a pre-fill or
917
+ // a current bundle fill.
918
+ const duplicateDeposits = deposits.slice(1);
919
+ duplicateDeposits.forEach((duplicateDeposit) => {
920
+ if (isSlowFill(fill)) {
921
+ updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit);
922
+ } else {
923
+ validatedBundleV3Fills.push({
924
+ ...fillToRefund,
925
+ quoteTimestamp: duplicateDeposit.quoteTimestamp,
926
+ });
927
+ }
928
+ });
929
+ }
930
+
931
+ // If fill replaced a slow fill request, then mark it as one that might have created an
932
+ // unexecutable slow fill. We can't know for sure until we check the slow fill request
933
+ // events.
934
+ if (
935
+ fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
936
+ _canCreateSlowFillLeaf(deposits[0])
937
+ ) {
938
+ fastFillsReplacingSlowFills.push(relayDataHash);
939
+ }
940
+ }
941
+ } else {
893
942
  this.logger.debug({
894
943
  at: "BundleDataClient#loadData",
895
944
  message: "Duplicate fill detected",
@@ -897,61 +946,6 @@ export class BundleDataClient {
897
946
  });
898
947
  throw new Error("Duplicate fill detected");
899
948
  }
900
- assert(
901
- isDefined(v3RelayHashes[relayDataHash].deposits) && v3RelayHashes[relayDataHash].deposits!.length > 0,
902
- "Deposit should exist in relay hash dictionary."
903
- );
904
- v3RelayHashes[relayDataHash].fill = fill;
905
- if (fill.blockNumber >= destinationChainBlockRange[0]) {
906
- const fillToRefund = await verifyFillRepayment(
907
- fill,
908
- destinationClient.spokePool.provider,
909
- v3RelayHashes[relayDataHash].deposits![0],
910
- this.clients.hubPoolClient
911
- );
912
- if (!isDefined(fillToRefund)) {
913
- bundleUnrepayableFillsV3.push(fill);
914
- // We don't return here yet because we still need to mark unexecutable slow fill leaves
915
- // or duplicate deposits. However, we won't issue a fast fill refund.
916
- } else {
917
- v3RelayHashes[relayDataHash].fill = fillToRefund;
918
- validatedBundleV3Fills.push({
919
- ...fillToRefund,
920
- quoteTimestamp: v3RelayHashes[relayDataHash].deposits![0].quoteTimestamp,
921
- });
922
-
923
- // Now that we know this deposit has been filled on-chain, identify any duplicate deposits
924
- // sent for this fill and refund them to the filler, because this value would not be paid out
925
- // otherwise. These deposits can no longer expire and get refunded as an expired deposit,
926
- // and they won't trigger a pre-fill refund because the fill is in this bundle.
927
- // Pre-fill refunds only happen when deposits are sent in this bundle and the
928
- // fill is from a prior bundle. Paying out the filler keeps the behavior consistent for how
929
- // we deal with duplicate deposits regardless if the deposit is matched with a pre-fill or
930
- // a current bundle fill.
931
- const duplicateDeposits = v3RelayHashes[relayDataHash].deposits!.slice(1);
932
- duplicateDeposits.forEach((duplicateDeposit) => {
933
- if (isSlowFill(fill)) {
934
- updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit);
935
- } else {
936
- validatedBundleV3Fills.push({
937
- ...fillToRefund,
938
- quoteTimestamp: duplicateDeposit.quoteTimestamp,
939
- });
940
- }
941
- });
942
- }
943
-
944
- // If fill replaced a slow fill request, then mark it as one that might have created an
945
- // unexecutable slow fill. We can't know for sure until we check the slow fill request
946
- // events.
947
- if (
948
- fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill &&
949
- _canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposits![0])
950
- ) {
951
- fastFillsReplacingSlowFills.push(relayDataHash);
952
- }
953
- }
954
-
955
949
  return;
956
950
  }
957
951
 
@@ -1051,7 +1045,26 @@ export class BundleDataClient {
1051
1045
  const relayDataHash = getRelayEventKey(slowFillRequest);
1052
1046
 
1053
1047
  if (v3RelayHashes[relayDataHash]) {
1054
- if (v3RelayHashes[relayDataHash].slowFillRequest) {
1048
+ if (!v3RelayHashes[relayDataHash].slowFillRequest) {
1049
+ v3RelayHashes[relayDataHash].slowFillRequest = slowFillRequest;
1050
+ const { deposits, fill } = v3RelayHashes[relayDataHash];
1051
+ if (fill) {
1052
+ // Exiting here assumes that slow fill requests must precede fills, so if there was a fill
1053
+ // following this slow fill request, then we would have already seen it. We don't need to check
1054
+ // for a fill older than this slow fill request.
1055
+ return;
1056
+ }
1057
+ assert(isDefined(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary.");
1058
+ const matchedDeposit = deposits[0];
1059
+
1060
+ if (
1061
+ slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
1062
+ _canCreateSlowFillLeaf(matchedDeposit) &&
1063
+ !_depositIsExpired(matchedDeposit)
1064
+ ) {
1065
+ validatedBundleSlowFills.push(matchedDeposit);
1066
+ }
1067
+ } else {
1055
1068
  this.logger.debug({
1056
1069
  at: "BundleDataClient#loadData",
1057
1070
  message: "Duplicate slow fill request detected",
@@ -1059,26 +1072,6 @@ export class BundleDataClient {
1059
1072
  });
1060
1073
  throw new Error("Duplicate slow fill request detected.");
1061
1074
  }
1062
- v3RelayHashes[relayDataHash].slowFillRequest = slowFillRequest;
1063
- if (v3RelayHashes[relayDataHash].fill) {
1064
- // Exiting here assumes that slow fill requests must precede fills, so if there was a fill
1065
- // following this slow fill request, then we would have already seen it. We don't need to check
1066
- // for a fill older than this slow fill request.
1067
- return;
1068
- }
1069
- assert(
1070
- isDefined(v3RelayHashes[relayDataHash].deposits) && v3RelayHashes[relayDataHash].deposits!.length > 0,
1071
- "Deposit should exist in relay hash dictionary."
1072
- );
1073
- const matchedDeposit = v3RelayHashes[relayDataHash].deposits![0];
1074
-
1075
- if (
1076
- slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
1077
- _canCreateSlowFillLeaf(matchedDeposit) &&
1078
- !_depositIsExpired(matchedDeposit)
1079
- ) {
1080
- validatedBundleSlowFills.push(matchedDeposit);
1081
- }
1082
1075
  return;
1083
1076
  }
1084
1077
 
@@ -1173,7 +1166,7 @@ export class BundleDataClient {
1173
1166
  const fillToRefund = await verifyFillRepayment(
1174
1167
  fill,
1175
1168
  destinationClient.spokePool.provider,
1176
- v3RelayHashes[relayDataHash].deposits![0],
1169
+ deposits[0],
1177
1170
  this.clients.hubPoolClient
1178
1171
  );
1179
1172
  if (!isDefined(fillToRefund)) {
@@ -1221,18 +1214,18 @@ export class BundleDataClient {
1221
1214
  // then we wouldn't be in this branch of the code.
1222
1215
  const prefill = await this.findMatchingFillEvent(deposit, destinationClient);
1223
1216
  assert(isDefined(prefill), `findFillEvent# Cannot find prefill: ${relayDataHash}`);
1224
- assert(getRelayEventKey(prefill!) === relayDataHash, "Relay hashes should match.");
1217
+ assert(getRelayEventKey(prefill) === relayDataHash, "Relay hashes should match.");
1225
1218
  const verifiedFill = await verifyFillRepayment(
1226
- prefill!,
1219
+ prefill,
1227
1220
  destinationClient.spokePool.provider,
1228
1221
  deposit,
1229
1222
  this.clients.hubPoolClient
1230
1223
  );
1231
1224
  if (!isDefined(verifiedFill)) {
1232
- bundleUnrepayableFillsV3.push(prefill!);
1225
+ bundleUnrepayableFillsV3.push(prefill);
1233
1226
  } else if (!isSlowFill(verifiedFill)) {
1234
1227
  validatedBundleV3Fills.push({
1235
- ...verifiedFill!,
1228
+ ...verifiedFill,
1236
1229
  quoteTimestamp: deposit.quoteTimestamp,
1237
1230
  });
1238
1231
  } else {
@@ -1355,14 +1348,16 @@ export class BundleDataClient {
1355
1348
  validatedBundleV3Fills.length > 0
1356
1349
  ? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(
1357
1350
  validatedBundleV3Fills.map((fill) => {
1358
- const matchedDeposit = v3RelayHashes[getRelayEventKey(fill)].deposits![0];
1351
+ const { deposits } = v3RelayHashes[getRelayEventKey(fill)];
1352
+ assert(isDefined(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary.");
1353
+ const matchedDeposit = deposits[0];
1359
1354
  assert(isDefined(matchedDeposit), "Deposit should exist in relay hash dictionary.");
1360
1355
  const { chainToSendRefundTo: paymentChainId } = getRefundInformationFromFill(
1361
1356
  fill,
1362
1357
  this.clients.hubPoolClient,
1363
1358
  blockRangesForChains,
1364
1359
  chainIds,
1365
- matchedDeposit!.fromLiteChain
1360
+ matchedDeposit.fromLiteChain
1366
1361
  );
1367
1362
  return {
1368
1363
  ...fill,
@@ -1399,14 +1394,16 @@ export class BundleDataClient {
1399
1394
  });
1400
1395
  v3FillLpFees.forEach(({ realizedLpFeePct }, idx) => {
1401
1396
  const fill = validatedBundleV3Fills[idx];
1402
- const associatedDeposit = v3RelayHashes[getRelayEventKey(fill)].deposits![0];
1397
+ const { deposits } = v3RelayHashes[getRelayEventKey(fill)];
1398
+ assert(isDefined(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary.");
1399
+ const associatedDeposit = deposits[0];
1403
1400
  assert(isDefined(associatedDeposit), "Deposit should exist in relay hash dictionary.");
1404
1401
  const { chainToSendRefundTo, repaymentToken } = getRefundInformationFromFill(
1405
1402
  fill,
1406
1403
  this.clients.hubPoolClient,
1407
1404
  blockRangesForChains,
1408
1405
  chainIds,
1409
- associatedDeposit!.fromLiteChain
1406
+ associatedDeposit.fromLiteChain
1410
1407
  );
1411
1408
  updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken, fill.relayer);
1412
1409
  });
@@ -776,15 +776,19 @@ export class HubPoolClient extends BaseAbstractClient {
776
776
  return endBlock > 0 ? endBlock + 1 : 0;
777
777
  }
778
778
 
779
- getLatestExecutedRootBundleContainingL1Token(block: number, chain: number, l1Token: string): ExecutedRootBundle {
779
+ getLatestExecutedRootBundleContainingL1Token(
780
+ block: number,
781
+ chain: number,
782
+ l1Token: string
783
+ ): ExecutedRootBundle | undefined {
780
784
  // Search ExecutedRootBundles in descending block order to find the most recent event before the target block.
781
785
  return sortEventsDescending(this.executedRootBundles).find((executedLeaf: ExecutedRootBundle) => {
782
786
  return (
783
787
  executedLeaf.blockNumber <= block &&
784
788
  executedLeaf.chainId === chain &&
785
- executedLeaf.l1Tokens.map((l1Token) => l1Token.toLowerCase()).includes(l1Token.toLowerCase())
789
+ executedLeaf.l1Tokens.some((token) => token.toLowerCase() === l1Token.toLowerCase())
786
790
  );
787
- }) as ExecutedRootBundle;
791
+ });
788
792
  }
789
793
 
790
794
  getRunningBalanceBeforeBlockForChain(block: number, chain: number, l1Token: string): TokenRunningBalance {
@@ -793,18 +797,19 @@ export class HubPoolClient extends BaseAbstractClient {
793
797
  return this.getRunningBalanceForToken(l1Token, executedRootBundle);
794
798
  }
795
799
 
796
- public getRunningBalanceForToken(l1Token: string, executedRootBundle: ExecutedRootBundle): TokenRunningBalance {
800
+ public getRunningBalanceForToken(
801
+ l1Token: string,
802
+ executedRootBundle: ExecutedRootBundle | undefined
803
+ ): TokenRunningBalance {
797
804
  let runningBalance = toBN(0);
798
- let incentiveBalance = toBN(0);
799
805
  if (executedRootBundle) {
800
806
  const indexOfL1Token = executedRootBundle.l1Tokens
801
807
  .map((l1Token) => l1Token.toLowerCase())
802
808
  .indexOf(l1Token.toLowerCase());
803
809
  runningBalance = executedRootBundle.runningBalances[indexOfL1Token];
804
- incentiveBalance = executedRootBundle.incentiveBalances[indexOfL1Token];
805
810
  }
806
811
 
807
- return { runningBalance, incentiveBalance };
812
+ return { runningBalance };
808
813
  }
809
814
 
810
815
  async _update(eventNames: HubPoolEvent[]): Promise<HubPoolUpdate> {
@@ -1009,8 +1014,6 @@ export class HubPoolClient extends BaseAbstractClient {
1009
1014
  );
1010
1015
  }
1011
1016
  executedRootBundle.runningBalances = runningBalances.slice(0, nTokens);
1012
- executedRootBundle.incentiveBalances =
1013
- runningBalances.length > nTokens ? runningBalances.slice(nTokens) : runningBalances.map(() => toBN(0));
1014
1017
  this.executedRootBundles.push(executedRootBundle);
1015
1018
  }
1016
1019
  }
@@ -1,9 +1,11 @@
1
+ import assert from "assert";
1
2
  import { Contract, EventFilter } from "ethers";
2
3
  import winston from "winston";
3
4
  import {
4
5
  AnyObject,
5
6
  BigNumber,
6
7
  bnZero,
8
+ bnUint32Max,
7
9
  DefaultLogLevels,
8
10
  EventSearchConfig,
9
11
  MAX_BIG_INT,
@@ -54,7 +56,6 @@ import { getRepaymentChainId, forceDestinationRepayment } from "./BundleDataClie
54
56
  type SpokePoolUpdateSuccess = {
55
57
  success: true;
56
58
  currentTime: number;
57
- oldestTime: number;
58
59
  firstDepositId: BigNumber;
59
60
  latestDepositId: BigNumber;
60
61
  events: Log[][];
@@ -72,7 +73,6 @@ export type SpokePoolUpdate = SpokePoolUpdateSuccess | SpokePoolUpdateFailure;
72
73
  */
73
74
  export class SpokePoolClient extends BaseAbstractClient {
74
75
  protected currentTime = 0;
75
- protected oldestTime = 0;
76
76
  protected depositHashes: { [depositHash: string]: DepositWithBlock } = {};
77
77
  protected duplicateDepositHashes: { [depositHash: string]: DepositWithBlock[] } = {};
78
78
  protected depositHashesToFills: { [depositHash: string]: FillWithBlock[] } = {};
@@ -543,12 +543,11 @@ export class SpokePoolClient extends BaseAbstractClient {
543
543
 
544
544
  const timerStart = Date.now();
545
545
  const multicallFunctions = ["getCurrentTime", "numberOfDeposits"];
546
- const [multicallOutput, oldestTime, ...events] = await Promise.all([
546
+ const [multicallOutput, ...events] = await Promise.all([
547
547
  spokePool.callStatic.multicall(
548
548
  multicallFunctions.map((f) => spokePool.interface.encodeFunctionData(f)),
549
549
  { blockTag: searchConfig.toBlock }
550
550
  ),
551
- this.spokePool.getCurrentTime({ blockTag: Math.max(searchConfig.fromBlock, this.deploymentBlock) }),
552
551
  ...eventSearchConfigs.map((config) => paginatedEventQuery(this.spokePool, config.filter, config.searchConfig)),
553
552
  ]);
554
553
  this.log("debug", `Time to query new events from RPC for ${this.chainId}: ${Date.now() - timerStart} ms`);
@@ -571,7 +570,6 @@ export class SpokePoolClient extends BaseAbstractClient {
571
570
  return {
572
571
  success: true,
573
572
  currentTime: currentTime.toNumber(), // uint32
574
- oldestTime: oldestTime.toNumber(),
575
573
  firstDepositId,
576
574
  latestDepositId: _latestDepositId.gt(bnZero) ? _latestDepositId : bnZero,
577
575
  searchEndBlock: searchConfig.toBlock,
@@ -597,7 +595,7 @@ export class SpokePoolClient extends BaseAbstractClient {
597
595
  if (!update.success) {
598
596
  return;
599
597
  }
600
- const { events: queryResults, currentTime, oldestTime, searchEndBlock } = update;
598
+ const { events: queryResults, currentTime, searchEndBlock } = update;
601
599
 
602
600
  if (eventsToQuery.includes("TokensBridged")) {
603
601
  // Temporarily query old spoke pool events as well to ease migration:
@@ -660,11 +658,7 @@ export class SpokePoolClient extends BaseAbstractClient {
660
658
  if (this.depositHashes[getRelayEventKey(deposit)] !== undefined) {
661
659
  // Sanity check that this event is not a duplicate, even though the relay data hash is a duplicate.
662
660
  const allDeposits = this._getDuplicateDeposits(deposit).concat(this.depositHashes[getRelayEventKey(deposit)]);
663
- if (
664
- allDeposits.some((e) => {
665
- return duplicateEvent(deposit, e);
666
- })
667
- ) {
661
+ if (allDeposits.some((e) => duplicateEvent(deposit, e))) {
668
662
  duplicateEvents.push(event);
669
663
  continue;
670
664
  }
@@ -830,7 +824,6 @@ export class SpokePoolClient extends BaseAbstractClient {
830
824
 
831
825
  // Next iteration should start off from where this one ended.
832
826
  this.currentTime = currentTime;
833
- if (this.oldestTime === 0) this.oldestTime = oldestTime; // Set oldest time only after the first update.
834
827
  this.firstDepositIdForSpokePool = update.firstDepositId;
835
828
  this.latestBlockSearched = searchEndBlock;
836
829
  this.lastDepositIdForSpokePool = update.latestDepositId;
@@ -920,11 +913,13 @@ export class SpokePoolClient extends BaseAbstractClient {
920
913
  }
921
914
 
922
915
  /**
923
- * Retrieves the oldest time searched on the SpokePool contract.
924
- * @returns The oldest time searched, which will be 0 if there has been no update() yet.
916
+ * Retrieves the time from the SpokePool contract at a particular block.
917
+ * @returns The time at the specified block tag.
925
918
  */
926
- public getOldestTime(): number {
927
- return this.oldestTime;
919
+ public async getTimeAt(blockNumber: number): Promise<number> {
920
+ const currentTime = await this.spokePool.getCurrentTime({ blockTag: blockNumber });
921
+ assert(BigNumber.isBigNumber(currentTime) && currentTime.lt(bnUint32Max));
922
+ return currentTime.toNumber();
928
923
  }
929
924
 
930
925
  async findDeposit(depositId: BigNumber, destinationChainId: number): Promise<DepositWithBlock> {
@@ -54,7 +54,6 @@ export interface ExecutedRootBundle extends SortableEvent {
54
54
  bundleLpFees: BigNumber[];
55
55
  netSendAmounts: BigNumber[];
56
56
  runningBalances: BigNumber[];
57
- incentiveBalances: BigNumber[];
58
57
  leafId: number;
59
58
  l1Tokens: string[];
60
59
  proof: string[];
@@ -62,17 +61,15 @@ export interface ExecutedRootBundle extends SortableEvent {
62
61
 
63
62
  export type ExecutedRootBundleStringified = Omit<
64
63
  ExecutedRootBundle,
65
- "bundleLpFees" | "netSendAmounts" | "runningBalances" | "incentiveBalances"
64
+ "bundleLpFees" | "netSendAmounts" | "runningBalances"
66
65
  > & {
67
66
  bundleLpFees: string[];
68
67
  netSendAmounts: string[];
69
68
  runningBalances: string[];
70
- incentiveBalances: string[];
71
69
  };
72
70
 
73
71
  export type TokenRunningBalance = {
74
72
  runningBalance: BigNumber;
75
- incentiveBalance: BigNumber;
76
73
  };
77
74
 
78
75
  export interface RelayerRefundLeafWithGroup extends RelayerRefundLeaf {
@@ -13,10 +13,10 @@ import {
13
13
  BigNumber,
14
14
  toBNWei,
15
15
  bnZero,
16
- assert,
17
16
  chainIsOPStack,
18
17
  fixedPointAdjustment,
19
18
  } from "../../utils";
19
+ import assert from "assert";
20
20
  import { Logger, QueryInterface } from "../relayFeeCalculator";
21
21
  import { Transport } from "viem";
22
22
  import { getGasPriceEstimate } from "../../gasPriceOracle/oracle";
@@ -1,6 +1,6 @@
1
1
  import { DEFAULT_CACHING_SAFE_LAG, DEFAULT_CACHING_TTL } from "../constants";
2
2
  import { CachingMechanismInterface, Deposit, Fill, SlowFillRequest } from "../interfaces";
3
- import { assert } from "./LogUtils";
3
+ import assert from "assert";
4
4
  import { composeRevivers, objectWithBigNumberReviver } from "./ReviverUtils";
5
5
  import { getRelayEventKey } from "./SpokeUtils";
6
6
  import { getCurrentTime } from "./TimeUtils";
@@ -24,15 +24,3 @@ export function formattedLog(
24
24
  });
25
25
  }
26
26
  }
27
-
28
- /**
29
- * Asserts the truth of a condition. If the condition is false, an error is thrown with the provided message.
30
- * @param condition The condition to assert.
31
- * @param message The message to throw if the condition is false.
32
- * @throws Error if the condition is false.
33
- */
34
- export function assert(condition: boolean, message: string): void {
35
- if (!condition) {
36
- throw new Error(message);
37
- }
38
- }
@@ -34,6 +34,7 @@ const DETERMINISTIC_MULTICALL_CHAINS = [
34
34
  CHAIN_IDs.POLYGON_AMOY,
35
35
  CHAIN_IDs.SCROLL_SEPOLIA,
36
36
  CHAIN_IDs.SEPOLIA,
37
+ CHAIN_IDs.ARBITRUM_SEPOLIA,
37
38
  ];
38
39
 
39
40
  export function getMulticallAddress(chainId: number): string | undefined {