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.
- package/CHANGELOG.md +34 -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 +17 -3
- package/_cjs/tempo/Formatters.js.map +1 -1
- package/_cjs/tempo/Relay.js +5 -0
- 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 +17 -5
- 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/autoSwap.js +200 -0
- package/_cjs/tempo/internal/relay/autoSwap.js.map +1 -0
- package/_cjs/tempo/internal/relay/error.js +5 -1
- package/_cjs/tempo/internal/relay/error.js.map +1 -1
- package/_cjs/tempo/internal/relay/feePayer.js +4 -1
- package/_cjs/tempo/internal/relay/feePayer.js.map +1 -1
- package/_cjs/tempo/internal/relay/feeToken.js +14 -1
- package/_cjs/tempo/internal/relay/feeToken.js.map +1 -1
- package/_cjs/tempo/internal/relay/simulate.js +57 -15
- package/_cjs/tempo/internal/relay/simulate.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 +17 -4
- package/_esm/tempo/Formatters.js.map +1 -1
- package/_esm/tempo/Relay.js +20 -0
- 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 +22 -5
- 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/autoSwap.js +218 -0
- package/_esm/tempo/internal/relay/autoSwap.js.map +1 -0
- package/_esm/tempo/internal/relay/error.js +6 -2
- package/_esm/tempo/internal/relay/error.js.map +1 -1
- package/_esm/tempo/internal/relay/feePayer.js +4 -1
- package/_esm/tempo/internal/relay/feePayer.js.map +1 -1
- package/_esm/tempo/internal/relay/feeToken.js +17 -3
- package/_esm/tempo/internal/relay/feeToken.js.map +1 -1
- package/_esm/tempo/internal/relay/simulate.js +68 -17
- package/_esm/tempo/internal/relay/simulate.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 +15 -1
- package/_types/tempo/Account.d.ts.map +1 -1
- package/_types/tempo/Capabilities.d.ts +32 -2
- package/_types/tempo/Capabilities.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 +46 -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/actions/accessKey.d.ts +2 -2
- 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/autoSwap.d.ts +3 -0
- package/_types/tempo/internal/relay/autoSwap.d.ts.map +1 -0
- package/_types/tempo/internal/relay/error.d.ts.map +1 -1
- package/_types/tempo/internal/relay/feePayer.d.ts.map +1 -1
- package/_types/tempo/internal/relay/feeToken.d.ts.map +1 -1
- package/_types/tempo/internal/relay/simulate.d.ts +4 -0
- package/_types/tempo/internal/relay/simulate.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 +19 -9
- package/tempo/Capabilities.ts +34 -2
- package/tempo/Formatters.ts +24 -12
- package/tempo/Relay.ts +57 -0
- package/tempo/Transaction.ts +10 -2
- package/tempo/accounts/Config.ts +39 -16
- package/tempo/actions/accessKey.ts +2 -2
- package/tempo/chainConfig.ts +26 -5
- package/tempo/internal/relay/accounts.ts +44 -6
- package/tempo/internal/relay/autoSwap.ts +263 -0
- package/tempo/internal/relay/error.ts +7 -2
- package/tempo/internal/relay/feePayer.ts +6 -1
- package/tempo/internal/relay/feeToken.ts +21 -3
- package/tempo/internal/relay/simulate.ts +106 -19
package/tempo/Relay.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { Address } from 'abitype'
|
|
2
|
+
import type * as Hex from 'ox/Hex'
|
|
2
3
|
import * as RpcResponse from 'ox/RpcResponse'
|
|
4
|
+
import type { AccountConfig } from 'ox/tempo'
|
|
3
5
|
import type { LocalAccount } from '../accounts/types.js'
|
|
4
6
|
import type { Client as Client_ } from '../clients/createClient.js'
|
|
5
7
|
import { ChainNotConfiguredError } from '../clients/createClientResolver.js'
|
|
6
8
|
import type { EIP1193RequestOptions } from '../types/eip1193.js'
|
|
9
|
+
import type { MaybePromise } from '../types/utils.js'
|
|
7
10
|
import * as Accounts from './internal/relay/accounts.js'
|
|
11
|
+
import * as AutoSwap from './internal/relay/autoSwap.js'
|
|
8
12
|
import * as Sponsorship from './internal/relay/feePayer.js'
|
|
9
13
|
import * as FeeToken from './internal/relay/feeToken.js'
|
|
10
14
|
import * as KeyAuthorization from './internal/relay/keyAuthorization.js'
|
|
@@ -342,13 +346,66 @@ export function accounts(options: accounts.Options): accounts.ReturnType {
|
|
|
342
346
|
export declare namespace accounts {
|
|
343
347
|
/** Configurable account options. */
|
|
344
348
|
export type Options = {
|
|
349
|
+
/**
|
|
350
|
+
* Resolves a config that `store` does not hold, such as from an indexer of
|
|
351
|
+
* `ConfigurableAccountConfigUpdated` events. The plugin stores and returns
|
|
352
|
+
* a resolved config only when it matches the account and commitment.
|
|
353
|
+
*/
|
|
354
|
+
resolveConfig?:
|
|
355
|
+
| ((
|
|
356
|
+
options: resolveConfig.Options,
|
|
357
|
+
) => MaybePromise<AccountConfig.Config | null | undefined>)
|
|
358
|
+
| undefined
|
|
345
359
|
/** Store shared by relays, with atomic compare-and-set support. */
|
|
346
360
|
store: Store.Atomic
|
|
347
361
|
}
|
|
362
|
+
|
|
363
|
+
export namespace resolveConfig {
|
|
364
|
+
/** Lookup that `resolveConfig` receives. */
|
|
365
|
+
export type Options = {
|
|
366
|
+
/** Configurable account address. */
|
|
367
|
+
address: Address
|
|
368
|
+
/** Chain whose commitment the config must match. */
|
|
369
|
+
chainId: number
|
|
370
|
+
/** Config commitment read from the chain. */
|
|
371
|
+
commitment: Hex.Hex
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
348
375
|
/** Middleware advertising configurable account support. */
|
|
349
376
|
export type ReturnType = Plugin & { readonly [accountsBrand]: true }
|
|
350
377
|
}
|
|
351
378
|
|
|
379
|
+
/**
|
|
380
|
+
* Recovers fills that revert with `InsufficientBalance` by buying the missing
|
|
381
|
+
* amount on the stablecoin DEX from a funded token. The swap call is
|
|
382
|
+
* prepended to the transaction and reported as `capabilities.autoSwap`.
|
|
383
|
+
*
|
|
384
|
+
* Place this plugin last, after `Relay.simulate()`, so it sees node reverts
|
|
385
|
+
* before they become error capabilities.
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```ts
|
|
389
|
+
* import { Relay } from 'viem/tempo'
|
|
390
|
+
* const plugins = [Relay.feeToken(), Relay.simulate(), Relay.autoSwap()]
|
|
391
|
+
* ```
|
|
392
|
+
* @param options - Slippage tolerance and metadata store.
|
|
393
|
+
* @returns An auto-swap relay plugin.
|
|
394
|
+
*/
|
|
395
|
+
export function autoSwap(options: autoSwap.Options = {}): Plugin {
|
|
396
|
+
return AutoSwap.create(options)
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export declare namespace autoSwap {
|
|
400
|
+
/** Auto-swap configuration. */
|
|
401
|
+
export type Options = {
|
|
402
|
+
/** Largest accepted price slippage over the missing amount, between 0 and 1. @default 0.05 */
|
|
403
|
+
slippage?: number | undefined
|
|
404
|
+
/** Store for cached token metadata. Omit to read metadata for each request. */
|
|
405
|
+
store?: Store.Store | undefined
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
352
409
|
/**
|
|
353
410
|
* Sponsors transactions with a local account or an external fee-payer relay.
|
|
354
411
|
*
|
package/tempo/Transaction.ts
CHANGED
|
@@ -72,7 +72,10 @@ export type TransactionTempo<
|
|
|
72
72
|
isPending extends boolean = boolean,
|
|
73
73
|
type = 'tempo',
|
|
74
74
|
> = PartialBy<
|
|
75
|
-
Omit<
|
|
75
|
+
Omit<
|
|
76
|
+
TransactionBase<quantity, index, isPending>,
|
|
77
|
+
'input' | 'nonce' | 'value' | 'to'
|
|
78
|
+
>,
|
|
76
79
|
'r' | 's' | 'v' | 'yParity'
|
|
77
80
|
> & {
|
|
78
81
|
accessList: AccessList
|
|
@@ -83,12 +86,17 @@ export type TransactionTempo<
|
|
|
83
86
|
feePayerSignature?: viem_Signature | undefined
|
|
84
87
|
keyAuthorization?: KeyAuthorization.Signed<quantity, index> | null | undefined
|
|
85
88
|
operation?: AccountOperation.TransactionOperation | undefined
|
|
89
|
+
/** Sequence number, or for expiring nonce transactions (TIP-1106) an opaque `uint64` discriminator, often above `Number.MAX_SAFE_INTEGER`. */
|
|
90
|
+
nonce: quantity
|
|
86
91
|
nonceKey?: quantity | undefined
|
|
87
92
|
signature: SignatureEnvelope.SignatureEnvelope
|
|
88
93
|
type: type
|
|
89
94
|
validBefore?: index | undefined
|
|
90
95
|
validAfter?: index | undefined
|
|
91
|
-
} & FeeValuesEIP1559<quantity>
|
|
96
|
+
} & Omit<FeeValuesEIP1559<quantity>, 'gasPrice'> & {
|
|
97
|
+
/** Effective gas price the transaction paid, once included. */
|
|
98
|
+
gasPrice?: quantity | undefined
|
|
99
|
+
}
|
|
92
100
|
|
|
93
101
|
export type TransactionRequest<
|
|
94
102
|
bigintType = bigint,
|
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. */
|
|
@@ -134,7 +134,7 @@ export namespace authorize {
|
|
|
134
134
|
/**
|
|
135
135
|
* Whether to authorize the key as an admin key. Admin keys are unrestricted
|
|
136
136
|
* and can manage the account's other access keys; `expiry`, `limits`, and
|
|
137
|
-
* `scopes` are ignored. Requires the T6 hardfork.
|
|
137
|
+
* `scopes` are ignored. Requires the T6 hardfork; T14 (TIP-1137) removes admin key creation.
|
|
138
138
|
*
|
|
139
139
|
* [TIP-1049](https://tips.sh/1049)
|
|
140
140
|
*/
|
|
@@ -1135,7 +1135,7 @@ export namespace prepareAuthorization {
|
|
|
1135
1135
|
/**
|
|
1136
1136
|
* Whether to authorize the key as an admin key. Admin keys are unrestricted
|
|
1137
1137
|
* and can manage the account's other access keys; `expiry`, `limits`, and
|
|
1138
|
-
* `scopes` are ignored. Requires the T6 hardfork.
|
|
1138
|
+
* `scopes` are ignored. Requires the T6 hardfork; T14 (TIP-1137) removes admin key creation.
|
|
1139
1139
|
*
|
|
1140
1140
|
* [TIP-1049](https://tips.sh/1049)
|
|
1141
1141
|
*/
|
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
|
}),
|
|
@@ -144,11 +155,18 @@ export const chainConfig = {
|
|
|
144
155
|
// Actual tx has larger keychain/webAuthn sigs + real fee payer sig, costing more intrinsic gas.
|
|
145
156
|
if (phase === 'afterFillParameters') {
|
|
146
157
|
// Fee payer signature covers the gas limit, so the relay must set it before signing and Viem must not change it afterward.
|
|
158
|
+
// Owner approvals also cover it, so a request carrying them keeps its gas.
|
|
159
|
+
const approved =
|
|
160
|
+
Array.isArray((request as { signatures?: unknown }).signatures) &&
|
|
161
|
+
(request as { signatures: readonly unknown[] }).signatures.length > 0
|
|
147
162
|
if (
|
|
148
163
|
typeof request.gas !== 'undefined' &&
|
|
149
164
|
request.feePayer &&
|
|
150
|
-
!request.feePayerSignature
|
|
165
|
+
!request.feePayerSignature &&
|
|
166
|
+
!approved
|
|
151
167
|
) {
|
|
168
|
+
// The fill omits the fee payer's signature and fee token (85 bytes), which count toward intrinsic gas.
|
|
169
|
+
request.gas = (request.gas ?? 0n) + feePayerGas
|
|
152
170
|
if (request.keyAuthorization?.signature.type === 'webAuthn')
|
|
153
171
|
request.gas = (request.gas ?? 0n) + 20_000n
|
|
154
172
|
else if (request.account?.source === 'accessKey')
|
|
@@ -514,3 +532,6 @@ function selectOwners(config: AccountConfig.Config) {
|
|
|
514
532
|
a.owner.toLowerCase().localeCompare(b.owner.toLowerCase()),
|
|
515
533
|
)
|
|
516
534
|
}
|
|
535
|
+
|
|
536
|
+
/** Intrinsic gas reserved for a fee payer's signature and fee token, which `eth_fillTransaction` estimates without. */
|
|
537
|
+
const feePayerGas = 5_000n
|
|
@@ -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
|
}
|