From 65ad04ba701ac46d573896c9041b877b9c73c595 Mon Sep 17 00:00:00 2001 From: kris Date: Mon, 25 Dec 2023 18:04:13 +0500 Subject: [PATCH 1/4] ensured required values in subgraph entities are populated --- packages/subgraph/schema.graphql | 2 +- packages/subgraph/src/mappings/pool.ts | 5 +++++ packages/subgraph/src/mappings/poolFactory.ts | 4 ++++ packages/subgraph/src/mappings/superApp.ts | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/subgraph/schema.graphql b/packages/subgraph/schema.graphql index 01e7c952..0b04403e 100644 --- a/packages/subgraph/schema.graphql +++ b/packages/subgraph/schema.graphql @@ -86,7 +86,7 @@ type ProvableNFT @entity { owner: String! hash: String! steward: [Steward!]! @derivedFrom(field: "nfts") - collective: Collective! + collective: Collective # This is always populated, but not by the same handler that creates the ProvableNFT } type EventData @entity { diff --git a/packages/subgraph/src/mappings/pool.ts b/packages/subgraph/src/mappings/pool.ts index 99a063c0..b2987295 100644 --- a/packages/subgraph/src/mappings/pool.ts +++ b/packages/subgraph/src/mappings/pool.ts @@ -156,6 +156,9 @@ export function handleRewardClaim(event: EventRewardClaimed): void { let steward = Steward.load(contributors[i].toHexString()); if (steward === null) { steward = new Steward(contributors[i].toHexString()); + steward.actions = 0; + steward.totalEarned = BigInt.fromI32(0); + steward.nfts = new Array(); } steward.nfts.push(nftId); steward.actions = steward.actions + 1; @@ -166,6 +169,8 @@ export function handleRewardClaim(event: EventRewardClaimed): void { let stewardCollective = StewardCollective.load(stewardCollectiveId); if (stewardCollective === null) { stewardCollective = new StewardCollective(stewardCollectiveId); + stewardCollective.actions = 0; + stewardCollective.totalEarned = BigInt.fromI32(0); } stewardCollective.actions = stewardCollective.actions + 1; stewardCollective.totalEarned = stewardCollective.totalEarned.plus(totalReward); diff --git a/packages/subgraph/src/mappings/poolFactory.ts b/packages/subgraph/src/mappings/poolFactory.ts index 50d1a703..db828efe 100644 --- a/packages/subgraph/src/mappings/poolFactory.ts +++ b/packages/subgraph/src/mappings/poolFactory.ts @@ -2,6 +2,7 @@ import { PoolCreated } from '../../generated/DirectPaymentsFactory/DirectPayment import { Collective, PoolSettings, SafetyLimits } from '../../generated/schema'; import { createOrUpdateIpfsCollective } from './ipfsCollective'; import { DirectPaymentsPool } from '../../generated/templates'; +import { BigInt } from '@graphprotocol/graph-ts'; export function handlePoolCreated(event: PoolCreated): void { const poolAddress = event.params.pool.toHexString(); @@ -23,6 +24,9 @@ export function handlePoolCreated(event: PoolCreated): void { directPaymentPool.isVerified = false; directPaymentPool.poolFactory = event.address.toHexString(); directPaymentPool.timestamp = event.block.timestamp; + directPaymentPool.paymentsMade = BigInt.fromI32(0); + directPaymentPool.totalDonations = BigInt.fromI32(0); + directPaymentPool.totalRewards = BigInt.fromI32(0); // Pool Settings directPaymentPoolSettings.nftType = nftType; diff --git a/packages/subgraph/src/mappings/superApp.ts b/packages/subgraph/src/mappings/superApp.ts index b9d49b63..305ce610 100644 --- a/packages/subgraph/src/mappings/superApp.ts +++ b/packages/subgraph/src/mappings/superApp.ts @@ -24,6 +24,7 @@ export function handleSupport(event: SupporterUpdated): void { if (donor == null) { donor = new Donor(donorAddress); donor.joined = timestamp; + donor.totalDonated = BigInt.fromI32(0); } donor.totalDonated = donor.totalDonated.plus(contributionDelta); From b8421c329010b8d9e8940508795eccab855fe0df Mon Sep 17 00:00:00 2001 From: kris Date: Mon, 25 Dec 2023 18:14:08 +0500 Subject: [PATCH 2/4] update yarn.lock --- yarn.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index f6a5e3de..c40dd9cd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -39301,7 +39301,7 @@ __metadata: "typescript@patch:typescript@5#~builtin, typescript@patch:typescript@^5.1.3#~builtin": version: 5.2.2 - resolution: "typescript@patch:typescript@npm%3A5.2.2#~builtin::version=5.2.2&hash=14eedb" + resolution: "typescript@patch:typescript@npm%3A5.2.2#~builtin::version=5.2.2&hash=5da071" bin: tsc: bin/tsc tsserver: bin/tsserver From 56bda6710de679159889bac26190d762fc9fd6f0 Mon Sep 17 00:00:00 2001 From: kris Date: Tue, 26 Dec 2023 11:02:39 +0500 Subject: [PATCH 3/4] fixed assemblyscript config extension path --- packages/subgraph/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/subgraph/tsconfig.json b/packages/subgraph/tsconfig.json index 0009c63f..b68eb5f6 100644 --- a/packages/subgraph/tsconfig.json +++ b/packages/subgraph/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "assemblyscript/std/assembly.json", + "extends": "./node_modules/assemblyscript/std/assembly.json", "include": [ "./src/**/*.ts", ], From 0232d0c05dd591057f2fdc5e657d725cc687eefb Mon Sep 17 00:00:00 2001 From: kris Date: Tue, 26 Dec 2023 15:00:38 +0500 Subject: [PATCH 4/4] added donation timestamp to DonorCollective (needed for superfluid real-time updates) --- packages/subgraph/schema.graphql | 1 + packages/subgraph/src/mappings/superApp.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/subgraph/schema.graphql b/packages/subgraph/schema.graphql index 339c568d..72559c5a 100644 --- a/packages/subgraph/schema.graphql +++ b/packages/subgraph/schema.graphql @@ -14,6 +14,7 @@ type DonorCollective @entity { collective: Collective! contribution: BigInt! # This is the total contribution of the donor to the collective flowRate: BigInt! + timestamp: BigInt! } type Steward @entity { diff --git a/packages/subgraph/src/mappings/superApp.ts b/packages/subgraph/src/mappings/superApp.ts index 46c0c299..f7d74176 100644 --- a/packages/subgraph/src/mappings/superApp.ts +++ b/packages/subgraph/src/mappings/superApp.ts @@ -38,6 +38,7 @@ export function handleSupport(event: SupporterUpdated): void { // This value is updated in _updateSupporter at line 260 of GoodCollectiveSuperApp.sol before the event is emitted donorCollective.contribution = event.params.contribution; donorCollective.flowRate = event.params.flowRate; + donorCollective.timestamp = timestamp; donorCollective.donor = donor.id; donorCollective.collective = pool.id;