Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt committed Jan 27, 2025
1 parent 224dc45 commit 5d527e7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 42 deletions.
19 changes: 19 additions & 0 deletions src/modes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,22 @@ export async function findOpp({
throw result;
}
}

/**
* Records gas estimates for otel span attributes
*/
export function recordGasEstAttrs(
spanAttributes: Record<string, any>,
estimation: any,
config: BotConfig,
headroom: boolean,
) {
const header = headroom ? "headroom" : "final";
spanAttributes[`gasEst.${header}.gasLimit`] = estimation.gas.toString();
spanAttributes[`gasEst.${header}.totalCost`] = estimation.totalGasCost.toString();
spanAttributes[`gasEst.${header}.gasPrice`] = estimation.gasPrice.toString();
if (config.isSpecialL2) {
spanAttributes[`gasEst.${header}.l1Cost`] = estimation.l1Cost.toString();
spanAttributes[`gasEst.${header}.l1GasPrice`] = estimation.l1GasPrice.toString();
}
}
17 changes: 3 additions & 14 deletions src/modes/interOrderbook.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { recordGasEstAttrs } from ".";
import { orderbookAbi } from "../abis";
import { estimateGasCost } from "../gas";
import { BigNumber, Contract, ethers } from "ethers";
Expand Down Expand Up @@ -121,13 +122,7 @@ export async function dryrun({
gasLimit = ethers.BigNumber.from(estimation.gas).mul(config.gasLimitMultiplier).div(100);

// include dryrun headroom gas estimation in otel logs
spanAttributes["gasEst.headroom.gasLimit"] = estimation.gas.toString();
spanAttributes["gasEst.headroom.totalCost"] = estimation.totalGasCost.toString();
spanAttributes["gasEst.headroom.gasPrice"] = estimation.gasPrice.toString();
if (config.isSpecialL2) {
spanAttributes["gasEst.headroom.l1Cost"] = estimation.l1Cost.toString();
spanAttributes["gasEst.headroom.l1GasPrice"] = estimation.l1GasPrice.toString();
}
recordGasEstAttrs(spanAttributes, estimation, config, true);
} catch (e) {
const isNodeError = containsNodeError(e as BaseError);
const errMsg = errorSnapshot("", e);
Expand Down Expand Up @@ -197,13 +192,7 @@ export async function dryrun({
gasCost = gasLimit.mul(gasPrice).add(estimation.l1Cost);

// include dryrun final gas estimation in otel logs
spanAttributes["gasEst.final.gasLimit"] = estimation.gas.toString();
spanAttributes["gasEst.final.totalCost"] = estimation.totalGasCost.toString();
spanAttributes["gasEst.final.gasPrice"] = estimation.gasPrice.toString();
if (config.isSpecialL2) {
spanAttributes["gasEst.final.l1Cost"] = estimation.l1Cost.toString();
spanAttributes["gasEst.final.l1GasPrice"] = estimation.l1GasPrice.toString();
}
recordGasEstAttrs(spanAttributes, estimation, config, false);
task.evaluable.bytecode = await parseRainlang(
await getBountyEnsureRainlang(
ethers.utils.parseUnits(inputToEthPrice),
Expand Down
17 changes: 3 additions & 14 deletions src/modes/intraOrderbook.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { recordGasEstAttrs } from ".";
import { orderbookAbi } from "../abis";
import { estimateGasCost } from "../gas";
import { BigNumber, ethers } from "ethers";
Expand Down Expand Up @@ -119,13 +120,7 @@ export async function dryrun({
gasLimit = ethers.BigNumber.from(estimation.gas).mul(config.gasLimitMultiplier).div(100);

// include dryrun headroom gas estimation in otel logs
spanAttributes["gasEst.headroom.gasLimit"] = estimation.gas.toString();
spanAttributes["gasEst.headroom.totalCost"] = estimation.totalGasCost.toString();
spanAttributes["gasEst.headroom.gasPrice"] = estimation.gasPrice.toString();
if (config.isSpecialL2) {
spanAttributes["gasEst.headroom.l1Cost"] = estimation.l1Cost.toString();
spanAttributes["gasEst.headroom.l1GasPrice"] = estimation.l1GasPrice.toString();
}
recordGasEstAttrs(spanAttributes, estimation, config, true);
} catch (e) {
// reason, code, method, transaction, error, stack, message
const isNodeError = containsNodeError(e as BaseError);
Expand Down Expand Up @@ -205,13 +200,7 @@ export async function dryrun({
gasCost = gasLimit.mul(gasPrice).add(estimation.l1Cost);

// include dryrun final gas estimation in otel logs
spanAttributes["gasEst.final.gasLimit"] = estimation.gas.toString();
spanAttributes["gasEst.final.totalCost"] = estimation.totalGasCost.toString();
spanAttributes["gasEst.final.gasPrice"] = estimation.gasPrice.toString();
if (config.isSpecialL2) {
spanAttributes["gasEst.final.l1Cost"] = estimation.l1Cost.toString();
spanAttributes["gasEst.final.l1GasPrice"] = estimation.l1GasPrice.toString();
}
recordGasEstAttrs(spanAttributes, estimation, config, false);
task.evaluable.bytecode = await parseRainlang(
await getWithdrawEnsureRainlang(
signer.account.address,
Expand Down
17 changes: 3 additions & 14 deletions src/modes/routeProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { recordGasEstAttrs } from ".";
import { Token } from "sushi/currency";
import { estimateGasCost } from "../gas";
import { ChainId, DataFetcher, Router } from "sushi";
Expand Down Expand Up @@ -190,13 +191,7 @@ export async function dryrun({
.div(100);

// include dryrun headroom gas estimation in otel logs
spanAttributes["gasEst.headroom.gasLimit"] = estimation.gas.toString();
spanAttributes["gasEst.headroom.totalCost"] = estimation.totalGasCost.toString();
spanAttributes["gasEst.headroom.gasPrice"] = estimation.gasPrice.toString();
if (config.isSpecialL2) {
spanAttributes["gasEst.headroom.l1Cost"] = estimation.l1Cost.toString();
spanAttributes["gasEst.headroom.l1GasPrice"] = estimation.l1GasPrice.toString();
}
recordGasEstAttrs(spanAttributes, estimation, config, true);
} catch (e) {
// reason, code, method, transaction, error, stack, message
const isNodeError = containsNodeError(e as BaseError);
Expand Down Expand Up @@ -268,13 +263,7 @@ export async function dryrun({
gasCost = gasLimit.mul(gasPrice).add(estimation.l1Cost);

// include dryrun final gas estimation in otel logs
spanAttributes["gasEst.final.gasLimit"] = estimation.gas.toString();
spanAttributes["gasEst.final.totalCost"] = estimation.totalGasCost.toString();
spanAttributes["gasEst.final.gasPrice"] = estimation.gasPrice.toString();
if (config.isSpecialL2) {
spanAttributes["gasEst.final.l1Cost"] = estimation.l1Cost.toString();
spanAttributes["gasEst.final.l1GasPrice"] = estimation.l1GasPrice.toString();
}
recordGasEstAttrs(spanAttributes, estimation, config, false);
task.evaluable.bytecode = await parseRainlang(
await getBountyEnsureRainlang(
ethers.utils.parseUnits(ethPrice),
Expand Down

0 comments on commit 5d527e7

Please sign in to comment.