Skip to content

Add gasFeeEstimates for batch transactions #5886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 54 commits into
base: main
Choose a base branch
from

Conversation

vinistevam
Copy link
Contributor

@vinistevam vinistevam commented May 30, 2025

Explanation

This PR enhances TransactionBatchMeta by adding support for gasFeeEstimates, time, and status.
When both useHook and requireApproval are true, the batch approval flow is triggered, and gasFeeEstimates are populated using the DefaultGasFeeFlow. These estimates are then passed along with the request to be consumed by the client.

Changes

  • Extended TransactionBatchMeta to include:
    • gasFeeEstimates
    • status
  • Introduced a new helper function: prepareApprovalData
    • Responsible for preparing approval data before creating the request

References

Changelog

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

vinistevam and others added 30 commits May 13, 2025 17:18
…:MetaMask/core into feat/add-batch-transaction-approval-type
@vinistevam vinistevam marked this pull request as ready for review June 2, 2025 12:42
@vinistevam vinistevam requested review from a team as code owners June 2, 2025 12:42
Base automatically changed from feat/add-estimate-gas-batch-transaction to main June 3, 2025 13:00
@vinistevam vinistevam changed the title feat: add gasFeeEstimates for batch transactions Add gasFeeEstimates for batch transactions Jun 5, 2025
status: TransactionStatus;

/** When the transaction was created. */
time: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than adding these purely to support the DefaultGasFeeFlow, could we instead just use mock values at the point of calling? To minimise the complexity here as much as possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I removed the time property, I'm keeping status to filter it in the next PR and filter unapproved transactionBatches in the GasFeePoller.

},
});

txBatchMeta.gasFeeEstimates = gasFeeResponse.estimates;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nature of gas fee estimates is they change per block, so should this ticket also update the GasFeePoller to update the batch metadata overtime, or is that a separate dedicated ticket?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we split into two tickets, and I'm currently working on it on a separate PR.

});

const gasFeeResponse = await defaultGasFeeFlow.getGasFees({
ethQuery: getEthQuery(networkClientId),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, should we define ethQuery as a variable as we'd likely need it in future, and helps readability?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suro, done.

@@ -1450,6 +1504,8 @@ describe('Batch Utils', () => {

const result = await resultPromise;
expect(result?.batchId).toMatch(/^0x[0-9a-f]{32}$/u);
expect(simulateGasBatchMock).toHaveBeenCalledTimes(1);
expect(getGasFeesMock).toHaveBeenCalledTimes(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this warrant dedicated separate unit tests to verify that gas limit and gas fees are actually set on the batch metadata in the state?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created a dedicated test for updating gas properties.

@vinistevam vinistevam requested a review from matthewwalsh0 June 6, 2025 07:53
OGPoyraz
OGPoyraz previously approved these changes Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants