@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,348 @@ 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
+ }
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);
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
+ if (globalThis.navigator.onLine) {
492
+ restartPingTimer();
493
+ }
494
+ let handleOffline;
495
+ let handleOnline;
496
+ {
497
+ handleOffline = () => {
498
+ clearInterval(intervalId);
499
+ };
500
+ handleOnline = () => {
501
+ sendPing();
502
+ restartPingTimer();
503
+ };
504
+ globalThis.window.addEventListener("offline", handleOffline);
505
+ globalThis.window.addEventListener("online", handleOnline);
65
506
  }
66
507
  }
508
+ return pingableConnections.get(connection);
509
+ };
510
+ }
511
+
512
+ // src/rpc-websocket-connection-sharding.ts
513
+ var NULL_SHARD_CACHE_KEY = Symbol(
514
+ __DEV__ ? "Cache key to use when there is no connection sharding strategy" : void 0
515
+ );
516
+ function getWebSocketTransportWithConnectionSharding({
517
+ getShard,
518
+ transport
519
+ }) {
520
+ return getCachedAbortableIterableFactory({
521
+ getAbortSignalFromInputArgs: ({ signal }) => signal,
522
+ getCacheEntryMissingError(shardKey) {
523
+ return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
524
+ },
525
+ getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
526
+ onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
527
+ onCreateIterable: (abortSignal, config) => transport({
528
+ ...config,
529
+ signal: abortSignal
530
+ })
531
+ });
532
+ }
533
+
534
+ // src/rpc-websocket-transport.ts
535
+ function createDefaultRpcSubscriptionsTransport(config) {
536
+ const { getShard, intervalMs, ...rest } = config;
537
+ return functional.pipe(
538
+ rpcTransport.createWebSocketTransport({
539
+ ...rest,
540
+ sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
541
+ 131072
542
+ }),
543
+ (transport) => getWebSocketTransportWithAutoping({
544
+ intervalMs: intervalMs ?? 5e3,
545
+ transport
546
+ }),
547
+ (transport) => getWebSocketTransportWithConnectionSharding({
548
+ getShard,
549
+ transport
550
+ })
551
+ );
552
+ }
553
+ function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, config) {
554
+ if (
555
+ // The developer has supplied no value for `preflightCommitment`.
556
+ !config?.preflightCommitment && // The value of `commitment` is lower than the server default of `preflightCommitment`.
557
+ rpcTypes.commitmentComparator(
558
+ commitment,
559
+ "finalized"
560
+ /* default value of `preflightCommitment` */
561
+ ) < 0
562
+ ) {
563
+ return {
564
+ ...config,
565
+ // In the common case, it is unlikely that you want to simulate a transaction at
566
+ // `finalized` commitment when your standard of commitment for confirming the
567
+ // transaction is lower. Cap the simulation commitment level to the level of the
568
+ // confirmation commitment.
569
+ preflightCommitment: commitment
570
+ };
571
+ }
572
+ return config;
573
+ }
574
+ async function sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
575
+ abortSignal,
576
+ commitment,
577
+ rpc,
578
+ transaction,
579
+ ...sendTransactionConfig
580
+ }) {
581
+ const base64EncodedWireTransaction = transactions.getBase64EncodedWireTransaction(transaction);
582
+ return await rpc.sendTransaction(base64EncodedWireTransaction, {
583
+ ...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),
584
+ encoding: "base64"
585
+ }).send({ abortSignal });
586
+ }
587
+ async function sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
588
+ abortSignal,
589
+ commitment,
590
+ confirmDurableNonceTransaction,
591
+ rpc,
592
+ transaction,
593
+ ...sendTransactionConfig
594
+ }) {
595
+ const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
596
+ ...sendTransactionConfig,
597
+ abortSignal,
598
+ commitment,
599
+ rpc,
600
+ transaction
601
+ });
602
+ await confirmDurableNonceTransaction({
603
+ abortSignal,
604
+ commitment,
605
+ transaction
606
+ });
607
+ return transactionSignature;
608
+ }
609
+ async function sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({
610
+ abortSignal,
611
+ commitment,
612
+ confirmRecentTransaction,
613
+ rpc,
614
+ transaction,
615
+ ...sendTransactionConfig
616
+ }) {
617
+ const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
618
+ ...sendTransactionConfig,
619
+ abortSignal,
620
+ commitment,
621
+ rpc,
622
+ transaction
623
+ });
624
+ await confirmRecentTransaction({
625
+ abortSignal,
626
+ commitment,
627
+ transaction
67
628
  });
629
+ return transactionSignature;
68
630
  }
69
631
 
