@across-protocol/sdk 3.1.30 → 3.1.32

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 (61) hide show
  1. package/dist/cjs/caching/Arweave/ArweaveClient.js +12 -2
  2. package/dist/cjs/caching/Arweave/ArweaveClient.js.map +1 -1
  3. package/dist/cjs/providers/index.d.ts +1 -0
  4. package/dist/cjs/providers/index.js +1 -0
  5. package/dist/cjs/providers/index.js.map +1 -1
  6. package/dist/cjs/providers/retryProvider.js +9 -0
  7. package/dist/cjs/providers/retryProvider.js.map +1 -1
  8. package/dist/cjs/providers/speedProvider.d.ts +10 -0
  9. package/dist/cjs/providers/speedProvider.js +59 -0
  10. package/dist/cjs/providers/speedProvider.js.map +1 -0
  11. package/dist/cjs/providers/utils.js +2 -0
  12. package/dist/cjs/providers/utils.js.map +1 -1
  13. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +1 -1
  14. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +2 -2
  15. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +1 -1
  16. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +2 -2
  17. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  18. package/dist/cjs/utils/common.d.ts +1 -1
  19. package/dist/cjs/utils/common.js +28 -22
  20. package/dist/cjs/utils/common.js.map +1 -1
  21. package/dist/esm/caching/Arweave/ArweaveClient.js +12 -2
  22. package/dist/esm/caching/Arweave/ArweaveClient.js.map +1 -1
  23. package/dist/esm/providers/index.d.ts +1 -0
  24. package/dist/esm/providers/index.js +1 -0
  25. package/dist/esm/providers/index.js.map +1 -1
  26. package/dist/esm/providers/retryProvider.js +10 -0
  27. package/dist/esm/providers/retryProvider.js.map +1 -1
  28. package/dist/esm/providers/speedProvider.d.ts +13 -0
  29. package/dist/esm/providers/speedProvider.js +63 -0
  30. package/dist/esm/providers/speedProvider.js.map +1 -0
  31. package/dist/esm/providers/utils.js +3 -1
  32. package/dist/esm/providers/utils.js.map +1 -1
  33. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +2 -2
  34. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +3 -3
  35. package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +3 -1
  36. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +4 -2
  37. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  38. package/dist/esm/utils/common.d.ts +2 -2
  39. package/dist/esm/utils/common.js +29 -23
  40. package/dist/esm/utils/common.js.map +1 -1
  41. package/dist/types/caching/Arweave/ArweaveClient.d.ts.map +1 -1
  42. package/dist/types/providers/index.d.ts +1 -0
  43. package/dist/types/providers/index.d.ts.map +1 -1
  44. package/dist/types/providers/retryProvider.d.ts.map +1 -1
  45. package/dist/types/providers/speedProvider.d.ts +14 -0
  46. package/dist/types/providers/speedProvider.d.ts.map +1 -0
  47. package/dist/types/providers/utils.d.ts.map +1 -1
  48. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +2 -2
  49. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +3 -1
  50. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
  51. package/dist/types/utils/common.d.ts +2 -2
  52. package/dist/types/utils/common.d.ts.map +1 -1
  53. package/package.json +1 -1
  54. package/src/caching/Arweave/ArweaveClient.ts +15 -7
  55. package/src/providers/index.ts +1 -0
  56. package/src/providers/retryProvider.ts +12 -0
  57. package/src/providers/speedProvider.ts +63 -0
  58. package/src/providers/utils.ts +2 -0
  59. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +3 -3
  60. package/src/relayFeeCalculator/relayFeeCalculator.ts +4 -2
  61. package/src/utils/common.ts +8 -7
@@ -1,6 +1,7 @@
1
1
  export * from "./rateLimitedProvider";
2
2
  export * from "./cachedProvider";
3
3
  export * from "./retryProvider";
4
+ export * from "./speedProvider";
4
5
  export * from "./constants";
5
6
  export * from "./types";
6
7
  export * from "./utils";
@@ -41,6 +41,18 @@ export class RetryProvider extends ethers.providers.StaticJsonRpcProvider {
41
41
  ...inputs
42
42
  )
43
43
  );
