1
- import type {
2
- ExtendedTransactionInfo ,
3
- FullStatusData ,
4
- Process ,
5
- } from '@lifi/types'
1
+ import type { Process } from '@lifi/types'
6
2
import type {
7
3
Client ,
8
4
GetAddressesReturnType ,
@@ -15,18 +11,16 @@ import { config } from '../../config.js'
15
11
import { LiFiErrorCode } from '../../errors/constants.js'
16
12
import { TransactionError , ValidationError } from '../../errors/errors.js'
17
13
import { getStepTransaction } from '../../services/api.js'
18
- import { getTransactionFailedMessage } from '../../utils/getTransactionMessage.js'
19
14
import { isZeroAddress } from '../../utils/isZeroAddress.js'
20
15
import { BaseStepExecutor } from '../BaseStepExecutor.js'
21
16
import { checkBalance } from '../checkBalance.js'
22
- import { getSubstatusMessage } from '../processMessages.js'
23
17
import { stepComparison } from '../stepComparison.js'
24
18
import type {
25
19
LiFiStepExtended ,
26
20
StepExecutorOptions ,
27
21
TransactionParameters ,
28
22
} from '../types.js'
29
- import { waitForReceivingTransaction } from '../waitForReceivingTransaction .js'
23
+ import { waitForDestinationChainTransaction } from '../waitForDestinationChainTransaction .js'
30
24
import { checkAllowance } from './checkAllowance.js'
31
25
import { updateMultisigRouteProcess } from './multisig.js'
32
26
import { parseEVMErrors } from './parseEVMErrors.js'
@@ -109,16 +103,16 @@ export class EVMStepExecutor extends BaseStepExecutor {
109
103
executeStep = async ( step : LiFiStepExtended ) : Promise < LiFiStepExtended > => {
110
104
step . execution = this . statusManager . initExecutionObject ( step )
111
105
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 (
114
108
( process ) => process . type === 'RECEIVING_CHAIN'
115
109
)
116
110
117
111
// 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
119
113
// All changes are already done from the source chain
120
114
// Return the step
121
- if ( recievingChainProcess ?. substatus !== 'WAIT_DESTINATION_TRANSACTION' ) {
115
+ if ( destinationChainProcess ?. substatus !== 'WAIT_DESTINATION_TRANSACTION' ) {
122
116
const updatedClient = await this . checkClient ( step )
123
117
if ( ! updatedClient ) {
124
118
return step
@@ -138,7 +132,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
138
132
const isBridgeExecution = fromChain . id !== toChain . id
139
133
const currentProcessType = isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'
140
134
141
- // STEP 1: Check allowance
135
+ // Check allowance
142
136
const existingProcess = step . execution . process . find (
143
137
( p ) => p . type === currentProcessType
144
138
)
@@ -171,7 +165,6 @@ export class EVMStepExecutor extends BaseStepExecutor {
171
165
}
172
166
}
173
167
174
- // STEP 2: Get transaction
175
168
let process = this . statusManager . findOrCreateProcess ( {
176
169
step,
177
170
type : currentProcessType ,
@@ -245,7 +238,6 @@ export class EVMStepExecutor extends BaseStepExecutor {
245
238
)
246
239
}
247
240
248
- // STEP 3: Send the transaction
249
241
// Make sure that the chain is still correct
250
242
const updatedClient = await this . checkClient ( step , process )
251
243
if ( ! updatedClient ) {
@@ -335,7 +327,6 @@ export class EVMStepExecutor extends BaseStepExecutor {
335
327
} as SendTransactionParameters )
336
328
}
337
329
338
- // STEP 4: Wait for the transaction
339
330
if ( isMultisigClient ) {
340
331
process = this . statusManager . updateProcess (
341
332
step ,
@@ -423,8 +414,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
423
414
}
424
415
}
425
416
426
- // STEP 5: Wait for the receiving chain
427
- const processTxHash = process . txHash
417
+ // Wait for the transaction status on the destination chain
428
418
if ( isBridgeExecution ) {
429
419
process = this . statusManager . findOrCreateProcess ( {
430
420
step,
@@ -433,63 +423,13 @@ export class EVMStepExecutor extends BaseStepExecutor {
433
423
chainId : toChain . id ,
434
424
} )
435
425
}
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
- } )
460
426
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
+ )
493
433
494
434
// DONE
495
435
return step
0 commit comments