viem 2.0.0-beta.0 → 2.0.0-beta.2

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 (203) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/README.md +4 -0
  3. package/_cjs/actions/index.js.map +1 -1
  4. package/_cjs/actions/public/getBlockNumber.js +2 -2
  5. package/_cjs/actions/public/getBlockNumber.js.map +1 -1
  6. package/_cjs/actions/public/watchContractEvent.js +2 -1
  7. package/_cjs/actions/public/watchContractEvent.js.map +1 -1
  8. package/_cjs/chains/celo/formatters.js +23 -35
  9. package/_cjs/chains/celo/formatters.js.map +1 -1
  10. package/_cjs/chains/celo/serializers.js +20 -38
  11. package/_cjs/chains/celo/serializers.js.map +1 -1
  12. package/_cjs/chains/celo/utils.js +44 -0
  13. package/_cjs/chains/celo/utils.js.map +1 -0
  14. package/_cjs/chains/definitions/astar.js +29 -0
  15. package/_cjs/chains/definitions/astar.js.map +1 -0
  16. package/_cjs/chains/definitions/gnosis.js +4 -1
  17. package/_cjs/chains/definitions/gnosis.js.map +1 -1
  18. package/_cjs/chains/definitions/gnosisChiado.js +10 -1
  19. package/_cjs/chains/definitions/gnosisChiado.js.map +1 -1
  20. package/_cjs/chains/definitions/kava.js +29 -0
  21. package/_cjs/chains/definitions/kava.js.map +1 -0
  22. package/_cjs/chains/definitions/kavaTestnet.js +32 -0
  23. package/_cjs/chains/definitions/kavaTestnet.js.map +1 -0
  24. package/_cjs/chains/definitions/neonDevnet.js +1 -1
  25. package/_cjs/chains/definitions/neonDevnet.js.map +1 -1
  26. package/_cjs/chains/definitions/neonMainnet.js +27 -0
  27. package/_cjs/chains/definitions/neonMainnet.js.map +1 -0
  28. package/_cjs/chains/definitions/scrollSepolia.js +0 -1
  29. package/_cjs/chains/definitions/scrollSepolia.js.map +1 -1
  30. package/_cjs/chains/definitions/tenet.js +23 -0
  31. package/_cjs/chains/definitions/tenet.js.map +1 -0
  32. package/_cjs/chains/index.js +14 -4
  33. package/_cjs/chains/index.js.map +1 -1
  34. package/_cjs/chains/zksync/formatters.js +6 -2
  35. package/_cjs/chains/zksync/formatters.js.map +1 -1
  36. package/_cjs/errors/contract.js +1 -1
  37. package/_cjs/errors/contract.js.map +1 -1
  38. package/_cjs/errors/encoding.js +1 -37
  39. package/_cjs/errors/encoding.js.map +1 -1
  40. package/_cjs/errors/estimateGas.js +1 -1
  41. package/_cjs/errors/estimateGas.js.map +1 -1
  42. package/_cjs/errors/node.js +11 -11
  43. package/_cjs/errors/node.js.map +1 -1
  44. package/_cjs/errors/rpc.js +18 -18
  45. package/_cjs/errors/rpc.js.map +1 -1
  46. package/_cjs/errors/transaction.js +1 -1
  47. package/_cjs/errors/transaction.js.map +1 -1
  48. package/_cjs/errors/version.js +1 -1
  49. package/_cjs/index.js +5 -9
  50. package/_cjs/index.js.map +1 -1
  51. package/_cjs/utils/hash/getFunctionSignature.js +9 -9
  52. package/_cjs/utils/hash/getFunctionSignature.js.map +1 -1
  53. package/_cjs/utils/hash/normalizeSignature.js +48 -0
  54. package/_cjs/utils/hash/normalizeSignature.js.map +1 -0
  55. package/_cjs/utils/index.js +3 -10
  56. package/_cjs/utils/index.js.map +1 -1
  57. package/_cjs/utils/transaction/serializeTransaction.js +14 -5
  58. package/_cjs/utils/transaction/serializeTransaction.js.map +1 -1
  59. package/_esm/actions/index.js.map +1 -1
  60. package/_esm/actions/public/getBlockNumber.js +2 -2
  61. package/_esm/actions/public/getBlockNumber.js.map +1 -1
  62. package/_esm/actions/public/watchContractEvent.js +2 -1
  63. package/_esm/actions/public/watchContractEvent.js.map +1 -1
  64. package/_esm/chains/celo/formatters.js +23 -35
  65. package/_esm/chains/celo/formatters.js.map +1 -1
  66. package/_esm/chains/celo/serializers.js +19 -44
  67. package/_esm/chains/celo/serializers.js.map +1 -1
  68. package/_esm/chains/celo/utils.js +39 -0
  69. package/_esm/chains/celo/utils.js.map +1 -0
  70. package/_esm/chains/definitions/astar.js +26 -0
  71. package/_esm/chains/definitions/astar.js.map +1 -0
  72. package/_esm/chains/definitions/gnosis.js +4 -1
  73. package/_esm/chains/definitions/gnosis.js.map +1 -1
  74. package/_esm/chains/definitions/gnosisChiado.js +10 -1
  75. package/_esm/chains/definitions/gnosisChiado.js.map +1 -1
  76. package/_esm/chains/definitions/kava.js +26 -0
  77. package/_esm/chains/definitions/kava.js.map +1 -0
  78. package/_esm/chains/definitions/kavaTestnet.js +29 -0
  79. package/_esm/chains/definitions/kavaTestnet.js.map +1 -0
  80. package/_esm/chains/definitions/neonDevnet.js +1 -1
  81. package/_esm/chains/definitions/neonDevnet.js.map +1 -1
  82. package/_esm/chains/definitions/neonMainnet.js +24 -0
  83. package/_esm/chains/definitions/neonMainnet.js.map +1 -0
  84. package/_esm/chains/definitions/scrollSepolia.js +0 -1
  85. package/_esm/chains/definitions/scrollSepolia.js.map +1 -1
  86. package/_esm/chains/definitions/tenet.js +20 -0
  87. package/_esm/chains/definitions/tenet.js.map +1 -0
  88. package/_esm/chains/index.js +5 -0
  89. package/_esm/chains/index.js.map +1 -1
  90. package/_esm/chains/zksync/formatters.js +6 -2
  91. package/_esm/chains/zksync/formatters.js.map +1 -1
  92. package/_esm/errors/contract.js +1 -1
  93. package/_esm/errors/contract.js.map +1 -1
  94. package/_esm/errors/encoding.js +0 -36
  95. package/_esm/errors/encoding.js.map +1 -1
  96. package/_esm/errors/estimateGas.js +1 -1
  97. package/_esm/errors/estimateGas.js.map +1 -1
  98. package/_esm/errors/node.js +11 -22
  99. package/_esm/errors/node.js.map +1 -1
  100. package/_esm/errors/rpc.js +18 -36
  101. package/_esm/errors/rpc.js.map +1 -1
  102. package/_esm/errors/transaction.js +1 -1
  103. package/_esm/errors/transaction.js.map +1 -1
  104. package/_esm/errors/version.js +1 -1
  105. package/_esm/index.js +2 -4
  106. package/_esm/index.js.map +1 -1
  107. package/_esm/utils/hash/getFunctionSignature.js +9 -9
  108. package/_esm/utils/hash/getFunctionSignature.js.map +1 -1
  109. package/_esm/utils/hash/normalizeSignature.js +51 -0
  110. package/_esm/utils/hash/normalizeSignature.js.map +1 -0
  111. package/_esm/utils/index.js +1 -7
  112. package/_esm/utils/index.js.map +1 -1
  113. package/_esm/utils/transaction/serializeTransaction.js +17 -5
  114. package/_esm/utils/transaction/serializeTransaction.js.map +1 -1
  115. package/_types/actions/index.d.ts +1 -5
  116. package/_types/actions/index.d.ts.map +1 -1
  117. package/_types/actions/public/getBlockNumber.d.ts +1 -3
  118. package/_types/actions/public/getBlockNumber.d.ts.map +1 -1
  119. package/_types/actions/public/watchContractEvent.d.ts.map +1 -1
  120. package/_types/chains/celo/formatters.d.ts +6 -6
  121. package/_types/chains/celo/formatters.d.ts.map +1 -1
  122. package/_types/chains/celo/serializers.d.ts +3 -2
  123. package/_types/chains/celo/serializers.d.ts.map +1 -1
  124. package/_types/chains/celo/types.d.ts +13 -9
  125. package/_types/chains/celo/types.d.ts.map +1 -1
  126. package/_types/chains/celo/utils.d.ts +7 -0
  127. package/_types/chains/celo/utils.d.ts.map +1 -0
  128. package/_types/chains/definitions/astar.d.ts +36 -0
  129. package/_types/chains/definitions/astar.d.ts.map +1 -0
  130. package/_types/chains/definitions/celo.d.ts +7 -7
  131. package/_types/chains/definitions/celoAlfajores.d.ts +7 -7
  132. package/_types/chains/definitions/celoCannoli.d.ts +7 -7
  133. package/_types/chains/definitions/gnosis.d.ts +1 -0
  134. package/_types/chains/definitions/gnosis.d.ts.map +1 -1
  135. package/_types/chains/definitions/gnosisChiado.d.ts +7 -8
  136. package/_types/chains/definitions/gnosisChiado.d.ts.map +1 -1
  137. package/_types/chains/definitions/kava.d.ts +36 -0
  138. package/_types/chains/definitions/kava.d.ts.map +1 -0
  139. package/_types/chains/definitions/kavaTestnet.d.ts +36 -0
  140. package/_types/chains/definitions/kavaTestnet.d.ts.map +1 -0
  141. package/_types/chains/definitions/neonDevnet.d.ts +1 -1
  142. package/_types/chains/definitions/neonMainnet.d.ts +31 -0
  143. package/_types/chains/definitions/neonMainnet.d.ts.map +1 -0
  144. package/_types/chains/definitions/scrollSepolia.d.ts +0 -1
  145. package/_types/chains/definitions/scrollSepolia.d.ts.map +1 -1
  146. package/_types/chains/definitions/tenet.d.ts +38 -0
  147. package/_types/chains/definitions/tenet.d.ts.map +1 -0
  148. package/_types/chains/index.d.ts +5 -0
  149. package/_types/chains/index.d.ts.map +1 -1
  150. package/_types/chains/zksync/formatters.d.ts.map +1 -1
  151. package/_types/chains/zksync/types.d.ts +7 -7
  152. package/_types/chains/zksync/types.d.ts.map +1 -1
  153. package/_types/errors/encoding.d.ts +0 -33
  154. package/_types/errors/encoding.d.ts.map +1 -1
  155. package/_types/errors/version.d.ts +1 -1
  156. package/_types/index.d.ts +5 -25
  157. package/_types/index.d.ts.map +1 -1
  158. package/_types/types/contract.d.ts +6 -6
  159. package/_types/types/contract.d.ts.map +1 -1
  160. package/_types/utils/hash/getFunctionSignature.d.ts +4 -5
  161. package/_types/utils/hash/getFunctionSignature.d.ts.map +1 -1
  162. package/_types/utils/hash/normalizeSignature.d.ts +6 -0
  163. package/_types/utils/hash/normalizeSignature.d.ts.map +1 -0
  164. package/_types/utils/index.d.ts +1 -7
  165. package/_types/utils/index.d.ts.map +1 -1
  166. package/actions/index.ts +0 -4
  167. package/actions/public/getBlockNumber.ts +2 -4
  168. package/actions/public/watchContractEvent.ts +2 -1
  169. package/chains/celo/formatters.ts +24 -37
  170. package/chains/celo/serializers.ts +23 -59
  171. package/chains/celo/types.ts +30 -21
  172. package/chains/celo/utils.ts +68 -0
  173. package/chains/definitions/astar.ts +26 -0
  174. package/chains/definitions/gnosis.ts +4 -1
  175. package/chains/definitions/gnosisChiado.ts +10 -1
  176. package/chains/definitions/kava.ts +26 -0
  177. package/chains/definitions/kavaTestnet.ts +29 -0
  178. package/chains/definitions/neonDevnet.ts +1 -1
  179. package/chains/definitions/neonMainnet.ts +24 -0
  180. package/chains/definitions/scrollSepolia.ts +0 -1
  181. package/chains/definitions/tenet.ts +20 -0
  182. package/chains/index.ts +5 -0
  183. package/chains/zksync/formatters.ts +6 -2
  184. package/chains/zksync/types.ts +7 -7
  185. package/errors/contract.ts +1 -1
  186. package/errors/encoding.ts +0 -43
  187. package/errors/estimateGas.ts +1 -1
  188. package/errors/transaction.ts +1 -1
  189. package/errors/version.ts +1 -1
  190. package/index.ts +0 -26
  191. package/package.json +2 -1
  192. package/types/contract.ts +4 -20
  193. package/utils/hash/getFunctionSignature.ts +11 -21
  194. package/utils/hash/normalizeSignature.ts +64 -0
  195. package/utils/index.ts +0 -15
  196. package/utils/transaction/serializeTransaction.ts +17 -4
  197. package/_cjs/utils/contract/extractFunctionParts.js +0 -31
  198. package/_cjs/utils/contract/extractFunctionParts.js.map +0 -1
  199. package/_esm/utils/contract/extractFunctionParts.js +0 -24
  200. package/_esm/utils/contract/extractFunctionParts.js.map +0 -1
  201. package/_types/utils/contract/extractFunctionParts.d.ts +0 -18
  202. package/_types/utils/contract/extractFunctionParts.d.ts.map +0 -1
  203. package/utils/contract/extractFunctionParts.ts +0 -37
