Skip to content

Commit

Permalink
Merge branch 'feat/add-testing-optimizations' of https://github.com/m…
Browse files Browse the repository at this point in the history
…etaDAOproject/futarchy-sdk into feat/add-testing-optimizations
  • Loading branch information
Reid-Garner committed Aug 4, 2024
2 parents f9244b9 + 21209b5 commit 35c2e93
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
ProposalAccounts,
ProgramVersionLabel,
ProposalWithFullData,
Dao
Dao,
TokenCache
} from "@/types";
import { SwapType } from "@metadaoproject/futarchy";
import { Observable } from "rxjs";
Expand Down Expand Up @@ -220,3 +221,7 @@ export interface CreateProposal {
proposalDetails: ProposalDetails
): void;
}

export interface FutarchyTokenClient {
fetchFutarchyTokens(): Promise<TokenCache[] | undefined>;
}
6 changes: 6 additions & 0 deletions lib/client/indexer/indexerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { ClientOptions, createClient as createWsClient } from "graphql-ws";
import { FutarchyProtocol } from "@/types";
import { Observable } from "rxjs";
import { FutarchyIndexerUserClient } from "./user";
import { FutarchyIndexerTokenClient } from "./tokens";

export class FutarchyIndexerClient implements FutarchyClient {
public daos: FutarchyIndexerDaoClient;
public proposals: FutarchyIndexerProposalsClient;
public balances: FutarchyIndexerBalancesClient;
public markets: FutarchyIndexerMarketsClient;
public user: FutarchyIndexerUserClient;
public tokens: FutarchyIndexerTokenClient;
private protocolMap: Map<string, FutarchyProtocol>;
private wsClient;

Expand Down Expand Up @@ -75,6 +77,10 @@ export class FutarchyIndexerClient implements FutarchyClient {
graphqlClient,
this.protocolMap,
)
this.tokens = new FutarchyIndexerTokenClient(
rpcClient.daos,
graphqlClient
)
}

watchSlot() {
Expand Down
64 changes: 64 additions & 0 deletions lib/client/indexer/tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {
Tokens__GQL,
TokenCache
} from "@/types";
import { FutarchyTokenClient } from "@/client";
import { FutarchyRPCDaoClient } from "../rpc";
import {
Client as IndexerGraphQLClient,
} from "./__generated__";

export class FutarchyIndexerTokenClient implements FutarchyTokenClient {
private rpcDaoClient: FutarchyRPCDaoClient;
private graphqlClient: IndexerGraphQLClient;
constructor(
rpcDaoClient: FutarchyRPCDaoClient,
graphqlClient: IndexerGraphQLClient,
) {
this.rpcDaoClient = rpcDaoClient;
this.graphqlClient = graphqlClient;
}
async fetchFutarchyTokens(): Promise<TokenCache[]> {
try {

const { tokens } = await this.graphqlClient.query?.({
tokens: {
__args: {
where: {}
},
// pass arguments to the query
decimals: true,
symbol: true,
mint_acct: true,
name: true,
image_url: true,
supply: true,
updated_at: true,
}
});

const tokenDetails = this.getTokenCacheFromQuery(tokens) ?? [] as TokenCache[]

return tokenDetails;
} catch (e) {
console.error(e);
//return this.rpcDaoClient.fetchFutarchyTokens();
return []
}
}

private getTokenCacheFromQuery(
tokens: Tokens__GQL
): TokenCache[] {
return tokens.map((t) => {
return {
symbol: t.symbol,
decimals: t.decimals,
name: t.name ?? null,
mint_acct: t.mint_acct,
url: t.image_url,
supply: t.supply ?? null
} as TokenCache
}) as TokenCache[]
};
}
19 changes: 19 additions & 0 deletions lib/types/autocrats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ export type Dao = {
};
};

// Tokens Cache
export type TokenCache = {
symbol: string;
decimals: number;
name: string | null;
mint_acct: string;
url: string;
supply: number | null;
}

// we might want to consider changing this to be DaoDetails as the main component and
export type DaoAggregate = {
name: string;
Expand Down Expand Up @@ -142,3 +152,12 @@ export type DaoDetails__GQL = {
};
}>;
};

export type Tokens__GQL = {
symbol: string;
decimals: number;
name: string | null;
mint_acct: string;
image_url: string | null;
supply: number | null;
}[]

0 comments on commit 35c2e93

Please sign in to comment.