Skip to content

Commit

Permalink
Merge pull request #17 from aavegotchi/feat/contractStats
Browse files Browse the repository at this point in the history
added stats for contracts
  • Loading branch information
cinnabarhorse authored Feb 6, 2023
2 parents 2054707 + 5d9110e commit 3ef19d1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
13 changes: 13 additions & 0 deletions src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
getOrCreateAuction,
getOrCreateBid,
getOrCreateIncentive,
getOrCreateStatistics,
getOrCreateUser,
updateProceeds,
} from "./helper";
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 3ef19d1

Please sign in to comment.