viem 2.13.1 → 2.13.3

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/CHANGELOG.md +18 -0
  2. package/_cjs/chains/definitions/avalanche.js +3 -3
  3. package/_cjs/chains/definitions/avalanche.js.map +1 -1
  4. package/_cjs/chains/definitions/avalancheFuji.js +3 -3
  5. package/_cjs/chains/definitions/avalancheFuji.js.map +1 -1
  6. package/_cjs/chains/definitions/lycan.js +40 -0
  7. package/_cjs/chains/definitions/lycan.js.map +1 -0
  8. package/_cjs/chains/index.js +6 -4
  9. package/_cjs/chains/index.js.map +1 -1
  10. package/_cjs/errors/version.js +1 -1
  11. package/_cjs/experimental/eip5792/actions/writeContracts.js +2 -1
  12. package/_cjs/experimental/eip5792/actions/writeContracts.js.map +1 -1
  13. package/_cjs/experimental/index.js.map +1 -1
  14. package/_cjs/index.js.map +1 -1
  15. package/_cjs/utils/index.js.map +1 -1
  16. package/_esm/chains/definitions/avalanche.js +3 -3
  17. package/_esm/chains/definitions/avalanche.js.map +1 -1
  18. package/_esm/chains/definitions/avalancheFuji.js +3 -3
  19. package/_esm/chains/definitions/avalancheFuji.js.map +1 -1
  20. package/_esm/chains/definitions/lycan.js +37 -0
  21. package/_esm/chains/definitions/lycan.js.map +1 -0
  22. package/_esm/chains/index.js +1 -0
  23. package/_esm/chains/index.js.map +1 -1
  24. package/_esm/errors/version.js +1 -1
  25. package/_esm/experimental/eip5792/actions/writeContracts.js +2 -1
  26. package/_esm/experimental/eip5792/actions/writeContracts.js.map +1 -1
  27. package/_esm/experimental/index.js.map +1 -1
  28. package/_esm/index.js.map +1 -1
  29. package/_esm/utils/index.js.map +1 -1
  30. package/_types/chains/definitions/avalanche.d.ts +3 -3
  31. package/_types/chains/definitions/avalancheFuji.d.ts +3 -3
  32. package/_types/chains/definitions/lycan.d.ts +36 -0
  33. package/_types/chains/definitions/lycan.d.ts.map +1 -0
  34. package/_types/chains/index.d.ts +1 -0
  35. package/_types/chains/index.d.ts.map +1 -1
  36. package/_types/errors/version.d.ts +1 -1
  37. package/_types/experimental/eip5792/actions/writeContracts.d.ts +11 -3
  38. package/_types/experimental/eip5792/actions/writeContracts.d.ts.map +1 -1
  39. package/_types/experimental/index.d.ts +1 -1
  40. package/_types/experimental/index.d.ts.map +1 -1
  41. package/_types/index.d.ts +1 -1
  42. package/_types/index.d.ts.map +1 -1
  43. package/_types/types/contract.d.ts +1 -1
  44. package/_types/types/contract.d.ts.map +1 -1
  45. package/_types/utils/index.d.ts +1 -1
  46. package/_types/utils/index.d.ts.map +1 -1
  47. package/chains/definitions/avalanche.ts +3 -3
  48. package/chains/definitions/avalancheFuji.ts +3 -3
  49. package/chains/definitions/lycan.ts +37 -0
  50. package/chains/index.ts +1 -0
  51. package/errors/version.ts +1 -1
  52. package/experimental/eip5792/actions/writeContracts.ts +44 -5
  53. package/experimental/index.ts +1 -0
  54. package/index.ts +1 -0
  55. package/package.json +4 -3
  56. package/types/contract.ts +1 -3
  57. package/utils/index.ts +1 -0
@@ -1,16 +1,23 @@
1
- import type { AbiStateMutability, Narrow } from 'abitype'
1
+ import type { Abi, AbiStateMutability, Address, Narrow } from 'abitype'
2
2
 
3
3
  import type { Client } from '../../../clients/createClient.js'
4
4
  import type { Transport } from '../../../clients/transports/createTransport.js'
5
5
  import type { ErrorType } from '../../../errors/utils.js'
6
6
  import type { Account, GetAccountParameter } from '../../../types/account.js'
7
7
  import type { Chain, GetChainParameter } from '../../../types/chain.js'
8
- import type { ContractFunctionParameters } from '../../../types/contract.js'
8
+ import type {
9
+ ContractFunctionArgs,
10
+ ContractFunctionName,
11
+ GetValue,
12
+ UnionWiden,
13
+ Widen,
14
+ } from '../../../types/contract.js'
9
15
  import type { MulticallContracts } from '../../../types/multicall.js'
10
16
  import {
11
17
  type EncodeFunctionDataErrorType,
12
18
  encodeFunctionData,
13
19
  } from '../../../utils/abi/encodeFunctionData.js'
