diff --git a/packages/sdk-router/src/rfq/api.ts b/packages/sdk-router/src/rfq/api.ts index 388645e392..ef8c084e4d 100644 --- a/packages/sdk-router/src/rfq/api.ts +++ b/packages/sdk-router/src/rfq/api.ts @@ -6,6 +6,7 @@ import { FastBridgeQuoteAPI, unmarshallFastBridgeQuote, } from './quote' +import { logger } from '../utils/logger' const API_URL = 'https://rfq-api-stage.omnirpc.io' const API_TIMEOUT = 2000 @@ -83,24 +84,24 @@ export const getAllQuotes = async (): Promise => { try { const response = await fetchWithTimeout(`${API_URL}/quotes`, API_TIMEOUT) if (!response.ok) { - console.error('Error fetching quotes:', response.statusText) + logger.error('Error fetching quotes', { response }) return [] } // The response is a list of quotes in the FastBridgeQuoteAPI format const quotes: FastBridgeQuoteAPI[] = await response.json() - console.log(`${API_URL}/quotes`, { quotes }) + logger.info(`${API_URL}/quotes`, { quotes }) return quotes .map((quote) => { try { return unmarshallFastBridgeQuote(quote) } catch (error) { - console.error('Error unmarshalling quote:', error) + logger.error('Error unmarshalling quote', { quote, error }) return null } }) .filter((quote): quote is FastBridgeQuote => quote !== null) } catch (error) { - console.error('Error fetching quotes:', error) + logger.error('Error fetching quotes', { error }) return [] } } @@ -142,20 +143,20 @@ export const getBestRelayerQuote = async ( }, }) if (!response.ok) { - console.error('Error fetching quote', { response }) + logger.error('Error fetching quote', { response }) return ZeroQuote } // Check that response is successful, contains non-zero dest amount, and has a relayer address const rfqResponse: PutRFQResponseAPI = await response.json() - console.log(`${API_URL}/rfq`, { rfqRequest, rfqResponse }) + logger.info(`${API_URL}/rfq`, { rfqRequest, rfqResponse }) if (!rfqResponse.success) { - console.error('No RFQ quote returned', { + logger.error('No RFQ quote returned', { reason: rfqResponse.reason ?? 'Unknown reason', }) return ZeroQuote } if (!rfqResponse.dest_amount || !rfqResponse.relayer_address) { - console.error( + logger.error( 'Error fetching quote: missing dest_amount or relayer_address in response:', { rfqResponse } ) @@ -163,7 +164,7 @@ export const getBestRelayerQuote = async ( } const destAmount = BigNumber.from(rfqResponse.dest_amount) if (destAmount.lte(0)) { - console.error('No RFQ quote returned', { rfqResponse }) + logger.error('No RFQ quote returned', { rfqResponse }) return ZeroQuote } return { @@ -172,7 +173,7 @@ export const getBestRelayerQuote = async ( quoteID: rfqResponse.quote_id, } } catch (error) { - console.error('Error fetching quote:', { error }) + logger.error('Error fetching quote', { error }) return ZeroQuote } } diff --git a/packages/sdk-router/src/rfq/engine/paraSwapEngine.ts b/packages/sdk-router/src/rfq/engine/paraSwapEngine.ts index 8bbd7cfc5a..7138e889c0 100644 --- a/packages/sdk-router/src/rfq/engine/paraSwapEngine.ts +++ b/packages/sdk-router/src/rfq/engine/paraSwapEngine.ts @@ -22,6 +22,7 @@ import { StepParams } from '../steps' import { AMOUNT_NOT_PRESENT, encodeZapData } from '../zapData' import { ChainProvider } from '../../router' import { isNativeToken } from '../../utils/handleNativeToken' +import { logger } from '../../utils/logger' const PARASWAP_API_URL = 'https://api.paraswap.io/swap' const PARASWAP_API_TIMEOUT = 2000 @@ -148,7 +149,7 @@ export class ParaSwapEngine implements SwapEngine { if (request.slippage > MAX_SLIPPAGE) { request.slippage = MAX_SLIPPAGE } - console.log('Fetching ParaSwap response', { request }) + logger.info('Fetching ParaSwap response', { request }) // Stringify every value in the request const params = new URLSearchParams( Object.entries(request).map(([k, v]) => { @@ -158,14 +159,14 @@ export class ParaSwapEngine implements SwapEngine { const url = `${PARASWAP_API_URL}?${params.toString()}` const response = await fetchWithTimeout(url, PARASWAP_API_TIMEOUT) if (!response.ok) { - console.error('Error fetching ParaSwap response', { url, response }) + logger.error('Error fetching ParaSwap response', { url, response }) return EmptyParaSwapResponse } const paraSwapResponse: ParaSwapResponse = await response.json() - console.log('Fetched ParaSwap response', { url, paraSwapResponse }) + logger.info('Fetched ParaSwap response', { url, paraSwapResponse }) return paraSwapResponse } catch (error) { - console.error('Error fetching ParaSwap response', { error }) + logger.error('Error fetching ParaSwap response', { error }) return EmptyParaSwapResponse } } @@ -207,14 +208,14 @@ export class ParaSwapEngine implements SwapEngine { } const provider = this.providers[chainId] if (!provider) { - console.error('No provider found for chainId', chainId) + logger.error('No provider found', { chainId }) return 0 } const tokenContract = new Contract(token, erc20ABI, provider) as ERC20 try { return tokenContract.decimals() } catch (error) { - console.error('Error fetching token decimals:', error) + logger.error('Error fetching token decimals', { token, error }) return 0 } } diff --git a/packages/sdk-router/src/rfq/sirSet.ts b/packages/sdk-router/src/rfq/sirSet.ts index f995db0282..5454386810 100644 --- a/packages/sdk-router/src/rfq/sirSet.ts +++ b/packages/sdk-router/src/rfq/sirSet.ts @@ -27,6 +27,7 @@ import { SynapseIntentRouter } from './sir' import { ChainProvider } from '../router' import { ONE_HOUR, TEN_MINUTES } from '../utils/deadlines' import { isSameAddress } from '../utils/addressUtils' +import { logger } from '../utils/logger' import { marshallTicker, Ticker } from './ticker' import { getAllQuotes, getBestRelayerQuote } from './api' import { @@ -231,8 +232,12 @@ export class SynapseIntentRouterSet extends SynapseModuleSet { ): { originQuery: Query; destQuery: Query } { // We should have saved neccessary params within dstQuery.rawParams if (hexDataLength(destQueryPrecise.rawParams) === 0) { - console.warn( - 'No params saved in destQuery.rawParams, slippage is not applied' + logger.warn( + 'No params saved in destQuery.rawParams, slippage is not applied', + { + originQuery: originQueryPrecise, + destQuery: destQueryPrecise, + } ) return { originQuery: originQueryPrecise, @@ -247,8 +252,14 @@ export class SynapseIntentRouterSet extends SynapseModuleSet { isSameAddress(paramsV1.destRelayToken, AddressZero) || paramsV1.destRelayAmount.eq(0) ) { - console.warn( - 'No destToken or destAmount saved in destQuery.rawParams, slippage is not applied' + logger.warn( + 'No destToken or destAmount saved in destQuery.rawParams, slippage is not applied', + { + originQuery: originQueryPrecise, + destQuery: destQueryPrecise, + paramsV1, + paramsV2, + } ) return { originQuery: originQueryPrecise, diff --git a/packages/sdk-router/src/utils/logger.ts b/packages/sdk-router/src/utils/logger.ts new file mode 100644 index 0000000000..950200f3a9 --- /dev/null +++ b/packages/sdk-router/src/utils/logger.ts @@ -0,0 +1,7 @@ +import winston from 'winston' + +export const logger = winston.createLogger({ + level: 'info', + format: winston.format.json(), + transports: [new winston.transports.Console()], +})