Skip to content

Commit 88dcd26

Browse files
committed
chore: up
1 parent cd3a33d commit 88dcd26

File tree

2 files changed

+51
-19
lines changed

2 files changed

+51
-19
lines changed

src/actions/public/simulateCalls.test.ts

+34-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ test('behavior: with mutation calls + asset changes', async () => {
117117
const account = '0xdead000000000000000042069420694206942069' as const
118118
const { assetChanges, results } = await simulateCalls(mainnetClient, {
119119
account,
120-
assetChanges: true,
120+
traceAssetChanges: true,
121121
calls: [
122122
{
123123
to: accounts[1].address,
@@ -384,3 +384,36 @@ test('behavior: stress', async () => {
384384
calls,
385385
})
386386
})
387+
388+
test('behavior: account not provided with traceAssetChanges', async () => {
389+
await expect(() =>
390+
simulateCalls(mainnetClient, {
391+
traceAssetChanges: true,
392+
calls: [
393+
{
394+
to: accounts[1].address,
395+
value: parseEther('1'),
396+
},
397+
{
398+
to: accounts[2].address,
399+
value: parseEther('1'),
400+
},
401+
{
402+
abi: wagmiContractConfig.abi,
403+
functionName: 'mint',
404+
to: wagmiContractConfig.address,
405+
},
406+
{
407+
abi: erc20Abi,
408+
functionName: 'transfer',
409+
to: '0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE',
410+
args: [accounts[1].address, parseEther('1')],
411+
},
412+
],
413+
}),
414+
).rejects.toThrowErrorMatchingInlineSnapshot(`
415+
[BaseError: \`account\` is required when \`traceAssetChanges\` is true
416+
417+
418+
`)
419+
})

src/actions/public/simulateCalls.ts

+17-18
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ export type SimulateCallsParameters<
4242
> = Omit<SimulateBlocksParameters, 'blocks' | 'returnFullTransactions'> & {
4343
/** Account attached to the calls (msg.sender). */
4444
account?: account | undefined
45-
/** Whether to trace asset changes. */
46-
assetChanges?: boolean | undefined
4745
/** Calls to simulate. */
4846
calls: Calls<Narrow<calls>>
4947
/** State overrides. */
5048
stateOverrides?: StateOverride | undefined
49+
/** Whether to trace asset changes. */
50+
traceAssetChanges?: boolean | undefined
5151
}
5252

5353
export type SimulateCallsReturnType<
@@ -57,8 +57,8 @@ export type SimulateCallsReturnType<
5757
assetChanges: readonly {
5858
token: {
5959
address: Address
60-
decimals: number
61-
symbol: string
60+
decimals?: number | undefined
61+
symbol?: string | undefined
6262
}
6363
value: { pre: bigint; post: bigint; diff: bigint }
6464
}[]
@@ -130,11 +130,11 @@ export async function simulateCalls<
130130
parameters: SimulateCallsParameters<calls, account>,
131131
): Promise<SimulateCallsReturnType<calls>> {
132132
const {
133-
assetChanges,
134133
blockNumber,
135134
blockTag,
136135
calls,
137136
stateOverrides,
137+
traceAssetChanges,
138138
traceTransfers,
139139
validation,
140140
} = parameters
@@ -143,8 +143,10 @@ export async function simulateCalls<
143143
? parseAccount(parameters.account)
144144
: undefined
145145

146-
if (assetChanges && !account)
147-
throw new BaseError('`account` is required when `assetChanges` is true')
146+
if (traceAssetChanges && !account)
147+
throw new BaseError(
148+
'`account` is required when `traceAssetChanges` is true',
149+
)
148150

149151
// Derive bytecode to extract ETH balance via a contract call.
150152
const getBalanceData = account
@@ -161,7 +163,7 @@ export async function simulateCalls<
161163
: undefined
162164

163165
// Fetch ERC20/721 addresses that were "touched" from the calls.
164-
const assetAddresses = assetChanges
166+
const assetAddresses = traceAssetChanges
165167
? await Promise.all(
166168
parameters.calls.map(async (call: any) => {
167169
if (!call.data && !call.abi) return
@@ -190,7 +192,7 @@ export async function simulateCalls<
190192
blockNumber,
191193
blockTag: blockTag as undefined,
192194
blocks: [
193-
...(assetChanges
195+
...(traceAssetChanges
194196
? [
195197
// ETH pre balances
196198
{
@@ -231,7 +233,7 @@ export async function simulateCalls<
231233
stateOverrides: resultsStateOverrides,
232234
},
233235

234-
...(assetChanges
236+
...(traceAssetChanges
235237
? [
236238
// ETH post balances
237239
{
@@ -324,7 +326,7 @@ export async function simulateCalls<
324326
validation,
325327
})
326328

327-
const block_results = assetChanges ? blocks[2] : blocks[0]
329+
const block_results = traceAssetChanges ? blocks[2] : blocks[0]
328330
const [
329331
block_ethPre,
330332
block_assetsPre,
@@ -334,7 +336,7 @@ export async function simulateCalls<
334336
block_decimals,
335337
block_tokenURI,
336338
block_symbols,
337-
] = assetChanges ? blocks : []
339+
] = traceAssetChanges ? blocks : []
338340

339341
// Extract call results from the simulation.
340342
const { calls: block_calls, ...block } = block_results
@@ -383,14 +385,11 @@ export async function simulateCalls<
383385
decimals: 18,
384386
symbol: 'ETH',
385387
}
386-
if ((!decimals_ && !tokenURI_) || !symbol_)
387-
throw new BaseError(
388-
'cannot simulate asset changes. asset does not comply with ERC20 or ERC721 standard.',
389-
)
388+
390389
return {
391390
address: assetAddresses[i - 1]! as Address,
392-
decimals: Number(decimals_ ?? 1),
393-
symbol: symbol_,
391+
decimals: tokenURI_ || decimals_ ? Number(decimals_ ?? 1) : undefined,
392+
symbol: symbol_ ?? undefined,
394393
}
395394
})()
396395

0 commit comments

Comments
 (0)