Skip to content

Commit

Permalink
Fix for anvil's lack of estimateGas reason string
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively committed Apr 24, 2023
1 parent 5072940 commit 1577fdb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
8 changes: 8 additions & 0 deletions app/src/Liquidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions app/src/index-sim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.:
/*
Expand Down
2 changes: 1 addition & 1 deletion app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions app/src/sim/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -109,7 +109,7 @@ export async function web3WithWebsocketProvider(
return web3;
} catch (e) {
console.error(e);
await sleep(100);
await sleep(1000);
}
}
throw new Error(
Expand Down

0 comments on commit 1577fdb

Please sign in to comment.