viem 1.9.2 → 1.9.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 (67) hide show
  1. package/README.md +6 -0
  2. package/chains/dist/cjs/celo/formatters.js +57 -0
  3. package/chains/dist/cjs/celo/formatters.js.map +1 -0
  4. package/chains/dist/cjs/celo/parsers.js +72 -0
  5. package/chains/dist/cjs/celo/parsers.js.map +1 -0
  6. package/chains/dist/cjs/celo/serializers.js +75 -0
  7. package/chains/dist/cjs/celo/serializers.js.map +1 -0
  8. package/chains/dist/cjs/celo/types.js +3 -0
  9. package/chains/dist/cjs/celo/types.js.map +1 -0
  10. package/chains/dist/cjs/index.js +135 -0
  11. package/chains/dist/cjs/index.js.map +1 -0
  12. package/chains/dist/cjs/optimism/fees.js +7 -0
  13. package/chains/dist/cjs/optimism/fees.js.map +1 -0
  14. package/chains/dist/cjs/optimism/formatters.js +51 -0
  15. package/chains/dist/cjs/optimism/formatters.js.map +1 -0
  16. package/chains/dist/cjs/optimism/types.js +3 -0
  17. package/chains/dist/cjs/optimism/types.js.map +1 -0
  18. package/chains/dist/cjs/types.js +3 -0
  19. package/chains/dist/cjs/types.js.map +1 -0
  20. package/chains/dist/cjs/utils.js +23 -0
  21. package/chains/dist/cjs/utils.js.map +1 -0
  22. package/chains/dist/tsconfig.build.tsbuildinfo +1 -0
  23. package/chains/tsconfig.tsbuildinfo +1 -0
  24. package/dist/cjs/actions/public/call.js +1 -1
  25. package/dist/cjs/actions/public/call.js.map +1 -1
  26. package/dist/cjs/actions/public/multicall.js +54 -31
  27. package/dist/cjs/actions/public/multicall.js.map +1 -1
  28. package/dist/cjs/chains/definitions/sepolia.js +5 -0
  29. package/dist/cjs/chains/definitions/sepolia.js.map +1 -1
  30. package/dist/cjs/errors/version.js +1 -1
  31. package/dist/cjs/utils/formatters/transaction.js +5 -5
  32. package/dist/cjs/utils/formatters/transaction.js.map +1 -1
  33. package/dist/cjs/utils/hash/getFunctionSelector.js.map +1 -1
  34. package/dist/cjs/utils/hash/hashFunction.js.map +1 -1
  35. package/dist/cjs/utils/signature/hexToSignature.js +1 -1
  36. package/dist/cjs/utils/signature/hexToSignature.js.map +1 -1
  37. package/dist/esm/actions/public/call.js +1 -1
  38. package/dist/esm/actions/public/call.js.map +1 -1
  39. package/dist/esm/actions/public/multicall.js +66 -31
  40. package/dist/esm/actions/public/multicall.js.map +1 -1
  41. package/dist/esm/chains/definitions/sepolia.js +5 -0
  42. package/dist/esm/chains/definitions/sepolia.js.map +1 -1
  43. package/dist/esm/errors/version.js +1 -1
  44. package/dist/esm/utils/formatters/transaction.js +5 -5
  45. package/dist/esm/utils/formatters/transaction.js.map +1 -1
  46. package/dist/esm/utils/hash/getFunctionSelector.js.map +1 -1
  47. package/dist/esm/utils/hash/hashFunction.js.map +1 -1
  48. package/dist/esm/utils/signature/hexToSignature.js +1 -1
  49. package/dist/esm/utils/signature/hexToSignature.js.map +1 -1
  50. package/dist/types/actions/public/multicall.d.ts.map +1 -1
  51. package/dist/types/chains/definitions/sepolia.d.ts +7 -0
  52. package/dist/types/chains/definitions/sepolia.d.ts.map +1 -1
  53. package/dist/types/errors/version.d.ts +1 -1
  54. package/dist/types/utils/hash/getEventSelector.d.ts +1 -1
  55. package/dist/types/utils/hash/getEventSelector.d.ts.map +1 -1
  56. package/dist/types/utils/hash/getFunctionSelector.d.ts.map +1 -1
  57. package/dist/types/utils/hash/hashFunction.d.ts.map +1 -1
  58. package/package.json +1 -1
  59. package/src/actions/public/call.ts +1 -1
  60. package/src/actions/public/multicall.ts +70 -31
  61. package/src/chains/definitions/sepolia.ts +5 -0
  62. package/src/errors/version.ts +1 -1
  63. package/src/utils/formatters/transaction.ts +5 -5
  64. package/src/utils/hash/getEventSelector.ts +1 -1
  65. package/src/utils/hash/getFunctionSelector.ts +1 -1
  66. package/src/utils/hash/hashFunction.ts +1 -1
  67. package/src/utils/signature/hexToSignature.ts +1 -1
