@solana/web3.js 2.0.0-experimental.3244e3e → 2.0.0-experimental.34c3228

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 (49) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1153 -43
  3. package/dist/index.browser.cjs +728 -30
  4. package/dist/index.browser.cjs.map +1 -1
  5. package/dist/index.browser.js +660 -32
  6. package/dist/index.browser.js.map +1 -1
  7. package/dist/index.development.js +5629 -295
  8. package/dist/index.development.js.map +1 -1
  9. package/dist/index.native.js +649 -32
  10. package/dist/index.native.js.map +1 -1
  11. package/dist/index.node.cjs +717 -30
  12. package/dist/index.node.cjs.map +1 -1
  13. package/dist/index.node.js +651 -32
  14. package/dist/index.node.js.map +1 -1
  15. package/dist/index.production.min.js +273 -4
  16. package/dist/types/airdrop-internal.d.ts +16 -0
  17. package/dist/types/airdrop-internal.d.ts.map +1 -0
  18. package/dist/types/airdrop.d.ts +12 -0
  19. package/dist/types/airdrop.d.ts.map +1 -0
  20. package/dist/types/cached-abortable-iterable.d.ts +11 -0
  21. package/dist/types/cached-abortable-iterable.d.ts.map +1 -0
  22. package/dist/types/decode-transaction.d.ts +10 -0
  23. package/dist/types/decode-transaction.d.ts.map +1 -0
  24. package/dist/types/index.d.ts +16 -2
  25. package/dist/types/index.d.ts.map +1 -1
  26. package/dist/types/rpc-default-config.d.ts.map +1 -1
  27. package/dist/types/rpc-integer-overflow-error.d.ts +3 -7
  28. package/dist/types/rpc-integer-overflow-error.d.ts.map +1 -1
  29. package/dist/types/rpc-request-coalescer.d.ts +5 -0
  30. package/dist/types/rpc-request-coalescer.d.ts.map +1 -0
  31. package/dist/types/rpc-request-deduplication.d.ts +2 -0
  32. package/dist/types/rpc-request-deduplication.d.ts.map +1 -0
  33. package/dist/types/rpc-subscription-coalescer.d.ts +10 -0
  34. package/dist/types/rpc-subscription-coalescer.d.ts.map +1 -0
  35. package/dist/types/rpc-transport.d.ts +7 -2
  36. package/dist/types/rpc-transport.d.ts.map +1 -1
  37. package/dist/types/rpc-websocket-autopinger.d.ts +8 -0
  38. package/dist/types/rpc-websocket-autopinger.d.ts.map +1 -0
  39. package/dist/types/rpc-websocket-connection-sharding.d.ts +13 -0
  40. package/dist/types/rpc-websocket-connection-sharding.d.ts.map +1 -0
  41. package/dist/types/rpc-websocket-transport.d.ts +16 -0
  42. package/dist/types/rpc-websocket-transport.d.ts.map +1 -0
  43. package/dist/types/rpc.d.ts +12 -4
  44. package/dist/types/rpc.d.ts.map +1 -1
  45. package/dist/types/send-transaction-internal.d.ts +27 -0
  46. package/dist/types/send-transaction-internal.d.ts.map +1 -0
  47. package/dist/types/send-transaction.d.ts +23 -0
  48. package/dist/types/send-transaction.d.ts.map +1 -0
  49. package/package.json +28 -39
@@ -1,52 +1,425 @@
1
1
  'use strict';
2
2
 
3
+ var accounts = require('@solana/accounts');
4
+ var addresses = require('@solana/addresses');
5
+ var codecs = require('@solana/codecs');
6
+ var functional = require('@solana/functional');
7
+ var instructions = require('@solana/instructions');
3
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');
13
+ var transactions = require('@solana/transactions');
14
+ var transactionConfirmation = require('@solana/transaction-confirmation');
4
15
  var rpcCore = require('@solana/rpc-core');
5
16
  var rpcTransport = require('@solana/rpc-transport');
17
+ var fastStableStringify = require('fast-stable-stringify');
18
+ var errors = require('@solana/errors');
6
19
 
7
- // src/index.ts
20
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
21
 
