@vue-solana/core 1.1.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 +14 -10
- package/dist/address.d.mts +14 -10
- package/dist/address.d.ts +14 -10
- 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 +2 -4
- package/dist/clusters.d.mts +2 -4
- package/dist/clusters.d.ts +2 -4
- package/dist/index.cjs +9 -19
- package/dist/index.d.cts +5 -8
- package/dist/index.d.mts +5 -8
- package/dist/index.d.ts +5 -8
- package/dist/index.mjs +7 -6
- package/dist/ios-wallet.cjs +2 -2
- package/dist/ios-wallet.d.cts +2 -4
- package/dist/ios-wallet.d.mts +2 -4
- package/dist/ios-wallet.d.ts +2 -4
- package/dist/ios-wallet.mjs +2 -2
- package/dist/kit.cjs +21 -0
- package/dist/kit.d.cts +2 -0
- package/dist/kit.d.mts +2 -0
- package/dist/kit.d.ts +2 -0
- package/dist/kit.mjs +18 -0
- package/dist/mobile-wallet.d.cts +2 -4
- package/dist/mobile-wallet.d.mts +2 -4
- package/dist/mobile-wallet.d.ts +2 -4
- package/dist/rpc.cjs +4 -12
- package/dist/rpc.d.cts +3 -6
- package/dist/rpc.d.mts +3 -6
- package/dist/rpc.d.ts +3 -6
- package/dist/rpc.mjs +5 -12
- package/dist/shared/{core.BBMCTQpw.mjs → core.BOHiMZiM.mjs} +7 -30
- 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.BU9rgxEj.cjs → core.Cu_gaUSn.cjs} +20 -43
- package/dist/shared/core.DMgTrB_2.d.cts +102 -0
- package/dist/shared/core.DMgTrB_2.d.mts +102 -0
- package/dist/shared/core.DMgTrB_2.d.ts +102 -0
- package/dist/token-accounts.cjs +44 -28
- package/dist/token-accounts.d.cts +26 -8
- package/dist/token-accounts.d.mts +26 -8
- package/dist/token-accounts.d.ts +26 -8
- package/dist/token-accounts.mjs +44 -28
- package/dist/transaction.cjs +50 -31
- package/dist/transaction.d.cts +14 -6
- package/dist/transaction.d.mts +14 -6
- package/dist/transaction.d.ts +14 -6
- package/dist/transaction.mjs +51 -32
- package/dist/types.d.cts +2 -80
- package/dist/types.d.mts +2 -80
- package/dist/types.d.ts +2 -80
- package/dist/wallet-standard.cjs +1 -4
- package/dist/wallet-standard.d.cts +2 -4
- package/dist/wallet-standard.d.mts +2 -4
- package/dist/wallet-standard.d.ts +2 -4
- package/dist/wallet-standard.mjs +1 -4
- package/dist/wallet.d.cts +2 -4
- package/dist/wallet.d.mts +2 -4
- package/dist/wallet.d.ts +2 -4
- package/package.json +9 -14
- 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
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const features = require('@wallet-standard/features');
|
|
4
4
|
const walletStandardFeatures = require('@solana/wallet-standard-features');
|
|
5
|
-
const web3Compat = require('@solana/web3-compat');
|
|
6
5
|
const bs58 = require('bs58');
|
|
7
|
-
const wallet = require('../wallet.cjs');
|
|
8
6
|
const app = require('@wallet-standard/app');
|
|
9
7
|
|
|
10
8
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
@@ -34,28 +32,15 @@ function hasSignMessage(wallet) {
|
|
|
34
32
|
return walletStandardFeatures.SolanaSignMessage in wallet.features;
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
function serializeTransaction(transaction) {
|
|
38
|
-
if (transaction instanceof web3Compat.Transaction) {
|
|
39
|
-
return transaction.serialize({ requireAllSignatures: false, verifySignatures: false });
|
|
40
|
-
}
|
|
41
|
-
return transaction.serialize();
|
|
42
|
-
}
|
|
43
|
-
function deserializeTransaction(source, bytes) {
|
|
44
|
-
if (source instanceof web3Compat.Transaction) {
|
|
45
|
-
return web3Compat.Transaction.from(bytes);
|
|
46
|
-
}
|
|
47
|
-
return web3Compat.VersionedTransaction.deserialize(bytes);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
35
|
function adaptSolanaStandardWallet(walletInfo, options = {}) {
|
|
51
|
-
const wallet
|
|
52
|
-
let accounts = wallet
|
|
36
|
+
const wallet = walletInfo.wallet;
|
|
37
|
+
let accounts = wallet.accounts;
|
|
53
38
|
let account = options.account;
|
|
54
39
|
let allowAccountUpdates = Boolean(options.account);
|
|
55
40
|
let connecting = false;
|
|
56
41
|
let disconnecting = false;
|
|
57
42
|
let manuallyDisconnected = false;
|
|
58
|
-
const eventsFeature = wallet
|
|
43
|
+
const eventsFeature = wallet.features[features.StandardEvents];
|
|
59
44
|
eventsFeature?.on("change", (properties) => {
|
|
60
45
|
if (properties.accounts) {
|
|
61
46
|
accounts = properties.accounts;
|
|
@@ -67,7 +52,7 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
|
|
|
67
52
|
platform: walletInfo.platform,
|
|
68
53
|
source: walletInfo.source,
|
|
69
54
|
get publicKey() {
|
|
70
|
-
return account ?
|
|
55
|
+
return account ? account.address : null;
|
|
71
56
|
},
|
|
72
57
|
get connected() {
|
|
73
58
|
return Boolean(account);
|
|
@@ -83,7 +68,7 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
|
|
|
83
68
|
manuallyDisconnected = false;
|
|
84
69
|
options.onChange?.();
|
|
85
70
|
try {
|
|
86
|
-
const feature = wallet
|
|
71
|
+
const feature = wallet.features[features.StandardConnect];
|
|
87
72
|
const result = await feature.connect();
|
|
88
73
|
accounts = result.accounts;
|
|
89
74
|
allowAccountUpdates = true;
|
|
@@ -97,7 +82,7 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
|
|
|
97
82
|
}
|
|
98
83
|
},
|
|
99
84
|
async disconnect() {
|
|
100
|
-
const feature = wallet
|
|
85
|
+
const feature = wallet.features[features.StandardDisconnect];
|
|
101
86
|
disconnecting = true;
|
|
102
87
|
manuallyDisconnected = true;
|
|
103
88
|
allowAccountUpdates = false;
|
|
@@ -117,9 +102,9 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
|
|
|
117
102
|
options.onChange?.();
|
|
118
103
|
}
|
|
119
104
|
},
|
|
120
|
-
signMessage: hasSignMessage(wallet
|
|
105
|
+
signMessage: hasSignMessage(wallet) ? async (message) => {
|
|
121
106
|
const activeAccount = getActiveAccount(account);
|
|
122
|
-
const [result] = await wallet
|
|
107
|
+
const [result] = await wallet.features[walletStandardFeatures.SolanaSignMessage].signMessage({
|
|
123
108
|
account: activeAccount,
|
|
124
109
|
message
|
|
125
110
|
});
|
|
@@ -128,24 +113,24 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
|
|
|
128
113
|
}
|
|
129
114
|
return result;
|
|
130
115
|
} : void 0,
|
|
131
|
-
signTransaction: hasSignTransaction(wallet
|
|
116
|
+
signTransaction: hasSignTransaction(wallet) ? async (transaction) => {
|
|
132
117
|
const activeAccount = getActiveAccount(account);
|
|
133
|
-
const [result] = await wallet
|
|
118
|
+
const [result] = await wallet.features[walletStandardFeatures.SolanaSignTransaction].signTransaction({
|
|
134
119
|
account: activeAccount,
|
|
135
|
-
transaction
|
|
120
|
+
transaction,
|
|
136
121
|
chain: options.chain
|
|
137
122
|
});
|
|
138
123
|
if (!result) {
|
|
139
124
|
throw new Error("Solana wallet did not return a signed transaction");
|
|
140
125
|
}
|
|
141
|
-
return
|
|
126
|
+
return result.signedTransaction;
|
|
142
127
|
} : void 0,
|
|
143
|
-
signAllTransactions: hasSignTransaction(wallet
|
|
128
|
+
signAllTransactions: hasSignTransaction(wallet) ? async (transactions) => {
|
|
144
129
|
const activeAccount = getActiveAccount(account);
|
|
145
|
-
const results = await wallet
|
|
130
|
+
const results = await wallet.features[walletStandardFeatures.SolanaSignTransaction].signTransaction(
|
|
146
131
|
...transactions.map((transaction) => ({
|
|
147
132
|
account: activeAccount,
|
|
148
|
-
transaction
|
|
133
|
+
transaction,
|
|
149
134
|
chain: options.chain
|
|
150
135
|
}))
|
|
151
136
|
);
|
|
@@ -154,26 +139,18 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
|
|
|
154
139
|
`Solana wallet returned ${results.length} signed transactions for ${transactions.length} requested transactions`
|
|
155
140
|
);
|
|
156
141
|
}
|
|
157
|
-
return results.map((result
|
|
142
|
+
return results.map((result) => {
|
|
158
143
|
if (!result) {
|
|
159
144
|
throw new Error("Solana wallet did not return a signed transaction");
|
|
160
145
|
}
|
|
161
|
-
|
|
162
|
-
if (!transaction) {
|
|
163
|
-
throw new wallet.SolanaWalletError(
|
|
164
|
-
"WALLET_FEATURE_UNSUPPORTED",
|
|
165
|
-
"Solana wallet returned a signed transaction without a matching request",
|
|
166
|
-
{ feature: "signTransaction" }
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
return deserializeTransaction(transaction, result.signedTransaction);
|
|
146
|
+
return result.signedTransaction;
|
|
170
147
|
});
|
|
171
148
|
} : void 0,
|
|
172
|
-
signAndSendTransaction: hasSignAndSendTransaction(wallet
|
|
149
|
+
signAndSendTransaction: hasSignAndSendTransaction(wallet) ? async (transaction, sendOptions) => {
|
|
173
150
|
const activeAccount = getActiveAccount(account);
|
|
174
|
-
const [result] = await wallet
|
|
151
|
+
const [result] = await wallet.features[walletStandardFeatures.SolanaSignAndSendTransaction].signAndSendTransaction({
|
|
175
152
|
account: activeAccount,
|
|
176
|
-
transaction
|
|
153
|
+
transaction,
|
|
177
154
|
chain: options.chain ?? getSolanaAccountChain(activeAccount),
|
|
178
155
|
options: sendOptions
|
|
179
156
|
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import * as _solana_kit from '@solana/kit';
|
|
2
|
+
import { Commitment, Slot, Address, Signature } from '@solana/kit';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create a @solana/kit client for the given Solana configuration.
|
|
6
|
+
*
|
|
7
|
+
* The returned client exposes read-only `rpc` and `rpcSubscriptions`; use
|
|
8
|
+
* `client.rpc.getSlot().send()` and friends instead of the legacy
|
|
9
|
+
* `connection` APIs.
|
|
10
|
+
*/
|
|
11
|
+
declare function createSolanaClient(config?: SolanaConfig): _solana_kit.Client<_solana_kit.ExtendedClient<object, {
|
|
12
|
+
rpc: _solana_kit.Rpc<_solana_kit.RequestAirdropApi & _solana_kit.GetAccountInfoApi & _solana_kit.GetAgGenesisCertApi & _solana_kit.GetBalanceApi & _solana_kit.GetBlockApi & _solana_kit.GetBlockCommitmentApi & _solana_kit.GetBlockHeightApi & _solana_kit.GetBlockProductionApi & _solana_kit.GetBlocksApi & _solana_kit.GetBlocksWithLimitApi & _solana_kit.GetBlockTimeApi & _solana_kit.GetClusterNodesApi & _solana_kit.GetEpochInfoApi & _solana_kit.GetEpochScheduleApi & _solana_kit.GetFeeForMessageApi & _solana_kit.GetFirstAvailableBlockApi & _solana_kit.GetGenesisHashApi & _solana_kit.GetHealthApi & _solana_kit.GetHighestSnapshotSlotApi & _solana_kit.GetIdentityApi & _solana_kit.GetInflationGovernorApi & _solana_kit.GetInflationRateApi & _solana_kit.GetInflationRewardApi & _solana_kit.GetLargestAccountsApi & _solana_kit.GetLatestBlockhashApi & _solana_kit.GetLeaderScheduleApi & _solana_kit.GetMaxRetransmitSlotApi & _solana_kit.GetMaxShredInsertSlotApi & _solana_kit.GetMinimumBalanceForRentExemptionApi & _solana_kit.GetMultipleAccountsApi & _solana_kit.GetProgramAccountsApi & _solana_kit.GetRecentPerformanceSamplesApi & _solana_kit.GetRecentPrioritizationFeesApi & _solana_kit.GetSignaturesForAddressApi & _solana_kit.GetSignatureStatusesApi & _solana_kit.GetSlotApi & _solana_kit.GetSlotLeaderApi & _solana_kit.GetSlotLeadersApi & _solana_kit.GetStakeMinimumDelegationApi & _solana_kit.GetSupplyApi & _solana_kit.GetTokenAccountBalanceApi & _solana_kit.GetTokenAccountsByDelegateApi & _solana_kit.GetTokenAccountsByOwnerApi & _solana_kit.GetTokenLargestAccountsApi & _solana_kit.GetTokenSupplyApi & _solana_kit.GetTransactionApi & _solana_kit.GetTransactionCountApi & _solana_kit.GetTransactionsForAddressApi & _solana_kit.GetVersionApi & _solana_kit.GetVoteAccountsApi & _solana_kit.IsBlockhashValidApi & _solana_kit.MinimumLedgerSlotApi & _solana_kit.SendTransactionApi & _solana_kit.SimulateTransactionApi>;
|
|
13
|
+
rpcSubscriptions: _solana_kit.RpcSubscriptions<_solana_kit.SolanaRpcSubscriptionsApi>;
|
|
14
|
+
}>>;
|
|
15
|
+
type SolanaClient = ReturnType<typeof createSolanaClient>;
|
|
16
|
+
|
|
17
|
+
type SolanaCluster = "mainnet-beta" | "testnet" | "devnet" | "localnet";
|
|
18
|
+
type SolanaChain = "solana:mainnet" | "solana:testnet" | "solana:devnet" | "solana:localnet";
|
|
19
|
+
interface SolanaConfig {
|
|
20
|
+
cluster?: SolanaCluster;
|
|
21
|
+
endpoint?: string;
|
|
22
|
+
wsEndpoint?: string;
|
|
23
|
+
commitment?: Commitment;
|
|
24
|
+
autoConnect?: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface SolanaContext {
|
|
27
|
+
cluster: SolanaCluster;
|
|
28
|
+
endpoint: string;
|
|
29
|
+
wsEndpoint: string;
|
|
30
|
+
client: SolanaClient;
|
|
31
|
+
}
|
|
32
|
+
type SolanaTransaction = Uint8Array;
|
|
33
|
+
interface SolanaSignMessageResult {
|
|
34
|
+
signedMessage: Uint8Array;
|
|
35
|
+
signature: Uint8Array;
|
|
36
|
+
}
|
|
37
|
+
interface SolanaWallet {
|
|
38
|
+
publicKey: Address | null;
|
|
39
|
+
connected: boolean;
|
|
40
|
+
connecting?: boolean;
|
|
41
|
+
disconnecting?: boolean;
|
|
42
|
+
platform?: SolanaWalletInfo["platform"];
|
|
43
|
+
source?: SolanaWalletInfo["source"];
|
|
44
|
+
connect: () => Promise<void>;
|
|
45
|
+
disconnect: () => Promise<void>;
|
|
46
|
+
signMessage?: (message: Uint8Array) => Promise<SolanaSignMessageResult>;
|
|
47
|
+
signTransaction?: (transaction: SolanaTransaction) => Promise<SolanaTransaction>;
|
|
48
|
+
signAllTransactions?: (transactions: SolanaTransaction[]) => Promise<SolanaTransaction[]>;
|
|
49
|
+
signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendTransactionOptions) => Promise<{
|
|
50
|
+
signature: string;
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
interface SolanaWalletInfo {
|
|
54
|
+
name: string;
|
|
55
|
+
icon: string;
|
|
56
|
+
chains: readonly string[];
|
|
57
|
+
platform?: "browser" | "mobile" | "desktop";
|
|
58
|
+
source?: "wallet-standard" | "mobile-wallet-adapter" | "deep-link" | "protocol-link";
|
|
59
|
+
appUrl?: string;
|
|
60
|
+
installUrl?: string;
|
|
61
|
+
callbackUrl?: string;
|
|
62
|
+
capabilities?: {
|
|
63
|
+
connect?: boolean;
|
|
64
|
+
disconnect?: boolean;
|
|
65
|
+
signMessage?: boolean;
|
|
66
|
+
signTransaction?: boolean;
|
|
67
|
+
signAllTransactions?: boolean;
|
|
68
|
+
signAndSendTransaction?: boolean;
|
|
69
|
+
};
|
|
70
|
+
accounts: readonly {
|
|
71
|
+
address: string;
|
|
72
|
+
publicKey: Uint8Array;
|
|
73
|
+
chains: readonly string[];
|
|
74
|
+
label?: string;
|
|
75
|
+
icon?: string;
|
|
76
|
+
}[];
|
|
77
|
+
wallet: unknown;
|
|
78
|
+
}
|
|
79
|
+
interface SendTransactionOptions {
|
|
80
|
+
skipPreflight?: boolean;
|
|
81
|
+
maxRetries?: bigint;
|
|
82
|
+
minContextSlot?: Slot;
|
|
83
|
+
preflightCommitment?: Commitment;
|
|
84
|
+
}
|
|
85
|
+
interface ConfirmTransactionOptions {
|
|
86
|
+
commitment?: Commitment;
|
|
87
|
+
timeoutMs?: number;
|
|
88
|
+
}
|
|
89
|
+
interface TransactionStatus {
|
|
90
|
+
slot: Slot;
|
|
91
|
+
confirmations: bigint | null;
|
|
92
|
+
err: unknown | null;
|
|
93
|
+
confirmationStatus: Commitment | null;
|
|
94
|
+
}
|
|
95
|
+
interface TransactionConfirmation {
|
|
96
|
+
signature: Signature;
|
|
97
|
+
commitment: Commitment;
|
|
98
|
+
status: TransactionStatus;
|
|
99
|
+
}
|
|
100
|
+
|
|
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 };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import * as _solana_kit from '@solana/kit';
|
|
2
|
+
import { Commitment, Slot, Address, Signature } from '@solana/kit';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create a @solana/kit client for the given Solana configuration.
|
|
6
|
+
*
|
|
7
|
+
* The returned client exposes read-only `rpc` and `rpcSubscriptions`; use
|
|
8
|
+
* `client.rpc.getSlot().send()` and friends instead of the legacy
|
|
9
|
+
* `connection` APIs.
|
|
10
|
+
*/
|
|
11
|
+
declare function createSolanaClient(config?: SolanaConfig): _solana_kit.Client<_solana_kit.ExtendedClient<object, {
|
|
12
|
+
rpc: _solana_kit.Rpc<_solana_kit.RequestAirdropApi & _solana_kit.GetAccountInfoApi & _solana_kit.GetAgGenesisCertApi & _solana_kit.GetBalanceApi & _solana_kit.GetBlockApi & _solana_kit.GetBlockCommitmentApi & _solana_kit.GetBlockHeightApi & _solana_kit.GetBlockProductionApi & _solana_kit.GetBlocksApi & _solana_kit.GetBlocksWithLimitApi & _solana_kit.GetBlockTimeApi & _solana_kit.GetClusterNodesApi & _solana_kit.GetEpochInfoApi & _solana_kit.GetEpochScheduleApi & _solana_kit.GetFeeForMessageApi & _solana_kit.GetFirstAvailableBlockApi & _solana_kit.GetGenesisHashApi & _solana_kit.GetHealthApi & _solana_kit.GetHighestSnapshotSlotApi & _solana_kit.GetIdentityApi & _solana_kit.GetInflationGovernorApi & _solana_kit.GetInflationRateApi & _solana_kit.GetInflationRewardApi & _solana_kit.GetLargestAccountsApi & _solana_kit.GetLatestBlockhashApi & _solana_kit.GetLeaderScheduleApi & _solana_kit.GetMaxRetransmitSlotApi & _solana_kit.GetMaxShredInsertSlotApi & _solana_kit.GetMinimumBalanceForRentExemptionApi & _solana_kit.GetMultipleAccountsApi & _solana_kit.GetProgramAccountsApi & _solana_kit.GetRecentPerformanceSamplesApi & _solana_kit.GetRecentPrioritizationFeesApi & _solana_kit.GetSignaturesForAddressApi & _solana_kit.GetSignatureStatusesApi & _solana_kit.GetSlotApi & _solana_kit.GetSlotLeaderApi & _solana_kit.GetSlotLeadersApi & _solana_kit.GetStakeMinimumDelegationApi & _solana_kit.GetSupplyApi & _solana_kit.GetTokenAccountBalanceApi & _solana_kit.GetTokenAccountsByDelegateApi & _solana_kit.GetTokenAccountsByOwnerApi & _solana_kit.GetTokenLargestAccountsApi & _solana_kit.GetTokenSupplyApi & _solana_kit.GetTransactionApi & _solana_kit.GetTransactionCountApi & _solana_kit.GetTransactionsForAddressApi & _solana_kit.GetVersionApi & _solana_kit.GetVoteAccountsApi & _solana_kit.IsBlockhashValidApi & _solana_kit.MinimumLedgerSlotApi & _solana_kit.SendTransactionApi & _solana_kit.SimulateTransactionApi>;
|
|
13
|
+
rpcSubscriptions: _solana_kit.RpcSubscriptions<_solana_kit.SolanaRpcSubscriptionsApi>;
|
|
14
|
+
}>>;
|
|
15
|
+
type SolanaClient = ReturnType<typeof createSolanaClient>;
|
|
16
|
+
|
|
17
|
+
type SolanaCluster = "mainnet-beta" | "testnet" | "devnet" | "localnet";
|
|
18
|
+
type SolanaChain = "solana:mainnet" | "solana:testnet" | "solana:devnet" | "solana:localnet";
|
|
19
|
+
interface SolanaConfig {
|
|
20
|
+
cluster?: SolanaCluster;
|
|
21
|
+
endpoint?: string;
|
|
22
|
+
wsEndpoint?: string;
|
|
23
|
+
commitment?: Commitment;
|
|
24
|
+
autoConnect?: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface SolanaContext {
|
|
27
|
+
cluster: SolanaCluster;
|
|
28
|
+
endpoint: string;
|
|
29
|
+
wsEndpoint: string;
|
|
30
|
+
client: SolanaClient;
|
|
31
|
+
}
|
|
32
|
+
type SolanaTransaction = Uint8Array;
|
|
33
|
+
interface SolanaSignMessageResult {
|
|
34
|
+
signedMessage: Uint8Array;
|
|
35
|
+
signature: Uint8Array;
|
|
36
|
+
}
|
|
37
|
+
interface SolanaWallet {
|
|
38
|
+
publicKey: Address | null;
|
|
39
|
+
connected: boolean;
|
|
40
|
+
connecting?: boolean;
|
|
41
|
+
disconnecting?: boolean;
|
|
42
|
+
platform?: SolanaWalletInfo["platform"];
|
|
43
|
+
source?: SolanaWalletInfo["source"];
|
|
44
|
+
connect: () => Promise<void>;
|
|
45
|
+
disconnect: () => Promise<void>;
|
|
46
|
+
signMessage?: (message: Uint8Array) => Promise<SolanaSignMessageResult>;
|
|
47
|
+
signTransaction?: (transaction: SolanaTransaction) => Promise<SolanaTransaction>;
|
|
48
|
+
signAllTransactions?: (transactions: SolanaTransaction[]) => Promise<SolanaTransaction[]>;
|
|
49
|
+
signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendTransactionOptions) => Promise<{
|
|
50
|
+
signature: string;
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
interface SolanaWalletInfo {
|
|
54
|
+
name: string;
|
|
55
|
+
icon: string;
|
|
56
|
+
chains: readonly string[];
|
|
57
|
+
platform?: "browser" | "mobile" | "desktop";
|
|
58
|
+
source?: "wallet-standard" | "mobile-wallet-adapter" | "deep-link" | "protocol-link";
|
|
59
|
+
appUrl?: string;
|
|
60
|
+
installUrl?: string;
|
|
61
|
+
callbackUrl?: string;
|
|
62
|
+
capabilities?: {
|
|
63
|
+
connect?: boolean;
|
|
64
|
+
disconnect?: boolean;
|
|
65
|
+
signMessage?: boolean;
|
|
66
|
+
signTransaction?: boolean;
|
|
67
|
+
signAllTransactions?: boolean;
|
|
68
|
+
signAndSendTransaction?: boolean;
|
|
69
|
+
};
|
|
70
|
+
accounts: readonly {
|
|
71
|
+
address: string;
|
|
72
|
+
publicKey: Uint8Array;
|
|
73
|
+
chains: readonly string[];
|
|
74
|
+
label?: string;
|
|
75
|
+
icon?: string;
|
|
76
|
+
}[];
|
|
77
|
+
wallet: unknown;
|
|
78
|
+
}
|
|
79
|
+
interface SendTransactionOptions {
|
|
80
|
+
skipPreflight?: boolean;
|
|
81
|
+
maxRetries?: bigint;
|
|
82
|
+
minContextSlot?: Slot;
|
|
83
|
+
preflightCommitment?: Commitment;
|
|
84
|
+
}
|
|
85
|
+
interface ConfirmTransactionOptions {
|
|
86
|
+
commitment?: Commitment;
|
|
87
|
+
timeoutMs?: number;
|
|
88
|
+
}
|
|
89
|
+
interface TransactionStatus {
|
|
90
|
+
slot: Slot;
|
|
91
|
+
confirmations: bigint | null;
|
|
92
|
+
err: unknown | null;
|
|
93
|
+
confirmationStatus: Commitment | null;
|
|
94
|
+
}
|
|
95
|
+
interface TransactionConfirmation {
|
|
96
|
+
signature: Signature;
|
|
97
|
+
commitment: Commitment;
|
|
98
|
+
status: TransactionStatus;
|
|
99
|
+
}
|
|
100
|
+
|
|
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 };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import * as _solana_kit from '@solana/kit';
|
|
2
|
+
import { Commitment, Slot, Address, Signature } from '@solana/kit';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create a @solana/kit client for the given Solana configuration.
|
|
6
|
+
*
|
|
7
|
+
* The returned client exposes read-only `rpc` and `rpcSubscriptions`; use
|
|
8
|
+
* `client.rpc.getSlot().send()` and friends instead of the legacy
|
|
9
|
+
* `connection` APIs.
|
|
10
|
+
*/
|
|
11
|
+
declare function createSolanaClient(config?: SolanaConfig): _solana_kit.Client<_solana_kit.ExtendedClient<object, {
|
|
12
|
+
rpc: _solana_kit.Rpc<_solana_kit.RequestAirdropApi & _solana_kit.GetAccountInfoApi & _solana_kit.GetAgGenesisCertApi & _solana_kit.GetBalanceApi & _solana_kit.GetBlockApi & _solana_kit.GetBlockCommitmentApi & _solana_kit.GetBlockHeightApi & _solana_kit.GetBlockProductionApi & _solana_kit.GetBlocksApi & _solana_kit.GetBlocksWithLimitApi & _solana_kit.GetBlockTimeApi & _solana_kit.GetClusterNodesApi & _solana_kit.GetEpochInfoApi & _solana_kit.GetEpochScheduleApi & _solana_kit.GetFeeForMessageApi & _solana_kit.GetFirstAvailableBlockApi & _solana_kit.GetGenesisHashApi & _solana_kit.GetHealthApi & _solana_kit.GetHighestSnapshotSlotApi & _solana_kit.GetIdentityApi & _solana_kit.GetInflationGovernorApi & _solana_kit.GetInflationRateApi & _solana_kit.GetInflationRewardApi & _solana_kit.GetLargestAccountsApi & _solana_kit.GetLatestBlockhashApi & _solana_kit.GetLeaderScheduleApi & _solana_kit.GetMaxRetransmitSlotApi & _solana_kit.GetMaxShredInsertSlotApi & _solana_kit.GetMinimumBalanceForRentExemptionApi & _solana_kit.GetMultipleAccountsApi & _solana_kit.GetProgramAccountsApi & _solana_kit.GetRecentPerformanceSamplesApi & _solana_kit.GetRecentPrioritizationFeesApi & _solana_kit.GetSignaturesForAddressApi & _solana_kit.GetSignatureStatusesApi & _solana_kit.GetSlotApi & _solana_kit.GetSlotLeaderApi & _solana_kit.GetSlotLeadersApi & _solana_kit.GetStakeMinimumDelegationApi & _solana_kit.GetSupplyApi & _solana_kit.GetTokenAccountBalanceApi & _solana_kit.GetTokenAccountsByDelegateApi & _solana_kit.GetTokenAccountsByOwnerApi & _solana_kit.GetTokenLargestAccountsApi & _solana_kit.GetTokenSupplyApi & _solana_kit.GetTransactionApi & _solana_kit.GetTransactionCountApi & _solana_kit.GetTransactionsForAddressApi & _solana_kit.GetVersionApi & _solana_kit.GetVoteAccountsApi & _solana_kit.IsBlockhashValidApi & _solana_kit.MinimumLedgerSlotApi & _solana_kit.SendTransactionApi & _solana_kit.SimulateTransactionApi>;
|
|
13
|
+
rpcSubscriptions: _solana_kit.RpcSubscriptions<_solana_kit.SolanaRpcSubscriptionsApi>;
|
|
14
|
+
}>>;
|
|
15
|
+
type SolanaClient = ReturnType<typeof createSolanaClient>;
|
|
16
|
+
|
|
17
|
+
type SolanaCluster = "mainnet-beta" | "testnet" | "devnet" | "localnet";
|
|
18
|
+
type SolanaChain = "solana:mainnet" | "solana:testnet" | "solana:devnet" | "solana:localnet";
|
|
19
|
+
interface SolanaConfig {
|
|
20
|
+
cluster?: SolanaCluster;
|
|
21
|
+
endpoint?: string;
|
|
22
|
+
wsEndpoint?: string;
|
|
23
|
+
commitment?: Commitment;
|
|
24
|
+
autoConnect?: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface SolanaContext {
|
|
27
|
+
cluster: SolanaCluster;
|
|
28
|
+
endpoint: string;
|
|
29
|
+
wsEndpoint: string;
|
|
30
|
+
client: SolanaClient;
|
|
31
|
+
}
|
|
32
|
+
type SolanaTransaction = Uint8Array;
|
|
33
|
+
interface SolanaSignMessageResult {
|
|
34
|
+
signedMessage: Uint8Array;
|
|
35
|
+
signature: Uint8Array;
|
|
36
|
+
}
|
|
37
|
+
interface SolanaWallet {
|
|
38
|
+
publicKey: Address | null;
|
|
39
|
+
connected: boolean;
|
|
40
|
+
connecting?: boolean;
|
|
41
|
+
disconnecting?: boolean;
|
|
42
|
+
platform?: SolanaWalletInfo["platform"];
|
|
43
|
+
source?: SolanaWalletInfo["source"];
|
|
44
|
+
connect: () => Promise<void>;
|
|
45
|
+
disconnect: () => Promise<void>;
|
|
46
|
+
signMessage?: (message: Uint8Array) => Promise<SolanaSignMessageResult>;
|
|
47
|
+
signTransaction?: (transaction: SolanaTransaction) => Promise<SolanaTransaction>;
|
|
48
|
+
signAllTransactions?: (transactions: SolanaTransaction[]) => Promise<SolanaTransaction[]>;
|
|
49
|
+
signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendTransactionOptions) => Promise<{
|
|
50
|
+
signature: string;
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
interface SolanaWalletInfo {
|
|
54
|
+
name: string;
|
|
55
|
+
icon: string;
|
|
56
|
+
chains: readonly string[];
|
|
57
|
+
platform?: "browser" | "mobile" | "desktop";
|
|
58
|
+
source?: "wallet-standard" | "mobile-wallet-adapter" | "deep-link" | "protocol-link";
|
|
59
|
+
appUrl?: string;
|
|
60
|
+
installUrl?: string;
|
|
61
|
+
callbackUrl?: string;
|
|
62
|
+
capabilities?: {
|
|
63
|
+
connect?: boolean;
|
|
64
|
+
disconnect?: boolean;
|
|
65
|
+
signMessage?: boolean;
|
|
66
|
+
signTransaction?: boolean;
|
|
67
|
+
signAllTransactions?: boolean;
|
|
68
|
+
signAndSendTransaction?: boolean;
|
|
69
|
+
};
|
|
70
|
+
accounts: readonly {
|
|
71
|
+
address: string;
|
|
72
|
+
publicKey: Uint8Array;
|
|
73
|
+
chains: readonly string[];
|
|
74
|
+
label?: string;
|
|
75
|
+
icon?: string;
|
|
76
|
+
}[];
|
|
77
|
+
wallet: unknown;
|
|
78
|
+
}
|
|
79
|
+
interface SendTransactionOptions {
|
|
80
|
+
skipPreflight?: boolean;
|
|
81
|
+
maxRetries?: bigint;
|
|
82
|
+
minContextSlot?: Slot;
|
|
83
|
+
preflightCommitment?: Commitment;
|
|
84
|
+
}
|
|
85
|
+
interface ConfirmTransactionOptions {
|
|
86
|
+
commitment?: Commitment;
|
|
87
|
+
timeoutMs?: number;
|
|
88
|
+
}
|
|
89
|
+
interface TransactionStatus {
|
|
90
|
+
slot: Slot;
|
|
91
|
+
confirmations: bigint | null;
|
|
92
|
+
err: unknown | null;
|
|
93
|
+
confirmationStatus: Commitment | null;
|
|
94
|
+
}
|
|
95
|
+
interface TransactionConfirmation {
|
|
96
|
+
signature: Signature;
|
|
97
|
+
commitment: Commitment;
|
|
98
|
+
status: TransactionStatus;
|
|
99
|
+
}
|
|
100
|
+
|
|
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,17 +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
|
-
|
|
9
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Get all SPL token accounts for an owner using parsed kit RPC reads.
|
|
19
|
+
*/
|
|
20
|
+
declare function getTokenAccountsByOwner(client: SolanaClient, owner: Address, options?: TokenAccountsByOwnerOptions): Promise<TokenAccountInfo[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Get a single parsed token account at the given address.
|
|
23
|
+
*/
|
|
24
|
+
declare function getTokenAccount(client: SolanaClient, address: Address, commitment?: Commitment): Promise<TokenAccountInfo | null>;
|
|
10
25
|
interface TokenBalanceResult {
|
|
11
26
|
amount: bigint;
|
|
12
27
|
decimals: number;
|
|
13
28
|
}
|
|
14
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Read the token balance of the accounts an owner holds for a given mint.
|
|
31
|
+
*/
|
|
32
|
+
declare function getTokenBalance(client: SolanaClient, mint: Address, owner: Address, commitment?: Commitment): Promise<TokenBalanceResult | null>;
|
|
15
33
|
|
|
16
34
|
export { getTokenAccount, getTokenAccountsByOwner, getTokenBalance };
|
|
17
|
-
export type { TokenAccountsByOwnerOptions, TokenBalanceResult };
|
|
35
|
+
export type { TokenAccountInfo, TokenAccountsByOwnerOptions, TokenBalanceResult };
|
|
@@ -1,17 +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
|
-
|
|
9
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Get all SPL token accounts for an owner using parsed kit RPC reads.
|
|
19
|
+
*/
|
|
20
|
+
declare function getTokenAccountsByOwner(client: SolanaClient, owner: Address, options?: TokenAccountsByOwnerOptions): Promise<TokenAccountInfo[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Get a single parsed token account at the given address.
|
|
23
|
+
*/
|
|
24
|
+
declare function getTokenAccount(client: SolanaClient, address: Address, commitment?: Commitment): Promise<TokenAccountInfo | null>;
|
|
10
25
|
interface TokenBalanceResult {
|
|
11
26
|
amount: bigint;
|
|
12
27
|
decimals: number;
|
|
13
28
|
}
|
|
14
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Read the token balance of the accounts an owner holds for a given mint.
|
|
31
|
+
*/
|
|
32
|
+
declare function getTokenBalance(client: SolanaClient, mint: Address, owner: Address, commitment?: Commitment): Promise<TokenBalanceResult | null>;
|
|
15
33
|
|
|
16
34
|
export { getTokenAccount, getTokenAccountsByOwner, getTokenBalance };
|
|
17
|
-
export type { TokenAccountsByOwnerOptions, TokenBalanceResult };
|
|
35
|
+
export type { TokenAccountInfo, TokenAccountsByOwnerOptions, TokenBalanceResult };
|