@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.
- package/README.md +44 -35
- package/dist/address.cjs +10 -10
- package/dist/address.d.cts +11 -13
- package/dist/address.d.mts +11 -13
- package/dist/address.d.ts +11 -13
- package/dist/address.mjs +10 -10
- package/dist/buffer-polyfill.d.cts +0 -1
- package/dist/buffer-polyfill.d.mts +0 -1
- package/dist/buffer-polyfill.d.ts +0 -1
- package/dist/clusters.d.cts +1 -4
- package/dist/clusters.d.mts +1 -4
- package/dist/clusters.d.ts +1 -4
- package/dist/index.cjs +3 -19
- package/dist/index.d.cts +5 -9
- package/dist/index.d.mts +5 -9
- package/dist/index.d.ts +5 -9
- package/dist/index.mjs +4 -6
- package/dist/ios-wallet.cjs +2 -2
- package/dist/ios-wallet.d.cts +1 -4
- package/dist/ios-wallet.d.mts +1 -4
- package/dist/ios-wallet.d.ts +1 -4
- package/dist/ios-wallet.mjs +2 -2
- package/dist/kit.d.cts +2 -5
- package/dist/kit.d.mts +2 -5
- package/dist/kit.d.ts +2 -5
- package/dist/mobile-wallet.d.cts +1 -4
- package/dist/mobile-wallet.d.mts +1 -4
- package/dist/mobile-wallet.d.ts +1 -4
- package/dist/rpc.cjs +0 -12
- package/dist/rpc.d.cts +2 -11
- package/dist/rpc.d.mts +2 -11
- package/dist/rpc.d.ts +2 -11
- package/dist/rpc.mjs +1 -12
- package/dist/shared/{core.DjbtrJWl.mjs → core.BOHiMZiM.mjs} +7 -33
- package/dist/shared/{core.Ch_Z7_17.mjs → core.BwW4HVQI.mjs} +12 -28
- package/dist/shared/{core.BsekSwcZ.cjs → core.Cb48vQvC.cjs} +12 -28
- package/dist/shared/{core.BQoh-5Wu.cjs → core.Cu_gaUSn.cjs} +20 -46
- package/dist/shared/{core.DAUuCWrr.d.mts → core.DMgTrB_2.d.cts} +21 -17
- package/dist/shared/{core.DAUuCWrr.d.ts → core.DMgTrB_2.d.mts} +21 -17
- package/dist/shared/{core.DAUuCWrr.d.cts → core.DMgTrB_2.d.ts} +21 -17
- package/dist/token-accounts.cjs +44 -28
- package/dist/token-accounts.d.cts +20 -20
- package/dist/token-accounts.d.mts +20 -20
- package/dist/token-accounts.d.ts +20 -20
- package/dist/token-accounts.mjs +44 -28
- package/dist/transaction.cjs +50 -31
- package/dist/transaction.d.cts +9 -15
- package/dist/transaction.d.mts +9 -15
- package/dist/transaction.d.ts +9 -15
- package/dist/transaction.mjs +51 -32
- package/dist/types.d.cts +1 -4
- package/dist/types.d.mts +1 -4
- package/dist/types.d.ts +1 -4
- package/dist/wallet-standard.cjs +1 -4
- package/dist/wallet-standard.d.cts +1 -4
- package/dist/wallet-standard.d.mts +1 -4
- package/dist/wallet-standard.d.ts +1 -4
- package/dist/wallet-standard.mjs +1 -4
- package/dist/wallet.d.cts +1 -4
- package/dist/wallet.d.mts +1 -4
- package/dist/wallet.d.ts +1 -4
- package/package.json +1 -13
- package/dist/spl-token.cjs +0 -12
- package/dist/spl-token.d.cts +0 -4
- package/dist/spl-token.d.mts +0 -4
- package/dist/spl-token.d.ts +0 -4
- package/dist/spl-token.mjs +0 -1
- package/dist/web3.cjs +0 -13
- package/dist/web3.d.cts +0 -3
- package/dist/web3.d.mts +0 -3
- package/dist/web3.d.ts +0 -3
- package/dist/web3.mjs +0 -1
- 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 =
|
|
32
|
+
type SolanaTransaction = Uint8Array;
|
|
37
33
|
interface SolanaSignMessageResult {
|
|
38
34
|
signedMessage: Uint8Array;
|
|
39
35
|
signature: Uint8Array;
|
|
40
36
|
}
|
|
41
37
|
interface SolanaWallet {
|
|
42
|
-
publicKey:
|
|
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?:
|
|
53
|
-
signAllTransactions?:
|
|
54
|
-
signAndSendTransaction?: (transaction: SolanaTransaction, options?:
|
|
55
|
-
signature:
|
|
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
|
|
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:
|
|
96
|
+
signature: Signature;
|
|
93
97
|
commitment: Commitment;
|
|
94
|
-
|
|
98
|
+
status: TransactionStatus;
|
|
95
99
|
}
|
|
96
100
|
|
|
97
|
-
export { createSolanaClient as
|
|
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 =
|
|
32
|
+
type SolanaTransaction = Uint8Array;
|
|
37
33
|
interface SolanaSignMessageResult {
|
|
38
34
|
signedMessage: Uint8Array;
|
|
39
35
|
signature: Uint8Array;
|
|
40
36
|
}
|
|
41
37
|
interface SolanaWallet {
|
|
42
|
-
publicKey:
|
|
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?:
|
|
53
|
-
signAllTransactions?:
|
|
54
|
-
signAndSendTransaction?: (transaction: SolanaTransaction, options?:
|
|
55
|
-
signature:
|
|
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
|
|
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:
|
|
96
|
+
signature: Signature;
|
|
93
97
|
commitment: Commitment;
|
|
94
|
-
|
|
98
|
+
status: TransactionStatus;
|
|
95
99
|
}
|
|
96
100
|
|
|
97
|
-
export { createSolanaClient as
|
|
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 =
|
|
32
|
+
type SolanaTransaction = Uint8Array;
|
|
37
33
|
interface SolanaSignMessageResult {
|
|
38
34
|
signedMessage: Uint8Array;
|
|
39
35
|
signature: Uint8Array;
|
|
40
36
|
}
|
|
41
37
|
interface SolanaWallet {
|
|
42
|
-
publicKey:
|
|
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?:
|
|
53
|
-
signAllTransactions?:
|
|
54
|
-
signAndSendTransaction?: (transaction: SolanaTransaction, options?:
|
|
55
|
-
signature:
|
|
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
|
|
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:
|
|
96
|
+
signature: Signature;
|
|
93
97
|
commitment: Commitment;
|
|
94
|
-
|
|
98
|
+
status: TransactionStatus;
|
|
95
99
|
}
|
|
96
100
|
|
|
97
|
-
export { createSolanaClient as
|
|
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 };
|
package/dist/token-accounts.cjs
CHANGED
|
@@ -1,55 +1,71 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const kit = require('@solana/kit');
|
|
4
4
|
const errors = require('./errors.cjs');
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const programIds = programId ? [programId] : [
|
|
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
|
|
12
|
-
programIds.map(
|
|
13
|
-
|
|
14
|
-
|
|
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
|
|
16
|
+
return results.flat();
|
|
20
17
|
} catch (cause) {
|
|
21
18
|
throw errors.normalizeSolanaError(cause, "RPC_FAILURE");
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
|
-
async function getTokenAccount(
|
|
21
|
+
async function getTokenAccount(client, address2, commitment) {
|
|
25
22
|
try {
|
|
26
|
-
const
|
|
27
|
-
|
|
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
|
|
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(
|
|
33
|
+
async function getTokenBalance(client, mint, owner, commitment) {
|
|
36
34
|
try {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
if (!accountInfo) {
|
|
35
|
+
const [account] = await fetchParsedTokenAccounts(client, owner, { mint }, commitment);
|
|
36
|
+
if (!account) {
|
|
40
37
|
return null;
|
|
41
38
|
}
|
|
42
|
-
|
|
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 {
|
|
2
|
-
import {
|
|
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?:
|
|
6
|
-
programId?:
|
|
14
|
+
commitment?: Commitment;
|
|
15
|
+
programId?: Address;
|
|
7
16
|
}
|
|
8
17
|
/**
|
|
9
|
-
* Get all SPL token accounts for an owner using
|
|
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(
|
|
20
|
+
declare function getTokenAccountsByOwner(client: SolanaClient, owner: Address, options?: TokenAccountsByOwnerOptions): Promise<TokenAccountInfo[]>;
|
|
15
21
|
/**
|
|
16
|
-
* Get a single token account
|
|
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(
|
|
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
|
|
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(
|
|
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 {
|
|
2
|
-
import {
|
|
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?:
|
|
6
|
-
programId?:
|
|
14
|
+
commitment?: Commitment;
|
|
15
|
+
programId?: Address;
|
|
7
16
|
}
|
|
8
17
|
/**
|
|
9
|
-
* Get all SPL token accounts for an owner using
|
|
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(
|
|
20
|
+
declare function getTokenAccountsByOwner(client: SolanaClient, owner: Address, options?: TokenAccountsByOwnerOptions): Promise<TokenAccountInfo[]>;
|
|
15
21
|
/**
|
|
16
|
-
* Get a single token account
|
|
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(
|
|
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
|
|
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(
|
|
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 };
|
package/dist/token-accounts.d.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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?:
|
|
6
|
-
programId?:
|
|
14
|
+
commitment?: Commitment;
|
|
15
|
+
programId?: Address;
|
|
7
16
|
}
|
|
8
17
|
/**
|
|
9
|
-
* Get all SPL token accounts for an owner using
|
|
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(
|
|
20
|
+
declare function getTokenAccountsByOwner(client: SolanaClient, owner: Address, options?: TokenAccountsByOwnerOptions): Promise<TokenAccountInfo[]>;
|
|
15
21
|
/**
|
|
16
|
-
* Get a single token account
|
|
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(
|
|
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
|
|
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(
|
|
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 };
|
package/dist/token-accounts.mjs
CHANGED
|
@@ -1,52 +1,68 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { address } from '@solana/kit';
|
|
2
2
|
import { normalizeSolanaError } from './errors.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const programIds = programId ? [programId] : [
|
|
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
|
|
10
|
-
programIds.map(
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
14
|
+
return results.flat();
|
|
18
15
|
} catch (cause) {
|
|
19
16
|
throw normalizeSolanaError(cause, "RPC_FAILURE");
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
|
-
async function getTokenAccount(
|
|
19
|
+
async function getTokenAccount(client, address2, commitment) {
|
|
23
20
|
try {
|
|
24
|
-
const
|
|
25
|
-
|
|
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
|
|
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(
|
|
31
|
+
async function getTokenBalance(client, mint, owner, commitment) {
|
|
34
32
|
try {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
if (!accountInfo) {
|
|
33
|
+
const [account] = await fetchParsedTokenAccounts(client, owner, { mint }, commitment);
|
|
34
|
+
if (!account) {
|
|
38
35
|
return null;
|
|
39
36
|
}
|
|
40
|
-
|
|
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 };
|