viem 1.2.10 → 1.2.11

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 (70) hide show
  1. package/dist/cjs/chains/formatters/celo.js +2 -2
  2. package/dist/cjs/chains/formatters/celo.js.map +1 -1
  3. package/dist/cjs/chains/formatters/optimism.js +2 -2
  4. package/dist/cjs/chains/formatters/optimism.js.map +1 -1
  5. package/dist/cjs/chains/index.js +8 -8
  6. package/dist/cjs/chains/serializers/celo.js +12 -13
  7. package/dist/cjs/chains/serializers/celo.js.map +1 -1
  8. package/dist/cjs/clients/createClient.js +19 -12
  9. package/dist/cjs/clients/createClient.js.map +1 -1
  10. package/dist/cjs/clients/createPublicClient.js +6 -7
  11. package/dist/cjs/clients/createPublicClient.js.map +1 -1
  12. package/dist/cjs/clients/createTestClient.js +9 -9
  13. package/dist/cjs/clients/createTestClient.js.map +1 -1
  14. package/dist/cjs/clients/createWalletClient.js +6 -6
  15. package/dist/cjs/clients/createWalletClient.js.map +1 -1
  16. package/dist/cjs/clients/decorators/public.js +44 -42
  17. package/dist/cjs/clients/decorators/public.js.map +1 -1
  18. package/dist/cjs/clients/decorators/wallet.js +17 -15
  19. package/dist/cjs/clients/decorators/wallet.js.map +1 -1
  20. package/dist/esm/chains/formatters/celo.js +1 -1
  21. package/dist/esm/chains/formatters/celo.js.map +1 -1
  22. package/dist/esm/chains/formatters/optimism.js +1 -1
  23. package/dist/esm/chains/formatters/optimism.js.map +1 -1
  24. package/dist/esm/chains/index.js +11 -11
  25. package/dist/esm/chains/serializers/celo.js +13 -14
  26. package/dist/esm/chains/serializers/celo.js.map +1 -1
  27. package/dist/esm/clients/createClient.js +19 -15
  28. package/dist/esm/clients/createClient.js.map +1 -1
  29. package/dist/esm/clients/createPublicClient.js +6 -26
  30. package/dist/esm/clients/createPublicClient.js.map +1 -1
  31. package/dist/esm/clients/createTestClient.js +9 -32
  32. package/dist/esm/clients/createTestClient.js.map +1 -1
  33. package/dist/esm/clients/createWalletClient.js +6 -42
  34. package/dist/esm/clients/createWalletClient.js.map +1 -1
  35. package/dist/esm/clients/decorators/public.js +44 -42
  36. package/dist/esm/clients/decorators/public.js.map +1 -1
  37. package/dist/esm/clients/decorators/wallet.js +17 -15
  38. package/dist/esm/clients/decorators/wallet.js.map +1 -1
  39. package/dist/types/chains/formatters/celo.d.ts +2 -2
  40. package/dist/types/chains/formatters/celo.d.ts.map +1 -1
  41. package/dist/types/chains/formatters/optimism.d.ts +9 -9
  42. package/dist/types/chains/formatters/optimism.d.ts.map +1 -1
  43. package/dist/types/chains/serializers/celo.d.ts +3 -4
  44. package/dist/types/chains/serializers/celo.d.ts.map +1 -1
  45. package/dist/types/clients/createClient.d.ts +29 -32
  46. package/dist/types/clients/createClient.d.ts.map +1 -1
  47. package/dist/types/clients/createPublicClient.d.ts +3 -3
  48. package/dist/types/clients/createPublicClient.d.ts.map +1 -1
  49. package/dist/types/clients/createTestClient.d.ts +9 -7
  50. package/dist/types/clients/createTestClient.d.ts.map +1 -1
  51. package/dist/types/clients/createWalletClient.d.ts +3 -3
  52. package/dist/types/clients/createWalletClient.d.ts.map +1 -1
  53. package/dist/types/clients/decorators/public.d.ts +1 -519
  54. package/dist/types/clients/decorators/public.d.ts.map +1 -1
  55. package/dist/types/clients/decorators/wallet.d.ts +1 -519
  56. package/dist/types/clients/decorators/wallet.d.ts.map +1 -1
  57. package/dist/types/types/chain.d.ts +3 -4
  58. package/dist/types/types/chain.d.ts.map +1 -1
  59. package/package.json +1 -1
  60. package/src/chains/formatters/celo.ts +8 -7
  61. package/src/chains/formatters/optimism.ts +14 -14
  62. package/src/chains/index.ts +11 -11
  63. package/src/chains/serializers/celo.ts +15 -19
  64. package/src/clients/createClient.ts +113 -89
  65. package/src/clients/createPublicClient.ts +26 -26
  66. package/src/clients/createTestClient.ts +41 -47
  67. package/src/clients/createWalletClient.ts +30 -33
  68. package/src/clients/decorators/public.ts +49 -44
  69. package/src/clients/decorators/wallet.ts +18 -16
  70. package/src/types/chain.ts +6 -7
