Skip to content

Commit 9b049bf

Browse files
committed
fix: adjust tx links handling
1 parent ff170ae commit 9b049bf

File tree

5 files changed

+50
-42
lines changed

5 files changed

+50
-42
lines changed

src/core/EVM/EVMStepExecutor.ts

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
sendTransaction,
1616
signTypedData,
1717
} from 'viem/actions'
18-
import { getAction } from 'viem/utils'
18+
import { getAction, isHex } from 'viem/utils'
1919
import { config } from '../../config.js'
2020
import { LiFiErrorCode } from '../../errors/constants.js'
2121
import { TransactionError } from '../../errors/errors.js'
@@ -126,38 +126,34 @@ export class EVMStepExecutor extends BaseStepExecutor {
126126
process,
127127
fromChain,
128128
toChain,
129-
txType,
130-
txHash,
131129
isBridgeExecution,
132130
}: {
133131
step: LiFiStepExtended
134132
process: Process
135133
fromChain: ExtendedChain
136134
toChain: ExtendedChain
137-
txType: TransactionMethodType
138-
txHash: Hash
139135
isBridgeExecution: boolean
140136
}) => {
141137
let transactionReceipt: TransactionReceipt | WalletCallReceipt | undefined
142138

143-
switch (txType) {
139+
switch (process.txType) {
144140
case 'batched':
145141
transactionReceipt = await waitForBatchTransactionReceipt(
146142
this.client,
147-
txHash
143+
process.taskId as Hash
148144
)
149145
break
150146
case 'relayed':
151147
transactionReceipt = await waitForRelayedTransactionReceipt(
152-
txHash,
148+
process.taskId as Hash,
153149
step
154150
)
155151
break
156152
default:
157153
transactionReceipt = await waitForTransactionReceipt({
158154
client: this.client,
159155
chainId: fromChain.id,
160-
txHash,
156+
txHash: process.txHash as Hash,
161157
onReplaced: (response) => {
162158
this.statusManager.updateProcess(step, process.type, 'PENDING', {
163159
txHash: response.transaction.hash,
@@ -171,17 +167,24 @@ export class EVMStepExecutor extends BaseStepExecutor {
171167
// This might happen if the transaction was replaced.
172168
if (
173169
transactionReceipt?.transactionHash &&
174-
transactionReceipt.transactionHash !== txHash
170+
transactionReceipt.transactionHash !== process.txHash
175171
) {
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
176177
process = this.statusManager.updateProcess(
177178
step,
178179
process.type,
179180
'PENDING',
180181
{
181-
txHash: transactionReceipt.transactionHash,
182+
txHash: txHash,
182183
txLink:
183184
(transactionReceipt as WalletCallReceipt).transactionLink ||
184-
`${fromChain.metamask.blockExplorerUrls[0]}tx/${transactionReceipt.transactionHash}`,
185+
(txHash
186+
? `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`
187+
: undefined),
185188
}
186189
)
187190
}
@@ -307,6 +310,8 @@ export class EVMStepExecutor extends BaseStepExecutor {
307310
const checkForAllowance =
308311
// No existing swap/bridge transaction is pending
309312
!existingProcess?.txHash &&
313+
// No existing swap/bridge batch/order is pending
314+
!existingProcess?.taskId &&
310315
// Token is not native (address is not zero)
311316
!isFromNativeToken &&
312317
// 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 {
346351
}
347352

348353
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+
)
349363

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+
}
361366

362-
try {
363-
if (process?.txHash) {
367+
if (process?.txHash || process?.taskId) {
364368
// Make sure that the chain is still correct
365369
const updatedClient = await this.checkClient(step, process)
366370
if (!updatedClient) {
367371
return step
368372
}
369373

370-
// Wait for exiting transaction
371-
const txHash = process.txHash as Hash
372-
const txType = process.txType as TransactionMethodType
373-
374374
await this.waitForTransaction({
375375
step,
376376
process,
377377
fromChain,
378378
toChain,
379-
txType,
380-
txHash,
381379
isBridgeExecution,
382380
})
383381

@@ -488,7 +486,8 @@ export class EVMStepExecutor extends BaseStepExecutor {
488486
return step
489487
}
490488

491-
let txHash: Hash
489+
let txHash: Hash | undefined
490+
let taskId: Hash | undefined
492491
let txType: TransactionMethodType = 'standard'
493492
let txLink: string | undefined
494493

@@ -510,7 +509,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
510509
account: this.client.account!,
511510
calls,
512511
})
513-
txHash = id as Hash
512+
taskId = id as Hash
514513
txType = 'batched'
515514
} else if (isRelayerTransaction) {
516515
const relayerTypedData = step.typedData?.find(
@@ -561,7 +560,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
561560
...stepBase,
562561
typedData: signedTypedData,
563562
})
564-
txHash = relayedTransaction.taskId as Hash
563+
taskId = relayedTransaction.taskId as Hash
565564
txType = 'relayed'
566565
txLink = relayedTransaction.txLink
567566
} else {
@@ -663,9 +662,10 @@ export class EVMStepExecutor extends BaseStepExecutor {
663662
// When atomic batch or relayer are supported, txHash represents the batch hash or taskId rather than an individual transaction hash
664663
{
665664
txHash,
665+
taskId,
666666
txType,
667667
txLink:
668-
txType === 'standard'
668+
txType === 'standard' && txHash
669669
? `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`
670670
: txLink,
671671
}
@@ -676,8 +676,6 @@ export class EVMStepExecutor extends BaseStepExecutor {
676676
process,
677677
fromChain,
678678
toChain,
679-
txHash,
680-
txType,
681679
isBridgeExecution,
682680
})
683681

src/core/prepareRestart.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export const prepareRestart = async (route: RouteExtended) => {
66
if (step.execution) {
77
// Find the index of the last process that has tx hash
88
const lastValidIndex = step.execution.process.findLastIndex(
9-
(process) => !!process.txHash && process.status !== 'FAILED'
9+
(process) =>
10+
(!!process.txHash || !!process.taskId) && process.status !== 'FAILED'
1011
)
1112

1213
// Keep all processes up to the one with tx hash

src/core/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ export type Process = {
152152
substatus?: Substatus
153153
chainId?: number
154154
txHash?: string
155-
multisigTxHash?: string
155+
taskId?: string
156156
txLink?: string
157+
txType?: TransactionMethodType
157158
actionRequiredAt?: number
158159
doneAt?: number
159160
failedAt?: number

src/core/waitForDestinationChainTransaction.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export async function waitForDestinationChainTransaction(
1717
statusManager: StatusManager,
1818
pollingInterval?: number
1919
): Promise<LiFiStepExtended> {
20-
const transactionHash = process.txHash
20+
// At this point, we should have a txHash or taskId
21+
// taskId is used for custom integrations that don't use the standard transaction hash
22+
const transactionHash = process.txHash || process.taskId
2123
let processType = process.type
2224
try {
2325
// Wait for the transaction status on the destination chain
@@ -52,7 +54,9 @@ export async function waitForDestinationChainTransaction(
5254
substatus: statusResponse.substatus,
5355
substatusMessage: statusResponse.substatusMessage,
5456
txHash: statusReceiving?.txHash,
55-
txLink: `${toChain.metamask.blockExplorerUrls[0]}tx/${statusReceiving?.txHash}`,
57+
txLink:
58+
statusReceiving?.txLink ||
59+
`${toChain.metamask.blockExplorerUrls[0]}tx/${statusReceiving?.txHash}`,
5660
})
5761

5862
// Update execution status

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export {
1818
isGaslessStep,
1919
isRelayerStep,
2020
} from './core/EVM/typeguards.js'
21-
export type { EVMProvider, EVMProviderOptions } from './core/EVM/types.js'
21+
export type {
22+
EVMProvider,
23+
EVMProviderOptions,
24+
WalletCallReceipt,
25+
} from './core/EVM/types.js'
2226
export { isEVM } from './core/EVM/types.js'
2327
export {
2428
convertExtendedChain,

0 commit comments

Comments
 (0)