viem 2.56.9 → 2.57.0
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/CHANGELOG.md +40 -0
- package/_cjs/actions/public/waitForTransactionReceipt.js +12 -1
- package/_cjs/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/_cjs/chains/definitions/blockdag.js +23 -0
- package/_cjs/chains/definitions/blockdag.js.map +1 -0
- package/_cjs/chains/definitions/candyChain.js +29 -0
- package/_cjs/chains/definitions/candyChain.js.map +1 -0
- package/_cjs/chains/definitions/creditCoin3Devnet.js +6 -0
- package/_cjs/chains/definitions/creditCoin3Devnet.js.map +1 -1
- package/_cjs/chains/definitions/creditCoin3Mainnet.js +6 -0
- package/_cjs/chains/definitions/creditCoin3Mainnet.js.map +1 -1
- package/_cjs/chains/definitions/creditCoin3Testnet.js +6 -0
- package/_cjs/chains/definitions/creditCoin3Testnet.js.map +1 -1
- package/_cjs/chains/definitions/kortana.js +23 -0
- package/_cjs/chains/definitions/kortana.js.map +1 -0
- package/_cjs/chains/index.js +20 -14
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/clients/createClientResolver.js +45 -0
- package/_cjs/clients/createClientResolver.js.map +1 -0
- package/_cjs/errors/version.js +1 -1
- package/_cjs/index.js +13 -9
- package/_cjs/index.js.map +1 -1
- package/_cjs/op-stack/actions/getGame.js +1 -1
- package/_cjs/op-stack/actions/getGame.js.map +1 -1
- package/_cjs/op-stack/actions/getGames.js +1 -1
- package/_cjs/op-stack/actions/getGames.js.map +1 -1
- package/_cjs/op-stack/actions/getTimeToNextGame.js +1 -1
- package/_cjs/op-stack/actions/getTimeToNextGame.js.map +1 -1
- package/_cjs/op-stack/actions/getTimeToNextL2Output.js +1 -1
- package/_cjs/op-stack/actions/getTimeToNextL2Output.js.map +1 -1
- package/_cjs/tempo/Client.js +2 -10
- package/_cjs/tempo/Client.js.map +1 -1
- package/_cjs/tempo/ExecutionError.js +290 -0
- package/_cjs/tempo/ExecutionError.js.map +1 -0
- package/_cjs/tempo/Relay.js +88 -0
- package/_cjs/tempo/Relay.js.map +1 -0
- package/_cjs/tempo/Transaction.js.map +1 -1
- package/_cjs/tempo/Transport.js +21 -12
- package/_cjs/tempo/Transport.js.map +1 -1
- package/_cjs/tempo/chainConfig.js +3 -0
- package/_cjs/tempo/chainConfig.js.map +1 -1
- package/_cjs/tempo/index.js +3 -3
- package/_cjs/tempo/index.js.map +1 -1
- package/_cjs/tempo/internal/relay/cache.js +74 -0
- package/_cjs/tempo/internal/relay/cache.js.map +1 -0
- package/_cjs/tempo/internal/relay/deadline.js +35 -0
- package/_cjs/tempo/internal/relay/deadline.js.map +1 -0
- package/_cjs/tempo/internal/relay/error.js +102 -0
- package/_cjs/tempo/internal/relay/error.js.map +1 -0
- package/_cjs/tempo/internal/relay/feePayer.js +426 -0
- package/_cjs/tempo/internal/relay/feePayer.js.map +1 -0
- package/_cjs/tempo/internal/relay/feeToken.js +143 -0
- package/_cjs/tempo/internal/relay/feeToken.js.map +1 -0
- package/_cjs/tempo/{Multisig.js → internal/relay/multisig.js} +132 -122
- package/_cjs/tempo/internal/relay/multisig.js.map +1 -0
- package/_cjs/tempo/internal/relay/plugin.js +13 -0
- package/_cjs/tempo/internal/relay/plugin.js.map +1 -0
- package/_cjs/tempo/internal/relay/preflight.js +58 -0
- package/_cjs/tempo/internal/relay/preflight.js.map +1 -0
- package/_cjs/tempo/internal/relay/request.js +319 -0
- package/_cjs/tempo/internal/relay/request.js.map +1 -0
- package/_cjs/tempo/internal/relay/simulate.js +267 -0
- package/_cjs/tempo/internal/relay/simulate.js.map +1 -0
- package/_cjs/tempo/internal/relay/utils.js +174 -0
- package/_cjs/tempo/internal/relay/utils.js.map +1 -0
- package/_cjs/tempo/internal/relay/virtualAddress.js +78 -0
- package/_cjs/tempo/internal/relay/virtualAddress.js.map +1 -0
- package/_cjs/tempo/internal/relay.js +139 -0
- package/_cjs/tempo/internal/relay.js.map +1 -0
- package/_cjs/tempo/multisig/Config.js +0 -2
- package/_cjs/tempo/multisig/Config.js.map +1 -1
- package/_cjs/tempo/multisig/Operation.js +1 -2
- package/_cjs/tempo/multisig/Operation.js.map +1 -1
- package/_cjs/utils/siwe/parseSiweMessage.js +3 -3
- package/_cjs/utils/siwe/parseSiweMessage.js.map +1 -1
- package/_esm/actions/public/waitForTransactionReceipt.js +15 -1
- package/_esm/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/_esm/chains/definitions/blockdag.js +20 -0
- package/_esm/chains/definitions/blockdag.js.map +1 -0
- package/_esm/chains/definitions/candyChain.js +26 -0
- package/_esm/chains/definitions/candyChain.js.map +1 -0
- package/_esm/chains/definitions/creditCoin3Devnet.js +6 -0
- package/_esm/chains/definitions/creditCoin3Devnet.js.map +1 -1
- package/_esm/chains/definitions/creditCoin3Mainnet.js +6 -0
- package/_esm/chains/definitions/creditCoin3Mainnet.js.map +1 -1
- package/_esm/chains/definitions/creditCoin3Testnet.js +6 -0
- package/_esm/chains/definitions/creditCoin3Testnet.js.map +1 -1
- package/_esm/chains/definitions/kortana.js +20 -0
- package/_esm/chains/definitions/kortana.js.map +1 -0
- package/_esm/chains/index.js +3 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/clients/createClientResolver.js +64 -0
- package/_esm/clients/createClientResolver.js.map +1 -0
- package/_esm/errors/version.js +1 -1
- package/_esm/index.js +2 -0
- package/_esm/index.js.map +1 -1
- package/_esm/op-stack/actions/getGame.js +1 -1
- package/_esm/op-stack/actions/getGame.js.map +1 -1
- package/_esm/op-stack/actions/getGames.js +1 -1
- package/_esm/op-stack/actions/getGames.js.map +1 -1
- package/_esm/op-stack/actions/getTimeToNextGame.js +2 -2
- package/_esm/op-stack/actions/getTimeToNextGame.js.map +1 -1
- package/_esm/op-stack/actions/getTimeToNextL2Output.js +2 -2
- package/_esm/op-stack/actions/getTimeToNextL2Output.js.map +1 -1
- package/_esm/tempo/Client.js +8 -14
- package/_esm/tempo/Client.js.map +1 -1
- package/_esm/tempo/ExecutionError.js +306 -0
- package/_esm/tempo/ExecutionError.js.map +1 -0
- package/_esm/tempo/Relay.js +170 -0
- package/_esm/tempo/Relay.js.map +1 -0
- package/_esm/tempo/Transaction.js.map +1 -1
- package/_esm/tempo/Transport.js +21 -46
- package/_esm/tempo/Transport.js.map +1 -1
- package/_esm/tempo/chainConfig.js +4 -0
- package/_esm/tempo/chainConfig.js.map +1 -1
- package/_esm/tempo/index.js +8 -3
- package/_esm/tempo/index.js.map +1 -1
- package/_esm/tempo/internal/relay/cache.js +72 -0
- package/_esm/tempo/internal/relay/cache.js.map +1 -0
- package/_esm/tempo/internal/relay/deadline.js +34 -0
- package/_esm/tempo/internal/relay/deadline.js.map +1 -0
- package/_esm/tempo/internal/relay/error.js +101 -0
- package/_esm/tempo/internal/relay/error.js.map +1 -0
- package/_esm/tempo/internal/relay/feePayer.js +442 -0
- package/_esm/tempo/internal/relay/feePayer.js.map +1 -0
- package/_esm/tempo/internal/relay/feeToken.js +143 -0
- package/_esm/tempo/internal/relay/feeToken.js.map +1 -0
- package/_esm/tempo/{Multisig.js → internal/relay/multisig.js} +133 -129
- package/_esm/tempo/internal/relay/multisig.js.map +1 -0
- package/_esm/tempo/internal/relay/plugin.js +10 -0
- package/_esm/tempo/internal/relay/plugin.js.map +1 -0
- package/_esm/tempo/internal/relay/preflight.js +57 -0
- package/_esm/tempo/internal/relay/preflight.js.map +1 -0
- package/_esm/tempo/internal/relay/request.js +321 -0
- package/_esm/tempo/internal/relay/request.js.map +1 -0
- package/_esm/tempo/internal/relay/simulate.js +277 -0
- package/_esm/tempo/internal/relay/simulate.js.map +1 -0
- package/_esm/tempo/internal/relay/utils.js +174 -0
- package/_esm/tempo/internal/relay/utils.js.map +1 -0
- package/_esm/tempo/internal/relay/virtualAddress.js +73 -0
- package/_esm/tempo/internal/relay/virtualAddress.js.map +1 -0
- package/_esm/tempo/internal/relay.js +138 -0
- package/_esm/tempo/internal/relay.js.map +1 -0
- package/_esm/tempo/multisig/Config.js +2 -1
- package/_esm/tempo/multisig/Config.js.map +1 -1
- package/_esm/tempo/multisig/Operation.js +1 -1
- package/_esm/tempo/multisig/Operation.js.map +1 -1
- package/_esm/utils/siwe/parseSiweMessage.js +3 -3
- package/_esm/utils/siwe/parseSiweMessage.js.map +1 -1
- package/_types/actions/public/waitForTransactionReceipt.d.ts.map +1 -1
- package/_types/chains/definitions/blockdag.d.ts +51 -0
- package/_types/chains/definitions/blockdag.d.ts.map +1 -0
- package/_types/chains/definitions/candyChain.d.ts +48 -0
- package/_types/chains/definitions/candyChain.d.ts.map +1 -0
- package/_types/chains/definitions/creditCoin3Devnet.d.ts +6 -9
- package/_types/chains/definitions/creditCoin3Devnet.d.ts.map +1 -1
- package/_types/chains/definitions/creditCoin3Mainnet.d.ts +6 -9
- package/_types/chains/definitions/creditCoin3Mainnet.d.ts.map +1 -1
- package/_types/chains/definitions/creditCoin3Testnet.d.ts +6 -9
- package/_types/chains/definitions/creditCoin3Testnet.d.ts.map +1 -1
- package/_types/chains/definitions/kortana.d.ts +51 -0
- package/_types/chains/definitions/kortana.d.ts.map +1 -0
- package/_types/chains/index.d.ts +3 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/clients/createClientResolver.d.ts +76 -0
- package/_types/clients/createClientResolver.d.ts.map +1 -0
- package/_types/errors/version.d.ts +1 -1
- package/_types/index.d.ts +2 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/op-stack/actions/getGame.d.ts.map +1 -1
- package/_types/tempo/Capabilities.d.ts +7 -28
- package/_types/tempo/Capabilities.d.ts.map +1 -1
- package/_types/tempo/Client.d.ts +6 -15
- package/_types/tempo/Client.d.ts.map +1 -1
- package/_types/tempo/ExecutionError.d.ts +79 -0
- package/_types/tempo/ExecutionError.d.ts.map +1 -0
- package/_types/tempo/Relay.d.ts +302 -0
- package/_types/tempo/Relay.d.ts.map +1 -0
- package/_types/tempo/Transaction.d.ts +2 -1
- package/_types/tempo/Transaction.d.ts.map +1 -1
- package/_types/tempo/Transport.d.ts +15 -29
- package/_types/tempo/Transport.d.ts.map +1 -1
- package/_types/tempo/chainConfig.d.ts.map +1 -1
- package/_types/tempo/index.d.ts +8 -3
- package/_types/tempo/index.d.ts.map +1 -1
- package/_types/tempo/internal/relay/cache.d.ts +9 -0
- package/_types/tempo/internal/relay/cache.d.ts.map +1 -0
- package/_types/tempo/internal/relay/deadline.d.ts +4 -0
- package/_types/tempo/internal/relay/deadline.d.ts.map +1 -0
- package/_types/tempo/internal/relay/error.d.ts +47 -0
- package/_types/tempo/internal/relay/error.d.ts.map +1 -0
- package/_types/tempo/internal/relay/feePayer.d.ts +70 -0
- package/_types/tempo/internal/relay/feePayer.d.ts.map +1 -0
- package/_types/tempo/internal/relay/feeToken.d.ts +38 -0
- package/_types/tempo/internal/relay/feeToken.d.ts.map +1 -0
- package/_types/tempo/internal/relay/multisig.d.ts +4 -0
- package/_types/tempo/internal/relay/multisig.d.ts.map +1 -0
- package/_types/tempo/internal/relay/plugin.d.ts +5 -0
- package/_types/tempo/internal/relay/plugin.d.ts.map +1 -0
- package/_types/tempo/internal/relay/preflight.d.ts +17 -0
- package/_types/tempo/internal/relay/preflight.d.ts.map +1 -0
- package/_types/tempo/internal/relay/request.d.ts +16 -0
- package/_types/tempo/internal/relay/request.d.ts.map +1 -0
- package/_types/tempo/internal/relay/simulate.d.ts +59 -0
- package/_types/tempo/internal/relay/simulate.d.ts.map +1 -0
- package/_types/tempo/internal/relay/utils.d.ts +294 -0
- package/_types/tempo/internal/relay/utils.d.ts.map +1 -0
- package/_types/tempo/internal/relay/virtualAddress.d.ts +9 -0
- package/_types/tempo/internal/relay/virtualAddress.d.ts.map +1 -0
- package/_types/tempo/internal/relay.d.ts +4 -0
- package/_types/tempo/internal/relay.d.ts.map +1 -0
- package/_types/tempo/multisig/Config.d.ts +0 -13
- package/_types/tempo/multisig/Config.d.ts.map +1 -1
- package/_types/tempo/multisig/Operation.d.ts +0 -5
- package/_types/tempo/multisig/Operation.d.ts.map +1 -1
- package/_types/utils/siwe/parseSiweMessage.d.ts.map +1 -1
- package/actions/public/waitForTransactionReceipt.ts +16 -2
- package/chains/definitions/blockdag.ts +20 -0
- package/chains/definitions/candyChain.ts +26 -0
- package/chains/definitions/creditCoin3Devnet.ts +6 -0
- package/chains/definitions/creditCoin3Mainnet.ts +6 -0
- package/chains/definitions/creditCoin3Testnet.ts +6 -0
- package/chains/definitions/kortana.ts +20 -0
- package/chains/index.ts +3 -0
- package/clients/createClientResolver.ts +191 -0
- package/errors/version.ts +1 -1
- package/index.ts +6 -0
- package/op-stack/actions/getGame.ts +3 -1
- package/op-stack/actions/getGames.ts +1 -1
- package/op-stack/actions/getTimeToNextGame.ts +2 -2
- package/op-stack/actions/getTimeToNextL2Output.ts +2 -2
- package/package.json +1 -1
- package/tempo/Capabilities.ts +7 -29
- package/tempo/Client.ts +8 -38
- package/tempo/ExecutionError.ts +418 -0
- package/tempo/Relay.ts +428 -0
- package/tempo/Transaction.ts +2 -1
- package/tempo/Transport.ts +69 -60
- package/tempo/chainConfig.ts +4 -0
- package/tempo/index.ts +7 -3
- package/tempo/internal/relay/cache.ts +82 -0
- package/tempo/internal/relay/deadline.ts +45 -0
- package/tempo/internal/relay/error.ts +128 -0
- package/tempo/internal/relay/feePayer.ts +692 -0
- package/tempo/internal/relay/feeToken.ts +190 -0
- package/tempo/{Multisig.ts → internal/relay/multisig.ts} +162 -193
- package/tempo/internal/relay/plugin.ts +13 -0
- package/tempo/internal/relay/preflight.ts +81 -0
- package/tempo/internal/relay/request.ts +391 -0
- package/tempo/internal/relay/simulate.ts +367 -0
- package/tempo/internal/relay/utils.ts +202 -0
- package/tempo/internal/relay/virtualAddress.ts +95 -0
- package/tempo/internal/relay.ts +158 -0
- package/tempo/multisig/Config.ts +3 -2
- package/tempo/multisig/Operation.ts +1 -1
- package/utils/siwe/parseSiweMessage.ts +21 -13
- package/_cjs/tempo/Multisig.js.map +0 -1
- package/_esm/tempo/Multisig.js.map +0 -1
- package/_types/tempo/Multisig.d.ts +0 -37
- package/_types/tempo/Multisig.d.ts.map +0 -1
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type { Address } from 'abitype'
|
|
2
|
+
|
|
3
|
+
import type { JsonRpcAccount } from '../accounts/types.js'
|
|
4
|
+
import { BaseError } from '../errors/base.js'
|
|
5
|
+
import type { Tokens } from '../tokens/defineToken.js'
|
|
6
|
+
import type { Account } from '../types/account.js'
|
|
7
|
+
import type { Chain } from '../types/chain.js'
|
|
8
|
+
import type { RpcSchema } from '../types/eip1193.js'
|
|
9
|
+
import type { Prettify } from '../types/utils.js'
|
|
10
|
+
import {
|
|
11
|
+
type Client,
|
|
12
|
+
type ClientConfig,
|
|
13
|
+
type CreateClientErrorType,
|
|
14
|
+
createClient,
|
|
15
|
+
} from './createClient.js'
|
|
16
|
+
import type { Transport } from './transports/createTransport.js'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Creates a resolver that lazily constructs and caches a Client for each configured chain.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { createClientResolver, http } from 'viem'
|
|
24
|
+
* import { mainnet, optimism } from 'viem/chains'
|
|
25
|
+
*
|
|
26
|
+
* const resolver = createClientResolver({
|
|
27
|
+
* chains: [mainnet, optimism],
|
|
28
|
+
* transport: {
|
|
29
|
+
* [mainnet.id]: http(),
|
|
30
|
+
* [optimism.id]: http(),
|
|
31
|
+
* },
|
|
32
|
+
* })
|
|
33
|
+
*
|
|
34
|
+
* const client = resolver.getClient({ chainId: optimism.id })
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @param options - Resolver options, including shared Client configuration.
|
|
38
|
+
* @returns A resolver for the configured chains.
|
|
39
|
+
*/
|
|
40
|
+
export function createClientResolver<
|
|
41
|
+
const chains extends Chains,
|
|
42
|
+
accountOrAddress extends Account | Address | undefined = undefined,
|
|
43
|
+
const transport extends TransportConfig<NoInfer<chains>> = TransportConfig<
|
|
44
|
+
NoInfer<chains>
|
|
45
|
+
>,
|
|
46
|
+
const tokens extends Tokens | undefined = undefined,
|
|
47
|
+
rpcSchema extends RpcSchema | undefined = undefined,
|
|
48
|
+
>(
|
|
49
|
+
options: createClientResolver.Options<
|
|
50
|
+
chains,
|
|
51
|
+
accountOrAddress,
|
|
52
|
+
transport,
|
|
53
|
+
tokens,
|
|
54
|
+
rpcSchema
|
|
55
|
+
>,
|
|
56
|
+
): createClientResolver.ReturnType<
|
|
57
|
+
chains,
|
|
58
|
+
accountOrAddress,
|
|
59
|
+
transport,
|
|
60
|
+
tokens,
|
|
61
|
+
rpcSchema
|
|
62
|
+
> {
|
|
63
|
+
const { chains, transport, ...rest } = options
|
|
64
|
+
const clients = new Map<number, unknown>()
|
|
65
|
+
|
|
66
|
+
// The chain and transport are selected from the same chain ID.
|
|
67
|
+
return {
|
|
68
|
+
getClient({ chainId }) {
|
|
69
|
+
const cached = clients.get(chainId)
|
|
70
|
+
if (cached) return cached
|
|
71
|
+
|
|
72
|
+
const chain = chains.find((chain) => chain.id === chainId)
|
|
73
|
+
if (!chain) throw new ChainNotConfiguredError({ chainId })
|
|
74
|
+
const transport_ =
|
|
75
|
+
typeof transport === 'function'
|
|
76
|
+
? transport({ chainId })
|
|
77
|
+
: (transport as TransportMap<chains>)[chainId]
|
|
78
|
+
if (!transport_) throw new TransportNotConfiguredError({ chainId })
|
|
79
|
+
const client = createClient({ ...rest, chain, transport: transport_ })
|
|
80
|
+
clients.set(chainId, client)
|
|
81
|
+
return client
|
|
82
|
+
},
|
|
83
|
+
} as createClientResolver.ReturnType<
|
|
84
|
+
chains,
|
|
85
|
+
accountOrAddress,
|
|
86
|
+
transport,
|
|
87
|
+
tokens,
|
|
88
|
+
rpcSchema
|
|
89
|
+
>
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export declare namespace createClientResolver {
|
|
93
|
+
/** Errors thrown while resolving a Client. */
|
|
94
|
+
type ErrorType =
|
|
95
|
+
| ChainNotConfiguredError
|
|
96
|
+
| CreateClientErrorType
|
|
97
|
+
| TransportNotConfiguredError
|
|
98
|
+
|
|
99
|
+
/** Options for {@link createClientResolver}. */
|
|
100
|
+
type Options<
|
|
101
|
+
chains extends Chains = Chains,
|
|
102
|
+
accountOrAddress extends Account | Address | undefined =
|
|
103
|
+
| Account
|
|
104
|
+
| Address
|
|
105
|
+
| undefined,
|
|
106
|
+
transport extends TransportConfig<chains> = TransportConfig<chains>,
|
|
107
|
+
tokens extends Tokens | undefined = Tokens | undefined,
|
|
108
|
+
rpcSchema extends RpcSchema | undefined = undefined,
|
|
109
|
+
> = Prettify<
|
|
110
|
+
Omit<
|
|
111
|
+
ClientConfig<Transport, undefined, accountOrAddress, rpcSchema, tokens>,
|
|
112
|
+
'chain' | 'transport'
|
|
113
|
+
> & {
|
|
114
|
+
/** Chains available to the resolver. Must contain at least one chain. */
|
|
115
|
+
chains: chains
|
|
116
|
+
/** Transports indexed or resolved by chain ID. */
|
|
117
|
+
transport: transport
|
|
118
|
+
}
|
|
119
|
+
>
|
|
120
|
+
|
|
121
|
+
/** Return type of {@link createClientResolver}. */
|
|
122
|
+
type ReturnType<
|
|
123
|
+
chains extends Chains = Chains,
|
|
124
|
+
accountOrAddress extends Account | Address | undefined =
|
|
125
|
+
| Account
|
|
126
|
+
| Address
|
|
127
|
+
| undefined,
|
|
128
|
+
transport extends TransportConfig<chains> = TransportConfig<chains>,
|
|
129
|
+
tokens extends Tokens | undefined = Tokens | undefined,
|
|
130
|
+
rpcSchema extends RpcSchema | undefined = undefined,
|
|
131
|
+
> = {
|
|
132
|
+
/** Returns the cached Client configured for `chainId`, creating it on first use. */
|
|
133
|
+
getClient<const chainId extends chains[number]['id']>(options: {
|
|
134
|
+
/** ID of a configured chain. */
|
|
135
|
+
chainId: chainId
|
|
136
|
+
}): Client<
|
|
137
|
+
ResolvedTransport<chains, transport, chainId>,
|
|
138
|
+
number extends chains[number]['id']
|
|
139
|
+
? chains[number]
|
|
140
|
+
: Extract<chains[number], { id: chainId }>,
|
|
141
|
+
accountOrAddress extends Address
|
|
142
|
+
? Prettify<JsonRpcAccount<accountOrAddress>>
|
|
143
|
+
: accountOrAddress,
|
|
144
|
+
rpcSchema,
|
|
145
|
+
undefined,
|
|
146
|
+
tokens
|
|
147
|
+
>
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
type Chains = readonly [Chain, ...Chain[]]
|
|
152
|
+
|
|
153
|
+
type TransportConfig<chains extends Chains> =
|
|
154
|
+
| TransportMap<chains>
|
|
155
|
+
| ((options: { chainId: chains[number]['id'] }) => Transport)
|
|
156
|
+
|
|
157
|
+
type TransportMap<chains extends Chains> = {
|
|
158
|
+
readonly [chainId in chains[number]['id']]: Transport
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
type ResolvedTransport<
|
|
162
|
+
chains extends Chains,
|
|
163
|
+
transport extends TransportConfig<chains>,
|
|
164
|
+
chainId extends chains[number]['id'],
|
|
165
|
+
> = transport extends (...args: never[]) => infer resolved
|
|
166
|
+
? resolved extends Transport
|
|
167
|
+
? resolved
|
|
168
|
+
: never
|
|
169
|
+
: transport extends Record<chainId, infer resolved>
|
|
170
|
+
? resolved extends Transport
|
|
171
|
+
? resolved
|
|
172
|
+
: never
|
|
173
|
+
: never
|
|
174
|
+
|
|
175
|
+
/** Thrown when a Client is requested for an unconfigured chain. */
|
|
176
|
+
export class ChainNotConfiguredError extends BaseError {
|
|
177
|
+
constructor({ chainId }: { chainId: number }) {
|
|
178
|
+
super(`Chain with id ${chainId} is not configured.`, {
|
|
179
|
+
name: 'createClientResolver.ChainNotConfiguredError',
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Thrown when a configured chain has no transport. */
|
|
185
|
+
export class TransportNotConfiguredError extends BaseError {
|
|
186
|
+
constructor({ chainId }: { chainId: number }) {
|
|
187
|
+
super(`Transport for chain with id ${chainId} is not configured.`, {
|
|
188
|
+
name: 'createClientResolver.TransportNotConfiguredError',
|
|
189
|
+
})
|
|
190
|
+
}
|
|
191
|
+
}
|
package/errors/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.
|
|
1
|
+
export const version = '2.57.0'
|
package/index.ts
CHANGED
|
@@ -609,6 +609,12 @@ export {
|
|
|
609
609
|
type MulticallBatchOptions,
|
|
610
610
|
rpcSchema,
|
|
611
611
|
} from './clients/createClient.js'
|
|
612
|
+
/** Lazily resolves and caches typed Clients across configured chains. */
|
|
613
|
+
export {
|
|
614
|
+
ChainNotConfiguredError,
|
|
615
|
+
createClientResolver,
|
|
616
|
+
TransportNotConfiguredError,
|
|
617
|
+
} from './clients/createClientResolver.js'
|
|
612
618
|
export {
|
|
613
619
|
type CreatePublicClientErrorType,
|
|
614
620
|
createPublicClient,
|
|
@@ -93,7 +93,9 @@ export async function getGame<
|
|
|
93
93
|
|
|
94
94
|
const latestGames = await getGames(client, parameters)
|
|
95
95
|
|
|
96
|
-
const games = latestGames.filter(
|
|
96
|
+
const games = latestGames.filter(
|
|
97
|
+
(game) => game.l2BlockNumber >= l2BlockNumber,
|
|
98
|
+
)
|
|
97
99
|
|
|
98
100
|
const game = (() => {
|
|
99
101
|
if (strategy === 'random')
|
|
@@ -145,7 +145,7 @@ export async function getGames<
|
|
|
145
145
|
const games = rawGames
|
|
146
146
|
.map((game, i) => {
|
|
147
147
|
const blockNumber = l2SequenceNumbers[i] as bigint
|
|
148
|
-
return !l2BlockNumber || blockNumber
|
|
148
|
+
return !l2BlockNumber || blockNumber >= l2BlockNumber
|
|
149
149
|
? { ...game, l2BlockNumber: blockNumber, usesSuperRoots }
|
|
150
150
|
: null
|
|
151
151
|
})
|
|
@@ -133,9 +133,9 @@ export async function getTimeToNextGame<
|
|
|
133
133
|
// then we assume that the dispute game has already been submitted.
|
|
134
134
|
if (now < latestGameTimestamp) return 0
|
|
135
135
|
|
|
136
|
-
// If the latest dispute game
|
|
136
|
+
// If the latest dispute game covers the provided block number,
|
|
137
137
|
// then we assume that the dispute game has already been submitted.
|
|
138
|
-
if (latestGame.l2BlockNumber
|
|
138
|
+
if (latestGame.l2BlockNumber >= l2BlockNumber) return 0
|
|
139
139
|
|
|
140
140
|
// If there is only a single game, no interval data
|
|
141
141
|
if (intervalWithBuffer === 0) return 0
|
|
@@ -141,9 +141,9 @@ export async function getTimeToNextL2Output<
|
|
|
141
141
|
// then we assume that the L2 output has already been submitted.
|
|
142
142
|
if (now < latestOutputTimestamp) return 0
|
|
143
143
|
|
|
144
|
-
// If the latest L2 output
|
|
144
|
+
// If the latest L2 output covers the provided L2 block number,
|
|
145
145
|
// then we assume that the L2 output has already been submitted.
|
|
146
|
-
if (latestOutput.l2BlockNumber
|
|
146
|
+
if (latestOutput.l2BlockNumber >= l2BlockNumber) return 0
|
|
147
147
|
|
|
148
148
|
const elapsedBlocks = Number(l2BlockNumber - latestOutput.l2BlockNumber)
|
|
149
149
|
|
package/package.json
CHANGED
package/tempo/Capabilities.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Address } from 'abitype'
|
|
2
2
|
import type { DefaultCapabilitiesSchema } from '../types/capabilities.js'
|
|
3
3
|
import type { Hex } from '../types/misc.js'
|
|
4
|
-
import type { ExactPartial
|
|
5
|
-
import type
|
|
4
|
+
import type { ExactPartial } from '../types/utils.js'
|
|
5
|
+
import type * as ExecutionError from './ExecutionError.js'
|
|
6
6
|
import type { TransactionRequestTempo } from './Transaction.js'
|
|
7
7
|
|
|
8
8
|
export type Schema = Omit<DefaultCapabilitiesSchema, 'sendCalls'> & {
|
|
@@ -18,27 +18,13 @@ export type Schema = Omit<DefaultCapabilitiesSchema, 'sendCalls'> & {
|
|
|
18
18
|
export type FillTransactionRequestCapabilities = {
|
|
19
19
|
/** Whether to include `balanceDiffs` in the response. */
|
|
20
20
|
balanceDiffs?: boolean | undefined
|
|
21
|
+
/** Whether execution reverts return error capabilities instead of throwing. */
|
|
22
|
+
errors?: boolean | undefined
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export type FillTransactionCapabilities = {
|
|
24
|
-
autoSwap?:
|
|
25
|
-
| {
|
|
26
|
-
calls: readonly { to: Address; data: Hex; value: Hex }[]
|
|
27
|
-
maxIn: SwapAmount
|
|
28
|
-
minOut: SwapAmount
|
|
29
|
-
slippage: number
|
|
30
|
-
}
|
|
31
|
-
| undefined
|
|
32
26
|
balanceDiffs?: Readonly<Record<Address, readonly BalanceDiff[]>> | undefined
|
|
33
|
-
error?:
|
|
34
|
-
| OneOf<
|
|
35
|
-
| (DecodeErrorResultReturnType & {
|
|
36
|
-
data: Hex
|
|
37
|
-
message: string
|
|
38
|
-
})
|
|
39
|
-
| { errorName: 'unknown'; message: string }
|
|
40
|
-
>
|
|
41
|
-
| undefined
|
|
27
|
+
error?: ExecutionError.Rpc | undefined
|
|
42
28
|
fee?:
|
|
43
29
|
| {
|
|
44
30
|
amount: Hex
|
|
@@ -47,7 +33,7 @@ export type FillTransactionCapabilities = {
|
|
|
47
33
|
symbol: string
|
|
48
34
|
}
|
|
49
35
|
| undefined
|
|
50
|
-
|
|
36
|
+
insufficientFunds?:
|
|
51
37
|
| {
|
|
52
38
|
amount: Hex
|
|
53
39
|
decimals: number
|
|
@@ -68,6 +54,7 @@ export type FillTransactionCapabilities = {
|
|
|
68
54
|
virtualAddresses?: Readonly<Record<Address, Address | null>> | undefined
|
|
69
55
|
}
|
|
70
56
|
|
|
57
|
+
/** A token balance preview. Incoming funds and outgoing approval exposure can produce separate entries for the same token. */
|
|
71
58
|
export type BalanceDiff = {
|
|
72
59
|
address: Address
|
|
73
60
|
decimals: number
|
|
@@ -78,12 +65,3 @@ export type BalanceDiff = {
|
|
|
78
65
|
symbol: string
|
|
79
66
|
value: Hex
|
|
80
67
|
}
|
|
81
|
-
|
|
82
|
-
export type SwapAmount = {
|
|
83
|
-
decimals: number
|
|
84
|
-
formatted: string
|
|
85
|
-
name: string
|
|
86
|
-
symbol: string
|
|
87
|
-
token: Address
|
|
88
|
-
value: Hex
|
|
89
|
-
}
|
package/tempo/Client.ts
CHANGED
|
@@ -25,8 +25,6 @@ import type { RpcSchema } from '../types/eip1193.js'
|
|
|
25
25
|
import type { Prettify } from '../types/utils.js'
|
|
26
26
|
import { tempo, tempoTestnet } from './Chain.js'
|
|
27
27
|
import { type Decorator, decorator as tempoActions } from './Decorator.js'
|
|
28
|
-
import * as Store from './Store.js'
|
|
29
|
-
import { withMultisig } from './Transport.js'
|
|
30
28
|
|
|
31
29
|
/**
|
|
32
30
|
* Configuration for a Tempo {@link Client}.
|
|
@@ -54,19 +52,6 @@ export type ClientConfig<
|
|
|
54
52
|
* @default tempo (or `tempoTestnet` when `testnet` is truthy)
|
|
55
53
|
*/
|
|
56
54
|
chain?: chain | Chain | undefined
|
|
57
|
-
/**
|
|
58
|
-
* Enables native multisig approval coordination. Pass `true` to use an
|
|
59
|
-
* in-memory store or provide a shared store.
|
|
60
|
-
*
|
|
61
|
-
* @default undefined
|
|
62
|
-
*/
|
|
63
|
-
experimental_multisig?:
|
|
64
|
-
| true
|
|
65
|
-
| {
|
|
66
|
-
/** Store shared by multisig coordinators. */
|
|
67
|
-
store: Store.Atomic
|
|
68
|
-
}
|
|
69
|
-
| undefined
|
|
70
55
|
/**
|
|
71
56
|
* Default fee token for the Client. Extended onto the chain so it applies
|
|
72
57
|
* to every transaction sent with the Client.
|
|
@@ -121,8 +106,8 @@ export type CreateClientErrorType = ErrorType
|
|
|
121
106
|
* Defaults to the `tempo` mainnet chain and `http` transport, so a minimal
|
|
122
107
|
* client can be created with `createClient()`. Pass `testnet` to use the
|
|
123
108
|
* Tempo testnet, or `chain` to override the chain entirely. Pass `feeToken`
|
|
124
|
-
* to set a default fee token for every transaction.
|
|
125
|
-
* `
|
|
109
|
+
* to set a default fee token for every transaction. Use `withRelay` with a
|
|
110
|
+
* `Relay.multisig` plugin to coordinate multisig owner approvals.
|
|
126
111
|
*
|
|
127
112
|
* @example
|
|
128
113
|
* ```ts
|
|
@@ -156,11 +141,13 @@ export type CreateClientErrorType = ErrorType
|
|
|
156
141
|
*
|
|
157
142
|
* @example
|
|
158
143
|
* ```ts
|
|
159
|
-
* import { createClient } from 'viem/tempo'
|
|
144
|
+
* import { createClient, http, Relay, Store, withRelay } from 'viem/tempo'
|
|
160
145
|
*
|
|
161
146
|
* // Multisig coordination with a client-local in-memory store.
|
|
162
147
|
* const client = createClient({
|
|
163
|
-
*
|
|
148
|
+
* transport: withRelay(http(), {
|
|
149
|
+
* plugins: [Relay.multisig({ store: Store.memory() })],
|
|
150
|
+
* }),
|
|
164
151
|
* })
|
|
165
152
|
* ```
|
|
166
153
|
*
|
|
@@ -182,15 +169,7 @@ export function createClient<
|
|
|
182
169
|
: accountOrAddress,
|
|
183
170
|
rpcSchema
|
|
184
171
|
> {
|
|
185
|
-
const {
|
|
186
|
-
chain,
|
|
187
|
-
experimental_multisig,
|
|
188
|
-
feeToken,
|
|
189
|
-
testnet,
|
|
190
|
-
tokens,
|
|
191
|
-
transport,
|
|
192
|
-
...rest
|
|
193
|
-
} = parameters
|
|
172
|
+
const { chain, feeToken, testnet, tokens, transport, ...rest } = parameters
|
|
194
173
|
const baseChain = chain ?? (testnet ? tempoTestnet : tempo)
|
|
195
174
|
const resolvedChain =
|
|
196
175
|
feeToken && typeof (baseChain as { extend?: unknown }).extend === 'function'
|
|
@@ -198,20 +177,11 @@ export function createClient<
|
|
|
198
177
|
feeToken,
|
|
199
178
|
})
|
|
200
179
|
: baseChain
|
|
201
|
-
const transport_ = transport ?? http()
|
|
202
|
-
const resolvedTransport = experimental_multisig
|
|
203
|
-
? withMultisig(
|
|
204
|
-
transport_,
|
|
205
|
-
experimental_multisig === true
|
|
206
|
-
? { store: Store.memory() }
|
|
207
|
-
: experimental_multisig,
|
|
208
|
-
)
|
|
209
|
-
: transport_
|
|
210
180
|
return createClient_({
|
|
211
181
|
...rest,
|
|
212
182
|
chain: resolvedChain,
|
|
213
183
|
tokens: tokens ?? tokenSets.tempo,
|
|
214
|
-
transport:
|
|
184
|
+
transport: transport ?? http(),
|
|
215
185
|
} as ClientConfig_)
|
|
216
186
|
.extend(publicActions)
|
|
217
187
|
.extend(walletActions)
|