@@ -22,20 +22,15 @@ import type {
22
22
  TransactionSerializedCIP42,
23
23
  TransactionSerializedCIP64,
24
24
  } from './types.js'
25
+ import { isCIP42, isCIP64, isEmpty, isPresent } from './utils.js'
25
26
 
26
27
  export const serializeTransactionCelo: SerializeTransactionFn<
27
- CeloTransactionSerializable
28
+ CeloTransactionSerializable | TransactionSerializable
28
29
  > = (tx, signature) => {
29
30
  if (isCIP64(tx)) {
30
- return serializeTransactionCIP64(
31
- tx as TransactionSerializableCIP64,
32
- signature,
33
- )
31
+ return serializeTransactionCIP64(tx, signature)
34
32
  } else if (isCIP42(tx)) {
35
- return serializeTransactionCIP42(
36
- tx as TransactionSerializableCIP42,
37
- signature,
38
- )
33
+ return serializeTransactionCIP42(tx, signature)
39
34
  } else {
40
35
  return serializeTransaction(tx as TransactionSerializable, signature)
41
36
  }
@@ -131,7 +126,7 @@ function serializeTransactionCIP64(
131
126
  value ? toHex(value) : '0x',
132
127
  data ?? '0x',
133
128
  serializeAccessList(accessList),
134
- feeCurrency ?? '0x',
129
+ feeCurrency!,
135
130
  ]
136
131
 
137
132
  if (signature) {
@@ -148,43 +143,8 @@ function serializeTransactionCIP64(
148
143
  ]) as SerializeTransactionCIP64ReturnType
149
144
  }