20
+ import { getAction } from '../../../utils/getAction.js'
14
21
  import {
15
22
  type SendCallsErrorType,
16
23
  type SendCallsParameters,
@@ -19,7 +26,8 @@ import {
19
26
  } from './sendCalls.js'
20
27
 
21
28
  export type WriteContractsParameters<
22
- contracts extends readonly unknown[] = readonly ContractFunctionParameters[],
29
+ contracts extends
30
+ readonly unknown[] = readonly WriteContractFunctionParameters[],
23
31
  chain extends Chain | undefined = Chain | undefined,
24
32
  account extends Account | undefined = Account | undefined,
25
33
  chainOverride extends Chain | undefined = Chain | undefined,
@@ -98,7 +106,7 @@ export async function writeContracts<
98
106
  chainOverride
99
107
  >,
100
108
  ): Promise<WriteContractsReturnType> {
101
- const contracts = parameters.contracts as ContractFunctionParameters[]
109
+ const contracts = parameters.contracts as WriteContractFunctionParameters[]
102
110
  const calls = contracts.map((contract) => {
103
111
  const { address, abi, functionName, args, value } = contract
104
112
  return {
@@ -111,5 +119,36 @@ export async function writeContracts<
111
119
  value,
112
120
  } satisfies SendCallsParameters['calls'][number]
113
121
  })
114
- return sendCalls(client, { ...parameters, calls } as SendCallsParameters)
122
+ return getAction(
123
+ client,
124
+ sendCalls,
125
+ 'sendCalls',
126
+ )({ ...parameters, calls } as SendCallsParameters)
115
127
  }
128
+
129
+ export type WriteContractFunctionParameters<
130
+ abi extends Abi | readonly unknown[] = Abi,
131
+ mutability extends AbiStateMutability = AbiStateMutability,
132
+ functionName extends ContractFunctionName<
133
+ abi,
134
+ mutability
135
+ > = ContractFunctionName<abi, mutability>,
136
+ args extends ContractFunctionArgs<
137
+ abi,
138
+ mutability,
139
+ functionName
140
+ > = ContractFunctionArgs<abi, mutability, functionName>,
141
+ ///
142
+ allFunctionNames = ContractFunctionName<abi, mutability>,
143
+ allArgs = ContractFunctionArgs<abi, mutability, functionName>,
144
+ // when `args` is inferred to `readonly []` ("inputs": []) or `never` (`abi` declared as `Abi` or not inferrable), allow `args` to be optional.
145
+ // important that both branches return same structural type
146
+ > = {
147
+ address: Address
148
+ abi: abi
149
+ functionName:
150
+ | allFunctionNames // show all options
151
+ | (functionName extends allFunctionNames ? functionName : never) // infer value
152
+ args?: (abi extends Abi ? UnionWiden<args> : never) | allArgs | undefined
153
+ } & (readonly [] extends allArgs ? {} : { args: Widen<args> }) &
154
+ GetValue<abi, functionName>
@@ -27,6 +27,7 @@ export {
27
27
  type WriteContractsErrorType,
28
28
  type WriteContractsParameters,
29
29
  type WriteContractsReturnType,
30
+ type WriteContractFunctionParameters,
30
31
  writeContracts,
31
32
  } from './eip5792/actions/writeContracts.js'
32
33
  export {
package/index.ts CHANGED
@@ -1097,6 +1097,7 @@ export {
1097
1097
  export {
1098
1098
  type DecodeFunctionDataErrorType,
1099
1099
  type DecodeFunctionDataParameters,
1100
+ type DecodeFunctionDataReturnType,
1100
1101
  decodeFunctionData,
1101
1102
  } from './utils/abi/decodeFunctionData.js'
1102
1103
  export {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.13.1",
4
+ "version": "2.13.3",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -9,11 +9,12 @@
9
9
  "sideEffects": false,
10
10
  "files": [
11
11
  "*",
12
- "!**/*.tsbuildinfo",
12
+ "!**/*.bench.ts",
13
+ "!**/*.bench-d.ts",
13
14
  "!**/*.test.ts",
14
15
  "!**/*.test.ts.snap",
15
16
  "!**/*.test-d.ts",
16
- "!**/*.bench.ts",
17
+ "!**/*.tsbuildinfo",
17
18
  "!tsconfig.build.json",
18
19
  "!jsr.json"
19
20
  ],
package/types/contract.ts CHANGED
@@ -209,9 +209,7 @@ export type ContractFunctionParameters<
209
209
  | allFunctionNames // show all options
210
210
  | (functionName extends allFunctionNames ? functionName : never) // infer value
211
211
  args?: (abi extends Abi ? UnionWiden<args> : never) | allArgs | undefined
212
- } & (readonly [] extends allArgs ? {} : { args: Widen<args> }) &
213
- // TODO: Remove `GetValue` from here (should be applied to top-level type as separate utility)
214
- GetValue<abi, functionName>
212
+ } & (readonly [] extends allArgs ? {} : { args: Widen<args> })
215
213
 
216
214
  export type ContractFunctionReturnType<
217
215
  abi extends Abi | readonly unknown[] = Abi,
package/utils/index.ts CHANGED
@@ -86,6 +86,7 @@ export {
86
86
  export {
87
87
  type DecodeFunctionDataErrorType,
88
88
  type DecodeFunctionDataParameters,
89
+ type DecodeFunctionDataReturnType,
89
90
  decodeFunctionData,
90
91
  } from './abi/decodeFunctionData.js'
91
92
  export {