Skip to content

Commit

Permalink
the grpha final setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Suja16 committed Dec 7, 2024
1 parent 3b3a891 commit 45fb28d
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 80 deletions.
4 changes: 3 additions & 1 deletion packages/subgraph1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@
"@graphprotocol/graph-cli": "0.91.1",
"@graphprotocol/graph-ts": "0.32.0"
},
"devDependencies": { "matchstick-as": "0.5.0" }
"devDependencies": {
"matchstick-as": "0.5.0"
}
}
6 changes: 6 additions & 0 deletions packages/subgraph1/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,9 @@ type Transfer @entity(immutable: true) {
blockTimestamp: BigInt!
transactionHash: Bytes!
}

type UserStake @entity {
id: ID!
user: Bytes!
totalStaked: BigInt!
}
170 changes: 91 additions & 79 deletions packages/subgraph1/src/step-stake-dynamic-nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
StakeForfeit as StakeForfeitEvent,
Staked as StakedEvent,
StepsCounted as StepsCountedEvent,
Transfer as TransferEvent
} from "../generated/StepStakeDynamicNFT/StepStakeDynamicNFT"
Transfer as TransferEvent,
} from "../generated/StepStakeDynamicNFT/StepStakeDynamicNFT";
import {
Approval,
ApprovalForAll,
Expand All @@ -20,151 +20,163 @@ import {
StakeForfeit,
Staked,
StepsCounted,
Transfer
} from "../generated/schema"
Transfer,
UserStake,
} from "../generated/schema";

export function handleApproval(event: ApprovalEvent): void {
let entity = new Approval(
event.transaction.hash.concatI32(event.logIndex.toI32())
)
entity.owner = event.params.owner
entity.approved = event.params.approved
entity.tokenId = event.params.tokenId
);
entity.owner = event.params.owner;
entity.approved = event.params.approved;
entity.tokenId = event.params.tokenId;

entity.blockNumber = event.block.number
entity.blockTimestamp = event.block.timestamp
entity.transactionHash = event.transaction.hash
entity.blockNumber = event.block.number;
entity.blockTimestamp = event.block.timestamp;
entity.transactionHash = event.transaction.hash;

entity.save()
entity.save();
}

export function handleApprovalForAll(event: ApprovalForAllEvent): void {
let entity = new ApprovalForAll(
event.transaction.hash.concatI32(event.logIndex.toI32())
)
entity.owner = event.params.owner
entity.operator = event.params.operator
entity.approved = event.params.approved
);
entity.owner = event.params.owner;
entity.operator = event.params.operator;
entity.approved = event.params.approved;

entity.blockNumber = event.block.number
entity.blockTimestamp = event.block.timestamp
entity.transactionHash = event.transaction.hash
entity.blockNumber = event.block.number;
entity.blockTimestamp = event.block.timestamp;
entity.transactionHash = event.transaction.hash;

entity.save()
entity.save();
}

export function handleBatchMetadataUpdate(
event: BatchMetadataUpdateEvent
): void {
let entity = new BatchMetadataUpdate(
event.transaction.hash.concatI32(event.logIndex.toI32())
)
entity._fromTokenId = event.params._fromTokenId
entity._toTokenId = event.params._toTokenId
);
entity._fromTokenId = event.params._fromTokenId;
entity._toTokenId = event.params._toTokenId;

entity.blockNumber = event.block.number
entity.blockTimestamp = event.block.timestamp
entity.transactionHash = event.transaction.hash
entity.blockNumber = event.block.number;
entity.blockTimestamp = event.block.timestamp;
entity.transactionHash = event.transaction.hash;

entity.save()
entity.save();
}

export function handleMetadataUpdate(event: MetadataUpdateEvent): void {
let entity = new MetadataUpdate(
event.transaction.hash.concatI32(event.logIndex.toI32())
)
entity._tokenId = event.params._tokenId
);
entity._tokenId = event.params._tokenId;

entity.blockNumber = event.block.number
entity.blockTimestamp = event.block.timestamp
entity.transactionHash = event.transaction.hash
entity.blockNumber = event.block.number;
entity.blockTimestamp = event.block.timestamp;
entity.transactionHash = event.transaction.hash;

entity.save()
entity.save();
}

