@quicknode/sdk 2.6.0 → 3.0.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/browser.js +9 -0
  2. package/index.d.ts +2298 -650
  3. package/index.darwin-arm64.node +0 -0
  4. package/index.linux-arm64-gnu.node +0 -0
  5. package/index.linux-arm64-musl.node +0 -0
  6. package/index.linux-x64-gnu.node +0 -0
  7. package/index.linux-x64-musl.node +0 -0
  8. package/package.json +46 -54
  9. package/sdk.d.ts +339 -0
  10. package/sdk.js +102 -0
  11. package/sdk.mjs +34 -0
  12. package/README.md +0 -80
  13. package/cjs/index.js +0 -542
  14. package/cjs/package.json +0 -3
  15. package/esm/client/client.js +0 -9
  16. package/esm/client/index.js +0 -2
  17. package/esm/core/addOns/nftTokenV2/actions.js +0 -107
  18. package/esm/core/addOns/nftTokenV2/types/qn_fetchNFTCollectionDetails.js +0 -10
  19. package/esm/core/addOns/nftTokenV2/types/qn_fetchNFTs.js +0 -13
  20. package/esm/core/addOns/nftTokenV2/types/qn_fetchNFTsByCollection.js +0 -13
  21. package/esm/core/addOns/nftTokenV2/types/qn_getTokenMetadataByContractAddress.js +0 -10
  22. package/esm/core/addOns/nftTokenV2/types/qn_getTokenMetadataBySymbol.js +0 -11
  23. package/esm/core/addOns/nftTokenV2/types/qn_getTransactionsByAddress.js +0 -18
  24. package/esm/core/addOns/nftTokenV2/types/qn_getTransfersByNFT.js +0 -12
  25. package/esm/core/addOns/nftTokenV2/types/qn_getWalletTokenBalance.js +0 -12
  26. package/esm/core/addOns/nftTokenV2/types/qn_getWalletTokenTransactions.js +0 -14
  27. package/esm/core/addOns/nftTokenV2/types/qn_verifyNFTsOwner.js +0 -11
  28. package/esm/core/addOns/shared/helpers.js +0 -10
  29. package/esm/core/chains.js +0 -118
  30. package/esm/core/core.js +0 -30
  31. package/esm/core/index.d.ts +0 -558
  32. package/esm/core/index.js +0 -2
  33. package/esm/index.js +0 -11
  34. package/esm/lib/constants.js +0 -4
  35. package/esm/lib/errors/QNChainNotSupported.js +0 -7
  36. package/esm/lib/errors/QNInputValidationError.js +0 -10
  37. package/esm/lib/errors/QNInvalidEnpointUrl.js +0 -7
  38. package/esm/lib/helpers/getClientHeaders.js +0 -11
  39. package/esm/lib/helpers/globalFetch.js +0 -13
  40. package/esm/lib/validation/ValidateInput.js +0 -16
  41. package/esm/lib/validation/validators.js +0 -15
  42. package/esm/package.json +0 -4
  43. package/esm/solana/index.d.ts +0 -76
  44. package/esm/solana/index.js +0 -2
  45. package/esm/solana/solana.js +0 -111
