@@ -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 */
321322export 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