export function handleNFTMinted(event: NFTMintedEvent): void {
let entity = new NFTMinted(
event.transaction.hash.concatI32(event.logIndex.toI32())
)
entity.user = event.params.user
entity.tokenId = event.params.tokenId
);
entity.user = event.params.user;
entity.tokenId = event.params.tokenId;

entity.blockNumber = event.block.number
entity.blockTimestamp = event.block.timestamp
entity.transactionHash = event.transaction.hash
entity.blockNumber = event.block.number;
entity.blockTimestamp = event.block.timestamp;
entity.transactionHash = event.transaction.hash;

entity.save()
entity.save();
}

export function handleOwnershipTransferred(
event: OwnershipTransferredEvent
): void {
let entity = new OwnershipTransferred(
event.transaction.hash.concatI32(event.logIndex.toI32())
)
entity.previousOwner = event.params.previousOwner
entity.newOwner = event.params.newOwner
);
entity.previousOwner = event.params.previousOwner;
entity.newOwner = event.params.newOwner;

entity.blockNumber = event.block.number
entity.blockTimestamp = event.block.timestamp
entity.transactionHash = event.transaction.hash
entity.blockNumber = event.block.number;
entity.blockTimestamp = event.block.timestamp;
entity.transactionHash = event.transaction.hash;

entity.save()
entity.save();
}

export function handleStakeForfeit(event: StakeForfeitEvent): void {
let entity = new StakeForfeit(
event.transaction.hash.concatI32(event.logIndex.toI32())
)
entity.user = event.params.user
entity.amount = event.params.amount
);
entity.user = event.params.user;
entity.amount = event.params.amount;

entity.blockNumber = event.block.number
entity.blockTimestamp = event.block.timestamp
entity.transactionHash = event.transaction.hash
entity.blockNumber = event.block.number;
entity.blockTimestamp = event.block.timestamp;
entity.transactionHash = event.transaction.hash;

entity.save()
entity.save();
}

export function handleStaked(event: StakedEvent): void {
let entity = new Staked(
// Create Staked entity (as you already do)
let stakedEntity = new Staked(
event.transaction.hash.concatI32(event.logIndex.toI32())
)
entity.user = event.params.user
entity.amount = event.params.amount

entity.blockNumber = event.block.number
entity.blockTimestamp = event.block.timestamp
entity.transactionHash = event.transaction.hash

entity.save()
);
stakedEntity.user = event.params.user;
stakedEntity.amount = event.params.amount;
stakedEntity.blockNumber = event.block.number;
stakedEntity.blockTimestamp = event.block.timestamp;
stakedEntity.transactionHash = event.transaction.hash;
stakedEntity.save();

// Update aggregated UserStake entity
let userId = event.params.user.toHex();
let userStake = UserStake.load(userId);
if (userStake === null) {
userStake = new UserStake(userId);
userStake.user = event.params.user;
userStake.totalStaked = event.params.amount;
} else {
userStake.totalStaked = userStake.totalStaked.plus(event.params.amount);
}
userStake.save();
}

export function handleStepsCounted(event: StepsCountedEvent): void {
let entity = new StepsCounted(
event.transaction.hash.concatI32(event.logIndex.toI32())
)
entity.user = event.params.user
entity.stepCount = event.params.stepCount
);
entity.user = event.params.user;
entity.stepCount = event.params.stepCount;

entity.blockNumber = event.block.number
entity.blockTimestamp = event.block.timestamp
entity.transactionHash = event.transaction.hash
entity.blockNumber = event.block.number;
entity.blockTimestamp = event.block.timestamp;
entity.transactionHash = event.transaction.hash;

entity.save()
entity.save();
}

export function handleTransfer(event: TransferEvent): void {
let entity = new Transfer(
event.transaction.hash.concatI32(event.logIndex.toI32())
)
entity.from = event.params.from
entity.to = event.params.to
entity.tokenId = event.params.tokenId
);
entity.from = event.params.from;
entity.to = event.params.to;
entity.tokenId = event.params.tokenId;

entity.blockNumber = event.block.number
entity.blockTimestamp = event.block.timestamp
entity.transactionHash = event.transaction.hash
entity.blockNumber = event.block.number;
entity.blockTimestamp = event.block.timestamp;
entity.transactionHash = event.transaction.hash;

entity.save()
entity.save();
}

0 comments on commit 45fb28d

Please sign in to comment.