@octaflowlabs/onchain-sdk 1.0.0-test12 → 1.0.0-test13

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.
@@ -1,6 +1,9 @@
1
1
  export const estimateGasLimitFromProvider = async ({ provider, unsignedTx, walletAddress, defaultGasLimit, }) => {
2
+ let lastFeeData = null;
3
+ let lastGasEstimated = null;
2
4
  try {
3
5
  const feeData = await provider.getFeeData();
6
+ lastFeeData = feeData;
4
7
  const txForEstimation = { ...unsignedTx, from: walletAddress };
5
8
  if (feeData.maxFeePerGas !== undefined)
6
9
  txForEstimation.maxFeePerGas = feeData.maxFeePerGas;
@@ -9,6 +12,7 @@ export const estimateGasLimitFromProvider = async ({ provider, unsignedTx, walle
9
12
  if (feeData.gasPrice !== undefined && txForEstimation.maxFeePerGas === undefined)
10
13
  txForEstimation.gasPrice = feeData.gasPrice;
11
14
  const gasEstimated = await provider.estimateGas(txForEstimation);
15
+ lastGasEstimated = gasEstimated;
12
16
  let congestionFactor = 1.5;
13
17
  if (feeData.maxFeePerGas && feeData.maxPriorityFeePerGas) {
14
18
  try {
@@ -40,12 +44,20 @@ export const estimateGasLimitFromProvider = async ({ provider, unsignedTx, walle
40
44
  catch (error) {
41
45
  console.error('Unable to estimate gas limit: ', error);
42
46
  console.log(`Setting default gas limit to: ${defaultGasLimit}`);
47
+ const feeData = lastFeeData;
48
+ const gasEstimated = lastGasEstimated ?? defaultGasLimit;
43
49
  return {
44
- gasEstimated: defaultGasLimit,
50
+ gasEstimated,
45
51
  gasLimit: defaultGasLimit,
46
52
  bufferPercentage: 0,
47
53
  fallbackUsed: true,
48
- feeData: {},
54
+ feeData: feeData
55
+ ? {
56
+ maxFeePerGas: feeData.maxFeePerGas ?? undefined,
57
+ maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ?? undefined,
58
+ gasPrice: feeData.gasPrice ?? undefined,
59
+ }
60
+ : {},
49
61
  };
50
62
  }
51
63
  };
@@ -2,8 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.estimateGasLimitFromProvider = void 0;
4
4
  const estimateGasLimitFromProvider = async ({ provider, unsignedTx, walletAddress, defaultGasLimit, }) => {
5
+ let lastFeeData = null;
6
+ let lastGasEstimated = null;
5
7
  try {
6
8
  const feeData = await provider.getFeeData();
9
+ lastFeeData = feeData;
7
10
  const txForEstimation = { ...unsignedTx, from: walletAddress };
8
11
  if (feeData.maxFeePerGas !== undefined)
9
12
  txForEstimation.maxFeePerGas = feeData.maxFeePerGas;
@@ -12,6 +15,7 @@ const estimateGasLimitFromProvider = async ({ provider, unsignedTx, walletAddres
12
15
  if (feeData.gasPrice !== undefined && txForEstimation.maxFeePerGas === undefined)
13
16
  txForEstimation.gasPrice = feeData.gasPrice;
14
17
  const gasEstimated = await provider.estimateGas(txForEstimation);
18
+ lastGasEstimated = gasEstimated;
15
19
  let congestionFactor = 1.5;
16
20
  if (feeData.maxFeePerGas && feeData.maxPriorityFeePerGas) {
17
21
  try {
@@ -43,12 +47,20 @@ const estimateGasLimitFromProvider = async ({ provider, unsignedTx, walletAddres
43
47
  catch (error) {
44
48
  console.error('Unable to estimate gas limit: ', error);
45
49
  console.log(`Setting default gas limit to: ${defaultGasLimit}`);
50
+ const feeData = lastFeeData;
51
+ const gasEstimated = lastGasEstimated ?? defaultGasLimit;
46
52
  return {
47
- gasEstimated: defaultGasLimit,
53
+ gasEstimated,
48
54
  gasLimit: defaultGasLimit,
49
55
  bufferPercentage: 0,
50
56
  fallbackUsed: true,
51
- feeData: {},
57
+ feeData: feeData
58
+ ? {
59
+ maxFeePerGas: feeData.maxFeePerGas ?? undefined,
60
+ maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ?? undefined,
61
+ gasPrice: feeData.gasPrice ?? undefined,
62
+ }
63
+ : {},
52
64
  };
53
65
  }
54
66
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octaflowlabs/onchain-sdk",
3
- "version": "1.0.0-test12",
3
+ "version": "1.0.0-test13",
4
4
  "description": "onchain methods for web3",
5
5
  "repository": "https://github.com/crisramb665/onchain-sdk.git",
6
6
  "license": "MIT",