viem 0.0.1-alpha.19 → 0.0.1-alpha.20

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.
Files changed (151) hide show
  1. package/dist/{rpc-858670f1.d.ts → chain-32f56cfa.d.ts} +68 -18
  2. package/dist/chain-f12cdc7f.d.ts +5 -0
  3. package/dist/chains.d.ts +757 -170
  4. package/dist/chains.js +80 -86
  5. package/dist/chains.js.map +1 -1
  6. package/dist/chains.mjs +120 -126
  7. package/dist/chains.mjs.map +1 -1
  8. package/dist/{chunk-PHSAQQGZ.mjs → chunk-5Q6FSUU2.mjs} +75 -37
  9. package/dist/chunk-5Q6FSUU2.mjs.map +1 -0
  10. package/dist/{chunk-24EKKMUO.js → chunk-FHXXG7I6.js} +12 -12
  11. package/dist/chunk-FHXXG7I6.js.map +1 -0
  12. package/dist/{chunk-HRE6LYF3.js → chunk-IAQPMSGJ.js} +13 -13
  13. package/dist/chunk-IAQPMSGJ.js.map +1 -0
  14. package/dist/{chunk-IVWG22RQ.mjs → chunk-MYQNZSWD.mjs} +69 -12
  15. package/dist/chunk-MYQNZSWD.mjs.map +1 -0
  16. package/dist/{chunk-NYMS65YI.js → chunk-NHAKUPTF.js} +124 -67
  17. package/dist/chunk-NHAKUPTF.js.map +1 -0
  18. package/dist/{chunk-BZFF747V.js → chunk-SF4I2NKC.js} +81 -43
  19. package/dist/chunk-SF4I2NKC.js.map +1 -0
  20. package/dist/{chunk-VAT5CEF7.mjs → chunk-T7CBAKLI.mjs} +2 -2
  21. package/dist/chunk-T7CBAKLI.mjs.map +1 -0
  22. package/dist/{chunk-CTU4PQLY.js → chunk-YFKR74XG.js} +14 -14
  23. package/dist/{chunk-CTU4PQLY.js.map → chunk-YFKR74XG.js.map} +0 -0
  24. package/dist/{chunk-NSRORL3O.mjs → chunk-YODUQCHJ.mjs} +2 -2
  25. package/dist/{chunk-NSRORL3O.mjs.map → chunk-YODUQCHJ.mjs.map} +0 -0
  26. package/dist/{chunk-E7LH5H76.mjs → chunk-ZVGTYLKU.mjs} +2 -2
  27. package/dist/chunk-ZVGTYLKU.mjs.map +1 -0
  28. package/dist/clients/index.d.ts +7 -8
  29. package/dist/clients/index.js +3 -3
  30. package/dist/clients/index.mjs +2 -2
  31. package/dist/{transactionReceipt-aed524b4.d.ts → contract-9af4608b.d.ts} +30 -18
  32. package/dist/{createClient-03ba79e8.d.ts → createClient-5d316c7e.d.ts} +2 -2
  33. package/dist/{createPublicClient-818241ba.d.ts → createPublicClient-9d2b42e1.d.ts} +3 -3
  34. package/dist/{createTestClient-24eb7be8.d.ts → createTestClient-79498dab.d.ts} +3 -3
  35. package/dist/{createWalletClient-7cbd6ad1.d.ts → createWalletClient-f69a5230.d.ts} +3 -3
  36. package/dist/{eip1193-71d8e27d.d.ts → eip1193-6c485d63.d.ts} +1 -1
  37. package/dist/index.d.ts +45 -23
  38. package/dist/index.js +10 -6
  39. package/dist/index.mjs +9 -5
  40. package/dist/{parseGwei-dbd12305.d.ts → parseGwei-4308ad80.d.ts} +17 -4
  41. package/dist/public.d.ts +9 -10
  42. package/dist/public.js +4 -4
  43. package/dist/public.mjs +3 -3
  44. package/dist/{sendTransaction-d09961a7.d.ts → sendTransaction-1c8290a9.d.ts} +3 -4
  45. package/dist/{stopImpersonatingAccount-c8a00be7.d.ts → stopImpersonatingAccount-7781842a.d.ts} +2 -2
  46. package/dist/test.d.ts +5 -6
  47. package/dist/test.js +3 -3
  48. package/dist/test.mjs +2 -2
  49. package/dist/transactionRequest-341b6ed2.d.ts +15 -0
  50. package/dist/utils/index.d.ts +9 -8
  51. package/dist/utils/index.js +22 -2
  52. package/dist/utils/index.mjs +25 -5
  53. package/dist/wallet.d.ts +7 -8
  54. package/dist/wallet.js +3 -3
  55. package/dist/wallet.mjs +2 -2
  56. package/dist/{watchAsset-c39645b7.d.ts → watchAsset-afaad3c7.d.ts} +3 -4
  57. package/dist/{watchPendingTransactions-01e6be4f.d.ts → watchPendingTransactions-3b722547.d.ts} +21 -16
  58. package/dist/{webSocket-3a00015b.d.ts → webSocket-b180e679.d.ts} +2 -2
  59. package/dist/window.d.ts +3 -2
  60. package/package.json +3 -3
  61. package/src/_test/abis.ts +188 -0
  62. package/src/_test/constants.ts +0 -3
  63. package/src/_test/index.ts +5 -2
  64. package/src/actions/index.test.ts +2 -0
  65. package/src/actions/index.ts +6 -0
  66. package/src/actions/public/call.ts +2 -1
  67. package/src/actions/public/createContractEventFilter.test.ts +119 -0
  68. package/src/actions/public/createContractEventFilter.ts +69 -0
  69. package/src/actions/public/createEventFilter.ts +5 -8
  70. package/src/actions/public/deployContract.ts +1 -2
  71. package/src/actions/public/getBlock.test.ts +3 -3
  72. package/src/actions/public/getBlock.ts +1 -2
  73. package/src/actions/public/getBlockTransactionCount.ts +1 -2
  74. package/src/actions/public/getFilterChanges.test.ts +9 -7
  75. package/src/actions/public/getFilterLogs.test.ts +7 -5
  76. package/src/actions/public/getLogs.test.ts +7 -5
  77. package/src/actions/public/getLogs.ts +3 -2
  78. package/src/actions/public/getTransaction.ts +1 -2
  79. package/src/actions/public/getTransactionConfirmations.ts +1 -2
  80. package/src/actions/public/getTransactionReceipt.test.ts +24 -62
  81. package/src/actions/public/getTransactionReceipt.ts +1 -2
  82. package/src/actions/public/index.test.ts +4 -0
  83. package/src/actions/public/index.ts +18 -0
  84. package/src/actions/public/readContract.ts +1 -1
  85. package/src/actions/public/simulateContract.ts +1 -1
  86. package/src/actions/public/waitForTransactionReceipt.ts +1 -2
  87. package/src/actions/public/watchBlocks.test.ts +27 -2
  88. package/src/actions/public/watchBlocks.ts +33 -14
  89. package/src/actions/public/watchContractEvent.test.ts +301 -0
  90. package/src/actions/public/watchContractEvent.ts +108 -0
  91. package/src/actions/public/watchEvent.test.ts +190 -0
  92. package/src/actions/public/watchEvent.ts +95 -0
  93. package/src/actions/public/watchPendingTransactions.ts +1 -0
  94. package/src/actions/wallet/addChain.ts +1 -1
  95. package/src/actions/wallet/sendTransaction.ts +2 -1
  96. package/src/actions/wallet/switchChain.ts +1 -1
  97. package/src/actions/wallet/writeContract.ts +1 -1
  98. package/src/chains.test.ts +830 -52
  99. package/src/chains.ts +90 -158
  100. package/src/clients/createClient.ts +1 -1
  101. package/src/clients/createPublicClient.ts +1 -1
  102. package/src/clients/createTestClient.ts +1 -1
  103. package/src/clients/createWalletClient.ts +1 -1
  104. package/src/clients/transports/createTransport.ts +1 -1
  105. package/src/index.test.ts +2 -0
  106. package/src/index.ts +10 -2
  107. package/src/types/chain.ts +6 -0
  108. package/src/types/contract.ts +17 -2
  109. package/src/types/formatter.ts +23 -0
  110. package/src/types/index.ts +6 -0
  111. package/src/types/transaction.ts +1 -1
  112. package/src/utils/abi/decodeErrorResult.ts +2 -2
  113. package/src/utils/abi/decodeFunctionData.ts +2 -2
  114. package/src/utils/abi/encodeErrorResult.ts +2 -2
  115. package/src/utils/abi/encodeEventTopics.ts +4 -4
  116. package/src/utils/abi/encodeFunctionData.ts +2 -2
  117. package/src/utils/abi/{formatAbiItemWithParams.test.ts → formatAbiItem.test.ts} +11 -11
  118. package/src/utils/abi/{formatAbiItemWithParams.ts → formatAbiItem.ts} +1 -1
  119. package/src/utils/abi/index.test.ts +1 -1
  120. package/src/utils/abi/index.ts +1 -1
  121. package/src/utils/chain.test.ts +43 -0
  122. package/src/utils/chain.ts +8 -0
  123. package/src/utils/contract/getContractError.ts +2 -6
  124. package/src/utils/formatters/block.ts +4 -3
  125. package/src/utils/formatters/extract.ts +1 -1
  126. package/src/utils/formatters/format.ts +39 -2
  127. package/src/utils/formatters/index.test.ts +10 -0
  128. package/src/utils/formatters/index.ts +15 -5
  129. package/src/utils/formatters/transaction.ts +16 -4
  130. package/src/utils/formatters/transactionReceipt.ts +13 -4
  131. package/src/utils/formatters/transactionRequest.ts +12 -3
  132. package/src/utils/hash/getEventSignature.ts +2 -2
  133. package/src/utils/index.test.ts +24 -1
  134. package/src/utils/index.ts +12 -1
  135. package/src/{constants.test.ts → utils/unit/constants.test.ts} +0 -5
  136. package/src/{constants.ts → utils/unit/constants.ts} +0 -6
  137. package/src/utils/unit/formatEther.ts +1 -1
  138. package/src/utils/unit/formatGwei.ts +1 -1
  139. package/src/utils/unit/index.test.ts +12 -0
  140. package/src/utils/unit/index.ts +1 -0
  141. package/src/utils/unit/parseEther.ts +1 -1
  142. package/src/utils/unit/parseGwei.ts +1 -1
  143. package/dist/chunk-24EKKMUO.js.map +0 -1
  144. package/dist/chunk-BZFF747V.js.map +0 -1
  145. package/dist/chunk-E7LH5H76.mjs.map +0 -1
  146. package/dist/chunk-HRE6LYF3.js.map +0 -1
  147. package/dist/chunk-IVWG22RQ.mjs.map +0 -1
  148. package/dist/chunk-NYMS65YI.js.map +0 -1
  149. package/dist/chunk-PHSAQQGZ.mjs.map +0 -1
  150. package/dist/chunk-VAT5CEF7.mjs.map +0 -1
  151. package/dist/transactionRequest-8e970b0e.d.ts +0 -33
