@mentaproject/client 0.2.0 → 0.2.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,36 @@
1
+ import { MentaAccountClient } from "@mentaproject/core/types";
2
+ import { GasTracker, GasEstimate, GasEstimates } from "@mentaproject/transactions";
3
+ export type GasStrategy = "slow" | "medium" | "fast";
4
+ /**
5
+ * Manages gas estimation and configuration.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * // Get all prices
10
+ * const prices = await client.gas.getPrices();
11
+ * console.log(prices.fast.maxFeePerGas);
12
+ *
13
+ * // Get specific estimate
14
+ * const fast = await client.gas.estimate("fast");
15
+ * tx.withGasConfig(fast);
16
+ * ```
17
+ */
18
+ export declare class GasManager {
19
+ private client;
20
+ private tracker;
21
+ constructor(client: MentaAccountClient);
22
+ /**
23
+ * Gets all gas price estimates (slow, medium, fast).
24
+ */
25
+ getPrices(): Promise<GasEstimates>;
26
+ /**
27
+ * Gets a specific gas estimate by strategy.
28
+ *
29
+ * @param strategy - "slow", "medium", or "fast"
30
+ */
31
+ estimate(strategy: GasStrategy): Promise<GasEstimate>;
32
+ /**
33
+ * Gets the underlying GasTracker for advanced usage.
34
+ */
35
+ getTracker(): GasTracker;
36
+ }
@@ -2,19 +2,21 @@
2
2
  * @module TransactionManager
3
3
  */
4
4
  import { GetTransactionParameters, SendTransactionParameters } from "@mentaproject/core/types";
5
- import { Transaction as RichTransaction } from "../structures/Transaction";
5
+ import { TransactionRecord } from "../structures/TransactionRecord";
6
6
  import { MulticallTransaction } from "@mentaproject/transactions";
7
7
  import { MentaClient } from "../structures";
8
8
  import { JSONTransaction } from "../types";
9
+ import { WithGas } from "../utils/withGasSupport";
9
10
  /**
10
11
  * Manages blockchain transaction-related operations.
11
12
  *
12
13
  * @example
13
14
  * ```ts
14
- * // Create a multicall transaction
15
+ * // Create a multicall transaction with gas support
15
16
  * const pending = await client.transactions.create()
16
17
  * .addCall(account.sendEth(parseEther("1")))
17
18
  * .addCall(erc20.transfer(to, amount))
19
+ * .withGas("fast")
18
20
  * .execute();
19
21
  *
20
22
  * const receipt = await pending.confirm();
@@ -29,23 +31,24 @@ export declare class TransactionManager {
29
31
  constructor(client: MentaClient);
30
32
  /**
31
33
  * Creates a new MulticallTransaction for batching multiple calls.
34
+ * Enhanced with withGas() support for easy gas configuration.
32
35
  *
33
- * @returns A MulticallTransaction builder
36
+ * @returns A MulticallTransaction builder with withGas() support
34
37
  *
35
38
  * @example
36
39
  * ```ts
37
40
  * const pending = await client.transactions.create()
38
41
  * .addCall(account.sendEth(parseEther("1")))
39
- * .addCall(erc20.transfer(to, amount))
42
+ * .withGas("fast")
40
43
  * .execute();
41
44
  * ```
42
45
  */
43
- create(): MulticallTransaction;
46
+ create(): WithGas<MulticallTransaction>;
44
47
  /**
45
- * Retrieves a rich transaction by its hash.
48
+ * Retrieves a transaction record by its hash.
46
49
  *
47
50
  * @param hash - The transaction hash
48
- * @returns A rich Transaction with receipt, block, etc.
51
+ * @returns A TransactionRecord with receipt, block, etc.
49
52
  *
50
53
  * @example
51
54
  * ```ts
@@ -53,18 +56,18 @@ export declare class TransactionManager {
53
56
  * console.log(tx.from, tx.to, tx.value);
54
57
  * ```
55
58
  */
