Skip to content

Commit

Permalink
fix: init issue
Browse files Browse the repository at this point in the history
  • Loading branch information
orionstardust committed Mar 21, 2024
1 parent ec12631 commit fdb84cf
Showing 1 changed file with 97 additions and 97 deletions.
194 changes: 97 additions & 97 deletions src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ export function handleAuction_Initialized(
auction.startsAt = auctionInfo.info.startTime;
auction.endsAt = auctionInfo.info.endTime;
auction.endsAtOriginal = auctionInfo.info.endTime;
auction.buyNowPrice = auctionInfo.info.buyItNowPrice;
auction.startBidPrice = auctionInfo.info.startingBid;
auction.buyNowPrice = auctionInfo.buyItNowPrice;
auction.startBidPrice = auctionInfo.startingBid;

// auction.claimAt =
auction.highestBidder = auctionInfo.highestBidder;
Expand Down Expand Up @@ -541,110 +541,110 @@ export function handleContract_RoyaltyPaid(event: RoyaltyPaidEvent): void {
export function handleAuction_BuyItNowUpdated(
event: Auction_BuyItNowUpdatedEvent
): void {
// emitter
let emitter = getOrCreateUser(event.transaction.from);
emitter.save();

// event
let ev = new Auction_BuyItNowUpdated(events.id(event));
ev.emitter = emitter.id;
ev.transaction = transactions.log(event).id;
ev.timestamp = event.block.timestamp;

ev.auctionId = event.params._auctionId;
ev.buyNowPrice = event.params._buyItNowPrice;
ev.save();

// update entity
let entity = getOrCreateAuction(event.params._auctionId, event);
if (!entity) {
log.warning("auction with id {} not found", [
event.params._auctionId.toString(),
]);
return;
}
entity.buyNowPrice = event.params._buyItNowPrice;
entity.save();
// // emitter
// let emitter = getOrCreateUser(event.transaction.from);
// emitter.save();
//
// // event
// let ev = new Auction_BuyItNowUpdated(events.id(event));
// ev.emitter = emitter.id;
// ev.transaction = transactions.log(event).id;
// ev.timestamp = event.block.timestamp;
//
// ev.auctionId = event.params._auctionId;
// ev.buyNowPrice = event.params._buyItNowPrice;
// ev.save();
//
// // update entity
// let entity = getOrCreateAuction(event.params._auctionId, event);
// if (!entity) {
// log.warning("auction with id {} not found", [
// event.params._auctionId.toString(),
// ]);
// return;
// }
// entity.buyNowPrice = event.params._buyItNowPrice;
// entity.save();
}

export function handleAuction_StartingPriceUpdated(
event: Auction_StartingPriceUpdatedEvent
): void {
// emitter
let emitter = getOrCreateUser(event.transaction.from);
emitter.save();

// event
let ev = new Auction_StartingPriceUpdated(events.id(event));
ev.emitter = emitter.id;
ev.transaction = transactions.log(event).id;
ev.timestamp = event.block.timestamp;

ev.auctionId = event.params._auctionId;
ev.startBidPrice = event.params._startPrice;
ev.save();

// update entity
let entity = getOrCreateAuction(event.params._auctionId, event);
if (!entity) {
log.warning("auction with id {} not found", [
event.params._auctionId.toString(),
]);
return;
}
entity.startBidPrice = event.params._startPrice;
entity.save();
// let emitter = getOrCreateUser(event.transaction.from);
// emitter.save();
//
// // event
// let ev = new Auction_StartingPriceUpdated(events.id(event));
// ev.emitter = emitter.id;
// ev.transaction = transactions.log(event).id;
// ev.timestamp = event.block.timestamp;
//
// ev.auctionId = event.params._auctionId;
// ev.startBidPrice = event.params._startPrice;
// ev.save();
//
// // update entity
// let entity = getOrCreateAuction(event.params._auctionId, event);
// if (!entity) {
// log.warning("auction with id {} not found", [
// event.params._auctionId.toString(),
// ]);
// return;
// }
// entity.startBidPrice = event.params._startPrice;
// entity.save();
}

export function handleAuction_BoughtNow(
event: Auction_BoughtNowEvent
): void {
// emitter
let emitter = getOrCreateUser(event.transaction.from);
emitter.save();

// event
let ev = new Auction_BoughtNow(events.id(event));
ev.emitter = emitter.id;
ev.transaction = transactions.log(event).id;
ev.timestamp = event.block.timestamp;

ev.auctionId = event.params._auctionId;
ev.save();

// update entity
let auction = getOrCreateAuction(event.params._auctionId, event);
if (!auction) {
log.warning("auction with id {} not found", [
event.params._auctionId.toString(),
]);
return;
}
auction.claimed = true;
auction.claimAt = event.block.timestamp;

let bid = getOrCreateBid(
auction.highestBidder,
auction.highestBid,
auction as Auction,
event
);
bid.outbid = true;

let user = getOrCreateUser(auction.highestBidder);
user.outbids = user.outbids.plus(BigInt.fromI32(1));
user.save();

// Update Stats
let stats = Statistic.load("0")!;
stats.totalSalesVolume = stats.totalSalesVolume.plus(auction.buyNowPrice);
stats.save();

// update contract stats
let cStats = getOrCreateStatistics(auction.contractAddress);
cStats.totalSalesVolume = cStats.totalSalesVolume.plus(auction.buyNowPrice);
cStats.save();

bid.save();
auction.save();
// // emitter
// let emitter = getOrCreateUser(event.transaction.from);
// emitter.save();
//
// // event
// let ev = new Auction_BoughtNow(events.id(event));
// ev.emitter = emitter.id;
// ev.transaction = transactions.log(event).id;
// ev.timestamp = event.block.timestamp;
//
// ev.auctionId = event.params._auctionId;
// ev.save();
//
// // update entity
// let auction = getOrCreateAuction(event.params._auctionId, event);
// if (!auction) {
// log.warning("auction with id {} not found", [
// event.params._auctionId.toString(),
// ]);
// return;
// }
// auction.claimed = true;
// auction.claimAt = event.block.timestamp;
//
// let bid = getOrCreateBid(
// auction.highestBidder,
// auction.highestBid,
// auction as Auction,
// event
// );
// bid.outbid = true;
//
// let user = getOrCreateUser(auction.highestBidder);
// user.outbids = user.outbids.plus(BigInt.fromI32(1));
// user.save();
//
// // Update Stats
// let stats = Statistic.load("0")!;
// stats.totalSalesVolume = stats.totalSalesVolume.plus(auction.buyNowPrice);
// stats.save();
//
// // update contract stats
// let cStats = getOrCreateStatistics(auction.contractAddress);
// cStats.totalSalesVolume = cStats.totalSalesVolume.plus(auction.buyNowPrice);
// cStats.save();
//
// bid.save();
// auction.save();
}

0 comments on commit fdb84cf

Please sign in to comment.