viem 0.0.0-w-20230815171822 → 0.0.0-w-20230816153316

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 (33) hide show
  1. package/dist/cjs/actions/public/multicall.js +2 -2
  2. package/dist/cjs/actions/public/multicall.js.map +1 -1
  3. package/dist/cjs/actions/public/readContract.js +2 -1
  4. package/dist/cjs/actions/public/readContract.js.map +1 -1
  5. package/dist/cjs/actions/wallet/writeContract.js +2 -1
  6. package/dist/cjs/actions/wallet/writeContract.js.map +1 -1
  7. package/dist/cjs/index.js.map +1 -1
  8. package/dist/esm/actions/public/multicall.js +2 -2
  9. package/dist/esm/actions/public/multicall.js.map +1 -1
  10. package/dist/esm/actions/public/readContract.js +2 -1
  11. package/dist/esm/actions/public/readContract.js.map +1 -1
  12. package/dist/esm/actions/wallet/writeContract.js +2 -1
  13. package/dist/esm/actions/wallet/writeContract.js.map +1 -1
  14. package/dist/esm/index.js.map +1 -1
  15. package/dist/types/actions/public/multicall.d.ts +12 -9
  16. package/dist/types/actions/public/multicall.d.ts.map +1 -1
  17. package/dist/types/actions/public/readContract.d.ts +4 -4
  18. package/dist/types/actions/public/readContract.d.ts.map +1 -1
  19. package/dist/types/actions/wallet/writeContract.d.ts +4 -4
  20. package/dist/types/actions/wallet/writeContract.d.ts.map +1 -1
  21. package/dist/types/index.d.ts +2 -2
  22. package/dist/types/index.d.ts.map +1 -1
  23. package/dist/types/types/contract.d.ts +11 -0
  24. package/dist/types/types/contract.d.ts.map +1 -1
  25. package/dist/types/types/multicall.d.ts +35 -35
  26. package/dist/types/types/multicall.d.ts.map +1 -1
  27. package/package.json +1 -1
  28. package/src/actions/public/multicall.ts +30 -23
  29. package/src/actions/public/readContract.ts +19 -21
  30. package/src/actions/wallet/writeContract.ts +35 -37
  31. package/src/index.ts +3 -0
  32. package/src/types/contract.ts +55 -0
  33. package/src/types/multicall.ts +82 -76
@@ -1,108 +1,114 @@
1
- import type { Abi, ExtractAbiFunctionNames } from 'abitype'
1
+ import type { Abi, AbiStateMutability, ExtractAbiFunctionNames } from 'abitype'
2
2
 
3
- import type {
4
- ContractFunctionConfig,
5
- ContractFunctionResult,
6
- } from './contract.js'
3
+ import type { ContractParameters, ContractReturnType } from './contract.js'
7
4
 
5
+ // Avoid TS depth-limit error in case of large array literal
8
6
  type MAXIMUM_DEPTH = 20
9
7
 
10
8
  export type MulticallContract<
11
- TAbi extends Abi | readonly unknown[] = Abi | readonly unknown[],
12
- TFunctionName extends ExtractAbiFunctionNames<
13
- TAbi extends Abi ? TAbi : Abi,
14
- 'pure' | 'view'
9
+ abi extends Abi | readonly unknown[] = Abi | readonly unknown[],
10
+ stateMutability extends AbiStateMutability = AbiStateMutability,
11
+ functionName extends ExtractAbiFunctionNames<
12
+ abi extends Abi ? abi : Abi,
13
+ stateMutability
15
14
  > = string,
16
- > = { abi: TAbi; functionName: TFunctionName }
15
+ > = { abi: abi; functionName: functionName }
17
16
 
18
17
  export type MulticallContracts<
19
- TContracts extends readonly MulticallContract[],
20
- TProperties extends Record<string, any> = object,
21
- Result extends any[] = [],
22
- Depth extends readonly number[] = [],
23
- > = Depth['length'] extends MAXIMUM_DEPTH
24
- ? (ContractFunctionConfig & TProperties)[]
25
- : TContracts extends []
18
+ contracts extends readonly MulticallContract[],
19
+ properties extends Record<string, any> = object,
20
+ ///
21
+ result extends any[] = [],
22
+ depth extends readonly number[] = [],
23
+ > = depth['length'] extends MAXIMUM_DEPTH
24
+ ? (ContractParameters & properties)[]
25
+ : contracts extends []
26
26
  ? []
27
- : TContracts extends [infer Head extends MulticallContract]
27
+ : contracts extends [infer head extends MulticallContract]
28
28
  ? [
29
- ...Result,
30
- ContractFunctionConfig<Head['abi'], Head['functionName']> & TProperties,
29
+ ...result,
30
+ ContractParameters<head['abi'], 'pure' | 'view', head['functionName']> &
31
+ properties,
31
32
  ]
