@across-protocol/sdk 3.3.27 → 3.3.29

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 (40) hide show
  1. package/dist/cjs/gasPriceOracle/adapters/arbitrum.js +1 -7
  2. package/dist/cjs/gasPriceOracle/adapters/arbitrum.js.map +1 -1
  3. package/dist/cjs/gasPriceOracle/adapters/ethereum.d.ts +2 -0
  4. package/dist/cjs/gasPriceOracle/adapters/ethereum.js +30 -2
  5. package/dist/cjs/gasPriceOracle/adapters/ethereum.js.map +1 -1
  6. package/dist/cjs/gasPriceOracle/oracle.js +27 -43
  7. package/dist/cjs/gasPriceOracle/oracle.js.map +1 -1
  8. package/dist/cjs/utils/BlockUtils.js +1 -0
  9. package/dist/cjs/utils/BlockUtils.js.map +1 -1
  10. package/dist/cjs/utils/Multicall.js +2 -1
  11. package/dist/cjs/utils/Multicall.js.map +1 -1
  12. package/dist/cjs/utils/common.js +30 -41
  13. package/dist/cjs/utils/common.js.map +1 -1
  14. package/dist/esm/gasPriceOracle/adapters/arbitrum.js +4 -12
  15. package/dist/esm/gasPriceOracle/adapters/arbitrum.js.map +1 -1
  16. package/dist/esm/gasPriceOracle/adapters/ethereum.d.ts +19 -0
  17. package/dist/esm/gasPriceOracle/adapters/ethereum.js +44 -1
  18. package/dist/esm/gasPriceOracle/adapters/ethereum.js.map +1 -1
  19. package/dist/esm/gasPriceOracle/oracle.js +27 -43
  20. package/dist/esm/gasPriceOracle/oracle.js.map +1 -1
  21. package/dist/esm/utils/BlockUtils.js +1 -0
  22. package/dist/esm/utils/BlockUtils.js.map +1 -1
  23. package/dist/esm/utils/Multicall.js +2 -1
  24. package/dist/esm/utils/Multicall.js.map +1 -1
  25. package/dist/esm/utils/common.js +31 -42
  26. package/dist/esm/utils/common.js.map +1 -1
  27. package/dist/types/gasPriceOracle/adapters/arbitrum.d.ts.map +1 -1
  28. package/dist/types/gasPriceOracle/adapters/ethereum.d.ts +19 -0
  29. package/dist/types/gasPriceOracle/adapters/ethereum.d.ts.map +1 -1
  30. package/dist/types/gasPriceOracle/oracle.d.ts.map +1 -1
  31. package/dist/types/utils/BlockUtils.d.ts.map +1 -1
  32. package/dist/types/utils/Multicall.d.ts.map +1 -1
  33. package/dist/types/utils/common.d.ts.map +1 -1
  34. package/package.json +1 -1
  35. package/src/gasPriceOracle/adapters/arbitrum.ts +3 -12
  36. package/src/gasPriceOracle/adapters/ethereum.ts +39 -2
  37. package/src/gasPriceOracle/oracle.ts +7 -19
  38. package/src/utils/BlockUtils.ts +1 -0
  39. package/src/utils/Multicall.ts +2 -1
  40. package/src/utils/common.ts +19 -22
@@ -4,7 +4,7 @@ import assert from "assert";
4
4
  import Decimal from "decimal.js";
5
5
  import { ethers, PopulatedTransaction, providers, VoidSigner } from "ethers";
6
6
  import { getGasPriceEstimate } from "../gasPriceOracle";
7
- import { BigNumber, BigNumberish, BN, formatUnits, parseUnits, toBN } from "./BigNumberUtils";
7
+ import { BigNumber, BigNumberish, BN, bnZero, formatUnits, parseUnits, toBN } from "./BigNumberUtils";
8
8
  import { ConvertDecimals } from "./FormattingUtils";
9
9
  import { chainIsOPStack } from "./NetworkUtils";
10
10
  import { Address, Transport } from "viem";
@@ -265,8 +265,12 @@ export async function estimateTotalGasRequiredByUnsignedTransaction(
265
265
  const voidSigner = new VoidSigner(senderAddress, provider);
266
266
 
267
267
  // Estimate the Gas units required to submit this transaction.
268
- const nativeGasCost = gasUnits ? BigNumber.from(gasUnits) : await voidSigner.estimateGas(unsignedTx);
269
- assert(nativeGasCost.gt(0), "Gas cost should not be 0");
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");
270
274
  let tokenGasCost: BigNumber;
271
275
 
272
276
  // OP stack is a special case; gas cost is computed by the SDK, without having to query price.
@@ -276,28 +280,21 @@ export async function estimateTotalGasRequiredByUnsignedTransaction(
276
280
  ...unsignedTx,
277
281
  gasLimit: nativeGasCost, // prevents additional gas estimation call
278
282
  });
279
- // Concurrently estimate the gas cost on L1 and L2 instead of calling
280
- // `provider.estimateTotalGasCost` to improve performance.
281
- const [l1GasCost, l2GasPrice] = await Promise.all([
282
- provider.estimateL1GasCost(populatedTransaction),
283
- _gasPrice || provider.getGasPrice(),
284
- ]);
285
- const l2GasCost = nativeGasCost.mul(l2GasPrice);
283
+ const l1GasCost = await provider.estimateL1GasCost(populatedTransaction);
284
+ const l2GasCost = nativeGasCost.mul(gasPrice);
286
285
  tokenGasCost = l1GasCost.add(l2GasCost);
287
- } else 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
- const {
290
- gasLimit: nativeGasCost,
291
- baseFeePerGas,
292
- priorityFeePerGas,
293
- } = await getLineaGasFees(chainId, transport, unsignedTx);
294
- tokenGasCost = baseFeePerGas.add(priorityFeePerGas).mul(nativeGasCost);
295
286
  } else {
296
- let gasPrice = _gasPrice;
297
- if (!gasPrice) {
298
- const gasPriceEstimate = await getGasPriceEstimate(provider, chainId, transport);
299
- gasPrice = gasPriceEstimate.maxFeePerGas;
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);
300
296
  }
297
+
301
298
  tokenGasCost = nativeGasCost.mul(gasPrice);
302
299
  }
303
300