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

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