@@ -15,7 +15,7 @@ import {
15
15
sendTransaction ,
16
16
signTypedData ,
17
17
} from 'viem/actions'
18
- import { getAction } from 'viem/utils'
18
+ import { getAction , isHex } from 'viem/utils'
19
19
import { config } from '../../config.js'
20
20
import { LiFiErrorCode } from '../../errors/constants.js'
21
21
import { TransactionError } from '../../errors/errors.js'
@@ -126,38 +126,34 @@ export class EVMStepExecutor extends BaseStepExecutor {
126
126
process,
127
127
fromChain,
128
128
toChain,
129
- txType,
130
- txHash,
131
129
isBridgeExecution,
132
130
} : {
133
131
step : LiFiStepExtended
134
132
process : Process
135
133
fromChain : ExtendedChain
136
134
toChain : ExtendedChain
137
- txType : TransactionMethodType
138
- txHash : Hash
139
135
isBridgeExecution : boolean
140
136
} ) => {
141
137
let transactionReceipt : TransactionReceipt | WalletCallReceipt | undefined
142
138
143
- switch ( txType ) {
139
+ switch ( process . txType ) {
144
140
case 'batched' :
145
141
transactionReceipt = await waitForBatchTransactionReceipt (
146
142
this . client ,
147
- txHash
143
+ process . taskId as Hash
148
144
)
149
145
break
150
146
case 'relayed' :
151
147
transactionReceipt = await waitForRelayedTransactionReceipt (
152
- txHash ,
148
+ process . taskId as Hash ,
153
149
step
154
150
)
155
151
break
156
152
default :
157
153
transactionReceipt = await waitForTransactionReceipt ( {
158
154
client : this . client ,
159
155
chainId : fromChain . id ,
160
- txHash,
156
+ txHash : process . txHash as Hash ,
161
157
onReplaced : ( response ) => {
162
158
this . statusManager . updateProcess ( step , process . type , 'PENDING' , {
163
159
txHash : response . transaction . hash ,
@@ -171,17 +167,24 @@ export class EVMStepExecutor extends BaseStepExecutor {
171
167
// This might happen if the transaction was replaced.
172
168
if (
173
169
transactionReceipt ?. transactionHash &&
174
- transactionReceipt . transactionHash !== txHash
170
+ transactionReceipt . transactionHash !== process . txHash
175
171
) {
172
+ // Validate if transaction hash is a valid hex string that can be used on-chain
173
+ // Some custom integrations may return non-hex identifiers to support custom status tracking
174
+ const txHash = isHex ( transactionReceipt . transactionHash , { strict : true } )
175
+ ? transactionReceipt . transactionHash
176
+ : undefined
176
177
process = this . statusManager . updateProcess (
177
178
step ,
178
179
process . type ,
179
180
'PENDING' ,
180
181
{
181
- txHash : transactionReceipt . transactionHash ,
182
+ txHash : txHash ,
182
183
txLink :
183
184
( transactionReceipt as WalletCallReceipt ) . transactionLink ||
184
- `${ fromChain . metamask . blockExplorerUrls [ 0 ] } tx/${ transactionReceipt . transactionHash } ` ,
185
+ ( txHash
186
+ ? `${ fromChain . metamask . blockExplorerUrls [ 0 ] } tx/${ txHash } `
187
+ : undefined ) ,
185
188
}
186
189
)
187
190
}
@@ -307,6 +310,8 @@ export class EVMStepExecutor extends BaseStepExecutor {
307
310
const checkForAllowance =
308
311
// No existing swap/bridge transaction is pending
309
312
! existingProcess ?. txHash &&
313
+ // No existing swap/bridge batch/order is pending
314
+ ! existingProcess ?. taskId &&
310
315
// Token is not native (address is not zero)
311
316
! isFromNativeToken &&
312
317
// Approval address is required for allowance checks, but may be null in special cases (e.g. direct transfers)
@@ -346,38 +351,31 @@ export class EVMStepExecutor extends BaseStepExecutor {
346
351
}
347
352
348
353
let process = this . statusManager . findProcess ( step , currentProcessType )
354
+ try {
355
+ if ( process ?. status === 'DONE' ) {
356
+ await waitForDestinationChainTransaction (
357
+ step ,
358
+ process ,
359
+ fromChain ,
360
+ toChain ,
361
+ this . statusManager
362
+ )
349
363
350
- if ( process ?. status === 'DONE' ) {
351
- await waitForDestinationChainTransaction (
352
- step ,
353
- process ,
354
- fromChain ,
355
- toChain ,
356
- this . statusManager
357
- )
358
-
359
- return step
360
- }
364
+ return step
365
+ }
361
366
362
- try {
363
- if ( process ?. txHash ) {
367
+ if ( process ?. txHash || process ?. taskId ) {
364
368
// Make sure that the chain is still correct
365
369
const updatedClient = await this . checkClient ( step , process )
366
370
if ( ! updatedClient ) {
367
371
return step
368
372
}
369
373
370
- // Wait for exiting transaction
371
- const txHash = process . txHash as Hash
372
- const txType = process . txType as TransactionMethodType
373
-
374
374
await this . waitForTransaction ( {
375
375
step,
376
376
process,
377
377
fromChain,
378
378
toChain,
379
- txType,
380
- txHash,
381
379
isBridgeExecution,
382
380
} )
383
381
@@ -488,7 +486,8 @@ export class EVMStepExecutor extends BaseStepExecutor {
488
486
return step
489
487
}
490
488
491
- let txHash : Hash
489
+ let txHash : Hash | undefined
490
+ let taskId : Hash | undefined
492
491
let txType : TransactionMethodType = 'standard'
493
492
let txLink : string | undefined
494
493
@@ -510,7 +509,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
510
509
account : this . client . account ! ,
511
510
calls,
512
511
} )
513
- txHash = id as Hash
512
+ taskId = id as Hash
514
513
txType = 'batched'
515
514
} else if ( isRelayerTransaction ) {
516
515
const relayerTypedData = step . typedData ?. find (
@@ -561,7 +560,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
561
560
...stepBase ,
562
561
typedData : signedTypedData ,
563
562
} )
564
- txHash = relayedTransaction . taskId as Hash
563
+ taskId = relayedTransaction . taskId as Hash
565
564
txType = 'relayed'
566
565
txLink = relayedTransaction . txLink
567
566
} else {
@@ -663,9 +662,10 @@ export class EVMStepExecutor extends BaseStepExecutor {
663
662
// When atomic batch or relayer are supported, txHash represents the batch hash or taskId rather than an individual transaction hash
664
663
{
665
664
txHash,
665
+ taskId,
666
666
txType,
667
667
txLink :
668
- txType === 'standard'
668
+ txType === 'standard' && txHash
669
669
? `${ fromChain . metamask . blockExplorerUrls [ 0 ] } tx/${ txHash } `
670
670
: txLink ,
671
671
}
@@ -676,8 +676,6 @@ export class EVMStepExecutor extends BaseStepExecutor {
676
676
process,
677
677
fromChain,
678
678
toChain,
679
- txHash,
680
- txType,
681
679
isBridgeExecution,
682
680
} )
683
681
0 commit comments