viem 2.57.12 → 2.57.14

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 (135) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/_cjs/actions/public/fillTransaction.js +6 -3
  3. package/_cjs/actions/public/fillTransaction.js.map +1 -1
  4. package/_cjs/actions/public/watchContractEvent.js +58 -29
  5. package/_cjs/actions/public/watchContractEvent.js.map +1 -1
  6. package/_cjs/actions/public/watchEvent.js +58 -29
  7. package/_cjs/actions/public/watchEvent.js.map +1 -1
  8. package/_cjs/chains/definitions/molibra.js +21 -0
  9. package/_cjs/chains/definitions/molibra.js.map +1 -0
  10. package/_cjs/chains/index.js +9 -7
  11. package/_cjs/chains/index.js.map +1 -1
  12. package/_cjs/errors/version.js +1 -1
  13. package/_cjs/tempo/Account.js +4 -4
  14. package/_cjs/tempo/Account.js.map +1 -1
  15. package/_cjs/tempo/Formatters.js +17 -3
  16. package/_cjs/tempo/Formatters.js.map +1 -1
  17. package/_cjs/tempo/Relay.js +5 -0
  18. package/_cjs/tempo/Relay.js.map +1 -1
  19. package/_cjs/tempo/Transaction.js.map +1 -1
  20. package/_cjs/tempo/accounts/Config.js +21 -8
  21. package/_cjs/tempo/accounts/Config.js.map +1 -1
  22. package/_cjs/tempo/chainConfig.js +17 -5
  23. package/_cjs/tempo/chainConfig.js.map +1 -1
  24. package/_cjs/tempo/internal/relay/accounts.js +41 -4
  25. package/_cjs/tempo/internal/relay/accounts.js.map +1 -1
  26. package/_cjs/tempo/internal/relay/autoSwap.js +200 -0
  27. package/_cjs/tempo/internal/relay/autoSwap.js.map +1 -0
  28. package/_cjs/tempo/internal/relay/error.js +5 -1
  29. package/_cjs/tempo/internal/relay/error.js.map +1 -1
  30. package/_cjs/tempo/internal/relay/feePayer.js +4 -1
  31. package/_cjs/tempo/internal/relay/feePayer.js.map +1 -1
  32. package/_cjs/tempo/internal/relay/feeToken.js +14 -1
  33. package/_cjs/tempo/internal/relay/feeToken.js.map +1 -1
  34. package/_cjs/tempo/internal/relay/simulate.js +57 -15
  35. package/_cjs/tempo/internal/relay/simulate.js.map +1 -1
  36. package/_esm/actions/public/fillTransaction.js +8 -3
  37. package/_esm/actions/public/fillTransaction.js.map +1 -1
  38. package/_esm/actions/public/watchContractEvent.js +73 -36
  39. package/_esm/actions/public/watchContractEvent.js.map +1 -1
  40. package/_esm/actions/public/watchEvent.js +73 -36
  41. package/_esm/actions/public/watchEvent.js.map +1 -1
  42. package/_esm/chains/definitions/molibra.js +18 -0
  43. package/_esm/chains/definitions/molibra.js.map +1 -0
  44. package/_esm/chains/index.js +1 -0
  45. package/_esm/chains/index.js.map +1 -1
  46. package/_esm/errors/version.js +1 -1
  47. package/_esm/tempo/Account.js +4 -4
  48. package/_esm/tempo/Account.js.map +1 -1
  49. package/_esm/tempo/Formatters.js +17 -4
  50. package/_esm/tempo/Formatters.js.map +1 -1
  51. package/_esm/tempo/Relay.js +20 -0
  52. package/_esm/tempo/Relay.js.map +1 -1
  53. package/_esm/tempo/Transaction.js.map +1 -1
  54. package/_esm/tempo/accounts/Config.js +27 -12
  55. package/_esm/tempo/accounts/Config.js.map +1 -1
  56. package/_esm/tempo/chainConfig.js +22 -5
  57. package/_esm/tempo/chainConfig.js.map +1 -1
  58. package/_esm/tempo/internal/relay/accounts.js +43 -4
  59. package/_esm/tempo/internal/relay/accounts.js.map +1 -1
  60. package/_esm/tempo/internal/relay/autoSwap.js +218 -0
  61. package/_esm/tempo/internal/relay/autoSwap.js.map +1 -0
  62. package/_esm/tempo/internal/relay/error.js +6 -2
  63. package/_esm/tempo/internal/relay/error.js.map +1 -1
  64. package/_esm/tempo/internal/relay/feePayer.js +4 -1
  65. package/_esm/tempo/internal/relay/feePayer.js.map +1 -1
  66. package/_esm/tempo/internal/relay/feeToken.js +17 -3
  67. package/_esm/tempo/internal/relay/feeToken.js.map +1 -1
  68. package/_esm/tempo/internal/relay/simulate.js +68 -17
  69. package/_esm/tempo/internal/relay/simulate.js.map +1 -1
  70. package/_types/actions/getContract.d.ts +1 -1
  71. package/_types/actions/public/fillTransaction.d.ts.map +1 -1
  72. package/_types/actions/public/watchContractEvent.d.ts +1 -1
  73. package/_types/actions/public/watchContractEvent.d.ts.map +1 -1
  74. package/_types/actions/public/watchEvent.d.ts +1 -1
  75. package/_types/actions/public/watchEvent.d.ts.map +1 -1
  76. package/_types/chains/definitions/molibra.d.ts +52 -0
  77. package/_types/chains/definitions/molibra.d.ts.map +1 -0
  78. package/_types/chains/definitions/tempo.d.ts +14 -6
  79. package/_types/chains/definitions/tempo.d.ts.map +1 -1
  80. package/_types/chains/definitions/tempoDevnet.d.ts +14 -6
  81. package/_types/chains/definitions/tempoDevnet.d.ts.map +1 -1
  82. package/_types/chains/definitions/tempoLocalnet.d.ts +14 -6
  83. package/_types/chains/definitions/tempoLocalnet.d.ts.map +1 -1
  84. package/_types/chains/definitions/tempoModerato.d.ts +14 -6
  85. package/_types/chains/definitions/tempoModerato.d.ts.map +1 -1
  86. package/_types/chains/index.d.ts +1 -0
  87. package/_types/chains/index.d.ts.map +1 -1
  88. package/_types/clients/decorators/public.d.ts +2 -2
  89. package/_types/errors/version.d.ts +1 -1
  90. package/_types/tempo/Account.d.ts +15 -1
  91. package/_types/tempo/Account.d.ts.map +1 -1
  92. package/_types/tempo/Capabilities.d.ts +32 -2
  93. package/_types/tempo/Capabilities.d.ts.map +1 -1
  94. package/_types/tempo/Formatters.d.ts +3 -0
  95. package/_types/tempo/Formatters.d.ts.map +1 -1
  96. package/_types/tempo/Relay.d.ts +46 -0
  97. package/_types/tempo/Relay.d.ts.map +1 -1
  98. package/_types/tempo/Transaction.d.ts +7 -2
  99. package/_types/tempo/Transaction.d.ts.map +1 -1
  100. package/_types/tempo/accounts/Config.d.ts +24 -2
  101. package/_types/tempo/accounts/Config.d.ts.map +1 -1
  102. package/_types/tempo/actions/accessKey.d.ts +2 -2
  103. package/_types/tempo/chainConfig.d.ts +8 -3
  104. package/_types/tempo/chainConfig.d.ts.map +1 -1
  105. package/_types/tempo/internal/relay/accounts.d.ts.map +1 -1
  106. package/_types/tempo/internal/relay/autoSwap.d.ts +3 -0
  107. package/_types/tempo/internal/relay/autoSwap.d.ts.map +1 -0
  108. package/_types/tempo/internal/relay/error.d.ts.map +1 -1
  109. package/_types/tempo/internal/relay/feePayer.d.ts.map +1 -1
  110. package/_types/tempo/internal/relay/feeToken.d.ts.map +1 -1
  111. package/_types/tempo/internal/relay/simulate.d.ts +4 -0
  112. package/_types/tempo/internal/relay/simulate.d.ts.map +1 -1
  113. package/actions/getContract.ts +1 -1
  114. package/actions/public/fillTransaction.ts +12 -3
  115. package/actions/public/watchContractEvent.ts +82 -39
  116. package/actions/public/watchEvent.ts +82 -39
  117. package/chains/definitions/molibra.ts +18 -0
  118. package/chains/index.ts +1 -0
  119. package/clients/decorators/public.ts +2 -2
  120. package/errors/version.ts +1 -1
  121. package/package.json +1 -1
  122. package/tempo/Account.ts +19 -9
  123. package/tempo/Capabilities.ts +34 -2
  124. package/tempo/Formatters.ts +24 -12
  125. package/tempo/Relay.ts +57 -0
  126. package/tempo/Transaction.ts +10 -2
  127. package/tempo/accounts/Config.ts +39 -16
  128. package/tempo/actions/accessKey.ts +2 -2
  129. package/tempo/chainConfig.ts +26 -5
  130. package/tempo/internal/relay/accounts.ts +44 -6
  131. package/tempo/internal/relay/autoSwap.ts +263 -0
  132. package/tempo/internal/relay/error.ts +7 -2
  133. package/tempo/internal/relay/feePayer.ts +6 -1
  134. package/tempo/internal/relay/feeToken.ts +21 -3
  135. package/tempo/internal/relay/simulate.ts +106 -19
