@vue-solana/core 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +44 -35
  2. package/dist/address.cjs +10 -10
  3. package/dist/address.d.cts +11 -13
  4. package/dist/address.d.mts +11 -13
  5. package/dist/address.d.ts +11 -13
  6. package/dist/address.mjs +10 -10
  7. package/dist/buffer-polyfill.d.cts +0 -1
  8. package/dist/buffer-polyfill.d.mts +0 -1
  9. package/dist/buffer-polyfill.d.ts +0 -1
  10. package/dist/clusters.d.cts +1 -4
  11. package/dist/clusters.d.mts +1 -4
  12. package/dist/clusters.d.ts +1 -4
  13. package/dist/index.cjs +3 -19
  14. package/dist/index.d.cts +5 -9
  15. package/dist/index.d.mts +5 -9
  16. package/dist/index.d.ts +5 -9
  17. package/dist/index.mjs +4 -6
  18. package/dist/ios-wallet.cjs +2 -2
  19. package/dist/ios-wallet.d.cts +1 -4
  20. package/dist/ios-wallet.d.mts +1 -4
  21. package/dist/ios-wallet.d.ts +1 -4
  22. package/dist/ios-wallet.mjs +2 -2
  23. package/dist/kit.d.cts +2 -5
  24. package/dist/kit.d.mts +2 -5
  25. package/dist/kit.d.ts +2 -5
  26. package/dist/mobile-wallet.d.cts +1 -4
  27. package/dist/mobile-wallet.d.mts +1 -4
  28. package/dist/mobile-wallet.d.ts +1 -4
  29. package/dist/rpc.cjs +0 -12
  30. package/dist/rpc.d.cts +2 -11
  31. package/dist/rpc.d.mts +2 -11
  32. package/dist/rpc.d.ts +2 -11
  33. package/dist/rpc.mjs +1 -12
  34. package/dist/shared/{core.DjbtrJWl.mjs → core.BOHiMZiM.mjs} +7 -33
  35. package/dist/shared/{core.Ch_Z7_17.mjs → core.BwW4HVQI.mjs} +12 -28
  36. package/dist/shared/{core.BsekSwcZ.cjs → core.Cb48vQvC.cjs} +12 -28
  37. package/dist/shared/{core.BQoh-5Wu.cjs → core.Cu_gaUSn.cjs} +20 -46
  38. package/dist/shared/{core.DAUuCWrr.d.mts → core.DMgTrB_2.d.cts} +21 -17
  39. package/dist/shared/{core.DAUuCWrr.d.ts → core.DMgTrB_2.d.mts} +21 -17
  40. package/dist/shared/{core.DAUuCWrr.d.cts → core.DMgTrB_2.d.ts} +21 -17
  41. package/dist/token-accounts.cjs +44 -28
  42. package/dist/token-accounts.d.cts +20 -20
  43. package/dist/token-accounts.d.mts +20 -20
  44. package/dist/token-accounts.d.ts +20 -20
  45. package/dist/token-accounts.mjs +44 -28
  46. package/dist/transaction.cjs +50 -31
  47. package/dist/transaction.d.cts +9 -15
  48. package/dist/transaction.d.mts +9 -15
  49. package/dist/transaction.d.ts +9 -15
  50. package/dist/transaction.mjs +51 -32
  51. package/dist/types.d.cts +1 -4
  52. package/dist/types.d.mts +1 -4
  53. package/dist/types.d.ts +1 -4
  54. package/dist/wallet-standard.cjs +1 -4
  55. package/dist/wallet-standard.d.cts +1 -4
  56. package/dist/wallet-standard.d.mts +1 -4
  57. package/dist/wallet-standard.d.ts +1 -4
  58. package/dist/wallet-standard.mjs +1 -4
  59. package/dist/wallet.d.cts +1 -4
  60. package/dist/wallet.d.mts +1 -4
  61. package/dist/wallet.d.ts +1 -4
  62. package/package.json +1 -13
  63. package/dist/spl-token.cjs +0 -12
  64. package/dist/spl-token.d.cts +0 -4
  65. package/dist/spl-token.d.mts +0 -4
  66. package/dist/spl-token.d.ts +0 -4
  67. package/dist/spl-token.mjs +0 -1
  68. package/dist/web3.cjs +0 -13
  69. package/dist/web3.d.cts +0 -3
  70. package/dist/web3.d.mts +0 -3
  71. package/dist/web3.d.ts +0 -3
  72. package/dist/web3.mjs +0 -1
  73. package/types/web3-compat.d.ts +0 -140
@@ -1,8 +1,5 @@
1
- /// <reference path="../../types/web3-compat.d.ts" />
2
- /// <reference path="../../types/buffer.d.ts" />
3
- import { Commitment, SendOptions, Connection, Transaction, VersionedTransaction, PublicKey, TransactionSignature, RpcResponseAndContext, SignatureResult } from '@solana/web3-compat';
4
1
  import * as _solana_kit from '@solana/kit';
5
- import { Address } from '@solana/kit';
2
+ import { Commitment, Slot, Address, Signature } from '@solana/kit';
6
3
 
7
4
  /**
8
5
  * Create a @solana/kit client for the given Solana configuration.
@@ -30,17 +27,15 @@ interface SolanaContext {
30
27
  cluster: SolanaCluster;
31
28
  endpoint: string;
32
29
  wsEndpoint: string;
33
- connection: Connection;
34
30
  client: SolanaClient;
35
31
  }
36
- type SolanaTransaction = Transaction | VersionedTransaction;
32
+ type SolanaTransaction = Uint8Array;
37
33
  interface SolanaSignMessageResult {
38
34
  signedMessage: Uint8Array;
39
35
  signature: Uint8Array;
40
36
  }
41
37
  interface SolanaWallet {
42
- publicKey: PublicKey | null;
43
- address?: Address;
38
+ publicKey: Address | null;
44
39
  connected: boolean;
45
40
  connecting?: boolean;
46
41
  disconnecting?: boolean;
@@ -49,10 +44,10 @@ interface SolanaWallet {
49
44
  connect: () => Promise<void>;
50
45
  disconnect: () => Promise<void>;
51
46
  signMessage?: (message: Uint8Array) => Promise<SolanaSignMessageResult>;
52
- signTransaction?: <T extends SolanaTransaction>(transaction: T) => Promise<T>;
53
- signAllTransactions?: <T extends SolanaTransaction>(transactions: T[]) => Promise<T[]>;
54
- signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendOptions) => Promise<{
55
- signature: TransactionSignature;
47
+ signTransaction?: (transaction: SolanaTransaction) => Promise<SolanaTransaction>;
48
+ signAllTransactions?: (transactions: SolanaTransaction[]) => Promise<SolanaTransaction[]>;
49
+ signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendTransactionOptions) => Promise<{
50
+ signature: string;
56
51
  }>;
57
52
  }
58
53
  interface SolanaWalletInfo {
@@ -81,18 +76,27 @@ interface SolanaWalletInfo {
81
76
  }[];
82
77
  wallet: unknown;
83
78
  }
84
- interface SendTransactionOptions extends SendOptions {
79
+ interface SendTransactionOptions {
85
80
  skipPreflight?: boolean;
81
+ maxRetries?: bigint;
82
+ minContextSlot?: Slot;
83
+ preflightCommitment?: Commitment;
86
84
  }
87
85
  interface ConfirmTransactionOptions {
88
86
  commitment?: Commitment;
89
87
  timeoutMs?: number;
90
88
  }
89
+ interface TransactionStatus {
90
+ slot: Slot;
91
+ confirmations: bigint | null;
92
+ err: unknown | null;
93
+ confirmationStatus: Commitment | null;
94
+ }
91
95
  interface TransactionConfirmation {
92
- signature: TransactionSignature;
96
+ signature: Signature;
93
97
  commitment: Commitment;
94
- result: RpcResponseAndContext<SignatureResult>;
98
+ status: TransactionStatus;
95
99
  }
96
100
 
97
- export { createSolanaClient as j };
98
- export type { ConfirmTransactionOptions as C, SendTransactionOptions as S, TransactionConfirmation as T, SolanaChain as a, SolanaClient as b, SolanaCluster as c, SolanaConfig as d, SolanaContext as e, SolanaSignMessageResult as f, SolanaTransaction as g, SolanaWallet as h, SolanaWalletInfo as i };
101
+ export { createSolanaClient as k };
102
+ export type { ConfirmTransactionOptions as C, SendTransactionOptions as S, TransactionConfirmation as T, SolanaChain as a, SolanaClient as b, SolanaCluster as c, SolanaConfig as d, SolanaContext as e, SolanaSignMessageResult as f, SolanaTransaction as g, SolanaWallet as h, SolanaWalletInfo as i, TransactionStatus as j };
@@ -1,8 +1,5 @@
1
- /// <reference path="../../types/web3-compat.d.ts" />
2
- /// <reference path="../../types/buffer.d.ts" />
3
- import { Commitment, SendOptions, Connection, Transaction, VersionedTransaction, PublicKey, TransactionSignature, RpcResponseAndContext, SignatureResult } from '@solana/web3-compat';
4
1
  import * as _solana_kit from '@solana/kit';
5
- import { Address } from '@solana/kit';
2
+ import { Commitment, Slot, Address, Signature } from '@solana/kit';
6
3
 
7
4
  /**
8
5
  * Create a @solana/kit client for the given Solana configuration.
@@ -30,17 +27,15 @@ interface SolanaContext {
30
27
  cluster: SolanaCluster;
31
28
  endpoint: string;
32
29
  wsEndpoint: string;
33
- connection: Connection;
34
30
  client: SolanaClient;
35
31
  }
36
- type SolanaTransaction = Transaction | VersionedTransaction;
32
+ type SolanaTransaction = Uint8Array;
37
33
  interface SolanaSignMessageResult {
38
34
  signedMessage: Uint8Array;
39
35
  signature: Uint8Array;
40
36
  }
41
37
  interface SolanaWallet {
42
- publicKey: PublicKey | null;
43
- address?: Address;
38
+ publicKey: Address | null;
44
39
  connected: boolean;
45
40
  connecting?: boolean;
46
41
  disconnecting?: boolean;
@@ -49,10 +44,10 @@ interface SolanaWallet {
49
44
  connect: () => Promise<void>;
50
45
  disconnect: () => Promise<void>;
51
46
  signMessage?: (message: Uint8Array) => Promise<SolanaSignMessageResult>;
52
- signTransaction?: <T extends SolanaTransaction>(transaction: T) => Promise<T>;
53
- signAllTransactions?: <T extends SolanaTransaction>(transactions: T[]) => Promise<T[]>;
54
- signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendOptions) => Promise<{
55
- signature: TransactionSignature;
47
+ signTransaction?: (transaction: SolanaTransaction) => Promise<SolanaTransaction>;
48
+ signAllTransactions?: (transactions: SolanaTransaction[]) => Promise<SolanaTransaction[]>;
49
+ signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendTransactionOptions) => Promise<{
50
+ signature: string;
56
51
  }>;
57
52
  }
58
53
  interface SolanaWalletInfo {
@@ -81,18 +76,27 @@ interface SolanaWalletInfo {
81
76
  }[];
82
77
  wallet: unknown;
83
78
  }
84
- interface SendTransactionOptions extends SendOptions {
79
+ interface SendTransactionOptions {
85
80
  skipPreflight?: boolean;
81
+ maxRetries?: bigint;
82
+ minContextSlot?: Slot;
83
+ preflightCommitment?: Commitment;
86
84
  }
87
85
  interface ConfirmTransactionOptions {
88
86
  commitment?: Commitment;
89
87
  timeoutMs?: number;
90
88
  }
89
+ interface TransactionStatus {
90
+ slot: Slot;
91
+ confirmations: bigint | null;
92
+ err: unknown | null;
93
+ confirmationStatus: Commitment | null;
94
+ }
91
95
  interface TransactionConfirmation {
92
- signature: TransactionSignature;
96
+ signature: Signature;
93
97
  commitment: Commitment;
94
- result: RpcResponseAndContext<SignatureResult>;
98
+ status: TransactionStatus;
95
99
  }
96
100
 
97
- export { createSolanaClient as j };
98
- export type { ConfirmTransactionOptions as C, SendTransactionOptions as S, TransactionConfirmation as T, SolanaChain as a, SolanaClient as b, SolanaCluster as c, SolanaConfig as d, SolanaContext as e, SolanaSignMessageResult as f, SolanaTransaction as g, SolanaWallet as h, SolanaWalletInfo as i };
101
+ export { createSolanaClient as k };
102
+ export type { ConfirmTransactionOptions as C, SendTransactionOptions as S, TransactionConfirmation as T, SolanaChain as a, SolanaClient as b, SolanaCluster as c, SolanaConfig as d, SolanaContext as e, SolanaSignMessageResult as f, SolanaTransaction as g, SolanaWallet as h, SolanaWalletInfo as i, TransactionStatus as j };
@@ -1,8 +1,5 @@
1
- /// <reference path="../../types/web3-compat.d.ts" />
2
- /// <reference path="../../types/buffer.d.ts" />
3
- import { Commitment, SendOptions, Connection, Transaction, VersionedTransaction, PublicKey, TransactionSignature, RpcResponseAndContext, SignatureResult } from '@solana/web3-compat';
4
1
  import * as _solana_kit from '@solana/kit';
5
- import { Address } from '@solana/kit';
2
+ import { Commitment, Slot, Address, Signature } from '@solana/kit';
6
3
 
7
4
  /**
8
5
  * Create a @solana/kit client for the given Solana configuration.
@@ -30,17 +27,15 @@ interface SolanaContext {
30
27
  cluster: SolanaCluster;
31
28
  endpoint: string;
32
29
  wsEndpoint: string;
33
- connection: Connection;
34
30
  client: SolanaClient;
35
31
  }
36
- type SolanaTransaction = Transaction | VersionedTransaction;
32
+ type SolanaTransaction = Uint8Array;
37
33
  interface SolanaSignMessageResult {
38
34
  signedMessage: Uint8Array;
39
35
  signature: Uint8Array;
40
36
  }
41
37
  interface SolanaWallet {
42
- publicKey: PublicKey | null;
43
- address?: Address;
38
+ publicKey: Address | null;
44
39
  connected: boolean;
45
40
  connecting?: boolean;
46
41
  disconnecting?: boolean;
@@ -49,10 +44,10 @@ interface SolanaWallet {
49
44
  connect: () => Promise<void>;
50
45
  disconnect: () => Promise<void>;
51
46
  signMessage?: (message: Uint8Array) => Promise<SolanaSignMessageResult>;
52
- signTransaction?: <T extends SolanaTransaction>(transaction: T) => Promise<T>;
53
- signAllTransactions?: <T extends SolanaTransaction>(transactions: T[]) => Promise<T[]>;
54
- signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendOptions) => Promise<{
55
- signature: TransactionSignature;
47
+ signTransaction?: (transaction: SolanaTransaction) => Promise<SolanaTransaction>;
48
+ signAllTransactions?: (transactions: SolanaTransaction[]) => Promise<SolanaTransaction[]>;
49
+ signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendTransactionOptions) => Promise<{
50
+ signature: string;
56
51
  }>;
57
52
  }
58
53
  interface SolanaWalletInfo {
@@ -81,18 +76,27 @@ interface SolanaWalletInfo {
81
76
  }[];
82
77
  wallet: unknown;
83
78
  }
84
- interface SendTransactionOptions extends SendOptions {
79
+ interface SendTransactionOptions {
85
80
  skipPreflight?: boolean;
81
+ maxRetries?: bigint;
82
+ minContextSlot?: Slot;
83
+ preflightCommitment?: Commitment;
86
84
  }
87
85
  interface ConfirmTransactionOptions {
88
86
  commitment?: Commitment;
89
87
  timeoutMs?: number;
90
88
  }
89
+ interface TransactionStatus {
90
+ slot: Slot;
91
+ confirmations: bigint | null;
92
+ err: unknown | null;
93
+ confirmationStatus: Commitment | null;
94
+ }
91
95
  interface TransactionConfirmation {
92
- signature: TransactionSignature;
96
+ signature: Signature;
93
97
  commitment: Commitment;
94
- result: RpcResponseAndContext<SignatureResult>;
98
+ status: TransactionStatus;
95
99
  }
96
100
 
97
- export { createSolanaClient as j };
98
- export type { ConfirmTransactionOptions as C, SendTransactionOptions as S, TransactionConfirmation as T, SolanaChain as a, SolanaClient as b, SolanaCluster as c, SolanaConfig as d, SolanaContext as e, SolanaSignMessageResult as f, SolanaTransaction as g, SolanaWallet as h, SolanaWalletInfo as i };
101
+ export { createSolanaClient as k };
102
+ export type { ConfirmTransactionOptions as C, SendTransactionOptions as S, TransactionConfirmation as T, SolanaChain as a, SolanaClient as b, SolanaCluster as c, SolanaConfig as d, SolanaContext as e, SolanaSignMessageResult as f, SolanaTransaction as g, SolanaWallet as h, SolanaWalletInfo as i, TransactionStatus as j };
@@ -1,55 +1,71 @@
1
1
  'use strict';
2
2
 
3
- const splToken = require('@solana/spl-token');
3
+ const kit = require('@solana/kit');
4
4
  const errors = require('./errors.cjs');
5
5
 
6
- async function getTokenAccountsByOwner(connection, owner, options) {
7
- const commitment = options?.commitment ?? "confirmed";
8
- const programId = options?.programId;
9
- const programIds = programId ? [programId] : [splToken.TOKEN_PROGRAM_ID, splToken.TOKEN_2022_PROGRAM_ID];
6
+ const TOKEN_PROGRAM_ADDRESS = kit.address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
7
+ const TOKEN_2022_PROGRAM_ADDRESS = kit.address("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
8
+ async function getTokenAccountsByOwner(client, owner, options = {}) {
9
+ const programIds = options.programId ? [options.programId] : [TOKEN_PROGRAM_ADDRESS, TOKEN_2022_PROGRAM_ADDRESS];
10
10
  try {
11
- const responses = await Promise.all(
12
- programIds.map(async (pid) => {
13
- const resp = await connection.getTokenAccountsByOwner(owner, { programId: pid }, commitment);
14
- return resp.value.map(
15
- (info) => splToken.unpackAccount(info.pubkey, { data: info.account.data })
16
- );
17
- })
11
+ const results = await Promise.all(
12
+ programIds.map(
13
+ (programId) => fetchParsedTokenAccounts(client, owner, { programId }, options.commitment)
14
+ )
18
15
  );
19
- return responses.flat();
16
+ return results.flat();
20
17
  } catch (cause) {
21
18
  throw errors.normalizeSolanaError(cause, "RPC_FAILURE");
22
19
  }
23
20
  }
24
- async function getTokenAccount(connection, address) {
21
+ async function getTokenAccount(client, address2, commitment) {
25
22
  try {
26
- const accountInfo = await connection.getAccountInfo(address);
27
- if (!accountInfo) {
23
+ const response = await client.rpc.getAccountInfo(address2, { encoding: "jsonParsed", commitment }).send();
24
+ const accountInfo = response.value;
25
+ if (!accountInfo || !isParsedTokenAccount(accountInfo.data) || accountInfo.data.parsed.type !== "account") {
28
26
  return null;
29
27
  }
30
- return splToken.unpackAccount(address, accountInfo);
28
+ return tokenAccountInfoFromParsed(address2, accountInfo.data);
31
29
  } catch (cause) {
32
30
  throw errors.normalizeSolanaError(cause, "RPC_FAILURE");
33
31
  }
34
32
  }
35
- async function getTokenBalance(connection, mint, owner) {
33
+ async function getTokenBalance(client, mint, owner, commitment) {
36
34
  try {
37
- const ata = splToken.getAssociatedTokenAddressSync(mint, owner, true);
38
- const accountInfo = await connection.getAccountInfo(ata);
39
- if (!accountInfo) {
35
+ const [account] = await fetchParsedTokenAccounts(client, owner, { mint }, commitment);
36
+ if (!account) {
40
37
  return null;
41
38
  }
42
- const tokenAccount = splToken.unpackAccount(ata, accountInfo);
43
- const mintAccountInfo = await connection.getAccountInfo(mint);
44
- if (!mintAccountInfo) {
45
- return null;
46
- }
47
- const mintAccount = splToken.unpackMint(mint, mintAccountInfo);
48
- return { amount: tokenAccount.amount, decimals: mintAccount.decimals };
39
+ return { amount: account.amount, decimals: account.decimals };
49
40
  } catch (cause) {
50
41
  throw errors.normalizeSolanaError(cause, "RPC_FAILURE");
51
42
  }
52
43
  }
44
+ async function fetchParsedTokenAccounts(client, owner, filter, commitment) {
45
+ const response = await client.rpc.getTokenAccountsByOwner(owner, filter, { encoding: "jsonParsed", commitment }).send();
46
+ return response.value.filter(({ account }) => isParsedTokenAccount(account.data)).map(({ pubkey, account }) => tokenAccountInfoFromParsed(pubkey, account.data));
47
+ }
48
+ function isParsedTokenAccount(data) {
49
+ return typeof data === "object" && data !== null && "parsed" in data;
50
+ }
51
+ function tokenAccountInfoFromParsed(address2, data) {
52
+ if (data.parsed.type !== "account") {
53
+ throw new Error(`Token account ${address2} is not a parsed token account`);
54
+ }
55
+ const parsed = data.parsed.info;
56
+ if (!parsed) {
57
+ throw new Error(`Token account ${address2} has no parsed data`);
58
+ }
59
+ return {
60
+ address: address2,
61
+ mint: parsed.mint,
62
+ owner: parsed.owner,
63
+ amount: BigInt(parsed.tokenAmount.amount),
64
+ decimals: parsed.tokenAmount.decimals,
65
+ state: parsed.state,
66
+ isNative: parsed.isNative
67
+ };
68
+ }
53
69
 
54
70
  exports.getTokenAccount = getTokenAccount;
55
71
  exports.getTokenAccountsByOwner = getTokenAccountsByOwner;
@@ -1,35 +1,35 @@
1
- import { PublicKey, Connection } from '@vue-solana/core/web3';
2
- import { Account } from '@solana/spl-token';
1
+ import { Address, Commitment } from '@solana/kit';
2
+ import { b as SolanaClient } from './shared/core.DMgTrB_2.cjs';
3
3
 
4
+ interface TokenAccountInfo {
5
+ address: Address;
6
+ mint: Address;
7
+ owner: Address;
8
+ amount: bigint;
9
+ decimals: number;
10
+ state: "frozen" | "initialized" | "uninitialized";
11
+ isNative: boolean;
12
+ }
4
13
  interface TokenAccountsByOwnerOptions {
5
- commitment?: "processed" | "confirmed" | "finalized";
6
- programId?: PublicKey;
14
+ commitment?: Commitment;
15
+ programId?: Address;
7
16
  }
8
17
  /**
9
- * Get all SPL token accounts for an owner using the legacy `Connection` API.
10
- *
11
- * @deprecated Prefer `@solana-program/token` reads against `client.rpc` from
12
- * `@vue-solana/core/kit`.
18
+ * Get all SPL token accounts for an owner using parsed kit RPC reads.
13
19
  */
