viem 2.21.33 → 2.21.35

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/_cjs/actions/public/waitForTransactionReceipt.js +94 -91
  3. package/_cjs/actions/public/waitForTransactionReceipt.js.map +1 -1
  4. package/_cjs/chains/definitions/base.js +5 -0
  5. package/_cjs/chains/definitions/base.js.map +1 -1
  6. package/_cjs/chains/definitions/genesys.js +24 -0
  7. package/_cjs/chains/definitions/genesys.js.map +1 -0
  8. package/_cjs/chains/definitions/iota.js +6 -0
  9. package/_cjs/chains/definitions/iota.js.map +1 -1
  10. package/_cjs/chains/definitions/unichainSepolia.js +18 -0
  11. package/_cjs/chains/definitions/unichainSepolia.js.map +1 -1
  12. package/_cjs/chains/definitions/velas.js +22 -0
  13. package/_cjs/chains/definitions/velas.js.map +1 -0
  14. package/_cjs/chains/definitions/worldchain.js +38 -1
  15. package/_cjs/chains/definitions/worldchain.js.map +1 -1
  16. package/_cjs/chains/definitions/worldchainSepolia.js +37 -1
  17. package/_cjs/chains/definitions/worldchainSepolia.js.map +1 -1
  18. package/_cjs/chains/definitions/xdc.js +5 -5
  19. package/_cjs/chains/definitions/xdc.js.map +1 -1
  20. package/_cjs/chains/index.js +11 -7
  21. package/_cjs/chains/index.js.map +1 -1
  22. package/_cjs/errors/typedData.js +10 -1
  23. package/_cjs/errors/typedData.js.map +1 -1
  24. package/_cjs/errors/version.js +1 -1
  25. package/_cjs/index.js +5 -4
  26. package/_cjs/index.js.map +1 -1
  27. package/_cjs/linea/actions/estimateGas.js +1 -4
  28. package/_cjs/linea/actions/estimateGas.js.map +1 -1
  29. package/_cjs/op-stack/chains.js +7 -1
  30. package/_cjs/op-stack/chains.js.map +1 -1
  31. package/_cjs/utils/promise/createBatchScheduler.js +8 -11
  32. package/_cjs/utils/promise/createBatchScheduler.js.map +1 -1
  33. package/_cjs/utils/promise/withResolvers.js +13 -0
  34. package/_cjs/utils/promise/withResolvers.js.map +1 -0
  35. package/_cjs/utils/typedData.js +6 -2
  36. package/_cjs/utils/typedData.js.map +1 -1
  37. package/_esm/actions/public/waitForTransactionReceipt.js +109 -106
  38. package/_esm/actions/public/waitForTransactionReceipt.js.map +1 -1
  39. package/_esm/chains/definitions/base.js +5 -0
  40. package/_esm/chains/definitions/base.js.map +1 -1
  41. package/_esm/chains/definitions/genesys.js +21 -0
  42. package/_esm/chains/definitions/genesys.js.map +1 -0
  43. package/_esm/chains/definitions/iota.js +6 -0
  44. package/_esm/chains/definitions/iota.js.map +1 -1
  45. package/_esm/chains/definitions/unichainSepolia.js +18 -0
  46. package/_esm/chains/definitions/unichainSepolia.js.map +1 -1
  47. package/_esm/chains/definitions/velas.js +19 -0
  48. package/_esm/chains/definitions/velas.js.map +1 -0
  49. package/_esm/chains/definitions/worldchain.js +38 -1
  50. package/_esm/chains/definitions/worldchain.js.map +1 -1
  51. package/_esm/chains/definitions/worldchainSepolia.js +37 -1
  52. package/_esm/chains/definitions/worldchainSepolia.js.map +1 -1
  53. package/_esm/chains/definitions/xdc.js +5 -5
  54. package/_esm/chains/definitions/xdc.js.map +1 -1
  55. package/_esm/chains/index.js +2 -0
  56. package/_esm/chains/index.js.map +1 -1
  57. package/_esm/errors/typedData.js +8 -0
  58. package/_esm/errors/typedData.js.map +1 -1
  59. package/_esm/errors/version.js +1 -1
  60. package/_esm/index.js +1 -1
  61. package/_esm/index.js.map +1 -1
  62. package/_esm/linea/actions/estimateGas.js +1 -4
  63. package/_esm/linea/actions/estimateGas.js.map +1 -1
  64. package/_esm/op-stack/chains.js +3 -0
  65. package/_esm/op-stack/chains.js.map +1 -1
  66. package/_esm/utils/promise/createBatchScheduler.js +8 -11
  67. package/_esm/utils/promise/createBatchScheduler.js.map +1 -1
  68. package/_esm/utils/promise/withResolvers.js +11 -0
  69. package/_esm/utils/promise/withResolvers.js.map +1 -0
  70. package/_esm/utils/typedData.js +7 -3
  71. package/_esm/utils/typedData.js.map +1 -1
  72. package/_types/actions/public/waitForTransactionReceipt.d.ts.map +1 -1
  73. package/_types/chains/definitions/base.d.ts +5 -0
  74. package/_types/chains/definitions/base.d.ts.map +1 -1
  75. package/_types/chains/definitions/genesys.d.ts +37 -0
  76. package/_types/chains/definitions/genesys.d.ts.map +1 -0
  77. package/_types/chains/definitions/iota.d.ts +6 -10
  78. package/_types/chains/definitions/iota.d.ts.map +1 -1
  79. package/_types/chains/definitions/unichainSepolia.d.ts +267 -2
  80. package/_types/chains/definitions/unichainSepolia.d.ts.map +1 -1
  81. package/_types/chains/definitions/velas.d.ts +37 -0
  82. package/_types/chains/definitions/velas.d.ts.map +1 -0
  83. package/_types/chains/definitions/worldchain.d.ts +286 -14
  84. package/_types/chains/definitions/worldchain.d.ts.map +1 -1
  85. package/_types/chains/definitions/worldchainSepolia.d.ts +285 -14
  86. package/_types/chains/definitions/worldchainSepolia.d.ts.map +1 -1
  87. package/_types/chains/definitions/xdc.d.ts +5 -5
  88. package/_types/chains/index.d.ts +2 -0
  89. package/_types/chains/index.d.ts.map +1 -1
  90. package/_types/errors/typedData.d.ts +10 -0
  91. package/_types/errors/typedData.d.ts.map +1 -1
  92. package/_types/errors/version.d.ts +1 -1
  93. package/_types/index.d.ts +1 -1
  94. package/_types/index.d.ts.map +1 -1
  95. package/_types/linea/actions/estimateGas.d.ts.map +1 -1
  96. package/_types/op-stack/chains.d.ts +3 -0
  97. package/_types/op-stack/chains.d.ts.map +1 -1
  98. package/_types/utils/promise/createBatchScheduler.d.ts.map +1 -1
  99. package/_types/utils/promise/withResolvers.d.ts +9 -0
  100. package/_types/utils/promise/withResolvers.d.ts.map +1 -0
  101. package/_types/utils/typedData.d.ts.map +1 -1
  102. package/actions/public/waitForTransactionReceipt.ts +162 -156
  103. package/chains/definitions/base.ts +5 -0
  104. package/chains/definitions/genesys.ts +21 -0
  105. package/chains/definitions/iota.ts +6 -0
  106. package/chains/definitions/unichainSepolia.ts +18 -0
  107. package/chains/definitions/velas.ts +19 -0
  108. package/chains/definitions/worldchain.ts +39 -1
  109. package/chains/definitions/worldchainSepolia.ts +38 -1
  110. package/chains/definitions/xdc.ts +5 -5
  111. package/chains/index.ts +2 -0
  112. package/errors/typedData.ts +20 -0
  113. package/errors/version.ts +1 -1
  114. package/index.ts +2 -0
  115. package/linea/actions/estimateGas.ts +1 -11
  116. package/op-stack/chains.ts +3 -0
  117. package/package.json +1 -1
  118. package/utils/promise/createBatchScheduler.ts +12 -16
  119. package/utils/promise/withResolvers.ts +19 -0
  120. package/utils/typedData.ts +8 -2
