From 468907146b6eebf19a1e6775e1e37e6dd6ce48dd Mon Sep 17 00:00:00 2001 From: ncomerci Date: Wed, 3 Jul 2024 13:51:06 -0300 Subject: [PATCH] added project enacted event --- src/services/ProposalService.ts | 1 + src/services/events.ts | 26 ++++++++++++++++++++++++++ src/shared/types/events.ts | 11 +++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/services/ProposalService.ts b/src/services/ProposalService.ts index cd529c617..a11b7a9de 100644 --- a/src/services/ProposalService.ts +++ b/src/services/ProposalService.ts @@ -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) diff --git a/src/services/events.ts b/src/services/events.ts index f335cafee..0f8dfe15b 100644 --- a/src/services/events.ts +++ b/src/services/events.ts @@ -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' @@ -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' @@ -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]) diff --git a/src/shared/types/events.ts b/src/shared/types/events.ts index 56f682256..5ceedd665 100644 --- a/src/shared/types/events.ts +++ b/src/shared/types/events.ts @@ -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 @@ -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