1- import type {
2- ExtendedTransactionInfo ,
3- FullStatusData ,
4- Process ,
5- } from '@lifi/types'
1+ import type { Process } from '@lifi/types'
62import type {
73 Client ,
84 GetAddressesReturnType ,
@@ -15,18 +11,16 @@ import { config } from '../../config.js'
1511import { LiFiErrorCode } from '../../errors/constants.js'
1612import { TransactionError , ValidationError } from '../../errors/errors.js'
1713import { getStepTransaction } from '../../services/api.js'
18- import { getTransactionFailedMessage } from '../../utils/getTransactionMessage.js'
1914import { isZeroAddress } from '../../utils/isZeroAddress.js'
2015import { BaseStepExecutor } from '../BaseStepExecutor.js'
2116import { checkBalance } from '../checkBalance.js'
22- import { getSubstatusMessage } from '../processMessages.js'
2317import { stepComparison } from '../stepComparison.js'
2418import type {
2519 LiFiStepExtended ,
2620 StepExecutorOptions ,
2721 TransactionParameters ,
2822} from '../types.js'
29- import { waitForReceivingTransaction } from '../waitForReceivingTransaction .js'
23+ import { waitForDestinationChainTransaction } from '../waitForDestinationChainTransaction .js'
3024import { checkAllowance } from './checkAllowance.js'
3125import { updateMultisigRouteProcess } from './multisig.js'
3226import { parseEVMErrors } from './parseEVMErrors.js'
@@ -109,16 +103,16 @@ export class EVMStepExecutor extends BaseStepExecutor {
109103 executeStep = async ( step : LiFiStepExtended ) : Promise < LiFiStepExtended > => {
110104 step . execution = this . statusManager . initExecutionObject ( step )
111105
112- // Find if it's bridging and the step is waiting for a transaction on the receiving chain
113- const recievingChainProcess = step . execution ?. process . find (
106+ // Find if it's bridging and the step is waiting for a transaction on the destination chain
107+ const destinationChainProcess = step . execution ?. process . find (
114108 ( process ) => process . type === 'RECEIVING_CHAIN'
115109 )
116110
117111 // Make sure that the chain is still correct
118- // If the step is waiting for a transaction on the receiving chain, we do not switch the chain
112+ // If the step is waiting for a transaction on the destination chain, we do not switch the chain
119113 // All changes are already done from the source chain
120114 // Return the step
121- if ( recievingChainProcess ?. substatus !== 'WAIT_DESTINATION_TRANSACTION' ) {
115+ if ( destinationChainProcess ?. substatus !== 'WAIT_DESTINATION_TRANSACTION' ) {
122116 const updatedClient = await this . checkClient ( step )
123117 if ( ! updatedClient ) {
124118 return step
@@ -138,7 +132,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
138132 const isBridgeExecution = fromChain . id !== toChain . id
139133 const currentProcessType = isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'
140134
141- // STEP 1: Check allowance
135+ // Check allowance
142136 const existingProcess = step . execution . process . find (
143137 ( p ) => p . type === currentProcessType
144138 )
@@ -171,7 +165,6 @@ export class EVMStepExecutor extends BaseStepExecutor {
171165 }
172166 }
173167
174- // STEP 2: Get transaction
175168 let process = this . statusManager . findOrCreateProcess ( {
176169 step,
177170 type : currentProcessType ,
@@ -245,7 +238,6 @@ export class EVMStepExecutor extends BaseStepExecutor {
245238 )
246239 }
247240
248- // STEP 3: Send the transaction
249241 // Make sure that the chain is still correct
250242 const updatedClient = await this . checkClient ( step , process )
251243 if ( ! updatedClient ) {
@@ -335,7 +327,6 @@ export class EVMStepExecutor extends BaseStepExecutor {
335327 } as SendTransactionParameters )
336328 }
337329
338- // STEP 4: Wait for the transaction
339330 if ( isMultisigClient ) {
340331 process = this . statusManager . updateProcess (
341332 step ,
@@ -423,8 +414,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
423414 }
424415 }
425416
426- // STEP 5: Wait for the receiving chain
427- const processTxHash = process . txHash
417+ // Wait for the transaction status on the destination chain
428418 if ( isBridgeExecution ) {
429419 process = this . statusManager . findOrCreateProcess ( {
430420 step,
@@ -433,63 +423,13 @@ export class EVMStepExecutor extends BaseStepExecutor {
433423 chainId : toChain . id ,
434424 } )
435425 }
436- let statusResponse : FullStatusData
437-
438- try {
439- if ( ! processTxHash ) {
440- throw new Error ( 'Transaction hash is undefined.' )
441- }
442- statusResponse = ( await waitForReceivingTransaction (
443- processTxHash ,
444- this . statusManager ,
445- process . type ,
446- step
447- ) ) as FullStatusData
448-
449- const statusReceiving =
450- statusResponse . receiving as ExtendedTransactionInfo
451-
452- process = this . statusManager . updateProcess ( step , process . type , 'DONE' , {
453- substatus : statusResponse . substatus ,
454- substatusMessage :
455- statusResponse . substatusMessage ||
456- getSubstatusMessage ( statusResponse . status , statusResponse . substatus ) ,
457- txHash : statusReceiving ?. txHash ,
458- txLink : `${ toChain . metamask . blockExplorerUrls [ 0 ] } tx/${ statusReceiving ?. txHash } ` ,
459- } )
460426
461- this . statusManager . updateExecution ( step , 'DONE' , {
462- fromAmount : statusResponse . sending . amount ,
463- toAmount : statusReceiving ?. amount ,
464- toToken : statusReceiving ?. token ,
465- gasCosts : [
466- {
467- amount : statusResponse . sending . gasAmount ,
468- amountUSD : statusResponse . sending . gasAmountUSD ,
469- token : statusResponse . sending . gasToken ,
470- estimate : statusResponse . sending . gasUsed ,
471- limit : statusResponse . sending . gasUsed ,
472- price : statusResponse . sending . gasPrice ,
473- type : 'SEND' ,
474- } ,
475- ] ,
476- } )
477- } catch ( e : unknown ) {
478- const htmlMessage = await getTransactionFailedMessage (
479- step ,
480- process . txLink
481- )
482-
483- process = this . statusManager . updateProcess ( step , process . type , 'FAILED' , {
484- error : {
485- code : LiFiErrorCode . TransactionFailed ,
486- message : 'Failed while waiting for receiving chain.' ,
487- htmlMessage,
488- } ,
489- } )
490- this . statusManager . updateExecution ( step , 'FAILED' )
491- throw await parseEVMErrors ( e as Error , step , process )
492- }
427+ await waitForDestinationChainTransaction (
428+ step ,
429+ process ,
430+ this . statusManager ,
431+ toChain
432+ )
493433
494434 // DONE
495435 return step
0 commit comments