package/chains/index.ts CHANGED
@@ -151,6 +151,7 @@ export { fuseSparknet } from './definitions/fuseSparknet.js'
151
151
  export { fusion } from './definitions/fusion.js'
152
152
  export { fusionTestnet } from './definitions/fusionTestnet.js'
153
153
  export { garnet } from './definitions/garnet.js'
154
+ export { genesys } from './definitions/genesys.js'
154
155
  export { gnosis } from './definitions/gnosis.js'
155
156
  export { gnosisChiado } from './definitions/gnosisChiado.js'
156
157
  export { gobi } from './definitions/gobi.js'
@@ -378,6 +379,7 @@ export { uniqueOpal } from './definitions/uniqueOpal.js'
378
379
  export { uniqueQuartz } from './definitions/uniqueQuartz.js'
379
380
  export { unreal } from './definitions/unreal.js'
380
381
  export { vechain } from './definitions/vechain.js'
382
+ export { velas } from './definitions/velas.js'
381
383
  export { viction } from './definitions/viction.js'
382
384
  export { victionTestnet } from './definitions/victionTestnet.js'
383
385
  export { vision } from './definitions/vision.js'
@@ -1,5 +1,25 @@
1
+ import type { TypedData } from 'abitype'
2
+
1
3
  import { BaseError } from './base.js'
