@across-protocol/sdk 3.3.32 → 3.4.0

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 (142) hide show
  1. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +10 -10
  2. package/dist/cjs/gasPriceOracle/adapters/arbitrum.d.ts +2 -1
  3. package/dist/cjs/gasPriceOracle/adapters/arbitrum.js +2 -2
  4. package/dist/cjs/gasPriceOracle/adapters/arbitrum.js.map +1 -1
  5. package/dist/cjs/gasPriceOracle/adapters/ethereum.d.ts +6 -4
  6. package/dist/cjs/gasPriceOracle/adapters/ethereum.js +21 -13
  7. package/dist/cjs/gasPriceOracle/adapters/ethereum.js.map +1 -1
  8. package/dist/cjs/gasPriceOracle/adapters/linea-viem.d.ts +2 -1
  9. package/dist/cjs/gasPriceOracle/adapters/linea-viem.js +16 -10
  10. package/dist/cjs/gasPriceOracle/adapters/linea-viem.js.map +1 -1
  11. package/dist/cjs/gasPriceOracle/adapters/linea.d.ts +2 -1
  12. package/dist/cjs/gasPriceOracle/adapters/linea.js +2 -2
  13. package/dist/cjs/gasPriceOracle/adapters/linea.js.map +1 -1
  14. package/dist/cjs/gasPriceOracle/adapters/polygon.d.ts +21 -1
  15. package/dist/cjs/gasPriceOracle/adapters/polygon.js +45 -5
  16. package/dist/cjs/gasPriceOracle/adapters/polygon.js.map +1 -1
  17. package/dist/cjs/gasPriceOracle/oracle.d.ts +11 -3
  18. package/dist/cjs/gasPriceOracle/oracle.js +29 -27
  19. package/dist/cjs/gasPriceOracle/oracle.js.map +1 -1
  20. package/dist/cjs/providers/types.d.ts +3 -3
  21. package/dist/cjs/relayFeeCalculator/chain-queries/alephZero.d.ts +0 -229
  22. package/dist/cjs/relayFeeCalculator/chain-queries/alephZero.js +2 -12
  23. package/dist/cjs/relayFeeCalculator/chain-queries/alephZero.js.map +1 -1
  24. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +10 -5
  25. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +55 -11
  26. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  27. package/dist/cjs/relayFeeCalculator/chain-queries/factory.d.ts +1 -1
  28. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js +4 -5
  29. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  30. package/dist/cjs/relayFeeCalculator/chain-queries/polygon.d.ts +0 -229
  31. package/dist/cjs/relayFeeCalculator/chain-queries/polygon.js +2 -12
  32. package/dist/cjs/relayFeeCalculator/chain-queries/polygon.js.map +1 -1
  33. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +1 -1
  34. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  35. package/dist/cjs/utils/common.d.ts +1 -8
  36. package/dist/cjs/utils/common.js +1 -83
  37. package/dist/cjs/utils/common.js.map +1 -1
  38. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +10 -10
  39. package/dist/esm/gasPriceOracle/adapters/arbitrum.d.ts +10 -1
  40. package/dist/esm/gasPriceOracle/adapters/arbitrum.js +10 -4
  41. package/dist/esm/gasPriceOracle/adapters/arbitrum.js.map +1 -1
  42. package/dist/esm/gasPriceOracle/adapters/ethereum.d.ts +19 -6
  43. package/dist/esm/gasPriceOracle/adapters/ethereum.js +38 -16
  44. package/dist/esm/gasPriceOracle/adapters/ethereum.js.map +1 -1
  45. package/dist/esm/gasPriceOracle/adapters/linea-viem.d.ts +19 -1
  46. package/dist/esm/gasPriceOracle/adapters/linea-viem.js +33 -10
  47. package/dist/esm/gasPriceOracle/adapters/linea-viem.js.map +1 -1
  48. package/dist/esm/gasPriceOracle/adapters/linea.d.ts +2 -1
  49. package/dist/esm/gasPriceOracle/adapters/linea.js +6 -2
  50. package/dist/esm/gasPriceOracle/adapters/linea.js.map +1 -1
  51. package/dist/esm/gasPriceOracle/adapters/polygon.d.ts +27 -1
  52. package/dist/esm/gasPriceOracle/adapters/polygon.js +49 -5
  53. package/dist/esm/gasPriceOracle/adapters/polygon.js.map +1 -1
  54. package/dist/esm/gasPriceOracle/oracle.d.ts +16 -8
  55. package/dist/esm/gasPriceOracle/oracle.js +35 -33
  56. package/dist/esm/gasPriceOracle/oracle.js.map +1 -1
  57. package/dist/esm/providers/types.d.ts +3 -3
  58. package/dist/esm/relayFeeCalculator/chain-queries/alephZero.d.ts +0 -229
  59. package/dist/esm/relayFeeCalculator/chain-queries/alephZero.js +3 -13
  60. package/dist/esm/relayFeeCalculator/chain-queries/alephZero.js.map +1 -1
  61. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +21 -7
  62. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +68 -15
  63. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  64. package/dist/esm/relayFeeCalculator/chain-queries/factory.d.ts +1 -1
  65. package/dist/esm/relayFeeCalculator/chain-queries/factory.js +4 -5
  66. package/dist/esm/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  67. package/dist/esm/relayFeeCalculator/chain-queries/polygon.d.ts +0 -229
  68. package/dist/esm/relayFeeCalculator/chain-queries/polygon.js +3 -13
  69. package/dist/esm/relayFeeCalculator/chain-queries/polygon.js.map +1 -1
  70. package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +1 -1
  71. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  72. package/dist/esm/utils/common.d.ts +1 -19
  73. package/dist/esm/utils/common.js +3 -95
  74. package/dist/esm/utils/common.js.map +1 -1
  75. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +10 -10
  76. package/dist/types/gasPriceOracle/adapters/arbitrum.d.ts +10 -1
  77. package/dist/types/gasPriceOracle/adapters/arbitrum.d.ts.map +1 -1
  78. package/dist/types/gasPriceOracle/adapters/ethereum.d.ts +19 -6
  79. package/dist/types/gasPriceOracle/adapters/ethereum.d.ts.map +1 -1
  80. package/dist/types/gasPriceOracle/adapters/linea-viem.d.ts +19 -1
  81. package/dist/types/gasPriceOracle/adapters/linea-viem.d.ts.map +1 -1
  82. package/dist/types/gasPriceOracle/adapters/linea.d.ts +2 -1
  83. package/dist/types/gasPriceOracle/adapters/linea.d.ts.map +1 -1
  84. package/dist/types/gasPriceOracle/adapters/polygon.d.ts +27 -1
  85. package/dist/types/gasPriceOracle/adapters/polygon.d.ts.map +1 -1
  86. package/dist/types/gasPriceOracle/oracle.d.ts +16 -8
  87. package/dist/types/gasPriceOracle/oracle.d.ts.map +1 -1
  88. package/dist/types/providers/types.d.ts +3 -3
  89. package/dist/types/relayFeeCalculator/chain-queries/alephZero.d.ts +0 -229
  90. package/dist/types/relayFeeCalculator/chain-queries/alephZero.d.ts.map +1 -1
  91. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +21 -7
  92. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
  93. package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts +1 -1
  94. package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts.map +1 -1
  95. package/dist/types/relayFeeCalculator/chain-queries/polygon.d.ts +0 -229
  96. package/dist/types/relayFeeCalculator/chain-queries/polygon.d.ts.map +1 -1
  97. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +1 -1
  98. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
  99. package/dist/types/utils/common.d.ts +1 -19
  100. package/dist/types/utils/common.d.ts.map +1 -1
  101. package/package.json +1 -1
  102. package/src/gasPriceOracle/adapters/arbitrum.ts +13 -6
  103. package/src/gasPriceOracle/adapters/ethereum.ts +43 -12
  104. package/src/gasPriceOracle/adapters/linea-viem.ts +32 -6
  105. package/src/gasPriceOracle/adapters/linea.ts +7 -2
  106. package/src/gasPriceOracle/adapters/polygon.ts +46 -5
  107. package/src/gasPriceOracle/oracle.ts +53 -28
  108. package/src/relayFeeCalculator/chain-queries/alephZero.ts +1 -29
  109. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +73 -20
  110. package/src/relayFeeCalculator/chain-queries/factory.ts +6 -6
  111. package/src/relayFeeCalculator/chain-queries/polygon.ts +1 -29
  112. package/src/relayFeeCalculator/relayFeeCalculator.ts +6 -1
  113. package/src/utils/common.ts +2 -92
  114. package/dist/cjs/gasPriceOracle/adapters/arbitrum-viem.d.ts +0 -3
  115. package/dist/cjs/gasPriceOracle/adapters/arbitrum-viem.js +0 -21
  116. package/dist/cjs/gasPriceOracle/adapters/arbitrum-viem.js.map +0 -1
  117. package/dist/cjs/gasPriceOracle/adapters/ethereum-viem.d.ts +0 -4
  118. package/dist/cjs/gasPriceOracle/adapters/ethereum-viem.js +0 -26
  119. package/dist/cjs/gasPriceOracle/adapters/ethereum-viem.js.map +0 -1
  120. package/dist/cjs/gasPriceOracle/adapters/polygon-viem.d.ts +0 -3
  121. package/dist/cjs/gasPriceOracle/adapters/polygon-viem.js +0 -84
  122. package/dist/cjs/gasPriceOracle/adapters/polygon-viem.js.map +0 -1
  123. package/dist/cjs/package.json +0 -1
  124. package/dist/esm/gasPriceOracle/adapters/arbitrum-viem.d.ts +0 -3
  125. package/dist/esm/gasPriceOracle/adapters/arbitrum-viem.js +0 -20
  126. package/dist/esm/gasPriceOracle/adapters/arbitrum-viem.js.map +0 -1
  127. package/dist/esm/gasPriceOracle/adapters/ethereum-viem.d.ts +0 -4
  128. package/dist/esm/gasPriceOracle/adapters/ethereum-viem.js +0 -21
  129. package/dist/esm/gasPriceOracle/adapters/ethereum-viem.js.map +0 -1
  130. package/dist/esm/gasPriceOracle/adapters/polygon-viem.d.ts +0 -3
  131. package/dist/esm/gasPriceOracle/adapters/polygon-viem.js +0 -82
  132. package/dist/esm/gasPriceOracle/adapters/polygon-viem.js.map +0 -1
  133. package/dist/esm/package.json +0 -1
  134. package/dist/types/gasPriceOracle/adapters/arbitrum-viem.d.ts +0 -4
  135. package/dist/types/gasPriceOracle/adapters/arbitrum-viem.d.ts.map +0 -1
  136. package/dist/types/gasPriceOracle/adapters/ethereum-viem.d.ts +0 -5
  137. package/dist/types/gasPriceOracle/adapters/ethereum-viem.d.ts.map +0 -1
  138. package/dist/types/gasPriceOracle/adapters/polygon-viem.d.ts +0 -4
  139. package/dist/types/gasPriceOracle/adapters/polygon-viem.d.ts.map +0 -1
  140. package/src/gasPriceOracle/adapters/arbitrum-viem.ts +0 -13
  141. package/src/gasPriceOracle/adapters/ethereum-viem.ts +0 -19
  142. package/src/gasPriceOracle/adapters/polygon-viem.ts +0 -86