14
- declare function getTokenAccountsByOwner(connection: Connection, owner: PublicKey, options?: TokenAccountsByOwnerOptions): Promise<Account[]>;
20
+ declare function getTokenAccountsByOwner(client: SolanaClient, owner: Address, options?: TokenAccountsByOwnerOptions): Promise<TokenAccountInfo[]>;
15
21
  /**
16
- * Get a single token account using the legacy `Connection` API.
17
- *
18
- * @deprecated Prefer `@solana-program/token` reads against `client.rpc` from
19
- * `@vue-solana/core/kit`.
22
+ * Get a single parsed token account at the given address.
20
23
  */
21
- declare function getTokenAccount(connection: Connection, address: PublicKey): Promise<Account | null>;
24
+ declare function getTokenAccount(client: SolanaClient, address: Address, commitment?: Commitment): Promise<TokenAccountInfo | null>;
22
25
  interface TokenBalanceResult {
23
26
  amount: bigint;
24
27
  decimals: number;
25
28
  }
26
29
  /**
27
- * Read the token balance of the associated token account for an owner.
28
- *
29
- * @deprecated Prefer `@solana-program/token` reads against `client.rpc` from
30
- * `@vue-solana/core/kit`.
30
+ * Read the token balance of the accounts an owner holds for a given mint.
31
31
  */
