|
| 1 | +import type { Address } from "@solana/kit"; |
| 2 | + |
| 3 | +export const GRILL_REACT_QUERY_NAMESPACE = "solana" as const; |
| 4 | + |
| 5 | +// Type definitions for query keys |
| 6 | +export type AccountQueryKey = readonly ["solana", "account", Address]; |
| 7 | +export type TokenInfoQueryKey = readonly [ |
| 8 | + "solana", |
| 9 | + "tokenInfo", |
| 10 | + Address | null | undefined, |
| 11 | +]; |
| 12 | +export type PdaQueryKey<TArgs> = readonly [ |
| 13 | + "solana", |
| 14 | + "pda", |
| 15 | + string, |
| 16 | + TArgs | null | undefined, |
| 17 | +]; |
| 18 | + |
| 19 | +/** |
| 20 | + * Create a query key for the account query |
| 21 | + * @param address - The address of the account |
| 22 | + * @returns The query key |
| 23 | + */ |
| 24 | +export const createAccountQueryKey = (address: Address): AccountQueryKey => |
| 25 | + [GRILL_REACT_QUERY_NAMESPACE, "account", address] as const; |
| 26 | + |
| 27 | +/** |
| 28 | + * Create a query key for token info query |
| 29 | + * @param mint - The mint address |
| 30 | + * @returns The query key |
| 31 | + */ |
| 32 | +export const createTokenInfoQueryKey = ( |
| 33 | + mint: Address | null | undefined, |
| 34 | +): TokenInfoQueryKey => |
| 35 | + [GRILL_REACT_QUERY_NAMESPACE, "tokenInfo", mint] as const; |
| 36 | + |
| 37 | +/** |
| 38 | + * Create a query key for PDA queries |
| 39 | + * @param queryKeyPrefix - The PDA type prefix |
| 40 | + * @param args - The arguments for the PDA |
| 41 | + * @returns The query key |
| 42 | + */ |
| 43 | +export const createPdaQueryKey = <TArgs>( |
| 44 | + queryKeyPrefix: string, |
| 45 | + args: TArgs | null | undefined, |
| 46 | +): PdaQueryKey<TArgs> => |
| 47 | + [GRILL_REACT_QUERY_NAMESPACE, "pda", queryKeyPrefix, args] as const; |
0 commit comments