Skip to content

Commit

Permalink
Merge pull request #177 from metaDAOproject/feat/data-for-dao-view
Browse files Browse the repository at this point in the history
feat: data for dao view
  • Loading branch information
LukasDeco authored Aug 1, 2024
2 parents 4c25477 + 63ff85a commit 040ccc8
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/client/indexer/dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ export class FutarchyIndexerDaoClient implements FutarchyDaoClient {
slug: daoDetails.slug ?? "",
logo: daoDetails.image_url,
description: daoDetails.description,
url: daoDetails.url,
xAccount: daoDetails.x_account ?? "",
github: daoDetails.github ?? "",
failTokenImageUrl: daoDetails.fail_token_image_url,
passTokenImageUrl: daoDetails.pass_token_image_url,
lpTokenImageUrl: daoDetails.lp_token_image_url,
Expand Down
57 changes: 56 additions & 1 deletion lib/client/indexer/proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
BalanceLockedInProposal,
TransactionProcessingUpdate,
Dao,
GovernanceParticipant
GovernanceParticipant,
ProposalRanking
} from "@/types";
import { FutarchyProposalsClient } from "@/client";
import { FutarchyRPCProposalsClient } from "@/client/rpc";
Expand Down Expand Up @@ -317,6 +318,60 @@ export class FutarchyIndexerProposalsClient implements FutarchyProposalsClient {
.flat()
.filter((p): p is Proposal => !!p);
}

async fetchTopProposals(daoSlug: string): Promise<ProposalRanking[]> {
try {
const { proposals } = await this.graphqlClient.query?.({
proposals: {
__args: {
order_by: [
{
user_performances_aggregate: {
sum: {
total_volume: "desc_nulls_last"
}
}
}
],
limit: 3,
where: {
dao: {
dao_detail: {
slug: { _eq: daoSlug }
}
}
}
},
proposal_acct: true,
status: true,
proposal_details: {
title: true
},
user_performances_aggregate: {
aggregate: {
sum: {
total_volume: true
}
}
}
}
});

return proposals
.map((p) => ({
proposalAcct: new PublicKey(p.proposal_acct),
state: p.status as ProposalState,
title: p.proposal_details[0]?.title ?? "",
totalVolume:
p.user_performances_aggregate.aggregate?.sum?.total_volume ?? 0
}))
.filter((p) => p.totalVolume > 0 && p.title);
} catch (e) {
console.error("error fetching top proposals", e);
return [];
}
}

async fetchProposal(
proposalAcct: PublicKey
): Promise<ProposalWithFullData | null> {
Expand Down
2 changes: 2 additions & 0 deletions lib/client/indexer/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class FutarchyIndexerUserClient implements FutarchyUserClient {
tokens_sold: true,
volume_bought: true,
volume_sold: true,
total_volume: true,
created_at: true,
proposal: {
dao: {
Expand Down Expand Up @@ -256,6 +257,7 @@ export class FutarchyIndexerUserClient implements FutarchyUserClient {
tokensSold: p.tokens_sold,
volumeBought: p.volume_bought,
volumeSold: p.volume_sold,
totalVolume: p.total_volume,
createdAt: new Date(p.created_at),
pnl: pnl,
proposal: {
Expand Down
7 changes: 7 additions & 0 deletions lib/types/autocrats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ export type DaoAggregate = {
slug: string;
daos: Dao[];
logo?: string | null;
xAccount?: string | null;
github?: string | null;
discord?: string | null;
description?: string | null;
url?: string | null;
failTokenImageUrl?: string | null;
passTokenImageUrl?: string | null;
lpTokenImageUrl?: string | null;
Expand All @@ -102,6 +106,9 @@ export type DaoDetails__GQL = {
slug: string | null;
image_url: string | null;
description: string | null;
url: string | null;
x_account: string | null;
github: string | null;
fail_token_image_url: string | null;
pass_token_image_url: string | null;
lp_token_image_url: string | null;
Expand Down
1 change: 1 addition & 0 deletions lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export * from "./amm";
export * from "./prices";
export * from "./reactions";
export * from "./transactions";
export * from "./user";

export type MergeWithOptionalFields<T, U> = {
[K in keyof (T | U)]: U[K];
Expand Down
7 changes: 7 additions & 0 deletions lib/types/proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ export type ProposalCounts = {
past: number;
};

export type ProposalRanking = {
proposalAcct: PublicKey;
title: string;
state: ProposalState;
totalVolume: number;
};

export type Proposal = ProposalAccountWithKeyNoState & {
dao: {
name: string;
Expand Down
1 change: 1 addition & 0 deletions lib/types/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type UserPerformance = {
tokensSold: string;
volumeBought: string;
volumeSold: string;
totalVolume: number;
proposal: ProposalWithFullData;
createdAt: Date;
pnl: number;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metadaoproject/futarchy-sdk",
"version": "4.0.0-alpha.5",
"version": "4.0.0-alpha.6",
"main": "dist",
"scripts": {
"preinstall": "npx only-allow pnpm",
Expand Down

0 comments on commit 040ccc8

Please sign in to comment.