Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/crazy-drinks-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@macalinao/grill": patch
---

Add ALT fetching hooks
5 changes: 5 additions & 0 deletions .changeset/warm-beans-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@macalinao/grill": patch
---

Reorganize directory structure of account/pda fetchers
1 change: 1 addition & 0 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions packages/grill/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
13 changes: 13 additions & 0 deletions packages/grill/src/accounts/address-lookup-table.ts
Original file line number Diff line number Diff line change
@@ -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(),
);
3 changes: 3 additions & 0 deletions packages/grill/src/accounts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./address-lookup-table.js";
export * from "./mint.js";
export * from "./token-account.js";
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 16 additions & 0 deletions packages/grill/src/accounts/token-account.ts
Original file line number Diff line number Diff line change
@@ -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<Token> =
createDecodedAccountHook<Token>(getTokenDecoder());

export const useTokenAccounts: UseDecodedAccountsHook<Token> =
createDecodedAccountsHook<Token>(getTokenDecoder());
3 changes: 0 additions & 3 deletions packages/grill/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions packages/grill/src/hooks/use-associated-token-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
24 changes: 0 additions & 24 deletions packages/grill/src/hooks/use-associated-token-pda.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/grill/src/hooks/use-token-account.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/grill/src/hooks/use-token-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/grill/src/hooks/use-token-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/grill/src/hooks/use-token-infos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions packages/grill/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
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 "./pdas/index.js";
export * from "./providers/index.js";
export * from "./query-keys.js";
export * from "./types.js";
Expand Down
47 changes: 47 additions & 0 deletions packages/grill/src/pdas/associated-token.ts
Original file line number Diff line number Diff line change
@@ -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",
);
1 change: 1 addition & 0 deletions packages/grill/src/pdas/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./associated-token.js";