From 85d14483cb0ca7df107fe1e62e6c1876218270e4 Mon Sep 17 00:00:00 2001 From: Shredder <110225819+EmperorOrokuSaki@users.noreply.github.com> Date: Tue, 2 May 2023 19:19:02 +0330 Subject: [PATCH] fix: decrement total tokens by one for each burn, fix the collection id, remove tokens field of git repo in the mapping file. (#249) --- subgraph/src/contract.ts | 4 ++-- subgraph/src/mint.ts | 10 +--------- subgraph/src/transfer.ts | 12 ++++++++++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/subgraph/src/contract.ts b/subgraph/src/contract.ts index 0162ee9..824e0fe 100644 --- a/subgraph/src/contract.ts +++ b/subgraph/src/contract.ts @@ -1,4 +1,4 @@ -import { log, ethereum, BigInt } from '@graphprotocol/graph-ts'; +import { log, ethereum, BigInt, Address } from '@graphprotocol/graph-ts'; // Event Imports [based on the yaml config] import { Initialized as InitializedEvent } from '../generated/FleekNFA/FleekNFA'; @@ -15,7 +15,7 @@ export function handleInitialized(event: InitializedEvent): void { ]); // start collection entity - const collection = new Collection(event.address.toHexString()); + const collection = new Collection(event.address); collection.totalTokens = BigInt.fromU32(0); collection.save(); diff --git a/subgraph/src/mint.ts b/subgraph/src/mint.ts index 64e1a77..c0b3472 100644 --- a/subgraph/src/mint.ts +++ b/subgraph/src/mint.ts @@ -92,16 +92,8 @@ export function handleNewMint(event: NewMintEvent): void { repository = new GitRepository(gitRepository); } - let repositoryTokens = repository.tokens; - if (repositoryTokens === null) { - repositoryTokens = [token.id]; - } else { - repositoryTokens.push(token.id); - } - repository.tokens = repositoryTokens; - // Increase total tokens counter - const collection = Collection.load(event.address.toHexString()); + const collection = Collection.load(event.address); if (collection) { collection.totalTokens = collection.totalTokens.plus(BigInt.fromU32(1)); collection.save(); diff --git a/subgraph/src/transfer.ts b/subgraph/src/transfer.ts index ec49ba8..c7fe98a 100644 --- a/subgraph/src/transfer.ts +++ b/subgraph/src/transfer.ts @@ -1,10 +1,10 @@ -import { Bytes, log, store } from '@graphprotocol/graph-ts'; +import { BigInt, Bytes, log, store } from '@graphprotocol/graph-ts'; // Event Imports [based on the yaml config] import { Transfer as TransferEvent } from '../generated/FleekNFA/FleekNFA'; // Entity Imports [based on the schema] -import { Owner, Token, Transfer } from '../generated/schema'; +import { Collection, Owner, Token, Transfer } from '../generated/schema'; export function handleTransfer(event: TransferEvent): void { const transfer = new Transfer( @@ -39,6 +39,14 @@ export function handleTransfer(event: TransferEvent): void { // Remove the entity from storage // Its controllers and owner will be affected. store.remove('Token', TokenId.toString()); + // decrement the collection entity's token count + const collection = Collection.load(event.address); + if (collection) { + collection.totalTokens = collection.totalTokens.minus( + BigInt.fromU32(1) + ); + collection.save(); + } } else { // Transfer // Load the Token by using its TokenId