@solana/web3.js 1.73.4 → 1.75.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.
@@ -3504,6 +3504,13 @@ const GetInflationRewardResult = jsonRpcResult(array(nullable(type({
3504
3504
  postBalance: number(),
3505
3505
  commission: optional(nullable(number()))
3506
3506
  }))));
3507
+ /**
3508
+ * Expected JSON RPC response for the "getRecentPrioritizationFees" message
3509
+ */
3510
+ const GetRecentPrioritizationFeesResult = array(type({
3511
+ slot: number(),
3512
+ prioritizationFee: number()
3513
+ }));
3507
3514
  /**
3508
3515
  * Expected JSON RPC response for the "getInflationRate" message
3509
3516
  */
@@ -3705,6 +3712,11 @@ const GetInflationGovernorRpcResult = jsonRpcResult(GetInflationGovernorResult);
3705
3712
  */
3706
3713
  const GetInflationRateRpcResult = jsonRpcResult(GetInflationRateResult);
3707
3714
 
3715
+ /**
3716
+ * Expected JSON RPC response for the "getRecentPrioritizationFees" message
3717
+ */
3718
+ const GetRecentPrioritizationFeesRpcResult = jsonRpcResult(GetRecentPrioritizationFeesResult);
3719
+
3708
3720
  /**
3709
3721
  * Expected JSON RPC response for the "getEpochInfo" message
3710
3722
  */
@@ -4460,7 +4472,7 @@ class Connection {
4460
4472
  * @param endpoint URL to the fullnode JSON RPC endpoint
4461
4473
  * @param commitmentOrConfig optional default commitment level or optional ConnectionConfig configuration object
4462
4474
  */
4463
- constructor(endpoint, commitmentOrConfig) {
4475
+ constructor(endpoint, _commitmentOrConfig) {
4464
4476
  this._commitment = void 0;
4465
4477
  this._confirmTransactionInitialTimeout = void 0;
4466
4478
  this._rpcEndpoint = void 0;
@@ -4488,23 +4500,47 @@ class Connection {
4488
4500
  this._subscriptionCallbacksByServerSubscriptionId = {};
4489
4501
  this._subscriptionsByHash = {};
4490
4502
  this._subscriptionsAutoDisposedByRpc = new Set();
4503
+ this.getBlockHeight = (() => {
4504
+ const requestPromises = {};
4505
+ return async commitmentOrConfig => {
4506
+ const {
4507
+ commitment,
4508
+ config
4509
+ } = extractCommitmentFromConfig(commitmentOrConfig);
4510
+ const args = this._buildArgs([], commitment, undefined /* encoding */, config);
4511
+ const requestHash = fastStableStringify$1(args);
4512
+ requestPromises[requestHash] = requestPromises[requestHash] ?? (async () => {
4513
+ try {
4514
+ const unsafeRes = await this._rpcRequest('getBlockHeight', args);
4515
+ const res = create(unsafeRes, jsonRpcResult(number()));
4516
+ if ('error' in res) {
4517
+ throw new SolanaJSONRPCError(res.error, 'failed to get block height information');
4518
+ }
4519
+ return res.result;
4520
+ } finally {
4521
+ delete requestPromises[requestHash];
4522
+ }
4523
+ })();
4524
+ return await requestPromises[requestHash];
4525
+ };
4526
+ })();
4491
4527
  let wsEndpoint;
4492
4528
  let httpHeaders;
4493
4529
  let fetch;
4494
4530
  let fetchMiddleware;
4495
4531
  let disableRetryOnRateLimit;
4496
4532
  let httpAgent;
4497
- if (commitmentOrConfig && typeof commitmentOrConfig === 'string') {
4498
- this._commitment = commitmentOrConfig;
4499
- } else if (commitmentOrConfig) {
4500
- this._commitment = commitmentOrConfig.commitment;
4501
- this._confirmTransactionInitialTimeout = commitmentOrConfig.confirmTransactionInitialTimeout;
4502
- wsEndpoint = commitmentOrConfig.wsEndpoint;
4503
- httpHeaders = commitmentOrConfig.httpHeaders;
4504
- fetch = commitmentOrConfig.fetch;
4505
- fetchMiddleware = commitmentOrConfig.fetchMiddleware;
4506
- disableRetryOnRateLimit = commitmentOrConfig.disableRetryOnRateLimit;
4507
- httpAgent = commitmentOrConfig.httpAgent;
4533
+ if (_commitmentOrConfig && typeof _commitmentOrConfig === 'string') {
4534
+ this._commitment = _commitmentOrConfig;
4535
+ } else if (_commitmentOrConfig) {
4536
+ this._commitment = _commitmentOrConfig.commitment;
4537
+ this._confirmTransactionInitialTimeout = _commitmentOrConfig.confirmTransactionInitialTimeout;
4538
+ wsEndpoint = _commitmentOrConfig.wsEndpoint;
4539
+ httpHeaders = _commitmentOrConfig.httpHeaders;
4540
+ fetch = _commitmentOrConfig.fetch;
4541
+ fetchMiddleware = _commitmentOrConfig.fetchMiddleware;
4542
+ disableRetryOnRateLimit = _commitmentOrConfig.disableRetryOnRateLimit;
4543
+ httpAgent = _commitmentOrConfig.httpAgent;
4508
4544
  }
4509
4545
  this._rpcEndpoint = assertEndpointUrl(endpoint);
4510
4546
  this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
@@ -5578,6 +5614,19 @@ class Connection {
5578
5614
  return res.result;
5579
5615
  }
5580
5616
 
5617
+ /**
5618
+ * Fetch a list of prioritization fees from recent blocks.
5619
+ */
5620
+ async getRecentPrioritizationFees(config) {
5621
+ const accounts = config?.lockedWritableAccounts?.map(key => key.toBase58());
5622
+ const args = this._buildArgs(accounts?.length ? [accounts] : []);
5623
+ const unsafeRes = await this._rpcRequest('getRecentPrioritizationFees', args);
5624
+ const res = create(unsafeRes, GetRecentPrioritizationFeesRpcResult);
5625
+ if ('error' in res) {
5626
+ throw new SolanaJSONRPCError(res.error, 'failed to get recent prioritization fees');
5627
+ }
5628
+ return res.result;
5629
+ }
5581
5630
  /**
5582
5631
  * Fetch a recent blockhash from the cluster
5583
5632
  * @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
@@ -5762,19 +5811,6 @@ class Connection {
5762
5811
  /*
5763
5812
  * Returns the current block height of the node
5764
5813
  */
5765
- async getBlockHeight(commitmentOrConfig) {
5766
- const {
5767
- commitment,
5768
- config
5769
- } = extractCommitmentFromConfig(commitmentOrConfig);
5770
- const args = this._buildArgs([], commitment, undefined /* encoding */, config);
5771
- const unsafeRes = await this._rpcRequest('getBlockHeight', args);
5772
- const res = create(unsafeRes, jsonRpcResult(number()));
5773
- if ('error' in res) {
5774
- throw new SolanaJSONRPCError(res.error, 'failed to get block height information');
5775
- }
5776
- return res.result;
5777
- }
5778
5814
 
5779
5815
  /*
5780
5816
  * Returns recent block production information from the current or previous epoch