@octaflowlabs/onchain-sdk 1.0.0-test11 → 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.
@@ -4,6 +4,7 @@ import { Interface, formatUnits, parseUnits } from 'ethers';
4
4
  import { getProvider } from './getProvider';
5
5
  import { estimateGasLimitFromProvider } from './estimateGasLimitFromProvider';
6
6
  export const buildUnsignedTransferTx = async (options) => {
7
+ console.log({ options });
7
8
  const provider = getProvider(options.rpcUrl, options.chainId);
8
9
  if (!provider)
9
10
  throw new Error('Could not create provider with given rpcUrl and chainId');
@@ -65,6 +66,7 @@ export const buildUnsignedTransferTx = async (options) => {
65
66
  : estimateGas.feeData.gasPrice
66
67
  ? estimateGas.gasLimit * estimateGas.feeData.gasPrice
67
68
  : undefined;
69
+ console.log({ gasReserve: gasReserve?.toString() });
68
70
  try {
69
71
  await provider.call({
70
72
  from: options.fromAddress,
@@ -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
  };
@@ -7,6 +7,7 @@ const ethers_1 = require("ethers");
7
7
  const getProvider_1 = require("./getProvider");
8
8
  const estimateGasLimitFromProvider_1 = require("./estimateGasLimitFromProvider");
9
9
  const buildUnsignedTransferTx = async (options) => {
10
+ console.log({ options });
10
11
  const provider = (0, getProvider_1.getProvider)(options.rpcUrl, options.chainId);
11
12
  if (!provider)
12
13
  throw new Error('Could not create provider with given rpcUrl and chainId');
@@ -68,6 +69,7 @@ const buildUnsignedTransferTx = async (options) => {
68
69
  : estimateGas.feeData.gasPrice
69
70
  ? estimateGas.gasLimit * estimateGas.feeData.gasPrice
70
71
  : undefined;
72
+ console.log({ gasReserve: gasReserve?.toString() });
71
73
  try {
72
74
  await provider.call({
73
75
  from: options.fromAddress,
@@ -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-test11",
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",