package/src/chains.ts CHANGED
@@ -1,167 +1,99 @@
1
- // TODO: Remove chain formatter implementation once @wagmi/chains supports it.
1
+ import * as chains from '@wagmi/chains'
2
2
 
3
- import type { Chain as Chain_ } from '@wagmi/chains'
3
+ import type { Address, Hex, Quantity } from './types'
4
4
  import {
5
- arbitrumGoerli as arbitrumGoerli_,
6
- arbitrum as arbitrum_,
7
- avalancheFuji as avalancheFuji_,
8
- avalanche as avalanche_,
9
- bscTestnet as bscTestnet_,
10
- bsc as bsc_,
11
- fantomTestnet as fantomTestnet_,
12
- fantom as fantom_,
13
- foundry as foundry_,
14
- goerli as goerli_,
15
- hardhat as hardhat_,
16
- localhost as localhost_,
17
- mainnet as mainnet_,
18
- optimismGoerli as optimismGoerli_,
19
- optimism as optimism_,
20
- polygonMumbai as polygonMumbai_,
21
- polygon as polygon_,
22
- sepolia as sepolia_,
23
- } from '@wagmi/chains'
24
-
25
- import type {
26
- Address,
27
- Block,
28
- Hex,
29
- Quantity,
30
- RpcBlock,
31
- RpcTransaction,
32
- RpcTransactionReceipt,
33
- RpcTransactionRequest,
34
- Transaction,
35
- TransactionReceipt,
36
- TransactionRequest,
37
- } from './types'
38
- import {
39
- formatBlock,
40
- formatTransaction,
41
- formatTransactionRequest,
5
+ defineBlock,
6
+ defineChain,
7
+ defineTransaction,
8
+ defineTransactionReceipt,
9
+ defineTransactionRequest,
42
10
  } from './utils'