56
- fromHash(hash: `0x${string}`): Promise<RichTransaction>;
59
+ fromHash(hash: `0x${string}`): Promise<TransactionRecord>;
57
60
  /**
58
61
  * Retrieves a transaction by its hash or block number and index.
59
62
  */
60
- get(params: GetTransactionParameters): Promise<RichTransaction>;
63
+ get(params: GetTransactionParameters): Promise<TransactionRecord>;
61
64
  /**
62
65
  * Parse a transaction object from a JSON converted transaction data object.
63
66
  */
64
- parse<J extends JSONTransaction<0>>(data: J): RichTransaction;
67
+ parse<J extends JSONTransaction<0>>(data: J): TransactionRecord;
65
68
  /**
66
69
  * Sends a transaction to the blockchain network.
67
70
  * @deprecated Use client.transactions.create() for new transactions
68
71
  */
69
- send(params: SendTransactionParameters): Promise<RichTransaction>;
72
+ send(params: SendTransactionParameters): Promise<TransactionRecord>;
70
73
  }
@@ -1,4 +1,5 @@
1
1
  export * from './AccountManager';
2
2
  export * from './BlockManager';
3
3
  export * from './ContractManager';
4
+ export * from './GasManager';
4
5
  export * from './TransactionManager';
@@ -1,9 +1,10 @@
1
1
  import type { Address, Hash } from "@mentaproject/core/types";
2
- import { Transaction as RichTransaction } from "./Transaction";
2
+ import { TransactionRecord } from "./TransactionRecord";
3
3
  import { Transaction } from "@mentaproject/transactions";
4
4
  import { AccountData, FetchTransactionParams, GetTransactionsParams, JSONAccount } from "../types/Account";
5
5
  import { PersistenceManager } from "../managers/PersistenceManager";
6
6
  import { MentaClient } from "./MentaClient";
7
+ import { WithGas } from "../utils/withGasSupport";
7
8
  /**
8
9
  * Represents a blockchain account with functionalities to interact with the Menta blockchain.
9
10
  */
