viem 2.7.1 → 2.7.3
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/call.js +69 -6
- package/_cjs/actions/public/call.js.map +1 -1
- package/_cjs/actions/public/multicall.js +2 -1
- package/_cjs/actions/public/multicall.js.map +1 -1
- package/_cjs/chains/definitions/hedera.js +27 -0
- package/_cjs/chains/definitions/hedera.js.map +1 -0
- package/_cjs/chains/definitions/hederaPreviewnet.js +27 -0
- package/_cjs/chains/definitions/hederaPreviewnet.js.map +1 -0
- package/_cjs/chains/definitions/hederaTestnet.js +27 -0
- package/_cjs/chains/definitions/hederaTestnet.js.map +1 -0
- package/_cjs/chains/definitions/optimismSepolia.js +1 -1
- package/_cjs/chains/definitions/optimismSepolia.js.map +1 -1
- package/_cjs/chains/index.js +9 -3
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/errors/contract.js +6 -2
- package/_cjs/errors/contract.js.map +1 -1
- package/_cjs/errors/data.js +15 -1
- package/_cjs/errors/data.js.map +1 -1
- package/_cjs/errors/stateOverride.js +58 -0
- package/_cjs/errors/stateOverride.js.map +1 -0
- package/_cjs/errors/version.js +1 -1
- package/_cjs/index.js +7 -4
- package/_cjs/index.js.map +1 -1
- package/_cjs/types/eip1193.js.map +1 -1
- package/_cjs/types/stateOverride.js +3 -0
- package/_cjs/types/stateOverride.js.map +1 -0
- package/_esm/actions/public/call.js +65 -5
- package/_esm/actions/public/call.js.map +1 -1
- package/_esm/actions/public/multicall.js +2 -1
- package/_esm/actions/public/multicall.js.map +1 -1
- package/_esm/chains/definitions/hedera.js +24 -0
- package/_esm/chains/definitions/hedera.js.map +1 -0
- package/_esm/chains/definitions/hederaPreviewnet.js +24 -0
- package/_esm/chains/definitions/hederaPreviewnet.js.map +1 -0
- package/_esm/chains/definitions/hederaTestnet.js +24 -0
- package/_esm/chains/definitions/hederaTestnet.js.map +1 -0
- package/_esm/chains/definitions/optimismSepolia.js +1 -1
- package/_esm/chains/definitions/optimismSepolia.js.map +1 -1
- package/_esm/chains/index.js +3 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/errors/contract.js +6 -2
- package/_esm/errors/contract.js.map +1 -1
- package/_esm/errors/data.js +13 -0
- package/_esm/errors/data.js.map +1 -1
- package/_esm/errors/stateOverride.js +51 -0
- package/_esm/errors/stateOverride.js.map +1 -0
- package/_esm/errors/version.js +1 -1
- package/_esm/index.js +1 -0
- package/_esm/index.js.map +1 -1
- package/_esm/types/eip1193.js.map +1 -1
- package/_esm/types/stateOverride.js +2 -0
- package/_esm/types/stateOverride.js.map +1 -0
- package/_types/actions/public/call.d.ts +15 -2
- package/_types/actions/public/call.d.ts.map +1 -1
- package/_types/actions/public/multicall.d.ts +1 -1
- package/_types/actions/public/multicall.d.ts.map +1 -1
- package/_types/actions/public/readContract.d.ts +1 -1
- package/_types/actions/public/readContract.d.ts.map +1 -1
- package/_types/actions/wallet/sendTransaction.d.ts +2 -2
- package/_types/actions/wallet/sendTransaction.d.ts.map +1 -1
- package/_types/chains/definitions/hedera.d.ts +36 -0
- package/_types/chains/definitions/hedera.d.ts.map +1 -0
- package/_types/chains/definitions/hederaPreviewnet.d.ts +36 -0
- package/_types/chains/definitions/hederaPreviewnet.d.ts.map +1 -0
- package/_types/chains/definitions/hederaTestnet.d.ts +36 -0
- package/_types/chains/definitions/hederaTestnet.d.ts.map +1 -0
- package/_types/chains/definitions/optimismSepolia.d.ts +1 -1
- package/_types/chains/index.d.ts +3 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/errors/contract.d.ts +1 -1
- package/_types/errors/contract.d.ts.map +1 -1
- package/_types/errors/data.d.ts +11 -0
- package/_types/errors/data.d.ts.map +1 -1
- package/_types/errors/stateOverride.d.ts +21 -0
- package/_types/errors/stateOverride.d.ts.map +1 -0
- package/_types/errors/version.d.ts +1 -1
- package/_types/index.d.ts +3 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/types/eip1193.d.ts +5 -0
- package/_types/types/eip1193.d.ts.map +1 -1
- package/_types/types/rpc.d.ts +21 -0
- package/_types/types/rpc.d.ts.map +1 -1
- package/_types/types/stateOverride.d.ts +20 -0
- package/_types/types/stateOverride.d.ts.map +1 -0
- package/actions/public/call.ts +105 -6
- package/actions/public/multicall.ts +3 -1
- package/actions/public/readContract.ts +1 -1
- package/actions/wallet/sendTransaction.ts +2 -2
- package/chains/definitions/hedera.ts +24 -0
- package/chains/definitions/hederaPreviewnet.ts +24 -0
- package/chains/definitions/hederaTestnet.ts +24 -0
- package/chains/definitions/optimismSepolia.ts +1 -1
- package/chains/index.ts +3 -0
- package/errors/contract.ts +7 -1
- package/errors/data.ts +22 -0
- package/errors/stateOverride.ts +50 -0
- package/errors/version.ts +1 -1
- package/index.ts +13 -0
- package/package.json +1 -1
- package/types/eip1193.ts +6 -0
- package/types/rpc.ts +24 -0
- package/types/stateOverride.ts +26 -0
package/errors/contract.ts
CHANGED
@@ -17,6 +17,7 @@ import { formatGwei } from '../utils/unit/formatGwei.js'
|
|
17
17
|
|
18
18
|
import { AbiErrorSignatureNotFoundError } from './abi.js'
|
19
19
|
import { BaseError } from './base.js'
|
20
|
+
import { prettyStateOverride } from './stateOverride.js'
|
20
21
|
import { prettyPrint } from './transaction.js'
|
21
22
|
import { getContractAddress } from './utils.js'
|
22
23
|
|
@@ -42,10 +43,11 @@ export class CallExecutionError extends BaseError {
|
|
42
43
|
nonce,
|
43
44
|
to,
|
44
45
|
value,
|
46
|
+
stateOverride,
|
45
47
|
}: CallParameters & { chain?: Chain; docsPath?: string },
|
46
48
|
) {
|
47
49
|
const account = account_ ? parseAccount(account_) : undefined
|
48
|
-
|
50
|
+
let prettyArgs = prettyPrint({
|
49
51
|
from: account?.address,
|
50
52
|
to,
|
51
53
|
value:
|
@@ -64,6 +66,10 @@ export class CallExecutionError extends BaseError {
|
|
64
66
|
nonce,
|
65
67
|
})
|
66
68
|
|
69
|
+
if (stateOverride) {
|
70
|
+
prettyArgs += `\n${prettyStateOverride(stateOverride)}`
|
71
|
+
}
|
72
|
+
|
67
73
|
super(cause.shortMessage, {
|
68
74
|
cause,
|
69
75
|
docsPath,
|
package/errors/data.ts
CHANGED
@@ -39,3 +39,25 @@ export class SizeExceedsPaddingSizeError extends BaseError {
|
|
39
39
|
)
|
40
40
|
}
|
41
41
|
}
|
42
|
+
|
43
|
+
export type InvalidBytesLengthErrorType = InvalidBytesLengthError & {
|
44
|
+
name: 'InvalidBytesLengthError'
|
45
|
+
}
|
46
|
+
export class InvalidBytesLengthError extends BaseError {
|
47
|
+
override name = 'InvalidBytesLengthError'
|
48
|
+
constructor({
|
49
|
+
size,
|
50
|
+
targetSize,
|
51
|
+
type,
|
52
|
+
}: {
|
53
|
+
size: number
|
54
|
+
targetSize: number
|
55
|
+
type: 'hex' | 'bytes'
|
56
|
+
}) {
|
57
|
+
super(
|
58
|
+
`${type.charAt(0).toUpperCase()}${type
|
59
|
+
.slice(1)
|
60
|
+
.toLowerCase()} is expected to be ${targetSize} ${type} long, but is ${size} ${type} long.`,
|
61
|
+
)
|
62
|
+
}
|
63
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
import type { StateMapping, StateOverride } from '../types/stateOverride.js'
|
2
|
+
import { BaseError } from './base.js'
|
3
|
+
|
4
|
+
export type AccountStateConflictErrorType = AccountStateConflictError & {
|
5
|
+
name: 'AccountStateConflictError'
|
6
|
+
}
|
7
|
+
|
8
|
+
export class AccountStateConflictError extends BaseError {
|
9
|
+
override name = 'AccountStateConflictError'
|
10
|
+
constructor({ address }: { address: string }) {
|
11
|
+
super(`State for account "${address}" is set multiple times.`)
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
export type StateAssignmentConflictErrorType = StateAssignmentConflictError & {
|
16
|
+
name: 'StateAssignmentConflictError'
|
17
|
+
}
|
18
|
+
|
19
|
+
export class StateAssignmentConflictError extends BaseError {
|
20
|
+
override name = 'StateAssignmentConflictError'
|
21
|
+
constructor() {
|
22
|
+
super('state and stateDiff are set on the same account.')
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
export function prettyStateMapping(stateMapping: StateMapping) {
|
27
|
+
return stateMapping.reduce((pretty, { slot, value }) => {
|
28
|
+
return `${pretty} ${slot}: ${value}\n`
|
29
|
+
}, '')
|
30
|
+
}
|
31
|
+
|
32
|
+
export function prettyStateOverride(stateOverride: StateOverride) {
|
33
|
+
return stateOverride
|
34
|
+
.reduce((pretty, { address, ...state }) => {
|
35
|
+
let val = `${pretty} ${address}:\n`
|
36
|
+
if (state.nonce) val += ` nonce: ${state.nonce}\n`
|
37
|
+
if (state.balance) val += ` balance: ${state.balance}\n`
|
38
|
+
if (state.code) val += ` code: ${state.code}\n`
|
39
|
+
if (state.state) {
|
40
|
+
val += ' state:\n'
|
41
|
+
val += prettyStateMapping(state.state)
|
42
|
+
}
|
43
|
+
if (state.stateDiff) {
|
44
|
+
val += ' stateDiff:\n'
|
45
|
+
val += prettyStateMapping(state.stateDiff)
|
46
|
+
}
|
47
|
+
return val
|
48
|
+
}, ' State Override:\n')
|
49
|
+
.slice(0, -1)
|
50
|
+
}
|
package/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '2.7.
|
1
|
+
export const version = '2.7.3'
|
package/index.ts
CHANGED
@@ -852,6 +852,12 @@ export {
|
|
852
852
|
UrlRequiredError,
|
853
853
|
type UrlRequiredErrorType,
|
854
854
|
} from './errors/transport.js'
|
855
|
+
export {
|
856
|
+
AccountStateConflictError,
|
857
|
+
type AccountStateConflictErrorType,
|
858
|
+
StateAssignmentConflictError,
|
859
|
+
type StateAssignmentConflictErrorType,
|
860
|
+
} from './errors/stateOverride.js'
|
855
861
|
export type {
|
856
862
|
AbiItem,
|
857
863
|
ExtractAbiFunctionForArgs,
|
@@ -973,8 +979,15 @@ export type {
|
|
973
979
|
RpcUncle,
|
974
980
|
Status,
|
975
981
|
RpcProof,
|
982
|
+
RpcAccountStateOverride,
|
983
|
+
RpcStateOverride,
|
984
|
+
RpcStateMapping,
|
976
985
|
} from './types/rpc.js'
|
977
986
|
export type { Withdrawal } from './types/withdrawal.js'
|
987
|
+
export type {
|
988
|
+
StateMapping,
|
989
|
+
StateOverride,
|
990
|
+
} from './types/stateOverride.js'
|
978
991
|
export { labelhash, type LabelhashErrorType } from './utils/ens/labelhash.js'
|
979
992
|
export { namehash, type NamehashErrorType } from './utils/ens/namehash.js'
|
980
993
|
export {
|
package/package.json
CHANGED
package/types/eip1193.ts
CHANGED
@@ -2,6 +2,7 @@ import type { Address } from 'abitype'
|
|
2
2
|
|
3
3
|
import type { BlockTag } from './block.js'
|
4
4
|
import type { Hash, Hex, LogTopic } from './misc.js'
|
5
|
+
import type { RpcStateOverride } from './rpc.js'
|
5
6
|
import type {
|
6
7
|
Quantity,
|
7
8
|
RpcBlock as Block,
|
@@ -232,6 +233,11 @@ export type PublicRpcSchema = [
|
|
232
233
|
transaction: Partial<TransactionRequest>,
|
233
234
|
block: BlockNumber | BlockTag | BlockIdentifier,
|
234
235
|
]
|
236
|
+
| [
|
237
|
+
transaction: Partial<TransactionRequest>,
|
238
|
+
block: BlockNumber | BlockTag | BlockIdentifier,
|
239
|
+
stateOverrideSet: RpcStateOverride,
|
240
|
+
]
|
235
241
|
ReturnType: Hex
|
236
242
|
},
|
237
243
|
/**
|
package/types/rpc.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import type { Address } from 'abitype'
|
1
2
|
import type {
|
2
3
|
Block,
|
3
4
|
BlockIdentifier,
|
@@ -7,6 +8,7 @@ import type {
|
|
7
8
|
} from './block.js'
|
8
9
|
import type { FeeHistory, FeeValues } from './fee.js'
|
9
10
|
import type { Log } from './log.js'
|
11
|
+
import type { Hex } from './misc.js'
|
10
12
|
import type { Proof } from './proof.js'
|
11
13
|
import type {
|
12
14
|
TransactionEIP1559,
|
@@ -103,3 +105,25 @@ export type RpcResponse<TResult = any, TError = any> = {
|
|
103
105
|
| ErrorResult<TError>
|
104
106
|
| Subscription<TResult, TError>
|
105
107
|
)
|
108
|
+
|
109
|
+
/** A key-value mapping of slot and storage values (supposedly 32 bytes each) */
|
110
|
+
export type RpcStateMapping = {
|
111
|
+
[slots: Hex]: Hex
|
112
|
+
}
|
113
|
+
|
114
|
+
export type RpcAccountStateOverride = {
|
115
|
+
/** Fake balance to set for the account before executing the call. <32 bytes */
|
116
|
+
balance?: Hex
|
117
|
+
/** Fake nonce to set for the account before executing the call. <8 bytes */
|
118
|
+
nonce?: Hex
|
119
|
+
/** Fake EVM bytecode to inject into the account before executing the call. */
|
120
|
+
code?: Hex
|
121
|
+
/** Fake key-value mapping to override all slots in the account storage before executing the call. */
|
122
|
+
state?: RpcStateMapping
|
123
|
+
/** Fake key-value mapping to override individual slots in the account storage before executing the call. */
|
124
|
+
stateDiff?: RpcStateMapping
|
125
|
+
}
|
126
|
+
|
127
|
+
export type RpcStateOverride = {
|
128
|
+
[address: Address]: RpcAccountStateOverride
|
129
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import type { Address } from 'abitype'
|
2
|
+
import type { Hex } from './misc.js'
|
3
|
+
import type { OneOf } from './utils.js'
|
4
|
+
|
5
|
+
export type StateMapping = Array<{
|
6
|
+
slot: Hex
|
7
|
+
value: Hex
|
8
|
+
}>
|
9
|
+
|
10
|
+
export type StateOverride = Array<
|
11
|
+
{
|
12
|
+
address: Address
|
13
|
+
balance?: bigint
|
14
|
+
nonce?: number
|
15
|
+
code?: Hex
|
16
|
+
} & OneOf<
|
17
|
+
| {
|
18
|
+
/** Fake key-value mapping to override all slots in the account storage before executing the call. */
|
19
|
+
state?: StateMapping
|
20
|
+
}
|
21
|
+
| {
|
22
|
+
/** Fake key-value mapping to override individual slots in the account storage before executing the call. */
|
23
|
+
stateDiff?: StateMapping
|
24
|
+
}
|
25
|
+
>
|
26
|
+
>
|