Skip to content

Commit

Permalink
fix: better handle blockheight exceeded error
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Jul 22, 2024
1 parent b89343a commit 2eb6158
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/core/Solana/SolanaStepExecutor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ExtendedTransactionInfo, FullStatusData } from '@lifi/types'
import { type SignerWalletAdapter } from '@solana/wallet-adapter-base'
import {
TransactionExpiredBlockheightExceededError,
VersionedTransaction,
type SendOptions,
type SignatureResult,
Expand Down Expand Up @@ -244,33 +243,24 @@ export class SolanaStepExecutor extends BaseStepExecutor {
// Stop waiting for tx confirmation
abortController.abort()

if (!confirmedTx) {
throw new TransactionError(
LiFiErrorCode.TransactionExpired,
'Transaction has expired: The block height has exceeded the maximum allowed limit.'
)
}

if (confirmedTx?.err) {
const reason =
typeof confirmedTx.err === 'object'
? JSON.stringify(confirmedTx.err)
: confirmedTx.err
if (
confirmedTx.err instanceof
TransactionExpiredBlockheightExceededError
) {
throw new TransactionError(
LiFiErrorCode.TransactionExpired,
`${reason}`
)
}
throw new TransactionError(
LiFiErrorCode.TransactionFailed,
`Transaction failed: ${reason}`
)
}

if (!confirmedTx) {
throw new TransactionError(
LiFiErrorCode.TransactionExpired,
'Transaction has expired: The block height has exceeded the maximum allowed limit.'
)
}

// Transaction has been confirmed and we can update the process
process = this.statusManager.updateProcess(
step,
Expand Down
4 changes: 4 additions & 0 deletions src/core/Solana/parseSolanaErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const handleSpecificErrors = (e: any) => {
return new TransactionError(LiFiErrorCode.TransactionFailed, e.message, e)
}

if (e.name === 'TransactionExpiredBlockheightExceededError') {
return new TransactionError(LiFiErrorCode.TransactionExpired, e.message, e)
}

if (e.message?.includes('simulate')) {
return new TransactionError(
LiFiErrorCode.TransactionSimulationFailed,
Expand Down

0 comments on commit 2eb6158

Please sign in to comment.