Skip to content

Commit a367c33

Browse files
committed
fix: delegated account + gasIncluded7702=false
1 parent 457d85f commit a367c33

3 files changed

Lines changed: 67 additions & 50 deletions

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ import type {
2626
MockAnyNamespace,
2727
} from '@metamask/messenger';
2828
import type { Provider } from '@metamask/network-controller';
29-
import { CHAIN_IDS } from '@metamask/transaction-controller';
29+
import {
30+
CHAIN_IDS,
31+
GasFeeEstimateType,
32+
} from '@metamask/transaction-controller';
3033
import {
3134
TransactionType,
3235
TransactionStatus,
@@ -2833,6 +2836,7 @@ describe('BridgeStatusController', () => {
28332836

28342837
const mockEstimateGasFeeResult = {
28352838
estimates: {
2839+
type: GasFeeEstimateType.FeeMarket,
28362840
high: {
28372841
suggestedMaxFeePerGas: '0x1234',
28382842
suggestedMaxPriorityFeePerGas: '0x5678',
@@ -3636,6 +3640,7 @@ describe('BridgeStatusController', () => {
36363640
mockMessengerCall.mockReturnValueOnce('arbitrum-client-id');
36373641
mockMessengerCall.mockResolvedValueOnce({
36383642
estimates: {
3643+
type: GasFeeEstimateType.FeeMarket,
36393644
high: {
36403645
suggestedMaxFeePerGas: '0x1234',
36413646
suggestedMaxPriorityFeePerGas: '0x5678',
@@ -3806,6 +3811,7 @@ describe('BridgeStatusController', () => {
38063811

38073812
const mockEstimateGasFeeResult = {
38083813
estimates: {
3814+
type: GasFeeEstimateType.FeeMarket,
38093815
high: {
38103816
suggestedMaxFeePerGas: '0x1234',
38113817
suggestedMaxPriorityFeePerGas: '0x5678',

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

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
TxData,
1212
} from '@metamask/bridge-controller';
1313
import {
14+
GasFeeEstimateType,
1415
TransactionStatus,
1516
TransactionType,
1617
} from '@metamask/transaction-controller';
@@ -1709,10 +1710,14 @@ describe('Bridge Status Controller Transaction Utils', () => {
17091710
[FeeType.METABRIDGE]: {
17101711
amount: '100000000000000000',
17111712
},
1712-
txFee: {
1713-
maxFeePerGas: '50000000000000000',
1714-
maxPriorityFeePerGas: '50000000000000000',
1715-
},
1713+
...(overrides.gasIncluded7702 || overrides.gasIncluded
1714+
? {
1715+
txFee: {
1716+
maxFeePerGas: '50000000000000000',
1717+
maxPriorityFeePerGas: '50000000000000000',
1718+
},
1719+
}
1720+
: {}),
17161721
},
17171722
gasIncluded: overrides.gasIncluded ?? false,
17181723
gasIncluded7702: overrides.gasIncluded7702 ?? false,
@@ -1844,8 +1849,8 @@ describe('Bridge Status Controller Transaction Utils', () => {
18441849
"data": "0xbridgeData",
18451850
"from": "0xUserAddress",
18461851
"gas": "0x5208",
1847-
"maxFeePerGas": "0xb1a2bc2ec50000",
1848-
"maxPriorityFeePerGas": "0xb1a2bc2ec50000",
1852+
"maxFeePerGas": undefined,
1853+
"maxPriorityFeePerGas": undefined,
18491854
"to": "0xBridgeContract",
18501855
"value": "0x1000",
18511856
}
@@ -1875,8 +1880,8 @@ describe('Bridge Status Controller Transaction Utils', () => {
18751880
"data": "0xbridgeData",
18761881
"from": "0xUserAddress",
18771882
"gas": "0x5208",
1878-
"maxFeePerGas": "0xb1a2bc2ec50000",
1879-
"maxPriorityFeePerGas": "0xb1a2bc2ec50000",
1883+
"maxFeePerGas": undefined,
1884+
"maxPriorityFeePerGas": undefined,
18801885
"to": "0xBridgeContract",
18811886
"value": "0x1000",
18821887
}
@@ -1979,8 +1984,8 @@ describe('Bridge Status Controller Transaction Utils', () => {
19791984
"data": "0xbridgeData",
19801985
"from": "0xUserAddress",
19811986
"gas": "0x5208",
1982-
"maxFeePerGas": "0xb1a2bc2ec50000",
1983-
"maxPriorityFeePerGas": "0xb1a2bc2ec50000",
1987+
"maxFeePerGas": undefined,
1988+
"maxPriorityFeePerGas": undefined,
19841989
"to": "0xBridgeContract",
19851990
"value": "0x1000",
19861991
},
@@ -2079,8 +2084,8 @@ describe('Bridge Status Controller Transaction Utils', () => {
20792084
"data": "0xbridgeData",
20802085
"from": "0xUserAddress",
20812086
"gas": "0x5208",
2082-
"maxFeePerGas": "0xb1a2bc2ec50000",
2083-
"maxPriorityFeePerGas": "0xb1a2bc2ec50000",
2087+
"maxFeePerGas": undefined,
2088+
"maxPriorityFeePerGas": undefined,
20842089
"to": "0xBridgeContract",
20852090
"value": "0x1000",
20862091
},
@@ -2098,6 +2103,7 @@ describe('Bridge Status Controller Transaction Utils', () => {
20982103

20992104
const mockMessenger = createMockMessagingSystem({
21002105
estimates: {
2106+
type: GasFeeEstimateType.FeeMarket,
21012107
medium: {
21022108
maxFeePerGas: '0xabc',
21032109
maxPriorityFeePerGas: '0xdef',
@@ -2149,11 +2155,18 @@ describe('Bridge Status Controller Transaction Utils', () => {
21492155
`);
21502156
// Transaction params should include gas fields
21512157
expect(result.transactions).toHaveLength(1);
2152-
expect(result.transactions[0].params).toHaveProperty('gas');
2153-
expect(result.transactions[0].params).toHaveProperty('maxFeePerGas');
2154-
expect(result.transactions[0].params).toHaveProperty(
2155-
'maxPriorityFeePerGas',
2156-
);
2158+
// TxFee values from the estimateGasFee call
2159+
expect(result.transactions[0].params).toMatchInlineSnapshot(`
2160+
{
2161+
"data": "0xbridgeData",
2162+
"from": "0xUserAddress",
2163+
"gas": "0x5208",
2164+
"maxFeePerGas": "0xabc",
2165+
"maxPriorityFeePerGas": "0xdef",
2166+
"to": "0xBridgeContract",
2167+
"value": "0x1000",
2168+
}
2169+
`);
21572170
});
21582171

21592172
it('should enable 7702 and omit gas fields when isDelegatedAccount is true and gasIncluded7702 is true', async () => {
@@ -2192,6 +2205,9 @@ describe('Bridge Status Controller Transaction Utils', () => {
21922205
{
21932206
"data": "0xbridgeData",
21942207
"from": "0xUserAddress",
2208+
"gas": "0x5208",
2209+
"maxFeePerGas": "0xb1a2bc2ec50000",
2210+
"maxPriorityFeePerGas": "0xb1a2bc2ec50000",
21952211
"to": "0xBridgeContract",
21962212
"value": "0x1000",
21972213
}

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

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
} from '@metamask/bridge-controller';
1717
import { toHex } from '@metamask/controller-utils';
1818
import {
19+
GasFeeEstimateType,
1920
TransactionStatus,
2021
TransactionType,
2122
} from '@metamask/transaction-controller';
@@ -58,6 +59,22 @@ const is7702Tx = (tx: TransactionMeta) => {
5859
);
5960
};
6061

62+
const getGasFeeEstimates = async (
63+
messenger: BridgeStatusControllerMessenger,
64+
args: Parameters<TransactionController['estimateGasFee']>[0],
65+
) => {
66+
const { estimates } = await messenger.call(
67+
'TransactionController:estimateGasFee',
68+
args,
69+
);
70+
71+
if (estimates?.type === GasFeeEstimateType.FeeMarket) {
72+
return estimates[BRIDGE_PREFERRED_GAS_ESTIMATE];
73+
}
74+
75+
return undefined;
76+
};
77+
6178
export const getTransactions = (messenger: BridgeStatusControllerMessenger) => {
6279
return messenger.call('TransactionController:getState').transactions ?? [];
6380
};
@@ -298,7 +315,6 @@ export const toQuoteAndTxMetadata = ({
298315
* @param trade.gasLimit - the gas limit to use for the gas fee estimates
299316
* @param networkClientId - the network client ID to use for the gas fee estimates
300317
* @param chainId - the chain ID to use for the gas fee estimates
301-
* @param isGasIncluded7702 - whether the gas is included via 7702
302318
* @param simulatedGasFeeLimits - either the txFee from the quote or the simulated gas fee limits for the batch sell
303319
* @returns The gas fee estimates for the transaction
304320
*/
@@ -307,7 +323,6 @@ export const toTransactionParams = async (
307323
{ chainId: tradeChainId, gasLimit, ...trade }: TxData,
308324
networkClientId: string,
309325
chainId: Hex,
310-
isGasIncluded7702: boolean,
311326
simulatedGasFeeLimits?: SimulatedGasFeeLimits | TxFeeGasLimits,
312327
): Promise<BatchTransactionParams> => {
313328
const normalizedTrade = {
@@ -317,16 +332,14 @@ export const toTransactionParams = async (
317332
from: trade.from,
318333
value: trade.value,
319334
};
320-
if (isGasIncluded7702 && !simulatedGasFeeLimits) {
321-
return normalizedTrade;
322-
}
323335
const transactionParams = {
324336
...trade,
325337
// Only add gasLimit and gas if they're truthy
326338
gas: gasLimit ? toHex(gasLimit) : undefined,
327339
...normalizedTrade,
328340
};
329341

342+
// Use bridge-api's provided gas fee estimates
330343
if (simulatedGasFeeLimits) {
331344
return {
332345
...transactionParams,
@@ -336,32 +349,16 @@ export const toTransactionParams = async (
336349
}
337350

338351
// Get transaction's 1559 gas fee estimates
339-
const { estimates } = await messenger.call(
340-
'TransactionController:estimateGasFee',
341-
{
342-
transactionParams,
343-
networkClientId,
344-
chainId,
345-
},
346-
);
347-
348-
let gasFeeEstimates: Partial<Record<keyof SimulatedGasFeeLimits, Hex>> = {
349-
maxFeePerGas: undefined,
350-
maxPriorityFeePerGas: undefined,
351-
};
352-
if (
353-
estimates &&
354-
BRIDGE_PREFERRED_GAS_ESTIMATE in estimates &&
355-
typeof estimates[BRIDGE_PREFERRED_GAS_ESTIMATE] === 'object' &&
356-
'maxFeePerGas' in estimates[BRIDGE_PREFERRED_GAS_ESTIMATE]
357-
) {
358-
gasFeeEstimates = estimates[BRIDGE_PREFERRED_GAS_ESTIMATE];
359-
}
352+
const gasFeeEstimates = await getGasFeeEstimates(messenger, {
353+
transactionParams,
354+
networkClientId,
355+
chainId,
356+
});
360357

361358
return {
362359
...transactionParams,
363-
maxFeePerGas: gasFeeEstimates.maxFeePerGas,
364-
maxPriorityFeePerGas: gasFeeEstimates.maxPriorityFeePerGas,
360+
maxFeePerGas: gasFeeEstimates?.maxFeePerGas,
361+
maxPriorityFeePerGas: gasFeeEstimates?.maxPriorityFeePerGas,
365362
};
366363
};
367364

@@ -390,14 +387,13 @@ export const getAddTransactionBatchParams = async ({
390387
const networkClientId = getNetworkClientIdByChainId(messenger, hexChainId);
391388

392389
const transactions: TransactionBatchSingleRequest[] = await Promise.all(
393-
tradeData.map(async ({ tx, txFee, quoteResponse: { quote }, ...rest }) => ({
390+
tradeData.map(async ({ tx, txFee, quoteResponse: _, ...rest }) => ({
394391
params: await toTransactionParams(
395392
messenger,
396393
tx,
397394
networkClientId,
398395
hexChainId,
399-
Boolean(quote.gasIncluded7702),
400-
isDelegatedAccount ? undefined : txFee,
396+
txFee,
401397
),
402398
...rest,
403399
})),
@@ -635,7 +631,6 @@ export const submitEvmTransaction = async ({
635631
trade,
636632
networkClientId,
637633
hexChainId,
638-
false,
639634
txFee,
640635
);
641636

0 commit comments

Comments
 (0)