@solana/web3.js 2.0.0-experimental.e09b513 → 2.0.0-experimental.e0b865d

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.
@@ -125,13 +125,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
125
125
  // ../addresses/dist/index.browser.js
126
126
  init_env_shim();
127
127
 
128
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/index.mjs
128
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/index.mjs
129
129
  init_env_shim();
130
130
 
131
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/index.mjs
131
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/index.mjs
132
132
  init_env_shim();
133
133
 
134
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
134
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
135
135
  init_env_shim();
136
136
  var mergeBytes = (bytesArr) => {
137
137
  const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
@@ -152,7 +152,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
152
152
  };
153
153
  var fixBytes = (bytes2, length) => padBytes(bytes2.slice(0, length), length);
154
154
 
155
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
155
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
156
156
  init_env_shim();
157
157
  var DeserializingEmptyBufferError = class extends Error {
158
158
  constructor(serializer) {
@@ -174,7 +174,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
174
174
  }
175
175
  };
176
176
 
177
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
177
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
178
178
  init_env_shim();
179
179
  function fixSerializer(serializer, fixedBytes, description) {
180
180
  return {
@@ -196,7 +196,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
196
196
  };
197
197
  }
198
198
 
199
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/mapSerializer.mjs
199
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/mapSerializer.mjs
200
200
  init_env_shim();
201
201
  function mapSerializer(serializer, unmap, map) {
202
202
  return {
@@ -211,13 +211,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
211
211
  };
212
212
  }
213
213
 
214
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/index.mjs
214
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/index.mjs
215
215
  init_env_shim();
216
216
 
217
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
217
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
218
218
  init_env_shim();
219
219
 
220
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
220
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
221
221
  init_env_shim();
222
222
  var InvalidBaseStringError = class extends Error {
223
223
  constructor(value, base, cause) {
@@ -228,7 +228,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
228
228
  }
229
229
  };
230
230
 
231
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
231
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
232
232
  var baseX = (alphabet) => {
233
233
  const base = alphabet.length;
234
234
  const baseBigInt = BigInt(base);
@@ -282,18 +282,18 @@ this.globalThis.solanaWeb3 = (function (exports) {
282
282
  };
283
283
  };
284
284
 
285
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
285
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
286
286
  init_env_shim();
287
287
  var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
288
288
 
289
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
289
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
290
290
  init_env_shim();
291
291
  var removeNullCharacters = (value) => (
292
292
  // eslint-disable-next-line no-control-regex
293
293
  value.replace(/\u0000/g, "")
294
294
  );
295
295
 
296
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
296
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
297
297
  init_env_shim();
298
298
  var utf8 = {
299
299
  description: "utf8",
@@ -308,10 +308,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
308
308
  }
309
309
  };
310
310
 
311
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/index.mjs
311
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/index.mjs
312
312
  init_env_shim();
313
313
 
314
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
314
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
315
315
  init_env_shim();
316
316
  var Endian;
317
317
  (function(Endian2) {
@@ -319,7 +319,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
319
319
  Endian2["Big"] = "be";
320
320
  })(Endian || (Endian = {}));
321
321
 
322
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
322
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
323
323
  init_env_shim();
324
324
  var NumberOutOfRangeError = class extends RangeError {
325
325
  constructor(serializer, min, max, actual) {
@@ -328,7 +328,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
328
328
  }
329
329
  };
330
330
 
331
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
331
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
332
332
  init_env_shim();
333
333
  function numberFactory(input) {
334
334
  let littleEndian;
@@ -373,7 +373,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
373
373
  }
374
374
  };
375
375
 
376
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u8.mjs
376
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u8.mjs
377
377
  init_env_shim();
378
378
  var u8 = (options = {}) => numberFactory({
379
379
  name: "u8",
@@ -384,7 +384,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
384
384
  options
385
385
  });
386
386
 
387
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
387
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
388
388
  init_env_shim();
389
389
  var u32 = (options = {}) => numberFactory({
390
390
  name: "u32",
@@ -395,7 +395,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
395
395
  options
396
396
  });
397
397
 
398
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
398
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
399
399
  init_env_shim();
400
400
  var shortU16 = (options = {}) => ({
401
401
  description: options.description ?? "shortU16",
@@ -433,10 +433,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
433
433
  }
434
434
  });
435
435
 
436
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
436
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
437
437
  init_env_shim();
438
438
 
439
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
439
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
440
440
  init_env_shim();
441
441
  var InvalidNumberOfItemsError = class extends Error {
442
442
  constructor(serializer, expected, actual) {
@@ -457,16 +457,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
457
457
  }
458
458
  };
459
459
 
460
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
460
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
461
461
  init_env_shim();
462
462
 
463
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
463
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
464
464
  init_env_shim();
465
465
  function sumSerializerSizes(sizes) {
466
466
  return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
467
467
  }
468
468
 
469
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
469
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
470
470
  function getResolvedSize(size, childrenSizes, bytes2, offset) {
471
471
  if (typeof size === "number") {
472
472
  return [size, offset];
@@ -502,7 +502,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
502
502
  return typeof size === "object" ? size.serialize(realSize) : new Uint8Array();
503
503
  }
504
504
 
505
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
505
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
506
506
  function array(item, options = {}) {
507
507
  const size = options.size ?? u32();
508
508
  if (size === "remainder" && item.fixedSize === null) {
@@ -535,7 +535,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
535
535
  };
536
536
  }
537
537
 
538
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
538
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
539
539
  init_env_shim();
540
540
  function bytes(options = {}) {
541
541
  const size = options.size ?? "variable";
@@ -583,7 +583,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
583
583
  };
584
584
  }
585
585
 
586
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
586
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
587
587
  init_env_shim();
588
588
  function string(options = {}) {
589
589
  const size = options.size ?? u32();
@@ -625,7 +625,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
625
625
  };
626
626
  }
627
627
 