2
4
 
5
+ export type InvalidPrimaryTypeErrorType = InvalidPrimaryTypeError & {
6
+ name: 'InvalidPrimaryTypeError'
7
+ }
8
+ export class InvalidPrimaryTypeError extends BaseError {
9
+ constructor({
10
+ primaryType,
11
+ types,
12
+ }: { primaryType: string; types: TypedData | Record<string, unknown> }) {
13
+ super(
14
+ `Invalid primary type \`${primaryType}\` must be one of \`${JSON.stringify(Object.keys(types))}\`.`,
15
+ {
16
+ docsPath: '/api/glossary/Errors#typeddatainvalidprimarytypeerror',
17
+ metaMessages: ['Check that the primary type is a key in `types`.'],
18
+ },
19
+ )
20
+ }
21
+ }
22
+
3
23
  export type InvalidStructTypeErrorType = InvalidStructTypeError & {
4
24
  name: 'InvalidStructTypeError'
5
25
  }
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.21.33'
1
+ export const version = '2.21.35'
package/index.ts CHANGED
@@ -918,6 +918,8 @@ export {
918
918
  type StateAssignmentConflictErrorType,
919
919
  } from './errors/stateOverride.js'
920
920
  export {
921
+ type InvalidPrimaryTypeErrorType,
922
+ InvalidPrimaryTypeError,
921
923
  type InvalidStructTypeErrorType,
922
924
  InvalidStructTypeError,
923
925
  } from './errors/typedData.js'
@@ -1,10 +1,6 @@
1
1
  import type { Account } from '../../accounts/types.js'
2
2
  import { parseAccount } from '../../accounts/utils/parseAccount.js'
3
3
  import type { EstimateGasParameters as EstimateGasParameters_base } from '../../actions/public/estimateGas.js'
4
- import {
5
- type PrepareTransactionRequestParameters,
6
- prepareTransactionRequest,
7
- } from '../../actions/wallet/prepareTransactionRequest.js'
8
4
  import type { Client } from '../../clients/createClient.js'
9
5
  import type { Transport } from '../../clients/transports/createTransport.js'
10
6
  import { AccountNotFoundError } from '../../errors/account.js'
@@ -82,13 +78,7 @@ export async function estimateGas<
82
78
  to,
83
79
  value,
84
80
  ...rest
85
- } =
86
- account?.type === 'local'
87
- ? ((await prepareTransactionRequest(
88
- client,
89
- args as PrepareTransactionRequestParameters,
90
- )) as EstimateGasParameters)
91
- : args
81
+ } = args
92
82
 
93
83
  const blockNumberHex = blockNumber ? numberToHex(blockNumber) : undefined
94
84
  const block = blockNumberHex || blockTag
@@ -16,6 +16,9 @@ export { shape } from '../chains/definitions/shape.js'
16
16
  export { snax } from '../chains/definitions/snax.js'
17
17
  export { snaxTestnet } from '../chains/definitions/snaxTestnet.js'
18
18
  export { soneiumMinato } from '../chains/definitions/soneiumMinato.js'
19
+ export { unichainSepolia } from '../chains/definitions/unichainSepolia.js'
20
+ export { worldchain } from '../chains/definitions/worldchain.js'
21
+ export { worldchainSepolia } from '../chains/definitions/worldchainSepolia.js'
19
22
  export { zora } from '../chains/definitions/zora.js'
20
23
  export { zoraSepolia } from '../chains/definitions/zoraSepolia.js'
21
24
  export { zoraTestnet } from '../chains/definitions/zoraTestnet.js'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.21.33",
4
+ "version": "2.21.35",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -1,17 +1,17 @@
1
1
  import type { ErrorType } from '../../errors/utils.js'
2
+ import { type PromiseWithResolvers, withResolvers } from './withResolvers.js'
2
3
 
3
4
  type Resolved<returnType extends readonly unknown[] = any> = [
4
5
  result: returnType[number],
5
6
  results: returnType,
6
7
  ]
7
8
 