@@ -1,37 +1,61 @@
1
1
  import assert from "assert";
2
2
  import { Transport } from "viem";
3
- import { providers } from "ethers";
3
+ import { PopulatedTransaction, providers } from "ethers";
4
4
  import { CHAIN_IDs } from "../constants";
5
- import { BigNumber, chainIsOPStack } from "../utils";
5
+ import { BigNumber, chainIsOPStack, fixedPointAdjustment, toBNWei } from "../utils";
6
6
  import { GasPriceEstimate } from "./types";
7
7
  import { getPublicClient } from "./util";
8
8
  import * as arbitrum from "./adapters/arbitrum";
9
9
  import * as ethereum from "./adapters/ethereum";
10
10
  import * as linea from "./adapters/linea";
11
11
  import * as polygon from "./adapters/polygon";
12
- import * as arbitrumViem from "./adapters/arbitrum-viem";
13
12
  import * as lineaViem from "./adapters/linea-viem";
14
- import * as polygonViem from "./adapters/polygon-viem";
13
+
14
+ export interface GasPriceEstimateOptions {
15
+ // baseFeeMultiplier Multiplier applied to base fee for EIP1559 gas prices (or total fee for legacy).
16
+ baseFeeMultiplier: BigNumber;
17
+ // legacyFallback In the case of an unrecognized chain, fall back to type 0 gas estimation.
18
+ legacyFallback: boolean;
19
+ // chainId The chain ID to query for gas prices. If omitted can be inferred by provider.
20
+ chainId: number;
21
+ // unsignedTx The unsigned transaction used for simulation by Linea's Viem provider to produce the priority gas fee.
22
+ unsignedTx?: PopulatedTransaction;
23
+ // transport Viem Transport object to use for querying gas fees used for testing.
24
+ transport?: Transport;
25
+ }
26
+
27
+ const GAS_PRICE_ESTIMATE_DEFAULTS = {
28
+ legacyFallback: true,
29
+ };
15
30
 
