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

Merging the group currencies changes by BootNode #106

Draft
wants to merge 15 commits into
base: merge-group-currencies
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[SG] Adds Group Notifications (#8)
* adds new event data schemas for group notifications

* feat: adds notifications when group is created, member is added/removed and group minted

* add missing group id in event data
  • Loading branch information
LaimeJesus authored Aug 5, 2022
commit 15cb295dcd379ed8df1585300288cde60e912a1d
43 changes: 43 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
@@ -58,6 +58,10 @@ enum NotificationType {
OWNERSHIP
TRANSFER
TRUST
GROUP_CREATION
GROUP_ADD_MEMBER
GROUP_REMOVE_MEMBER
GROUP_MINT
}

type TrustChange implements Event @entity {
@@ -87,6 +91,40 @@ type OwnershipChange implements Event @entity {
removes: String
}

type GroupCreation implements Event @entity {
id: ID! # Concatenation of block number and log ID
group: String
creator: String
name: String
}

type GroupMint implements Event @entity {
id: ID! # Concatenation of block number and log ID
receiver: String
amount: BigInt
mintFee: BigInt
group: String
}

type GroupOwnerChange implements Event @entity {
id: ID! # Concatenation of block number and log ID
oldOwner: String
newOwner: BigInt
group: String
}

type GroupAddMember implements Event @entity {
id: ID! # Concatenation of block number and log ID
user: String
group: String
}

type GroupRemoveMember implements Event @entity {
id: ID! # Concatenation of block number and log ID
user: String
group: String
}

type Notification implements Event @entity {
id: ID! # Concatenation of notification type, block number and log ID
safe: Safe
@@ -98,6 +136,11 @@ type Notification implements Event @entity {
transfer: Transfer
hubTransfer: HubTransfer
ownership: OwnershipChange
groupCreation: GroupCreation
groupMint: GroupMint
groupOwnerChange: GroupOwnerChange
groupAddMember: GroupAddMember
groupRemoveMember: GroupRemoveMember
}

type SafeGroupMember @entity {
82 changes: 81 additions & 1 deletion src/groupCurrencyToken.ts
Original file line number Diff line number Diff line change
@@ -15,8 +15,9 @@ import {
Suspended as SuspendedEvent,
Minted as MintedEvent,
} from './types/GroupCurrencyTokenFactory/GroupCurrencyToken'
import { GroupCurrencyToken, SafeGroupMember } from './types/schema'
import { GroupAddMember, GroupCreation, GroupCurrencyToken, GroupMint, GroupRemoveMember, Notification, SafeGroupMember } from './types/schema'
import { GroupCurrencyToken as GroupCurrencyTokenTemplate } from './types/templates'
import { createEventID, createNotificationID } from './utils'

export function createGroupCurrencyTokenIfNonExistent(groupAddress: Address): GroupCurrencyToken {
let groupAddressString = groupAddress.toHexString()
@@ -65,6 +66,25 @@ export function handleGroupCurrencyTokenCreation(event: GroupCurrencyTokenCreate
let groupCurrencyToken = createGroupCurrencyTokenIfNonExistent(groupAddress)
groupCurrencyToken.creator = creator
groupCurrencyToken.save()

// Creates Group Creation event
let eventId = createEventID(event.block.number, event.logIndex)
let groupCreationEvent = new GroupCreation(eventId)
groupCreationEvent.creator = creator
groupCreationEvent.group = groupCurrencyToken.id
groupCreationEvent.name = groupCurrencyToken.name
groupCreationEvent.save()

// Creates Notification for Group Creation event
let notificationId = createNotificationID('group-creation', event.block.number, event.logIndex)
let notification = new Notification(notificationId)
notification.transactionHash = event.transaction.hash.toHexString()
notification.safeAddress = creator
notification.safe = creator
notification.type = 'GROUP_CREATION'
notification.time = event.block.timestamp
notification.groupCreation = eventId
notification.save()
}

export function handleMemberTokenAdded(event: MemberTokenAddedEvent): void {
@@ -73,6 +93,25 @@ export function handleMemberTokenAdded(event: MemberTokenAddedEvent): void {
// safe Id is generated by transforming the Safe Address to Hex
let safeId = event.params._memberToken.toHex()
createSafeGroupMemberIfNonExistent(groupId, safeId)

// Creates Group Add Member event
let eventId = createEventID(event.block.number, event.logIndex)
let groupAddMemberEvent = new GroupAddMember(eventId)
groupAddMemberEvent.user = safeId
groupAddMemberEvent.group = groupId
groupAddMemberEvent.save()

// Creates Notification for Group Creation event
let notificationId = createNotificationID('group-add-member', event.block.number, event.logIndex)
let notification = new Notification(notificationId)
notification.transactionHash = event.transaction.hash.toHexString()

notification.safeAddress = safeId
notification.safe = safeId
notification.type = 'GROUP_ADD_MEMBER'
notification.time = event.block.timestamp
notification.groupAddMember = eventId
notification.save()
}

// @TODO shall we remove them or we might want to keep them for historical data?
@@ -84,6 +123,25 @@ export function handleMemberTokenRemoved(event: MemberTokenAddedEvent): void {
let safeId = event.params._memberToken.toHex()
let groupMemberId = createSafeGroupMemberId(groupId, safeId)
store.remove('SafeGroupMember', groupMemberId)

// Creates Group Remove Member event
let eventId = createEventID(event.block.number, event.logIndex)
let groupRemoveMemberEvent = new GroupRemoveMember(eventId)
groupRemoveMemberEvent.user = safeId
groupRemoveMemberEvent.group = groupId
groupRemoveMemberEvent.save()

// Creates Notification for Group Creation event
let notificationId = createNotificationID('group-remove-member', event.block.number, event.logIndex)
let notification = new Notification(notificationId)
notification.transactionHash = event.transaction.hash.toHexString()

notification.safeAddress = safeId
notification.safe = safeId
notification.type = 'GROUP_REMOVE_MEMBER'
notification.time = event.block.timestamp
notification.groupRemoveMember = eventId
notification.save()
}

export function handleOnlyOwnerCanMint(event: OnlyOwnerCanMintEvent): void {
@@ -129,4 +187,26 @@ export function handleMinted(event: MintedEvent): void {
let groupCurrencyToken = createGroupCurrencyTokenIfNonExistent(groupAddress)
groupCurrencyToken.minted = groupCurrencyToken.minted.plus(mintAmount)
groupCurrencyToken.save()

// Creates Group Mint event
let eventId = createEventID(event.block.number, event.logIndex)
let groupMintEvent = new GroupMint(eventId)
let receiver = event.params._receiver.toHexString()
groupMintEvent.receiver = receiver
groupMintEvent.amount = mintAmount
groupMintEvent.mintFee = event.params._mintFee
groupMintEvent.group = groupAddress.toHexString()
groupMintEvent.save()

// Creates Notification for Group Creation event
let notificationId = createNotificationID('group-mint', event.block.number, event.logIndex)
let notification = new Notification(notificationId)
notification.transactionHash = event.transaction.hash.toHexString()

notification.safeAddress = receiver
notification.safe = receiver
notification.type = 'GROUP_MINT'
notification.time = event.block.timestamp
notification.groupMint = eventId
notification.save()
}