Skip to content

Commit

Permalink
fix: set correct buyer for sales done by thid parties (#2297)
Browse files Browse the repository at this point in the history
* fix: set correct buyer for sales done by thid parties

* fix: erc721 abi
  • Loading branch information
cazala authored Sep 20, 2024
1 parent 5a0a21a commit aca80b4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
6 changes: 6 additions & 0 deletions indexer/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"printWidth": 80
}
4 changes: 4 additions & 0 deletions indexer/.subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -187,6 +189,8 @@ dataSources:
entities:
- Bid
abis:
- name: ERC721
file: ./abis/ERC721.json
- name: ERC721Bid
file: ./abis/ERC721Bid.json
eventHandlers:
Expand Down
25 changes: 24 additions & 1 deletion indexer/src/modules/analytics/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
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'

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,
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit aca80b4

Please sign in to comment.