From 1577fdbafe2b801783520c7358861a994f5ab838 Mon Sep 17 00:00:00 2001 From: Hayden Shively <17186559+haydenshively@users.noreply.github.com> Date: Mon, 24 Apr 2023 01:10:06 -0500 Subject: [PATCH] Fix for anvil's lack of estimateGas reason string --- app/src/Liquidator.ts | 8 ++++++++ app/src/index-sim.ts | 4 ++-- app/src/index.ts | 2 +- app/src/sim/Utils.ts | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/Liquidator.ts b/app/src/Liquidator.ts index c8cd8f1..9be6bd9 100644 --- a/app/src/Liquidator.ts +++ b/app/src/Liquidator.ts @@ -280,6 +280,14 @@ export default class Liquidator { .estimateGas({ gasLimit: Liquidator.GAS_LIMIT, }); + if (process.env.SIM && estimatedGasLimit < 23000) { + return { + success: false, + estimatedGas: estimatedGasLimit, + error: LiquidationError.Unknown, + errorMsg: "Anvil doesn't bubble-up reverts when estimating gas, so we have no clue what's happening" + } + } return { success: true, estimatedGas: estimatedGasLimit, diff --git a/app/src/index-sim.ts b/app/src/index-sim.ts index 6cade46..04236c8 100644 --- a/app/src/index-sim.ts +++ b/app/src/index-sim.ts @@ -12,14 +12,14 @@ import { const alchemy_key = process.env.ALCHEMY_API_KEY; const anvil = startAnvil({ forkUrl: `https://opt-mainnet.g.alchemy.com/v2/${alchemy_key}`, - forkBlockNumber: Number(process.argv[2]), // e.g. 79537361 + forkBlockNumber: Number(process.argv[2]), // e.g. 92975261 blockTime: 5, baseFee: 1, }); nextStdoutMsg(anvil).then(async () => { // `await` this to make sure things are good to go - const web3 = await web3WithWebsocketProvider("ws://localhost:8545"); + const web3 = await web3WithWebsocketProvider("ws://127.0.0.1:8545"); // NOTE: We can do all the usual things with this `web3` instance, e.g.: /* diff --git a/app/src/index.ts b/app/src/index.ts index 34fe4e5..324341b 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -23,7 +23,7 @@ const limiter = new Bottleneck({ }); const LIQUIDATOR_ADDRESS = process.env.LIQUIDATOR_ADDRESS!; const liquidators: Liquidator[] = process.env.SIM === 'true' - ? [new Liquidator("ws://localhost:8545", LIQUIDATOR_ADDRESS, limiter)] + ? [new Liquidator("ws://127.0.0.1:8545", LIQUIDATOR_ADDRESS, limiter)] : [ new Liquidator(OPTIMISM_ALCHEMY_URL, LIQUIDATOR_ADDRESS, limiter), new Liquidator(ARBITRUM_ALCHEMY_URL, LIQUIDATOR_ADDRESS, limiter), diff --git a/app/src/sim/Utils.ts b/app/src/sim/Utils.ts index 96b81ba..1e8eafb 100644 --- a/app/src/sim/Utils.ts +++ b/app/src/sim/Utils.ts @@ -98,7 +98,7 @@ export function startAnvil( export async function web3WithWebsocketProvider( url: string, - connectionAttempts = 5 + connectionAttempts = 10 ) { for (let i = 0; i < connectionAttempts; i += 1) { try { @@ -109,7 +109,7 @@ export async function web3WithWebsocketProvider( return web3; } catch (e) { console.error(e); - await sleep(100); + await sleep(1000); } } throw new Error(