diff --git a/src/helper.ts b/src/helper.ts index ee728e4..c0e6629 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -10,7 +10,7 @@ import { Auction_BidRemoved, Contract, } from "../generated/Contract/Contract"; -import { Auction, Bid, Incentive, User } from "../generated/schema"; +import { Auction, Bid, Incentive, Statistic, User } from "../generated/schema"; import { BIGINT_ONE, BIGINT_ZERO } from "./constants"; export function getOrCreateBid( @@ -94,6 +94,7 @@ export function getOrCreateAuction( auction.contractAddress = event.address; auction.totalBidsVolume = BIGINT_ZERO; auction.royaltyFees = BIGINT_ZERO; + auction.totalBids = BIGINT_ZERO; } return auction; @@ -200,3 +201,16 @@ export function updateProceeds(auction: Auction): Auction { return auction; } + +export function getOrCreateStatistics(contractAddress: Bytes): Statistic { + let stats = Statistic.load(contractAddress.toHexString()); + if (!stats) { + stats = new Statistic(contractAddress.toHexString()); + stats.erc1155Auctions = BIGINT_ZERO; + stats.erc721Auctions = BIGINT_ZERO; + stats.totalBidsVolume = BIGINT_ZERO; + stats.totalSalesVolume = BIGINT_ZERO; + } + + return stats; +} diff --git a/src/mapping.ts b/src/mapping.ts index e538118..54edad0 100644 --- a/src/mapping.ts +++ b/src/mapping.ts @@ -32,6 +32,7 @@ import { getOrCreateAuction, getOrCreateBid, getOrCreateIncentive, + getOrCreateStatistics, getOrCreateUser, updateProceeds, } from "./helper"; @@ -104,6 +105,13 @@ export function handleAuction_BidPlaced(event: Auction_BidPlacedEvent): void { stats.totalBidsVolume = stats.totalBidsVolume.plus(event.params._bidAmount); stats.save(); + // update contract stats + let cStats = getOrCreateStatistics(auction.contractAddress); + cStats.totalBidsVolume = cStats.totalBidsVolume.plus( + event.params._bidAmount + ); + cStats.save(); + user.save(); auction.save(); bid.save(); @@ -469,6 +477,11 @@ export function handleAuction_ItemClaimed( stats.totalSalesVolume = stats.totalSalesVolume.plus(auction.highestBid); stats.save(); + // update contract stats + let cStats = getOrCreateStatistics(auction.contractAddress); + cStats.totalSalesVolume = cStats.totalSalesVolume.plus(auction.highestBid); + cStats.save(); + bid.save(); auction.save(); }