aztec-packages icon indicating copy to clipboard operation
aztec-packages copied to clipboard

EPIC: Refactor contract interactions

Open just-mitch opened this issue 8 months ago • 0 comments

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:

  1. creating a transaction request
  2. estimating the gas needed to perform a TX
  3. simulating a transaction request
  4. proving a transaction request
  5. sending a proven transaction to the network

Candidate design in progress is here

just-mitch avatar Jun 07 '24 15:06 just-mitch