@quicknode/sdk 2.3.0 → 2.4.1

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/cjs/index.js CHANGED
@@ -347,6 +347,17 @@ function setupGlobalFetch() {
347
347
  }
348
348
  }
349
349
 
350
+ // Ideally we read directly from package.json, but ran into some packaging issues with that
351
+ const PACKAGE_VERSION = '2.4.1';
352
+
353
+ // Headers to use in RPC clients
354
+ function getClientHeaders() {
355
+ const packageVersion = PACKAGE_VERSION ;
356
+ return {
357
+ 'x-qn-sdk-version': packageVersion,
358
+ };
359
+ }
360
+
350
361
  const buildQNActions = (config) => {
351
362
  return (client) => ({
352
363
  ...nftAndTokenActions(client, config),
@@ -355,10 +366,15 @@ const buildQNActions = (config) => {
355
366
  class Core {
356
367
  constructor({ endpointUrl, chain, config = {} }) {
357
368
  setupGlobalFetch();
369
+ const clientHeaders = getClientHeaders();
358
370
  this.endpointUrl = endpointUrl;
359
371
  const baseClient = viem.createClient({
360
372
  chain: chain || deriveChainFromUrl(endpointUrl),
361
- transport: viem.http(this.endpointUrl),
373
+ transport: viem.http(this.endpointUrl, {
374
+ fetchOptions: {
375
+ headers: clientHeaders,
376
+ },
377
+ }),
362
378
  }).extend(viem.publicActions);
363
379
  const qnClient = baseClient.extend(buildQNActions(config));
364
380
  this.client = qnClient;
@@ -368,8 +384,11 @@ class Core {
368
384
  // eslint-disable-next-line @nx/enforce-module-boundaries
369
385
  class Solana {
370
386
  constructor({ endpointUrl }) {
387
+ const clientHeaders = getClientHeaders();
371
388
  this.endpointUrl = endpointUrl;
372
- this.connection = new web3_js.Connection(endpointUrl);
389
+ this.connection = new web3_js.Connection(endpointUrl, {
390
+ httpHeaders: clientHeaders,
391
+ });
373
392
  }
374
393
  /**
375
394
  * Sends a transaction with a dynamically generated priority fee based on the current network conditions and compute units needed by the transaction.
@@ -420,7 +439,7 @@ class Solana {
420
439
  async fetchEstimatePriorityFees(args = {}) {
421
440
  const payload = {
422
441
  method: 'qn_estimatePriorityFees',
423
- params: args,
442
+ params: { api_version: 2, ...args },
424
443
  id: 1,
425
444
  jsonrpc: '2.0',
426
445
  };
@@ -442,7 +461,9 @@ class Solana {
442
461
  }
443
462
  async createDynamicPriorityFeeInstruction(feeType = 'medium') {
444
463
  const { result } = await this.fetchEstimatePriorityFees({});
445
- const priorityFee = result.per_compute_unit[feeType];
464
+ const priorityFee = feeType === 'recommended'
465
+ ? result.recommended
466
+ : result.per_compute_unit[feeType];
446
467
  const priorityFeeInstruction = web3_js.ComputeBudgetProgram.setComputeUnitPrice({
447
468
  microLamports: priorityFee,
448
469
  });
package/esm/core/core.js CHANGED
@@ -2,6 +2,7 @@ import { createClient, http, publicActions } from 'viem';
2
2
  import { nftAndTokenActions } from './addOns/nftTokenV2/actions.js';
3
3
  import { deriveChainFromUrl } from './chains.js';
4
4
  import { setupGlobalFetch } from '../lib/helpers/globalFetch.js';
5
+ import { getClientHeaders } from '../lib/helpers/getClientHeaders.js';
5
6
 
6
7
  const buildQNActions = (config) => {
7
8
  return (client) => ({
@@ -11,10 +12,15 @@ const buildQNActions = (config) => {
11
12
  class Core {
12
13
  constructor({ endpointUrl, chain, config = {} }) {
13
14
  setupGlobalFetch();
15
+ const clientHeaders = getClientHeaders();
14
16
  this.endpointUrl = endpointUrl;
15
17
  const baseClient = createClient({
16
18
  chain: chain || deriveChainFromUrl(endpointUrl),
17
- transport: http(this.endpointUrl),
19
+ transport: http(this.endpointUrl, {
20
+ fetchOptions: {
21
+ headers: clientHeaders,
22
+ },
23
+ }),
18
24
  }).extend(publicActions);
19
25
  const qnClient = baseClient.extend(buildQNActions(config));
20
26
  this.client = qnClient;
@@ -0,0 +1,4 @@
1
+ // Ideally we read directly from package.json, but ran into some packaging issues with that
2
+ const PACKAGE_VERSION = '2.4.1';
3
+
4
+ export { PACKAGE_VERSION };
@@ -0,0 +1,11 @@
1
+ import { PACKAGE_VERSION } from '../constants.js';
2
+
3
+ // Headers to use in RPC clients
4
+ function getClientHeaders() {
5
+ const packageVersion = PACKAGE_VERSION ;
6
+ return {
7
+ 'x-qn-sdk-version': packageVersion,
8
+ };
9
+ }
10
+
11
+ export { getClientHeaders };
@@ -2,7 +2,7 @@ import * as _solana_web3_js from '@solana/web3.js';
2
2
  import { Transaction, PublicKey, Keypair, SendOptions, Connection } from '@solana/web3.js';
3
3
 
4
4
  type PercentileRangeUnion = '0' | '5' | '10' | '15' | '20' | '25' | '30' | '35' | '40' | '45' | '50' | '55' | '60' | '65' | '70' | '75' | '80' | '85' | '90' | '95' | '100';
5
- type PriorityFeeLevels = 'low' | 'medium' | 'high' | 'extreme';
5
+ type PriorityFeeLevels = 'low' | 'medium' | 'high' | 'extreme' | 'recommended';
6
6
  interface PriorityFeeRequestPayload {
7
7
  method: string;
8
8
  params: {
@@ -29,12 +29,14 @@ interface PriorityFeeResponseData {
29
29
  };
30
30
  per_compute_unit: PriorityFeeEstimates;
31
31
  per_transaction: PriorityFeeEstimates;
32
+ recommended: number;
32
33
  };
33
34
  id: number;
34
35
  }
35
36
  interface EstimatePriorityFeesParams {
36
37
  last_n_blocks?: number;
37
38
  account?: string;
39
+ api_version?: number;
38
40
  }
39
41
  interface SolanaClientArgs {
40
42
  endpointUrl: string;
@@ -1,10 +1,15 @@
1
1
  import { Connection, ComputeBudgetProgram, VersionedTransaction, TransactionMessage, PublicKey } from '@solana/web3.js';
2
+ import 'cross-fetch';
3
+ import { getClientHeaders } from '../lib/helpers/getClientHeaders.js';
2
4
 
3
5
  // eslint-disable-next-line @nx/enforce-module-boundaries
4
6
  class Solana {
5
7
  constructor({ endpointUrl }) {
8
+ const clientHeaders = getClientHeaders();
6
9
  this.endpointUrl = endpointUrl;
7
- this.connection = new Connection(endpointUrl);
10
+ this.connection = new Connection(endpointUrl, {
11
+ httpHeaders: clientHeaders,
12
+ });
8
13
  }
9
14
  /**
10
15
  * Sends a transaction with a dynamically generated priority fee based on the current network conditions and compute units needed by the transaction.
@@ -55,7 +60,7 @@ class Solana {
55
60
  async fetchEstimatePriorityFees(args = {}) {
56
61
  const payload = {
57
62
  method: 'qn_estimatePriorityFees',
58
- params: args,
63
+ params: { api_version: 2, ...args },
59
64
  id: 1,
60
65
  jsonrpc: '2.0',
61
66
  };
@@ -77,7 +82,9 @@ class Solana {
77
82
  }
78
83
  async createDynamicPriorityFeeInstruction(feeType = 'medium') {
79
84
  const { result } = await this.fetchEstimatePriorityFees({});
80
- const priorityFee = result.per_compute_unit[feeType];
85
+ const priorityFee = feeType === 'recommended'
86
+ ? result.recommended
87
+ : result.per_compute_unit[feeType];
81
88
  const priorityFeeInstruction = ComputeBudgetProgram.setComputeUnitPrice({
82
89
  microLamports: priorityFee,
83
90
  });
package/index.d.ts CHANGED
@@ -561,7 +561,7 @@ declare class Core {
561
561
  }
562
562
 
563
563
  type PercentileRangeUnion = '0' | '5' | '10' | '15' | '20' | '25' | '30' | '35' | '40' | '45' | '50' | '55' | '60' | '65' | '70' | '75' | '80' | '85' | '90' | '95' | '100';
564
- type PriorityFeeLevels = 'low' | 'medium' | 'high' | 'extreme';
564
+ type PriorityFeeLevels = 'low' | 'medium' | 'high' | 'extreme' | 'recommended';
565
565
  interface PriorityFeeRequestPayload {
566
566
  method: string;
567
567
  params: {
@@ -588,12 +588,14 @@ interface PriorityFeeResponseData {
588
588
  };
589
589
  per_compute_unit: PriorityFeeEstimates;
590
590
  per_transaction: PriorityFeeEstimates;
591
+ recommended: number;
591
592
  };
592
593
  id: number;
593
594
  }
594
595
  interface EstimatePriorityFeesParams {
595
596
  last_n_blocks?: number;
596
597
  account?: string;
598
+ api_version?: number;
597
599
  }
598
600
  interface SolanaClientArgs {
599
601
  endpointUrl: string;
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "directory": "packages/libs/sdk"
7
7
  },
8
8
  "license": "MIT",
9
- "version": "2.3.0",
9
+ "version": "2.4.1",
10
10
  "main": "./cjs/index.js",
11
11
  "module": "./esm/index.js",
12
12
  "types": "./index.d.ts",