Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@quicknode/sdk

Package Overview
Dependencies
Maintainers
27
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@quicknode/sdk - npm Package Compare versions

Comparing version 2.1.3 to 2.2.0

esm/solana/index.d.ts

112

cjs/index.js

@@ -8,3 +8,4 @@ 'use strict';

var chains = require('viem/chains');
var fetch = require('cross-fetch');
var fetch$1 = require('cross-fetch');
var web3_js = require('@solana/web3.js');

@@ -32,3 +33,4 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var viem__namespace = /*#__PURE__*/_interopNamespace(viem);
var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch$1);
var web3_js__namespace = /*#__PURE__*/_interopNamespace(web3_js);

@@ -334,5 +336,5 @@ class QNInputValidationError extends Error {

globalThis.fetch = fetch__default["default"];
globalThis.Headers = fetch.Headers;
globalThis.Request = fetch.Request;
globalThis.Response = fetch.Response;
globalThis.Headers = fetch$1.Headers;
globalThis.Request = fetch$1.Request;
globalThis.Response = fetch$1.Response;
}

@@ -359,7 +361,106 @@ }

// eslint-disable-next-line @nx/enforce-module-boundaries
class Solana {
constructor({ endpointUrl }) {
this.endpointUrl = endpointUrl;
this.connection = new web3_js.Connection(endpointUrl);
}
/**
* Sends a transaction with a dynamically generated priority fee based on the current network conditions and compute units needed by the transaction.
*/
async sendSmartTransaction(args) {
const { transaction, keyPair, feeLevel = 'medium', sendTransactionOptions = {}, } = args;
const smartTransaction = await this.prepareSmartTransaction({
transaction,
payerPublicKey: keyPair.publicKey,
feeLevel,
});
smartTransaction.sign(keyPair);
const hash = await this.connection.sendRawTransaction(transaction.serialize(), { skipPreflight: true, ...sendTransactionOptions });
return hash;
}
/**
* Prepares a transaction to be sent with a dynamically generated priority fee based
* on the current network conditions. It adds a `setComputeUnitPrice` instruction to the transaction
* and simulates the transaction to estimate the number of compute units it will consume.
* The returned transaction still needs to be signed and sent to the network.
*/
async prepareSmartTransaction(args) {
const { transaction, payerPublicKey, feeLevel = 'medium' } = args;
// Need to fetch this ahead of time and add to transaction so it's in the transaction instructions
// for the simulation
const computeUnitPriceInstruction = await this.createDynamicPriorityFeeInstruction(feeLevel);
const allInstructions = [
...transaction.instructions,
computeUnitPriceInstruction,
];
// eslint-disable-next-line prefer-const
let [units, recentBlockhash] = await Promise.all([
this.getSimulationUnits(this.connection, allInstructions, payerPublicKey),
this.connection.getLatestBlockhash(),
]);
transaction.add(computeUnitPriceInstruction);
if (units) {
units = Math.ceil(units * 1.05); // margin of error
transaction.add(web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units }));
}
transaction.recentBlockhash = recentBlockhash.blockhash;
return transaction;
}
// Get the priority fee averages based on fee data from the latest blocks
async fetchEstimatePriorityFees(args = {}) {
const payload = {
method: 'qn_estimatePriorityFees',
params: args,
id: 1,
jsonrpc: '2.0',
};
const response = await fetch(this.endpointUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
});
if (!response.ok) {
if (response.status === 404) {
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.`);
}
throw new Error('Failed to fetch priority fee estimates');
}
const data = await response.json();
return data;
}
async createDynamicPriorityFeeInstruction(feeType = 'medium') {
const { result } = await this.fetchEstimatePriorityFees({});
const priorityFee = result.per_compute_unit[feeType];
const priorityFeeInstruction = web3_js.ComputeBudgetProgram.setComputeUnitPrice({
microLamports: priorityFee,
});
return priorityFeeInstruction;
}
async getSimulationUnits(connection, instructions, publicKey) {
const testVersionedTxn = new web3_js.VersionedTransaction(new web3_js.TransactionMessage({
instructions: instructions,
payerKey: publicKey,
recentBlockhash: web3_js.PublicKey.default.toString(), // just a placeholder
}).compileToV0Message());
const simulation = await connection.simulateTransaction(testVersionedTxn, {
replaceRecentBlockhash: true,
sigVerify: false,
});
if (simulation.value.err) {
return undefined;
}
return simulation.value.unitsConsumed;
}
}
const QuickNode = {
Core: Core,
Solana: Solana,
};
exports.viem = viem__namespace;
exports.solanaWeb3 = web3_js__namespace;
exports.Core = Core;

@@ -369,2 +470,3 @@ exports.QNChainNotSupported = QNChainNotSupported;

exports.QNInvalidEndpointUrl = QNInvalidEndpointUrl;
exports.Solana = Solana;
exports["default"] = QuickNode;
import { Core } from '../core/core.js';
import { Solana } from '../solana/solana.js';
const QuickNode = {
Core: Core,
Solana: Solana,
};
export { QuickNode as default };
import QuickNode from './client/client.js';
export { default } from './client/client.js';
export { Core } from './core/core.js';
export { Solana } from './solana/solana.js';
import * as viem from 'viem';
export { viem };
import * as web3_js from '@solana/web3.js';
export { web3_js as solanaWeb3 };
export { QNInputValidationError } from './lib/errors/QNInputValidationError.js';
export { QNInvalidEndpointUrl } from './lib/errors/QNInvalidEnpointUrl.js';
export { QNChainNotSupported } from './lib/errors/QNChainNotSupported.js';

@@ -5,2 +5,5 @@ import { Chain, PublicClient } from 'viem';

import { z, ZodError } from 'zod';
import * as _solana_web3_js from '@solana/web3.js';
import { Transaction, PublicKey, Keypair, SendOptions, Connection } from '@solana/web3.js';
export { _solana_web3_js as solanaWeb3 };

@@ -561,4 +564,75 @@ type SimplifyType<T> = T extends object ? {

type PercentileRangeUnion = '0' | '5' | '10' | '15' | '20' | '25' | '30' | '35' | '40' | '45' | '50' | '55' | '60' | '65' | '70' | '75' | '80' | '85' | '90' | '95' | '100';
type PriorityFeeLevels = 'low' | 'medium' | 'high' | 'extreme';
interface PriorityFeeRequestPayload {
method: string;
params: {
last_n_blocks?: number;
account?: string;
};
id: number;
jsonrpc: string;
}
interface PriorityFeeEstimates {
extreme: number;
high: number;
low: number;
medium: number;
percentiles: {
[key in PercentileRangeUnion]: number;
};
}
interface PriorityFeeResponseData {
jsonrpc: string;
result: {
context: {
slot: number;
};
per_compute_unit: PriorityFeeEstimates;
per_transaction: PriorityFeeEstimates;
};
id: number;
}
interface EstimatePriorityFeesParams {
last_n_blocks?: number;
account?: string;
}
interface SolanaClientArgs {
endpointUrl: string;
}
interface SmartTransactionBaseArgs {
transaction: Transaction;
feeLevel?: PriorityFeeLevels;
}
interface PrepareSmartTransactionArgs extends SmartTransactionBaseArgs {
payerPublicKey: PublicKey;
}
interface SendSmartTransactionArgs extends SmartTransactionBaseArgs {
keyPair: Keypair;
sendTransactionOptions?: SendOptions;
}
declare class Solana {
readonly endpointUrl: string;
readonly connection: Connection;
constructor({ endpointUrl }: SolanaClientArgs);
/**
* Sends a transaction with a dynamically generated priority fee based on the current network conditions and compute units needed by the transaction.
*/
sendSmartTransaction(args: SendSmartTransactionArgs): Promise<string>;
/**
* Prepares a transaction to be sent with a dynamically generated priority fee based
* on the current network conditions. It adds a `setComputeUnitPrice` instruction to the transaction
* and simulates the transaction to estimate the number of compute units it will consume.
* The returned transaction still needs to be signed and sent to the network.
*/
prepareSmartTransaction(args: PrepareSmartTransactionArgs): Promise<_solana_web3_js.Transaction>;
fetchEstimatePriorityFees(args?: EstimatePriorityFeesParams): Promise<PriorityFeeResponseData>;
private createDynamicPriorityFeeInstruction;
private getSimulationUnits;
}
declare const QuickNode: {
Core: typeof Core;
Solana: typeof Solana;
};

@@ -584,2 +658,2 @@

export { Core, CoreArguments, QNChainNotSupported, QNCoreClient, QNCoreClientConfig, QNFetchNFTCollectionDetailsInput, QNFetchNFTCollectionDetailsResult, QNFetchNFTInput, QNFetchNFTResult, QNFetchNFTsByCollectionInput, QNFetchNFTsByCollectionResult, QNGetTokenMetadataByCAInput, QNGetTokenMetadataByCAResult, QNGetTokenMetadataBySymbolInput, QNGetTokenMetadataBySymbolResult, QNGetTransactionsByAddressInput, QNGetTransactionsByAddressResult, QNGetTransfersByNFTInput, QNGetTransfersByNFTResult, QNGetWalletTokenBalanceInput, QNGetWalletTokenBalanceResult, QNGetWalletTokenTransactionsInput, QNGetWalletTokenTransactionsResult, QNInputValidationError, QNInvalidEndpointUrl, QNVerifyNFTsOwnerInput, QNVerifyNFTsOwnerResult, QuickNode as default };
export { Core, CoreArguments, EstimatePriorityFeesParams, PrepareSmartTransactionArgs, PriorityFeeEstimates, PriorityFeeLevels, PriorityFeeRequestPayload, PriorityFeeResponseData, QNChainNotSupported, QNCoreClient, QNCoreClientConfig, QNFetchNFTCollectionDetailsInput, QNFetchNFTCollectionDetailsResult, QNFetchNFTInput, QNFetchNFTResult, QNFetchNFTsByCollectionInput, QNFetchNFTsByCollectionResult, QNGetTokenMetadataByCAInput, QNGetTokenMetadataByCAResult, QNGetTokenMetadataBySymbolInput, QNGetTokenMetadataBySymbolResult, QNGetTransactionsByAddressInput, QNGetTransactionsByAddressResult, QNGetTransfersByNFTInput, QNGetTransfersByNFTResult, QNGetWalletTokenBalanceInput, QNGetWalletTokenBalanceResult, QNGetWalletTokenTransactionsInput, QNGetWalletTokenTransactionsResult, QNInputValidationError, QNInvalidEndpointUrl, QNVerifyNFTsOwnerInput, QNVerifyNFTsOwnerResult, SendSmartTransactionArgs, SmartTransactionBaseArgs, Solana, SolanaClientArgs, QuickNode as default };

@@ -9,3 +9,3 @@ {

"license": "MIT",
"version": "2.1.3",
"version": "2.2.0",
"main": "./cjs/index.js",

@@ -25,2 +25,3 @@ "module": "./esm/index.js",

"@pollyjs/persister-fs": "^6.0.5",
"@solana/web3.js": "^1.91",
"@types/jest": "^29.5.1",

@@ -45,2 +46,7 @@ "@types/mocha": "^10.0.1",

"types": "./esm/core/index.d.ts"
},
"./solana": {
"import": "./esm/solana/index.js",
"default": "./cjs/solana/index.js",
"types": "./esm/solana/index.d.ts"
}

@@ -52,2 +58,5 @@ },

"./esm/core/index.d.ts"
],
"solana": [
"./esm/solana/index.d.ts"
]

@@ -54,0 +63,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc