Skip to content

EPIC: Refactor contract interactions #6973

@just-mitch

Description

@just-mitch

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions