From 4a8ffbf4f889b3b9c8da21eae2409b3b62020286 Mon Sep 17 00:00:00 2001 From: rouzwelt Date: Wed, 11 Dec 2024 05:07:32 +0000 Subject: [PATCH 1/2] update --- src/error.ts | 20 +++++++++++--------- src/processOrders.ts | 25 +++++++++---------------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/error.ts b/src/error.ts index 83bebcf1..e8576204 100644 --- a/src/error.ts +++ b/src/error.ts @@ -337,18 +337,20 @@ export async function hasFrontrun( } })(); if (orderConfig) { - const logs = await viemClient.getLogs({ - event: TakeOrderV2EventAbi[0], - address: orderbook, - blockHash: receipt.blockHash, - }); - const otherLogs = logs.filter( + const txHash = receipt.transactionHash.toLowerCase(); + const logs = ( + await viemClient.getLogs({ + event: TakeOrderV2EventAbi[0], + address: orderbook, + blockHash: receipt.blockHash, + }) + ).filter( (v) => receipt.transactionIndex > v.transactionIndex && - v.transactionHash.toLowerCase() !== receipt.transactionHash.toLowerCase(), + v.transactionHash.toLowerCase() !== txHash, ); - if (otherLogs.length) { - for (const log of otherLogs) { + if (logs.length) { + for (const log of logs) { if (isDeepStrictEqual(log.args.config, orderConfig)) return log.transactionHash; } } diff --git a/src/processOrders.ts b/src/processOrders.ts index 30d4e90d..05bcacd2 100644 --- a/src/processOrders.ts +++ b/src/processOrders.ts @@ -157,7 +157,7 @@ export const processOrders = async ( throw errorSnapshot("Failed to batch quote orders", e); } - let avgGasCost: BigNumber | undefined; + const txGasCosts: BigNumber[] = []; const reports: Report[] = []; const results: { settle: () => Promise; @@ -239,6 +239,7 @@ export const processOrders = async ( for (const { settle, pair, orderPairObject } of results) { // instantiate a span for this pair const span = tracer.startSpan(`order_${pair}`, undefined, ctx); + span.setAttribute("details.owner", orderPairObject.takeOrders[0].takeOrder.order.owner); try { // settle the process results // this will return the report of the operation and in case @@ -248,11 +249,7 @@ export const processOrders = async ( // keep track of avg gas cost if (result.gasCost) { - if (!avgGasCost) { - avgGasCost = result.gasCost; - } else { - avgGasCost = avgGasCost.add(result.gasCost).div(2); - } + txGasCosts.push(result.gasCost); } reports.push(result.report); @@ -277,15 +274,6 @@ export const processOrders = async ( span.setStatus({ code: SpanStatusCode.ERROR, message: "unexpected error" }); } } catch (e: any) { - // keep track of avg gas cost - if (e.gasCost) { - if (!avgGasCost) { - avgGasCost = e.gasCost; - } else { - avgGasCost = avgGasCost.add(e.gasCost).div(2); - } - } - // set the span attributes with the values gathered at processPair() span.setAttributes(e.spanAttributes); @@ -419,7 +407,12 @@ export const processOrders = async ( } span.end(); } - return { reports, avgGasCost }; + return { + reports, + avgGasCost: txGasCosts.length + ? txGasCosts.reduce((a, b) => a.add(b), ethers.constants.Zero).div(txGasCosts.length) + : undefined, + }; }; /** From a02af8414d8c4b56dfe213a6650b36cf6fd7e65e Mon Sep 17 00:00:00 2001 From: rouzwelt Date: Tue, 17 Dec 2024 01:50:29 +0000 Subject: [PATCH 2/2] update --- src/utils.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index e55991f7..2d8dfba9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -515,7 +515,9 @@ export const visualizeRoute = (fromToken: Token, toToken: Token, legs: RouteLeg[ (e) => e.tokenFrom.address.toLowerCase() === portions.at(-1)?.tokenTo.address.toLowerCase() && - !portions.includes(e), + portions.every( + (k) => k.poolAddress.toLowerCase() !== e.poolAddress.toLowerCase(), + ), ); if (legPortion) { portions.push(legPortion);