43
- import { formatTransactionReceipt } from './utils/formatters/transactionReceipt'
44
-
45
- export type Formatter<TSource = any, TTarget = any> = (
46
- value: TSource & { [key: string]: unknown },
47
- ) => TTarget
48
-
49
- export type Formatters = {
50
- block?: Formatter<RpcBlock, Block>
51
- transaction?: Formatter<RpcTransaction, Transaction>
52
- transactionReceipt?: Formatter<RpcTransactionReceipt, TransactionReceipt>
53
- transactionRequest?: Formatter<TransactionRequest, RpcTransactionRequest>
54
- }
55
11
 
56
- export type Chain<TFormatters extends Formatters = Formatters> = Chain_ & {
57
- formatters?: TFormatters
58
- }
59
-
60
- export function defineChain<
61
- TFormatters extends Formatters = Formatters,
62
- TChain extends Chain<TFormatters> = Chain<TFormatters>,
63
- >(chain: TChain) {
64
- return chain
65
- }
66
-
67
- function defineFormatter<TSource extends Record<string, unknown>, TFormatted>({
68
- format,
69
- }: {
70
- format: (data: TSource) => TFormatted
71
- }) {
72
- return <
73
- TFormat extends Formatter<
74
- TSource,
75
- Partial<TFormatted> & { [key: string]: unknown }
76
- >,
77
- TExclude extends (keyof TSource)[] = [],
78
- >({
79
- exclude,
80
- format: formatOverride,
81
- }: {
82
- exclude?: TExclude
83
- format?: TFormat
84
- }) =>
85
- (data: TSource & { [key: string]: unknown }) => {
86
- const formatted = format(data)
87
- if (exclude) {
88
- for (const key of exclude) {
89
- delete (formatted as any)[key]
90
- }
91
- }
92
- return {
93
- ...formatted,
94
- ...formatOverride?.(data),
95
- } as TFormatted &
96
- ReturnType<TFormat> & {
97
- [K in TExclude[number]]: never
98
- }
99
- }
100
- }
12
+ export type { Chain } from './types'
13
+ export { defineChain } from './utils'
101
14
 
