Skip to content

Commit

Permalink
added project enacted event
Browse files Browse the repository at this point in the history
  • Loading branch information
ncomerci committed Jul 3, 2024
1 parent 0369d57 commit 4689071
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/services/ProposalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export class ProposalService {
const project = await ProjectService.getUpdatedProject(proposal.project_id!)
updatedProposal.project_status = project.status
NotificationService.projectProposalEnacted(proposal)
await EventsService.projectEnacted(project)
}

DiscourseService.commentUpdatedProposal(updatedProposal)
Expand Down
26 changes: 26 additions & 0 deletions src/services/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { UserAttributes } from '../entities/User/types'
import { DISCOURSE_USER } from '../entities/User/utils'
import { addressShortener } from '../helpers'
import EventModel from '../models/Event'
import type { Project } from '../models/Project'
import CacheService, { TTL_1_HS } from '../services/CacheService'
import { DiscourseService } from '../services/DiscourseService'
import { ErrorService } from '../services/ErrorService'
Expand All @@ -30,10 +31,12 @@ import {
ProposalCreatedEvent,
ProposalFinishedEvent,
UpdateCreatedEvent,
VestingCreatedEvent,
VotedEvent,
} from '../shared/types/events'
import { DEFAULT_AVATAR_IMAGE, getProfiles } from '../utils/Catalyst'
import { DclProfile } from '../utils/Catalyst/types'
import Time from '../utils/date/Time'
import { ErrorCategory } from '../utils/errorCategories'

import { NotificationService } from './notification'
Expand Down Expand Up @@ -370,6 +373,29 @@ export class EventsService {
}
}

static async projectEnacted(project: Project) {
const { author, id, proposal_id, funding } = project
if (!funding || !funding.vesting) {
ErrorService.report('Project enacted without vesting', { project_id: id, category: ErrorCategory.Events })
return
}
const { years, months, days } = Time(funding.vesting.finish_at).preciseDiff(Time(funding.vesting.start_at), true)
const vestingEvent: VestingCreatedEvent = {
id: crypto.randomUUID(),
address: author,
event_type: EventType.VestingCreated,
event_data: {
proposal_id,
proposal_title: project.title,
vesting_address: funding.vesting.address,
amount: funding.vesting.total,
duration_in_months: years * 12 + months + (days > 0 ? 1 : 0),
},
created_at: funding.enacted_at ? new Date(funding.enacted_at) : new Date(),
}
await EventModel.create(vestingEvent)
}

private static decodeLogTopics(topics: string[]) {
const methodSignature = topics[0]
const delegator = this.decodeTopicToAddress(topics[1])
Expand Down
11 changes: 11 additions & 0 deletions src/shared/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export type ProposalFinishedEventData = ProposalEventData & {
new_status: ProposalStatus
}

export type VestingCreatedEventData = ProposalEventData & {
vesting_address: string
amount: number
duration_in_months: number
}

type DelegationSetData = {
new_delegate: string | null
transaction_hash: string
Expand Down Expand Up @@ -77,6 +83,11 @@ export type ProposalFinishedEvent = {
event_data: ProposalFinishedEventData
} & CommonEventAttributes

export type VestingCreatedEvent = {
event_type: EventType.VestingCreated
event_data: VestingCreatedEventData
} & CommonEventAttributes

export type UpdateCreatedEvent = {
event_type: EventType.UpdateCreated
event_data: UpdateCreatedEventData
Expand Down

0 comments on commit 4689071

Please sign in to comment.