44
+
45
+ // This is added for interim testing to see whether relayer fill performance improves.
46
+ this.providers.forEach((provider) => {
47
+ const url = getOriginFromURL(provider.connection.url);
48
+ const { pollingInterval } = provider;
49
+ provider.pollingInterval = 1000;
50
+ logger?.debug({
51
+ at: "RetryProvider",
52
+ message: `Dropped ${url} pollingInterval ${pollingInterval} -> ${provider.pollingInterval}.`,
53
+ });
54
+ });
55
+
44
56
  if (this.nodeQuorumThreshold < 1 || !Number.isInteger(this.nodeQuorumThreshold)) {
45
57
  throw new Error(
46
58
  `nodeQuorum,Threshold cannot be < 1 and must be an integer. Currently set to ${this.nodeQuorumThreshold}`
@@ -0,0 +1,63 @@
1
+ import { ethers } from "ethers";
2
+ import { CachingMechanismInterface } from "../interfaces";
3
+ import { CacheProvider } from "./cachedProvider";
4
+ import { formatProviderError } from "./utils";
5
+ import { PROVIDER_CACHE_TTL } from "./constants";
6
+ import { Logger } from "winston";
7
+
8
+ /**
9
+ * RPC provider that sends requests to multiple providers in parallel and returns the fastest response.
10
+ */
11
+ export class SpeedProvider extends ethers.providers.StaticJsonRpcProvider {
12
+ readonly providers: ethers.providers.StaticJsonRpcProvider[];
13
+
14
+ constructor(
15
+ params: ConstructorParameters<typeof ethers.providers.StaticJsonRpcProvider>[],
16
+ chainId: number,
17
+ readonly maxConcurrencySpeed: number,
18
+ readonly maxConcurrencyRateLimit: number,
19
+ providerCacheNamespace: string,
20
+ pctRpcCallsLogged: number,
21
+ redisClient?: CachingMechanismInterface,
22
+ standardTtlBlockDistance?: number,
23
+ noTtlBlockDistance?: number,
24
+ providerCacheTtl = PROVIDER_CACHE_TTL,
25
+ logger?: Logger
26
+ ) {
27
+ // Initialize the super just with the chainId, which stops it from trying to immediately send out a .send before
28
+ // this derived class is initialized.
29
+ super(undefined, chainId);
30
+ this.providers = params.map(
31
+ (inputs) =>
32
+ new CacheProvider(
33
+ providerCacheNamespace,
34
+ redisClient,
35
+ standardTtlBlockDistance,
36
+ noTtlBlockDistance,
37
+ providerCacheTtl,
38
+ maxConcurrencyRateLimit,
39
+ pctRpcCallsLogged,
40
+ logger,
41
+ ...inputs
42
+ )
43
+ );
44
+ }
45
+
46
+ override async send(method: string, params: Array<unknown>): Promise<unknown> {
47
+ try {
48
+ const providersToUse = this.providers.slice(0, this.maxConcurrencySpeed);
49
+ const result = await Promise.any(providersToUse.map((provider) => provider.send(method, params)));
50
+ return result;
51
+ } catch (error) {
52
+ // Only thrown if all providers failed to respond
53
+ if (error instanceof AggregateError) {
54
+ const errors = error.errors.map((error, index) => {
55
+ const provider = this.providers[index];
56
+ return formatProviderError(provider, error.message);
57
+ });
58
+ throw new Error("All providers errored:\n" + errors.join("\n"));
59
+ }
60
+ throw error;
61
+ }
62
+ }
63
+ }
@@ -102,6 +102,8 @@ const IGNORED_FIELDS = {
102
102
  "l1BatchTimestamp", // zkSync
103
103
  "size", // Alchemy/Arbitrum (temporary)
104
104
  "totalDifficulty", // Quicknode/Alchemy (sometimes)
105
+ "logsBloom", // zkSync (third-party providers return 0x0..0)
106
+ "transactions", // Polygon yParity field in transactions[]
105
107
  ],
106
108
  eth_getLogs: ["blockTimestamp", "transactionLogIndex", "l1BatchNumber", "logType"],
107
109
  };
@@ -59,14 +59,14 @@ export class QueryBase implements QueryInterface {
59
59
  * @param deposit V3 deposit instance.
60
60
  * @param relayerAddress Relayer address to simulate with.
61
61
  * @param gasPrice Optional gas price to use for the simulation.
62
- * @param gasLimit Optional gas limit to use for the simulation.
62
+ * @param gasUnits Optional gas units to use for the simulation.
63
63
  * @returns The gas estimate for this function call (multiplied with the optional buffer).
64
64
  */
65
65
  async getGasCosts(
66
66
  deposit: Deposit,
67
67
  relayer = DEFAULT_SIMULATED_RELAYER_ADDRESS,
68
68
  gasPrice = this.fixedGasPrice,
69
- gasLimit?: BigNumberish
69
+ gasUnits?: BigNumberish
70
70
  ): Promise<TransactionCostEstimate> {
71
71
  const tx = await populateV3Relay(this.spokePool, deposit, relayer);
72
72
  return estimateTotalGasRequiredByUnsignedTransaction(
@@ -75,7 +75,7 @@ export class QueryBase implements QueryInterface {
75
75
  this.provider,
76
76
  this.gasMarkup,
77
77
  gasPrice,
78
- gasLimit
78
+ gasUnits
79
79
  );
80
80
  }
81
81
 
@@ -342,6 +342,8 @@ export class RelayFeeCalculator {
342
342
  * the relayer.
343
343
  * @param relayerAddress The relayer that will be used for the gas cost simulation
344
344
  * @param _tokenPrice The token price for normalizing fees
345
+ * @param gasPrice Optional gas price to use for the simulation
346
+ * @param gasUnits Optional gas units to use for the simulation
345
347
  * @returns A resulting `RelayerFeeDetails` object
346
348
  */
347
349
  async relayerFeeDetails(
@@ -351,7 +353,7 @@ export class RelayFeeCalculator {
351
353
  relayerAddress = DEFAULT_SIMULATED_RELAYER_ADDRESS,
352
354
  _tokenPrice?: number,
353
355
  gasPrice?: BigNumberish,
354
- gasLimit?: BigNumberish
356
+ gasUnits?: BigNumberish
355
357
  ): Promise<RelayerFeeDetails> {
356
358
  // If the amount to relay is not provided, then we
357
359
  // should use the full deposit amount.
@@ -370,7 +372,7 @@ export class RelayFeeCalculator {
370
372
  _tokenPrice,
371
373
  undefined,
372
374
  gasPrice,
373
- gasLimit
375
+ gasUnits
374
376
  );
375
377
  const gasFeeTotal = gasFeePercent.mul(amountToRelay).div(fixedPointAdjustment);
376
378
  const capitalFeePercent = this.capitalFeePercent(
@@ -242,7 +242,7 @@ export type TransactionCostEstimate = {
242
242
  * @param provider A valid ethers provider - will be used to reason the gas price.
243
243
  * @param gasMarkup Markup on the estimated gas cost. For example, 0.2 will increase this resulting value 1.2x.
244
244
  * @param gasPrice A manually provided gas price - if set, this function will not resolve the current gas price.
245
- * @param gasLimit A manually provided gas limit - if set, this function will not estimate the gas limit.
245
+ * @param gasUnits A manually provided gas units - if set, this function will not estimate the gas units.
246
246
  * @returns Estimated cost in units of gas and the underlying gas token (gasPrice * estimatedGasUnits).
247
247
  */
248
248
  export async function estimateTotalGasRequiredByUnsignedTransaction(
@@ -251,7 +251,7 @@ export async function estimateTotalGasRequiredByUnsignedTransaction(
251
251
  provider: providers.Provider | L2Provider<providers.Provider>,
252
252
  gasMarkup: number,
253
253
  gasPrice?: BigNumberish,
254
- gasLimit?: BigNumberish
254
+ gasUnits?: BigNumberish
255
255
  ): Promise<TransactionCostEstimate> {
256
256
  assert(
257
257
  gasMarkup > -1 && gasMarkup <= 4,
@@ -262,11 +262,12 @@ export async function estimateTotalGasRequiredByUnsignedTransaction(
262
262
  const voidSigner = new VoidSigner(senderAddress, provider);
263
263
 
264
264
  // Estimate the Gas units required to submit this transaction.
265
- let nativeGasCost = await voidSigner.estimateGas({
266
- ...unsignedTx,
267
- gasPrice,
268
- gasLimit,
269
- });
265
+ let nativeGasCost = gasUnits
266
+ ? BigNumber.from(gasUnits)
267
+ : await voidSigner.estimateGas({
268
+ ...unsignedTx,
269
+ gasPrice,
270
+ });
270
271
  let tokenGasCost: BigNumber;
271
272
 
272
273
  // OP stack is a special case; gas cost is computed by the SDK, without having to query price.