102
- export const defineBlock = defineFormatter({ format: formatBlock })
103
- export const defineTransaction = defineFormatter({ format: formatTransaction })
104
- export const defineTransactionRequest = defineFormatter({
105
- format: formatTransactionRequest,
106
- })
107
- export const defineTransactionReceipt = defineFormatter({
108
- format: formatTransactionReceipt,
109
- })
110
-
111
- export const arbitrumGoerli = defineChain(arbitrumGoerli_)
112
- export const arbitrum = defineChain(arbitrum_)
113
- export const avalancheFuji = defineChain(avalancheFuji_)
114
- export const avalanche = defineChain(avalanche_)
115
- export const bscTestnet = defineChain(bscTestnet_)
116
- export const bsc = defineChain(bsc_)
117
- export const celo = defineChain({
118
- id: 42220,
119
- name: 'Celo',
120
- network: 'celo',
121
- nativeCurrency: { name: 'Celo', symbol: 'CELO', decimals: 18 },
122
- rpcUrls: {
123
- public: { http: ['https://rpc.ankr.com/celo'] },
124
- default: { http: ['https://rpc.ankr.com/celo'] },
125
- },
126
- formatters: {
127
- block: defineBlock({
128
- exclude: ['difficulty', 'gasLimit', 'mixHash', 'nonce', 'uncles'],
129
- format: (block) => ({
130
- randomness: block.randomness as {
131
- committed: Hex
132
- revealed: Hex
133
- },
134
- }),
15
+ const celoFormatters = {
16
+ block: defineBlock({
17
+ exclude: ['difficulty', 'gasLimit', 'mixHash', 'nonce', 'uncles'],
18
+ format: (block) => ({
19
+ randomness: block.randomness as {
20
+ committed: Hex
21
+ revealed: Hex
22
+ },
23
+ }),
24
+ }),
25
+ transaction: defineTransaction({
26
+ format: (transaction) => ({
27
+ feeCurrency: transaction.feeCurrency as Address | null,
28
+ gatewayFee: transaction.gatewayFee
29
+ ? BigInt(transaction.gatewayFee as Quantity)
30
+ : null,
31
+ gatewayFeeRecipient: transaction.gatewayFeeRecipient as Address | null,
135
32
  }),
136
- transaction: defineTransaction({
137
- format: (transaction) => ({
138
- feeCurrency: transaction.feeCurrency as Address | null,
139
- gatewayFee: transaction.gatewayFee
140
- ? BigInt(transaction.gatewayFee as Quantity)
141
- : null,
142
- gatewayFeeRecipient: transaction.gatewayFeeRecipient as Address | null,
143
- }),
33
+ }),
34
+ transactionReceipt: defineTransactionReceipt({
35
+ format: (transaction) => ({
36
+ feeCurrency: transaction.feeCurrency as Address | null,
37
+ gatewayFee: transaction.gatewayFee
38
+ ? BigInt(transaction.gatewayFee as Quantity)
39
+ : null,
40
+ gatewayFeeRecipient: transaction.gatewayFeeRecipient as Address | null,
144
41
  }),
145
- transactionRequest: defineTransactionRequest({
146
- format: (transactionRequest) => ({
147
- feeCurrency: transactionRequest.feeCurrency as Address | undefined,
148
- gatewayFee: transactionRequest.gatewayFee as Quantity | undefined,
149
- gatewayFeeRecipient: transactionRequest.gatewayFeeRecipient as
150
- | Address
151
- | undefined,
152
- }),
42
+ }),
43
+ transactionRequest: defineTransactionRequest({
44
+ format: (transactionRequest) => ({
45
+ feeCurrency: transactionRequest.feeCurrency as Address | undefined,
46
+ gatewayFee: transactionRequest.gatewayFee as Quantity | undefined,
47
+ gatewayFeeRecipient: transactionRequest.gatewayFeeRecipient as
48
+ | Address
49
+ | undefined,
153
50
  }),
154
- },
51
+ }),
52
+ }
53
+
54
+ export const arbitrum = defineChain(chains.arbitrum)
55
+ export const arbitrumGoerli = defineChain(chains.arbitrumGoerli)
56
+ export const aurora = defineChain(chains.aurora)
57
+ export const auroraGoerli = defineChain(chains.auroraTestnet)
58
+ export const avalanche = defineChain(chains.avalanche)
59
+ export const avalancheFuji = defineChain(chains.avalancheFuji)
60
+ export const bronos = defineChain(chains.bronos)
61
+ export const bronosTestnet = defineChain(chains.bronosTestnet)
62
+ export const bsc = defineChain(chains.bsc)
63
+ export const bscTestnet = defineChain(chains.bscTestnet)
64
+ export const canto = defineChain(chains.canto)
65
+ export const celo = defineChain({
66
+ ...chains.celo,
67
+ formatters: celoFormatters,
68
+ })
69
+ export const celoAlfajores = defineChain({
70
+ ...chains.celoAlfajores,
71
+ formatters: celoFormatters,
155
72
  })
156
- export const fantomTestnet = defineChain(fantomTestnet_)
157
- export const fantom = defineChain(fantom_)
158
- export const foundry = defineChain(foundry_)
159
- export const goerli = defineChain(goerli_)
160
- export const hardhat = defineChain(hardhat_)
161
- export const localhost = defineChain(localhost_)
162
- export const mainnet = defineChain(mainnet_)
163
- export const optimismGoerli = defineChain(optimismGoerli_)
164
- export const optimism = defineChain(optimism_)
165
- export const polygonMumbai = defineChain(polygonMumbai_)
166
- export const polygon = defineChain(polygon_)
167
- export const sepolia = defineChain(sepolia_)
73
+ export const crossbell = defineChain(chains.crossbell)
74
+ export const evmos = defineChain(chains.evmos)
75
+ export const evmosTestnet = defineChain(chains.evmosTestnet)
76
+ export const fantom = defineChain(chains.fantom)
77
+ export const fantomTestnet = defineChain(chains.fantomTestnet)
78
+ export const filecoin = defineChain(chains.filecoin)
79
+ export const filecoinTestnet = defineChain(chains.filecoinHyperspace)
80
+ export const foundry = defineChain(chains.foundry)
81
+ export const goerli = defineChain(chains.goerli)
82
+ export const gnosis = defineChain(chains.gnosis)
83
+ export const gnosisChiado = defineChain(chains.gnosisChiado)
84
+ export const hardhat = defineChain(chains.hardhat)
85
+ export const iotex = defineChain(chains.iotex)
86
+ export const iotexTestnet = defineChain(chains.iotexTestnet)
87
+ export const localhost = defineChain(chains.localhost)
88
+ export const mainnet = defineChain(chains.mainnet)
89
+ export const metis = defineChain(chains.metis)
90
+ export const metisGoerli = defineChain(chains.metisGoerli)
91
+ export const optimism = defineChain(chains.optimism)
92
+ export const optimismGoerli = defineChain(chains.optimismGoerli)
93
+ export const polygon = defineChain(chains.polygon)
94
+ export const polygonMumbai = defineChain(chains.polygonMumbai)
95
+ export const sepolia = defineChain(chains.sepolia)
96
+ export const taraxa = defineChain(chains.taraxa)
97
+ export const taraxaTestnet = defineChain(chains.taraxaTestnet)
98
+ export const zkSync = defineChain(chains.zkSync)
99
+ export const zkSyncTestnet = defineChain(chains.zkSyncTestnet)
@@ -1,4 +1,4 @@
1
- import type { Chain } from '../chains'
1
+ import { Chain } from '../types'
2
2
  import type { Requests } from '../types/eip1193'
3
3
  import { buildRequest } from '../utils/buildRequest'
4
4
  import { uid } from '../utils/uid'
@@ -1,8 +1,8 @@
1
- import type { Chain } from '../chains'
2
1
  import type { PublicRequests } from '../types/eip1193'
3
2
  import type { Transport } from './transports/createTransport'
4
3
  import type { Client, ClientConfig } from './createClient'
5
4
  import { createClient } from './createClient'
5
+ import { Chain } from '../types'
6
6
 
7
7
  export type PublicClientConfig<
8
8
  TTransport extends Transport = Transport,
@@ -2,7 +2,7 @@ import type { TestRequests } from '../types/eip1193'
2
2
  import type { Transport } from './transports/createTransport'
3
3
  import type { Client, ClientConfig } from './createClient'
4
4
  import { createClient } from './createClient'
5
- import type { Chain } from '../chains'
5
+ import { Chain } from '../types'
6
6
 
7
7
  type TestClientModes = 'anvil' | 'hardhat'
8
8
 
@@ -2,7 +2,7 @@ import type { SignableRequests, WalletRequests } from '../types/eip1193'
2
2
  import type { Transport } from './transports/createTransport'
3
3
  import type { Client, ClientConfig } from './createClient'
4
4
  import { createClient } from './createClient'
5
- import type { Chain } from '../chains'
5
+ import { Chain } from '../types'
6
6
 
7
7
  export type WalletClientConfig<
8
8
  TTransport extends Transport = Transport,
@@ -1,4 +1,4 @@
1
- import type { Chain } from '../../chains'
1
+ import type { Chain } from '../../types'
2
2
  import type { Requests } from '../../types/eip1193'
3
3
 
4
4
  export type BaseRpcRequests = {
package/src/index.test.ts CHANGED
@@ -67,6 +67,8 @@ test('exports actions', () => {
67
67
  "call": [Function],
68
68
  "createBlockFilter": [Function],
69
69
  "createClient": [Function],
70
+ "createContractEventFilter": [Function],
71
+ "createEventFilter": [Function],
70
72
  "createPendingTransactionFilter": [Function],
71
73
  "createPublicClient": [Function],
72
74
  "createTestClient": [Function],
package/src/index.ts CHANGED
@@ -2,6 +2,10 @@ export type {
2
2
  CallArgs,
3
3
  CallResponse,
4
4
  CreateBlockFilterResponse,
5
+ CreateContractEventFilterArgs,
6
+ CreateContractEventFilterResponse,
7
+ CreateEventFilterArgs,
8
+ CreateEventFilterResponse,
5
9
  CreatePendingTransactionFilterResponse,
6
10
  EstimateGasArgs,
7
11
  EstimateGasResponse,
@@ -89,6 +93,8 @@ export {
89
93
  addChain,
90
94
  call,
91
95
  createBlockFilter,
96
+ createContractEventFilter,
97
+ createEventFilter,
92
98
  createPendingTransactionFilter,
93
99
  deployContract,
94
100
  dropTransaction,
@@ -185,8 +191,6 @@ export {
185
191
  webSocket,
186
192
  } from './clients'
187
193
 
188
- export { etherUnits, gweiUnits, transactionType, weiUnits } from './constants'
189
-
190
194
  export {
191
195
  AbiConstructorNotFoundError,
192
196
  AbiConstructorParamsNotFoundError,
@@ -325,12 +329,14 @@ export {
325
329
  encodeFunctionResult,
326
330
  encodeHex,
327
331
  encodeRlp,
332
+ etherUnits,
328
333
  getAddress,
329
334
  getContractAddress,
330
335
  getCreateAddress,
331
336
  getCreate2Address,
332
337
  getEventSignature,
333
338
  getFunctionSignature,
339
+ gweiUnits,
334
340
  formatEther,
335
341
  isAddress,
336
342
  isAddressEqual,
@@ -361,5 +367,7 @@ export {
361
367
  sliceHex,
362
368
  stringToBytes,
363
369
  stringToHex,
370
+ transactionType,
364
371
  trim,
372
+ weiUnits,
365
373
  } from './utils'
@@ -0,0 +1,6 @@
1
+ import { Chain as Chain_ } from '@wagmi/chains'
2
+ import { Formatters } from './formatter'
3
+
4
+ export type Chain<TFormatters extends Formatters = Formatters> = Chain_ & {
5
+ formatters?: TFormatters
6
+ }
@@ -10,6 +10,7 @@ import type {
10
10
  AbiParametersToPrimitiveTypes,
11
11
  ExtractAbiFunction,
12
12
  ExtractAbiEvent,
13
+ ExtractAbiEventNames,
13
14
  ExtractAbiError,
14
15
  AbiStateMutability,
15
16
  ExtractAbiFunctionNames,
@@ -139,9 +140,9 @@ export type ExtractErrorArgsFromAbi<
139
140
 
140
141
  export type ExtractEventArgsFromAbi<
141
142
  TAbi extends Abi | readonly unknown[],
142
- TFunctionName extends string,
143
+ TEventName extends string,
143
144
  TAbiEvent extends AbiEvent & { type: 'event' } = TAbi extends Abi
144
- ? ExtractAbiEvent<TAbi, TFunctionName>
145
+ ? ExtractAbiEvent<TAbi, TEventName>
145
146
  : AbiEvent & { type: 'event' },
146
147
  TArgs = AbiEventParametersToPrimitiveTypes<TAbiEvent['inputs']>,
147
148
  FailedToParseArgs =
@@ -162,6 +163,18 @@ export type ExtractEventArgsFromAbi<
162
163
  args?: TArgs
163
164
  }
164
165
 
166
+ export type ExtractEventNameFromAbi<
167
+ TAbi extends Abi | readonly unknown[] = Abi,
168
+ TEventName extends string = string,
169
+ > = TAbi extends Abi
170
+ ? ExtractAbiEventNames<TAbi> extends infer AbiEventNames
171
+ ?
172
+ | AbiEventNames
173
+ | (TEventName extends AbiEventNames ? TEventName : never)
174
+ | (Abi extends TAbi ? string : never)
175
+ : never
176
+ : TEventName
177
+
165
178
  export type ExtractFunctionNameFromAbi<
166
179
  TAbi extends Abi | readonly unknown[] = Abi,
167
180
  TFunctionName extends string = string,
@@ -201,6 +214,8 @@ export type ExtractResultFromAbi<
201
214
  //////////////////////////////////////////////////////////////////////
202
215
  // Event/Function Definitions
203
216
 
217
+ export type EventDefinition = `${string}(${string})`
218
+
204
219
  type ExtractArgsFromDefinitionConfig = {
205
220
  indexedOnly: unknown
206
221
  }
@@ -0,0 +1,23 @@
1
+ import { Block } from './block'
2
+ import {
3
+ RpcBlock,
4
+ RpcTransaction,
5
+ RpcTransactionReceipt,
6
+ RpcTransactionRequest,
7
+ } from './rpc'
8
+ import {
9
+ Transaction,
10
+ TransactionReceipt,
11
+ TransactionRequest,
12
+ } from './transaction'
13
+
14
+ export type Formatter<TSource = any, TTarget = any> = (
15
+ value: TSource & { [key: string]: unknown },
16
+ ) => TTarget
17
+
18
+ export type Formatters = {
19
+ block?: Formatter<RpcBlock, Block>
20
+ transaction?: Formatter<RpcTransaction, Transaction>
21
+ transactionReceipt?: Formatter<RpcTransactionReceipt, TransactionReceipt>
22
+ transactionRequest?: Formatter<TransactionRequest, RpcTransactionRequest>
23
+ }
@@ -6,15 +6,19 @@ export type {
6
6
  Uncle,
7
7
  } from './block'
8
8
 
9
+ export type { Chain } from './chain'
10
+
9
11
  export type {
10
12
  AbiItem,
11
13
  AbiEventParametersToPrimitiveTypes,
14
+ EventDefinition,
12
15
  ExtractArgsFromAbi,
13
16
  ExtractArgsFromEventDefinition,
14
17
  ExtractArgsFromFunctionDefinition,
15
18
  ExtractConstructorArgsFromAbi,
16
19
  ExtractErrorArgsFromAbi,
17
20
  ExtractEventArgsFromAbi,
21
+ ExtractEventNameFromAbi,
18
22
  ExtractFunctionNameFromAbi,
19
23
  ExtractResultFromAbi,
20
24
  GetValue,
@@ -30,6 +34,8 @@ export type {
30
34
 
31
35
  export type { Filter, FilterType } from './filter'
32
36
 
37
+ export type { Formatter, Formatters } from './formatter'
38
+
33
39
  export type { Log } from './log'
34
40
 
35
41
  export type { Address, ByteArray, Hex, Hash, LogTopic } from './misc'
@@ -1,4 +1,4 @@
1
- import type { transactionType } from '../constants'
1
+ import { transactionType } from '../utils'
2
2
  import type { FeeValuesEIP1559, FeeValuesLegacy } from './fee'
3
3
  import type { Log } from './log'
4
4
  import type { Address, Hash, Hex } from './misc'
@@ -4,14 +4,14 @@ import { Hex } from '../../types'
4
4
  import { slice } from '../data'
5
5
  import { getFunctionSignature } from '../hash'
6
6
  import { decodeAbi } from './decodeAbi'
7
- import { formatAbiItemWithParams } from './formatAbiItemWithParams'
7
+ import { formatAbiItem } from './formatAbiItem'
8
8
 
9
9
  export type DecodeErrorResultArgs = { abi: Abi; data: Hex }
10
10
 
11
11
  export function decodeErrorResult({ abi, data }: DecodeErrorResultArgs) {
12
12
  const signature = slice(data, 0, 4)
13
13
  const description = abi.find(
14
- (x) => signature === getFunctionSignature(formatAbiItemWithParams(x)),
14
+ (x) => signature === getFunctionSignature(formatAbiItem(x)),
15
15
  )
16
16
  if (!description)
17
17
  throw new AbiErrorSignatureNotFoundError(signature, {
@@ -5,14 +5,14 @@ import { Hex } from '../../types'
5
5
  import { slice } from '../data'
6
6
  import { getFunctionSignature } from '../hash'
7
7
  import { decodeAbi } from './decodeAbi'
8
- import { formatAbiItemWithParams } from './formatAbiItemWithParams'
8
+ import { formatAbiItem } from './formatAbiItem'
9
9
 
10
10
  export type DecodeFunctionDataArgs = { abi: Abi; data: Hex }
11
11
 
12
12
  export function decodeFunctionData({ abi, data }: DecodeFunctionDataArgs) {
13
13
  const signature = slice(data, 0, 4)
14
14
  const description = abi.find(
15
- (x) => signature === getFunctionSignature(formatAbiItemWithParams(x)),
15
+ (x) => signature === getFunctionSignature(formatAbiItem(x)),
16
16
  )
17
17
  if (!description)
18
18
  throw new AbiFunctionSignatureNotFoundError(signature, {
@@ -8,7 +8,7 @@ import { ExtractErrorArgsFromAbi, Hex } from '../../types'
8
8
  import { concatHex } from '../data'
9
9
  import { getFunctionSignature } from '../hash'
10
10
  import { encodeAbi } from './encodeAbi'
11
- import { formatAbiItemWithParams } from './formatAbiItemWithParams'
11
+ import { formatAbiItem } from './formatAbiItem'
12
12
  import { getAbiItem } from './getAbiItem'
13
13
 
14
14
  const docsPath = '/docs/contract/encodeErrorResult'
@@ -27,7 +27,7 @@ export function encodeErrorResult<
27
27
  >({ abi, errorName, args }: EncodeErrorResultArgs<TAbi, TErrorName>) {
28
28
  const description = getAbiItem({ abi, name: errorName })
29
29
  if (!description) throw new AbiErrorNotFoundError(errorName, { docsPath })
30
- const definition = formatAbiItemWithParams(description)
30
+ const definition = formatAbiItem(description)
31
31
  const signature = getFunctionSignature(definition)
32
32
 
33
33
  let data: Hex = '0x'
@@ -9,11 +9,11 @@ import {
9
9
  AbiEventNotFoundError,
10
10
  FilterTypeNotSupportedError,
11
11
  } from '../../errors'
12
- import { ExtractEventArgsFromAbi, Hex } from '../../types'
12
+ import { EventDefinition, ExtractEventArgsFromAbi, Hex } from '../../types'
13
13
  import { encodeBytes } from '../encoding'
14
14
  import { keccak256, getEventSignature } from '../hash'
15
15
  import { encodeAbi } from './encodeAbi'
16
- import { formatAbiItemWithParams } from './formatAbiItemWithParams'
16
+ import { formatAbiItem } from './formatAbiItem'
17
17
  import { getAbiItem } from './getAbiItem'
18
18
 
19
19
  export type EncodeEventTopicsArgs<
@@ -33,8 +33,8 @@ export function encodeEventTopics<
33
33
  throw new AbiEventNotFoundError(eventName, {
34
34
  docsPath: '/docs/contract/encodeEventTopics',
35
35
  })
36
- const definition = formatAbiItemWithParams(abiItem)
37
- const signature = getEventSignature(definition as `${string}(${string})`)
36
+ const definition = formatAbiItem(abiItem)
37
+ const signature = getEventSignature(definition as EventDefinition)
38
38
 
39
39
  let topics: Hex[] = []
40
40
  if (args && 'inputs' in abiItem) {
@@ -5,7 +5,7 @@ import { ExtractArgsFromAbi, ExtractFunctionNameFromAbi } from '../../types'
5
5
  import { concatHex } from '../data'
6
6
  import { getFunctionSignature } from '../hash'
7
7
  import { encodeAbi } from './encodeAbi'
8
- import { formatAbiItemWithParams } from './formatAbiItemWithParams'
8
+ import { formatAbiItem } from './formatAbiItem'
9
9
  import { getAbiItem } from './getAbiItem'
10
10
 
11
11
  export type EncodeFunctionDataArgs<
@@ -25,7 +25,7 @@ export function encodeFunctionData<
25
25
  throw new AbiFunctionNotFoundError(functionName, {
26
26
  docsPath: '/docs/contract/encodeFunctionData',
27
27
  })
28
- const definition = formatAbiItemWithParams(description)
28
+ const definition = formatAbiItem(description)
29
29
  const signature = getFunctionSignature(definition)
30
30
  const data =
31
31
  'inputs' in description && description.inputs