Skip to content

Commit

Permalink
Merge pull request #65 from GoodDollar/kris/subgraph-fix
Browse files Browse the repository at this point in the history
subgraph fixes for unpopulated non-nullable fields
  • Loading branch information
sirpy authored Dec 26, 2023
2 parents dcc77ea + 0232d0c commit d3fb52b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -98,7 +99,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 {
Expand Down
5 changes: 5 additions & 0 deletions packages/subgraph/src/mappings/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,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<string>();
}
steward.nfts.push(nftId);
steward.actions = steward.actions + 1;
Expand All @@ -132,6 +135,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);
Expand Down
2 changes: 2 additions & 0 deletions packages/subgraph/src/mappings/poolFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { Collective, PoolSettings, SafetyLimits } from '../../generated/schema';
import { createOrUpdateIpfsCollective } from './ipfsCollective';
import { DirectPaymentsPool } from '../../generated/templates';
import { BigInt } from '@graphprotocol/graph-ts';

export function handlePoolDetailsChanged(event: PoolDetailsChanged): void {
const poolAddress = event.params.pool;
Expand Down Expand Up @@ -60,6 +61,7 @@ export function handlePoolCreated(event: PoolCreated): void {
directPaymentPool.paymentsMade = 0;
directPaymentPool.totalDonations = new BigInt(0);
directPaymentPool.totalRewards = new BigInt(0);

// Pool Settings
directPaymentPoolSettings.nftType = nftType;
directPaymentPoolSettings.manager = poolSettings.manager;
Expand Down
2 changes: 2 additions & 0 deletions packages/subgraph/src/mappings/superApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -37,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;

Expand Down
2 changes: 1 addition & 1 deletion packages/subgraph/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "assemblyscript/std/assembly.json",
"extends": "./node_modules/assemblyscript/std/assembly.json",
"include": [
"./src/**/*.ts",
],
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39301,7 +39301,7 @@ __metadata:

"typescript@patch:typescript@5#~builtin<compat/typescript>, typescript@patch:typescript@^5.1.3#~builtin<compat/typescript>":
version: 5.2.2
resolution: "typescript@patch:typescript@npm%3A5.2.2#~builtin<compat/typescript>::version=5.2.2&hash=14eedb"
resolution: "typescript@patch:typescript@npm%3A5.2.2#~builtin<compat/typescript>::version=5.2.2&hash=5da071"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
Expand Down

0 comments on commit d3fb52b

Please sign in to comment.