Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subgraph update #60

Merged
merged 11 commits into from
Dec 22, 2023
122 changes: 62 additions & 60 deletions packages/subgraph/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,69 +1,72 @@
# TODO
# get total donated from correct field
# handling of generated pools from factory contract
# per collective donor/steward record
# update nft with stewards on claim
type Donor @entity {
id: String! # The address of the donor
joined: BigInt!
totalDonated: BigInt!
collectives: [DonorCollective!]!
}

"""Represents the relationship between a Donor and a Collective"""
type DonorCollective @entity {
id: String! # donorAddress + " " + collectiveAddress
donor: Donor! @derivedFrom(field: "collectives")
collective: Collective! @derivedFrom(field: "donors")
Comment on lines +11 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this will work. it has to be the other way around.
here it should just be donor: Donor! and collective: Collective!
in Collective and Donor there should be Donors: [DonorCollective!] @derivedFrom(field:"collective")
in Donor Collectives: [DonorCollective!] @derivedFrom(field:"donor")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware that the derivedFrom relationship only works one way. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved in #63

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its not one way, but rather I dont think it can be derived from an array, how would it know which one?

contribution: BigInt! # This is the total contribution of the donor to the collective
flowRate: BigInt!
}

type Steward @entity {
"{ user address} "
"""{ user address}"""
id: String!
" Number of actions performed "
"""Number of actions performed"""
actions: Int!
totalEarned: BigInt!
" NFT's minted to steward"
nfts: [ProvableNFT!]! @derivedFrom(field: "steward")
" Collectives the steward is apart of "
collectives: [Collective!]! @derivedFrom(field: "stewards")
}

type Donor @entity {
id: String! # This will be the contract address from which the transaction originated
supporter: Bytes! # Address of the supporter
joined: Int!
totalDonated: BigInt!
previousContribution: BigInt
contribution: BigInt
previousFlowRate: BigInt
flowRate: BigInt
isFlowUpdate: Boolean
collectives: [Collective!]!
}

type CollectiveDonor @entity {
id: String! #collective_donor
totalDonated: BigInt!
flowRate: BigInt
"""NFT's minted to steward"""
nfts: [ProvableNFT!]!
"""Collectives the steward is apart of"""
collectives: [StewardCollective!]!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as on DonorCollective

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved in #63

}

type CollectiveSteward @entity {
id: String! #collective_donor
"""Represents the relationship between a Steward and a Collective"""
type StewardCollective @entity {
id: String! # stewardAddress + " " + collectiveAddress
steward: Steward! @derivedFrom(field: "collectives")
collective: Collective! @derivedFrom(field: "stewards")
Comment on lines +32 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as on donorcollective

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved in #63

actions: Int!
totalEarned: BigInt!
nft: [ProvableNFT!]!
}

type Collective @entity {
"This is the address source"
id: String!
ipfs: String
nftType: BigInt
manager: Bytes
contributions: BigInt!
membersValidator: Bytes
uniquenessValidator: String
donors: [Donor!] @derivedFrom(field: "collectives")
stewards: [Steward!]!
rewardToken: String
projectId: String
isVerified: Boolean
limits: SafetyLimits
nft: ProvableNFT
poolAddress: String
timestamp: Int
id: String! # pool address
ipfs: String!
settings: PoolSettings!
limits: SafetyLimits!
donors: [DonorCollective!]!
stewards: [StewardCollective!]!
Comment on lines +43 to +44
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment on collectivedonor/steward probably should have derivedfrom field

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved in #63

projectId: String!
isVerified: Boolean!
poolFactory: String! # pool factory (event source)
timestamp: BigInt!
paymentsMade: Int!
totalDonations: BigInt!
totalRewards: BigInt!
}

type IpfsCollective @entity {
id: String! # collective address
name: String!
description: String!
email: String
website: String
twitter: String
instagram: String
threads: String
headerImage: String
logo: String
images: [String!]
}

type PoolSettings @entity {
id: String!
id: String! # collective address
nftType: BigInt!
manager: Bytes!
membersValidator: Bytes!
Expand All @@ -72,34 +75,33 @@ type PoolSettings @entity {
}

type SafetyLimits @entity {
id: String!
maxTotalPerMonth: BigInt
maxMemberPerMonth: BigInt
maxMemberPerDay: BigInt
id: String! # collective address
maxTotalPerMonth: BigInt!
maxMemberPerMonth: BigInt!
maxMemberPerDay: BigInt!
}

type ProvableNFT @entity {
id: ID!
owner: String!
hash: String!
steward: [Steward!]!
steward: [Steward!]! @derivedFrom(field: "nfts")
collective: Collective!
}

type EventData @entity {
id: String!
id: String! # event uri
eventType: Int!
timestamp: BigInt!
quantity: BigInt!
uri: String!
rewardPerContributor: BigInt!
contributors: [Steward!]!
nft: ProvableNFT!
claim: Claim
claim: Claim! @derivedFrom(field: "events")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as in CollectiveDonor, probably should be the other way around

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved in #63

}

type Claim @entity {
id: String!
totalRewards: BigInt!
events: [EventData!] @derivedFrom(field: "claim")
events: [EventData!]!
}
11 changes: 5 additions & 6 deletions packages/subgraph/src/mappings/ProvableNFT.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { ProvableNftMinted } from '../../generated/ProvableNFT/ProvableNFT';
import { ProvableNFT, Steward } from '../../generated/schema';
import { ProvableNFT } from '../../generated/schema';

// Note that ProvableNFT.collective is set by steward reward event
export function handleNftMint(event: ProvableNftMinted): void {
const tokenID = event.params.tokenId.toString();
const to = event.params.to.toHexString();
const nftHash = event.params.nftDataHash.toHexString();

let provableNFT = ProvableNFT.load(tokenID);

if (provableNFT === null) {
provableNFT = new ProvableNFT(tokenID);
provableNFT.id = tokenID;
provableNFT.owner = to; // Fixed this line
provableNFT.hash = nftHash;
provableNFT.save();
}
provableNFT.owner = to;
provableNFT.hash = nftHash;
provableNFT.save();
}
Loading
Loading