import { TransactionManagerResponse } from '../transaction-inputs/transaction-manager-response'; import { TransactionError, TransactionManagerQueueItem } from '../types'; import { CUSTOM_ERROR_CODES, ErrorCode, NESTED_ERROR_CODES } from './constants'; import { TransactionErrorHandler } from './error-handler'; export class HandleNestedErrors { private errorHandler: TransactionErrorHandler; constructor(errorHandler: TransactionErrorHandler) { this.errorHandler = errorHandler; } // handle nested errors public async handleNestedErrors( transactionQueueItem: TransactionManagerQueueItem, transactionError: TransactionError, ): Promise { // handling nested error codes if ( transactionError.errorCodeNested == NESTED_ERROR_CODES.TRANSACTION_UNDERPRICED && transactionError.errorMessage ) { if ( transactionError.errorMessage.includes( 'max priority fee per gas higher than max fee per gas', ) ) { transactionError.gasErrorCode = CUSTOM_ERROR_CODES.MAX_PRIORITY_FEE_PER_GAS_HIGHER_THAN_MAX_FEE_PER_GAS; return await this.errorHandler.handleGasTransactionError( transactionQueueItem, transactionError, ); } if ( transactionError.errorMessage.includes( 'max fee per gas less than block base fee', ) ) { transactionError.gasErrorCode = CUSTOM_ERROR_CODES.MAX_FEE_PER_GAS_LESS_THAN_BLOCK_BASE_FEE; return await this.errorHandler.handleGasTransactionError( transactionQueueItem, transactionError, ); } if ( transactionError.errorMessage.includes( 'gas required exceeds allowance (0)', ) ) { return await this.errorHandler.handleTransactionFailure( transactionQueueItem, transactionError, ); } if (transactionError.errorMessage.includes('transaction underpriced')) { transactionError.gasErrorCode = CUSTOM_ERROR_CODES.GAS_LIMIT_TOO_LOW; return await this.errorHandler.handleGasTransactionError( transactionQueueItem, transactionError, ); } if (transactionError.errorMessage.includes('intrinsic gas too low')) { transactionError.gasErrorCode = CUSTOM_ERROR_CODES.GAS_LIMIT_TOO_LOW; return await this.errorHandler.handleGasTransactionError( transactionQueueItem, transactionError, ); } if (transactionError.errorMessage.includes('replacement fee too low')) { transactionError.gasErrorCode = ErrorCode.TRANSACTION_REPLACED; return await this.errorHandler.handleGasTransactionError( transactionQueueItem, transactionError, ); } return await this.errorHandler.handleGasTransactionError( transactionQueueItem, transactionError, ); } return undefined; } }