viem 0.0.1-alpha.24 → 0.0.1-alpha.25
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/contract/package.json +4 -0
- package/dist/call-ac509982.d.ts +23 -0
- package/dist/{chain-e33d019b.d.ts → chain-c4ccb458.d.ts} +1 -1
- package/dist/{chain-afa13f5a.d.ts → chain-f16512e8.d.ts} +20 -1
- package/dist/chains.d.ts +20 -8
- package/dist/chains.js +46 -46
- package/dist/chains.mjs +1 -1
- package/dist/{chunk-YQUC52RL.mjs → chunk-2Y3UZMSP.mjs} +77 -84
- package/dist/chunk-2Y3UZMSP.mjs.map +1 -0
- package/dist/{chunk-A2HXAZXC.js → chunk-CD2XJOBJ.js} +135 -142
- package/dist/chunk-CD2XJOBJ.js.map +1 -0
- package/dist/{chunk-LQVMDX5I.mjs → chunk-KSAO4Y4Q.mjs} +133 -54
- package/dist/chunk-KSAO4Y4Q.mjs.map +1 -0
- package/dist/{chunk-3ARWEJ3G.mjs → chunk-LEPQJNVO.mjs} +18 -2
- package/dist/chunk-LEPQJNVO.mjs.map +1 -0
- package/dist/{chunk-ZYSXBTBB.js → chunk-NUXMGPMK.js} +30 -14
- package/dist/chunk-NUXMGPMK.js.map +1 -0
- package/dist/{chunk-4D5XG6XB.js → chunk-THMRUG4D.js} +148 -69
- package/dist/chunk-THMRUG4D.js.map +1 -0
- package/dist/{contract-70f4ddbe.d.ts → contract-9e76e561.d.ts} +44 -31
- package/dist/contract.d.ts +123 -0
- package/dist/contract.js +53 -0
- package/dist/{clients/index.js.map → contract.js.map} +0 -0
- package/dist/contract.mjs +53 -0
- package/dist/{clients/index.mjs.map → contract.mjs.map} +0 -0
- package/dist/{createClient-60e3ab98.d.ts → createClient-68ee4bb4.d.ts} +3 -3
- package/dist/{createPublicClient-d3d12dc3.d.ts → createPublicClient-b732194e.d.ts} +3 -3
- package/dist/{createTestClient-5f4532c4.d.ts → createTestClient-dedf321e.d.ts} +3 -3
- package/dist/{createWalletClient-9ec3df4f.d.ts → createWalletClient-75813d83.d.ts} +3 -3
- package/dist/decodeErrorResult-0b934d23.d.ts +16 -0
- package/dist/{eip1193-9317a312.d.ts → eip1193-6f9ba163.d.ts} +1 -1
- package/dist/ens.d.ts +82 -1
- package/dist/ens.js +208 -3
- package/dist/ens.js.map +1 -1
- package/dist/ens.mjs +209 -4
- package/dist/ens.mjs.map +1 -1
- package/dist/getAbiItem-c8e6e7d4.d.ts +97 -0
- package/dist/index.d.ts +85 -175
- package/dist/index.js +237 -279
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +245 -287
- package/dist/index.mjs.map +1 -1
- package/dist/public.d.ts +352 -10
- package/dist/public.js +3 -4
- package/dist/public.mjs +6 -7
- package/dist/readContract-4f6e2692.d.ts +10 -0
- package/dist/rpc-a5a7f376.d.ts +121 -0
- package/dist/{sendTransaction-54a0d509.d.ts → sendTransaction-e713f90c.d.ts} +3 -3
- package/dist/test.d.ts +160 -5
- package/dist/test.js +222 -18
- package/dist/test.js.map +1 -1
- package/dist/test.mjs +233 -29
- package/dist/test.mjs.map +1 -1
- package/dist/transactionReceipt-2a86c7c7.d.ts +26 -0
- package/dist/{transactionRequest-bdf57f7d.d.ts → transactionRequest-c7794f5e.d.ts} +1 -1
- package/dist/utils/index.d.ts +224 -20
- package/dist/utils/index.js +2 -6
- package/dist/utils/index.mjs +3 -7
- package/dist/wallet.d.ts +41 -7
- package/dist/wallet.js +3 -3
- package/dist/wallet.mjs +2 -2
- package/dist/watchEvent-c346c12d.d.ts +41 -0
- package/dist/window.d.ts +2 -2
- package/ens/package.json +4 -0
- package/package.json +13 -9
- package/src/_test/constants.ts +2 -0
- package/src/_test/utils.ts +10 -5
- package/src/actions/ens/getEnsAddress.bench.ts +26 -0
- package/src/actions/ens/getEnsAddress.test.ts +97 -0
- package/src/actions/ens/getEnsAddress.ts +122 -0
- package/src/actions/ens/getEnsName.bench.ts +30 -0
- package/src/actions/ens/getEnsName.test.ts +101 -0
- package/src/actions/ens/getEnsName.ts +106 -0
- package/src/actions/ens/index.test.ts +12 -0
- package/src/actions/ens/index.ts +3 -0
- package/src/actions/index.ts +3 -3
- package/src/actions/public/createEventFilter.test.ts +36 -4
- package/src/actions/public/createEventFilter.ts +27 -10
- package/src/actions/public/getFilterChanges.test.ts +198 -4
- package/src/actions/public/getFilterLogs.test.ts +195 -2
- package/src/actions/public/getLogs.test.ts +201 -2
- package/src/actions/public/index.test.ts +0 -1
- package/src/actions/public/index.ts +1 -7
- package/src/actions/public/multicall.ts +8 -3
- package/src/actions/public/simulateContract.ts +1 -4
- package/src/actions/public/watchContractEvent.test.ts +4 -4
- package/src/actions/{public → wallet}/deployContract.test.ts +1 -2
- package/src/actions/{public → wallet}/deployContract.ts +0 -0
- package/src/actions/wallet/index.test.ts +1 -0
- package/src/actions/wallet/index.ts +6 -0
- package/src/chains.test.ts +44 -1517
- package/src/clients/transports/webSocket.test.ts +1 -0
- package/src/clients/transports/webSocket.ts +1 -0
- package/src/contract.test.ts +31 -0
- package/src/contract.ts +68 -0
- package/src/ens.test.ts +15 -0
- package/src/ens.ts +4 -1
- package/src/errors/abi.ts +18 -2
- package/src/errors/chain.test.ts +46 -0
- package/src/errors/chain.ts +33 -0
- package/src/errors/contract.ts +2 -2
- package/src/errors/index.ts +3 -0
- package/src/index.test.ts +0 -147
- package/src/index.ts +0 -257
- package/src/public.test.ts +36 -0
- package/src/public.ts +2 -6
- package/src/test.test.ts +38 -0
- package/src/test.ts +1 -0
- package/src/types/contract.ts +144 -40
- package/src/types/index.ts +2 -1
- package/src/types/utils.ts +21 -0
- package/src/utils/abi/decodeErrorResult.test.ts +1 -1
- package/src/utils/abi/decodeEventLog.test.ts +542 -0
- package/src/utils/abi/decodeEventLog.ts +107 -0
- package/src/utils/abi/decodeFunctionData.test.ts +1 -2
- package/src/utils/abi/decodeFunctionData.ts +5 -2
- package/src/utils/abi/encodeFunctionData.ts +1 -4
- package/src/utils/abi/index.test.ts +1 -0
- package/src/utils/abi/index.ts +6 -0
- package/src/utils/ens/index.test.ts +1 -0
- package/src/utils/ens/index.ts +2 -0
- package/src/utils/ens/packetToBytes.test.ts +11 -0
- package/src/utils/ens/packetToBytes.ts +29 -0
- package/src/utils/index.test.ts +1 -3
- package/src/utils/index.ts +3 -2
- package/src/utils/rpc.test.ts +1 -0
- package/src/utils/rpc.ts +4 -2
- package/src/wallet.test.ts +19 -0
- package/wallet/package.json +4 -0
- package/clients/package.json +0 -4
- package/dist/chunk-3ARWEJ3G.mjs.map +0 -1
- package/dist/chunk-4D5XG6XB.js.map +0 -1
- package/dist/chunk-6QTEW2BE.mjs +0 -260
- package/dist/chunk-6QTEW2BE.mjs.map +0 -1
- package/dist/chunk-A2HXAZXC.js.map +0 -1
- package/dist/chunk-KRPS5CIB.mjs +0 -256
- package/dist/chunk-KRPS5CIB.mjs.map +0 -1
- package/dist/chunk-LQVMDX5I.mjs.map +0 -1
- package/dist/chunk-N3IOPT3R.js +0 -256
- package/dist/chunk-N3IOPT3R.js.map +0 -1
- package/dist/chunk-YQUC52RL.mjs.map +0 -1
- package/dist/chunk-ZSTVHQ6J.js +0 -260
- package/dist/chunk-ZSTVHQ6J.js.map +0 -1
- package/dist/chunk-ZYSXBTBB.js.map +0 -1
- package/dist/clients/index.d.ts +0 -9
- package/dist/clients/index.js +0 -24
- package/dist/clients/index.mjs +0 -24
- package/dist/normalize-ef9240c0.d.ts +0 -33
- package/dist/parseGwei-492ab7dd.d.ts +0 -355
- package/dist/rpc-26932bae.d.ts +0 -61
- package/dist/stopImpersonatingAccount-c1a4b7e5.d.ts +0 -156
- package/dist/watchAsset-d59d6e35.d.ts +0 -38
- package/dist/watchPendingTransactions-ea21b31d.d.ts +0 -373
- package/dist/webSocket-775b4037.d.ts +0 -83
package/src/index.ts
CHANGED
@@ -1,172 +1,3 @@
|
|
1
|
-
export type {
|
2
|
-
CallArgs,
|
3
|
-
CallResponse,
|
4
|
-
CreateBlockFilterResponse,
|
5
|
-
CreateContractEventFilterArgs,
|
6
|
-
CreateContractEventFilterResponse,
|
7
|
-
CreateEventFilterArgs,
|
8
|
-
CreateEventFilterResponse,
|
9
|
-
CreatePendingTransactionFilterResponse,
|
10
|
-
EstimateGasArgs,
|
11
|
-
EstimateGasResponse,
|
12
|
-
DeployContractArgs,
|
13
|
-
DeployContractResponse,
|
14
|
-
DropTransactionArgs,
|
15
|
-
GetBalanceArgs,
|
16
|
-
GetBalanceResponse,
|
17
|
-
GetBlockArgs,
|
18
|
-
GetBlockNumberArgs,
|
19
|
-
GetBlockNumberResponse,
|
20
|
-
GetBlockResponse,
|
21
|
-
GetBlockTransactionCountArgs,
|
22
|
-
GetBlockTransactionCountResponse,
|
23
|
-
GetBytecodeArgs,
|
24
|
-
GetBytecodeResponse,
|
25
|
-
GetFeeHistoryArgs,
|
26
|
-
GetFeeHistoryResponse,
|
27
|
-
GetFilterChangesArgs,
|
28
|
-
GetFilterChangesResponse,
|
29
|
-
GetFilterLogsArgs,
|
30
|
-
GetFilterLogsResponse,
|
31
|
-
GetGasPriceResponse,
|
32
|
-
GetLogsArgs,
|
33
|
-
GetLogsResponse,
|
34
|
-
GetPermissionsResponse,
|
35
|
-
GetStorageAtArgs,
|
36
|
-
GetStorageAtResponse,
|
37
|
-
GetTransactionArgs,
|
38
|
-
GetTransactionConfirmationsArgs,
|
39
|
-
GetTransactionConfirmationsResponse,
|
40
|
-
GetTransactionCountArgs,
|
41
|
-
GetTransactionCountResponse,
|
42
|
-
GetTransactionResponse,
|
43
|
-
GetTransactionReceiptArgs,
|
44
|
-
GetTransactionReceiptResponse,
|
45
|
-
ImpersonateAccountArgs,
|
46
|
-
IncreaseTimeArgs,
|
47
|
-
MineArgs,
|
48
|
-
MulticallArgs,
|
49
|
-
OnBlock,
|
50
|
-
OnBlockNumber,
|
51
|
-
OnBlockNumberResponse,
|
52
|
-
OnBlockResponse,
|
53
|
-
OnLogs,
|
54
|
-
OnLogsResponse,
|
55
|
-
OnTransactions,
|
56
|
-
OnTransactionsResponse,
|
57
|
-
ReadContractArgs,
|
58
|
-
ReadContractResponse,
|
59
|
-
ResetArgs,
|
60
|
-
RequestPermissionsResponse,
|
61
|
-
RevertArgs,
|
62
|
-
SendTransactionArgs,
|
63
|
-
SendTransactionResponse,
|
64
|
-
SendUnsignedTransactionArgs,
|
65
|
-
SendUnsignedTransactionResponse,
|
66
|
-
SetBalanceArgs,
|
67
|
-
SetBlockGasLimitArgs,
|
68
|
-
SetCodeArgs,
|
69
|
-
SetCoinbaseArgs,
|
70
|
-
SetIntervalMiningArgs,
|
71
|
-
SetMinGasPriceArgs,
|
72
|
-
SetBlockTimestampIntervalArgs,
|
73
|
-
SetNextBlockTimestampArgs,
|
74
|
-
SetNextBlockBaseFeePerGasArgs,
|
75
|
-
SetNonceArgs,
|
76
|
-
SetStorageAtArgs,
|
77
|
-
SignMessageArgs,
|
78
|
-
SignMessageResponse,
|
79
|
-
SimulateContractArgs,
|
80
|
-
SimulateContractResponse,
|
81
|
-
StopImpersonatingAccountArgs,
|
82
|
-
SwitchChainArgs,
|
83
|
-
UninstallFilterArgs,
|
84
|
-
UninstallFilterResponse,
|
85
|
-
WaitForTransactionReceiptArgs,
|
86
|
-
WaitForTransactionReceiptResponse,
|
87
|
-
WatchAssetArgs,
|
88
|
-
WatchAssetResponse,
|
89
|
-
WatchBlockNumberArgs,
|
90
|
-
WatchBlocksArgs,
|
91
|
-
WatchPendingTransactionsArgs,
|
92
|
-
WatchContractEventArgs,
|
93
|
-
WatchEventArgs,
|
94
|
-
WriteContractArgs,
|
95
|
-
WriteContractResponse,
|
96
|
-
} from './actions'
|
97
|
-
export {
|
98
|
-
addChain,
|
99
|
-
call,
|
100
|
-
createBlockFilter,
|
101
|
-
createContractEventFilter,
|
102
|
-
createEventFilter,
|
103
|
-
createPendingTransactionFilter,
|
104
|
-
deployContract,
|
105
|
-
dropTransaction,
|
106
|
-
estimateGas,
|
107
|
-
getAccounts,
|
108
|
-
getAutomine,
|
109
|
-
getBalance,
|
110
|
-
getBlock,
|
111
|
-
getBlockNumber,
|
112
|
-
getBlockTransactionCount,
|
113
|
-
getBytecode,
|
114
|
-
getChainId,
|
115
|
-
getFeeHistory,
|
116
|
-
getFilterChanges,
|
117
|
-
getFilterLogs,
|
118
|
-
getGasPrice,
|
119
|
-
getLogs,
|
120
|
-
getPermissions,
|
121
|
-
getStorageAt,
|
122
|
-
getTransaction,
|
123
|
-
getTransactionConfirmations,
|
124
|
-
getTransactionCount,
|
125
|
-
getTransactionReceipt,
|
126
|
-
getTxpoolContent,
|
127
|
-
getTxpoolStatus,
|
128
|
-
impersonateAccount,
|
129
|
-
increaseTime,
|
130
|
-
inspectTxpool,
|
131
|
-
mine,
|
132
|
-
multicall,
|
133
|
-
readContract,
|
134
|
-
removeBlockTimestampInterval,
|
135
|
-
reset,
|
136
|
-
requestAccounts,
|
137
|
-
requestPermissions,
|
138
|
-
revert,
|
139
|
-
sendTransaction,
|
140
|
-
sendUnsignedTransaction,
|
141
|
-
setAutomine,
|
142
|
-
setBalance,
|
143
|
-
setBlockGasLimit,
|
144
|
-
setBlockTimestampInterval,
|
145
|
-
setCode,
|
146
|
-
setCoinbase,
|
147
|
-
setIntervalMining,
|
148
|
-
setLoggingEnabled,
|
149
|
-
setMinGasPrice,
|
150
|
-
setNextBlockBaseFeePerGas,
|
151
|
-
setNextBlockTimestamp,
|
152
|
-
setNonce,
|
153
|
-
setStorageAt,
|
154
|
-
signMessage,
|
155
|
-
simulateContract,
|
156
|
-
snapshot,
|
157
|
-
stopImpersonatingAccount,
|
158
|
-
switchChain,
|
159
|
-
uninstallFilter,
|
160
|
-
waitForTransactionReceipt,
|
161
|
-
watchAsset,
|
162
|
-
watchBlockNumber,
|
163
|
-
watchBlocks,
|
164
|
-
watchPendingTransactions,
|
165
|
-
watchContractEvent,
|
166
|
-
watchEvent,
|
167
|
-
writeContract,
|
168
|
-
} from './actions'
|
169
|
-
|
170
1
|
export type {
|
171
2
|
Client,
|
172
3
|
ClientConfig,
|
@@ -299,91 +130,3 @@ export type {
|
|
299
130
|
TransactionLegacy,
|
300
131
|
Uncle,
|
301
132
|
} from './types'
|
302
|
-
|
303
|
-
export type {
|
304
|
-
DecodeAbiArgs,
|
305
|
-
DecodeErrorResultArgs,
|
306
|
-
DecodeFunctionDataArgs,
|
307
|
-
DecodeFunctionResultArgs,
|
308
|
-
DecodeFunctionResultResponse,
|
309
|
-
EncodeAbiArgs,
|
310
|
-
EncodeDeployDataArgs,
|
311
|
-
EncodeErrorResultArgs,
|
312
|
-
EncodeEventTopicsArgs,
|
313
|
-
EncodeFunctionDataArgs,
|
314
|
-
EncodeFunctionResultArgs,
|
315
|
-
GetContractAddressOptions,
|
316
|
-
GetCreateAddressOptions,
|
317
|
-
GetCreate2AddressOptions,
|
318
|
-
GetAbiItemArgs,
|
319
|
-
EncodeRlpResponse,
|
320
|
-
FormattedBlock,
|
321
|
-
FormattedTransaction,
|
322
|
-
FormattedTransactionRequest,
|
323
|
-
} from './utils'
|
324
|
-
export {
|
325
|
-
bytesToHex,
|
326
|
-
bytesToString,
|
327
|
-
boolToBytes,
|
328
|
-
boolToHex,
|
329
|
-
bytesToBigint,
|
330
|
-
bytesToBool,
|
331
|
-
bytesToNumber,
|
332
|
-
decodeAbi,
|
333
|
-
decodeBytes,
|
334
|
-
decodeErrorResult,
|
335
|
-
decodeFunctionData,
|
336
|
-
decodeFunctionResult,
|
337
|
-
decodeHex,
|
338
|
-
decodeRlp,
|
339
|
-
encodeAbi,
|
340
|
-
encodeBytes,
|
341
|
-
encodeDeployData,
|
342
|
-
encodeErrorResult,
|
343
|
-
encodeEventTopics,
|
344
|
-
encodeFunctionData,
|
345
|
-
encodeFunctionResult,
|
346
|
-
encodeHex,
|
347
|
-
encodeRlp,
|
348
|
-
etherUnits,
|
349
|
-
getAddress,
|
350
|
-
getContractAddress,
|
351
|
-
getCreateAddress,
|
352
|
-
getCreate2Address,
|
353
|
-
getEventSignature,
|
354
|
-
getFunctionSignature,
|
355
|
-
gweiUnits,
|
356
|
-
formatEther,
|
357
|
-
isAddress,
|
358
|
-
isAddressEqual,
|
359
|
-
isBytes,
|
360
|
-
isHex,
|
361
|
-
hexToBigInt,
|
362
|
-
hexToBool,
|
363
|
-
hexToBytes,
|
364
|
-
hexToString,
|
365
|
-
keccak256,
|
366
|
-
numberToBytes,
|
367
|
-
pad,
|
368
|
-
padBytes,
|
369
|
-
padHex,
|
370
|
-
parseEther,
|
371
|
-
parseGwei,
|
372
|
-
parseUnit,
|
373
|
-
formatBlock,
|
374
|
-
formatGwei,
|
375
|
-
formatTransaction,
|
376
|
-
formatTransactionRequest,
|
377
|
-
formatUnit,
|
378
|
-
hexToNumber,
|
379
|
-
numberToHex,
|
380
|
-
size,
|
381
|
-
slice,
|
382
|
-
sliceBytes,
|
383
|
-
sliceHex,
|
384
|
-
stringToBytes,
|
385
|
-
stringToHex,
|
386
|
-
transactionType,
|
387
|
-
trim,
|
388
|
-
weiUnits,
|
389
|
-
} from './utils'
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { expect, test } from 'vitest'
|
2
|
+
|
3
|
+
import * as public_ from './public'
|
4
|
+
|
5
|
+
test('exports public actions', () => {
|
6
|
+
expect(Object.keys(public_)).toMatchInlineSnapshot(`
|
7
|
+
[
|
8
|
+
"call",
|
9
|
+
"createBlockFilter",
|
10
|
+
"createPendingTransactionFilter",
|
11
|
+
"estimateGas",
|
12
|
+
"getBalance",
|
13
|
+
"getBlock",
|
14
|
+
"getBlockNumber",
|
15
|
+
"getBlockNumberCache",
|
16
|
+
"getBlockTransactionCount",
|
17
|
+
"getBytecode",
|
18
|
+
"getChainId",
|
19
|
+
"getFeeHistory",
|
20
|
+
"getFilterChanges",
|
21
|
+
"getFilterLogs",
|
22
|
+
"getLogs",
|
23
|
+
"getGasPrice",
|
24
|
+
"getTransaction",
|
25
|
+
"getTransactionConfirmations",
|
26
|
+
"getTransactionCount",
|
27
|
+
"getTransactionReceipt",
|
28
|
+
"uninstallFilter",
|
29
|
+
"waitForTransactionReceipt",
|
30
|
+
"watchBlockNumber",
|
31
|
+
"watchBlocks",
|
32
|
+
"watchEvent",
|
33
|
+
"watchPendingTransactions",
|
34
|
+
]
|
35
|
+
`)
|
36
|
+
})
|
package/src/public.ts
CHANGED
@@ -2,7 +2,6 @@ export {
|
|
2
2
|
call,
|
3
3
|
createBlockFilter,
|
4
4
|
createPendingTransactionFilter,
|
5
|
-
deployContract,
|
6
5
|
estimateGas,
|
7
6
|
getBalance,
|
8
7
|
getBlock,
|
@@ -14,16 +13,17 @@ export {
|
|
14
13
|
getFeeHistory,
|
15
14
|
getFilterChanges,
|
16
15
|
getFilterLogs,
|
16
|
+
getLogs,
|
17
17
|
getGasPrice,
|
18
18
|
getTransaction,
|
19
19
|
getTransactionConfirmations,
|
20
20
|
getTransactionCount,
|
21
21
|
getTransactionReceipt,
|
22
|
-
simulateContract,
|
23
22
|
uninstallFilter,
|
24
23
|
waitForTransactionReceipt,
|
25
24
|
watchBlockNumber,
|
26
25
|
watchBlocks,
|
26
|
+
watchEvent,
|
27
27
|
watchPendingTransactions,
|
28
28
|
} from './actions/public'
|
29
29
|
export type {
|
@@ -31,8 +31,6 @@ export type {
|
|
31
31
|
CallResponse,
|
32
32
|
CreateBlockFilterResponse,
|
33
33
|
CreatePendingTransactionFilterResponse,
|
34
|
-
DeployContractArgs,
|
35
|
-
DeployContractResponse,
|
36
34
|
EstimateGasArgs,
|
37
35
|
EstimateGasResponse,
|
38
36
|
GetBalanceArgs,
|
@@ -68,8 +66,6 @@ export type {
|
|
68
66
|
OnTransactionsResponse,
|
69
67
|
ReplacementReason,
|
70
68
|
ReplacementResponse,
|
71
|
-
SimulateContractArgs,
|
72
|
-
SimulateContractResponse,
|
73
69
|
UninstallFilterArgs,
|
74
70
|
UninstallFilterResponse,
|
75
71
|
WaitForTransactionReceiptArgs,
|
package/src/test.test.ts
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
import { expect, test } from 'vitest'
|
2
|
+
|
3
|
+
import * as test_ from './test'
|
4
|
+
|
5
|
+
test('exports test actions', () => {
|
6
|
+
expect(Object.keys(test_)).toMatchInlineSnapshot(`
|
7
|
+
[
|
8
|
+
"dropTransaction",
|
9
|
+
"getAutomine",
|
10
|
+
"getTxpoolContent",
|
11
|
+
"getTxpoolStatus",
|
12
|
+
"impersonateAccount",
|
13
|
+
"increaseTime",
|
14
|
+
"inspectTxpool",
|
15
|
+
"mine",
|
16
|
+
"removeBlockTimestampInterval",
|
17
|
+
"reset",
|
18
|
+
"revert",
|
19
|
+
"sendUnsignedTransaction",
|
20
|
+
"setAutomine",
|
21
|
+
"setBalance",
|
22
|
+
"setBlockGasLimit",
|
23
|
+
"setBlockTimestampInterval",
|
24
|
+
"setCode",
|
25
|
+
"setCoinbase",
|
26
|
+
"setIntervalMining",
|
27
|
+
"setLoggingEnabled",
|
28
|
+
"setMinGasPrice",
|
29
|
+
"setNextBlockBaseFeePerGas",
|
30
|
+
"setNextBlockTimestamp",
|
31
|
+
"setNonce",
|
32
|
+
"setStorageAt",
|
33
|
+
"snapshot",
|
34
|
+
"setRpcUrl",
|
35
|
+
"stopImpersonatingAccount",
|
36
|
+
]
|
37
|
+
`)
|
38
|
+
})
|
package/src/test.ts
CHANGED
package/src/types/contract.ts
CHANGED
@@ -17,49 +17,135 @@ import type {
|
|
17
17
|
ExtractAbiFunctionNames,
|
18
18
|
Narrow,
|
19
19
|
} from 'abitype'
|
20
|
-
import type { Address } from './misc'
|
20
|
+
import type { Address, Hex, LogTopic } from './misc'
|
21
21
|
import type { TransactionRequest } from './transaction'
|
22
|
-
import type { Trim } from './utils'
|
22
|
+
import type { NoUndefined, Prettify, Trim } from './utils'
|
23
23
|
|
24
24
|
//////////////////////////////////////////////////////////////////////
|
25
25
|
// ABIs
|
26
26
|
|
27
27
|
export type AbiItem = Abi[number]
|
28
28
|
|
29
|
+
type HashedEventTypes = 'string' | 'bytes' | 'tuple' | `${string}[${string}]`
|
30
|
+
|
31
|
+
type EventTopicParam<
|
32
|
+
TPrimitiveType = Hex,
|
33
|
+
TTopic extends LogTopic = LogTopic,
|
34
|
+
> = NoUndefined<
|
35
|
+
| (TTopic extends Hex ? TPrimitiveType : undefined)
|
36
|
+
| (TTopic extends Hex[] ? TPrimitiveType[] : undefined)
|
37
|
+
| (TTopic extends null ? null : undefined)
|
38
|
+
>
|
39
|
+
|
40
|
+
export type AbiEventParameterToPrimitiveType<TParam extends AbiParameter> =
|
41
|
+
EventTopicParam<AbiParameterToPrimitiveType<TParam>>
|
42
|
+
|
29
43
|
export type AbiEventParametersToPrimitiveTypes<
|
30
44
|
TAbiParameters extends readonly AbiParameter[],
|
31
45
|
TBase = TAbiParameters[0] extends { name: string } ? {} : [],
|
32
|
-
> =
|
33
|
-
|
34
|
-
? Head extends
|
35
|
-
? Head extends
|
36
|
-
?
|
37
|
-
?
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
? []
|
56
|
-
: Tail extends readonly AbiParameter[]
|
57
|
-
? AbiEventParametersToPrimitiveTypes<Tail>
|
58
|
-
: []),
|
59
|
-
]
|
46
|
+
> = Prettify<
|
47
|
+
TAbiParameters extends readonly [infer Head, ...infer Tail]
|
48
|
+
? Head extends { indexed: true }
|
49
|
+
? Head extends AbiParameter
|
50
|
+
? Head extends { name: infer Name }
|
51
|
+
? Name extends string
|
52
|
+
? {
|
53
|
+
[name in Name]?: AbiEventParameterToPrimitiveType<Head>
|
54
|
+
} & (Tail extends readonly []
|
55
|
+
? {}
|
56
|
+
: Tail extends readonly AbiParameter[]
|
57
|
+
? AbiEventParametersToPrimitiveTypes<Tail>
|
58
|
+
: {})
|
59
|
+
: never
|
60
|
+
: [
|
61
|
+
AbiEventParameterToPrimitiveType<Head>,
|
62
|
+
...(Tail extends readonly []
|
63
|
+
? []
|
64
|
+
: Tail extends readonly AbiParameter[]
|
65
|
+
? AbiEventParametersToPrimitiveTypes<Tail>
|
66
|
+
: []),
|
67
|
+
]
|
68
|
+
: TBase
|
60
69
|
: TBase
|
61
70
|
: TBase
|
62
|
-
|
71
|
+
>
|
72
|
+
|
73
|
+
export type AbiEventTopicToPrimitiveType<
|
74
|
+
TParam extends AbiParameter,
|
75
|
+
TTopic extends LogTopic,
|
76
|
+
TPrimitiveType = TParam['type'] extends HashedEventTypes
|
77
|
+
? TTopic
|
78
|
+
: AbiParameterToPrimitiveType<TParam>,
|
79
|
+
> = EventTopicParam<TPrimitiveType, TTopic>
|
80
|
+
|
81
|
+
export type AbiEventTopicsToPrimitiveTypes<
|
82
|
+
TAbiParameters extends readonly AbiParameter[],
|
83
|
+
TTopics extends LogTopic[] | undefined = undefined,
|
84
|
+
TData extends Hex | undefined = undefined,
|
85
|
+
TBase = TAbiParameters[0] extends { name: string } ? {} : [],
|
86
|
+
> = Prettify<
|
87
|
+
TAbiParameters extends readonly [infer Head, ...infer Tail]
|
88
|
+
? TTopics extends readonly [infer TopicHead, ...infer TopicTail]
|
89
|
+
? Head extends { indexed: true }
|
90
|
+
? Head extends AbiParameter
|
91
|
+
? Head extends { name: infer Name }
|
92
|
+
? Name extends string
|
93
|
+
? {
|
94
|
+
[name in Name]: TopicHead extends LogTopic
|
95
|
+
? AbiEventTopicToPrimitiveType<Head, TopicHead>
|
96
|
+
: never
|
97
|
+
} & (Tail extends readonly []
|
98
|
+
? {}
|
99
|
+
: Tail extends readonly AbiParameter[]
|
100
|
+
? TopicTail extends LogTopic[]
|
101
|
+
? AbiEventTopicsToPrimitiveTypes<Tail, TopicTail, TData>
|
102
|
+
: {}
|
103
|
+
: {})
|
104
|
+
: never
|
105
|
+
: [
|
106
|
+
TopicHead extends LogTopic
|
107
|
+
? AbiEventTopicToPrimitiveType<Head, TopicHead>
|
108
|
+
: never,
|
109
|
+
...(Tail extends readonly []
|
110
|
+
? []
|
111
|
+
: Tail extends readonly AbiParameter[]
|
112
|
+
? TopicTail extends LogTopic[]
|
113
|
+
? AbiEventTopicsToPrimitiveTypes<Tail, TopicTail, TData>
|
114
|
+
: []
|
115
|
+
: []),
|
116
|
+
]
|
117
|
+
: TBase
|
118
|
+
: TBase
|
119
|
+
: TTopics extends readonly []
|
120
|
+
? TData extends Hex
|
121
|
+
? Head extends AbiParameter
|
122
|
+
? Head extends { indexed: true }
|
123
|
+
? Tail extends readonly AbiParameter[]
|
124
|
+
? AbiEventTopicsToPrimitiveTypes<Tail, [], TData>
|
125
|
+
: TBase
|
126
|
+
: Head extends { name: infer Name }
|
127
|
+
? Name extends string
|
128
|
+
? {
|
129
|
+
[name in Name]: AbiParameterToPrimitiveType<Head>
|
130
|
+
} & (Tail extends readonly []
|
131
|
+
? {}
|
132
|
+
: Tail extends readonly AbiParameter[]
|
133
|
+
? AbiEventTopicsToPrimitiveTypes<Tail, [], TData>
|
134
|
+
: {})
|
135
|
+
: never
|
136
|
+
: [
|
137
|
+
AbiParameterToPrimitiveType<Head>,
|
138
|
+
...(Tail extends readonly []
|
139
|
+
? []
|
140
|
+
: Tail extends readonly AbiParameter[]
|
141
|
+
? AbiEventTopicsToPrimitiveTypes<Tail, [], TData>
|
142
|
+
: []),
|
143
|
+
]
|
144
|
+
: TBase
|
145
|
+
: TBase
|
146
|
+
: TBase
|
147
|
+
: undefined
|
148
|
+
>
|
63
149
|
|
64
150
|
export type ExtractArgsFromAbi<
|
65
151
|
TAbi extends Abi | readonly unknown[],
|
@@ -165,6 +251,23 @@ export type ExtractEventArgsFromAbi<
|
|
165
251
|
args?: TArgs
|
166
252
|
}
|
167
253
|
|
254
|
+
export type ExtractEventArgsFromTopics<
|
255
|
+
TAbi extends Abi | readonly unknown[],
|
256
|
+
TEventName extends string,
|
257
|
+
TTopics extends LogTopic[],
|
258
|
+
TData extends Hex | undefined,
|
259
|
+
TAbiEvent extends AbiEvent & { type: 'event' } = TAbi extends Abi
|
260
|
+
? ExtractAbiEvent<TAbi, TEventName>
|
261
|
+
: AbiEvent & { type: 'event' },
|
262
|
+
TArgs = AbiEventTopicsToPrimitiveTypes<TAbiEvent['inputs'], TTopics, TData>,
|
263
|
+
> = TTopics extends readonly []
|
264
|
+
? TData extends undefined
|
265
|
+
? { args?: never }
|
266
|
+
: { args?: TArgs }
|
267
|
+
: {
|
268
|
+
args?: TArgs
|
269
|
+
}
|
270
|
+
|
168
271
|
export type ExtractErrorNameFromAbi<
|
169
272
|
TAbi extends Abi | readonly unknown[] = Abi,
|
170
273
|
TErrorName extends string = string,
|
@@ -348,15 +451,16 @@ type ExtractArgsFromDefinition<
|
|
348
451
|
: 'Error: Invalid definition was provided.'
|
349
452
|
|
350
453
|
export type ExtractArgsFromEventDefinition<
|
351
|
-
TDef,
|
352
|
-
TConfig extends ExtractArgsFromDefinitionConfig = {
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
454
|
+
TDef extends EventDefinition | undefined,
|
455
|
+
TConfig extends ExtractArgsFromDefinitionConfig = {
|
456
|
+
indexedOnly: true
|
457
|
+
},
|
458
|
+
> = Prettify<
|
459
|
+
TDef extends EventDefinition
|
460
|
+
? ExtractArgsFromDefinition<TDef, TConfig> extends [...args: any]
|
461
|
+
? ExtractArgsFromDefinition<TDef, TConfig> | []
|
462
|
+
: ExtractArgsFromDefinition<TDef, TConfig>
|
463
|
+
: undefined
|
360
464
|
>
|
361
465
|
|
362
466
|
//////////////////////////////////////////////////////////////////////
|
package/src/types/index.ts
CHANGED
@@ -15,11 +15,11 @@ export type {
|
|
15
15
|
EventDefinition,
|
16
16
|
ExtractArgsFromAbi,
|
17
17
|
ExtractArgsFromEventDefinition,
|
18
|
-
ExtractArgsFromFunctionDefinition,
|
19
18
|
ExtractConstructorArgsFromAbi,
|
20
19
|
ExtractErrorArgsFromAbi,
|
21
20
|
ExtractErrorNameFromAbi,
|
22
21
|
ExtractEventArgsFromAbi,
|
22
|
+
ExtractEventArgsFromTopics,
|
23
23
|
ExtractEventNameFromAbi,
|
24
24
|
ExtractFunctionNameFromAbi,
|
25
25
|
ExtractNameFromAbi,
|
@@ -78,6 +78,7 @@ export type {
|
|
78
78
|
|
79
79
|
export type {
|
80
80
|
PartialBy,
|
81
|
+
Prettify,
|
81
82
|
MergeIntersectionProperties,
|
82
83
|
OptionalNullable,
|
83
84
|
} from './utils'
|
package/src/types/utils.ts
CHANGED
@@ -29,6 +29,15 @@ export type OptionalNullable<T> = {
|
|
29
29
|
[K in keyof T as T[K] extends NonNullable<unknown> ? never : K]?: T[K]
|
30
30
|
}
|
31
31
|
|
32
|
+
/**
|
33
|
+
* @description Constructs a type by excluding `undefined` from `T`.
|
34
|
+
*
|
35
|
+
* @example
|
36
|
+
* NoUndefined<string | undefined>
|
37
|
+
* => string
|
38
|
+
*/
|
39
|
+
export type NoUndefined<T> = T extends undefined ? never : T
|
40
|
+
|
32
41
|
/**
|
33
42
|
* @description Creates a type that is a partial of T, but with the required keys K.
|
34
43
|
*
|
@@ -38,6 +47,18 @@ export type OptionalNullable<T> = {
|
|
38
47
|
*/
|
39
48
|
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
|
40
49
|
|
50
|
+
/**
|
51
|
+
* @description Combines members of an intersection into a readable type.
|
52
|
+
*
|
53
|
+
* @link https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg
|
54
|
+
* @example
|
55
|
+
* Prettify<{ a: string } | { b: string } | { c: number, d: bigint }>
|
56
|
+
* => { a: string, b: string, c: number, d: bigint }
|
57
|
+
*/
|
58
|
+
export type Prettify<T> = {
|
59
|
+
[K in keyof T]: T[K]
|
60
|
+
} & {}
|
61
|
+
|
41
62
|
type TrimLeft<T, Chars extends string = ' '> = T extends `${Chars}${infer R}`
|
42
63
|
? TrimLeft<R>
|
43
64
|
: T
|
@@ -222,7 +222,7 @@ test("errors: error doesn't exist", () => {
|
|
222
222
|
).toThrowErrorMatchingInlineSnapshot(`
|
223
223
|
"Encoded error signature \\"0xa3741467\\" not found on ABI.
|
224
224
|
Make sure you are using the correct ABI and that the error exists on it.
|
225
|
-
You can look up the signature
|
225
|
+
You can look up the signature here: https://openchain.xyz/signatures?query=0xa3741467.
|
226
226
|
|
227
227
|
Docs: https://viem.sh/docs/contract/decodeErrorResult
|
228
228
|
Version: viem@1.0.2"
|