32
- declare function getTokenBalance(connection: Connection, mint: PublicKey, owner: PublicKey): Promise<TokenBalanceResult | null>;
32
+ declare function getTokenBalance(client: SolanaClient, mint: Address, owner: Address, commitment?: Commitment): Promise<TokenBalanceResult | null>;
33
33
 
34
34
  export { getTokenAccount, getTokenAccountsByOwner, getTokenBalance };
35
- export type { TokenAccountsByOwnerOptions, TokenBalanceResult };
35
+ export type { TokenAccountInfo, TokenAccountsByOwnerOptions, TokenBalanceResult };
@@ -1,35 +1,35 @@
1
- import { PublicKey, Connection } from '@vue-solana/core/web3';
2
- import { Account } from '@solana/spl-token';
1
+ import { Address, Commitment } from '@solana/kit';
2
+ import { b as SolanaClient } from './shared/core.DMgTrB_2.mjs';
3
3
 
4
+ interface TokenAccountInfo {
5
+ address: Address;
6
+ mint: Address;
7
+ owner: Address;
8
+ amount: bigint;
9
+ decimals: number;
10
+ state: "frozen" | "initialized" | "uninitialized";
11
+ isNative: boolean;
12
+ }
4
13
  interface TokenAccountsByOwnerOptions {
5
- commitment?: "processed" | "confirmed" | "finalized";
6
- programId?: PublicKey;
14
+ commitment?: Commitment;
15
+ programId?: Address;
7
16
  }
