viem 3.0.0-next.12 → 3.0.0-next.13

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 (185) hide show
  1. package/dist/chains/definitions/creditCoin3Devnet.d.ts +6 -0
  2. package/dist/chains/definitions/creditCoin3Devnet.d.ts.map +1 -1
  3. package/dist/chains/definitions/creditCoin3Devnet.js +6 -0
  4. package/dist/chains/definitions/creditCoin3Devnet.js.map +1 -1
  5. package/dist/chains/definitions/creditCoin3Mainnet.d.ts +5 -1
  6. package/dist/chains/definitions/creditCoin3Mainnet.d.ts.map +1 -1
  7. package/dist/chains/definitions/creditCoin3Mainnet.js +4 -0
  8. package/dist/chains/definitions/creditCoin3Mainnet.js.map +1 -1
  9. package/dist/chains/definitions/creditCoin3Testnet.d.ts +5 -1
  10. package/dist/chains/definitions/creditCoin3Testnet.d.ts.map +1 -1
  11. package/dist/chains/definitions/creditCoin3Testnet.js +4 -0
  12. package/dist/chains/definitions/creditCoin3Testnet.js.map +1 -1
  13. package/dist/chains/definitions/crymad.d.ts +25 -0
  14. package/dist/chains/definitions/crymad.d.ts.map +1 -0
  15. package/dist/chains/definitions/crymad.js +23 -0
  16. package/dist/chains/definitions/crymad.js.map +1 -0
  17. package/dist/chains/definitions/crymadL2.d.ts +26 -0
  18. package/dist/chains/definitions/crymadL2.d.ts.map +1 -0
  19. package/dist/chains/definitions/crymadL2.js +24 -0
  20. package/dist/chains/definitions/crymadL2.js.map +1 -0
  21. package/dist/chains/definitions/kortana.d.ts +18 -0
  22. package/dist/chains/definitions/kortana.d.ts.map +1 -0
  23. package/dist/chains/definitions/kortana.js +16 -0
  24. package/dist/chains/definitions/kortana.js.map +1 -0
  25. package/dist/chains/index.d.ts +3 -0
  26. package/dist/chains/index.d.ts.map +1 -1
  27. package/dist/chains/index.js +3 -0
  28. package/dist/chains/index.js.map +1 -1
  29. package/dist/core/actions/wallet/sendCalls.d.ts.map +1 -1
  30. package/dist/core/actions/wallet/sendCalls.js +1 -0
  31. package/dist/core/actions/wallet/sendCalls.js.map +1 -1
  32. package/dist/erc4337/actions/userOperation/waitForReceipt.js +1 -1
  33. package/dist/erc4337/actions/userOperation/waitForReceipt.js.map +1 -1
  34. package/dist/node/transports/ipc.d.ts.map +1 -1
  35. package/dist/node/transports/ipc.js +20 -2
  36. package/dist/node/transports/ipc.js.map +1 -1
  37. package/dist/tempo/Abis.d.ts +778 -174
  38. package/dist/tempo/Abis.d.ts.map +1 -1
  39. package/dist/tempo/Abis.js +178 -37
  40. package/dist/tempo/Abis.js.map +1 -1
  41. package/dist/tempo/Capabilities.d.ts +7 -13
  42. package/dist/tempo/Capabilities.d.ts.map +1 -1
  43. package/dist/tempo/Client.d.ts +0 -5
  44. package/dist/tempo/Client.d.ts.map +1 -1
  45. package/dist/tempo/Client.js +3 -10
  46. package/dist/tempo/Client.js.map +1 -1
  47. package/dist/tempo/ExecutionError.d.ts +81 -0
  48. package/dist/tempo/ExecutionError.d.ts.map +1 -0
  49. package/dist/tempo/ExecutionError.js +309 -0
  50. package/dist/tempo/ExecutionError.js.map +1 -0
  51. package/dist/tempo/Relay.d.ts +303 -0
  52. package/dist/tempo/Relay.d.ts.map +1 -0
  53. package/dist/tempo/Relay.js +170 -0
  54. package/dist/tempo/Relay.js.map +1 -0
  55. package/dist/tempo/Selectors.d.ts +16 -5
  56. package/dist/tempo/Selectors.d.ts.map +1 -1
  57. package/dist/tempo/Selectors.js +16 -5
  58. package/dist/tempo/Selectors.js.map +1 -1
  59. package/dist/tempo/Transport.d.ts +11 -11
  60. package/dist/tempo/Transport.d.ts.map +1 -1
  61. package/dist/tempo/Transport.js +22 -51
  62. package/dist/tempo/Transport.js.map +1 -1
  63. package/dist/tempo/actions/token/burn.d.ts +38 -9
  64. package/dist/tempo/actions/token/burn.d.ts.map +1 -1
  65. package/dist/tempo/actions/token/burn.js +12 -5
  66. package/dist/tempo/actions/token/burn.js.map +1 -1
  67. package/dist/tempo/actions/token/burnSync.d.ts +2 -0
  68. package/dist/tempo/actions/token/burnSync.d.ts.map +1 -1
  69. package/dist/tempo/chainConfig.d.ts +4 -5
  70. package/dist/tempo/chainConfig.d.ts.map +1 -1
  71. package/dist/tempo/chainConfig.js +6 -1
  72. package/dist/tempo/chainConfig.js.map +1 -1
  73. package/dist/tempo/index.d.ts +5 -3
  74. package/dist/tempo/index.d.ts.map +1 -1
  75. package/dist/tempo/index.js +5 -3
  76. package/dist/tempo/index.js.map +1 -1
  77. package/dist/tempo/internal/relay/cache.d.ts +9 -0
  78. package/dist/tempo/internal/relay/cache.d.ts.map +1 -0
  79. package/dist/tempo/internal/relay/cache.js +72 -0
  80. package/dist/tempo/internal/relay/cache.js.map +1 -0
  81. package/dist/tempo/internal/relay/deadline.d.ts +4 -0
  82. package/dist/tempo/internal/relay/deadline.d.ts.map +1 -0
  83. package/dist/tempo/internal/relay/deadline.js +34 -0
  84. package/dist/tempo/internal/relay/deadline.js.map +1 -0
  85. package/dist/tempo/internal/relay/error.d.ts +47 -0
  86. package/dist/tempo/internal/relay/error.d.ts.map +1 -0
  87. package/dist/tempo/internal/relay/error.js +101 -0
  88. package/dist/tempo/internal/relay/error.js.map +1 -0
  89. package/dist/tempo/internal/relay/feePayer.d.ts +70 -0
  90. package/dist/tempo/internal/relay/feePayer.d.ts.map +1 -0
  91. package/dist/tempo/internal/relay/feePayer.js +442 -0
  92. package/dist/tempo/internal/relay/feePayer.js.map +1 -0
  93. package/dist/tempo/internal/relay/feeToken.d.ts +38 -0
  94. package/dist/tempo/internal/relay/feeToken.d.ts.map +1 -0
  95. package/dist/tempo/internal/relay/feeToken.js +143 -0
  96. package/dist/tempo/internal/relay/feeToken.js.map +1 -0
  97. package/dist/tempo/internal/relay/multisig.d.ts +4 -0
  98. package/dist/tempo/internal/relay/multisig.d.ts.map +1 -0
  99. package/dist/tempo/{Multisig.js → internal/relay/multisig.js} +134 -126
  100. package/dist/tempo/internal/relay/multisig.js.map +1 -0
  101. package/dist/tempo/internal/relay/plugin.d.ts +5 -0
  102. package/dist/tempo/internal/relay/plugin.d.ts.map +1 -0
  103. package/dist/tempo/internal/relay/plugin.js +10 -0
  104. package/dist/tempo/internal/relay/plugin.js.map +1 -0
  105. package/dist/tempo/internal/relay/preflight.d.ts +17 -0
  106. package/dist/tempo/internal/relay/preflight.d.ts.map +1 -0
  107. package/dist/tempo/internal/relay/preflight.js +53 -0
  108. package/dist/tempo/internal/relay/preflight.js.map +1 -0
  109. package/dist/tempo/internal/relay/request.d.ts +16 -0
  110. package/dist/tempo/internal/relay/request.d.ts.map +1 -0
  111. package/dist/tempo/internal/relay/request.js +327 -0
  112. package/dist/tempo/internal/relay/request.js.map +1 -0
  113. package/dist/tempo/internal/relay/simulate.d.ts +62 -0
  114. package/dist/tempo/internal/relay/simulate.d.ts.map +1 -0
  115. package/dist/tempo/internal/relay/simulate.js +284 -0
  116. package/dist/tempo/internal/relay/simulate.js.map +1 -0
  117. package/dist/tempo/internal/relay/utils.d.ts +346 -0
  118. package/dist/tempo/internal/relay/utils.d.ts.map +1 -0
  119. package/dist/tempo/internal/relay/utils.js +185 -0
  120. package/dist/tempo/internal/relay/utils.js.map +1 -0
  121. package/dist/tempo/internal/relay/virtualAddress.d.ts +9 -0
  122. package/dist/tempo/internal/relay/virtualAddress.d.ts.map +1 -0
  123. package/dist/tempo/internal/relay/virtualAddress.js +73 -0
  124. package/dist/tempo/internal/relay/virtualAddress.js.map +1 -0
  125. package/dist/tempo/internal/relay.d.ts +4 -0
  126. package/dist/tempo/internal/relay.d.ts.map +1 -0
  127. package/dist/tempo/internal/relay.js +132 -0
  128. package/dist/tempo/internal/relay.js.map +1 -0
  129. package/dist/tokens/definitions/ousd.d.ts +26 -0
  130. package/dist/tokens/definitions/ousd.d.ts.map +1 -0
  131. package/dist/tokens/definitions/ousd.js +26 -0
  132. package/dist/tokens/definitions/ousd.js.map +1 -0
  133. package/dist/tokens/index.d.ts +2 -0
  134. package/dist/tokens/index.d.ts.map +1 -1
  135. package/dist/tokens/index.js +2 -0
  136. package/dist/tokens/index.js.map +1 -1
  137. package/dist/tokens/sets.d.ts +33 -0
  138. package/dist/tokens/sets.d.ts.map +1 -1
  139. package/dist/tokens/sets.js +4 -1
  140. package/dist/tokens/sets.js.map +1 -1
  141. package/dist/version.d.ts +1 -1
  142. package/dist/version.js +1 -1
  143. package/package.json +1 -1
  144. package/src/chains/definitions/creditCoin3Devnet.ts +6 -0
  145. package/src/chains/definitions/creditCoin3Mainnet.ts +4 -0
  146. package/src/chains/definitions/creditCoin3Testnet.ts +4 -0
  147. package/src/chains/definitions/crymad.ts +23 -0
  148. package/src/chains/definitions/crymadL2.ts +24 -0
  149. package/src/chains/definitions/kortana.ts +16 -0
  150. package/src/chains/index.ts +3 -0
  151. package/src/core/actions/wallet/sendCalls.ts +1 -0
  152. package/src/erc4337/actions/userOperation/waitForReceipt.ts +1 -1
  153. package/src/node/transports/ipc.ts +17 -2
  154. package/src/tempo/Abis.ts +179 -37
  155. package/src/tempo/Account.ts +1 -1
  156. package/src/tempo/Capabilities.ts +7 -15
  157. package/src/tempo/Client.ts +3 -23
  158. package/src/tempo/ExecutionError.ts +428 -0
  159. package/src/tempo/Relay.ts +430 -0
  160. package/src/tempo/Selectors.ts +25 -11
  161. package/src/tempo/Transport.ts +71 -41
  162. package/src/tempo/actions/token/burn.ts +21 -9
  163. package/src/tempo/actions/token/burnSync.ts +2 -0
  164. package/src/tempo/chainConfig.ts +9 -6
  165. package/src/tempo/index.ts +7 -4
  166. package/src/tempo/internal/relay/cache.ts +82 -0
  167. package/src/tempo/internal/relay/deadline.ts +45 -0
  168. package/src/tempo/internal/relay/error.ts +129 -0
  169. package/src/tempo/internal/relay/feePayer.ts +693 -0
  170. package/src/tempo/internal/relay/feeToken.ts +190 -0
  171. package/src/tempo/{Multisig.ts → internal/relay/multisig.ts} +165 -193
  172. package/src/tempo/internal/relay/plugin.ts +13 -0
  173. package/src/tempo/internal/relay/preflight.ts +83 -0
  174. package/src/tempo/internal/relay/request.ts +401 -0
  175. package/src/tempo/internal/relay/simulate.ts +394 -0
  176. package/src/tempo/internal/relay/utils.ts +213 -0
  177. package/src/tempo/internal/relay/virtualAddress.ts +95 -0
  178. package/src/tempo/internal/relay.ts +149 -0
  179. package/src/tokens/definitions/ousd.ts +26 -0
  180. package/src/tokens/index.ts +2 -0
  181. package/src/tokens/sets.ts +4 -1
  182. package/src/version.ts +1 -1
  183. package/dist/tempo/Multisig.d.ts +0 -39
  184. package/dist/tempo/Multisig.d.ts.map +0 -1
  185. package/dist/tempo/Multisig.js.map +0 -1