628
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
628
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
629
629
  init_env_shim();
630
630
  function struct(fields, options = {}) {
631
631
  const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
@@ -715,6 +715,21 @@ this.globalThis.solanaWeb3 = (function (exports) {
715
715
  throw new Error("No signature verification implementation could be found");
716
716
  }
717
717
  }
718
+ function isBase58EncodedAddress(putativeBase58EncodedAddress) {
719
+ if (
720
+ // Lowest address (32 bytes of zeroes)
721
+ putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
722
+ putativeBase58EncodedAddress.length > 44
723
+ ) {
724
+ return false;
725
+ }
726
+ const bytes2 = base58.serialize(putativeBase58EncodedAddress);
727
+ const numBytes = bytes2.byteLength;
728
+ if (numBytes !== 32) {
729
+ return false;
730
+ }
731
+ return true;
732
+ }
718
733
  function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
719
734
  try {
720
735
  if (
@@ -735,6 +750,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
735
750
  });
736
751
  }
737
752
  }
753
+ function address(putativeBase58EncodedAddress) {
754
+ assertIsBase58EncodedAddress(putativeBase58EncodedAddress);
755
+ return putativeBase58EncodedAddress;
756
+ }
738
757
  function getBase58EncodedAddressCodec(config) {
739
758
  return string({
740
759
  description: config?.description ?? ("A 32-byte account address" ),
@@ -1167,8 +1186,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
1167
1186
  Object.freeze(out);
1168
1187
  return out;
1169
1188
  }
1170
- function upsert(addressMap, address, update) {
1171
- addressMap[address] = update(addressMap[address] ?? { role: AccountRole2.READONLY });
1189
+ function upsert(addressMap, address2, update) {
1190
+ addressMap[address2] = update(addressMap[address2] ?? { role: AccountRole2.READONLY });
1172
1191
  }
1173
1192
  var TYPE = Symbol("AddressMapTypeProperty");
1174
1193
  function getAddressMapFromInstructions(feePayer, instructions) {
@@ -1333,8 +1352,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
1333
1352
  } else {
1334
1353
  return addressComparator(leftAddress, rightAddress);
1335
1354
  }
1336
- }).map(([address, addressMeta]) => ({
1337
- address,
1355
+ }).map(([address2, addressMeta]) => ({
1356
+ address: address2,
1338
1357
  ...addressMeta
1339
1358
  }));
1340
1359
  return orderedAccounts;
@@ -1397,7 +1416,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1397
1416
  return instructions.map(({ accounts, data, programAddress }) => {
1398
1417
  return {
1399
1418
  programAddressIndex: accountIndex[programAddress],
1400
- ...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[address]) } : null,
1419
+ ...accounts ? { accountIndices: accounts.map(({ address: address2 }) => accountIndex[address2]) } : null,
1401
1420
  ...data ? { data } : null
1402
1421
  };
1403
1422
  });
@@ -1411,7 +1430,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1411
1430
  function getCompiledStaticAccounts(orderedAccounts) {
1412
1431
  const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
1413
1432
  const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
1414
- return orderedStaticAccounts.map(({ address }) => address);
1433
+ return orderedStaticAccounts.map(({ address: address2 }) => address2);
1415
1434
  }
