From a14a0d07feffb77930cb7c400123ea210c366d91 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 22 Aug 2022 11:48:40 -0700 Subject: [PATCH] updating seaport scraping to account for weth accepted --- src/scraper.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/scraper.js b/src/scraper.js index 3ae5b30..e4a460a 100644 --- a/src/scraper.js +++ b/src/scraper.js @@ -177,23 +177,25 @@ class Scrape extends Collection { let tokenId; if (log.topics[0].toLowerCase() === SEAPORT_SALE_TOPIC.toLowerCase()) { // Handle Opensea/Seaport sales - const logDescription = seaportInterface.parseLog(log) - const matchingOffers = logDescription.args.offer.filter( + const logDescription = seaportInterface.parseLog(log); + // skip if not logs do not match contract address + const matchingOffers = logDescription.args.consideration.filter( o => o.token.toLowerCase() == this.contractAddress.toLowerCase() ); if (matchingOffers.length === 0) return; + const ethOffer = logDescription.args.offer.map( + o => (o.token.toLowerCase() === this.contractAddress.toLowerCase() && o.amount > 0) ? BigInt(o.amount) : BigInt(0) + ); + const wethOffer = logDescription.args.offer.map( + o => (o.token.toLowerCase() === WETH_ADDRESS.toLowerCase() && o.amount > 0) ? BigInt(o.amount) : BigInt(0) + ); + const allOffers = ethOffer.concat(wethOffer); sale = true; platform = 'opensea'; fromAddress = logDescription.args.offerer.toLowerCase(); toAddress = logDescription.args.recipient.toLowerCase(); tokenId = logDescription.args.offer.map(o => o.identifier.toString()); - let amounts = logDescription.args.consideration.map(c => BigInt(c.amount)); - // add weth - const wethOffers = matchingOffers.map(o => o.token.toLowerCase() === WETH_ADDRESS.toLowerCase() && o.amount > 0 ? BigInt(o.amount) : BigInt(0)); - if (wethOffers.length > 0 && wethOffers[0] != BigInt(0)) { - amounts = wethOffers - } - amountWei = amounts.reduce((previous,current) => previous + current, BigInt(0)); + amountWei = allOffers.reduce((prev, curr) => prev + curr, BigInt(0)); } else if (log.topics[0].toLowerCase() === WYVERN_SALE_TOPIC.toLowerCase()) { // Handle Opensea/Wyvern sales const logDescription = wyvernInterface.parseLog(log);