8
17
  /**
9
- * Get all SPL token accounts for an owner using the legacy `Connection` API.
10
- *
11
- * @deprecated Prefer `@solana-program/token` reads against `client.rpc` from
12
- * `@vue-solana/core/kit`.
18
+ * Get all SPL token accounts for an owner using parsed kit RPC reads.
13
19
  */
14
- declare function getTokenAccountsByOwner(connection: Connection, owner: PublicKey, options?: TokenAccountsByOwnerOptions): Promise<Account[]>;
20
+ declare function getTokenAccountsByOwner(client: SolanaClient, owner: Address, options?: TokenAccountsByOwnerOptions): Promise<TokenAccountInfo[]>;
15
21
  /**
16
- * Get a single token account using the legacy `Connection` API.
17
- *
18
- * @deprecated Prefer `@solana-program/token` reads against `client.rpc` from
19
- * `@vue-solana/core/kit`.
22
+ * Get a single parsed token account at the given address.
20
23
  */
21
- declare function getTokenAccount(connection: Connection, address: PublicKey): Promise<Account | null>;
24
+ declare function getTokenAccount(client: SolanaClient, address: Address, commitment?: Commitment): Promise<TokenAccountInfo | null>;
22
25
  interface TokenBalanceResult {
23
26
  amount: bigint;
24
27
  decimals: number;
25
28
  }
