-
Notifications
You must be signed in to change notification settings - Fork 39
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
feat: New project events #1874
feat: New project events #1874
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { MigrationBuilder } from "node-pg-migrate" | ||
import { EventType } from "../shared/types/events" | ||
|
||
export async function up(pgm: MigrationBuilder): Promise<void> { | ||
pgm.addTypeValue({name: 'event_type'}, EventType.ProposalFinished) | ||
pgm.addTypeValue({name: 'event_type'}, EventType.VestingCreated) | ||
} | ||
|
||
export async function down(): Promise<void> { | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't you remove those event types? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not recommended to do that (check here) |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, no need for await There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's also an async method 🤔 |
||
} | ||
|
||
DiscourseService.commentUpdatedProposal(updatedProposal) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { ethers } from 'ethers' | |
import isEthereumAddress from 'validator/lib/isEthereumAddress' | ||
|
||
import ProposalModel from '../entities/Proposal/model' | ||
import { ProposalWithOutcome } from '../entities/Proposal/outcome' | ||
import { ProposalAttributes } from '../entities/Proposal/types' | ||
import { SNAPSHOT_SPACE } from '../entities/Snapshot/constants' | ||
import UpdateModel from '../entities/Updates/model' | ||
|
@@ -12,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' | ||
|
@@ -27,11 +29,14 @@ import { | |
ProjectUpdateCommentedEvent, | ||
ProposalCommentedEvent, | ||
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' | ||
|
@@ -354,6 +359,43 @@ export class EventsService { | |
} | ||
} | ||
|
||
static async proposalFinished(proposalsWithOutcome: ProposalWithOutcome[]) { | ||
for (const proposal of proposalsWithOutcome) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we should try catch inside the for... wdyt? |
||
const { id, title, newStatus, finish_at, user } = proposal | ||
const finishEvent: ProposalFinishedEvent = { | ||
id: crypto.randomUUID(), | ||
address: user, | ||
event_type: EventType.ProposalFinished, | ||
event_data: { proposal_id: id, proposal_title: title, new_status: newStatus }, | ||
created_at: new Date(finish_at), | ||
} | ||
await EventModel.create(finishEvent) | ||
} | ||
} | ||
|
||
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]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to await this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not? it's an async method