@@ -16,24 +17,27 @@ export declare class Account implements AccountData {
16
17
  contractType(): Promise<any>;
17
18
  /**
18
19
  * Creates a Transaction to send ETH to this account.
20
+ * Enhanced with withGas() support for easy gas configuration.
19
21
  *
20
22
  * @param amount The amount of ETH to send, in wei.
21
- * @returns A Transaction with .call(), .simulate(), and .execute() methods.
23
+ * @returns A Transaction with withGas(), .call(), .simulate(), and .execute() methods.
22
24
  *
23
25
  * @example
24
26
  * ```ts
25
- * // Direct execution
26
- * const pending = await account.sendEth(parseEther("1")).execute();
27
+ * // With gas config
28
+ * const pending = await account.sendEth(parseEther("1"))
29
+ * .withGas("fast")
30
+ * .execute();
27
31
  * const receipt = await pending.confirm();
28
32
  *
29
33
  * // Batch with MulticallTransaction
30
34
  * multicall.addCall(account.sendEth(parseEther("1")));
31
35
  * ```
32
36
  */
33
- sendEth(amount: bigint): Transaction;
37
+ sendEth(amount: bigint): WithGas<Transaction>;
34
38
  ETHBalance(): Promise<bigint>;
35
39
  transactionCount(): Promise<number>;
36
- transactions(params: GetTransactionsParams, forceFetch?: boolean): Promise<RichTransaction[]>;
40
+ transactions(params: GetTransactionsParams, forceFetch?: boolean): Promise<TransactionRecord[]>;
37
41
  syncTransactions(limit?: number): Promise<void>;
38
42
  tokenTransactions(tokenAddress: Address): Promise<any>;
39
43
  toJSON<D extends number = 1>(depth: D): Promise<JSONAccount<D>>;
@@ -1,6 +1,6 @@
1
1
  import { Block as RawBlock, Hash, Hex, Withdrawal } from "@mentaproject/core";
2
2
  import { Account } from "./Account";
3
- import { Transaction } from "./Transaction";
3
+ import { TransactionRecord } from "./TransactionRecord";
4
4
  import { JSONBlock } from "../types/Block";
5
5
  import { MentaClient } from "./MentaClient";
6
6
  /**
@@ -116,7 +116,7 @@ export declare class Block implements Omit<RawBlock, "miner" | "transactions"> {
116
116
  /**
117
117
  * @description The transactions included in the block, represented as an array of Transaction instances.
118
118
  */
119
- transactions?: Transaction[] | Hash[];
119
+ transactions?: TransactionRecord[] | Hash[];
120
120
  /**
121
121
  * @description Creates an instance of Block.
122
122
  * @param client - The instance of MentaClient used to interact with the blockchain.
@@ -125,7 +125,7 @@ export declare class Block implements Omit<RawBlock, "miner" | "transactions"> {
125
125
  */
126
126
  constructor(client: MentaClient, data: RawBlock);
127
127
  protected includeTransactions(): this is this & {
128
- transactions: Transaction[];
128
+ transactions: TransactionRecord[];
129
129
  };
130
130
  /**
131
131
  * @description Converts the Block instance to a JSON representation.
@@ -7,98 +7,75 @@ import { TransactionManager } from "../managers/TransactionManager";
7
7
  import { ContractManager } from "../managers/ContractManager";
8
8
  import { AccountManager } from "../managers/AccountManager";
9
9
  import { PersistenceManager } from "../managers/PersistenceManager";
10
+ import { GasManager, GasStrategy } from "../managers/GasManager";
10
11
  import { ClientEvents, GetListenerCallback, MentaClientConfig } from "../types/MentaClient";
11
12
  import { Account } from "./Account";
12
13
  /**
13
14
  * The main client for interacting with the Menta API.
14
- * It provides managers for blocks, transactions, contracts, and accounts.
15
+ * It provides managers for blocks, transactions, contracts, accounts, and gas.
15
16
  *
16
- * @description This class serves as the primary entry point for interacting with the Menta blockchain.
17
- * It encapsulates the core RPC client and provides specialized managers for various blockchain entities,
18
- * simplifying common operations.
17
+ * @example
18
+ * ```ts
19
+ * const client = new MentaClient({
20
+ * url: 'http://rpcurlhere.com',
21
+ * gas: { strategy: 'fast' }, // Default gas strategy
22
+ * });
23
+ *
24
+ * await client.init();
25
+ *
26
+ * // Use gas manager
27
+ * const prices = await client.gas.getPrices();
28
+ * const fastConfig = await client.gas.estimate('fast');
29
+ * ```
19
30
  */
20
31
  export declare class MentaClient {
21
32
  protected params: MentaClientConfig;
22
33
  protected _rpc?: MentaAccountClient;
23
34
  protected _account?: Account;
35
+ protected _gas?: GasManager;
24
36
  /**
25
37
  * The underlying RPC client used for blockchain interactions.
26
- * @description This client is responsible for low-level communication with the RPC node.
27
38
  */
28
39
  get rpc(): MentaAccountClient;
29
40
  /**
30
41
  * The account associated with the client.
31
- * @description This account is used for signing transactions and interacting with the blockchain.
32
42
  */
33
43
  get account(): Account;
44
+ /**
45
+ * Manager for gas estimation and configuration.
46
+ */
47
+ get gas(): GasManager;
48
+ /**
49
+ * Default gas strategy for transactions.
50
+ */
51
+ defaultGasStrategy?: GasStrategy;
34
52
  /**
35
53
  * Manager for block-related operations.
36
- * @description Provides methods to query and interact with blockchain blocks.
37
54
  */
38
55
  blocks: BlockManager;
39
56
  /**
40
57
  * Manager for transaction-related operations.
41
- * @description Provides methods to send, query, and manage blockchain transactions.
42
58
  */
43
59
  transactions: TransactionManager;
44
60
  /**
45
61
  * Manager for contract-related operations.
46
- * @description Provides methods to deploy, interact with, and query smart contracts.
47
62
  */
48
63
  contracts: ContractManager;
49
64
  /**
50
65
  * Manager for account-related operations.
51
- * @description Provides methods to manage and interact with blockchain accounts.
52
66
  */
53
67
  accounts: AccountManager;
68
+ /**
69
+ * Optional manager for persistence-related operations.
70
+ */
71
+ persistenceManager?: PersistenceManager;
54
72
  /**
55
73
  * Subscribes to a specific client event.
56
- * @template TEvent The type of the event to listen for.
57
- * @param {TEvent} event - The event to listen for (e.g., 'block', 'transaction').
58
- * @param {GetListenerCallback<TEvent>} callback - The callback function to execute when the event is triggered.
59
- * @returns {() => void} An unsubscribe function to stop listening to the event.
60
- * @description This method allows the client to listen for real-time events from the blockchain, such as new blocks or transactions.
61
- * @example
62
- * import { MentaClient } from '@mentaproject/client';
63
- *
64
- * const client = new MentaClient({ url: 'http://rpcurlhere.com' });
65
- *
66
- * // Subscribe to new blocks
67
- * const unsubscribe = client.on('block', (block) => {
68
- * console.log('New block received:', block);
69
- * });
70
- *
71
- * // To stop listening
72
- * // unsubscribe();
73
74
  */
74
75
  on<TEvent extends keyof typeof ClientEvents>(event: TEvent, callback: GetListenerCallback<TEvent>): any;
75
76
  /**
76
77
  * Creates an instance of MentaClient.
77
- * @param {MentaClientConfig} params - The configuration parameters for the client.
78
- * @description The constructor initializes the RPC client and the various managers based on the provided configuration.
79
- * It also applies caching and persistence if specified in the configuration.
80
- * @example
81
- * import { MentaClient } from '@mentaproject/client';
82
- *
83
- * // Basic initialization
84
- * const client = new MentaClient({
85
- * url: 'http://rpcurlhere.com',
86
- * });
87
- *
88
- * // Initialization with a persistent cache
89
- * const clientWithCache = new MentaClient({
90
- * url: 'http://rpcurlhere.com',
91
- * cache: {
92
- * ttl: 60000, // 1 minute
93
- * },
94
- * });
95
78
  */
96
79
  constructor(params: MentaClientConfig);
97
80
  init(): Promise<void>;
98
- /**
99
- * Optional manager for persistence-related operations.
100
- * @description This manager is initialized if a persistence adapter is provided in the client configuration,
101
- * allowing for data storage and retrieval.
102
- */
103
- persistenceManager?: PersistenceManager;
104
81
  }
@@ -0,0 +1,138 @@
1
+ import { AccessList, Hash, Hex, Transaction as RawTransaction, WaitForTransactionReceiptReturnType } from '@mentaproject/core/types';
2
+ import { Account } from './Account';
3
+ import { Block } from './Block';
4
+ import { MentaClient } from './MentaClient';
5
+ import { JSONTransaction, TransactionCall } from '../types';
6
+ /**
7
+ * Represents a blockchain transaction with its properties and methods.
8
+ *
9
+ * @description This class encapsulates the data and functionalities related to an Ethereum-like transaction,
10
+ * providing methods to interact with the blockchain to retrieve transaction-related information such as
11
+ * internal calls, receipts, and the block it belongs to.
12
+ */
13
+ export declare class TransactionRecord implements Omit<RawTransaction, "from" | "to"> {
14
+ protected client: MentaClient;
15
+ /**
16
+ * @description The access list for the transaction.
17
+ */
18
+ accessList?: AccessList;
19
+ /**
20
+ * @description The blob versioned hashes.
21
+ */
22
+ blobVersionedHashes?: readonly Hex[];
23
+ /**
24
+ * @description The gas limit for the transaction.
25
+ */
26
+ gas: bigint;
27
+ /**
28
+ * @description The gas price for the transaction.
29
+ */
30
+ gasPrice?: bigint;
31
+ /**
32
+ * @description The hash of the transaction.
33
+ */
34
+ hash: Hash;
35
+ /**
36
+ * @description The input data for the transaction.
37
+ */
38
+ input: Hex;
39
+ /**
40
+ * @description The maximum fee per gas.
41
+ */
42
+ maxFeePerGas?: bigint;
43
+ /**
44
+ * @description The maximum priority fee per gas.
45
+ */
46
+ maxPriorityFeePerGas?: bigint;
47
+ /**
48
+ * @description The nonce of the transaction.
49
+ */
50
+ nonce: number;
51
+ /**
52
+ * @description The r value of the signature.
53
+ */
54
+ r: Hex;
55
+ /**
56
+ * @description The s value of the signature.
57
+ */
58
+ s: Hex;
59
+ /**
60
+ * @description The index of the transaction within the block.
61
+ */
62
+ transactionIndex: number | null;
63
+ /**
64
+ * @description The type of the transaction.
65
+ */
66
+ type: "legacy" | "eip2930" | "eip1559" | "eip4844" | "eip7702";
67
+ /**
68
+ * @description The v value of the signature.
69
+ */
70
+ v: bigint;
71
+ /**
72
+ * @description The value transferred in the transaction.
73
+ */
74
+ value: bigint;
75
+ /**
76
+ * @description The y parity of the signature.
77
+ */
78
+ yParity?: number;
79
+ /**
80
+ * @description The hash of the block containing this transaction.
81
+ */
82
+ blockHash: Hash | null;
83
+ /**
84
+ * @description The number of the block containing this transaction.
85
+ */
86
+ blockNumber: bigint | null;
87
+ /**
88
+ * @description The hex representation of the type of the transaction.
89
+ */
90
+ typeHex: `0x${string}` | null;
91
+ /**
92
+ * @description The sender account of the transaction.
93
+ */
94
+ from?: Account;
95
+ /**
96
+ * @description The recipient account of the transaction.
97
+ */
98
+ to?: Account;
99
+ /**
100
+ * Creates an instance of Transaction.
101
+ * @description Initializes a new Transaction instance with the provided RPC client and transaction data.
102
+ * @param {MentaClient} client - The instance of MentaClient used to interact with the blockchain.
103
+ * @param {ITransactionData} data The raw transaction data.
104
+ */
105
+ constructor(client: MentaClient, data: RawTransaction);
106
+ /**
107
+ * Retrieves the internal calls made by this transaction.
108
+ * @description Fetches and processes the transaction traces to extract internal call details.
109
+ * @returns {Promise<TransactionCall[] | undefined>} A promise that resolves to an array of call objects, each representing an internal call with sender, recipient, value, input data, gas used, and call type.
110
+ */
111
+ calls(): Promise<TransactionCall[] | undefined>;
112
+ /**
113
+ * Waits for the transaction receipt to be available.
114
+ * @description Asynchronously waits for the transaction to be confirmed on the blockchain and its receipt to be available.
115
+ * @param {number} [confirmations] The number of confirmations to wait for. Defaults to 1.
116
+ * @returns {Promise<WaitForTransactionReceiptReturnType>} A promise that resolves to the transaction receipt once the specified number of confirmations are met.
117
+ */
118
+ waitForReceipt(confirmations?: number): Promise<WaitForTransactionReceiptReturnType>;
119
+ /**
120
+ * Retrieves the transaction receipt.
121
+ * @description Fetches the transaction receipt for the current transaction hash.
122
+ * @returns {Promise<WaitForTransactionReceiptReturnType>} A promise that resolves to the transaction receipt.
123
+ */
124
+ receipt(): Promise<WaitForTransactionReceiptReturnType | undefined>;
125
+ /**
126
+ * Retrieves the block containing this transaction.
127
+ * @description Fetches the block data using the transaction's block hash and returns a Block instance.
128
+ * @returns {Promise<Block>} A promise that resolves to a Block instance representing the block that includes this transaction.
129
+ */
130
+ block(): Promise<Block>;
131
+ /**
132
+ * Converts the Transaction instance to a JSON representation.
133
+ * @description Serializes the transaction instance into a JSON object, including nested representations of related entities like block, receipt, and internal calls based on the specified depth.
134
+ * @param {number} [depth=1] The depth of the conversion. Controls how deeply nested objects are serialized.
135
+ * @returns {Promise<object>} A promise that resolves to the JSON representation of the transaction.
136
+ */
137
+ toJSON<D extends number = 1>(depth: D): Promise<JSONTransaction<D>>;
138
+ }
@@ -1,5 +1,5 @@
1
1
  export * from "./Account";
2
2
  export * from "./Block";
3
3
  export * from "./MentaClient";
4
- export * from "./Transaction";
4
+ export * from "./TransactionRecord";
5
5
  export * from "./Cache";
@@ -6,6 +6,7 @@ import { ICache } from "./Cache";
6
6
  import { watchBlockNumber, watchBlocks } from "@mentaproject/core/actions";
7
7
  import { IPersistenceAdapter } from "./PersistenceAdapter";
8
8
  import { WebAuthnAccount } from "@mentaproject/core/account-abstraction";
9
+ import { GasStrategy } from "../managers/GasManager";
9
10
  /**
10
11
  * Configuration for the client's cache.
11
12
  * @interface CacheConfig
@@ -18,6 +19,16 @@ export interface CacheConfig {
18
19
  */
19
20
  ttl_policies: Record<string, number>;
20
21
  }