@@ -0,0 +1,430 @@
1
+ import type { Address } from 'abitype'
2
+ import * as RpcResponse from 'ox/RpcResponse'
3
+ import type { Local as LocalAccount } from '../core/Account.js'
4
+ import type { Client as Client_ } from '../core/Client.js'
5
+ import { ChainNotConfiguredError } from '../core/Client.js'
6
+ import type * as Transport from '../core/Transport.js'
7
+ import * as Sponsorship from './internal/relay/feePayer.js'
8
+ import * as FeeToken from './internal/relay/feeToken.js'
9
+ import * as Multisig from './internal/relay/multisig.js'
10
+ import * as Request_ from './internal/relay/request.js'
11
+ import * as Simulate from './internal/relay/simulate.js'
12
+ import * as internal from './internal/relay.js'
13
+ import type * as Store from './Store.js'
14
+
15
+ type EIP1193RequestOptions = NonNullable<Parameters<Transport.RequestFn>[1]>
16
+
17
+ /**
18
+ * Creates a relay with RPC and Fetch handlers backed by a client or chain resolver.
19
+ *
20
+ * Pass a chain-configured `client` for a single chain, or `getClient` for multiple
21
+ * chains. Plugins may resolve the chain before forwarding to the selected client.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { Client, http } from 'viem'
26
+ * import { tempo } from 'viem/chains'
27
+ * import { Relay } from 'viem/tempo'
28
+ *
29
+ * const relay = Relay.create({
30
+ * client: Client.create({ chain: tempo, transport: http() }),
31
+ * })
32
+ * export default { fetch: relay.fetch }
33
+ * ```
34
+ *
35
+ * @param options - Client selection and relay plugins.
36
+ * @returns RPC and Fetch handlers sharing the same plugins.
37
+ */
38
+ export function create<const chainId extends number>(
39
+ options: handleRequest.Options & {
40
+ client: Client & { chain: { id: chainId } }
41
+ getClient?: never
42
+ },
43
+ ): create.ReturnType<chainId>
44
+ export function create<const chainId extends number = number>(
45
+ options: handleRequest.Options & {
46
+ client?: never
47
+ getClient: (options: { chainId: chainId }) => Client
48
+ },
49
+ ): create.ReturnType<chainId>
50
+ export function create<getClient extends (options: never) => Client>(
51
+ options: handleRequest.Options & { client?: never; getClient: getClient },
52
+ ): create.ReturnType<
53
+ Parameters<getClient>[0] extends { chainId: infer chainId extends number }
54
+ ? chainId
55
+ : number
56
+ >
57
+ export function create(
58
+ options: handleRequest.Options & {
59
+ client?: Client | undefined
60
+ getClient?: ((options: never) => Client) | undefined
61
+ },
62
+ ): create.ReturnType {
63
+ if (Boolean(options.client) === Boolean(options.getClient))
64
+ throw new RpcResponse.InvalidParamsError({
65
+ message: 'Expected exactly one of client or getClient.',
66
+ })
67
+ const clientChainId = options.client?.chain?.id
68
+ if (
69
+ options.client &&
70
+ (!Number.isSafeInteger(clientChainId) ||
71
+ !clientChainId ||
72
+ clientChainId <= 0)
73
+ )
74
+ throw new RpcResponse.InvalidParamsError({
75
+ message: 'Expected a client with a configured chain.',
76
+ })
77
+
78
+ const getClient = (chainId: number) => {
79
+ try {
80
+ const client = options.client ?? options.getClient!({ chainId } as never)
81
+ if (client.chain.id !== chainId)
82
+ throw new RpcResponse.InvalidParamsError({
83
+ message: 'Conflicting chain ids.',
84
+ })
85
+ return client
86
+ } catch (error) {
87
+ if (error instanceof ChainNotConfiguredError)
88
+ throw new RpcResponse.InvalidParamsError({
89
+ message: error.shortMessage,
90
+ })
91
+ throw error
92
+ }
93
+ }
94
+ const handle = Request_.compose(
95
+ async (request, requestOptions) => {
96
+ const { chainId, response: _, ...rest } = requestOptions ?? {}
97
+ if (chainId === undefined)
98
+ throw new RpcResponse.InvalidParamsError({
99
+ message: 'A chain ID is required to resolve the downstream client.',
100
+ })
101
+ return getClient(chainId).request(request as never, rest)
102
+ },
103
+ options,
104
+ getClient,
105
+ )
106
+
107
+ const request: handleRequest.Handler = (request, requestOptions) => {
108
+ const chainId = requestOptions?.chainId ?? clientChainId
109
+ if (
110
+ chainId !== undefined &&
111
+ (!Number.isSafeInteger(chainId) || chainId <= 0)
112
+ )
113
+ return Promise.reject(
114
+ new RpcResponse.InvalidParamsError({
115
+ message: 'Expected a valid chain ID.',
116
+ }),
117
+ )
118
+ if (clientChainId !== undefined && chainId !== clientChainId)
119
+ return Promise.reject(
120
+ new RpcResponse.InvalidParamsError({
121
+ message: 'Conflicting chain ids.',
122
+ }),
123
+ )
124
+ return handle(request, { ...requestOptions, chainId })
125
+ }
126
+ return {
127
+ request,
128
+ fetch: (request_, options: create.RequestOptions = {}) =>
129
+ internal.fetch(request_, request, options),
130
+ }
131
+ }
132
+
133
+ export declare namespace create {
134
+ /** Client selection and middleware for a relay. */
135
+ export type Options<chainId extends number = number> = handleRequest.Options &
136
+ (
137
+ | {
138
+ /** Chain-configured client used for every forwarded request. */
139
+ client: Client & { chain: { id: chainId } }
140
+ getClient?: never
141
+ }
142
+ | {
143
+ client?: never
144
+ /** Resolves the client after plugins have selected the request's chain. */
145
+ getClient: (options: {
146
+ chainId: chainId
147
+ }) => Client & { chain: { id: number } }
148
+ }
149
+ )
150
+
151
+ /** Optional chain selection and RPC request options. */
152
+ export type RequestOptions<chainId extends number = number> = Omit<
153
+ handleRequest.RequestOptions,
154
+ 'chainId'
155
+ > & { chainId?: chainId | undefined }
156
+
157
+ /** Handlers sharing one composed relay pipeline. */
158
+ export type ReturnType<chainId extends number = number> = {
159
+ /** Handles a POST JSON-RPC request, returning JSON or an empty 204 for notifications. */
160
+ fetch: {
161
+ (request: Request): Promise<Response>
162
+ (
163
+ request: Request,
164
+ options?: RequestOptions<chainId> | undefined,
165
+ ): Promise<Response>
166
+ }
167
+ /** Handles a parsed RPC call and returns its result. */
168
+ request: (
169
+ request: handleRequest.Request,
170
+ options?: RequestOptions<chainId> | undefined,
171
+ ) => Promise<unknown>
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Creates an RPC request handler by composing relay plugins around a downstream handler.
177
+ *
178
+ * Requests enter plugins in array order, and responses return in reverse order.
179
+ * Post-fill hooks run concurrently after middleware finishes. Middleware sees
180
+ * the downstream result before post-fill enrichment and signing.
181
+ * Without plugins, the downstream handler is returned unchanged. Plugins decide
182
+ * whether to forward, transform, or handle a request. Errors propagate unchanged
183
+ * unless a plugin handles them.
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * import { http } from 'viem'
188
+ * import { Relay } from 'viem/tempo'
189
+ *
190
+ * const rpc = http('https://rpc.tempo.xyz').setup()
191
+ * const handle = Relay.handleRequest(rpc.request, {
192
+ * plugins: [
193
+ * {
194
+ * async handleRequest(context, next) {
195
+ * context.options.retryCount = 0
196
+ * await next()
197
+ * },
198
+ * },
199
+ * ],
200
+ * })
201
+ * const chainId = await handle({ method: 'eth_chainId' })
202
+ * // @log: '0x1079'
203
+ * ```
204
+ *
205
+ * @param next - Downstream RPC request handler, typically forwarding to the Tempo (Execution) RPC.
206
+ * @param options - Relay options.
207
+ * @returns The composed RPC request handler.
208
+ */
209
+ export function handleRequest(
210
+ next: handleRequest.Handler,
211
+ options: handleRequest.Options = {},
212
+ ): handleRequest.Handler {
213
+ return Request_.compose(next, options)
214
+ }
215
+
216
+ export declare namespace handleRequest {
217
+ /** RPC request handler shared by relay plugins and the downstream execution RPC. */
218
+ export type Handler = (
219
+ request: Request,
220
+ options?: RequestOptions | undefined,
221
+ ) => Promise<unknown>
222
+
223
+ /** Options for {@link handleRequest}. */
224
+ export type Options = {
225
+ /** Plugins in request execution order. Defaults to an empty list. */
226
+ plugins?: readonly Plugin[] | undefined
227
+ /** Fee-token candidates shared by all plugins, memoized per request and chain. */
228
+ resolveTokens?:
229
+ | ((chainId: number) => readonly Address[] | Promise<readonly Address[]>)
230
+ | undefined
231
+ /** Deadline in milliseconds for a plugin-handled fill, including callbacks. Defaults to 10,000. */
232
+ timeout?: number | undefined
233
+ }
234
+
235
+ /** RPC request passed to a handler. */
236
+ export type Request = {
237
+ /** RPC method name. */
238
+ method: string
239
+ /** RPC method parameters. */
240
+ params?: readonly unknown[] | undefined
241
+ }
242
+
243
+ /** Options for one handled request. */
244
+ export type RequestOptions = EIP1193RequestOptions & {
245
+ /** Chain selected by the caller or resolved by a plugin. */
246
+ chainId?: number | undefined
247
+ /** Response metadata collected by the Fetch adapter. */
248
+ response?:
249
+ | { sponsorship_details?: Sponsorship.SponsorshipDetails | undefined }
250
+ | undefined
251
+ }
252
+ }
253
+
254
+ /** Hooks extending relay request processing and filled transaction responses. */
255
+ export type Plugin = {
256
+ /** Processes an RPC request. Await next(), then read or replace context.result. */
257
+ handleRequest?:
258
+ | ((context: Plugin.Context, next: () => Promise<void>) => Promise<unknown>)
259
+ | undefined
260
+ /** Runs concurrently after the final fill. Returns capability fields to merge. */
261
+ afterFill?:
262
+ | ((
263
+ filled: Plugin.FillResult,
264
+ context: Plugin.Context,
265
+ ) => Promise<Plugin.Enrichment | undefined>)
266
+ | undefined
267
+ /** Signs the final fill concurrently with enrichment. Only one signer may be registered. */
268
+ signTransaction?:
269
+ | ((
270
+ filled: Plugin.FillResult,
271
+ context: Plugin.Context,
272
+ ) => Promise<Plugin.Signature | undefined>)
273
+ | undefined
274
+ }
275
+
276
+ export declare namespace Plugin {
277
+ /** State and services isolated to one RPC invocation. */
278
+ export type Context = {
279
+ /** Current RPC request. Changes are passed to next(). */
280
+ request: handleRequest.Request
281
+ /** Downstream result, populated by next(). */
282
+ result: unknown
283
+ /** Transport options and selected chain. */
284
+ options: handleRequest.RequestOptions
285
+ /** Downstream client for the selected chain. */
286
+ readonly client: Client_
287
+ /** Gets a downstream client for the selected or specified chain. */
288
+ getClient: (chainId?: number) => Client_
289
+ /** Gets the shared token candidates for the selected or specified chain. */
290
+ resolveTokens: (chainId?: number) => Promise<readonly Address[]>
291
+ /** Scopes a configured store to this invocation. */
292
+ getStore: (store: Store.Store | undefined) => Store.Store | undefined
293
+ }
294
+ /** Immutable RPC fill supplied to post-fill hooks. */
295
+ export type FillResult = {
296
+ readonly tx: Readonly<Record<string, unknown>>
297
+ readonly capabilities?: Readonly<Record<string, unknown>> | undefined
298
+ readonly sponsor?: unknown
299
+ }
300
+ /** Additional response capabilities. Duplicate keys from hooks are rejected. */
301
+ export type Enrichment = {
302
+ capabilities?: Record<string, unknown> | undefined
303
+ }
304
+ /** Fee-payer signature in RPC format. */
305
+ export type Signature = {
306
+ r: `0x${string}`
307
+ s: `0x${string}`
308
+ yParity: `0x${string}`
309
+ }
310
+ }
311
+
312
+ declare const multisigBrand: unique symbol
313
+
314
+ /**
315
+ * Coordinates native multisig approvals using shared atomic storage.
316
+ *
317
+ * Memory storage is process-local. Independent clients and multiple server
318
+ * instances must use the same persistent store to share pending approvals.
319
+ *
320
+ * @example
321
+ * ```ts
322
+ * import { http } from 'viem'
323
+ * import { Relay, Store, withRelay } from 'viem/tempo'
324
+ *
325
+ * const transport = withRelay(http(), {
326
+ * plugins: [Relay.multisig({ store: Store.memory() })],
327
+ * })
328
+ * ```
329
+ *
330
+ * @param options - Shared atomic storage.
331
+ * @returns A plugin that coordinates multisig requests and forwards other calls.
332
+ */
333
+ export function multisig(options: multisig.Options): multisig.ReturnType {
334
+ return Multisig.create(options)
335
+ }
336
+
337
+ export declare namespace multisig {
338
+ /** Multisig coordination options. */
339
+ export type Options = {
340
+ /** Store shared by multisig coordinators, with atomic compare-and-set support. */
341
+ store: Store.Atomic
342
+ }
343
+ /** Middleware advertising native multisig coordination. */
344
+ export type ReturnType = Plugin & { readonly [multisigBrand]: true }
345
+ }
346
+
347
+ /**
348
+ * Sponsors transactions with a local account or an external fee-payer relay.
349
+ *
350
+ * Place multisig before this plugin and fee-token selection after it.
351
+ *
352
+ * @example
353
+ * ```ts
354
+ * import { Account } from 'viem'
355
+ * import { Relay } from 'viem/tempo'
356
+ * const plugin = Relay.feePayer({ account: Account.fromPrivateKey('0x...') })
357
+ * ```
358
+ * @param options - Sponsor account, policy, and display metadata.
359
+ * @returns A fee-payer relay plugin.
360
+ */
361
+ export function feePayer(options: feePayer.Options = {}): Plugin {
362
+ return Sponsorship.create(options)
363
+ }
364
+
365
+ export declare namespace feePayer {
366
+ /** Fee sponsorship configuration. */
367
+ export type Options = {
368
+ /** Local sponsor. Omit when requests use an external fee-payer URL. */
369
+ account?: LocalAccount | undefined
370
+ /** Trusted external fee-payer URLs. Matches the normalized full URL, including path and query. Defaults to none. */
371
+ allowedFeePayers?: readonly string[] | undefined
372
+ /** Sponsor's preferred fee token. Overrides the request token on sponsored fills. */
373
+ feeToken?: Address | undefined
374
+ /** Allow HTTP and private external relay hosts in trusted development environments. @default false */
375
+ internal_allowUnsafeUrls?: boolean | undefined
376
+ /** Display name returned in sponsor capabilities. */
377
+ name?: string | undefined
378
+ /** Called after signing and before returning or broadcasting. A thrown error aborts sponsorship. */
379
+ onSponsored?: Sponsorship.sign.Options['onSponsored'] | undefined
380
+ /** Sponsor display URL. */
381
+ url?: string | undefined
382
+ /** Only `true` authorizes sponsorship. Rejected fills fall back to sender-paid transactions. */
383
+ validate?: Sponsorship.Validate | undefined
384
+ }
385
+ /** Result of a sponsorship policy check. */
386
+ export type Validation = Sponsorship.Validation
387
+ /** Facts passed to the sponsorship callback. */
388
+ export type SponsoredEvent = Sponsorship.SponsoredEvent
389
+ }
390
+
391
+ /**
392
+ * Resolves fee tokens from user preferences, balances, and available fee AMM liquidity.
393
+ *
394
+ * @example
395
+ * ```ts
396
+ * import { Relay } from 'viem/tempo'
397
+ * const plugin = Relay.feeToken()
398
+ * ```
399
+ * @returns A fee-token relay plugin.
400
+ */
401
+ export function feeToken(): Plugin {
402
+ return FeeToken.create()
403
+ }
404
+
405
+ /**
406
+ * Adds balance changes, estimated fees, and execution errors to fill capabilities.
407
+ *
408
+ * Runs after transaction middleware to simulate the final filled result.
409
+ *
410
+ * @example
411
+ * ```ts
412
+ * import { Relay } from 'viem/tempo'
413
+ * const plugin = Relay.simulate()
414
+ * ```
415
+ * @param options - Optional metadata store.
416
+ * @returns A simulation relay plugin.
417
+ */
418
+ export function simulate(options: simulate.Options = {}): Plugin {
419
+ return Simulate.create(options)
420
+ }
421
+
422
+ export declare namespace simulate {
423
+ /** Simulation configuration. */
424
+ export type Options = {
425
+ /** Store for cached metadata. Omit to read metadata for each request. */
426
+ store?: Store.Store | undefined
427
+ }
428
+ }
429
+
430
+ type Client = Pick<Client_, 'request'> & { chain: { id: number } }
@@ -186,6 +186,7 @@ export const tip20Factory = {
186
186
 
187
187
  /** Function selectors of the TIP-20 token interface. */
188
188
  export const tip20 = {
189
+ BURN_AT_ROLE: '0xc6990381',
189
190
  BURN_BLOCKED_ROLE: '0x32ad9be8',
190
191
  DOMAIN_SEPARATOR: '0x3644e515',
191
192
  ISSUER_ROLE: '0x82aefa24',
@@ -195,6 +196,7 @@ export const tip20 = {
195
196
  approve: '0x095ea7b3',
196
197
  balanceOf: '0x70a08231',
197
198
  burn: '0x42966c68',
199
+ burnAt: '0x9803f216',
198
200
  burnBlocked: '0xec0cf3dc',
199
201
  burnWithMemo: '0x38f23b0b',
200
202
  changeTransferPolicyId: '0xfd5e9420',
@@ -317,14 +319,8 @@ export const zoneFactory = {
317
319
  OverloadedFunctionSelectors<'createZone'>
318
320
 
319
321
  export const zoneVerifier = {
320
- verify: {
321
- 'verify(uint32,uint64,uint64,bytes32,uint64,(bytes32,bytes32),(bytes32,bytes32,uint64,uint64),bytes32,bytes,bytes)':
322
- '0x7106a43e',
323
- 'verify(uint32,uint64,uint64,bytes32,uint64,uint256,(bytes32,bytes32),(bytes32,bytes32,uint64,uint64),(uint64,uint64),bytes32,bytes,bytes)':
324
- '0xebb2ddc9',
325
- },
326
- } as const satisfies FunctionSelectors<typeof Abis.zoneVerifier, 'verify'> &
327
- OverloadedFunctionSelectors<'verify'>
322
+ verify: '0xebb2ddc9',
323
+ } as const satisfies FunctionSelectors<typeof Abis.zoneVerifier>
328
324
 
329
325
  export const zonePortal = {
330
326
  FIXED_DEPOSIT_GAS: '0xf706cfbf',
@@ -332,6 +328,8 @@ export const zonePortal = {
332
328
  MAX_GAS_FEE_RATE: '0xf490ca96',
333
329
  MAX_TOKENS_ENABLED_PER_TEMPO_BLOCK: '0x3fcf7df4',
334
330
  MAX_TOKEN_METADATA_BYTES: '0x996329a2',
331
+ MAX_UNPROCESSED_DEPOSITS: '0x5e53dcd3',
332
+ MAX_UNPROCESSED_TOKEN_ENABLEMENTS: '0x3b667e74',
335
333
  MAX_WITHDRAWAL_GAS_LIMIT: '0x86f47e55',
336
334
  abdicate: '0xbf4c5411',
337
335
  abdicationEffectiveAt: '0x04a3b098',
@@ -366,6 +364,7 @@ export const zonePortal = {
366
364
  isSequencer: '0x6d46e987',
367
365
  isTokenEnabled: '0x748538d9',
368
366
  lastProcessedDepositNumber: '0xe84abe69',
367
+ lastProcessedEnabledTokenCount: '0xccd537ca',
369
368
  lastSyncedTempoBlockNumber: '0xbe2a63ee',
370
369
  leader: '0x40eedabb',
371
370
  leaderActivationTempoBlock: '0xb83c755f',
@@ -399,8 +398,14 @@ export const zonePortal = {
399
398
  setSequencerEncryptionKey: '0xef10b187',
400
399
  setSequencerSet: '0x86012b45',
401
400
  setZoneGasRate: '0x0e86bbdc',
402
- submitBatch: '0x78fb159b',
401
+ submitBatch: {
402
+ 'submitBatch(uint64,uint64,(bytes32,bytes32),(bytes32,bytes32,uint64,uint64),(uint64,uint64),bytes32,bytes,bytes,uint256,bytes[])':
403
+ '0x4cd6c7c7',
404
+ 'submitBatch(uint64,uint64,(bytes32,bytes32),(bytes32,bytes32,uint64,uint64),bytes32,bytes,bytes,uint256,bytes[])':
405
+ '0x78fb159b',
406
+ },
403
407
  tokenConfig: '0xfe136c4e',
408
+ tokenEnablementCursorInitialized: '0x370ddf99',
404
409
  tokenEnablementHash: '0xb456c0dd',
405
410
  transferAdmin: '0x75829def',
406
411
  verifier: '0x2b7ac3f3',
@@ -411,8 +416,17 @@ export const zonePortal = {
411
416
  zoneGasRate: '0xecf79a4e',
412
417
  zoneHeight: '0x430f8b4f',
413
418
  zoneId: '0xd179978a',
414
- } as const satisfies FunctionSelectors<typeof Abis.zonePortal, 'deposit'> &
415
- OverloadedFunctionSelectors<'deposit'>
419
+ } as const satisfies FunctionSelectors<
420
+ typeof Abis.zonePortal,
421
+ 'deposit' | 'submitBatch'
422
+ > &
423
+ OverloadedFunctionSelectors<'deposit' | 'submitBatch'>
424
+
425
+ export const zonePortalPreT13Retired = {
426
+ MAX_DEPOSITS_PER_TEMPO_BLOCK: '0x1bf00ca8',
427
+ MAX_TOKENS_ENABLED_PER_TEMPO_BLOCK: '0x3fcf7df4',
428
+ submitBatch: '0x78fb159b',
429
+ } as const satisfies FunctionSelectors<typeof Abis.zonePortalPreT13Retired>
416
430
 
417
431
  export const zoneOutbox = {
418
432
  AUTHENTICATED_WITHDRAWAL_CIPHERTEXT_LENGTH: '0x43c3cb83',
@@ -4,7 +4,9 @@ import { TxEnvelopeTempo } from 'ox/tempo'
4
4
  import { RpcResponse } from 'ox'
5
5
  import * as Transport from '../core/Transport.js'
6
6
  import { http as http_ } from '../core/transports/http.js'
7
- import * as Multisig from './Multisig.js'
7
+ import * as Plugin from './internal/relay/plugin.js'
8
+ import * as Request from './internal/relay/request.js'
9
+ import type * as Relay_ from './Relay.js'
8
10
  import * as Store from './Store.js'
9
11
 
10
12
  /** A relay {@link Transport.Transport}: routes fee sponsorship traffic to a relay (fee payer service). */
@@ -44,17 +46,55 @@ export type Relay = Transport.Transport<'relay', { multisig: true }>
44
46
  * @param options - Options.
45
47
  * @returns A relay transport.
46
48
  */
49
+ export function withRelay<
50
+ transport extends Transport.Transport,
51
+ const plugins extends readonly Relay_.Plugin[] = readonly [],
52
+ >(
53
+ defaultTransport: transport,
54
+ options: withRelay.LocalOptions<plugins>,
55
+ ): withRelay.LocalReturnValue<transport, plugins>
47
56
  export function withRelay(
48
57
  defaultTransport: Transport.Transport,
49
58
  relayTransport: Transport.Transport,
59
+ options?: withRelay.Options,
60
+ ): Relay
61
+ export function withRelay(
62
+ defaultTransport: Transport.Transport,
63
+ relayTransport: Transport.Transport | withRelay.LocalOptions,
50
64
  options: withRelay.Options = {},
51
- ): Relay {
65
+ ): Transport.Transport {
66
+ if (!('setup' in relayTransport))
67
+ return {
68
+ ...defaultTransport,
69
+ setup(config = {}) {
70
+ const transport = defaultTransport.setup(config)
71
+ const request = Request.compose(
72
+ (request, options) => transport.request(request, options),
73
+ relayTransport,
74
+ config.chain ? () => ({ chain: config.chain! }) : undefined,
75
+ )
76
+ return {
77
+ ...transport,
78
+ request: ((request_, options) =>
79
+ request(request_ as Relay_.handleRequest.Request, {
80
+ chainId: config.chain?.id,
81
+ ...options,
82
+ })) as typeof transport.request,
83
+ ...(relayTransport.plugins?.some((plugin) =>
84
+ Plugin.isMultisig(plugin),
85
+ )
86
+ ? { multisig: true }
87
+ : {}),
88
+ }
89
+ },
90
+ }
91
+
52
92
  const { policy = 'sign-only' } = options
53
93
  return Transport.from({
54
94
  key: options.key ?? 'relay',
55
95
  name: options.name ?? 'Relay Proxy',
56
96
  type: 'relay',
57
- setup({ chain, retryCount, timeout }) {
97
+ setup({ chain, timeout }) {
58
98
  const transport = defaultTransport.setup({
59
99
  chain,
60
100
  retryCount: 0,
@@ -65,7 +105,7 @@ export function withRelay(
65
105
  return {
66
106
  multisig: true as const,
67
107
  methods: options.methods,
68
- retryCount: options.retryCount ?? retryCount,
108
+ retryCount: 0,
69
109
  retryDelay: options.retryDelay,
70
110
  async request(args, opts) {
71
111
  const { method, params } = args
@@ -166,6 +206,33 @@ export function withRelay(
166
206
  }
167
207
 
168
208
  export declare namespace withRelay {
209
+ /** Plugins applied directly to the default transport. */
210
+ type LocalOptions<
211
+ plugins extends readonly Relay_.Plugin[] = readonly Relay_.Plugin[],
212
+ > = Pick<Relay_.handleRequest.Options, 'resolveTokens'> & {
213
+ /** Ordered relay plugins. Defaults to an empty list. */
214
+ plugins?: plugins | undefined
215
+ }
216
+ /** Wrapped transport preserving its attributes and RPC schema. */
217
+ type LocalReturnValue<
218
+ transport extends Transport.Transport,
219
+ plugins extends readonly Relay_.Plugin[] = readonly [],
220
+ > =
221
+ transport extends Transport.Transport<
222
+ infer type,
223
+ infer properties,
224
+ infer request
225
+ >
226
+ ? Transport.Transport<
227
+ type,
228
+ properties &
229
+ (Extract<plugins[number], Relay_.multisig.ReturnType> extends never
230
+ ? {}
231
+ : { multisig: true }),
232
+ request
233
+ >
234
+ : never
235
+
169
236
  type Options = {
170
237
  /** Transport key. @default 'relay' */
171
238
  key?: string | undefined
@@ -265,40 +332,3 @@ export declare namespace http {
265
332
  store?: Store.Store | undefined
266
333
  }
267
334
  }
268
-
269
- /** Wraps a transport with native multisig approval coordination. */
270
- export function withMultisig<transport extends Transport.Transport>(
271
- transport: transport,
272
- options: Multisig.handleRequest.Parameters,
273
- ): withMultisig.ReturnValue<transport> {
274
- return {
275
- ...transport,
276
- setup(parameters = {}) {
277
- const value = transport.setup(parameters)
278
- return {
279
- ...value,
280
- multisig: true,
281
- request: Multisig.handleRequest(
282
- (request, options) => value.request(request, options),
283
- options,
284
- ),
285
- }
286
- },
287
- } as unknown as withMultisig.ReturnValue<transport>
288
- }
289
-
290
- export declare namespace withMultisig {
291
- /** Parameters for multisig coordination. */
292
- type Options = Multisig.handleRequest.Parameters
293
- /** Wrapped transport with multisig coordination metadata. */
294
- type ReturnValue<
295
- transport extends Transport.Transport = Transport.Transport,
296
- > =
297
- transport extends Transport.Transport<
298
- infer type,
299
- infer properties,
300
- infer request
301
- >
302
- ? Transport.Transport<type, properties & { multisig: true }, request>
303
- : never
304
- }