@@ -6,6 +6,8 @@ import {
6
6
  DecodeLogDataMismatch,
7
7
  DecodeLogTopicsMismatch,
8
8
  } from '../../errors/abi.js'
9
+ import { BaseError } from '../../errors/base.js'
10
+ import { HttpRequestError, RpcRequestError } from '../../errors/request.js'
9
11
  import { InvalidInputRpcError } from '../../errors/rpc.js'
10
12
  import type { ErrorType } from '../../errors/utils.js'
11
13
  import type { BlockNumber } from '../../types/block.js'
@@ -106,7 +108,7 @@ export type WatchContractEventErrorType =
106
108
  *
107
109
  * This Action will batch up all the event logs found within the [`pollingInterval`](https://viem.sh/docs/contract/watchContractEvent#pollinginterval-optional), and invoke them via [`onLogs`](https://viem.sh/docs/contract/watchContractEvent#onLogs).
108
110
  *
109
- * `watchContractEvent` will attempt to create an [Event Filter](https://viem.sh/docs/contract/createContractEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchContractEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead.
111
+ * `watchContractEvent` will attempt to create an [Event Filter](https://viem.sh/docs/contract/createContractEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchContractEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead. If `getLogs` fails for a block range, `watchContractEvent` will retry with smaller block ranges and may call `onLogs` more than once per polling interval.
110
112
  *
111
113
  * @param client - Client to use
112
114
  * @param parameters - {@link WatchContractEventParameters}
@@ -185,11 +187,34 @@ export function watchContractEvent<
185
187
  ])
186
188
 
187
189
  return observe(observerId, { onLogs, onError }, (emit) => {
188
- let previousBlockNumber: bigint
189
- if (fromBlock !== undefined) previousBlockNumber = fromBlock - 1n
190
+ let active = true
191
+ let previousBlockNumber =
192
+ fromBlock === undefined ? undefined : fromBlock - 1n
190
193
  let filter: Filter<'event', abi, eventName> | undefined
191
194
  let initialized = false
192
195
 
196
+ const emitLogs = (logs: Log[]) => {
197
+ if (logs.length === 0) return
198
+ if (batch) emit.onLogs(logs as any)
199
+ else for (const log of logs) emit.onLogs([log] as any)
200
+ }
201
+
202
+ // Fetches the logs of the blocks from `from` to `to`, inclusive.
203
+ const getLogsInRange = (from: bigint, to: bigint) =>
204
+ getAction(
205
+ client,
206
+ getContractEvents,
207
+ 'getContractEvents',
208
+ )({
209
+ abi,
210
+ address,
211
+ args,
212
+ eventName,
213
+ fromBlock: from,
214
+ toBlock: to,
215
+ strict,
216
+ } as {} as GetContractEventsParameters)
217
+
193
218
  const unwatch = poll(
194
219
  async () => {
195
220
  if (!initialized) {
@@ -208,54 +233,55 @@ export function watchContractEvent<
208
233
  })) as Filter<'event', abi, eventName>
209
234
  } catch {}
210
235
  initialized = true
211
- return
236
+ if (filter) return
212
237
  }
213
238
 
214
239
  try {
215
- let logs: Log[]
216
240
  if (filter) {
217
- logs = await getAction(
241
+ const logs = await getAction(
218
242
  client,
219
243
  getFilterChanges,
220
244
  'getFilterChanges',
221
245
  )({ filter })
222
- } else {
223
- // If the filter doesn't exist, we will fall back to use `getLogs`.
224
- // The fall back exists because some RPC Providers do not support filters.
246
+ emitLogs(logs)
247
+ return
248
+ }
225
249
 
226
- // Fetch the block number to use for `getLogs`.
227
- const blockNumber = await getAction(
228
- client,
229
- getBlockNumber,
230
- 'getBlockNumber',
231
- )({})
250
+ // If the filter doesn't exist, we will fall back to use `getLogs`.
251
+ // The fall back exists because some RPC Providers do not support filters.
252
+ const blockNumber = await getAction(
253
+ client,
254
+ getBlockNumber,
255
+ 'getBlockNumber',
256
+ )({})
232
257
 
233
- // If the block number has changed, we will need to fetch the logs.
234
- // If the block number doesn't exist, we are yet to reach the first poll interval,
235
- // so do not emit any logs.
236
- if (previousBlockNumber && previousBlockNumber < blockNumber) {
237
- logs = await getAction(
238
- client,
239
- getContractEvents,
240
- 'getContractEvents',
241
- )({
242
- abi,
243
- address,
244
- args,
245
- eventName,
246
- fromBlock: previousBlockNumber + 1n,
247
- toBlock: blockNumber,
248
- strict,
249
- } as {} as GetContractEventsParameters)
250
- } else {
251
- logs = []
258
+ // Without `fromBlock`, start watching from the current block.
259
+ previousBlockNumber ??= blockNumber
260
+
261
+ // RPC Providers limit `eth_getLogs` by block range, log count or response
262
+ // size. `size` is the most blocks to request at once: it starts with all
263
+ // new blocks and halves whenever a request fails.
264
+ let size = blockNumber - previousBlockNumber
265
+ while (previousBlockNumber < blockNumber) {
266
+ const from = previousBlockNumber + 1n
267
+ const end: bigint = previousBlockNumber + size
268
+ const to = end < blockNumber ? end : blockNumber
269
+
270
+ const logs = await getLogsInRange(from, to).catch((error) => {
271
+ // A single block cannot be split, and a smaller range does not
272
+ // help when the RPC Provider is unreachable or rejects the client.
273
+ if (from === to || !isRangeError(error)) throw error
274
+ })
275
+ if (!active) return
276
+ if (!logs) {
277
+ size = (to - from + 1n) / 2n
278
+ continue
252
279
  }
253
- previousBlockNumber = blockNumber
254
- }
255
280
 
256
- if (logs.length === 0) return
257
- if (batch) emit.onLogs(logs as any)
258
- else for (const log of logs) emit.onLogs([log] as any)
281
+ // Only move past blocks whose logs were fetched, so none are skipped.
282
+ previousBlockNumber = to
283
+ emitLogs(logs)
284
+ }
259
285
  } catch (err) {
260
286
  // If a filter has been set and gets uninstalled, providers will throw an InvalidInput error.
261
287
  // Reinitialize the filter when this occurs
@@ -271,6 +297,7 @@ export function watchContractEvent<
271
297
  )
272
298
 
273
299
  return async () => {
300
+ active = false
274
301
  if (filter)
275
302
  await getAction(
276
303
  client,
@@ -377,3 +404,19 @@ export function watchContractEvent<
377
404
 
378
405
  return enablePolling ? pollContractEvent() : subscribeContractEvent()
379
406
  }
407
+
408
+ /** Returns whether a failed `eth_getLogs` request may succeed with a smaller block range. */
409
+ function isRangeError(error: unknown) {
410
+ if (!(error instanceof BaseError)) return true
411
+ const cause = error.walk(
412
+ (err) => err instanceof HttpRequestError || err instanceof RpcRequestError,
413
+ ) as HttpRequestError | RpcRequestError | null
414
+ if (!cause) return true
415
+ // Rate limited.
416
+ if (cause instanceof RpcRequestError && cause.code === 429) return false
417
+ // Unreachable.
418
+ if (cause instanceof HttpRequestError && cause.status === undefined)
419
+ return false
420
+ // Unauthorized, forbidden or rate limited.
421
+ return cause.status !== 401 && cause.status !== 403 && cause.status !== 429
422
+ }
@@ -6,6 +6,8 @@ import {
6
6
  DecodeLogDataMismatch,
7
7
  DecodeLogTopicsMismatch,
8
8
  } from '../../errors/abi.js'
9
+ import { BaseError } from '../../errors/base.js'
10
+ import { HttpRequestError, RpcRequestError } from '../../errors/request.js'
9
11
  import { InvalidInputRpcError } from '../../errors/rpc.js'
10
12
  import type { ErrorType } from '../../errors/utils.js'
11
13
  import type { BlockNumber } from '../../types/block.js'
@@ -128,7 +130,7 @@ export type WatchEventErrorType =
128
130
  *
129
131
  * This Action will batch up all the Event Logs found within the [`pollingInterval`](https://viem.sh/docs/actions/public/watchEvent#pollinginterval-optional), and invoke them via [`onLogs`](https://viem.sh/docs/actions/public/watchEvent#onLogs).
130
132
  *
131
- * `watchEvent` will attempt to create an [Event Filter](https://viem.sh/docs/actions/public/createEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead.
133
+ * `watchEvent` will attempt to create an [Event Filter](https://viem.sh/docs/actions/public/createEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead. If `getLogs` fails for a block range, `watchEvent` will retry with smaller block ranges and may call `onLogs` more than once per polling interval.
132
134
  *
133
135
  * @param client - Client to use
134
136
  * @param parameters - {@link WatchEventParameters}
@@ -206,11 +208,34 @@ export function watchEvent<
206
208
  ])
207
209
 
208
210
  return observe(observerId, { onLogs, onError }, (emit) => {
209
- let previousBlockNumber: bigint
210
- if (fromBlock !== undefined) previousBlockNumber = fromBlock - 1n
211
+ let active = true
212
+ let previousBlockNumber =
213
+ fromBlock === undefined ? undefined : fromBlock - 1n
211
214
  let filter: Filter<'event', abiEvents, _eventName, any>
212
215
  let initialized = false
213
216
 
217
+ const emitLogs = (logs: Log[]) => {
218
+ if (logs.length === 0) return
219
+ if (batch) emit.onLogs(logs as any)
220
+ else for (const log of logs) emit.onLogs([log] as any)
221
+ }
222
+
223
+ // Fetches the logs of the blocks from `from` to `to`, inclusive.
224
+ const getLogsInRange = (from: bigint, to: bigint) =>
225
+ getAction(
226
+ client,
227
+ getLogs,
228
+ 'getLogs',
229
+ )({
230
+ address,
231
+ args,
232
+ event: event!,
233
+ events,
234
+ fromBlock: from,
235
+ strict,
236
+ toBlock: to,
237
+ } as unknown as GetLogsParameters)
238
+
214
239
  const unwatch = poll(
215
240
  async () => {
216
241
  if (!initialized) {
@@ -233,54 +258,55 @@ export function watchEvent<
233
258
  >
234
259
  } catch {}
235
260
  initialized = true
236
- return
261
+ if (filter) return
237
262
  }
238
263
 
239
264
  try {
240
- let logs: Log[]
241
265
  if (filter) {
242
- logs = await getAction(
266
+ const logs = await getAction(
243
267
  client,
244
268
  getFilterChanges,
245
269
  'getFilterChanges',
246
270
  )({ filter })
247
- } else {
248
- // If the filter doesn't exist, we will fall back to use `getLogs`.
249
- // The fall back exists because some RPC Providers do not support filters.
271
+ emitLogs(logs)
272
+ return
273
+ }
250
274
 
251
- // Fetch the block number to use for `getLogs`.
252
- const blockNumber = await getAction(
253
- client,
254
- getBlockNumber,
255
- 'getBlockNumber',
256
- )({})
275
+ // If the filter doesn't exist, we will fall back to use `getLogs`.
276
+ // The fall back exists because some RPC Providers do not support filters.
277
+ const blockNumber = await getAction(
278
+ client,
279
+ getBlockNumber,
280
+ 'getBlockNumber',
281
+ )({})
282
+
283
+ // Without `fromBlock`, start watching from the current block.
284
+ previousBlockNumber ??= blockNumber
257
285
 
258
- // If the block number has changed, we will need to fetch the logs.
259
- // If the block number doesn't exist, we are yet to reach the first poll interval,
260
- // so do not emit any logs.
261
- if (previousBlockNumber && previousBlockNumber !== blockNumber) {
262
- logs = await getAction(
263
- client,
264
- getLogs,
265
- 'getLogs',
266
- )({
267
- address,
268
- args,
269
- event: event!,
270
- events,
271
- fromBlock: previousBlockNumber + 1n,
272
- strict,
273
- toBlock: blockNumber,
274
- } as unknown as GetLogsParameters)
275
- } else {
276
- logs = []
286
+ // RPC Providers limit `eth_getLogs` by block range, log count or response
287
+ // size. `size` is the most blocks to request at once: it starts with all
288
+ // new blocks and halves whenever a request fails.
289
+ let size = blockNumber - previousBlockNumber
290
+ while (previousBlockNumber < blockNumber) {
291
+ const from = previousBlockNumber + 1n
292
+ const end: bigint = previousBlockNumber + size
293
+ const to = end < blockNumber ? end : blockNumber
294
+
295
+ const logs = await getLogsInRange(from, to).catch((error) => {
296
+ // A single block cannot be split, and a smaller range does not
297
+ // help when the RPC Provider is unreachable or rejects the client.
298
+ if (from === to || !isRangeError(error)) throw error
299
+ })
300
+ if (!active) return
301
+ if (!logs) {
302
+ size = (to - from + 1n) / 2n
303
+ continue
277
304
  }
278
- previousBlockNumber = blockNumber
279
- }
280
305
 
281
- if (logs.length === 0) return
282
- if (batch) emit.onLogs(logs as any)
283
- else for (const log of logs) emit.onLogs([log] as any)
306
+ // Only move past blocks whose logs were fetched, so none are skipped.
307
+ previousBlockNumber = to
308
+ emitLogs(logs)
309
+ }
284
310
  } catch (err) {
285
311
  // If a filter has been set and gets uninstalled, providers will throw an InvalidInput error.
286
312
  // Reinitialize the filter when this occurs
@@ -296,6 +322,7 @@ export function watchEvent<
296
322
  )
297
323
 
298
324
  return async () => {
325
+ active = false
299
326
  if (filter)
300
327
  await getAction(
301
328
  client,
@@ -392,3 +419,19 @@ export function watchEvent<
392
419
 
393
420
  return enablePolling ? pollEvent() : subscribeEvent()
394
421
  }
422
+
423
+ /** Returns whether a failed `eth_getLogs` request may succeed with a smaller block range. */
424
+ function isRangeError(error: unknown) {
425
+ if (!(error instanceof BaseError)) return true
426
+ const cause = error.walk(
427
+ (err) => err instanceof HttpRequestError || err instanceof RpcRequestError,
428
+ ) as HttpRequestError | RpcRequestError | null
429
+ if (!cause) return true
430
+ // Rate limited.
431
+ if (cause instanceof RpcRequestError && cause.code === 429) return false
432
+ // Unreachable.
433
+ if (cause instanceof HttpRequestError && cause.status === undefined)
434
+ return false
435
+ // Unauthorized, forbidden or rate limited.
436
+ return cause.status !== 401 && cause.status !== 403 && cause.status !== 429
437
+ }
@@ -0,0 +1,18 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const molibra = /*#__PURE__*/ defineChain({
4
+ id: 20226,
5
+ name: 'Molibra',
6
+ nativeCurrency: { name: 'Molibra', symbol: 'MOLI', decimals: 18 },
7
+ rpcUrls: {
8
+ default: {
9
+ http: ['https://molibra.org'],
10
+ },
11
+ },
12
+ blockExplorers: {
13
+ default: {
14
+ name: 'Moliscan',
15
+ url: 'https://molibra.org/molibra/moliscan',
16
+ },
17
+ },
18
+ })
package/chains/index.ts CHANGED
@@ -434,6 +434,7 @@ export { mitosisTestnet } from './definitions/mitosisTestnet.js'
434
434
  export { mizuhikiTestnetAwaji } from './definitions/mizuhikiTestnetAwaji.js'
435
435
  export { mode } from './definitions/mode.js'
436
436
  export { modeTestnet } from './definitions/modeTestnet.js'
437
+ export { molibra } from './definitions/molibra.js'
437
438
  export { monad } from './definitions/monad.js'
438
439
  export { monadTestnet } from './definitions/monadTestnet.js'
439
440
  export { moonbaseAlpha } from './definitions/moonbaseAlpha.js'
@@ -2083,7 +2083,7 @@ export type PublicActions<
2083
2083
  * @remarks
2084
2084
  * This Action will batch up all the event logs found within the [`pollingInterval`](https://viem.sh/docs/contract/watchContractEvent#pollinginterval-optional), and invoke them via [`onLogs`](https://viem.sh/docs/contract/watchContractEvent#onLogs).
2085
2085
  *
2086
- * `watchContractEvent` will attempt to create an [Event Filter](https://viem.sh/docs/contract/createContractEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchContractEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead.
2086
+ * `watchContractEvent` will attempt to create an [Event Filter](https://viem.sh/docs/contract/createContractEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchContractEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead. If `getLogs` fails for a block range, `watchContractEvent` will retry with smaller block ranges and may call `onLogs` more than once per polling interval.
2087
2087
  *
2088
2088
  * @param args - {@link WatchContractEventParameters}
2089
2089
  * @returns A function that can be invoked to stop watching for new event logs. {@link WatchContractEventReturnType}
@@ -2125,7 +2125,7 @@ export type PublicActions<
2125
2125
  * @remarks
2126
2126
  * This Action will batch up all the Event Logs found within the [`pollingInterval`](https://viem.sh/docs/actions/public/watchEvent#pollinginterval-optional), and invoke them via [`onLogs`](https://viem.sh/docs/actions/public/watchEvent#onLogs).
2127
2127
  *
2128
- * `watchEvent` will attempt to create an [Event Filter](https://viem.sh/docs/actions/public/createEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead.
2128
+ * `watchEvent` will attempt to create an [Event Filter](https://viem.sh/docs/actions/public/createEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead. If `getLogs` fails for a block range, `watchEvent` will retry with smaller block ranges and may call `onLogs` more than once per polling interval.
2129
2129
  *
2130
2130
  * @param args - {@link WatchEventParameters}
2131
2131
  * @returns A function that can be invoked to stop watching for new Event Logs. {@link WatchEventReturnType}
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.57.12'
1
+ export const version = '2.57.14'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.57.12",
4
+ "version": "2.57.14",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
package/tempo/Account.ts CHANGED
@@ -294,6 +294,14 @@ export declare namespace fromSecp256k1 {
294
294
  * Normalizes supplied config fields with `AccountConfig.from`, so callers do
295
295
  * not need to normalize owner ordering themselves.
296
296
  *
297
+ * `sign`, `signMessage`, and `signTypedData` return a configurable signature
298
+ * envelope with local owner approvals up to the config threshold. Signatures
299
+ * verify against the account's current config, so a config update invalidates
300
+ * earlier signatures. Verify them with `verifyHash`, `verifyMessage`, or
301
+ * `verifyTypedData` on a Tempo client, which use the signature verifier
302
+ * precompile. Configurable accounts have no code and do not implement ERC-1271
303
+ * `isValidSignature`, so ERC-1271 verifiers do not accept their signatures.
304
+ *
297
305
  * @example
298
306
  * ```ts
299
307
  * import { Account } from 'viem/tempo'
@@ -406,10 +414,8 @@ export function fromConfig(value: fromConfig.Parameters): ConfigurableAccount {
406
414
  await signConfigurable(account, { payload: hash }),
407
415
  )
408
416
  },
409
- async signMessage() {
410
- throw new Error(
411
- '`signMessage` is not supported for configurable accounts.',
412
- )
417
+ async signMessage({ message }) {
418
+ return await account.sign({ hash: hashMessage(message) })
413
419
  },
414
420
  async signTransaction(transaction, options) {
415
421
  const { serializer = Transaction.serialize } = options ?? {}
@@ -456,10 +462,8 @@ export function fromConfig(value: fromConfig.Parameters): ConfigurableAccount {
456
462
  signature as never,
457
463
  )) as Hex.Hex
458
464
  },
459
- async signTypedData() {
460
- throw new Error(
461
- '`signTypedData` is not supported for configurable accounts.',
462
- )
465
+ async signTypedData(typedData) {
466
+ return await account.sign({ hash: hashTypedData(typedData) })
463
467
  },
464
468
  }
465
469
  return account
@@ -528,6 +532,12 @@ export declare namespace fromConfig {
528
532
  }
529
533
  }
530
534
 
535
+ /**
536
+ * Configurable account (TIP-1107) returned by {@link fromConfig}.
537
+ *
538
+ * Its signatures verify against the account's current config through Tempo's
539
+ * `verifyHash`, not ERC-1271, and a config update invalidates earlier signatures.
540
+ */
531
541
  export type ConfigurableAccount<
532
542
  config extends AccountConfig.Config | undefined =
533
543
  | AccountConfig.Config
@@ -900,7 +910,7 @@ export declare namespace signKeyAuthorization {
900
910
  /**
901
911
  * Whether to authorize the key as an admin key. Admin keys are
902
912
  * unrestricted and can manage the account's other access keys; `expiry`,
903
- * `limits`, and `scopes` are ignored. Requires the T6 hardfork.
913
+ * `limits`, and `scopes` are ignored. Requires the T6 hardfork; T14 (TIP-1137) removes admin key creation.
904
914
  *
905
915
  * [TIP-1049](https://tips.sh/1049)
906
916
  */
@@ -16,13 +16,23 @@ export type Schema = Omit<DefaultCapabilitiesSchema, 'sendCalls'> & {
16
16
  }
17
17
 
18
18
  export type FillTransactionRequestCapabilities = {
19
- /** Whether to include `balanceDiffs` in the response. */
19
+ /** Opts into a `Relay.autoSwap` buy of a missing token. A `slippage` can only tighten the relay's bound. */
20
+ autoSwap?:
21
+ | boolean
22
+ | {
23
+ /** Largest accepted price slippage, between 0 and 1. */
24
+ slippage?: number | undefined
25
+ }
26
+ | undefined
27
+ /** Opts into `balanceDiffs` in the response. */
20
28
  balanceDiffs?: boolean | undefined
21
29
  /** Whether execution reverts return error capabilities instead of throwing. */
22
30
  errors?: boolean | undefined
23
31
  }
24
32
 
25
33
  export type FillTransactionCapabilities = {
34
+ /** Stablecoin DEX buy prepended by `Relay.autoSwap` to cover a missing token. */
35
+ autoSwap?: AutoSwap | undefined
26
36
  balanceDiffs?: Readonly<Record<Address, readonly BalanceDiff[]>> | undefined
27
37
  error?: ExecutionError.Rpc | undefined
28
38
  fee?:
@@ -54,7 +64,29 @@ export type FillTransactionCapabilities = {
54
64
  virtualAddresses?: Readonly<Record<Address, Address | null>> | undefined
55
65
  }
56
66
 
57
- /** A token balance preview. Incoming funds and outgoing approval exposure can produce separate entries for the same token. */
67
+ /** A swap that buys a fill's missing token before its calls. */
68
+ export type AutoSwap = {
69
+ /** Swap calls prepended to the transaction. */
70
+ calls: readonly { data: Hex; to: Address }[]
71
+ /** Largest amount of the input token the swap may spend. */
72
+ maxIn: AutoSwapAmount
73
+ /** Amount of the missing token the swap buys. */
74
+ minOut: AutoSwapAmount
75
+ /** Largest accepted price slippage over the missing amount. */
76
+ slippage: number
77
+ }
78
+
79
+ /** One side of an {@link AutoSwap}. */
80
+ export type AutoSwapAmount = {
81
+ decimals: number
82
+ formatted: string
83
+ name: string
84
+ symbol: string
85
+ token: Address
86
+ value: Hex
87
+ }
88
+
89
+ /** A token balance preview. A token's incoming and outgoing movements use separate entries; outgoing includes remaining approval exposure. */
58
90
  export type BalanceDiff = {
59
91
  address: Address
60
92
  decimals: number
@@ -9,6 +9,9 @@ import {
9
9
  } from 'ox/tempo'
10
10
  import type { Account as viem_Account } from '../accounts/types.js'
11
11
  import { parseAccount } from '../accounts/utils/parseAccount.js'
12
+ import type { Block } from '../types/block.js'
13
+ import type { RpcBlock } from '../types/rpc.js'
14
+ import { formatBlock as viem_formatBlock } from '../utils/formatters/block.js'
12
15
  import { formatTransaction as viem_formatTransaction } from '../utils/formatters/transaction.js'
13
16
  import { formatTransactionReceipt as viem_formatTransactionReceipt } from '../utils/formatters/transactionReceipt.js'
14
17
  import { formatTransactionRequest as viem_formatTransactionRequest } from '../utils/formatters/transactionRequest.js'
@@ -23,6 +26,18 @@ import {
23
26
  type TransactionRpc,
24
27
  } from './Transaction.js'
25
28
 
29
+ export function formatBlock(block: RpcBlock): Block {
30
+ const { transactions = [], ...rest } = block
31
+ return {
32
+ ...viem_formatBlock({ ...rest, transactions: [] }),
33
+ transactions: transactions.map((transaction) =>
34
+ typeof transaction === 'string'
35
+ ? transaction
36
+ : formatTransaction(transaction as never),
37
+ ),
38
+ } as never
39
+ }
40
+
26
41
  export function formatTransaction(
27
42
  transaction: TransactionRpc,
28
43
  ): Transaction<bigint, number, boolean> {
@@ -34,12 +49,9 @@ export function formatTransaction(
34
49
  ? undefined
35
50
  : BigInt(transaction.blockTimestamp)
36
51
  const operation = transaction.operation
37
- const {
38
- feePayerSignature,
39
- gasPrice: _,
40
- nonce,
41
- ...tx
42
- } = ox_Transaction.fromRpc(transaction as never) as ox_Transaction.Tempo
52
+ const { feePayerSignature, nonce, ...tx } = ox_Transaction.fromRpc(
53
+ transaction as never,
54
+ ) as ox_Transaction.Tempo
43
55
 
44
56
  return {
45
57
  ...tx,
@@ -53,7 +65,7 @@ export function formatTransaction(
53
65
  yParity: feePayerSignature.yParity,
54
66
  }
55
67
  : undefined,
56
- nonce: Number(nonce),
68
+ nonce: nonce ?? 0n,
57
69
  operation: formatOperation(operation),
58
70
  typeHex:
59
71
  ox_Transaction.toRpcType[
@@ -115,12 +127,12 @@ export function formatTransactionRequest(
115
127
  'A local owner account is required to approve a configurable account transaction.',
116
128
  )
117
129
 
118
- // If the request is not a Tempo transaction, route to Viem formatter.
130
+ // If the request is not a Tempo transaction, route to Viem formatter, keeping relay capabilities.
119
131
  if (!isTempo(request))
120
- return viem_formatTransactionRequest(
121
- r as never,
122
- action,
123
- ) as TransactionRequestRpc
132
+ return {
133
+ ...viem_formatTransactionRequest(r as never, action),
134
+ ...(request.capabilities ? { capabilities: request.capabilities } : {}),
135
+ } as TransactionRequestRpc
124
136
 
125
137
  if (action)
126
138
  request.calls = request.calls ?? [