1416
1435
  function compileMessage(transaction) {
1417
1436
  const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
@@ -1661,16 +1680,20 @@ this.globalThis.solanaWeb3 = (function (exports) {
1661
1680
  const signature = await signBytes(secretKey, wireMessageBytes);
1662
1681
  return signature;
1663
1682
  }
1664
- async function signTransaction(keyPair, transaction) {
1683
+ async function signTransaction(keyPairs, transaction) {
1665
1684
  const compiledMessage = compileMessage(transaction);
1666
- const [signerPublicKey, signature] = await Promise.all([
1667
- getAddressFromPublicKey(keyPair.publicKey),
1668
- getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
1669
- ]);
1670
- const nextSignatures = {
1671
- ..."signatures" in transaction ? transaction.signatures : null,
1672
- ...{ [signerPublicKey]: signature }
1673
- };
1685
+ const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
1686
+ const publicKeySignaturePairs = await Promise.all(
1687
+ keyPairs.map(
1688
+ (keyPair) => Promise.all([
1689
+ getAddressFromPublicKey(keyPair.publicKey),
1690
+ getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
1691
+ ])
1692
+ )
1693
+ );
1694
+ for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
1695
+ nextSignatures[signerPublicKey] = signature;
1696
+ }
1674
1697
  const out = {
1675
1698
  ...transaction,
1676
1699
  signatures: nextSignatures
@@ -1729,6 +1752,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
1729
1752
  // src/rpc.ts
1730
1753
  init_env_shim();
1731
1754
 
1755
+ // ../functional/dist/index.browser.js
1756
+ init_env_shim();
1757
+ function pipe(init, ...fns) {
1758
+ return fns.reduce((acc, fn) => fn(acc), init);
1759
+ }
1760
+
1732
1761
  // ../rpc-core/dist/index.browser.js
1733
1762
  init_env_shim();
1734
1763
  function visitNode(value, keyPath, onIntegerOverflow) {
@@ -1757,9 +1786,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
1757
1786
  return visitNode(params, [], onIntegerOverflow);
1758
1787
  }
1759
1788
  var KEYPATH_WILDCARD = {};
1760
- var memoizedKeypaths;
1761
- function getAllowedNumericKeypaths() {
1762
- if (!memoizedKeypaths) {
1789
+ var memoizedNotificationKeypaths;
1790
+ var memoizedResponseKeypaths;
1791
+ function getAllowedNumericKeypathsForNotification() {
1792
+ if (!memoizedNotificationKeypaths) {
1793
+ memoizedNotificationKeypaths = {};
1794
+ }
1795
+ return memoizedNotificationKeypaths;
1796
+ }
1797
+ function getAllowedNumericKeypathsForResponse() {
1798
+ if (!memoizedResponseKeypaths) {
1763
1799
  const jsonParsedTokenAccountsConfigs = [
1764
1800
  // parsed Token/Token22 token account
1765
1801
  ["data", "parsed", "info", "tokenAmount", "decimals"],
@@ -1812,8 +1848,97 @@ this.globalThis.solanaWeb3 = (function (exports) {
1812
1848
  ["data", "parsed", "info", "commission"],
1813
1849
  ["data", "parsed", "info", "votes", KEYPATH_WILDCARD, "confirmationCount"]
1814
1850
  ];
1815
- memoizedKeypaths = {
1851
+ memoizedResponseKeypaths = {
1816
1852
  getAccountInfo: jsonParsedAccountsConfigs.map((c) => ["value", ...c]),
1853
+ getBlock: [
1854
+ ["blockTime"],
1855
+ ["transactions", KEYPATH_WILDCARD, "meta", "preTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
1856
+ [
1857
+ "transactions",
1858
+ KEYPATH_WILDCARD,
1859
+ "meta",
1860
+ "preTokenBalances",
1861
+ KEYPATH_WILDCARD,
1862
+ "uiTokenAmount",
1863
+ "decimals"
1864
+ ],
1865
+ ["transactions", KEYPATH_WILDCARD, "meta", "postTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
1866
+ [
1867
+ "transactions",
1868
+ KEYPATH_WILDCARD,
1869
+ "meta",
1870
+ "postTokenBalances",
1871
+ KEYPATH_WILDCARD,
1872
+ "uiTokenAmount",
1873
+ "decimals"
1874
+ ],
1875
+ ["transactions", KEYPATH_WILDCARD, "meta", "rewards", KEYPATH_WILDCARD, "commission"],
1876
+ ["transactions", KEYPATH_WILDCARD, "meta", "innerInstructions", KEYPATH_WILDCARD, "index"],
1877
+ [
1878
+ "transactions",
1879
+ KEYPATH_WILDCARD,
1880
+ "meta",
1881
+ "innerInstructions",
1882
+ KEYPATH_WILDCARD,
1883
+ "instructions",
1884
+ KEYPATH_WILDCARD,
1885
+ "programIdIndex"
1886
+ ],
1887
+ [
1888
+ "transactions",
1889
+ KEYPATH_WILDCARD,
1890
+ "meta",
1891
+ "innerInstructions",
1892
+ KEYPATH_WILDCARD,
1893
+ "instructions",
1894
+ KEYPATH_WILDCARD,
1895
+ "accounts",
1896
+ KEYPATH_WILDCARD
1897
+ ],
1898
+ [
1899
+ "transactions",
1900
+ KEYPATH_WILDCARD,
1901
+ "transaction",
1902
+ "message",
1903
+ "addressTableLookups",
1904
+ KEYPATH_WILDCARD,
1905
+ "writableIndexes",
1906
+ KEYPATH_WILDCARD
1907
+ ],
1908
+ [
1909
+ "transactions",
1910
+ KEYPATH_WILDCARD,
1911
+ "transaction",
1912
+ "message",
1913
+ "addressTableLookups",
1914
+ KEYPATH_WILDCARD,
1915
+ "readonlyIndexes",
1916
+ KEYPATH_WILDCARD
1917
+ ],
1918
+ [
1919
+ "transactions",
1920
+ KEYPATH_WILDCARD,
1921
+ "transaction",
1922
+ "message",
1923
+ "instructions",
1924
+ KEYPATH_WILDCARD,
1925
+ "programIdIndex"
1926
+ ],
1927
+ [
1928
+ "transactions",
1929
+ KEYPATH_WILDCARD,
1930
+ "transaction",
1931
+ "message",
1932
+ "instructions",
1933
+ KEYPATH_WILDCARD,
1934
+ "accounts",
1935
+ KEYPATH_WILDCARD
1936
+ ],
1937
+ ["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numReadonlySignedAccounts"],
1938
+ ["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numReadonlyUnsignedAccounts"],
1939
+ ["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numRequiredSignatures"],
1940
+ ["rewards", KEYPATH_WILDCARD, "commission"]
1941
+ ],
1817
1942
  getBlockTime: [[]],
1818
1943
  getClusterNodes: [
1819
1944
  [KEYPATH_WILDCARD, "featureSet"],
@@ -1899,7 +2024,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1899
2024
  simulateTransaction: jsonParsedAccountsConfigs.map((c) => ["value", "accounts", KEYPATH_WILDCARD, ...c])
1900
2025
  };
1901
2026
  }
1902
- return memoizedKeypaths;
2027
+ return memoizedResponseKeypaths;
1903
2028
  }
1904
2029
  function getNextAllowedKeypaths(keyPaths, property) {
1905
2030
  return keyPaths.filter((keyPath) => keyPath[0] === KEYPATH_WILDCARD && typeof property === "number" || keyPath[0] === property).map((keyPath) => keyPath.slice(1));
@@ -1927,7 +2052,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
1927
2052
  }
1928
2053
  }
1929
2054
  function patchResponseForSolanaLabsRpc(rawResponse, methodName) {
1930
- const allowedKeypaths = methodName ? getAllowedNumericKeypaths()[methodName] : void 0;
2055
+ const allowedKeypaths = methodName ? getAllowedNumericKeypathsForResponse()[methodName] : void 0;
2056
+ return visitNode2(rawResponse, allowedKeypaths ?? []);
2057
+ }
2058
+ function patchResponseForSolanaLabsRpcSubscriptions(rawResponse, methodName) {
2059
+ const allowedKeypaths = methodName ? getAllowedNumericKeypathsForNotification()[methodName] : void 0;
1931
2060
  return visitNode2(rawResponse, allowedKeypaths ?? []);
1932
2061
  }
1933
2062
  function createSolanaRpcApi(config) {
@@ -1956,6 +2085,36 @@ this.globalThis.solanaWeb3 = (function (exports) {
1956
2085
  }
1957
2086
  });
1958
2087
  }
2088
+ function createSolanaRpcSubscriptionsApi(config) {
2089
+ return new Proxy({}, {
2090
+ defineProperty() {
2091
+ return false;
2092
+ },
2093
+ deleteProperty() {
2094
+ return false;
2095
+ },
2096
+ get(...args) {
2097
+ const [_, p] = args;
2098
+ const notificationName = p.toString();
2099
+ return function(...rawParams) {
2100
+ const handleIntegerOverflow = config?.onIntegerOverflow;
2101
+ const params = patchParamsForSolanaLabsRpc(
2102
+ rawParams,
2103
+ handleIntegerOverflow ? (keyPath, value) => handleIntegerOverflow(notificationName, keyPath, value) : void 0
2104
+ );
2105
+ return {
2106
+ params,
2107
+ responseProcessor: (rawResponse) => patchResponseForSolanaLabsRpcSubscriptions(rawResponse, notificationName),
2108
+ subscribeMethodName: notificationName.replace(/Notifications$/, "Subscribe"),
2109
+ unsubscribeMethodName: notificationName.replace(/Notifications$/, "Unsubscribe")
2110
+ };
2111
+ };
2112
+ }
2113
+ });
2114
+ }
2115
+ function createSolanaRpcSubscriptionsApi_UNSTABLE(config) {
2116
+ return createSolanaRpcSubscriptionsApi(config);
2117
+ }
1959
2118
 
1960
2119
  // ../rpc-transport/dist/index.browser.js
1961
2120
  init_env_shim();
@@ -2022,6 +2181,100 @@ this.globalThis.solanaWeb3 = (function (exports) {
2022
2181
  function createJsonRpc(rpcConfig) {
2023
2182
  return makeProxy(rpcConfig);
2024
2183
  }
2184
+ function registerIterableCleanup(iterable, cleanupFn) {
2185
+ (async () => {
2186
+ try {
2187
+ for await (const _ of iterable)
2188
+ ;
2189
+ } catch {
2190
+ } finally {
2191
+ cleanupFn();
2192
+ }
2193
+ })();
2194
+ }
2195
+ function createPendingRpcSubscription(rpcConfig, { params, subscribeMethodName, unsubscribeMethodName, responseProcessor }) {
2196
+ return {
2197
+ async subscribe({ abortSignal }) {
2198
+ abortSignal.throwIfAborted();
2199
+ let subscriptionId;
2200
+ function handleCleanup() {
2201
+ if (subscriptionId !== void 0) {
2202
+ const payload = createJsonRpcMessage(unsubscribeMethodName, [subscriptionId]);
2203
+ connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload).finally(() => {
2204
+ connectionAbortController.abort();
2205
+ });
2206
+ } else {
2207
+ connectionAbortController.abort();
2208
+ }
2209
+ }
2210
+ abortSignal.addEventListener("abort", handleCleanup);
2211
+ const connectionAbortController = new AbortController();
2212
+ const subscribeMessage = createJsonRpcMessage(subscribeMethodName, params);
2213
+ const connection = await rpcConfig.transport({
2214
+ payload: subscribeMessage,
2215
+ signal: connectionAbortController.signal
2216
+ });
2217
+ function handleConnectionCleanup() {
2218
+ abortSignal.removeEventListener("abort", handleCleanup);
2219
+ }
2220
+ registerIterableCleanup(connection, handleConnectionCleanup);
2221
+ for await (const message of connection) {
2222
+ if ("id" in message && message.id === subscribeMessage.id) {
2223
+ if ("error" in message) {
2224
+ throw new SolanaJsonRpcError(message.error);
2225
+ } else {
2226
+ subscriptionId = message.result;
2227
+ break;
2228
+ }
2229
+ }
2230
+ }
2231
+ if (subscriptionId == null) {
2232
+ throw new Error("Failed to obtain a subscription id from the server");
2233
+ }
2234
+ return {
2235
+ async *[Symbol.asyncIterator]() {
2236
+ for await (const message of connection) {
2237
+ if (!("params" in message) || message.params.subscription !== subscriptionId) {
2238
+ continue;
2239
+ }
2240
+ const notification = message.params.result;
2241
+ yield responseProcessor ? responseProcessor(notification) : notification;
2242
+ }
2243
+ }
2244
+ };
2245
+ }
2246
+ };
2247
+ }
2248
+ function makeProxy2(rpcConfig) {
2249
+ return new Proxy(rpcConfig.api, {
2250
+ defineProperty() {
2251
+ return false;
2252
+ },
2253
+ deleteProperty() {
2254
+ return false;
2255
+ },
2256
+ get(target, p, receiver) {
2257
+ return function(...rawParams) {
2258
+ const methodName = p.toString();
2259
+ const createRpcSubscription = Reflect.get(target, methodName, receiver);
2260
+ if (p.toString().endsWith("Notifications") === false && !createRpcSubscription) {
2261
+ throw new Error(
2262
+ "Either the notification name must end in 'Notifications' or the API must supply a subscription creator function to map between the notification name and the subscribe/unsubscribe method names."
2263
+ );
2264
+ }
2265
+ const newRequest = createRpcSubscription ? createRpcSubscription(...rawParams) : {
2266
+ params: rawParams,
2267
+ subscribeMethodName: methodName.replace(/Notifications$/, "Subscribe"),
2268
+ unsubscribeMethodName: methodName.replace(/Notifications$/, "Unsubscribe")
2269
+ };
2270
+ return createPendingRpcSubscription(rpcConfig, newRequest);
2271
+ };
2272
+ }
2273
+ });
2274
+ }
2275
+ function createJsonSubscriptionRpc(rpcConfig) {
2276
+ return makeProxy2(rpcConfig);
2277
+ }
2025
2278
  var e = globalThis.fetch;
2026
2279
  var SolanaHttpError = class extends Error {
2027
2280
  constructor(details) {
@@ -2120,6 +2373,175 @@ this.globalThis.solanaWeb3 = (function (exports) {
2120
2373
  return await response.json();
2121
2374
  };
2122
2375
  }
2376
+ var e2 = globalThis.WebSocket;
2377
+ var EXPLICIT_ABORT_TOKEN = Symbol(
2378
+ "This symbol is thrown from a socket's iterator when the connection is explicity aborted by the user"
2379
+ );
2380
+ async function createWebSocketConnection({
2381
+ sendBufferHighWatermark,
2382
+ signal,
2383
+ url
2384
+ }) {
2385
+ return new Promise((resolve, reject) => {
2386
+ signal.addEventListener("abort", handleAbort, { once: true });
2387
+ const iteratorState = /* @__PURE__ */ new Map();
2388
+ function errorAndClearAllIteratorStates(reason) {
2389
+ const errorCallbacks = [...iteratorState.values()].filter((state) => state.__hasPolled).map(({ onError }) => onError);
2390
+ iteratorState.clear();
2391
+ errorCallbacks.forEach((cb) => {
2392
+ try {
2393
+ cb(reason);
2394
+ } catch {
2395
+ }
2396
+ });
2397
+ }
2398
+ function handleAbort() {
2399
+ errorAndClearAllIteratorStates(EXPLICIT_ABORT_TOKEN);
2400
+ if (webSocket.readyState !== e2.CLOSED && webSocket.readyState !== e2.CLOSING) {
2401
+ webSocket.close(1e3);
2402
+ }
2403
+ }
2404
+ function handleClose(ev) {
2405
+ bufferDrainWatcher?.onCancel();
2406
+ signal.removeEventListener("abort", handleAbort);
2407
+ webSocket.removeEventListener("close", handleClose);
2408
+ webSocket.removeEventListener("error", handleError);
2409
+ webSocket.removeEventListener("open", handleOpen);
2410
+ webSocket.removeEventListener("message", handleMessage);
2411
+ errorAndClearAllIteratorStates(ev);
2412
+ }
2413
+ function handleError(ev) {
2414
+ if (!hasConnected) {
2415
+ reject(
2416
+ // TODO: Coded error
2417
+ new Error("WebSocket failed to connect", { cause: ev })
2418
+ );
2419
+ }
2420
+ }
2421
+ let hasConnected = false;
2422
+ let bufferDrainWatcher;
2423
+ function handleOpen() {
2424
+ hasConnected = true;
2425
+ resolve({
2426
+ async send(payload) {
2427
+ const message = JSON.stringify(payload);
2428
+ if (!bufferDrainWatcher && webSocket.readyState === e2.OPEN && webSocket.bufferedAmount > sendBufferHighWatermark) {
2429
+ let onCancel;
2430
+ const promise = new Promise((resolve2, reject2) => {
2431
+ const intervalId = setInterval(() => {
2432
+ if (webSocket.readyState !== e2.OPEN || !(webSocket.bufferedAmount > sendBufferHighWatermark)) {
2433
+ clearInterval(intervalId);
2434
+ bufferDrainWatcher = void 0;
2435
+ resolve2();
2436
+ }
2437
+ }, 16);
2438
+ onCancel = () => {
2439
+ bufferDrainWatcher = void 0;
2440
+ clearInterval(intervalId);
2441
+ reject2(
2442
+ // TODO: Coded error
2443
+ new Error("WebSocket was closed before payload could be sent")
2444
+ );
2445
+ };
2446
+ });
2447
+ bufferDrainWatcher = {
2448
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2449
+ // @ts-ignore
2450
+ onCancel,
2451
+ promise
2452
+ };
2453
+ }
2454
+ if (bufferDrainWatcher) {
2455
+ await bufferDrainWatcher.promise;
2456
+ }
2457
+ webSocket.send(message);
2458
+ },
2459
+ async *[Symbol.asyncIterator]() {
2460
+ const iteratorKey = Symbol();
2461
+ iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] });
2462
+ try {
2463
+ while (true) {
2464
+ const state = iteratorState.get(iteratorKey);
2465
+ if (!state) {
2466
+ throw new Error("Invariant: WebSocket message iterator is missing state storage");
2467
+ }
2468
+ if (state.__hasPolled) {
2469
+ throw new Error(
2470
+ "Invariant: WebSocket message iterator state is corrupt; iterated without first resolving existing message promise"
2471
+ );
2472
+ }
2473
+ const queuedMessages = state.queuedMessages;
2474
+ if (queuedMessages.length) {
2475
+ state.queuedMessages = [];
2476
+ yield* queuedMessages;
2477
+ } else {
2478
+ try {
2479
+ yield await new Promise((resolve2, reject2) => {
2480
+ iteratorState.set(iteratorKey, {
2481
+ __hasPolled: true,
2482
+ onError: reject2,
2483
+ onMessage: resolve2
2484
+ });
2485
+ });
2486
+ } catch (e3) {
2487
+ if (e3 === EXPLICIT_ABORT_TOKEN) {
2488
+ return;
2489
+ } else {
2490
+ throw new Error("WebSocket connection closed", { cause: e3 });
2491
+ }
2492
+ }
2493
+ }
2494
+ }
2495
+ } finally {
2496
+ iteratorState.delete(iteratorKey);
2497
+ }
2498
+ }
2499
+ });
2500
+ }
2501
+ function handleMessage({ data }) {
2502
+ const message = JSON.parse(data);
2503
+ iteratorState.forEach((state, iteratorKey) => {
2504
+ if (state.__hasPolled) {
2505
+ const { onMessage } = state;
2506
+ iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] });
2507
+ onMessage(message);
2508
+ } else {
2509
+ state.queuedMessages.push(message);
2510
+ }
2511
+ });
2512
+ }
2513
+ const webSocket = new e2(url);
2514
+ webSocket.addEventListener("close", handleClose);
2515
+ webSocket.addEventListener("error", handleError);
2516
+ webSocket.addEventListener("open", handleOpen);
2517
+ webSocket.addEventListener("message", handleMessage);
2518
+ });
2519
+ }
2520
+ function createWebSocketTransport({ sendBufferHighWatermark, url }) {
2521
+ if (/^wss?:/i.test(url) === false) {
2522
+ const protocolMatch = url.match(/^([^:]+):/);
2523
+ throw new DOMException(
2524
+ protocolMatch ? `Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. '${protocolMatch[1]}:' is not allowed.` : `Failed to construct 'WebSocket': The URL '${url}' is invalid.`
2525
+ );
2526
+ }
2527
+ return async function sendWebSocketMessage({ payload, signal }) {
2528
+ signal?.throwIfAborted();
2529
+ const connection = await createWebSocketConnection({
2530
+ sendBufferHighWatermark,
2531
+ signal,
2532
+ url
2533
+ });
2534
+ signal?.throwIfAborted();
2535
+ await connection.send(payload);
2536
+ return {
2537
+ [Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
2538
+ send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: connection.send.bind(connection)
2539
+ };
2540
+ };
2541
+ }
2542
+
2543
+ // src/rpc.ts
2544
+ var import_fast_stable_stringify = __toESM(require_fast_stable_stringify(), 1);
2123
2545
 
2124
2546
  // src/rpc-default-config.ts
2125
2547
  init_env_shim();
@@ -2161,6 +2583,197 @@ this.globalThis.solanaWeb3 = (function (exports) {
2161
2583
  }
2162
2584
  };
2163
2585
 
2586
+ // src/rpc-subscription-coalescer.ts
2587
+ init_env_shim();
2588
+
2589
+ // src/cached-abortable-iterable.ts
2590
+ init_env_shim();
2591
+ function registerIterableCleanup2(iterable, cleanupFn) {
2592
+ (async () => {
2593
+ try {
2594
+ for await (const _ of iterable)
2595
+ ;
2596
+ } catch {
2597
+ } finally {
2598
+ cleanupFn();
2599
+ }
2600
+ })();
2601
+ }
2602
+ function getCachedAbortableIterableFactory({
2603
+ getAbortSignalFromInputArgs,
2604
+ getCacheEntryMissingError,
2605
+ getCacheKeyFromInputArgs,
2606
+ onCacheHit,
2607
+ onCreateIterable
2608
+ }) {
2609
+ const cache = /* @__PURE__ */ new Map();
2610
+ function getCacheEntryOrThrow(cacheKey) {
2611
+ const currentCacheEntry = cache.get(cacheKey);
2612
+ if (!currentCacheEntry) {
2613
+ throw getCacheEntryMissingError(cacheKey);
2614
+ }
2615
+ return currentCacheEntry;
2616
+ }
2617
+ return async (...args) => {
2618
+ const cacheKey = getCacheKeyFromInputArgs(...args);
2619
+ const signal = getAbortSignalFromInputArgs(...args);
2620
+ if (cacheKey === void 0) {
2621
+ return await onCreateIterable(signal, ...args);
2622
+ }
2623
+ const cleanup = () => {
2624
+ cache.delete(cacheKey);
2625
+ signal.removeEventListener("abort", handleAbort);
2626
+ };
2627
+ const handleAbort = () => {
2628
+ const cacheEntry = getCacheEntryOrThrow(cacheKey);
2629
+ if (cacheEntry.purgeScheduled !== true) {
2630
+ cacheEntry.purgeScheduled = true;
2631
+ globalThis.queueMicrotask(() => {
2632
+ cacheEntry.purgeScheduled = false;
2633
+ if (cacheEntry.referenceCount === 0) {
2634
+ cacheEntry.abortController.abort();
2635
+ cleanup();
2636
+ }
2637
+ });
2638
+ }
2639
+ cacheEntry.referenceCount--;
2640
+ };
2641
+ signal.addEventListener("abort", handleAbort);
2642
+ try {
2643
+ const cacheEntry = cache.get(cacheKey);
2644
+ if (!cacheEntry) {
2645
+ const singletonAbortController = new AbortController();
2646
+ const newIterablePromise = onCreateIterable(singletonAbortController.signal, ...args);
2647
+ const newCacheEntry = {
2648
+ abortController: singletonAbortController,
2649
+ iterable: newIterablePromise,
2650
+ purgeScheduled: false,
2651
+ referenceCount: 1
2652
+ };
2653
+ cache.set(cacheKey, newCacheEntry);
2654
+ const newIterable = await newIterablePromise;
2655
+ registerIterableCleanup2(newIterable, cleanup);
2656
+ newCacheEntry.iterable = newIterable;
2657
+ return newIterable;
2658
+ } else {
2659
+ cacheEntry.referenceCount++;
2660
+ const iterableOrIterablePromise = cacheEntry.iterable;
2661
+ const cachedIterable = "then" in iterableOrIterablePromise ? await iterableOrIterablePromise : iterableOrIterablePromise;
2662
+ await onCacheHit(cachedIterable, ...args);
2663
+ return cachedIterable;
2664
+ }
2665
+ } catch (e3) {
2666
+ cleanup();
2667
+ throw e3;
2668
+ }
2669
+ };
2670
+ }
2671
+
2672
+ // src/rpc-subscription-coalescer.ts
2673
+ var EXPLICIT_ABORT_TOKEN2 = Symbol(
2674
+ "This symbol is thrown from a subscription's iterator when the subscription is explicitly aborted by the user"
2675
+ );
2676
+ function registerIterableCleanup3(iterable, cleanupFn) {
2677
+ (async () => {
2678
+ try {
2679
+ for await (const _ of iterable)
2680
+ ;
2681
+ } catch {
2682
+ } finally {
2683
+ cleanupFn();
2684
+ }
2685
+ })();
2686
+ }
2687
+ function getRpcSubscriptionsWithSubscriptionCoalescing({
2688
+ getDeduplicationKey,
2689
+ rpcSubscriptions
2690
+ }) {
2691
+ const cache = /* @__PURE__ */ new Map();
2692
+ return new Proxy(rpcSubscriptions, {
2693
+ defineProperty() {
2694
+ return false;
2695
+ },
2696
+ deleteProperty() {
2697
+ return false;
2698
+ },
2699
+ get(target, p, receiver) {
2700
+ const subscriptionMethod = Reflect.get(target, p, receiver);
2701
+ if (typeof subscriptionMethod !== "function") {
2702
+ return subscriptionMethod;
2703
+ }
2704
+ return function(...rawParams) {
2705
+ const deduplicationKey = getDeduplicationKey(p, rawParams);
2706
+ if (deduplicationKey === void 0) {
2707
+ return subscriptionMethod(...rawParams);
2708
+ }
2709
+ if (cache.has(deduplicationKey)) {
2710
+ return cache.get(deduplicationKey);
2711
+ }
2712
+ const iterableFactory = getCachedAbortableIterableFactory({
2713
+ getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
2714
+ getCacheEntryMissingError(deduplicationKey2) {
2715
+ return new Error(
2716
+ `Found no cache entry for subscription with deduplication key \`${deduplicationKey2?.toString()}\``
2717
+ );
2718
+ },
2719
+ getCacheKeyFromInputArgs: () => deduplicationKey,
2720
+ async onCacheHit(_iterable, _config) {
2721
+ },
2722
+ async onCreateIterable(abortSignal, config) {
2723
+ const pendingSubscription2 = subscriptionMethod(
2724
+ ...rawParams
2725
+ );
2726
+ const iterable = await pendingSubscription2.subscribe({
2727
+ ...config,
2728
+ abortSignal
2729
+ });
2730
+ registerIterableCleanup3(iterable, () => {
2731
+ cache.delete(deduplicationKey);
2732
+ });
2733
+ return iterable;
2734
+ }
2735
+ });
2736
+ const pendingSubscription = {
2737
+ async subscribe(...args) {
2738
+ const iterable = await iterableFactory(...args);
2739
+ const { abortSignal } = args[0];
2740
+ let abortPromise;
2741
+ return {
2742
+ ...iterable,
2743
+ async *[Symbol.asyncIterator]() {
2744
+ abortPromise || (abortPromise = abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN2) : new Promise((_, reject) => {
2745
+ abortSignal.addEventListener("abort", () => {
2746
+ reject(EXPLICIT_ABORT_TOKEN2);
2747
+ });
2748
+ }));
2749
+ try {
2750
+ const iterator = iterable[Symbol.asyncIterator]();
2751
+ while (true) {
2752
+ const iteratorResult = await Promise.race([iterator.next(), abortPromise]);
2753
+ if (iteratorResult.done) {
2754
+ return;
2755
+ } else {
2756
+ yield iteratorResult.value;
2757
+ }
2758
+ }
2759
+ } catch (e3) {
2760
+ if (e3 === EXPLICIT_ABORT_TOKEN2) {
2761
+ return;
2762
+ }
2763
+ cache.delete(deduplicationKey);
2764
+ throw e3;
2765
+ }
2766
+ }
2767
+ };
2768
+ }
2769
+ };
2770
+ cache.set(deduplicationKey, pendingSubscription);
2771
+ return pendingSubscription;
2772
+ };
2773
+ }
2774
+ });
2775
+ }
2776
+
2164
2777
  // src/rpc.ts
2165
2778
  function createSolanaRpc(config) {
2166
2779
  return createJsonRpc({
@@ -2168,6 +2781,24 @@ this.globalThis.solanaWeb3 = (function (exports) {
2168
2781
  api: createSolanaRpcApi(DEFAULT_RPC_CONFIG)
2169
2782
  });
2170
2783
  }
2784
+ function createSolanaRpcSubscriptions(config) {
2785
+ return pipe(
2786
+ createJsonSubscriptionRpc({
2787
+ ...config,
2788
+ api: createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
2789
+ }),
2790
+ (rpcSubscriptions) => getRpcSubscriptionsWithSubscriptionCoalescing({
2791
+ getDeduplicationKey: (...args) => (0, import_fast_stable_stringify.default)(args),
2792
+ rpcSubscriptions
2793
+ })
2794
+ );
2795
+ }
2796
+ function createSolanaRpcSubscriptions_UNSTABLE(config) {
2797
+ return createJsonSubscriptionRpc({
2798
+ ...config,
2799
+ api: createSolanaRpcSubscriptionsApi_UNSTABLE(DEFAULT_RPC_CONFIG)
2800
+ });
2801
+ }
2171
2802
 
2172
2803
  // src/rpc-transport.ts
2173
2804
  init_env_shim();
@@ -2227,14 +2858,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
2227
2858
 
2228
2859
  // src/rpc-request-deduplication.ts
2229
2860
  init_env_shim();
2230
- var import_fast_stable_stringify = __toESM(require_fast_stable_stringify(), 1);
2231
- function getSolanaRpcPayloadDeduplicationKey(payload) {
2861
+ var import_fast_stable_stringify2 = __toESM(require_fast_stable_stringify(), 1);
2862
+ function isJsonRpcPayload(payload) {
2232
2863
  if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
2233
- return;
2234
- }
2235
- if ("jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && "params" in payload) {
2236
- return (0, import_fast_stable_stringify.default)([payload.method, payload.params]);
2864
+ return false;
2237
2865
  }
2866
+ return "jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && typeof payload.method === "string" && "params" in payload;
2867
+ }
2868
+ function getSolanaRpcPayloadDeduplicationKey(payload) {
2869
+ return isJsonRpcPayload(payload) ? (0, import_fast_stable_stringify2.default)([payload.method, payload.params]) : void 0;
2238
2870
  }
2239
2871
 
2240
2872
  // src/rpc-transport.ts
@@ -2246,7 +2878,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
2246
2878
  return out;
2247
2879
  }
2248
2880
  function createDefaultRpcTransport(config) {
2249
- return getRpcTransportWithRequestCoalescing(
2881
+ return pipe(
2250
2882
  createHttpTransport({
2251
2883
  ...config,
2252
2884
  headers: {
@@ -2257,18 +2889,129 @@ this.globalThis.solanaWeb3 = (function (exports) {
2257
2889
  }
2258
2890
  }
2259
2891
  }),
2260
- getSolanaRpcPayloadDeduplicationKey
2892
+ (transport) => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
2893
+ );
2894
+ }
2895
+
2896
+ // src/rpc-websocket-transport.ts
2897
+ init_env_shim();
2898
+
2899
+ // src/rpc-websocket-autopinger.ts
2900
+ init_env_shim();
2901
+ var PING_PAYLOAD = {
2902
+ jsonrpc: "2.0",
2903
+ method: "ping"
2904
+ };
2905
+ function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
2906
+ const pingableConnections = /* @__PURE__ */ new Map();
2907
+ return async (...args) => {
2908
+ const connection = await transport(...args);
2909
+ let intervalId;
2910
+ function sendPing() {
2911
+ connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
2912
+ }
2913
+ function restartPingTimer() {
2914
+ clearInterval(intervalId);
2915
+ intervalId = setInterval(sendPing, intervalMs);
2916
+ }
2917
+ if (pingableConnections.has(connection) === false) {
2918
+ pingableConnections.set(connection, {
2919
+ [Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
2920
+ send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: (...args2) => {
2921
+ restartPingTimer();
2922
+ return connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(...args2);
2923
+ }
2924
+ });
2925
+ (async () => {
2926
+ try {
2927
+ for await (const _ of connection) {
2928
+ restartPingTimer();
2929
+ }
2930
+ } catch {
2931
+ } finally {
2932
+ pingableConnections.delete(connection);
2933
+ clearInterval(intervalId);
2934
+ if (handleOffline) {
2935
+ globalThis.window.removeEventListener("offline", handleOffline);
2936
+ }
2937
+ if (handleOnline) {
2938
+ globalThis.window.removeEventListener("online", handleOnline);
2939
+ }
2940
+ }
2941
+ })();
2942
+ if (globalThis.navigator.onLine) {
2943
+ restartPingTimer();
2944
+ }
2945
+ let handleOffline;
2946
+ let handleOnline;
2947
+ {
2948
+ handleOffline = () => {
2949
+ clearInterval(intervalId);
2950
+ };
2951
+ handleOnline = () => {
2952
+ sendPing();
2953
+ restartPingTimer();
2954
+ };
2955
+ globalThis.window.addEventListener("offline", handleOffline);
2956
+ globalThis.window.addEventListener("online", handleOnline);
2957
+ }
2958
+ }
2959
+ return pingableConnections.get(connection);
2960
+ };
2961
+ }
2962
+
2963
+ // src/rpc-websocket-connection-sharding.ts
2964
+ init_env_shim();
2965
+ var NULL_SHARD_CACHE_KEY = Symbol(
2966
+ "Cache key to use when there is no connection sharding strategy"
2967
+ );
2968
+ function getWebSocketTransportWithConnectionSharding({ getShard, transport }) {
2969
+ return getCachedAbortableIterableFactory({
2970
+ getAbortSignalFromInputArgs: ({ signal }) => signal,
2971
+ getCacheEntryMissingError(shardKey) {
2972
+ return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
2973
+ },
2974
+ getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
2975
+ onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
2976
+ onCreateIterable: (abortSignal, config) => transport({
2977
+ ...config,
2978
+ signal: abortSignal
2979
+ })
2980
+ });
2981
+ }
2982
+
2983
+ // src/rpc-websocket-transport.ts
2984
+ function createDefaultRpcSubscriptionsTransport(config) {
2985
+ const { getShard, intervalMs, ...rest } = config;
2986
+ return pipe(
2987
+ createWebSocketTransport({
2988
+ ...rest,
2989
+ sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
2990
+ 131072
2991
+ }),
2992
+ (transport) => getWebSocketTransportWithAutoping({
2993
+ intervalMs: intervalMs ?? 5e3,
2994
+ transport
2995
+ }),
2996
+ (transport) => getWebSocketTransportWithConnectionSharding({
2997
+ getShard,
2998
+ transport
2999
+ })
2261
3000
  );
2262
3001
  }
2263
3002
 
2264
3003
  exports.AccountRole = AccountRole;
3004
+ exports.address = address;
2265
3005
  exports.appendTransactionInstruction = appendTransactionInstruction;
2266
3006
  exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
2267
3007
  exports.assertIsBlockhash = assertIsBlockhash;
2268
3008
  exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
2269
3009
  exports.createAddressWithSeed = createAddressWithSeed;
3010
+ exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
2270
3011
  exports.createDefaultRpcTransport = createDefaultRpcTransport;
2271
3012
  exports.createSolanaRpc = createSolanaRpc;
3013
+ exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
3014
+ exports.createSolanaRpcSubscriptions_UNSTABLE = createSolanaRpcSubscriptions_UNSTABLE;
2272
3015
  exports.createTransaction = createTransaction;
2273
3016
  exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
2274
3017
  exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
@@ -2278,6 +3021,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
2278
3021
  exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
2279
3022
  exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
2280
3023
  exports.getProgramDerivedAddress = getProgramDerivedAddress;
3024
+ exports.isBase58EncodedAddress = isBase58EncodedAddress;
2281
3025
  exports.isSignerRole = isSignerRole;
2282
3026
  exports.isWritableRole = isWritableRole;
2283
3027
  exports.mergeRoles = mergeRoles;