Skip to content

Commit ab3d1e3

Browse files
authored
refactor: improve waiting for destination chain (#229)
1 parent e791141 commit ab3d1e3

11 files changed

+260
-294
lines changed

examples/node/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
"author": "LI.FI <[email protected]>",
88
"license": "MIT",
99
"dependencies": {
10-
"@lifi/data-types": "^5.19.0",
11-
"@lifi/sdk": "^3.4.4",
10+
"@lifi/data-types": "^5.19.1",
11+
"@lifi/sdk": "^3.5.0",
1212
"@wagmi/connectors": "^5.7.3",
1313
"@wagmi/core": "^2.16.3",
1414
"dotenv": "^16.4.7",
15-
"viem": "^2.22.1"
15+
"viem": "^2.22.2"
1616
},
1717
"scripts": {
1818
"example:swap": "tsx examples/swap.ts",
@@ -24,7 +24,7 @@
2424
"example:yearn": "tsx examples/yearnDeposit.ts"
2525
},
2626
"devDependencies": {
27-
"@types/node": "^22.10.3",
27+
"@types/node": "^22.10.5",
2828
"tsx": "^4.19.2",
2929
"typescript": "^5.7.2"
3030
}

examples/node/pnpm-lock.yaml

+105-62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lifi/sdk",
3-
"version": "3.5.0",
3+
"version": "3.5.1-beta.0",
44
"description": "LI.FI Any-to-Any Cross-Chain-Swap SDK",
55
"keywords": [
66
"bridge",
@@ -62,7 +62,7 @@
6262
"build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./src/_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./src/_cjs/package.json",
6363
"build:esm": "tsc --project ./tsconfig.build.json --module es2015 --outDir ./src/_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./src/_esm/package.json",
6464
"build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./src/_types --emitDeclarationOnly --declaration --declarationMap",
65-
"clean": "rm -rf dist tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo src/tsconfig.build.tsbuildinfo src/_esm src/_cjs src/_types",
65+
"clean": "rm -rf dist src/_esm src/_cjs src/_types",
6666
"coverage": "vitest run --coverage",
6767
"postinstall": "husky",
6868
"prepack": "pinst --disable",
@@ -94,14 +94,13 @@
9494
"dependencies": {
9595
"@bigmi/core": "^0.1.0",
9696
"@lifi/types": "^16.5.0",
97-
"@noble/curves": "^1.7.0",
98-
"@noble/hashes": "^1.6.1",
97+
"@noble/curves": "^1.8.0",
9998
"@solana/wallet-adapter-base": "^0.9.23",
10099
"@solana/web3.js": "^1.98.0",
101100
"bech32": "^2.0.0",
102101
"bitcoinjs-lib": "^7.0.0-rc.0",
103102
"bs58": "^6.0.0",
104-
"viem": "^2.22.1"
103+
"viem": "^2.22.2"
105104
},
106105
"devDependencies": {
107106
"@biomejs/biome": "^1.9.4",

pnpm-lock.yaml

+25-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/EVM/EVMStepExecutor.ts

+14-74
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import type {
2-
ExtendedTransactionInfo,
3-
FullStatusData,
4-
Process,
5-
} from '@lifi/types'
1+
import type { Process } from '@lifi/types'
62
import type {
73
Client,
84
GetAddressesReturnType,
@@ -15,18 +11,16 @@ import { config } from '../../config.js'
1511
import { LiFiErrorCode } from '../../errors/constants.js'
1612
import { TransactionError, ValidationError } from '../../errors/errors.js'
1713
import { getStepTransaction } from '../../services/api.js'
18-
import { getTransactionFailedMessage } from '../../utils/getTransactionMessage.js'
1914
import { isZeroAddress } from '../../utils/isZeroAddress.js'
2015
import { BaseStepExecutor } from '../BaseStepExecutor.js'
2116
import { checkBalance } from '../checkBalance.js'
22-
import { getSubstatusMessage } from '../processMessages.js'
2317
import { stepComparison } from '../stepComparison.js'
2418
import type {
2519
LiFiStepExtended,
2620
StepExecutorOptions,
2721
TransactionParameters,
2822
} from '../types.js'
29-
import { waitForReceivingTransaction } from '../waitForReceivingTransaction.js'
23+
import { waitForDestinationChainTransaction } from '../waitForDestinationChainTransaction.js'
3024
import { checkAllowance } from './checkAllowance.js'
3125
import { updateMultisigRouteProcess } from './multisig.js'
3226
import { 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

Comments
 (0)