22
+ /**
23
+ * Gas configuration for the client.
24
+ */
25
+ export interface GasConfig {
26
+ /**
27
+ * Default gas strategy for all transactions.
28
+ * Can be overridden per transaction with withGas() or withGasConfig().
29
+ */
30
+ strategy: GasStrategy;
31
+ }
21
32
  /**
22
33
  * Configuration options for the MentaClient.
23
34
  * Extends {@link CoreClientConfig} from `@mentaproject/core`.
@@ -46,6 +57,11 @@ export interface MentaClientConfig extends CoreClientConfig {
46
57
  * Validator address used for userOperations
47
58
  */
48
59
  validatorAddress: Address;
60
+ /**
61
+ * Optional gas configuration.
62
+ * If provided, sets the default gas strategy for all transactions.
63
+ */
64
+ gas?: GasConfig;
49
65
  }
50
66
  /**
51
67
  * Defines the available client events and their corresponding watch functions.
@@ -1,5 +1,5 @@
1
1
  import { Address } from '@mentaproject/core/types';
2
- import { Transaction } from '../structures/Transaction';
2
+ import { TransactionRecord } from '../structures/TransactionRecord';
3
3
  import { GetTransactionsParams } from './Account';
4
4
  import { JSONTransaction } from './Transaction';
5
5
  /**
@@ -10,15 +10,15 @@ export interface IPersistenceAdapter {
10
10
  /**
11
11
  * @method upsertTransactions
12
12
  * @description Inserts or updates a list of transactions. The operation must be atomic.
13
- * @param {Transaction[]} transactions - An array of transaction data, including associated account addresses and timestamps.
13
+ * @param {TransactionRecord[]} transactions - An array of transaction data, including associated account addresses and timestamps.
14
14
  * @returns {Promise<void>} A Promise that resolves when the transactions have been successfully inserted or updated.
15
15
  */
