viem 2.22.23 → 2.23.1

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 (118) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/_cjs/actions/index.js +7 -4
  3. package/_cjs/actions/index.js.map +1 -1
  4. package/_cjs/actions/public/{simulate.js → simulateBlocks.js} +3 -3
  5. package/_cjs/actions/public/simulateBlocks.js.map +1 -0
  6. package/_cjs/actions/public/simulateCalls.js +221 -0
  7. package/_cjs/actions/public/simulateCalls.js.map +1 -0
  8. package/_cjs/chains/definitions/0g.js +22 -0
  9. package/_cjs/chains/definitions/0g.js.map +1 -0
  10. package/_cjs/chains/definitions/berachain.js +8 -0
  11. package/_cjs/chains/definitions/berachain.js.map +1 -1
  12. package/_cjs/chains/definitions/story.js +18 -0
  13. package/_cjs/chains/definitions/story.js.map +1 -0
  14. package/_cjs/chains/definitions/unichain.js +28 -0
  15. package/_cjs/chains/definitions/unichain.js.map +1 -0
  16. package/_cjs/chains/definitions/worldchainSepolia.js +1 -1
  17. package/_cjs/chains/definitions/worldchainSepolia.js.map +1 -1
  18. package/_cjs/chains/index.js +9 -3
  19. package/_cjs/chains/index.js.map +1 -1
  20. package/_cjs/clients/decorators/public.js +5 -2
  21. package/_cjs/clients/decorators/public.js.map +1 -1
  22. package/_cjs/clients/transports/createTransport.js +1 -0
  23. package/_cjs/clients/transports/createTransport.js.map +1 -1
  24. package/_cjs/clients/transports/fallback.js +11 -0
  25. package/_cjs/clients/transports/fallback.js.map +1 -1
  26. package/_cjs/constants/address.js +2 -1
  27. package/_cjs/constants/address.js.map +1 -1
  28. package/_cjs/errors/version.js +1 -1
  29. package/_cjs/errors/version.js.map +1 -1
  30. package/_cjs/experimental/eip5792/actions/sendCalls.js +0 -5
  31. package/_cjs/experimental/eip5792/actions/sendCalls.js.map +1 -1
  32. package/_cjs/index.js +10 -9
  33. package/_cjs/index.js.map +1 -1
  34. package/_esm/actions/index.js +4 -1
  35. package/_esm/actions/index.js.map +1 -1
  36. package/_esm/actions/public/{simulate.js → simulateBlocks.js} +4 -4
  37. package/_esm/actions/public/simulateBlocks.js.map +1 -0
  38. package/_esm/actions/public/simulateCalls.js +264 -0
  39. package/_esm/actions/public/simulateCalls.js.map +1 -0
  40. package/_esm/chains/definitions/0g.js +19 -0
  41. package/_esm/chains/definitions/0g.js.map +1 -0
  42. package/_esm/chains/definitions/berachain.js +8 -0
  43. package/_esm/chains/definitions/berachain.js.map +1 -1
  44. package/_esm/chains/definitions/story.js +15 -0
  45. package/_esm/chains/definitions/story.js.map +1 -0
  46. package/_esm/chains/definitions/unichain.js +25 -0
  47. package/_esm/chains/definitions/unichain.js.map +1 -0
  48. package/_esm/chains/definitions/worldchainSepolia.js +1 -1
  49. package/_esm/chains/definitions/worldchainSepolia.js.map +1 -1
  50. package/_esm/chains/index.js +3 -0
  51. package/_esm/chains/index.js.map +1 -1
  52. package/_esm/clients/decorators/public.js +5 -2
  53. package/_esm/clients/decorators/public.js.map +1 -1
  54. package/_esm/clients/transports/createTransport.js +1 -0
  55. package/_esm/clients/transports/createTransport.js.map +1 -1
  56. package/_esm/clients/transports/fallback.js +12 -0
  57. package/_esm/clients/transports/fallback.js.map +1 -1
  58. package/_esm/constants/address.js +1 -0
  59. package/_esm/constants/address.js.map +1 -1
  60. package/_esm/errors/version.js +1 -1
  61. package/_esm/errors/version.js.map +1 -1
  62. package/_esm/experimental/eip5792/actions/sendCalls.js +0 -5
  63. package/_esm/experimental/eip5792/actions/sendCalls.js.map +1 -1
  64. package/_esm/index.js +1 -1
  65. package/_esm/index.js.map +1 -1
  66. package/_types/actions/index.d.ts +10 -1
  67. package/_types/actions/index.d.ts.map +1 -1
  68. package/_types/actions/public/{simulate.d.ts → simulateBlocks.d.ts} +10 -10
  69. package/_types/actions/public/simulateBlocks.d.ts.map +1 -0
  70. package/_types/actions/public/simulateCalls.d.ts +89 -0
  71. package/_types/actions/public/simulateCalls.d.ts.map +1 -0
  72. package/_types/chains/definitions/0g.d.ts +37 -0
  73. package/_types/chains/definitions/0g.d.ts.map +1 -0
  74. package/_types/chains/definitions/berachain.d.ts +8 -0
  75. package/_types/chains/definitions/berachain.d.ts.map +1 -1
  76. package/_types/chains/definitions/story.d.ts +43 -0
  77. package/_types/chains/definitions/story.d.ts.map +1 -0
  78. package/_types/chains/definitions/unichain.d.ts +34 -0
  79. package/_types/chains/definitions/unichain.d.ts.map +1 -0
  80. package/_types/chains/definitions/worldchainSepolia.d.ts +1 -3
  81. package/_types/chains/definitions/worldchainSepolia.d.ts.map +1 -1
  82. package/_types/chains/index.d.ts +3 -0
  83. package/_types/chains/index.d.ts.map +1 -1
  84. package/_types/clients/decorators/public.d.ts +41 -3
  85. package/_types/clients/decorators/public.d.ts.map +1 -1
  86. package/_types/clients/transports/createTransport.d.ts.map +1 -1
  87. package/_types/clients/transports/fallback.d.ts.map +1 -1
  88. package/_types/constants/address.d.ts +1 -0
  89. package/_types/constants/address.d.ts.map +1 -1
  90. package/_types/errors/version.d.ts +1 -1
  91. package/_types/errors/version.d.ts.map +1 -1
  92. package/_types/experimental/eip5792/actions/sendCalls.d.ts +3 -29
  93. package/_types/experimental/eip5792/actions/sendCalls.d.ts.map +1 -1
  94. package/_types/index.d.ts +1 -1
  95. package/_types/index.d.ts.map +1 -1
  96. package/_types/utils/cursor.d.ts +3 -3
  97. package/_types/utils/cursor.d.ts.map +1 -1
  98. package/actions/index.ts +19 -5
  99. package/actions/public/{simulate.ts → simulateBlocks.ts} +12 -12
  100. package/actions/public/simulateCalls.ts +414 -0
  101. package/chains/definitions/0g.ts +19 -0
  102. package/chains/definitions/berachain.ts +8 -0
  103. package/chains/definitions/story.ts +15 -0
  104. package/chains/definitions/unichain.ts +25 -0
  105. package/chains/definitions/worldchainSepolia.ts +1 -1
  106. package/chains/index.ts +3 -0
  107. package/clients/decorators/public.ts +57 -9
  108. package/clients/transports/createTransport.ts +1 -0
  109. package/clients/transports/fallback.ts +12 -0
  110. package/constants/address.ts +3 -0
  111. package/errors/version.ts +1 -1
  112. package/experimental/eip5792/actions/sendCalls.ts +3 -82
  113. package/index.ts +1 -1
  114. package/package.json +1 -1
  115. package/utils/cursor.ts +2 -2
  116. package/_cjs/actions/public/simulate.js.map +0 -1
  117. package/_esm/actions/public/simulate.js.map +0 -1
  118. package/_types/actions/public/simulate.d.ts.map +0 -1
