@hawksightco/hawk-sdk
Advanced tools
Comparing version 0.0.39 to 0.0.40
@@ -66,2 +66,12 @@ import * as client from "@hawksightco/swagger-client"; | ||
* Add priority fee instructions (compute budget) | ||
* | ||
* This method adds priority fee instructions to the transaction based on the specified | ||
* priority level and compute unit limit. It ensures that the total fee does not exceed | ||
* the specified maximum priority fee (in SOL) if provided. | ||
* | ||
* @param connection - The connection to the Solana cluster. | ||
* @param priorityLevel - The priority level for the fee estimation. | ||
* @param computeUnitLimit - The limit on the number of compute units. | ||
* @param maxPriorityFee - The maximum priority fee in SOL (optional). | ||
* @returns An array of transaction instructions. | ||
*/ | ||
@@ -68,0 +78,0 @@ addPriorityFeeIx(connection: web3.Connection, priorityLevel: client.PriorityLevel, computeUnitLimit: number, maxPriorityFee?: number): Promise<web3.TransactionInstruction[]>; |
@@ -153,2 +153,12 @@ "use strict"; | ||
* Add priority fee instructions (compute budget) | ||
* | ||
* This method adds priority fee instructions to the transaction based on the specified | ||
* priority level and compute unit limit. It ensures that the total fee does not exceed | ||
* the specified maximum priority fee (in SOL) if provided. | ||
* | ||
* @param connection - The connection to the Solana cluster. | ||
* @param priorityLevel - The priority level for the fee estimation. | ||
* @param computeUnitLimit - The limit on the number of compute units. | ||
* @param maxPriorityFee - The maximum priority fee in SOL (optional). | ||
* @returns An array of transaction instructions. | ||
*/ | ||
@@ -161,10 +171,12 @@ addPriorityFeeIx(connection, priorityLevel, computeUnitLimit, maxPriorityFee) { | ||
const estimate = yield (0, functions_1.getFeeEstimate)(this.generalUtility, priorityLevel, this.txMetadataResponse); | ||
// Convert maxPriorityFee from SOL to lamports (1 SOL = 1_000_000_000 lamports) | ||
const maxPriorityFeeLamports = maxPriorityFee !== undefined ? maxPriorityFee * 1000000000 : undefined; | ||
// Calculate the total fee in lamports | ||
let totalPriorityFeeLamports = (new bn_js_1.BN(estimate).mul(new bn_js_1.BN(computeUnitLimit)).div(new bn_js_1.BN(1000000))).toNumber(); | ||
let totalPriorityFeeLamports = new bn_js_1.BN(estimate).mul(new bn_js_1.BN(computeUnitLimit)).div(new bn_js_1.BN(1000000)).toNumber(); | ||
// If maxPriorityFee is defined and it is less than the total calculated fee, cap it | ||
if (maxPriorityFee !== undefined && maxPriorityFee > 0 && totalPriorityFeeLamports > maxPriorityFee) { | ||
totalPriorityFeeLamports = maxPriorityFee; | ||
if (maxPriorityFeeLamports !== undefined && totalPriorityFeeLamports > maxPriorityFeeLamports) { | ||
totalPriorityFeeLamports = maxPriorityFeeLamports; | ||
} | ||
// Convert the total priority fee back to microLamports per compute unit | ||
const priorityFeePerUnitMicroLamports = (new bn_js_1.BN(totalPriorityFeeLamports).mul(new bn_js_1.BN(1000000)).div(new bn_js_1.BN(computeUnitLimit))).toNumber(); | ||
const priorityFeePerUnitMicroLamports = new bn_js_1.BN(totalPriorityFeeLamports).mul(new bn_js_1.BN(1000000)).div(new bn_js_1.BN(computeUnitLimit)).toNumber(); | ||
// Create priority fee instructions for transaction | ||
@@ -171,0 +183,0 @@ const priorityFeeIxs = [ |
{ | ||
"name": "@hawksightco/hawk-sdk", | ||
"version": "0.0.39", | ||
"version": "0.0.40", | ||
"description": "Hawksight v2 SDK", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
133784
2421