Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tentative to add premint tx in token holder entity. FAIL. #7

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/creator-subgraph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions packages/creator-subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ type Token1155Holder @entity {
lastUpdatedBlock: BigInt!
tokenAndContract: ZoraCreateToken!
balance: BigInt!
txn: TransactionInfo
}

### Protocol Rewards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand All @@ -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(
Expand All @@ -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));
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/creator-subgraph/src/constants/chainid.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigInt } from "@graphprotocol/graph-ts";

export const chainid = BigInt.fromI32(8453);
export const network = "base";
export const chainid = BigInt.fromI32(999999999);
export const network = "zora-sepolia";
Loading