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

Autovote on contests #9993

Merged
merged 19 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 11 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
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:
NODE_ENV: 'test'
ROLLBAR_ENV: 'GitHubCI'
TEST_WITHOUT_LOGS: 'true'
PRIVATE_KEY: 'web3-pk'
PRIVATE_KEY: '0x83c65f24efbc8f4bc54ad425e897fc3ea01f760d5e71671a30eacb075ebe2313'
rbennettcw marked this conversation as resolved.
Show resolved Hide resolved
USES_DOCKER_PGSQL: true
PORT: 8080
REDIS_URL: redis://localhost:6379
Expand Down
4 changes: 4 additions & 0 deletions libs/core/src/integration/events.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,7 @@ export const FarcasterReplyCastCreated = FarcasterCast.describe(
export const FarcasterVoteCreated = FarcasterAction.extend({
contest_address: z.string(),
}).describe('When a farcaster action is initiated on a cast reply');

export const CheckContests = z.object({});
rbennettcw marked this conversation as resolved.
Show resolved Hide resolved

export const RolloverContests = z.object({});
10 changes: 10 additions & 0 deletions libs/core/src/integration/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export enum EventNames {
FarcasterCastCreated = 'FarcasterCastCreated',
FarcasterReplyCastCreated = 'FarcasterReplyCastCreated',
FarcasterVoteCreated = 'FarcasterVoteCreated',
CheckContests = 'CheckContests',
RolloverContests = 'RolloverContests',

// Preferences
SubscriptionPreferencesUpdated = 'SubscriptionPreferencesUpdated',
Expand Down Expand Up @@ -113,6 +115,14 @@ export type EventPairs =
event_name: EventNames.FarcasterVoteCreated;
event_payload: z.infer<typeof events.FarcasterVoteCreated>;
}
| {
event_name: EventNames.CheckContests;
event_payload: z.infer<typeof events.CheckContests>;
}
| {
event_name: EventNames.RolloverContests;
event_payload: z.infer<typeof events.RolloverContests>;
}
| {
event_name: EventNames.DiscordThreadCreated;
event_payload: z.infer<typeof events.DiscordThreadCreated>;
Expand Down
12 changes: 12 additions & 0 deletions libs/core/src/integration/outbox.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ export const Outbox = z.union([
event_payload: events.FarcasterVoteCreated,
})
.merge(BaseOutboxProperties),
z
.object({
rbennettcw marked this conversation as resolved.
Show resolved Hide resolved
event_name: z.literal(EventNames.CheckContests),
event_payload: events.CheckContests,
})
.merge(BaseOutboxProperties),
z
.object({
event_name: z.literal(EventNames.RolloverContests),
event_payload: events.RolloverContests,
})
.merge(BaseOutboxProperties),
z
.object({
event_name: z.literal(EventNames.DiscordThreadCreated),
Expand Down
23 changes: 14 additions & 9 deletions libs/model/src/contest/GetActiveContestManagers.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function GetActiveContestManagers(): Query<
url: string;
private_url: string;
contest_address: string;
end_time: string;
max_contest_id: number;
actions: Array<z.infer<typeof schemas.ContestAction>>;
}>(
Expand All @@ -29,6 +30,7 @@ export function GetActiveContestManagers(): Query<
cn.url,
cm.contest_address,
co.max_contest_id,
co.end_time,
COALESCE(JSON_AGG(ca) FILTER (WHERE ca IS NOT NULL), '[]'::json) as actions
FROM "Communities" c
JOIN "ChainNodes" cn ON c.chain_node_id = cn.id
Expand All @@ -40,24 +42,26 @@ export function GetActiveContestManagers(): Query<
FROM "Contests"
GROUP BY contest_address) co ON cm.contest_address = co.contest_address
LEFT JOIN "ContestActions" ca on (
ca.contest_address = cm.contest_address AND
ca.created_at > co.start_time AND
ca.created_at < co.end_time
)
WHERE cm.topic_id = :topic_id
AND cm.community_id = :community_id
AND cm.cancelled IS NOT TRUE
ca.contest_address = cm.contest_address AND
ca.created_at > co.start_time AND
ca.created_at < co.end_time
)
WHERE
cm.cancelled IS NOT TRUE
AND cm.ended IS NOT TRUE
${payload.topic_id ? 'AND cm.topic_id = :topic_id' : ''}
${payload.community_id ? 'AND cm.community_id = :community_id' : ''}
AND (
cm.interval = 0 AND NOW() < co.end_time
OR
cm.interval > 0
)
GROUP BY cn.eth_chain_id, cn.private_url, cn.url, cm.contest_address, co.max_contest_id
GROUP BY cn.eth_chain_id, cn.private_url, cn.url, cm.contest_address, co.max_contest_id, co.end_time
`,
{
type: QueryTypes.SELECT,
replacements: {
topic_id: payload.topic_id!,
topic_id: payload.topic_id,
community_id: payload.community_id,
},
},
Expand All @@ -67,6 +71,7 @@ export function GetActiveContestManagers(): Query<
eth_chain_id: r.eth_chain_id,
url: getChainNodeUrl(r),
contest_address: r.contest_address,
end_time: new Date(r.end_time),
max_contest_id: r.max_contest_id,
actions: r.actions,
}));
Expand Down
133 changes: 0 additions & 133 deletions libs/model/src/contest/PerformContestRollovers.command.ts

This file was deleted.

1 change: 0 additions & 1 deletion libs/model/src/contest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ export * from './GetContest.query';
export * from './GetContestLog.query';
export * from './GetFarcasterContestCasts';
export * from './GetFarcasterUpvoteActionMetadata.query';
export * from './PerformContestRollovers.command';
export * from './UpdateContestManagerMetadata.command';
Loading
Loading