@@ -23,6 +23,12 @@ type RpcTransaction = RpcTransaction_ & {
23
23
  sourceHash?: undefined
24
24
  }
25
25
 
26
+ type Transaction = Transaction_ & {
27
+ isSystemTx?: undefined
28
+ mint?: undefined
29
+ sourceHash?: undefined
30
+ }
31
+
26
32
  export type RpcDepositTransaction = TransactionBase<Quantity, Index> &
27
33
  FeeValuesEIP1559<Quantity> & {
28
34
  isSystemTx?: boolean
@@ -31,12 +37,6 @@ export type RpcDepositTransaction = TransactionBase<Quantity, Index> &
31
37
  type: '0x7e'
32
38
  }
33
39
 
34
- type Transaction = Transaction_ & {
35
- isSystemTx?: undefined
36
- mint?: undefined
37
- sourceHash?: undefined
38
- }
39
-
40
40
  export type DepositTransaction = TransactionBase &
41
41
  FeeValuesEIP1559 & {
42
42
  isSystemTx?: boolean
@@ -45,22 +45,22 @@ export type DepositTransaction = TransactionBase &
45
45
  type: 'deposit'
46
46
  }
47
47
 
48
- type OptimismOverrides = {
48
+ export type OptimismFormatOverrides = {
49
49
  RpcBlock: {
50
- transactions: Hash[] | OptimismOverrides['RpcTransaction'][]
50
+ transactions: Hash[] | OptimismFormatOverrides['RpcTransaction'][]
51
51
  }
52
52
  RpcTransaction: RpcTransaction | RpcDepositTransaction
53
53
  Transaction: Transaction | DepositTransaction
54
54
  }
55
55
 
56
- export const optimismFormatters = {
56
+ export const formattersOptimism = {
57
57
  block: /*#__PURE__*/ defineBlock({
58
- format(args: OptimismOverrides['RpcBlock']) {
58
+ format(args: OptimismFormatOverrides['RpcBlock']) {
59
59
  const transactions = args.transactions?.map((transaction) => {
60
60
  if (typeof transaction === 'string') return transaction
61
61
  const formatted = formatTransaction(
62
62
  transaction as RpcTransaction,
63
- ) as OptimismOverrides['Transaction']
63
+ ) as OptimismFormatOverrides['Transaction']
64
64
  if (formatted.typeHex === '0x7e') {
65
65
  formatted.isSystemTx = transaction.isSystemTx
66
66
  formatted.mint = transaction.mint
@@ -70,15 +70,15 @@ export const optimismFormatters = {
70
70
  formatted.type = 'deposit'
71
71
  }
72
72
  return formatted
73
- }) as Hash[] | OptimismOverrides['Transaction'][]
73
+ }) as Hash[] | OptimismFormatOverrides['Transaction'][]
74
74
  return {
75
75
  transactions,
76
76
  }
77
77
  },
78
78
  }),
79
79
  transaction: /*#__PURE__*/ defineTransaction({
80
- format(args: OptimismOverrides['RpcTransaction']) {
81
- const transaction = {} as OptimismOverrides['Transaction']
80
+ format(args: OptimismFormatOverrides['RpcTransaction']) {
81
+ const transaction = {} as OptimismFormatOverrides['Transaction']
82
82
  if (args.type === '0x7e') {
83
83
  transaction.isSystemTx = args.isSystemTx
84
84
  transaction.mint = args.mint ? hexToBigInt(args.mint) : undefined
@@ -1,9 +1,9 @@
1
1
  import * as chains from '@wagmi/chains'
2
2
 
3
3
  import { defineChain } from '../utils/chain.js'
4
- import { celoFormatters } from './formatters/celo.js'
5
- import { optimismFormatters } from './formatters/optimism.js'
6
- import { celoSerializers } from './serializers/celo.js'
4
+ import { formattersCelo } from './formatters/celo.js'
5
+ import { formattersOptimism } from './formatters/optimism.js'
6
+ import { serializersCelo } from './serializers/celo.js'
7
7
 
8
8
  export const arbitrum = /*#__PURE__*/ defineChain(chains.arbitrum)
9
9
  export const arbitrumGoerli = /*#__PURE__*/ defineChain(chains.arbitrumGoerli)
@@ -19,16 +19,16 @@ export const bsc = /*#__PURE__*/ defineChain(chains.bsc)
19
19
  export const bscTestnet = /*#__PURE__*/ defineChain(chains.bscTestnet)
20
20
  export const canto = /*#__PURE__*/ defineChain(chains.canto)
21
21
  export const celo = /*#__PURE__*/ defineChain(chains.celo, {
22
- formatters: celoFormatters,
23
- serializers: celoSerializers,
22
+ formatters: formattersCelo,
23
+ serializers: serializersCelo,
24
24
  })
25
25
  export const celoAlfajores = /*#__PURE__*/ defineChain(chains.celoAlfajores, {
26
- formatters: celoFormatters,
27
- serializers: celoSerializers,
26
+ formatters: formattersCelo,
27
+ serializers: serializersCelo,
28
28
  })
29
29
  export const celoCannoli = /*#__PURE__*/ defineChain(chains.celoCannoli, {
30
- formatters: celoFormatters,
31
- serializers: celoSerializers,
30
+ formatters: formattersCelo,
31
+ serializers: serializersCelo,
32
32
  })
33
33
  export const cronos = /*#__PURE__*/ defineChain(chains.cronos)
34
34
  export const crossbell = /*#__PURE__*/ defineChain(chains.crossbell)
@@ -69,10 +69,10 @@ export const moonriver = /*#__PURE__*/ defineChain(chains.moonriver)
69
69
  export const nexi = /*#__PURE__*/ defineChain(chains.nexi)
70
70
  export const okc = /*#__PURE__*/ defineChain(chains.okc)
71
71
  export const optimism = /*#__PURE__*/ defineChain(chains.optimism, {
72
- formatters: optimismFormatters,
72
+ formatters: formattersOptimism,
73
73
  })
74
74
  export const optimismGoerli = /*#__PURE__*/ defineChain(chains.optimismGoerli, {
75
- formatters: optimismFormatters,
75
+ formatters: formattersOptimism,
76
76
  })
77
77
  export const polygon = /*#__PURE__*/ defineChain(chains.polygon)
78
78
  export const polygonMumbai = /*#__PURE__*/ defineChain(chains.polygonMumbai)
@@ -6,6 +6,7 @@ import { InvalidChainIdError } from '../../errors/chain.js'
6
6
  import { FeeCapTooHighError, TipAboveFeeCapError } from '../../errors/node.js'
7
7
  import type { FeeValuesEIP1559 } from '../../types/fee.js'
8
8
  import type { Signature } from '../../types/misc.js'
9
+ import type { Serializers } from '../../types/serializer.js'
9
10
  import type {
10
11
  AccessList,
11
12
  TransactionSerializable,
@@ -19,30 +20,26 @@ import { toRlp } from '../../utils/encoding/toRlp.js'
19
20
  import { serializeAccessList } from '../../utils/transaction/serializeAccessList.js'
20
21
  import {
21
22
  type SerializeTransactionFn,
22
- serializeTransaction as serializeTransaction_,
23
+ serializeTransaction,
23
24
  } from '../../utils/transaction/serializeTransaction.js'
24
25
 
25
- export const serializeTransaction: SerializeTransactionFn<
26
+ export const serializeTransactionCelo: SerializeTransactionFn<
26
27
  TransactionSerializableCelo
27
28
  > = (tx, signature) => {
28
- // Handle Celo's CIP-42 Transactions
29
- if (couldBeCIP42(tx))
29
+ // Handle CIP-42 transactions
30
+ if (isCIP42(tx))
30
31
  return serializeTransactionCIP42(
31
32
  tx as TransactionSerializableCIP42,
32
33
  signature,
33
34
  )
34
35
 
35
36
  // Handle other transaction types
36
- return serializeTransaction_(tx as TransactionSerializable, signature)
37
+ return serializeTransaction(tx as TransactionSerializable, signature)
37
38
  }
38
39
 
39
- export type CeloSerializers = {
40
- transaction: typeof serializeTransaction
41
- }
42
-
43
- export const celoSerializers: CeloSerializers = {
44
- transaction: serializeTransaction,
45
- }
40
+ export const serializersCelo = {
41
+ transaction: serializeTransactionCelo,
42
+ } as const satisfies Serializers
46
43
 
47
44
  //////////////////////////////////////////////////////////////////////////////
48
45
  // Types
@@ -126,14 +123,13 @@ function serializeTransactionCIP42(
126
123
  // Utilities
127
124
 
128
125
  // process as CIP42 if any of these fields are present. realistically gatewayfee is not used but is part of spec
129
- function couldBeCIP42(tx: TransactionSerializableCelo) {
130
- const maybeCIP42 = tx as TransactionSerializableCIP42
126
+ function isCIP42(transaction: TransactionSerializableCelo) {
131
127
  if (
132
- 'maxFeePerGas' in maybeCIP42 &&
133
- 'maxPriorityFeePerGas' in maybeCIP42 &&
134
- ('feeCurrency' in maybeCIP42 ||
135
- 'gatewayFee' in maybeCIP42 ||
136
- 'gatewayFeeRecipient' in maybeCIP42)
128
+ 'maxFeePerGas' in transaction &&
129
+ 'maxPriorityFeePerGas' in transaction &&
130
+ ('feeCurrency' in transaction ||
131
+ 'gatewayFee' in transaction ||
132
+ 'gatewayFeeRecipient' in transaction)
137
133
  )
138
134
  return true
139
135
  return false
@@ -1,7 +1,6 @@
1
- import type { Address, Narrow } from 'abitype'
1
+ import type { Address } from 'abitype'
2
2
 
3
3
  import type { Account, JsonRpcAccount } from '../accounts/types.js'
4
- import type { ParseAccount } from '../types/account.js'
5
4
  import type { Chain } from '../types/chain.js'
6
5
  import type {
7
6
  EIP1193RequestFn,
@@ -13,60 +12,82 @@ import { parseAccount } from '../utils/accounts.js'
13
12
  import { uid } from '../utils/uid.js'
14
13
  import type { Transport } from './transports/createTransport.js'
15
14
 
16
- export type MulticallBatchOptions = {
17
- /** The maximum size (in bytes) for each calldata chunk. @default 1_024 */
18
- batchSize?: number
19
- /** The maximum number of milliseconds to wait before sending a batch. @default 0 */
20
- wait?: number
21
- }
22
-
23
15
  export type ClientConfig<
24
- TTransport extends Transport = Transport,
25
- TChain extends Chain | undefined = Chain | undefined,
26
- TAccountOrAddress extends Account | Address | undefined =
16
+ transport extends Transport = Transport,
17
+ chain extends Chain | undefined = Chain | undefined,
18
+ accountOrAddress extends Account | Address | undefined =
27
19
  | Account
28
20
  | Address
29
21
  | undefined,
30
22
  > = {
31
23
  /** The Account to use for the Client. This will be used for Actions that require an account as an argument. */
32
- account?: TAccountOrAddress
24
+ account?: accountOrAddress extends Account | Address
25
+ ? accountOrAddress | Account | Address // `accountOrAddress` defined, add for inference
26
+ : Account | Address | undefined // `accountOrAddress` undefined, show possible types for autocomplete
33
27
  /** Flags for batch settings. */
34
- batch?: {
35
- /** Toggle to enable `eth_call` multicall aggregation. */
36
- multicall?: boolean | MulticallBatchOptions
37
- }
28
+ batch?:
29
+ | {
30
+ /** Toggle to enable `eth_call` multicall aggregation. */
31
+ multicall?: boolean | Prettify<MulticallBatchOptions> | undefined
32
+ }
33
+ | undefined
38
34
  /** Chain for the client. */
39
- chain?: TChain
35
+ chain?: chain extends Chain
36
+ ? chain // `chain` defined, add for inference
37
+ : Chain | undefined // `chain` undefined, show possible types for autocomplete
40
38
  /** A key for the client. */
41
- key?: string
39
+ key?: string | undefined
42
40
  /** A name for the client. */
43
- name?: string
41
+ name?: string | undefined
44
42
  /**
45
43
  * Frequency (in ms) for polling enabled actions & events.
46
44
  * @default 4_000
47
45
  */
48
- pollingInterval?: number
46
+ pollingInterval?: number | undefined
49
47
  /** The RPC transport */
50
- transport: TTransport
48
+ transport: transport
51
49
  /** The type of client. */
52
- type?: string
50
+ type?: string | undefined
53
51
  }
54
52
 
53
+ // TODO: Move `transport` to slot index 2 since `chain` and `account` used more frequently.
54
+ // Otherwise, we end up with a lot of `Client<Transport, chain, account>` in actions.
55
+ export type Client<
56
+ transport extends Transport = Transport,
57
+ chain extends Chain | undefined = Chain | undefined,
58
+ account extends Account | undefined = Account | undefined,
59
+ rpcSchema extends RpcSchema | undefined = undefined,
60
+ extended extends Extended | undefined = Extended | undefined,
61
+ > = Prettify<
62
+ Prettify<Client_Base<transport, chain, account, rpcSchema>> & {
63
+ extend: <const client extends Extended>(
64
+ fn: (
65
+ client: Client<transport, chain, account, rpcSchema, extended>,
66
+ ) => client,
67
+ ) => Prettify<
68
+ Client<
69
+ transport,
70
+ chain,
71
+ account,
72
+ rpcSchema,
73
+ Prettify<client> & (extended extends Extended ? extended : unknown)
74
+ >
75
+ >
76
+ } & (extended extends Extended ? extended : unknown)
77
+ >
78
+
55
79
  type Client_Base<
56
- TTransport extends Transport = Transport,
57
- TChain extends Chain | undefined = Chain | undefined,
58
- TAccount extends Account | undefined = Account | undefined,
59
- TRpcSchema extends RpcSchema | undefined = undefined,
80
+ transport extends Transport = Transport,
81
+ chain extends Chain | undefined = Chain | undefined,
82
+ account extends Account | undefined = Account | undefined,
83
+ rpcSchema extends RpcSchema | undefined = undefined,
60
84
  > = {
61
85
  /** The Account of the Client. */
62
- account: TAccount
86
+ account: account
63
87
  /** Flags for batch settings. */
64
- batch?: {
65
- /** Toggle to enable `eth_call` multicall aggregation. */
66
- multicall?: boolean | MulticallBatchOptions
67
- }
88
+ batch?: ClientConfig['batch']
68
89
  /** Chain for the client. */
69
- chain: TChain
90
+ chain: chain
70
91
  /** A key for the client. */
71
92
  key: string
72
93
  /** A name for the client. */
@@ -74,86 +95,89 @@ type Client_Base<
74
95
  /** Frequency (in ms) for polling enabled actions & events. Defaults to 4_000 milliseconds. */
75
96
  pollingInterval: number
76
97
  /** Request function wrapped with friendly error handling */
77
- request: TRpcSchema extends undefined
78
- ? EIP1193RequestFn<EIP1474Methods>
79
- : EIP1193RequestFn<TRpcSchema>
98
+ request: EIP1193RequestFn<
99
+ rpcSchema extends undefined ? EIP1474Methods : rpcSchema
100
+ >
80
101
  /** The RPC transport */
81
- transport: ReturnType<TTransport>['config'] & ReturnType<TTransport>['value']
102
+ transport: ReturnType<transport>['config'] & ReturnType<transport>['value']
82
103
  /** The type of client. */
83
104
  type: string
84
105
  /** A unique ID for the client. */
85
106
  uid: string
86
107
  }
87
108
 
88
- type Extended = { [K in keyof Client_Base]?: undefined } & {
89
- [key: string]: unknown
90
- }
109
+ type Extended = Prettify<
110
+ // disallow redefining base properties
111
+ { [K in keyof Client_Base]?: undefined } & {
112
+ [key: string]: unknown
113
+ }
114
+ >
91
115
 
92
- export type Client<
93
- TTransport extends Transport = Transport,
94
- TChain extends Chain | undefined = Chain | undefined,
95
- TAccount extends Account | undefined = Account | undefined,
96
- TRpcSchema extends RpcSchema | undefined = undefined,
97
- TExtended extends Extended | undefined = Extended | undefined,
98
- > = Client_Base<TTransport, TChain, TAccount, TRpcSchema> & {
99
- extend: <TNextExtended extends Extended = Extended>(
100
- fn: (
101
- client: Client<TTransport, TChain, TAccount, TRpcSchema, TExtended>,
102
- ) => Narrow<TNextExtended>,
103
- ) => Client<
104
- TTransport,
105
- TChain,
106
- TAccount,
107
- TRpcSchema,
108
- (TExtended extends Extended ? TExtended : {}) & TNextExtended
109
- >
110
- } & (TExtended extends Extended ? TExtended : {})
116
+ export type MulticallBatchOptions = {
117
+ /** The maximum size (in bytes) for each calldata chunk. @default 1_024 */
118
+ batchSize?: number | undefined
119
+ /** The maximum number of milliseconds to wait before sending a batch. @default 0 */
120
+ wait?: number | undefined
121
+ }
111
122
 
112
123
  /**
113
- * @description Creates a base client with the given transport.
124
+ * Creates a base client with the given transport.
114
125
  */
115
126
  export function createClient<
116
- TTransport extends Transport,
117
- TChain extends Chain | undefined = undefined,
118
- TAccountOrAddress extends Account | Address | undefined = undefined,
119
- >({
120
- account,
121
- batch,
122
- chain,
123
- key = 'base',
124
- name = 'Base Client',
125
- pollingInterval = 4_000,
127
+ transport extends Transport,
128
+ chain extends Chain | undefined = undefined,
129
+ accountOrAddress extends Account | Address | undefined = undefined,
130
+ >(
131
+ parameters: ClientConfig<transport, chain, accountOrAddress>,
132
+ ): Client<
126
133
  transport,
127
- type = 'base',
128
- }: ClientConfig<TTransport, TChain, TAccountOrAddress>): Client<
129
- TTransport,
130
- TChain,
131
- TAccountOrAddress extends Address
132
- ? Prettify<JsonRpcAccount<TAccountOrAddress>>
133
- : TAccountOrAddress
134
- > {
135
- const { config, request, value } = transport({ chain, pollingInterval })
134
+ chain,
135
+ accountOrAddress extends Address
136
+ ? Prettify<JsonRpcAccount<accountOrAddress>>
137
+ : accountOrAddress
138
+ >
139
+
140
+ export function createClient(parameters: ClientConfig): Client {
141
+ const {
142
+ batch,
143
+ key = 'base',
144
+ name = 'Base Client',
145
+ pollingInterval = 4_000,
146
+ type = 'base',
147
+ } = parameters
148
+
149
+ const chain = parameters.chain
150
+ const account = parameters.account
151
+ ? parseAccount(parameters.account)
152
+ : undefined
153
+ const { config, request, value } = parameters.transport({
154
+ chain,
155
+ pollingInterval,
156
+ })
157
+ const transport = { ...config, ...value }
158
+
136
159
  const client = {
137
- account: (account
138
- ? parseAccount(account)
139
- : undefined) as ParseAccount<TAccountOrAddress>,
160
+ account,
140
161
  batch,
141
- chain: chain as TChain,
162
+ chain,
142
163
  key,
143
164
  name,
144
165
  pollingInterval,
145
166
  request,
146
- transport: { ...config, ...value },
167
+ transport,
147
168
  type,
148
169
  uid: uid(),
149
170
  }
150
- function extend(client_: typeof client) {
151
- return (fn: (_: typeof client) => unknown) => {
152
- const extended = fn(client_) as Extended
171
+
172
+ function extend(base: typeof client) {
173
+ type ExtendFn = (base: typeof client) => unknown
174
+ return (extendFn: ExtendFn) => {
175
+ const extended = extendFn(base) as Extended
153
176
  for (const key in client) delete extended[key]
154
- const nextClient = { ...client_, ...extended }
155
- return Object.assign(nextClient, { extend: extend(nextClient) })
177
+ const combined = { ...base, ...extended }
178
+ return Object.assign(combined, { extend: extend(combined) })
156
179
  }
157
180
  }
181
+
158
182
  return Object.assign(client, { extend: extend(client) as any })
159
183
  }
@@ -6,23 +6,25 @@ import { type PublicActions, publicActions } from './decorators/public.js'
6
6
  import type { Transport } from './transports/createTransport.js'
7
7
 
8
8
  export type PublicClientConfig<
9
- TTransport extends Transport = Transport,
10
- TChain extends Chain | undefined = Chain | undefined,
11
- > = Pick<
12
- ClientConfig<TTransport, TChain>,
13
- 'batch' | 'chain' | 'key' | 'name' | 'pollingInterval' | 'transport'
9
+ transport extends Transport = Transport,
10
+ chain extends Chain | undefined = Chain | undefined,
11
+ > = Prettify<
12
+ Pick<
13
+ ClientConfig<transport, chain>,
14
+ 'batch' | 'chain' | 'key' | 'name' | 'pollingInterval' | 'transport'
15
+ >
14
16
  >
15
17
 
16
18
  export type PublicClient<
17
- TTransport extends Transport = Transport,
18
- TChain extends Chain | undefined = Chain | undefined,
19
+ transport extends Transport = Transport,
20
+ chain extends Chain | undefined = Chain | undefined,
19
21
  > = Prettify<
20
22
  Client<
21
- TTransport,
22
- TChain,
23
+ transport,
24
+ chain,
23
25
  undefined,
24
26
  PublicRpcSchema,
25
- PublicActions<TTransport, TChain>
27
+ PublicActions<transport, chain>
26
28
  >
27
29
  >
28
30
 
@@ -46,23 +48,21 @@ export type PublicClient<
46
48
  * })
47
49
  */
48
50
  export function createPublicClient<
49
- TTransport extends Transport,
50
- TChain extends Chain | undefined = undefined,
51
- >({
52
- batch,
53
- chain,
54
- key = 'public',
55
- name = 'Public Client',
56
- transport,
57
- pollingInterval,
58
- }: PublicClientConfig<TTransport, TChain>): PublicClient<TTransport, TChain> {
59
- return createClient({
60
- batch,
61
- chain,
51
+ transport extends Transport,
52
+ chain extends Chain | undefined = undefined,
53
+ >(
54
+ parameters: PublicClientConfig<transport, chain>,
55
+ ): PublicClient<transport, chain>
56
+
57
+ export function createPublicClient(
58
+ parameters: PublicClientConfig,
59
+ ): PublicClient {
60
+ const { key = 'public', name = 'Public Client' } = parameters
61
+ const client = createClient({
62
+ ...parameters,
62
63
  key,
63
64
  name,
64
- pollingInterval,
65
- transport,
66
65
  type: 'publicClient',
67
- }).extend(publicActions)
66
+ })
67
+ return client.extend(publicActions)
68
68
  }
@@ -2,6 +2,7 @@ import type { Account } from '../accounts/types.js'
2
2
  import type { ParseAccount } from '../types/account.js'
3
3
  import type { Chain } from '../types/chain.js'
4
4
  import type { TestRpcSchema } from '../types/eip1193.js'
5
+ import type { Prettify } from '../types/utils.js'
5
6
  import { type Client, type ClientConfig, createClient } from './createClient.js'
6
7
  import { type TestActions, testActions } from './decorators/test.js'
7
8
  import type { Transport } from './transports/createTransport.js'
@@ -10,36 +11,38 @@ import type { Address } from 'abitype'
10
11
  export type TestClientMode = 'anvil' | 'hardhat' | 'ganache'
11
12
 
12
13
  export type TestClientConfig<
13
- TMode extends TestClientMode = TestClientMode,
14
- TTransport extends Transport = Transport,
15
- TChain extends Chain | undefined = Chain | undefined,
16
- TAccountOrAddress extends Account | Address | undefined =
14
+ mode extends TestClientMode = TestClientMode,
15
+ transport extends Transport = Transport,
16
+ chain extends Chain | undefined = Chain | undefined,
17
+ accountOrAddress extends Account | Address | undefined =
17
18
  | Account
18
19
  | Address
19
20
  | undefined,
20
- > = Pick<
21
- ClientConfig<TTransport, TChain, TAccountOrAddress>,
22
- 'account' | 'chain' | 'key' | 'name' | 'pollingInterval' | 'transport'
23
- > & {
24
- /** Mode of the test client. Available: "anvil" | "hardhat" | "ganache" */
25
- mode: TMode
26
- }
21
+ > = Prettify<
22
+ Pick<
23
+ ClientConfig<transport, chain, accountOrAddress>,
24
+ 'account' | 'chain' | 'key' | 'name' | 'pollingInterval' | 'transport'
25
+ > & {
26
+ /** Mode of the test client. */
27
+ mode: mode | ('anvil' | 'hardhat' | 'ganache') // TODO: Type utility that expands `TestClientMode`
28
+ }
29
+ >
27
30
 
28
31
  export type TestClient<
29
32
  TMode extends TestClientMode = TestClientMode,
30
- TTransport extends Transport = Transport,
31
- TChain extends Chain | undefined = Chain | undefined,
33
+ transport extends Transport = Transport,
34
+ chain extends Chain | undefined = Chain | undefined,
32
35
  TAccount extends Account | undefined = Account | undefined,
33
36
  TIncludeActions extends boolean = true,
34
- > = Client<
35
- TTransport,
36
- TChain,
37
- TAccount,
38
- TestRpcSchema<TMode>,
39
- TIncludeActions extends true ? TestActions : Record<string, unknown>
40
- > & {
41
- mode: TMode
42
- }
37
+ > = Prettify<
38
+ { mode: TMode } & Client<
39
+ transport,
40
+ chain,
41
+ TAccount,
42
+ TestRpcSchema<TMode>,
43
+ TIncludeActions extends true ? TestActions : Record<string, unknown>
44
+ >
45
+ >
43
46
 
44
47
  /**
45
48
  * @description Creates a test client with a given transport.
@@ -65,33 +68,24 @@ export type TestClient<
65
68
  * })
66
69
  */
67
70
  export function createTestClient<
68
- TMode extends TestClientMode,
69
- TTransport extends Transport,
70
- TChain extends Chain | undefined = undefined,
71
- TAccountOrAddress extends Account | Address | undefined = undefined,
72
- >({
73
- account,
74
- chain,
75
- key = 'test',
76
- name = 'Test Client',
77
- mode,
78
- pollingInterval,
79
- transport,
80
- }: TestClientConfig<TMode, TTransport, TChain, TAccountOrAddress>): TestClient<
81
- TMode,
82
- TTransport,
83
- TChain,
84
- ParseAccount<TAccountOrAddress>
85
- > {
86
- return createClient({
87
- account,
88
- chain,
71
+ mode extends 'anvil' | 'hardhat' | 'ganache', // TODO: Type utility that expands `TestClientMode`
72
+ transport extends Transport,
73
+ chain extends Chain | undefined = undefined,
74
+ accountOrAddress extends Account | Address | undefined = undefined,
75
+ >(
76
+ parameters: TestClientConfig<mode, transport, chain, accountOrAddress>,
77
+ ): TestClient<mode, transport, chain, ParseAccount<accountOrAddress>>
78
+
79
+ export function createTestClient(parameters: TestClientConfig): TestClient {
80
+ const { key = 'test', name = 'Test Client', mode } = parameters
81
+ const client = createClient({
82
+ ...parameters,
89
83
  key,
90
84
  name,
91
- pollingInterval,
92
- transport,
93
85
  type: 'testClient',
94
86
  })
95
- .extend(() => ({ mode }))
96
- .extend(testActions({ mode }))
87
+ return client.extend((config) => ({
88
+ mode,
89
+ ...testActions({ mode })(config),
90
+ }))
97
91
  }