viem 0.0.0-w-20230820223631 → 0.0.0-w-20230821171049

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 (57) hide show
  1. package/dist/cjs/actions/getContract.js.map +1 -1
  2. package/dist/cjs/actions/public/estimateContractGas.js +7 -14
  3. package/dist/cjs/actions/public/estimateContractGas.js.map +1 -1
  4. package/dist/cjs/actions/public/readContract.js +6 -10
  5. package/dist/cjs/actions/public/readContract.js.map +1 -1
  6. package/dist/cjs/actions/public/simulateContract.js +6 -9
  7. package/dist/cjs/actions/public/simulateContract.js.map +1 -1
  8. package/dist/cjs/actions/wallet/writeContract.js +1 -5
  9. package/dist/cjs/actions/wallet/writeContract.js.map +1 -1
  10. package/dist/cjs/clients/decorators/public.js.map +1 -1
  11. package/dist/cjs/clients/decorators/wallet.js.map +1 -1
  12. package/dist/cjs/index.js.map +1 -1
  13. package/dist/esm/actions/getContract.js.map +1 -1
  14. package/dist/esm/actions/public/estimateContractGas.js +8 -15
  15. package/dist/esm/actions/public/estimateContractGas.js.map +1 -1
  16. package/dist/esm/actions/public/readContract.js +8 -12
  17. package/dist/esm/actions/public/readContract.js.map +1 -1
  18. package/dist/esm/actions/public/simulateContract.js +8 -11
  19. package/dist/esm/actions/public/simulateContract.js.map +1 -1
  20. package/dist/esm/actions/wallet/writeContract.js +2 -6
  21. package/dist/esm/actions/wallet/writeContract.js.map +1 -1
  22. package/dist/esm/clients/decorators/public.js.map +1 -1
  23. package/dist/esm/clients/decorators/wallet.js +1 -0
  24. package/dist/esm/clients/decorators/wallet.js.map +1 -1
  25. package/dist/esm/index.js.map +1 -1
  26. package/dist/esm/types/contract.js +1 -1
  27. package/dist/esm/types/contract.js.map +1 -1
  28. package/dist/types/actions/getContract.d.ts +10 -10
  29. package/dist/types/actions/getContract.d.ts.map +1 -1
  30. package/dist/types/actions/public/estimateContractGas.d.ts +3 -3
  31. package/dist/types/actions/public/estimateContractGas.d.ts.map +1 -1
  32. package/dist/types/actions/public/readContract.d.ts.map +1 -1
  33. package/dist/types/actions/public/simulateContract.d.ts +11 -11
  34. package/dist/types/actions/public/simulateContract.d.ts.map +1 -1
  35. package/dist/types/actions/wallet/writeContract.d.ts +3 -3
  36. package/dist/types/actions/wallet/writeContract.d.ts.map +1 -1
  37. package/dist/types/clients/decorators/public.d.ts +2 -2
  38. package/dist/types/clients/decorators/public.d.ts.map +1 -1
  39. package/dist/types/clients/decorators/wallet.d.ts +2 -1
  40. package/dist/types/clients/decorators/wallet.d.ts.map +1 -1
  41. package/dist/types/index.d.ts +1 -1
  42. package/dist/types/index.d.ts.map +1 -1
  43. package/dist/types/types/contract.d.ts +7 -28
  44. package/dist/types/types/contract.d.ts.map +1 -1
  45. package/dist/types/types/utils.d.ts +5 -0
  46. package/dist/types/types/utils.d.ts.map +1 -1
  47. package/package.json +1 -1
  48. package/src/actions/getContract.ts +70 -18
  49. package/src/actions/public/estimateContractGas.ts +48 -38
  50. package/src/actions/public/readContract.ts +10 -22
  51. package/src/actions/public/simulateContract.ts +91 -59
  52. package/src/actions/wallet/writeContract.ts +28 -15
  53. package/src/clients/decorators/public.ts +25 -8
  54. package/src/clients/decorators/wallet.ts +10 -4
  55. package/src/index.ts +0 -3
  56. package/src/types/contract.ts +43 -112
  57. package/src/types/utils.ts +11 -0
@@ -6,67 +6,95 @@ import type { Transport } from '../../clients/transports/createTransport.js'
6
6
  import type { BaseError } from '../../errors/base.js'
