Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt committed Jan 16, 2025
1 parent 6a38f01 commit 31ce5d8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 46 deletions.
22 changes: 7 additions & 15 deletions src/modes/interOrderbook.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { orderbookAbi } from "../abis";
import { estimateGasCost } from "../gas";
import { BaseError, PublicClient } from "viem";
import { BigNumber, Contract, ethers } from "ethers";
import { containsNodeError, errorSnapshot } from "../error";
import { getBountyEnsureRainlang, parseRainlang } from "../task";
import { BaseError, ExecutionRevertedError, PublicClient } from "viem";
import { BotConfig, BundledOrders, ViemClient, DryrunResult, SpanAttrs } from "../types";
import {
ONE18,
Expand Down Expand Up @@ -175,6 +175,12 @@ export async function dryrun({
gasLimit = ethers.BigNumber.from(estimation.gas)
.mul(config.gasLimitMultiplier)
.div(100);
if (gasLimit.isZero()) {
throw new ExecutionRevertedError({
message:
"Failed to estimated gas, rpc returned 0 for gasEstimate call without rejection",
});
}
rawtx.gas = gasLimit.toBigInt();
gasCost = gasLimit.mul(gasPrice).add(estimation.l1Cost);
task.evaluable.bytecode = await parseRainlang(
Expand Down Expand Up @@ -214,20 +220,6 @@ export async function dryrun({
return Promise.reject(result);
}
}
if (gasLimit.isZero()) {
spanAttributes["stage"] = 2;
spanAttributes["isNodeError"] = true;
spanAttributes["error"] =
"Failed to estimated gas, rpc returned 0 for gasEstimate call without rejection";
spanAttributes["rawtx"] = JSON.stringify(
{
...rawtx,
from: signer.account.address,
},
withBigintSerializer,
);
return Promise.reject(result);
}
rawtx.gas = gasLimit.toBigInt();

// if reached here, it means there was a success and found opp
Expand Down
22 changes: 7 additions & 15 deletions src/modes/intraOrderbook.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { orderbookAbi } from "../abis";
import { estimateGasCost } from "../gas";
import { BigNumber, ethers } from "ethers";
import { BaseError, erc20Abi, PublicClient } from "viem";
import { containsNodeError, errorSnapshot } from "../error";
import { getWithdrawEnsureRainlang, parseRainlang } from "../task";
import { BaseError, erc20Abi, ExecutionRevertedError, PublicClient } from "viem";
import { estimateProfit, scale18, withBigintSerializer, extendSpanAttributes } from "../utils";
import {
SpanAttrs,
Expand Down Expand Up @@ -177,6 +177,12 @@ export async function dryrun({
gasLimit = ethers.BigNumber.from(estimation.gas)
.mul(config.gasLimitMultiplier)
.div(100);
if (gasLimit.isZero()) {
throw new ExecutionRevertedError({
message:
"Failed to estimated gas, rpc returned 0 for gasEstimate call without rejection",
});
}
rawtx.gas = gasLimit.toBigInt();
gasCost = gasLimit.mul(gasPrice).add(estimation.l1Cost);
task.evaluable.bytecode = await parseRainlang(
Expand Down Expand Up @@ -225,20 +231,6 @@ export async function dryrun({
return Promise.reject(result);
}
}
if (gasLimit.isZero()) {
spanAttributes["stage"] = 2;
spanAttributes["isNodeError"] = true;
spanAttributes["error"] =
"Failed to estimated gas, rpc returned 0 for gasEstimate call without rejection";
spanAttributes["rawtx"] = JSON.stringify(
{
...rawtx,
from: signer.account.address,
},
withBigintSerializer,
);
return Promise.reject(result);
}
rawtx.gas = gasLimit.toBigInt();

// if reached here, it means there was a success and found opp
Expand Down
23 changes: 7 additions & 16 deletions src/modes/routeProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Token } from "sushi/currency";
import { estimateGasCost } from "../gas";
import { BaseError, PublicClient } from "viem";
import { ChainId, DataFetcher, Router } from "sushi";
import { BigNumber, Contract, ethers } from "ethers";
import { containsNodeError, errorSnapshot } from "../error";
import { getBountyEnsureRainlang, parseRainlang } from "../task";
import { BaseError, ExecutionRevertedError, PublicClient } from "viem";
import { SpanAttrs, BotConfig, ViemClient, DryrunResult, BundledOrders } from "../types";
import {
ONE18,
Expand Down Expand Up @@ -241,6 +241,12 @@ export async function dryrun({
gasLimit = ethers.BigNumber.from(estimation.gas)
.mul(config.gasLimitMultiplier)
.div(100);
if (gasLimit.isZero()) {
throw new ExecutionRevertedError({
message:
"Failed to estimated gas, rpc returned 0 for gasEstimate call without rejection",
});
}
rawtx.gas = gasLimit.toBigInt();
gasCost = gasLimit.mul(gasPrice).add(estimation.l1Cost);
task.evaluable.bytecode = await parseRainlang(
Expand Down Expand Up @@ -281,21 +287,6 @@ export async function dryrun({
return Promise.reject(result);
}
}
if (gasLimit.isZero()) {
spanAttributes["stage"] = 2;
spanAttributes["isNodeError"] = true;
spanAttributes["error"] =
"Failed to estimated gas, rpc returned 0 for gasEstimate call without rejection";
spanAttributes["rawtx"] = JSON.stringify(
{
...rawtx,
from: signer.account.address,
},
withBigintSerializer,
);
result.reason = RouteProcessorDryrunHaltReason.NoOpportunity;
return Promise.reject(result);
}
rawtx.gas = gasLimit.toBigInt();

// if reached here, it means there was a success and found opp
Expand Down

0 comments on commit 31ce5d8

Please sign in to comment.