From aca80b416f93d54b7fdd3adeb7f444aac625940f Mon Sep 17 00:00:00 2001 From: Juan Cazala Date: Fri, 20 Sep 2024 10:26:13 -0300 Subject: [PATCH] fix: set correct buyer for sales done by thid parties (#2297) * fix: set correct buyer for sales done by thid parties * fix: erc721 abi --- indexer/.prettierrc | 6 ++++++ indexer/.subgraph.yaml | 4 ++++ indexer/src/modules/analytics/index.ts | 25 ++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 indexer/.prettierrc diff --git a/indexer/.prettierrc b/indexer/.prettierrc new file mode 100644 index 0000000000..2f82a26d09 --- /dev/null +++ b/indexer/.prettierrc @@ -0,0 +1,6 @@ +{ + "tabWidth": 2, + "semi": false, + "singleQuote": true, + "printWidth": 80 +} \ No newline at end of file diff --git a/indexer/.subgraph.yaml b/indexer/.subgraph.yaml index 5347cb7674..e2f6c2e9b4 100644 --- a/indexer/.subgraph.yaml +++ b/indexer/.subgraph.yaml @@ -116,6 +116,8 @@ dataSources: abis: - name: Marketplace file: ./abis/Marketplace.json + - name: ERC721 + file: ./abis/ERC721.json eventHandlers: - event: OrderCreated(bytes32,indexed uint256,indexed address,address,uint256,uint256) handler: handleOrderCreated @@ -187,6 +189,8 @@ dataSources: entities: - Bid abis: + - name: ERC721 + file: ./abis/ERC721.json - name: ERC721Bid file: ./abis/ERC721Bid.json eventHandlers: diff --git a/indexer/src/modules/analytics/index.ts b/indexer/src/modules/analytics/index.ts index ede87b9a58..2d556b87d9 100644 --- a/indexer/src/modules/analytics/index.ts +++ b/indexer/src/modules/analytics/index.ts @@ -1,5 +1,6 @@ import { Address, BigInt, Bytes, log } from '@graphprotocol/graph-ts' import { NFT, Sale, AnalyticsDayData } from '../../entities/schema' +import { ERC721 } from '../../entities/templates/ERC721/ERC721' import { createOrLoadAccount } from '../account' import { buildCountFromSale } from '../count' import { ONE_MILLION } from '../utils' @@ -7,6 +8,17 @@ import { ONE_MILLION } from '../utils' export let BID_SALE_TYPE = 'bid' export let ORDER_SALE_TYPE = 'order' +// check if the buyer in a sale was a third party provider (to pay with credit card, cross chain, etc) +export function isThirdPartySale(buyer: string): boolean { + if ( + buyer == '0xed038688ecf1193f8d9717eb3930f0bf0d745cb4' || // Transak Polygon + buyer == '0xea749fd6ba492dbc14c24fe8a3d08769229b896c' // Axelar Polygon & Ethereum + ) { + return true + } + return false +} + export function trackSale( type: string, buyer: Address, @@ -28,6 +40,15 @@ export function trackSale( // load entities let nft = NFT.load(nftId) + if (!nft) { + return + } + + // check if the buyer is a third party and update it if so + if (isThirdPartySale(buyer.toHexString())) { + let erc721 = ERC721.bind(Address.fromString(nft.contractAddress.toHex())) + buyer = erc721.ownerOf(nft.tokenId) + } // save sale let saleId = BigInt.fromI32(count.salesTotal).toString() @@ -67,7 +88,9 @@ export function trackSale( analyticsDayData.save() } -export function getOrCreateAnalyticsDayData(blockTimestamp: BigInt): AnalyticsDayData { +export function getOrCreateAnalyticsDayData( + blockTimestamp: BigInt +): AnalyticsDayData { let timestamp = blockTimestamp.toI32() let dayID = timestamp / 86400 // unix timestamp for start of day / 86400 giving a unique day index let dayStartTimestamp = dayID * 86400