@solana/kit 6.3.1 → 6.3.2-canary-20260313143218
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/dist/index.development.js +6 -6
- package/dist/index.development.js.map +1 -1
- package/dist/index.production.min.js +32 -32
- package/package.json +27 -26
- package/src/airdrop-internal.ts +38 -0
- package/src/airdrop.ts +80 -0
- package/src/decompile-transaction-message-fetching-lookup-tables.ts +50 -0
- package/src/fetch-lookup-tables.ts +46 -0
- package/src/get-minimum-balance-for-rent-exemption.ts +26 -0
- package/src/index.ts +43 -0
- package/src/program-client-core.ts +1 -0
- package/src/send-and-confirm-durable-nonce-transaction.ts +172 -0
- package/src/send-and-confirm-transaction.ts +95 -0
- package/src/send-transaction-internal.ts +134 -0
- package/src/send-transaction-without-confirming.ts +52 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { Signature } from '@solana/keys';
|
|
2
|
+
import type { Rpc, SendTransactionApi } from '@solana/rpc';
|
|
3
|
+
import { Commitment, commitmentComparator } from '@solana/rpc-types';
|
|
4
|
+
import {
|
|
5
|
+
TransactionWithLastValidBlockHeight,
|
|
6
|
+
waitForDurableNonceTransactionConfirmation,
|
|
7
|
+
waitForRecentTransactionConfirmation,
|
|
8
|
+
} from '@solana/transaction-confirmation';
|
|
9
|
+
import {
|
|
10
|
+
getBase64EncodedWireTransaction,
|
|
11
|
+
SendableTransaction,
|
|
12
|
+
Transaction,
|
|
13
|
+
TransactionWithDurableNonceLifetime,
|
|
14
|
+
} from '@solana/transactions';
|
|
15
|
+
|
|
16
|
+
interface SendAndConfirmDurableNonceTransactionConfig
|
|
17
|
+
extends SendTransactionBaseConfig, SendTransactionConfigWithoutEncoding {
|
|
18
|
+
confirmDurableNonceTransaction: (
|
|
19
|
+
config: Omit<
|
|
20
|
+
Parameters<typeof waitForDurableNonceTransactionConfirmation>[0],
|
|
21
|
+
'getNonceInvalidationPromise' | 'getRecentSignatureConfirmationPromise'
|
|
22
|
+
>,
|
|
23
|
+
) => Promise<void>;
|
|
24
|
+
transaction: SendableTransaction & Transaction & TransactionWithDurableNonceLifetime;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface SendAndConfirmTransactionWithBlockhashLifetimeConfig
|
|
28
|
+
extends SendTransactionBaseConfig, SendTransactionConfigWithoutEncoding {
|
|
29
|
+
confirmRecentTransaction: (
|
|
30
|
+
config: Omit<
|
|
31
|
+
Parameters<typeof waitForRecentTransactionConfirmation>[0],
|
|
32
|
+
'getBlockHeightExceedencePromise' | 'getRecentSignatureConfirmationPromise'
|
|
33
|
+
>,
|
|
34
|
+
) => Promise<void>;
|
|
35
|
+
transaction: SendableTransaction & Transaction & TransactionWithLastValidBlockHeight;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface SendTransactionBaseConfig extends SendTransactionConfigWithoutEncoding {
|
|
39
|
+
abortSignal?: AbortSignal;
|
|
40
|
+
commitment: Commitment;
|
|
41
|
+
rpc: Rpc<SendTransactionApi>;
|
|
42
|
+
transaction: SendableTransaction & Transaction;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type SendTransactionConfigWithoutEncoding = Omit<
|
|
46
|
+
NonNullable<Parameters<SendTransactionApi['sendTransaction']>[1]>,
|
|
47
|
+
'encoding'
|
|
48
|
+
>;
|
|
49
|
+
|
|
50
|
+
function getSendTransactionConfigWithAdjustedPreflightCommitment(
|
|
51
|
+
commitment: Commitment,
|
|
52
|
+
config?: SendTransactionConfigWithoutEncoding,
|
|
53
|
+
): SendTransactionConfigWithoutEncoding | void {
|
|
54
|
+
if (
|
|
55
|
+
// The developer has supplied no value for `preflightCommitment`.
|
|
56
|
+
!config?.preflightCommitment &&
|
|
57
|
+
// The value of `commitment` is lower than the server default of `preflightCommitment`.
|
|
58
|
+
commitmentComparator(commitment, 'finalized' /* default value of `preflightCommitment` */) < 0
|
|
59
|
+
) {
|
|
60
|
+
return {
|
|
61
|
+
...config,
|
|
62
|
+
// In the common case, it is unlikely that you want to simulate a transaction at
|
|
63
|
+
// `finalized` commitment when your standard of commitment for confirming the
|
|
64
|
+
// transaction is lower. Cap the simulation commitment level to the level of the
|
|
65
|
+
// confirmation commitment.
|
|
66
|
+
preflightCommitment: commitment,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
// The commitment at which the developer wishes to confirm the transaction is at least as
|
|
70
|
+
// high as the commitment at which they want to simulate it. Honour the config as-is.
|
|
71
|
+
return config;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export async function sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
75
|
+
abortSignal,
|
|
76
|
+
commitment,
|
|
77
|
+
rpc,
|
|
78
|
+
transaction,
|
|
79
|
+
...sendTransactionConfig
|
|
80
|
+
}: SendTransactionBaseConfig): Promise<Signature> {
|
|
81
|
+
const base64EncodedWireTransaction = getBase64EncodedWireTransaction(transaction);
|
|
82
|
+
return await rpc
|
|
83
|
+
.sendTransaction(base64EncodedWireTransaction, {
|
|
84
|
+
...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),
|
|
85
|
+
encoding: 'base64',
|
|
86
|
+
})
|
|
87
|
+
.send({ abortSignal });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
91
|
+
abortSignal,
|
|
92
|
+
commitment,
|
|
93
|
+
confirmDurableNonceTransaction,
|
|
94
|
+
rpc,
|
|
95
|
+
transaction,
|
|
96
|
+
...sendTransactionConfig
|
|
97
|
+
}: SendAndConfirmDurableNonceTransactionConfig): Promise<Signature> {
|
|
98
|
+
const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
99
|
+
...sendTransactionConfig,
|
|
100
|
+
abortSignal,
|
|
101
|
+
commitment,
|
|
102
|
+
rpc,
|
|
103
|
+
transaction,
|
|
104
|
+
});
|
|
105
|
+
await confirmDurableNonceTransaction({
|
|
106
|
+
abortSignal,
|
|
107
|
+
commitment,
|
|
108
|
+
transaction,
|
|
109
|
+
});
|
|
110
|
+
return transactionSignature;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
114
|
+
abortSignal,
|
|
115
|
+
commitment,
|
|
116
|
+
confirmRecentTransaction,
|
|
117
|
+
rpc,
|
|
118
|
+
transaction,
|
|
119
|
+
...sendTransactionConfig
|
|
120
|
+
}: SendAndConfirmTransactionWithBlockhashLifetimeConfig): Promise<Signature> {
|
|
121
|
+
const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
122
|
+
...sendTransactionConfig,
|
|
123
|
+
abortSignal,
|
|
124
|
+
commitment,
|
|
125
|
+
rpc,
|
|
126
|
+
transaction,
|
|
127
|
+
});
|
|
128
|
+
await confirmRecentTransaction({
|
|
129
|
+
abortSignal,
|
|
130
|
+
commitment,
|
|
131
|
+
transaction,
|
|
132
|
+
});
|
|
133
|
+
return transactionSignature;
|
|
134
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Rpc, SendTransactionApi } from '@solana/rpc';
|
|
2
|
+
import { SendableTransaction, Transaction } from '@solana/transactions';
|
|
3
|
+
|
|
4
|
+
import { sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT } from './send-transaction-internal';
|
|
5
|
+
|
|
6
|
+
type SendTransactionWithoutConfirmingFunction = (
|
|
7
|
+
transaction: SendableTransaction & Transaction,
|
|
8
|
+
config: Omit<Parameters<typeof sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT>[0], 'rpc' | 'transaction'>,
|
|
9
|
+
) => Promise<void>;
|
|
10
|
+
|
|
11
|
+
interface SendTransactionWithoutConfirmingFactoryConfig {
|
|
12
|
+
/** An object that supports the {@link SendTransactionApi} of the Solana RPC API */
|
|
13
|
+
rpc: Rpc<SendTransactionApi>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Returns a function that you can call to send a transaction with any kind of lifetime to the
|
|
18
|
+
* network without waiting for it to be confirmed.
|
|
19
|
+
*
|
|
20
|
+
* @param config
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import {
|
|
25
|
+
* sendTransactionWithoutConfirmingFactory,
|
|
26
|
+
* SOLANA_ERROR__JSON_RPC__SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE,
|
|
27
|
+
* } from '@solana/kit';
|
|
28
|
+
*
|
|
29
|
+
* const sendTransaction = sendTransactionWithoutConfirmingFactory({ rpc });
|
|
30
|
+
*
|
|
31
|
+
* try {
|
|
32
|
+
* await sendTransaction(transaction, { commitment: 'confirmed' });
|
|
33
|
+
* } catch (e) {
|
|
34
|
+
* if (isSolanaError(e, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE)) {
|
|
35
|
+
* console.error('The transaction failed in simulation', e.cause);
|
|
36
|
+
* } else {
|
|
37
|
+
* throw e;
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export function sendTransactionWithoutConfirmingFactory({
|
|
43
|
+
rpc,
|
|
44
|
+
}: SendTransactionWithoutConfirmingFactoryConfig): SendTransactionWithoutConfirmingFunction {
|
|
45
|
+
return async function sendTransactionWithoutConfirming(transaction, config) {
|
|
46
|
+
await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
47
|
+
...config,
|
|
48
|
+
rpc,
|
|
49
|
+
transaction,
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
}
|