viem 2.0.3 → 2.0.5

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 (60) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/_cjs/actions/wallet/writeContract.js.map +1 -1
  3. package/_cjs/chains/definitions/taikoJolnir.js +7 -0
  4. package/_cjs/chains/definitions/taikoJolnir.js.map +1 -1
  5. package/_cjs/chains/definitions/taikoKatla.js +25 -0
  6. package/_cjs/chains/definitions/taikoKatla.js.map +1 -0
  7. package/_cjs/chains/index.js +3 -1
  8. package/_cjs/chains/index.js.map +1 -1
  9. package/_cjs/clients/transports/http.js +1 -1
  10. package/_cjs/clients/transports/http.js.map +1 -1
  11. package/_cjs/errors/abi.js +13 -1
  12. package/_cjs/errors/abi.js.map +1 -1
  13. package/_cjs/errors/version.js +1 -1
  14. package/_cjs/index.js +5 -3
  15. package/_cjs/index.js.map +1 -1
  16. package/_cjs/utils/abi/decodeAbiParameters.js +2 -0
  17. package/_cjs/utils/abi/decodeAbiParameters.js.map +1 -1
  18. package/_esm/actions/wallet/writeContract.js.map +1 -1
  19. package/_esm/chains/definitions/taikoJolnir.js +7 -0
  20. package/_esm/chains/definitions/taikoJolnir.js.map +1 -1
  21. package/_esm/chains/definitions/taikoKatla.js +22 -0
  22. package/_esm/chains/definitions/taikoKatla.js.map +1 -0
  23. package/_esm/chains/index.js +1 -0
  24. package/_esm/chains/index.js.map +1 -1
  25. package/_esm/clients/transports/http.js +1 -1
  26. package/_esm/clients/transports/http.js.map +1 -1
  27. package/_esm/errors/abi.js +11 -0
  28. package/_esm/errors/abi.js.map +1 -1
  29. package/_esm/errors/version.js +1 -1
  30. package/_esm/index.js +1 -0
  31. package/_esm/index.js.map +1 -1
  32. package/_esm/utils/abi/decodeAbiParameters.js +3 -1
  33. package/_esm/utils/abi/decodeAbiParameters.js.map +1 -1
  34. package/_types/actions/wallet/writeContract.d.ts +1 -1
  35. package/_types/actions/wallet/writeContract.d.ts.map +1 -1
  36. package/_types/chains/definitions/taikoJolnir.d.ts +7 -9
  37. package/_types/chains/definitions/taikoJolnir.d.ts.map +1 -1
  38. package/_types/chains/definitions/taikoKatla.d.ts +38 -0
  39. package/_types/chains/definitions/taikoKatla.d.ts.map +1 -0
  40. package/_types/chains/index.d.ts +1 -0
  41. package/_types/chains/index.d.ts.map +1 -1
  42. package/_types/errors/abi.d.ts +10 -0
  43. package/_types/errors/abi.d.ts.map +1 -1
  44. package/_types/errors/version.d.ts +1 -1
  45. package/_types/index.d.ts +1 -0
  46. package/_types/index.d.ts.map +1 -1
  47. package/_types/types/contract.d.ts +2 -1
  48. package/_types/types/contract.d.ts.map +1 -1
  49. package/_types/utils/abi/decodeAbiParameters.d.ts.map +1 -1
  50. package/actions/wallet/writeContract.ts +5 -1
  51. package/chains/definitions/taikoJolnir.ts +7 -0
  52. package/chains/definitions/taikoKatla.ts +22 -0
  53. package/chains/index.ts +1 -0
  54. package/clients/transports/http.ts +1 -1
  55. package/errors/abi.ts +13 -0
  56. package/errors/version.ts +1 -1
  57. package/index.ts +6 -0
  58. package/package.json +1 -1
  59. package/types/contract.ts +13 -12
  60. package/utils/abi/decodeAbiParameters.ts +4 -0
package/errors/abi.ts CHANGED
@@ -95,6 +95,19 @@ export class AbiDecodingDataSizeTooSmallError extends BaseError {
95
95
  }
96
96
  }
97
97
 
