UNPKG

mev-inspect

Version:

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

89 lines 4.2 kB
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _Inspector_instances, _Inspector_getMev; import Chain from './chain.js'; import classify from './classifier/index.js'; import { fetchPools, fetchNftPools, fetchMarkets } from './fetch.js'; import { getArbitrages, getJitSandwiches, getSeizures, getLiquidations, getLiquidityDeposits, getLiquidityWithdrawals, getRepayments, getSandwiches, getSwaps, getNftSwaps, getNftArbitrages, getTransfers, } from './mev/index.js'; import { groupBy } from './utils.js'; class Inspector { constructor(chainId, provider) { _Inspector_instances.add(this); Object.defineProperty(this, "chainId", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "provider", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "chain", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.chainId = chainId; this.provider = provider; this.chain = new Chain(provider); } async tx(hash) { const logs = await this.chain.getTransactionLogs(hash); return await __classPrivateFieldGet(this, _Inspector_instances, "m", _Inspector_getMev).call(this, logs); } async block(number) { const logs = await this.chain.getBlockLogs(number); return await __classPrivateFieldGet(this, _Inspector_instances, "m", _Inspector_getMev).call(this, logs); } async receipts(receipts) { const logs = this.chain.parseReceipts(receipts); const logsByBlock = groupBy(logs, (log) => log.blockNumber.toString()); const mev = []; for (const block in logsByBlock) { const blockLogs = logsByBlock[block]; const blockMev = await __classPrivateFieldGet(this, _Inspector_instances, "m", _Inspector_getMev).call(this, blockLogs); for (const mevItem of blockMev) { mev.push(mevItem); } } return mev; } } _Inspector_instances = new WeakSet(), _Inspector_getMev = async function _Inspector_getMev(logs) { if (logs.length === 0) { return []; } const block = logs[0].blockNumber; const events = classify(this.chainId, logs); const pools = await fetchPools(this.chainId, this.provider, events); const transfers = getTransfers(events); const swaps = getSwaps(this.chainId, pools, transfers, events); const arbitrages = getArbitrages(swaps); const markets = await fetchMarkets(this.chainId, this.provider, events); const repayments = getRepayments(this.chainId, markets, events); const seizures = getSeizures(this.chainId, markets, events); const liquidations = getLiquidations(repayments, seizures); const liquidityDeposits = getLiquidityDeposits(this.chainId, pools, transfers, events); const liquidityWithdrawals = getLiquidityWithdrawals(this.chainId, pools, transfers, events); const sandwiches = getSandwiches(this.chainId, swaps, liquidityDeposits, liquidityWithdrawals); const jitSandwiches = getJitSandwiches(swaps, liquidityDeposits, liquidityWithdrawals); const nftPools = await fetchNftPools(this.chainId, this.provider, events, block); const nftSwaps = getNftSwaps(this.chainId, nftPools, events, logs); const nftArbitrages = getNftArbitrages(nftSwaps); return [ ...arbitrages, ...liquidations, ...sandwiches, ...jitSandwiches, ...nftArbitrages, ]; }; export default Inspector; //# sourceMappingURL=inspector.js.map