7
7
  import type { Chain } from '../../types/chain.js'
8
8
  import type {
9
- ContractFunctionConfig,
10
- ContractFunctionResult,
9
+ ContractFunctionArgs,
10
+ ContractFunctionName,
11
+ ContractFunctionParameters,
12
+ ContractFunctionReturnType,
11
13
  GetValue,
12
14
  } from '../../types/contract.js'
13
15
  import type { Hex } from '../../types/misc.js'
14
16
  import type { UnionOmit } from '../../types/utils.js'
15
- import {
16
- type DecodeFunctionResultParameters,
17
- decodeFunctionResult,
18
- } from '../../utils/abi/decodeFunctionResult.js'
19
- import {
20
- type EncodeFunctionDataParameters,
21
- encodeFunctionData,
22
- } from '../../utils/abi/encodeFunctionData.js'
17
+ import { decodeFunctionResult } from '../../utils/abi/decodeFunctionResult.js'
18
+ import { encodeFunctionData } from '../../utils/abi/encodeFunctionData.js'
23
19
  import { getContractError } from '../../utils/errors/getContractError.js'
24
20
  import type { WriteContractParameters } from '../wallet/writeContract.js'
25
21
 
26
22
  import { type CallParameters, call } from './call.js'
27
23
 
28
24
  export type SimulateContractParameters<
29
- TAbi extends Abi | readonly unknown[] = Abi,
30
- TFunctionName extends string = any,
31
- TChain extends Chain | undefined = Chain | undefined,
32
- TChainOverride extends Chain | undefined = Chain | undefined,
25
+ abi extends Abi | readonly unknown[] = Abi,
26
+ functionName extends ContractFunctionName<
27
+ abi,
28
+ 'nonpayable' | 'payable'
29
+ > = ContractFunctionName<abi, 'nonpayable' | 'payable'>,
30
+ args extends ContractFunctionArgs<
31
+ abi,
32
+ 'nonpayable' | 'payable',
33
+ functionName
34
+ > = ContractFunctionArgs<abi, 'nonpayable' | 'payable', functionName>,
35
+ chain extends Chain | undefined = Chain | undefined,
36
+ chainOverride extends Chain | undefined = Chain | undefined,
33
37
  > = {
34
- chain?: TChainOverride
38
+ chain?: chainOverride
35
39
  /** Data to append to the end of the calldata. Useful for adding a ["domain" tag](https://opensea.notion.site/opensea/Seaport-Order-Attributions-ec2d69bf455041a5baa490941aad307f). */
36
40
  dataSuffix?: Hex
37
- } & ContractFunctionConfig<TAbi, TFunctionName, 'payable' | 'nonpayable'> &
41
+ } & ContractFunctionParameters<
42
+ abi,
43
+ 'nonpayable' | 'payable',
44
+ functionName,
45
+ args
46
+ > &
38
47
  UnionOmit<
39
- CallParameters<TChainOverride extends Chain ? TChainOverride : TChain>,
48
+ CallParameters<chainOverride extends Chain ? chainOverride : chain>,
40
49
  'batch' | 'to' | 'data' | 'value'
41
50
  > &
42
51
  GetValue<
43
- TAbi,
44
- TFunctionName,
45
- CallParameters<TChain> extends CallParameters
46
- ? CallParameters<TChain>['value']
52
+ abi,
53
+ functionName,
54
+ CallParameters<chain> extends CallParameters
55
+ ? CallParameters<chain>['value']
47
56
  : CallParameters['value']
48
57
  >
49
58
 
50
59
  export type SimulateContractReturnType<
