@solana/web3.js 2.0.0-experimental.0cfc222 → 2.0.0-experimental.0e03ca9

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 (57) hide show
  1. package/README.md +1153 -43
  2. package/dist/index.browser.cjs +479 -111
  3. package/dist/index.browser.cjs.map +1 -1
  4. package/dist/index.browser.js +434 -111
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.development.js +4351 -2065
  7. package/dist/index.development.js.map +1 -1
  8. package/dist/index.native.js +434 -111
  9. package/dist/index.native.js.map +1 -1
  10. package/dist/index.node.cjs +481 -111
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.js +436 -111
  13. package/dist/index.node.js.map +1 -1
  14. package/dist/index.production.min.js +273 -50
  15. package/dist/types/airdrop-confirmer.d.ts +19 -0
  16. package/dist/types/airdrop-confirmer.d.ts.map +1 -0
  17. package/dist/types/airdrop.d.ts +21 -0
  18. package/dist/types/airdrop.d.ts.map +1 -0
  19. package/dist/types/cached-abortable-iterable.d.ts.map +1 -0
  20. package/dist/types/decode-transaction.d.ts +10 -0
  21. package/dist/types/decode-transaction.d.ts.map +1 -0
  22. package/dist/types/index.d.ts +17 -7
  23. package/dist/types/index.d.ts.map +1 -0
  24. package/dist/types/rpc-default-config.d.ts.map +1 -0
  25. package/dist/types/rpc-integer-overflow-error.d.ts +3 -2
  26. package/dist/types/rpc-integer-overflow-error.d.ts.map +1 -0
  27. package/dist/types/rpc-request-coalescer.d.ts +2 -2
  28. package/dist/types/rpc-request-coalescer.d.ts.map +1 -0
  29. package/dist/types/rpc-request-deduplication.d.ts.map +1 -0
  30. package/dist/types/rpc-subscription-coalescer.d.ts +1 -1
  31. package/dist/types/rpc-subscription-coalescer.d.ts.map +1 -0
  32. package/dist/types/rpc-transport.d.ts +7 -2
  33. package/dist/types/rpc-transport.d.ts.map +1 -0
  34. package/dist/types/rpc-websocket-autopinger.d.ts +4 -4
  35. package/dist/types/rpc-websocket-autopinger.d.ts.map +1 -0
  36. package/dist/types/rpc-websocket-connection-sharding.d.ts +4 -4
  37. package/dist/types/rpc-websocket-connection-sharding.d.ts.map +1 -0
  38. package/dist/types/rpc-websocket-transport.d.ts +7 -4
  39. package/dist/types/rpc-websocket-transport.d.ts.map +1 -0
  40. package/dist/types/rpc.d.ts +12 -6
  41. package/dist/types/rpc.d.ts.map +1 -0
  42. package/dist/types/send-transaction.d.ts +37 -0
  43. package/dist/types/send-transaction.d.ts.map +1 -0
  44. package/dist/types/transaction-confirmation-strategy-blockheight.d.ts +9 -5
  45. package/dist/types/transaction-confirmation-strategy-blockheight.d.ts.map +1 -0
  46. package/dist/types/transaction-confirmation-strategy-nonce.d.ts +4 -6
  47. package/dist/types/transaction-confirmation-strategy-nonce.d.ts.map +1 -0
  48. package/dist/types/transaction-confirmation-strategy-racer.d.ts +14 -0
  49. package/dist/types/transaction-confirmation-strategy-racer.d.ts.map +1 -0
  50. package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts +11 -0
  51. package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts.map +1 -0
  52. package/dist/types/transaction-confirmation-strategy-timeout.d.ts +8 -0
  53. package/dist/types/transaction-confirmation-strategy-timeout.d.ts.map +1 -0
  54. package/dist/types/transaction-confirmation.d.ts +20 -27
  55. package/dist/types/transaction-confirmation.d.ts.map +1 -0
  56. package/package.json +24 -18
  57. package/dist/types/transaction-confirmation-strategy-signature.d.ts +0 -13
@@ -1,14 +1,19 @@
1
1
  'use strict';
2
2
 
3
+ var accounts = require('@solana/accounts');
3
4
  var addresses = require('@solana/addresses');
5
+ var codecs = require('@solana/codecs');
6
+ var functional = require('@solana/functional');
4
7
  var instructions = require('@solana/instructions');
5
8
  var keys = require('@solana/keys');
