@solana/web3.js 2.0.0-experimental.e9c1b10 → 2.0.0-experimental.eb14acd

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