Destiner / mev-inspect-js

A JS port of "mev-inspect-py" optimised for ease of use.
MIT License
129 stars 14 forks source link

MEV Inspect

A JS port of mev-inspect-py optimised for ease of use.

Motivation

While mev-inspect-py is great, I believe that there are a few changes can be made to make historical MEV data more accessible. Here are some defining decisions for this port:

Other, less fundamental, changes include:

API

A common data flow is to first fetch all the MEV using any of the Inspector method, then filter it by type using getArbitrages, etc, and finally process each type of MEV separately

Usage

This package requires ethers V6. If you use ethers V5, you need to use mev-inspect V3.

This package uses BigInt. If you use a bundler, you may want to set the build target to es2020.

This package is a pure ESM package. Follow this guide for more info.

npm i mev-inspect
// Ethers V6
import { AlchemyProvider } from 'ethers';
import { Inspector } from 'mev-inspect';

const arbitrageTx =
  '0x06387618ee3752bed447f192802895921a7d45a60875927adfedc93a68bcbe05';
const key = process.env.PROVIDER_KEY;
const provider = new AlchemyProvider(1, key);
const inspector = new Inspector(1, provider);
const txMev = await inspector.tx(arbitrageTx);
console.log(txMev);

For more examlples, see examples.

Support

MEV type

Chains

Protocols

How it works

It starts by fetching all event logs for a given transaction or block. Then, it "sorts" logs based on their source and type. From those logs, it extracts swap data. It then analyzes the swaps to find arbitrage.