@@ -4,7 +4,7 @@ import type { Client } from '../../clients/createClient.js'
4
4
  import type { Transport } from '../../clients/transports/createTransport.js'
5
5
  import { multicall3Abi } from '../../constants/abis.js'
6
6
  import { AbiDecodingZeroDataError } from '../../errors/abi.js'
7
- import type { BaseError } from '../../errors/base.js'
7
+ import { BaseError } from '../../errors/base.js'
8
8
  import { RawContractError } from '../../errors/contract.js'
9
9
  import type { Chain } from '../../types/chain.js'
10
10
  import type { ContractFunctionConfig } from '../../types/contract.js'
@@ -136,8 +136,16 @@ export async function multicall<
136
136
  functionName,
137
137
  } as unknown as EncodeFunctionDataParameters)
138
138
 
139
- currentChunkSize += callData.length
140
- if (batchSize > 0 && currentChunkSize > batchSize) {
139
+ currentChunkSize += (callData.length - 2) / 2
140
+ // Check to see if we need to create a new chunk.
141
+ if (
142
+ // Check if batching is enabled.
143
+ batchSize > 0 &&
144
+ // Check if the current size of the batch exceeds the size limit.
145
+ currentChunkSize > batchSize &&
146
+ // Check if the current chunk is not already empty.
147
+ chunkedCalls[currentChunk].length > 0
148
+ ) {
141
149
  currentChunk++
142
150
  currentChunkSize = (callData.length - 2) / 2
143
151
  chunkedCalls[currentChunk] = []
@@ -171,7 +179,7 @@ export async function multicall<
171
179
  }
172
180
  }
173
181
 
