@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.
package/dist/index.js CHANGED
@@ -85,6 +85,17 @@ async function toJSON({ obj, depth = 0 }) {
85
85
  return convertBigintsToStrings(data);
86
86
  }
87
87
 
88
+ // src/utils/withGasSupport.ts
89
+ function withGasSupport(tx, gasManager) {
90
+ const enhanced = tx;
91
+ enhanced.withGas = async (strategy) => {
92
+ const config = await gasManager.estimate(strategy);
93
+ tx.withGasConfig(config);
94
+ return tx;
95
+ };
96
+ return enhanced;
97
+ }
98
+
88
99
  // src/structures/Account.ts
89
100
  var Account = class {
90
101
  constructor(client, data, persistenceManager) {
@@ -104,14 +115,17 @@ var Account = class {
104
115
  }
105
116
  /**
106
117
  * Creates a Transaction to send ETH to this account.
118
+ * Enhanced with withGas() support for easy gas configuration.
107
119
  *
108
120
  * @param amount The amount of ETH to send, in wei.
109
- * @returns A Transaction with .call(), .simulate(), and .execute() methods.
121
+ * @returns A Transaction with withGas(), .call(), .simulate(), and .execute() methods.
110
122
  *
111
123
  * @example
112
124
  * ```ts
113
- * // Direct execution
114
- * const pending = await account.sendEth(parseEther("1")).execute();
125
+ * // With gas config
126
+ * const pending = await account.sendEth(parseEther("1"))
127
+ * .withGas("fast")
128
+ * .execute();
115
129
  * const receipt = await pending.confirm();
116
130
  *
117
131
  * // Batch with MulticallTransaction
@@ -119,10 +133,11 @@ var Account = class {
119
133
  * ```
120
134
  */
121
135
  sendEth(amount) {
122
- return new Transaction(this.client.rpc, {
136
+ const tx = new Transaction(this.client.rpc, {
123
137
  to: this.address,
124
138
  value: amount
125
139
  });
140
+ return withGasSupport(tx, this.client.gas);
126
141
  }
127
142
  async ETHBalance() {
128
143
  return await getBalance(this.client.rpc, { address: this.address });
@@ -196,10 +211,10 @@ var Account = class {
196
211
  }
197
212
  };
198
213
 
199
- // src/structures/Transaction.ts
214
+ // src/structures/TransactionRecord.ts
200
215
  import { getBlock, getTransactionReceipt, traceTransaction, waitForTransactionReceipt } from "@mentaproject/core/actions";
201
216
  import { hexToBigInt } from "@mentaproject/core/utils";
202
- var Transaction2 = class {
217
+ var TransactionRecord = class {
203
218
  /**
204
219
  * Creates an instance of Transaction.
205
220
  * @description Initializes a new Transaction instance with the provided RPC client and transaction data.
@@ -343,7 +358,7 @@ var Block = class {
343
358
  this.withdrawalsRoot = data.withdrawalsRoot;
344
359
  this.miner = new Account(this.client, { address: data.miner });
345
360
  if (!data.transactions || data.transactions.length === 0) {
346
- const parsed = data.transactions.map((data2) => typeof data2 === "string" ? data2 : new Transaction2(this.client, data2));
361
+ const parsed = data.transactions.map((data2) => typeof data2 === "string" ? data2 : new TransactionRecord(this.client, data2));
347
362
  this.transactions = parsed;
348
363
  }
349
364
  }
@@ -479,25 +494,27 @@ var TransactionManager = class {
479
494
  }
480
495
  /**
481
496
  * Creates a new MulticallTransaction for batching multiple calls.
497
+ * Enhanced with withGas() support for easy gas configuration.
482
498
  *
483
- * @returns A MulticallTransaction builder
499
+ * @returns A MulticallTransaction builder with withGas() support
484
500
  *
485
501
  * @example
486
502
  * ```ts
487
503
  * const pending = await client.transactions.create()
488
504
  * .addCall(account.sendEth(parseEther("1")))
489
- * .addCall(erc20.transfer(to, amount))
505
+ * .withGas("fast")
490
506
  * .execute();
491
507
  * ```
492
508
  */
493
509
  create() {
494
- return new MulticallTransaction(this.client.rpc);
510
+ const tx = new MulticallTransaction(this.client.rpc);
511
+ return withGasSupport(tx, this.client.gas);
495
512
  }
496
513
  /**
497
- * Retrieves a rich transaction by its hash.
514
+ * Retrieves a transaction record by its hash.
498
515
  *
499
516
  * @param hash - The transaction hash
500
- * @returns A rich Transaction with receipt, block, etc.
517
+ * @returns A TransactionRecord with receipt, block, etc.
501
518
  *
502
519
  * @example
503
520
  * ```ts
@@ -513,7 +530,7 @@ var TransactionManager = class {
513
530
  */
514
531
  async get(params) {
515
532
  const data = await getTransaction(this.client.rpc, params);
516
- return new Transaction2(this.client, data);
533
+ return new TransactionRecord(this.client, data);
517
534
  }
518
535
  /**
519
536
  * Parse a transaction object from a JSON converted transaction data object.
@@ -525,7 +542,7 @@ var TransactionManager = class {
525
542
  from: parsed.from.address,
526
543
  to: parsed.to ? parsed.to.address : null
527
544
  };
528
- return new Transaction2(this.client, rawData);
545
+ return new TransactionRecord(this.client, rawData);
529
546
  }
530
547
  /**
531
548
  * Sends a transaction to the blockchain network.
@@ -673,6 +690,36 @@ var PersistenceManager = class {
673
690
  }
674
691
  };
675
692
 
693
+ // src/managers/GasManager.ts
694
+ import { GasTracker } from "@mentaproject/transactions";
695
+ var GasManager = class {
696
+ constructor(client) {
697
+ this.client = client;
698
+ this.tracker = new GasTracker(client);
699
+ }
700
+ /**
701
+ * Gets all gas price estimates (slow, medium, fast).
702
+ */
703
+ async getPrices() {
704
+ return this.tracker.getEstimates();
705
+ }
706
+ /**
707
+ * Gets a specific gas estimate by strategy.
708
+ *
709
+ * @param strategy - "slow", "medium", or "fast"
710
+ */
711
+ async estimate(strategy) {
712
+ const prices = await this.getPrices();
713
+ return prices[strategy];
714
+ }
715
+ /**
716
+ * Gets the underlying GasTracker for advanced usage.
717
+ */
718
+ getTracker() {
719
+ return this.tracker;
720
+ }
721
+ };
722
+
676
723
  // src/types/MentaClient.ts
677
724
  import { watchBlockNumber, watchBlocks } from "@mentaproject/core/actions";
678
725
  var ClientEvents = {
@@ -729,30 +776,15 @@ function withCache(client, cache) {
729
776
  var MentaClient = class {
730
777
  /**
731
778
  * Creates an instance of MentaClient.
732
- * @param {MentaClientConfig} params - The configuration parameters for the client.
733
- * @description The constructor initializes the RPC client and the various managers based on the provided configuration.
734
- * It also applies caching and persistence if specified in the configuration.
735
- * @example
736
- * import { MentaClient } from '@mentaproject/client';
737
- *
738
- * // Basic initialization
739
- * const client = new MentaClient({
740
- * url: 'http://rpcurlhere.com',
741
- * });
742
- *
743
- * // Initialization with a persistent cache
744
- * const clientWithCache = new MentaClient({
745
- * url: 'http://rpcurlhere.com',
746
- * cache: {
747
- * ttl: 60000, // 1 minute
748
- * },
749
- * });
750
779
  */
751
780
  constructor(params) {
752
781
  this.params = params;
753
782
  this.blocks = new BlockManager(this);
754
783
  this.transactions = new TransactionManager(this);
755
784
  this.contracts = new ContractManager(this);
785
+ if (params.gas?.strategy) {
786
+ this.defaultGasStrategy = params.gas.strategy;
787
+ }
756
788
  if (params.persistenceAdapter) {
757
789
  this.persistenceManager = new PersistenceManager(
758
790
  this,
@@ -765,7 +797,6 @@ var MentaClient = class {
765
797
  }
766
798
  /**
767
799
  * The underlying RPC client used for blockchain interactions.
768
- * @description This client is responsible for low-level communication with the RPC node.
769
800
  */
770
801
  get rpc() {
771
802
  if (!this._rpc) {
@@ -775,7 +806,6 @@ var MentaClient = class {
775
806
  }
776
807
  /**
777
808
  * The account associated with the client.
778
- * @description This account is used for signing transactions and interacting with the blockchain.
779
809
  */
780
810
  get account() {
781
811
  if (!this._account) {
@@ -783,25 +813,17 @@ var MentaClient = class {
783
813
  }
784
814
  return this._account;
785
815
  }
816
+ /**
817
+ * Manager for gas estimation and configuration.
818
+ */
819
+ get gas() {
820
+ if (!this._gas) {
821
+ throw new Error("Gas manager not initialized");
822
+ }
823
+ return this._gas;
824
+ }
786
825
  /**
787
826
  * Subscribes to a specific client event.
788
- * @template TEvent The type of the event to listen for.
789
- * @param {TEvent} event - The event to listen for (e.g., 'block', 'transaction').
790
- * @param {GetListenerCallback<TEvent>} callback - The callback function to execute when the event is triggered.
791
- * @returns {() => void} An unsubscribe function to stop listening to the event.
792
- * @description This method allows the client to listen for real-time events from the blockchain, such as new blocks or transactions.
793
- * @example
794
- * import { MentaClient } from '@mentaproject/client';
795
- *
796
- * const client = new MentaClient({ url: 'http://rpcurlhere.com' });
797
- *
798
- * // Subscribe to new blocks
799
- * const unsubscribe = client.on('block', (block) => {
800
- * console.log('New block received:', block);
801
- * });
802
- *
803
- * // To stop listening
804
- * // unsubscribe();
805
827
  */
806
828
  on(event, callback) {
807
829
  const eventFunction = ClientEvents[event];
@@ -824,6 +846,7 @@ var MentaClient = class {
824
846
  validatorAddress: this.params.validatorAddress
825
847
  });
826
848
  this._account = this.accounts.get(this.rpc.account.address);
849
+ this._gas = new GasManager(this.rpc);
827
850
  }
828
851
  };
829
852
 
@@ -927,10 +950,11 @@ export {
927
950
  Block,
928
951
  BlockManager,
929
952
  ContractManager,
953
+ GasManager,
930
954
  MemoryCache,
931
955
  MentaClient,
932
- Transaction2 as Transaction,
933
956
  TransactionManager,
957
+ TransactionRecord,
934
958
  bigIntMax,
935
959
  bigIntMin,
936
960
  bigIntReviver,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/structures/Account.ts","../src/utils/toJSON.ts","../src/structures/Transaction.ts","../src/structures/Block.ts","../src/structures/MentaClient.ts","../src/managers/BlockManager.ts","../src/managers/TransactionManager.ts","../src/utils/bigint.ts","../src/managers/ContractManager.ts","../src/managers/AccountManager.ts","../src/managers/PersistenceManager.ts","../src/types/MentaClient.ts","../src/utils/withCache.ts","../src/structures/Cache.ts"],"sourcesContent":["import {\n fetchByBlockRange,\n getBalance,\n getBlockNumber,\n getCode,\n getTransactionCount,\n traceFilter,\n} from \"@mentaproject/core/actions\";\nimport type {\n Address,\n Hash,\n onBlockRangeCallback,\n} from \"@mentaproject/core/types\";\nimport { Transaction as RichTransaction } from \"./Transaction\";\nimport { Transaction } from \"@mentaproject/transactions\";\nimport { toHex } from \"@mentaproject/core/utils\";\nimport {\n AccountData,\n FetchTransactionParams,\n GetTransactionsParams,\n JSONAccount,\n} from \"../types/Account\";\nimport { getContractType } from \"@mentaproject/contracts\";\nimport { toJSON } from \"../utils/toJSON\";\nimport { PersistenceManager } from \"../managers/PersistenceManager\";\nimport { MentaClient } from \"./MentaClient\";\n\n/**\n * Represents a blockchain account with functionalities to interact with the Menta blockchain.\n */\nexport class Account implements AccountData {\n public address: Address;\n private persistenceManager?: PersistenceManager;\n\n constructor(\n public client: MentaClient,\n data: AccountData,\n persistenceManager?: PersistenceManager,\n ) {\n this.address = data.address;\n this.persistenceManager = persistenceManager;\n }\n\n async isContract(): Promise<boolean> {\n const code = await getCode(this.client.rpc, { address: this.address });\n if (!code || code === \"0x\") return false;\n return true;\n }\n\n async contractType(): Promise<any> {\n const isContract = await this.isContract();\n if (!isContract) return undefined;\n return await getContractType(this.client.rpc, this.address);\n }\n\n /**\n * Creates a Transaction to send ETH to this account.\n *\n * @param amount The amount of ETH to send, in wei.\n * @returns A Transaction with .call(), .simulate(), and .execute() methods.\n *\n * @example\n * ```ts\n * // Direct execution\n * const pending = await account.sendEth(parseEther(\"1\")).execute();\n * const receipt = await pending.confirm();\n *\n * // Batch with MulticallTransaction\n * multicall.addCall(account.sendEth(parseEther(\"1\")));\n * ```\n */\n sendEth(amount: bigint): Transaction {\n return new Transaction(this.client.rpc, {\n to: this.address,\n value: amount,\n });\n }\n\n async ETHBalance(): Promise<bigint> {\n return await getBalance(this.client.rpc, { address: this.address });\n }\n\n async transactionCount(): Promise<number> {\n return await getTransactionCount(this.client.rpc, { address: this.address });\n }\n\n async transactions(\n params: GetTransactionsParams,\n forceFetch = false,\n ): Promise<RichTransaction[]> {\n if (!this.persistenceManager || forceFetch) {\n const hashes = await this._fetchTransactions(params);\n const transactions = await Promise.all(\n hashes.map((hash) => this.client.transactions.get({ hash })),\n );\n return transactions;\n }\n\n const jsons = await this.persistenceManager.getTransactions(\n this.address,\n params,\n );\n return jsons.map((j) => this.client.transactions.parse(j));\n }\n\n async syncTransactions(limit: number = 1000): Promise<void> {\n if (!this.persistenceManager)\n throw new Error(\"The persistence module is not configured.\");\n await this.persistenceManager.syncTransactions(this, limit);\n }\n\n async tokenTransactions(tokenAddress: Address): Promise<any> {\n if (!this.persistenceManager)\n throw new Error(\"The persistence module is not configured.\");\n return {};\n }\n\n async toJSON<D extends number = 1>(depth: D): Promise<JSONAccount<D>> {\n return await toJSON({\n obj: {\n address: this.address,\n isContract: this.isContract.bind(this),\n contractType: this.contractType.bind(this),\n ETHBalance: this.ETHBalance.bind(this),\n transactionCount: this.transactionCount.bind(this),\n },\n depth,\n });\n }\n\n protected async _fetchTransactions({\n fromBlock,\n toBlock,\n limit = 50,\n }: FetchTransactionParams): Promise<Hash[]> {\n const lastBlock = await getBlockNumber(this.client.rpc);\n\n const onBlockRange: onBlockRangeCallback = async (\n { fromBlock, toBlock },\n stop,\n ) => {\n const outgoing = await traceFilter(this.client.rpc, {\n fromBlock: toHex(fromBlock),\n toBlock: toHex(toBlock),\n fromAddress: this.address,\n });\n\n const incoming = await traceFilter(this.client.rpc, {\n fromBlock: toHex(fromBlock),\n toBlock: toHex(toBlock),\n toAddress: this.address,\n });\n\n const traces = outgoing\n .concat(incoming)\n .sort((a, b) => a.blockNumber - b.blockNumber);\n\n return traces.map((t) => t.transactionHash as Hash);\n };\n\n return await fetchByBlockRange({\n toBlock: BigInt(toBlock !== undefined ? toBlock : 0),\n fromBlock: BigInt(fromBlock !== undefined ? fromBlock : lastBlock),\n direction: \"backward\",\n itemLimit: limit,\n onBlockRange,\n });\n }\n}\n","/**\n * @module toJSON\n */\n\n/**\n * Interface for parameters passed to the toJSON function.\n * @template T The type of the object to be converted to JSON.\n */\nexport interface IToJSONParams<T extends { [key: string]: any } = { [key: string]: any }> {\n /** The object to convert. */\n obj: T;\n /** The depth for recursive conversion. Defaults to 0. */\n depth?: number;\n}\n\n/**\n * Checks if an object is a class instance (not a native JavaScript object like Array, Date, etc.).\n * @param {any} obj The object to check.\n * @returns {boolean} True if the object is a class instance, false otherwise.\n */\nfunction isClassInstance(obj: any): boolean {\n if (!obj) return false;\n\n const constructor = obj.constructor;\n const nativeConstructors = [Array, Date, RegExp, Map, Set, Promise, Function, Number, String, Boolean, Error, Object];\n\n if (nativeConstructors.includes(constructor)) {\n return false;\n }\n\n return true\n};\n\n/**\n * Recursively converts BigInt values in an object to strings.\n * @param {any} obj The object to convert.\n * @returns {any} The object with BigInts converted to strings.\n */\nfunction convertBigintsToStrings(obj: any): any {\n if (typeof obj === 'bigint') {\n return obj.toString() + \"n\";\n }\n\n if (typeof obj === 'object') {\n for (const key in obj) {\n obj[key] = convertBigintsToStrings(obj[key]);\n }\n }\n\n if (Array.isArray(obj)) {\n for (let i = 0; i < obj.length; i++) {\n obj[i] = convertBigintsToStrings(obj[i]);\n }\n }\n\n return obj;\n}\n\n/**\n * Converts an object, including its nested class instances and getter methods, into a plain JSON object.\n * BigInt values are converted to strings.\n *\n * @param params - The parameters for conversion.\n * @param params.obj - The object to convert.\n * @param [params.depth=0] - The depth for recursive conversion. Defaults to 0.\n * @returns A promise that resolves to the JSON representation of the object.\n */\nexport async function toJSON({ obj, depth = 0 }: IToJSONParams) {\n const data: any = {};\n const promises: Promise<any>[] = [];\n\n for (const key in obj) {\n // skip class related properties\n if (key === \"toJSON\" || key === \"constructor\" || key === \"client\" || key === \"persistenceManager\") continue;\n\n const prop: any = obj[key];\n\n if (typeof prop === \"function\") {\n // do not fetch getters if depth is 0\n if (depth === 0) continue;\n\n const promise = async () => {\n const value = await obj[key]();\n\n // if the value is a class instance, convert it to JSON recursively\n if (typeof value === \"object\" && isClassInstance(value)) return data[key] = await toJSON({ obj: value, depth: depth - 1 });\n\n data[key] = value;\n };\n\n promises.push(promise());\n };\n\n if (typeof prop === \"object\" && isClassInstance(prop)) {\n // If depth is 0, just flatten the object using recursion\n if (depth === 0) {\n const promise = async () => {\n data[key] = await toJSON({\n obj: prop,\n depth: depth - 1\n });\n };\n promises.push(promise());\n\n continue;\n };\n \n // If depth is not 0, fetch the object\n const promise = async () => {\n data[key] = await prop.toJSON({ depth: depth - 1 });\n };\n promises.push(promise());\n\n continue;\n };\n\n data[key] = prop;\n };\n\n await Promise.all(promises);\n\n return convertBigintsToStrings(data);\n};","import { AccessList, Address, Hash, Hex, Transaction as RawTransaction, WaitForTransactionReceiptReturnType } from '@mentaproject/core/types';\nimport { getBlock, getTransactionReceipt, traceTransaction, waitForTransactionReceipt } from '@mentaproject/core/actions';\nimport { hexToBigInt } from '@mentaproject/core/utils';\nimport { TransactionReceiptNotFoundError } from 'viem';\n\nimport { Account } from './Account';\nimport { Block } from './Block';\nimport { MentaClient } from './MentaClient';\n\nimport { toJSON } from '../utils/toJSON';\nimport { JSONTransaction, TransactionCall } from '../types';\n\n/**\n * Represents a blockchain transaction with its properties and methods.\n *\n * @description This class encapsulates the data and functionalities related to an Ethereum-like transaction,\n * providing methods to interact with the blockchain to retrieve transaction-related information such as\n * internal calls, receipts, and the block it belongs to.\n */\nexport class Transaction implements Omit<RawTransaction, \"from\" | \"to\"> {\n /**\n * @description The access list for the transaction.\n */\n public accessList?: AccessList;\n /**\n * @description The blob versioned hashes.\n */\n public blobVersionedHashes?: readonly Hex[];\n /**\n * @description The gas limit for the transaction.\n */\n public gas: bigint;\n /**\n * @description The gas price for the transaction.\n */\n public gasPrice?: bigint;\n /**\n * @description The hash of the transaction.\n */\n public hash: Hash;\n /**\n * @description The input data for the transaction.\n */\n public input: Hex;\n /**\n * @description The maximum fee per gas.\n */\n public maxFeePerGas?: bigint;\n /**\n * @description The maximum priority fee per gas.\n */\n public maxPriorityFeePerGas?: bigint;\n /**\n * @description The nonce of the transaction.\n */\n public nonce: number;\n /**\n * @description The r value of the signature.\n */\n public r: Hex;\n /**\n * @description The s value of the signature.\n */\n public s: Hex;\n /**\n * @description The index of the transaction within the block.\n */\n public transactionIndex: number | null;\n /**\n * @description The type of the transaction.\n */\n public type: \"legacy\" | \"eip2930\" | \"eip1559\" | \"eip4844\" | \"eip7702\";\n /**\n * @description The v value of the signature.\n */\n public v: bigint;\n /**\n * @description The value transferred in the transaction.\n */\n public value: bigint;\n /**\n * @description The y parity of the signature.\n */\n public yParity?: number;\n /**\n * @description The hash of the block containing this transaction.\n */\n public blockHash: Hash | null;\n /**\n * @description The number of the block containing this transaction.\n */\n public blockNumber: bigint | null;\n /**\n * @description The hex representation of the type of the transaction.\n */\n public typeHex: `0x${string}` | null;\n\n /**\n * @description The sender account of the transaction.\n */\n public from?: Account;\n /**\n * @description The recipient account of the transaction.\n */\n public to?: Account;\n\n\n /**\n * Creates an instance of Transaction.\n * @description Initializes a new Transaction instance with the provided RPC client and transaction data.\n * @param {MentaClient} client - The instance of MentaClient used to interact with the blockchain.\n * @param {ITransactionData} data The raw transaction data.\n */\n constructor(protected client: MentaClient, data: RawTransaction) {\n this.accessList = data.accessList;\n this.blobVersionedHashes = data.blobVersionedHashes;\n this.gas = data.gas;\n this.gasPrice = data.gasPrice;\n this.hash = data.hash;\n this.input = data.input;\n this.maxFeePerGas = data.maxFeePerGas;\n this.maxPriorityFeePerGas = data.maxPriorityFeePerGas;\n this.nonce = data.nonce;\n this.r = data.r;\n this.s = data.s;\n this.transactionIndex = data.transactionIndex;\n this.type = data.type;\n this.v = data.v;\n this.value = data.value;\n this.yParity = data.yParity;\n this.blockHash = data.blockHash;\n this.blockNumber = data.blockNumber;\n this.typeHex = data.typeHex;\n\n this.from = data.from ? this.client.accounts.get(data.from) : undefined;\n this.to = data.to ? this.client.accounts.get(data.to) : undefined;\n };\n\n /**\n * Retrieves the internal calls made by this transaction.\n * @description Fetches and processes the transaction traces to extract internal call details.\n * @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.\n */\n public async calls(): Promise<TransactionCall[] | undefined> {\n const traces = await traceTransaction(this.client.rpc, this.hash);\n if (!traces) return undefined;\n\n const calls = traces.filter(t => t.type === \"call\" && t.action !== undefined);\n\n return calls.map(c => ({\n from: new Account(this.client, { address: c.action!.from as Address }),\n to: new Account(this.client, { address: c.action!.to as Address }),\n value: hexToBigInt(c.action!.value as Hex),\n input: c.action!.input as Hex,\n gas: hexToBigInt(c.action!.gas as Hex),\n callType: c.action!.callType,\n })) as TransactionCall[];\n }\n\n /**\n * Waits for the transaction receipt to be available.\n * @description Asynchronously waits for the transaction to be confirmed on the blockchain and its receipt to be available.\n * @param {number} [confirmations] The number of confirmations to wait for. Defaults to 1.\n * @returns {Promise<WaitForTransactionReceiptReturnType>} A promise that resolves to the transaction receipt once the specified number of confirmations are met.\n */\n async waitForReceipt(confirmations?: number): Promise<WaitForTransactionReceiptReturnType> {\n return await waitForTransactionReceipt(this.client.rpc, {\n hash: this.hash,\n confirmations: confirmations || 1,\n });\n };\n\n /**\n * Retrieves the transaction receipt.\n * @description Fetches the transaction receipt for the current transaction hash.\n * @returns {Promise<WaitForTransactionReceiptReturnType>} A promise that resolves to the transaction receipt.\n */\n async receipt(): Promise<WaitForTransactionReceiptReturnType | undefined> {\n try {\n return await getTransactionReceipt(this.client.rpc, { hash: this.hash });\n } catch (error) {\n if (error instanceof TransactionReceiptNotFoundError) {\n return undefined;\n }\n }\n };\n\n /**\n * Retrieves the block containing this transaction.\n * @description Fetches the block data using the transaction's block hash and returns a Block instance.\n * @returns {Promise<Block>} A promise that resolves to a Block instance representing the block that includes this transaction.\n */\n async block(): Promise<Block> {\n const data = await getBlock(this.client.rpc, { blockHash: this.blockHash! });\n return new Block(this.client, data);\n };\n\n /**\n * Converts the Transaction instance to a JSON representation.\n * @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.\n * @param {number} [depth=1] The depth of the conversion. Controls how deeply nested objects are serialized.\n * @returns {Promise<object>} A promise that resolves to the JSON representation of the transaction.\n */\n async toJSON<D extends number = 1>(depth: D): Promise<JSONTransaction<D>> {\n return await toJSON({\n obj: {\n ...this,\n block: this.block,\n receipt: this.receipt,\n calls: async () => {\n const calls = await this.calls();\n if (!calls) return undefined;\n\n return Promise.all(calls.map(async c => await toJSON({ obj: c, depth: depth })));\n }\n },\n depth\n });\n }\n};","import { Block as RawBlock, Hash, Hex, Withdrawal } from \"@mentaproject/core\";\n\nimport { Account } from \"./Account\";\nimport { Transaction } from \"./Transaction\";\nimport { JSONBlock } from \"../types/Block\";\nimport { toJSON } from \"../utils/toJSON\";\nimport { MentaClient } from \"./MentaClient\";\n\n/**\n * @description Represents a blockchain block with its properties and methods.\n * This class provides a structured way to access block-related data and interact with the blockchain client.\n */\nexport class Block implements Omit<RawBlock, \"miner\" | \"transactions\"> {\n /**\n * @description The base fee per gas for the block.\n */\n baseFeePerGas: bigint | null\n /**\n * @description The gas used for blobs in the block.\n */\n blobGasUsed: bigint\n /**\n * @description The block's difficulty.\n */\n difficulty: bigint\n /**\n * @description The excess blob gas in the block.\n */\n excessBlobGas: bigint\n /**\n * @description Extra data included in the block.\n */\n extraData: Hex\n /**\n * @description The gas limit for the block.\n */\n gasLimit: bigint\n /**\n * @description The gas used in the block.\n */\n gasUsed: bigint\n /**\n * @description The hash of the block.\n */\n hash: Hash | null\n /**\n * @description The logs bloom filter for the block.\n */\n logsBloom: Hex | null\n /**\n * @description The mix hash of the block.\n */\n mixHash: Hash\n /**\n * @description The nonce of the block.\n */\n nonce: Hex | null\n /**\n * @description The block number.\n */\n number: bigint | null\n /**\n * @description The parent beacon block root.\n */\n parentBeaconBlockRoot?: Hex\n /**\n * @description The hash of the parent block.\n */\n parentHash: Hash\n /**\n * @description The root of the receipts trie.\n */\n receiptsRoot: Hex\n /**\n * @description The seal fields of the block.\n */\n sealFields: Hex[]\n /**\n * @description The SHA3 uncles hash.\n */\n sha3Uncles: Hash\n /**\n * @description The size of the block in bytes.\n */\n size: bigint\n /**\n * @description The state root of the block.\n */\n stateRoot: Hash\n /**\n * @description The timestamp of the block.\n */\n timestamp: bigint\n /**\n * @description The total difficulty of the chain up to this block.\n */\n totalDifficulty: bigint | null\n /**\n * @description The root of the transactions trie.\n */\n transactionsRoot: Hash\n /**\n * @description The list of uncle hashes.\n */\n uncles: Hash[]\n /**\n * @description The list of withdrawals.\n */\n withdrawals?: Withdrawal[]\n /**\n * @description The root of the withdrawals trie.\n */\n withdrawalsRoot?: Hex\n\n /**\n * @description The miner of the block, represented as an Account instance.\n */\n miner: Account\n /**\n * @description The transactions included in the block, represented as an array of Transaction instances.\n */\n transactions?: Transaction[] | Hash[]\n\n /**\n * @description Creates an instance of Block.\n * @param client - The instance of MentaClient used to interact with the blockchain.\n * @param data The raw block data conforming to IBlockData.\n * @param includeTransactions Whether to include full transaction objects. Defaults to false.\n */\n constructor(public client: MentaClient, data: RawBlock) {\n this.baseFeePerGas = data.baseFeePerGas;\n this.blobGasUsed = data.blobGasUsed;\n this.difficulty = data.difficulty;\n this.excessBlobGas = data.excessBlobGas;\n this.extraData = data.extraData;\n this.gasLimit = data.gasLimit;\n this.gasUsed = data.gasUsed;\n this.hash = data.hash;\n this.logsBloom = data.logsBloom;\n this.mixHash = data.mixHash;\n this.nonce = data.nonce;\n this.number = data.number;\n this.parentBeaconBlockRoot = data.parentBeaconBlockRoot;\n this.parentHash = data.parentHash;\n this.receiptsRoot = data.receiptsRoot;\n this.sealFields = data.sealFields;\n this.sha3Uncles = data.sha3Uncles;\n this.size = data.size;\n this.stateRoot = data.stateRoot;\n this.timestamp = data.timestamp;\n this.totalDifficulty = data.totalDifficulty;\n this.transactionsRoot = data.transactionsRoot;\n this.uncles = data.uncles;\n this.withdrawals = data.withdrawals;\n this.withdrawalsRoot = data.withdrawalsRoot;\n\n this.miner = new Account(this.client, { address: data.miner});\n \n if (!data.transactions || data.transactions.length === 0) {\n const parsed = data.transactions.map((data) => typeof data === \"string\" ? data : new Transaction(this.client, data))\n this.transactions = parsed as Transaction[] | Hash[];\n }\n };\n\n protected includeTransactions(): this is this & { transactions: Transaction[] } {\n if (!this.transactions || this.transactions.length === 0) return false;\n return true\n }\n\n /**\n * @description Converts the Block instance to a JSON representation.\n * This method serializes the block's properties into a plain JavaScript object,\n * suitable for JSON serialization.\n * @param depth The depth of the conversion. Defaults to 1.\n * @returns A promise that resolves to the JSON representation of the block.\n */\n async toJSON<D extends number = 1>(depth: D): Promise<JSONBlock<D>> {\n return await toJSON({\n obj: {\n ...this,\n },\n depth\n });\n }\n};","/**\n * @module MentaClient\n */\nimport type { MentaAccountClient } from \"@mentaproject/core/types\";\nimport { createMentaAccount } from \"@mentaproject/core/clients\";\nimport { createClient } from \"@mentaproject/core\";\n\nimport { BlockManager } from \"../managers/BlockManager\";\nimport { TransactionManager } from \"../managers/TransactionManager\";\nimport { ContractManager } from \"../managers/ContractManager\";\nimport { AccountManager } from \"../managers/AccountManager\";\nimport { PersistenceManager } from \"../managers/PersistenceManager\";\nimport {\n ClientEvents,\n GetListenerCallback,\n MentaClientConfig,\n} from \"../types/MentaClient\";\nimport { withCache } from \"../utils/withCache\";\nimport { Account } from \"./Account\";\n\n/**\n * The main client for interacting with the Menta API.\n * It provides managers for blocks, transactions, contracts, and accounts.\n *\n * @description This class serves as the primary entry point for interacting with the Menta blockchain.\n * It encapsulates the core RPC client and provides specialized managers for various blockchain entities,\n * simplifying common operations.\n */\nexport class MentaClient {\n protected _rpc?: MentaAccountClient;\n protected _account?: Account;\n /**\n * The underlying RPC client used for blockchain interactions.\n * @description This client is responsible for low-level communication with the RPC node.\n */\n public get rpc(): MentaAccountClient {\n if (!this._rpc) {\n throw new Error(\"RPC client not initialized\");\n }\n return this._rpc;\n }\n\n /**\n * The account associated with the client.\n * @description This account is used for signing transactions and interacting with the blockchain.\n */\n public get account(): Account {\n if (!this._account) {\n throw new Error(\"Account not initialized\");\n }\n return this._account;\n }\n\n /**\n * Manager for block-related operations.\n * @description Provides methods to query and interact with blockchain blocks.\n */\n public blocks!: BlockManager;\n /**\n * Manager for transaction-related operations.\n * @description Provides methods to send, query, and manage blockchain transactions.\n */\n public transactions!: TransactionManager;\n /**\n * Manager for contract-related operations.\n * @description Provides methods to deploy, interact with, and query smart contracts.\n */\n public contracts!: ContractManager;\n /**\n * Manager for account-related operations.\n * @description Provides methods to manage and interact with blockchain accounts.\n */\n public accounts!: AccountManager;\n\n /**\n * Subscribes to a specific client event.\n * @template TEvent The type of the event to listen for.\n * @param {TEvent} event - The event to listen for (e.g., 'block', 'transaction').\n * @param {GetListenerCallback<TEvent>} callback - The callback function to execute when the event is triggered.\n * @returns {() => void} An unsubscribe function to stop listening to the event.\n * @description This method allows the client to listen for real-time events from the blockchain, such as new blocks or transactions.\n * @example\n * import { MentaClient } from '@mentaproject/client';\n *\n * const client = new MentaClient({ url: 'http://rpcurlhere.com' });\n *\n * // Subscribe to new blocks\n * const unsubscribe = client.on('block', (block) => {\n * console.log('New block received:', block);\n * });\n *\n * // To stop listening\n * // unsubscribe();\n */\n on<TEvent extends keyof typeof ClientEvents>(\n event: TEvent,\n callback: GetListenerCallback<TEvent>,\n ) {\n const eventFunction = ClientEvents[event];\n const capitalizedEvent = event.charAt(0).toUpperCase() + event.slice(1);\n const params = {\n [`on${capitalizedEvent}`]: callback,\n pollingInterval: 1000,\n };\n\n return (eventFunction as any)(this.rpc, params);\n }\n\n /**\n * Creates an instance of MentaClient.\n * @param {MentaClientConfig} params - The configuration parameters for the client.\n * @description The constructor initializes the RPC client and the various managers based on the provided configuration.\n * It also applies caching and persistence if specified in the configuration.\n * @example\n * import { MentaClient } from '@mentaproject/client';\n *\n * // Basic initialization\n * const client = new MentaClient({\n * url: 'http://rpcurlhere.com',\n * });\n *\n * // Initialization with a persistent cache\n * const clientWithCache = new MentaClient({\n * url: 'http://rpcurlhere.com',\n * cache: {\n * ttl: 60000, // 1 minute\n * },\n * });\n */\n constructor(protected params: MentaClientConfig) {\n this.blocks = new BlockManager(this);\n this.transactions = new TransactionManager(this);\n this.contracts = new ContractManager(this);\n\n if (params.persistenceAdapter) {\n this.persistenceManager = new PersistenceManager(\n this,\n params.persistenceAdapter,\n );\n this.accounts = new AccountManager(this, this.persistenceManager);\n } else {\n this.accounts = new AccountManager(this);\n }\n }\n\n async init() {\n let coreClient = createClient(this.params);\n\n if (this.params.cache) {\n coreClient = withCache(coreClient, this.params.cache);\n }\n\n this._rpc = await createMentaAccount(coreClient as any, {\n bundlerTransport: this.params.bundlerTransport,\n publicTransport: this.params.transport,\n signer: this.params.signer,\n validatorAddress: this.params.validatorAddress,\n });\n\n this._account = this.accounts.get(this.rpc.account.address);\n }\n\n /**\n * Optional manager for persistence-related operations.\n * @description This manager is initialized if a persistence adapter is provided in the client configuration,\n * allowing for data storage and retrieval.\n */\n public persistenceManager?: PersistenceManager;\n}\n","/**\n * @module BlockManager\n */\nimport { BlockTag, GetBlockParameters } from \"@mentaproject/core/types\";\nimport { Block } from \"../structures/Block\";\nimport { getBlock } from \"@mentaproject/core/actions\";\nimport { MentaClient } from \"../structures\";\n\n/**\n * Manages blockchain block-related operations, providing methods to interact with and retrieve block data.\n */\nexport class BlockManager {\n /**\n * Creates an instance of BlockManager.\n * @param client - The instance of MentaClient used to interact with the blockchain.\n */\n constructor(public client: MentaClient) {};\n\n /**\n * Retrieves a block from the blockchain based on the provided parameters.\n * This method uses the underlying RPC client to fetch block data and then\n * encapsulates it within a {@link Block} instance.\n * @param params The parameters for retrieving the block, including block hash, block number, or block tag.\n * @returns A promise that resolves to a {@link Block} instance representing the retrieved block.\n * @example\n * import { http } from '@mentaproject/core';\n * import { mainnet } from '@mentaproject/core/chains';\n * import { MentaClient } from '@mentaproject/client';\n *\n * // Initialize the MentaClient\n * const mentaClient = new MentaClient({ chain: mainnet, transport: http(\"http://rpcurlhere.com\") });\n *\n * async function fetchBlock() {\n * // Retrieve the latest block\n * const latestBlock = await mentaClient.blocks.get({ blockTag: 'latest' });\n * console.log('Latest block number:', latestBlock.number);\n *\n * // Retrieve a specific block by its number\n * if (latestBlock.number) {\n * const specificBlock = await mentaClient.blocks.get({ blockNumber: latestBlock.number - 10n });\n * console.log('Specific block hash:', specificBlock.hash);\n * }\n * }\n *\n * fetchBlock();\n */\n async get(params: GetBlockParameters<boolean, BlockTag>): Promise<Block> {\n const data = await getBlock(this.client.rpc, params);\n return new Block(this.client, data);\n };\n}","/**\n * @module TransactionManager\n */\nimport { GetTransactionParameters, Transaction as RawTransaction, SendTransactionParameters } from \"@mentaproject/core/types\";\nimport { Transaction as RichTransaction } from \"../structures/Transaction\";\nimport { MulticallTransaction } from \"@mentaproject/transactions\";\nimport { getTransaction, sendTransaction } from \"@mentaproject/core/actions\";\nimport { MentaClient } from \"../structures\";\nimport { JSONTransaction } from \"../types\";\nimport { parseBingints } from \"../utils/bigint\";\n\n/**\n * Manages blockchain transaction-related operations.\n *\n * @example\n * ```ts\n * // Create a multicall transaction\n * const pending = await client.transactions.create()\n * .addCall(account.sendEth(parseEther(\"1\")))\n * .addCall(erc20.transfer(to, amount))\n * .execute();\n *\n * const receipt = await pending.confirm();\n *\n * // Get a transaction by hash\n * const tx = await client.transactions.fromHash(hash);\n * console.log(tx.receipt, tx.block);\n * ```\n */\nexport class TransactionManager {\n constructor(public client: MentaClient) {}\n\n /**\n * Creates a new MulticallTransaction for batching multiple calls.\n *\n * @returns A MulticallTransaction builder\n *\n * @example\n * ```ts\n * const pending = await client.transactions.create()\n * .addCall(account.sendEth(parseEther(\"1\")))\n * .addCall(erc20.transfer(to, amount))\n * .execute();\n * ```\n */\n create(): MulticallTransaction {\n return new MulticallTransaction(this.client.rpc);\n }\n\n /**\n * Retrieves a rich transaction by its hash.\n *\n * @param hash - The transaction hash\n * @returns A rich Transaction with receipt, block, etc.\n *\n * @example\n * ```ts\n * const tx = await client.transactions.fromHash(hash);\n * console.log(tx.from, tx.to, tx.value);\n * ```\n */\n async fromHash(hash: `0x${string}`): Promise<RichTransaction> {\n return this.get({ hash });\n }\n\n /**\n * Retrieves a transaction by its hash or block number and index.\n */\n async get(params: GetTransactionParameters): Promise<RichTransaction> {\n const data = await getTransaction(this.client.rpc, params);\n return new RichTransaction(this.client, data);\n }\n\n /**\n * Parse a transaction object from a JSON converted transaction data object.\n */\n parse<J extends JSONTransaction<0>>(data: J): RichTransaction {\n const parsed = parseBingints(data);\n\n const rawData = {\n ...parsed,\n from: parsed.from.address,\n to: parsed.to ? parsed.to.address : null,\n };\n\n return new RichTransaction(this.client, rawData as RawTransaction);\n }\n\n /**\n * Sends a transaction to the blockchain network.\n * @deprecated Use client.transactions.create() for new transactions\n */\n async send(params: SendTransactionParameters): Promise<RichTransaction> {\n const hash = await sendTransaction(this.client.rpc, params);\n return await this.get({ hash });\n }\n}\n","import { WithoutBigintStringified } from \"../types/Utils\";\n\nexport const bigIntMax = (...args: bigint[]) => args.reduce((m, e) => e > m ? e : m);\nexport const bigIntMin = (...args: bigint[]) => args.reduce((m, e) => e < m ? e : m);\n\nexport function bigIntReviver(key: string, value: any) {\n if (typeof value === 'string') {\n if (value.endsWith('n')) {\n try {\n return BigInt(value.slice(0, -1));\n } catch (e) {\n return value;\n }\n };\n };\n\n return value;\n};\n\nexport function stringifyBingints(obj: any) {\n if (typeof obj === 'bigint') {\n return obj.toString() + \"n\";\n }\n\n if (typeof obj === 'object') {\n for (const key in obj) {\n obj[key] = stringifyBingints(obj[key]);\n }\n }\n\n if (Array.isArray(obj)) {\n for (let i = 0; i < obj.length; i++) {\n obj[i] = stringifyBingints(obj[i]);\n }\n }\n\n return obj;\n};\n\nexport function parseBingints<T extends { [key: string]: any }>(obj: T): WithoutBigintStringified<T> {\n if (typeof obj !== 'object' || obj === null) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item, index) => bigIntReviver(index.toString(), parseBingints(item))) as WithoutBigintStringified<T>;\n }\n\n const newObj: { [key: string]: any } = {};\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n const value = obj[key];\n const processedValue = parseBingints(value);\n newObj[key] = bigIntReviver(key, processedValue);\n }\n };\n\n return newObj as WithoutBigintStringified<T>;\n};","/**\n * @module ContractManager\n */\nimport type { AbiItem } from \"@mentaproject/core/types\";\nimport { getContract, GetContractParameters } from \"@mentaproject/contracts\";\nimport { MentaClient } from \"../structures\";\n\n/**\n * Manages smart contract-related operations within the Menta client.\n * This class provides methods to interact with smart contracts deployed on the blockchain,\n * facilitating the retrieval of contract instances for various operations.\n */\nexport class ContractManager {\n /**\n * Creates an instance of ContractManager.\n * @description Initializes the ContractManager with a CoreClient instance, which is used for RPC communication.\n * @param client - The instance of MentaClient used to interact with the blockchain.\n */\n constructor(protected client: MentaClient) {};\n\n /**\n * Retrieves a contract instance to interact with it.\n * @description This method fetches a contract instance based on the provided parameters, allowing for interaction with its methods and events.\n * @template P The type of the contract retrieval parameters, extending `GetContractParameters` with `AbiItem` array.\n * @param {P} params The parameters for retrieving the contract, including its Application Binary Interface (ABI) and address.\n * @returns {ReturnType<typeof getContract<ReadonlyArray<AbiItem>, P>>} A contract instance that can be used to call contract methods or listen to events.\n * @example\n * import { MentaClient } from '@mentaproject/client';\n * import { http } from '@mentaproject/core';\n *\n * // Initialize the MentaClient with a transport\n * const client = new MentaClient({\n * transport: http('http://rpcurlhere.com'),\n * });\n *\n * // Define the ABI and address for the smart contract\n * const abi = [\n * {\n * \"type\": \"function\",\n * \"name\": \"greet\",\n * \"stateMutability\": \"view\",\n * \"inputs\": [],\n * \"outputs\": [{ \"name\": \"\", \"type\": \"string\" }]\n * }\n * ] as const;\n * const contractAddress = '0x...'; // Replace with your contract address\n *\n * // Retrieve the contract instance\n * const contract = client.contracts.get({\n * abi,\n * address: contractAddress,\n * });\n *\n * // Example of interacting with the contract\n * const greeting = await contract.greet();\n */\n get<P extends GetContractParameters<ReadonlyArray<AbiItem>>>(params: P) {\n return getContract(this.client.rpc, params);\n };\n};","/**\n * @module AccountManager\n */\nimport { Address } from \"@mentaproject/core/types\";\nimport { Account } from \"../structures/Account\";\nimport { PersistenceManager } from \"./PersistenceManager\";\nimport { MentaClient } from \"../structures\";\n\n/**\n * Manages blockchain account operations.\n * This class provides methods to interact with accounts,\n * including retrieving and managing them via an RPC client and a persistence manager.\n *\n * @class AccountManager\n */\nexport class AccountManager {\n /**\n * Creates an instance of AccountManager.\n *\n * @param {MentaClient} client - The instance of MentaClient used to interact with the blockchain.\n * @param {persistenceManager} persistenceManager - The optional persistence manager to store and retrieve account data.\n */\n constructor(public client: MentaClient, private persistenceManager?: PersistenceManager) { };\n\n /**\n * Retrieves an account instance by its blockchain address.\n * @param address - The blockchain address of the account to retrieve.\n * @returns An instance of the `Account` class.\n * @example\n * ```typescript\n * import { MentaClient } from '@mentaproject/client';\n * import { http } from '@mentaproject/core';\n *\n * // Initialize the MentaClient\n * const client = new MentaClient({\n * transport: http('http://rpcurlhere.com'),\n * });\n *\n * // The address of the account to retrieve\n * const accountAddress = '0x1234567890123456789012345678901234567890';\n *\n * // Retrieve the account instance using the account manager from the client\n * const account = client.accounts.get(accountAddress);\n *\n * console.log(account.address); // 0x1234567890123456789012345678901234567890\n * ```\n */\n get(address: Address): Account {\n return new Account(this.client, { address: address }, this.persistenceManager);\n };\n}","import { getBlockNumber } from '@mentaproject/core/actions';\nimport { Address } from '@mentaproject/core/types';\n\nimport { Account } from '../structures/Account';\nimport { MentaClient, Transaction } from '../structures';\nimport { bigIntMax } from '../utils/bigint';\nimport { GetTransactionsParams, IPersistenceAdapter, JSONTransaction } from 'src/types';\n\n/**\n * Manages the persistence of data, including transactions, using a specified persistence adapter.\n * It handles fetching data from both local storage and remote sources, and synchronizing them.\n */\nexport class PersistenceManager {\n /**\n * Creates an instance of PersistenceManager.\n * @param client - The instance of MentaClient used to interact with the blockchain.\n * @param persistenceAdapter - The adapter responsible for actual data persistence operations.\n */\n constructor(\n private client: MentaClient,\n private persistenceAdapter: IPersistenceAdapter\n ) {}\n\n /**\n * Retrieves transactions for a given account, applying a \"stale-while-revalidate\" strategy.\n * @param params - Parameters for retrieving transactions.\n * @returns A promise that resolves to an array of transactions with associated account information.\n */\n public async getTransactions(address: Address, params: GetTransactionsParams): Promise<JSONTransaction<0>[]> {\n return await this.persistenceAdapter.getTransactions(address, params);\n }\n\n /**\n * Synchronizes an account's transactions from the remote source to the local persistence.\n * It fetches new transactions starting from the last synced block and updates the local storage.\n * @param account - The account whose transactions are to be synchronized.\n * @param limit - The maximum number of transactions to fetch.\n * @returns A promise that resolves when the synchronization is complete.\n */\n public async syncTransactions(account: Account, limit: number = 100_000): Promise<void> {\n const lastSyncedBlock = await this.persistenceAdapter.getLastSyncedBlock(account.address);\n const lastBlock = lastSyncedBlock ?? 0n;\n\n const fromBlock = lastSyncedBlock ? lastSyncedBlock + 1n : (await getBlockNumber(this.client.rpc));\n\n const newTransactions = await account.transactions({\n fromBlock: fromBlock,\n toBlock: lastBlock,\n limit: limit\n }, true)\n\n if (newTransactions.length > 0) {\n await this.persistenceAdapter.upsertTransactions(newTransactions);\n \n const latestBlock = bigIntMax(...newTransactions.map(t => t.blockNumber || 0n));\n await this.persistenceAdapter.setLastSyncedBlock(account.address, latestBlock);\n }\n }\n}","/**\n * @module MentaClientTypes\n */\nimport { Address, CoreClientConfig, Transport } from \"@mentaproject/core/types\";\nimport { ICache } from \"./Cache\";\nimport { watchBlockNumber, watchBlocks } from \"@mentaproject/core/actions\";\nimport { IPersistenceAdapter } from \"./PersistenceAdapter\";\nimport { WebAuthnAccount } from \"@mentaproject/core/account-abstraction\";\n\n/**\n * Configuration for the client's cache.\n * @interface CacheConfig\n */\nexport interface CacheConfig {\n /**\n * Time-to-live policies for different RPC methods.\n * Keys are RPC method names (e.g., \"eth_getBlockByNumber\"), and values are\n * the TTL in milliseconds for caching responses from those methods.\n */\n ttl_policies: Record<string, number>;\n}\n\n/**\n * Configuration options for the MentaClient.\n * Extends {@link CoreClientConfig} from `@mentaproject/core`.\n * @interface MentaClientConfig\n */\nexport interface MentaClientConfig extends CoreClientConfig {\n /**\n * Optional cache implementation for the client.\n * If provided, the client will use this cache for RPC responses.\n */\n cache?: ICache;\n /**\n * Optional persistence adapter for local data storage.\n * If provided, the client will use this adapter to persist and retrieve data.\n */\n persistenceAdapter?: IPersistenceAdapter;\n /**\n * Bundler transport used for userOperations\n */\n bundlerTransport: Transport;\n /**\n * Passkey compatible signer used for signing user operations\n */\n signer: WebAuthnAccount;\n /**\n * Validator address used for userOperations\n */\n validatorAddress: Address;\n}\n\n/**\n * Defines the available client events and their corresponding watch functions.\n * These functions are used to subscribe to real-time updates from the client.\n */\nexport const ClientEvents = {\n /**\n * Event for new blocks.\n * Uses the {@link watchBlocks} function from `@mentaproject/core`.\n */\n block: watchBlocks,\n /**\n * Event for new block numbers.\n * Uses the {@link watchBlockNumber} function from `@mentaproject/core`.\n */\n blockNumber: watchBlockNumber,\n};\n\n/**\n * Utility type to extract the callback function type for a given event.\n * This type dynamically determines the expected callback signature for a specific client event.\n * @template TEvent The name of the event (e.g., 'block' or 'blockNumber') for which to get the listener callback type.\n */\nexport type GetListenerCallback<TEvent extends keyof typeof ClientEvents> =\n Parameters<(typeof ClientEvents)[TEvent]>[1] extends infer P\n ? P extends { [K in `on${Capitalize<TEvent>}`]: infer TCallback }\n ? TCallback\n : never\n : never;\n","/**\n * @module withCache\n */\nimport { watchBlockNumber } from \"@mentaproject/core/actions\";\nimport type { CoreClient } from \"@mentaproject/core/types\";\nimport { ICache } from \"../types/Cache\";\nimport { Methods } from \"../types/JsonRPC\";\n\n// EntryPoint.getNonce selector - must never be cached to avoid nonce reuse\nconst GET_NONCE_SELECTOR = \"0x35567e1a\";\n\n/**\n * Checks if an eth_call is a getNonce call to the EntryPoint.\n * These calls must not be cached to ensure fresh nonce values for each UserOperation.\n */\nfunction isNonceCall(method: Methods, params: any): boolean {\n if (method !== \"eth_call\") return false;\n const callData = params?.[0]?.data;\n return typeof callData === \"string\" && callData.startsWith(GET_NONCE_SELECTOR);\n}\n\n/**\n * A higher-order function that enhances a class method with caching capabilities.\n * It intercepts RPC requests made through the client and caches their responses\n * based on the provided cache implementation.\n *\n * @param client The CoreClient instance to enhance with caching.\n * @param cache The cache implementation (ICache) to use for storing and retrieving responses.\n * @returns The enhanced CoreClient instance with caching enabled.\n */\nexport function withCache<T extends CoreClient>(client: T, cache: ICache): T {\n watchBlockNumber(client, {\n onBlockNumber: (blockNumber) => {\n cache.setBlockNumber(blockNumber);\n },\n pollingInterval: 1000,\n });\n // 2. We keep a reference to the original request method\n const originalRequest = client.request;\n\n // 3. We replace the client's `request` method\n client.request = (async (args: { method: Methods, params: any }) => {\n const { method, params } = args;\n\n // Never cache nonce calls - they must always return fresh values\n const shouldSkipCache = method === \"eth_blockNumber\" || isNonceCall(method, params);\n\n const cacheKey = `${client.chain!.id}:${method}:${JSON.stringify(params || [], (_, v) => typeof v === 'bigint' ? v.toString() : v)}`;\n\n let result;\n if (!shouldSkipCache) {\n result = cache.get(cacheKey);\n }\n\n if (!result) {\n result = await originalRequest(args as any);\n };\n\n if (result !== null && result !== undefined && !shouldSkipCache) {\n const ttl = cache.config.ttlPolicies[method] || cache.config.defaultTtl;\n await cache.set(cacheKey, result, ttl);\n }\n\n return result;\n }) as any;\n\n return client;\n}\n","/**\n * @module MemoryCache\n */\nimport { ICache, ICacheEntry, ICacheConfig } from '../types/Cache';\n\n/**\n/**\n * @class MemoryCache\n * @description A simple in-memory cache implementation that adheres to the ICache interface.\n * It stores key-value pairs with an associated time-to-live (TTL) based on block numbers.\n * The cache automatically evicts the oldest entries when its maximum size is reached.\n */\nexport class MemoryCache implements ICache {\n /**\n * @property {Map<string, ICacheEntry<any>>} cache - The internal Map used to store cache entries.\n * @private\n */\n private cache = new Map<string, ICacheEntry<any>>();\n /**\n * @property {ICacheConfig} config - The configuration object for the cache, including maxSize, defaultTtl, and ttlPolicies.\n */\n public config: ICacheConfig;\n /**\n * @property {bigint} blockNumber - The current block number used for TTL calculations.\n * @private\n */\n private blockNumber: bigint;\n\n /**\n * @constructor\n * @description Creates an instance of MemoryCache.\n * @param {bigint} blockNumber - The current block number to use for TTL calculations.\n * @param {Partial<ICacheConfig>} [options] - Optional configuration for the cache.\n * @param {number} [options.maxSize=500] - The maximum number of entries the cache can hold.\n * @param {number} [options.defaultTtl=1] - The default time-to-live in blocks for cache entries if not specified.\n * @param {Object.<string, number>} [options.ttlPolicies={}] - A map of specific TTL policies for different keys.\n */\n constructor(blockNumber: bigint, options?: Partial<ICacheConfig>) {\n this.blockNumber = blockNumber;\n this.config = {\n maxSize: 500,\n defaultTtl: 1,\n ttlPolicies: options?.ttlPolicies || {},\n ...options,\n };\n };\n\n /**\n * @method isExpired\n * @description Checks if a cache entry has expired based on the current block number and the entry's expiry block.\n * @param {bigint} expiry - The expiry block number of the cache entry.\n * @returns {boolean} `true` if the entry has expired, `false` otherwise.\n * @protected\n */\n protected isExpired(expiry: bigint): boolean {\n return this.blockNumber > expiry;\n };\n\n /**\n * @method setBlockNumber\n * @description Sets the current block number for TTL calculations. This is crucial for managing cache entry expiry.\n * @param {bigint} blockNumber - The new current block number.\n * @returns {void}\n */\n setBlockNumber(blockNumber: bigint): void {\n this.blockNumber = blockNumber;\n }\n\n /**\n * @method set\n * @description Sets a value in the cache. If the key already exists, its entry will be updated.\n * If the cache reaches its maximum size, the oldest entry will be evicted before adding the new one.\n * @template T - The type of the value being stored.\n * @param {string} key - The unique key for the cache entry.\n * @param {T} value - The value to store in the cache.\n * @param {number} [ttl=this.config.defaultTtl] - The time-to-live (in blocks) for this specific entry. Defaults to the cache's `defaultTtl`.\n * @returns {void}\n */\n set<T>(key: string, value: T, ttl: number = this.config.defaultTtl): void {\n if (this.cache.has(key)) {\n this.cache.delete(key);\n }\n\n if (this.cache.size >= this.config.maxSize) this.evict();\n \n const expiry = this.blockNumber + BigInt(ttl);\n this.cache.set(key, { value, expiry });\n }\n\n /**\n * @method get\n * @description Retrieves a value from the cache. If the entry is found and has not expired,\n * it is moved to the end of the cache (making it the most recently used) to prevent premature eviction.\n * @template T - The expected type of the value.\n * @param {string} key - The key of the cache entry to retrieve.\n * @returns {T | undefined} The cached value if found and not expired, otherwise `undefined`.\n */\n get<T>(key: string): T | undefined {\n const entry = this.cache.get(key);\n if (!entry) return undefined;\n\n if (this.isExpired(entry.expiry)) {\n this.cache.delete(key);\n return undefined;\n }\n\n this.cache.delete(key);\n this.cache.set(key, entry);\n\n return entry.value as T;\n }\n\n /**\n * @method evict\n * @description Evicts the oldest entry from the cache. This method is called internally when the cache\n * reaches its `maxSize` to make room for new entries.\n * @returns {void}\n * @private\n */\n private evict(): void {\n const oldestKey = this.cache.keys().next().value;\n if (!oldestKey) return;\n\n this.cache.delete(oldestKey);\n }\n}"],"mappings":";;;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,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AW;AAEf,SAAK,MAAM,OAAO,SAAS;AAAA,EAC7B;AACF;","names":["promise","fromBlock","toBlock","Transaction","data","Transaction","getBlock","Transaction","getBlockNumber","getBlockNumber","watchBlockNumber"]}
1
+ {"version":3,"sources":["../src/structures/Account.ts","../src/utils/toJSON.ts","../src/utils/withGasSupport.ts","../src/structures/TransactionRecord.ts","../src/structures/Block.ts","../src/structures/MentaClient.ts","../src/managers/BlockManager.ts","../src/managers/TransactionManager.ts","../src/utils/bigint.ts","../src/managers/ContractManager.ts","../src/managers/AccountManager.ts","../src/managers/PersistenceManager.ts","../src/managers/GasManager.ts","../src/types/MentaClient.ts","../src/utils/withCache.ts","../src/structures/Cache.ts"],"sourcesContent":["import {\n fetchByBlockRange,\n getBalance,\n getBlockNumber,\n getCode,\n getTransactionCount,\n traceFilter,\n} from \"@mentaproject/core/actions\";\nimport type {\n Address,\n Hash,\n onBlockRangeCallback,\n} from \"@mentaproject/core/types\";\nimport { TransactionRecord } from \"./TransactionRecord\";\nimport { Transaction } from \"@mentaproject/transactions\";\nimport { toHex } from \"@mentaproject/core/utils\";\nimport {\n AccountData,\n FetchTransactionParams,\n GetTransactionsParams,\n JSONAccount,\n} from \"../types/Account\";\nimport { getContractType } from \"@mentaproject/contracts\";\nimport { toJSON } from \"../utils/toJSON\";\nimport { PersistenceManager } from \"../managers/PersistenceManager\";\nimport { MentaClient } from \"./MentaClient\";\nimport { withGasSupport, WithGas } from \"../utils/withGasSupport\";\n\n/**\n * Represents a blockchain account with functionalities to interact with the Menta blockchain.\n */\nexport class Account implements AccountData {\n public address: Address;\n private persistenceManager?: PersistenceManager;\n\n constructor(\n public client: MentaClient,\n data: AccountData,\n persistenceManager?: PersistenceManager,\n ) {\n this.address = data.address;\n this.persistenceManager = persistenceManager;\n }\n\n async isContract(): Promise<boolean> {\n const code = await getCode(this.client.rpc, { address: this.address });\n if (!code || code === \"0x\") return false;\n return true;\n }\n\n async contractType(): Promise<any> {\n const isContract = await this.isContract();\n if (!isContract) return undefined;\n return await getContractType(this.client.rpc, this.address);\n }\n\n /**\n * Creates a Transaction to send ETH to this account.\n * Enhanced with withGas() support for easy gas configuration.\n *\n * @param amount The amount of ETH to send, in wei.\n * @returns A Transaction with withGas(), .call(), .simulate(), and .execute() methods.\n *\n * @example\n * ```ts\n * // With gas config\n * const pending = await account.sendEth(parseEther(\"1\"))\n * .withGas(\"fast\")\n * .execute();\n * const receipt = await pending.confirm();\n *\n * // Batch with MulticallTransaction\n * multicall.addCall(account.sendEth(parseEther(\"1\")));\n * ```\n */\n sendEth(amount: bigint): WithGas<Transaction> {\n const tx = new Transaction(this.client.rpc, {\n to: this.address,\n value: amount,\n });\n return withGasSupport(tx, this.client.gas);\n }\n\n async ETHBalance(): Promise<bigint> {\n return await getBalance(this.client.rpc, { address: this.address });\n }\n\n async transactionCount(): Promise<number> {\n return await getTransactionCount(this.client.rpc, { address: this.address });\n }\n\n async transactions(\n params: GetTransactionsParams,\n forceFetch = false,\n ): Promise<TransactionRecord[]> {\n if (!this.persistenceManager || forceFetch) {\n const hashes = await this._fetchTransactions(params);\n const transactions = await Promise.all(\n hashes.map((hash) => this.client.transactions.get({ hash })),\n );\n return transactions;\n }\n\n const jsons = await this.persistenceManager.getTransactions(\n this.address,\n params,\n );\n return jsons.map((j) => this.client.transactions.parse(j));\n }\n\n async syncTransactions(limit: number = 1000): Promise<void> {\n if (!this.persistenceManager)\n throw new Error(\"The persistence module is not configured.\");\n await this.persistenceManager.syncTransactions(this, limit);\n }\n\n async tokenTransactions(tokenAddress: Address): Promise<any> {\n if (!this.persistenceManager)\n throw new Error(\"The persistence module is not configured.\");\n return {};\n }\n\n async toJSON<D extends number = 1>(depth: D): Promise<JSONAccount<D>> {\n return await toJSON({\n obj: {\n address: this.address,\n isContract: this.isContract.bind(this),\n contractType: this.contractType.bind(this),\n ETHBalance: this.ETHBalance.bind(this),\n transactionCount: this.transactionCount.bind(this),\n },\n depth,\n });\n }\n\n protected async _fetchTransactions({\n fromBlock,\n toBlock,\n limit = 50,\n }: FetchTransactionParams): Promise<Hash[]> {\n const lastBlock = await getBlockNumber(this.client.rpc);\n\n const onBlockRange: onBlockRangeCallback = async (\n { fromBlock, toBlock },\n stop,\n ) => {\n const outgoing = await traceFilter(this.client.rpc, {\n fromBlock: toHex(fromBlock),\n toBlock: toHex(toBlock),\n fromAddress: this.address,\n });\n\n const incoming = await traceFilter(this.client.rpc, {\n fromBlock: toHex(fromBlock),\n toBlock: toHex(toBlock),\n toAddress: this.address,\n });\n\n const traces = outgoing\n .concat(incoming)\n .sort((a, b) => a.blockNumber - b.blockNumber);\n\n return traces.map((t) => t.transactionHash as Hash);\n };\n\n return await fetchByBlockRange({\n toBlock: BigInt(toBlock !== undefined ? toBlock : 0),\n fromBlock: BigInt(fromBlock !== undefined ? fromBlock : lastBlock),\n direction: \"backward\",\n itemLimit: limit,\n onBlockRange,\n });\n }\n}\n","/**\n * @module toJSON\n */\n\n/**\n * Interface for parameters passed to the toJSON function.\n * @template T The type of the object to be converted to JSON.\n */\nexport interface IToJSONParams<T extends { [key: string]: any } = { [key: string]: any }> {\n /** The object to convert. */\n obj: T;\n /** The depth for recursive conversion. Defaults to 0. */\n depth?: number;\n}\n\n/**\n * Checks if an object is a class instance (not a native JavaScript object like Array, Date, etc.).\n * @param {any} obj The object to check.\n * @returns {boolean} True if the object is a class instance, false otherwise.\n */\nfunction isClassInstance(obj: any): boolean {\n if (!obj) return false;\n\n const constructor = obj.constructor;\n const nativeConstructors = [Array, Date, RegExp, Map, Set, Promise, Function, Number, String, Boolean, Error, Object];\n\n if (nativeConstructors.includes(constructor)) {\n return false;\n }\n\n return true\n};\n\n/**\n * Recursively converts BigInt values in an object to strings.\n * @param {any} obj The object to convert.\n * @returns {any} The object with BigInts converted to strings.\n */\nfunction convertBigintsToStrings(obj: any): any {\n if (typeof obj === 'bigint') {\n return obj.toString() + \"n\";\n }\n\n if (typeof obj === 'object') {\n for (const key in obj) {\n obj[key] = convertBigintsToStrings(obj[key]);\n }\n }\n\n if (Array.isArray(obj)) {\n for (let i = 0; i < obj.length; i++) {\n obj[i] = convertBigintsToStrings(obj[i]);\n }\n }\n\n return obj;\n}\n\n/**\n * Converts an object, including its nested class instances and getter methods, into a plain JSON object.\n * BigInt values are converted to strings.\n *\n * @param params - The parameters for conversion.\n * @param params.obj - The object to convert.\n * @param [params.depth=0] - The depth for recursive conversion. Defaults to 0.\n * @returns A promise that resolves to the JSON representation of the object.\n */\nexport async function toJSON({ obj, depth = 0 }: IToJSONParams) {\n const data: any = {};\n const promises: Promise<any>[] = [];\n\n for (const key in obj) {\n // skip class related properties\n if (key === \"toJSON\" || key === \"constructor\" || key === \"client\" || key === \"persistenceManager\") continue;\n\n const prop: any = obj[key];\n\n if (typeof prop === \"function\") {\n // do not fetch getters if depth is 0\n if (depth === 0) continue;\n\n const promise = async () => {\n const value = await obj[key]();\n\n // if the value is a class instance, convert it to JSON recursively\n if (typeof value === \"object\" && isClassInstance(value)) return data[key] = await toJSON({ obj: value, depth: depth - 1 });\n\n data[key] = value;\n };\n\n promises.push(promise());\n };\n\n if (typeof prop === \"object\" && isClassInstance(prop)) {\n // If depth is 0, just flatten the object using recursion\n if (depth === 0) {\n const promise = async () => {\n data[key] = await toJSON({\n obj: prop,\n depth: depth - 1\n });\n };\n promises.push(promise());\n\n continue;\n };\n \n // If depth is not 0, fetch the object\n const promise = async () => {\n data[key] = await prop.toJSON({ depth: depth - 1 });\n };\n promises.push(promise());\n\n continue;\n };\n\n data[key] = prop;\n };\n\n await Promise.all(promises);\n\n return convertBigintsToStrings(data);\n};","import { BaseTransaction } from \"@mentaproject/transactions\";\nimport { GasManager, GasStrategy } from \"../managers/GasManager\";\n\n/**\n * Transaction enhanced with withGas() support.\n */\nexport type WithGas<T extends BaseTransaction> = T & {\n /**\n * Sets gas configuration using a strategy (easy mode).\n * Uses the client's GasManager for estimation.\n *\n * @param strategy - \"slow\", \"medium\", or \"fast\"\n *\n * @example\n * ```ts\n * await tx.withGas(\"fast\").execute();\n * ```\n */\n withGas(strategy: GasStrategy): Promise<T>;\n};\n\n/**\n * Enhances a transaction with withGas() support.\n * This injects the client's GasManager for gas estimation.\n *\n * @param tx - The transaction to enhance\n * @param gasManager - The client's GasManager\n * @returns The enhanced transaction with withGas() method\n *\n * @example\n * ```ts\n * const tx = new Transaction(client.rpc, call);\n * const enhanced = withGasSupport(tx, client.gas);\n * await enhanced.withGas(\"fast\").execute();\n * ```\n */\nexport function withGasSupport<T extends BaseTransaction>(\n tx: T,\n gasManager: GasManager,\n): WithGas<T> {\n const enhanced = tx as WithGas<T>;\n\n enhanced.withGas = async (strategy: GasStrategy): Promise<T> => {\n const config = await gasManager.estimate(strategy);\n tx.withGasConfig(config);\n return tx;\n };\n\n return enhanced;\n}\n","import { AccessList, Address, Hash, Hex, Transaction as RawTransaction, WaitForTransactionReceiptReturnType } from '@mentaproject/core/types';\nimport { getBlock, getTransactionReceipt, traceTransaction, waitForTransactionReceipt } from '@mentaproject/core/actions';\nimport { hexToBigInt } from '@mentaproject/core/utils';\nimport { TransactionReceiptNotFoundError } from 'viem';\n\nimport { Account } from './Account';\nimport { Block } from './Block';\nimport { MentaClient } from './MentaClient';\n\nimport { toJSON } from '../utils/toJSON';\nimport { JSONTransaction, TransactionCall } from '../types';\n\n/**\n * Represents a blockchain transaction with its properties and methods.\n *\n * @description This class encapsulates the data and functionalities related to an Ethereum-like transaction,\n * providing methods to interact with the blockchain to retrieve transaction-related information such as\n * internal calls, receipts, and the block it belongs to.\n */\nexport class TransactionRecord implements Omit<RawTransaction, \"from\" | \"to\"> {\n /**\n * @description The access list for the transaction.\n */\n public accessList?: AccessList;\n /**\n * @description The blob versioned hashes.\n */\n public blobVersionedHashes?: readonly Hex[];\n /**\n * @description The gas limit for the transaction.\n */\n public gas: bigint;\n /**\n * @description The gas price for the transaction.\n */\n public gasPrice?: bigint;\n /**\n * @description The hash of the transaction.\n */\n public hash: Hash;\n /**\n * @description The input data for the transaction.\n */\n public input: Hex;\n /**\n * @description The maximum fee per gas.\n */\n public maxFeePerGas?: bigint;\n /**\n * @description The maximum priority fee per gas.\n */\n public maxPriorityFeePerGas?: bigint;\n /**\n * @description The nonce of the transaction.\n */\n public nonce: number;\n /**\n * @description The r value of the signature.\n */\n public r: Hex;\n /**\n * @description The s value of the signature.\n */\n public s: Hex;\n /**\n * @description The index of the transaction within the block.\n */\n public transactionIndex: number | null;\n /**\n * @description The type of the transaction.\n */\n public type: \"legacy\" | \"eip2930\" | \"eip1559\" | \"eip4844\" | \"eip7702\";\n /**\n * @description The v value of the signature.\n */\n public v: bigint;\n /**\n * @description The value transferred in the transaction.\n */\n public value: bigint;\n /**\n * @description The y parity of the signature.\n */\n public yParity?: number;\n /**\n * @description The hash of the block containing this transaction.\n */\n public blockHash: Hash | null;\n /**\n * @description The number of the block containing this transaction.\n */\n public blockNumber: bigint | null;\n /**\n * @description The hex representation of the type of the transaction.\n */\n public typeHex: `0x${string}` | null;\n\n /**\n * @description The sender account of the transaction.\n */\n public from?: Account;\n /**\n * @description The recipient account of the transaction.\n */\n public to?: Account;\n\n\n /**\n * Creates an instance of Transaction.\n * @description Initializes a new Transaction instance with the provided RPC client and transaction data.\n * @param {MentaClient} client - The instance of MentaClient used to interact with the blockchain.\n * @param {ITransactionData} data The raw transaction data.\n */\n constructor(protected client: MentaClient, data: RawTransaction) {\n this.accessList = data.accessList;\n this.blobVersionedHashes = data.blobVersionedHashes;\n this.gas = data.gas;\n this.gasPrice = data.gasPrice;\n this.hash = data.hash;\n this.input = data.input;\n this.maxFeePerGas = data.maxFeePerGas;\n this.maxPriorityFeePerGas = data.maxPriorityFeePerGas;\n this.nonce = data.nonce;\n this.r = data.r;\n this.s = data.s;\n this.transactionIndex = data.transactionIndex;\n this.type = data.type;\n this.v = data.v;\n this.value = data.value;\n this.yParity = data.yParity;\n this.blockHash = data.blockHash;\n this.blockNumber = data.blockNumber;\n this.typeHex = data.typeHex;\n\n this.from = data.from ? this.client.accounts.get(data.from) : undefined;\n this.to = data.to ? this.client.accounts.get(data.to) : undefined;\n };\n\n /**\n * Retrieves the internal calls made by this transaction.\n * @description Fetches and processes the transaction traces to extract internal call details.\n * @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.\n */\n public async calls(): Promise<TransactionCall[] | undefined> {\n const traces = await traceTransaction(this.client.rpc, this.hash);\n if (!traces) return undefined;\n\n const calls = traces.filter(t => t.type === \"call\" && t.action !== undefined);\n\n return calls.map(c => ({\n from: new Account(this.client, { address: c.action!.from as Address }),\n to: new Account(this.client, { address: c.action!.to as Address }),\n value: hexToBigInt(c.action!.value as Hex),\n input: c.action!.input as Hex,\n gas: hexToBigInt(c.action!.gas as Hex),\n callType: c.action!.callType,\n })) as TransactionCall[];\n }\n\n /**\n * Waits for the transaction receipt to be available.\n * @description Asynchronously waits for the transaction to be confirmed on the blockchain and its receipt to be available.\n * @param {number} [confirmations] The number of confirmations to wait for. Defaults to 1.\n * @returns {Promise<WaitForTransactionReceiptReturnType>} A promise that resolves to the transaction receipt once the specified number of confirmations are met.\n */\n async waitForReceipt(confirmations?: number): Promise<WaitForTransactionReceiptReturnType> {\n return await waitForTransactionReceipt(this.client.rpc, {\n hash: this.hash,\n confirmations: confirmations || 1,\n });\n };\n\n /**\n * Retrieves the transaction receipt.\n * @description Fetches the transaction receipt for the current transaction hash.\n * @returns {Promise<WaitForTransactionReceiptReturnType>} A promise that resolves to the transaction receipt.\n */\n async receipt(): Promise<WaitForTransactionReceiptReturnType | undefined> {\n try {\n return await getTransactionReceipt(this.client.rpc, { hash: this.hash });\n } catch (error) {\n if (error instanceof TransactionReceiptNotFoundError) {\n return undefined;\n }\n }\n };\n\n /**\n * Retrieves the block containing this transaction.\n * @description Fetches the block data using the transaction's block hash and returns a Block instance.\n * @returns {Promise<Block>} A promise that resolves to a Block instance representing the block that includes this transaction.\n */\n async block(): Promise<Block> {\n const data = await getBlock(this.client.rpc, { blockHash: this.blockHash! });\n return new Block(this.client, data);\n };\n\n /**\n * Converts the Transaction instance to a JSON representation.\n * @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.\n * @param {number} [depth=1] The depth of the conversion. Controls how deeply nested objects are serialized.\n * @returns {Promise<object>} A promise that resolves to the JSON representation of the transaction.\n */\n async toJSON<D extends number = 1>(depth: D): Promise<JSONTransaction<D>> {\n return await toJSON({\n obj: {\n ...this,\n block: this.block,\n receipt: this.receipt,\n calls: async () => {\n const calls = await this.calls();\n if (!calls) return undefined;\n\n return Promise.all(calls.map(async c => await toJSON({ obj: c, depth: depth })));\n }\n },\n depth\n });\n }\n};","import { Block as RawBlock, Hash, Hex, Withdrawal } from \"@mentaproject/core\";\n\nimport { Account } from \"./Account\";\nimport { TransactionRecord } from \"./TransactionRecord\";\nimport { JSONBlock } from \"../types/Block\";\nimport { toJSON } from \"../utils/toJSON\";\nimport { MentaClient } from \"./MentaClient\";\n\n/**\n * @description Represents a blockchain block with its properties and methods.\n * This class provides a structured way to access block-related data and interact with the blockchain client.\n */\nexport class Block implements Omit<RawBlock, \"miner\" | \"transactions\"> {\n /**\n * @description The base fee per gas for the block.\n */\n baseFeePerGas: bigint | null\n /**\n * @description The gas used for blobs in the block.\n */\n blobGasUsed: bigint\n /**\n * @description The block's difficulty.\n */\n difficulty: bigint\n /**\n * @description The excess blob gas in the block.\n */\n excessBlobGas: bigint\n /**\n * @description Extra data included in the block.\n */\n extraData: Hex\n /**\n * @description The gas limit for the block.\n */\n gasLimit: bigint\n /**\n * @description The gas used in the block.\n */\n gasUsed: bigint\n /**\n * @description The hash of the block.\n */\n hash: Hash | null\n /**\n * @description The logs bloom filter for the block.\n */\n logsBloom: Hex | null\n /**\n * @description The mix hash of the block.\n */\n mixHash: Hash\n /**\n * @description The nonce of the block.\n */\n nonce: Hex | null\n /**\n * @description The block number.\n */\n number: bigint | null\n /**\n * @description The parent beacon block root.\n */\n parentBeaconBlockRoot?: Hex\n /**\n * @description The hash of the parent block.\n */\n parentHash: Hash\n /**\n * @description The root of the receipts trie.\n */\n receiptsRoot: Hex\n /**\n * @description The seal fields of the block.\n */\n sealFields: Hex[]\n /**\n * @description The SHA3 uncles hash.\n */\n sha3Uncles: Hash\n /**\n * @description The size of the block in bytes.\n */\n size: bigint\n /**\n * @description The state root of the block.\n */\n stateRoot: Hash\n /**\n * @description The timestamp of the block.\n */\n timestamp: bigint\n /**\n * @description The total difficulty of the chain up to this block.\n */\n totalDifficulty: bigint | null\n /**\n * @description The root of the transactions trie.\n */\n transactionsRoot: Hash\n /**\n * @description The list of uncle hashes.\n */\n uncles: Hash[]\n /**\n * @description The list of withdrawals.\n */\n withdrawals?: Withdrawal[]\n /**\n * @description The root of the withdrawals trie.\n */\n withdrawalsRoot?: Hex\n\n /**\n * @description The miner of the block, represented as an Account instance.\n */\n miner: Account\n /**\n * @description The transactions included in the block, represented as an array of Transaction instances.\n */\n transactions?: TransactionRecord[] | Hash[]\n\n /**\n * @description Creates an instance of Block.\n * @param client - The instance of MentaClient used to interact with the blockchain.\n * @param data The raw block data conforming to IBlockData.\n * @param includeTransactions Whether to include full transaction objects. Defaults to false.\n */\n constructor(public client: MentaClient, data: RawBlock) {\n this.baseFeePerGas = data.baseFeePerGas;\n this.blobGasUsed = data.blobGasUsed;\n this.difficulty = data.difficulty;\n this.excessBlobGas = data.excessBlobGas;\n this.extraData = data.extraData;\n this.gasLimit = data.gasLimit;\n this.gasUsed = data.gasUsed;\n this.hash = data.hash;\n this.logsBloom = data.logsBloom;\n this.mixHash = data.mixHash;\n this.nonce = data.nonce;\n this.number = data.number;\n this.parentBeaconBlockRoot = data.parentBeaconBlockRoot;\n this.parentHash = data.parentHash;\n this.receiptsRoot = data.receiptsRoot;\n this.sealFields = data.sealFields;\n this.sha3Uncles = data.sha3Uncles;\n this.size = data.size;\n this.stateRoot = data.stateRoot;\n this.timestamp = data.timestamp;\n this.totalDifficulty = data.totalDifficulty;\n this.transactionsRoot = data.transactionsRoot;\n this.uncles = data.uncles;\n this.withdrawals = data.withdrawals;\n this.withdrawalsRoot = data.withdrawalsRoot;\n\n this.miner = new Account(this.client, { address: data.miner});\n \n if (!data.transactions || data.transactions.length === 0) {\n const parsed = data.transactions.map((data) => typeof data === \"string\" ? data : new TransactionRecord(this.client, data))\n this.transactions = parsed as TransactionRecord[] | Hash[];\n }\n };\n\n protected includeTransactions(): this is this & { transactions: TransactionRecord[] } {\n if (!this.transactions || this.transactions.length === 0) return false;\n return true\n }\n\n /**\n * @description Converts the Block instance to a JSON representation.\n * This method serializes the block's properties into a plain JavaScript object,\n * suitable for JSON serialization.\n * @param depth The depth of the conversion. Defaults to 1.\n * @returns A promise that resolves to the JSON representation of the block.\n */\n async toJSON<D extends number = 1>(depth: D): Promise<JSONBlock<D>> {\n return await toJSON({\n obj: {\n ...this,\n },\n depth\n });\n }\n};","/**\n * @module MentaClient\n */\nimport type { MentaAccountClient } from \"@mentaproject/core/types\";\nimport { createMentaAccount } from \"@mentaproject/core/clients\";\nimport { createClient } from \"@mentaproject/core\";\n\nimport { BlockManager } from \"../managers/BlockManager\";\nimport { TransactionManager } from \"../managers/TransactionManager\";\nimport { ContractManager } from \"../managers/ContractManager\";\nimport { AccountManager } from \"../managers/AccountManager\";\nimport { PersistenceManager } from \"../managers/PersistenceManager\";\nimport { GasManager, GasStrategy } from \"../managers/GasManager\";\nimport {\n ClientEvents,\n GetListenerCallback,\n MentaClientConfig,\n} from \"../types/MentaClient\";\nimport { withCache } from \"../utils/withCache\";\nimport { Account } from \"./Account\";\n\n/**\n * The main client for interacting with the Menta API.\n * It provides managers for blocks, transactions, contracts, accounts, and gas.\n *\n * @example\n * ```ts\n * const client = new MentaClient({\n * url: 'http://rpcurlhere.com',\n * gas: { strategy: 'fast' }, // Default gas strategy\n * });\n *\n * await client.init();\n *\n * // Use gas manager\n * const prices = await client.gas.getPrices();\n * const fastConfig = await client.gas.estimate('fast');\n * ```\n */\nexport class MentaClient {\n protected _rpc?: MentaAccountClient;\n protected _account?: Account;\n protected _gas?: GasManager;\n\n /**\n * The underlying RPC client used for blockchain interactions.\n */\n public get rpc(): MentaAccountClient {\n if (!this._rpc) {\n throw new Error(\"RPC client not initialized\");\n }\n return this._rpc;\n }\n\n /**\n * The account associated with the client.\n */\n public get account(): Account {\n if (!this._account) {\n throw new Error(\"Account not initialized\");\n }\n return this._account;\n }\n\n /**\n * Manager for gas estimation and configuration.\n */\n public get gas(): GasManager {\n if (!this._gas) {\n throw new Error(\"Gas manager not initialized\");\n }\n return this._gas;\n }\n\n /**\n * Default gas strategy for transactions.\n */\n public defaultGasStrategy?: GasStrategy;\n\n /**\n * Manager for block-related operations.\n */\n public blocks!: BlockManager;\n /**\n * Manager for transaction-related operations.\n */\n public transactions!: TransactionManager;\n /**\n * Manager for contract-related operations.\n */\n public contracts!: ContractManager;\n /**\n * Manager for account-related operations.\n */\n public accounts!: AccountManager;\n /**\n * Optional manager for persistence-related operations.\n */\n public persistenceManager?: PersistenceManager;\n\n /**\n * Subscribes to a specific client event.\n */\n on<TEvent extends keyof typeof ClientEvents>(\n event: TEvent,\n callback: GetListenerCallback<TEvent>,\n ) {\n const eventFunction = ClientEvents[event];\n const capitalizedEvent = event.charAt(0).toUpperCase() + event.slice(1);\n const params = {\n [`on${capitalizedEvent}`]: callback,\n pollingInterval: 1000,\n };\n\n return (eventFunction as any)(this.rpc, params);\n }\n\n /**\n * Creates an instance of MentaClient.\n */\n constructor(protected params: MentaClientConfig) {\n this.blocks = new BlockManager(this);\n this.transactions = new TransactionManager(this);\n this.contracts = new ContractManager(this);\n\n if (params.gas?.strategy) {\n this.defaultGasStrategy = params.gas.strategy;\n }\n\n if (params.persistenceAdapter) {\n this.persistenceManager = new PersistenceManager(\n this,\n params.persistenceAdapter,\n );\n this.accounts = new AccountManager(this, this.persistenceManager);\n } else {\n this.accounts = new AccountManager(this);\n }\n }\n\n async init() {\n let coreClient = createClient(this.params);\n\n if (this.params.cache) {\n coreClient = withCache(coreClient, this.params.cache);\n }\n\n this._rpc = await createMentaAccount(coreClient as any, {\n bundlerTransport: this.params.bundlerTransport,\n publicTransport: this.params.transport,\n signer: this.params.signer,\n validatorAddress: this.params.validatorAddress,\n });\n\n this._account = this.accounts.get(this.rpc.account.address);\n this._gas = new GasManager(this.rpc);\n }\n}\n","/**\n * @module BlockManager\n */\nimport { BlockTag, GetBlockParameters } from \"@mentaproject/core/types\";\nimport { Block } from \"../structures/Block\";\nimport { getBlock } from \"@mentaproject/core/actions\";\nimport { MentaClient } from \"../structures\";\n\n/**\n * Manages blockchain block-related operations, providing methods to interact with and retrieve block data.\n */\nexport class BlockManager {\n /**\n * Creates an instance of BlockManager.\n * @param client - The instance of MentaClient used to interact with the blockchain.\n */\n constructor(public client: MentaClient) {};\n\n /**\n * Retrieves a block from the blockchain based on the provided parameters.\n * This method uses the underlying RPC client to fetch block data and then\n * encapsulates it within a {@link Block} instance.\n * @param params The parameters for retrieving the block, including block hash, block number, or block tag.\n * @returns A promise that resolves to a {@link Block} instance representing the retrieved block.\n * @example\n * import { http } from '@mentaproject/core';\n * import { mainnet } from '@mentaproject/core/chains';\n * import { MentaClient } from '@mentaproject/client';\n *\n * // Initialize the MentaClient\n * const mentaClient = new MentaClient({ chain: mainnet, transport: http(\"http://rpcurlhere.com\") });\n *\n * async function fetchBlock() {\n * // Retrieve the latest block\n * const latestBlock = await mentaClient.blocks.get({ blockTag: 'latest' });\n * console.log('Latest block number:', latestBlock.number);\n *\n * // Retrieve a specific block by its number\n * if (latestBlock.number) {\n * const specificBlock = await mentaClient.blocks.get({ blockNumber: latestBlock.number - 10n });\n * console.log('Specific block hash:', specificBlock.hash);\n * }\n * }\n *\n * fetchBlock();\n */\n async get(params: GetBlockParameters<boolean, BlockTag>): Promise<Block> {\n const data = await getBlock(this.client.rpc, params);\n return new Block(this.client, data);\n };\n}","/**\n * @module TransactionManager\n */\nimport { GetTransactionParameters, Transaction as RawTransaction, SendTransactionParameters } from \"@mentaproject/core/types\";\nimport { TransactionRecord } from \"../structures/TransactionRecord\";\nimport { MulticallTransaction } from \"@mentaproject/transactions\";\nimport { getTransaction, sendTransaction } from \"@mentaproject/core/actions\";\nimport { MentaClient } from \"../structures\";\nimport { JSONTransaction } from \"../types\";\nimport { parseBingints } from \"../utils/bigint\";\nimport { withGasSupport, WithGas } from \"../utils/withGasSupport\";\n\n/**\n * Manages blockchain transaction-related operations.\n *\n * @example\n * ```ts\n * // Create a multicall transaction with gas support\n * const pending = await client.transactions.create()\n * .addCall(account.sendEth(parseEther(\"1\")))\n * .addCall(erc20.transfer(to, amount))\n * .withGas(\"fast\")\n * .execute();\n *\n * const receipt = await pending.confirm();\n *\n * // Get a transaction by hash\n * const tx = await client.transactions.fromHash(hash);\n * console.log(tx.receipt, tx.block);\n * ```\n */\nexport class TransactionManager {\n constructor(public client: MentaClient) {}\n\n /**\n * Creates a new MulticallTransaction for batching multiple calls.\n * Enhanced with withGas() support for easy gas configuration.\n *\n * @returns A MulticallTransaction builder with withGas() support\n *\n * @example\n * ```ts\n * const pending = await client.transactions.create()\n * .addCall(account.sendEth(parseEther(\"1\")))\n * .withGas(\"fast\")\n * .execute();\n * ```\n */\n create(): WithGas<MulticallTransaction> {\n const tx = new MulticallTransaction(this.client.rpc);\n return withGasSupport(tx, this.client.gas);\n }\n\n /**\n * Retrieves a transaction record by its hash.\n *\n * @param hash - The transaction hash\n * @returns A TransactionRecord with receipt, block, etc.\n *\n * @example\n * ```ts\n * const tx = await client.transactions.fromHash(hash);\n * console.log(tx.from, tx.to, tx.value);\n * ```\n */\n async fromHash(hash: `0x${string}`): Promise<TransactionRecord> {\n return this.get({ hash });\n }\n\n /**\n * Retrieves a transaction by its hash or block number and index.\n */\n async get(params: GetTransactionParameters): Promise<TransactionRecord> {\n const data = await getTransaction(this.client.rpc, params);\n return new TransactionRecord(this.client, data);\n }\n\n /**\n * Parse a transaction object from a JSON converted transaction data object.\n */\n parse<J extends JSONTransaction<0>>(data: J): TransactionRecord {\n const parsed = parseBingints(data);\n\n const rawData = {\n ...parsed,\n from: parsed.from.address,\n to: parsed.to ? parsed.to.address : null,\n };\n\n return new TransactionRecord(this.client, rawData as RawTransaction);\n }\n\n /**\n * Sends a transaction to the blockchain network.\n * @deprecated Use client.transactions.create() for new transactions\n */\n async send(params: SendTransactionParameters): Promise<TransactionRecord> {\n const hash = await sendTransaction(this.client.rpc, params);\n return await this.get({ hash });\n }\n}\n","import { WithoutBigintStringified } from \"../types/Utils\";\n\nexport const bigIntMax = (...args: bigint[]) => args.reduce((m, e) => e > m ? e : m);\nexport const bigIntMin = (...args: bigint[]) => args.reduce((m, e) => e < m ? e : m);\n\nexport function bigIntReviver(key: string, value: any) {\n if (typeof value === 'string') {\n if (value.endsWith('n')) {\n try {\n return BigInt(value.slice(0, -1));\n } catch (e) {\n return value;\n }\n };\n };\n\n return value;\n};\n\nexport function stringifyBingints(obj: any) {\n if (typeof obj === 'bigint') {\n return obj.toString() + \"n\";\n }\n\n if (typeof obj === 'object') {\n for (const key in obj) {\n obj[key] = stringifyBingints(obj[key]);\n }\n }\n\n if (Array.isArray(obj)) {\n for (let i = 0; i < obj.length; i++) {\n obj[i] = stringifyBingints(obj[i]);\n }\n }\n\n return obj;\n};\n\nexport function parseBingints<T extends { [key: string]: any }>(obj: T): WithoutBigintStringified<T> {\n if (typeof obj !== 'object' || obj === null) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item, index) => bigIntReviver(index.toString(), parseBingints(item))) as WithoutBigintStringified<T>;\n }\n\n const newObj: { [key: string]: any } = {};\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n const value = obj[key];\n const processedValue = parseBingints(value);\n newObj[key] = bigIntReviver(key, processedValue);\n }\n };\n\n return newObj as WithoutBigintStringified<T>;\n};","/**\n * @module ContractManager\n */\nimport type { AbiItem } from \"@mentaproject/core/types\";\nimport { getContract, GetContractParameters } from \"@mentaproject/contracts\";\nimport { MentaClient } from \"../structures\";\n\n/**\n * Manages smart contract-related operations within the Menta client.\n * This class provides methods to interact with smart contracts deployed on the blockchain,\n * facilitating the retrieval of contract instances for various operations.\n */\nexport class ContractManager {\n /**\n * Creates an instance of ContractManager.\n * @description Initializes the ContractManager with a CoreClient instance, which is used for RPC communication.\n * @param client - The instance of MentaClient used to interact with the blockchain.\n */\n constructor(protected client: MentaClient) {};\n\n /**\n * Retrieves a contract instance to interact with it.\n * @description This method fetches a contract instance based on the provided parameters, allowing for interaction with its methods and events.\n * @template P The type of the contract retrieval parameters, extending `GetContractParameters` with `AbiItem` array.\n * @param {P} params The parameters for retrieving the contract, including its Application Binary Interface (ABI) and address.\n * @returns {ReturnType<typeof getContract<ReadonlyArray<AbiItem>, P>>} A contract instance that can be used to call contract methods or listen to events.\n * @example\n * import { MentaClient } from '@mentaproject/client';\n * import { http } from '@mentaproject/core';\n *\n * // Initialize the MentaClient with a transport\n * const client = new MentaClient({\n * transport: http('http://rpcurlhere.com'),\n * });\n *\n * // Define the ABI and address for the smart contract\n * const abi = [\n * {\n * \"type\": \"function\",\n * \"name\": \"greet\",\n * \"stateMutability\": \"view\",\n * \"inputs\": [],\n * \"outputs\": [{ \"name\": \"\", \"type\": \"string\" }]\n * }\n * ] as const;\n * const contractAddress = '0x...'; // Replace with your contract address\n *\n * // Retrieve the contract instance\n * const contract = client.contracts.get({\n * abi,\n * address: contractAddress,\n * });\n *\n * // Example of interacting with the contract\n * const greeting = await contract.greet();\n */\n get<P extends GetContractParameters<ReadonlyArray<AbiItem>>>(params: P) {\n return getContract(this.client.rpc, params);\n };\n};","/**\n * @module AccountManager\n */\nimport { Address } from \"@mentaproject/core/types\";\nimport { Account } from \"../structures/Account\";\nimport { PersistenceManager } from \"./PersistenceManager\";\nimport { MentaClient } from \"../structures\";\n\n/**\n * Manages blockchain account operations.\n * This class provides methods to interact with accounts,\n * including retrieving and managing them via an RPC client and a persistence manager.\n *\n * @class AccountManager\n */\nexport class AccountManager {\n /**\n * Creates an instance of AccountManager.\n *\n * @param {MentaClient} client - The instance of MentaClient used to interact with the blockchain.\n * @param {persistenceManager} persistenceManager - The optional persistence manager to store and retrieve account data.\n */\n constructor(public client: MentaClient, private persistenceManager?: PersistenceManager) { };\n\n /**\n * Retrieves an account instance by its blockchain address.\n * @param address - The blockchain address of the account to retrieve.\n * @returns An instance of the `Account` class.\n * @example\n * ```typescript\n * import { MentaClient } from '@mentaproject/client';\n * import { http } from '@mentaproject/core';\n *\n * // Initialize the MentaClient\n * const client = new MentaClient({\n * transport: http('http://rpcurlhere.com'),\n * });\n *\n * // The address of the account to retrieve\n * const accountAddress = '0x1234567890123456789012345678901234567890';\n *\n * // Retrieve the account instance using the account manager from the client\n * const account = client.accounts.get(accountAddress);\n *\n * console.log(account.address); // 0x1234567890123456789012345678901234567890\n * ```\n */\n get(address: Address): Account {\n return new Account(this.client, { address: address }, this.persistenceManager);\n };\n}","import { getBlockNumber } from '@mentaproject/core/actions';\nimport { Address } from '@mentaproject/core/types';\n\nimport { Account } from '../structures/Account';\nimport { MentaClient, TransactionRecord } from '../structures';\nimport { bigIntMax } from '../utils/bigint';\nimport { GetTransactionsParams, IPersistenceAdapter, JSONTransaction } from 'src/types';\n\n/**\n * Manages the persistence of data, including transactions, using a specified persistence adapter.\n * It handles fetching data from both local storage and remote sources, and synchronizing them.\n */\nexport class PersistenceManager {\n /**\n * Creates an instance of PersistenceManager.\n * @param client - The instance of MentaClient used to interact with the blockchain.\n * @param persistenceAdapter - The adapter responsible for actual data persistence operations.\n */\n constructor(\n private client: MentaClient,\n private persistenceAdapter: IPersistenceAdapter\n ) {}\n\n /**\n * Retrieves transactions for a given account, applying a \"stale-while-revalidate\" strategy.\n * @param params - Parameters for retrieving transactions.\n * @returns A promise that resolves to an array of transactions with associated account information.\n */\n public async getTransactions(address: Address, params: GetTransactionsParams): Promise<JSONTransaction<0>[]> {\n return await this.persistenceAdapter.getTransactions(address, params);\n }\n\n /**\n * Synchronizes an account's transactions from the remote source to the local persistence.\n * It fetches new transactions starting from the last synced block and updates the local storage.\n * @param account - The account whose transactions are to be synchronized.\n * @param limit - The maximum number of transactions to fetch.\n * @returns A promise that resolves when the synchronization is complete.\n */\n public async syncTransactions(account: Account, limit: number = 100_000): Promise<void> {\n const lastSyncedBlock = await this.persistenceAdapter.getLastSyncedBlock(account.address);\n const lastBlock = lastSyncedBlock ?? 0n;\n\n const fromBlock = lastSyncedBlock ? lastSyncedBlock + 1n : (await getBlockNumber(this.client.rpc));\n\n const newTransactions = await account.transactions({\n fromBlock: fromBlock,\n toBlock: lastBlock,\n limit: limit\n }, true)\n\n if (newTransactions.length > 0) {\n await this.persistenceAdapter.upsertTransactions(newTransactions);\n \n const latestBlock = bigIntMax(...newTransactions.map(t => t.blockNumber || 0n));\n await this.persistenceAdapter.setLastSyncedBlock(account.address, latestBlock);\n }\n }\n}","import { MentaAccountClient } from \"@mentaproject/core/types\";\nimport { GasTracker, GasEstimate, GasEstimates } from \"@mentaproject/transactions\";\n\nexport type GasStrategy = \"slow\" | \"medium\" | \"fast\";\n\n/**\n * Manages gas estimation and configuration.\n *\n * @example\n * ```ts\n * // Get all prices\n * const prices = await client.gas.getPrices();\n * console.log(prices.fast.maxFeePerGas);\n *\n * // Get specific estimate\n * const fast = await client.gas.estimate(\"fast\");\n * tx.withGasConfig(fast);\n * ```\n */\nexport class GasManager {\n private tracker: GasTracker;\n\n constructor(private client: MentaAccountClient) {\n this.tracker = new GasTracker(client);\n }\n\n /**\n * Gets all gas price estimates (slow, medium, fast).\n */\n async getPrices(): Promise<GasEstimates> {\n return this.tracker.getEstimates();\n }\n\n /**\n * Gets a specific gas estimate by strategy.\n *\n * @param strategy - \"slow\", \"medium\", or \"fast\"\n */\n async estimate(strategy: GasStrategy): Promise<GasEstimate> {\n const prices = await this.getPrices();\n return prices[strategy];\n }\n\n /**\n * Gets the underlying GasTracker for advanced usage.\n */\n getTracker(): GasTracker {\n return this.tracker;\n }\n}\n","/**\n * @module MentaClientTypes\n */\nimport { Address, CoreClientConfig, Transport } from \"@mentaproject/core/types\";\nimport { ICache } from \"./Cache\";\nimport { watchBlockNumber, watchBlocks } from \"@mentaproject/core/actions\";\nimport { IPersistenceAdapter } from \"./PersistenceAdapter\";\nimport { WebAuthnAccount } from \"@mentaproject/core/account-abstraction\";\nimport { GasStrategy } from \"../managers/GasManager\";\n\n/**\n * Configuration for the client's cache.\n * @interface CacheConfig\n */\nexport interface CacheConfig {\n /**\n * Time-to-live policies for different RPC methods.\n * Keys are RPC method names (e.g., \"eth_getBlockByNumber\"), and values are\n * the TTL in milliseconds for caching responses from those methods.\n */\n ttl_policies: Record<string, number>;\n}\n\n/**\n * Gas configuration for the client.\n */\nexport interface GasConfig {\n /**\n * Default gas strategy for all transactions.\n * Can be overridden per transaction with withGas() or withGasConfig().\n */\n strategy: GasStrategy;\n}\n\n/**\n * Configuration options for the MentaClient.\n * Extends {@link CoreClientConfig} from `@mentaproject/core`.\n * @interface MentaClientConfig\n */\nexport interface MentaClientConfig extends CoreClientConfig {\n /**\n * Optional cache implementation for the client.\n * If provided, the client will use this cache for RPC responses.\n */\n cache?: ICache;\n /**\n * Optional persistence adapter for local data storage.\n * If provided, the client will use this adapter to persist and retrieve data.\n */\n persistenceAdapter?: IPersistenceAdapter;\n /**\n * Bundler transport used for userOperations\n */\n bundlerTransport: Transport;\n /**\n * Passkey compatible signer used for signing user operations\n */\n signer: WebAuthnAccount;\n /**\n * Validator address used for userOperations\n */\n validatorAddress: Address;\n /**\n * Optional gas configuration.\n * If provided, sets the default gas strategy for all transactions.\n */\n gas?: GasConfig;\n}\n\n/**\n * Defines the available client events and their corresponding watch functions.\n * These functions are used to subscribe to real-time updates from the client.\n */\nexport const ClientEvents = {\n /**\n * Event for new blocks.\n * Uses the {@link watchBlocks} function from `@mentaproject/core`.\n */\n block: watchBlocks,\n /**\n * Event for new block numbers.\n * Uses the {@link watchBlockNumber} function from `@mentaproject/core`.\n */\n blockNumber: watchBlockNumber,\n};\n\n/**\n * Utility type to extract the callback function type for a given event.\n * This type dynamically determines the expected callback signature for a specific client event.\n * @template TEvent The name of the event (e.g., 'block' or 'blockNumber') for which to get the listener callback type.\n */\nexport type GetListenerCallback<TEvent extends keyof typeof ClientEvents> =\n Parameters<(typeof ClientEvents)[TEvent]>[1] extends infer P\n ? P extends { [K in `on${Capitalize<TEvent>}`]: infer TCallback }\n ? TCallback\n : never\n : never;\n","/**\n * @module withCache\n */\nimport { watchBlockNumber } from \"@mentaproject/core/actions\";\nimport type { CoreClient } from \"@mentaproject/core/types\";\nimport { ICache } from \"../types/Cache\";\nimport { Methods } from \"../types/JsonRPC\";\n\n// EntryPoint.getNonce selector - must never be cached to avoid nonce reuse\nconst GET_NONCE_SELECTOR = \"0x35567e1a\";\n\n/**\n * Checks if an eth_call is a getNonce call to the EntryPoint.\n * These calls must not be cached to ensure fresh nonce values for each UserOperation.\n */\nfunction isNonceCall(method: Methods, params: any): boolean {\n if (method !== \"eth_call\") return false;\n const callData = params?.[0]?.data;\n return typeof callData === \"string\" && callData.startsWith(GET_NONCE_SELECTOR);\n}\n\n/**\n * A higher-order function that enhances a class method with caching capabilities.\n * It intercepts RPC requests made through the client and caches their responses\n * based on the provided cache implementation.\n *\n * @param client The CoreClient instance to enhance with caching.\n * @param cache The cache implementation (ICache) to use for storing and retrieving responses.\n * @returns The enhanced CoreClient instance with caching enabled.\n */\nexport function withCache<T extends CoreClient>(client: T, cache: ICache): T {\n watchBlockNumber(client, {\n onBlockNumber: (blockNumber) => {\n cache.setBlockNumber(blockNumber);\n },\n pollingInterval: 1000,\n });\n // 2. We keep a reference to the original request method\n const originalRequest = client.request;\n\n // 3. We replace the client's `request` method\n client.request = (async (args: { method: Methods, params: any }) => {\n const { method, params } = args;\n\n // Never cache nonce calls - they must always return fresh values\n const shouldSkipCache = method === \"eth_blockNumber\" || isNonceCall(method, params);\n\n const cacheKey = `${client.chain!.id}:${method}:${JSON.stringify(params || [], (_, v) => typeof v === 'bigint' ? v.toString() : v)}`;\n\n let result;\n if (!shouldSkipCache) {\n result = cache.get(cacheKey);\n }\n\n if (!result) {\n result = await originalRequest(args as any);\n };\n\n if (result !== null && result !== undefined && !shouldSkipCache) {\n const ttl = cache.config.ttlPolicies[method] || cache.config.defaultTtl;\n await cache.set(cacheKey, result, ttl);\n }\n\n return result;\n }) as any;\n\n return client;\n}\n","/**\n * @module MemoryCache\n */\nimport { ICache, ICacheEntry, ICacheConfig } from '../types/Cache';\n\n/**\n/**\n * @class MemoryCache\n * @description A simple in-memory cache implementation that adheres to the ICache interface.\n * It stores key-value pairs with an associated time-to-live (TTL) based on block numbers.\n * The cache automatically evicts the oldest entries when its maximum size is reached.\n */\nexport class MemoryCache implements ICache {\n /**\n * @property {Map<string, ICacheEntry<any>>} cache - The internal Map used to store cache entries.\n * @private\n */\n private cache = new Map<string, ICacheEntry<any>>();\n /**\n * @property {ICacheConfig} config - The configuration object for the cache, including maxSize, defaultTtl, and ttlPolicies.\n */\n public config: ICacheConfig;\n /**\n * @property {bigint} blockNumber - The current block number used for TTL calculations.\n * @private\n */\n private blockNumber: bigint;\n\n /**\n * @constructor\n * @description Creates an instance of MemoryCache.\n * @param {bigint} blockNumber - The current block number to use for TTL calculations.\n * @param {Partial<ICacheConfig>} [options] - Optional configuration for the cache.\n * @param {number} [options.maxSize=500] - The maximum number of entries the cache can hold.\n * @param {number} [options.defaultTtl=1] - The default time-to-live in blocks for cache entries if not specified.\n * @param {Object.<string, number>} [options.ttlPolicies={}] - A map of specific TTL policies for different keys.\n */\n constructor(blockNumber: bigint, options?: Partial<ICacheConfig>) {\n this.blockNumber = blockNumber;\n this.config = {\n maxSize: 500,\n defaultTtl: 1,\n ttlPolicies: options?.ttlPolicies || {},\n ...options,\n };\n };\n\n /**\n * @method isExpired\n * @description Checks if a cache entry has expired based on the current block number and the entry's expiry block.\n * @param {bigint} expiry - The expiry block number of the cache entry.\n * @returns {boolean} `true` if the entry has expired, `false` otherwise.\n * @protected\n */\n protected isExpired(expiry: bigint): boolean {\n return this.blockNumber > expiry;\n };\n\n /**\n * @method setBlockNumber\n * @description Sets the current block number for TTL calculations. This is crucial for managing cache entry expiry.\n * @param {bigint} blockNumber - The new current block number.\n * @returns {void}\n */\n setBlockNumber(blockNumber: bigint): void {\n this.blockNumber = blockNumber;\n }\n\n /**\n * @method set\n * @description Sets a value in the cache. If the key already exists, its entry will be updated.\n * If the cache reaches its maximum size, the oldest entry will be evicted before adding the new one.\n * @template T - The type of the value being stored.\n * @param {string} key - The unique key for the cache entry.\n * @param {T} value - The value to store in the cache.\n * @param {number} [ttl=this.config.defaultTtl] - The time-to-live (in blocks) for this specific entry. Defaults to the cache's `defaultTtl`.\n * @returns {void}\n */\n set<T>(key: string, value: T, ttl: number = this.config.defaultTtl): void {\n if (this.cache.has(key)) {\n this.cache.delete(key);\n }\n\n if (this.cache.size >= this.config.maxSize) this.evict();\n \n const expiry = this.blockNumber + BigInt(ttl);\n this.cache.set(key, { value, expiry });\n }\n\n /**\n * @method get\n * @description Retrieves a value from the cache. If the entry is found and has not expired,\n * it is moved to the end of the cache (making it the most recently used) to prevent premature eviction.\n * @template T - The expected type of the value.\n * @param {string} key - The key of the cache entry to retrieve.\n * @returns {T | undefined} The cached value if found and not expired, otherwise `undefined`.\n */\n get<T>(key: string): T | undefined {\n const entry = this.cache.get(key);\n if (!entry) return undefined;\n\n if (this.isExpired(entry.expiry)) {\n this.cache.delete(key);\n return undefined;\n }\n\n this.cache.delete(key);\n this.cache.set(key, entry);\n\n return entry.value as T;\n }\n\n /**\n * @method evict\n * @description Evicts the oldest entry from the cache. This method is called internally when the cache\n * reaches its `maxSize` to make room for new entries.\n * @returns {void}\n * @private\n */\n private evict(): void {\n const oldestKey = this.cache.keys().next().value;\n if (!oldestKey) return;\n\n this.cache.delete(oldestKey);\n }\n}"],"mappings":";;;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAOP,SAAS,mBAAmB;AAC5B,SAAS,aAAa;AAOtB,SAAS,uBAAuB;;;ACF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