@across-protocol/sdk 3.1.31 → 3.1.33

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 (73) 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/clients/BundleDataClient/BundleDataClient.js +10 -12
  4. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  5. package/dist/cjs/clients/SpokePoolClient.d.ts +3 -1
  6. package/dist/cjs/clients/SpokePoolClient.js +16 -0
  7. package/dist/cjs/clients/SpokePoolClient.js.map +1 -1
  8. package/dist/cjs/providers/constants.d.ts +0 -1
  9. package/dist/cjs/providers/constants.js +1 -2
  10. package/dist/cjs/providers/constants.js.map +1 -1
  11. package/dist/cjs/providers/index.d.ts +1 -0
  12. package/dist/cjs/providers/index.js +1 -0
  13. package/dist/cjs/providers/index.js.map +1 -1
  14. package/dist/cjs/providers/speedProvider.d.ts +10 -0
  15. package/dist/cjs/providers/speedProvider.js +59 -0
  16. package/dist/cjs/providers/speedProvider.js.map +1 -0
  17. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +1 -1
  18. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +2 -2
  19. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +1 -1
  20. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +2 -2
  21. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  22. package/dist/cjs/utils/common.d.ts +1 -1
  23. package/dist/cjs/utils/common.js +28 -22
  24. package/dist/cjs/utils/common.js.map +1 -1
  25. package/dist/esm/caching/Arweave/ArweaveClient.js +12 -2
  26. package/dist/esm/caching/Arweave/ArweaveClient.js.map +1 -1
  27. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +11 -13
  28. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  29. package/dist/esm/clients/SpokePoolClient.d.ts +9 -1
  30. package/dist/esm/clients/SpokePoolClient.js +23 -1
  31. package/dist/esm/clients/SpokePoolClient.js.map +1 -1
  32. package/dist/esm/providers/constants.d.ts +0 -4
  33. package/dist/esm/providers/constants.js +0 -4
  34. package/dist/esm/providers/constants.js.map +1 -1
  35. package/dist/esm/providers/index.d.ts +1 -0
  36. package/dist/esm/providers/index.js +1 -0
  37. package/dist/esm/providers/index.js.map +1 -1
  38. package/dist/esm/providers/speedProvider.d.ts +13 -0
  39. package/dist/esm/providers/speedProvider.js +63 -0
  40. package/dist/esm/providers/speedProvider.js.map +1 -0
  41. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +2 -2
  42. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +3 -3
  43. package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +3 -1
  44. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +4 -2
  45. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  46. package/dist/esm/utils/common.d.ts +2 -2
  47. package/dist/esm/utils/common.js +29 -23
  48. package/dist/esm/utils/common.js.map +1 -1
  49. package/dist/types/caching/Arweave/ArweaveClient.d.ts.map +1 -1
  50. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  51. package/dist/types/clients/SpokePoolClient.d.ts +9 -1
  52. package/dist/types/clients/SpokePoolClient.d.ts.map +1 -1
  53. package/dist/types/providers/constants.d.ts +0 -4
  54. package/dist/types/providers/constants.d.ts.map +1 -1
  55. package/dist/types/providers/index.d.ts +1 -0
  56. package/dist/types/providers/index.d.ts.map +1 -1
  57. package/dist/types/providers/speedProvider.d.ts +14 -0
  58. package/dist/types/providers/speedProvider.d.ts.map +1 -0
  59. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +2 -2
  60. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +3 -1
  61. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
  62. package/dist/types/utils/common.d.ts +2 -2
  63. package/dist/types/utils/common.d.ts.map +1 -1
  64. package/package.json +1 -1
  65. package/src/caching/Arweave/ArweaveClient.ts +15 -7
  66. package/src/clients/BundleDataClient/BundleDataClient.ts +3 -5
  67. package/src/clients/SpokePoolClient.ts +21 -1
  68. package/src/providers/constants.ts +0 -5
  69. package/src/providers/index.ts +1 -0
  70. package/src/providers/speedProvider.ts +63 -0
  71. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +3 -3
  72. package/src/relayFeeCalculator/relayFeeCalculator.ts +4 -2
  73. package/src/utils/common.ts +8 -7
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@across-protocol/sdk",
3
3
  "author": "UMA Team",
4
- "version": "3.1.31",
4
+ "version": "3.1.33",
5
5
  "license": "AGPL-3.0",
6
6
  "homepage": "https://docs.across.to/reference/sdk",
7
7
  "files": [
@@ -175,13 +175,21 @@ export class ArweaveClient {
175
175
  });
176
176
  const results = await Promise.all(
177
177
  entries.map(async (edge) => {
178
- const data = await this.get<T>(edge.node.id, validator);
179
- return isDefined(data)
180
- ? {
181
- data,
182
- hash: edge.node.id,
183
- }
184
- : null;
178
+ try {
179
+ const data = await this.get<T>(edge.node.id, validator);
180
+ return isDefined(data)
181
+ ? {
182
+ data,
183
+ hash: edge.node.id,
184
+ }
185
+ : null;
186
+ } catch (e) {
187
+ this.logger.warn({
188
+ at: "ArweaveClient:getByTopic",
189
+ message: `Bad request for Arweave topic ${edge.node.id}: ${e}`,
190
+ });
191
+ return null;
192
+ }
185
193
  })
186
194
  );