@@ -67,7 +67,7 @@ type CallExtraProperties = ExactPartial<
67
67
  account?: Account | Address | undefined
68
68
  }
69
69
 
70
- export type SimulateParameters<
70
+ export type SimulateBlocksParameters<
71
71
  calls extends readonly unknown[] = readonly unknown[],
72
72
  > = {
73
73
  /** Blocks to simulate. */
@@ -80,11 +80,11 @@ export type SimulateParameters<
80
80
  stateOverrides?: StateOverride | undefined
81
81
  }[]
82
82
  /** Whether to return the full transactions. */
83
- returnFullTransactions?: boolean
83
+ returnFullTransactions?: boolean | undefined
84
84
  /** Whether to trace transfers. */
85
- traceTransfers?: boolean
85
+ traceTransfers?: boolean | undefined
86
86
  /** Whether to enable validation mode. */
87
- validation?: boolean
87
+ validation?: boolean | undefined
88
88
  } & (
89
89
  | {
90
90
  /** The balance of the account at a block number. */
@@ -101,7 +101,7 @@ export type SimulateParameters<
101
101
  }
102
102
  )
103
103
 
104
- export type SimulateReturnType<
104
+ export type SimulateBlocksReturnType<
105
105
  calls extends readonly unknown[] = readonly unknown[],
