@octaflowlabs/onchain-sdk 1.4.1 → 1.4.2

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.
@@ -0,0 +1,20 @@
1
+ /** local imports */
2
+ import { GAS_LIMIT_PER_TX_TYPE } from '../constants/constants';
3
+ import { FeeDataInput } from '../types/common';
4
+ export type FeeSnapshotTxKind = keyof typeof GAS_LIMIT_PER_TX_TYPE;
5
+ export type FetchFeeSnapshotOptions = {
6
+ rpcUrl: string;
7
+ chainId: number;
8
+ /**
9
+ * Selects a default `gasLimit` for the returned `FeeDataInput` (e.g. for `getFeePresets`).
10
+ * Does not trigger `eth_estimateGas`; only `gasLimit` on the returned object changes.
11
+ */
12
+ txKind?: FeeSnapshotTxKind;
13
+ /** When set, overrides the gas limit implied by `txKind`. */
14
+ gasLimit?: bigint;
15
+ };
16
+ /**
17
+ * Reads current fee fields from the node (`getFeeData` → `eth_feeHistory` / `eth_gasPrice`, etc.).
18
+ * Does not call `eth_estimateGas` or `eth_getTransactionCount`.
19
+ */
20
+ export declare const fetchFeeSnapshot: (options: FetchFeeSnapshotOptions) => Promise<FeeDataInput>;
@@ -0,0 +1,30 @@
1
+ /** local imports */
2
+ import { GAS_LIMIT_PER_TX_TYPE } from '../constants/constants';
3
+ import { getProvider } from './getProvider';
4
+ /**
5
+ * Reads current fee fields from the node (`getFeeData` → `eth_feeHistory` / `eth_gasPrice`, etc.).
6
+ * Does not call `eth_estimateGas` or `eth_getTransactionCount`.
7
+ */
8
+ export const fetchFeeSnapshot = async (options) => {
9
+ const { rpcUrl, chainId, txKind = 'DEFAULT_TRANSFER_NATIVE', gasLimit: gasLimitOverride, } = options;
10
+ const provider = getProvider(rpcUrl, chainId);
11
+ if (!provider)
12
+ throw new Error('Could not create provider with given rpcUrl and chainId');
13
+ const raw = await provider.getFeeData();
14
+ const feeData = {
15
+ maxFeePerGas: raw.maxFeePerGas ?? undefined,
16
+ maxPriorityFeePerGas: raw.maxPriorityFeePerGas ?? undefined,
17
+ gasPrice: raw.gasPrice ?? undefined,
18
+ };
19
+ const has1559 = feeData.maxFeePerGas != null && feeData.maxPriorityFeePerGas != null;
20
+ const hasLegacy = feeData.gasPrice != null;
21
+ if (!has1559 && !hasLegacy) {
22
+ throw new Error('fetchFeeSnapshot: provider returned no usable fee fields (EIP-1559 or legacy gas price)');
23
+ }
24
+ const gasLimit = gasLimitOverride ?? GAS_LIMIT_PER_TX_TYPE[txKind];
25
+ return {
26
+ chainId,
27
+ gasLimit,
28
+ feeData,
29
+ };
30
+ };
@@ -0,0 +1,20 @@
1
+ /** local imports */
2
+ import { GAS_LIMIT_PER_TX_TYPE } from '../constants/constants';
3
+ import { FeeDataInput } from '../types/common';
4
+ export type FeeSnapshotTxKind = keyof typeof GAS_LIMIT_PER_TX_TYPE;
5
+ export type FetchFeeSnapshotOptions = {
6
+ rpcUrl: string;
7
+ chainId: number;
8
+ /**
9
+ * Selects a default `gasLimit` for the returned `FeeDataInput` (e.g. for `getFeePresets`).
10
+ * Does not trigger `eth_estimateGas`; only `gasLimit` on the returned object changes.
11
+ */
12
+ txKind?: FeeSnapshotTxKind;
13
+ /** When set, overrides the gas limit implied by `txKind`. */
14
+ gasLimit?: bigint;
15
+ };
16
+ /**
17
+ * Reads current fee fields from the node (`getFeeData` → `eth_feeHistory` / `eth_gasPrice`, etc.).
18
+ * Does not call `eth_estimateGas` or `eth_getTransactionCount`.
19
+ */
20
+ export declare const fetchFeeSnapshot: (options: FetchFeeSnapshotOptions) => Promise<FeeDataInput>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchFeeSnapshot = void 0;
4
+ /** local imports */
5
+ const constants_1 = require("../constants/constants");
6
+ const getProvider_1 = require("./getProvider");
7
+ /**
8
+ * Reads current fee fields from the node (`getFeeData` → `eth_feeHistory` / `eth_gasPrice`, etc.).
9
+ * Does not call `eth_estimateGas` or `eth_getTransactionCount`.
10
+ */
11
+ const fetchFeeSnapshot = async (options) => {
12
+ const { rpcUrl, chainId, txKind = 'DEFAULT_TRANSFER_NATIVE', gasLimit: gasLimitOverride, } = options;
13
+ const provider = (0, getProvider_1.getProvider)(rpcUrl, chainId);
14
+ if (!provider)
15
+ throw new Error('Could not create provider with given rpcUrl and chainId');
16
+ const raw = await provider.getFeeData();
17
+ const feeData = {
18
+ maxFeePerGas: raw.maxFeePerGas ?? undefined,
19
+ maxPriorityFeePerGas: raw.maxPriorityFeePerGas ?? undefined,
20
+ gasPrice: raw.gasPrice ?? undefined,
21
+ };
22
+ const has1559 = feeData.maxFeePerGas != null && feeData.maxPriorityFeePerGas != null;
23
+ const hasLegacy = feeData.gasPrice != null;
24
+ if (!has1559 && !hasLegacy) {
25
+ throw new Error('fetchFeeSnapshot: provider returned no usable fee fields (EIP-1559 or legacy gas price)');
26
+ }
27
+ const gasLimit = gasLimitOverride ?? constants_1.GAS_LIMIT_PER_TX_TYPE[txKind];
28
+ return {
29
+ chainId,
30
+ gasLimit,
31
+ feeData,
32
+ };
33
+ };
34
+ exports.fetchFeeSnapshot = fetchFeeSnapshot;
@@ -14,6 +14,7 @@ export { txStatus } from './blockchain/txStatus';
14
14
  export { getBalance, getBalances } from './blockchain/getBalances';
