@solana/web3.js 2.0.0-experimental.06517d7 → 2.0.0-experimental.07c30c1

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 (62) hide show
  1. package/dist/index.browser.cjs +114 -855
  2. package/dist/index.browser.cjs.map +1 -1
  3. package/dist/index.browser.js +97 -834
  4. package/dist/index.browser.js.map +1 -1
  5. package/dist/index.development.js +3900 -3182
  6. package/dist/index.development.js.map +1 -1
  7. package/dist/index.native.js +97 -823
  8. package/dist/index.native.js.map +1 -1
  9. package/dist/index.node.cjs +114 -844
  10. package/dist/index.node.cjs.map +1 -1
  11. package/dist/index.node.js +97 -823
  12. package/dist/index.node.js.map +1 -1
  13. package/dist/index.production.min.js +278 -277
  14. package/dist/types/airdrop-internal.d.ts +16 -0
  15. package/dist/types/airdrop-internal.d.ts.map +1 -0
  16. package/dist/types/airdrop.d.ts +7 -16
  17. package/dist/types/airdrop.d.ts.map +1 -1
  18. package/dist/types/decode-transaction.d.ts +1 -2
  19. package/dist/types/decode-transaction.d.ts.map +1 -1
  20. package/dist/types/index.d.ts +2 -7
  21. package/dist/types/index.d.ts.map +1 -1
  22. package/dist/types/send-transaction-internal.d.ts +27 -0
  23. package/dist/types/send-transaction-internal.d.ts.map +1 -0
  24. package/dist/types/send-transaction.d.ts +16 -30
  25. package/dist/types/send-transaction.d.ts.map +1 -1
  26. package/package.json +24 -45
  27. package/dist/types/airdrop-confirmer.d.ts +0 -19
  28. package/dist/types/airdrop-confirmer.d.ts.map +0 -1
  29. package/dist/types/cached-abortable-iterable.d.ts +0 -11
  30. package/dist/types/cached-abortable-iterable.d.ts.map +0 -1
  31. package/dist/types/rpc-default-config.d.ts +0 -3
  32. package/dist/types/rpc-default-config.d.ts.map +0 -1
  33. package/dist/types/rpc-integer-overflow-error.d.ts +0 -4
  34. package/dist/types/rpc-integer-overflow-error.d.ts.map +0 -1
  35. package/dist/types/rpc-request-coalescer.d.ts +0 -5
  36. package/dist/types/rpc-request-coalescer.d.ts.map +0 -1
  37. package/dist/types/rpc-request-deduplication.d.ts +0 -2
  38. package/dist/types/rpc-request-deduplication.d.ts.map +0 -1
  39. package/dist/types/rpc-subscription-coalescer.d.ts +0 -10
  40. package/dist/types/rpc-subscription-coalescer.d.ts.map +0 -1
  41. package/dist/types/rpc-transport.d.ts +0 -9
  42. package/dist/types/rpc-transport.d.ts.map +0 -1
  43. package/dist/types/rpc-websocket-autopinger.d.ts +0 -8
  44. package/dist/types/rpc-websocket-autopinger.d.ts.map +0 -1
  45. package/dist/types/rpc-websocket-connection-sharding.d.ts +0 -13
  46. package/dist/types/rpc-websocket-connection-sharding.d.ts.map +0 -1
  47. package/dist/types/rpc-websocket-transport.d.ts +0 -16
  48. package/dist/types/rpc-websocket-transport.d.ts.map +0 -1
  49. package/dist/types/rpc.d.ts +0 -13
  50. package/dist/types/rpc.d.ts.map +0 -1
  51. package/dist/types/transaction-confirmation-strategy-blockheight.d.ts +0 -14
  52. package/dist/types/transaction-confirmation-strategy-blockheight.d.ts.map +0 -1
  53. package/dist/types/transaction-confirmation-strategy-nonce.d.ts +0 -13
  54. package/dist/types/transaction-confirmation-strategy-nonce.d.ts.map +0 -1
  55. package/dist/types/transaction-confirmation-strategy-racer.d.ts +0 -14
  56. package/dist/types/transaction-confirmation-strategy-racer.d.ts.map +0 -1
  57. package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts +0 -11
  58. package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts.map +0 -1
  59. package/dist/types/transaction-confirmation-strategy-timeout.d.ts +0 -8
  60. package/dist/types/transaction-confirmation-strategy-timeout.d.ts.map +0 -1
  61. package/dist/types/transaction-confirmation.d.ts +0 -32
  62. package/dist/types/transaction-confirmation.d.ts.map +0 -1
@@ -7,176 +7,55 @@ var functional = require('@solana/functional');
7
7
  var instructions = require('@solana/instructions');
8
8
  var keys = require('@solana/keys');
9
9
  var programs = require('@solana/programs');
10
+ var rpc = require('@solana/rpc');
10
11
  var rpcParsedTypes = require('@solana/rpc-parsed-types');
12
+ var rpcSubscriptions = require('@solana/rpc-subscriptions');
11
13
  var rpcTypes = require('@solana/rpc-types');
12
14
  var signers = require('@solana/signers');
13
15
  var transactions = require('@solana/transactions');
14
- var rpcCore = require('@solana/rpc-core');
15
- var rpcTransport = require('@solana/rpc-transport');
16
- var fastStableStringify = require('fast-stable-stringify');
17
- var errors = require('@solana/errors');
16
+ var transactionConfirmation = require('@solana/transaction-confirmation');
18
17
 
19
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
18
+ // src/index.ts
20
19
 
