feat: QuoteError

This commit is contained in:
Francisco Bezzecchi
2025-04-04 17:26:07 -03:00
parent c778c2bf85
commit fe43f7e07e
2 changed files with 18 additions and 2 deletions

View File

@@ -31,6 +31,9 @@ export enum ErrorCode {
// SDK error. Wrapper for sdk's native errors
SDK_ERROR = "SDK_ERROR",
// Quote errors
QUOTE_ERROR = "QUOTE_ERROR",
}
/**
@@ -257,3 +260,16 @@ export class BlockchainError extends RelayerError {
}
}
export class QuoterError extends RelayerError {
constructor(message: string, code: ErrorCode = ErrorCode.QUOTE_ERROR, details?: Record<string, unknown> | string) {
super(message, code, details);
this.name = this.constructor.name;
}
public static assetNotSupported(
details?: Record<string, unknown> | string) {
return new QuoterError("Asset is not supported", ErrorCode.ASSET_NOT_SUPPORTED, details);
}
}

View File

@@ -1,7 +1,7 @@
import { NextFunction, Request, Response } from "express";
import { getAddress } from "viem";
import { getAssetConfig } from "../../config/index.js";
import { RelayerError } from "../../exceptions/base.exception.js";
import { QuoterError } from "../../exceptions/base.exception.js";
import { web3Provider } from "../../providers/index.js";
import { QuoteProvider } from "../../providers/quote.provider.js";
import { QuoteMarshall } from "../../types.js";
@@ -20,7 +20,7 @@ export async function relayQuoteHandler(
const config = getAssetConfig(chainId, tokenAddress);
if (config === undefined)
throw RelayerError.unknown(`Asset ${tokenAddress} for chain ${chainId} is not supported`)
return next(QuoterError.assetNotSupported(`Asset ${tokenAddress} for chain ${chainId} is not supported`));
const quoteProvider = new QuoteProvider(config.fee_bps);
const gasPrice = await web3Provider.getGasPrice(chainId);