106
106
  > = readonly (Block & {
107
107
  calls: MulticallResults<
@@ -119,7 +119,7 @@ export type SimulateReturnType<
119
119
  >
120
120
  })[]
121
121
 
122
- export type SimulateErrorType =
122
+ export type SimulateBlocksErrorType =
123
123
  | AssertRequestErrorType
124
124
  | DecodeFunctionResultErrorType
125
125
  | EncodeFunctionDataErrorType
@@ -171,16 +171,16 @@ export type SimulateErrorType =
171
171
  * ```
172
172
  *
173
173
  * @param client - Client to use.
174
- * @param parameters - {@link SimulateParameters}
175
- * @returns Simulated blocks. {@link SimulateReturnType}
174
+ * @param parameters - {@link SimulateBlocksParameters}
175
+ * @returns Simulated blocks. {@link SimulateBlocksReturnType}
176
176
  */
177
- export async function simulate<
177
+ export async function simulateBlocks<
178
178
  chain extends Chain | undefined,
179
179
  const calls extends readonly unknown[],
180
180
  >(
181
181
  client: Client<Transport, chain>,
182
- parameters: SimulateParameters<calls>,
183
- ): Promise<SimulateReturnType<calls>> {
182
+ parameters: SimulateBlocksParameters<calls>,
183
+ ): Promise<SimulateBlocksReturnType<calls>> {
184
184
  const {
185
185
  blockNumber,
186
186
  blockTag = 'latest',
@@ -281,7 +281,7 @@ export async function simulate<
281
281
  }),
282
282
  }
283
283
  }),
284
- })) as unknown as SimulateReturnType<calls>
284
+ })) as unknown as SimulateBlocksReturnType<calls>
285
285
  } catch (e) {
286
286
  const cause = e as BaseError
287
287
  const error = getNodeError(cause, {})
@@ -0,0 +1,414 @@
1
+ import type { AbiStateMutability, Address, Narrow } from 'abitype'
2
+ import * as AbiConstructor from 'ox/AbiConstructor'
3
+ import * as AbiFunction from 'ox/AbiFunction'
4
+
5
+ import { parseAccount } from '../../accounts/utils/parseAccount.js'
6
+ import type { Client } from '../../clients/createClient.js'
7
+ import type { Transport } from '../../clients/transports/createTransport.js'
8
+ import { ethAddress, zeroAddress } from '../../constants/address.js'
9
+ import { deploylessCallViaBytecodeBytecode } from '../../constants/contracts.js'
10
+ import { BaseError } from '../../errors/base.js'
11
+ import type { ErrorType } from '../../errors/utils.js'
12
+ import type { Account } from '../../types/account.js'
13
+ import type { Block } from '../../types/block.js'
14
+ import type { Call, Calls } from '../../types/calls.js'
15
+ import type { Chain } from '../../types/chain.js'
16
+ import type { Log } from '../../types/log.js'
17
+ import type { Hex } from '../../types/misc.js'
18
+ import type { MulticallResults } from '../../types/multicall.js'
19
+ import type { StateOverride } from '../../types/stateOverride.js'
20
+ import type { Mutable } from '../../types/utils.js'
21
+ import {
22
+ type EncodeFunctionDataErrorType,
23
+ encodeFunctionData,
24
+ } from '../../utils/abi/encodeFunctionData.js'
25
+ import { hexToBigInt } from '../../utils/index.js'
26
+ import {
27
+ type CreateAccessListErrorType,
28
+ createAccessList,
29
+ } from './createAccessList.js'
30
+ import {
31
+ type SimulateBlocksErrorType,
32
+ type SimulateBlocksParameters,
33
+ simulateBlocks,
34
+ } from './simulateBlocks.js'
35
+
36
+ const getBalanceCode =
37
+ '0x6080604052348015600e575f80fd5b5061016d8061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063f8b2cb4f1461002d575b5f80fd5b610047600480360381019061004291906100db565b61005d565b604051610054919061011e565b60405180910390f35b5f8173ffffffffffffffffffffffffffffffffffffffff16319050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6100aa82610081565b9050919050565b6100ba816100a0565b81146100c4575f80fd5b50565b5f813590506100d5816100b1565b92915050565b5f602082840312156100f0576100ef61007d565b5b5f6100fd848285016100c7565b91505092915050565b5f819050919050565b61011881610106565b82525050565b5f6020820190506101315f83018461010f565b9291505056fea26469706673582212203b9fe929fe995c7cf9887f0bdba8a36dd78e8b73f149b17d2d9ad7cd09d2dc6264736f6c634300081a0033'
38
+
39
+ export type SimulateCallsParameters<
40
+ calls extends readonly unknown[] = readonly unknown[],
41
+ account extends Account | Address | undefined = Account | Address | undefined,
42
+ > = Omit<SimulateBlocksParameters, 'blocks' | 'returnFullTransactions'> & {
43
+ /** Account attached to the calls (msg.sender). */
44
+ account?: account | undefined
45
+ /** Calls to simulate. */
46
+ calls: Calls<Narrow<calls>>
47
+ /** State overrides. */
48
+ stateOverrides?: StateOverride | undefined
49
+ /** Whether to trace asset changes. */
50
+ traceAssetChanges?: boolean | undefined
51
+ }
52
+
53
+ export type SimulateCallsReturnType<
54
+ calls extends readonly unknown[] = readonly unknown[],
55
+ > = {
56
+ /** Asset changes. */
57
+ assetChanges: readonly {
58
+ token: {
59
+ address: Address
60
+ decimals?: number | undefined
61
+ symbol?: string | undefined
62
+ }
63
+ value: { pre: bigint; post: bigint; diff: bigint }
64
+ }[]
65
+ /** Block results. */
66
+ block: Block
67
+ /** Call results. */
68
+ results: MulticallResults<
69
+ Narrow<calls>,
70
+ true,
71
+ {
72
+ extraProperties: {
73
+ data: Hex
74
+ gasUsed: bigint
75
+ logs?: Log[] | undefined
76
+ }
77
+ error: Error
78
+ mutability: AbiStateMutability
79
+ }
80
+ >
81
+ }
82
+
83
+ export type SimulateCallsErrorType =
84
+ | AbiFunction.encodeData.ErrorType
85
+ | AbiFunction.from.ErrorType
86
+ | CreateAccessListErrorType
87
+ | EncodeFunctionDataErrorType
88
+ | SimulateBlocksErrorType
89
+ | ErrorType
90
+
91
+ /**
92
+ * Simulates execution of a batch of calls.
93
+ *
94
+ * @param client - Client to use
95
+ * @param parameters - {@link SimulateCallsParameters}
96
+ * @returns Results. {@link SimulateCallsReturnType}
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * import { createPublicClient, http, parseEther } from 'viem'
101
+ * import { mainnet } from 'viem/chains'
102
+ * import { simulateCalls } from 'viem/actions'
103
+ *
104
+ * const client = createPublicClient({
105
+ * chain: mainnet,
106
+ * transport: http(),
107
+ * })
108
+ *
109
+ * const result = await simulateCalls(client, {
110
+ * account: '0x5a0b54d5dc17e482fe8b0bdca5320161b95fb929',
111
+ * calls: [{
112
+ * {
113
+ * data: '0xdeadbeef',
114
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
115
+ * },
116
+ * {
117
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
118
+ * value: parseEther('1'),
119
+ * },
120
+ * ]
121
+ * })
122
+ * ```
123
+ */
124
+ export async function simulateCalls<
125
+ const calls extends readonly unknown[],
126
+ chain extends Chain | undefined,
127
+ account extends Account | Address | undefined = undefined,
128
+ >(
129
+ client: Client<Transport, chain>,
130
+ parameters: SimulateCallsParameters<calls, account>,
131
+ ): Promise<SimulateCallsReturnType<calls>> {
132
+ const {
133
+ blockNumber,
134
+ blockTag,
135
+ calls,
136
+ stateOverrides,
137
+ traceAssetChanges,
138
+ traceTransfers,
139
+ validation,
140
+ } = parameters
141
+
142
+ const account = parameters.account
143
+ ? parseAccount(parameters.account)
144
+ : undefined
145
+
146
+ if (traceAssetChanges && !account)
147
+ throw new BaseError(
148
+ '`account` is required when `traceAssetChanges` is true',
149
+ )
150
+
151
+ // Derive bytecode to extract ETH balance via a contract call.
152
+ const getBalanceData = account
153
+ ? AbiConstructor.encode(AbiConstructor.from('constructor(bytes, bytes)'), {
154
+ bytecode: deploylessCallViaBytecodeBytecode,
155
+ args: [
156
+ getBalanceCode,
157
+ AbiFunction.encodeData(
158
+ AbiFunction.from('function getBalance(address)'),
159
+ [account.address],
160
+ ),
161
+ ],
162
+ })
163
+ : undefined
164
+
165
+ // Fetch ERC20/721 addresses that were "touched" from the calls.
166
+ const assetAddresses = traceAssetChanges
167
+ ? await Promise.all(
168
+ parameters.calls.map(async (call: any) => {
169
+ if (!call.data && !call.abi) return
170
+ const { accessList } = await createAccessList(client, {
171
+ account: account!.address,
172
+ ...call,
173
+ data: call.abi ? encodeFunctionData(call) : call.data,
174
+ })
175
+ return accessList.map(({ address, storageKeys }) =>
176
+ storageKeys.length > 0 ? address : null,
177
+ )
178
+ }),
179
+ ).then((x) => x.flat().filter(Boolean))
180
+ : []
181
+
182
+ const resultsStateOverrides = stateOverrides?.map((override) => {
183
+ if (override.address === account?.address)
184
+ return {
185
+ ...override,
186
+ nonce: 0,
187
+ }
188
+ return override
189
+ })
190
+
191
+ const blocks = await simulateBlocks(client, {
192
+ blockNumber,
193
+ blockTag: blockTag as undefined,
194
+ blocks: [
195
+ ...(traceAssetChanges
196
+ ? [
197
+ // ETH pre balances
198
+ {
199
+ calls: [{ data: getBalanceData }],
200
+ stateOverrides,
201
+ },
202
+
203
+ // Asset pre balances
204
+ {
205
+ calls: assetAddresses.map((address, i) => ({
206
+ abi: [
207
+ AbiFunction.from(
208
+ 'function balanceOf(address) returns (uint256)',
209
+ ),
210
+ ],
211
+ functionName: 'balanceOf',
212
+ args: [account!.address],
213
+ to: address,
214
+ from: zeroAddress,
215
+ nonce: i,
216
+ })),
217
+ stateOverrides: [
218
+ {
219
+ address: zeroAddress,
220
+ nonce: 0,
221
+ },
222
+ ],
223
+ },
224
+ ]
225
+ : []),
226
+
227
+ {
228
+ calls: [...calls, {}].map((call, index) => ({
229
+ ...(call as Call),
230
+ from: account?.address,
231
+ nonce: index,
232
+ })) as any,
233
+ stateOverrides: resultsStateOverrides,
234
+ },
235
+
236
+ ...(traceAssetChanges
237
+ ? [
238
+ // ETH post balances
239
+ {
240
+ calls: [{ data: getBalanceData }],
241
+ },
242
+
243
+ // Asset post balances
244
+ {
245
+ calls: assetAddresses.map((address, i) => ({
246
+ abi: [
247
+ AbiFunction.from(
248
+ 'function balanceOf(address) returns (uint256)',
249
+ ),
250
+ ],
251
+ functionName: 'balanceOf',
252
+ args: [account!.address],
253
+ to: address,
254
+ from: zeroAddress,
255
+ nonce: i,
256
+ })),
257
+ stateOverrides: [
258
+ {
259
+ address: zeroAddress,
260
+ nonce: 0,
261
+ },
262
+ ],
263
+ },
264
+
265
+ // Decimals
266
+ {
267
+ calls: assetAddresses.map((address, i) => ({
268
+ to: address,
269
+ abi: [
270
+ AbiFunction.from('function decimals() returns (uint256)'),
271
+ ],
272
+ functionName: 'decimals',
273
+ from: zeroAddress,
274
+ nonce: i,
275
+ })),
276
+ stateOverrides: [
277
+ {
278
+ address: zeroAddress,
279
+ nonce: 0,
280
+ },
281
+ ],
282
+ },
283
+
284
+ // Token URI
285
+ {
286
+ calls: assetAddresses.map((address, i) => ({
287
+ to: address,
288
+ abi: [
289
+ AbiFunction.from(
290
+ 'function tokenURI(uint256) returns (string)',
291
+ ),
292
+ ],
293
+ functionName: 'tokenURI',
294
+ args: [0n],
295
+ from: zeroAddress,
296
+ nonce: i,
297
+ })),
298
+ stateOverrides: [
299
+ {
300
+ address: zeroAddress,
301
+ nonce: 0,
302
+ },
303
+ ],
304
+ },
305
+
306
+ // Symbols
307
+ {
308
+ calls: assetAddresses.map((address, i) => ({
309
+ to: address,
310
+ abi: [AbiFunction.from('function symbol() returns (string)')],
311
+ functionName: 'symbol',
312
+ from: zeroAddress,
313
+ nonce: i,
314
+ })),
315
+ stateOverrides: [
316
+ {
317
+ address: zeroAddress,
318
+ nonce: 0,
319
+ },
320
+ ],
321
+ },
322
+ ]
323
+ : []),
324
+ ],
325
+ traceTransfers,
326
+ validation,
327
+ })
328
+
329
+ const block_results = traceAssetChanges ? blocks[2] : blocks[0]
330
+ const [
331
+ block_ethPre,
332
+ block_assetsPre,
333
+ ,
334
+ block_ethPost,
335
+ block_assetsPost,
336
+ block_decimals,
337
+ block_tokenURI,
338
+ block_symbols,
339
+ ] = traceAssetChanges ? blocks : []
340
+
341
+ // Extract call results from the simulation.
342
+ const { calls: block_calls, ...block } = block_results
343
+ const results = block_calls.slice(0, -1) ?? []
344
+
345
+ // Extract pre-execution ETH and asset balances.
346
+ const ethPre = block_ethPre?.calls ?? []
347
+ const assetsPre = block_assetsPre?.calls ?? []
348
+ const balancesPre = [...ethPre, ...assetsPre].map((call) =>
349
+ call.status === 'success' ? hexToBigInt(call.data) : null,
350
+ )
351
+
352
+ // Extract post-execution ETH and asset balances.
353
+ const ethPost = block_ethPost?.calls ?? []
354
+ const assetsPost = block_assetsPost?.calls ?? []
355
+ const balancesPost = [...ethPost, ...assetsPost].map((call) =>
356
+ call.status === 'success' ? hexToBigInt(call.data) : null,
357
+ )
358
+
359
+ // Extract asset symbols & decimals.
360
+ const decimals = (block_decimals?.calls ?? []).map((x) =>
361
+ x.status === 'success' ? x.result : null,
362
+ ) as (number | null)[]
363
+ const symbols = (block_symbols?.calls ?? []).map((x) =>
364
+ x.status === 'success' ? x.result : null,
365
+ ) as (string | null)[]
366
+ const tokenURI = (block_tokenURI?.calls ?? []).map((x) =>
367
+ x.status === 'success' ? x.result : null,
368
+ ) as (string | null)[]
369
+
370
+ const changes: Mutable<SimulateCallsReturnType<calls>['assetChanges']> = []
371
+ for (const [i, balancePost] of balancesPost.entries()) {
372
+ const balancePre = balancesPre[i]
373
+
374
+ if (typeof balancePost !== 'bigint') continue
375
+ if (typeof balancePre !== 'bigint') continue
376
+
377
+ const decimals_ = decimals[i - 1]
378
+ const symbol_ = symbols[i - 1]
379
+ const tokenURI_ = tokenURI[i - 1]
380
+
381
+ const token = (() => {
382
+ if (i === 0)
383
+ return {
384
+ address: ethAddress,
385
+ decimals: 18,
386
+ symbol: 'ETH',
387
+ }
388
+
389
+ return {
390
+ address: assetAddresses[i - 1]! as Address,
391
+ decimals: tokenURI_ || decimals_ ? Number(decimals_ ?? 1) : undefined,
392
+ symbol: symbol_ ?? undefined,
393
+ }
394
+ })()
395
+
396
+ if (changes.some((change) => change.token.address === token.address))
397
+ continue
398
+
399
+ changes.push({
400
+ token,
401
+ value: {
402
+ pre: balancePre,
403
+ post: balancePost,
404
+ diff: balancePost - balancePre,
405
+ },
406
+ })
407
+ }
408
+
409
+ return {
410
+ assetChanges: changes,
411
+ block,
412
+ results,
413
+ } as unknown as SimulateCallsReturnType<calls>
414
+ }
@@ -0,0 +1,19 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const zeroG = /*#__PURE__*/ defineChain({
4
+ id: 16_600,
5
+ name: '0G Newton Testnet',
6
+ nativeCurrency: { name: 'A0GI', symbol: 'A0GI', decimals: 18 },
7
+ rpcUrls: {
8
+ default: {
9
+ http: ['https://evmrpc-testnet.0g.ai'],
10
+ },
11
+ },
12
+ blockExplorers: {
13
+ default: {
14
+ name: '0G BlockChain Explorer',
15
+ url: 'https://chainscan-newton.0g.ai',
16
+ },
17
+ },
18
+ testnet: true,
19
+ })
@@ -12,6 +12,14 @@ export const berachain = /*#__PURE__*/ defineChain({
12
12
  address: '0xcA11bde05977b3631167028862bE2a173976CA11',
13
13
  blockCreated: 0,
14
14
  },
15
+ ensRegistry: {
16
+ address: '0x5b22280886a2f5e09a49bea7e320eab0e5320e28',
17
+ blockCreated: 877007,
18
+ },
19
+ ensUniversalResolver: {
20
+ address: '0xddfb18888a9466688235887dec2a10c4f5effee9',
21
+ blockCreated: 877008,
22
+ },
15
23
  },