174
- const results = await Promise.all(
182
+ const aggregate3Results = await Promise.allSettled(
175
183
  chunkedCalls.map((calls) =>
176
184
  readContract(client, {
177
185
  abi: multicall3Abi,
@@ -184,33 +192,64 @@ export async function multicall<
184
192
  ),
185
193
  )
186
194
 
187
- const calls = chunkedCalls.flat()
195
+ const results = []
196
+ for (let i = 0; i < aggregate3Results.length; i++) {
197
+ const result = aggregate3Results[i]
188
198
 
189
- return results.flat().map(({ returnData, success }, i) => {
190
- const { callData } = calls[i]
191
- const { abi, address, functionName, args } = contracts[
192
- i
193
- ] as ContractFunctionConfig
194
- try {
195
- if (callData === '0x') throw new AbiDecodingZeroDataError()
196
- if (!success) throw new RawContractError({ data: returnData })
197
- const result = decodeFunctionResult({
198
- abi,
199
- args,
200
- data: returnData,
201
- functionName,
202
- })
203
- return allowFailure ? { result, status: 'success' } : result
204
- } catch (err) {
205
- const error = getContractError(err as BaseError, {
206
- abi,
207
- address,
208
- args,
209
- docsPath: '/docs/contract/multicall',
210
- functionName,
211
- })
212
- if (!allowFailure) throw error
213
- return { error, result: undefined, status: 'failure' }
199
+ // If an error occurred in a `readContract` invocation (ie. network error),
200
+ // then append the failure reason to each contract result.
201
+ if (result.status === 'rejected') {
202
+ if (!allowFailure) throw result.reason
203
+ for (let j = 0; j < chunkedCalls[i].length; j++) {
204
+ results.push({
205
+ status: 'failure',
206
+ error: result.reason,
207
+ result: undefined,
208
+ })
209
+ }
210
+ continue
211
+ }
212
+
213
+ // If the `readContract` call was successful, then decode the results.
214
+ const aggregate3Result = result.value
215
+ for (let j = 0; j < aggregate3Result.length; j++) {
216
+ // Extract the response from `readContract`
217
+ const { returnData, success } = aggregate3Result[j]
218
+
219
+ // Extract the request call data from the original call.
220
+ const { callData } = chunkedCalls[i][j]
221
+
222
+ // Extract the contract config for this call from the `contracts` argument
223
+ // for decoding.
224
+ const { abi, address, functionName, args } = contracts[
225
+ results.length
226
+ ] as ContractFunctionConfig
227
+
228
+ try {
229
+ if (callData === '0x') throw new AbiDecodingZeroDataError()
230
+ if (!success) throw new RawContractError({ data: returnData })
231
+ const result = decodeFunctionResult({
232
+ abi,
233
+ args,
234
+ data: returnData,
235
+ functionName,
236
+ })
237
+ results.push(allowFailure ? { result, status: 'success' } : result)
238
+ } catch (err) {
239
+ const error = getContractError(err as BaseError, {
240
+ abi,
241
+ address,
242
+ args,
243
+ docsPath: '/docs/contract/multicall',
244
+ functionName,
245
+ })
246
+ if (!allowFailure) throw error
247
+ results.push({ error, result: undefined, status: 'failure' })
248
+ }
214
249
  }
215
- }) as MulticallResults<TContracts, TAllowFailure>
250
+ }
251
+
252
+ if (results.length !== contracts.length)
253
+ throw new BaseError('multicall results mismatch')
254
+ return results as MulticallResults<TContracts, TAllowFailure>
216
255
  }
@@ -36,6 +36,11 @@ export const sepolia = /*#__PURE__*/ defineChain({
36
36
  address: '0xca11bde05977b3631167028862be2a173976ca11',
37
37
  blockCreated: 6507670,
38
38
  },
39
+ ensRegistry: { address: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e' },
40
+ ensUniversalResolver: {
41
+ address: '0x21B000Fd62a880b2125A61e36a284BB757b76025',
42
+ blockCreated: 3914906,
43
+ },
39
44
  },
40
45
  testnet: true,
41
46
  })
@@ -1 +1 @@
1
- export const version = '1.9.2'
1
+ export const version = '1.9.5'
@@ -68,13 +68,13 @@ export function formatTransaction(transaction: Partial<RpcTransaction>) {
68
68
  }
69
69
 
70
70
  if (transaction_.type === 'legacy') {
71
- delete transaction_['accessList']
72
- delete transaction_['maxFeePerGas']
73
- delete transaction_['maxPriorityFeePerGas']
71
+ delete transaction_.accessList
72
+ delete transaction_.maxFeePerGas
73
+ delete transaction_.maxPriorityFeePerGas
74
74
  }
75
75
  if (transaction_.type === 'eip2930') {
76
- delete transaction_['maxFeePerGas']
77
- delete transaction_['maxPriorityFeePerGas']
76
+ delete transaction_.maxFeePerGas
77
+ delete transaction_.maxPriorityFeePerGas
78
78
  }
79
79
  return transaction_ as Transaction
80
80
  }
@@ -1,5 +1,5 @@
1
- import type { EventDefinition } from '../../types/contract.js'
2
1
  import type { AbiEvent } from 'abitype'
2
+ import type { EventDefinition } from '../../types/contract.js'
3
3
 
4
4
  import { hashAbiItem, hashFunction } from './hashFunction.js'
5
5
 
@@ -1,5 +1,5 @@
1
- import { slice } from '../data/slice.js'
2
1
  import type { AbiFunction } from 'abitype'
2
+ import { slice } from '../data/slice.js'
3
3
 
4
4
  import { hashAbiItem, hashFunction } from './hashFunction.js'
5
5
 
@@ -1,10 +1,10 @@
1
+ import type { AbiEvent, AbiFunction } from 'abitype'
1
2
  import { formatAbiItem } from '../abi/formatAbiItem.js'
2
3
  import {
3
4
  extractFunctionName,
4
5
  extractFunctionParams,
5
6
  } from '../contract/extractFunctionParts.js'
6
7
  import { toBytes } from '../encoding/toBytes.js'
7
- import type { AbiEvent, AbiFunction } from 'abitype'
8
8
 
9
9
  import { keccak256 } from './keccak256.js'
10
10
 
@@ -16,5 +16,5 @@ import { numberToHex } from '../../utils/encoding/toHex.js'
16
16
  export function hexToSignature(signatureHex: Hex): Signature {
17
17
  const { r, s } = secp256k1.Signature.fromCompact(signatureHex.slice(2, 130))
18
18
  const v = BigInt(`0x${signatureHex.slice(130)}`)
19
- return { r: numberToHex(r), s: numberToHex(s), v }
19
+ return { r: numberToHex(r, { size: 32 }), s: numberToHex(s, { size: 32 }), v }
20
20
  }