32
- : TContracts extends [
33
- infer Head extends MulticallContract,
34
- ...infer Tail extends readonly MulticallContract[],
33
+ : contracts extends [
34
+ infer head extends MulticallContract,
35
+ ...infer tail extends readonly MulticallContract[],
35
36
  ]
36
37
  ? MulticallContracts<
37
- [...Tail],
38
- TProperties,
38
+ [...tail],
39
+ properties,
39
40
  [
40
- ...Result,
41
- ContractFunctionConfig<Head['abi'], Head['functionName']> & TProperties,
41
+ ...result,
42
+ ContractParameters<head['abi'], 'pure' | 'view', head['functionName']> &
43
+ properties,
42
44
  ],
43
- [...Depth, 1]
45
+ [...depth, 1]
44
46
  >
45
- : unknown[] extends TContracts
46
- ? TContracts
47
- : // If `TContracts` is *some* array but we couldn't assign `unknown[]` to it, then it must hold some known/homogenous type!
47
+ : unknown[] extends contracts
48
+ ? contracts
49
+ : // If `contracts` is *some* array but we couldn't assign `unknown[]` to it, then it must hold some known/homogenous type!
48
50
  // use this to infer the param types in the case of Array.map() argument
49
- TContracts extends ContractFunctionConfig<infer TAbi, infer TFunctionName>[]
50
- ? (ContractFunctionConfig<TAbi, TFunctionName> & TProperties)[]
51
- : (ContractFunctionConfig & TProperties)[]
52
-
53
- export type MulticallResult<
54
- Result,
55
- TAllowFailure extends boolean = true,
56
- > = TAllowFailure extends true
57
- ?
58
- | {
59
- error?: undefined
60
- result: Result
61
- status: 'success'
62
- }
63
- | {
64
- error: Error
65
- result?: undefined
66
- status: 'failure'
67
- }
68
- : Result
51
+ contracts extends ContractParameters<infer abi, infer _, infer functionName>[]
52
+ ? (ContractParameters<abi, 'pure' | 'view', functionName> & properties)[]
53
+ : // Fallback
54
+ (ContractParameters & properties)[]
69
55
 
70
56
  export type MulticallResults<
71
- TContracts extends readonly MulticallContract[],
72
- TAllowFailure extends boolean = true,
73
- Result extends any[] = [],
74
- Depth extends readonly number[] = [],
75
- > = Depth['length'] extends MAXIMUM_DEPTH
76
- ? MulticallResult<ContractFunctionResult, TAllowFailure>[]
77
- : TContracts extends []
57
+ contracts extends readonly MulticallContract[],
58
+ allowFailure extends boolean = true,
59
+ ///
60
+ result extends any[] = [],
61
+ depth extends readonly number[] = [],
62
+ > = depth['length'] extends MAXIMUM_DEPTH
63
+ ? MulticallResult<ContractReturnType, allowFailure>[]
64
+ : contracts extends []
78
65
  ? []
79
- : TContracts extends [infer Head extends MulticallContract]
66
+ : contracts extends [infer head extends MulticallContract]
80
67
  ? [
81
- ...Result,
68
+ ...result,
82
69
  MulticallResult<
83
- ContractFunctionResult<Head['abi'], Head['functionName']>,
84
- TAllowFailure
70
+ ContractReturnType<head['abi'], 'pure' | 'view', head['functionName']>,
71
+ allowFailure
85
72
  >,
86
73
  ]
87
- : TContracts extends [
88
- infer Head extends MulticallContract,
89
- ...infer Tail extends readonly MulticallContract[],
74
+ : contracts extends [
75
+ infer head extends MulticallContract,
76
+ ...infer tail extends readonly MulticallContract[],
90
77
  ]
91
78
  ? MulticallResults<
92
- [...Tail],
93
- TAllowFailure,
79
+ [...tail],
80
+ allowFailure,
94
81
  [
95
- ...Result,
82
+ ...result,
96
83
  MulticallResult<
97
- ContractFunctionResult<Head['abi'], Head['functionName']>,
98
- TAllowFailure
84
+ ContractReturnType<
85
+ head['abi'],
86
+ 'pure' | 'view',
87
+ head['functionName']
88
+ >,
89
+ allowFailure
99
90
  >,
100
91
  ],
101
- [...Depth, 1]
92
+ [...depth, 1]
102
93
  >
103
- : TContracts extends ContractFunctionConfig<infer TAbi, infer TFunctionName>[]
104
- ? MulticallResult<
105
- ContractFunctionResult<TAbi, TFunctionName>,
106
- TAllowFailure
94
+ : contracts extends ContractParameters<
95
+ infer abi,
96
+ infer _,
97
+ infer functionName
98
+ >[]
99
+ ? // Dynamic-size (homogenous) UseQueryOptions array: map directly to array of results
100
+ MulticallResult<
101
+ ContractReturnType<abi, 'pure' | 'view', functionName>,
102
+ allowFailure
107
103
  >[]
108
- : MulticallResult<ContractFunctionResult, TAllowFailure>[]
104
+ : // Fallback
105
+ MulticallResult<ContractReturnType, allowFailure>[]
106
+
107
+ export type MulticallResult<
108
+ result,
109
+ allowFailure extends boolean = true,
110
+ > = allowFailure extends true
111
+ ?
112
+ | { error?: undefined; result: result; status: 'success' }
113
+ | { error: Error; result?: undefined; status: 'failure' }
114
+ : result