16
24
  rpcUrls: {
17
25
  default: { http: ['https://rpc.berachain.com'] },
@@ -0,0 +1,15 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const story = /*#__PURE__*/ defineChain({
4
+ id: 1514,
5
+ name: 'Story',
6
+ nativeCurrency: {
7
+ decimals: 18,
8
+ name: 'IP Token',
9
+ symbol: 'IP',
10
+ },
11
+ rpcUrls: {
12
+ default: { http: ['https://mainnet.storyrpc.io'] },
13
+ },
14
+ testnet: false,
15
+ })
@@ -0,0 +1,25 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const unichain = /*#__PURE__*/ defineChain({
4
+ id: 130,
5
+ name: 'Unichain',
6
+ nativeCurrency: { name: 'Unichain', symbol: 'ETH', decimals: 18 },
7
+ rpcUrls: {
8
+ default: {
9
+ http: ['https://mainnet.unichain.org/'],
10
+ },
11
+ },
12
+ blockExplorers: {
13
+ default: {
14
+ name: 'Uniscan',
15
+ url: 'https://uniscan.xyz',
16
+ apiUrl: 'https://api.uniscan.xyz/api',
17
+ },
18
+ },
19
+ contracts: {
20
+ multicall3: {
21
+ address: '0xca11bde05977b3631167028862be2a173976ca11',
22
+ blockCreated: 0,
23
+ },
24
+ },
25
+ })
@@ -11,12 +11,12 @@ export const worldchainSepolia = /*#__PURE__*/ defineChain({
11
11
  nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
12
12
  rpcUrls: {
13
13
  default: { http: ['https://worldchain-sepolia.g.alchemy.com/public'] },
14
- public: { http: ['https://worldchain-sepolia.g.alchemy.com/public'] },
15
14
  },
16
15
  blockExplorers: {
17
16
  default: {
18
17
  name: 'Worldscan Sepolia',
19
18
  url: 'https://sepolia.worldscan.org',
19
+ apiUrl: 'https://api-sepolia.worldscan.org/api',
20
20
  },
21
21
  blockscout: {
22
22
  name: 'Blockscout',
package/chains/index.ts CHANGED
@@ -440,6 +440,7 @@ export { sophon } from './definitions/sophon.js'
440
440
  export { sophonTestnet } from './definitions/sophonTestnet.js'
441
441
  export { spicy } from './definitions/spicy.js'
442
442
  export { step } from './definitions/step.js'
443
+ export { story } from './definitions/story.js'
443
444
  export { storyOdyssey } from './definitions/storyOdyssey.js'
444
445
  export { storyTestnet } from './definitions/storyTestnet.js'
445
446
  export { stratis } from './definitions/stratis.js'
@@ -482,6 +483,7 @@ export { ultra } from './definitions/ultra.js'
482
483
  export { ultraTestnet } from './definitions/ultraTestnet.js'
483
484
  export { ultron } from './definitions/ultron.js'
484
485
  export { ultronTestnet } from './definitions/ultronTestnet.js'
486
+ export { unichain } from './definitions/unichain.js'
485
487
  export { unichainSepolia } from './definitions/unichainSepolia.js'
486
488
  export { unique } from './definitions/unique.js'
487
489
  export { uniqueOpal } from './definitions/uniqueOpal.js'
@@ -519,6 +521,7 @@ export { yooldoVerse } from './definitions/yooldoVerse.js'
519
521
  export { yooldoVerseTestnet } from './definitions/yooldoVerseTestnet.js'
520
522
  export { zenchainTestnet } from './definitions/zenchainTestnet.js'
521
523
  export { zeniq } from './definitions/zeniq.js'
524
+ export { zeroG } from './definitions/0g.js'
522
525
  export { zetachain } from './definitions/zetachain.js'
523
526
  export { zetachainAthensTestnet } from './definitions/zetachainAthensTestnet.js'
524
527
  export { zhejiang } from './definitions/zhejiang.js'