From 2a2916445bd03ce4fb6a8164b1a9b441f305f25d Mon Sep 17 00:00:00 2001 From: Cujowolf Date: Tue, 17 Oct 2023 10:17:51 -0500 Subject: [PATCH] Update seller activity links --- carbonmark/schema.graphql | 2 +- carbonmark/src/Carbonmark.ts | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/carbonmark/schema.graphql b/carbonmark/schema.graphql index b505e102..363609ad 100644 --- a/carbonmark/schema.graphql +++ b/carbonmark/schema.graphql @@ -25,7 +25,7 @@ type Project @entity { methodology: String! vintage: BigInt! projectAddress: Bytes! - # registry: String! + registry: String! # #relationships activities: [Activity!] @derivedFrom(field: "project") listings: [Listing!] @derivedFrom(field: "project") diff --git a/carbonmark/src/Carbonmark.ts b/carbonmark/src/Carbonmark.ts index 12c2a30c..56d2faa3 100644 --- a/carbonmark/src/Carbonmark.ts +++ b/carbonmark/src/Carbonmark.ts @@ -8,6 +8,7 @@ import { loadOrCreateUser, } from './Entities' import { ZERO_BI } from '../../lib/utils/Decimals' +import { ZERO_ADDRESS } from '../../lib/utils/Constants' export function handleListingCreated(event: ListingCreated): void { // Ensure the user entity exists @@ -35,6 +36,7 @@ export function handleListingCreated(event: ListingCreated): void { activity.price = event.params.price activity.timeStamp = event.block.timestamp activity.activityType = 'CreatedListing' + activity.project = listing.project activity.user = event.params.account activity.listing = listing.id activity.seller = event.params.account @@ -54,20 +56,27 @@ export function handleListingUpdated(event: ListingUpdated): void { activity.activityType = 'UpdatedQuantity' activity.project = listing.project + activity.user = event.transaction.from activity.previousAmount = event.params.oldAmount activity.amount = event.params.newAmount activity.timeStamp = event.block.timestamp activity.seller = listing.seller + activity.save() } if (event.params.oldUnitPrice != event.params.newUnitPrice) { + if (activity.seller != ZERO_ADDRESS) { + activity = loadOrCreateActivity(event.transaction.hash.toHexString().concat('ListingUpdated2')) + } + listing.singleUnitPrice = event.params.newUnitPrice listing.updatedAt = event.block.timestamp activity.activityType = 'UpdatedPrice' activity.project = listing.project + activity.user = event.transaction.from activity.price = event.params.newUnitPrice - activity.previousAmount = event.params.oldUnitPrice + activity.previousPrice = event.params.oldUnitPrice activity.timeStamp = event.block.timestamp activity.seller = listing.seller } @@ -98,7 +107,7 @@ export function handleListingFilled(event: ListingFilled): void { buyerActivty.project = listing.project buyerActivty.user = event.transaction.from buyerActivty.listing = listing.id - buyerActivty.seller = event.params.account + buyerActivty.seller = listing.seller buyerActivty.buyer = event.transaction.from buyerActivty.save() @@ -109,7 +118,7 @@ export function handleListingFilled(event: ListingFilled): void { sellerActivity.project = listing.project sellerActivity.user = event.params.account sellerActivity.listing = listing.id - sellerActivity.seller = event.params.account + sellerActivity.seller = listing.seller sellerActivity.buyer = event.transaction.from sellerActivity.save()