150
145
 
151
- //////////////////////////////////////////////////////////////////////////////
152
- // Utilities
153
-
154
- // process as CIP42 if any of these fields are present. realistically gatewayfee is not used but is part of spec
155
- function isCIP42(transaction: CeloTransactionSerializable): boolean {
156
- if (transaction.type === 'cip42') return true
157
- // if the type is defined as anything else, assume it is *not* cip42
158
- if (transaction.type) return false
159
-
160
- // if the type is undefined, check if the fields match the expectations for cip42
161
- return (
162
- 'maxFeePerGas' in transaction &&
163
- 'maxPriorityFeePerGas' in transaction &&
164
- ('feeCurrency' in transaction ||
165
- 'gatewayFee' in transaction ||
166
- 'gatewayFeeRecipient' in transaction)
167
- )
168
- }
169
-
170
- function isCIP64(transaction: CeloTransactionSerializable): boolean {
171
- if (transaction.type === 'cip64') return true
172
- // if the type is defined as anything else, assume it is *not* cip64
173
- if (transaction.type) return false
174
-
175
- // if the type is undefined, check if the fields match the expectations for cip64
176
- return (
177
- 'maxFeePerGas' in transaction &&
178
- 'maxPriorityFeePerGas' in transaction &&
179
- 'feeCurrency' in transaction &&
180
- !('gatewayFee' in transaction) &&
181
- !('gatewayFeeRecipient' in transaction)
182
- )
183
- }
184
-
185
- // maxFeePerGas must be less than 2^256 - 1: however writing like that caused exceptions to be raised
186
- const MAX_MAX_FEE_PER_GAS =
187
- 115792089237316195423570985008687907853269984665640564039457584007913129639935n
146
+ // maxFeePerGas must be less than 2^256 - 1
147
+ const MAX_MAX_FEE_PER_GAS = 2n ** 256n - 1n
188
148
 