9
- // src/rpc-integer-overflow-error.ts
10
- var SolanaJsonRpcIntegerOverflowError = class extends Error {
11
- constructor(methodName, keyPath, value) {
12
- const argPosition = (typeof keyPath[0] === "number" ? keyPath[0] : parseInt(keyPath[0], 10)) + 1;
13
- let ordinal = "";
22
+ var fastStableStringify__default = /*#__PURE__*/_interopDefault(fastStableStringify);
23
+
24
+ // ../build-scripts/env-shim.ts
25
+ var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
26
+
27
+ // src/airdrop-internal.ts
28
+ async function requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({
29
+ abortSignal,
30
+ commitment,
31
+ confirmSignatureOnlyTransaction,
32
+ lamports,
33
+ recipientAddress,
34
+ rpc
35
+ }) {
36
+ const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports, { commitment }).send({ abortSignal });
37
+ await confirmSignatureOnlyTransaction({
38
+ abortSignal,
39
+ commitment,
40
+ signature: airdropTransactionSignature
41
+ });
42
+ return airdropTransactionSignature;
43
+ }
44
+
45
+ // src/airdrop.ts
46
+ function airdropFactory({ rpc, rpcSubscriptions }) {
47
+ const getRecentSignatureConfirmationPromise = transactionConfirmation.createRecentSignatureConfirmationPromiseFactory(
48
+ rpc,
49
+ rpcSubscriptions
50
+ );
51
+ async function confirmSignatureOnlyTransaction(config) {
52
+ await transactionConfirmation.waitForRecentTransactionConfirmationUntilTimeout({
53
+ ...config,
54
+ getRecentSignatureConfirmationPromise,
55
+ getTimeoutPromise: transactionConfirmation.getTimeoutPromise
56
+ });
57
+ }
58
+ return async function airdrop(config) {
59
+ return await requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({
60
+ ...config,
61
+ confirmSignatureOnlyTransaction,
62
+ rpc
63
+ });
64
+ };
65
+ }
66
+ var compiledTransactionDecoder = void 0;
67
+ async function fetchLookupTables(lookupTableAddresses, rpc, config) {
68
+ const fetchedLookupTables = await accounts.fetchJsonParsedAccounts(
69
+ rpc,
70
+ lookupTableAddresses,
71
+ config
72
+ );
73
+ accounts.assertAccountsDecoded(fetchedLookupTables);
74
+ accounts.assertAccountsExist(fetchedLookupTables);
75
+ return fetchedLookupTables.reduce((acc, lookup) => {
76
+ return {
77
+ ...acc,
78
+ [lookup.address]: lookup.data.addresses
79
+ };
80
+ }, {});
81
+ }
82
+ async function decodeTransaction(encodedTransaction, rpc, config) {
83
+ const { lastValidBlockHeight, ...fetchAccountsConfig } = config ?? {};
84
+ if (!compiledTransactionDecoder)
85
+ compiledTransactionDecoder = transactions.getCompiledTransactionDecoder();
86
+ const compiledTransaction = compiledTransactionDecoder.decode(encodedTransaction);
87
+ const { compiledMessage } = compiledTransaction;
88
+ const lookupTables = "addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups !== void 0 && compiledMessage.addressTableLookups.length > 0 ? compiledMessage.addressTableLookups : [];
89
+ const lookupTableAddresses = lookupTables.map((l) => l.lookupTableAddress);
90
+ const fetchedLookupTables = lookupTableAddresses.length > 0 ? await fetchLookupTables(lookupTableAddresses, rpc, fetchAccountsConfig) : {};
91
+ return transactions.decompileTransaction(compiledTransaction, {
92
+ addressesByLookupTableAddress: fetchedLookupTables,
93
+ lastValidBlockHeight
94
+ });
95
+ }
96
+ function createSolanaJsonRpcIntegerOverflowError(methodName, keyPath, value) {
97
+ let argumentLabel = "";
98
+ if (typeof keyPath[0] === "number") {
99
+ const argPosition = keyPath[0] + 1;
14
100
  const lastDigit = argPosition % 10;
15
101
  const lastTwoDigits = argPosition % 100;
16
102
  if (lastDigit == 1 && lastTwoDigits != 11) {
17
- ordinal = argPosition + "st";
103
+ argumentLabel = argPosition + "st";
18
104
  } else if (lastDigit == 2 && lastTwoDigits != 12) {
19
- ordinal = argPosition + "nd";
105
+ argumentLabel = argPosition + "nd";
20
106
  } else if (lastDigit == 3 && lastTwoDigits != 13) {
21
- ordinal = argPosition + "rd";
107
+ argumentLabel = argPosition + "rd";
22
108
  } else {
23
- ordinal = argPosition + "th";
109
+ argumentLabel = argPosition + "th";
24
110
  }
25
- const path = keyPath.length > 1 ? keyPath.slice(1).map((pathPart) => typeof pathPart === "number" ? `[${pathPart}]` : pathPart).join(".") : null;
26
- super(
27
- `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\`.`
28
- );
29
- this.keyPath = keyPath;
30
- this.methodName = methodName;
31
- this.value = value;
111
+ } else {
112
+ argumentLabel = `\`${keyPath[0].toString()}\``;
32
113
  }
33
- get name() {
34
- return "SolanaJsonRpcIntegerOverflowError";
114
+ const path = keyPath.length > 1 ? keyPath.slice(1).map((pathPart) => typeof pathPart === "number" ? `[${pathPart}]` : pathPart).join(".") : void 0;
115
+ const error = new errors.SolanaError(errors.SOLANA_ERROR__RPC_INTEGER_OVERFLOW, {
116
+ argumentLabel,
117
+ keyPath,
118
+ methodName,
119
+ optionalPathLabel: path ? ` at path \`${path}\`` : "",
120
+ value,
121
+ ...path !== void 0 ? { path } : void 0
122
+ });
123
+ if ("captureStackTrace" in Error && typeof Error.captureStackTrace === "function") {
124
+ Error.captureStackTrace(error, createSolanaJsonRpcIntegerOverflowError);
35
125
  }
36
- };
126
+ return error;
127
+ }
37
128
 
38
129
  // src/rpc-default-config.ts
39
130
  var DEFAULT_RPC_CONFIG = {
131
+ defaultCommitment: "confirmed",
40
132
  onIntegerOverflow(methodName, keyPath, value) {
41
- throw new SolanaJsonRpcIntegerOverflowError(methodName, keyPath, value);
133
+ throw createSolanaJsonRpcIntegerOverflowError(methodName, keyPath, value);
42
134
  }
43
135
  };
136
+
137
+ // src/cached-abortable-iterable.ts
138
+ function registerIterableCleanup(iterable, cleanupFn) {
139
+ (async () => {
140
+ try {
141
+ for await (const _ of iterable)
142
+ ;
143
+ } catch {
144
+ } finally {
145
+ cleanupFn();
146
+ }
147
+ })();
148
+ }
149
+ function getCachedAbortableIterableFactory({
150
+ getAbortSignalFromInputArgs,
151
+ getCacheEntryMissingError,
152
+ getCacheKeyFromInputArgs,
153
+ onCacheHit,
154
+ onCreateIterable
155
+ }) {
156
+ const cache = /* @__PURE__ */ new Map();
157
+ function getCacheEntryOrThrow(cacheKey) {
158
+ const currentCacheEntry = cache.get(cacheKey);
159
+ if (!currentCacheEntry) {
160
+ throw getCacheEntryMissingError(cacheKey);
161
+ }
162
+ return currentCacheEntry;
163
+ }
164
+ return async (...args) => {
165
+ const cacheKey = getCacheKeyFromInputArgs(...args);
166
+ const signal = getAbortSignalFromInputArgs(...args);
167
+ if (cacheKey === void 0) {
168
+ return await onCreateIterable(signal, ...args);
169
+ }
170
+ const cleanup = () => {
171
+ cache.delete(cacheKey);
172
+ signal.removeEventListener("abort", handleAbort);
173
+ };
174
+ const handleAbort = () => {
175
+ const cacheEntry = getCacheEntryOrThrow(cacheKey);
176
+ if (cacheEntry.purgeScheduled !== true) {
177
+ cacheEntry.purgeScheduled = true;
178
+ globalThis.queueMicrotask(() => {
179
+ cacheEntry.purgeScheduled = false;
180
+ if (cacheEntry.referenceCount === 0) {
181
+ cacheEntry.abortController.abort();
182
+ cleanup();
183
+ }
184
+ });
185
+ }
186
+ cacheEntry.referenceCount--;
187
+ };
188
+ signal.addEventListener("abort", handleAbort);
189
+ try {
190
+ const cacheEntry = cache.get(cacheKey);
191
+ if (!cacheEntry) {
192
+ const singletonAbortController = new AbortController();
193
+ const newIterablePromise = onCreateIterable(singletonAbortController.signal, ...args);
194
+ const newCacheEntry = {
195
+ abortController: singletonAbortController,
196
+ iterable: newIterablePromise,
197
+ purgeScheduled: false,
198
+ referenceCount: 1
199
+ };
200
+ cache.set(cacheKey, newCacheEntry);
201
+ const newIterable = await newIterablePromise;
202
+ registerIterableCleanup(newIterable, cleanup);
203
+ newCacheEntry.iterable = newIterable;
204
+ return newIterable;
205
+ } else {
206
+ cacheEntry.referenceCount++;
207
+ const iterableOrIterablePromise = cacheEntry.iterable;
208
+ const cachedIterable = "then" in iterableOrIterablePromise ? await iterableOrIterablePromise : iterableOrIterablePromise;
209
+ await onCacheHit(cachedIterable, ...args);
210
+ return cachedIterable;
211
+ }
212
+ } catch (e) {
213
+ cleanup();
214
+ throw e;
215
+ }
216
+ };
217
+ }
218
+
219
+ // src/rpc-subscription-coalescer.ts
220
+ var EXPLICIT_ABORT_TOKEN = Symbol(
221
+ __DEV__ ? "This symbol is thrown from a subscription's iterator when the subscription is explicitly aborted by the user" : void 0
222
+ );
223
+ function registerIterableCleanup2(iterable, cleanupFn) {
224
+ (async () => {
225
+ try {
226
+ for await (const _ of iterable)
227
+ ;
228
+ } catch {
229
+ } finally {
230
+ cleanupFn();
231
+ }
232
+ })();
233
+ }
234
+ function getRpcSubscriptionsWithSubscriptionCoalescing({
235
+ getDeduplicationKey,
236
+ rpcSubscriptions
237
+ }) {
238
+ const cache = /* @__PURE__ */ new Map();
239
+ return new Proxy(rpcSubscriptions, {
240
+ defineProperty() {
241
+ return false;
242
+ },
243
+ deleteProperty() {
244
+ return false;
245
+ },
246
+ get(target, p, receiver) {
247
+ const subscriptionMethod = Reflect.get(target, p, receiver);
248
+ if (typeof subscriptionMethod !== "function") {
249
+ return subscriptionMethod;
250
+ }
251
+ return function(...rawParams) {
252
+ const deduplicationKey = getDeduplicationKey(p, rawParams);
253
+ if (deduplicationKey === void 0) {
254
+ return subscriptionMethod(...rawParams);
255
+ }
256
+ if (cache.has(deduplicationKey)) {
257
+ return cache.get(deduplicationKey);
258
+ }
259
+ const iterableFactory = getCachedAbortableIterableFactory({
260
+ getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
261
+ getCacheEntryMissingError(deduplicationKey2) {
262
+ return new Error(
263
+ `Found no cache entry for subscription with deduplication key \`${deduplicationKey2?.toString()}\``
264
+ );
265
+ },
266
+ getCacheKeyFromInputArgs: () => deduplicationKey,
267
+ async onCacheHit(_iterable, _config) {
268
+ },
269
+ async onCreateIterable(abortSignal, config) {
270
+ const pendingSubscription2 = subscriptionMethod(
271
+ ...rawParams
272
+ );
273
+ const iterable = await pendingSubscription2.subscribe({
274
+ ...config,
275
+ abortSignal
276
+ });
277
+ registerIterableCleanup2(iterable, () => {
278
+ cache.delete(deduplicationKey);
279
+ });
280
+ return iterable;
281
+ }
282
+ });
283
+ const pendingSubscription = {
284
+ async subscribe(...args) {
285
+ const iterable = await iterableFactory(...args);
286
+ const { abortSignal } = args[0];
287
+ let abortPromise;
288
+ return {
289
+ ...iterable,
290
+ async *[Symbol.asyncIterator]() {
291
+ abortPromise ||= abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN) : new Promise((_, reject) => {
292
+ abortSignal.addEventListener("abort", () => {
293
+ reject(EXPLICIT_ABORT_TOKEN);
294
+ });
295
+ });
296
+ try {
297
+ const iterator = iterable[Symbol.asyncIterator]();
298
+ while (true) {
299
+ const iteratorResult = await Promise.race([iterator.next(), abortPromise]);
300
+ if (iteratorResult.done) {
301
+ return;
302
+ } else {
303
+ yield iteratorResult.value;
304
+ }
305
+ }
306
+ } catch (e) {
307
+ if (e === EXPLICIT_ABORT_TOKEN) {
308
+ return;
309
+ }
310
+ cache.delete(deduplicationKey);
311
+ throw e;
312
+ }
313
+ }
314
+ };
315
+ }
316
+ };
317
+ cache.set(deduplicationKey, pendingSubscription);
318
+ return pendingSubscription;
319
+ };
320
+ }
321
+ });
322
+ }
323
+
324
+ // src/rpc.ts
44
325
  function createSolanaRpc(config) {
326
+ const api = rpcCore.createSolanaRpcApi(DEFAULT_RPC_CONFIG);
45
327
  return rpcTransport.createJsonRpc({
46
328
  ...config,
47
- api: rpcCore.createSolanaRpcApi(DEFAULT_RPC_CONFIG)
329
+ api
48
330
  });
49
331
  }
