From 9b2b9b58d36346566717626623f2fb0296f660f7 Mon Sep 17 00:00:00 2001 From: Ian Macalinao Date: Fri, 24 Oct 2025 01:54:41 +0800 Subject: [PATCH 1/4] add ALT fetching --- bun.lock | 1 + packages/grill/package.json | 1 + packages/grill/src/accounts/address-lookup-table.ts | 13 +++++++++++++ packages/grill/src/accounts/index.ts | 1 + packages/grill/src/index.ts | 1 + 5 files changed, 17 insertions(+) create mode 100644 packages/grill/src/accounts/address-lookup-table.ts create mode 100644 packages/grill/src/accounts/index.ts diff --git a/bun.lock b/bun.lock index d9e48e0..7813ad8 100644 --- a/bun.lock +++ b/bun.lock @@ -127,6 +127,7 @@ "@macalinao/solana-batch-accounts-loader": "workspace:^", "@macalinao/token-utils": "workspace:^", "@macalinao/zod-solana": "workspace:^", + "@solana-program/address-lookup-table": "^0.7.0", "@solana-program/token": "^0.6.0", }, "devDependencies": { diff --git a/packages/grill/package.json b/packages/grill/package.json index 9c1a001..86d1c22 100644 --- a/packages/grill/package.json +++ b/packages/grill/package.json @@ -53,6 +53,7 @@ "@macalinao/solana-batch-accounts-loader": "workspace:^", "@macalinao/token-utils": "workspace:^", "@macalinao/zod-solana": "workspace:^", + "@solana-program/address-lookup-table": "^0.7.0", "@solana-program/token": "^0.6.0" }, "devDependencies": { diff --git a/packages/grill/src/accounts/address-lookup-table.ts b/packages/grill/src/accounts/address-lookup-table.ts new file mode 100644 index 0000000..b246414 --- /dev/null +++ b/packages/grill/src/accounts/address-lookup-table.ts @@ -0,0 +1,13 @@ +import { + createDecodedAccountHook, + createDecodedAccountsHook, +} from "@macalinao/grill"; +import { getAddressLookupTableDecoder } from "@solana-program/address-lookup-table"; + +export const useAddressLookupTable = createDecodedAccountHook( + getAddressLookupTableDecoder(), +); + +export const useAddressLookupTables = createDecodedAccountsHook( + getAddressLookupTableDecoder(), +); diff --git a/packages/grill/src/accounts/index.ts b/packages/grill/src/accounts/index.ts new file mode 100644 index 0000000..ee444ef --- /dev/null +++ b/packages/grill/src/accounts/index.ts @@ -0,0 +1 @@ +export * from "./address-lookup-table.js"; diff --git a/packages/grill/src/index.ts b/packages/grill/src/index.ts index cf13c54..e02d15f 100644 --- a/packages/grill/src/index.ts +++ b/packages/grill/src/index.ts @@ -1,5 +1,6 @@ export { SolanaProvider, useSolanaClient } from "@gillsdk/react"; export * from "@macalinao/gill-extra"; +export * from "./accounts/index.js"; export * from "./contexts/index.js"; export * from "./hooks/index.js"; export * from "./providers/index.js"; From 90affa86fd4e2c297e09d3a01f86ce7dec87159d Mon Sep 17 00:00:00 2001 From: Ian Macalinao Date: Fri, 24 Oct 2025 01:55:10 +0800 Subject: [PATCH 2/4] docs(changeset): Add ALT fetching hooks --- .changeset/crazy-drinks-kiss.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/crazy-drinks-kiss.md diff --git a/.changeset/crazy-drinks-kiss.md b/.changeset/crazy-drinks-kiss.md new file mode 100644 index 0000000..88a8929 --- /dev/null +++ b/.changeset/crazy-drinks-kiss.md @@ -0,0 +1,5 @@ +--- +"@macalinao/grill": patch +--- + +Add ALT fetching hooks From 0671a05de4d02033f3b0317fa4b742213054ea10 Mon Sep 17 00:00:00 2001 From: Ian Macalinao Date: Fri, 24 Oct 2025 02:28:21 +0800 Subject: [PATCH 3/4] reorganize directories --- packages/grill/src/accounts/index.ts | 2 + .../use-mint-account.ts => accounts/mint.ts} | 10 ++-- packages/grill/src/accounts/token-account.ts | 16 +++++++ packages/grill/src/hooks/index.ts | 3 -- .../src/hooks/use-associated-token-account.ts | 4 +- .../src/hooks/use-associated-token-pda.ts | 24 ---------- packages/grill/src/hooks/use-token-account.ts | 8 ---- packages/grill/src/hooks/use-token-balance.ts | 2 +- packages/grill/src/hooks/use-token-info.ts | 2 +- packages/grill/src/hooks/use-token-infos.ts | 2 +- packages/grill/src/index.ts | 1 + packages/grill/src/pdas/associated-token.ts | 47 +++++++++++++++++++ packages/grill/src/pdas/index.ts | 1 + 13 files changed, 78 insertions(+), 44 deletions(-) rename packages/grill/src/{hooks/use-mint-account.ts => accounts/mint.ts} (65%) create mode 100644 packages/grill/src/accounts/token-account.ts delete mode 100644 packages/grill/src/hooks/use-associated-token-pda.ts delete mode 100644 packages/grill/src/hooks/use-token-account.ts create mode 100644 packages/grill/src/pdas/associated-token.ts create mode 100644 packages/grill/src/pdas/index.ts diff --git a/packages/grill/src/accounts/index.ts b/packages/grill/src/accounts/index.ts index ee444ef..e93ef79 100644 --- a/packages/grill/src/accounts/index.ts +++ b/packages/grill/src/accounts/index.ts @@ -1 +1,3 @@ export * from "./address-lookup-table.js"; +export * from "./mint.js"; +export * from "./token-account.js"; diff --git a/packages/grill/src/hooks/use-mint-account.ts b/packages/grill/src/accounts/mint.ts similarity index 65% rename from packages/grill/src/hooks/use-mint-account.ts rename to packages/grill/src/accounts/mint.ts index f858ad7..1453ce6 100644 --- a/packages/grill/src/hooks/use-mint-account.ts +++ b/packages/grill/src/accounts/mint.ts @@ -1,9 +1,11 @@ import type { Mint } from "@solana-program/token"; -import type { UseDecodedAccountHook } from "./create-decoded-account-hook.js"; -import type { UseDecodedAccountsHook } from "./create-decoded-accounts-hook.js"; +import type { UseDecodedAccountHook } from "../hooks/create-decoded-account-hook.js"; +import type { UseDecodedAccountsHook } from "../hooks/create-decoded-accounts-hook.js"; +import { + createDecodedAccountHook, + createDecodedAccountsHook, +} from "@macalinao/grill"; import { getMintDecoder } from "@solana-program/token"; -import { createDecodedAccountHook } from "./create-decoded-account-hook.js"; -import { createDecodedAccountsHook } from "./create-decoded-accounts-hook.js"; /** * Hook for fetching and decoding a mint account diff --git a/packages/grill/src/accounts/token-account.ts b/packages/grill/src/accounts/token-account.ts new file mode 100644 index 0000000..3aeebf4 --- /dev/null +++ b/packages/grill/src/accounts/token-account.ts @@ -0,0 +1,16 @@ +import type { + UseDecodedAccountHook, + UseDecodedAccountsHook, +} from "@macalinao/grill"; +import type { Token } from "@solana-program/token"; +import { + createDecodedAccountHook, + createDecodedAccountsHook, +} from "@macalinao/grill"; +import { getTokenDecoder } from "@solana-program/token"; + +export const useTokenAccount: UseDecodedAccountHook = + createDecodedAccountHook(getTokenDecoder()); + +export const useTokenAccounts: UseDecodedAccountsHook = + createDecodedAccountsHook(getTokenDecoder()); diff --git a/packages/grill/src/hooks/index.ts b/packages/grill/src/hooks/index.ts index 3bdd958..a5d6ab9 100644 --- a/packages/grill/src/hooks/index.ts +++ b/packages/grill/src/hooks/index.ts @@ -5,13 +5,10 @@ export * from "./create-pdas-hook.js"; export * from "./use-account.js"; export * from "./use-accounts.js"; export * from "./use-associated-token-account.js"; -export * from "./use-associated-token-pda.js"; export * from "./use-ata-balance.js"; export { useConnectedWallet } from "./use-connected-wallet.js"; export { useKitWallet } from "./use-kit-wallet.js"; -export * from "./use-mint-account.js"; export * from "./use-send-tx.js"; -export * from "./use-token-account.js"; export * from "./use-token-balance.js"; export * from "./use-token-info.js"; export * from "./use-token-infos.js"; diff --git a/packages/grill/src/hooks/use-associated-token-account.ts b/packages/grill/src/hooks/use-associated-token-account.ts index 8706ff4..a8cdc55 100644 --- a/packages/grill/src/hooks/use-associated-token-account.ts +++ b/packages/grill/src/hooks/use-associated-token-account.ts @@ -2,8 +2,8 @@ import type { Account, Address } from "@solana/kit"; import type { Token } from "@solana-program/token"; import type { UseQueryResult } from "@tanstack/react-query"; import { TOKEN_PROGRAM_ADDRESS } from "@solana-program/token"; -import { useAssociatedTokenPda } from "./use-associated-token-pda.js"; -import { useTokenAccount } from "./use-token-account.js"; +import { useTokenAccount } from "../accounts/token-account.js"; +import { useAssociatedTokenPda } from "../pdas/associated-token.js"; export interface UseAssociatedTokenAccountOptions { /** The mint address of the token */ diff --git a/packages/grill/src/hooks/use-associated-token-pda.ts b/packages/grill/src/hooks/use-associated-token-pda.ts deleted file mode 100644 index 11c6d62..0000000 --- a/packages/grill/src/hooks/use-associated-token-pda.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { findAssociatedTokenPda } from "@solana-program/token"; -import { createPdaHook } from "./create-pda-hook.js"; - -/** - * Hook to compute the Associated Token Account (ATA) address for a given mint and owner - * - * @example - * ```typescript - * const { data: ataPda, isLoading } = useAssociatedTokenPda({ - * mint: mintAddress, - * owner: ownerAddress, - * tokenProgram: TOKEN_PROGRAM_ADDRESS, - * }); - * - * if (ataPda) { - * const [ataAddress, bump] = ataPda; - * console.log("ATA address:", ataAddress); - * } - * ``` - */ -export const useAssociatedTokenPda = createPdaHook( - findAssociatedTokenPda, - "associatedTokenPda", -); diff --git a/packages/grill/src/hooks/use-token-account.ts b/packages/grill/src/hooks/use-token-account.ts deleted file mode 100644 index c7069dc..0000000 --- a/packages/grill/src/hooks/use-token-account.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type { Token } from "@solana-program/token"; -import { getTokenDecoder } from "@solana-program/token"; -import { createDecodedAccountHook } from "./create-decoded-account-hook.js"; - -// Create the base hook using the generic helper -export const useTokenAccount = createDecodedAccountHook( - getTokenDecoder(), -); diff --git a/packages/grill/src/hooks/use-token-balance.ts b/packages/grill/src/hooks/use-token-balance.ts index d8ce7b9..ea9ae85 100644 --- a/packages/grill/src/hooks/use-token-balance.ts +++ b/packages/grill/src/hooks/use-token-balance.ts @@ -2,7 +2,7 @@ import type { TokenAmount } from "@macalinao/token-utils"; import type { Address } from "@solana/kit"; import { createTokenAmount } from "@macalinao/token-utils"; import { useMemo } from "react"; -import { useTokenAccount } from "./use-token-account.js"; +import { useTokenAccount } from "../accounts/token-account.js"; import { useTokenInfo } from "./use-token-info.js"; export interface UseTokenBalanceOptions { diff --git a/packages/grill/src/hooks/use-token-info.ts b/packages/grill/src/hooks/use-token-info.ts index 1d503e5..369a0ca 100644 --- a/packages/grill/src/hooks/use-token-info.ts +++ b/packages/grill/src/hooks/use-token-info.ts @@ -3,9 +3,9 @@ import type { Address } from "@solana/kit"; import type { UseQueryResult } from "@tanstack/react-query"; import { fetchTokenInfo } from "@macalinao/gill-extra"; import { useQuery } from "@tanstack/react-query"; +import { useMintAccount } from "../accounts/mint.js"; import { useGrillContext } from "../contexts/grill-context.js"; import { createTokenInfoQueryKey } from "../query-keys.js"; -import { useMintAccount } from "./use-mint-account.js"; import { useTokenMetadataAccount } from "./use-token-metadata-account.js"; export interface UseTokenInfoInput { diff --git a/packages/grill/src/hooks/use-token-infos.ts b/packages/grill/src/hooks/use-token-infos.ts index a4f1dc5..3c2ec35 100644 --- a/packages/grill/src/hooks/use-token-infos.ts +++ b/packages/grill/src/hooks/use-token-infos.ts @@ -2,9 +2,9 @@ import type { TokenInfo } from "@macalinao/token-utils"; import type { Address } from "@solana/kit"; import { fetchTokenInfo } from "@macalinao/gill-extra"; import { useQueries } from "@tanstack/react-query"; +import { useMintAccounts } from "../accounts/mint.js"; import { useGrillContext } from "../contexts/grill-context.js"; import { createTokenInfoQueryKey } from "../query-keys.js"; -import { useMintAccounts } from "./use-mint-account.js"; import { useTokenMetadataAccounts } from "./use-token-metadata-account.js"; export interface UseTokenInfosInput { diff --git a/packages/grill/src/index.ts b/packages/grill/src/index.ts index e02d15f..b40b28f 100644 --- a/packages/grill/src/index.ts +++ b/packages/grill/src/index.ts @@ -3,6 +3,7 @@ export * from "@macalinao/gill-extra"; export * from "./accounts/index.js"; export * from "./contexts/index.js"; export * from "./hooks/index.js"; +export * from "./pdas/index.js"; export * from "./providers/index.js"; export * from "./query-keys.js"; export * from "./types.js"; diff --git a/packages/grill/src/pdas/associated-token.ts b/packages/grill/src/pdas/associated-token.ts new file mode 100644 index 0000000..d1b673f --- /dev/null +++ b/packages/grill/src/pdas/associated-token.ts @@ -0,0 +1,47 @@ +import { createPdaHook, createPdasHook } from "@macalinao/grill"; +import { findAssociatedTokenPda } from "@solana-program/token"; + +/** + * Hook to compute the Associated Token Account (ATA) address for a given mint and owner + * + * @example + * ```typescript + * const { data: ataPda, isLoading } = useAssociatedTokenPda({ + * mint: mintAddress, + * owner: ownerAddress, + * tokenProgram: TOKEN_PROGRAM_ADDRESS, + * }); + * + * if (ataPda) { + * const [ataAddress, bump] = ataPda; + * console.log("ATA address:", ataAddress); + * } + * ``` + */ +export const useAssociatedTokenPda = createPdaHook( + findAssociatedTokenPda, + "associatedTokenPda", +); + +/** + * Hook to compute multiple Associated Token Account (ATA) addresses for given mints and owners + * + * @example + * ```typescript + * const { data: ataPdas, isLoading } = useAssociatedTokenPdas([ + * { mint: mintAddress1, owner: ownerAddress1 }, + * { mint: mintAddress2, owner: ownerAddress2 }, + * ]); + * + * ataPdas?.forEach((ataPda, index) => { + * if (ataPda) { + * const [ataAddress, bump] = ataPda; + * console.log(`ATA ${index} address:`, ataAddress); + * } + * }); + * ``` + */ +export const useAssociatedTokenPdas = createPdasHook( + findAssociatedTokenPda, + "associatedTokenPdas", +); diff --git a/packages/grill/src/pdas/index.ts b/packages/grill/src/pdas/index.ts new file mode 100644 index 0000000..9177e0c --- /dev/null +++ b/packages/grill/src/pdas/index.ts @@ -0,0 +1 @@ +export * from "./associated-token.js"; From f4b610cb4162e2e3c74b423992ccaeba7942d6b4 Mon Sep 17 00:00:00 2001 From: Ian Macalinao Date: Fri, 24 Oct 2025 02:28:44 +0800 Subject: [PATCH 4/4] docs(changeset): Reorganize directory structure of account/pda fetchers --- .changeset/warm-beans-check.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/warm-beans-check.md diff --git a/.changeset/warm-beans-check.md b/.changeset/warm-beans-check.md new file mode 100644 index 0000000..a134803 --- /dev/null +++ b/.changeset/warm-beans-check.md @@ -0,0 +1,5 @@ +--- +"@macalinao/grill": patch +--- + +Reorganize directory structure of account/pda fetchers