21
- var fastStableStringify__default = /*#__PURE__*/_interopDefault(fastStableStringify);
22
-
23
- // ../build-scripts/env-shim.ts
24
- var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
25
-
26
- // src/transaction-confirmation-strategy-racer.ts
27
- async function raceStrategies(signature, config, getSpecificStrategiesForRace) {
28
- const { abortSignal: callerAbortSignal, commitment, getRecentSignatureConfirmationPromise } = config;
29
- callerAbortSignal?.throwIfAborted();
30
- const abortController = new AbortController();
31
- if (callerAbortSignal) {
32
- const handleAbort = () => {
33
- abortController.abort();
34
- };
35
- callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
36
- }
37
- try {
38
- const specificStrategies = getSpecificStrategiesForRace({
39
- ...config,
40
- abortSignal: abortController.signal
41
- });
42
- return await Promise.race([
43
- getRecentSignatureConfirmationPromise({
44
- abortSignal: abortController.signal,
45
- commitment,
46
- signature
47
- }),
48
- ...specificStrategies
49
- ]);
50
- } finally {
51
- abortController.abort();
52
- }
53
- }
54
- function createRecentSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
55
- return async function getRecentSignatureConfirmationPromise({
56
- abortSignal: callerAbortSignal,
20
+ // src/airdrop-internal.ts
21
+ async function requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({
22
+ abortSignal,
23
+ commitment,
24
+ confirmSignatureOnlyTransaction,
25
+ lamports,
26
+ recipientAddress,
27
+ rpc
28
+ }) {
29
+ const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports, { commitment }).send({ abortSignal });
30
+ await confirmSignatureOnlyTransaction({
31
+ abortSignal,
57
32
  commitment,
58
- signature
59
- }) {
60
- const abortController = new AbortController();
61
- function handleAbort() {
62
- abortController.abort();
63
- }
64
- callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
65
- const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature, { commitment }).subscribe({ abortSignal: abortController.signal });
66
- const signatureDidCommitPromise = (async () => {
67
- for await (const signatureStatusNotification of signatureStatusNotifications) {
68
- if (signatureStatusNotification.value.err) {
69
- throw new Error(`The transaction with signature \`${signature}\` failed.`, {
70
- cause: signatureStatusNotification.value.err
71
- });
72
- } else {
73
- return;
74
- }
75
- }
76
- })();
77
- const signatureStatusLookupPromise = (async () => {
78
- const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature]).send({ abortSignal: abortController.signal });
79
- const signatureStatus = signatureStatusResults[0];
80
- if (signatureStatus && signatureStatus.confirmationStatus && rpcTypes.commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
81
- return;
82
- } else {
83
- await new Promise(() => {
84
- });
85
- }
86
- })();
87
- try {
88
- return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
89
- } finally {
90
- abortController.abort();
91
- }
92
- };
93
- }
94
-
95
- // src/transaction-confirmation-strategy-timeout.ts
96
- async function getTimeoutPromise({ abortSignal: callerAbortSignal, commitment }) {
97
- return await new Promise((_, reject) => {
98
- const handleAbort = (e) => {
99
- clearTimeout(timeoutId);
100
- const abortError = new DOMException(e.target.reason, "AbortError");
101
- reject(abortError);
102
- };
103
- callerAbortSignal.addEventListener("abort", handleAbort);
104
- const timeoutMs = commitment === "processed" ? 3e4 : 6e4;
105
- const startMs = performance.now();
106
- const timeoutId = (
107
- // We use `setTimeout` instead of `AbortSignal.timeout()` because we want to measure
108
- // elapsed time instead of active time.
109
- // See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static
110
- setTimeout(() => {
111
- const elapsedMs = performance.now() - startMs;
112
- reject(new DOMException(`Timeout elapsed after ${elapsedMs} ms`, "TimeoutError"));
113
- }, timeoutMs)
114
- );
33
+ signature: airdropTransactionSignature
115
34
  });
35
+ return airdropTransactionSignature;
116
36
  }
117
37
 
