UNPKG

mev-inspect

Version:

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

132 lines 3.85 kB
import { Contract } from 'ethcall'; import marketAbi from '../../abi/compoundV2Market.js'; import { nativeAsset } from '../directory.js'; const CETH_MARKET = { '0x3d9819210a31b4961b30ef54be2aed79b9c9cd3b': '0x4ddc2d193948926d02f9b1fe9e1daa0718270ed5', }; function isValidRepayment(event) { return event.name === 'RepayBorrow'; } function isValidSeizure(event) { return event.name === 'LiquidateBorrow'; } function getMarketCalls(address) { const marketContract = new Contract(address, marketAbi); const comptrollerCall = marketContract.comptroller(); const underlyingCall = marketContract.underlying(); return [comptrollerCall, underlyingCall]; } function processMarketCalls(chainId, address, result) { const comptroller = result[0]; const underlying = result[1]; if (!comptroller || !underlying) { return null; } const cethMarket = CETH_MARKET[comptroller]; const native = nativeAsset[chainId]; const asset = address === cethMarket ? native : underlying.toLowerCase(); return { poolAddress: comptroller.toLowerCase(), asset, }; } function parseRepayment(market, event) { const { values, transactionFrom, transactionHash: hash, transactionIndex, gasUsed, logIndex, address, blockHash, blockNumber, } = event; const payer = values.payer.toLowerCase(); const borrower = values.borrower.toLowerCase(); const amount = values.repayAmount; const asset = market.asset; return { contract: { address: market.address, protocol: { abi: 'CompoundV2', pool: market.pool, }, }, block: { hash: blockHash, number: blockNumber, }, transaction: { from: transactionFrom.toLowerCase(), hash, index: transactionIndex, gasUsed, }, event: { logIndex, address: address.toLowerCase(), }, payer, borrower, asset: { type: 'erc20', address: asset, }, amount, }; } function parseSeizure(market, event) { const { values, transactionFrom, transactionHash: hash, transactionIndex, gasUsed, logIndex, address, blockHash, blockNumber, } = event; const seizor = values.liquidator.toLowerCase(); const borrower = values.borrower.toLowerCase(); const asset = values.cTokenCollateral.toLowerCase(); const amount = values.seizeTokens; return { contract: { address: market.address, protocol: { abi: 'CompoundV2', pool: market.pool, }, }, block: { hash: blockHash, number: blockNumber, }, transaction: { from: transactionFrom.toLowerCase(), hash, index: transactionIndex, gasUsed, }, event: { logIndex, address: address.toLowerCase(), }, seizor, borrower, asset: { type: 'erc20', address: asset, }, amount, }; } const CLASSIFIERS = { repayment: { type: 'repayment', protocol: 'CompoundV2', abi: marketAbi, isValid: isValidRepayment, parse: parseRepayment, market: { getCalls: getMarketCalls, processCalls: processMarketCalls, }, }, seizure: { type: 'seizure', protocol: 'CompoundV2', abi: marketAbi, isValid: isValidSeizure, parse: parseSeizure, market: { getCalls: getMarketCalls, processCalls: processMarketCalls, }, }, }; export default CLASSIFIERS; //# sourceMappingURL=compoundV2.js.map