632
+ // src/send-transaction.ts
633
+ function sendTransactionWithoutConfirmingFactory({
634
+ rpc
635
+ }) {
636
+ return async function sendTransactionWithoutConfirming(transaction, config) {
637
+ await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
638
+ ...config,
639
+ rpc,
640
+ transaction
641
+ });
642
+ };
643
+ }
644
+ function sendAndConfirmDurableNonceTransactionFactory({
645
+ rpc,
646
+ rpcSubscriptions
647
+ }) {
648
+ const getNonceInvalidationPromise = transactionConfirmation.createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
649
+ const getRecentSignatureConfirmationPromise = transactionConfirmation.createRecentSignatureConfirmationPromiseFactory(
650
+ rpc,
651
+ rpcSubscriptions
652
+ );
653
+ async function confirmDurableNonceTransaction(config) {
654
+ await transactionConfirmation.waitForDurableNonceTransactionConfirmation({
655
+ ...config,
656
+ getNonceInvalidationPromise,
657
+ getRecentSignatureConfirmationPromise
658
+ });
659
+ }
660
+ return async function sendAndConfirmDurableNonceTransaction(transaction, config) {
661
+ await sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
662
+ ...config,
663
+ confirmDurableNonceTransaction,
664
+ rpc,
665
+ transaction
666
+ });
667
+ };
668
+ }
669
+ function sendAndConfirmTransactionFactory({
670
+ rpc,
671
+ rpcSubscriptions
672
+ }) {
673
+ const getBlockHeightExceedencePromise = transactionConfirmation.createBlockHeightExceedencePromiseFactory({
674
+ rpc,
675
+ rpcSubscriptions
676
+ });
677
+ const getRecentSignatureConfirmationPromise = transactionConfirmation.createRecentSignatureConfirmationPromiseFactory(
678
+ rpc,
679
+ rpcSubscriptions
680
+ );
681
+ async function confirmRecentTransaction(config) {
682
+ await transactionConfirmation.waitForRecentTransactionConfirmation({
683
+ ...config,
684
+ getBlockHeightExceedencePromise,
685
+ getRecentSignatureConfirmationPromise
686
+ });
687
+ }
688
+ return async function sendAndConfirmTransaction(transaction, config) {
689
+ await sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({
690
+ ...config,
691
+ confirmRecentTransaction,
692
+ rpc,
693
+ transaction
694
+ });
695
+ };
696
+ }
697
+
698
+ exports.airdropFactory = airdropFactory;
699
+ exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
70
700
  exports.createDefaultRpcTransport = createDefaultRpcTransport;
71
701
  exports.createSolanaRpc = createSolanaRpc;
702
+ exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
703
+ exports.createSolanaRpcSubscriptions_UNSTABLE = createSolanaRpcSubscriptions_UNSTABLE;
704
+ exports.decodeTransaction = decodeTransaction;
705
+ exports.sendAndConfirmDurableNonceTransactionFactory = sendAndConfirmDurableNonceTransactionFactory;
706
+ exports.sendAndConfirmTransactionFactory = sendAndConfirmTransactionFactory;
707
+ exports.sendTransactionWithoutConfirmingFactory = sendTransactionWithoutConfirmingFactory;
708
+ Object.keys(accounts).forEach(function (k) {
709
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
710
+ enumerable: true,
711
+ get: function () { return accounts[k]; }
712
+ });
713
+ });
714
+ Object.keys(addresses).forEach(function (k) {
715
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
716
+ enumerable: true,
717
+ get: function () { return addresses[k]; }
718
+ });
719
+ });
720
+ Object.keys(codecs).forEach(function (k) {
721
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
722
+ enumerable: true,
723
+ get: function () { return codecs[k]; }
724
+ });
725
+ });
726
+ Object.keys(functional).forEach(function (k) {
727
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
728
+ enumerable: true,
729
+ get: function () { return functional[k]; }
730
+ });
731
+ });
732
+ Object.keys(instructions).forEach(function (k) {
733
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
734
+ enumerable: true,
735
+ get: function () { return instructions[k]; }
736
+ });
737
+ });
72
738
  Object.keys(keys).forEach(function (k) {
73
- if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
739
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
74
740
  enumerable: true,
75
741
  get: function () { return keys[k]; }
76
742
  });
77
743
  });
744
+ Object.keys(programs).forEach(function (k) {
745
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
746
+ enumerable: true,
747
+ get: function () { return programs[k]; }
748
+ });
749
+ });
750
+ Object.keys(rpcParsedTypes).forEach(function (k) {
751
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
752
+ enumerable: true,
753
+ get: function () { return rpcParsedTypes[k]; }
754
+ });
755
+ });
756
+ Object.keys(rpcTypes).forEach(function (k) {
757
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
758
+ enumerable: true,
759
+ get: function () { return rpcTypes[k]; }
760
+ });
761
+ });
762
+ Object.keys(signers).forEach(function (k) {
763
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
764
+ enumerable: true,
765
+ get: function () { return signers[k]; }
766
+ });
767
+ });
768
+ Object.keys(transactions).forEach(function (k) {
769
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
770
+ enumerable: true,
771
+ get: function () { return transactions[k]; }
772
+ });
773
+ });
774
+ //# sourceMappingURL=out.js.map
775
+ //# sourceMappingURL=index.browser.cjs.map