118
- // src/airdrop-confirmer.ts
119
- function createDefaultSignatureOnlyRecentTransactionConfirmer({
120
- rpc,
121
- rpcSubscriptions
122
- }) {
123
- const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
38
+ // src/airdrop.ts
39
+ function airdropFactory({ rpc, rpcSubscriptions }) {
40
+ const getRecentSignatureConfirmationPromise = transactionConfirmation.createRecentSignatureConfirmationPromiseFactory(
124
41
  rpc,
125
42
  rpcSubscriptions
126
43
  );
127
- return async function confirmSignatureOnlyRecentTransaction(config) {
128
- await waitForRecentTransactionConfirmationUntilTimeout({
44
+ async function confirmSignatureOnlyTransaction(config) {
45
+ await transactionConfirmation.waitForRecentTransactionConfirmationUntilTimeout({
129
46
  ...config,
130
47
  getRecentSignatureConfirmationPromise,
131
- getTimeoutPromise
48
+ getTimeoutPromise: transactionConfirmation.getTimeoutPromise
132
49
  });
133
- };
134
- }
135
- async function waitForRecentTransactionConfirmationUntilTimeout(config) {
136
- await raceStrategies(
137
- config.signature,
138
- config,
139
- function getSpecificStrategiesForRace({ abortSignal, commitment, getTimeoutPromise: getTimeoutPromise2 }) {
140
- return [
141
- getTimeoutPromise2({
142
- abortSignal,
143
- commitment
144
- })
145
- ];
146
- }
147
- );
148
- }
149
-
150
- // src/airdrop.ts
151
- function createDefaultAirdropRequester({ rpc, rpcSubscriptions }) {
152
- const confirmSignatureOnlyTransaction = createDefaultSignatureOnlyRecentTransactionConfirmer({
153
- rpc,
154
- rpcSubscriptions
155
- });
156
- return async function requestAirdrop(config) {
157
- return await requestAndConfirmAirdrop({
50
+ }
51
+ return async function airdrop(config) {
52
+ return await requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({
158
53
  ...config,
159
54
  confirmSignatureOnlyTransaction,
160
55
  rpc
161
56
  });
162
57
  };
163
58
  }
164
- async function requestAndConfirmAirdrop({
165
- abortSignal,
166
- commitment,
167
- confirmSignatureOnlyTransaction,
168
- lamports,
169
- recipientAddress,
170
- rpc
171
- }) {
172
- const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports, { commitment }).send({ abortSignal });
173
- await confirmSignatureOnlyTransaction({
174
- abortSignal,
175
- commitment,
176
- signature: airdropTransactionSignature
177
- });
178
- return airdropTransactionSignature;
179
- }
180
59
  var compiledTransactionDecoder = void 0;
181
60
  async function fetchLookupTables(lookupTableAddresses, rpc, config) {
182
61
  const fetchedLookupTables = await accounts.fetchJsonParsedAccounts(
@@ -207,645 +86,6 @@ async function decodeTransaction(encodedTransaction, rpc, config) {
207
86
  lastValidBlockHeight
208
87
  });
209
88
  }
210
- function createSolanaJsonRpcIntegerOverflowError(methodName, keyPath, value) {
211
- let argumentLabel = "";
212
- if (typeof keyPath[0] === "number") {
213
- const argPosition = keyPath[0] + 1;
214
- const lastDigit = argPosition % 10;
215
- const lastTwoDigits = argPosition % 100;
216
- if (lastDigit == 1 && lastTwoDigits != 11) {
217
- argumentLabel = argPosition + "st";
218
- } else if (lastDigit == 2 && lastTwoDigits != 12) {
219
- argumentLabel = argPosition + "nd";
220
- } else if (lastDigit == 3 && lastTwoDigits != 13) {
221
- argumentLabel = argPosition + "rd";
222
- } else {
223
- argumentLabel = argPosition + "th";
224
- }
225
- } else {
226
- argumentLabel = `\`${keyPath[0].toString()}\``;
227
- }
228
- const path = keyPath.length > 1 ? keyPath.slice(1).map((pathPart) => typeof pathPart === "number" ? `[${pathPart}]` : pathPart).join(".") : void 0;
229
- const error = new errors.SolanaError(errors.SOLANA_ERROR__RPC_INTEGER_OVERFLOW, {
230
- argumentLabel,
231
- keyPath,
232
- methodName,
233
- optionalPathLabel: path ? ` at path \`${path}\`` : "",
234
- value,
235
- ...path !== void 0 ? { path } : void 0
236
- });
237
- if ("captureStackTrace" in Error && typeof Error.captureStackTrace === "function") {
238
- Error.captureStackTrace(error, createSolanaJsonRpcIntegerOverflowError);
239
- }
240
- return error;
241
- }
242
-
243
- // src/rpc-default-config.ts
244
- var DEFAULT_RPC_CONFIG = {
245
- defaultCommitment: "confirmed",
246
- onIntegerOverflow(methodName, keyPath, value) {
247
- throw createSolanaJsonRpcIntegerOverflowError(methodName, keyPath, value);
248
- }
249
- };
250
-
251
- // src/cached-abortable-iterable.ts
252
- function registerIterableCleanup(iterable, cleanupFn) {
253
- (async () => {
254
- try {
255
- for await (const _ of iterable)
256
- ;
257
- } catch {
258
- } finally {
259
- cleanupFn();
260
- }
261
- })();
262
- }
263
- function getCachedAbortableIterableFactory({
264
- getAbortSignalFromInputArgs,
265
- getCacheEntryMissingError,
266
- getCacheKeyFromInputArgs,
267
- onCacheHit,
268
- onCreateIterable
269
- }) {
270
- const cache = /* @__PURE__ */ new Map();
271
- function getCacheEntryOrThrow(cacheKey) {
272
- const currentCacheEntry = cache.get(cacheKey);
273
- if (!currentCacheEntry) {
274
- throw getCacheEntryMissingError(cacheKey);
275
- }
276
- return currentCacheEntry;
277
- }
278
- return async (...args) => {
279
- const cacheKey = getCacheKeyFromInputArgs(...args);
280
- const signal = getAbortSignalFromInputArgs(...args);
281
- if (cacheKey === void 0) {
282
- return await onCreateIterable(signal, ...args);
283
- }
284
- const cleanup = () => {
285
- cache.delete(cacheKey);
286
- signal.removeEventListener("abort", handleAbort);
287
- };
288
- const handleAbort = () => {
289
- const cacheEntry = getCacheEntryOrThrow(cacheKey);
290
- if (cacheEntry.purgeScheduled !== true) {
291
- cacheEntry.purgeScheduled = true;
292
- globalThis.queueMicrotask(() => {
293
- cacheEntry.purgeScheduled = false;
294
- if (cacheEntry.referenceCount === 0) {
295
- cacheEntry.abortController.abort();
296
- cleanup();
297
- }
298
- });
299
- }
300
- cacheEntry.referenceCount--;
301
- };
302
- signal.addEventListener("abort", handleAbort);
303
- try {
304
- const cacheEntry = cache.get(cacheKey);
305
- if (!cacheEntry) {
306
- const singletonAbortController = new AbortController();
307
- const newIterablePromise = onCreateIterable(singletonAbortController.signal, ...args);
308
- const newCacheEntry = {
309
- abortController: singletonAbortController,
310
- iterable: newIterablePromise,
311
- purgeScheduled: false,
312
- referenceCount: 1
313
- };
314
- cache.set(cacheKey, newCacheEntry);
315
- const newIterable = await newIterablePromise;
316
- registerIterableCleanup(newIterable, cleanup);
317
- newCacheEntry.iterable = newIterable;
318
- return newIterable;
319
- } else {
320
- cacheEntry.referenceCount++;
321
- const iterableOrIterablePromise = cacheEntry.iterable;
322
- const cachedIterable = "then" in iterableOrIterablePromise ? await iterableOrIterablePromise : iterableOrIterablePromise;
323
- await onCacheHit(cachedIterable, ...args);
324
- return cachedIterable;
325
- }
326
- } catch (e) {
327
- cleanup();
328
- throw e;
329
- }
330
- };
331
- }
332
-
333
- // src/rpc-subscription-coalescer.ts
334
- var EXPLICIT_ABORT_TOKEN = Symbol(
335
- __DEV__ ? "This symbol is thrown from a subscription's iterator when the subscription is explicitly aborted by the user" : void 0
336
- );
337
- function registerIterableCleanup2(iterable, cleanupFn) {
338
- (async () => {
339
- try {
340
- for await (const _ of iterable)
341
- ;
342
- } catch {
343
- } finally {
344
- cleanupFn();
345
- }
346
- })();
347
- }
348
- function getRpcSubscriptionsWithSubscriptionCoalescing({
349
- getDeduplicationKey,
350
- rpcSubscriptions
351
- }) {
352
- const cache = /* @__PURE__ */ new Map();
353
- return new Proxy(rpcSubscriptions, {
354
- defineProperty() {
355
- return false;
356
- },
357
- deleteProperty() {
358
- return false;
359
- },
360
- get(target, p, receiver) {
361
- const subscriptionMethod = Reflect.get(target, p, receiver);
362
- if (typeof subscriptionMethod !== "function") {
363
- return subscriptionMethod;
364
- }
365
- return function(...rawParams) {
366
- const deduplicationKey = getDeduplicationKey(p, rawParams);
367
- if (deduplicationKey === void 0) {
368
- return subscriptionMethod(...rawParams);
369
- }
370
- if (cache.has(deduplicationKey)) {
371
- return cache.get(deduplicationKey);
372
- }
373
- const iterableFactory = getCachedAbortableIterableFactory({
374
- getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
375
- getCacheEntryMissingError(deduplicationKey2) {
376
- return new Error(
377
- `Found no cache entry for subscription with deduplication key \`${deduplicationKey2?.toString()}\``
378
- );
379
- },
380
- getCacheKeyFromInputArgs: () => deduplicationKey,
381
- async onCacheHit(_iterable, _config) {
382
- },
383
- async onCreateIterable(abortSignal, config) {
384
- const pendingSubscription2 = subscriptionMethod(
385
- ...rawParams
386
- );
387
- const iterable = await pendingSubscription2.subscribe({
388
- ...config,
389
- abortSignal
390
- });
391
- registerIterableCleanup2(iterable, () => {
392
- cache.delete(deduplicationKey);
393
- });
394
- return iterable;
395
- }
396
- });
397
- const pendingSubscription = {
398
- async subscribe(...args) {
399
- const iterable = await iterableFactory(...args);
400
- const { abortSignal } = args[0];
401
- let abortPromise;
402
- return {
403
- ...iterable,
404
- async *[Symbol.asyncIterator]() {
405
- abortPromise ||= abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN) : new Promise((_, reject) => {
406
- abortSignal.addEventListener("abort", () => {
407
- reject(EXPLICIT_ABORT_TOKEN);
408
- });
409
- });
410
- try {
411
- const iterator = iterable[Symbol.asyncIterator]();
412
- while (true) {
413
- const iteratorResult = await Promise.race([iterator.next(), abortPromise]);
414
- if (iteratorResult.done) {
415
- return;
416
- } else {
417
- yield iteratorResult.value;
418
- }
419
- }
420
- } catch (e) {
421
- if (e === EXPLICIT_ABORT_TOKEN) {
422
- return;
423
- }
424
- cache.delete(deduplicationKey);
425
- throw e;
426
- }
427
- }
428
- };
429
- }
430
- };
431
- cache.set(deduplicationKey, pendingSubscription);
432
- return pendingSubscription;
433
- };
434
- }
435
- });
436
- }
437
-
438
- // src/rpc.ts
439
- function createSolanaRpc(config) {
440
- const api = rpcCore.createSolanaRpcApi(DEFAULT_RPC_CONFIG);
441
- return rpcTransport.createJsonRpc({
442
- ...config,
443
- api
444
- });
445
- }
446
- function createSolanaRpcSubscriptions(config) {
447
- return functional.pipe(
448
- rpcTransport.createJsonSubscriptionRpc({
449
- ...config,
450
- api: rpcCore.createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
451
- }),
452
- (rpcSubscriptions) => getRpcSubscriptionsWithSubscriptionCoalescing({
453
- getDeduplicationKey: (...args) => fastStableStringify__default.default(args),
454
- rpcSubscriptions
455
- })
456
- );
457
- }
458
- function createSolanaRpcSubscriptions_UNSTABLE(config) {
459
- return rpcTransport.createJsonSubscriptionRpc({
460
- ...config,
461
- api: rpcCore.createSolanaRpcSubscriptionsApi_UNSTABLE(DEFAULT_RPC_CONFIG)
462
- });
463
- }
464
-
465
- // src/rpc-request-coalescer.ts
466
- function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
467
- let coalescedRequestsByDeduplicationKey;
468
- return async function makeCoalescedHttpRequest(config) {
469
- const { payload, signal } = config;
470
- const deduplicationKey = getDeduplicationKey(payload);
471
- if (deduplicationKey === void 0) {
472
- return await transport(config);
473
- }
474
- if (!coalescedRequestsByDeduplicationKey) {
475
- Promise.resolve().then(() => {
476
- coalescedRequestsByDeduplicationKey = void 0;
477
- });
478
- coalescedRequestsByDeduplicationKey = {};
479
- }
480
- if (coalescedRequestsByDeduplicationKey[deduplicationKey] == null) {
481
- const abortController = new AbortController();
482
- const responsePromise = (async () => {
483
- try {
484
- return await transport({
485
- ...config,
486
- signal: abortController.signal
487
- });
488
- } catch (e) {
489
- if (e && typeof e === "object" && "name" in e && e.name === "AbortError") {
490
- return;
491
- }
492
- throw e;
493
- }
494
- })();
495
- coalescedRequestsByDeduplicationKey[deduplicationKey] = {
496
- abortController,
497
- numConsumers: 0,
498
- responsePromise
499
- };
500
- }
501
- const coalescedRequest = coalescedRequestsByDeduplicationKey[deduplicationKey];
502
- coalescedRequest.numConsumers++;
503
- if (signal) {
504
- const responsePromise = coalescedRequest.responsePromise;
505
- return await new Promise((resolve, reject) => {
506
- const handleAbort = (e) => {
507
- signal.removeEventListener("abort", handleAbort);
508
- coalescedRequest.numConsumers -= 1;
509
- if (coalescedRequest.numConsumers === 0) {
510
- const abortController = coalescedRequest.abortController;
511
- abortController.abort();
512
- }
513
- const abortError = new DOMException(e.target.reason, "AbortError");
514
- reject(abortError);
515
- };
516
- signal.addEventListener("abort", handleAbort);
517
- responsePromise.then(resolve).finally(() => {
518
- signal.removeEventListener("abort", handleAbort);
519
- });
520
- });
521
- } else {
522
- return await coalescedRequest.responsePromise;
523
- }
524
- };
525
- }
526
- function isJsonRpcPayload(payload) {
527
- if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
528
- return false;
529
- }
530
- return "jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && typeof payload.method === "string" && "params" in payload;
531
- }
532
- function getSolanaRpcPayloadDeduplicationKey(payload) {
533
- return isJsonRpcPayload(payload) ? fastStableStringify__default.default([payload.method, payload.params]) : void 0;
534
- }
535
-
536
- // src/rpc-transport.ts
537
- function normalizeHeaders(headers) {
538
- const out = {};
539
- for (const headerName in headers) {
540
- out[headerName.toLowerCase()] = headers[headerName];
541
- }
542
- return out;
543
- }
544
- function createDefaultRpcTransport(config) {
545
- return functional.pipe(
546
- rpcTransport.createHttpTransport({
547
- ...config,
548
- headers: {
549
- ...config.headers ? normalizeHeaders(config.headers) : void 0,
550
- ...{
551
- // Keep these headers lowercase so they will override any user-supplied headers above.
552
- "solana-client": `js/${"2.0.0-development"}` ?? "UNKNOWN"
553
- }
554
- }
555
- }),
556
- (transport) => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
557
- );
558
- }
559
-
560
- // src/rpc-websocket-autopinger.ts
561
- var PING_PAYLOAD = {
562
- jsonrpc: "2.0",
563
- method: "ping"
564
- };
565
- function getWebSocketTransportWithAutoping({
566
- intervalMs,
567
- transport
568
- }) {
569
- const pingableConnections = /* @__PURE__ */ new Map();
570
- return async (...args) => {
571
- const connection = await transport(...args);
572
- let intervalId;
573
- function sendPing() {
574
- connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
575
- }
576
- function restartPingTimer() {
577
- clearInterval(intervalId);
578
- intervalId = setInterval(sendPing, intervalMs);
579
- }
580
- if (pingableConnections.has(connection) === false) {
581
- pingableConnections.set(connection, {
582
- [Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
583
- send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: (...args2) => {
584
- restartPingTimer();
585
- return connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(...args2);
586
- }
587
- });
588
- (async () => {
589
- try {
590
- for await (const _ of connection) {
591
- restartPingTimer();
592
- }
593
- } catch {
594
- } finally {
595
- pingableConnections.delete(connection);
596
- clearInterval(intervalId);
597
- if (handleOffline) {
598
- globalThis.window.removeEventListener("offline", handleOffline);
599
- }
600
- if (handleOnline) {
601
- globalThis.window.removeEventListener("online", handleOnline);
602
- }
603
- }
604
- })();
605
- {
606
- restartPingTimer();
607
- }
608
- let handleOffline;
609
- let handleOnline;
610
- }
611
- return pingableConnections.get(connection);
612
- };
613
- }
614
-
615
- // src/rpc-websocket-connection-sharding.ts
616
- var NULL_SHARD_CACHE_KEY = Symbol(
617
- __DEV__ ? "Cache key to use when there is no connection sharding strategy" : void 0
618
- );
619
- function getWebSocketTransportWithConnectionSharding({
620
- getShard,
621
- transport
622
- }) {
623
- return getCachedAbortableIterableFactory({
624
- getAbortSignalFromInputArgs: ({ signal }) => signal,
625
- getCacheEntryMissingError(shardKey) {
626
- return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
627
- },
628
- getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
629
- onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
630
- onCreateIterable: (abortSignal, config) => transport({
631
- ...config,
632
- signal: abortSignal
633
- })
634
- });
635
- }
636
-
637
- // src/rpc-websocket-transport.ts
638
- function createDefaultRpcSubscriptionsTransport(config) {
639
- const { getShard, intervalMs, ...rest } = config;
640
- return functional.pipe(
641
- rpcTransport.createWebSocketTransport({
642
- ...rest,
643
- sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
644
- 131072
645
- }),
646
- (transport) => getWebSocketTransportWithAutoping({
647
- intervalMs: intervalMs ?? 5e3,
648
- transport
649
- }),
650
- (transport) => getWebSocketTransportWithConnectionSharding({
651
- getShard,
652
- transport
653
- })
654
- );
655
- }
656
-
657
- // src/transaction-confirmation-strategy-blockheight.ts
658
- function createBlockHeightExceedencePromiseFactory({
659
- rpc,
660
- rpcSubscriptions
661
- }) {
662
- return async function getBlockHeightExceedencePromise({
663
- abortSignal: callerAbortSignal,
664
- commitment,
665
- lastValidBlockHeight
666
- }) {
667
- const abortController = new AbortController();
668
- const handleAbort = () => {
669
- abortController.abort();
670
- };
671
- callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
672
- async function getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight() {
673
- const { absoluteSlot, blockHeight } = await rpc.getEpochInfo({ commitment }).send({ abortSignal: abortController.signal });
674
- return {
675
- blockHeight,
676
- differenceBetweenSlotHeightAndBlockHeight: absoluteSlot - blockHeight
677
- };
678
- }
679
- try {
680
- const [slotNotifications, { blockHeight, differenceBetweenSlotHeightAndBlockHeight }] = await Promise.all([
681
- rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal }),
682
- getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight()
683
- ]);
684
- if (blockHeight <= lastValidBlockHeight) {
685
- let lastKnownDifferenceBetweenSlotHeightAndBlockHeight = differenceBetweenSlotHeightAndBlockHeight;
686
- for await (const slotNotification of slotNotifications) {
687
- const { slot } = slotNotification;
688
- if (slot - lastKnownDifferenceBetweenSlotHeightAndBlockHeight > lastValidBlockHeight) {
689
- const {
690
- blockHeight: currentBlockHeight,
691
- differenceBetweenSlotHeightAndBlockHeight: currentDifferenceBetweenSlotHeightAndBlockHeight
692
- } = await getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight();
693
- if (currentBlockHeight > lastValidBlockHeight) {
694
- break;
695
- } else {
696
- lastKnownDifferenceBetweenSlotHeightAndBlockHeight = currentDifferenceBetweenSlotHeightAndBlockHeight;
697
- }
698
- }
699
- }
700
- }
701
- throw new Error(
702
- "The network has progressed past the last block for which this transaction could have been committed."
703
- );
704
- } finally {
705
- abortController.abort();
706
- }
707
- };
708
- }
709
- var NONCE_VALUE_OFFSET = 4 + // version(u32)
710
- 4 + // state(u32)
711
- 32;
712
- function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
713
- return async function getNonceInvalidationPromise({
714
- abortSignal: callerAbortSignal,
715
- commitment,
716
- currentNonceValue,
717
- nonceAccountAddress
718
- }) {
719
- const abortController = new AbortController();
720
- function handleAbort() {
721
- abortController.abort();
722
- }
723
- callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
724
- const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
725
- const base58Decoder = codecs.getBase58Decoder();
726
- const base64Encoder = codecs.getBase64Encoder();
727
- function getNonceFromAccountData([base64EncodedBytes]) {
728
- const data = base64Encoder.encode(base64EncodedBytes);
729
- const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
730
- return base58Decoder.decode(nonceValueBytes);
731
- }
732
- const nonceAccountDidAdvancePromise = (async () => {
733
- for await (const accountNotification of accountNotifications) {
734
- const nonceValue = getNonceFromAccountData(accountNotification.value.data);
735
- if (nonceValue !== currentNonceValue) {
736
- throw new Error(
737
- `The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
738
- );
739
- }
740
- }
741
- })();
742
- const nonceIsAlreadyInvalidPromise = (async () => {
743
- const { value: nonceAccount } = await rpc.getAccountInfo(nonceAccountAddress, {
744
- commitment,
745
- dataSlice: { length: 32, offset: NONCE_VALUE_OFFSET },
746
- encoding: "base58"
747
- }).send({ abortSignal: abortController.signal });
748
- if (!nonceAccount) {
749
- throw new Error(`No nonce account could be found at address \`${nonceAccountAddress}\`.`);
750
- }
751
- const nonceValue = (
752
- // This works because we asked for the exact slice of data representing the nonce
753
- // value, and furthermore asked for it in `base58` encoding.
754
- nonceAccount.data[0]
755
- );
756
- if (nonceValue !== currentNonceValue) {
757
- throw new Error(
758
- `The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
759
- );
760
- } else {
761
- await new Promise(() => {
762
- });
763
- }
764
- })();
765
- try {
766
- return await Promise.race([nonceAccountDidAdvancePromise, nonceIsAlreadyInvalidPromise]);
767
- } finally {
768
- abortController.abort();
769
- }
770
- };
771
- }
772
-
773
- // src/transaction-confirmation.ts
774
- function createDefaultDurableNonceTransactionConfirmer({
775
- rpc,
776
- rpcSubscriptions
777
- }) {
778
- const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
779
- const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
780
- rpc,
781
- rpcSubscriptions
782
- );
783
- return async function confirmDurableNonceTransaction(config) {
784
- await waitForDurableNonceTransactionConfirmation({
785
- ...config,
786
- getNonceInvalidationPromise,
787
- getRecentSignatureConfirmationPromise
788
- });
789
- };
790
- }
791
- function createDefaultRecentTransactionConfirmer({
792
- rpc,
793
- rpcSubscriptions
794
- }) {
795
- const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory({
796
- rpc,
797
- rpcSubscriptions
798
- });
799
- const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
800
- rpc,
801
- rpcSubscriptions
802
- );
803
- return async function confirmRecentTransaction(config) {
804
- await waitForRecentTransactionConfirmation({
805
- ...config,
806
- getBlockHeightExceedencePromise,
807
- getRecentSignatureConfirmationPromise
808
- });
809
- };
810
- }
811
- async function waitForDurableNonceTransactionConfirmation(config) {
812
- await raceStrategies(
813
- transactions.getSignatureFromTransaction(config.transaction),
814
- config,
815
- function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
816
- return [
817
- getNonceInvalidationPromise({
818
- abortSignal,
819
- commitment,
820
- currentNonceValue: transaction.lifetimeConstraint.nonce,
821
- nonceAccountAddress: transaction.instructions[0].accounts[0].address
822
- })
823
- ];
824
- }
825
- );
826
- }
827
- async function waitForRecentTransactionConfirmation(config) {
828
- await raceStrategies(
829
- transactions.getSignatureFromTransaction(config.transaction),
830
- config,
831
- function getSpecificStrategiesForRace({
832
- abortSignal,
833
- commitment,
834
- getBlockHeightExceedencePromise,
835
- transaction
836
- }) {
837
- return [
838
- getBlockHeightExceedencePromise({
839
- abortSignal,
840
- commitment,
841
- lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
842
- })
843
- ];
844
- }
845
- );
846
- }
847
-
848
- // src/send-transaction.ts
849
89
  function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, config) {
850
90
  if (
851
91
  // The developer has supplied no value for `preflightCommitment`.
@@ -867,7 +107,7 @@ function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, con
867
107
  }
868
108
  return config;
869
109
  }
870
- async function sendTransaction_INTERNAL({
110
+ async function sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
871
111
  abortSignal,
872
112
  commitment,
873
113
  rpc,
@@ -880,41 +120,7 @@ async function sendTransaction_INTERNAL({
880
120
  encoding: "base64"
881
121
  }).send({ abortSignal });
882
122
  }
883
- function createDefaultDurableNonceTransactionSender({
884
- rpc,
885
- rpcSubscriptions
886
- }) {
887
- const confirmDurableNonceTransaction = createDefaultDurableNonceTransactionConfirmer({
888
- rpc,
889
- rpcSubscriptions
890
- });
891
- return async function sendDurableNonceTransaction(transaction, config) {
892
- await sendAndConfirmDurableNonceTransaction({
893
- ...config,
894
- confirmDurableNonceTransaction,
895
- rpc,
896
- transaction
897
- });
898
- };
899
- }
900
- function createDefaultTransactionSender({
901
- rpc,
902
- rpcSubscriptions
903
- }) {
904
- const confirmRecentTransaction = createDefaultRecentTransactionConfirmer({
905
- rpc,
906
- rpcSubscriptions
907
- });
908
- return async function sendTransaction(transaction, config) {
909
- await sendAndConfirmTransaction({
910
- ...config,
911
- confirmRecentTransaction,
912
- rpc,
913
- transaction
914
- });
915
- };
916
- }
917
- async function sendAndConfirmDurableNonceTransaction({
123
+ async function sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
918
124
  abortSignal,
919
125
  commitment,
920
126
  confirmDurableNonceTransaction,
@@ -922,7 +128,7 @@ async function sendAndConfirmDurableNonceTransaction({
922
128
  transaction,
923
129
  ...sendTransactionConfig
924
130
  }) {
925
- const transactionSignature = await sendTransaction_INTERNAL({
131
+ const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
926
132
  ...sendTransactionConfig,
927
133
  abortSignal,
928
134
  commitment,
@@ -936,7 +142,7 @@ async function sendAndConfirmDurableNonceTransaction({
936
142
  });
937
143
  return transactionSignature;
938
144
  }
939
- async function sendAndConfirmTransaction({
145
+ async function sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({
940
146
  abortSignal,
941
147
  commitment,
942
148
  confirmRecentTransaction,
@@ -944,7 +150,7 @@ async function sendAndConfirmTransaction({
944
150
  transaction,
945
151
  ...sendTransactionConfig
946
152
  }) {
947
- const transactionSignature = await sendTransaction_INTERNAL({
153
+ const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
948
154
  ...sendTransactionConfig,
949
155
  abortSignal,
950
156
  commitment,
@@ -959,25 +165,77 @@ async function sendAndConfirmTransaction({
959
165
  return transactionSignature;
960
166
  }
961
167
 
962
- exports.createBlockHeightExceedencePromiseFactory = createBlockHeightExceedencePromiseFactory;
963
- exports.createDefaultAirdropRequester = createDefaultAirdropRequester;
964
- exports.createDefaultDurableNonceTransactionConfirmer = createDefaultDurableNonceTransactionConfirmer;
965
- exports.createDefaultDurableNonceTransactionSender = createDefaultDurableNonceTransactionSender;
966
- exports.createDefaultRecentTransactionConfirmer = createDefaultRecentTransactionConfirmer;
967
- exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
968
- exports.createDefaultRpcTransport = createDefaultRpcTransport;
969
- exports.createDefaultTransactionSender = createDefaultTransactionSender;
970
- exports.createNonceInvalidationPromiseFactory = createNonceInvalidationPromiseFactory;
971
- exports.createRecentSignatureConfirmationPromiseFactory = createRecentSignatureConfirmationPromiseFactory;
972
- exports.createSolanaRpc = createSolanaRpc;
973
- exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
974
- exports.createSolanaRpcSubscriptions_UNSTABLE = createSolanaRpcSubscriptions_UNSTABLE;
168
+ // src/send-transaction.ts
169
+ function sendTransactionWithoutConfirmingFactory({
170
+ rpc
171
+ }) {
172
+ return async function sendTransactionWithoutConfirming(transaction, config) {
173
+ await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
174
+ ...config,
175
+ rpc,
176
+ transaction
177
+ });
178
+ };
179
+ }
180
+ function sendAndConfirmDurableNonceTransactionFactory({
181
+ rpc,
182
+ rpcSubscriptions
183
+ }) {
184
+ const getNonceInvalidationPromise = transactionConfirmation.createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
185
+ const getRecentSignatureConfirmationPromise = transactionConfirmation.createRecentSignatureConfirmationPromiseFactory(
186
+ rpc,
187
+ rpcSubscriptions
188
+ );
189
+ async function confirmDurableNonceTransaction(config) {
190
+ await transactionConfirmation.waitForDurableNonceTransactionConfirmation({
191
+ ...config,
192
+ getNonceInvalidationPromise,
193
+ getRecentSignatureConfirmationPromise
194
+ });
195
+ }
196
+ return async function sendAndConfirmDurableNonceTransaction(transaction, config) {
197
+ await sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
198
+ ...config,
199
+ confirmDurableNonceTransaction,
200
+ rpc,
201
+ transaction
202
+ });
203
+ };
204
+ }
205
+ function sendAndConfirmTransactionFactory({
206
+ rpc,
207
+ rpcSubscriptions
208
+ }) {
209
+ const getBlockHeightExceedencePromise = transactionConfirmation.createBlockHeightExceedencePromiseFactory({
210
+ rpc,
211
+ rpcSubscriptions
212
+ });
213
+ const getRecentSignatureConfirmationPromise = transactionConfirmation.createRecentSignatureConfirmationPromiseFactory(
214
+ rpc,
215
+ rpcSubscriptions
216
+ );
217
+ async function confirmRecentTransaction(config) {
218
+ await transactionConfirmation.waitForRecentTransactionConfirmation({
219
+ ...config,
220
+ getBlockHeightExceedencePromise,
221
+ getRecentSignatureConfirmationPromise
222
+ });
223
+ }
224
+ return async function sendAndConfirmTransaction(transaction, config) {
225
+ await sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({
226
+ ...config,
227
+ confirmRecentTransaction,
228
+ rpc,
229
+ transaction
230
+ });
231
+ };
232
+ }
233
+
234
+ exports.airdropFactory = airdropFactory;
975
235
  exports.decodeTransaction = decodeTransaction;
976
- exports.requestAndConfirmAirdrop = requestAndConfirmAirdrop;
977
- exports.sendAndConfirmDurableNonceTransaction = sendAndConfirmDurableNonceTransaction;
978
- exports.sendAndConfirmTransaction = sendAndConfirmTransaction;
979
- exports.waitForDurableNonceTransactionConfirmation = waitForDurableNonceTransactionConfirmation;
980
- exports.waitForRecentTransactionConfirmation = waitForRecentTransactionConfirmation;
236
+ exports.sendAndConfirmDurableNonceTransactionFactory = sendAndConfirmDurableNonceTransactionFactory;
237
+ exports.sendAndConfirmTransactionFactory = sendAndConfirmTransactionFactory;
238
+ exports.sendTransactionWithoutConfirmingFactory = sendTransactionWithoutConfirmingFactory;
981
239
  Object.keys(accounts).forEach(function (k) {
982
240
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
983
241
  enumerable: true,
@@ -1020,12 +278,24 @@ Object.keys(programs).forEach(function (k) {
1020
278
  get: function () { return programs[k]; }
1021
279
  });
1022
280
  });
281
+ Object.keys(rpc).forEach(function (k) {
282
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
283
+ enumerable: true,
284
+ get: function () { return rpc[k]; }
285
+ });
286
+ });
1023
287
  Object.keys(rpcParsedTypes).forEach(function (k) {
1024
288
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1025
289
  enumerable: true,
1026
290
  get: function () { return rpcParsedTypes[k]; }
1027
291
  });
1028
292
  });
293
+ Object.keys(rpcSubscriptions).forEach(function (k) {
294
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
295
+ enumerable: true,
296
+ get: function () { return rpcSubscriptions[k]; }
297
+ });
298
+ });
1029
299
  Object.keys(rpcTypes).forEach(function (k) {
1030
300
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1031
301
  enumerable: true,