Skip to content

Commit f35ae4c

Browse files
authored
chore: add is gasFeeSponsored field in transaction batch params (#7064)
## Explanation This PR introduces a new boolean flag, isGasFeeSponsored, across the Transaction Controller and Bridge Status Controller to indicate when a transaction’s gas fee is sponsored (i.e., paid by MetaMask or another service provider). This complements the existing isGasFeeIncluded flag, which tracks when the gas cost is embedded within the transaction itself. Together, these flags enable more accurate handling of different gas payment scenarios. Especially needed for the fully sponsored scenario for SEI and MONAD chain. <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## 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](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [ ] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds `isGasFeeSponsored` flag to transaction batches and addTransaction, wiring it from BridgeStatusController quotes through to TransactionController. > > - **Transaction Controller**: > - Add `isGasFeeSponsored` to `TransactionBatchRequest` and `AddTransactionOptions` types; persist on transactions. > - Pass `isGasFeeSponsored` through `addTransactionBatch` paths (EIP-7702 and hook-based) by forwarding `userRequest.isGasFeeSponsored` when calling `addTransaction`. > - Update tests to include `isGasFeeSponsored` in expected metadata; changelog updated. > - **Bridge Status Controller**: > - Read `gasSponsored` from quote and set `isGasFeeSponsored` on batch params in `getAddTransactionBatchParams`. > - Update snapshots to include `isGasFeeSponsored` in batch request objects. > - **Changelogs**: Document new `isGasFeeSponsored` support in both packages. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 0a5a3ad. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 6175608 commit f35ae4c

File tree

9 files changed

+46
-0
lines changed

9 files changed

+46
-0
lines changed

packages/bridge-status-controller/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add isGasFeeSponsored field in transaction batch params ([#7064](https://github.com/MetaMask/core/pull/7064))
13+
1014
## [59.0.0]
1115

1216
### Changed

packages/bridge-status-controller/src/__snapshots__/bridge-status-controller.test.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,7 @@ Array [
12521252
"disable7702": true,
12531253
"from": "0xaccount1",
12541254
"isGasFeeIncluded": false,
1255+
"isGasFeeSponsored": false,
12551256
"networkClientId": "arbitrum",
12561257
"origin": "metamask",
12571258
"requireApproval": false,
@@ -2952,6 +2953,7 @@ Array [
29522953
"disable7702": true,
29532954
"from": "0xaccount1",
29542955
"isGasFeeIncluded": false,
2956+
"isGasFeeSponsored": false,
29552957
"networkClientId": "arbitrum",
29562958
"origin": "metamask",
29572959
"requireApproval": false,

packages/bridge-status-controller/src/utils/transaction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ export const getAddTransactionBatchParams = async ({
300300
feeData: { txFee },
301301
gasIncluded,
302302
gasIncluded7702,
303+
gasSponsored,
303304
},
304305
sentAmount,
305306
toTokenAmount,
@@ -393,6 +394,7 @@ export const getAddTransactionBatchParams = async ({
393394
>[0] = {
394395
disable7702,
395396
isGasFeeIncluded: Boolean(gasIncluded7702),
397+
isGasFeeSponsored: Boolean(gasSponsored),
396398
networkClientId,
397399
requireApproval,
398400
origin: 'metamask',

packages/transaction-controller/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Calculate operator fee for OP stack networks and include it in `layer1GasFee` ([#6979](https://github.com/MetaMask/core/pull/6979))
13+
- Add support for `isGasFeeSponsored` field in transaction batch and add transaction options ([#7064](https://github.com/MetaMask/core/pull/7064))
1314

1415
## [61.1.0]
1516

packages/transaction-controller/src/TransactionController.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,7 @@ describe('TransactionController', () => {
16921692
id: expect.any(String),
16931693
isFirstTimeInteraction: undefined,
16941694
isGasFeeIncluded: undefined,
1695+
isGasFeeSponsored: undefined,
16951696
nestedTransactions: undefined,
16961697
networkClientId: NETWORK_CLIENT_ID_MOCK,
16971698
origin: undefined,

packages/transaction-controller/src/TransactionController.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,7 @@ export class TransactionController extends BaseController<
12161216
deviceConfirmedOn,
12171217
disableGasBuffer,
12181218
isGasFeeIncluded,
1219+
isGasFeeSponsored,
12191220
method,
12201221
nestedTransactions,
12211222
networkClientId,
@@ -1315,6 +1316,7 @@ export class TransactionController extends BaseController<
13151316
disableGasBuffer,
13161317
id: random(),
13171318
isGasFeeIncluded,
1319+
isGasFeeSponsored,
13181320
isFirstTimeInteraction: undefined,
13191321
nestedTransactions,
13201322
networkClientId,

packages/transaction-controller/src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,9 @@ export type TransactionBatchRequest = {
17261726
/** Whether MetaMask will be compensated for the gas fee by the transaction. */
17271727
isGasFeeIncluded?: boolean;
17281728

1729+
/** Whether MetaMask will sponsor the gas fee for the transaction. */
1730+
isGasFeeSponsored?: boolean;
1731+
17291732
/** ID of the network client to submit the transaction. */
17301733
networkClientId: NetworkClientId;
17311734

@@ -2061,6 +2064,9 @@ export type AddTransactionOptions = {
20612064
/** Whether MetaMask will be compensated for the gas fee by the transaction. */
20622065
isGasFeeIncluded?: boolean;
20632066

2067+
/** Whether MetaMask will sponsor the gas fee for the transaction. */
2068+
isGasFeeSponsored?: boolean;
2069+
20642070
/** RPC method that requested the transaction. */
20652071
method?: string;
20662072

packages/transaction-controller/src/utils/batch.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,33 @@ describe('Batch Utils', () => {
810810
},
811811
);
812812

813+
it.each([true, false])(
814+
'passes isGasFeeSponsored flag (%s) through to addTransaction when provided (EIP-7702 path)',
815+
async (isGasFeeSponsored) => {
816+
isAccountUpgradedToEIP7702Mock.mockResolvedValueOnce({
817+
delegationAddress: undefined,
818+
isSupported: true,
819+
});
820+
821+
addTransactionMock.mockResolvedValueOnce({
822+
transactionMeta: TRANSACTION_META_MOCK,
823+
result: Promise.resolve(''),
824+
});
825+
826+
request.request.isGasFeeSponsored = isGasFeeSponsored;
827+
828+
await addTransactionBatch(request);
829+
830+
expect(addTransactionMock).toHaveBeenCalledTimes(1);
831+
expect(addTransactionMock).toHaveBeenCalledWith(
832+
expect.any(Object),
833+
expect.objectContaining({
834+
isGasFeeSponsored,
835+
}),
836+
);
837+
},
838+
);
839+
813840
describe('validates security', () => {
814841
it('using transaction params', async () => {
815842
isAccountUpgradedToEIP7702Mock.mockResolvedValueOnce({

packages/transaction-controller/src/utils/batch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ async function addTransactionBatchWith7702(
401401
const { result } = await addTransaction(txParams, {
402402
batchId,
403403
isGasFeeIncluded: userRequest.isGasFeeIncluded,
404+
isGasFeeSponsored: userRequest.isGasFeeSponsored,
404405
nestedTransactions,
405406
networkClientId,
406407
origin,

0 commit comments

Comments
 (0)