332
+ function createSolanaRpcSubscriptions(config) {
333
+ return functional.pipe(
334
+ rpcTransport.createJsonSubscriptionRpc({
335
+ ...config,
336
+ api: rpcCore.createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
337
+ }),
338
+ (rpcSubscriptions) => getRpcSubscriptionsWithSubscriptionCoalescing({
339
+ getDeduplicationKey: (...args) => fastStableStringify__default.default(args),
340
+ rpcSubscriptions
341
+ })
342
+ );
343
+ }
344
+ function createSolanaRpcSubscriptions_UNSTABLE(config) {
345
+ return rpcTransport.createJsonSubscriptionRpc({
346
+ ...config,
347
+ api: rpcCore.createSolanaRpcSubscriptionsApi_UNSTABLE(DEFAULT_RPC_CONFIG)
348
+ });
349
+ }
350
+
351
+ // src/rpc-request-coalescer.ts
352
+ function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
353
+ let coalescedRequestsByDeduplicationKey;
354
+ return async function makeCoalescedHttpRequest(config) {
355
+ const { payload, signal } = config;
356
+ const deduplicationKey = getDeduplicationKey(payload);
357
+ if (deduplicationKey === void 0) {
358
+ return await transport(config);
359
+ }
360
+ if (!coalescedRequestsByDeduplicationKey) {
361
+ Promise.resolve().then(() => {
362
+ coalescedRequestsByDeduplicationKey = void 0;
363
+ });
364
+ coalescedRequestsByDeduplicationKey = {};
365
+ }
366
+ if (coalescedRequestsByDeduplicationKey[deduplicationKey] == null) {
367
+ const abortController = new AbortController();
368
+ const responsePromise = (async () => {
369
+ try {
370
+ return await transport({
371
+ ...config,
372
+ signal: abortController.signal
373
+ });
374
+ } catch (e) {
375
+ if (e && typeof e === "object" && "name" in e && e.name === "AbortError") {
376
+ return;
377
+ }
378
+ throw e;
379
+ }
380
+ })();
381
+ coalescedRequestsByDeduplicationKey[deduplicationKey] = {
382
+ abortController,
383
+ numConsumers: 0,
384
+ responsePromise
385
+ };
386
+ }
387
+ const coalescedRequest = coalescedRequestsByDeduplicationKey[deduplicationKey];
388
+ coalescedRequest.numConsumers++;
389
+ if (signal) {
390
+ const responsePromise = coalescedRequest.responsePromise;
391
+ return await new Promise((resolve, reject) => {
392
+ const handleAbort = (e) => {
393
+ signal.removeEventListener("abort", handleAbort);
394
+ coalescedRequest.numConsumers -= 1;
395
+ if (coalescedRequest.numConsumers === 0) {
396
+ const abortController = coalescedRequest.abortController;
397
+ abortController.abort();
398
+ }
399
+ const abortError = new DOMException(e.target.reason, "AbortError");
400
+ reject(abortError);
401
+ };
402
+ signal.addEventListener("abort", handleAbort);
403
+ responsePromise.then(resolve).finally(() => {
404
+ signal.removeEventListener("abort", handleAbort);
405
+ });
406
+ });
407
+ } else {
408
+ return await coalescedRequest.responsePromise;
409
+ }
410
+ };
411
+ }
412
+ function isJsonRpcPayload(payload) {
413
+ if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
414
+ return false;
415
+ }
416
+ return "jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && typeof payload.method === "string" && "params" in payload;
417
+ }
418
+ function getSolanaRpcPayloadDeduplicationKey(payload) {
419
+ return isJsonRpcPayload(payload) ? fastStableStringify__default.default([payload.method, payload.params]) : void 0;
420
+ }
421
+
422
+ // src/rpc-transport.ts
50
423
  function normalizeHeaders(headers) {
51
424
  const out = {};
52
425
  for (const headerName in headers) {
@@ -55,23 +428,337 @@ function normalizeHeaders(headers) {
55
428
  return out;
56
429
  }
57
430
  function createDefaultRpcTransport(config) {
58
- return rpcTransport.createHttpTransport({
59
- ...config,
60
- headers: {
61
- ...config.headers ? normalizeHeaders(config.headers) : void 0,
62
- ...{
63
- // Keep these headers lowercase so they will override any user-supplied headers above.
64
- "solana-client": `js/${"2.0.0-development"}` ?? "UNKNOWN"
431
+ return functional.pipe(
432
+ rpcTransport.createHttpTransport({
433
+ ...config,
434
+ headers: {
435
+ ...config.headers ? normalizeHeaders(config.headers) : void 0,
436
+ ...{
437
+ // Keep these headers lowercase so they will override any user-supplied headers above.
438
+ "solana-client": `js/${"2.0.0-development"}` ?? "UNKNOWN"
439
+ }
65
440
  }
441
+ }),
442
+ (transport) => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
443
+ );
444
+ }
445
+
446
+ // src/rpc-websocket-autopinger.ts
447
+ var PING_PAYLOAD = {
448
+ jsonrpc: "2.0",
449
+ method: "ping"
450
+ };
451
+ function getWebSocketTransportWithAutoping({
452
+ intervalMs,
453
+ transport
454
+ }) {
455
+ const pingableConnections = /* @__PURE__ */ new Map();
456
+ return async (...args) => {
457
+ const connection = await transport(...args);
458
+ let intervalId;
459
+ function sendPing() {
460
+ connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
461
+ }
462
+ function restartPingTimer() {
463
+ clearInterval(intervalId);
464
+ intervalId = setInterval(sendPing, intervalMs);
66
465
  }
466
+ if (pingableConnections.has(connection) === false) {
467
+ pingableConnections.set(connection, {
468
+ [Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
469
+ send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: (...args2) => {
470
+ restartPingTimer();
471
+ return connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(...args2);
472
+ }
473
+ });
474
+ (async () => {
475
+ try {
476
+ for await (const _ of connection) {
477
+ restartPingTimer();
478
+ }
479
+ } catch {
480
+ } finally {
481
+ pingableConnections.delete(connection);
482
+ clearInterval(intervalId);
483
+ if (handleOffline) {
484
+ globalThis.window.removeEventListener("offline", handleOffline);
485
+ }
486
+ if (handleOnline) {
487
+ globalThis.window.removeEventListener("online", handleOnline);
488
+ }
489
+ }
490
+ })();
491
+ {
492
+ restartPingTimer();
493
+ }
494
+ let handleOffline;
495
+ let handleOnline;
496
+ }
497
+ return pingableConnections.get(connection);
498
+ };
499
+ }
500
+
501
+ // src/rpc-websocket-connection-sharding.ts
502
+ var NULL_SHARD_CACHE_KEY = Symbol(
503
+ __DEV__ ? "Cache key to use when there is no connection sharding strategy" : void 0
504
+ );
505
+ function getWebSocketTransportWithConnectionSharding({
506
+ getShard,
507
+ transport
508
+ }) {
509
+ return getCachedAbortableIterableFactory({
510
+ getAbortSignalFromInputArgs: ({ signal }) => signal,
511
+ getCacheEntryMissingError(shardKey) {
512
+ return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
513
+ },
514
+ getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
515
+ onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
516
+ onCreateIterable: (abortSignal, config) => transport({
517
+ ...config,
518
+ signal: abortSignal
519
+ })
520
+ });
521
+ }
522
+
523
+ // src/rpc-websocket-transport.ts
524
+ function createDefaultRpcSubscriptionsTransport(config) {
525
+ const { getShard, intervalMs, ...rest } = config;
526
+ return functional.pipe(
527
+ rpcTransport.createWebSocketTransport({
528
+ ...rest,
529
+ sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
530
+ 131072
531
+ }),
532
+ (transport) => getWebSocketTransportWithAutoping({
533
+ intervalMs: intervalMs ?? 5e3,
534
+ transport
535
+ }),
536
+ (transport) => getWebSocketTransportWithConnectionSharding({
537
+ getShard,
538
+ transport
539
+ })
540
+ );
541
+ }
542
+ function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, config) {
543
+ if (
544
+ // The developer has supplied no value for `preflightCommitment`.
545
+ !config?.preflightCommitment && // The value of `commitment` is lower than the server default of `preflightCommitment`.
546
+ rpcTypes.commitmentComparator(
547
+ commitment,
548
+ "finalized"
549
+ /* default value of `preflightCommitment` */
550
+ ) < 0
551
+ ) {
552
+ return {
553
+ ...config,
554
+ // In the common case, it is unlikely that you want to simulate a transaction at
555
+ // `finalized` commitment when your standard of commitment for confirming the
556
+ // transaction is lower. Cap the simulation commitment level to the level of the
557
+ // confirmation commitment.
558
+ preflightCommitment: commitment
559
+ };
560
+ }
561
+ return config;
562
+ }
563
+ async function sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
564
+ abortSignal,
565
+ commitment,
566
+ rpc,
567
+ transaction,
568
+ ...sendTransactionConfig
569
+ }) {
570
+ const base64EncodedWireTransaction = transactions.getBase64EncodedWireTransaction(transaction);
571
+ return await rpc.sendTransaction(base64EncodedWireTransaction, {
572
+ ...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),
573
+ encoding: "base64"
574
+ }).send({ abortSignal });
575
+ }
576
+ async function sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
577
+ abortSignal,
578
+ commitment,
579
+ confirmDurableNonceTransaction,
580
+ rpc,
581
+ transaction,
582
+ ...sendTransactionConfig
583
+ }) {
584
+ const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
585
+ ...sendTransactionConfig,
586
+ abortSignal,
587
+ commitment,
588
+ rpc,
589
+ transaction
590
+ });
591
+ await confirmDurableNonceTransaction({
592
+ abortSignal,
593
+ commitment,
594
+ transaction
595
+ });
596
+ return transactionSignature;
597
+ }
598
+ async function sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({
599
+ abortSignal,
600
+ commitment,
601
+ confirmRecentTransaction,
602
+ rpc,
603
+ transaction,
604
+ ...sendTransactionConfig
605
+ }) {
606
+ const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
607
+ ...sendTransactionConfig,
608
+ abortSignal,
609
+ commitment,
610
+ rpc,
611
+ transaction
67
612
  });
