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

Feature/#210 group ownership change notification #10

Merged
merged 3 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ enum NotificationType {
GROUP_ADD_MEMBER
GROUP_REMOVE_MEMBER
GROUP_MINT
GROUP_OWNER_CHANGE
}

type TrustChange implements Event @entity {
Expand Down Expand Up @@ -107,8 +108,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
}

Expand Down
50 changes: 45 additions & 5 deletions src/groupCurrencyToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down