From 2bc23278e8ed9b6765c8843665bdeaf3843ed8ee Mon Sep 17 00:00:00 2001 From: Maxime Date: Thu, 25 Jul 2024 08:51:15 -0700 Subject: [PATCH] tentative to add premint tx in token holder entity. FAIL. --- packages/creator-subgraph/README.md | 1 + packages/creator-subgraph/schema.graphql | 1 + .../templates/ZoraCreator1155ImplMappings.ts | 68 +++++++++++++++---- .../creator-subgraph/src/constants/chainid.ts | 4 +- 4 files changed, 57 insertions(+), 17 deletions(-) diff --git a/packages/creator-subgraph/README.md b/packages/creator-subgraph/README.md index d265c19..6d9e8ca 100644 --- a/packages/creator-subgraph/README.md +++ b/packages/creator-subgraph/README.md @@ -6,6 +6,7 @@ Run `yarn` and `yarn build` at root of contracts to build contracts (need `forge Then run `NETWORK=base-sepolia yarn run build` or `NETWORK=base-mainnet yarn run build` to build subgraph in this dir. Then run goldsky command to deploy subgraph. +`cd packages/creator-subgraph` `goldsky subgraph deploy drakula-zora-base-sepolia/0.2.8` And create webhook for subgraph. diff --git a/packages/creator-subgraph/schema.graphql b/packages/creator-subgraph/schema.graphql index 8e50b05..f37d56f 100644 --- a/packages/creator-subgraph/schema.graphql +++ b/packages/creator-subgraph/schema.graphql @@ -447,6 +447,7 @@ type Token1155Holder @entity { lastUpdatedBlock: BigInt! tokenAndContract: ZoraCreateToken! balance: BigInt! + txn: TransactionInfo } ### Protocol Rewards diff --git a/packages/creator-subgraph/src/ERC1155Mappings/templates/ZoraCreator1155ImplMappings.ts b/packages/creator-subgraph/src/ERC1155Mappings/templates/ZoraCreator1155ImplMappings.ts index b8d63f9..dcd6020 100644 --- a/packages/creator-subgraph/src/ERC1155Mappings/templates/ZoraCreator1155ImplMappings.ts +++ b/packages/creator-subgraph/src/ERC1155Mappings/templates/ZoraCreator1155ImplMappings.ts @@ -186,7 +186,8 @@ function _updateHolderTransfer( from: Address, to: Address, id: BigInt, - value: BigInt + value: BigInt, + txn: string | null, ): BigInt { let tokenHolderCountChange = new BigInt(0); if (!to.equals(Address.zero())) { @@ -202,6 +203,9 @@ function _updateHolderTransfer( holder.balance = holder.balance.plus(value); } holder.lastUpdatedBlock = blockNumber; + if (txn) { + holder.txn = txn; + } holder.save(); } else { const fromHolder = Token1155Holder.load( @@ -210,6 +214,9 @@ function _updateHolderTransfer( if (fromHolder) { fromHolder.balance = fromHolder.balance.minus(value); fromHolder.lastUpdatedBlock = blockNumber; + if (txn) { + fromHolder.txn = txn; + } fromHolder.save(); if (fromHolder.balance.equals(BigInt.zero())) { tokenHolderCountChange = tokenHolderCountChange.minus(new BigInt(1)); @@ -294,17 +301,23 @@ export function handleUpdatedToken(event: UpdatedToken): void { // update the minted number and mx number export function handleTransferSingle(event: TransferSingle): void { + const token = ZoraCreateToken.load( + getTokenId(event.address, event.params.id) + ); + + let txn: string | null = null + if (token) { + txn = token.txn; + } + const newHolderNumber = _updateHolderTransfer( event.block.number, event.address, event.params.from, event.params.to, event.params.id, - event.params.value - ); - - const token = ZoraCreateToken.load( - getTokenId(event.address, event.params.id) + event.params.value, + txn ); if (!token) { @@ -329,16 +342,24 @@ export function handleTransferSingle(event: TransferSingle): void { export function handleTransferBatch(event: TransferBatch): void { if (event.params.from.equals(Address.zero())) { for (let i = 0; i < event.params.ids.length; i++) { + const tokenId = getTokenId(event.address, event.params.ids[i]); + const token = ZoraCreateToken.load(tokenId); + + let txn: string | null = null + if (token) { + txn = token.txn; + } + const newTokenHolderBalance = _updateHolderTransfer( event.block.number, event.address, event.params.from, event.params.to, event.params.ids[i], - event.params.values[i] + event.params.values[i], + txn ); - const tokenId = getTokenId(event.address, event.params.ids[i]); - const token = ZoraCreateToken.load(tokenId); + if (token) { token.holders1155Number = token.holders1155Number.plus( newTokenHolderBalance @@ -350,16 +371,24 @@ export function handleTransferBatch(event: TransferBatch): void { } } else if (event.params.to.equals(Address.zero())) { for (let i = 0; i < event.params.ids.length; i++) { + const tokenId = getTokenId(event.address, event.params.ids[i]); + const token = ZoraCreateToken.load(tokenId); + + let txn: string | null = null + if (token) { + txn = token.txn; + } + const newTokenHolderBalance = _updateHolderTransfer( event.block.number, event.address, event.params.from, event.params.to, event.params.ids[i], - event.params.values[i] + event.params.values[i], + txn ); - const tokenId = getTokenId(event.address, event.params.ids[i]); - const token = ZoraCreateToken.load(tokenId); + if (token) { token.holders1155Number = token.holders1155Number.plus( newTokenHolderBalance @@ -370,16 +399,25 @@ export function handleTransferBatch(event: TransferBatch): void { } } else { for (let i = 0; i < event.params.ids.length; i++) { + const tokenId = getTokenId(event.address, event.params.ids[i]); + const token = ZoraCreateToken.load(tokenId); + + + let txn: string | null = null + if (token) { + txn = token.txn; + } + const newTokenHolderBalance = _updateHolderTransfer( event.block.number, event.address, event.params.from, event.params.to, event.params.ids[i], - event.params.values[i] + event.params.values[i], + txn ); - const tokenId = getTokenId(event.address, event.params.ids[i]); - const token = ZoraCreateToken.load(tokenId); + if (token) { token.holders1155Number = token.holders1155Number.plus( newTokenHolderBalance diff --git a/packages/creator-subgraph/src/constants/chainid.ts b/packages/creator-subgraph/src/constants/chainid.ts index c264e4e..e9bf38c 100644 --- a/packages/creator-subgraph/src/constants/chainid.ts +++ b/packages/creator-subgraph/src/constants/chainid.ts @@ -1,4 +1,4 @@ import { BigInt } from "@graphprotocol/graph-ts"; -export const chainid = BigInt.fromI32(8453); -export const network = "base"; \ No newline at end of file +export const chainid = BigInt.fromI32(999999999); +export const network = "zora-sepolia"; \ No newline at end of file