98
+ export type AbiDecodingOffsetOutOfBoundsErrorType =
99
+ AbiDecodingOffsetOutOfBoundsError & {
100
+ name: 'AbiDecodingOffsetOutOfBoundsError'
101
+ }
102
+ export class AbiDecodingOffsetOutOfBoundsError extends BaseError {
103
+ override name = 'AbiDecodingOffsetOutOfBoundsError'
104
+ constructor({ offset, position }: { offset: number; position: number }) {
105
+ super(
106
+ `Offset at "${offset}" is out-of-bounds (current position: "${position}").`,
107
+ )
108
+ }
109
+ }
110
+
98
111
  export type AbiDecodingZeroDataErrorType = AbiDecodingZeroDataError & {
99
112
  name: 'AbiDecodingZeroDataError'
100
113
  }
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.0.3'
1
+ export const version = '2.0.5'
package/index.ts CHANGED
@@ -1046,6 +1046,12 @@ export {
1046
1046
  type EncodeFunctionResultReturnType,
1047
1047
  encodeFunctionResult,
1048
1048
  } from './utils/abi/encodeFunctionResult.js'
1049
+ export {
1050
+ type ParseEventLogsErrorType,
1051
+ type ParseEventLogsParameters,
1052
+ type ParseEventLogsReturnType,
1053
+ parseEventLogs,
1054
+ } from './utils/abi/parseEventLogs.js'
1049
1055
  export {
1050
1056
  type FormattedTransaction,
1051
1057
  defineTransaction,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.0.3",
4
+ "version": "2.0.5",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
package/types/contract.ts CHANGED
@@ -168,21 +168,22 @@ export type ExtractAbiFunctionForArgs<
168
168
  ? IsUnion<abiFunction> extends true // narrow overloads using `args` by converting to tuple and filtering out overloads that don't match
169
169
  ? UnionToTuple<abiFunction> extends infer abiFunctions extends
170
170
  readonly AbiFunction[]
171
- ? {
172
- [k in keyof abiFunctions]: (
173
- readonly [] extends args
174
- ? readonly [] // fallback to `readonly []` if `args` has no value (e.g. `args` property not provided)
175
- : args
176
- ) extends AbiParametersToPrimitiveTypes<
177
- abiFunctions[k]['inputs'],
178
- 'inputs'
179
- >
180
- ? abiFunctions[k]
181
- : never
182
- }[number] // convert back to union (removes `never` tuple entries: `['foo', never, 'bar'][number]` => `'foo' | 'bar'`)
171
+ ? // convert back to union (removes `never` tuple entries)
172
+ { [k in keyof abiFunctions]: CheckArgs<abiFunctions[k], args> }[number]
183
173
  : never
184
174
  : abiFunction
185
175
  : never
176
+ type CheckArgs<
177
+ abiFunction extends AbiFunction,
178
+ args,
179
+ ///
180
+ targetArgs extends AbiParametersToPrimitiveTypes<
181
+ abiFunction['inputs'],
182
+ 'inputs'
183
+ > = AbiParametersToPrimitiveTypes<abiFunction['inputs'], 'inputs'>,
184
+ > = (readonly [] extends args ? readonly [] : args) extends targetArgs // fallback to `readonly []` if `args` has no value (e.g. `args` property not provided)
185
+ ? abiFunction
186
+ : never
186
187
 
187
188
  export type ContractFunctionParameters<
188
189
  abi extends Abi | readonly unknown[] = Abi,
@@ -7,6 +7,7 @@ import type {
7
7
  import {
8
8
  AbiDecodingDataSizeTooSmallError,
9
9
  type AbiDecodingDataSizeTooSmallErrorType,
10
+ AbiDecodingOffsetOutOfBoundsError,
10
11
  AbiDecodingZeroDataError,
11
12
  type AbiDecodingZeroDataErrorType,
12
13
  InvalidAbiDecodingTypeError,
@@ -185,6 +186,9 @@ function decodeArray<const TParam extends AbiParameter>(
185
186
  const offset = hexToNumber(
186
187
  slice(data, position, position + 32, { strict: true }),
187
188
  )
189
+ if (offset < position)
190
+ throw new AbiDecodingOffsetOutOfBoundsError({ offset, position })
191
+
188
192
  // Get the length of the array from the offset.
189
193
  const length = hexToNumber(
190
194
  slice(data, offset, offset + 32, { strict: true }),