8
- type PendingPromise<returnType extends readonly unknown[] = any> = {
9
- resolve?: ((data: Resolved<returnType>) => void) | undefined
10
- reject?: ((reason?: unknown) => void) | undefined
9
+ type SchedulerItem = {
10
+ args: unknown
11
+ resolve: PromiseWithResolvers<unknown>['resolve']
12
+ reject: PromiseWithResolvers<unknown>['reject']
11
13
  }
12
14
 
13
- type SchedulerItem = { args: unknown; pendingPromise: PendingPromise }
14
-
15
15
  type BatchResultsCompareFn<result = unknown> = (a: result, b: result) => number
16
16
 
17
17
  type CreateBatchSchedulerArguments<
@@ -65,14 +65,14 @@ export function createBatchScheduler<
65
65
  .then((data) => {
66
66
  if (sort && Array.isArray(data)) data.sort(sort)
67
67
  for (let i = 0; i < scheduler.length; i++) {
68
- const { pendingPromise } = scheduler[i]
69
- pendingPromise.resolve?.([data[i], data])
68
+ const { resolve } = scheduler[i]
69
+ resolve?.([data[i], data])
70
70
  }
71
71
  })
72
72
  .catch((err) => {
73
73
  for (let i = 0; i < scheduler.length; i++) {
74
- const { pendingPromise } = scheduler[i]
75
- pendingPromise.reject?.(err)
74
+ const { reject } = scheduler[i]
75
+ reject?.(err)
76
76
  }
77
77
  })
78
78
  }
@@ -90,11 +90,7 @@ export function createBatchScheduler<
90
90
  return {
91
91
  flush,
92
92
  async schedule(args: parameters) {
93
- const pendingPromise: PendingPromise<returnType> = {}
94
- const promise = new Promise<Resolved<returnType>>((resolve, reject) => {
95
- pendingPromise.resolve = resolve
96
- pendingPromise.reject = reject
97
- })
93
+ const { promise, resolve, reject } = withResolvers()
98
94
 
99
95
  const split = shouldSplitBatch?.([...getBatchedArgs(), args])
100
96
 
@@ -102,11 +98,11 @@ export function createBatchScheduler<
102
98
 
103
99
  const hasActiveScheduler = getScheduler().length > 0
104
100
  if (hasActiveScheduler) {
105
- setScheduler({ args, pendingPromise })
101
+ setScheduler({ args, resolve, reject })
106
102
  return promise
107
103
  }
108
104
 
109
- setScheduler({ args, pendingPromise })
105
+ setScheduler({ args, resolve, reject })
110
106
  setTimeout(exec, wait)
111
107
  return promise
112
108
  },
@@ -0,0 +1,19 @@
1
+ /** @internal */
2
+ export type PromiseWithResolvers<type> = {
3
+ promise: Promise<type>
4
+ resolve: (value: type | PromiseLike<type>) => void
5
+ reject: (reason?: unknown) => void
6
+ }
7
+
8
+ /** @internal */
9
+ export function withResolvers<type>(): PromiseWithResolvers<type> {
10
+ let resolve: PromiseWithResolvers<type>['resolve'] = () => undefined
11
+ let reject: PromiseWithResolvers<type>['reject'] = () => undefined
12
+
13
+ const promise = new Promise<type>((resolve_, reject_) => {
14
+ resolve = resolve_
15
+ reject = reject_
16
+ })
17
+
18
+ return { promise, resolve, reject }
19
+ }
@@ -2,7 +2,10 @@ import type { TypedData, TypedDataDomain, TypedDataParameter } from 'abitype'
2
2
 
3
3
  import { BytesSizeMismatchError } from '../errors/abi.js'
4
4
  import { InvalidAddressError } from '../errors/address.js'
5
- import { InvalidStructTypeError } from '../errors/typedData.js'
5
+ import {
6
+ InvalidPrimaryTypeError,
7
+ InvalidStructTypeError,
8
+ } from '../errors/typedData.js'
6
9
  import type { ErrorType } from '../errors/utils.js'
7
10
  import type { Hex } from '../types/misc.js'
8
11
  import type { TypedDataDefinition } from '../types/typedData.js'
@@ -121,7 +124,10 @@ export function validateTypedData<
121
124
  if (types.EIP712Domain && domain) validateData(types.EIP712Domain, domain)
122
125
 
123
126
  // Validate message types.
124
- if (primaryType !== 'EIP712Domain') validateData(types[primaryType], message)
127
+ if (primaryType !== 'EIP712Domain') {
128
+ if (types[primaryType]) validateData(types[primaryType], message)
129
+ else throw new InvalidPrimaryTypeError({ primaryType, types })
130
+ }
125
131
  }
126
132
 
127
133
  export type GetTypesForEIP712DomainErrorType = ErrorType