@solana/kit 6.10.0-canary-20260514084615 → 6.10.0

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.
@@ -344,6 +344,95 @@ async function decompileTransactionMessageFetchingLookupTables(compiledTransacti
344
344
  lastValidBlockHeight
345
345
  });
346
346
  }
347
+ var PROVISORY_LIMIT = 0;
348
+ var MAX_COMPUTE_UNIT_LIMIT2 = 14e5;
349
+ var MAX_LOADED_ACCOUNTS_DATA_SIZE_LIMIT = 64 * 1024 * 1024;
350
+ function estimateResourceLimitsFactory({
351
+ rpc
352
+ }) {
353
+ return async function estimateResourceLimits(transactionMessage, config) {
354
+ const { abortSignal, ...simulateConfig } = config ?? {};
355
+ const replaceRecentBlockhash = !transactionMessages.isTransactionMessageWithDurableNonceLifetime(transactionMessage);
356
+ const isDataSizeRequired = transactionMessage.version === 1;
357
+ const transaction = functional.pipe(
358
+ transactionMessage,
359
+ (m) => transactionMessages.setTransactionMessageComputeUnitLimit(MAX_COMPUTE_UNIT_LIMIT2, m),
360
+ (m) => isDataSizeRequired ? transactionMessages.setTransactionMessageLoadedAccountsDataSizeLimit(MAX_LOADED_ACCOUNTS_DATA_SIZE_LIMIT, m) : m,
361
+ transactions.compileTransaction
362
+ );
363
+ const wireTransactionBytes = transactions.getBase64EncodedWireTransaction(transaction);
364
+ try {
365
+ const response = await rpc.simulateTransaction(wireTransactionBytes, {
366
+ ...simulateConfig,
367
+ encoding: "base64",
368
+ replaceRecentBlockhash,
369
+ sigVerify: false
370
+ }).send({ abortSignal });
371
+ const { err: transactionError, ...simulationResult } = response.value;
372
+ if (simulationResult.unitsConsumed == null) {
373
+ throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT);
374
+ }
375
+ if (isDataSizeRequired && simulationResult.loadedAccountsDataSize == null) {
376
+ throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_LOADED_ACCOUNTS_DATA_SIZE_LIMIT);
377
+ }
378
+ if (transactionError) {
379
+ throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_RESOURCE_LIMITS, {
380
+ ...simulationResult,
381
+ cause: errors.getSolanaErrorFromTransactionError(transactionError)
382
+ });
383
+ }
384
+ const computeUnitLimit = simulationResult.unitsConsumed > 4294967295n ? 4294967295 : Number(simulationResult.unitsConsumed);
385
+ if (isDataSizeRequired) {
386
+ return {
387
+ computeUnitLimit,
388
+ loadedAccountsDataSizeLimit: simulationResult.loadedAccountsDataSize
389
+ };
390
+ }
391
+ return simulationResult.loadedAccountsDataSize == null ? { computeUnitLimit } : { computeUnitLimit, loadedAccountsDataSizeLimit: simulationResult.loadedAccountsDataSize };
392
+ } catch (e) {
393
+ if (errors.isSolanaError(e, errors.SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_RESOURCE_LIMITS) || errors.isSolanaError(e, errors.SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_LOADED_ACCOUNTS_DATA_SIZE_LIMIT)) {
394
+ throw e;
395
+ }
396
+ throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, {
397
+ cause: e
398
+ });
399
+ }
400
+ };
401
+ }
402
+ function estimateAndSetResourceLimitsFactory(estimateResourceLimits) {
403
+ return async function estimateAndSetResourceLimits(transactionMessage, config) {
404
+ const existingComputeUnitLimit = transactionMessages.getTransactionMessageComputeUnitLimit(transactionMessage);
405
+ const computeUnitLimitIsExplicit = existingComputeUnitLimit !== void 0 && existingComputeUnitLimit !== PROVISORY_LIMIT && existingComputeUnitLimit !== MAX_COMPUTE_UNIT_LIMIT2;
406
+ const isV1 = transactionMessage.version === 1;
407
+ let loadedAccountsDataSizeLimitIsExplicit = true;
408
+ if (isV1) {
409
+ const existingLoadedAccountsDataSizeLimit = transactionMessages.getTransactionMessageLoadedAccountsDataSizeLimit(transactionMessage);
410
+ loadedAccountsDataSizeLimitIsExplicit = existingLoadedAccountsDataSizeLimit !== void 0 && existingLoadedAccountsDataSizeLimit !== PROVISORY_LIMIT;
411
+ }
412
+ if (computeUnitLimitIsExplicit && loadedAccountsDataSizeLimitIsExplicit) {
413
+ return transactionMessage;
414
+ }
415
+ const estimate = await estimateResourceLimits(transactionMessage, config);
416
+ let result = transactionMessage;
417
+ if (!computeUnitLimitIsExplicit) {
418
+ result = transactionMessages.setTransactionMessageComputeUnitLimit(estimate.computeUnitLimit, result);
419
+ }
420
+ if (isV1 && !loadedAccountsDataSizeLimitIsExplicit && "loadedAccountsDataSizeLimit" in estimate) {
421
+ result = transactionMessages.setTransactionMessageLoadedAccountsDataSizeLimit(estimate.loadedAccountsDataSizeLimit, result);
422
+ }
423
+ return result;
424
+ };
425
+ }
426
+ function fillTransactionMessageProvisoryResourceLimits(transactionMessage) {
427
+ let result = transactionMessage;
428
+ if (transactionMessages.getTransactionMessageComputeUnitLimit(result) === void 0) {
429
+ result = transactionMessages.setTransactionMessageComputeUnitLimit(PROVISORY_LIMIT, result);
430
+ }
431
+ if (result.version === 1 && transactionMessages.getTransactionMessageLoadedAccountsDataSizeLimit(result) === void 0) {
432
+ result = transactionMessages.setTransactionMessageLoadedAccountsDataSizeLimit(PROVISORY_LIMIT, result);
433
+ }
434
+ return result;
435
+ }
347
436
 
348
437
  // src/get-minimum-balance-for-rent-exemption.ts