@@ -1,76 +0,0 @@
1
- import * as _solana_web3_js from '@solana/web3.js';
2
- import { Transaction, PublicKey, Keypair, SendOptions, Connection } from '@solana/web3.js';
3
-
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' | 'recommended';
6
- interface PriorityFeeRequestPayload {
7
- method: string;
8
- params: {
9
- last_n_blocks?: number;
10
- account?: string;
11
- };
12
- id: number;
13
- jsonrpc: string;
14
- }
15
- interface PriorityFeeEstimates {
16
- extreme: number;
17
- high: number;
18
- low: number;
19
- medium: number;
20
- percentiles: {
21
- [key in PercentileRangeUnion]: number;
22
- };
23
- }
24
- interface PriorityFeeResponseData {
25
- jsonrpc: string;
26
- result: {
27
- context: {
28
- slot: number;
29
- };
30
- per_compute_unit: PriorityFeeEstimates;
31
- per_transaction: PriorityFeeEstimates;
32
- recommended: number;
33
- };
34
- id: number;
35
- }
36
- interface EstimatePriorityFeesParams {
37
- last_n_blocks?: number;
38
- account?: string;
39
- api_version?: number;
40
- }
41
- interface SolanaClientArgs {
42
- endpointUrl: string;
43
- }
44
- interface SmartTransactionBaseArgs {
45
- transaction: Transaction;
46
- feeLevel?: PriorityFeeLevels;
47
- }
48
- interface PrepareSmartTransactionArgs extends SmartTransactionBaseArgs {
49
- payerPublicKey: PublicKey;
50
- }
51
- interface SendSmartTransactionArgs extends SmartTransactionBaseArgs {
52
- keyPair: Keypair;
53
- sendTransactionOptions?: SendOptions;
54
- }
55
-
56
- declare class Solana {
57
- readonly endpointUrl: string;
58
- readonly connection: Connection;
59
- constructor({ endpointUrl }: SolanaClientArgs);
60
- /**
61
- * Sends a transaction with a dynamically generated priority fee based on the current network conditions and compute units needed by the transaction.
62
- */
63
- sendSmartTransaction(args: SendSmartTransactionArgs): Promise<string>;
64
- /**
65
- * Prepares a transaction to be sent with a dynamically generated priority fee based
66
- * on the current network conditions. It adds a `setComputeUnitPrice` instruction to the transaction
67
- * and simulates the transaction to estimate the number of compute units it will consume.
68
- * The returned transaction still needs to be signed and sent to the network.
69
- */
70
- prepareSmartTransaction(args: PrepareSmartTransactionArgs): Promise<_solana_web3_js.Transaction>;
71
- fetchEstimatePriorityFees(args?: EstimatePriorityFeesParams): Promise<PriorityFeeResponseData>;
72
- private createDynamicPriorityFeeInstruction;
73
- private getSimulationUnits;
74
- }
75
-
76
- export { EstimatePriorityFeesParams, PrepareSmartTransactionArgs, PriorityFeeEstimates, PriorityFeeLevels, PriorityFeeRequestPayload, PriorityFeeResponseData, SendSmartTransactionArgs, SmartTransactionBaseArgs, SolanaClientArgs, Solana as default };
@@ -1,2 +0,0 @@
1
- import { Solana } from './solana.js';
2
- export { Solana as default } from './solana.js';
@@ -1,111 +0,0 @@
1
- import { Connection, ComputeBudgetProgram, VersionedTransaction, TransactionMessage, PublicKey } from '@solana/web3.js';
2
- import 'cross-fetch';
3
- import { getClientHeaders } from '../lib/helpers/getClientHeaders.js';
4
-
5
- // eslint-disable-next-line @nx/enforce-module-boundaries
6
- class Solana {
7
- constructor({ endpointUrl }) {
8
- const clientHeaders = getClientHeaders();
9
- this.endpointUrl = endpointUrl;
10
- this.connection = new Connection(endpointUrl, {
11
- httpHeaders: clientHeaders,
12
- });
13
- }
14
- /**
15
- * Sends a transaction with a dynamically generated priority fee based on the current network conditions and compute units needed by the transaction.
16
- */
17
- async sendSmartTransaction(args) {
18
- const { transaction, keyPair, feeLevel = 'medium', sendTransactionOptions = {}, } = args;
19
- const smartTransaction = await this.prepareSmartTransaction({
20
- transaction,
21
- payerPublicKey: keyPair.publicKey,
22
- feeLevel,
23
- });
24
- smartTransaction.sign(keyPair);
25
- const hash = await this.connection.sendRawTransaction(transaction.serialize(), { skipPreflight: true, ...sendTransactionOptions });
26
- return hash;
27
- }
28
- /**
29
- * Prepares a transaction to be sent with a dynamically generated priority fee based
30
- * on the current network conditions. It adds a `setComputeUnitPrice` instruction to the transaction
31
- * and simulates the transaction to estimate the number of compute units it will consume.
32
- * The returned transaction still needs to be signed and sent to the network.
33
- */
34
- async prepareSmartTransaction(args) {
35
- const { transaction, payerPublicKey, feeLevel = 'medium' } = args;
36
- // Send simulation with placeholders so the value calculated is accurate
37
- // placeholders kept low to avoid InsufficientFundsForFee error with the high cu budget limit
38
- const simulationInstructions = [
39
- ComputeBudgetProgram.setComputeUnitPrice({
40
- microLamports: 1,
41
- }),
42
- ComputeBudgetProgram.setComputeUnitLimit({ units: 1_400_000 }),
43
- ...transaction.instructions,
44
- ];
45
- // eslint-disable-next-line prefer-const
46
- let [units, computeUnitPriceInstruction, recentBlockhash] = await Promise.all([
47
- this.getSimulationUnits(this.connection, simulationInstructions, payerPublicKey),
48
- this.createDynamicPriorityFeeInstruction(feeLevel),
49
- this.connection.getLatestBlockhash(),
50
- ]);
51
- transaction.add(computeUnitPriceInstruction);
52
- if (units) {
53
- units = Math.ceil(units * 1.05); // margin of error
54
- transaction.add(ComputeBudgetProgram.setComputeUnitLimit({ units }));
55
- }
56
- transaction.recentBlockhash = recentBlockhash.blockhash;
57
- return transaction;
58
- }
59
- // Get the priority fee averages based on fee data from the latest blocks
60
- async fetchEstimatePriorityFees(args = {}) {
61
- const payload = {
62
- method: 'qn_estimatePriorityFees',
63
- params: { api_version: 2, ...args },
64
- id: 1,
65
- jsonrpc: '2.0',
66
- };
67
- const response = await fetch(this.endpointUrl, {
68
- method: 'POST',
69
- headers: {
70
- 'Content-Type': 'application/json',
71
- },
72
- body: JSON.stringify(payload),
73
- });
74
- if (!response.ok) {
75
- if (response.status === 404) {
76
- throw new Error(`The RPC method qn_estimatePriorityFees was not found on your endpoint! Your endpoint likely does not have the Priority Fee API add-on installed. Please visit https://marketplace.quicknode.com/add-on/solana-priority-fee to install the Priority Fee API and use this method to send your transactions with priority fees calculated with real-time data.`);
77
- }
78
- throw new Error('Failed to fetch priority fee estimates');
79
- }
80
- const data = await response.json();
81
- return data;
82
- }
83
- async createDynamicPriorityFeeInstruction(feeType = 'medium') {
84
- const { result } = await this.fetchEstimatePriorityFees({});
85
- const priorityFee = feeType === 'recommended'
86
- ? result.recommended
87
- : result.per_compute_unit[feeType];
88
- const priorityFeeInstruction = ComputeBudgetProgram.setComputeUnitPrice({
89
- microLamports: priorityFee,
90
- });
91
- return priorityFeeInstruction;
92
- }
93
- async getSimulationUnits(connection, instructions, publicKey) {
94
- const testVersionedTxn = new VersionedTransaction(new TransactionMessage({
95
- instructions: instructions,
96
- payerKey: publicKey,
97
- recentBlockhash: PublicKey.default.toString(), // just a placeholder
98
- }).compileToV0Message());
99
- const simulation = await connection.simulateTransaction(testVersionedTxn, {
100
- replaceRecentBlockhash: true,
101
- sigVerify: false,
102
- });
103
- if (simulation.value.err) {
104
- console.error('Simulation error:', simulation.value.err);
105
- throw new Error(`Failed to simulate transaction ${JSON.stringify(simulation.value.err)}`);
106
- }
107
- return simulation.value.unitsConsumed;
108
- }
109
- }
110
-
111
- export { Solana };