aztec-packages
aztec-packages copied to clipboard
EPIC: Refactor contract interactions
We have a mess in terms of the base API we expose to users. This is epitomized in:
public async estimateGas(
opts?: Omit<SendMethodOptions, 'estimateGas' | 'skipPublicSimulation'>,
): Promise<Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>> {
// REFACTOR: both `this.txRequest = undefined` below are horrible, we should not be caching stuff that doesn't need to be.
// This also hints at a weird interface for create/request/estimate/send etc.
// Ensure we don't accidentally use a version of tx request that has estimateGas set to true, leading to an infinite loop.
this.txRequest = undefined;
const txRequest = await this.create({ ...opts, estimateGas: false });
// Ensure we don't accidentally cache a version of tx request that has estimateGas forcefully set to false.
this.txRequest = undefined;
const simulationResult = await this.wallet.simulateTx(txRequest, true);
const { totalGas: gasLimits, teardownGas: teardownGasLimits } = getGasLimits(
simulationResult,
(opts?.fee?.gasSettings ?? GasSettings.default()).teardownGasLimits,
);
return { gasLimits, teardownGasLimits };
}
We need to clean this up so developers have a much simpler interface when performing basic interactions like:
- creating a transaction request
- estimating the gas needed to perform a TX
- simulating a transaction request
- proving a transaction request
- sending a proven transaction to the network
Candidate design in progress is here