189
149
  export function assertTransactionCIP42(
190
150
  transaction: TransactionSerializableCIP42,
@@ -206,32 +166,36 @@ export function assertTransactionCIP42(
206
166
  '`gasPrice` is not a valid CIP-42 Transaction attribute.',
207
167
  )
208
168
 
209
- if (maxFeePerGas && maxFeePerGas > MAX_MAX_FEE_PER_GAS)
169
+ if (isPresent(maxFeePerGas) && maxFeePerGas > MAX_MAX_FEE_PER_GAS)
210
170
  throw new FeeCapTooHighError({ maxFeePerGas })
211
171
 
212
172
  if (
213
- maxPriorityFeePerGas &&
214
- maxFeePerGas &&
173
+ isPresent(maxPriorityFeePerGas) &&
174
+ isPresent(maxFeePerGas) &&
215
175
  maxPriorityFeePerGas > maxFeePerGas
216
176
  )
217
177
  throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas })
218
178
 
219
179
  if (
220
- (gatewayFee && !gatewayFeeRecipient) ||
221
- (gatewayFeeRecipient && !gatewayFee)
180
+ (isPresent(gatewayFee) && isEmpty(gatewayFeeRecipient)) ||
181
+ (isPresent(gatewayFeeRecipient) && isEmpty(gatewayFee))
222
182
  ) {
223
183
  throw new BaseError(
224
184
  '`gatewayFee` and `gatewayFeeRecipient` must be provided together.',
225
185
  )
226
186
  }
227
187
 
