viem 1.18.9 → 1.19.1
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 +22 -0
- package/README.md +1 -1
- package/_cjs/actions/test/dumpState.js +10 -0
- package/_cjs/actions/test/dumpState.js.map +1 -0
- package/_cjs/actions/test/loadState.js +11 -0
- package/_cjs/actions/test/loadState.js.map +1 -0
- package/_cjs/chains/definitions/chiliz.js +29 -0
- package/_cjs/chains/definitions/chiliz.js.map +1 -0
- package/_cjs/chains/definitions/lukso.js +31 -0
- package/_cjs/chains/definitions/lukso.js.map +1 -0
- package/_cjs/chains/definitions/spicy.js +44 -0
- package/_cjs/chains/definitions/spicy.js.map +1 -0
- package/_cjs/chains/index.js +10 -4
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/clients/decorators/test.js +4 -0
- package/_cjs/clients/decorators/test.js.map +1 -1
- package/_cjs/constants/bytes.js +5 -0
- package/_cjs/constants/bytes.js.map +1 -0
- package/_cjs/constants/strings.js +5 -0
- package/_cjs/constants/strings.js.map +1 -0
- package/_cjs/errors/node.js +11 -11
- package/_cjs/errors/node.js.map +1 -1
- package/_cjs/errors/rpc.js +18 -18
- package/_cjs/errors/rpc.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/index.js +10 -6
- package/_cjs/index.js.map +1 -1
- package/_cjs/utils/formatters/transaction.js +14 -0
- package/_cjs/utils/formatters/transaction.js.map +1 -1
- package/_cjs/utils/signature/hashMessage.js +2 -1
- package/_cjs/utils/signature/hashMessage.js.map +1 -1
- package/_cjs/utils/transaction/serializeTransaction.js +20 -4
- package/_cjs/utils/transaction/serializeTransaction.js.map +1 -1
- package/_esm/actions/test/dumpState.js +26 -0
- package/_esm/actions/test/dumpState.js.map +1 -0
- package/_esm/actions/test/loadState.js +27 -0
- package/_esm/actions/test/loadState.js.map +1 -0
- package/_esm/chains/definitions/chiliz.js +26 -0
- package/_esm/chains/definitions/chiliz.js.map +1 -0
- package/_esm/chains/definitions/lukso.js +28 -0
- package/_esm/chains/definitions/lukso.js.map +1 -0
- package/_esm/chains/definitions/spicy.js +41 -0
- package/_esm/chains/definitions/spicy.js.map +1 -0
- package/_esm/chains/index.js +3 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/clients/decorators/test.js +4 -0
- package/_esm/clients/decorators/test.js.map +1 -1
- package/_esm/constants/bytes.js +2 -0
- package/_esm/constants/bytes.js.map +1 -0
- package/_esm/constants/strings.js +2 -0
- package/_esm/constants/strings.js.map +1 -0
- package/_esm/errors/node.js +22 -11
- package/_esm/errors/node.js.map +1 -1
- package/_esm/errors/rpc.js +36 -18
- package/_esm/errors/rpc.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/index.js +2 -0
- package/_esm/index.js.map +1 -1
- package/_esm/utils/formatters/transaction.js +16 -0
- package/_esm/utils/formatters/transaction.js.map +1 -1
- package/_esm/utils/signature/hashMessage.js +2 -1
- package/_esm/utils/signature/hashMessage.js.map +1 -1
- package/_esm/utils/transaction/serializeTransaction.js +20 -6
- package/_esm/utils/transaction/serializeTransaction.js.map +1 -1
- package/_types/actions/test/dumpState.d.ts +31 -0
- package/_types/actions/test/dumpState.d.ts.map +1 -0
- package/_types/actions/test/loadState.d.ts +34 -0
- package/_types/actions/test/loadState.d.ts.map +1 -0
- package/_types/chains/celo/formatters.d.ts +24 -13
- package/_types/chains/celo/formatters.d.ts.map +1 -1
- package/_types/chains/definitions/base.d.ts +18 -10
- package/_types/chains/definitions/base.d.ts.map +1 -1
- package/_types/chains/definitions/baseGoerli.d.ts +18 -10
- package/_types/chains/definitions/baseGoerli.d.ts.map +1 -1
- package/_types/chains/definitions/baseSepolia.d.ts +18 -10
- package/_types/chains/definitions/baseSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/celo.d.ts +24 -13
- package/_types/chains/definitions/celo.d.ts.map +1 -1
- package/_types/chains/definitions/celoAlfajores.d.ts +24 -13
- package/_types/chains/definitions/celoAlfajores.d.ts.map +1 -1
- package/_types/chains/definitions/celoCannoli.d.ts +24 -13
- package/_types/chains/definitions/celoCannoli.d.ts.map +1 -1
- package/_types/chains/definitions/chiliz.d.ts +25 -0
- package/_types/chains/definitions/chiliz.d.ts.map +1 -0
- package/_types/chains/definitions/lukso.d.ts +27 -0
- package/_types/chains/definitions/lukso.d.ts.map +1 -0
- package/_types/chains/definitions/optimism.d.ts +18 -10
- package/_types/chains/definitions/optimism.d.ts.map +1 -1
- package/_types/chains/definitions/optimismGoerli.d.ts +18 -10
- package/_types/chains/definitions/optimismGoerli.d.ts.map +1 -1
- package/_types/chains/definitions/optimismSepolia.d.ts +18 -10
- package/_types/chains/definitions/optimismSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/spicy.d.ts +28 -0
- package/_types/chains/definitions/spicy.d.ts.map +1 -0
- package/_types/chains/definitions/zkSync.d.ts +11 -0
- package/_types/chains/definitions/zkSync.d.ts.map +1 -1
- package/_types/chains/definitions/zkSyncTestnet.d.ts +11 -0
- package/_types/chains/definitions/zkSyncTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/zora.d.ts +18 -10
- package/_types/chains/definitions/zora.d.ts.map +1 -1
- package/_types/chains/definitions/zoraSepolia.d.ts +18 -10
- package/_types/chains/definitions/zoraSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/zoraTestnet.d.ts +18 -10
- package/_types/chains/definitions/zoraTestnet.d.ts.map +1 -1
- package/_types/chains/index.d.ts +3 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/chains/optimism/formatters.d.ts +18 -10
- package/_types/chains/optimism/formatters.d.ts.map +1 -1
- package/_types/chains/zksync/formatters.d.ts +11 -0
- package/_types/chains/zksync/formatters.d.ts.map +1 -1
- package/_types/clients/decorators/test.d.ts +41 -0
- package/_types/clients/decorators/test.d.ts.map +1 -1
- package/_types/constants/bytes.d.ts +2 -0
- package/_types/constants/bytes.d.ts.map +1 -0
- package/_types/constants/strings.d.ts +2 -0
- package/_types/constants/strings.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/types/eip1193.d.ts +16 -0
- package/_types/types/eip1193.d.ts.map +1 -1
- package/_types/types/rpc.d.ts +2 -2
- package/_types/types/rpc.d.ts.map +1 -1
- package/_types/types/transaction.d.ts +10 -1
- package/_types/types/transaction.d.ts.map +1 -1
- package/_types/types/utils.d.ts +8 -0
- package/_types/types/utils.d.ts.map +1 -1
- package/_types/utils/formatters/transaction.d.ts +1 -1
- package/_types/utils/formatters/transaction.d.ts.map +1 -1
- package/_types/utils/formatters/transactionRequest.d.ts +1 -1
- package/_types/utils/signature/hashMessage.d.ts.map +1 -1
- package/_types/utils/transaction/serializeTransaction.d.ts.map +1 -1
- package/actions/test/dumpState.ts +44 -0
- package/actions/test/loadState.ts +47 -0
- package/chains/definitions/chiliz.ts +26 -0
- package/chains/definitions/lukso.ts +28 -0
- package/chains/definitions/spicy.ts +41 -0
- package/chains/index.ts +3 -0
- package/clients/decorators/test.ts +50 -0
- package/constants/bytes.ts +2 -0
- package/constants/strings.ts +1 -0
- package/errors/version.ts +1 -1
- package/index.ts +2 -0
- package/package.json +1 -1
- package/types/eip1193.ts +16 -0
- package/types/rpc.ts +15 -6
- package/types/transaction.ts +10 -1
- package/types/utils.ts +11 -0
- package/utils/formatters/transaction.ts +17 -2
- package/utils/signature/hashMessage.ts +2 -1
- package/utils/transaction/serializeTransaction.ts +18 -12
@@ -0,0 +1,47 @@
|
|
1
|
+
import type {
|
2
|
+
TestClient,
|
3
|
+
TestClientMode,
|
4
|
+
} from '../../clients/createTestClient.js'
|
5
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
6
|
+
import type { ErrorType } from '../../errors/utils.js'
|
7
|
+
import type { Account } from '../../types/account.js'
|
8
|
+
import type { Chain } from '../../types/chain.js'
|
9
|
+
import type { Hex } from '../../types/misc.js'
|
10
|
+
import type { RequestErrorType } from '../../utils/buildRequest.js'
|
11
|
+
|
12
|
+
export type LoadStateParameters = { state: Hex }
|
13
|
+
export type LoadStateReturnType = void
|
14
|
+
export type LoadStateErrorType = RequestErrorType | ErrorType
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Adds state previously dumped with `dumpState` to the current chain.
|
18
|
+
*
|
19
|
+
* - Docs: https://viem.sh/docs/actions/test/loadState.html
|
20
|
+
*
|
21
|
+
* @param client - Client to use
|
22
|
+
* @param parameters - {@link LoadStateParameters}
|
23
|
+
*
|
24
|
+
* @example
|
25
|
+
* import { createTestClient, http } from 'viem'
|
26
|
+
* import { foundry } from 'viem/chains'
|
27
|
+
* import { loadState } from 'viem/test'
|
28
|
+
*
|
29
|
+
* const client = createTestClient({
|
30
|
+
* mode: 'anvil',
|
31
|
+
* chain: 'foundry',
|
32
|
+
* transport: http(),
|
33
|
+
* })
|
34
|
+
* await loadState(client, { state: '0x...' })
|
35
|
+
*/
|
36
|
+
export async function loadState<
|
37
|
+
TChain extends Chain | undefined,
|
38
|
+
TAccount extends Account | undefined,
|
39
|
+
>(
|
40
|
+
client: TestClient<TestClientMode, Transport, TChain, TAccount, false>,
|
41
|
+
{ state }: LoadStateParameters,
|
42
|
+
): Promise<LoadStateReturnType> {
|
43
|
+
await client.request({
|
44
|
+
method: `${client.mode}_loadState`,
|
45
|
+
params: [state],
|
46
|
+
})
|
47
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { defineChain } from '../../utils/chain/defineChain.js'
|
2
|
+
|
3
|
+
export const chiliz = /*#__PURE__*/ defineChain({
|
4
|
+
id: 88_888,
|
5
|
+
name: 'Chiliz Chain',
|
6
|
+
network: 'chiliz-chain',
|
7
|
+
nativeCurrency: {
|
8
|
+
decimals: 18,
|
9
|
+
name: 'CHZ',
|
10
|
+
symbol: 'CHZ',
|
11
|
+
},
|
12
|
+
rpcUrls: {
|
13
|
+
default: {
|
14
|
+
http: ['https://rpc.ankr.com/chiliz', 'https://chiliz.publicnode.com'],
|
15
|
+
},
|
16
|
+
public: {
|
17
|
+
http: ['https://rpc.ankr.com/chiliz', 'https://chiliz.publicnode.com'],
|
18
|
+
},
|
19
|
+
},
|
20
|
+
blockExplorers: {
|
21
|
+
default: {
|
22
|
+
name: 'Chiliz Explorer',
|
23
|
+
url: 'https://scan.chiliz.com',
|
24
|
+
},
|
25
|
+
},
|
26
|
+
})
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { defineChain } from '../../utils/chain/defineChain.js'
|
2
|
+
|
3
|
+
export const lukso = /*#__PURE__*/ defineChain({
|
4
|
+
id: 42,
|
5
|
+
network: 'lukso',
|
6
|
+
name: 'LUKSO',
|
7
|
+
nativeCurrency: {
|
8
|
+
name: 'LUKSO',
|
9
|
+
symbol: 'LYX',
|
10
|
+
decimals: 18,
|
11
|
+
},
|
12
|
+
rpcUrls: {
|
13
|
+
default: {
|
14
|
+
http: ['https://rpc.mainnet.lukso.network'],
|
15
|
+
webSocket: ['wss://ws-rpc.mainnet.lukso.network'],
|
16
|
+
},
|
17
|
+
public: {
|
18
|
+
http: ['https://rpc.mainnet.lukso.network'],
|
19
|
+
webSocket: ['wss://ws-rpc.mainnet.lukso.network'],
|
20
|
+
},
|
21
|
+
},
|
22
|
+
blockExplorers: {
|
23
|
+
default: {
|
24
|
+
name: 'LUKSO Mainnet Explorer',
|
25
|
+
url: 'https://explorer.execution.mainnet.lukso.network',
|
26
|
+
},
|
27
|
+
},
|
28
|
+
})
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { defineChain } from '../../utils/chain/defineChain.js'
|
2
|
+
|
3
|
+
export const spicy = /*#__PURE__*/ defineChain({
|
4
|
+
id: 88_882,
|
5
|
+
name: 'Chiliz Spicy Testnet',
|
6
|
+
network: 'chiliz-spicy-Testnet',
|
7
|
+
nativeCurrency: {
|
8
|
+
decimals: 18,
|
9
|
+
name: 'CHZ',
|
10
|
+
symbol: 'CHZ',
|
11
|
+
},
|
12
|
+
rpcUrls: {
|
13
|
+
default: {
|
14
|
+
http: [
|
15
|
+
'https://spicy-rpc.chiliz.com',
|
16
|
+
'https://chiliz-spicy.publicnode.com',
|
17
|
+
],
|
18
|
+
webSocket: [
|
19
|
+
'wss://spicy-rpc-ws.chiliz.com',
|
20
|
+
'wss://chiliz-spicy.publicnode.com',
|
21
|
+
],
|
22
|
+
},
|
23
|
+
public: {
|
24
|
+
http: [
|
25
|
+
'https://spicy-rpc.chiliz.com',
|
26
|
+
'https://chiliz-spicy.publicnode.com',
|
27
|
+
],
|
28
|
+
webSocket: [
|
29
|
+
'wss://spicy-rpc-ws.chiliz.com',
|
30
|
+
'wss://chiliz-spicy.publicnode.com',
|
31
|
+
],
|
32
|
+
},
|
33
|
+
},
|
34
|
+
blockExplorers: {
|
35
|
+
default: {
|
36
|
+
name: 'Chiliz Explorer',
|
37
|
+
url: 'http://spicy-explorer.chiliz.com',
|
38
|
+
},
|
39
|
+
},
|
40
|
+
testnet: true,
|
41
|
+
})
|
package/chains/index.ts
CHANGED
@@ -25,6 +25,7 @@ export { bxnTestnet } from './definitions/bxnTestnet.js'
|
|
25
25
|
export { canto } from './definitions/canto.js'
|
26
26
|
export { celo } from './definitions/celo.js'
|
27
27
|
export { celoAlfajores } from './definitions/celoAlfajores.js'
|
28
|
+
export { chiliz } from './definitions/chiliz.js'
|
28
29
|
export { celoCannoli } from './definitions/celoCannoli.js'
|
29
30
|
export { classic } from './definitions/classic.js'
|
30
31
|
export { confluxESpace } from './definitions/confluxESpace.js'
|
@@ -72,6 +73,7 @@ export { kromaSepolia } from './definitions/kromaSepolia.js'
|
|
72
73
|
export { linea } from './definitions/linea.js'
|
73
74
|
export { lineaTestnet } from './definitions/lineaTestnet.js'
|
74
75
|
export { localhost } from './definitions/localhost.js'
|
76
|
+
export { lukso } from './definitions/lukso.js'
|
75
77
|
export { mainnet } from './definitions/mainnet.js'
|
76
78
|
export { manta } from './definitions/manta.js'
|
77
79
|
export { mantaTestnet } from './definitions/mantaTestnet.js'
|
@@ -133,6 +135,7 @@ export { skaleTitan } from './definitions/skale/titan.js'
|
|
133
135
|
export { skaleTitanTestnet } from './definitions/skale/titanTestnet.js'
|
134
136
|
export { songbird } from './definitions/songbird.js'
|
135
137
|
export { songbirdTestnet } from './definitions/songbirdTestnet.js'
|
138
|
+
export { spicy } from './definitions/spicy.js'
|
136
139
|
export { shardeumSphinx } from './definitions/shardeumSphinx.js'
|
137
140
|
export { syscoin } from './definitions/syscoin.js'
|
138
141
|
export { syscoinTestnet } from './definitions/syscoinTestnet.js'
|
@@ -2,6 +2,10 @@ import {
|
|
2
2
|
type DropTransactionParameters,
|
3
3
|
dropTransaction,
|
4
4
|
} from '../../actions/test/dropTransaction.js'
|
5
|
+
import {
|
6
|
+
type DumpStateReturnType,
|
7
|
+
dumpState,
|
8
|
+
} from '../../actions/test/dumpState.js'
|
5
9
|
import {
|
6
10
|
type GetAutomineReturnType,
|
7
11
|
getAutomine,
|
@@ -26,6 +30,11 @@ import {
|
|
26
30
|
type InspectTxpoolReturnType,
|
27
31
|
inspectTxpool,
|
28
32
|
} from '../../actions/test/inspectTxpool.js'
|
33
|
+
import {
|
34
|
+
type LoadStateParameters,
|
35
|
+
type LoadStateReturnType,
|
36
|
+
loadState,
|
37
|
+
} from '../../actions/test/loadState.js'
|
29
38
|
import { type MineParameters, mine } from '../../actions/test/mine.js'
|
30
39
|
import { removeBlockTimestampInterval } from '../../actions/test/removeBlockTimestampInterval.js'
|
31
40
|
import { type ResetParameters, reset } from '../../actions/test/reset.js'
|
@@ -113,6 +122,26 @@ export type TestActions = {
|
|
113
122
|
* })
|
114
123
|
*/
|
115
124
|
dropTransaction: (args: DropTransactionParameters) => Promise<void>
|
125
|
+
/**
|
126
|
+
* Serializes the current state (including contracts code, contract's storage,
|
127
|
+
* accounts properties, etc.) into a savable data blob.
|
128
|
+
*
|
129
|
+
* - Docs: https://viem.sh/docs/actions/test/dumpState.html
|
130
|
+
*
|
131
|
+
* @param client - Client to use
|
132
|
+
*
|
133
|
+
* @example
|
134
|
+
* import { createTestClient, http } from 'viem'
|
135
|
+
* import { foundry } from 'viem/chains'
|
136
|
+
*
|
137
|
+
* const client = createTestClient({
|
138
|
+
* mode: 'anvil',
|
139
|
+
* chain: 'foundry',
|
140
|
+
* transport: http(),
|
141
|
+
* })
|
142
|
+
* await client.dumpState()
|
143
|
+
*/
|
144
|
+
dumpState: () => Promise<DumpStateReturnType>
|
116
145
|
/**
|
117
146
|
* Returns the automatic mining status of the node.
|
118
147
|
*
|
@@ -231,6 +260,25 @@ export type TestActions = {
|
|
231
260
|
* const data = await client.inspectTxpool()
|
232
261
|
*/
|
233
262
|
inspectTxpool: () => Promise<InspectTxpoolReturnType>
|
263
|
+
/**
|
264
|
+
* Adds state previously dumped with `dumpState` to the current chain.
|
265
|
+
*
|
266
|
+
* - Docs: https://viem.sh/docs/actions/test/loadState.html
|
267
|
+
*
|
268
|
+
* @param client - Client to use
|
269
|
+
*
|
270
|
+
* @example
|
271
|
+
* import { createTestClient, http } from 'viem'
|
272
|
+
* import { foundry } from 'viem/chains'
|
273
|
+
*
|
274
|
+
* const client = createTestClient({
|
275
|
+
* mode: 'anvil',
|
276
|
+
* chain: 'foundry',
|
277
|
+
* transport: http(),
|
278
|
+
* })
|
279
|
+
* await client.loadState({ state: '0x...' })
|
280
|
+
*/
|
281
|
+
loadState: (args: LoadStateParameters) => Promise<LoadStateReturnType>
|
234
282
|
/**
|
235
283
|
* Mine a specified number of blocks.
|
236
284
|
*
|
@@ -689,12 +737,14 @@ export function testActions<TMode extends TestClientMode>({
|
|
689
737
|
}))
|
690
738
|
return {
|
691
739
|
dropTransaction: (args) => dropTransaction(client, args),
|
740
|
+
dumpState: () => dumpState(client),
|
692
741
|
getAutomine: () => getAutomine(client),
|
693
742
|
getTxpoolContent: () => getTxpoolContent(client),
|
694
743
|
getTxpoolStatus: () => getTxpoolStatus(client),
|
695
744
|
impersonateAccount: (args) => impersonateAccount(client, args),
|
696
745
|
increaseTime: (args) => increaseTime(client, args),
|
697
746
|
inspectTxpool: () => inspectTxpool(client),
|
747
|
+
loadState: (args) => loadState(client, args),
|
698
748
|
mine: (args) => mine(client, args),
|
699
749
|
removeBlockTimestampInterval: () => removeBlockTimestampInterval(client),
|
700
750
|
reset: (args) => reset(client, args),
|
@@ -0,0 +1 @@
|
|
1
|
+
export const presignMessagePrefix = '\x19Ethereum Signed Message:\n'
|
package/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '1.
|
1
|
+
export const version = '1.19.1'
|
package/index.ts
CHANGED
@@ -582,6 +582,8 @@ export {
|
|
582
582
|
minInt248,
|
583
583
|
minInt256,
|
584
584
|
} from './constants/number.js'
|
585
|
+
export { zeroHash } from './constants/bytes.js'
|
586
|
+
export { presignMessagePrefix } from './constants/strings.js'
|
585
587
|
export {
|
586
588
|
AbiConstructorNotFoundError,
|
587
589
|
type AbiConstructorNotFoundErrorType,
|
package/package.json
CHANGED
package/types/eip1193.ts
CHANGED
@@ -707,6 +707,14 @@ export type TestRpcSchema<TMode extends string> = [
|
|
707
707
|
Parameters: [hash: Hash]
|
708
708
|
ReturnType: void
|
709
709
|
},
|
710
|
+
/**
|
711
|
+
* @description Serializes the current state (including contracts code, contract's storage, accounts properties, etc.) into a savable data blob.
|
712
|
+
*/
|
713
|
+
{
|
714
|
+
Method: `${TMode}_dumpState`
|
715
|
+
Parameters?: undefined
|
716
|
+
ReturnType: Hex
|
717
|
+
},
|
710
718
|
/**
|
711
719
|
* @description Turn on call traces for transactions that are returned to the user when they execute a transaction (instead of just txhash/receipt).
|
712
720
|
*/
|
@@ -733,6 +741,14 @@ export type TestRpcSchema<TMode extends string> = [
|
|
733
741
|
Parameters?: undefined
|
734
742
|
ReturnType: boolean
|
735
743
|
},
|
744
|
+
/**
|
745
|
+
* @description Adds state previously dumped with `dumpState` to the current chain.
|
746
|
+
*/
|
747
|
+
{
|
748
|
+
Method: `${TMode}_loadState`
|
749
|
+
Parameters?: [Hex]
|
750
|
+
ReturnType: void
|
751
|
+
},
|
736
752
|
/**
|
737
753
|
* @description Advance the block number of the network by a certain number of blocks
|
738
754
|
* @link https://hardhat.org/hardhat-network/docs/reference#hardhat_mine
|
package/types/rpc.ts
CHANGED
@@ -17,7 +17,7 @@ import type {
|
|
17
17
|
TransactionRequestEIP2930,
|
18
18
|
TransactionRequestLegacy,
|
19
19
|
} from './transaction.js'
|
20
|
-
import type { UnionOmit } from './utils.js'
|
20
|
+
import type { UnionOmit, UnionPartialBy } from './utils.js'
|
21
21
|
|
22
22
|
export type Index = `0x${string}`
|
23
23
|
export type Quantity = `0x${string}`
|
@@ -46,9 +46,18 @@ export type RpcTransactionRequest =
|
|
46
46
|
| TransactionRequestLegacy<Quantity, Index, '0x0'>
|
47
47
|
| TransactionRequestEIP2930<Quantity, Index, '0x1'>
|
48
48
|
| TransactionRequestEIP1559<Quantity, Index, '0x2'>
|
49
|
-
export type RpcTransaction<
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
'
|
49
|
+
export type RpcTransaction<
|
50
|
+
TPending extends boolean = boolean,
|
51
|
+
// `yParity` is optional on the RPC type as some nodes do not return it
|
52
|
+
// for 1559 & 2930 transactions (they should!).
|
53
|
+
_optionalProperties extends 'yParity' = 'yParity',
|
54
|
+
_excludedProperties extends string = 'typeHex',
|
55
|
+
> = UnionOmit<
|
56
|
+
UnionPartialBy<
|
57
|
+
| TransactionLegacy<Quantity, Index, TPending, '0x0'>
|
58
|
+
| TransactionEIP2930<Quantity, Index, TPending, '0x1'>
|
59
|
+
| TransactionEIP1559<Quantity, Index, TPending, '0x2'>,
|
60
|
+
_optionalProperties
|
61
|
+
>,
|
62
|
+
_excludedProperties
|
54
63
|
>
|
package/types/transaction.ts
CHANGED
@@ -80,16 +80,21 @@ export type TransactionBase<
|
|
80
80
|
v: TQuantity
|
81
81
|
/** Value in wei sent with this transaction */
|
82
82
|
value: TQuantity
|
83
|
+
/** The parity of the y-value of the secp256k1 signature. */
|
84
|
+
yParity: TIndex
|
83
85
|
}
|
84
86
|
export type TransactionLegacy<
|
85
87
|
TQuantity = bigint,
|
86
88
|
TIndex = number,
|
87
89
|
TPending extends boolean = boolean,
|
88
90
|
TType = 'legacy',
|
89
|
-
> = TransactionBase<TQuantity, TIndex, TPending> &
|
91
|
+
> = Omit<TransactionBase<TQuantity, TIndex, TPending>, 'yParity'> &
|
90
92
|
FeeValuesLegacy<TQuantity> & {
|
93
|
+
/** EIP-2930 Access List. */
|
91
94
|
accessList?: never
|
95
|
+
/** Chain ID that this transaction is valid on. */
|
92
96
|
chainId?: TIndex
|
97
|
+
yParity?: never
|
93
98
|
type: TType
|
94
99
|
}
|
95
100
|
export type TransactionEIP2930<
|
@@ -99,7 +104,9 @@ export type TransactionEIP2930<
|
|
99
104
|
TType = 'eip2930',
|
100
105
|
> = TransactionBase<TQuantity, TIndex, TPending> &
|
101
106
|
FeeValuesLegacy<TQuantity> & {
|
107
|
+
/** EIP-2930 Access List. */
|
102
108
|
accessList: AccessList
|
109
|
+
/** Chain ID that this transaction is valid on. */
|
103
110
|
chainId: TIndex
|
104
111
|
type: TType
|
105
112
|
}
|
@@ -110,7 +117,9 @@ export type TransactionEIP1559<
|
|
110
117
|
TType = 'eip1559',
|
111
118
|
> = TransactionBase<TQuantity, TIndex, TPending> &
|
112
119
|
FeeValuesEIP1559<TQuantity> & {
|
120
|
+
/** EIP-2930 Access List. */
|
113
121
|
accessList: AccessList
|
122
|
+
/** Chain ID that this transaction is valid on. */
|
114
123
|
chainId: TIndex
|
115
124
|
type: TType
|
116
125
|
}
|
package/types/utils.ts
CHANGED
@@ -194,6 +194,17 @@ export type UnionOmit<T, K extends keyof any> = T extends any
|
|
194
194
|
*/
|
195
195
|
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
|
196
196
|
|
197
|
+
/**
|
198
|
+
* @description Creates a type that is a partial of T, but with the required keys K.
|
199
|
+
*
|
200
|
+
* @example
|
201
|
+
* PartialBy<{ a: string, b: number } | { a: string, b: undefined, c: number }, 'a'>
|
202
|
+
* => { a?: string, b: number } | { a?: string, b: undefined, c: number }
|
203
|
+
*/
|
204
|
+
export type UnionPartialBy<T, K extends keyof T> = T extends any
|
205
|
+
? PartialBy<T, K>
|
206
|
+
: never
|
207
|
+
|
197
208
|
/**
|
198
209
|
* @description Combines members of an intersection into a readable type.
|
199
210
|
*
|
@@ -68,18 +68,33 @@ export function formatTransaction(transaction: Partial<RpcTransaction>) {
|
|
68
68
|
typeHex: transaction.type ? transaction.type : undefined,
|
69
69
|
value: transaction.value ? BigInt(transaction.value) : undefined,
|
70
70
|
v: transaction.v ? BigInt(transaction.v) : undefined,
|
71
|
-
}
|
71
|
+
} as Transaction
|
72
|
+
|
73
|
+
transaction_.yParity = (() => {
|
74
|
+
// If `yParity` is provided, we will use it.
|
75
|
+
if (transaction.yParity) return Number(transaction.yParity)
|
76
|
+
|
77
|
+
// If no `yParity` provided, try derive from `v`.
|
78
|
+
if (typeof transaction_.v === 'bigint') {
|
79
|
+
if (transaction_.v === 0n || transaction_.v === 27n) return 0
|
80
|
+
if (transaction_.v === 1n || transaction_.v === 28n) return 1
|
81
|
+
if (transaction_.v >= 35n) return transaction_.v % 2n === 0n ? 1 : 0
|
82
|
+
}
|
83
|
+
|
84
|
+
return undefined
|
85
|
+
})()
|
72
86
|
|
73
87
|
if (transaction_.type === 'legacy') {
|
74
88
|
delete transaction_.accessList
|
75
89
|
delete transaction_.maxFeePerGas
|
76
90
|
delete transaction_.maxPriorityFeePerGas
|
91
|
+
delete transaction_.yParity
|
77
92
|
}
|
78
93
|
if (transaction_.type === 'eip2930') {
|
79
94
|
delete transaction_.maxFeePerGas
|
80
95
|
delete transaction_.maxPriorityFeePerGas
|
81
96
|
}
|
82
|
-
return transaction_
|
97
|
+
return transaction_
|
83
98
|
}
|
84
99
|
|
85
100
|
export type DefineTransactionErrorType = DefineFormatterErrorType | ErrorType
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { presignMessagePrefix } from '../../constants/strings.js'
|
1
2
|
import type { ErrorType } from '../../errors/utils.js'
|
2
3
|
import type { ByteArray, Hex, SignableMessage } from '../../types/misc.js'
|
3
4
|
import { type ConcatErrorType, concat } from '../data/concat.js'
|
@@ -32,7 +33,7 @@ export function hashMessage<TTo extends To = 'hex'>(
|
|
32
33
|
return toBytes(message.raw)
|
33
34
|
})()
|
34
35
|
const prefixBytes = stringToBytes(
|
35
|
-
|
36
|
+
`${presignMessagePrefix}${messageBytes.length}`,
|
36
37
|
)
|
37
38
|
return keccak256(concat([prefixBytes, messageBytes]), to_)
|
38
39
|
}
|
@@ -121,12 +121,15 @@ function serializeTransactionEIP1559(
|
|
121
121
|
serializedAccessList,
|
122
122
|
]
|
123
123
|
|
124
|
-
if (signature)
|
125
|
-
|
126
|
-
signature.v ===
|
127
|
-
|
128
|
-
|
129
|
-
|
124
|
+
if (signature) {
|
125
|
+
const yParity = (() => {
|
126
|
+
if (signature.v === 0n) return '0x'
|
127
|
+
if (signature.v === 1n) return toHex(1)
|
128
|
+
|
129
|
+
return signature.v === 27n ? '0x' : toHex(1)
|
130
|
+
})()
|
131
|
+
serializedTransaction.push(yParity, trim(signature.r), trim(signature.s))
|
132
|
+
}
|
130
133
|
|
131
134
|
return concatHex([
|
132
135
|
'0x02',
|
@@ -165,12 +168,15 @@ function serializeTransactionEIP2930(
|
|
165
168
|
serializedAccessList,
|
166
169
|
]
|
167
170
|
|
168
|
-
if (signature)
|
169
|
-
|
170
|
-
signature.v ===
|
171
|
-
signature.
|
172
|
-
|
173
|
-
|
171
|
+
if (signature) {
|
172
|
+
const yParity = (() => {
|
173
|
+
if (signature.v === 0n) return '0x'
|
174
|
+
if (signature.v === 1n) return toHex(1)
|
175
|
+
|
176
|
+
return signature.v === 27n ? '0x' : toHex(1)
|
177
|
+
})()
|
178
|
+
serializedTransaction.push(yParity, trim(signature.r), trim(signature.s))
|
179
|
+
}
|
174
180
|
|
175
181
|
return concatHex([
|
176
182
|
'0x01',
|