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

add conditional tokens to dao details #117

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions lib/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ export interface FutarchyBalancesClient {
): Array<TokenWithPDA & { proposal: PublicKey }>;
fetchAllConditionalTokenWalletBalances(
ownerWallet: PublicKey | null,
quoteToken: TokenProps,
baseToken: TokenProps,
proposals: Proposal[]
quoteToken: TokenProps,
proposals: Proposal[],
passTokenUrl?: string,
failTokenUrl?: string,
): Promise<TokenWithBalancePDAAndProposal[]>;
watchTokenBalance(tokenWithPDA: TokenWithPDA): Observable<TokenWithBalance>;
}
Expand Down
8 changes: 6 additions & 2 deletions lib/client/indexer/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@ export class FutarchyIndexerBalancesClient implements FutarchyBalancesClient {
ownerWallet: PublicKey | null,
baseToken: TokenProps,
quoteToken: TokenProps,
proposalsWithVaults: Proposal[]
proposalsWithVaults: Proposal[],
passTokenUrl?: string,
failtokenUrl?: string,
): Promise<TokenWithBalancePDAAndProposal[]> {
return this.rpcBalancesClient.fetchAllConditionalTokenWalletBalances(
ownerWallet,
baseToken,
quoteToken,
proposalsWithVaults
proposalsWithVaults,
passTokenUrl,
failtokenUrl,
);
}
watchTokenBalance(tokenWithPDA: TokenWithPDA): Observable<TokenWithBalance> {
Expand Down
9 changes: 9 additions & 0 deletions lib/client/indexer/dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export class FutarchyIndexerDaoClient implements FutarchyDaoClient {
x_account: true,
description: true,
image_url: true,
fail_token_image_url: true,
pass_token_image_url: true,
lp_token_image_url: true,
daos: {
program_acct: true,
dao_acct: true,
Expand Down Expand Up @@ -86,6 +89,9 @@ export class FutarchyIndexerDaoClient implements FutarchyDaoClient {
x_account: true,
description: true,
image_url: true,
fail_token_image_url: true,
pass_token_image_url: true,
lp_token_image_url: true,
daos: {
program_acct: true,
dao_acct: true,
Expand Down Expand Up @@ -131,6 +137,9 @@ export class FutarchyIndexerDaoClient implements FutarchyDaoClient {
name: daoDetails.name ?? "",
slug: daoDetails.slug ?? "",
logo: daoDetails.image_url,
failTokenImageUrl: daoDetails.fail_token_image_url,
passTokenImageUrl: daoDetails.pass_token_image_url,
lpTokenImageUrl: daoDetails.lp_token_image_url,
daos: daoDetails.daos
.map((d) => {
if (this.protocolMap.get(d.program_acct)) {
Expand Down
79 changes: 44 additions & 35 deletions lib/client/rpc/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { Proposal } from "@/types/proposals";
import { BN, Provider } from "@coral-xyz/anchor";
import { Observable, retry } from "rxjs";

const PASS_USDC_URL = "https://imagedelivery.net/HYEnlujCFMCgj6yA728xIw/f38677ab-8ec6-4706-6606-7d4e0a3cfc00/public"
const FAIL_USDC_URL = "https://imagedelivery.net/HYEnlujCFMCgj6yA728xIw/d9bfd8de-2937-419a-96f6-8d6a3a76d200/public"

export class FutarchyRPCBalancesClient implements FutarchyBalancesClient {
private rpcProvider: Provider;

Expand Down Expand Up @@ -98,10 +101,10 @@ export class FutarchyRPCBalancesClient implements FutarchyBalancesClient {
mapping.set(dao.baseToken.publicKey, {
pda: owner
? getAssociatedTokenAddressSync(
new PublicKey(dao.baseToken.publicKey),
owner,
true
)
new PublicKey(dao.baseToken.publicKey),
owner,
true
)
: null,
token: dao.baseToken
});
Expand All @@ -110,10 +113,10 @@ export class FutarchyRPCBalancesClient implements FutarchyBalancesClient {
mapping.set(dao.quoteToken.publicKey, {
pda: owner
? getAssociatedTokenAddressSync(
new PublicKey(dao.quoteToken.publicKey),
owner,
true
)
new PublicKey(dao.quoteToken.publicKey),
owner,
true
)
: null,
token: dao.quoteToken
});
Expand Down Expand Up @@ -178,7 +181,9 @@ export class FutarchyRPCBalancesClient implements FutarchyBalancesClient {
ownerWallet: PublicKey | null,
baseToken: TokenProps,
quoteToken: TokenProps,
proposals: Proposal[]
proposals: Proposal[],
passTokenUrl?: string,
failTokenUrl?: string,
): Promise<TokenWithBalancePDAAndProposal[]> {
const tokenBalances = await Promise.all(
proposals.map(async (proposal) => {
Expand All @@ -188,15 +193,16 @@ export class FutarchyRPCBalancesClient implements FutarchyBalancesClient {
{
pda: ownerWallet
? getAssociatedTokenAddressSync(
new PublicKey(
proposal.baseVaultAccount.conditionalOnFinalizeTokenMint
),
ownerWallet,
true
)
new PublicKey(
proposal.baseVaultAccount.conditionalOnFinalizeTokenMint
),
ownerWallet,
true
)
: null,
token: {
...baseToken,
url: passTokenUrl ?? baseToken.url,
publicKey:
proposal.baseVaultAccount.conditionalOnFinalizeTokenMint.toString(),
symbol: "p" + baseToken.symbol
Expand All @@ -206,15 +212,16 @@ export class FutarchyRPCBalancesClient implements FutarchyBalancesClient {
{
pda: ownerWallet
? getAssociatedTokenAddressSync(
new PublicKey(
proposal.baseVaultAccount.conditionalOnRevertTokenMint
),
ownerWallet,
true
)
new PublicKey(
proposal.baseVaultAccount.conditionalOnRevertTokenMint
),
ownerWallet,
true
)
: null,
token: {
...baseToken,
url: failTokenUrl ?? baseToken.url,
publicKey:
proposal.baseVaultAccount.conditionalOnRevertTokenMint.toString(),
symbol: "f" + baseToken.symbol
Expand All @@ -224,15 +231,16 @@ export class FutarchyRPCBalancesClient implements FutarchyBalancesClient {
{
pda: ownerWallet
? getAssociatedTokenAddressSync(
new PublicKey(
proposal.quoteVaultAccount.conditionalOnFinalizeTokenMint
),
ownerWallet,
true
)
new PublicKey(
proposal.quoteVaultAccount.conditionalOnFinalizeTokenMint
),
ownerWallet,
true
)
: null,
token: {
...quoteToken,
url: PASS_USDC_URL,
publicKey:
proposal.quoteVaultAccount.conditionalOnFinalizeTokenMint.toString(),
symbol: "p" + quoteToken.symbol
Expand All @@ -242,15 +250,16 @@ export class FutarchyRPCBalancesClient implements FutarchyBalancesClient {
{
pda: ownerWallet
? getAssociatedTokenAddressSync(
new PublicKey(
proposal.quoteVaultAccount.conditionalOnRevertTokenMint
),
ownerWallet,
true
)
new PublicKey(
proposal.quoteVaultAccount.conditionalOnRevertTokenMint
),
ownerWallet,
true
)
: null,
token: {
...quoteToken,
url: FAIL_USDC_URL,
publicKey:
proposal.quoteVaultAccount.conditionalOnRevertTokenMint.toString(),
symbol: "f" + quoteToken.symbol
Expand All @@ -264,8 +273,8 @@ export class FutarchyRPCBalancesClient implements FutarchyBalancesClient {
try {
const tokenBalance = t.pda
? await this.rpcProvider.connection.getTokenAccountBalance(
t.pda
)
t.pda
)
: { value: { uiAmount: 0 } };
return {
balance: tokenBalance.value.uiAmount ?? 0,
Expand Down
6 changes: 6 additions & 0 deletions lib/types/autocrats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,19 @@ export type DaoAggregate = {
slug: string;
daos: Dao[];
logo?: string | null;
failTokenImageUrl?: string | null,
passTokenImageUrl?: string | null,
lpTokenImageUrl?: string | null,
};

/** INDEXER GRAPHQL TYPES */
export type DaoDetails__GQL = {
name: string | null;
slug: string | null;
image_url: string | null;
fail_token_image_url: string | null,
pass_token_image_url: string | null,
lp_token_image_url: string | null,
daos: Array<{
program_acct: string;
dao_acct: string;
Expand Down
Loading