15
15
  export { estimateTransaction } from './blockchain/estimateTransaction';
16
16
  export { prepareTransaction } from './blockchain/prepareTransaction';
17
+ export { fetchFeeSnapshot, type FetchFeeSnapshotOptions, type FeeSnapshotTxKind, } from './blockchain/fetchFeeSnapshot';
17
18
  /** services exports */
18
19
  export { EvmWalletService, EvmGeneratedWallet, EvmDerivedWallet, } from './services/evm-wallet-core/evmWalletService';
19
20
  export { EntropySource } from './services/evm-wallet-core/entropy';
package/dist/cjs/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.BLOCK_TIME_BY_CHAIN = exports.getBlockTime = exports.estimateSeconds = exports.calcReserve = exports.getFeePresets = exports.parseGasLimit = exports.tryParseGweiToWei = exports.toGwei = exports.normalizeAddress = exports.errorMessagesForGasLimitEstimation = exports.errorMessagesForBroadcast = exports.handleErrorMessages = exports.parsedAmount = exports.formattedAmountForDisplay = exports.NATIVE_TOKENS = exports.transformBigInt = exports.getShortenData = exports.getShortenTransactionHashOrAddress = exports.signTransaction = exports.signMessage = exports.createWallet = exports.EvmWalletService = exports.prepareTransaction = exports.estimateTransaction = exports.getBalances = exports.getBalance = exports.txStatus = exports.getProvider = exports.estimateGasLimitFromProvider = exports.broadcastTransaction = exports.buildUnsignedTransferTx = exports.buildMaxNativeTransferTx = exports.buildBaseUnsignedTransferTx = exports.BASIC_TOKENS_BY_CHAIN = exports.NETWORKS_REGISTRY = exports.MULTICALL3_ADDRESS = exports.GAS_LIMIT_PER_TX_TYPE = exports.ERC20_TOKEN_CONTRACT_ABI = void 0;
6
+ exports.BLOCK_TIME_BY_CHAIN = exports.getBlockTime = exports.estimateSeconds = exports.calcReserve = exports.getFeePresets = exports.parseGasLimit = exports.tryParseGweiToWei = exports.toGwei = exports.normalizeAddress = exports.errorMessagesForGasLimitEstimation = exports.errorMessagesForBroadcast = exports.handleErrorMessages = exports.parsedAmount = exports.formattedAmountForDisplay = exports.NATIVE_TOKENS = exports.transformBigInt = exports.getShortenData = exports.getShortenTransactionHashOrAddress = exports.signTransaction = exports.signMessage = exports.createWallet = exports.EvmWalletService = exports.fetchFeeSnapshot = exports.prepareTransaction = exports.estimateTransaction = exports.getBalances = exports.getBalance = exports.txStatus = exports.getProvider = exports.estimateGasLimitFromProvider = exports.broadcastTransaction = exports.buildUnsignedTransferTx = exports.buildMaxNativeTransferTx = exports.buildBaseUnsignedTransferTx = exports.BASIC_TOKENS_BY_CHAIN = exports.NETWORKS_REGISTRY = exports.MULTICALL3_ADDRESS = exports.GAS_LIMIT_PER_TX_TYPE = exports.ERC20_TOKEN_CONTRACT_ABI = void 0;
7
7
  /** ABIs exports */