9
+ var programs = require('@solana/programs');
10
+ var rpcParsedTypes = require('@solana/rpc-parsed-types');
11
+ var rpcTypes = require('@solana/rpc-types');
12
+ var signers = require('@solana/signers');
6
13
  var transactions = require('@solana/transactions');
7
- var functional = require('@solana/functional');
8
14
  var rpcCore = require('@solana/rpc-core');
9
15
  var rpcTransport = require('@solana/rpc-transport');
10
16
  var fastStableStringify = require('fast-stable-stringify');
11
- var umiSerializers = require('@metaplex-foundation/umi-serializers');
12
17
 
13
18
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
19
 
@@ -17,25 +22,217 @@ var fastStableStringify__default = /*#__PURE__*/_interopDefault(fastStableString
17
22
  // ../build-scripts/env-shim.ts
18
23
  var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
19
24
 
25
+ // src/transaction-confirmation-strategy-racer.ts
26
+ async function raceStrategies(signature, config, getSpecificStrategiesForRace) {
27
+ const { abortSignal: callerAbortSignal, commitment, getRecentSignatureConfirmationPromise } = config;
28
+ callerAbortSignal?.throwIfAborted();
29
+ const abortController = new AbortController();
30
+ if (callerAbortSignal) {
31
+ const handleAbort = () => {
32
+ abortController.abort();
33
+ };
34
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
35
+ }
36
+ try {
37
+ const specificStrategies = getSpecificStrategiesForRace({
38
+ ...config,
39
+ abortSignal: abortController.signal
40
+ });
41
+ return await Promise.race([
42
+ getRecentSignatureConfirmationPromise({
43
+ abortSignal: abortController.signal,
44
+ commitment,
45
+ signature
46
+ }),
47
+ ...specificStrategies
48
+ ]);
49
+ } finally {
50
+ abortController.abort();
51
+ }
52
+ }
53
+ function createRecentSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
54
+ return async function getRecentSignatureConfirmationPromise({
55
+ abortSignal: callerAbortSignal,
56
+ commitment,
57
+ signature
58
+ }) {
59
+ const abortController = new AbortController();
60
+ function handleAbort() {
61
+ abortController.abort();
62
+ }
63
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
64
+ const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature, { commitment }).subscribe({ abortSignal: abortController.signal });
65
+ const signatureDidCommitPromise = (async () => {
66
+ for await (const signatureStatusNotification of signatureStatusNotifications) {
67
+ if (signatureStatusNotification.value.err) {
68
+ throw new Error(`The transaction with signature \`${signature}\` failed.`, {
69
+ cause: signatureStatusNotification.value.err
70
+ });
71
+ } else {
72
+ return;
73
+ }
74
+ }
75
+ })();
76
+ const signatureStatusLookupPromise = (async () => {
77
+ const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature]).send({ abortSignal: abortController.signal });
78
+ const signatureStatus = signatureStatusResults[0];
79
+ if (signatureStatus && signatureStatus.confirmationStatus && rpcTypes.commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
80
+ return;
81
+ } else {
82
+ await new Promise(() => {
83
+ });
84
+ }
85
+ })();
86
+ try {
87
+ return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
88
+ } finally {
89
+ abortController.abort();
90
+ }
91
+ };
92
+ }
93
+
94
+ // src/transaction-confirmation-strategy-timeout.ts
95
+ async function getTimeoutPromise({ abortSignal: callerAbortSignal, commitment }) {
96
+ return await new Promise((_, reject) => {
97
+ const handleAbort = (e) => {
98
+ clearTimeout(timeoutId);
99
+ const abortError = new DOMException(e.target.reason, "AbortError");
100
+ reject(abortError);
101
+ };
102
+ callerAbortSignal.addEventListener("abort", handleAbort);
103
+ const timeoutMs = commitment === "processed" ? 3e4 : 6e4;
104
+ const startMs = performance.now();
105
+ const timeoutId = (
106
+ // We use `setTimeout` instead of `AbortSignal.timeout()` because we want to measure
107
+ // elapsed time instead of active time.
108
+ // See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static
109
+ setTimeout(() => {
110
+ const elapsedMs = performance.now() - startMs;
111
+ reject(new DOMException(`Timeout elapsed after ${elapsedMs} ms`, "TimeoutError"));
112
+ }, timeoutMs)
113
+ );
114
+ });
115
+ }
116
+
117
+ // src/airdrop-confirmer.ts
118
+ function createDefaultSignatureOnlyRecentTransactionConfirmer({
119
+ rpc,
120
+ rpcSubscriptions
121
+ }) {
122
+ const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
123
+ rpc,
124
+ rpcSubscriptions
125
+ );
126
+ return async function confirmSignatureOnlyRecentTransaction(config) {
127
+ await waitForRecentTransactionConfirmationUntilTimeout({
128
+ ...config,
129
+ getRecentSignatureConfirmationPromise,
130
+ getTimeoutPromise
131
+ });
132
+ };
133
+ }
134
+ async function waitForRecentTransactionConfirmationUntilTimeout(config) {
135
+ await raceStrategies(
136
+ config.signature,
137
+ config,
138
+ function getSpecificStrategiesForRace({ abortSignal, commitment, getTimeoutPromise: getTimeoutPromise2 }) {
139
+ return [
140
+ getTimeoutPromise2({
141
+ abortSignal,
142
+ commitment
143
+ })
144
+ ];
145
+ }
146
+ );
147
+ }
148
+
149
+ // src/airdrop.ts
150
+ function createDefaultAirdropRequester({ rpc, rpcSubscriptions }) {
151
+ const confirmSignatureOnlyTransaction = createDefaultSignatureOnlyRecentTransactionConfirmer({
152
+ rpc,
153
+ rpcSubscriptions
154
+ });
155
+ return async function requestAirdrop(config) {
156
+ return await requestAndConfirmAirdrop({
157
+ ...config,
158
+ confirmSignatureOnlyTransaction,
159
+ rpc
160
+ });
161
+ };
162
+ }
163
+ async function requestAndConfirmAirdrop({
164
+ abortSignal,
165
+ commitment,
166
+ confirmSignatureOnlyTransaction,
167
+ lamports,
168
+ recipientAddress,
169
+ rpc
170
+ }) {
171
+ const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports, { commitment }).send({ abortSignal });
172
+ await confirmSignatureOnlyTransaction({
173
+ abortSignal,
174
+ commitment,
175
+ signature: airdropTransactionSignature
176
+ });
177
+ return airdropTransactionSignature;
178
+ }
179
+ var compiledTransactionDecoder = void 0;
180
+ async function fetchLookupTables(lookupTableAddresses, rpc, config) {
181
+ const fetchedLookupTables = await accounts.fetchJsonParsedAccounts(
182
+ rpc,
183
+ lookupTableAddresses,
184
+ config
185
+ );
186
+ accounts.assertAccountsDecoded(fetchedLookupTables);
187
+ accounts.assertAccountsExist(fetchedLookupTables);
188
+ return fetchedLookupTables.reduce((acc, lookup) => {
189
+ return {
190
+ ...acc,
191
+ [lookup.address]: lookup.data.addresses
192
+ };
193
+ }, {});
194
+ }
195
+ async function decodeTransaction(encodedTransaction, rpc, config) {
196
+ const { lastValidBlockHeight, ...fetchAccountsConfig } = config ?? {};
197
+ if (!compiledTransactionDecoder)
198
+ compiledTransactionDecoder = transactions.getCompiledTransactionDecoder();
199
+ const compiledTransaction = compiledTransactionDecoder.decode(encodedTransaction);
200
+ const { compiledMessage } = compiledTransaction;
201
+ const lookupTables = "addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups !== void 0 && compiledMessage.addressTableLookups.length > 0 ? compiledMessage.addressTableLookups : [];
202
+ const lookupTableAddresses = lookupTables.map((l) => l.lookupTableAddress);
203
+ const fetchedLookupTables = lookupTableAddresses.length > 0 ? await fetchLookupTables(lookupTableAddresses, rpc, fetchAccountsConfig) : {};
204
+ return transactions.decompileTransaction(compiledTransaction, {
205
+ addressesByLookupTableAddress: fetchedLookupTables,
206
+ lastValidBlockHeight
207
+ });
208
+ }
209
+
20
210
  // src/rpc-integer-overflow-error.ts
