Skip to content

Commit

Permalink
add tx to Token1155Holder
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime committed Jul 25, 2024
1 parent 4a316b1 commit 052e819
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
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,
): BigInt {
let tokenHolderCountChange = new BigInt(0);
if (!to.equals(Address.zero())) {
Expand All @@ -201,6 +202,7 @@ function _updateHolderTransfer(
} else {
holder.balance = holder.balance.plus(value);
}
holder.txn = txn;
holder.lastUpdatedBlock = blockNumber;
holder.save();
} else {
Expand All @@ -210,6 +212,7 @@ function _updateHolderTransfer(
if (fromHolder) {
fromHolder.balance = fromHolder.balance.minus(value);
fromHolder.lastUpdatedBlock = blockNumber;
fromHolder.txn = txn;
fromHolder.save();
if (fromHolder.balance.equals(BigInt.zero())) {
tokenHolderCountChange = tokenHolderCountChange.minus(new BigInt(1));
Expand Down Expand Up @@ -294,13 +297,15 @@ export function handleUpdatedToken(event: UpdatedToken): void {

// update the minted number and mx number
export function handleTransferSingle(event: TransferSingle): void {
const txn = makeTransaction(event);
const newHolderNumber = _updateHolderTransfer(
event.block.number,
event.address,
event.params.from,
event.params.to,
event.params.id,
event.params.value
event.params.value,
txn
);

const token = ZoraCreateToken.load(
Expand All @@ -327,6 +332,7 @@ export function handleTransferSingle(event: TransferSingle): void {

// update the minted number and max number
export function handleTransferBatch(event: TransferBatch): void {
const txn = makeTransaction(event);
if (event.params.from.equals(Address.zero())) {
for (let i = 0; i < event.params.ids.length; i++) {
const newTokenHolderBalance = _updateHolderTransfer(
Expand All @@ -335,7 +341,8 @@ export function handleTransferBatch(event: TransferBatch): void {
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);
Expand All @@ -356,7 +363,8 @@ export function handleTransferBatch(event: TransferBatch): void {
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);
Expand All @@ -376,7 +384,8 @@ export function handleTransferBatch(event: TransferBatch): void {
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);
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(84532);
export const network = "base-sepolia";

0 comments on commit 052e819

Please sign in to comment.