187
195
  return results.filter(isDefined);
@@ -29,7 +29,6 @@ import {
29
29
  getImpliedBundleBlockRanges,
30
30
  isSlowFill,
31
31
  mapAsync,
32
- relayFillStatus,
33
32
  bnUint32Max,
34
33
  } from "../../utils";
35
34
  import { BigNumber } from "ethers";
@@ -1125,8 +1124,7 @@ export class BundleDataClient {
1125
1124
  ) {
1126
1125
  // If we haven't seen a fill matching this deposit, then we need to rule out that it was filled a long time ago
1127
1126
  // by checkings its on-chain fill status.
1128
- const fillStatus = await relayFillStatus(
1129
- spokePoolClients[destinationChainId].spokePool,
1127
+ const fillStatus = await spokePoolClients[destinationChainId].relayFillStatus(
1130
1128
  deposit,
1131
1129
  // We can assume that in production
1132
1130
  // the block ranges passed into this function would never contain blocks where the spoke pool client
@@ -1313,8 +1311,8 @@ export class BundleDataClient {
1313
1311
  const startBlockForChain = Math.min(_startBlockForChain, spokePoolClient.latestBlockSearched);
1314
1312
  const endBlockForChain = Math.min(_endBlockForChain, spokePoolClient.latestBlockSearched);
1315
1313
  const [startTime, endTime] = [
1316
- Number((await spokePoolClient.spokePool.provider.getBlock(startBlockForChain)).timestamp),
1317
- Number((await spokePoolClient.spokePool.provider.getBlock(endBlockForChain)).timestamp),
1314
+ await spokePoolClient.getTimestampForBlock(startBlockForChain),
1315
+ await spokePoolClient.getTimestampForBlock(endBlockForChain),
1318
1316
  ];
1319
1317
  // Sanity checks:
1320
1318
  assert(endTime >= startTime, "End time should be greater than start time.");
@@ -25,6 +25,7 @@ import {
25
25
  Deposit,
26
26
  DepositWithBlock,
27
27
  Fill,
28
+ FillStatus,
28
29
  FillWithBlock,
29
30
  FilledV3RelayEvent,
30
31
  RealizedLpFee,
@@ -38,7 +39,7 @@ import {
38
39
  } from "../interfaces";
39
40
  import { SpokePool } from "../typechain";
40
41
  import { getNetworkName } from "../utils/NetworkUtils";
41
- import { getBlockRangeForDepositId, getDepositIdAtBlock } from "../utils/SpokeUtils";
42
+ import { getBlockRangeForDepositId, getDepositIdAtBlock, relayFillStatus } from "../utils/SpokeUtils";
42
43
  import { BaseAbstractClient, isUpdateFailureReason, UpdateFailureReason } from "./BaseAbstractClient";
43
44
  import { HubPoolClient } from "./HubPoolClient";
44
45
  import { AcrossConfigStoreClient } from "./AcrossConfigStoreClient";
@@ -883,4 +884,23 @@ export class SpokePoolClient extends BaseAbstractClient {
883
884
  this.configStoreClient?.isChainLiteChainAtTimestamp(deposit.destinationChainId, deposit.quoteTimestamp) ?? false
884
885
  );
885
886
  }
887
+
888
+ public async getTimestampForBlock(blockTag: number): Promise<number> {
889
+ const block = await this.spokePool.provider.getBlock(blockTag);
890
+ return Number(block.timestamp);
891
+ }
892
+
893
+ /**
894
+ * Find the amount filled for a deposit at a particular block.
895
+ * @param relayData Deposit information that is used to complete a fill.
896
+ * @param blockTag Block tag (numeric or "latest") to query at.
897
+ * @returns The amount filled for the specified deposit at the requested block (or latest).
898
+ */
899
+ public relayFillStatus(
900
+ relayData: RelayData,
901
+ blockTag?: number | "latest",
902
+ destinationChainId?: number
903
+ ): Promise<FillStatus> {
904
+ return relayFillStatus(this.spokePool, relayData, blockTag, destinationChainId);
905
+ }
886
906
  }
@@ -4,8 +4,3 @@ export const BLOCK_NUMBER_TTL = 60;
4
4
  // This is the TTL for the provider cache.
5
5
  export const PROVIDER_CACHE_TTL = 3600;
6
6
  export const PROVIDER_CACHE_TTL_MODIFIER = 0.15;
7
-
8
- /**
9
- * A default timeout for requests of 60 seconds.
10
- */
11
- export const defaultTimeout = 60 * 1000;
@@ -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";
@@ -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
+ }
@@ -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.