UNPKG

mev-inspect

Version:

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

111 lines 3.55 kB
import exchangeAbi from '../../abi/openseaSeaport.js'; import { nativeAsset } from '../index.js'; function isValid(event) { return event.name === 'OrderFulfilled'; } function getPoolCalls() { return []; } function processPoolCalls(_results, address) { return { factoryAddress: address.toLowerCase(), asset: '', collection: '', metadata: {}, }; } function parse(pool, event, chainId) { const { values, transactionFrom, transactionHash: hash, transactionIndex, gasUsed, logIndex, address, blockHash, blockNumber, } = event; const offerer = values.offerer.toLowerCase(); const recipient = values.recipient.toLowerCase(); const offer = values.offer; const consideration = values.consideration; // Filter out fee, royalty, and other payments const recipientConsideration = consideration.filter((item) => item.recipient.toLowerCase() === offerer); if (offer.length !== 1 || recipientConsideration.length !== 1) { // Only single item trades are supported return null; } const spentItem = offer[0]; const receivedItem = recipientConsideration[0]; const considerationAmount = consideration.reduce((total, item) => total + item.amount, 0n); const feeAmount = considerationAmount - receivedItem.amount; const from = recipient; const to = recipient; return { contract: { address: pool.address, protocol: { abi: 'OpenseaSeaport', factory: pool.factory, }, }, block: { hash: blockHash, number: blockNumber, }, transaction: { from: transactionFrom.toLowerCase(), hash, index: transactionIndex, gasUsed, }, event: { address: address.toLowerCase(), logIndex, }, from, to, assetIn: receivedItem.itemType === 0n ? { type: 'erc20', address: nativeAsset[chainId], } : receivedItem.itemType === 1n ? { type: 'erc20', address: spentItem.token.toLowerCase(), } : { type: 'erc721', collection: receivedItem.token.toLowerCase(), id: receivedItem.identifier, }, amountIn: receivedItem.itemType < 2 ? considerationAmount : considerationAmount - feeAmount, assetOut: spentItem.itemType === 0n ? { type: 'erc20', address: nativeAsset[chainId], } : spentItem.itemType === 1n ? { type: 'erc20', address: spentItem.token.toLowerCase(), } : { type: 'erc721', collection: spentItem.token.toLowerCase(), id: spentItem.identifier, }, amountOut: receivedItem.itemType < 2 ? spentItem.amount : spentItem.amount - feeAmount, }; } const CLASSIFIER = { nftSwap: { type: 'nft_swap', protocol: 'OpenseaSeaport', abi: exchangeAbi, isValid, parse, pool: { getCalls: getPoolCalls, processCalls: processPoolCalls, }, }, }; export default CLASSIFIER; //# sourceMappingURL=openseaSeaport.js.map