From 96431991170b051c3a114221ddf923a06856e54f Mon Sep 17 00:00:00 2001 From: Cody Born Date: Fri, 31 May 2024 17:18:13 +0100 Subject: [PATCH 1/3] Add Open Order QuoteResponse log --- lib/handlers/hard-quote/handler.ts | 46 +++++++++++++++++++----------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/lib/handlers/hard-quote/handler.ts b/lib/handlers/hard-quote/handler.ts index 3f48e32..79acb89 100644 --- a/lib/handlers/hard-quote/handler.ts +++ b/lib/handlers/hard-quote/handler.ts @@ -51,25 +51,26 @@ export class QuoteHandler extends APIGLambdaHandler< // Instead of decoding the order, we rely on frontend passing in the requestId // from indicative quote + const logBody = { + requestId: request.requestId, + quoteId: request.quoteId, + tokenInChainId: request.tokenInChainId, + tokenOutChainId: request.tokenOutChainId, + tokenIn: request.tokenIn, + tokenOut: request.tokenOut, + offerer: request.swapper, + amount: request.amount.toString(), + type: TradeType[request.type], + numOutputs: request.numOutputs, + cosigner: request.order.info.cosigner, + createdAt: timestampInMstoSeconds(start), + createdAtMs: start.toString(), + } log.info({ eventType: 'HardRequest', - body: { - requestId: request.requestId, - quoteId: request.quoteId, - tokenInChainId: request.tokenInChainId, - tokenOutChainId: request.tokenOutChainId, - tokenIn: request.tokenIn, - tokenOut: request.tokenOut, - offerer: request.swapper, - amount: request.amount.toString(), - type: TradeType[request.type], - numOutputs: request.numOutputs, - cosigner: request.order.info.cosigner, - createdAt: timestampInMstoSeconds(start), - createdAtMs: start.toString(), - }, + body: logBody, }); - + let bestQuote; if (!requestBody.forceOpenOrder) { bestQuote = await getBestQuote(quoters, request.toQuoteRequest(), log, metric, 'HardResponse'); @@ -87,6 +88,19 @@ export class QuoteHandler extends APIGLambdaHandler< } else { cosignerData = getDefaultCosignerData(request); log.info({ cosignerData: cosignerData }, 'open order with default cosignerData'); + + // The RFQ responses are logged in getBestQuote() + // we log the Open Orders here + log.info({ + eventType: 'QuoteResponse', + body: { + ...logBody, + amountIn: request.totalInputAmountStart.toString(), + amountOut: request.totalOutputAmountStart.toString(), + filler: cosignerData.exclusiveFiller, + swapper: request.swapper + }, + }); } // TODO: use server key to cosign instead of local wallet From e668b0fed277acd0e65def9ad10eda2dc9663d19 Mon Sep 17 00:00:00 2001 From: Cody Born Date: Mon, 3 Jun 2024 16:32:08 +0100 Subject: [PATCH 2/3] log response directly --- lib/handlers/hard-quote/handler.ts | 55 ++++++++++++++---------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/lib/handlers/hard-quote/handler.ts b/lib/handlers/hard-quote/handler.ts index 79acb89..770f081 100644 --- a/lib/handlers/hard-quote/handler.ts +++ b/lib/handlers/hard-quote/handler.ts @@ -51,24 +51,23 @@ export class QuoteHandler extends APIGLambdaHandler< // Instead of decoding the order, we rely on frontend passing in the requestId // from indicative quote - const logBody = { - requestId: request.requestId, - quoteId: request.quoteId, - tokenInChainId: request.tokenInChainId, - tokenOutChainId: request.tokenOutChainId, - tokenIn: request.tokenIn, - tokenOut: request.tokenOut, - offerer: request.swapper, - amount: request.amount.toString(), - type: TradeType[request.type], - numOutputs: request.numOutputs, - cosigner: request.order.info.cosigner, - createdAt: timestampInMstoSeconds(start), - createdAtMs: start.toString(), - } log.info({ eventType: 'HardRequest', - body: logBody, + body: { + requestId: request.requestId, + quoteId: request.quoteId, + tokenInChainId: request.tokenInChainId, + tokenOutChainId: request.tokenOutChainId, + tokenIn: request.tokenIn, + tokenOut: request.tokenOut, + offerer: request.swapper, + amount: request.amount.toString(), + type: TradeType[request.type], + numOutputs: request.numOutputs, + cosigner: request.order.info.cosigner, + createdAt: timestampInMstoSeconds(start), + createdAtMs: start.toString(), + }, }); let bestQuote; @@ -88,19 +87,6 @@ export class QuoteHandler extends APIGLambdaHandler< } else { cosignerData = getDefaultCosignerData(request); log.info({ cosignerData: cosignerData }, 'open order with default cosignerData'); - - // The RFQ responses are logged in getBestQuote() - // we log the Open Orders here - log.info({ - eventType: 'QuoteResponse', - body: { - ...logBody, - amountIn: request.totalInputAmountStart.toString(), - amountOut: request.totalOutputAmountStart.toString(), - filler: cosignerData.exclusiveFiller, - swapper: request.swapper - }, - }); } // TODO: use server key to cosign instead of local wallet @@ -120,6 +106,17 @@ export class QuoteHandler extends APIGLambdaHandler< metric.putMetric(Metric.QUOTE_200, 1, MetricLoggerUnit.Count); metric.putMetric(Metric.QUOTE_LATENCY, Date.now() - start, MetricLoggerUnit.Milliseconds); const hardResponse = new HardQuoteResponse(request, cosignedOrder); + if (!bestQuote) { + // The RFQ responses are logged in getBestQuote() + // we log the Open Orders here + log.info({ + eventType: 'QuoteResponse', + body: { + ...hardResponse.toLog(), + offerer: request.swapper + } + }); + } return { statusCode: 200, body: hardResponse.toResponseJSON(), From b9688bca0f1ebb146d15dd9e0596c3c8884f013d Mon Sep 17 00:00:00 2001 From: Cody Born Date: Mon, 3 Jun 2024 16:35:59 +0100 Subject: [PATCH 3/3] Fix linting errors --- lib/config/chains.ts | 8 +++++++- lib/entities/HardQuoteResponse.ts | 2 +- lib/handlers/hard-quote/handler.ts | 8 ++++---- lib/handlers/hard-quote/index.ts | 2 +- lib/providers/analytics/firehose.ts | 2 +- lib/util/chains.ts | 4 ++-- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/config/chains.ts b/lib/config/chains.ts index 1c0c724..e3c5c0c 100644 --- a/lib/config/chains.ts +++ b/lib/config/chains.ts @@ -1,3 +1,9 @@ import { ChainId } from '../util/chains'; -export const SUPPORTED_CHAINS: ChainId[] = [ChainId.MAINNET, ChainId.GÖRLI, ChainId.POLYGON, ChainId.SEPOLIA, ChainId.ARBITRUM_ONE]; +export const SUPPORTED_CHAINS: ChainId[] = [ + ChainId.MAINNET, + ChainId.GÖRLI, + ChainId.POLYGON, + ChainId.SEPOLIA, + ChainId.ARBITRUM_ONE, +]; diff --git a/lib/entities/HardQuoteResponse.ts b/lib/entities/HardQuoteResponse.ts index 6262653..656976a 100644 --- a/lib/entities/HardQuoteResponse.ts +++ b/lib/entities/HardQuoteResponse.ts @@ -2,9 +2,9 @@ import { CosignedV2DutchOrder } from '@uniswap/uniswapx-sdk'; import { BigNumber } from 'ethers'; import { v4 as uuidv4 } from 'uuid'; +import { HardQuoteRequest } from '.'; import { HardQuoteResponseData } from '../handlers/hard-quote/schema'; import { currentTimestampInMs, timestampInMstoSeconds } from '../util/time'; -import { HardQuoteRequest } from '.'; // data class for hard quote response helpers and conversions export class HardQuoteResponse { diff --git a/lib/handlers/hard-quote/handler.ts b/lib/handlers/hard-quote/handler.ts index 770f081..d91b3a7 100644 --- a/lib/handlers/hard-quote/handler.ts +++ b/lib/handlers/hard-quote/handler.ts @@ -69,7 +69,7 @@ export class QuoteHandler extends APIGLambdaHandler< createdAtMs: start.toString(), }, }); - + let bestQuote; if (!requestBody.forceOpenOrder) { bestQuote = await getBestQuote(quoters, request.toQuoteRequest(), log, metric, 'HardResponse'); @@ -107,14 +107,14 @@ export class QuoteHandler extends APIGLambdaHandler< metric.putMetric(Metric.QUOTE_LATENCY, Date.now() - start, MetricLoggerUnit.Milliseconds); const hardResponse = new HardQuoteResponse(request, cosignedOrder); if (!bestQuote) { - // The RFQ responses are logged in getBestQuote() + // The RFQ responses are logged in getBestQuote() // we log the Open Orders here log.info({ eventType: 'QuoteResponse', body: { ...hardResponse.toLog(), - offerer: request.swapper - } + offerer: request.swapper, + }, }); } return { diff --git a/lib/handlers/hard-quote/index.ts b/lib/handlers/hard-quote/index.ts index 7361207..a60e1b1 100644 --- a/lib/handlers/hard-quote/index.ts +++ b/lib/handlers/hard-quote/index.ts @@ -1,3 +1,3 @@ export { QuoteHandler as HardQuoteHandler } from './handler'; -export { RequestInjected, ContainerInjected, QuoteInjector as HardQuoteInjector } from './injector'; +export { ContainerInjected, QuoteInjector as HardQuoteInjector, RequestInjected } from './injector'; export * from './schema'; diff --git a/lib/providers/analytics/firehose.ts b/lib/providers/analytics/firehose.ts index bedea91..1dea906 100644 --- a/lib/providers/analytics/firehose.ts +++ b/lib/providers/analytics/firehose.ts @@ -1,8 +1,8 @@ import { FirehoseClient, PutRecordCommand } from '@aws-sdk/client-firehose'; import { default as Logger } from 'bunyan'; -import { AnalyticsEvent } from '../../entities/analytics-events'; import { IAnalyticsLogger } from '.'; +import { AnalyticsEvent } from '../../entities/analytics-events'; export class FirehoseLogger implements IAnalyticsLogger { private log: Logger; diff --git a/lib/util/chains.ts b/lib/util/chains.ts index 0f70fcc..b8d69af 100644 --- a/lib/util/chains.ts +++ b/lib/util/chains.ts @@ -25,8 +25,8 @@ export const ID_TO_NETWORK_NAME = (id: number): ChainName => { return ChainName.POLYGON; case 11155111: return ChainName.SEPOLIA; - case 42161: - return ChainName.ARBITRUM_ONE; + case 42161: + return ChainName.ARBITRUM_ONE; default: throw new Error(`Unknown chain id: ${id}`); }