-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reworked subgraph; added entities for StewardCollective, Reward, Dono…
…rCollective, and Donation
- Loading branch information
1 parent
321f623
commit ab3b969
Showing
4 changed files
with
192 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,61 @@ | ||
import { BigInt, Bytes, log } from '@graphprotocol/graph-ts'; | ||
import { BigInt, log } from '@graphprotocol/graph-ts'; | ||
import { SupporterUpdated } from '../../generated/DirectPaymentsPool/DirectPaymentsPool'; | ||
import { Collective, Donor } from '../../generated/schema'; | ||
import { Collective, Donation, Donor, DonorCollective } from '../../generated/schema'; | ||
|
||
export function handleSupport(event: SupporterUpdated): void { | ||
// TODO: need to call contract functions to get donor/pool total donated including streams, the current method done is incorrect | ||
const donorAddress = event.params.supporter.toHexString(); | ||
const poolAddress = event.address.toHexString(); | ||
const donorCollectiveId = donorAddress + " " + poolAddress; | ||
const timestamp = event.block.timestamp; | ||
const donationId = donorAddress + " " + poolAddress + " " + timestamp.toString() | ||
|
||
let donorId = event.params.supporter.toHexString(); | ||
let donor = Donor.load(donorId); | ||
let directPaymentPool = Collective.load(event.address.toHexString()); | ||
// update pool | ||
const pool = Collective.load(poolAddress); | ||
// This should never happen | ||
if (pool === null) { | ||
log.error('Missing Payment Pool {}', [event.address.toHex()]); | ||
return; | ||
} | ||
pool.contributions = pool.contributions.plus(event.params.contribution); | ||
|
||
// update Donor | ||
let donor = Donor.load(donorAddress); | ||
if (donor == null) { | ||
donor = new Donor(donorId); | ||
donor.supporter = event.params.supporter; | ||
donor.joined = event.block.timestamp.toI32(); | ||
donor.totalDonated = event.params.contribution; | ||
donor.collectives = new Array<string>(); | ||
donor = new Donor(donorAddress); | ||
donor.joined = timestamp; | ||
donor.totalDonated = BigInt.fromI32(0); | ||
} | ||
// TODO: need to call contract functions to get donor/pool total donated including streams, the current method done is incorrect | ||
donor.totalDonated = donor.totalDonated.plus(event.params.contribution); | ||
|
||
if (directPaymentPool === null) { | ||
log.error('Missing Payment Pool {}', [event.address.toHex()]); | ||
return; | ||
// update DonorCollective | ||
let donorCollective = DonorCollective.load(donorCollectiveId); | ||
if (donorCollective == null) { | ||
donorCollective = new DonorCollective(donorCollectiveId); | ||
donorCollective.totalDonated = BigInt.fromI32(0); | ||
} | ||
donorCollective.totalDonated = donorCollective.totalDonated.plus(event.params.contribution); | ||
|
||
directPaymentPool.contributions = directPaymentPool.contributions.plus(event.params.contribution); | ||
// create Donation | ||
const donation = new Donation(donationId); | ||
donation.donor = donorAddress; | ||
donation.collective = poolAddress; | ||
donation.timestamp = timestamp; | ||
donation.originationContract = event.address; | ||
donation.previousContribution = event.params.previousContribution; | ||
donation.contribution = event.params.contribution; | ||
donation.previousFlowRate = event.params.previousFlowRate; | ||
donation.flowRate = event.params.flowRate; | ||
donation.isFlowUpdate = event.params.isFlowUpdate; | ||
|
||
donor.previousContribution = event.params.previousContribution; | ||
donor.totalDonated = donor.totalDonated.plus(event.params.contribution); // Update totalDonated based on the current total | ||
donor.contribution = event.params.contribution; | ||
donor.previousFlowRate = event.params.previousFlowRate; | ||
donor.flowRate = event.params.flowRate; | ||
donor.isFlowUpdate = event.params.isFlowUpdate; | ||
if (donor.collectives.includes(event.address.toHexString()) == false) { | ||
donor.collectives.push(event.address.toHexString()); | ||
} | ||
// add Donation to DonorCollective | ||
donorCollective.donations.push(donationId); | ||
|
||
// add DonorCollective to Donor | ||
donor.collectives.push(donorCollectiveId); | ||
|
||
directPaymentPool.save(); // Save the updated directPaymentPool entity | ||
donor.save(); | ||
donorCollective.save(); | ||
donation.save(); | ||
pool.save(); | ||
} |