26
29
  /**
27
- * Read the token balance of the associated token account for an owner.
28
- *
29
- * @deprecated Prefer `@solana-program/token` reads against `client.rpc` from
30
- * `@vue-solana/core/kit`.
30
+ * Read the token balance of the accounts an owner holds for a given mint.
31
31
  */
32
- declare function getTokenBalance(connection: Connection, mint: PublicKey, owner: PublicKey): Promise<TokenBalanceResult | null>;
32
+ declare function getTokenBalance(client: SolanaClient, mint: Address, owner: Address, commitment?: Commitment): Promise<TokenBalanceResult | null>;
33
33
 
34
34
  export { getTokenAccount, getTokenAccountsByOwner, getTokenBalance };
35
- export type { TokenAccountsByOwnerOptions, TokenBalanceResult };
35
+ export type { TokenAccountInfo, TokenAccountsByOwnerOptions, TokenBalanceResult };
@@ -1,35 +1,35 @@
1
- import { PublicKey, Connection } from '@vue-solana/core/web3';
2
- import { Account } from '@solana/spl-token';
1
+ import { Address, Commitment } from '@solana/kit';
2
+ import { b as SolanaClient } from './shared/core.DMgTrB_2.js';
3
3
 
4
+ interface TokenAccountInfo {
5
+ address: Address;
6
+ mint: Address;
7
+ owner: Address;
8
+ amount: bigint;
9
+ decimals: number;
10
+ state: "frozen" | "initialized" | "uninitialized";
11
+ isNative: boolean;
12
+ }
4
13
  interface TokenAccountsByOwnerOptions {
5
- commitment?: "processed" | "confirmed" | "finalized";
6
- programId?: PublicKey;
14
+ commitment?: Commitment;
15
+ programId?: Address;
7
16
  }