16
- upsertTransactions(transactions: Transaction[]): Promise<void>;
16
+ upsertTransactions(transactions: TransactionRecord[]): Promise<void>;
17
17
  /**
18
18
  * @method getTransactions
19
19
  * @description Retrieves a paginated list of transactions for a specific account based on provided filters.
20
20
  * @param {GetTransactionsFilters} filters - An object containing filters for retrieving transactions, such as account address, block range, pagination, and sort order.
21
- * @returns {Promise<JSONTransaction[]>} A Promise that resolves with transactions objects.
21
+ * @returns {Promise<JSONTransactionRecord[]>} A Promise that resolves with transactions objects.
22
22
  */
23
23
  getTransactions(address: Address, params: GetTransactionsParams): Promise<JSONTransaction<0>[]>;
24
24
  /**
@@ -0,0 +1,35 @@
1
+ import { BaseTransaction } from "@mentaproject/transactions";
2
+ import { GasManager, GasStrategy } from "../managers/GasManager";
3
+ /**
4
+ * Transaction enhanced with withGas() support.
5
+ */
6
+ export type WithGas<T extends BaseTransaction> = T & {
7
+ /**
8
+ * Sets gas configuration using a strategy (easy mode).
9
+ * Uses the client's GasManager for estimation.
10
+ *
11
+ * @param strategy - "slow", "medium", or "fast"
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * await tx.withGas("fast").execute();
16
+ * ```
17
+ */
18
+ withGas(strategy: GasStrategy): Promise<T>;
19
+ };
20
+ /**
21
+ * Enhances a transaction with withGas() support.
22
+ * This injects the client's GasManager for gas estimation.
23
+ *
24
+ * @param tx - The transaction to enhance
25
+ * @param gasManager - The client's GasManager
26
+ * @returns The enhanced transaction with withGas() method
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const tx = new Transaction(client.rpc, call);
31
+ * const enhanced = withGasSupport(tx, client.gas);
32
+ * await enhanced.withGas("fast").execute();
33
+ * ```
34
+ */
35
+ export declare function withGasSupport<T extends BaseTransaction>(tx: T, gasManager: GasManager): WithGas<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mentaproject/client",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "High level EVM library used into the Menta App to facilitate Blockchain interactions. ",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -36,7 +36,7 @@
36
36
  "dependencies": {
37
37
  "@mentaproject/contracts": "^0.0.11",
38
38
  "@mentaproject/core": "^0.7.3",
39
- "@mentaproject/transactions": "^0.0.3",
39
+ "@mentaproject/transactions": "^0.0.5",
40
40
  "@modelcontextprotocol/sdk": "^1.13.0",
41
41
  "@shazow/whatsabi": "^0.21.1"
42
42
  },
