From 1c50038745016ebb14f8a3ab2e9aea2c43871c9c Mon Sep 17 00:00:00 2001 From: amilz <85324096+amilz@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:48:47 -0800 Subject: [PATCH] chore: add `recommended` field to prio fee api (#87) --- solana/priority-fees-addon/app.ts | 2 +- solana/priority-fees-addon/types.ts | 1 + solana/web3.js-2.0/optimized-tx/src/QuickNodeSolana.ts | 4 +++- solana/web3.js-2.0/optimized-tx/src/types/priority-fees.ts | 3 ++- solana/web3.js-2.0/quicknode-addons/types.ts | 1 + 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/solana/priority-fees-addon/app.ts b/solana/priority-fees-addon/app.ts index 7df2221..3ac5cfb 100644 --- a/solana/priority-fees-addon/app.ts +++ b/solana/priority-fees-addon/app.ts @@ -72,7 +72,7 @@ const params: EstimatePriorityFeesParams = { async function createDynamicPriorityFeeInstruction() { const { result } = await fetchEstimatePriorityFees(params); console.table(result); - const priorityFee = result.per_compute_unit.high; // 👈 Replace depending on your transaction requirements (e.g., low, medium, high, or specific percentile) + const priorityFee = result.recommended; // 👈 Replace depending on your transaction requirements (e.g., low, medium, high, or specific percentile) const priorityFeeInstruction = ComputeBudgetProgram.setComputeUnitPrice({ microLamports: priorityFee }); return priorityFeeInstruction; } diff --git a/solana/priority-fees-addon/types.ts b/solana/priority-fees-addon/types.ts index b19841c..5a92d80 100644 --- a/solana/priority-fees-addon/types.ts +++ b/solana/priority-fees-addon/types.ts @@ -28,6 +28,7 @@ interface ResponseData { }; per_compute_unit: FeeEstimates; per_transaction: FeeEstimates; + recommended: number; }; id: number; } diff --git a/solana/web3.js-2.0/optimized-tx/src/QuickNodeSolana.ts b/solana/web3.js-2.0/optimized-tx/src/QuickNodeSolana.ts index 0cc89c6..2a93d42 100644 --- a/solana/web3.js-2.0/optimized-tx/src/QuickNodeSolana.ts +++ b/solana/web3.js-2.0/optimized-tx/src/QuickNodeSolana.ts @@ -105,7 +105,9 @@ export class QuickNodeSolana { last_n_blocks: priorityFeeQuery.last_n_blocks, api_version: priorityFeeQuery.api_version }).send(); - return priorityFees.per_compute_unit[priorityFeeQuery.level]; + return priorityFeeQuery.level === "recommended" + ? priorityFees.recommended + : priorityFees.per_compute_unit[priorityFeeQuery.level]; } async prepareSmartTransactionMessage({ diff --git a/solana/web3.js-2.0/optimized-tx/src/types/priority-fees.ts b/solana/web3.js-2.0/optimized-tx/src/types/priority-fees.ts index 9531ced..ae8a2be 100644 --- a/solana/web3.js-2.0/optimized-tx/src/types/priority-fees.ts +++ b/solana/web3.js-2.0/optimized-tx/src/types/priority-fees.ts @@ -1,4 +1,4 @@ -type PriorityFeeLevel = { level: "low" | "medium" | "high" | "extreme" }; +type PriorityFeeLevel = { level: "low" | "medium" | "high" | "extreme" | "recommended" }; interface FeeEstimates { extreme: number; @@ -16,6 +16,7 @@ interface EstimatePriorityFeesResponse { }; per_compute_unit: FeeEstimates; per_transaction: FeeEstimates; + recommended: number; }; interface EstimatePriorityFeesParams { diff --git a/solana/web3.js-2.0/quicknode-addons/types.ts b/solana/web3.js-2.0/quicknode-addons/types.ts index d514f57..a476c21 100644 --- a/solana/web3.js-2.0/quicknode-addons/types.ts +++ b/solana/web3.js-2.0/quicknode-addons/types.ts @@ -16,6 +16,7 @@ interface EstimatePriorityFeesResponse { }; per_compute_unit: FeeEstimates; per_transaction: FeeEstimates; + recommended: number; }; interface EstimatePriorityFeesParams {