Skip to content

Commit

Permalink
Fix/handle batch transfers graph (#1149)
Browse files Browse the repository at this point in the history
* feat(batch): add batch transfers to grap
  • Loading branch information
bitbeckers authored Nov 3, 2023
1 parent fe9b359 commit b033d77
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"**/*.{js,jsx,ts,tsx,sol}": [
"eslint --ignore-path .gitignore --ignore-pattern sdk/ --ignore-pattern graph/generated/",
"eslint --ignore-path .gitignore --ignore-pattern sdk/ --ignore-pattern graph/generated/ --ignore-pattern graph/",
"prettier --write"
],
"**/*.{md,json}": ["prettier --write"]
Expand Down
36 changes: 24 additions & 12 deletions graph/src/hypercert-minter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,14 @@ import {
getOrCreateClaim,
getOrCreateClaimToken,
} from "./utils";
import { Address, BigInt, log } from "@graphprotocol/graph-ts";
import { log } from "@graphprotocol/graph-ts";
import { ClaimToken } from "../generated/schema";

const ZERO_ADDRESS = Address.fromString(
"0x0000000000000000000000000000000000000000"
);
const ZERO_TOKEN = BigInt.fromI32(0);

export function handleAllowlistCreated(event: AllowlistCreatedEvent): void {
let allowlist = getOrCreateAllowlist(
event.params.tokenID,
event.params.root,
event.address
event.address,
);

allowlist.save();
Expand All @@ -41,7 +36,7 @@ export function handleClaimStored(event: ClaimStoredEvent): void {
let claim = getOrCreateClaim(
event.params.claimID,
event.address,
event.block.timestamp
event.block.timestamp,
);

claim.uri = event.params.uri;
Expand All @@ -57,10 +52,27 @@ export function handleInitialized(event: InitializedEvent): void {}
export function handleLeafClaimed(event: LeafClaimedEvent): void {}

export function handleOwnershipTransferred(
event: OwnershipTransferredEvent
event: OwnershipTransferredEvent,
): void {}

export function handleTransferBatch(event: TransferBatchEvent): void {}
export function handleTransferBatch(event: TransferBatchEvent): void {
let ids = event.params.ids;
let size = ids.length;

for (let i = 0; i < size; i++) {
let id = getID(ids[i], event.address);
let token = ClaimToken.load(id);

if (!token) {
log.debug("Transfered ClaimToken does not exist: {}", [id]);
return;
}

token.owner = event.params.to;

token.save();
}
}

export function handleTransferSingle(event: TransferSingleEvent): void {
let id = getID(event.params.id, event.address);
Expand Down Expand Up @@ -95,12 +107,12 @@ export function handleValueTransfer(event: ValueTransferEvent): void {
let from = getOrCreateClaimToken(
event.params.claimID,
event.params.fromTokenID,
event.address
event.address,
);
let to = getOrCreateClaimToken(
event.params.claimID,
event.params.toTokenID,
event.address
event.address,
);

let value = event.params.value;
Expand Down
2 changes: 1 addition & 1 deletion graph/tests/.latest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "0.6.0",
"timestamp": 1698094053842
"timestamp": 1698760525590
}

0 comments on commit b033d77

Please sign in to comment.