viem 2.55.11 → 2.55.15

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.
Files changed (105) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/_cjs/actions/index.js +4 -2
  3. package/_cjs/actions/index.js.map +1 -1
  4. package/_cjs/actions/public/watchBlockHeaders.js +61 -0
  5. package/_cjs/actions/public/watchBlockHeaders.js.map +1 -0
  6. package/_cjs/actions/wallet/prepareTransactionRequest.js +12 -12
  7. package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
  8. package/_cjs/actions/wallet/sendTransaction.js +24 -12
  9. package/_cjs/actions/wallet/sendTransaction.js.map +1 -1
  10. package/_cjs/actions/wallet/sendTransactionSync.js +24 -12
  11. package/_cjs/actions/wallet/sendTransactionSync.js.map +1 -1
  12. package/_cjs/clients/createClient.js +1 -0
  13. package/_cjs/clients/createClient.js.map +1 -1
  14. package/_cjs/clients/decorators/public.js +2 -0
  15. package/_cjs/clients/decorators/public.js.map +1 -1
  16. package/_cjs/errors/version.js +1 -1
  17. package/_cjs/index.js.map +1 -1
  18. package/_cjs/tempo/Decorator.js +7 -0
  19. package/_cjs/tempo/Decorator.js.map +1 -1
  20. package/_cjs/tempo/actions/earn/deployment.js +654 -0
  21. package/_cjs/tempo/actions/earn/deployment.js.map +1 -0
  22. package/_cjs/tempo/actions/earn.js +17 -0
  23. package/_cjs/tempo/actions/earn.js.map +1 -1
  24. package/_cjs/tempo/actions/zone.js +29 -9
  25. package/_cjs/tempo/actions/zone.js.map +1 -1
  26. package/_cjs/tempo/chainConfig.js +24 -23
  27. package/_cjs/tempo/chainConfig.js.map +1 -1
  28. package/_cjs/tempo/internal/WithdrawalSenderTag.js +2 -2
  29. package/_cjs/tempo/internal/WithdrawalSenderTag.js.map +1 -1
  30. package/_cjs/tempo/zones/Abis.js +17 -0
  31. package/_cjs/tempo/zones/Abis.js.map +1 -1
  32. package/_esm/actions/index.js +1 -0
  33. package/_esm/actions/index.js.map +1 -1
  34. package/_esm/actions/public/watchBlockHeaders.js +81 -0
  35. package/_esm/actions/public/watchBlockHeaders.js.map +1 -0
  36. package/_esm/actions/wallet/prepareTransactionRequest.js +14 -13
  37. package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
  38. package/_esm/actions/wallet/sendTransaction.js +24 -12
  39. package/_esm/actions/wallet/sendTransaction.js.map +1 -1
  40. package/_esm/actions/wallet/sendTransactionSync.js +24 -12
  41. package/_esm/actions/wallet/sendTransactionSync.js.map +1 -1
  42. package/_esm/clients/createClient.js +4 -3
  43. package/_esm/clients/createClient.js.map +1 -1
  44. package/_esm/clients/decorators/public.js +2 -0
  45. package/_esm/clients/decorators/public.js.map +1 -1
  46. package/_esm/errors/version.js +1 -1
  47. package/_esm/index.js.map +1 -1
  48. package/_esm/tempo/Decorator.js +7 -0
  49. package/_esm/tempo/Decorator.js.map +1 -1
  50. package/_esm/tempo/actions/earn/deployment.js +967 -0
  51. package/_esm/tempo/actions/earn/deployment.js.map +1 -0
  52. package/_esm/tempo/actions/earn.js +4 -0
  53. package/_esm/tempo/actions/earn.js.map +1 -1
  54. package/_esm/tempo/actions/zone.js +31 -9
  55. package/_esm/tempo/actions/zone.js.map +1 -1
  56. package/_esm/tempo/chainConfig.js +26 -28
  57. package/_esm/tempo/chainConfig.js.map +1 -1
  58. package/_esm/tempo/internal/WithdrawalSenderTag.js +3 -3
  59. package/_esm/tempo/internal/WithdrawalSenderTag.js.map +1 -1
  60. package/_esm/tempo/zones/Abis.js +17 -0
  61. package/_esm/tempo/zones/Abis.js.map +1 -1
  62. package/_types/actions/index.d.ts +1 -0
  63. package/_types/actions/index.d.ts.map +1 -1
  64. package/_types/actions/public/watchBlockHeaders.d.ts +45 -0
  65. package/_types/actions/public/watchBlockHeaders.d.ts.map +1 -0
  66. package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
  67. package/_types/actions/wallet/sendTransaction.d.ts.map +1 -1
  68. package/_types/actions/wallet/sendTransactionSync.d.ts.map +1 -1
  69. package/_types/clients/createClient.d.ts +3 -3
  70. package/_types/clients/createClient.d.ts.map +1 -1
  71. package/_types/clients/decorators/public.d.ts +24 -0
  72. package/_types/clients/decorators/public.d.ts.map +1 -1
  73. package/_types/errors/version.d.ts +1 -1
  74. package/_types/index.d.ts +1 -0
  75. package/_types/index.d.ts.map +1 -1
  76. package/_types/tempo/Decorator.d.ts +18 -0
  77. package/_types/tempo/Decorator.d.ts.map +1 -1
  78. package/_types/tempo/actions/earn/deployment.d.ts +1710 -0
  79. package/_types/tempo/actions/earn/deployment.d.ts.map +1 -0
  80. package/_types/tempo/actions/earn.d.ts +1 -1
  81. package/_types/tempo/actions/earn.d.ts.map +1 -1
  82. package/_types/tempo/actions/zone.d.ts +21 -5
  83. package/_types/tempo/actions/zone.d.ts.map +1 -1
  84. package/_types/tempo/chainConfig.d.ts.map +1 -1
  85. package/_types/tempo/internal/WithdrawalSenderTag.d.ts +2 -1
  86. package/_types/tempo/internal/WithdrawalSenderTag.d.ts.map +1 -1
  87. package/_types/tempo/zones/Abis.d.ts +48 -0
  88. package/_types/tempo/zones/Abis.d.ts.map +1 -1
  89. package/actions/index.ts +9 -0
  90. package/actions/public/watchBlockHeaders.ts +131 -0
  91. package/actions/wallet/prepareTransactionRequest.ts +18 -17
  92. package/actions/wallet/sendTransaction.ts +25 -10
  93. package/actions/wallet/sendTransactionSync.ts +25 -10
  94. package/clients/createClient.ts +4 -3
  95. package/clients/decorators/public.ts +33 -0
  96. package/errors/version.ts +1 -1
  97. package/index.ts +8 -0
  98. package/package.json +1 -1
  99. package/tempo/Decorator.ts +41 -0
  100. package/tempo/actions/earn/deployment.ts +1427 -0
  101. package/tempo/actions/earn.ts +5 -0
  102. package/tempo/actions/zone.ts +66 -6
  103. package/tempo/chainConfig.ts +30 -27
  104. package/tempo/internal/WithdrawalSenderTag.ts +5 -4
  105. package/tempo/zones/Abis.ts +17 -0