228
- if (feeCurrency && !feeCurrency?.startsWith('0x')) {
188
+ if (isPresent(feeCurrency) && !isAddress(feeCurrency)) {
229
189
  throw new BaseError(
230
190
  '`feeCurrency` MUST be a token address for CIP-42 transactions.',
231
191
  )
232
192
  }
233
193
 
234
- if (!feeCurrency && !gatewayFeeRecipient) {
194
+ if (isPresent(gatewayFeeRecipient) && !isAddress(gatewayFeeRecipient)) {
195
+ throw new InvalidAddressError(gatewayFeeRecipient)
196
+ }
197
+
198
+ if (isEmpty(feeCurrency) && isEmpty(gatewayFeeRecipient)) {
235
199
  throw new BaseError(
236
200
  'Either `feeCurrency` or `gatewayFeeRecipient` must be provided for CIP-42 transactions.',
237
201
  )
@@ -258,22 +222,22 @@ export function assertTransactionCIP64(
258
222
  '`gasPrice` is not a valid CIP-64 Transaction attribute.',
259
223
  )
260
224
 
261
- if (maxFeePerGas && maxFeePerGas > MAX_MAX_FEE_PER_GAS)
225
+ if (isPresent(maxFeePerGas) && maxFeePerGas > MAX_MAX_FEE_PER_GAS)
262
226
  throw new FeeCapTooHighError({ maxFeePerGas })
263
227
  if (
264
- maxPriorityFeePerGas &&
265
- maxFeePerGas &&
228
+ isPresent(maxPriorityFeePerGas) &&
229
+ isPresent(maxFeePerGas) &&
266
230
  maxPriorityFeePerGas > maxFeePerGas
267
231
  )
268
232
  throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas })
269
233
 
270
- if (feeCurrency && !feeCurrency?.startsWith('0x')) {
234
+ if (isPresent(feeCurrency) && !feeCurrency?.startsWith('0x')) {
271
235
  throw new BaseError(
272
236
  '`feeCurrency` MUST be a token address for CIP-64 transactions.',
273
237
  )
274
238
  }
275
239
 
276
- if (!feeCurrency) {
240
+ if (isEmpty(feeCurrency)) {
277
241
  throw new BaseError(
278
242
  '`feeCurrency` must be provided for CIP-64 transactions.',
279
243
  )
@@ -24,7 +24,6 @@ import type {
24
24
  TransactionSerialized,
25
25
  } from '../../types/transaction.js'
26
26
  import type { NeverBy } from '../../types/utils.js'
27
- import type { OptimismRpcTransaction } from '../optimism/types.js'
28
27
 
29
28
  type CeloBlockExclude =
30
29
  | 'difficulty'
@@ -66,7 +65,7 @@ export type CeloRpcBlock<
66
65
  RpcBlock<
67
66
  TBlockTag,
68
67
  TIncludeTransactions,
69
- OptimismRpcTransaction<TBlockTag extends 'pending' ? true : false>
68
+ RpcTransaction<TBlockTag extends 'pending' ? true : false>
70
69
  >,
71
70
  CeloBlockExclude
72
71
  > &
@@ -111,7 +110,7 @@ export type CeloTransactionRequest =
111
110
  export type CeloTransactionSerializable =
112
111
  | TransactionSerializableCIP42
113
112
  | TransactionSerializableCIP64
114
- | TransactionSerializable
113
+ | CeloTransactionSerializableBase
115
114
 
116
115
  export type CeloTransactionSerialized<
117
116
  TType extends CeloTransactionType = 'legacy',
@@ -135,21 +134,25 @@ type RpcTransactionRequest = RpcTransactionRequest_ & {
135
134
  gatewayFeeRecipient?: Address
136
135
  }
137
136
 
138
- export type RpcTransactionCIP42<TPending extends boolean = boolean> =
139
- TransactionBase<Quantity, Index, TPending> &
140
- FeeValuesEIP1559<Quantity> & {
141
- feeCurrency: Address | null
142
- gatewayFee: Hex | null
143
- gatewayFeeRecipient: Address | null
144
- type: '0x7c'
145
- }
137
+ export type RpcTransactionCIP42<TPending extends boolean = boolean> = Omit<
138
+ TransactionBase<Quantity, Index, TPending>,
139
+ 'typeHex'
140
+ > &
141
+ FeeValuesEIP1559<Quantity> & {
142
+ feeCurrency: Address | null
143
+ gatewayFee: Hex | null
144
+ gatewayFeeRecipient: Address | null
145
+ type: '0x7c'
146
+ }
146
147
 
147
- export type RpcTransactionCIP64<TPending extends boolean = boolean> =
148
- TransactionBase<Quantity, Index, TPending> &
149
- FeeValuesEIP1559<Quantity> & {
150
- feeCurrency: Address | null
151
- type: '0x7b'
152
- }
148
+ export type RpcTransactionCIP64<TPending extends boolean = boolean> = Omit<
149
+ TransactionBase<Quantity, Index, TPending>,
150
+ 'typeHex'
151
+ > &
152
+ FeeValuesEIP1559<Quantity> & {
153
+ feeCurrency: Address | null
154
+ type: '0x7b'
155
+ }
153
156
 
154
157
  export type RpcTransactionRequestCIP42 = TransactionRequestBase<
155
158
  Quantity,
@@ -231,9 +234,8 @@ export type TransactionSerializableCIP42<
231
234
  TQuantity = bigint,
232
235
  TIndex = number,
233
236
  > = TransactionSerializableBase<TQuantity, TIndex> &
234
- FeeValuesEIP1559<TQuantity> & {
237
+ Partial<FeeValuesEIP1559<TQuantity>> & {
235
238
  accessList?: AccessList
236
- gasPrice?: never
237
239
  feeCurrency?: Address
238
240
  gatewayFeeRecipient?: Address
239
241
  gatewayFee?: TQuantity
@@ -245,13 +247,20 @@ export type TransactionSerializableCIP64<
245
247
  TQuantity = bigint,
246
248
  TIndex = number,
247
249
  > = TransactionSerializableBase<TQuantity, TIndex> &
248
- FeeValuesEIP1559<TQuantity> & {
250
+ Partial<FeeValuesEIP1559<TQuantity>> & {
249
251
  accessList?: AccessList
250
- gasPrice?: never
251
252
  feeCurrency?: Address
253
+ gatewayFee?: undefined
254
+ gatewayFeeRecipient?: undefined
252
255
  chainId: number
253
256
  type?: 'cip64'
254
257
  }
255
258
 
259
+ export type CeloTransactionSerializableBase = TransactionSerializable & {
260
+ feeCurrency?: undefined
261
+ gatewayFee?: undefined
262
+ gatewayFeeRecipient?: undefined
263
+ }
264
+
256
265
  export type TransactionSerializedCIP42 = `0x7c${string}`
257
266
  export type TransactionSerializedCIP64 = `0x7b${string}`
@@ -0,0 +1,68 @@
1
+ import type { Address } from 'abitype'
2
+ import { trim } from '../../utils/data/trim.js'
3
+ import type {
4
+ CeloTransactionRequest,
5
+ CeloTransactionSerializable,
6
+ TransactionSerializableCIP42,
7
+ TransactionSerializableCIP64,
8
+ } from './types.js'
9
+
10
+ export function isEmpty(
11
+ value: string | undefined | number | BigInt,
12
+ ): value is undefined {
13
+ return (
14
+ value === 0 ||
15
+ value === 0n ||
16
+ value === undefined ||
17
+ value === null ||
18
+ value === '0' ||
19
+ value === '' ||
20
+ (typeof value === 'string' &&
21
+ (trim(value as Address).toLowerCase() === '0x' ||
22
+ trim(value as Address).toLowerCase() === '0x00'))
23
+ )
24
+ }
25
+
26
+ export function isPresent(
27
+ value: string | undefined | number | BigInt,
28
+ ): value is string | number | BigInt {
29
+ return !isEmpty(value)
30
+ }
31
+
32
+ export function isEIP1559(
33
+ transaction: CeloTransactionSerializable | CeloTransactionRequest,
34
+ ): boolean {
35
+ return (
36
+ isPresent(transaction.maxFeePerGas) &&
37
+ isPresent(transaction.maxPriorityFeePerGas)
38
+ )
39
+ }
40
+
41
+ // process as CIP42 if any of these fields are present. realistically gatewayfee is not used but is part of spec
42
+ export function isCIP42(
43
+ transaction: CeloTransactionSerializable | CeloTransactionRequest,
44
+ ): transaction is TransactionSerializableCIP42 {
45
+ // Enable end-user to force the tx to be considered as a cip42
46
+ if (transaction.type) return transaction.type === 'cip42'
47
+
48
+ return (
49
+ isEIP1559(transaction) &&
50
+ (isPresent(transaction.feeCurrency) ||
51
+ isPresent(transaction.gatewayFeeRecipient) ||
52
+ isPresent(transaction.gatewayFee))
53
+ )
54
+ }
55
+
56
+ export function isCIP64(
57
+ transaction: CeloTransactionSerializable | CeloTransactionRequest,
58
+ ): transaction is TransactionSerializableCIP64 {
59
+ // Enable end-user to force the tx to be considered as a cip64
60
+ if (transaction.type) return transaction.type === 'cip64'
61
+
62
+ return (
63
+ isEIP1559(transaction) &&
64
+ isPresent(transaction.feeCurrency) &&
65
+ isEmpty(transaction.gatewayFee) &&
66
+ isEmpty(transaction.gatewayFeeRecipient)
67
+ )
68
+ }
@@ -0,0 +1,26 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const astar = /*#__PURE__*/ defineChain({
4
+ id: 592,
5
+ name: 'Astar',
6
+ network: 'astar-mainnet',
7
+ nativeCurrency: {
8
+ name: 'Astar',
9
+ symbol: 'ASTR',
10
+ decimals: 18,
11
+ },
12
+ rpcUrls: {
13
+ public: { http: ['https://astar.api.onfinality.io/public'] },
14
+ default: { http: ['https://astar.api.onfinality.io/public'] },
15
+ },
16
+ blockExplorers: {
17
+ default: { name: 'Astar Subscan', url: 'https://astar.subscan.io' },
18
+ },
19
+ contracts: {
20
+ multicall3: {
21
+ address: '0xca11bde05977b3631167028862be2a173976ca11',
22
+ blockCreated: 761794,
23
+ },
24
+ },
25
+ testnet: false,
26
+ })
@@ -9,7 +9,10 @@ export const gnosis = /*#__PURE__*/ defineChain({
9
9
  symbol: 'xDAI',
10
10
  },
11
11
  rpcUrls: {
12
- default: { http: ['https://rpc.gnosischain.com'] },
12
+ default: {
13
+ http: ['https://rpc.gnosischain.com'],
14
+ webSocket: ['wss://rpc.gnosischain.com/wss'],
15
+ },
13
16
  },
14
17
  blockExplorers: {
15
18
  default: {
@@ -9,7 +9,10 @@ export const gnosisChiado = /*#__PURE__*/ defineChain({
9
9
  symbol: 'xDAI',
10
10
  },
11
11
  rpcUrls: {
12
- default: { http: ['https://rpc.chiadochain.net'] },
12
+ default: {
13
+ http: ['https://rpc.chiadochain.net'],
14
+ webSocket: ['wss://rpc.chiadochain.net/wss'],
15
+ },
13
16
  },
14
17
  blockExplorers: {
15
18
  default: {
@@ -17,5 +20,11 @@ export const gnosisChiado = /*#__PURE__*/ defineChain({
17
20
  url: 'https://blockscout.chiadochain.net',
18
21
  },
19
22
  },
23
+ contracts: {
24
+ multicall3: {
25
+ address: '0xcA11bde05977b3631167028862bE2a173976CA11',
26
+ blockCreated: 4967313,
27
+ },
28
+ },
20
29
  testnet: true,
21
30
  })
@@ -0,0 +1,26 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const kava = /*#__PURE__*/ defineChain({
4
+ id: 2222,
5
+ name: 'Kava EVM',
6
+ network: 'kava-mainnet',
7
+ nativeCurrency: {
8
+ name: 'Kava',
9
+ symbol: 'KAVA',
10
+ decimals: 18,
11
+ },
12
+ rpcUrls: {
13
+ public: { http: ['https://evm.kava.io'] },
14
+ default: { http: ['https://evm.kava.io'] },
15
+ },
16
+ blockExplorers: {
17
+ default: { name: 'Kava EVM Explorer', url: 'https://kavascan.com' },
18
+ },
19
+ contracts: {
20
+ multicall3: {
21
+ address: '0xca11bde05977b3631167028862be2a173976ca11',
22
+ blockCreated: 3661165,
23
+ },
24
+ },
25
+ testnet: false,
26
+ })
@@ -0,0 +1,29 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const kavaTestnet = /*#__PURE__*/ defineChain({
4
+ id: 2221,
5
+ name: 'Kava EVM Testnet',
6
+ network: 'kava-testnet',
7
+ nativeCurrency: {
8
+ name: 'Kava',
9
+ symbol: 'KAVA',
10
+ decimals: 18,
11
+ },
12
+ rpcUrls: {
13
+ public: { http: ['https://evm.testnet.kava.io'] },
14
+ default: { http: ['https://evm.testnet.kava.io'] },
15
+ },
16
+ blockExplorers: {
17
+ default: {
18
+ name: 'Kava EVM Testnet Explorer',
19
+ url: 'https://testnet.kavascan.com/',
20
+ },
21
+ },
22
+ contracts: {
23
+ multicall3: {
24
+ address: '0xDf1D724A7166261eEB015418fe8c7679BBEa7fd6',
25
+ blockCreated: 7242179,
26
+ },
27
+ },
28
+ testnet: true,
29
+ })
@@ -12,7 +12,7 @@ export const neonDevnet = /*#__PURE__*/ defineChain({
12
12
  blockExplorers: {
13
13
  default: {
14
14
  name: 'Neonscan',
15
- url: 'https://neonscan.org',
15
+ url: 'https://devnet.neonscan.org',
16
16
  },
17
17
  },
18
18
  contracts: {
@@ -0,0 +1,24 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const neonMainnet = /*#__PURE__*/ defineChain({
4
+ id: 245_022_934,
5
+ network: 'neonMainnet',
6
+ name: 'Neon EVM MainNet',
7
+ nativeCurrency: { name: 'NEON', symbol: 'NEON', decimals: 18 },
8
+ rpcUrls: {
9
+ default: {
10
+ http: ['https://neon-proxy-mainnet.solana.p2p.org'],
11
+ },
12
+ public: {
13
+ http: ['https://neon-proxy-mainnet.solana.p2p.org'],
14
+ },
15
+ },
16
+ blockExplorers: {
17
+ default: {
18
+ name: 'Neonscan',
19
+ url: 'https://neonscan.org',
20
+ },
21
+ },
22
+ contracts: {},
23
+ testnet: false,
24
+ })
@@ -7,7 +7,6 @@ export const scrollSepolia = /*#__PURE__*/ defineChain({
7
7
  rpcUrls: {
8
8
  default: {
9
9
  http: ['https://sepolia-rpc.scroll.io'],
10
- webSocket: ['wss://sepolia-rpc.scroll.io/ws'],
11
10
  },
12
11
  },
13
12
  blockExplorers: {
@@ -0,0 +1,20 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const tenet = /*#__PURE__*/ defineChain({
4
+ id: 1559,
5
+ name: 'Tenet',
6
+ network: 'tenet-mainnet',
7
+ nativeCurrency: {
8
+ name: 'TENET',
9
+ symbol: 'TENET',
10
+ decimals: 18,
11
+ },
12
+ rpcUrls: {
13
+ public: { http: ['https://rpc.tenet.org'] },
14
+ default: { http: ['https://rpc.tenet.org'] },
15
+ },
16
+ blockExplorers: {
17
+ default: { name: 'TenetScan Mainnet', url: 'https://tenetscan.io' },
18
+ },
19
+ testnet: false,
20
+ })
package/chains/index.ts CHANGED
@@ -6,6 +6,7 @@ export type { Assign, Omit, Prettify } from '../types/utils.js'
6
6
  export { arbitrum } from './definitions/arbitrum.js'
7
7
  export { arbitrumGoerli } from './definitions/arbitrumGoerli.js'
8
8
  export { arbitrumNova } from './definitions/arbitrumNova.js'
9
+ export { astar } from './definitions/astar.js'
9
10
  export { arbitrumSepolia } from './definitions/arbitrumSepolia.js'
10
11
  export { astarZkatana } from './definitions/astarZkatana.js'
11
12
  export { aurora } from './definitions/aurora.js'
@@ -66,6 +67,8 @@ export { harmonyOne } from './definitions/harmonyOne.js'
66
67
  export { haqqMainnet } from './definitions/haqqMainnet.js'
67
68
  export { haqqTestedge2 } from './definitions/haqqTestedge2.js'
68
69
  export { holesky } from './definitions/holesky.js'
70
+ export { kava } from './definitions/kava.js'
71
+ export { kavaTestnet } from './definitions/kavaTestnet.js'
69
72
  export { klaytn } from './definitions/klaytn.js'
70
73
  export { kroma } from './definitions/kroma.js'
71
74
  export { kromaSepolia } from './definitions/kromaSepolia.js'
@@ -89,6 +92,7 @@ export { moonbeam } from './definitions/moonbeam.js'
89
92
  export { moonbeamDev } from './definitions/moonbeamDev.js'
90
93
  export { moonriver } from './definitions/moonriver.js'
91
94
  export { neonDevnet } from './definitions/neonDevnet.js'
95
+ export { neonMainnet } from './definitions/neonMainnet.js'
92
96
  export { nexi } from './definitions/nexi.js'
93
97
  export { nexilix } from './definitions/nexilix.js'
94
98
  export { oasys } from './definitions/oasys.js'
@@ -141,6 +145,7 @@ export { taikoTestnetSepolia } from './definitions/taikoTestnetSepolia.js'
141
145
  export { taraxaTestnet } from './definitions/taraxaTestnet.js'
142
146
  export { telos } from './definitions/telos.js'
143
147
  export { telosTestnet } from './definitions/telosTestnet.js'
148
+ export { tenet } from './definitions/tenet.js'
144
149
  export { thunderTestnet } from './definitions/thunderTestnet.js'
145
150
  export { vechain } from './definitions/vechain.js'
146
151
  export { wanchain } from './definitions/wanchain.js'
@@ -40,8 +40,12 @@ export const formattersZkSync = {
40
40
  return formatted
41
41
  }) as Hash[] | ZkSyncTransaction[]
42
42
  return {
43
- l1BatchNumber: hexToBigInt(args.l1BatchNumber),
44
- l1BatchTimestamp: hexToBigInt(args.l1BatchTimestamp),
43
+ l1BatchNumber: args.l1BatchNumber
44
+ ? hexToBigInt(args.l1BatchNumber)
45
+ : null,
46
+ l1BatchTimestamp: args.l1BatchTimestamp
47
+ ? hexToBigInt(args.l1BatchTimestamp)
48
+ : null,
45
49
  transactions,
46
50
  }
47
51
  },
@@ -45,7 +45,7 @@ export type ZkSyncLog<
45
45
  ? TAbiEvent['name']
46
46
  : undefined,
47
47
  > = Log_<TQuantity, TIndex, TPending, TAbiEvent, TStrict, TAbi, TEventName> & {
48
- l1BatchNumber: TQuantity
48
+ l1BatchNumber: TQuantity | null
49
49
  transactionLogIndex: TIndex
50
50
  logType: Hex | null
51
51
  }
@@ -125,8 +125,8 @@ export type ZkSyncBlock<
125
125
  // Block (RPC)
126
126
 
127
127
  export type ZkSyncRpcBlockOverrides = {
128
- l1BatchNumber: Hex
129
- l1BatchTimestamp: Hex
128
+ l1BatchNumber: Hex | null
129
+ l1BatchTimestamp: Hex | null
130
130
  }
131
131
  export type ZkSyncRpcBlock<
132
132
  TBlockTag extends BlockTag = BlockTag,
@@ -178,8 +178,8 @@ export type ZkSyncTransaction<TPending extends boolean = boolean> =
178
178
  // Transaction (RPC)
179
179
 
180
180
  type RpcTransactionOverrides = {
181
- l1BatchNumber: Hex
182
- l1BatchTxIndex: Hex
181
+ l1BatchNumber: Hex | null
182
+ l1BatchTxIndex: Hex | null
183
183
  }
184
184
 
185
185
  type RpcTransactionLegacy<TPending extends boolean = boolean> =
@@ -269,8 +269,8 @@ export type ZkSyncTransactionType = TransactionType | 'eip712' | 'priority'
269
269
  // https://era.zksync.io/docs/api/js/types.html#transactionreceipt
270
270
 
271
271
  export type ZkSyncRpcTransactionReceiptOverrides = {
272
- l1BatchNumber: Hex
273
- l1BatchTxIndex: Hex
272
+ l1BatchNumber: Hex | null
273
+ l1BatchTxIndex: Hex | null
274
274
  logs: ZkSyncRpcLog[]
275
275
  l2ToL1Logs: ZkSyncRpcL2ToL1Log[]
276
276
  root: Hex
@@ -50,7 +50,7 @@ export class CallExecutionError extends BaseError {
50
50
  to,
51
51
  value:
52
52
  typeof value !== 'undefined' &&
53
- `${formatEther(value)} ${chain?.nativeCurrency.symbol || 'ETH'}`,
53
+ `${formatEther(value)} ${chain?.nativeCurrency?.symbol || 'ETH'}`,
54
54
  data,
55
55
  gas,
56
56
  gasPrice:
@@ -2,36 +2,6 @@ import type { ByteArray, Hex } from '../types/misc.js'
2
2
 
3
3
  import { BaseError } from './base.js'
4
4
 
5
- export type DataLengthTooLongErrorType = DataLengthTooLongError & {
6
- name: 'DataLengthTooLongError'
7
- }
8
- /** @deprecated */
9
- export class DataLengthTooLongError extends BaseError {
10
- override name = 'DataLengthTooLongError'
11
- constructor({ consumed, length }: { consumed: number; length: number }) {
12
- super(
13
- `Consumed bytes (${consumed}) is shorter than data length (${
14
- length - 1
15
- }).`,
16
- )
17
- }
18
- }
19
-
20
- export type DataLengthTooShortErrorType = DataLengthTooShortError & {
21
- name: 'DataLengthTooShortError'
22
- }
23
- /** @deprecated */
24
- export class DataLengthTooShortError extends BaseError {
25
- override name = 'DataLengthTooShortError'
26
- constructor({ length, dataLength }: { length: number; dataLength: number }) {
27
- super(
28
- `Data length (${dataLength - 1}) is shorter than consumed bytes length (${
29
- length - 1
30
- }).`,
31
- )
32
- }
33
- }
34
-
35
5
  export type IntegerOutOfRangeErrorType = IntegerOutOfRangeError & {
36
6
  name: 'IntegerOutOfRangeError'
37
7
  }
@@ -94,19 +64,6 @@ export class InvalidHexValueError extends BaseError {
94
64
  }
95
65
  }
96
66
 
97
- export type OffsetOutOfBoundsErrorType = OffsetOutOfBoundsError & {
98
- name: 'OffsetOutOfBoundsError'
99
- }
100
- /** @deprecated */
101
- export class OffsetOutOfBoundsError extends BaseError {
102
- override name = 'OffsetOutOfBoundsError' as const
103
- constructor({ nextOffset, offset }: { nextOffset: number; offset: number }) {
104
- super(
105
- `Next offset (${nextOffset}) is greater than previous offset + consumed bytes (${offset})`,
106
- )
107
- }
108
- }
109
-
110
67
  export type SizeOverflowErrorType = SizeOverflowError & {
111
68
  name: 'SizeOverflowError'
112
69
  }
@@ -40,7 +40,7 @@ export class EstimateGasExecutionError extends BaseError {
40
40
  to,
41
41
  value:
42
42
  typeof value !== 'undefined' &&
43
- `${formatEther(value)} ${chain?.nativeCurrency.symbol || 'ETH'}`,
43
+ `${formatEther(value)} ${chain?.nativeCurrency?.symbol || 'ETH'}`,
44
44
  data,
45
45
  gas,
46
46
  gasPrice: