viem 2.57.12 → 2.57.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.
- package/CHANGELOG.md +18 -0
- package/_cjs/actions/public/fillTransaction.js +6 -3
- package/_cjs/actions/public/fillTransaction.js.map +1 -1
- package/_cjs/actions/public/watchContractEvent.js +58 -29
- package/_cjs/actions/public/watchContractEvent.js.map +1 -1
- package/_cjs/actions/public/watchEvent.js +58 -29
- package/_cjs/actions/public/watchEvent.js.map +1 -1
- package/_cjs/chains/definitions/molibra.js +21 -0
- package/_cjs/chains/definitions/molibra.js.map +1 -0
- package/_cjs/chains/index.js +9 -7
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/tempo/Account.js +4 -4
- package/_cjs/tempo/Account.js.map +1 -1
- package/_cjs/tempo/Formatters.js +13 -2
- package/_cjs/tempo/Formatters.js.map +1 -1
- package/_cjs/tempo/Relay.js.map +1 -1
- package/_cjs/tempo/Transaction.js.map +1 -1
- package/_cjs/tempo/accounts/Config.js +21 -8
- package/_cjs/tempo/accounts/Config.js.map +1 -1
- package/_cjs/tempo/chainConfig.js +11 -4
- package/_cjs/tempo/chainConfig.js.map +1 -1
- package/_cjs/tempo/internal/relay/accounts.js +41 -4
- package/_cjs/tempo/internal/relay/accounts.js.map +1 -1
- package/_cjs/tempo/internal/relay/feePayer.js +4 -1
- package/_cjs/tempo/internal/relay/feePayer.js.map +1 -1
- package/_esm/actions/public/fillTransaction.js +8 -3
- package/_esm/actions/public/fillTransaction.js.map +1 -1
- package/_esm/actions/public/watchContractEvent.js +73 -36
- package/_esm/actions/public/watchContractEvent.js.map +1 -1
- package/_esm/actions/public/watchEvent.js +73 -36
- package/_esm/actions/public/watchEvent.js.map +1 -1
- package/_esm/chains/definitions/molibra.js +18 -0
- package/_esm/chains/definitions/molibra.js.map +1 -0
- package/_esm/chains/index.js +1 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/tempo/Account.js +4 -4
- package/_esm/tempo/Account.js.map +1 -1
- package/_esm/tempo/Formatters.js +12 -2
- package/_esm/tempo/Formatters.js.map +1 -1
- package/_esm/tempo/Relay.js.map +1 -1
- package/_esm/tempo/Transaction.js.map +1 -1
- package/_esm/tempo/accounts/Config.js +27 -12
- package/_esm/tempo/accounts/Config.js.map +1 -1
- package/_esm/tempo/chainConfig.js +13 -4
- package/_esm/tempo/chainConfig.js.map +1 -1
- package/_esm/tempo/internal/relay/accounts.js +43 -4
- package/_esm/tempo/internal/relay/accounts.js.map +1 -1
- package/_esm/tempo/internal/relay/feePayer.js +4 -1
- package/_esm/tempo/internal/relay/feePayer.js.map +1 -1
- package/_types/actions/getContract.d.ts +1 -1
- package/_types/actions/public/fillTransaction.d.ts.map +1 -1
- package/_types/actions/public/watchContractEvent.d.ts +1 -1
- package/_types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/_types/actions/public/watchEvent.d.ts +1 -1
- package/_types/actions/public/watchEvent.d.ts.map +1 -1
- package/_types/chains/definitions/molibra.d.ts +52 -0
- package/_types/chains/definitions/molibra.d.ts.map +1 -0
- package/_types/chains/definitions/tempo.d.ts +14 -6
- package/_types/chains/definitions/tempo.d.ts.map +1 -1
- package/_types/chains/definitions/tempoDevnet.d.ts +14 -6
- package/_types/chains/definitions/tempoDevnet.d.ts.map +1 -1
- package/_types/chains/definitions/tempoLocalnet.d.ts +14 -6
- package/_types/chains/definitions/tempoLocalnet.d.ts.map +1 -1
- package/_types/chains/definitions/tempoModerato.d.ts +14 -6
- package/_types/chains/definitions/tempoModerato.d.ts.map +1 -1
- package/_types/chains/index.d.ts +1 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/clients/decorators/public.d.ts +2 -2
- package/_types/errors/version.d.ts +1 -1
- package/_types/tempo/Account.d.ts +14 -0
- package/_types/tempo/Account.d.ts.map +1 -1
- package/_types/tempo/Formatters.d.ts +3 -0
- package/_types/tempo/Formatters.d.ts.map +1 -1
- package/_types/tempo/Relay.d.ts +20 -0
- package/_types/tempo/Relay.d.ts.map +1 -1
- package/_types/tempo/Transaction.d.ts +7 -2
- package/_types/tempo/Transaction.d.ts.map +1 -1
- package/_types/tempo/accounts/Config.d.ts +24 -2
- package/_types/tempo/accounts/Config.d.ts.map +1 -1
- package/_types/tempo/chainConfig.d.ts +8 -3
- package/_types/tempo/chainConfig.d.ts.map +1 -1
- package/_types/tempo/internal/relay/accounts.d.ts.map +1 -1
- package/_types/tempo/internal/relay/feePayer.d.ts.map +1 -1
- package/actions/getContract.ts +1 -1
- package/actions/public/fillTransaction.ts +12 -3
- package/actions/public/watchContractEvent.ts +82 -39
- package/actions/public/watchEvent.ts +82 -39
- package/chains/definitions/molibra.ts +18 -0
- package/chains/index.ts +1 -0
- package/clients/decorators/public.ts +2 -2
- package/errors/version.ts +1 -1
- package/package.json +1 -1
- package/tempo/Account.ts +18 -8
- package/tempo/Formatters.ts +19 -7
- package/tempo/Relay.ts +26 -0
- package/tempo/Transaction.ts +10 -2
- package/tempo/accounts/Config.ts +39 -16
- package/tempo/chainConfig.ts +15 -4
- package/tempo/internal/relay/accounts.ts +44 -6
- package/tempo/internal/relay/feePayer.ts +6 -1
package/tempo/accounts/Config.ts
CHANGED
|
@@ -17,8 +17,8 @@ export async function read(
|
|
|
17
17
|
store: Store.Store,
|
|
18
18
|
options: read.Options,
|
|
19
19
|
): Promise<AccountConfig.Config | null> {
|
|
20
|
-
const { address, commitment } = options
|
|
21
|
-
const value = await store.getItem(key({ address, commitment }))
|
|
20
|
+
const { address, chainId, commitment } = options
|
|
21
|
+
const value = await store.getItem(key({ address, chainId, commitment }))
|
|
22
22
|
if (value === null || value === undefined) return null
|
|
23
23
|
const config = deserialize(value)
|
|
24
24
|
assertKey({ address, commitment, config })
|
|
@@ -30,25 +30,43 @@ export declare namespace read {
|
|
|
30
30
|
export type Options = {
|
|
31
31
|
/** Configurable account address. */
|
|
32
32
|
address: Address.Address
|
|
33
|
+
/** Chain whose commitment selects the config. */
|
|
34
|
+
chainId: number
|
|
33
35
|
/** Config commitment observed onchain. */
|
|
34
36
|
commitment: Hex.Hex
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Writes a validated account config.
|
|
42
|
+
*
|
|
43
|
+
* Each key fixes one config, through its commitment or, before initialization, the account
|
|
44
|
+
* address. An existing key therefore holds the same config and is not written again.
|
|
45
|
+
*/
|
|
39
46
|
export async function write(
|
|
40
|
-
store: Store.
|
|
47
|
+
store: Store.Atomic,
|
|
41
48
|
options: write.Options,
|
|
42
49
|
): Promise<void> {
|
|
43
|
-
const { address, commitment } = options
|
|
44
|
-
const config =
|
|
50
|
+
const { address, chainId, commitment } = options
|
|
51
|
+
const config = (() => {
|
|
52
|
+
try {
|
|
53
|
+
return AccountConfig.from(options.config)
|
|
54
|
+
} catch (cause) {
|
|
55
|
+
throw new InvalidStoreValueError({ cause })
|
|
56
|
+
}
|
|
57
|
+
})()
|
|
45
58
|
assertKey({ address, commitment, config })
|
|
46
59
|
const value = serialize(config)
|
|
47
|
-
await store.
|
|
60
|
+
await store.compareAndSet(key({ address, chainId, commitment }), null, value)
|
|
48
61
|
// Initialization commits the version-zero config without changing its version.
|
|
49
62
|
if (commitment.toLowerCase() === zeroCommitment)
|
|
50
|
-
await store.
|
|
51
|
-
key({
|
|
63
|
+
await store.compareAndSet(
|
|
64
|
+
key({
|
|
65
|
+
address,
|
|
66
|
+
chainId,
|
|
67
|
+
commitment: AccountConfig.getCommitment(config),
|
|
68
|
+
}),
|
|
69
|
+
null,
|
|
52
70
|
value,
|
|
53
71
|
)
|
|
54
72
|
}
|
|
@@ -58,6 +76,8 @@ export declare namespace write {
|
|
|
58
76
|
export type Options = {
|
|
59
77
|
/** Configurable account address. */
|
|
60
78
|
address: Address.Address
|
|
79
|
+
/** Chain whose commitment selects the config. */
|
|
80
|
+
chainId: number
|
|
61
81
|
/** Config commitment used for lookup. */
|
|
62
82
|
commitment: Hex.Hex
|
|
63
83
|
/** Complete config. */
|
|
@@ -97,10 +117,14 @@ function deserialize(value: string): AccountConfig.Config {
|
|
|
97
117
|
}
|
|
98
118
|
}
|
|
99
119
|
|
|
100
|
-
/** Returns the store key for an account and config commitment. */
|
|
101
|
-
function key(options: {
|
|
102
|
-
|
|
103
|
-
|
|
120
|
+
/** Returns the store key for an account and config commitment on one chain. */
|
|
121
|
+
function key(options: {
|
|
122
|
+
address: Address.Address
|
|
123
|
+
chainId: number
|
|
124
|
+
commitment: Hex.Hex
|
|
125
|
+
}) {
|
|
126
|
+
const { address, chainId, commitment } = options
|
|
127
|
+
return `configurableAccount:config:${chainId}:${address.toLowerCase()}:${commitment.toLowerCase()}`
|
|
104
128
|
}
|
|
105
129
|
|
|
106
130
|
/** Serializes an account config for storage. */
|
|
@@ -116,8 +140,7 @@ function serialize(config: AccountConfig.Config): string {
|
|
|
116
140
|
}
|
|
117
141
|
|
|
118
142
|
/** Thrown when a stored account config is malformed or mismatched. */
|
|
119
|
-
|
|
120
|
-
class InvalidStoreValueError extends BaseError {
|
|
143
|
+
export class InvalidStoreValueError extends BaseError {
|
|
121
144
|
/** Creates an invalid store value error. */
|
|
122
145
|
constructor(options: InvalidStoreValueError.Options = {}) {
|
|
123
146
|
super('Stored account config is malformed or mismatched.', {
|
|
@@ -127,7 +150,7 @@ class InvalidStoreValueError extends BaseError {
|
|
|
127
150
|
}
|
|
128
151
|
}
|
|
129
152
|
|
|
130
|
-
declare namespace InvalidStoreValueError {
|
|
153
|
+
export declare namespace InvalidStoreValueError {
|
|
131
154
|
/** Error construction options. */
|
|
132
155
|
export type Options = {
|
|
133
156
|
/** Underlying error. */
|
package/tempo/chainConfig.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { maxUint256 } from '../constants/number.js'
|
|
|
15
15
|
import { BaseError } from '../errors/base.js'
|
|
16
16
|
import { ContractFunctionRevertedError } from '../errors/contract.js'
|
|
17
17
|
import type { Chain, ChainConfig as viem_ChainConfig } from '../types/chain.js'
|
|
18
|
+
import type { RpcBlock } from '../types/rpc.js'
|
|
18
19
|
import { isAddressEqual } from '../utils/address/isAddressEqual.js'
|
|
19
20
|
import { extendSchema } from '../utils/chain/defineChain.js'
|
|
20
21
|
import { defineTransaction } from '../utils/formatters/transaction.js'
|
|
@@ -41,6 +42,8 @@ const maxExpirySecs = 25
|
|
|
41
42
|
const serializeTransaction = ((transaction, signature) =>
|
|
42
43
|
Transaction.serialize(transaction, signature)) as SerializeTransactionFn
|
|
43
44
|
|
|
45
|
+
// The base formatters decode nonces as safe integers and throw on Tempo expiring nonces (random
|
|
46
|
+
// u64 values), so Tempo formats every transaction itself, including those inside blocks.
|
|
44
47
|
export const chainConfig = {
|
|
45
48
|
blockTime: 1_000,
|
|
46
49
|
extendSchema: extendSchema<{
|
|
@@ -48,10 +51,18 @@ export const chainConfig = {
|
|
|
48
51
|
hardfork?: Hardfork | undefined
|
|
49
52
|
}>(),
|
|
50
53
|
formatters: {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
54
|
+
block: {
|
|
55
|
+
format: (block: RpcBlock) => Formatters.formatBlock(block),
|
|
56
|
+
type: 'block' as const,
|
|
57
|
+
},
|
|
58
|
+
transaction: {
|
|
59
|
+
...defineTransaction({
|
|
60
|
+
exclude: ['aaAuthorizationList' as never],
|
|
61
|
+
format: Formatters.formatTransaction,
|
|
62
|
+
}),
|
|
63
|
+
format: (transaction: Transaction.TransactionRpc) =>
|
|
64
|
+
Formatters.formatTransaction(transaction),
|
|
65
|
+
},
|
|
55
66
|
transactionReceipt: defineTransactionReceipt({
|
|
56
67
|
format: Formatters.formatTransactionReceipt,
|
|
57
68
|
}),
|
|
@@ -25,6 +25,7 @@ import type * as Relay from '../../Relay.js'
|
|
|
25
25
|
import type * as Store from '../../Store.js'
|
|
26
26
|
import * as Transaction from '../../Transaction.js'
|
|
27
27
|
import * as Plugin from './plugin.js'
|
|
28
|
+
import * as Utils from './utils.js'
|
|
28
29
|
|
|
29
30
|
const submissionTtl = 30_000
|
|
30
31
|
const pollingInterval = 100
|
|
@@ -76,17 +77,42 @@ export function create(
|
|
|
76
77
|
throw new RpcResponse.InvalidParamsError({
|
|
77
78
|
message: 'Expected a configurable account address.',
|
|
78
79
|
})
|
|
79
|
-
const
|
|
80
|
+
const chainId = requestOptions?.chainId
|
|
81
|
+
if (chainId === undefined)
|
|
82
|
+
throw new RpcResponse.InvalidParamsError({
|
|
83
|
+
message: 'A chain ID is required to resolve the downstream client.',
|
|
84
|
+
})
|
|
85
|
+
// Surface a downstream failure as its RPC error, not as a reverted read.
|
|
80
86
|
const commitment = await getConfigCommitment(client, {
|
|
81
87
|
account: address,
|
|
82
|
-
|
|
88
|
+
}).catch((error) => {
|
|
89
|
+
throw Utils.toRpcError(error)
|
|
83
90
|
})
|
|
84
91
|
const config = await ConfigStore.read(options.store, {
|
|
85
92
|
address,
|
|
93
|
+
chainId,
|
|
86
94
|
commitment,
|
|
87
95
|
})
|
|
88
|
-
if (
|
|
89
|
-
|
|
96
|
+
if (config) return AccountConfig.toRpc(config)
|
|
97
|
+
const resolved = await options.resolveConfig?.({
|
|
98
|
+
address,
|
|
99
|
+
chainId,
|
|
100
|
+
commitment,
|
|
101
|
+
})
|
|
102
|
+
if (!resolved) return null
|
|
103
|
+
try {
|
|
104
|
+
await ConfigStore.write(options.store, {
|
|
105
|
+
address,
|
|
106
|
+
chainId,
|
|
107
|
+
commitment,
|
|
108
|
+
config: resolved,
|
|
109
|
+
})
|
|
110
|
+
} catch (error) {
|
|
111
|
+
// A resolved config that does not match the account and commitment is not served.
|
|
112
|
+
if (error instanceof ConfigStore.InvalidStoreValueError) return null
|
|
113
|
+
throw error
|
|
114
|
+
}
|
|
115
|
+
return AccountConfig.toRpc(AccountConfig.from(resolved))
|
|
90
116
|
}
|
|
91
117
|
|
|
92
118
|
if (request.method === 'account_getOperation') {
|
|
@@ -101,6 +127,7 @@ export function create(
|
|
|
101
127
|
|
|
102
128
|
if (request.method === 'account_approveKeyAuthorization')
|
|
103
129
|
return await approveKeyAuthorization({
|
|
130
|
+
chainId: requestOptions?.chainId,
|
|
104
131
|
client,
|
|
105
132
|
request,
|
|
106
133
|
store: options.store,
|
|
@@ -325,6 +352,7 @@ async function submit(options: submit.Options) {
|
|
|
325
352
|
|
|
326
353
|
await ConfigStore.write(options.store, {
|
|
327
354
|
address: signature.account,
|
|
355
|
+
chainId: transaction.chainId,
|
|
328
356
|
commitment: configCommitment,
|
|
329
357
|
config,
|
|
330
358
|
})
|
|
@@ -643,6 +671,11 @@ async function approveKeyAuthorization(
|
|
|
643
671
|
message: 'A owner approval envelope must include a signature.',
|
|
644
672
|
})
|
|
645
673
|
|
|
674
|
+
const { chainId } = options
|
|
675
|
+
if (chainId === undefined)
|
|
676
|
+
throw new RpcResponse.InvalidParamsError({
|
|
677
|
+
message: 'A chain ID is required to resolve the downstream client.',
|
|
678
|
+
})
|
|
646
679
|
const blockNumber = await getBlockNumber(options.client, { cacheTime: 0 })
|
|
647
680
|
const commitment = await validateConfig({
|
|
648
681
|
account: approval.account,
|
|
@@ -723,6 +756,7 @@ async function approveKeyAuthorization(
|
|
|
723
756
|
)
|
|
724
757
|
await ConfigStore.write(options.store, {
|
|
725
758
|
address: approval.account,
|
|
759
|
+
chainId,
|
|
726
760
|
commitment,
|
|
727
761
|
config: approval.config,
|
|
728
762
|
})
|
|
@@ -734,6 +768,8 @@ async function approveKeyAuthorization(
|
|
|
734
768
|
declare namespace approveKeyAuthorization {
|
|
735
769
|
/** Options for {@link approveKeyAuthorization}. */
|
|
736
770
|
export type Options = {
|
|
771
|
+
/** Chain of `client`, whose commitment validates the config. */
|
|
772
|
+
chainId?: number | undefined
|
|
737
773
|
/** Client used to validate configs. */
|
|
738
774
|
client: ReturnType<typeof createClient>
|
|
739
775
|
/** Original RPC request. */
|
|
@@ -843,6 +879,7 @@ async function cacheNextConfigs(options: cacheNextConfigs.Options) {
|
|
|
843
879
|
if (!config) continue
|
|
844
880
|
await ConfigStore.write(options.store, {
|
|
845
881
|
address: options.account,
|
|
882
|
+
chainId: options.transaction.chainId,
|
|
846
883
|
commitment: AccountConfig.getCommitment(config),
|
|
847
884
|
config,
|
|
848
885
|
})
|
|
@@ -858,7 +895,7 @@ declare namespace cacheNextConfigs {
|
|
|
858
895
|
/** Root config used to authorize the transaction. */
|
|
859
896
|
config: AccountConfig.Config
|
|
860
897
|
/** Shared account store. */
|
|
861
|
-
store: Store.
|
|
898
|
+
store: Store.Atomic
|
|
862
899
|
/** Submitted transaction containing potential config updates. */
|
|
863
900
|
transaction: Transaction.TransactionSerializableTempo
|
|
864
901
|
}
|
|
@@ -895,6 +932,7 @@ async function cacheUpgradeConfig(options: cacheUpgradeConfig.Options) {
|
|
|
895
932
|
if (!config) return
|
|
896
933
|
await ConfigStore.write(options.store, {
|
|
897
934
|
address: from,
|
|
935
|
+
chainId: options.transaction.chainId,
|
|
898
936
|
commitment: AccountConfig.getCommitment(config),
|
|
899
937
|
config,
|
|
900
938
|
})
|
|
@@ -904,7 +942,7 @@ declare namespace cacheUpgradeConfig {
|
|
|
904
942
|
/** Parameters for {@link cacheUpgradeConfig}. */
|
|
905
943
|
export type Options = {
|
|
906
944
|
/** Shared account store. */
|
|
907
|
-
store: Store.
|
|
945
|
+
store: Store.Atomic
|
|
908
946
|
/** Submitted transaction containing a potential account upgrade. */
|
|
909
947
|
transaction: Transaction.TransactionSerializableTempo
|
|
910
948
|
}
|
|
@@ -817,7 +817,12 @@ function isBaseFeeRejection(error: unknown) {
|
|
|
817
817
|
const { cause, code, message } = current as Record<string, unknown>
|
|
818
818
|
// Reth reports pool admission failures as invalid input (-32000). `transaction underpriced`
|
|
819
819
|
// reflects a node-configurable floor, so another node could still admit the envelope.
|
|
820
|
-
if (
|
|
820
|
+
if (
|
|
821
|
+
code === -32000 &&
|
|
822
|
+
typeof message === 'string' &&
|
|
823
|
+
(message === 'gas price is less than basefee' ||
|
|
824
|
+
message.startsWith('fee cap less than base fee'))
|
|
825
|
+
)
|
|
821
826
|
return true
|
|
822
827
|
current = cause
|
|
823
828
|
}
|