-
Notifications
You must be signed in to change notification settings - Fork 595
Expand file tree
/
Copy pathutils.ts
More file actions
39 lines (34 loc) · 1.83 KB
/
utils.ts
File metadata and controls
39 lines (34 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
import { type FunctionAbi, decodeFromAbi } from '@aztec/stdlib/abi';
import { AztecAddress } from '@aztec/stdlib/aztec-address';
import { GasSettings } from '@aztec/stdlib/gas';
import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
import type { Wallet } from '../wallet/wallet.js';
import { FeeJuicePaymentMethod } from './fee_juice_payment_method.js';
/**
* Use a wallet to simulate a function avoiding the wallet's entrypoint, as a SignerlessWallet would do
* @param wallet - The wallet to use for the simulation.
* @param contractAddress - The address of the contract to call.
* @param abi - The ABI of the function to simulate.
* @param args - The arguments to pass to the function.
* @returns The return values of the function call.
*/
export async function simulateWithoutSignature(
wallet: Wallet,
contractAddress: AztecAddress,
abi: FunctionAbi,
args: any[],
) {
const interaction = new ContractFunctionInteraction(wallet, contractAddress, abi, args);
const request = await interaction.request();
const maxFeesPerGas = (await wallet.getCurrentBaseFees()).mul(1.5);
const paymentMethod = new FeeJuicePaymentMethod(AztecAddress.ZERO);
const gasSettings = GasSettings.default({ maxFeesPerGas });
const fee = { gasSettings, paymentMethod };
const { l1ChainId: chainId, rollupVersion } = await wallet.getNodeInfo();
const entrypoint = new DefaultEntrypoint(chainId, rollupVersion);
const signerlessTxExecutionRequest = await entrypoint.createTxExecutionRequest(request, fee, {});
const simulationResult = await wallet.simulateTx(signerlessTxExecutionRequest, false, undefined, undefined, true);
const rawReturnValues = simulationResult.getPrivateReturnValues().values;
return decodeFromAbi(abi.returnTypes, rawReturnValues!);
}