349
438
  function getMinimumBalanceForRentExemption(space) {
@@ -543,9 +632,12 @@ exports.createAsyncGeneratorWithInitialValueAndSlotTracking = createAsyncGenerat
543
632
  exports.createReactiveStoreWithInitialValueAndSlotTracking = createReactiveStoreWithInitialValueAndSlotTracking;
544
633
  exports.decompileTransactionMessageFetchingLookupTables = decompileTransactionMessageFetchingLookupTables;
545
634
  exports.estimateAndSetComputeUnitLimitFactory = estimateAndSetComputeUnitLimitFactory;
635
+ exports.estimateAndSetResourceLimitsFactory = estimateAndSetResourceLimitsFactory;
546
636
  exports.estimateComputeUnitLimitFactory = estimateComputeUnitLimitFactory;
637
+ exports.estimateResourceLimitsFactory = estimateResourceLimitsFactory;
547
638
  exports.fetchAddressesForLookupTables = fetchAddressesForLookupTables;
548
639
  exports.fillTransactionMessageProvisoryComputeUnitLimit = fillTransactionMessageProvisoryComputeUnitLimit;
640
+ exports.fillTransactionMessageProvisoryResourceLimits = fillTransactionMessageProvisoryResourceLimits;
549
641
  exports.getMinimumBalanceForRentExemption = getMinimumBalanceForRentExemption;
550
642
  exports.sendAndConfirmDurableNonceTransactionFactory = sendAndConfirmDurableNonceTransactionFactory;
551
643
  exports.sendAndConfirmTransactionFactory = sendAndConfirmTransactionFactory;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/create-async-generator-with-initial-value-and-slot-tracking.ts","../src/create-reactive-store-with-initial-value-and-slot-tracking.ts","../src/airdrop-internal.ts","../src/airdrop.ts","../src/compute-unit-limit-estimation.ts","../src/fetch-lookup-tables.ts","../src/decompile-transaction-message-fetching-lookup-tables.ts","../src/get-minimum-balance-for-rent-exemption.ts","../src/send-transaction-internal.ts","../src/send-and-confirm-durable-nonce-transaction.ts","../src/send-and-confirm-transaction.ts","../src/send-transaction-without-confirming.ts"],"names":["createRecentSignatureConfirmationPromiseFactory","waitForRecentTransactionConfirmationUntilTimeout","getTimeoutPromise","isTransactionMessageWithDurableNonceLifetime","pipe","setTransactionMessageComputeUnitLimit","compileTransaction","getBase64EncodedWireTransaction","SolanaError","SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT","SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT","getSolanaErrorFromTransactionError","isSolanaError","getTransactionMessageComputeUnitLimit","fetchJsonParsedAccounts","assertAccountsDecoded","assertAccountsExist","decompileTransactionMessage","commitmentComparator","createNonceInvalidationPromiseFactory","SOLANA_ERROR__INVALID_NONCE","getSignatureFromTransaction","waitForDurableNonceTransactionConfirmation","createBlockHeightExceedencePromiseFactory","waitForRecentTransactionConfirmation"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA8EA,gBAAuB,mDAAA,CAA0F;AAAA,EAC7G,WAAA;AAAA,EACA,UAAA;AAAA,EACA,cAAA;AAAA,EACA,sBAAA;AAAA,EACA;AACJ,CAAA,EAEE;AACE,EAAA,IAAI,YAAY,OAAA,EAAS;AAEzB,EAAA,IAAI,iBAAiB,CAAC,EAAA;AAGtB,EAAA,MAAM,QAAoC,EAAC;AAC3C,EAAA,IAAI,cAAA,GAAqF,IAAA;AACzF,EAAA,IAAI,aAAA,GAAoD,IAAA;AACxD,EAAA,IAAI,OAAA,GAAU,KAAA;AACd,EAAA,IAAI,gBAAA,GAAmB,KAAA;AACvB,EAAA,IAAI,IAAA,GAAO,KAAA;AACX,EAAA,IAAI,YAAA;AAEJ,EAAA,SAAS,eAAA,GAAkB;AACvB,IAAA,IAAA,GAAO,IAAA;AACP,IAAA,IAAI,cAAA,EAAgB;AAChB,MAAA,MAAM,OAAA,GAAU,cAAA;AAChB,MAAA,cAAA,GAAiB,IAAA;AACjB,MAAA,aAAA,GAAgB,IAAA;AAChB,MAAA,OAAA,CAAQ,EAAE,IAAA,EAAM,IAAA,EAAM,KAAA,EAAO,QAAW,CAAA;AAAA,IAC5C;AAAA,EACJ;AAEA,EAAA,MAAM,eAAA,GAAkB,IAAI,eAAA,EAAgB;AAC5C,EAAA,MAAM,SAAS,eAAA,CAAgB,MAAA;AAE/B,EAAA,SAAS,OAAA,GAAU;AACf,IAAA,IAAA,GAAO,IAAA;AACP,IAAA,eAAA,CAAgB,KAAA,CAAM,YAAY,MAAM,CAAA;AACxC,IAAA,IAAI,cAAA,EAAgB;AAChB,MAAA,MAAM,OAAA,GAAU,cAAA;AAChB,MAAA,cAAA,GAAiB,IAAA;AACjB,MAAA,aAAA,GAAgB,IAAA;AAChB,MAAA,OAAA,CAAQ,EAAE,IAAA,E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AA;AAAA,EACL;AACA,EAAA,OAAO,eAAe,qCAAA,CAAsC,WAAA,EAAa,MAAA,EAAQ;AAC7E,IAAA,MAAM,iEAAA,CAAkE;AAAA,MACpE,GAAG,MAAA;AAAA,MACH,8BAAA;AAAA,MACA,GAAA;AAAA,MACA;AAAA,KACH,CAAA;AAAA,EACL,CAAA;AACJ;AC7GO,SAAS,gCAAA,CAAkG;AAAA,EAC9G,GAAA;AAAA,EACA;AACJ,CAAA,EAAkI;AAC9H,EAAA,MAAM,kCAAkCC,iEAAA,CAA0C;AAAA,IAC9E,GAAA;AAAA,IACA;AAAA,GACgE,CAAA;AACpE,EAAA,MAAM,wCAAwCvB,uEAAAA,CAAgD;AAAA,IAC1F,GAAA;AAAA,IACA;AAAA,GACsE,CAAA;AAC1E,EAAA,eAAe,yBACX,MAAA,EAIF;AACE,IAAA,MAAMwB,4DAAA,CAAqC;AAAA,MACvC,GAAG,MAAA;AAAA,MACH,+BAAA;AAAA,MACA;AAAA,KACH,CAAA;AAAA,EACL;AACA,EAAA,OAAO,eAAe,yBAAA,CAA0B,WAAA,EAAa,MAAA,EAAQ;AACjE,IAAA,MAAM,0EAAA,CAA2E;AAAA,MAC7E,GAAG,MAAA;AAAA,MACH,wBAAA;AAAA,MACA,GAAA;AAAA,MACA;AAAA,KACH,CAAA;AAAA,EACL,CAAA;AACJ;;;ACrDO,SAAS,uCAAA,CAAwC;AAAA,EACpD;AACJ,CAAA,EAA4F;AACxF,EAAA,OAAO,eAAe,gCAAA,CAAiC,WAAA,EAAa,MAAA,EAAQ;AACxE,IAAA,MAAM,2CAAA,CAA4C;AAAA,MAC9C,GAAG,MAAA;AAAA,MACH,GAAA;AAAA,MACA;AAAA,KACH,CAAA;AAAA,EACL,CAAA;AACJ","file":"index.browser.cjs","sourcesContent":["import type { PendingRpcRequest } from '@solana/rpc';\nimport type { PendingRpcSubscriptionsRequest } from '@solana/rpc-subscriptions';\nimport type { SolanaRpcResponse } from '@solana/rpc-types';\n\ntype CreateAsyncGeneratorWithInitialValueAndSlotTrackingConfig<TRpcValue, TSubscriptionValue, TItem> = Readonly<{\n /**\n * Triggering this abort signal will cancel the pending RPC request and subscription, and\n * cause the async generator to return (complete without error).\n */\n abortSignal: AbortSignal;\n /**\n * A pending RPC request whose response will be yielded as the generator's first value\n * (unless a subscription notification with a newer slot arrives first).\n * The response must be a {@link SolanaRpcResponse} so that its slot can be compared with\n * subscription notifications.\n */\n rpcRequest: PendingRpcRequest<SolanaRpcResponse<TRpcValue>>;\n /**\n * A pending RPC subscription request whose notifications will be yielded as they arrive.\n * Each notification must be a {@link SolanaRpcResponse} so that its slot can be compared\n * with the initial RPC response and other notifications.\n */\n rpcSubscriptionRequest: PendingRpcSubscriptionsRequest<SolanaRpcResponse<TSubscriptionValue>>;\n /**\n * Maps the value from a subscription notification to the item type yielded by the generator.\n */\n rpcSubscriptionValueMapper: (value: TSubscriptionValue) => TItem;\n /**\n * Maps the value from the RPC response to the item type yielded by the generator.\n */\n rpcValueMapper: (value: TRpcValue) => TItem;\n}>;\n\n/**\n * Creates an async generator that combines an initial RPC fetch with an ongoing subscription,\n * yielding values as they arrive from either source.\n *\n * The generator uses slot-based comparison to ensure that only the most recent values are yielded.\n * Any value at a slot older than a previously yielded value is silently dropped.\n * This prevents stale data from appearing when the RPC response and subscription notifications\n * arrive out of order.\n *\n * Things to note:\n *\n * - The generator yields {@link SolanaRpcResponse} values from both the RPC response and\n * subscription notifications, each containing the slot context and the mapped value.\n * - Out-of-order values (by slot) are silently dropped — they are never yielded.\n * - On error from either source, the generator throws the error.\n * - Triggering the caller's abort signal causes the generator to return (complete without error).\n * - The generator completes when the subscription ends, an error occurs, or the abort signal fires.\n *\n * @param config\n *\n * @example\n * ```ts\n * import {\n * address,\n * createAsyncGeneratorWithInitialValueAndSlotTracking,\n * createSolanaRpc,\n * createSolanaRpcSubscriptions,\n * } from '@solana/kit';\n *\n * const rpc = createSolanaRpc('http://127.0.0.1:8899');\n * const rpcSubscriptions = createSolanaRpcSubscriptions('ws://127.0.0.1:8900');\n * const myAddress = address('FnHyam9w4NZoWR6mKN1CuGBritdsEWZQa4Z4oawLZGxa');\n *\n * const abortController = new AbortController();\n * for await (const balance of createAsyncGeneratorWithInitialValueAndSlotTracking({\n * abortSignal: abortController.signal,\n * rpcRequest: rpc.getBalance(myAddress, { commitment: 'confirmed' }),\n * rpcValueMapper: lamports => lamports,\n * rpcSubscriptionRequest: rpcSubscriptions.accountNotifications(myAddress),\n * rpcSubscriptionValueMapper: ({ lamports }) => lamports,\n * })) {\n * console.log(`Balance at slot ${balance.context.slot}:`, balance.value);\n * }\n * ```\n */\nexport async function* createAsyncGeneratorWithInitialValueAndSlotTracking<TRpcValue, TSubscriptionValue, TItem>({\n abortSignal,\n rpcRequest,\n rpcValueMapper,\n rpcSubscriptionRequest,\n rpcSubscriptionValueMapper,\n}: CreateAsyncGeneratorWithInitialValueAndSlotTrackingConfig<TRpcValue, TSubscriptionValue, TItem>): AsyncGenerator<\n SolanaRpcResponse<TItem>\n> {\n if (abortSignal.aborted) return;\n\n let lastUpdateSlot = -1n;\n\n // Shared queue for merging values from the RPC response and subscription notifications.\n const queue: SolanaRpcResponse<TItem>[] = [];\n let waitingResolve: ((value: IteratorResult<SolanaRpcResponse<TItem>>) => void) | null = null;\n let waitingReject: ((reason: unknown) => void) | null = null;\n let rpcDone = false;\n let subscriptionDone = false;\n let done = false;\n let pendingError: unknown;\n\n function markSourcesDone() {\n done = true;\n if (waitingResolve) {\n const resolve = waitingResolve;\n waitingResolve = null;\n waitingReject = null;\n resolve({ done: true, value: undefined });\n }\n }\n\n const abortController = new AbortController();\n const signal = abortController.signal;\n\n function onAbort() {\n done = true;\n abortController.abort(abortSignal.reason);\n if (waitingResolve) {\n const resolve = waitingResolve;\n waitingResolve = null;\n waitingReject = null;\n resolve({ done: true, value: undefined });\n }\n }\n abortSignal.addEventListener('abort', onAbort);\n\n function enqueue(item: SolanaRpcResponse<TItem>) {\n if (done || signal.aborted) return;\n if (waitingResolve) {\n // generator is waiting for a value, so resolve immediately\n const resolve = waitingResolve;\n waitingResolve = null;\n waitingReject = null;\n resolve({ done: false, value: item });\n } else {\n // No pending generator pull, so enqueue the item for future delivery\n queue.push(item);\n }\n }\n\n function handleError(err: unknown) {\n if (signal.aborted) return;\n done = true;\n pendingError = err;\n abortController.abort(err);\n if (waitingReject) {\n // generator is waiting for a value, so reject immediately\n const reject = waitingReject;\n waitingResolve = null;\n waitingReject = null;\n reject(err);\n }\n }\n\n // Start both sources concurrently.\n rpcRequest\n .send({ abortSignal: signal })\n .then(({ context: { slot }, value }) => {\n if (signal.aborted) return;\n if (slot < lastUpdateSlot) return;\n lastUpdateSlot = slot;\n enqueue({ context: { slot }, value: rpcValueMapper(value) });\n })\n .then(() => {\n rpcDone = true;\n if (subscriptionDone) markSourcesDone();\n })\n .catch(handleError);\n\n rpcSubscriptionRequest\n .subscribe({ abortSignal: signal })\n .then(async notifications => {\n for await (const {\n context: { slot },\n value,\n } of notifications) {\n if (signal.aborted) return;\n if (slot < lastUpdateSlot) continue;\n lastUpdateSlot = slot;\n enqueue({ context: { slot }, value: rpcSubscriptionValueMapper(value) });\n }\n // Subscription completed normally.\n subscriptionDone = true;\n if (rpcDone) markSourcesDone();\n })\n .catch(handleError);\n\n try {\n while (true) {\n if (pendingError) throw pendingError;\n if (queue.length > 0) {\n yield queue.shift()!;\n } else if (done) {\n return;\n } else {\n // if no value queued or error, wait for the next value or error\n const result: IteratorResult<SolanaRpcResponse<TItem>> = await new Promise((resolve, reject) => {\n waitingResolve = resolve;\n waitingReject = reject;\n });\n if (result.done) return;\n yield result.value;\n }\n }\n } finally {\n abortSignal.removeEventListener('abort', onAbort);\n if (!signal.aborted) {\n abortController.abort();\n }\n }\n}\n","import type { PendingRpcRequest } from '@solana/rpc';\nimport type { PendingRpcSubscriptionsRequest } from '@solana/rpc-subscriptions';\nimport type { SolanaRpcResponse } from '@solana/rpc-types';\nimport type { ReactiveState, ReactiveStreamStore } from '@solana/subscribable';\n\n/**\n * Configuration for {@link createReactiveStoreWithInitialValueAndSlotTracking}. Pairs a one-shot\n * RPC fetch with an ongoing subscription so the resulting store can hydrate from the initial\n * response and keep up to date with notifications, slot-deduplicating the two streams.\n *\n * @typeParam TRpcValue - The value type returned by `rpcRequest` (inside the {@link SolanaRpcResponse} envelope).\n * @typeParam TSubscriptionValue - The value type emitted by `rpcSubscriptionRequest` (inside the {@link SolanaRpcResponse} envelope).\n * @typeParam TItem - The unified item type the store holds, produced by the two value mappers.\n *\n * @see {@link createReactiveStoreWithInitialValueAndSlotTracking}\n */\nexport type CreateReactiveStoreWithInitialValueAndSlotTrackingConfig<TRpcValue, TSubscriptionValue, TItem> = Readonly<{\n /**\n * Triggering this abort signal will cancel the pending RPC request and subscription, and\n * disconnect the store from further updates.\n */\n abortSignal: AbortSignal;\n /**\n * A pending RPC request whose response will be used to set the store's initial state.\n * The response must be a {@link SolanaRpcResponse} so that its slot can be compared with\n * subscription notifications.\n */\n rpcRequest: PendingRpcRequest<SolanaRpcResponse<TRpcValue>>;\n /**\n * A pending RPC subscription request whose notifications will be used to keep the store\n * up to date. Each notification must be a {@link SolanaRpcResponse} so that its slot can be\n * compared with the initial RPC response and other notifications.\n */\n rpcSubscriptionRequest: PendingRpcSubscriptionsRequest<SolanaRpcResponse<TSubscriptionValue>>;\n /**\n * Maps the value from a subscription notification to the item type stored in the reactive store.\n */\n rpcSubscriptionValueMapper: (value: TSubscriptionValue) => TItem;\n /**\n * Maps the value from the RPC response to the item type stored in the reactive store.\n */\n rpcValueMapper: (value: TRpcValue) => TItem;\n}>;\n\nconst LOADING_STATE: ReactiveState<never> = Object.freeze({\n data: undefined,\n error: undefined,\n status: 'loading',\n});\n\n/**\n * Creates a {@link ReactiveStreamStore} that combines an initial RPC fetch with an ongoing subscription\n * to keep its state up to date.\n *\n * The store uses slot-based comparison to ensure that only the most recent value is kept,\n * regardless of whether it came from the initial RPC response or a subscription notification.\n * This prevents stale data from overwriting newer data when the RPC response and subscription\n * notifications arrive out of order.\n *\n * Things to note:\n *\n * - `getUnifiedState()` starts in `status: 'loading'` until the first response or notification\n * arrives. Once data arrives it transitions to `status: 'loaded'` with a\n * {@link SolanaRpcResponse} containing the value and the slot context at which it was observed.\n * - On error from either source, the store transitions to `status: 'error'` preserving the last\n * known value. Only the first error per connection window is captured.\n * - Calling {@link ReactiveStreamStore.retry | `retry()`} while in `status: 'error'` re-sends the RPC\n * request and re-subscribes to the subscription using a fresh inner abort signal. The store\n * transitions through `status: 'retrying'` back to `loaded`/`error`.\n * - Triggering the caller's abort signal disconnects the store permanently; subsequent `retry()`\n * calls are no-ops.\n *\n * @param config\n *\n * @example\n * ```ts\n * import {\n * address,\n * createReactiveStoreWithInitialValueAndSlotTracking,\n * createSolanaRpc,\n * createSolanaRpcSubscriptions,\n * } from '@solana/kit';\n *\n * const rpc = createSolanaRpc('http://127.0.0.1:8899');\n * const rpcSubscriptions = createSolanaRpcSubscriptions('ws://127.0.0.1:8900');\n * const myAddress = address('FnHyam9w4NZoWR6mKN1CuGBritdsEWZQa4Z4oawLZGxa');\n *\n * const balanceStore = createReactiveStoreWithInitialValueAndSlotTracking({\n * abortSignal: AbortSignal.timeout(60_000),\n * rpcRequest: rpc.getBalance(myAddress, { commitment: 'confirmed' }),\n * rpcValueMapper: lamports => lamports,\n * rpcSubscriptionRequest: rpcSubscriptions.accountNotifications(myAddress),\n * rpcSubscriptionValueMapper: ({ lamports }) => lamports,\n * });\n *\n * const unsubscribe = balanceStore.subscribe(() => {\n * const state = balanceStore.getUnifiedState();\n * if (state.status === 'error') {\n * console.error('Error:', state.error);\n * balanceStore.retry();\n * } else if (state.status === 'loaded') {\n * console.log(`Balance at slot ${state.data.context.slot}:`, state.data.value);\n * }\n * });\n * ```\n *\n * @see {@link ReactiveStreamStore}\n */\nexport function createReactiveStoreWithInitialValueAndSlotTracking<TRpcValue, TSubscriptionValue, TItem>({\n abortSignal,\n rpcRequest,\n rpcValueMapper,\n rpcSubscriptionRequest,\n rpcSubscriptionValueMapper,\n}: CreateReactiveStoreWithInitialValueAndSlotTrackingConfig<TRpcValue, TSubscriptionValue, TItem>): ReactiveStreamStore<\n SolanaRpcResponse<TItem>\n> {\n let currentState: ReactiveState<SolanaRpcResponse<TItem>> = LOADING_STATE;\n let lastUpdateSlot = -1n;\n const subscribers = new Set<() => void>();\n\n const outerController = new AbortController();\n abortSignal.addEventListener('abort', () => outerController.abort(abortSignal.reason));\n\n function notify() {\n subscribers.forEach(cb => cb());\n }\n\n function connect() {\n if (outerController.signal.aborted) return;\n const innerController = new AbortController();\n const forwardAbort = () => innerController.abort(outerController.signal.reason);\n outerController.signal.addEventListener('abort', forwardAbort, { signal: innerController.signal });\n const innerSignal = innerController.signal;\n\n function handleError(err: unknown) {\n if (innerSignal.aborted) return;\n if (currentState.status === 'error') return;\n currentState = { data: currentState.data, error: err, status: 'error' };\n innerController.abort(err);\n notify();\n }\n\n function handleValue(value: SolanaRpcResponse<TItem>) {\n currentState = { data: value, error: undefined, status: 'loaded' };\n notify();\n }\n\n rpcRequest\n .send({ abortSignal: innerSignal })\n .then(({ context: { slot }, value }) => {\n if (innerSignal.aborted) return;\n // `lastUpdateSlot` persists across retries so the store never regresses. If the\n // retried RPC returns a slot older than one we've already seen, we wait for the\n // subscription to deliver something newer before leaving `retrying`.\n if (slot < lastUpdateSlot) return;\n lastUpdateSlot = slot;\n handleValue({ context: { slot }, value: rpcValueMapper(value) });\n })\n .catch(handleError);\n\n rpcSubscriptionRequest\n .subscribe({ abortSignal: innerSignal })\n .then(async notifications => {\n for await (const {\n context: { slot },\n value,\n } of notifications) {\n if (innerSignal.aborted) return;\n if (slot < lastUpdateSlot) continue;\n lastUpdateSlot = slot;\n handleValue({ context: { slot }, value: rpcSubscriptionValueMapper(value) });\n }\n })\n .catch(handleError);\n }\n\n connect();\n\n return {\n getError(): unknown {\n return currentState.error;\n },\n getState(): SolanaRpcResponse<TItem> | undefined {\n return currentState.data;\n },\n getUnifiedState(): ReactiveState<SolanaRpcResponse<TItem>> {\n return currentState;\n },\n retry(): void {\n if (outerController.signal.aborted) return;\n if (currentState.status !== 'error') return;\n currentState = { data: currentState.data, error: undefined, status: 'retrying' };\n notify();\n connect();\n },\n subscribe(callback: () => void): () => void {\n subscribers.add(callback);\n return () => {\n subscribers.delete(callback);\n };\n },\n };\n}\n","import type { Address } from '@solana/addresses';\nimport type { Signature } from '@solana/keys';\nimport type { RequestAirdropApi, Rpc } from '@solana/rpc';\nimport type { Commitment, Lamports } from '@solana/rpc-types';\nimport { waitForRecentTransactionConfirmationUntilTimeout } from '@solana/transaction-confirmation';\n\ntype RequestAndConfirmAirdropConfig = Readonly<{\n abortSignal?: AbortSignal;\n commitment: Commitment;\n confirmSignatureOnlyTransaction: (\n config: Omit<\n Parameters<typeof waitForRecentTransactionConfirmationUntilTimeout>[0],\n 'getRecentSignatureConfirmationPromise' | 'getTimeoutPromise'\n >,\n ) => Promise<void>;\n lamports: Lamports;\n recipientAddress: Address;\n rpc: Rpc<RequestAirdropApi>;\n}>;\n\nexport async function requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({\n abortSignal,\n commitment,\n confirmSignatureOnlyTransaction,\n lamports,\n recipientAddress,\n rpc,\n}: RequestAndConfirmAirdropConfig): Promise<Signature> {\n const airdropTransactionSignature = await rpc\n .requestAirdrop(recipientAddress, lamports, { commitment })\n .send({ abortSignal });\n await confirmSignatureOnlyTransaction({\n abortSignal,\n commitment,\n signature: airdropTransactionSignature,\n });\n return airdropTransactionSignature;\n}\n","import type { Signature } from '@solana/keys';\nimport type { GetSignatureStatusesApi, RequestAirdropApi, Rpc } from '@solana/rpc';\nimport type { RpcSubscriptions, SignatureNotificationsApi } from '@solana/rpc-subscriptions';\nimport {\n createRecentSignatureConfirmationPromiseFactory,\n getTimeoutPromise,\n waitForRecentTransactionConfirmationUntilTimeout,\n} from '@solana/transaction-confirmation';\n\nimport { requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT } from './airdrop-internal';\n\ntype AirdropFunction = (\n config: Omit<\n Parameters<typeof requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT>[0],\n 'confirmSignatureOnlyTransaction' | 'rpc'\n >,\n) => Promise<Signature>;\n\ntype AirdropFactoryConfig<TCluster> = {\n /** An object that supports the {@link GetSignatureStatusesApi} and the {@link RequestAirdropApi} of the Solana RPC API */\n rpc: Rpc<GetSignatureStatusesApi & RequestAirdropApi> & { '~cluster'?: TCluster };\n /** An object that supports the {@link SignatureNotificationsApi} of the Solana RPC Subscriptions API */\n rpcSubscriptions: RpcSubscriptions<SignatureNotificationsApi> & { '~cluster'?: TCluster };\n};\n\n/**\n * Returns a function that you can call to airdrop a certain amount of {@link Lamports} to a Solana\n * address.\n *\n * > [!NOTE] This only works on test clusters.\n *\n * @param config\n *\n * @example\n * ```ts\n * import { address, airdropFactory, createSolanaRpc, createSolanaRpcSubscriptions, devnet, lamports } from '@solana/kit';\n *\n * const rpc = createSolanaRpc(devnet('http://127.0.0.1:8899'));\n * const rpcSubscriptions = createSolanaRpcSubscriptions(devnet('ws://127.0.0.1:8900'));\n *\n * const airdrop = airdropFactory({ rpc, rpcSubscriptions });\n *\n * await airdrop({\n * commitment: 'confirmed',\n * recipientAddress: address('FnHyam9w4NZoWR6mKN1CuGBritdsEWZQa4Z4oawLZGxa'),\n * lamports: lamports(10_000_000n),\n * });\n * ```\n */\nexport function airdropFactory({ rpc, rpcSubscriptions }: AirdropFactoryConfig<'devnet'>): AirdropFunction;\nexport function airdropFactory({ rpc, rpcSubscriptions }: AirdropFactoryConfig<'mainnet'>): AirdropFunction;\nexport function airdropFactory({ rpc, rpcSubscriptions }: AirdropFactoryConfig<'testnet'>): AirdropFunction;\nexport function airdropFactory<TCluster extends 'devnet' | 'mainnet' | 'testnet' | void = void>({\n rpc,\n rpcSubscriptions,\n}: AirdropFactoryConfig<TCluster>): AirdropFunction {\n const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory({\n rpc,\n rpcSubscriptions,\n } as Parameters<typeof createRecentSignatureConfirmationPromiseFactory>[0]);\n async function confirmSignatureOnlyTransaction(\n config: Omit<\n Parameters<typeof waitForRecentTransactionConfirmationUntilTimeout>[0],\n 'getRecentSignatureConfirmationPromise' | 'getTimeoutPromise'\n >,\n ) {\n await waitForRecentTransactionConfirmationUntilTimeout({\n ...config,\n getRecentSignatureConfirmationPromise,\n getTimeoutPromise,\n });\n }\n return async function airdrop(config) {\n return await requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({\n ...config,\n confirmSignatureOnlyTransaction,\n rpc,\n });\n };\n}\n","import {\n getSolanaErrorFromTransactionError,\n isSolanaError,\n type RpcSimulateTransactionResult,\n SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT,\n SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT,\n SolanaError,\n} from '@solana/errors';\nimport { pipe } from '@solana/functional';\nimport type { Rpc, SimulateTransactionApi } from '@solana/rpc';\nimport type { Commitment, Slot } from '@solana/rpc-types';\nimport {\n getTransactionMessageComputeUnitLimit,\n isTransactionMessageWithDurableNonceLifetime,\n setTransactionMessageComputeUnitLimit,\n TransactionMessage,\n TransactionMessageWithFeePayer,\n} from '@solana/transaction-messages';\nimport { compileTransaction, getBase64EncodedWireTransaction } from '@solana/transactions';\n\nconst PROVISORY_COMPUTE_UNIT_LIMIT = 0;\nconst MAX_COMPUTE_UNIT_LIMIT = 1_400_000;\n\ntype EstimateComputeUnitLimitFactoryConfig = Readonly<{\n rpc: Rpc<SimulateTransactionApi>;\n}>;\n\ntype EstimateComputeUnitLimitConfig = Readonly<{\n abortSignal?: AbortSignal;\n commitment?: Commitment;\n minContextSlot?: Slot;\n}>;\n\ntype EstimateComputeUnitLimitFunction = (\n transactionMessage: TransactionMessage & TransactionMessageWithFeePayer,\n config?: EstimateComputeUnitLimitConfig,\n) => Promise<number>;\n\n/**\n * Returns a function that estimates the compute units consumed by a transaction message by\n * simulating it.\n *\n * The estimator sets the compute unit limit to the maximum (1,400,000) before simulating, so the\n * simulation does not fail due to compute unit exhaustion. For blockhash-lifetime transactions, the\n * RPC is asked to replace the blockhash during simulation, so any blockhash value will work. For\n * durable nonce transactions, the actual nonce value is used.\n *\n * @param factoryConfig - An object containing the RPC instance to use for simulation.\n * @return A function that accepts a transaction message and returns the estimated compute units.\n *\n * @example\n * ```ts\n * import { estimateComputeUnitLimitFactory } from '@solana/kit';\n *\n * const estimateComputeUnitLimit = estimateComputeUnitLimitFactory({ rpc });\n * const estimatedUnits = await estimateComputeUnitLimit(transactionMessage);\n * ```\n */\nexport function estimateComputeUnitLimitFactory({\n rpc,\n}: EstimateComputeUnitLimitFactoryConfig): EstimateComputeUnitLimitFunction {\n return async function estimateComputeUnitLimit(transactionMessage, config) {\n const { abortSignal, ...simulateConfig } = config ?? {};\n const replaceRecentBlockhash = !isTransactionMessageWithDurableNonceLifetime(transactionMessage);\n\n const transaction = pipe(\n transactionMessage,\n m => setTransactionMessageComputeUnitLimit(MAX_COMPUTE_UNIT_LIMIT, m),\n compileTransaction,\n );\n const wireTransactionBytes = getBase64EncodedWireTransaction(transaction);\n\n try {\n const response = await rpc\n .simulateTransaction(wireTransactionBytes, {\n ...simulateConfig,\n encoding: 'base64',\n replaceRecentBlockhash,\n sigVerify: false,\n })\n .send({ abortSignal });\n // The API response type varies based on config (eg. `replacementBlockhash` is only\n // present when `replaceRecentBlockhash` is true), but `RpcSimulateTransactionResult`\n // is a flat superset. Cast through `unknown` to bridge the structural gap.\n const { err: transactionError, ...simulationResult } =\n response.value as unknown as RpcSimulateTransactionResult;\n\n if (simulationResult.unitsConsumed == null) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT);\n }\n\n if (transactionError) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, {\n ...simulationResult,\n cause: getSolanaErrorFromTransactionError(transactionError),\n });\n }\n\n // Downcast from bigint to number, capping at u32 max.\n return simulationResult.unitsConsumed > 4_294_967_295n\n ? 4_294_967_295\n : Number(simulationResult.unitsConsumed);\n } catch (e) {\n if (isSolanaError(e, SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT)) {\n throw e;\n }\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, {\n cause: e,\n });\n }\n };\n}\n\n/**\n * Returns a function that estimates the compute unit limit for a transaction message and sets it on\n * the message. If the message already has an explicit compute unit limit set (one that is not the\n * provisory value of 0, and not the maximum of 1,400,000), the message is returned unchanged.\n *\n * This is designed to work with {@link fillTransactionMessageProvisoryComputeUnitLimit}: first add a provisory limit\n * during transaction construction, then later estimate and replace it before sending.\n *\n * @param estimateComputeUnitLimit - The estimator function, typically created by\n * {@link estimateComputeUnitLimitFactory}. You can also pass a custom wrapper that adds a buffer\n * (e.g. multiply the estimate by 1.1).\n * @return A function that accepts a transaction message and returns it with the compute unit limit\n * set to the estimated value.\n *\n * @example\n * ```ts\n * import { estimateAndSetComputeUnitLimitFactory, estimateComputeUnitLimitFactory } from '@solana/kit';\n *\n * const estimator = estimateComputeUnitLimitFactory({ rpc });\n * const estimateAndSet = estimateAndSetComputeUnitLimitFactory(estimator);\n * const updatedMessage = await estimateAndSet(transactionMessage);\n * ```\n */\nexport function estimateAndSetComputeUnitLimitFactory(\n estimateComputeUnitLimit: EstimateComputeUnitLimitFunction,\n): <TTransactionMessage extends TransactionMessage & TransactionMessageWithFeePayer>(\n transactionMessage: TTransactionMessage,\n config?: EstimateComputeUnitLimitConfig,\n) => Promise<TTransactionMessage> {\n return async function estimateAndSetComputeUnitLimit(transactionMessage, config) {\n const existingLimit = getTransactionMessageComputeUnitLimit(transactionMessage);\n\n // If a non-provisory, non-max CU limit is already set, leave it as-is.\n if (existingLimit && existingLimit !== MAX_COMPUTE_UNIT_LIMIT) {\n return transactionMessage;\n }\n\n const estimatedUnits = await estimateComputeUnitLimit(transactionMessage, config);\n return setTransactionMessageComputeUnitLimit(estimatedUnits, transactionMessage);\n };\n}\n\n/**\n * Sets the compute unit limit to a provisory value of 0 if no compute unit limit is currently set\n * on the transaction message. If a limit is already set (any value, including 0), the message is\n * returned unchanged.\n *\n * This is useful during transaction construction to reserve space for a compute unit limit that\n * will later be replaced with an actual estimate via\n * {@link estimateAndSetComputeUnitLimitFactory}.\n *\n * @param transactionMessage - The transaction message to add a provisory limit to.\n * @return The transaction message with a provisory compute unit limit set, or unchanged if one was\n * already present.\n *\n * @example\n * ```ts\n * import { fillTransactionMessageProvisoryComputeUnitLimit } from '@solana/kit';\n *\n * const messageWithProvisoryLimit = fillTransactionMessageProvisoryComputeUnitLimit(transactionMessage);\n * ```\n */\nexport function fillTransactionMessageProvisoryComputeUnitLimit<TTransactionMessage extends TransactionMessage>(\n transactionMessage: TTransactionMessage,\n): TTransactionMessage {\n if (getTransactionMessageComputeUnitLimit(transactionMessage) !== undefined) {\n return transactionMessage;\n }\n return setTransactionMessageComputeUnitLimit(PROVISORY_COMPUTE_UNIT_LIMIT, transactionMessage);\n}\n","import {\n assertAccountsDecoded,\n assertAccountsExist,\n type FetchAccountsConfig,\n fetchJsonParsedAccounts,\n} from '@solana/accounts';\nimport type { Address } from '@solana/addresses';\nimport type { GetMultipleAccountsApi, Rpc } from '@solana/rpc';\nimport { type AddressesByLookupTableAddress } from '@solana/transaction-messages';\n\ntype FetchedAddressLookup = {\n addresses: Address[];\n};\n\n/**\n * Given a list of addresses belonging to address lookup tables, returns a map of lookup table\n * addresses to an ordered array of the addresses they contain.\n *\n * @param rpc An object that supports the {@link GetMultipleAccountsApi} of the Solana RPC API\n * @param config\n */\nexport async function fetchAddressesForLookupTables(\n lookupTableAddresses: Address[],\n rpc: Rpc<GetMultipleAccountsApi>,\n config?: FetchAccountsConfig,\n): Promise<AddressesByLookupTableAddress> {\n if (lookupTableAddresses.length === 0) {\n return {};\n }\n\n const fetchedLookupTables = await fetchJsonParsedAccounts<FetchedAddressLookup[]>(\n rpc,\n lookupTableAddresses,\n config,\n );\n\n assertAccountsDecoded(fetchedLookupTables);\n assertAccountsExist(fetchedLookupTables);\n\n return fetchedLookupTables.reduce<AddressesByLookupTableAddress>((acc, lookup) => {\n return {\n ...acc,\n [lookup.address]: lookup.data.addresses,\n };\n }, {});\n}\n","import { type FetchAccountsConfig } from '@solana/accounts';\nimport type { GetMultipleAccountsApi, Rpc } from '@solana/rpc';\nimport {\n CompiledTransactionMessage,\n CompiledTransactionMessageWithLifetime,\n decompileTransactionMessage,\n TransactionMessage,\n TransactionMessageWithFeePayer,\n TransactionMessageWithLifetime,\n} from '@solana/transaction-messages';\n\nimport { fetchAddressesForLookupTables } from './fetch-lookup-tables';\n\ntype DecompileTransactionMessageFetchingLookupTablesConfig = FetchAccountsConfig & {\n lastValidBlockHeight?: bigint;\n};\n\n/**\n * Returns a {@link TransactionMessage} from a {@link CompiledTransactionMessage}. If any of the\n * accounts in the compiled message require an address lookup table to find their address, this\n * function will use the supplied RPC instance to fetch the contents of the address lookup table\n * from the network.\n *\n * @param rpc An object that supports the {@link GetMultipleAccountsApi} of the Solana RPC API\n * @param config\n */\nexport async function decompileTransactionMessageFetchingLookupTables(\n compiledTransactionMessage: CompiledTransactionMessage & CompiledTransactionMessageWithLifetime,\n rpc: Rpc<GetMultipleAccountsApi>,\n config?: DecompileTransactionMessageFetchingLookupTablesConfig,\n): Promise<TransactionMessage & TransactionMessageWithFeePayer & TransactionMessageWithLifetime> {\n const lookupTables =\n 'addressTableLookups' in compiledTransactionMessage &&\n compiledTransactionMessage.addressTableLookups !== undefined &&\n compiledTransactionMessage.addressTableLookups.length > 0\n ? compiledTransactionMessage.addressTableLookups\n : [];\n const lookupTableAddresses = lookupTables.map(l => l.lookupTableAddress);\n\n const { lastValidBlockHeight, ...fetchAccountsConfig } = config ?? {};\n const addressesByLookupTableAddress =\n lookupTableAddresses.length > 0\n ? await fetchAddressesForLookupTables(lookupTableAddresses, rpc, fetchAccountsConfig)\n : {};\n\n return decompileTransactionMessage(compiledTransactionMessage, {\n addressesByLookupTableAddress,\n lastValidBlockHeight,\n });\n}\n","import type { Lamports } from '@solana/rpc-types';\n\n/**\n * Calculates the minimum {@link Lamports | lamports} required to make an account rent exempt for a\n * given data size, without performing an RPC call.\n *\n * Values are sourced from the on-chain rent parameters in the Solana runtime:\n * https://github.com/anza-xyz/solana-sdk/blob/c07f692e41d757057c8700211a9300cdcd6d33b1/rent/src/lib.rs#L93-L97\n *\n * Note that this logic may change, or be incorrect depending on the cluster you are connected to.\n * You can always use the RPC method `getMinimumBalanceForRentExemption` to get the current value.\n *\n * @deprecated The minimum balance for an account is being actively reduced\n * (see {@link https://github.com/solana-foundation/solana-improvement-documents/pull/437 | SIMD-0437})\n * and is expected to become dynamic in future Solana upgrades\n * (see {@link https://github.com/solana-foundation/solana-improvement-documents/pull/194 | SIMD-0194}\n * and {@link https://github.com/solana-foundation/solana-improvement-documents/pull/389 | SIMD-0389}),\n * meaning a hardcoded local computation will no longer return accurate results. Use the\n * {@link GetMinimumBalanceForRentExemptionApi.getMinimumBalanceForRentExemption | getMinimumBalanceForRentExemption}\n * RPC method or a `ClientWithGetMinimumBalance` plugin instead. This function will be removed in v7.\n *\n * @param space The number of bytes of account data.\n */\nexport function getMinimumBalanceForRentExemption(space: bigint): Lamports {\n const RENT = {\n ACCOUNT_STORAGE_OVERHEAD: 128n,\n DEFAULT_EXEMPTION_THRESHOLD: 2n,\n DEFAULT_LAMPORTS_PER_BYTE_YEAR: 3_480n,\n } as const;\n const requiredLamports =\n (RENT.ACCOUNT_STORAGE_OVERHEAD + space) *\n RENT.DEFAULT_LAMPORTS_PER_BYTE_YEAR *\n RENT.DEFAULT_EXEMPTION_THRESHOLD;\n return requiredLamports as Lamports;\n}\n","import type { Signature } from '@solana/keys';\nimport type { Rpc, SendTransactionApi } from '@solana/rpc';\nimport { Commitment, commitmentComparator } from '@solana/rpc-types';\nimport {\n TransactionWithLastValidBlockHeight,\n waitForDurableNonceTransactionConfirmation,\n waitForRecentTransactionConfirmation,\n} from '@solana/transaction-confirmation';\nimport {\n getBase64EncodedWireTransaction,\n SendableTransaction,\n Transaction,\n TransactionWithDurableNonceLifetime,\n} from '@solana/transactions';\n\ninterface SendAndConfirmDurableNonceTransactionConfig\n extends SendTransactionBaseConfig, SendTransactionConfigWithoutEncoding {\n confirmDurableNonceTransaction: (\n config: Omit<\n Parameters<typeof waitForDurableNonceTransactionConfirmation>[0],\n 'getNonceInvalidationPromise' | 'getRecentSignatureConfirmationPromise'\n >,\n ) => Promise<void>;\n transaction: SendableTransaction & Transaction & TransactionWithDurableNonceLifetime;\n}\n\ninterface SendAndConfirmTransactionWithBlockhashLifetimeConfig\n extends SendTransactionBaseConfig, SendTransactionConfigWithoutEncoding {\n confirmRecentTransaction: (\n config: Omit<\n Parameters<typeof waitForRecentTransactionConfirmation>[0],\n 'getBlockHeightExceedencePromise' | 'getRecentSignatureConfirmationPromise'\n >,\n ) => Promise<void>;\n transaction: SendableTransaction & Transaction & TransactionWithLastValidBlockHeight;\n}\n\ninterface SendTransactionBaseConfig extends SendTransactionConfigWithoutEncoding {\n abortSignal?: AbortSignal;\n commitment: Commitment;\n rpc: Rpc<SendTransactionApi>;\n transaction: SendableTransaction & Transaction;\n}\n\ntype SendTransactionConfigWithoutEncoding = Omit<\n NonNullable<Parameters<SendTransactionApi['sendTransaction']>[1]>,\n 'encoding'\n>;\n\nfunction getSendTransactionConfigWithAdjustedPreflightCommitment(\n commitment: Commitment,\n config?: SendTransactionConfigWithoutEncoding,\n): SendTransactionConfigWithoutEncoding | void {\n if (\n // The developer has supplied no value for `preflightCommitment`.\n !config?.preflightCommitment &&\n // The value of `commitment` is lower than the server default of `preflightCommitment`.\n commitmentComparator(commitment, 'finalized' /* default value of `preflightCommitment` */) < 0\n ) {\n return {\n ...config,\n // In the common case, it is unlikely that you want to simulate a transaction at\n // `finalized` commitment when your standard of commitment for confirming the\n // transaction is lower. Cap the simulation commitment level to the level of the\n // confirmation commitment.\n preflightCommitment: commitment,\n };\n }\n // The commitment at which the developer wishes to confirm the transaction is at least as\n // high as the commitment at which they want to simulate it. Honour the config as-is.\n return config;\n}\n\nexport async function sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({\n abortSignal,\n commitment,\n rpc,\n transaction,\n ...sendTransactionConfig\n}: SendTransactionBaseConfig): Promise<Signature> {\n const base64EncodedWireTransaction = getBase64EncodedWireTransaction(transaction);\n return await rpc\n .sendTransaction(base64EncodedWireTransaction, {\n ...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),\n encoding: 'base64',\n })\n .send({ abortSignal });\n}\n\nexport async function sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({\n abortSignal,\n commitment,\n confirmDurableNonceTransaction,\n rpc,\n transaction,\n ...sendTransactionConfig\n}: SendAndConfirmDurableNonceTransactionConfig): Promise<Signature> {\n const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({\n ...sendTransactionConfig,\n abortSignal,\n commitment,\n rpc,\n transaction,\n });\n await confirmDurableNonceTransaction({\n abortSignal,\n commitment,\n transaction,\n });\n return transactionSignature;\n}\n\nexport async function sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({\n abortSignal,\n commitment,\n confirmRecentTransaction,\n rpc,\n transaction,\n ...sendTransactionConfig\n}: SendAndConfirmTransactionWithBlockhashLifetimeConfig): Promise<Signature> {\n const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({\n ...sendTransactionConfig,\n abortSignal,\n commitment,\n rpc,\n transaction,\n });\n await confirmRecentTransaction({\n abortSignal,\n commitment,\n transaction,\n });\n return transactionSignature;\n}\n","import { getSolanaErrorFromTransactionError, isSolanaError, SOLANA_ERROR__INVALID_NONCE } from '@solana/errors';\nimport { Signature } from '@solana/keys';\nimport type { GetAccountInfoApi, GetSignatureStatusesApi, Rpc, SendTransactionApi } from '@solana/rpc';\nimport type { AccountNotificationsApi, RpcSubscriptions, SignatureNotificationsApi } from '@solana/rpc-subscriptions';\nimport { commitmentComparator } from '@solana/rpc-types';\nimport {\n createNonceInvalidationPromiseFactory,\n createRecentSignatureConfirmationPromiseFactory,\n waitForDurableNonceTransactionConfirmation,\n} from '@solana/transaction-confirmation';\nimport {\n getSignatureFromTransaction,\n SendableTransaction,\n Transaction,\n TransactionWithDurableNonceLifetime,\n} from '@solana/transactions';\n\nimport { sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT } from './send-transaction-internal';\n\ntype SendAndConfirmDurableNonceTransactionFunction = (\n transaction: SendableTransaction & Transaction & TransactionWithDurableNonceLifetime,\n config: Omit<\n Parameters<typeof sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT>[0],\n 'confirmDurableNonceTransaction' | 'rpc' | 'transaction'\n >,\n) => Promise<void>;\n\ntype SendAndConfirmDurableNonceTransactionFactoryConfig<TCluster> = {\n /** An object that supports the {@link GetSignatureStatusesApi} and the {@link SendTransactionApi} of the Solana RPC API */\n rpc: Rpc<GetAccountInfoApi & GetSignatureStatusesApi & SendTransactionApi> & { '~cluster'?: TCluster };\n /** An object that supports the {@link AccountNotificationsApi} and the {@link SignatureNotificationsApi} of the Solana RPC Subscriptions API */\n rpcSubscriptions: RpcSubscriptions<AccountNotificationsApi & SignatureNotificationsApi> & { '~cluster'?: TCluster };\n};\n\n/**\n * Returns a function that you can call to send a nonce-based transaction to the network and to wait\n * until it has been confirmed.\n *\n * @param config\n *\n * @example\n * ```ts\n * import {\n * isSolanaError,\n * sendAndConfirmDurableNonceTransactionFactory,\n * SOLANA_ERROR__INVALID_NONCE,\n * SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND,\n * } from '@solana/kit';\n *\n * const sendAndConfirmNonceTransaction = sendAndConfirmDurableNonceTransactionFactory({ rpc, rpcSubscriptions });\n *\n * try {\n * await sendAndConfirmNonceTransaction(transaction, { commitment: 'confirmed' });\n * } catch (e) {\n * if (isSolanaError(e, SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND)) {\n * console.error(\n * 'The lifetime specified by this transaction refers to a nonce account ' +\n * `\\`${e.context.nonceAccountAddress}\\` that does not exist`,\n * );\n * } else if (isSolanaError(e, SOLANA_ERROR__INVALID_NONCE)) {\n * console.error('This transaction depends on a nonce that is no longer valid');\n * } else {\n * throw e;\n * }\n * }\n * ```\n */\nexport function sendAndConfirmDurableNonceTransactionFactory({\n rpc,\n rpcSubscriptions,\n}: SendAndConfirmDurableNonceTransactionFactoryConfig<'devnet'>): SendAndConfirmDurableNonceTransactionFunction;\nexport function sendAndConfirmDurableNonceTransactionFactory({\n rpc,\n rpcSubscriptions,\n}: SendAndConfirmDurableNonceTransactionFactoryConfig<'testnet'>): SendAndConfirmDurableNonceTransactionFunction;\nexport function sendAndConfirmDurableNonceTransactionFactory({\n rpc,\n rpcSubscriptions,\n}: SendAndConfirmDurableNonceTransactionFactoryConfig<'mainnet'>): SendAndConfirmDurableNonceTransactionFunction;\nexport function sendAndConfirmDurableNonceTransactionFactory<\n TCluster extends 'devnet' | 'mainnet' | 'testnet' | void = void,\n>({\n rpc,\n rpcSubscriptions,\n}: SendAndConfirmDurableNonceTransactionFactoryConfig<TCluster>): SendAndConfirmDurableNonceTransactionFunction {\n const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory({ rpc, rpcSubscriptions } as Parameters<\n typeof createNonceInvalidationPromiseFactory\n >[0]);\n const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory({\n rpc,\n rpcSubscriptions,\n } as Parameters<typeof createRecentSignatureConfirmationPromiseFactory>[0]);\n\n /**\n * Creates a wrapped version of getNonceInvalidationPromise that handles the race condition\n * where the nonce account update notification arrives before the signature confirmation.\n *\n * When the nonce changes, we check if our transaction actually landed on-chain.\n * If it did, we don't throw - letting the signature confirmation promise continue.\n */\n function createNonceInvalidationPromiseHandlingRaceCondition(\n signature: Signature,\n ): typeof getNonceInvalidationPromise {\n return async function wrappedGetNonceInvalidationPromise(config) {\n try {\n return await getNonceInvalidationPromise(config);\n } catch (e) {\n // If nonce became invalid, check if our transaction actually landed\n if (isSolanaError(e, SOLANA_ERROR__INVALID_NONCE)) {\n let status;\n try {\n const { value: statuses } = await rpc\n .getSignatureStatuses([signature])\n .send({ abortSignal: config.abortSignal });\n status = statuses[0];\n } catch {\n // RPC failed - propagate the original nonce error\n throw e;\n }\n\n if (status === null || status === undefined) {\n // Transaction doesn't exist - nonce was truly invalid\n throw e;\n }\n\n // Check if status meets required commitment\n if (\n status.confirmationStatus !== null &&\n commitmentComparator(status.confirmationStatus, config.commitment) >= 0\n ) {\n // Transaction failed on-chain, throw the error from the transaction\n if (status.err !== null) {\n throw getSolanaErrorFromTransactionError(status.err);\n }\n // Transaction succeeded, resolve the promise successfully\n return;\n }\n\n // Commitment not met yet - return a never-resolving promise\n // This lets the signature confirmation promise continue\n return await new Promise(() => {});\n }\n throw e;\n }\n };\n }\n\n async function confirmDurableNonceTransaction(\n config: Omit<\n Parameters<typeof waitForDurableNonceTransactionConfirmation>[0],\n 'getNonceInvalidationPromise' | 'getRecentSignatureConfirmationPromise'\n >,\n ) {\n const wrappedGetNonceInvalidationPromise = createNonceInvalidationPromiseHandlingRaceCondition(\n getSignatureFromTransaction(config.transaction),\n );\n\n await waitForDurableNonceTransactionConfirmation({\n ...config,\n getNonceInvalidationPromise: wrappedGetNonceInvalidationPromise,\n getRecentSignatureConfirmationPromise,\n });\n }\n return async function sendAndConfirmDurableNonceTransaction(transaction, config) {\n await sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({\n ...config,\n confirmDurableNonceTransaction,\n rpc,\n transaction,\n });\n };\n}\n","import type { GetEpochInfoApi, GetSignatureStatusesApi, Rpc, SendTransactionApi } from '@solana/rpc';\nimport type { RpcSubscriptions, SignatureNotificationsApi, SlotNotificationsApi } from '@solana/rpc-subscriptions';\nimport {\n createBlockHeightExceedencePromiseFactory,\n createRecentSignatureConfirmationPromiseFactory,\n TransactionWithLastValidBlockHeight,\n waitForRecentTransactionConfirmation,\n} from '@solana/transaction-confirmation';\nimport { SendableTransaction, Transaction } from '@solana/transactions';\n\nimport { sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT } from './send-transaction-internal';\n\ntype SendAndConfirmTransactionWithBlockhashLifetimeFunction = (\n transaction: SendableTransaction & Transaction & TransactionWithLastValidBlockHeight,\n config: Omit<\n Parameters<typeof sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT>[0],\n 'confirmRecentTransaction' | 'rpc' | 'transaction'\n >,\n) => Promise<void>;\n\ntype SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig<TCluster> = {\n /** An object that supports the {@link GetSignatureStatusesApi} and the {@link SendTransactionApi} of the Solana RPC API */\n rpc: Rpc<GetEpochInfoApi & GetSignatureStatusesApi & SendTransactionApi> & { '~cluster'?: TCluster };\n /** An object that supports the {@link SignatureNotificationsApi} and the {@link SlotNotificationsApi} of the Solana RPC Subscriptions API */\n rpcSubscriptions: RpcSubscriptions<SignatureNotificationsApi & SlotNotificationsApi> & { '~cluster'?: TCluster };\n};\n\n/**\n * Returns a function that you can call to send a blockhash-based transaction to the network and to\n * wait until it has been confirmed.\n *\n * @param config\n *\n * @example\n * ```ts\n * import { isSolanaError, sendAndConfirmTransactionFactory, SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED } from '@solana/kit';\n *\n * const sendAndConfirmTransaction = sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions });\n *\n * try {\n * await sendAndConfirmTransaction(transaction, { commitment: 'confirmed' });\n * } catch (e) {\n * if (isSolanaError(e, SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED)) {\n * console.error('This transaction depends on a blockhash that has expired');\n * } else {\n * throw e;\n * }\n * }\n * ```\n */\nexport function sendAndConfirmTransactionFactory({\n rpc,\n rpcSubscriptions,\n}: SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig<'devnet'>): SendAndConfirmTransactionWithBlockhashLifetimeFunction;\nexport function sendAndConfirmTransactionFactory({\n rpc,\n rpcSubscriptions,\n}: SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig<'testnet'>): SendAndConfirmTransactionWithBlockhashLifetimeFunction;\nexport function sendAndConfirmTransactionFactory({\n rpc,\n rpcSubscriptions,\n}: SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig<'mainnet'>): SendAndConfirmTransactionWithBlockhashLifetimeFunction;\nexport function sendAndConfirmTransactionFactory<TCluster extends 'devnet' | 'mainnet' | 'testnet' | void = void>({\n rpc,\n rpcSubscriptions,\n}: SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig<TCluster>): SendAndConfirmTransactionWithBlockhashLifetimeFunction {\n const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory({\n rpc,\n rpcSubscriptions,\n } as Parameters<typeof createBlockHeightExceedencePromiseFactory>[0]);\n const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory({\n rpc,\n rpcSubscriptions,\n } as Parameters<typeof createRecentSignatureConfirmationPromiseFactory>[0]);\n async function confirmRecentTransaction(\n config: Omit<\n Parameters<typeof waitForRecentTransactionConfirmation>[0],\n 'getBlockHeightExceedencePromise' | 'getRecentSignatureConfirmationPromise'\n >,\n ) {\n await waitForRecentTransactionConfirmation({\n ...config,\n getBlockHeightExceedencePromise,\n getRecentSignatureConfirmationPromise,\n });\n }\n return async function sendAndConfirmTransaction(transaction, config) {\n await sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({\n ...config,\n confirmRecentTransaction,\n rpc,\n transaction,\n });\n };\n}\n","import type { Rpc, SendTransactionApi } from '@solana/rpc';\nimport { SendableTransaction, Transaction } from '@solana/transactions';\n\nimport { sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT } from './send-transaction-internal';\n\ntype SendTransactionWithoutConfirmingFunction = (\n transaction: SendableTransaction & Transaction,\n config: Omit<Parameters<typeof sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT>[0], 'rpc' | 'transaction'>,\n) => Promise<void>;\n\ninterface SendTransactionWithoutConfirmingFactoryConfig {\n /** An object that supports the {@link SendTransactionApi} of the Solana RPC API */\n rpc: Rpc<SendTransactionApi>;\n}\n\n/**\n * Returns a function that you can call to send a transaction with any kind of lifetime to the\n * network without waiting for it to be confirmed.\n *\n * @param config\n *\n * @example\n * ```ts\n * import {\n * sendTransactionWithoutConfirmingFactory,\n * SOLANA_ERROR__JSON_RPC__SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE,\n * } from '@solana/kit';\n *\n * const sendTransaction = sendTransactionWithoutConfirmingFactory({ rpc });\n *\n * try {\n * await sendTransaction(transaction, { commitment: 'confirmed' });\n * } catch (e) {\n * if (isSolanaError(e, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE)) {\n * console.error('The transaction failed in simulation', e.cause);\n * } else {\n * throw e;\n * }\n * }\n * ```\n */\nexport function sendTransactionWithoutConfirmingFactory({\n rpc,\n}: SendTransactionWithoutConfirmingFactoryConfig): SendTransactionWithoutConfirmingFunction {\n return async function sendTransactionWithoutConfirming(transaction, config) {\n await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({\n ...config,\n rpc,\n transaction,\n });\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/create-async-generator-with-initial-value-and-slot-tracking.ts","../src/create-reactive-store-with-initial-value-and-slot-tracking.ts","../src/airdrop-internal.ts","../src/airdrop.ts","../src/compute-unit-limit-estimation.ts","../src/fetch-lookup-tables.ts","../src/decompile-transaction-message-fetching-lookup-tables.ts","../src/resource-limit-estimation.ts","../src/get-minimum-balance-for-rent-exemption.ts","../src/send-transaction-internal.ts","../src/send-and-confirm-durable-nonce-transaction.ts","../src/send-and-confirm-transaction.ts","../src/send-transaction-without-confirming.ts"],"names":["createRecentSignatureConfirmationPromiseFactory","waitForRecentTransactionConfirmationUntilTimeout","getTimeoutPromise","isTransactionMessageWithDurableNonceLifetime","pipe","setTransactionMessageComputeUnitLimit","compileTransaction","getBase64EncodedWireTransaction","SolanaError","SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT","SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT","getSolanaErrorFromTransactionError","isSolanaError","getTransactionMessageComputeUnitLimit","fetchJsonParsedAccounts","assertAccountsDecoded","assertAccountsExist","decompileTransactionMessage","MAX_COMPUTE_UNIT_LIMIT","setTransactionMessageLoadedAccountsDataSizeLimit","SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_LOADED_ACCOUNTS_DATA_SIZE_LIMIT","SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_RESOURCE_LIMITS","getTransactionMessageLoadedAccountsDataSizeLimit","commitmentComparator","createNonceInvalidationPromiseFactory","SOLANA_ERROR__INVALID_NONCE","getSignatureFromTransaction","waitForDurableNonceTransactionConfirmation","createBlockHeightExceedencePromiseFactory","waitForRecentTransactionConfirmation"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA8EA,gBAAuB,mDAAA,CAA0F;AAAA,EAC7G,WAAA;AAAA,EACA,UAAA;AAAA,EACA,cAAA;AAAA,EACA,sBAAA;AAAA,EACA;AACJ,CAAA,EAEE;AACE,EAAA,IAAI,YAAY,OAAA,EAAS;AAEzB,EAAA,IAAI,iBAAiB,CAAC,EAAA;AAGtB,EAAA,MAAM,QAAoC,EAAC;AAC3C,EAAA,IAAI,cAAA,GAAqF,IAAA;AACzF,EAAA,IAAI,aAAA,GAAo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C1E,EAAA,eAAe,yBACX,MAAA,EAIF;AACE,IAAA,MAAM6B,4DAAA,CAAqC;AAAA,MACvC,GAAG,MAAA;AAAA,MACH,+BAAA;AAAA,MACA;AAAA,KACH,CAAA;AAAA,EACL;AACA,EAAA,OAAO,eAAe,yBAAA,CAA0B,WAAA,EAAa,MAAA,EAAQ;AACjE,IAAA,MAAM,0EAAA,CAA2E;AAAA,MAC7E,GAAG,MAAA;AAAA,MACH,wBAAA;AAAA,MACA,GAAA;AAAA,MACA;AAAA,KACH,CAAA;AAAA,EACL,CAAA;AACJ;;;ACrDO,SAAS,uCAAA,CAAwC;AAAA,EACpD;AACJ,CAAA,EAA4F;AACxF,EAAA,OAAO,eAAe,gCAAA,CAAiC,WAAA,EAAa,MAAA,EAAQ;AACxE,IAAA,MAAM,2CAAA,CAA4C;AAAA,MAC9C,GAAG,MAAA;AAAA,MACH,GAAA;AAAA,MACA;AAAA,KACH,CAAA;AAAA,EACL,CAAA;AACJ","file":"index.browser.cjs","sourcesContent":["import type { PendingRpcRequest } from '@solana/rpc';\nimport type { PendingRpcSubscriptionsRequest } from '@solana/rpc-subscriptions';\nimport type { SolanaRpcResponse } from '@solana/rpc-types';\n\ntype CreateAsyncGeneratorWithInitialValueAndSlotTrackingConfig<TRpcValue, TSubscriptionValue, TItem> = Readonly<{\n /**\n * Triggering this abort signal will cancel the pending RPC request and subscription, and\n * cause the async generator to return (complete without error).\n */\n abortSignal: AbortSignal;\n /**\n * A pending RPC request whose response will be yielded as the generator's first value\n * (unless a subscription notification with a newer slot arrives first).\n * The response must be a {@link SolanaRpcResponse} so that its slot can be compared with\n * subscription notifications.\n */\n rpcRequest: PendingRpcRequest<SolanaRpcResponse<TRpcValue>>;\n /**\n * A pending RPC subscription request whose notifications will be yielded as they arrive.\n * Each notification must be a {@link SolanaRpcResponse} so that its slot can be compared\n * with the initial RPC response and other notifications.\n */\n rpcSubscriptionRequest: PendingRpcSubscriptionsRequest<SolanaRpcResponse<TSubscriptionValue>>;\n /**\n * Maps the value from a subscription notification to the item type yielded by the generator.\n */\n rpcSubscriptionValueMapper: (value: TSubscriptionValue) => TItem;\n /**\n * Maps the value from the RPC response to the item type yielded by the generator.\n */\n rpcValueMapper: (value: TRpcValue) => TItem;\n}>;\n\n/**\n * Creates an async generator that combines an initial RPC fetch with an ongoing subscription,\n * yielding values as they arrive from either source.\n *\n * The generator uses slot-based comparison to ensure that only the most recent values are yielded.\n * Any value at a slot older than a previously yielded value is silently dropped.\n * This prevents stale data from appearing when the RPC response and subscription notifications\n * arrive out of order.\n *\n * Things to note:\n *\n * - The generator yields {@link SolanaRpcResponse} values from both the RPC response and\n * subscription notifications, each containing the slot context and the mapped value.\n * - Out-of-order values (by slot) are silently dropped — they are never yielded.\n * - On error from either source, the generator throws the error.\n * - Triggering the caller's abort signal causes the generator to return (complete without error).\n * - The generator completes when the subscription ends, an error occurs, or the abort signal fires.\n *\n * @param config\n *\n * @example\n * ```ts\n * import {\n * address,\n * createAsyncGeneratorWithInitialValueAndSlotTracking,\n * createSolanaRpc,\n * createSolanaRpcSubscriptions,\n * } from '@solana/kit';\n *\n * const rpc = createSolanaRpc('http://127.0.0.1:8899');\n * const rpcSubscriptions = createSolanaRpcSubscriptions('ws://127.0.0.1:8900');\n * const myAddress = address('FnHyam9w4NZoWR6mKN1CuGBritdsEWZQa4Z4oawLZGxa');\n *\n * const abortController = new AbortController();\n * for await (const balance of createAsyncGeneratorWithInitialValueAndSlotTracking({\n * abortSignal: abortController.signal,\n * rpcRequest: rpc.getBalance(myAddress, { commitment: 'confirmed' }),\n * rpcValueMapper: lamports => lamports,\n * rpcSubscriptionRequest: rpcSubscriptions.accountNotifications(myAddress),\n * rpcSubscriptionValueMapper: ({ lamports }) => lamports,\n * })) {\n * console.log(`Balance at slot ${balance.context.slot}:`, balance.value);\n * }\n * ```\n */\nexport async function* createAsyncGeneratorWithInitialValueAndSlotTracking<TRpcValue, TSubscriptionValue, TItem>({\n abortSignal,\n rpcRequest,\n rpcValueMapper,\n rpcSubscriptionRequest,\n rpcSubscriptionValueMapper,\n}: CreateAsyncGeneratorWithInitialValueAndSlotTrackingConfig<TRpcValue, TSubscriptionValue, TItem>): AsyncGenerator<\n SolanaRpcResponse<TItem>\n> {\n if (abortSignal.aborted) return;\n\n let lastUpdateSlot = -1n;\n\n // Shared queue for merging values from the RPC response and subscription notifications.\n const queue: SolanaRpcResponse<TItem>[] = [];\n let waitingResolve: ((value: IteratorResult<SolanaRpcResponse<TItem>>) => void) | null = null;\n let waitingReject: ((reason: unknown) => void) | null = null;\n let rpcDone = false;\n let subscriptionDone = false;\n let done = false;\n let pendingError: unknown;\n\n function markSourcesDone() {\n done = true;\n if (waitingResolve) {\n const resolve = waitingResolve;\n waitingResolve = null;\n waitingReject = null;\n resolve({ done: true, value: undefined });\n }\n }\n\n const abortController = new AbortController();\n const signal = abortController.signal;\n\n function onAbort() {\n done = true;\n abortController.abort(abortSignal.reason);\n if (waitingResolve) {\n const resolve = waitingResolve;\n waitingResolve = null;\n waitingReject = null;\n resolve({ done: true, value: undefined });\n }\n }\n abortSignal.addEventListener('abort', onAbort);\n\n function enqueue(item: SolanaRpcResponse<TItem>) {\n if (done || signal.aborted) return;\n if (waitingResolve) {\n // generator is waiting for a value, so resolve immediately\n const resolve = waitingResolve;\n waitingResolve = null;\n waitingReject = null;\n resolve({ done: false, value: item });\n } else {\n // No pending generator pull, so enqueue the item for future delivery\n queue.push(item);\n }\n }\n\n function handleError(err: unknown) {\n if (signal.aborted) return;\n done = true;\n pendingError = err;\n abortController.abort(err);\n if (waitingReject) {\n // generator is waiting for a value, so reject immediately\n const reject = waitingReject;\n waitingResolve = null;\n waitingReject = null;\n reject(err);\n }\n }\n\n // Start both sources concurrently.\n rpcRequest\n .send({ abortSignal: signal })\n .then(({ context: { slot }, value }) => {\n if (signal.aborted) return;\n if (slot < lastUpdateSlot) return;\n lastUpdateSlot = slot;\n enqueue({ context: { slot }, value: rpcValueMapper(value) });\n })\n .then(() => {\n rpcDone = true;\n if (subscriptionDone) markSourcesDone();\n })\n .catch(handleError);\n\n rpcSubscriptionRequest\n .subscribe({ abortSignal: signal })\n .then(async notifications => {\n for await (const {\n context: { slot },\n value,\n } of notifications) {\n if (signal.aborted) return;\n if (slot < lastUpdateSlot) continue;\n lastUpdateSlot = slot;\n enqueue({ context: { slot }, value: rpcSubscriptionValueMapper(value) });\n }\n // Subscription completed normally.\n subscriptionDone = true;\n if (rpcDone) markSourcesDone();\n })\n .catch(handleError);\n\n try {\n while (true) {\n if (pendingError) throw pendingError;\n if (queue.length > 0) {\n yield queue.shift()!;\n } else if (done) {\n return;\n } else {\n // if no value queued or error, wait for the next value or error\n const result: IteratorResult<SolanaRpcResponse<TItem>> = await new Promise((resolve, reject) => {\n waitingResolve = resolve;\n waitingReject = reject;\n });\n if (result.done) return;\n yield result.value;\n }\n }\n } finally {\n abortSignal.removeEventListener('abort', onAbort);\n if (!signal.aborted) {\n abortController.abort();\n }\n }\n}\n","import type { PendingRpcRequest } from '@solana/rpc';\nimport type { PendingRpcSubscriptionsRequest } from '@solana/rpc-subscriptions';\nimport type { SolanaRpcResponse } from '@solana/rpc-types';\nimport type { ReactiveState, ReactiveStreamStore } from '@solana/subscribable';\n\n/**\n * Configuration for {@link createReactiveStoreWithInitialValueAndSlotTracking}. Pairs a one-shot\n * RPC fetch with an ongoing subscription so the resulting store can hydrate from the initial\n * response and keep up to date with notifications, slot-deduplicating the two streams.\n *\n * @typeParam TRpcValue - The value type returned by `rpcRequest` (inside the {@link SolanaRpcResponse} envelope).\n * @typeParam TSubscriptionValue - The value type emitted by `rpcSubscriptionRequest` (inside the {@link SolanaRpcResponse} envelope).\n * @typeParam TItem - The unified item type the store holds, produced by the two value mappers.\n *\n * @see {@link createReactiveStoreWithInitialValueAndSlotTracking}\n */\nexport type CreateReactiveStoreWithInitialValueAndSlotTrackingConfig<TRpcValue, TSubscriptionValue, TItem> = Readonly<{\n /**\n * Triggering this abort signal will cancel the pending RPC request and subscription, and\n * disconnect the store from further updates.\n */\n abortSignal: AbortSignal;\n /**\n * A pending RPC request whose response will be used to set the store's initial state.\n * The response must be a {@link SolanaRpcResponse} so that its slot can be compared with\n * subscription notifications.\n */\n rpcRequest: PendingRpcRequest<SolanaRpcResponse<TRpcValue>>;\n /**\n * A pending RPC subscription request whose notifications will be used to keep the store\n * up to date. Each notification must be a {@link SolanaRpcResponse} so that its slot can be\n * compared with the initial RPC response and other notifications.\n */\n rpcSubscriptionRequest: PendingRpcSubscriptionsRequest<SolanaRpcResponse<TSubscriptionValue>>;\n /**\n * Maps the value from a subscription notification to the item type stored in the reactive store.\n */\n rpcSubscriptionValueMapper: (value: TSubscriptionValue) => TItem;\n /**\n * Maps the value from the RPC response to the item type stored in the reactive store.\n */\n rpcValueMapper: (value: TRpcValue) => TItem;\n}>;\n\nconst LOADING_STATE: ReactiveState<never> = Object.freeze({\n data: undefined,\n error: undefined,\n status: 'loading',\n});\n\n/**\n * Creates a {@link ReactiveStreamStore} that combines an initial RPC fetch with an ongoing subscription\n * to keep its state up to date.\n *\n * The store uses slot-based comparison to ensure that only the most recent value is kept,\n * regardless of whether it came from the initial RPC response or a subscription notification.\n * This prevents stale data from overwriting newer data when the RPC response and subscription\n * notifications arrive out of order.\n *\n * Things to note:\n *\n * - `getUnifiedState()` starts in `status: 'loading'` until the first response or notification\n * arrives. Once data arrives it transitions to `status: 'loaded'` with a\n * {@link SolanaRpcResponse} containing the value and the slot context at which it was observed.\n * - On error from either source, the store transitions to `status: 'error'` preserving the last\n * known value. Only the first error per connection window is captured.\n * - Calling {@link ReactiveStreamStore.retry | `retry()`} while in `status: 'error'` re-sends the RPC\n * request and re-subscribes to the subscription using a fresh inner abort signal. The store\n * transitions through `status: 'retrying'` back to `loaded`/`error`.\n * - Triggering the caller's abort signal disconnects the store permanently; subsequent `retry()`\n * calls are no-ops.\n *\n * @param config\n *\n * @example\n * ```ts\n * import {\n * address,\n * createReactiveStoreWithInitialValueAndSlotTracking,\n * createSolanaRpc,\n * createSolanaRpcSubscriptions,\n * } from '@solana/kit';\n *\n * const rpc = createSolanaRpc('http://127.0.0.1:8899');\n * const rpcSubscriptions = createSolanaRpcSubscriptions('ws://127.0.0.1:8900');\n * const myAddress = address('FnHyam9w4NZoWR6mKN1CuGBritdsEWZQa4Z4oawLZGxa');\n *\n * const balanceStore = createReactiveStoreWithInitialValueAndSlotTracking({\n * abortSignal: AbortSignal.timeout(60_000),\n * rpcRequest: rpc.getBalance(myAddress, { commitment: 'confirmed' }),\n * rpcValueMapper: lamports => lamports,\n * rpcSubscriptionRequest: rpcSubscriptions.accountNotifications(myAddress),\n * rpcSubscriptionValueMapper: ({ lamports }) => lamports,\n * });\n *\n * const unsubscribe = balanceStore.subscribe(() => {\n * const state = balanceStore.getUnifiedState();\n * if (state.status === 'error') {\n * console.error('Error:', state.error);\n * balanceStore.retry();\n * } else if (state.status === 'loaded') {\n * console.log(`Balance at slot ${state.data.context.slot}:`, state.data.value);\n * }\n * });\n * ```\n *\n * @see {@link ReactiveStreamStore}\n */\nexport function createReactiveStoreWithInitialValueAndSlotTracking<TRpcValue, TSubscriptionValue, TItem>({\n abortSignal,\n rpcRequest,\n rpcValueMapper,\n rpcSubscriptionRequest,\n rpcSubscriptionValueMapper,\n}: CreateReactiveStoreWithInitialValueAndSlotTrackingConfig<TRpcValue, TSubscriptionValue, TItem>): ReactiveStreamStore<\n SolanaRpcResponse<TItem>\n> {\n let currentState: ReactiveState<SolanaRpcResponse<TItem>> = LOADING_STATE;\n let lastUpdateSlot = -1n;\n const subscribers = new Set<() => void>();\n\n const outerController = new AbortController();\n abortSignal.addEventListener('abort', () => outerController.abort(abortSignal.reason));\n\n function notify() {\n subscribers.forEach(cb => cb());\n }\n\n function connect() {\n if (outerController.signal.aborted) return;\n const innerController = new AbortController();\n const forwardAbort = () => innerController.abort(outerController.signal.reason);\n outerController.signal.addEventListener('abort', forwardAbort, { signal: innerController.signal });\n const innerSignal = innerController.signal;\n\n function handleError(err: unknown) {\n if (innerSignal.aborted) return;\n if (currentState.status === 'error') return;\n currentState = { data: currentState.data, error: err, status: 'error' };\n innerController.abort(err);\n notify();\n }\n\n function handleValue(value: SolanaRpcResponse<TItem>) {\n currentState = { data: value, error: undefined, status: 'loaded' };\n notify();\n }\n\n rpcRequest\n .send({ abortSignal: innerSignal })\n .then(({ context: { slot }, value }) => {\n if (innerSignal.aborted) return;\n // `lastUpdateSlot` persists across retries so the store never regresses. If the\n // retried RPC returns a slot older than one we've already seen, we wait for the\n // subscription to deliver something newer before leaving `retrying`.\n if (slot < lastUpdateSlot) return;\n lastUpdateSlot = slot;\n handleValue({ context: { slot }, value: rpcValueMapper(value) });\n })\n .catch(handleError);\n\n rpcSubscriptionRequest\n .subscribe({ abortSignal: innerSignal })\n .then(async notifications => {\n for await (const {\n context: { slot },\n value,\n } of notifications) {\n if (innerSignal.aborted) return;\n if (slot < lastUpdateSlot) continue;\n lastUpdateSlot = slot;\n handleValue({ context: { slot }, value: rpcSubscriptionValueMapper(value) });\n }\n })\n .catch(handleError);\n }\n\n connect();\n\n return {\n getError(): unknown {\n return currentState.error;\n },\n getState(): SolanaRpcResponse<TItem> | undefined {\n return currentState.data;\n },\n getUnifiedState(): ReactiveState<SolanaRpcResponse<TItem>> {\n return currentState;\n },\n retry(): void {\n if (outerController.signal.aborted) return;\n if (currentState.status !== 'error') return;\n currentState = { data: currentState.data, error: undefined, status: 'retrying' };\n notify();\n connect();\n },\n subscribe(callback: () => void): () => void {\n subscribers.add(callback);\n return () => {\n subscribers.delete(callback);\n };\n },\n };\n}\n","import type { Address } from '@solana/addresses';\nimport type { Signature } from '@solana/keys';\nimport type { RequestAirdropApi, Rpc } from '@solana/rpc';\nimport type { Commitment, Lamports } from '@solana/rpc-types';\nimport { waitForRecentTransactionConfirmationUntilTimeout } from '@solana/transaction-confirmation';\n\ntype RequestAndConfirmAirdropConfig = Readonly<{\n abortSignal?: AbortSignal;\n commitment: Commitment;\n confirmSignatureOnlyTransaction: (\n config: Omit<\n Parameters<typeof waitForRecentTransactionConfirmationUntilTimeout>[0],\n 'getRecentSignatureConfirmationPromise' | 'getTimeoutPromise'\n >,\n ) => Promise<void>;\n lamports: Lamports;\n recipientAddress: Address;\n rpc: Rpc<RequestAirdropApi>;\n}>;\n\nexport async function requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({\n abortSignal,\n commitment,\n confirmSignatureOnlyTransaction,\n lamports,\n recipientAddress,\n rpc,\n}: RequestAndConfirmAirdropConfig): Promise<Signature> {\n const airdropTransactionSignature = await rpc\n .requestAirdrop(recipientAddress, lamports, { commitment })\n .send({ abortSignal });\n await confirmSignatureOnlyTransaction({\n abortSignal,\n commitment,\n signature: airdropTransactionSignature,\n });\n return airdropTransactionSignature;\n}\n","import type { Signature } from '@solana/keys';\nimport type { GetSignatureStatusesApi, RequestAirdropApi, Rpc } from '@solana/rpc';\nimport type { RpcSubscriptions, SignatureNotificationsApi } from '@solana/rpc-subscriptions';\nimport {\n createRecentSignatureConfirmationPromiseFactory,\n getTimeoutPromise,\n waitForRecentTransactionConfirmationUntilTimeout,\n} from '@solana/transaction-confirmation';\n\nimport { requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT } from './airdrop-internal';\n\ntype AirdropFunction = (\n config: Omit<\n Parameters<typeof requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT>[0],\n 'confirmSignatureOnlyTransaction' | 'rpc'\n >,\n) => Promise<Signature>;\n\ntype AirdropFactoryConfig<TCluster> = {\n /** An object that supports the {@link GetSignatureStatusesApi} and the {@link RequestAirdropApi} of the Solana RPC API */\n rpc: Rpc<GetSignatureStatusesApi & RequestAirdropApi> & { '~cluster'?: TCluster };\n /** An object that supports the {@link SignatureNotificationsApi} of the Solana RPC Subscriptions API */\n rpcSubscriptions: RpcSubscriptions<SignatureNotificationsApi> & { '~cluster'?: TCluster };\n};\n\n/**\n * Returns a function that you can call to airdrop a certain amount of {@link Lamports} to a Solana\n * address.\n *\n * > [!NOTE] This only works on test clusters.\n *\n * @param config\n *\n * @example\n * ```ts\n * import { address, airdropFactory, createSolanaRpc, createSolanaRpcSubscriptions, devnet, lamports } from '@solana/kit';\n *\n * const rpc = createSolanaRpc(devnet('http://127.0.0.1:8899'));\n * const rpcSubscriptions = createSolanaRpcSubscriptions(devnet('ws://127.0.0.1:8900'));\n *\n * const airdrop = airdropFactory({ rpc, rpcSubscriptions });\n *\n * await airdrop({\n * commitment: 'confirmed',\n * recipientAddress: address('FnHyam9w4NZoWR6mKN1CuGBritdsEWZQa4Z4oawLZGxa'),\n * lamports: lamports(10_000_000n),\n * });\n * ```\n */\nexport function airdropFactory({ rpc, rpcSubscriptions }: AirdropFactoryConfig<'devnet'>): AirdropFunction;\nexport function airdropFactory({ rpc, rpcSubscriptions }: AirdropFactoryConfig<'mainnet'>): AirdropFunction;\nexport function airdropFactory({ rpc, rpcSubscriptions }: AirdropFactoryConfig<'testnet'>): AirdropFunction;\nexport function airdropFactory<TCluster extends 'devnet' | 'mainnet' | 'testnet' | void = void>({\n rpc,\n rpcSubscriptions,\n}: AirdropFactoryConfig<TCluster>): AirdropFunction {\n const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory({\n rpc,\n rpcSubscriptions,\n } as Parameters<typeof createRecentSignatureConfirmationPromiseFactory>[0]);\n async function confirmSignatureOnlyTransaction(\n config: Omit<\n Parameters<typeof waitForRecentTransactionConfirmationUntilTimeout>[0],\n 'getRecentSignatureConfirmationPromise' | 'getTimeoutPromise'\n >,\n ) {\n await waitForRecentTransactionConfirmationUntilTimeout({\n ...config,\n getRecentSignatureConfirmationPromise,\n getTimeoutPromise,\n });\n }\n return async function airdrop(config) {\n return await requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({\n ...config,\n confirmSignatureOnlyTransaction,\n rpc,\n });\n };\n}\n","import {\n getSolanaErrorFromTransactionError,\n isSolanaError,\n type RpcSimulateTransactionResult,\n SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT,\n SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT,\n SolanaError,\n} from '@solana/errors';\nimport { pipe } from '@solana/functional';\nimport type { Rpc, SimulateTransactionApi } from '@solana/rpc';\nimport type { Commitment, Slot } from '@solana/rpc-types';\nimport {\n getTransactionMessageComputeUnitLimit,\n isTransactionMessageWithDurableNonceLifetime,\n setTransactionMessageComputeUnitLimit,\n TransactionMessage,\n TransactionMessageWithFeePayer,\n} from '@solana/transaction-messages';\nimport { compileTransaction, getBase64EncodedWireTransaction } from '@solana/transactions';\n\nconst PROVISORY_COMPUTE_UNIT_LIMIT = 0;\nconst MAX_COMPUTE_UNIT_LIMIT = 1_400_000;\n\ntype EstimateComputeUnitLimitFactoryConfig = Readonly<{\n rpc: Rpc<SimulateTransactionApi>;\n}>;\n\ntype EstimateComputeUnitLimitConfig = Readonly<{\n abortSignal?: AbortSignal;\n commitment?: Commitment;\n minContextSlot?: Slot;\n}>;\n\ntype EstimateComputeUnitLimitFunction = (\n transactionMessage: TransactionMessage & TransactionMessageWithFeePayer,\n config?: EstimateComputeUnitLimitConfig,\n) => Promise<number>;\n\n/**\n * Returns a function that estimates the compute units consumed by a transaction message by\n * simulating it.\n *\n * The estimator sets the compute unit limit to the maximum (1,400,000) before simulating, so the\n * simulation does not fail due to compute unit exhaustion. For blockhash-lifetime transactions, the\n * RPC is asked to replace the blockhash during simulation, so any blockhash value will work. For\n * durable nonce transactions, the actual nonce value is used.\n *\n * @param factoryConfig - An object containing the RPC instance to use for simulation.\n * @return A function that accepts a transaction message and returns the estimated compute units.\n *\n * @example\n * ```ts\n * import { estimateComputeUnitLimitFactory } from '@solana/kit';\n *\n * const estimateComputeUnitLimit = estimateComputeUnitLimitFactory({ rpc });\n * const estimatedUnits = await estimateComputeUnitLimit(transactionMessage);\n * ```\n *\n * @deprecated Use {@link estimateResourceLimitsFactory} instead. The resource-limits estimator\n * returns both the compute unit limit and (for version 1 transactions) the loaded accounts data\n * size limit from a single simulation call.\n */\nexport function estimateComputeUnitLimitFactory({\n rpc,\n}: EstimateComputeUnitLimitFactoryConfig): EstimateComputeUnitLimitFunction {\n return async function estimateComputeUnitLimit(transactionMessage, config) {\n const { abortSignal, ...simulateConfig } = config ?? {};\n const replaceRecentBlockhash = !isTransactionMessageWithDurableNonceLifetime(transactionMessage);\n\n const transaction = pipe(\n transactionMessage,\n m => setTransactionMessageComputeUnitLimit(MAX_COMPUTE_UNIT_LIMIT, m),\n compileTransaction,\n );\n const wireTransactionBytes = getBase64EncodedWireTransaction(transaction);\n\n try {\n const response = await rpc\n .simulateTransaction(wireTransactionBytes, {\n ...simulateConfig,\n encoding: 'base64',\n replaceRecentBlockhash,\n sigVerify: false,\n })\n .send({ abortSignal });\n // The API response type varies based on config (eg. `replacementBlockhash` is only\n // present when `replaceRecentBlockhash` is true), but `RpcSimulateTransactionResult`\n // is a flat superset. Cast through `unknown` to bridge the structural gap.\n const { err: transactionError, ...simulationResult } =\n response.value as unknown as RpcSimulateTransactionResult;\n\n if (simulationResult.unitsConsumed == null) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT);\n }\n\n if (transactionError) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, {\n ...simulationResult,\n cause: getSolanaErrorFromTransactionError(transactionError),\n });\n }\n\n // Downcast from bigint to number, capping at u32 max.\n return simulationResult.unitsConsumed > 4_294_967_295n\n ? 4_294_967_295\n : Number(simulationResult.unitsConsumed);\n } catch (e) {\n if (isSolanaError(e, SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT)) {\n throw e;\n }\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, {\n cause: e,\n });\n }\n };\n}\n\n/**\n * Returns a function that estimates the compute unit limit for a transaction message and sets it on\n * the message. If the message already has an explicit compute unit limit set (one that is not the\n * provisory value of 0, and not the maximum of 1,400,000), the message is returned unchanged.\n *\n * This is designed to work with {@link fillTransactionMessageProvisoryComputeUnitLimit}: first add a provisory limit\n * during transaction construction, then later estimate and replace it before sending.\n *\n * @param estimateComputeUnitLimit - The estimator function, typically created by\n * {@link estimateComputeUnitLimitFactory}. You can also pass a custom wrapper that adds a buffer\n * (e.g. multiply the estimate by 1.1).\n * @return A function that accepts a transaction message and returns it with the compute unit limit\n * set to the estimated value.\n *\n * @example\n * ```ts\n * import { estimateAndSetComputeUnitLimitFactory, estimateComputeUnitLimitFactory } from '@solana/kit';\n *\n * const estimator = estimateComputeUnitLimitFactory({ rpc });\n * const estimateAndSet = estimateAndSetComputeUnitLimitFactory(estimator);\n * const updatedMessage = await estimateAndSet(transactionMessage);\n * ```\n *\n * @deprecated Use {@link estimateAndSetResourceLimitsFactory} instead, which additionally sets the\n * loaded accounts data size limit for version 1 transactions.\n */\nexport function estimateAndSetComputeUnitLimitFactory(\n estimateComputeUnitLimit: EstimateComputeUnitLimitFunction,\n): <TTransactionMessage extends TransactionMessage & TransactionMessageWithFeePayer>(\n transactionMessage: TTransactionMessage,\n config?: EstimateComputeUnitLimitConfig,\n) => Promise<TTransactionMessage> {\n return async function estimateAndSetComputeUnitLimit(transactionMessage, config) {\n const existingLimit = getTransactionMessageComputeUnitLimit(transactionMessage);\n\n // If a non-provisory, non-max CU limit is already set, leave it as-is.\n if (existingLimit && existingLimit !== MAX_COMPUTE_UNIT_LIMIT) {\n return transactionMessage;\n }\n\n const estimatedUnits = await estimateComputeUnitLimit(transactionMessage, config);\n return setTransactionMessageComputeUnitLimit(estimatedUnits, transactionMessage);\n };\n}\n\n/**\n * Sets the compute unit limit to a provisory value of 0 if no compute unit limit is currently set\n * on the transaction message. If a limit is already set (any value, including 0), the message is\n * returned unchanged.\n *\n * This is useful during transaction construction to reserve space for a compute unit limit that\n * will later be replaced with an actual estimate via\n * {@link estimateAndSetComputeUnitLimitFactory}.\n *\n * @param transactionMessage - The transaction message to add a provisory limit to.\n * @return The transaction message with a provisory compute unit limit set, or unchanged if one was\n * already present.\n *\n * @example\n * ```ts\n * import { fillTransactionMessageProvisoryComputeUnitLimit } from '@solana/kit';\n *\n * const messageWithProvisoryLimit = fillTransactionMessageProvisoryComputeUnitLimit(transactionMessage);\n * ```\n *\n * @deprecated Use {@link fillTransactionMessageProvisoryResourceLimits} instead, which additionally\n * reserves space for the loaded accounts data size limit on version 1 transactions.\n */\nexport function fillTransactionMessageProvisoryComputeUnitLimit<TTransactionMessage extends TransactionMessage>(\n transactionMessage: TTransactionMessage,\n): TTransactionMessage {\n if (getTransactionMessageComputeUnitLimit(transactionMessage) !== undefined) {\n return transactionMessage;\n }\n return setTransactionMessageComputeUnitLimit(PROVISORY_COMPUTE_UNIT_LIMIT, transactionMessage);\n}\n","import {\n assertAccountsDecoded,\n assertAccountsExist,\n type FetchAccountsConfig,\n fetchJsonParsedAccounts,\n} from '@solana/accounts';\nimport type { Address } from '@solana/addresses';\nimport type { GetMultipleAccountsApi, Rpc } from '@solana/rpc';\nimport { type AddressesByLookupTableAddress } from '@solana/transaction-messages';\n\ntype FetchedAddressLookup = {\n addresses: Address[];\n};\n\n/**\n * Given a list of addresses belonging to address lookup tables, returns a map of lookup table\n * addresses to an ordered array of the addresses they contain.\n *\n * @param rpc An object that supports the {@link GetMultipleAccountsApi} of the Solana RPC API\n * @param config\n */\nexport async function fetchAddressesForLookupTables(\n lookupTableAddresses: Address[],\n rpc: Rpc<GetMultipleAccountsApi>,\n config?: FetchAccountsConfig,\n): Promise<AddressesByLookupTableAddress> {\n if (lookupTableAddresses.length === 0) {\n return {};\n }\n\n const fetchedLookupTables = await fetchJsonParsedAccounts<FetchedAddressLookup[]>(\n rpc,\n lookupTableAddresses,\n config,\n );\n\n assertAccountsDecoded(fetchedLookupTables);\n assertAccountsExist(fetchedLookupTables);\n\n return fetchedLookupTables.reduce<AddressesByLookupTableAddress>((acc, lookup) => {\n return {\n ...acc,\n [lookup.address]: lookup.data.addresses,\n };\n }, {});\n}\n","import { type FetchAccountsConfig } from '@solana/accounts';\nimport type { GetMultipleAccountsApi, Rpc } from '@solana/rpc';\nimport {\n CompiledTransactionMessage,\n CompiledTransactionMessageWithLifetime,\n decompileTransactionMessage,\n TransactionMessage,\n TransactionMessageWithFeePayer,\n TransactionMessageWithLifetime,\n} from '@solana/transaction-messages';\n\nimport { fetchAddressesForLookupTables } from './fetch-lookup-tables';\n\ntype DecompileTransactionMessageFetchingLookupTablesConfig = FetchAccountsConfig & {\n lastValidBlockHeight?: bigint;\n};\n\n/**\n * Returns a {@link TransactionMessage} from a {@link CompiledTransactionMessage}. If any of the\n * accounts in the compiled message require an address lookup table to find their address, this\n * function will use the supplied RPC instance to fetch the contents of the address lookup table\n * from the network.\n *\n * @param rpc An object that supports the {@link GetMultipleAccountsApi} of the Solana RPC API\n * @param config\n */\nexport async function decompileTransactionMessageFetchingLookupTables(\n compiledTransactionMessage: CompiledTransactionMessage & CompiledTransactionMessageWithLifetime,\n rpc: Rpc<GetMultipleAccountsApi>,\n config?: DecompileTransactionMessageFetchingLookupTablesConfig,\n): Promise<TransactionMessage & TransactionMessageWithFeePayer & TransactionMessageWithLifetime> {\n const lookupTables =\n 'addressTableLookups' in compiledTransactionMessage &&\n compiledTransactionMessage.addressTableLookups !== undefined &&\n compiledTransactionMessage.addressTableLookups.length > 0\n ? compiledTransactionMessage.addressTableLookups\n : [];\n const lookupTableAddresses = lookupTables.map(l => l.lookupTableAddress);\n\n const { lastValidBlockHeight, ...fetchAccountsConfig } = config ?? {};\n const addressesByLookupTableAddress =\n lookupTableAddresses.length > 0\n ? await fetchAddressesForLookupTables(lookupTableAddresses, rpc, fetchAccountsConfig)\n : {};\n\n return decompileTransactionMessage(compiledTransactionMessage, {\n addressesByLookupTableAddress,\n lastValidBlockHeight,\n });\n}\n","import {\n getSolanaErrorFromTransactionError,\n isSolanaError,\n type RpcSimulateTransactionResult,\n SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT,\n SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_LOADED_ACCOUNTS_DATA_SIZE_LIMIT,\n SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_RESOURCE_LIMITS,\n SolanaError,\n} from '@solana/errors';\nimport { pipe } from '@solana/functional';\nimport type { Rpc, SimulateTransactionApi } from '@solana/rpc';\nimport type { Commitment, Slot } from '@solana/rpc-types';\nimport {\n getTransactionMessageComputeUnitLimit,\n getTransactionMessageLoadedAccountsDataSizeLimit,\n isTransactionMessageWithDurableNonceLifetime,\n setTransactionMessageComputeUnitLimit,\n setTransactionMessageLoadedAccountsDataSizeLimit,\n TransactionMessage,\n TransactionMessageWithFeePayer,\n} from '@solana/transaction-messages';\nimport { compileTransaction, getBase64EncodedWireTransaction } from '@solana/transactions';\n\nconst PROVISORY_LIMIT = 0;\n// From Agave: https://github.com/anza-xyz/agave/blob/2a165e7a90af75c76426d1e031ed0284211d5d1e/program-runtime/src/execution_budget.rs#L39\nconst MAX_COMPUTE_UNIT_LIMIT = 1_400_000;\n// From Agave: https://github.com/anza-xyz/agave/blob/2a165e7a90af75c76426d1e031ed0284211d5d1e/program-runtime/src/execution_budget.rs#L53\nconst MAX_LOADED_ACCOUNTS_DATA_SIZE_LIMIT = 64 * 1024 * 1024;\n\ntype EstimateResourceLimitsFactoryConfig = Readonly<{\n rpc: Rpc<SimulateTransactionApi>;\n}>;\n\ntype EstimateResourceLimitsConfig = Readonly<{\n abortSignal?: AbortSignal;\n commitment?: Commitment;\n minContextSlot?: Slot;\n}>;\n\n/**\n * The estimated resource limits for a transaction message.\n *\n * `computeUnitLimit` is always returned. For version 1 transaction messages,\n * `loadedAccountsDataSizeLimit` is also required. For legacy and version 0 messages, the\n * `loadedAccountsDataSizeLimit` is returned when the RPC includes it in the simulation result,\n * but is not required — callers that don't apply it can ignore the field.\n */\nexport type ResourceLimitsEstimate<TTransactionMessage extends TransactionMessage> = TTransactionMessage extends {\n version: 1;\n}\n ? { computeUnitLimit: number; loadedAccountsDataSizeLimit: number }\n : { computeUnitLimit: number; loadedAccountsDataSizeLimit?: number };\n\ntype EstimateResourceLimitsFunction = <TTransactionMessage extends TransactionMessage & TransactionMessageWithFeePayer>(\n transactionMessage: TTransactionMessage,\n config?: EstimateResourceLimitsConfig,\n) => Promise<ResourceLimitsEstimate<TTransactionMessage>>;\n\n/**\n * Returns a function that estimates the resource limits required by a transaction message by\n * simulating it.\n *\n * The estimator sets the compute unit limit to the maximum (1,400,000) and the loaded accounts data\n * size limit to the maximum (64 MiB) before simulating, so the simulation does not fail due to\n * resource exhaustion. For blockhash-lifetime transactions, the RPC is asked to replace the\n * blockhash during simulation, so any blockhash value will work. For durable nonce transactions,\n * the actual nonce value is used.\n *\n * For version 1 transaction messages, both `computeUnitLimit` and `loadedAccountsDataSizeLimit` are\n * returned. The function throws if the RPC does not return a `loadedAccountsDataSize` value, since\n * this value is required for version 1 transactions. For legacy and version 0 messages, only\n * `computeUnitLimit` is returned.\n *\n * @param factoryConfig - An object containing the RPC instance to use for simulation.\n * @return A function that accepts a transaction message and returns the estimated resource limits.\n *\n * @example\n * ```ts\n * import { estimateResourceLimitsFactory } from '@solana/kit';\n *\n * const estimateResourceLimits = estimateResourceLimitsFactory({ rpc });\n * const { computeUnitLimit, loadedAccountsDataSizeLimit } = await estimateResourceLimits(transactionMessage);\n * ```\n */\nexport function estimateResourceLimitsFactory({\n rpc,\n}: EstimateResourceLimitsFactoryConfig): EstimateResourceLimitsFunction {\n return async function estimateResourceLimits<\n TTransactionMessage extends TransactionMessage & TransactionMessageWithFeePayer,\n >(transactionMessage: TTransactionMessage, config?: EstimateResourceLimitsConfig) {\n const { abortSignal, ...simulateConfig } = config ?? {};\n const replaceRecentBlockhash = !isTransactionMessageWithDurableNonceLifetime(transactionMessage);\n const isDataSizeRequired = transactionMessage.version === 1;\n\n const transaction = pipe(\n transactionMessage,\n m => setTransactionMessageComputeUnitLimit(MAX_COMPUTE_UNIT_LIMIT, m),\n m =>\n isDataSizeRequired\n ? setTransactionMessageLoadedAccountsDataSizeLimit(MAX_LOADED_ACCOUNTS_DATA_SIZE_LIMIT, m)\n : m,\n compileTransaction,\n );\n const wireTransactionBytes = getBase64EncodedWireTransaction(transaction);\n\n try {\n const response = await rpc\n .simulateTransaction(wireTransactionBytes, {\n ...simulateConfig,\n encoding: 'base64',\n replaceRecentBlockhash,\n sigVerify: false,\n })\n .send({ abortSignal });\n // The API response type varies based on config (eg. `replacementBlockhash` is only\n // present when `replaceRecentBlockhash` is true), but `RpcSimulateTransactionResult`\n // is a flat superset. Cast through `unknown` to bridge the structural gap.\n const { err: transactionError, ...simulationResult } =\n response.value as unknown as RpcSimulateTransactionResult;\n\n if (simulationResult.unitsConsumed == null) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT);\n }\n\n if (isDataSizeRequired && simulationResult.loadedAccountsDataSize == null) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_LOADED_ACCOUNTS_DATA_SIZE_LIMIT);\n }\n\n if (transactionError) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_RESOURCE_LIMITS, {\n ...simulationResult,\n cause: getSolanaErrorFromTransactionError(transactionError),\n });\n }\n\n // Downcast from bigint to number, capping at u32 max.\n const computeUnitLimit =\n simulationResult.unitsConsumed > 4_294_967_295n\n ? 4_294_967_295\n : Number(simulationResult.unitsConsumed);\n\n if (isDataSizeRequired) {\n return {\n computeUnitLimit,\n loadedAccountsDataSizeLimit: simulationResult.loadedAccountsDataSize!,\n } as ResourceLimitsEstimate<TTransactionMessage>;\n }\n return (\n simulationResult.loadedAccountsDataSize == null\n ? { computeUnitLimit }\n : { computeUnitLimit, loadedAccountsDataSizeLimit: simulationResult.loadedAccountsDataSize }\n ) as ResourceLimitsEstimate<TTransactionMessage>;\n } catch (e) {\n if (\n isSolanaError(e, SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_RESOURCE_LIMITS) ||\n isSolanaError(e, SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_LOADED_ACCOUNTS_DATA_SIZE_LIMIT)\n ) {\n throw e;\n }\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, {\n cause: e,\n });\n }\n };\n}\n\n/**\n * Returns a function that estimates the resource limits for a transaction message and sets them on\n * the message.\n *\n * For all versions, the compute unit limit is updated to the estimated value if it is not already\n * set to an explicit, non-provisory value. The compute unit limit also treats the maximum\n * (1,400,000) as non-explicit, so messages that pre-set the max for simulation get re-estimated.\n *\n * For version 1 messages, the loaded accounts data size limit is updated only if it is unset or set\n * to the provisory value of 0. An explicit value — including the runtime maximum — is left\n * untouched, since callers who set it explicitly are signaling a deliberate choice.\n *\n * This is designed to work with {@link fillTransactionMessageProvisoryResourceLimits}: first add\n * provisory limits during transaction construction, then later estimate and replace them before\n * sending.\n *\n * @param estimateResourceLimits - The estimator function, typically created by\n * {@link estimateResourceLimitsFactory}. You can also pass a custom wrapper that applies a buffer\n * to the returned values.\n * @return A function that accepts a transaction message and returns it with resource limits set to\n * the estimated values.\n *\n * @example\n * ```ts\n * import { estimateAndSetResourceLimitsFactory, estimateResourceLimitsFactory } from '@solana/kit';\n *\n * const estimator = estimateResourceLimitsFactory({ rpc });\n * const estimateAndSet = estimateAndSetResourceLimitsFactory(estimator);\n * const updatedMessage = await estimateAndSet(transactionMessage);\n * ```\n */\nexport function estimateAndSetResourceLimitsFactory(\n estimateResourceLimits: EstimateResourceLimitsFunction,\n): <TTransactionMessage extends TransactionMessage & TransactionMessageWithFeePayer>(\n transactionMessage: TTransactionMessage,\n config?: EstimateResourceLimitsConfig,\n) => Promise<TTransactionMessage> {\n return async function estimateAndSetResourceLimits(transactionMessage, config) {\n const existingComputeUnitLimit = getTransactionMessageComputeUnitLimit(transactionMessage);\n const computeUnitLimitIsExplicit =\n existingComputeUnitLimit !== undefined &&\n existingComputeUnitLimit !== PROVISORY_LIMIT &&\n existingComputeUnitLimit !== MAX_COMPUTE_UNIT_LIMIT;\n\n const isV1 = transactionMessage.version === 1;\n let loadedAccountsDataSizeLimitIsExplicit = true;\n if (isV1) {\n const existingLoadedAccountsDataSizeLimit =\n getTransactionMessageLoadedAccountsDataSizeLimit(transactionMessage);\n loadedAccountsDataSizeLimitIsExplicit =\n existingLoadedAccountsDataSizeLimit !== undefined &&\n existingLoadedAccountsDataSizeLimit !== PROVISORY_LIMIT;\n }\n\n // Nothing to do — every applicable limit is already explicitly set.\n if (computeUnitLimitIsExplicit && loadedAccountsDataSizeLimitIsExplicit) {\n return transactionMessage;\n }\n\n const estimate = await estimateResourceLimits(transactionMessage, config);\n\n let result = transactionMessage;\n if (!computeUnitLimitIsExplicit) {\n result = setTransactionMessageComputeUnitLimit(estimate.computeUnitLimit, result);\n }\n if (isV1 && !loadedAccountsDataSizeLimitIsExplicit && 'loadedAccountsDataSizeLimit' in estimate) {\n result = setTransactionMessageLoadedAccountsDataSizeLimit(estimate.loadedAccountsDataSizeLimit, result);\n }\n return result;\n };\n}\n\n/**\n * Sets resource limits to a provisory value of 0 if no limit is currently set on the transaction\n * message.\n *\n * For all versions, this fills the compute unit limit. For version 1 messages, it also fills the\n * loaded accounts data size limit. If a limit is already set (any value, including 0), that limit\n * is left unchanged.\n *\n * This is useful during transaction construction to reserve space for resource limits that will\n * later be replaced with actual estimates via {@link estimateAndSetResourceLimitsFactory}.\n *\n * @param transactionMessage - The transaction message to add provisory limits to.\n * @return The transaction message with provisory resource limits set, or unchanged if all\n * applicable limits were already present.\n *\n * @example\n * ```ts\n * import { fillTransactionMessageProvisoryResourceLimits } from '@solana/kit';\n *\n * const messageWithProvisoryLimits = fillTransactionMessageProvisoryResourceLimits(transactionMessage);\n * ```\n */\nexport function fillTransactionMessageProvisoryResourceLimits<TTransactionMessage extends TransactionMessage>(\n transactionMessage: TTransactionMessage,\n): TTransactionMessage {\n let result: TTransactionMessage = transactionMessage;\n if (getTransactionMessageComputeUnitLimit(result) === undefined) {\n result = setTransactionMessageComputeUnitLimit(PROVISORY_LIMIT, result);\n }\n if (result.version === 1 && getTransactionMessageLoadedAccountsDataSizeLimit(result) === undefined) {\n result = setTransactionMessageLoadedAccountsDataSizeLimit(PROVISORY_LIMIT, result);\n }\n return result;\n}\n","import type { Lamports } from '@solana/rpc-types';\n\n/**\n * Calculates the minimum {@link Lamports | lamports} required to make an account rent exempt for a\n * given data size, without performing an RPC call.\n *\n * Values are sourced from the on-chain rent parameters in the Solana runtime:\n * https://github.com/anza-xyz/solana-sdk/blob/c07f692e41d757057c8700211a9300cdcd6d33b1/rent/src/lib.rs#L93-L97\n *\n * Note that this logic may change, or be incorrect depending on the cluster you are connected to.\n * You can always use the RPC method `getMinimumBalanceForRentExemption` to get the current value.\n *\n * @deprecated The minimum balance for an account is being actively reduced\n * (see {@link https://github.com/solana-foundation/solana-improvement-documents/pull/437 | SIMD-0437})\n * and is expected to become dynamic in future Solana upgrades\n * (see {@link https://github.com/solana-foundation/solana-improvement-documents/pull/194 | SIMD-0194}\n * and {@link https://github.com/solana-foundation/solana-improvement-documents/pull/389 | SIMD-0389}),\n * meaning a hardcoded local computation will no longer return accurate results. Use the\n * {@link GetMinimumBalanceForRentExemptionApi.getMinimumBalanceForRentExemption | getMinimumBalanceForRentExemption}\n * RPC method or a `ClientWithGetMinimumBalance` plugin instead. This function will be removed in v7.\n *\n * @param space The number of bytes of account data.\n */\nexport function getMinimumBalanceForRentExemption(space: bigint): Lamports {\n const RENT = {\n ACCOUNT_STORAGE_OVERHEAD: 128n,\n DEFAULT_EXEMPTION_THRESHOLD: 2n,\n DEFAULT_LAMPORTS_PER_BYTE_YEAR: 3_480n,\n } as const;\n const requiredLamports =\n (RENT.ACCOUNT_STORAGE_OVERHEAD + space) *\n RENT.DEFAULT_LAMPORTS_PER_BYTE_YEAR *\n RENT.DEFAULT_EXEMPTION_THRESHOLD;\n return requiredLamports as Lamports;\n}\n","import type { Signature } from '@solana/keys';\nimport type { Rpc, SendTransactionApi } from '@solana/rpc';\nimport { Commitment, commitmentComparator } from '@solana/rpc-types';\nimport {\n TransactionWithLastValidBlockHeight,\n waitForDurableNonceTransactionConfirmation,\n waitForRecentTransactionConfirmation,\n} from '@solana/transaction-confirmation';\nimport {\n getBase64EncodedWireTransaction,\n SendableTransaction,\n Transaction,\n TransactionWithDurableNonceLifetime,\n} from '@solana/transactions';\n\ninterface SendAndConfirmDurableNonceTransactionConfig\n extends SendTransactionBaseConfig, SendTransactionConfigWithoutEncoding {\n confirmDurableNonceTransaction: (\n config: Omit<\n Parameters<typeof waitForDurableNonceTransactionConfirmation>[0],\n 'getNonceInvalidationPromise' | 'getRecentSignatureConfirmationPromise'\n >,\n ) => Promise<void>;\n transaction: SendableTransaction & Transaction & TransactionWithDurableNonceLifetime;\n}\n\ninterface SendAndConfirmTransactionWithBlockhashLifetimeConfig\n extends SendTransactionBaseConfig, SendTransactionConfigWithoutEncoding {\n confirmRecentTransaction: (\n config: Omit<\n Parameters<typeof waitForRecentTransactionConfirmation>[0],\n 'getBlockHeightExceedencePromise' | 'getRecentSignatureConfirmationPromise'\n >,\n ) => Promise<void>;\n transaction: SendableTransaction & Transaction & TransactionWithLastValidBlockHeight;\n}\n\ninterface SendTransactionBaseConfig extends SendTransactionConfigWithoutEncoding {\n abortSignal?: AbortSignal;\n commitment: Commitment;\n rpc: Rpc<SendTransactionApi>;\n transaction: SendableTransaction & Transaction;\n}\n\ntype SendTransactionConfigWithoutEncoding = Omit<\n NonNullable<Parameters<SendTransactionApi['sendTransaction']>[1]>,\n 'encoding'\n>;\n\nfunction getSendTransactionConfigWithAdjustedPreflightCommitment(\n commitment: Commitment,\n config?: SendTransactionConfigWithoutEncoding,\n): SendTransactionConfigWithoutEncoding | void {\n if (\n // The developer has supplied no value for `preflightCommitment`.\n !config?.preflightCommitment &&\n // The value of `commitment` is lower than the server default of `preflightCommitment`.\n commitmentComparator(commitment, 'finalized' /* default value of `preflightCommitment` */) < 0\n ) {\n return {\n ...config,\n // In the common case, it is unlikely that you want to simulate a transaction at\n // `finalized` commitment when your standard of commitment for confirming the\n // transaction is lower. Cap the simulation commitment level to the level of the\n // confirmation commitment.\n preflightCommitment: commitment,\n };\n }\n // The commitment at which the developer wishes to confirm the transaction is at least as\n // high as the commitment at which they want to simulate it. Honour the config as-is.\n return config;\n}\n\nexport async function sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({\n abortSignal,\n commitment,\n rpc,\n transaction,\n ...sendTransactionConfig\n}: SendTransactionBaseConfig): Promise<Signature> {\n const base64EncodedWireTransaction = getBase64EncodedWireTransaction(transaction);\n return await rpc\n .sendTransaction(base64EncodedWireTransaction, {\n ...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),\n encoding: 'base64',\n })\n .send({ abortSignal });\n}\n\nexport async function sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({\n abortSignal,\n commitment,\n confirmDurableNonceTransaction,\n rpc,\n transaction,\n ...sendTransactionConfig\n}: SendAndConfirmDurableNonceTransactionConfig): Promise<Signature> {\n const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({\n ...sendTransactionConfig,\n abortSignal,\n commitment,\n rpc,\n transaction,\n });\n await confirmDurableNonceTransaction({\n abortSignal,\n commitment,\n transaction,\n });\n return transactionSignature;\n}\n\nexport async function sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({\n abortSignal,\n commitment,\n confirmRecentTransaction,\n rpc,\n transaction,\n ...sendTransactionConfig\n}: SendAndConfirmTransactionWithBlockhashLifetimeConfig): Promise<Signature> {\n const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({\n ...sendTransactionConfig,\n abortSignal,\n commitment,\n rpc,\n transaction,\n });\n await confirmRecentTransaction({\n abortSignal,\n commitment,\n transaction,\n });\n return transactionSignature;\n}\n","import { getSolanaErrorFromTransactionError, isSolanaError, SOLANA_ERROR__INVALID_NONCE } from '@solana/errors';\nimport { Signature } from '@solana/keys';\nimport type { GetAccountInfoApi, GetSignatureStatusesApi, Rpc, SendTransactionApi } from '@solana/rpc';\nimport type { AccountNotificationsApi, RpcSubscriptions, SignatureNotificationsApi } from '@solana/rpc-subscriptions';\nimport { commitmentComparator } from '@solana/rpc-types';\nimport {\n createNonceInvalidationPromiseFactory,\n createRecentSignatureConfirmationPromiseFactory,\n waitForDurableNonceTransactionConfirmation,\n} from '@solana/transaction-confirmation';\nimport {\n getSignatureFromTransaction,\n SendableTransaction,\n Transaction,\n TransactionWithDurableNonceLifetime,\n} from '@solana/transactions';\n\nimport { sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT } from './send-transaction-internal';\n\ntype SendAndConfirmDurableNonceTransactionFunction = (\n transaction: SendableTransaction & Transaction & TransactionWithDurableNonceLifetime,\n config: Omit<\n Parameters<typeof sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT>[0],\n 'confirmDurableNonceTransaction' | 'rpc' | 'transaction'\n >,\n) => Promise<void>;\n\ntype SendAndConfirmDurableNonceTransactionFactoryConfig<TCluster> = {\n /** An object that supports the {@link GetSignatureStatusesApi} and the {@link SendTransactionApi} of the Solana RPC API */\n rpc: Rpc<GetAccountInfoApi & GetSignatureStatusesApi & SendTransactionApi> & { '~cluster'?: TCluster };\n /** An object that supports the {@link AccountNotificationsApi} and the {@link SignatureNotificationsApi} of the Solana RPC Subscriptions API */\n rpcSubscriptions: RpcSubscriptions<AccountNotificationsApi & SignatureNotificationsApi> & { '~cluster'?: TCluster };\n};\n\n/**\n * Returns a function that you can call to send a nonce-based transaction to the network and to wait\n * until it has been confirmed.\n *\n * @param config\n *\n * @example\n * ```ts\n * import {\n * isSolanaError,\n * sendAndConfirmDurableNonceTransactionFactory,\n * SOLANA_ERROR__INVALID_NONCE,\n * SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND,\n * } from '@solana/kit';\n *\n * const sendAndConfirmNonceTransaction = sendAndConfirmDurableNonceTransactionFactory({ rpc, rpcSubscriptions });\n *\n * try {\n * await sendAndConfirmNonceTransaction(transaction, { commitment: 'confirmed' });\n * } catch (e) {\n * if (isSolanaError(e, SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND)) {\n * console.error(\n * 'The lifetime specified by this transaction refers to a nonce account ' +\n * `\\`${e.context.nonceAccountAddress}\\` that does not exist`,\n * );\n * } else if (isSolanaError(e, SOLANA_ERROR__INVALID_NONCE)) {\n * console.error('This transaction depends on a nonce that is no longer valid');\n * } else {\n * throw e;\n * }\n * }\n * ```\n */\nexport function sendAndConfirmDurableNonceTransactionFactory({\n rpc,\n rpcSubscriptions,\n}: SendAndConfirmDurableNonceTransactionFactoryConfig<'devnet'>): SendAndConfirmDurableNonceTransactionFunction;\nexport function sendAndConfirmDurableNonceTransactionFactory({\n rpc,\n rpcSubscriptions,\n}: SendAndConfirmDurableNonceTransactionFactoryConfig<'testnet'>): SendAndConfirmDurableNonceTransactionFunction;\nexport function sendAndConfirmDurableNonceTransactionFactory({\n rpc,\n rpcSubscriptions,\n}: SendAndConfirmDurableNonceTransactionFactoryConfig<'mainnet'>): SendAndConfirmDurableNonceTransactionFunction;\nexport function sendAndConfirmDurableNonceTransactionFactory<\n TCluster extends 'devnet' | 'mainnet' | 'testnet' | void = void,\n>({\n rpc,\n rpcSubscriptions,\n}: SendAndConfirmDurableNonceTransactionFactoryConfig<TCluster>): SendAndConfirmDurableNonceTransactionFunction {\n const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory({ rpc, rpcSubscriptions } as Parameters<\n typeof createNonceInvalidationPromiseFactory\n >[0]);\n const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory({\n rpc,\n rpcSubscriptions,\n } as Parameters<typeof createRecentSignatureConfirmationPromiseFactory>[0]);\n\n /**\n * Creates a wrapped version of getNonceInvalidationPromise that handles the race condition\n * where the nonce account update notification arrives before the signature confirmation.\n *\n * When the nonce changes, we check if our transaction actually landed on-chain.\n * If it did, we don't throw - letting the signature confirmation promise continue.\n */\n function createNonceInvalidationPromiseHandlingRaceCondition(\n signature: Signature,\n ): typeof getNonceInvalidationPromise {\n return async function wrappedGetNonceInvalidationPromise(config) {\n try {\n return await getNonceInvalidationPromise(config);\n } catch (e) {\n // If nonce became invalid, check if our transaction actually landed\n if (isSolanaError(e, SOLANA_ERROR__INVALID_NONCE)) {\n let status;\n try {\n const { value: statuses } = await rpc\n .getSignatureStatuses([signature])\n .send({ abortSignal: config.abortSignal });\n status = statuses[0];\n } catch {\n // RPC failed - propagate the original nonce error\n throw e;\n }\n\n if (status === null || status === undefined) {\n // Transaction doesn't exist - nonce was truly invalid\n throw e;\n }\n\n // Check if status meets required commitment\n if (\n status.confirmationStatus !== null &&\n commitmentComparator(status.confirmationStatus, config.commitment) >= 0\n ) {\n // Transaction failed on-chain, throw the error from the transaction\n if (status.err !== null) {\n throw getSolanaErrorFromTransactionError(status.err);\n }\n // Transaction succeeded, resolve the promise successfully\n return;\n }\n\n // Commitment not met yet - return a never-resolving promise\n // This lets the signature confirmation promise continue\n return await new Promise(() => {});\n }\n throw e;\n }\n };\n }\n\n async function confirmDurableNonceTransaction(\n config: Omit<\n Parameters<typeof waitForDurableNonceTransactionConfirmation>[0],\n 'getNonceInvalidationPromise' | 'getRecentSignatureConfirmationPromise'\n >,\n ) {\n const wrappedGetNonceInvalidationPromise = createNonceInvalidationPromiseHandlingRaceCondition(\n getSignatureFromTransaction(config.transaction),\n );\n\n await waitForDurableNonceTransactionConfirmation({\n ...config,\n getNonceInvalidationPromise: wrappedGetNonceInvalidationPromise,\n getRecentSignatureConfirmationPromise,\n });\n }\n return async function sendAndConfirmDurableNonceTransaction(transaction, config) {\n await sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({\n ...config,\n confirmDurableNonceTransaction,\n rpc,\n transaction,\n });\n };\n}\n","import type { GetEpochInfoApi, GetSignatureStatusesApi, Rpc, SendTransactionApi } from '@solana/rpc';\nimport type { RpcSubscriptions, SignatureNotificationsApi, SlotNotificationsApi } from '@solana/rpc-subscriptions';\nimport {\n createBlockHeightExceedencePromiseFactory,\n createRecentSignatureConfirmationPromiseFactory,\n TransactionWithLastValidBlockHeight,\n waitForRecentTransactionConfirmation,\n} from '@solana/transaction-confirmation';\nimport { SendableTransaction, Transaction } from '@solana/transactions';\n\nimport { sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT } from './send-transaction-internal';\n\ntype SendAndConfirmTransactionWithBlockhashLifetimeFunction = (\n transaction: SendableTransaction & Transaction & TransactionWithLastValidBlockHeight,\n config: Omit<\n Parameters<typeof sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT>[0],\n 'confirmRecentTransaction' | 'rpc' | 'transaction'\n >,\n) => Promise<void>;\n\ntype SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig<TCluster> = {\n /** An object that supports the {@link GetSignatureStatusesApi} and the {@link SendTransactionApi} of the Solana RPC API */\n rpc: Rpc<GetEpochInfoApi & GetSignatureStatusesApi & SendTransactionApi> & { '~cluster'?: TCluster };\n /** An object that supports the {@link SignatureNotificationsApi} and the {@link SlotNotificationsApi} of the Solana RPC Subscriptions API */\n rpcSubscriptions: RpcSubscriptions<SignatureNotificationsApi & SlotNotificationsApi> & { '~cluster'?: TCluster };\n};\n\n/**\n * Returns a function that you can call to send a blockhash-based transaction to the network and to\n * wait until it has been confirmed.\n *\n * @param config\n *\n * @example\n * ```ts\n * import { isSolanaError, sendAndConfirmTransactionFactory, SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED } from '@solana/kit';\n *\n * const sendAndConfirmTransaction = sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions });\n *\n * try {\n * await sendAndConfirmTransaction(transaction, { commitment: 'confirmed' });\n * } catch (e) {\n * if (isSolanaError(e, SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED)) {\n * console.error('This transaction depends on a blockhash that has expired');\n * } else {\n * throw e;\n * }\n * }\n * ```\n */\nexport function sendAndConfirmTransactionFactory({\n rpc,\n rpcSubscriptions,\n}: SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig<'devnet'>): SendAndConfirmTransactionWithBlockhashLifetimeFunction;\nexport function sendAndConfirmTransactionFactory({\n rpc,\n rpcSubscriptions,\n}: SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig<'testnet'>): SendAndConfirmTransactionWithBlockhashLifetimeFunction;\nexport function sendAndConfirmTransactionFactory({\n rpc,\n rpcSubscriptions,\n}: SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig<'mainnet'>): SendAndConfirmTransactionWithBlockhashLifetimeFunction;\nexport function sendAndConfirmTransactionFactory<TCluster extends 'devnet' | 'mainnet' | 'testnet' | void = void>({\n rpc,\n rpcSubscriptions,\n}: SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig<TCluster>): SendAndConfirmTransactionWithBlockhashLifetimeFunction {\n const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory({\n rpc,\n rpcSubscriptions,\n } as Parameters<typeof createBlockHeightExceedencePromiseFactory>[0]);\n const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory({\n rpc,\n rpcSubscriptions,\n } as Parameters<typeof createRecentSignatureConfirmationPromiseFactory>[0]);\n async function confirmRecentTransaction(\n config: Omit<\n Parameters<typeof waitForRecentTransactionConfirmation>[0],\n 'getBlockHeightExceedencePromise' | 'getRecentSignatureConfirmationPromise'\n >,\n ) {\n await waitForRecentTransactionConfirmation({\n ...config,\n getBlockHeightExceedencePromise,\n getRecentSignatureConfirmationPromise,\n });\n }\n return async function sendAndConfirmTransaction(transaction, config) {\n await sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({\n ...config,\n confirmRecentTransaction,\n rpc,\n transaction,\n });\n };\n}\n","import type { Rpc, SendTransactionApi } from '@solana/rpc';\nimport { SendableTransaction, Transaction } from '@solana/transactions';\n\nimport { sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT } from './send-transaction-internal';\n\ntype SendTransactionWithoutConfirmingFunction = (\n transaction: SendableTransaction & Transaction,\n config: Omit<Parameters<typeof sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT>[0], 'rpc' | 'transaction'>,\n) => Promise<void>;\n\ninterface SendTransactionWithoutConfirmingFactoryConfig {\n /** An object that supports the {@link SendTransactionApi} of the Solana RPC API */\n rpc: Rpc<SendTransactionApi>;\n}\n\n/**\n * Returns a function that you can call to send a transaction with any kind of lifetime to the\n * network without waiting for it to be confirmed.\n *\n * @param config\n *\n * @example\n * ```ts\n * import {\n * sendTransactionWithoutConfirmingFactory,\n * SOLANA_ERROR__JSON_RPC__SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE,\n * } from '@solana/kit';\n *\n * const sendTransaction = sendTransactionWithoutConfirmingFactory({ rpc });\n *\n * try {\n * await sendTransaction(transaction, { commitment: 'confirmed' });\n * } catch (e) {\n * if (isSolanaError(e, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE)) {\n * console.error('The transaction failed in simulation', e.cause);\n * } else {\n * throw e;\n * }\n * }\n * ```\n */\nexport function sendTransactionWithoutConfirmingFactory({\n rpc,\n}: SendTransactionWithoutConfirmingFactoryConfig): SendTransactionWithoutConfirmingFunction {\n return async function sendTransactionWithoutConfirming(transaction, config) {\n await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({\n ...config,\n rpc,\n transaction,\n });\n };\n}\n"]}
@@ -2,7 +2,7 @@ import { fetchJsonParsedAccounts, assertAccountsDecoded, assertAccountsExist } f
2
2
  export * from '@solana/accounts';
3
3
  export * from '@solana/addresses';
4
4
  export * from '@solana/codecs';
5
- import { SolanaError, SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, getSolanaErrorFromTransactionError, isSolanaError, SOLANA_ERROR__INVALID_NONCE } from '@solana/errors';
5
+ import { SolanaError, SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, getSolanaErrorFromTransactionError, isSolanaError, SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_LOADED_ACCOUNTS_DATA_SIZE_LIMIT, SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_RESOURCE_LIMITS, SOLANA_ERROR__INVALID_NONCE } from '@solana/errors';
6
6
  export * from '@solana/errors';
7
7
  import { pipe } from '@solana/functional';
8
8
  export * from '@solana/functional';
@@ -18,7 +18,7 @@ export * from '@solana/rpc-subscriptions';
18
18
  import { commitmentComparator } from '@solana/rpc-types';
19
19
  export * from '@solana/rpc-types';
20
20
  export * from '@solana/signers';
21
- import { isTransactionMessageWithDurableNonceLifetime, setTransactionMessageComputeUnitLimit, getTransactionMessageComputeUnitLimit, decompileTransactionMessage } from '@solana/transaction-messages';
21
+ import { isTransactionMessageWithDurableNonceLifetime, setTransactionMessageComputeUnitLimit, getTransactionMessageComputeUnitLimit, decompileTransactionMessage, setTransactionMessageLoadedAccountsDataSizeLimit, getTransactionMessageLoadedAccountsDataSizeLimit } from '@solana/transaction-messages';
22
22
  export * from '@solana/transaction-messages';
23
23
  import { compileTransaction, getBase64EncodedWireTransaction, getSignatureFromTransaction } from '@solana/transactions';
24
24
  export * from '@solana/transactions';
@@ -348,6 +348,95 @@ async function decompileTransactionMessageFetchingLookupTables(compiledTransacti
348
348
  lastValidBlockHeight
349
349
  });
350
350
  }
351
+ var PROVISORY_LIMIT = 0;
352
+ var MAX_COMPUTE_UNIT_LIMIT2 = 14e5;
353
+ var MAX_LOADED_ACCOUNTS_DATA_SIZE_LIMIT = 64 * 1024 * 1024;
354
+ function estimateResourceLimitsFactory({
355
+ rpc
356
+ }) {
357
+ return async function estimateResourceLimits(transactionMessage, config) {
358
+ const { abortSignal, ...simulateConfig } = config ?? {};
359
+ const replaceRecentBlockhash = !isTransactionMessageWithDurableNonceLifetime(transactionMessage);
360
+ const isDataSizeRequired = transactionMessage.version === 1;
361
+ const transaction = pipe(
362
+ transactionMessage,
363
+ (m) => setTransactionMessageComputeUnitLimit(MAX_COMPUTE_UNIT_LIMIT2, m),
364
+ (m) => isDataSizeRequired ? setTransactionMessageLoadedAccountsDataSizeLimit(MAX_LOADED_ACCOUNTS_DATA_SIZE_LIMIT, m) : m,
365
+ compileTransaction
366
+ );
367
+ const wireTransactionBytes = getBase64EncodedWireTransaction(transaction);
368
+ try {
369
+ const response = await rpc.simulateTransaction(wireTransactionBytes, {
370
+ ...simulateConfig,
371
+ encoding: "base64",
372
+ replaceRecentBlockhash,
373
+ sigVerify: false
374
+ }).send({ abortSignal });
375
+ const { err: transactionError, ...simulationResult } = response.value;
376
+ if (simulationResult.unitsConsumed == null) {
377
+ throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT);
378
+ }
379
+ if (isDataSizeRequired && simulationResult.loadedAccountsDataSize == null) {
380
+ throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_LOADED_ACCOUNTS_DATA_SIZE_LIMIT);
381
+ }
382
+ if (transactionError) {
383
+ throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_RESOURCE_LIMITS, {
384
+ ...simulationResult,
385
+ cause: getSolanaErrorFromTransactionError(transactionError)
386
+ });
387
+ }
388
+ const computeUnitLimit = simulationResult.unitsConsumed > 4294967295n ? 4294967295 : Number(simulationResult.unitsConsumed);
389
+ if (isDataSizeRequired) {
390
+ return {
391
+ computeUnitLimit,
392
+ loadedAccountsDataSizeLimit: simulationResult.loadedAccountsDataSize
393
+ };
394
+ }
395
+ return simulationResult.loadedAccountsDataSize == null ? { computeUnitLimit } : { computeUnitLimit, loadedAccountsDataSizeLimit: simulationResult.loadedAccountsDataSize };
396
+ } catch (e) {
397
+ if (isSolanaError(e, SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_RESOURCE_LIMITS) || isSolanaError(e, SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_LOADED_ACCOUNTS_DATA_SIZE_LIMIT)) {
398
+ throw e;
399
+ }
400
+ throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, {
401
+ cause: e
402
+ });
403
+ }
404
+ };
405
+ }
406
+ function estimateAndSetResourceLimitsFactory(estimateResourceLimits) {
407
+ return async function estimateAndSetResourceLimits(transactionMessage, config) {
408
+ const existingComputeUnitLimit = getTransactionMessageComputeUnitLimit(transactionMessage);
409
+ const computeUnitLimitIsExplicit = existingComputeUnitLimit !== void 0 && existingComputeUnitLimit !== PROVISORY_LIMIT && existingComputeUnitLimit !== MAX_COMPUTE_UNIT_LIMIT2;
410
+ const isV1 = transactionMessage.version === 1;
411
+ let loadedAccountsDataSizeLimitIsExplicit = true;
412
+ if (isV1) {
413
+ const existingLoadedAccountsDataSizeLimit = getTransactionMessageLoadedAccountsDataSizeLimit(transactionMessage);
414
+ loadedAccountsDataSizeLimitIsExplicit = existingLoadedAccountsDataSizeLimit !== void 0 && existingLoadedAccountsDataSizeLimit !== PROVISORY_LIMIT;
415
+ }
416
+ if (computeUnitLimitIsExplicit && loadedAccountsDataSizeLimitIsExplicit) {
417
+ return transactionMessage;
418
+ }
419
+ const estimate = await estimateResourceLimits(transactionMessage, config);
420
+ let result = transactionMessage;
421
+ if (!computeUnitLimitIsExplicit) {
422
+ result = setTransactionMessageComputeUnitLimit(estimate.computeUnitLimit, result);
423
+ }
424
+ if (isV1 && !loadedAccountsDataSizeLimitIsExplicit && "loadedAccountsDataSizeLimit" in estimate) {
425
+ result = setTransactionMessageLoadedAccountsDataSizeLimit(estimate.loadedAccountsDataSizeLimit, result);
426
+ }
427
+ return result;
428
+ };
429
+ }
430
+ function fillTransactionMessageProvisoryResourceLimits(transactionMessage) {
431
+ let result = transactionMessage;
432
+ if (getTransactionMessageComputeUnitLimit(result) === void 0) {
433
+ result = setTransactionMessageComputeUnitLimit(PROVISORY_LIMIT, result);
434
+ }
435
+ if (result.version === 1 && getTransactionMessageLoadedAccountsDataSizeLimit(result) === void 0) {
436
+ result = setTransactionMessageLoadedAccountsDataSizeLimit(PROVISORY_LIMIT, result);
437
+ }
438
+ return result;
439
+ }
351
440
 