8
17
  /**
9
- * Get all SPL token accounts for an owner using the legacy `Connection` API.
10
- *
11
- * @deprecated Prefer `@solana-program/token` reads against `client.rpc` from
12
- * `@vue-solana/core/kit`.
18
+ * Get all SPL token accounts for an owner using parsed kit RPC reads.
13
19
  */
14
- declare function getTokenAccountsByOwner(connection: Connection, owner: PublicKey, options?: TokenAccountsByOwnerOptions): Promise<Account[]>;
20
+ declare function getTokenAccountsByOwner(client: SolanaClient, owner: Address, options?: TokenAccountsByOwnerOptions): Promise<TokenAccountInfo[]>;
15
21
  /**
16
- * Get a single token account using the legacy `Connection` API.
17
- *
18
- * @deprecated Prefer `@solana-program/token` reads against `client.rpc` from
19
- * `@vue-solana/core/kit`.
22
+ * Get a single parsed token account at the given address.
20
23
  */
21
- declare function getTokenAccount(connection: Connection, address: PublicKey): Promise<Account | null>;
24
+ declare function getTokenAccount(client: SolanaClient, address: Address, commitment?: Commitment): Promise<TokenAccountInfo | null>;
22
25
  interface TokenBalanceResult {
23
26
  amount: bigint;
24
27
  decimals: number;
25
28
  }
26
29
  /**
27
- * Read the token balance of the associated token account for an owner.
28
- *
29
- * @deprecated Prefer `@solana-program/token` reads against `client.rpc` from
30
- * `@vue-solana/core/kit`.
30
+ * Read the token balance of the accounts an owner holds for a given mint.
31
31
  */
32
- declare function getTokenBalance(connection: Connection, mint: PublicKey, owner: PublicKey): Promise<TokenBalanceResult | null>;
32
+ declare function getTokenBalance(client: SolanaClient, mint: Address, owner: Address, commitment?: Commitment): Promise<TokenBalanceResult | null>;
33
33
 
34
34
  export { getTokenAccount, getTokenAccountsByOwner, getTokenBalance };
35
- export type { TokenAccountsByOwnerOptions, TokenBalanceResult };
35
+ export type { TokenAccountInfo, TokenAccountsByOwnerOptions, TokenBalanceResult };
@@ -1,52 +1,68 @@
1
- import { unpackAccount, TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, getAssociatedTokenAddressSync, unpackMint } from '@solana/spl-token';
1
+ import { address } from '@solana/kit';
2
2
  import { normalizeSolanaError } from './errors.mjs';
3
3
 
