@solana/web3.js 2.0.0-experimental.7d44763 → 2.0.0-experimental.7d67615

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