@@ -0,0 +1,50 @@
1
+ import { MentaAccountClient } from "@mentaproject/core/types";
2
+ import { GasTracker, GasEstimate, GasEstimates } from "@mentaproject/transactions";
3
+
4
+ export type GasStrategy = "slow" | "medium" | "fast";
5
+
6
+ /**
7
+ * Manages gas estimation and configuration.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * // Get all prices
12
+ * const prices = await client.gas.getPrices();
13
+ * console.log(prices.fast.maxFeePerGas);
14
+ *
15
+ * // Get specific estimate
16
+ * const fast = await client.gas.estimate("fast");
17
+ * tx.withGasConfig(fast);
18
+ * ```
19
+ */
20
+ export class GasManager {
21
+ private tracker: GasTracker;
22
+
23
+ constructor(private client: MentaAccountClient) {
24
+ this.tracker = new GasTracker(client);
25
+ }
26
+
27
+ /**
28
+ * Gets all gas price estimates (slow, medium, fast).
29
+ */
30
+ async getPrices(): Promise<GasEstimates> {
31
+ return this.tracker.getEstimates();
32
+ }
33
+
34
+ /**
35
+ * Gets a specific gas estimate by strategy.
36
+ *
37
+ * @param strategy - "slow", "medium", or "fast"
38
+ */
39
+ async estimate(strategy: GasStrategy): Promise<GasEstimate> {
40
+ const prices = await this.getPrices();
41
+ return prices[strategy];
42
+ }
43
+
44
+ /**
45
+ * Gets the underlying GasTracker for advanced usage.
46
+ */
47
+ getTracker(): GasTracker {
48
+ return this.tracker;
49
+ }
50
+ }
@@ -2,7 +2,7 @@ import { getBlockNumber } from '@mentaproject/core/actions';
2
2
  import { Address } from '@mentaproject/core/types';
3
3
 
4
4
  import { Account } from '../structures/Account';
5
- import { MentaClient, Transaction } from '../structures';
5
+ import { MentaClient, TransactionRecord } from '../structures';
6
6
  import { bigIntMax } from '../utils/bigint';
7
7
  import { GetTransactionsParams, IPersistenceAdapter, JSONTransaction } from 'src/types';
8
8