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