21
211
  var SolanaJsonRpcIntegerOverflowError = class extends Error {
212
+ methodName;
213
+ keyPath;
214
+ value;
22
215
  constructor(methodName, keyPath, value) {
23
- const argPosition = (typeof keyPath[0] === "number" ? keyPath[0] : parseInt(keyPath[0], 10)) + 1;
24
- let ordinal = "";
25
- const lastDigit = argPosition % 10;
26
- const lastTwoDigits = argPosition % 100;
27
- if (lastDigit == 1 && lastTwoDigits != 11) {
28
- ordinal = argPosition + "st";
29
- } else if (lastDigit == 2 && lastTwoDigits != 12) {
30
- ordinal = argPosition + "nd";
31
- } else if (lastDigit == 3 && lastTwoDigits != 13) {
32
- ordinal = argPosition + "rd";
216
+ let argumentLabel = "";
217
+ if (typeof keyPath[0] === "number") {
218
+ const argPosition = keyPath[0] + 1;
219
+ const lastDigit = argPosition % 10;
220
+ const lastTwoDigits = argPosition % 100;
221
+ if (lastDigit == 1 && lastTwoDigits != 11) {
222
+ argumentLabel = argPosition + "st";
223
+ } else if (lastDigit == 2 && lastTwoDigits != 12) {
224
+ argumentLabel = argPosition + "nd";
225
+ } else if (lastDigit == 3 && lastTwoDigits != 13) {
226
+ argumentLabel = argPosition + "rd";
227
+ } else {
228
+ argumentLabel = argPosition + "th";
229
+ }
33
230
  } else {
34
- ordinal = argPosition + "th";
231
+ argumentLabel = `\`${keyPath[0].toString()}\``;
35
232
  }
36
233
  const path = keyPath.length > 1 ? keyPath.slice(1).map((pathPart) => typeof pathPart === "number" ? `[${pathPart}]` : pathPart).join(".") : null;
37
234
  super(
38
- `The ${ordinal} argument to the \`${methodName}\` RPC method${path ? ` at path \`${path}\`` : ""} was \`${value}\`. This number is unsafe for use with the Solana JSON-RPC because it exceeds \`Number.MAX_SAFE_INTEGER\`.`
235
+ `The ${argumentLabel} argument to the \`${methodName}\` RPC method${path ? ` at path \`${path}\`` : ""} was \`${value}\`. This number is unsafe for use with the Solana JSON-RPC because it exceeds \`Number.MAX_SAFE_INTEGER\`.`
39
236
  );
40
237
  this.keyPath = keyPath;
41
238
  this.methodName = methodName;
@@ -48,6 +245,7 @@ var SolanaJsonRpcIntegerOverflowError = class extends Error {
48
245
 
49
246
  // src/rpc-default-config.ts
50
247
  var DEFAULT_RPC_CONFIG = {
248
+ defaultCommitment: "confirmed",
51
249
  onIntegerOverflow(methodName, keyPath, value) {
52
250
  throw new SolanaJsonRpcIntegerOverflowError(methodName, keyPath, value);
53
251
  }
@@ -207,11 +405,11 @@ function getRpcSubscriptionsWithSubscriptionCoalescing({
207
405
  return {
208
406
  ...iterable,
209
407
  async *[Symbol.asyncIterator]() {
210
- abortPromise || (abortPromise = abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN) : new Promise((_, reject) => {
408
+ abortPromise ||= abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN) : new Promise((_, reject) => {
211
409
  abortSignal.addEventListener("abort", () => {
212
410
  reject(EXPLICIT_ABORT_TOKEN);
213
411
  });
214
- }));
412
+ });
215
413
  try {
216
414
  const iterator = iterable[Symbol.asyncIterator]();
217
415
  while (true) {
@@ -242,9 +440,10 @@ function getRpcSubscriptionsWithSubscriptionCoalescing({
242
440
 
243
441
  // src/rpc.ts
244
442
  function createSolanaRpc(config) {
443
+ const api = rpcCore.createSolanaRpcApi(DEFAULT_RPC_CONFIG);
245
444
  return rpcTransport.createJsonRpc({
246
445
  ...config,
247
- api: rpcCore.createSolanaRpcApi(DEFAULT_RPC_CONFIG)
446
+ api
248
447
  });
249
448
  }
250
449
  function createSolanaRpcSubscriptions(config) {
@@ -283,13 +482,23 @@ function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
283
482
  }
284
483
  if (coalescedRequestsByDeduplicationKey[deduplicationKey] == null) {
285
484
  const abortController = new AbortController();
485
+ const responsePromise = (async () => {
486
+ try {
487
+ return await transport({
488
+ ...config,
489
+ signal: abortController.signal
490
+ });
491
+ } catch (e) {
492
+ if (e && typeof e === "object" && "name" in e && e.name === "AbortError") {
493
+ return;
494
+ }
495
+ throw e;
496
+ }
497
+ })();
286
498
  coalescedRequestsByDeduplicationKey[deduplicationKey] = {
287
499
  abortController,
288
500
  numConsumers: 0,
289
- responsePromise: transport({
290
- ...config,
291
- signal: abortController.signal
292
- })
501
+ responsePromise
293
502
  };
294
503
  }
295
504
  const coalescedRequest = coalescedRequestsByDeduplicationKey[deduplicationKey];
@@ -356,7 +565,10 @@ var PING_PAYLOAD = {
356
565
  jsonrpc: "2.0",
357
566
  method: "ping"
358
567
  };
359
- function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
568
+ function getWebSocketTransportWithAutoping({
569
+ intervalMs,
570
+ transport
571
+ }) {
360
572
  const pingableConnections = /* @__PURE__ */ new Map();
361
573
  return async (...args) => {
362
574
  const connection = await transport(...args);
@@ -418,7 +630,10 @@ function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
418
630
  var NULL_SHARD_CACHE_KEY = Symbol(
419
631
  __DEV__ ? "Cache key to use when there is no connection sharding strategy" : void 0
420
632
  );
421
- function getWebSocketTransportWithConnectionSharding({ getShard, transport }) {
633
+ function getWebSocketTransportWithConnectionSharding({
634
+ getShard,
635
+ transport
636
+ }) {
422
637
  return getCachedAbortableIterableFactory({
423
638
  getAbortSignalFromInputArgs: ({ signal }) => signal,
424
639
  getCacheEntryMissingError(shardKey) {
@@ -454,22 +669,52 @@ function createDefaultRpcSubscriptionsTransport(config) {
454
669
  }
455
670
 
456
671
  // src/transaction-confirmation-strategy-blockheight.ts
457
- function createBlockHeightExceedencePromiseFactory(rpcSubscriptions) {
458
- return async function getBlockHeightExceedencePromise({ abortSignal: callerAbortSignal, lastValidBlockHeight }) {
672
+ function createBlockHeightExceedencePromiseFactory({
673
+ rpc,
674
+ rpcSubscriptions
675
+ }) {
676
+ return async function getBlockHeightExceedencePromise({
677
+ abortSignal: callerAbortSignal,
678
+ commitment,
679
+ lastValidBlockHeight
680
+ }) {
459
681
  const abortController = new AbortController();
460
- function handleAbort() {
682
+ const handleAbort = () => {
461
683
  abortController.abort();
462
- }
684
+ };
463
685
  callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
464
- const slotNotifications = await rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal });
686
+ async function getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight() {
687
+ const { absoluteSlot, blockHeight } = await rpc.getEpochInfo({ commitment }).send({ abortSignal: abortController.signal });
688
+ return {
689
+ blockHeight,
690
+ differenceBetweenSlotHeightAndBlockHeight: absoluteSlot - blockHeight
691
+ };
692
+ }
465
693
  try {
466
- for await (const slotNotification of slotNotifications) {
467
- if (slotNotification.slot > lastValidBlockHeight) {
468
- throw new Error(
469
- "The network has progressed past the last block for which this transaction could have committed."
470
- );
694
+ const [slotNotifications, { blockHeight, differenceBetweenSlotHeightAndBlockHeight }] = await Promise.all([
695
+ rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal }),
696
+ getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight()
697
+ ]);
698
+ if (blockHeight <= lastValidBlockHeight) {
699
+ let lastKnownDifferenceBetweenSlotHeightAndBlockHeight = differenceBetweenSlotHeightAndBlockHeight;
700
+ for await (const slotNotification of slotNotifications) {
701
+ const { slot } = slotNotification;
702
+ if (slot - lastKnownDifferenceBetweenSlotHeightAndBlockHeight > lastValidBlockHeight) {
703
+ const {
704
+ blockHeight: currentBlockHeight,
705
+ differenceBetweenSlotHeightAndBlockHeight: currentDifferenceBetweenSlotHeightAndBlockHeight
706
+ } = await getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight();
707
+ if (currentBlockHeight > lastValidBlockHeight) {
708
+ break;
709
+ } else {
710
+ lastKnownDifferenceBetweenSlotHeightAndBlockHeight = currentDifferenceBetweenSlotHeightAndBlockHeight;
711
+ }
712
+ }
471
713
  }
472
714
  }
715
+ throw new Error(
716
+ "The network has progressed past the last block for which this transaction could have been committed."
717
+ );
473
718
  } finally {
474
719
  abortController.abort();
475
720
  }
@@ -491,10 +736,12 @@ function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
491
736
  }
492
737
  callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
493
738
  const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
739
+ const base58Decoder = codecs.getBase58Decoder();
740
+ const base64Encoder = codecs.getBase64Encoder();
494
741
  function getNonceFromAccountData([base64EncodedBytes]) {
495
- const data = umiSerializers.base64.serialize(base64EncodedBytes);
742
+ const data = base64Encoder.encode(base64EncodedBytes);
496
743
  const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
497
- return umiSerializers.base58.deserialize(nonceValueBytes)[0];
744
+ return base58Decoder.decode(nonceValueBytes);
498
745
  }
499
746
  const nonceAccountDidAdvancePromise = (async () => {
500
747
  for await (const accountNotification of accountNotifications) {
@@ -536,97 +783,48 @@ function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
536
783
  }
537
784
  };
538
785
  }
539
- function createSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
540
- return async function getSignatureConfirmationPromise({ abortSignal: callerAbortSignal, commitment, signature }) {
541
- const abortController = new AbortController();
542
- function handleAbort() {
543
- abortController.abort();
544
- }
545
- callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
546
- const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature, { commitment }).subscribe({ abortSignal: abortController.signal });
547
- const signatureDidCommitPromise = (async () => {
548
- for await (const signatureStatusNotification of signatureStatusNotifications) {
549
- if (signatureStatusNotification.value.err) {
550
- throw new Error(`The transaction with signature \`${signature}\` failed.`, {
551
- cause: signatureStatusNotification.value.err
552
- });
553
- } else {
554
- return;
555
- }
556
- }
557
- })();
558
- const signatureStatusLookupPromise = (async () => {
559
- const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature]).send({ abortSignal: abortController.signal });
560
- const signatureStatus = signatureStatusResults[0];
561
- if (signatureStatus && signatureStatus.confirmationStatus && rpcCore.commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
562
- return;
563
- } else {
564
- await new Promise(() => {
565
- });
566
- }
567
- })();
568
- try {
569
- return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
570
- } finally {
571
- abortController.abort();
572
- }
573
- };
574
- }
575
786
 
576
787
  // src/transaction-confirmation.ts
577
- async function raceStrategies(config, getSpecificStrategiesForRace) {
578
- const { abortSignal: callerAbortSignal, commitment, getSignatureConfirmationPromise, transaction } = config;
579
- callerAbortSignal.throwIfAborted();
580
- const signature = transactions.getSignatureFromTransaction(transaction);
581
- const abortController = new AbortController();
582
- function handleAbort() {
583
- abortController.abort();
584
- }
585
- callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
586
- try {
587
- const specificStrategies = getSpecificStrategiesForRace({
588
- ...config,
589
- abortSignal: abortController.signal
590
- });
591
- return await Promise.race([
592
- getSignatureConfirmationPromise({
593
- abortSignal: abortController.signal,
594
- commitment,
595
- signature
596
- }),
597
- ...specificStrategies
598
- ]);
599
- } finally {
600
- abortController.abort();
601
- }
602
- }
603
788
  function createDefaultDurableNonceTransactionConfirmer({
604
789
  rpc,
605
790
  rpcSubscriptions
606
791
  }) {
607
792
  const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
608
- const getSignatureConfirmationPromise = createSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions);
609
- return async function confirmTransaction(config) {
793
+ const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
794
+ rpc,
795
+ rpcSubscriptions
796
+ );
797
+ return async function confirmDurableNonceTransaction(config) {
610
798
  await waitForDurableNonceTransactionConfirmation({
611
799
  ...config,
612
800
  getNonceInvalidationPromise,
613
- getSignatureConfirmationPromise
801
+ getRecentSignatureConfirmationPromise
614
802
  });
615
803
  };
616
804
  }
617
- function createDefaultTransactionConfirmer({ rpc, rpcSubscriptions }) {
618
- const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory(rpcSubscriptions);
619
- const getSignatureConfirmationPromise = createSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions);
620
- return async function confirmTransaction(config) {
621
- await waitForTransactionConfirmation({
805
+ function createDefaultRecentTransactionConfirmer({
806
+ rpc,
807
+ rpcSubscriptions
808
+ }) {
809
+ const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory({
810
+ rpc,
811
+ rpcSubscriptions
812
+ });
813
+ const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
814
+ rpc,
815
+ rpcSubscriptions
816
+ );
817
+ return async function confirmRecentTransaction(config) {
818
+ await waitForRecentTransactionConfirmation({
622
819
  ...config,
623
820
  getBlockHeightExceedencePromise,
624
- getSignatureConfirmationPromise
821
+ getRecentSignatureConfirmationPromise
625
822
  });
626
823
  };
627
824
  }
628
825
  async function waitForDurableNonceTransactionConfirmation(config) {
629
826
  await raceStrategies(
827
+ transactions.getSignatureFromTransaction(config.transaction),
630
828
  config,
631
829
  function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
632
830
  return [
@@ -640,13 +838,20 @@ async function waitForDurableNonceTransactionConfirmation(config) {
640
838
  }
641
839
  );
642
840
  }
643
- async function waitForTransactionConfirmation(config) {
841
+ async function waitForRecentTransactionConfirmation(config) {
644
842
  await raceStrategies(
843
+ transactions.getSignatureFromTransaction(config.transaction),
645
844
  config,
646
- function getSpecificStrategiesForRace({ abortSignal, getBlockHeightExceedencePromise, transaction }) {
845
+ function getSpecificStrategiesForRace({
846
+ abortSignal,
847
+ commitment,
848
+ getBlockHeightExceedencePromise,
849
+ transaction
850
+ }) {
647
851
  return [
648
852
  getBlockHeightExceedencePromise({
649
853
  abortSignal,
854
+ commitment,
650
855
  lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
651
856
  })
652
857
  ];
@@ -654,24 +859,163 @@ async function waitForTransactionConfirmation(config) {
654
859
  );
655
860
  }
656
861
 
862
+ // src/send-transaction.ts
863
+ function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, config) {
864
+ if (
865
+ // The developer has supplied no value for `preflightCommitment`.
866
+ !config?.preflightCommitment && // The value of `commitment` is lower than the server default of `preflightCommitment`.
867
+ rpcTypes.commitmentComparator(
868
+ commitment,
869
+ "finalized"
870
+ /* default value of `preflightCommitment` */
871
+ ) < 0
872
+ ) {
873
+ return {
874
+ ...config,
875
+ // In the common case, it is unlikely that you want to simulate a transaction at
876
+ // `finalized` commitment when your standard of commitment for confirming the
877
+ // transaction is lower. Cap the simulation commitment level to the level of the
878
+ // confirmation commitment.
879
+ preflightCommitment: commitment
880
+ };
881
+ }
882
+ return config;
883
+ }
884
+ async function sendTransaction_INTERNAL({
885
+ abortSignal,
886
+ commitment,
887
+ rpc,
888
+ transaction,
889
+ ...sendTransactionConfig
890
+ }) {
891
+ const base64EncodedWireTransaction = transactions.getBase64EncodedWireTransaction(transaction);
892
+ return await rpc.sendTransaction(base64EncodedWireTransaction, {
893
+ ...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),
894
+ encoding: "base64"
895
+ }).send({ abortSignal });
896
+ }
897
+ function createDefaultDurableNonceTransactionSender({
898
+ rpc,
899
+ rpcSubscriptions
900
+ }) {
901
+ const confirmDurableNonceTransaction = createDefaultDurableNonceTransactionConfirmer({
902
+ rpc,
903
+ rpcSubscriptions
904
+ });
905
+ return async function sendDurableNonceTransaction(transaction, config) {
906
+ await sendAndConfirmDurableNonceTransaction({
907
+ ...config,
908
+ confirmDurableNonceTransaction,
909
+ rpc,
910
+ transaction
911
+ });
912
+ };
913
+ }
914
+ function createDefaultTransactionSender({
915
+ rpc,
916
+ rpcSubscriptions
917
+ }) {
918
+ const confirmRecentTransaction = createDefaultRecentTransactionConfirmer({
919
+ rpc,
920
+ rpcSubscriptions
921
+ });
922
+ return async function sendTransaction(transaction, config) {
923
+ await sendAndConfirmTransaction({
924
+ ...config,
925
+ confirmRecentTransaction,
926
+ rpc,
927
+ transaction
928
+ });
929
+ };
930
+ }
931
+ async function sendAndConfirmDurableNonceTransaction({
932
+ abortSignal,
933
+ commitment,
934
+ confirmDurableNonceTransaction,
935
+ rpc,
936
+ transaction,
937
+ ...sendTransactionConfig
938
+ }) {
939
+ const transactionSignature = await sendTransaction_INTERNAL({
940
+ ...sendTransactionConfig,
941
+ abortSignal,
942
+ commitment,
943
+ rpc,
944
+ transaction
945
+ });
946
+ await confirmDurableNonceTransaction({
947
+ abortSignal,
948
+ commitment,
949
+ transaction
950
+ });
951
+ return transactionSignature;
952
+ }
953
+ async function sendAndConfirmTransaction({
954
+ abortSignal,
955
+ commitment,
956
+ confirmRecentTransaction,
957
+ rpc,
958
+ transaction,
959
+ ...sendTransactionConfig
960
+ }) {
961
+ const transactionSignature = await sendTransaction_INTERNAL({
962
+ ...sendTransactionConfig,
963
+ abortSignal,
964
+ commitment,
965
+ rpc,
966
+ transaction
967
+ });
968
+ await confirmRecentTransaction({
969
+ abortSignal,
970
+ commitment,
971
+ transaction
972
+ });
973
+ return transactionSignature;
974
+ }
975
+
657
976
  exports.createBlockHeightExceedencePromiseFactory = createBlockHeightExceedencePromiseFactory;
977
+ exports.createDefaultAirdropRequester = createDefaultAirdropRequester;
658
978
  exports.createDefaultDurableNonceTransactionConfirmer = createDefaultDurableNonceTransactionConfirmer;
979
+ exports.createDefaultDurableNonceTransactionSender = createDefaultDurableNonceTransactionSender;
980
+ exports.createDefaultRecentTransactionConfirmer = createDefaultRecentTransactionConfirmer;
659
981
  exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
660
982
  exports.createDefaultRpcTransport = createDefaultRpcTransport;
661
- exports.createDefaultTransactionConfirmer = createDefaultTransactionConfirmer;
983
+ exports.createDefaultTransactionSender = createDefaultTransactionSender;
662
984
  exports.createNonceInvalidationPromiseFactory = createNonceInvalidationPromiseFactory;
663
- exports.createSignatureConfirmationPromiseFactory = createSignatureConfirmationPromiseFactory;
985
+ exports.createRecentSignatureConfirmationPromiseFactory = createRecentSignatureConfirmationPromiseFactory;
664
986
  exports.createSolanaRpc = createSolanaRpc;
665
987
  exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
666
988
  exports.createSolanaRpcSubscriptions_UNSTABLE = createSolanaRpcSubscriptions_UNSTABLE;
989
+ exports.decodeTransaction = decodeTransaction;
990
+ exports.requestAndConfirmAirdrop = requestAndConfirmAirdrop;
991
+ exports.sendAndConfirmDurableNonceTransaction = sendAndConfirmDurableNonceTransaction;
992
+ exports.sendAndConfirmTransaction = sendAndConfirmTransaction;
667
993
  exports.waitForDurableNonceTransactionConfirmation = waitForDurableNonceTransactionConfirmation;
668
- exports.waitForTransactionConfirmation = waitForTransactionConfirmation;
994
+ exports.waitForRecentTransactionConfirmation = waitForRecentTransactionConfirmation;
995
+ Object.keys(accounts).forEach(function (k) {
996
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
997
+ enumerable: true,
998
+ get: function () { return accounts[k]; }
999
+ });
1000
+ });
669
1001
  Object.keys(addresses).forEach(function (k) {
670
1002
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
671
1003
  enumerable: true,
672
1004
  get: function () { return addresses[k]; }
673
1005
  });
674
1006
  });
1007
+ Object.keys(codecs).forEach(function (k) {
1008
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1009
+ enumerable: true,
1010
+ get: function () { return codecs[k]; }
1011
+ });
1012
+ });
1013
+ Object.keys(functional).forEach(function (k) {
1014
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1015
+ enumerable: true,
1016
+ get: function () { return functional[k]; }
1017
+ });
1018
+ });
675
1019
  Object.keys(instructions).forEach(function (k) {
676
1020
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
677
1021
  enumerable: true,
@@ -684,6 +1028,30 @@ Object.keys(keys).forEach(function (k) {
684
1028
  get: function () { return keys[k]; }
685
1029
  });
686
1030
  });
1031
+ Object.keys(programs).forEach(function (k) {
1032
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1033
+ enumerable: true,
1034
+ get: function () { return programs[k]; }
1035
+ });
1036
+ });
1037
+ Object.keys(rpcParsedTypes).forEach(function (k) {
1038
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1039
+ enumerable: true,
1040
+ get: function () { return rpcParsedTypes[k]; }
1041
+ });
1042
+ });
1043
+ Object.keys(rpcTypes).forEach(function (k) {
1044
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1045
+ enumerable: true,
1046
+ get: function () { return rpcTypes[k]; }
1047
+ });
1048
+ });
1049
+ Object.keys(signers).forEach(function (k) {
1050
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1051
+ enumerable: true,
1052
+ get: function () { return signers[k]; }
1053
+ });
1054
+ });
687
1055
  Object.keys(transactions).forEach(function (k) {
688
1056
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
689
1057
  enumerable: true,