@@ -340,20 +340,6 @@ export async function prepareTransactionRequest<
340
340
  let account = account_ ? parseAccount(account_) : account_
341
341
 
342
342
  let nonce = request.nonce
343
- if (
344
- parameters.includes('nonce') &&
345
- typeof nonce === 'undefined' &&
346
- account &&
347
- nonceManager
348
- ) {
349
- const chainId = await getChainId()
350
- nonce = await nonceManager.consume({
351
- address: account.address,
352
- chainId,
353
- client,
354
- })
355
- }
356
-
357
343
  if (
358
344
  prepareTransactionRequest?.fn &&
359
345
  prepareTransactionRequest.runAt?.includes('beforeFillTransaction')
@@ -370,6 +356,20 @@ export async function prepareTransactionRequest<
370
356
  account = sender ? parseAccount(sender) : undefined
371
357
  }
372
358
 
359
+ if (
360
+ parameters.includes('nonce') &&
361
+ typeof nonce === 'undefined' &&
362
+ account &&
363
+ nonceManager
364
+ ) {
365
+ const chainId = await getChainId()
366
+ nonce = await nonceManager.consume({
367
+ address: account.address,
368
+ chainId,
369
+ client,
370
+ })
371
+ }
372
+
373
373
  const attemptFill = (() => {
374
374
  // Do not attempt if blobs are provided.
375
375
  if (
@@ -380,9 +380,6 @@ export async function prepareTransactionRequest<
380
380
  )
381
381
  return false
382
382
 
383
- // Do not attempt if `eth_fillTransaction` is not supported.
384
- if (supportsFillTransaction.get(client.uid) === false) return false
385
-
386
383
  // Always attempt if the caller explicitly requested a non-empty set of
387
384
  // `parameters` and a fee payer signature is being requested (e.g. Tempo
388
385
  // sponsorship via `feePayer: true`/`Account`) and has not already been
@@ -408,6 +405,10 @@ export async function prepareTransactionRequest<
408
405
  )
409
406
  return true
410
407
 
408
+ // Sponsorship can route fill requests to a different endpoint, so it must
409
+ // bypass support state cached from a non-sponsored request.
410
+ if (supportsFillTransaction.get(client.uid) === false) return false
411
+
411
412
  // Should attempt `eth_fillTransaction` if "fees" or "gas" are required to be populated,
412
413
  // otherwise, can just use the other individual calls.
413
414
  const shouldAttempt = ['fees', 'gas'].some((parameter) =>
@@ -47,6 +47,7 @@ import {
47
47
  } from '../../utils/formatters/transactionRequest.js'
48
48
  import { getAction } from '../../utils/getAction.js'
49
49
  import { LruMap } from '../../utils/lru.js'
50
+ import type { NonceManager } from '../../utils/nonceManager.js'
50
51
  import {
51
52
  type AssertRequestErrorType,
52
53
  type AssertRequestParameters,
@@ -310,15 +311,29 @@ export async function sendTransaction<
310
311
  }
311
312
 
312
313
  if (account?.type === 'local') {
313
- if (account.nonceManager && typeof nonce === 'undefined') {
314
- const requestChainId = (rest as unknown as { chainId?: number }).chainId
315
- const chainId = await (async () => {
316
- if (typeof requestChainId === 'number') return requestChainId
317
- if (chain) return chain.id
318
- return getAction(client, getChainId, 'getChainId')({})
319
- })()
320
- nonceManagerParameters = { address: account.address, chainId }
321
- }
314
+ const nonceManager = ((): NonceManager | undefined => {
315
+ if (!account.nonceManager || typeof nonce !== 'undefined')
316
+ return account.nonceManager
317
+ const nonceManager = account.nonceManager
318
+ return {
319
+ consume(parameters) {
320
+ nonceManagerParameters = {
321
+ address: parameters.address,
322
+ chainId: parameters.chainId,
323
+ }
324
+ return nonceManager.consume(parameters)
325
+ },
326
+ get(parameters) {
327
+ return nonceManager.get(parameters)
328
+ },
329
+ increment(parameters) {
330
+ return nonceManager.increment(parameters)
331
+ },
332
+ reset(parameters) {
333
+ return nonceManager.reset(parameters)
334
+ },
335
+ }
336
+ })()
322
337
 
323
338
  // Prepare the request for signing (assign appropriate fees, etc.)
324
339
  const request = await getAction(
@@ -338,7 +353,7 @@ export async function sendTransaction<
338
353
  maxFeePerGas,
339
354
  maxPriorityFeePerGas,
340
355
  nonce,
341
- nonceManager: account.nonceManager,
356
+ nonceManager,
342
357
  parameters: [...defaultParameters, 'sidecars'],
343
358
  type,
344
359
  value,
@@ -51,6 +51,7 @@ import {
51
51
  } from '../../utils/formatters/transactionRequest.js'
52
52
  import { getAction } from '../../utils/getAction.js'
53
53
  import { LruMap } from '../../utils/lru.js'
54
+ import type { NonceManager } from '../../utils/nonceManager.js'
54
55
  import {
55
56
  type AssertRequestErrorType,
56
57
  type AssertRequestParameters,
@@ -349,15 +350,29 @@ export async function sendTransactionSync<
349
350
  }
350
351
 
351
352
  if (account?.type === 'local') {
352
- if (account.nonceManager && typeof nonce === 'undefined') {
353
- const requestChainId = (rest as unknown as { chainId?: number }).chainId
354
- const chainId = await (async () => {
355
- if (typeof requestChainId === 'number') return requestChainId
356
- if (chain) return chain.id
357
- return getAction(client, getChainId, 'getChainId')({})
358
- })()
359
- nonceManagerParameters = { address: account.address, chainId }
360
- }
353
+ const nonceManager = ((): NonceManager | undefined => {
354
+ if (!account.nonceManager || typeof nonce !== 'undefined')
355
+ return account.nonceManager
356
+ const nonceManager = account.nonceManager
357
+ return {
358
+ consume(parameters) {
359
+ nonceManagerParameters = {
360
+ address: parameters.address,
361
+ chainId: parameters.chainId,
362
+ }
363
+ return nonceManager.consume(parameters)
364
+ },
365
+ get(parameters) {
366
+ return nonceManager.get(parameters)
367
+ },
368
+ increment(parameters) {
369
+ return nonceManager.increment(parameters)
370
+ },
371
+ reset(parameters) {
372
+ return nonceManager.reset(parameters)
373
+ },
374
+ }
375
+ })()
361
376
 
362
377
  // Prepare the request for signing (assign appropriate fees, etc.)
363
378
  const request = await getAction(
@@ -377,7 +392,7 @@ export async function sendTransactionSync<
377
392
  maxFeePerGas,
378
393
  maxPriorityFeePerGas,
379
394
  nonce,
380
- nonceManager: account.nonceManager,
395
+ nonceManager,
381
396
  parameters: [...defaultParameters, 'sidecars'],
382
397
  type,
383
398
  value,
@@ -350,9 +350,9 @@ function isPlainObject(value: unknown): value is Record<string, unknown> {
350
350
  * Binds an action function to a `client`, returning a parameter-only version
351
351
  * along with any helpers the action exposes. Helpers that need a client
352
352
  * (`.call`, `.calls`, `.callWithPeriod`, `.estimateGas`, `.prepare`,
353
- * `.prepareRecipient`, `.simulate`) are bound to `client`; pure helpers
354
- * (`.extractEvent`, `.extractEvents`) are copied as-is. Used by decorators
355
- * that attach namespaced actions to a Client.
353
+ * `.prepareRecipient`, `.predict`, `.simulate`) are bound to `client`;
354
+ * pure helpers (`.extractEvent`, `.extractEvents`) are copied as-is. Used
355
+ * by decorators that attach namespaced actions to a Client.
356
356
  * @internal
357
357
  */
358
358
  export function bindActionDecorators(
@@ -367,6 +367,7 @@ export function bindActionDecorators(
367
367
  'estimateGas',
368
368
  'prepare',
369
369
  'prepareRecipient',
370
+ 'predict',
370
371
  'simulate',
371
372
  ] as const)
372
373
  if (Object.hasOwn(action, key)) {
@@ -240,6 +240,11 @@ import {
240
240
  type WaitForTransactionReceiptReturnType,
241
241
  waitForTransactionReceipt,
242
242
  } from '../../actions/public/waitForTransactionReceipt.js'
243
+ import {
244
+ type WatchBlockHeadersParameters,
245
+ type WatchBlockHeadersReturnType,
246
+ watchBlockHeaders,
247
+ } from '../../actions/public/watchBlockHeaders.js'
243
248
  import {
244
249
  type WatchBlockNumberParameters,
245
250
  type WatchBlockNumberReturnType,
@@ -305,6 +310,7 @@ import type {
305
310
  } from '../../types/contract.js'
306
311
  import type { FeeValuesType } from '../../types/fee.js'
307
312
  import type { FilterType } from '../../types/filter.js'
313
+ import type { HasTransportType } from '../../types/transport.js'
308
314
  import { bindActionDecorators, type Client } from '../createClient.js'
309
315
  import type { Transport } from '../transports/createTransport.js'
310
316
 
@@ -1988,6 +1994,32 @@ export type PublicActions<
1988
1994
  watchBlockNumber: (
1989
1995
  args: WatchBlockNumberParameters,
1990
1996
  ) => WatchBlockNumberReturnType
1997
+ /**
1998
+ * Watches and returns incoming block headers without fetching full blocks.
1999
+ *
2000
+ * - Docs: https://viem.sh/docs/actions/public/watchBlockHeaders
2001
+ * - JSON-RPC Methods: Uses a WebSocket or IPC subscription via [`eth_subscribe`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_subscribe) and the `"newHeads"` event.
2002
+ *
2003
+ * @param args - {@link WatchBlockHeadersParameters}
2004
+ * @returns A function that can be invoked to stop watching for new block headers. {@link WatchBlockHeadersReturnType}
2005
+ *
2006
+ * @example
2007
+ * import { createPublicClient, webSocket } from 'viem'
2008
+ * import { mainnet } from 'viem/chains'
2009
+ *
2010
+ * const client = createPublicClient({
2011
+ * chain: mainnet,
2012
+ * transport: webSocket(),
2013
+ * })
2014
+ * const unwatch = client.watchBlockHeaders({
2015
+ * onBlockHeader: (blockHeader) => console.log(blockHeader),
2016
+ * })
2017
+ */
2018
+ watchBlockHeaders: (
2019
+ args: HasTransportType<transport, 'webSocket' | 'ipc'> extends true
2020
+ ? WatchBlockHeadersParameters<chain>
2021
+ : never,
2022
+ ) => WatchBlockHeadersReturnType
1991
2023
  /**
1992
2024
  * Watches and returns information for incoming blocks.
1993
2025
  *
@@ -2337,6 +2369,7 @@ export function publicActions<
2337
2369
  uninstallFilter: (args) => uninstallFilter(client, args),
2338
2370
  waitForTransactionReceipt: (args) =>
2339
2371
  waitForTransactionReceipt(client, args),
2372
+ watchBlockHeaders: (args) => watchBlockHeaders(client, args),
2340
2373
  watchBlocks: (args) => watchBlocks(client, args),
2341
2374
  watchBlockNumber: (args) => watchBlockNumber(client, args),
2342
2375
  watchContractEvent: (args) => watchContractEvent(client, args),
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.55.11'
1
+ export const version = '2.55.15'
package/index.ts CHANGED
@@ -320,6 +320,14 @@ export type {
320
320
  WaitForTransactionReceiptParameters,
321
321
  WaitForTransactionReceiptReturnType,
322
322
  } from './actions/public/waitForTransactionReceipt.js'
323
+ export type {
324
+ BlockHeader,
325
+ OnBlockHeader,
326
+ OnBlockHeaderParameter,
327
+ WatchBlockHeadersErrorType,
328
+ WatchBlockHeadersParameters,
329
+ WatchBlockHeadersReturnType,
330
+ } from './actions/public/watchBlockHeaders.js'
323
331
  export type {
324
332
  OnBlockNumberFn,
325
333
  OnBlockNumberParameter,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.55.11",
4
+ "version": "2.55.15",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -1744,6 +1744,37 @@ type DecoratorBase<
1744
1744
  ) => () => void
1745
1745
  }
1746
1746
  earn: {
1747
+ /** Deploys a deterministic ERC-4626 engine. */
1748
+ createErc4626Engine: (
1749
+ parameters: earnActions.createErc4626Engine.Parameters<chain, account>,
1750
+ ) => Promise<earnActions.createErc4626Engine.ReturnValue>
1751
+ /** Deploys a deterministic ERC-4626 engine and waits for confirmation. */
1752
+ createErc4626EngineSync: (
1753
+ parameters: earnActions.createErc4626EngineSync.Parameters<
1754
+ chain,
1755
+ account
1756
+ >,
1757
+ ) => Promise<earnActions.createErc4626EngineSync.ReturnValue>
1758
+ /** Deploys the EarnShare, EarnVault, and EarnFees contracts. */
1759
+ createStack: (
1760
+ parameters: earnActions.createStack.Parameters<chain, account>,
1761
+ ) => Promise<earnActions.createStack.ReturnValue>
1762
+ /** Deploys an Earn stack and waits for confirmation. */
1763
+ createStackSync: (
1764
+ parameters: earnActions.createStackSync.Parameters<chain, account>,
1765
+ ) => Promise<earnActions.createStackSync.ReturnValue>
1766
+ /** Binds an ERC-4626 engine to its EarnVault. */
1767
+ bindErc4626Engine: (
1768
+ parameters: earnActions.bindErc4626Engine.Parameters<chain, account>,
1769
+ ) => Promise<earnActions.bindErc4626Engine.ReturnValue>
1770
+ /** Binds an ERC-4626 engine and waits for confirmation. */
1771
+ bindErc4626EngineSync: (
1772
+ parameters: earnActions.bindErc4626EngineSync.Parameters<chain, account>,
1773
+ ) => Promise<earnActions.bindErc4626EngineSync.ReturnValue>
1774
+ /** Deploys and binds a complete, resumable ERC-4626 Earn stack. */
1775
+ deployErc4626StackSync: (
1776
+ parameters: earnActions.deployErc4626StackSync.Parameters<chain, account>,
1777
+ ) => Promise<earnActions.deployErc4626StackSync.ReturnValue>
1747
1778
  /**
1748
1779
  * Creates and attaches an admission-only TIP-403 policy to an Earn share
1749
1780
  * token. Existing holders remain able to send shares while
@@ -5686,6 +5717,9 @@ type BoundActionHelpers<action> = (action extends { call: infer helper }
5686
5717
  (action extends { prepareRecipient: infer helper }
5687
5718
  ? { prepareRecipient: BoundHelper<helper> }
5688
5719
  : {}) &
5720
+ (action extends { predict: infer helper }
5721
+ ? { predict: BoundHelper<helper> }
5722
+ : {}) &
5689
5723
  (action extends { simulate: infer helper }
5690
5724
  ? { simulate: BoundHelper<helper> }
5691
5725
  : {}) &
@@ -5888,11 +5922,18 @@ export function decorator() {
5888
5922
  'watchOrderPlaced',
5889
5923
  ]),
5890
5924
  earn: bindActions(client, earnActions, [
5925
+ 'bindErc4626Engine',
5926
+ 'bindErc4626EngineSync',
5891
5927
  'configureExitSafePolicy',
5928
+ 'createErc4626Engine',
5929
+ 'createErc4626EngineSync',
5930
+ 'createStack',
5931
+ 'createStackSync',
5892
5932
  'deposit',
5893
5933
  'depositSync',
5894
5934
  'depositShares',
5895
5935
  'depositSharesSync',
5936
+ 'deployErc4626StackSync',
5896
5937
  'privateDeposit',
5897
5938
  'privateDepositSync',
5898
5939
  'getFeeState',