From f7f1935aa62729e3c461486a9fd0612a110e1f9b Mon Sep 17 00:00:00 2001 From: Simon Emanuel Schmid Date: Sat, 19 Feb 2022 15:01:10 -0700 Subject: [PATCH 1/2] Update to apiVersion 0.0.5 --- package.json | 4 ++-- src/mapping.ts | 37 +++++++++++++++++++++---------------- subgraph.template.yaml | 2 +- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 42310ef..545aefc 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,8 @@ "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 poap-xyz/poap" }, "dependencies": { - "@graphprotocol/graph-cli": "0.18.0", - "@graphprotocol/graph-ts": "0.18.0" + "@graphprotocol/graph-cli": "0.26.0", + "@graphprotocol/graph-ts": "0.24.1" }, "devDependencies": { "mustache": "^4.0.1" diff --git a/src/mapping.ts b/src/mapping.ts index ffd9c37..77f8346 100644 --- a/src/mapping.ts +++ b/src/mapping.ts @@ -26,7 +26,7 @@ export function handleEventToken(ev: EventTokenEvent): void { let event = Event.load(ev.params.eventId.toString()); // This handler always run after the transfer handler - let token = Token.load(ev.params.tokenId.toString()); + let token = Token.load(ev.params.tokenId.toString())!; if (event == null) { event = new Event(ev.params.eventId.toString()); event.tokenCount = BigInt.fromI32(0); @@ -34,8 +34,8 @@ export function handleEventToken(ev: EventTokenEvent): void event.created = ev.block.timestamp } - event.tokenCount += BigInt.fromI32(1); - event.transferCount += BigInt.fromI32(1); + event.tokenCount = event.tokenCount.plus(BigInt.fromI32(1)); + event.transferCount = event.transferCount.plus(BigInt.fromI32(1)); token.event = event.id; event.save(); token.save(); @@ -55,7 +55,7 @@ export function handleTransfer(ev: TransferEvent): void { // Don't subtracts from the ZERO_ADDRESS (it's the one that mint the token) // Avoid negative values if(from.id != ZERO_ADDRESS) { - from.tokensOwned -= BigInt.fromI32(1); + from.tokensOwned = from.tokensOwned.minus(BigInt.fromI32(1)); } from.save(); @@ -63,7 +63,7 @@ export function handleTransfer(ev: TransferEvent): void { to = new Account(ev.params.to.toHex()); to.tokensOwned = BigInt.fromI32(0); } - to.tokensOwned += BigInt.fromI32(1); + to.tokensOwned = to.tokensOwned.plus(BigInt.fromI32(1)); to.save(); if (token == null) { @@ -72,24 +72,29 @@ export function handleTransfer(ev: TransferEvent): void { token.created = ev.block.timestamp } token.owner = to.id; - token.transferCount += BigInt.fromI32(1); + token.transferCount = token.transferCount.plus(BigInt.fromI32(1)); token.save(); - let event = Event.load(token.event); - if(event != null) { - // Add one transfer - event.transferCount += BigInt.fromI32(1); + if (token.event != null) { + let event = Event.load(token.event as string); - // Burning the token - if(to.id == ZERO_ADDRESS) { - event.tokenCount -= BigInt.fromI32(1); - // Subtract all the transfers from the burned token - event.transferCount -= token.transferCount; + if(event != null) { + // Add one transfer + event.transferCount = event.transferCount.plus(BigInt.fromI32(1)); + + // Burning the token + if(to.id == ZERO_ADDRESS) { + event.tokenCount = event.tokenCount.minus(BigInt.fromI32(1)); + // Subtract all the transfers from the burned token + event.transferCount = event.transferCount.minus(token.transferCount); + } + event.save(); } - event.save(); } + + transfer.token = token.id; transfer.from = from.id; transfer.to = to.id; diff --git a/subgraph.template.yaml b/subgraph.template.yaml index bc6e2b5..0f88646 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -13,7 +13,7 @@ dataSources: startBlock: {{ startBlock }} mapping: kind: ethereum/events - apiVersion: 0.0.4 + apiVersion: 0.0.5 language: wasm/assemblyscript entities: - EventToken From 644c4ebf4657030073571b3c2dea47f388157140 Mon Sep 17 00:00:00 2001 From: Simon Emanuel Schmid Date: Sat, 19 Feb 2022 16:00:28 -0700 Subject: [PATCH 2/2] Add studio deploy command --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 545aefc..62158b7 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "prepare:xdai": "mustache config/xdai.json subgraph.template.yaml > subgraph.yaml", "prepare:sokol": "mustache config/sokol.json subgraph.template.yaml > subgraph.yaml", + "deploy:studio": "graph deploy --studio poap-ethereum-mainnet", "deploy:mainnet": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ poap-xyz/poap", "deploy:ropsten": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ poap-xyz/poap-ropsten", "deploy:kovan": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ poap-xyz/poap-kovan",