Skip to content

Commit

Permalink
Merge branch 'master' into 2024-12-02-l1-gas
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt authored Dec 19, 2024
2 parents d947f8b + a02af84 commit d27b3ed
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
20 changes: 11 additions & 9 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
25 changes: 9 additions & 16 deletions src/processOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProcessPairResult>;
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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,
};
};

/**
Expand Down
4 changes: 3 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d27b3ed

Please sign in to comment.