MCPcopy Index your code
hub / github.com/Destiner/mev-inspect-js

github.com/Destiner/mev-inspect-js @v3.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v3.0.0 ↗ · + Follow
255 symbols 487 edges 88 files 0 documented · 0% updated 2y agov3.0.0 · 2022-08-25★ 1355 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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:

  • Written in Typescript: easier to run in browser/node, while keeping the code type-safe
  • Infra layer decoupling: message query, caching, and persistence layers can be added independenty when/if needed
  • Pricing data decoupling: to calculate profit and cost in USD, a pricing provider of your choice can be used
  • Single transaction inspection: while missing some types of MEV, this is helpful for quick transaction review
  • Using logs instead of call traces: any historical node would work

Other, less fundamental, changes include:

  • Fork support (e.g. Sushiswap)
  • Multichain support
  • Abilitiy to "bring your own transaction receipts" (e.g. via Alchemy)

API

  • Inspector
  • constructor(chainId, provider)
  • tx(hash): processes a single transaction given hash
  • block(number): processes a single block given number
  • receipts(receipts): processes an arbitrary amount of transaction receipts
  • getBlock(mev): get MEV block number
  • getTransaction(mev): get MEV transaction hash
  • getArbitrages(mevList): filter out non-arbitrage MEV
  • getLiquidations(mevList): filter out non-liquidation MEV
  • getSandwiches(mevList): filter out non-sandwich MEV
  • getJitSandwiches(mevList): filter out non-JIT liquidity sandwich MEV

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 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
import { ethers } from 'ethers';
import { Inspector } from 'mev-inspect';

const arbitrageTx =
  '0x06387618ee3752bed447f192802895921a7d45a60875927adfedc93a68bcbe05';
const key = process.env.PROVIDER_KEY;
const provider = new ethers.providers.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

  • Arbitrage
  • Liquidations
  • Sandwiches
  • JIT liquidity sandwiches

Chains

  • Ethereum
  • Polygon
  • Arbitrum
  • Optimism
  • Avalanche

Protocols

  • Swaps: Uniswap V2/V3 (+ forks), Balancer V1/V2, Curve V1/V2, 0x V3/V4, Bancor V2/V3
  • Lending: Compound V2 (+ forks), Aave V1/V2/V3

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.

Extension points exported contracts — how you extend this code

Log (Interface)
(no doc)
src/chain.ts
Searcher (Interface)
(no doc)
src/classifier/base.ts
Sandwich (Interface)
(no doc)
src/mev/sandwiches.ts
Transaction (Interface)
(no doc)
examples/sandwiches.ts
Transaction (Interface)
(no doc)
examples/polygon.ts
Transaction (Interface)
(no doc)
examples/nftArbitrages.ts
Transaction (Interface)
(no doc)
examples/arbitrage.ts
Transaction (Interface)
(no doc)
examples/liquidations.ts

Core symbols most depended-on inside this repo

getSandwiches
called by 15
src/utils.ts
getArbitrages
called by 13
src/utils.ts
getEffectivePrice
called by 9
src/classifier/items/sudoswapV1.ts
minByAbs
called by 7
src/utils.ts
equalWithTolerance
called by 6
src/utils.ts
getProvider
called by 6
examples/utils.ts
getLiquidations
called by 5
src/utils.ts
getJitSandwiches
called by 5
src/utils.ts

Shape

Function 189
Interface 50
Method 12
Class 4

Languages

TypeScript100%

Modules by API surface

src/classifier/base.ts28 symbols
src/utils.ts16 symbols
src/classifier/items/balancerV2.ts14 symbols
src/chain.ts11 symbols
src/classifier/directory.ts10 symbols
src/classifier/items/sudoswapV1.ts9 symbols
src/classifier/items/curveV2.ts9 symbols
src/classifier/items/curveV1.ts9 symbols
src/mev/nftArbitrages.ts8 symbols
src/classifier/items/uniswapV3.ts8 symbols
src/classifier/items/balancerV1.ts8 symbols
src/mev/sandwiches.ts7 symbols

For agents

$ claude mcp add mev-inspect-js \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact