@solana/web3.js 1.41.9 → 1.43.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.
package/lib/index.iife.js CHANGED
@@ -14028,9 +14028,17 @@ var solanaWeb3 = (function (exports) {
14028
14028
  }
14029
14029
  }
14030
14030
 
14031
+ exports.TransactionStatus = void 0;
14031
14032
  /**
14032
14033
  * Default (empty) signature
14033
14034
  */
14035
+
14036
+ (function (TransactionStatus) {
14037
+ TransactionStatus[TransactionStatus["BLOCKHEIGHT_EXCEEDED"] = 0] = "BLOCKHEIGHT_EXCEEDED";
14038
+ TransactionStatus[TransactionStatus["PROCESSED"] = 1] = "PROCESSED";
14039
+ TransactionStatus[TransactionStatus["TIMED_OUT"] = 2] = "TIMED_OUT";
14040
+ })(exports.TransactionStatus || (exports.TransactionStatus = {}));
14041
+
14034
14042
  const DEFAULT_SIGNATURE = buffer.Buffer.alloc(SIGNATURE_LENGTH_IN_BYTES).fill(0);
14035
14043
  /**
14036
14044
  * Account metadata used to define instructions
@@ -14121,10 +14129,23 @@ var solanaWeb3 = (function (exports) {
14121
14129
  this.feePayer = void 0;
14122
14130
  this.instructions = [];
14123
14131
  this.recentBlockhash = void 0;
14132
+ this.lastValidBlockHeight = void 0;
14124
14133
  this.nonceInfo = void 0;
14125
14134
  this._message = void 0;
14126
14135
  this._json = void 0;
14127
- opts && Object.assign(this, opts);
14136
+
14137
+ if (!opts) {
14138
+ return;
14139
+ } else if (Object.prototype.hasOwnProperty.call(opts, 'lastValidBlockHeight')) {
14140
+ const newOpts = opts;
14141
+ Object.assign(this, newOpts);
14142
+ this.recentBlockhash = newOpts.blockhash;
14143
+ this.lastValidBlockHeight = newOpts.lastValidBlockHeight;
14144
+ } else {
14145
+ const oldOpts = opts;
14146
+ Object.assign(this, oldOpts);
14147
+ this.recentBlockhash = oldOpts.recentBlockhash;
14148
+ }
14128
14149
  }
14129
14150
  /**
14130
14151
  * @internal
@@ -14459,8 +14480,6 @@ var solanaWeb3 = (function (exports) {
14459
14480
  const message = this._compile();
14460
14481
 
14461
14482
  this._partialSign(message, ...uniqueSigners);
14462
-
14463
- this._verifySignatures(message.serialize(), true);
14464
14483
  }
14465
14484
  /**
14466
14485
  * Partially sign a transaction with the specified accounts. All accounts must
@@ -14734,7 +14753,11 @@ var solanaWeb3 = (function (exports) {
14734
14753
  maxRetries: options.maxRetries
14735
14754
  };
14736
14755
  const signature = await connection.sendTransaction(transaction, signers, sendOptions);
14737
- const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
14756
+ const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
14757
+ signature: signature,
14758
+ blockhash: transaction.recentBlockhash,
14759
+ lastValidBlockHeight: transaction.lastValidBlockHeight
14760
+ }, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
14738
14761
 
14739
14762
  if (status.err) {
14740
14763
  throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
@@ -24106,6 +24129,34 @@ var solanaWeb3 = (function (exports) {
24106
24129
  bytes
24107
24130
  };
24108
24131
  }
24132
+ /**
24133
+ * Decode set compute unit limit compute budget instruction and retrieve the instruction params.
24134
+ */
24135
+
24136
+
24137
+ static decodeSetComputeUnitLimit(instruction) {
24138
+ this.checkProgramId(instruction.programId);
24139
+ const {
24140
+ units
24141
+ } = decodeData(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitLimit, instruction.data);
24142
+ return {
24143
+ units
24144
+ };
24145
+ }
24146
+ /**
24147
+ * Decode set compute unit price compute budget instruction and retrieve the instruction params.
24148
+ */
24149
+
24150
+
24151
+ static decodeSetComputeUnitPrice(instruction) {
24152
+ this.checkProgramId(instruction.programId);
24153
+ const {
24154
+ microLamports
24155
+ } = decodeData(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitPrice, instruction.data);
24156
+ return {
24157
+ microLamports
24158
+ };
24159
+ }
24109
24160
  /**
24110
24161
  * @internal
24111
24162
  */
@@ -24134,6 +24185,14 @@ var solanaWeb3 = (function (exports) {
24134
24185
  RequestHeapFrame: {
24135
24186
  index: 1,
24136
24187
  layout: struct([u8('instruction'), u32('bytes')])
24188
+ },
24189
+ SetComputeUnitLimit: {
24190
+ index: 2,
24191
+ layout: struct([u8('instruction'), u32('units')])
24192
+ },
24193
+ SetComputeUnitPrice: {
24194
+ index: 3,
24195
+ layout: struct([u8('instruction'), u64('microLamports')])
24137
24196
  }
24138
24197
  });
24139
24198
  /**
@@ -24170,6 +24229,28 @@ var solanaWeb3 = (function (exports) {
24170
24229
  });
24171
24230
  }
24172
24231
 
24232
+ static setComputeUnitLimit(params) {
24233
+ const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitLimit;
24234
+ const data = encodeData(type, params);
24235
+ return new TransactionInstruction({
24236
+ keys: [],
24237
+ programId: this.programId,
24238
+ data
24239
+ });
24240
+ }
24241
+
24242
+ static setComputeUnitPrice(params) {
24243
+ const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitPrice;
24244
+ const data = encodeData(type, {
24245
+ microLamports: BigInt(params.microLamports)
24246
+ });
24247
+ return new TransactionInstruction({
24248
+ keys: [],
24249
+ programId: this.programId,
24250
+ data
24251
+ });
24252
+ }
24253
+
24173
24254
  }
24174
24255
  ComputeBudgetProgram.programId = new PublicKey('ComputeBudget111111111111111111111111111111');
24175
24256
 
@@ -24938,16 +25019,28 @@ var solanaWeb3 = (function (exports) {
24938
25019
 
24939
25020
  const MS_PER_SLOT = 1000 / NUM_SLOTS_PER_SECOND;
24940
25021
 
24941
- function promiseTimeout(promise, timeoutMs) {
24942
- let timeoutId;
24943
- const timeoutPromise = new Promise(resolve => {
24944
- timeoutId = setTimeout(() => resolve(null), timeoutMs);
24945
- });
24946
- return Promise.race([promise, timeoutPromise]).then(result => {
24947
- clearTimeout(timeoutId);
24948
- return result;
24949
- });
25022
+ class TransactionExpiredBlockheightExceededError extends Error {
25023
+ constructor(signature) {
25024
+ super(`Signature ${signature} has expired: block height exceeded.`);
25025
+ this.signature = void 0;
25026
+ this.signature = signature;
25027
+ }
25028
+
25029
+ }
25030
+ Object.defineProperty(TransactionExpiredBlockheightExceededError.prototype, 'name', {
25031
+ value: 'TransactionExpiredBlockheightExceededError'
25032
+ });
25033
+ class TransactionExpiredTimeoutError extends Error {
25034
+ constructor(signature, timeoutSeconds) {
25035
+ super(`Transaction was not confirmed in ${timeoutSeconds.toFixed(2)} seconds. It is ` + 'unknown if it succeeded or failed. Check signature ' + `${signature} using the Solana Explorer or CLI tools.`);
25036
+ this.signature = void 0;
25037
+ this.signature = signature;
25038
+ }
25039
+
24950
25040
  }
25041
+ Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
25042
+ value: 'TransactionExpiredTimeoutError'
25043
+ });
24951
25044
 
24952
25045
  function makeWebsocketUrl(endpoint) {
24953
25046
  let url = new URL(endpoint);
@@ -25936,7 +26029,7 @@ var solanaWeb3 = (function (exports) {
25936
26029
  this._disableBlockhashCaching = false;
25937
26030
  this._pollingBlockhash = false;
25938
26031
  this._blockhashInfo = {
25939
- recentBlockhash: null,
26032
+ latestBlockhash: null,
25940
26033
  lastFetch: 0,
25941
26034
  transactionSignatures: [],
25942
26035
  simulatedSignatures: []
@@ -26417,67 +26510,124 @@ var solanaWeb3 = (function (exports) {
26417
26510
 
26418
26511
  return res.result;
26419
26512
  }
26420
- /**
26421
- * Confirm the transaction identified by the specified signature.
26422
- */
26423
26513
 
26514
+ // eslint-disable-next-line no-dupe-class-members
26515
+ async confirmTransaction(strategy, commitment) {
26516
+ let rawSignature;
26517
+
26518
+ if (typeof strategy == 'string') {
26519
+ rawSignature = strategy;
26520
+ } else {
26521
+ const config = strategy;
26522
+ rawSignature = config.signature;
26523
+ }
26424
26524
 
26425
- async confirmTransaction(signature, commitment) {
26426
26525
  let decodedSignature;
26427
26526
 
26428
26527
  try {
26429
- decodedSignature = bs58$1.decode(signature);
26528
+ decodedSignature = bs58$1.decode(rawSignature);
26430
26529
  } catch (err) {
26431
- throw new Error('signature must be base58 encoded: ' + signature);
26530
+ throw new Error('signature must be base58 encoded: ' + rawSignature);
26432
26531
  }
26433
26532
 
26434
26533
  assert$c(decodedSignature.length === 64, 'signature has invalid length');
26435
- const start = Date.now();
26436
26534
  const subscriptionCommitment = commitment || this.commitment;
26535
+ let timeoutId;
26437
26536
  let subscriptionId;
26438
- let response = null;
26439
- const confirmPromise = new Promise((resolve, reject) => {
26537
+ let done = false;
26538
+ const confirmationPromise = new Promise((resolve, reject) => {
26440
26539
  try {
26441
- subscriptionId = this.onSignature(signature, (result, context) => {
26540
+ subscriptionId = this.onSignature(rawSignature, (result, context) => {
26442
26541
  subscriptionId = undefined;
26443
- response = {
26542
+ const response = {
26444
26543
  context,
26445
26544
  value: result
26446
26545
  };
26447
- resolve(null);
26546
+ done = true;
26547
+ resolve({
26548
+ __type: exports.TransactionStatus.PROCESSED,
26549
+ response
26550
+ });
26448
26551
  }, subscriptionCommitment);
26449
26552
  } catch (err) {
26450
26553
  reject(err);
26451
26554
  }
26452
26555
  });
26453
- let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
26454
-
26455
- switch (subscriptionCommitment) {
26456
- case 'processed':
26457
- case 'recent':
26458
- case 'single':
26459
- case 'confirmed':
26460
- case 'singleGossip':
26461
- {
26462
- timeoutMs = this._confirmTransactionInitialTimeout || 30 * 1000;
26463
- break;
26556
+
26557
+ const checkBlockHeight = async () => {
26558
+ try {
26559
+ const blockHeight = await this.getBlockHeight(commitment);
26560
+ return blockHeight;
26561
+ } catch (_e) {
26562
+ return -1;
26563
+ }
26564
+ };
26565
+
26566
+ const expiryPromise = new Promise(resolve => {
26567
+ if (typeof strategy === 'string') {
26568
+ let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
26569
+
26570
+ switch (subscriptionCommitment) {
26571
+ case 'processed':
26572
+ case 'recent':
26573
+ case 'single':
26574
+ case 'confirmed':
26575
+ case 'singleGossip':
26576
+ {
26577
+ timeoutMs = this._confirmTransactionInitialTimeout || 30 * 1000;
26578
+ break;
26579
+ }
26464
26580
  }
26465
- }
26581
+
26582
+ timeoutId = setTimeout(() => resolve({
26583
+ __type: exports.TransactionStatus.TIMED_OUT,
26584
+ timeoutMs
26585
+ }), timeoutMs);
26586
+ } else {
26587
+ let config = strategy;
26588
+
26589
+ (async () => {
26590
+ let currentBlockHeight = await checkBlockHeight();
26591
+ if (done) return;
26592
+
26593
+ while (currentBlockHeight <= config.lastValidBlockHeight) {
26594
+ await sleep(1000);
26595
+ if (done) return;
26596
+ currentBlockHeight = await checkBlockHeight();
26597
+ if (done) return;
26598
+ }
26599
+
26600
+ resolve({
26601
+ __type: exports.TransactionStatus.BLOCKHEIGHT_EXCEEDED
26602
+ });
26603
+ })();
26604
+ }
26605
+ });
26606
+ let result;
26466
26607
 
26467
26608
  try {
26468
- await promiseTimeout(confirmPromise, timeoutMs);
26609
+ const outcome = await Promise.race([confirmationPromise, expiryPromise]);
26610
+
26611
+ switch (outcome.__type) {
26612
+ case exports.TransactionStatus.BLOCKHEIGHT_EXCEEDED:
26613
+ throw new TransactionExpiredBlockheightExceededError(rawSignature);
26614
+
26615
+ case exports.TransactionStatus.PROCESSED:
26616
+ result = outcome.response;
26617
+ break;
26618
+
26619
+ case exports.TransactionStatus.TIMED_OUT:
26620
+ throw new TransactionExpiredTimeoutError(rawSignature, outcome.timeoutMs / 1000);
26621
+ }
26469
26622
  } finally {
26623
+ clearTimeout(timeoutId);
26624
+
26470
26625
  if (subscriptionId) {
26471
26626
  this.removeSignatureListener(subscriptionId);
26472
26627
  }
26473
26628
  }
26474
26629
 
26475
- if (response === null) {
26476
- const duration = (Date.now() - start) / 1000;
26477
- throw new Error(`Transaction was not confirmed in ${duration.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`);
26478
- }
26479
-
26480
- return response;
26630
+ return result;
26481
26631
  }
26482
26632
  /**
26483
26633
  * Return the list of nodes that are currently participating in the cluster
@@ -26842,7 +26992,7 @@ var solanaWeb3 = (function (exports) {
26842
26992
  }
26843
26993
  /**
26844
26994
  * Fetch the latest blockhash from the cluster
26845
- * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
26995
+ * @return {Promise<BlockhashWithExpiryBlockHeight>}
26846
26996
  */
26847
26997
 
26848
26998
 
@@ -26856,7 +27006,7 @@ var solanaWeb3 = (function (exports) {
26856
27006
  }
26857
27007
  /**
26858
27008
  * Fetch the latest blockhash from the cluster
26859
- * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
27009
+ * @return {Promise<BlockhashWithExpiryBlockHeight>}
26860
27010
  */
26861
27011
 
26862
27012
 
@@ -27439,7 +27589,7 @@ var solanaWeb3 = (function (exports) {
27439
27589
  */
27440
27590
 
27441
27591
 
27442
- async _recentBlockhash(disableCache) {
27592
+ async _blockhashWithExpiryBlockHeight(disableCache) {
27443
27593
  if (!disableCache) {
27444
27594
  // Wait for polling to finish
27445
27595
  while (this._pollingBlockhash) {
@@ -27450,8 +27600,8 @@ var solanaWeb3 = (function (exports) {
27450
27600
 
27451
27601
  const expired = timeSinceFetch >= BLOCKHASH_CACHE_TIMEOUT_MS;
27452
27602
 
27453
- if (this._blockhashInfo.recentBlockhash !== null && !expired) {
27454
- return this._blockhashInfo.recentBlockhash;
27603
+ if (this._blockhashInfo.latestBlockhash !== null && !expired) {
27604
+ return this._blockhashInfo.latestBlockhash;
27455
27605
  }
27456
27606
  }
27457
27607
 
@@ -27467,20 +27617,20 @@ var solanaWeb3 = (function (exports) {
27467
27617
 
27468
27618
  try {
27469
27619
  const startTime = Date.now();
27620
+ const cachedLatestBlockhash = this._blockhashInfo.latestBlockhash;
27621
+ const cachedBlockhash = cachedLatestBlockhash ? cachedLatestBlockhash.blockhash : null;
27470
27622
 
27471
27623
  for (let i = 0; i < 50; i++) {
27472
- const {
27473
- blockhash
27474
- } = await this.getRecentBlockhash('finalized');
27624
+ const latestBlockhash = await this.getLatestBlockhash('finalized');
27475
27625
 
27476
- if (this._blockhashInfo.recentBlockhash != blockhash) {
27626
+ if (cachedBlockhash !== latestBlockhash.blockhash) {
27477
27627
  this._blockhashInfo = {
27478
- recentBlockhash: blockhash,
27628
+ latestBlockhash,
27479
27629
  lastFetch: Date.now(),
27480
27630
  transactionSignatures: [],
27481
27631
  simulatedSignatures: []
27482
27632
  };
27483
- return blockhash;
27633
+ return latestBlockhash;
27484
27634
  } // Sleep for approximately half a slot
27485
27635
 
27486
27636
 
@@ -27502,13 +27652,11 @@ var solanaWeb3 = (function (exports) {
27502
27652
 
27503
27653
  if (transactionOrMessage instanceof Transaction) {
27504
27654
  let originalTx = transactionOrMessage;
27505
- transaction = new Transaction({
27506
- recentBlockhash: originalTx.recentBlockhash,
27507
- nonceInfo: originalTx.nonceInfo,
27508
- feePayer: originalTx.feePayer,
27509
- signatures: [...originalTx.signatures]
27510
- });
27655
+ transaction = new Transaction();
27656
+ transaction.feePayer = originalTx.feePayer;
27511
27657
  transaction.instructions = transactionOrMessage.instructions;
27658
+ transaction.nonceInfo = originalTx.nonceInfo;
27659
+ transaction.signatures = originalTx.signatures;
27512
27660
  } else {
27513
27661
  transaction = Transaction.populate(transactionOrMessage); // HACK: this function relies on mutating the populated transaction
27514
27662
 
@@ -27521,7 +27669,9 @@ var solanaWeb3 = (function (exports) {
27521
27669
  let disableCache = this._disableBlockhashCaching;
27522
27670
 
27523
27671
  for (;;) {
27524
- transaction.recentBlockhash = await this._recentBlockhash(disableCache);
27672
+ const latestBlockhash = await this._blockhashWithExpiryBlockHeight(disableCache);
27673
+ transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
27674
+ transaction.recentBlockhash = latestBlockhash.blockhash;
27525
27675
  if (!signers) break;
27526
27676
  transaction.sign(...signers);
27527
27677
 
@@ -27605,7 +27755,9 @@ var solanaWeb3 = (function (exports) {
27605
27755
  let disableCache = this._disableBlockhashCaching;
27606
27756
 
27607
27757
  for (;;) {
27608
- transaction.recentBlockhash = await this._recentBlockhash(disableCache);
27758
+ const latestBlockhash = await this._blockhashWithExpiryBlockHeight(disableCache);
27759
+ transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
27760
+ transaction.recentBlockhash = latestBlockhash.blockhash;
27609
27761
  transaction.sign(...signers);
27610
27762
 
27611
27763
  if (!transaction.signature) {
@@ -30046,16 +30198,36 @@ var solanaWeb3 = (function (exports) {
30046
30198
  *
30047
30199
  * @param {Connection} connection
30048
30200
  * @param {Buffer} rawTransaction
30201
+ * @param {BlockheightBasedTransactionConfirmationStrategy} confirmationStrategy
30049
30202
  * @param {ConfirmOptions} [options]
30050
30203
  * @returns {Promise<TransactionSignature>}
30051
30204
  */
30052
- async function sendAndConfirmRawTransaction(connection, rawTransaction, options) {
30205
+
30206
+ /**
30207
+ * @deprecated Calling `sendAndConfirmRawTransaction()` without a `confirmationStrategy`
30208
+ * is no longer supported and will be removed in a future version.
30209
+ */
30210
+ // eslint-disable-next-line no-redeclare
30211
+ // eslint-disable-next-line no-redeclare
30212
+ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirmationStrategyOrConfirmOptions, maybeConfirmOptions) {
30213
+ let confirmationStrategy;
30214
+ let options;
30215
+
30216
+ if (confirmationStrategyOrConfirmOptions && Object.prototype.hasOwnProperty.call(confirmationStrategyOrConfirmOptions, 'lastValidBlockHeight')) {
30217
+ confirmationStrategy = confirmationStrategyOrConfirmOptions;
30218
+ options = maybeConfirmOptions;
30219
+ } else {
30220
+ options = confirmationStrategyOrConfirmOptions;
30221
+ }
30222
+
30053
30223
  const sendOptions = options && {
30054
30224
  skipPreflight: options.skipPreflight,
30055
30225
  preflightCommitment: options.preflightCommitment || options.commitment
30056
30226
  };
30057
30227
  const signature = await connection.sendRawTransaction(rawTransaction, sendOptions);
30058
- const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
30228
+ const commitment = options && options.commitment;
30229
+ const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature, commitment);
30230
+ const status = (await confirmationPromise).value;
30059
30231
 
30060
30232
  if (status.err) {
30061
30233
  throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);