16
31
  /**
17
32
  * Provide an estimate for the current gas price for a particular chain.
18
- * @param chainId The chain ID to query for gas prices.
19
33
  * @param provider A valid ethers provider.
20
- * @param legacyFallback In the case of an unrecognised chain, fall back to type 0 gas estimation.
21
- * @returns Am object of type GasPriceEstimate.
34
+ * @param {opts} GasPriceEstimateOptions optional parameters.
35
+ * @returns An object of type GasPriceEstimate.
22
36
  */
23
37
  export async function getGasPriceEstimate(
24
38
  provider: providers.Provider,
25
- chainId?: number,
26
- transport?: Transport,
27
- legacyFallback = true
39
+ opts: Partial<GasPriceEstimateOptions> = {}
28
40
  ): Promise<GasPriceEstimate> {
29
- chainId ?? ({ chainId } = await provider.getNetwork());
41
+ const baseFeeMultiplier = opts.baseFeeMultiplier ?? toBNWei("1");
42
+ assert(
43
+ baseFeeMultiplier.gte(toBNWei("1.0")) && baseFeeMultiplier.lte(toBNWei("5")),
44
+ `Require 1.0 < base fee multiplier (${baseFeeMultiplier}) <= 5.0 for a total gas multiplier within [+1.0, +5.0]`
45
+ );
46
+ const chainId = opts.chainId ?? (await provider.getNetwork()).chainId;
47
+ const optsWithDefaults: GasPriceEstimateOptions = {
48
+ ...GAS_PRICE_ESTIMATE_DEFAULTS,
49
+ baseFeeMultiplier,
50
+ ...opts,
51
+ chainId,
52
+ };
30
53
 
54
+ // We only use the unsignedTx in the viem flow.
31
55
  const useViem = process.env[`NEW_GAS_PRICE_ORACLE_${chainId}`] === "true";
32
56
  return useViem
33
- ? getViemGasPriceEstimate(chainId, transport)
34
- : getEthersGasPriceEstimate(provider, chainId, legacyFallback);
57
+ ? _getViemGasPriceEstimate(chainId, optsWithDefaults)
58
+ : _getEthersGasPriceEstimate(provider, optsWithDefaults);
35
59
  }
36
60
 
37
61
  /**
@@ -39,13 +63,14 @@ export async function getGasPriceEstimate(
39
63
  * @param chainId The chain ID to query for gas prices.
40
64
  * @param provider A valid ethers provider.
41
65
  * @param legacyFallback In the case of an unrecognised chain, fall back to type 0 gas estimation.
42
- * @returns Am object of type GasPriceEstimate.
66
+ * @returns An object of type GasPriceEstimate.
43
67
  */
