Skip to content

Commit dbe1e17

Browse files
committed
wip skip gas
1 parent a367c33 commit dbe1e17

2 files changed

Lines changed: 30 additions & 24 deletions

File tree

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,9 +1814,6 @@ describe('Bridge Status Controller Transaction Utils', () => {
18141814
{
18151815
"data": "0xbridgeData",
18161816
"from": "0xUserAddress",
1817-
"gas": "0x5208",
1818-
"maxFeePerGas": "0xb1a2bc2ec50000",
1819-
"maxPriorityFeePerGas": "0xb1a2bc2ec50000",
18201817
"to": "0xBridgeContract",
18211818
"value": "0x1000",
18221819
}
@@ -2033,9 +2030,6 @@ describe('Bridge Status Controller Transaction Utils', () => {
20332030
"params": {
20342031
"data": "0xbridgeData",
20352032
"from": "0xUserAddress",
2036-
"gas": "0x5208",
2037-
"maxFeePerGas": "0xb1a2bc2ec50000",
2038-
"maxPriorityFeePerGas": "0xb1a2bc2ec50000",
20392033
"to": "0xBridgeContract",
20402034
"value": "0x1000",
20412035
},
@@ -2205,9 +2199,6 @@ describe('Bridge Status Controller Transaction Utils', () => {
22052199
{
22062200
"data": "0xbridgeData",
22072201
"from": "0xUserAddress",
2208-
"gas": "0x5208",
2209-
"maxFeePerGas": "0xb1a2bc2ec50000",
2210-
"maxPriorityFeePerGas": "0xb1a2bc2ec50000",
22112202
"to": "0xBridgeContract",
22122203
"value": "0x1000",
22132204
}

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const is7702Tx = (tx: TransactionMeta) => {
5959
);
6060
};
6161

62-
const getGasFeeEstimates = async (
62+
export const getGasFeeEstimates = async (
6363
messenger: BridgeStatusControllerMessenger,
6464
args: Parameters<TransactionController['estimateGasFee']>[0],
6565
) => {
@@ -316,6 +316,7 @@ export const toQuoteAndTxMetadata = ({
316316
* @param networkClientId - the network client ID to use for the gas fee estimates
317317
* @param chainId - the chain ID to use for the gas fee estimates
318318
* @param simulatedGasFeeLimits - either the txFee from the quote or the simulated gas fee limits for the batch sell
319+
* @param skipGasFields - when true (gasIncluded7702), omit gas and fee fields so the batch controller sponsors gas
319320
* @returns The gas fee estimates for the transaction
320321
*/
321322
export const toTransactionParams = async (
@@ -324,6 +325,7 @@ export const toTransactionParams = async (
324325
networkClientId: string,
325326
chainId: Hex,
326327
simulatedGasFeeLimits?: SimulatedGasFeeLimits | TxFeeGasLimits,
328+
skipGasFields = false,
327329
): Promise<BatchTransactionParams> => {
328330
const normalizedTrade = {
329331
...trade,
@@ -332,6 +334,11 @@ export const toTransactionParams = async (
332334
from: trade.from,
333335
value: trade.value,
334336
};
337+
338+
if (skipGasFields) {
339+
return normalizedTrade;
340+
}
341+
335342
const transactionParams = {
336343
...trade,
337344
// Only add gasLimit and gas if they're truthy
@@ -386,17 +393,28 @@ export const getAddTransactionBatchParams = async ({
386393
const hexChainId = formatChainIdToHex(trade.chainId);
387394
const networkClientId = getNetworkClientIdByChainId(messenger, hexChainId);
388395

396+
// Gas fields should be omitted only when gas is sponsored via 7702
397+
const skipGasFields = quoteResponse.quote.gasIncluded7702 === true;
398+
const isGasless =
399+
quoteResponse.quote.gasIncluded === true || skipGasFields;
400+
389401
const transactions: TransactionBatchSingleRequest[] = await Promise.all(
390-
tradeData.map(async ({ tx, txFee, quoteResponse: _, ...rest }) => ({
391-
params: await toTransactionParams(
392-
messenger,
393-
tx,
394-
networkClientId,
395-
hexChainId,
396-
txFee,
397-
),
398-
...rest,
399-
})),
402+
tradeData.map(async ({ tx, txFee, quoteResponse: _, ...rest }) => {
403+
const simulatedGasFeeLimits =
404+
!skipGasFields && isGasless ? txFee : undefined;
405+
406+
return {
407+
params: await toTransactionParams(
408+
messenger,
409+
tx,
410+
networkClientId,
411+
hexChainId,
412+
simulatedGasFeeLimits,
413+
skipGasFields,
414+
),
415+
...rest,
416+
};
417+
}),
400418
);
401419

402420
return {
@@ -416,10 +434,7 @@ export const getAddTransactionBatchParams = async ({
416434
// For gasless transactions with STX/sendBundle we keep disabling 7702.
417435
quoteResponse.quote.gasIncluded,
418436
isGasFeeSponsored: Boolean(quoteResponse.quote.gasSponsored),
419-
/**
420-
* Gas fields should be omitted only when gas is sponsored via 7702
421-
*/
422-
isGasFeeIncluded: Boolean(quoteResponse.quote.gasIncluded7702),
437+
isGasFeeIncluded: skipGasFields,
423438
...addTransactionBatchParams,
424439
};
425440
};

0 commit comments

Comments
 (0)