51
- TAbi extends Abi | readonly unknown[] = Abi,
52
- TFunctionName extends string = string,
53
- TChain extends Chain | undefined = Chain | undefined,
54
- TChainOverride extends Chain | undefined = Chain | undefined,
60
+ abi extends Abi | readonly unknown[] = Abi,
61
+ functionName extends ContractFunctionName<
62
+ abi,
63
+ 'nonpayable' | 'payable'
64
+ > = ContractFunctionName<abi, 'nonpayable' | 'payable'>,
65
+ args extends ContractFunctionArgs<
66
+ abi,
67
+ 'nonpayable' | 'payable',
68
+ functionName
69
+ > = ContractFunctionArgs<abi, 'nonpayable' | 'payable', functionName>,
70
+ chain extends Chain | undefined = Chain | undefined,
71
+ chainOverride extends Chain | undefined = Chain | undefined,
55
72
  > = {
56
- result: ContractFunctionResult<TAbi, TFunctionName>
73
+ result: ContractFunctionReturnType<
74
+ abi,
75
+ 'nonpayable' | 'payable',
76
+ functionName,
77
+ args
78
+ >
57
79
  request: UnionOmit<
58
80
  WriteContractParameters<
59
- TAbi,
60
- TFunctionName,
61
- TChain,
81
+ abi,
82
+ functionName,
83
+ args,
84
+ chain,
62
85
  undefined,
63
- TChainOverride
86
+ chainOverride
64
87
  >,
65
88
  'chain' | 'functionName'
66
89
  > & {
67
- chain: TChainOverride
68
- functionName: TFunctionName
69
- } & ContractFunctionConfig<TAbi, TFunctionName, 'payable' | 'nonpayable'>
90
+ chain: chainOverride
91
+ functionName: functionName
92
+ } & ContractFunctionParameters<
93
+ abi,
94
+ 'nonpayable' | 'payable',
95
+ functionName,
96
+ args
97
+ >
70
98
  }
71
99
 
72
100
  /**
@@ -101,44 +129,47 @@ export type SimulateContractReturnType<
101
129
  * })
102
130
  */
103
131
  export async function simulateContract<
104
- TChain extends Chain | undefined,
105
- const TAbi extends Abi | readonly unknown[],
106
- TFunctionName extends string,
107
- TChainOverride extends Chain | undefined,
132
+ chain extends Chain | undefined,
133
+ const abi extends Abi | readonly unknown[],
134
+ functionName extends ContractFunctionName<abi, 'nonpayable' | 'payable'>,
135
+ args extends ContractFunctionArgs<
136
+ abi,
137
+ 'nonpayable' | 'payable',
138
+ functionName
139
+ >,
140
+ chainOverride extends Chain | undefined,
108
141
  >(
109
- client: Client<Transport, TChain>,
110
- {
142
+ client: Client<Transport, chain>,
143
+ parameters: SimulateContractParameters<
111
144
  abi,
112
- address,
113
- args,
114
- dataSuffix,
115
145
  functionName,
116
- ...callRequest
117
- }: SimulateContractParameters<TAbi, TFunctionName, TChain, TChainOverride>,
146
+ args,
147
+ chain,
148
+ chainOverride
149
+ >,
118
150
  ): Promise<
119
- SimulateContractReturnType<TAbi, TFunctionName, TChain, TChainOverride>
151
+ SimulateContractReturnType<abi, functionName, args, chain, chainOverride>
120
152
  > {
153
+ const { abi, address, args, dataSuffix, functionName, ...callRequest } =
154
+ parameters as SimulateContractParameters
155
+
121
156
  const account = callRequest.account
122
157
  ? parseAccount(callRequest.account)
123
158
  : undefined
124
- const calldata = encodeFunctionData({
125
- abi,
126
- args,
127
- functionName,
128
- } as unknown as EncodeFunctionDataParameters<TAbi, TFunctionName>)
159
+ const calldata = encodeFunctionData({ abi, args, functionName })
129
160
  try {
130
161
  const { data } = await call(client, {
131
162
  batch: false,
132
163
  data: `${calldata}${dataSuffix ? dataSuffix.replace('0x', '') : ''}`,
133
164
  to: address,
134
165
  ...callRequest,
135
- } as unknown as CallParameters<TChain>)
166
+ })
136
167
  const result = decodeFunctionResult({
137
168
  abi,
138
169
  args,
139
170
  functionName,
140
171
  data: data || '0x',
141
- } as DecodeFunctionResultParameters)
172
+ })
142
173
  return {
143
174
  result,
144
175
  request: {
@@ -150,14 +181,15 @@ export async function simulateContract<
150
181
  ...callRequest,
151
182
  },
152
183
  } as unknown as SimulateContractReturnType<
153
- TAbi,
154
- TFunctionName,
155
- TChain,
156
- TChainOverride
184
+ abi,
185
+ functionName,
186
+ args,
187
+ chain,
188
+ chainOverride
157
189
  >
