From 4933ecc27f4633e4da6aee0b27c1c992a21c0479 Mon Sep 17 00:00:00 2001 From: Shisus Date: Tue, 30 Aug 2022 11:54:45 -0300 Subject: [PATCH 1/3] group owner change schema event now uses string instead of safe because the old/new address could not be a safe account --- schema.graphql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/schema.graphql b/schema.graphql index 64c9bf9..f391c09 100644 --- a/schema.graphql +++ b/schema.graphql @@ -107,8 +107,8 @@ type GroupMint implements Event @entity { type GroupOwnerChange implements Event @entity { id: ID! # Concatenation of block number and log ID - oldOwner: Safe - newOwner: Safe + oldOwner: String + newOwner: String group: GroupCurrencyToken } From 8e77e5f38c3a4cef8b2258c2aa8389aed39f97aa Mon Sep 17 00:00:00 2001 From: Shisus Date: Tue, 30 Aug 2022 11:56:45 -0300 Subject: [PATCH 2/3] fixed issue when group owner change event was not created notifications for group owner change are only created when the new/old owner is a safe account --- src/groupCurrencyToken.ts | 50 +++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/src/groupCurrencyToken.ts b/src/groupCurrencyToken.ts index c76c11f..13fca28 100644 --- a/src/groupCurrencyToken.ts +++ b/src/groupCurrencyToken.ts @@ -15,7 +15,7 @@ import { Suspended as SuspendedEvent, Minted as MintedEvent, } from './types/GroupCurrencyTokenFactory/GroupCurrencyToken' -import { GroupAddMember, GroupCreation, GroupCurrencyToken, GroupMint, GroupRemoveMember, Notification, SafeGroupMember } from './types/schema' +import { GroupAddMember, GroupCreation, GroupCurrencyToken, GroupMint, GroupRemoveMember, Notification, SafeGroupMember, GroupOwnerChange, Safe } from './types/schema' import { GroupCurrencyToken as GroupCurrencyTokenTemplate } from './types/templates' import { createEventID, createNotificationID } from './utils' @@ -101,7 +101,7 @@ export function handleMemberTokenAdded(event: MemberTokenAddedEvent): void { groupAddMemberEvent.group = groupId groupAddMemberEvent.save() - // Creates Notification for Group Creation event + // Creates Notification for Group Add Member event let notificationId = createNotificationID('group-add-member', event.block.number, event.logIndex) let notification = new Notification(notificationId) notification.transactionHash = event.transaction.hash.toHexString() @@ -131,7 +131,7 @@ export function handleMemberTokenRemoved(event: MemberTokenAddedEvent): void { groupRemoveMemberEvent.group = groupId groupRemoveMemberEvent.save() - // Creates Notification for Group Creation event + // Creates Notification for Group Remove Member event let notificationId = createNotificationID('group-remove-member', event.block.number, event.logIndex) let notification = new Notification(notificationId) notification.transactionHash = event.transaction.hash.toHexString() @@ -162,10 +162,50 @@ export function handleOnlyTrustedCanMint(event: OnlyTrustedCanMintEvent): void { export function handleOwnerChanged(event: OwnerChangedEvent): void { let groupAddress = event.params._event.address - let newOwner = event.params._new + let newOwner = event.params._new.toHexString() let groupCurrencyToken = createGroupCurrencyTokenIfNonExistent(groupAddress) - groupCurrencyToken.owner = newOwner.toHexString() + let oldOwner = groupCurrencyToken.owner + groupCurrencyToken.owner = newOwner groupCurrencyToken.save() + + // Creates Group Owner Change event + let eventId = createEventID(event.block.number, event.logIndex) + let groupOwnerChangeEvent = new GroupOwnerChange(eventId) + groupOwnerChangeEvent.oldOwner = oldOwner + groupOwnerChangeEvent.newOwner = newOwner + groupOwnerChangeEvent.group = groupAddress.toHexString() + groupOwnerChangeEvent.save() + + // Creates Notifications for Group Owner Change event when safe exists + if (oldOwner) { + let safe = Safe.load(oldOwner) + if (safe) { + let oldOwnerNotificationId = createNotificationID('group-owner-change-old', event.block.number, event.logIndex) + let oldOwnerNotification = new Notification(oldOwnerNotificationId) + oldOwnerNotification.transactionHash = event.transaction.hash.toHexString() + oldOwnerNotification.safeAddress = oldOwner + oldOwnerNotification.safe = oldOwner + oldOwnerNotification.type = 'GROUP_OWNER_CHANGE' + oldOwnerNotification.time = event.block.timestamp + oldOwnerNotification.groupOwnerChange = eventId + oldOwnerNotification.save() + } + } + + // // Creates Notification for Group Creation event when safe exists + let safe = Safe.load(newOwner) + if (safe) { + let newOwnerNotificationId = createNotificationID('group-owner-change-new', event.block.number, event.logIndex) + let newOwnerNotification = new Notification(newOwnerNotificationId) + newOwnerNotification.transactionHash = event.transaction.hash.toHexString() + + newOwnerNotification.safeAddress = newOwner + newOwnerNotification.safe = newOwner + newOwnerNotification.type = 'GROUP_OWNER_CHANGE' + newOwnerNotification.time = event.block.timestamp + newOwnerNotification.groupOwnerChange = eventId + newOwnerNotification.save() + } } export function handleSuspended(event: SuspendedEvent): void { From 8e4fbd9b2d7e8c19cd74207093bc9d88abc5edcc Mon Sep 17 00:00:00 2001 From: Shisus Date: Tue, 30 Aug 2022 12:56:34 -0300 Subject: [PATCH 3/3] fixes: add missing notification type for the Group Owner Change event --- schema.graphql | 1 + 1 file changed, 1 insertion(+) diff --git a/schema.graphql b/schema.graphql index f391c09..349f45f 100644 --- a/schema.graphql +++ b/schema.graphql @@ -62,6 +62,7 @@ enum NotificationType { GROUP_ADD_MEMBER GROUP_REMOVE_MEMBER GROUP_MINT + GROUP_OWNER_CHANGE } type TrustChange implements Event @entity {