8
8
  const ERC20_TOKEN_CONTRACT_ABI_1 = __importDefault(require("./ABIs/ERC20_TOKEN_CONTRACT_ABI"));
9
9
  exports.ERC20_TOKEN_CONTRACT_ABI = ERC20_TOKEN_CONTRACT_ABI_1.default;
@@ -35,6 +35,8 @@ var estimateTransaction_1 = require("./blockchain/estimateTransaction");
35
35
  Object.defineProperty(exports, "estimateTransaction", { enumerable: true, get: function () { return estimateTransaction_1.estimateTransaction; } });
36
36
  var prepareTransaction_1 = require("./blockchain/prepareTransaction");
37
37
  Object.defineProperty(exports, "prepareTransaction", { enumerable: true, get: function () { return prepareTransaction_1.prepareTransaction; } });
38
+ var fetchFeeSnapshot_1 = require("./blockchain/fetchFeeSnapshot");
39
+ Object.defineProperty(exports, "fetchFeeSnapshot", { enumerable: true, get: function () { return fetchFeeSnapshot_1.fetchFeeSnapshot; } });
38
40
  /** services exports */
39
41
  var evmWalletService_1 = require("./services/evm-wallet-core/evmWalletService");
40
42
  Object.defineProperty(exports, "EvmWalletService", { enumerable: true, get: function () { return evmWalletService_1.EvmWalletService; } });
@@ -40,7 +40,7 @@ function getFeePresets(tx) {
40
40
  const priority = BigInt(maxPriorityFeePerGas);
41
41
  const baseFee = BigInt(maxFeePerGas) - BigInt(maxPriorityFeePerGas);
42
42
  const estimatedCostPerGas = (priority) => baseFee + priority;
43
- const chainId = builtTx.unsignedTx?.chainId ?? 1;
43
+ const chainId = builtTx.unsignedTx?.chainId ?? builtTx.chainId ?? 1;
44
44
  const blockTime = getBlockTime(chainId);
45
45
  const lowPriority = (priority * 75n) / 100n;
46
46
  const highPriority = (priority * 150n) / 100n;
package/dist/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export { txStatus } from './blockchain/txStatus';
14
14
  export { getBalance, getBalances } from './blockchain/getBalances';
15
15
  export { estimateTransaction } from './blockchain/estimateTransaction';
16
16
  export { prepareTransaction } from './blockchain/prepareTransaction';
17
+ export { fetchFeeSnapshot, type FetchFeeSnapshotOptions, type FeeSnapshotTxKind, } from './blockchain/fetchFeeSnapshot';
17
18
  /** services exports */
18
19
  export { EvmWalletService, EvmGeneratedWallet, EvmDerivedWallet, } from './services/evm-wallet-core/evmWalletService';
19
20
  export { EntropySource } from './services/evm-wallet-core/entropy';
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ export { txStatus } from './blockchain/txStatus';
14
14
  export { getBalance, getBalances } from './blockchain/getBalances';
15
15
  export { estimateTransaction } from './blockchain/estimateTransaction';
16
16
  export { prepareTransaction } from './blockchain/prepareTransaction';
17
+ export { fetchFeeSnapshot, } from './blockchain/fetchFeeSnapshot';
17
18
  /** services exports */
18
19
  export { EvmWalletService, } from './services/evm-wallet-core/evmWalletService';
19
20
  export { createWallet, signMessage, signTransaction } from './services/evm-wallet-core/signer';
@@ -33,7 +33,7 @@ export function getFeePresets(tx) {
33
33
  const priority = BigInt(maxPriorityFeePerGas);
34
34
  const baseFee = BigInt(maxFeePerGas) - BigInt(maxPriorityFeePerGas);
35
35
  const estimatedCostPerGas = (priority) => baseFee + priority;
36
- const chainId = builtTx.unsignedTx?.chainId ?? 1;
36
+ const chainId = builtTx.unsignedTx?.chainId ?? builtTx.chainId ?? 1;
37
37
  const blockTime = getBlockTime(chainId);
38
38
  const lowPriority = (priority * 75n) / 100n;
39
39
  const highPriority = (priority * 150n) / 100n;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@octaflowlabs/onchain-sdk",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "onchain methods for web3",
5
- "repository": "https://github.com/crisramb665/onchain-sdk.git",
5
+ "repository": {"type": "git", "url": "git+https://github.com/octaflowlabs/onchain-sdk.git"},
6
6
  "license": "MIT",
7
7
  "main": "dist/cjs/index.js",
8
8
  "module": "dist/index.js",
@@ -10,6 +10,10 @@
10
10
  "files": [
11
11
  "dist"
12
12
  ],
13
+ "publishConfig": {
14
+ "access": "public",
15
+ "registry": "https://registry.npmjs.org/"
16
+ },
13
17
  "scripts": {
14
18
  "build": "rm -rf dist && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && tsc-alias",
15
19
  "prettier": "prettier --write \"src/**/*.ts\"",