158
- } catch (err) {
159
- throw getContractError(err as BaseError, {
160
- abi: abi as Abi,
190
+ } catch (error) {
191
+ throw getContractError(error as BaseError, {
192
+ abi,
161
193
  address,
162
194
  args,
163
195
  docsPath: '/docs/contract/simulateContract',
@@ -5,13 +5,15 @@ import type { Client } from '../../clients/createClient.js'
5
5
  import type { Transport } from '../../clients/transports/createTransport.js'
6
6
  import type { GetAccountParameter } from '../../types/account.js'
7
7
  import type { Chain, GetChain } from '../../types/chain.js'
8
- import type { ContractFunctionConfig, GetValue } from '../../types/contract.js'
8
+ import type {
9
+ ContractFunctionArgs,
10
+ ContractFunctionName,
11
+ ContractFunctionParameters,
12
+ GetValue,
13
+ } from '../../types/contract.js'
9
14
  import type { Hex } from '../../types/misc.js'
10
15
  import type { UnionOmit } from '../../types/utils.js'
11
- import {
12
- type EncodeFunctionDataParameters,
13
- encodeFunctionData,
14
- } from '../../utils/abi/encodeFunctionData.js'
16
+ import { encodeFunctionData } from '../../utils/abi/encodeFunctionData.js'
15
17
  import type { FormattedTransactionRequest } from '../../utils/formatters/transactionRequest.js'
16
18
  import {
17
19
  type SendTransactionParameters,
@@ -21,11 +23,24 @@ import {
21
23
 
22
24
  export type WriteContractParameters<
23
25
  abi extends Abi | readonly unknown[] = Abi,
24
- functionName extends string = string,
26
+ functionName extends ContractFunctionName<
27
+ abi,
28
+ 'nonpayable' | 'payable'
29
+ > = ContractFunctionName<abi, 'nonpayable' | 'payable'>,
30
+ args extends ContractFunctionArgs<
31
+ abi,
32
+ 'nonpayable' | 'payable',
33
+ functionName
34
+ > = ContractFunctionArgs<abi, 'nonpayable' | 'payable', functionName>,
25
35
  chain extends Chain | undefined = Chain,
26
36
  account extends Account | undefined = Account | undefined,
27
37
  chainOverride extends Chain | undefined = Chain | undefined,
28
- > = ContractFunctionConfig<abi, functionName, 'payable' | 'nonpayable'> &
38
+ > = ContractFunctionParameters<
39
+ abi,
40
+ 'nonpayable' | 'payable',
41
+ functionName,
42
+ args
43
+ > &
29
44
  UnionOmit<
30
45
  FormattedTransactionRequest<
31
46
  chainOverride extends Chain ? chainOverride : chain
@@ -105,29 +120,27 @@ export async function writeContract<
105
120
  chain extends Chain | undefined,
106
121
  account extends Account | undefined,
107
122
  const abi extends Abi | readonly unknown[],
108
- functionName extends string,
123
+ functionName extends ContractFunctionName<abi, 'nonpayable' | 'payable'>,
124
+ args extends ContractFunctionArgs<abi, 'pure' | 'view', functionName>,
109
125
  chainOverride extends Chain | undefined,
110
126
  >(
111
127
  client: Client<Transport, chain, account>,
112
128
  parameters: WriteContractParameters<
113
129
  abi,
114
130
  functionName,
131
+ args,
115
132
  chain,
116
133
  account,
117
134
  chainOverride
118
135
  >,
119
136
  ): Promise<WriteContractReturnType> {
120
137
  const { abi, address, args, dataSuffix, functionName, ...request } =
121
- parameters
122
- const data = encodeFunctionData({
123
- abi,
124
- args,
125
- functionName,
126
- } as unknown as EncodeFunctionDataParameters<abi, functionName>)
138
+ parameters as WriteContractParameters
139
+ const data = encodeFunctionData({ abi, args, functionName })
127
140
  const hash = await sendTransaction(client, {
128
141
  data: `${data}${dataSuffix ? dataSuffix.replace('0x', '') : ''}`,
129
142
  to: address,
130
143
  ...request,
131
- } as unknown as SendTransactionParameters<chain, account, chainOverride>)
144
+ })
132
145
  return hash
133
146
  }
@@ -407,10 +407,21 @@ export type PublicActions<
407
407
  */
408
408
  estimateContractGas: <
409
409
  TChain extends Chain | undefined,
410
- const TAbi extends Abi | readonly unknown[],
411
- TFunctionName extends string,
410
+ const abi extends Abi | readonly unknown[],
411
+ functionName extends ContractFunctionName<abi, 'nonpayable' | 'payable'>,
412
+ args extends ContractFunctionArgs<
413
+ abi,
414
+ 'nonpayable' | 'payable',
415
+ functionName
416
+ >,
412
417
  >(
413
- args: EstimateContractGasParameters<TAbi, TFunctionName, TChain, TAccount>,
418
+ args: EstimateContractGasParameters<
419
+ abi,
420
+ functionName,
421
+ args,
422
+ TChain,
423
+ TAccount
424
+ >,
414
425
  ) => Promise<EstimateContractGasReturnType>
415
426
  /**
416
427
  * Estimates the gas necessary to complete a transaction without submitting it to the network.
@@ -1208,18 +1219,24 @@ export type PublicActions<
1208
1219
  * })
1209
1220
  */
1210
1221
  simulateContract: <
1211
- const TAbi extends Abi | readonly unknown[],
1212
- TFunctionName extends string,
1222
+ const abi extends Abi | readonly unknown[],
1223
+ functionName extends ContractFunctionName<abi, 'nonpayable' | 'payable'>,
1224
+ args extends ContractFunctionArgs<
1225
+ abi,
1226
+ 'nonpayable' | 'payable',
1227
+ functionName
1228
+ >,
1213
1229
  TChainOverride extends Chain | undefined,
1214
1230
  >(
1215
1231
  args: SimulateContractParameters<
1216
- TAbi,
1217
- TFunctionName,
1232
+ abi,
1233
+ functionName,
1234
+ args,
1218
1235
  TChain,
1219
1236
  TChainOverride
1220
1237
  >,
1221
1238
  ) => Promise<
1222
- SimulateContractReturnType<TAbi, TFunctionName, TChain, TChainOverride>
1239
+ SimulateContractReturnType<abi, functionName, args, TChain, TChainOverride>
1223
1240
  >
1224
1241
  verifyMessage: (
1225
1242
  args: VerifyMessageParameters,
@@ -61,6 +61,10 @@ import {
61
61
  writeContract,
62
62
  } from '../../actions/wallet/writeContract.js'
63
63
  import type { Chain } from '../../types/chain.js'
64
+ import {
65
+ type ContractFunctionArgs,
66
+ type ContractFunctionName,
67
+ } from '../../types/contract.js'
64
68
  import type { Client } from '../createClient.js'
65
69
  import type { Transport } from '../transports/createTransport.js'
66
70
 
@@ -509,13 +513,15 @@ export type WalletActions<
509
513
  * const hash = await client.writeContract(request)
510
514
  */
511
515
  writeContract: <
512
- const TAbi extends Abi | readonly unknown[],
513
- TFunctionName extends string,
516
+ const abi extends Abi | readonly unknown[],
517
+ functionName extends ContractFunctionName<abi, 'payable' | 'nonpayable'>,
518
+ args extends ContractFunctionArgs<abi, 'pure' | 'view', functionName>,
514
519
  TChainOverride extends Chain | undefined,
515
520
  >(
516
521
  args: WriteContractParameters<
517
- TAbi,
518
- TFunctionName,
522
+ abi,
523
+ functionName,
524
+ args,
519
525
  TChain,
520
526
  TAccount,
521
527
  TChainOverride
package/src/index.ts CHANGED
@@ -519,9 +519,6 @@ export type {
519
519
  ContractFunctionReturnType,
520
520
  ContractFunctionName,
521
521
  ContractFunctionArgs,
522
- ContractParameters,
523
- ContractReturnType,
524
- ContractFunctionConfig,
525
522
  ContractFunctionResult,
526
523
  GetConstructorArgs,
527
524
  GetErrorArgs,
@@ -1,21 +1,21 @@
1
- import type {
2
- Abi,
3
- AbiConstructor,
4
- AbiError,
5
- AbiEvent,
6
- AbiFunction,
7
- AbiParameter,
8
- AbiParameterToPrimitiveType,
9
- AbiParametersToPrimitiveTypes,
10
- AbiStateMutability,
11
- Address,
12
- ExtractAbiError,
13
- ExtractAbiErrorNames,
14
- ExtractAbiEvent,
15
- ExtractAbiEventNames,
16
- ExtractAbiFunction,
17
- ExtractAbiFunctionNames,
18
- ResolvedConfig,
1
+ import {
2
+ type Abi,
3
+ type AbiConstructor,
4
+ type AbiError,
5
+ type AbiEvent,
6
+ type AbiFunction,
7
+ type AbiParameter,
8
+ type AbiParameterToPrimitiveType,
9
+ type AbiParametersToPrimitiveTypes,
10
+ type AbiStateMutability,
11
+ type Address,
12
+ type ExtractAbiError,
13
+ type ExtractAbiErrorNames,
14
+ type ExtractAbiEvent,
15
+ type ExtractAbiEventNames,
16
+ type ExtractAbiFunction,
17
+ type ExtractAbiFunctionNames,
18
+ type ResolvedConfig,
19
19
  } from 'abitype'
20
20
 
21
21
  import type { Hex, LogTopic } from './misc.js'
@@ -27,6 +27,7 @@ import type {
27
27
  MaybeRequired,
28
28
  NoUndefined,
29
29
  Prettify,
30
+ UnionEvaluate,
30
31
  UnionToTuple,
31
32
  } from './utils.js'
32
33
 
@@ -128,28 +129,30 @@ export type ContractFunctionParameters<
128
129
  allFunctionNames = ContractFunctionName<abi, mutability>,
129
130
  // when `args` is inferred to `readonly []` ("inputs": []) or `never` (`abi` declared as `Abi` or not inferrable), allow `args` to be optional.
130
131
  // important that both branches return same structural type
131
- > = readonly [] extends allArgs
132
- ? {
133
- address: Address
134
- abi: abi
135
- functionName:
136
- | allFunctionNames // show all options
137
- | (functionName extends allFunctionNames ? functionName : never) // infer value
138
- args?:
139
- | allArgs // show all options
140
- | (args extends allArgs ? Widen<args> : never) // infer value, widen inferred value of `args` conditionally to match `allArgs`
141
- | undefined
142
- }
143
- : {
144
- address: Address
145
- abi: abi
146
- functionName:
147
- | allFunctionNames // show all options
148
- | (functionName extends allFunctionNames ? functionName : never) // infer value
149
- args:
150
- | allArgs // show all options
151
- | Widen<args> // infer value, widen inferred value of `args` match `allArgs` (e.g. avoid union `args: readonly [123n] | readonly [bigint]`)
152
- }
132
+ > = {
133
+ address: Address
134
+ abi: abi
135
+ functionName:
136
+ | allFunctionNames // show all options
137
+ | (functionName extends allFunctionNames ? functionName : never) // infer value
138
+ args?:
139
+ | allArgs // show all options
140
+ | (args extends allArgs ? Widen<args> : never) // infer value, widen inferred value of `args` conditionally to match `allArgs`
141
+ | undefined
142
+ } & UnionEvaluate<
143
+ readonly [] extends allArgs
144
+ ? {
145
+ args?:
146
+ | allArgs // show all options
147
+ | (args extends allArgs ? Widen<args> : never) // infer value, widen inferred value of `args` conditionally to match `allArgs`
148
+ | undefined
149
+ }
150
+ : {
151
+ args:
152
+ | allArgs // show all options
153
+ | (Widen<args> & (args extends allArgs ? unknown : never)) // infer value, widen inferred value of `args` match `allArgs` (e.g. avoid union `args: readonly [123n] | readonly [bigint]`)
154
+ }
155
+ >
153
156
 
154
157
  export type ContractFunctionReturnType<
155
158
  abi extends Abi | readonly unknown[] = Abi,
@@ -186,78 +189,6 @@ export type AbiItem = Abi[number]
186
189
 
187
190
  export type EventDefinition = `${string}(${string})`
188
191
 
189
- export type ContractParameters<
190
- abi extends Abi | readonly unknown[] = readonly unknown[],
191
- stateMutability extends AbiStateMutability = AbiStateMutability,
192
- functionName extends ExtractAbiFunctionNames<
193
- abi extends Abi ? abi : Abi,
194
- stateMutability
195
- > = string,
196
- ///
197
- functionNames extends string = abi extends Abi
198
- ? ExtractAbiFunctionNames<abi, stateMutability>
199
- : string,
200
- abiFunction extends AbiFunction = abi extends Abi
201
- ? ExtractAbiFunction<
202
- abi,
203
- functionName extends functionNames ? functionName : functionNames, // fallback to all function names if `functionName` is invalid
204
- stateMutability
205
- >
206
- : AbiFunction,
207
- types = AbiParametersToPrimitiveTypes<abiFunction['inputs'], 'inputs'>,
208
- args =
209
- | types // show all values
210
- | (Abi extends abi ? readonly unknown[] | undefined : never) // `abi` declared as `Abi`
211
- | (readonly [] extends types ? undefined : never), // `abiFunction` has no inputs
212
- isArgsOptional extends boolean = Abi extends abi
213
- ? true
214
- : readonly [] extends types
215
- ? true
216
- : false,
217
- > = {
218
- abi: abi
219
- address: Address
220
- functionName:
221
- | functionNames // show all values
222
- | (functionName extends functionNames ? functionName : never) // validate `functionName`
223
- | ([functionNames] extends [never] ? string : never) // `abi` declared as `Abi`
224
- } & (isArgsOptional extends true ? { args?: args | undefined } : { args: args })
225
-
226
- export type ContractReturnType<
227
- abi extends Abi | readonly unknown[] = readonly unknown[],
228
- stateMutability extends AbiStateMutability = AbiStateMutability,
229
- functionName extends ExtractAbiFunctionNames<
230
- abi extends Abi ? abi : Abi,
231
- stateMutability
232
- > = string,
233
- ///
234
- abiFunction extends AbiFunction = abi extends Abi
235
- ? ExtractAbiFunction<abi, functionName, stateMutability>
236
- : AbiFunction,
237
- types = AbiParametersToPrimitiveTypes<abiFunction['outputs'], 'outputs'>,
238
- > = [abiFunction] extends [never]
239
- ? unknown // `abiFunction` was not inferrable (e.g. `abi` declared as `Abi`)
240
- : readonly unknown[] extends types
241
- ? unknown // `abiFunction` was not inferrable (e.g. `abi` not const asserted)
242
- : types extends readonly [] // unwrap `types`
243
- ? void // no outputs
244
- : types extends readonly [infer type]
245
- ? type // single output
246
- : types
247
-
248
- export type ContractFunctionConfig<
249
- TAbi extends Abi | readonly unknown[] = Abi,
250
- TFunctionName extends string = string,
251
- TAbiStateMutability extends AbiStateMutability = AbiStateMutability,
252
- > = {
253
- /** Contract ABI */
254
- abi: TAbi
255
- /** Contract address */
256
- address: Address
257
- /** Function to invoke on the contract */
258
- functionName: InferFunctionName<TAbi, TFunctionName, TAbiStateMutability>
259
- } & GetFunctionArgs<TAbi, TFunctionName>
260
-
261
192
  export type ContractFunctionResult<
262
193
  TAbi extends Abi | readonly unknown[] = Abi,
263
194
  TFunctionName extends string = string,
@@ -147,6 +147,8 @@ export type Prettify<T> = {
147
147
  [K in keyof T]: T[K]
148
148
  } & {}
149
149
 
150
+ export type UnionEvaluate<type> = type extends object ? Prettify<type> : type
151
+
150
152
  /**
151
153
  * @description Creates a type that extracts the values of T.
152
154
  *
@@ -188,3 +190,12 @@ export type MaybePartial<
188
190
  export type ExactPartial<type> = {
189
191
  [key in keyof type]?: type[key] | undefined
190
192
  }
193
+
194
+ export type OneOf<
195
+ union extends object,
196
+ ///
197
+ keys extends KeyofUnion<union> = KeyofUnion<union>,
198
+ > = union extends infer Item
199
+ ? Prettify<Item & { [K in Exclude<keys, keyof Item>]?: undefined }>
200
+ : never
201
+ type KeyofUnion<type> = type extends type ? keyof type : never