352
441
  // src/get-minimum-balance-for-rent-exemption.ts
353
442
  function getMinimumBalanceForRentExemption(space) {
@@ -538,6 +627,6 @@ function sendTransactionWithoutConfirmingFactory({
538
627
  };
539
628
  }
540
629
 
541
- export { airdropFactory, createAsyncGeneratorWithInitialValueAndSlotTracking, createReactiveStoreWithInitialValueAndSlotTracking, decompileTransactionMessageFetchingLookupTables, estimateAndSetComputeUnitLimitFactory, estimateComputeUnitLimitFactory, fetchAddressesForLookupTables, fillTransactionMessageProvisoryComputeUnitLimit, getMinimumBalanceForRentExemption, sendAndConfirmDurableNonceTransactionFactory, sendAndConfirmTransactionFactory, sendTransactionWithoutConfirmingFactory };
630
+ export { airdropFactory, createAsyncGeneratorWithInitialValueAndSlotTracking, createReactiveStoreWithInitialValueAndSlotTracking, decompileTransactionMessageFetchingLookupTables, estimateAndSetComputeUnitLimitFactory, estimateAndSetResourceLimitsFactory, estimateComputeUnitLimitFactory, estimateResourceLimitsFactory, fetchAddressesForLookupTables, fillTransactionMessageProvisoryComputeUnitLimit, fillTransactionMessageProvisoryResourceLimits, getMinimumBalanceForRentExemption, sendAndConfirmDurableNonceTransactionFactory, sendAndConfirmTransactionFactory, sendTransactionWithoutConfirmingFactory };
542
631
  //# sourceMappingURL=index.browser.mjs.map
543
632
  //# sourceMappingURL=index.browser.mjs.map