613
+ await confirmRecentTransaction({
614
+ abortSignal,
615
+ commitment,
616
+ transaction
617
+ });
618
+ return transactionSignature;
68
619
  }
69
620
 
621
+ // src/send-transaction.ts
622
+ function sendTransactionWithoutConfirmingFactory({
623
+ rpc
624
+ }) {
625
+ return async function sendTransactionWithoutConfirming(transaction, config) {
626
+ await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
627
+ ...config,
628
+ rpc,
629
+ transaction
630
+ });
631
+ };
632
+ }
633
+ function sendAndConfirmDurableNonceTransactionFactory({
634
+ rpc,
635
+ rpcSubscriptions
636
+ }) {
637
+ const getNonceInvalidationPromise = transactionConfirmation.createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
638
+ const getRecentSignatureConfirmationPromise = transactionConfirmation.createRecentSignatureConfirmationPromiseFactory(
639
+ rpc,
640
+ rpcSubscriptions
641
+ );
642
+ async function confirmDurableNonceTransaction(config) {
643
+ await transactionConfirmation.waitForDurableNonceTransactionConfirmation({
644
+ ...config,
645
+ getNonceInvalidationPromise,
646
+ getRecentSignatureConfirmationPromise
647
+ });
648
+ }
649
+ return async function sendAndConfirmDurableNonceTransaction(transaction, config) {
650
+ await sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
651
+ ...config,
652
+ confirmDurableNonceTransaction,
653
+ rpc,
654
+ transaction
655
+ });
656
+ };
657
+ }
658
+ function sendAndConfirmTransactionFactory({
659
+ rpc,
660
+ rpcSubscriptions
661
+ }) {
662
+ const getBlockHeightExceedencePromise = transactionConfirmation.createBlockHeightExceedencePromiseFactory({
663
+ rpc,
664
+ rpcSubscriptions
665
+ });
666
+ const getRecentSignatureConfirmationPromise = transactionConfirmation.createRecentSignatureConfirmationPromiseFactory(
667
+ rpc,
668
+ rpcSubscriptions
669
+ );
670
+ async function confirmRecentTransaction(config) {
671
+ await transactionConfirmation.waitForRecentTransactionConfirmation({
672
+ ...config,
673
+ getBlockHeightExceedencePromise,
674
+ getRecentSignatureConfirmationPromise
675
+ });
676
+ }
677
+ return async function sendAndConfirmTransaction(transaction, config) {
678
+ await sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({
679
+ ...config,
680
+ confirmRecentTransaction,
681
+ rpc,
682
+ transaction
683
+ });
684
+ };
685
+ }
686
+
687
+ exports.airdropFactory = airdropFactory;
688
+ exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
70
689
  exports.createDefaultRpcTransport = createDefaultRpcTransport;