44
- function getEthersGasPriceEstimate(
68
+ function _getEthersGasPriceEstimate(
45
69
  provider: providers.Provider,
46
- chainId: number,
47
- legacyFallback = true
70
+ opts: GasPriceEstimateOptions
48
71
  ): Promise<GasPriceEstimate> {
72
+ const { chainId, legacyFallback } = opts;
73
+
49
74
  const gasPriceFeeds = {
50
75
  [CHAIN_IDs.ALEPH_ZERO]: arbitrum.eip1559,
51
76
  [CHAIN_IDs.ARBITRUM]: arbitrum.eip1559,
@@ -60,39 +85,39 @@ function getEthersGasPriceEstimate(
60
85
  assert(gasPriceFeed || legacyFallback, `No suitable gas price oracle for Chain ID ${chainId}`);
61
86
  gasPriceFeed ??= chainIsOPStack(chainId) ? ethereum.eip1559 : ethereum.legacy;
62
87
 
63
- return gasPriceFeed(provider, chainId);
88
+ return gasPriceFeed(provider, opts);
64
89
  }
65
90
 
66
91
  /**
67
92
  * Provide an estimate for the current gas price for a particular chain.
68
93
  * @param providerOrChainId A valid ethers provider or a chain ID.
69
- * @param transport An optional transport object for custom gas price retrieval.
70
- * @returns Am object of type GasPriceEstimate.
94
+ * @param transport An optional Viem Transport object for custom gas price retrieval.
95
+ * @param unsignedTx Only used in Linea provider to estimate priority gas fee.
96
+ * @returns An object of type GasPriceEstimate.
71
97
  */
72
- export async function getViemGasPriceEstimate(
98
+ export async function _getViemGasPriceEstimate(
73
99
  providerOrChainId: providers.Provider | number,
74
- transport?: Transport
100
+ opts: GasPriceEstimateOptions
75
101
  ): Promise<GasPriceEstimate> {
102
+ const { baseFeeMultiplier, transport } = opts;
103
+
76
104
  const chainId =
77
105
  typeof providerOrChainId === "number" ? providerOrChainId : (await providerOrChainId.getNetwork()).chainId;
78
106
  const viemProvider = getPublicClient(chainId, transport);
79
107
 
80
108
  const gasPriceFeeds = {
81
- [CHAIN_IDs.ALEPH_ZERO]: arbitrumViem.eip1559,
82
- [CHAIN_IDs.ARBITRUM]: arbitrumViem.eip1559,
83
109
  [CHAIN_IDs.LINEA]: lineaViem.eip1559,
84
- [CHAIN_IDs.POLYGON]: polygonViem.gasStation,
85
- } as const;
110
+ };
86
111
 
87
112
  let maxFeePerGas: bigint;
88
113
  let maxPriorityFeePerGas: bigint;
89
114
  if (gasPriceFeeds[chainId]) {
90
- ({ maxFeePerGas, maxPriorityFeePerGas } = await gasPriceFeeds[chainId](viemProvider, chainId));
115
+ ({ maxFeePerGas, maxPriorityFeePerGas } = await gasPriceFeeds[chainId](viemProvider, opts));
91
116
  } else {
92
117
  let gasPrice: bigint | undefined;
93
118
  ({ maxFeePerGas, maxPriorityFeePerGas, gasPrice } = await viemProvider.estimateFeesPerGas());
94
119
 
95
- maxFeePerGas ??= gasPrice!;
120
+ maxFeePerGas ??= (gasPrice! * BigInt(baseFeeMultiplier.toString())) / BigInt(fixedPointAdjustment.toString());
96
121
  maxPriorityFeePerGas ??= BigInt(0);
97
122
  }
98
123
 
@@ -1,36 +1,8 @@
1
- import assert from "assert";
2
- import { getDeployedAddress } from "../../utils/DeploymentUtils";
3
- import { DEFAULT_LOGGER, Logger } from "../relayFeeCalculator";
4
- import { providers } from "ethers";
5
- import { CHAIN_IDs, DEFAULT_SIMULATED_RELAYER_ADDRESS, TOKEN_SYMBOLS_MAP } from "../../constants";
1
+ import { CHAIN_IDs } from "../../constants";
6
2
  import { Coingecko } from "../../coingecko/Coingecko";
7
- import { isDefined } from "../../utils";
8
3
  import { QueryBase } from "./baseQuery";
9
4
 
10
5
  export class AlephZeroQueries extends QueryBase {
11
- constructor(
12
- provider: providers.Provider,
13
- symbolMapping = TOKEN_SYMBOLS_MAP,
14
- spokePoolAddress = getDeployedAddress("SpokePool", CHAIN_IDs.ALEPH_ZERO),
15
- simulatedRelayerAddress = DEFAULT_SIMULATED_RELAYER_ADDRESS,
16
- coingeckoProApiKey?: string,
17
- logger: Logger = DEFAULT_LOGGER,
18
- gasMarkup = 0
19
- ) {
20
- assert(isDefined(spokePoolAddress));
21
- super(
22
- provider,
23
- symbolMapping,
24
- spokePoolAddress,
25
- simulatedRelayerAddress,
26
- gasMarkup,
27
- logger,
28
- coingeckoProApiKey,
29
- undefined,
30
- "usd"
31
- );
32
- }
33
-
34
6
  override async getTokenPrice(tokenSymbol: string): Promise<number> {
35
7
  if (!this.symbolMapping[tokenSymbol]) throw new Error(`${tokenSymbol} does not exist in mapping`);
36
8
  const coingeckoInstance = Coingecko.get(this.logger, this.coingeckoProApiKey);
@@ -1,6 +1,7 @@
1
1
  import { L2Provider } from "@eth-optimism/sdk/dist/interfaces/l2-provider";
2
- import { providers } from "ethers";
3
- import assert from "assert";
2
+ import { isL2Provider as isOptimismL2Provider } from "@eth-optimism/sdk/dist/l2-provider";
3
+
4
+ import { PopulatedTransaction, providers, VoidSigner } from "ethers";
4
5
  import { Coingecko } from "../../coingecko";
5
6
  import { CHAIN_IDs, DEFAULT_SIMULATED_RELAYER_ADDRESS } from "../../constants";
6
7
  import { Deposit } from "../../interfaces";
@@ -8,14 +9,16 @@ import { SpokePool, SpokePool__factory } from "../../typechain";
8
9
  import {
9
10
  BigNumberish,
10
11
  TransactionCostEstimate,
11
- estimateTotalGasRequiredByUnsignedTransaction,
12
- fixedPointAdjustment,
13
12
  populateV3Relay,
13
+ BigNumber,
14
14
  toBNWei,
15
+ bnZero,
16
+ assert,
17
+ chainIsOPStack,
15
18
  } from "../../utils";
16
19
  import { Logger, QueryInterface } from "../relayFeeCalculator";
17
20
  import { Transport } from "viem";
18
-
21
+ import { getGasPriceEstimate } from "../../gasPriceOracle/oracle";
19
22
  type Provider = providers.Provider;
20
23
  type OptimismProvider = L2Provider<Provider>;
21
24
  type SymbolMappingType = Record<
@@ -38,7 +41,6 @@ export class QueryBase implements QueryInterface {
38
41
  * @param symbolMapping A mapping to valid ERC20 tokens and their respective characteristics
39
42
  * @param spokePoolAddress The valid address of the Spoke Pool deployment
40
43
  * @param simulatedRelayerAddress The address that these queries will reference as the sender. Note: This address must be approved for USDC
41
- * @param gasMarkup A multiplier that is applied to the total gas estimate
42
44
  * @param logger A logging utility to report logs
43
45
  * @param coingeckoProApiKey An optional CoinGecko API key that links to a PRO account
44
46
  * @param fixedGasPrice Overrides the gas price with a fixed value. Note: primarily used for the Boba blockchain
@@ -49,7 +51,6 @@ export class QueryBase implements QueryInterface {
49
51
  readonly symbolMapping: SymbolMappingType,
50
52
  readonly spokePoolAddress: string,
51
53
  readonly simulatedRelayerAddress: string,
52
- readonly gasMarkup: number,
53
54
  readonly logger: Logger,
54
55
  readonly coingeckoProApiKey?: string,
55
56
  readonly fixedGasPrice?: BigNumberish,
@@ -65,7 +66,6 @@ export class QueryBase implements QueryInterface {
65
66
  * @param options
66
67
  * @param options.gasPrice Optional gas price to use for the simulation.
67
68
  * @param options.gasUnits Optional gas units to use for the simulation.
68
- * @param options.omitMarkup Optional flag to omit the gas markup.
69
69
  * @param options.transport Optional transport object for custom gas price retrieval.
70
70
  * @returns The gas estimate for this function call (multiplied with the optional buffer).
71
71
  */
@@ -75,37 +75,90 @@ export class QueryBase implements QueryInterface {
75
75
  options: Partial<{
76
76
  gasPrice: BigNumberish;
77
77
  gasUnits: BigNumberish;
78
- omitMarkup: boolean;
78
+ baseFeeMultiplier: BigNumber;
79
79
  transport: Transport;
80
80
  }> = {}
81
81
  ): Promise<TransactionCostEstimate> {
82
- const { gasPrice = this.fixedGasPrice, gasUnits, omitMarkup, transport } = options;
83
-
84
- const gasMarkup = omitMarkup ? 0 : this.gasMarkup;
85
- assert(
86
- gasMarkup > -1 && gasMarkup <= 4,
87
- `Require -1.0 < Gas Markup (${gasMarkup}) <= 4.0 for a total gas multiplier within (0, +5.0]`
88
- );
89
- const gasTotalMultiplier = toBNWei(1.0 + gasMarkup);
82
+ const { gasPrice = this.fixedGasPrice, gasUnits, baseFeeMultiplier, transport } = options;
90
83
 
91
84
  const tx = await populateV3Relay(this.spokePool, deposit, relayer);
92
85
  const {
93
86
  nativeGasCost,
94
87
  tokenGasCost,
95
88
  gasPrice: impliedGasPrice,
96
- } = await estimateTotalGasRequiredByUnsignedTransaction(tx, relayer, this.provider, {
89
+ } = await this.estimateGas(tx, relayer, this.provider, {
97
90
  gasPrice,
98
91
  gasUnits,
92
+ baseFeeMultiplier,
99
93
  transport,
100
94
  });
101
95
 
102
96
  return {
103
- nativeGasCost: nativeGasCost.mul(gasTotalMultiplier).div(fixedPointAdjustment),
104
- tokenGasCost: tokenGasCost.mul(gasTotalMultiplier).div(fixedPointAdjustment),
97
+ nativeGasCost,
98
+ tokenGasCost,
105
99
  gasPrice: impliedGasPrice,
106
100
  };
107
101
  }
108
102
 
103
+ /**
104
+ * Estimates the total gas cost required to submit an unsigned (populated) transaction on-chain.
105
+ * @param unsignedTx The unsigned transaction that this function will estimate.
106
+ * @param senderAddress The address that the transaction will be submitted from.
107
+ * @param provider A valid ethers provider - will be used to reason the gas price.
108
+ * @param options
109
+ * @param options.gasPrice A manually provided gas price - if set, this function will not resolve the current gas price.
110
+ * @param options.gasUnits A manually provided gas units - if set, this function will not estimate the gas units.
111
+ * @param options.transport A custom transport object for custom gas price retrieval.
112
+ * @returns Estimated cost in units of gas and the underlying gas token (gasPrice * estimatedGasUnits).
113
+ */
114
+ async estimateGas(
115
+ unsignedTx: PopulatedTransaction,
116
+ senderAddress: string,
117
+ provider: providers.Provider | L2Provider<providers.Provider>,
118
+ options: Partial<{
119
+ gasPrice: BigNumberish;
120
+ gasUnits: BigNumberish;
121
+ baseFeeMultiplier: BigNumber;
122
+ transport: Transport;
123
+ }> = {}
124
+ ): Promise<TransactionCostEstimate> {
125
+ const { gasPrice: _gasPrice, gasUnits, baseFeeMultiplier = toBNWei("1"), transport } = options || {};
126
+
127
+ const { chainId } = await provider.getNetwork();
128
+ const voidSigner = new VoidSigner(senderAddress, provider);
129
+
130
+ // Estimate the Gas units required to submit this transaction.
131
+ const queries = [
132
+ gasUnits ? Promise.resolve(BigNumber.from(gasUnits)) : voidSigner.estimateGas(unsignedTx),
133
+ _gasPrice
134
+ ? Promise.resolve({ maxFeePerGas: _gasPrice })
135
+ : getGasPriceEstimate(provider, { chainId, baseFeeMultiplier, transport, unsignedTx }),
136
+ ] as const;
137
+ const [nativeGasCost, { maxFeePerGas: gasPrice }] = await Promise.all(queries);
138
+ assert(nativeGasCost.gt(bnZero), "Gas cost should not be 0");
139
+ let tokenGasCost: BigNumber;
140
+
141
+ // OP stack is a special case; gas cost is computed by the SDK, without having to query price.
142
+ if (chainIsOPStack(chainId)) {
143
+ assert(isOptimismL2Provider(provider), `Unexpected provider for chain ID ${chainId}.`);
144
+ const populatedTransaction = await voidSigner.populateTransaction({
145
+ ...unsignedTx,
146
+ gasLimit: nativeGasCost, // prevents additional gas estimation call
147
+ });
148
+ const l1GasCost = await provider.estimateL1GasCost(populatedTransaction);
149
+ const l2GasCost = nativeGasCost.mul(gasPrice);
150
+ tokenGasCost = l1GasCost.add(l2GasCost);
151
+ } else {
152
+ tokenGasCost = nativeGasCost.mul(gasPrice);
153
+ }
154
+
155
+ return {
156
+ nativeGasCost, // Units: gas
157
+ tokenGasCost, // Units: wei (nativeGasCost * wei/gas)
158
+ gasPrice: tokenGasCost.div(nativeGasCost), // Units: wei/gas
159
+ };
160
+ }
161
+
109
162
  /**
110
163
  * Retrieves the current price of a token
111
164
  * @param tokenSymbol A valid [CoinGecko-ID](https://api.coingecko.com/api/v3/coins/list)
@@ -27,7 +27,6 @@ export class QueryBase__factory {
27
27
  simulatedRelayerAddress = DEFAULT_SIMULATED_RELAYER_ADDRESS,
28
28
  coingeckoProApiKey?: string,
29
29
  logger: Logger = DEFAULT_LOGGER,
30
- gasMarkup = 0,
31
30
  coingeckoBaseCurrency = "eth"
32
31
  ): QueryBase {
33
32
  assert(isDefined(spokePoolAddress));
@@ -38,9 +37,10 @@ export class QueryBase__factory {
38
37
  symbolMapping,
39
38
  spokePoolAddress,
40
39
  simulatedRelayerAddress,
41
- coingeckoProApiKey,
42
40
  logger,
43
- gasMarkup
41
+ coingeckoProApiKey,
42
+ fixedGasPrice[chainId],
43
+ "usd"
44
44
  );
45
45
  }
46
46
 
@@ -50,9 +50,10 @@ export class QueryBase__factory {
50
50
  symbolMapping,
51
51
  spokePoolAddress,
52
52
  simulatedRelayerAddress,
53
- coingeckoProApiKey,
54
53
  logger,
55
- gasMarkup
54
+ coingeckoProApiKey,
55
+ fixedGasPrice[chainId],
56
+ "usd"
56
57
  );
57
58
  }
58
59
 
@@ -64,7 +65,6 @@ export class QueryBase__factory {
64
65
  symbolMapping,
65
66
  spokePoolAddress,
66
67
  simulatedRelayerAddress,
67
- gasMarkup,
68
68
  logger,
69
69
  coingeckoProApiKey,
70
70
  fixedGasPrice[chainId],
@@ -1,36 +1,8 @@
1
- import assert from "assert";
2
- import { getDeployedAddress } from "../../utils/DeploymentUtils";
3
- import { DEFAULT_LOGGER, Logger } from "../relayFeeCalculator";
4
- import { providers } from "ethers";
5
- import { CHAIN_IDs, DEFAULT_SIMULATED_RELAYER_ADDRESS, TOKEN_SYMBOLS_MAP } from "../../constants";
1
+ import { CHAIN_IDs } from "../../constants";
6
2
  import { Coingecko } from "../../coingecko/Coingecko";
7
- import { isDefined } from "../../utils";
8
3
  import { QueryBase } from "./baseQuery";
9
4
 
10
5
  export class PolygonQueries extends QueryBase {
11
- constructor(
12
- provider: providers.Provider,
13
- symbolMapping = TOKEN_SYMBOLS_MAP,
14
- spokePoolAddress = getDeployedAddress("SpokePool", CHAIN_IDs.POLYGON),
15
- simulatedRelayerAddress = DEFAULT_SIMULATED_RELAYER_ADDRESS,
16
- coingeckoProApiKey?: string,
17
- logger: Logger = DEFAULT_LOGGER,
18
- gasMarkup = 0
19
- ) {
20
- assert(isDefined(spokePoolAddress));
21
- super(
22
- provider,
23
- symbolMapping,
24
- spokePoolAddress,
25
- simulatedRelayerAddress,
26
- gasMarkup,
27
- logger,
28
- coingeckoProApiKey,
29
- undefined,
30
- "usd"
31
- );
32
- }
33
-
34
6
  override async getTokenPrice(tokenSymbol: string): Promise<number> {
35
7
  if (!this.symbolMapping[tokenSymbol]) throw new Error(`${tokenSymbol} does not exist in mapping`);
36
8
  const coingeckoInstance = Coingecko.get(this.logger, this.coingeckoProApiKey);
@@ -24,7 +24,12 @@ export interface QueryInterface {
24
24
  getGasCosts: (
25
25
  deposit: Deposit,
26
26
  relayer: string,
27
- options?: Partial<{ gasPrice: BigNumberish; gasUnits: BigNumberish; omitMarkup: boolean; transport: Transport }>
27
+ options?: Partial<{
28
+ gasPrice: BigNumberish;
29
+ gasUnits: BigNumberish;
30
+ baseFeeMultiplier: BigNumber;
31
+ transport: Transport;
32
+ }>
28
33
  ) => Promise<TransactionCostEstimate>;
29
34
  getTokenPrice: (tokenSymbol: string) => Promise<number>;
30
35
  getTokenDecimals: (tokenSymbol: string) => number;
@@ -1,16 +1,7 @@
1
- import { L2Provider } from "@eth-optimism/sdk/dist/interfaces/l2-provider";
2
- import { isL2Provider as isOptimismL2Provider } from "@eth-optimism/sdk/dist/l2-provider";
3
- import assert from "assert";
4
1
  import Decimal from "decimal.js";
5
- import { ethers, PopulatedTransaction, providers, VoidSigner } from "ethers";
6
- import { getGasPriceEstimate } from "../gasPriceOracle";
7
- import { BigNumber, BigNumberish, BN, bnZero, formatUnits, parseUnits, toBN } from "./BigNumberUtils";
2
+ import { ethers } from "ethers";
3
+ import { BigNumber, BigNumberish, BN, formatUnits, parseUnits, toBN } from "./BigNumberUtils";
8
4
  import { ConvertDecimals } from "./FormattingUtils";
9
- import { chainIsOPStack } from "./NetworkUtils";
10
- import { Address, Transport } from "viem";
11
- import { CHAIN_IDs } from "@across-protocol/constants";
12
- import { estimateGas } from "viem/linea";
13
- import { getPublicClient } from "../gasPriceOracle/util";
14
5
 
15
6
  export type Decimalish = string | number | Decimal;
16
7
  export const AddressZero = ethers.constants.AddressZero;
@@ -238,87 +229,6 @@ export type TransactionCostEstimate = {
238
229
  gasPrice: BigNumber; // Units: wei/gas
239
230
  };
240
231
 
241
- /**
242
- * Estimates the total gas cost required to submit an unsigned (populated) transaction on-chain.
243
- * @param unsignedTx The unsigned transaction that this function will estimate.
244
- * @param senderAddress The address that the transaction will be submitted from.
245
- * @param provider A valid ethers provider - will be used to reason the gas price.
246
- * @param options
247
- * @param options.gasPrice A manually provided gas price - if set, this function will not resolve the current gas price.
248
- * @param options.gasUnits A manually provided gas units - if set, this function will not estimate the gas units.
249
- * @param options.transport A custom transport object for custom gas price retrieval.
250
- * @returns Estimated cost in units of gas and the underlying gas token (gasPrice * estimatedGasUnits).
251
- */
252
- export async function estimateTotalGasRequiredByUnsignedTransaction(
253
- unsignedTx: PopulatedTransaction,
254
- senderAddress: string,
255
- provider: providers.Provider | L2Provider<providers.Provider>,
256
- options: Partial<{
257
- gasPrice: BigNumberish;
258
- gasUnits: BigNumberish;
259
- transport: Transport;
260
- }> = {}
261
- ): Promise<TransactionCostEstimate> {
262
- const { gasPrice: _gasPrice, gasUnits, transport } = options || {};
263
-
264
- const { chainId } = await provider.getNetwork();
265
- const voidSigner = new VoidSigner(senderAddress, provider);
266
-
267
- // Estimate the Gas units required to submit this transaction.
268
- const queries = [
269
- gasUnits ? Promise.resolve(BigNumber.from(gasUnits)) : voidSigner.estimateGas(unsignedTx),
270
- _gasPrice ? Promise.resolve({ maxFeePerGas: _gasPrice }) : getGasPriceEstimate(provider, chainId, transport),
271
- ] as const;
272
- let [nativeGasCost, { maxFeePerGas: gasPrice }] = await Promise.all(queries);
273
- assert(nativeGasCost.gt(bnZero), "Gas cost should not be 0");
274
- let tokenGasCost: BigNumber;
275
-
276
- // OP stack is a special case; gas cost is computed by the SDK, without having to query price.
277
- if (chainIsOPStack(chainId)) {
278
- assert(isOptimismL2Provider(provider), `Unexpected provider for chain ID ${chainId}.`);
279
- const populatedTransaction = await voidSigner.populateTransaction({
280
- ...unsignedTx,
281
- gasLimit: nativeGasCost, // prevents additional gas estimation call
282
- });
283
- const l1GasCost = await provider.estimateL1GasCost(populatedTransaction);
284
- const l2GasCost = nativeGasCost.mul(gasPrice);
285
- tokenGasCost = l1GasCost.add(l2GasCost);
286
- } else {
287
- if (chainId === CHAIN_IDs.LINEA && process.env[`NEW_GAS_PRICE_ORACLE_${chainId}`] === "true") {
288
- // Permit linea_estimateGas via NEW_GAS_PRICE_ORACLE_59144=true
289
- let baseFeePerGas: BigNumber, priorityFeePerGas: BigNumber;
290
- ({
291
- gasLimit: nativeGasCost,
292
- baseFeePerGas,
293
- priorityFeePerGas,
294
- } = await getLineaGasFees(chainId, transport, unsignedTx));
295
- gasPrice = baseFeePerGas.add(priorityFeePerGas);
296
- }
297
-
298
- tokenGasCost = nativeGasCost.mul(gasPrice);
299
- }
300
-
301
- return {
302
- nativeGasCost, // Units: gas
303
- tokenGasCost, // Units: wei (nativeGasCost * wei/gas)
304
- gasPrice: tokenGasCost.div(nativeGasCost), // Units: wei/gas
305
- };
306
- }
307
-
308
- async function getLineaGasFees(chainId: number, transport: Transport | undefined, unsignedTx: PopulatedTransaction) {
309
- const { gasLimit, baseFeePerGas, priorityFeePerGas } = await estimateGas(getPublicClient(chainId, transport), {
310
- account: unsignedTx.from as Address,
311
- to: unsignedTx.to as Address,
312
- value: BigInt(unsignedTx.value?.toString() || "1"),
313
- });
314
-
315
- return {
316
- gasLimit: BigNumber.from(gasLimit.toString()),
317
- baseFeePerGas: BigNumber.from(baseFeePerGas.toString()),
318
- priorityFeePerGas: BigNumber.from(priorityFeePerGas.toString()),
319
- };
320
- }
321
-
322
232
  export function randomAddress() {
323
233
  return ethers.utils.getAddress(ethers.utils.hexlify(ethers.utils.randomBytes(20)));
324
234
  }
@@ -1,3 +0,0 @@
1
- import { PublicClient } from "viem";
2
- import { InternalGasPriceEstimate } from "../types";
3
- export declare function eip1559(provider: PublicClient, _chainId: number): Promise<InternalGasPriceEstimate>;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.eip1559 = void 0;
4
- var tslib_1 = require("tslib");
5
- var MAX_PRIORITY_FEE_PER_GAS = BigInt(1);
6
- function eip1559(provider, _chainId) {
7
- return tslib_1.__awaiter(this, void 0, void 0, function () {
8
- var _a, _maxFeePerGas, maxPriorityFeePerGas, maxFeePerGas;
9
- return tslib_1.__generator(this, function (_b) {
10
- switch (_b.label) {
11
- case 0: return [4, provider.estimateFeesPerGas()];
12
- case 1:
13
- _a = _b.sent(), _maxFeePerGas = _a.maxFeePerGas, maxPriorityFeePerGas = _a.maxPriorityFeePerGas;
14
- maxFeePerGas = BigInt(_maxFeePerGas) - maxPriorityFeePerGas + MAX_PRIORITY_FEE_PER_GAS;
15
- return [2, { maxFeePerGas: maxFeePerGas, maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS }];
16
- }
17
- });
18
- });
19
- }
20
- exports.eip1559 = eip1559;
21
- //# sourceMappingURL=arbitrum-viem.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"arbitrum-viem.js","sourceRoot":"","sources":["../../../../src/gasPriceOracle/adapters/arbitrum-viem.ts"],"names":[],"mappings":";;;;AAGA,IAAM,wBAAwB,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAK3C,SAAsB,OAAO,CAAC,QAAsB,EAAE,QAAgB;;;;;wBACN,WAAM,QAAQ,CAAC,kBAAkB,EAAE,EAAA;;oBAA3F,KAAwD,SAAmC,EAA3E,aAAa,kBAAA,EAAE,oBAAoB,0BAAA;oBACnD,YAAY,GAAG,MAAM,CAAC,aAAa,CAAC,GAAG,oBAAoB,GAAG,wBAAwB,CAAC;oBAC7F,WAAO,EAAE,YAAY,cAAA,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,EAAC;;;;CACzE;AAJD,0BAIC"}
@@ -1,4 +0,0 @@
1
- import { PublicClient } from "viem";
2
- import { InternalGasPriceEstimate } from "../types";
3
- export declare function eip1559(provider: PublicClient, _chainId: number): Promise<InternalGasPriceEstimate>;
4
- export declare function legacy(provider: PublicClient, _chainId: number, _test?: number): Promise<InternalGasPriceEstimate>;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.legacy = exports.eip1559 = void 0;
4
- var tslib_1 = require("tslib");
5
- function eip1559(provider, _chainId) {
6
- return provider.estimateFeesPerGas();
7
- }
8
- exports.eip1559 = eip1559;
9
- function legacy(provider, _chainId, _test) {
10
- return tslib_1.__awaiter(this, void 0, void 0, function () {
11
- var gasPrice;
12
- return tslib_1.__generator(this, function (_a) {
13
- switch (_a.label) {
14
- case 0: return [4, provider.getGasPrice()];
15
- case 1:
16
- gasPrice = _a.sent();
17
- return [2, {
18
- maxFeePerGas: gasPrice,
19
- maxPriorityFeePerGas: BigInt(0),
20
- }];
21
- }
22
- });
23
- });
24
- }
25
- exports.legacy = legacy;
26
- //# sourceMappingURL=ethereum-viem.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ethereum-viem.js","sourceRoot":"","sources":["../../../../src/gasPriceOracle/adapters/ethereum-viem.ts"],"names":[],"mappings":";;;;AAGA,SAAgB,OAAO,CAAC,QAAsB,EAAE,QAAgB;IAC9D,OAAO,QAAQ,CAAC,kBAAkB,EAAE,CAAC;AACvC,CAAC;AAFD,0BAEC;AAED,SAAsB,MAAM,CAC1B,QAAsB,EACtB,QAAgB,EAChB,KAAc;;;;;wBAEG,WAAM,QAAQ,CAAC,WAAW,EAAE,EAAA;;oBAAvC,QAAQ,GAAG,SAA4B;oBAE7C,WAAO;4BACL,YAAY,EAAE,QAAQ;4BACtB,oBAAoB,EAAE,MAAM,CAAC,CAAC,CAAC;yBAChC,EAAC;;;;CACH;AAXD,wBAWC"}
@@ -1,3 +0,0 @@
1
- import { PublicClient } from "viem";
2
- import { InternalGasPriceEstimate } from "../types";
3
- export declare function gasStation(provider: PublicClient, chainId: number): Promise<InternalGasPriceEstimate>;