4
- async function getTokenAccountsByOwner(connection, owner, options) {
5
- const commitment = options?.commitment ?? "confirmed";
6
- const programId = options?.programId;
7
- const programIds = programId ? [programId] : [TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID];
4
+ const TOKEN_PROGRAM_ADDRESS = address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
5
+ const TOKEN_2022_PROGRAM_ADDRESS = address("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
6
+ async function getTokenAccountsByOwner(client, owner, options = {}) {
7
+ const programIds = options.programId ? [options.programId] : [TOKEN_PROGRAM_ADDRESS, TOKEN_2022_PROGRAM_ADDRESS];
8
8
  try {
9
- const responses = await Promise.all(
10
- programIds.map(async (pid) => {
11
- const resp = await connection.getTokenAccountsByOwner(owner, { programId: pid }, commitment);
12
- return resp.value.map(
13
- (info) => unpackAccount(info.pubkey, { data: info.account.data })
14
- );
15
- })
9
+ const results = await Promise.all(
10
+ programIds.map(
11
+ (programId) => fetchParsedTokenAccounts(client, owner, { programId }, options.commitment)
12
+ )
16
13
  );
17
- return responses.flat();
14
+ return results.flat();
18
15
  } catch (cause) {
19
16
  throw normalizeSolanaError(cause, "RPC_FAILURE");
20
17
  }
21
18
  }
22
- async function getTokenAccount(connection, address) {
19
+ async function getTokenAccount(client, address2, commitment) {
23
20
  try {
24
- const accountInfo = await connection.getAccountInfo(address);
25
- if (!accountInfo) {
21
+ const response = await client.rpc.getAccountInfo(address2, { encoding: "jsonParsed", commitment }).send();
22
+ const accountInfo = response.value;
23
+ if (!accountInfo || !isParsedTokenAccount(accountInfo.data) || accountInfo.data.parsed.type !== "account") {
26
24
  return null;
27
25
  }
28
- return unpackAccount(address, accountInfo);
26
+ return tokenAccountInfoFromParsed(address2, accountInfo.data);
29
27
  } catch (cause) {
30
28
  throw normalizeSolanaError(cause, "RPC_FAILURE");
31
29
  }
32
30
  }
33
- async function getTokenBalance(connection, mint, owner) {
31
+ async function getTokenBalance(client, mint, owner, commitment) {
34
32
  try {
35
- const ata = getAssociatedTokenAddressSync(mint, owner, true);
36
- const accountInfo = await connection.getAccountInfo(ata);
37
- if (!accountInfo) {
33
+ const [account] = await fetchParsedTokenAccounts(client, owner, { mint }, commitment);
34
+ if (!account) {
38
35
  return null;
39
36
  }
40
- const tokenAccount = unpackAccount(ata, accountInfo);
41
- const mintAccountInfo = await connection.getAccountInfo(mint);
42
- if (!mintAccountInfo) {
43
- return null;
44
- }
45
- const mintAccount = unpackMint(mint, mintAccountInfo);
46
- return { amount: tokenAccount.amount, decimals: mintAccount.decimals };
37
+ return { amount: account.amount, decimals: account.decimals };
47
38
  } catch (cause) {
48
39
  throw normalizeSolanaError(cause, "RPC_FAILURE");
49
40
  }
50
41
  }
42
+ async function fetchParsedTokenAccounts(client, owner, filter, commitment) {
43
+ const response = await client.rpc.getTokenAccountsByOwner(owner, filter, { encoding: "jsonParsed", commitment }).send();
44
+ return response.value.filter(({ account }) => isParsedTokenAccount(account.data)).map(({ pubkey, account }) => tokenAccountInfoFromParsed(pubkey, account.data));
45
+ }
46
+ function isParsedTokenAccount(data) {
47
+ return typeof data === "object" && data !== null && "parsed" in data;
48
+ }
49
+ function tokenAccountInfoFromParsed(address2, data) {
50
+ if (data.parsed.type !== "account") {
51
+ throw new Error(`Token account ${address2} is not a parsed token account`);
52
+ }
53
+ const parsed = data.parsed.info;
54
+ if (!parsed) {
55
+ throw new Error(`Token account ${address2} has no parsed data`);
56
+ }
57
+ return {
58
+ address: address2,
59
+ mint: parsed.mint,
60
+ owner: parsed.owner,
61
+ amount: BigInt(parsed.tokenAmount.amount),
62
+ decimals: parsed.tokenAmount.decimals,
63
+ state: parsed.state,
64
+ isNative: parsed.isNative
65
+ };
66
+ }
51
67
 
52
68
  export { getTokenAccount, getTokenAccountsByOwner, getTokenBalance };