71
690
  exports.createSolanaRpc = createSolanaRpc;
691
+ exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
692
+ exports.createSolanaRpcSubscriptions_UNSTABLE = createSolanaRpcSubscriptions_UNSTABLE;
693
+ exports.decodeTransaction = decodeTransaction;
694
+ exports.sendAndConfirmDurableNonceTransactionFactory = sendAndConfirmDurableNonceTransactionFactory;
695
+ exports.sendAndConfirmTransactionFactory = sendAndConfirmTransactionFactory;
696
+ exports.sendTransactionWithoutConfirmingFactory = sendTransactionWithoutConfirmingFactory;
697
+ Object.keys(accounts).forEach(function (k) {
698
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
699
+ enumerable: true,
700
+ get: function () { return accounts[k]; }
701
+ });
702
+ });
703
+ Object.keys(addresses).forEach(function (k) {
704
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
705
+ enumerable: true,
706
+ get: function () { return addresses[k]; }
707
+ });
708
+ });
709
+ Object.keys(codecs).forEach(function (k) {
710
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
711
+ enumerable: true,
712
+ get: function () { return codecs[k]; }
713
+ });
714
+ });
715
+ Object.keys(functional).forEach(function (k) {
716
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
717
+ enumerable: true,
718
+ get: function () { return functional[k]; }
719
+ });
720
+ });
721
+ Object.keys(instructions).forEach(function (k) {
722
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
723
+ enumerable: true,
724
+ get: function () { return instructions[k]; }
725
+ });
726
+ });
72
727
  Object.keys(keys).forEach(function (k) {
73
- if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
728
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
74
729
  enumerable: true,
75
730
  get: function () { return keys[k]; }
76
731
  });
77
732
  });
733
+ Object.keys(programs).forEach(function (k) {
734
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
735
+ enumerable: true,
736
+ get: function () { return programs[k]; }
737
+ });
738
+ });
739
+ Object.keys(rpcParsedTypes).forEach(function (k) {
740
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
741
+ enumerable: true,
742
+ get: function () { return rpcParsedTypes[k]; }
743
+ });
744
+ });
745
+ Object.keys(rpcTypes).forEach(function (k) {
746
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
747
+ enumerable: true,
748
+ get: function () { return rpcTypes[k]; }
749
+ });
750
+ });
751
+ Object.keys(signers).forEach(function (k) {
752
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
753
+ enumerable: true,
754
+ get: function () { return signers[k]; }
755
+ });
756
+ });
757
+ Object.keys(transactions).forEach(function (k) {
758
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
759
+ enumerable: true,
760
+ get: function () { return transactions[k]; }
761
+ });
762
+ });
763
+ //# sourceMappingURL=out.js.map
764
+ //# sourceMappingURL=index.node.cjs.map