From 078cbe80374cd4a29cf947717979f8c6842238fb Mon Sep 17 00:00:00 2001 From: gabrielkerekes Date: Mon, 25 Mar 2024 18:53:17 +0100 Subject: [PATCH] fix(blockchain-link): use constant and increased compute unit limit for Solana transactions In an ideal world over-reserving compute units would not result in faster transaction confirmation but if we optimize the compute unit limit to match the amount of CUs the transaction requires (+ a 20% buffer) the transactions simply do not go through in time. Perhaps this could be revisited at some point in the future e.g. when [this PR](https://github.com/anza-xyz/agave/pull/187) is released and validators update. --- .../blockchain-link/src/workers/solana/fee.ts | 15 ++++++--------- packages/connect/src/data/defaultFeeLevels.ts | 4 ++-- packages/suite/src/utils/wallet/solanaUtils.ts | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/blockchain-link/src/workers/solana/fee.ts b/packages/blockchain-link/src/workers/solana/fee.ts index 997e843ca15..edc77f6b695 100644 --- a/packages/blockchain-link/src/workers/solana/fee.ts +++ b/packages/blockchain-link/src/workers/solana/fee.ts @@ -1,9 +1,12 @@ -import { Connection, Message, PublicKey, VersionedTransaction } from '@solana/web3.js'; +import { Connection, Message, PublicKey } from '@solana/web3.js'; import BigNumber from 'bignumber.js'; const COMPUTE_BUDGET_PROGRAM_ID = 'ComputeBudget111111111111111111111111111111'; const DEFAULT_COMPUTE_UNIT_PRICE = 100_000; // micro-lamports, value taken from other wallets -const DEFAULT_COMPUTE_UNIT_LIMIT = 50_000; // sending tokens with token account creation requires ~28K units +// sending tokens with token account creation requires ~28K units. However we over-reserve for now +// since otherwise the transactions don't seem to go through otherwise. This can perhaps be changed +// if e.g. https://github.com/anza-xyz/agave/pull/187 is merged. +const DEFAULT_COMPUTE_UNIT_LIMIT = 200_000; export const getBaseFee = async (api: Connection, message: Message) => { // Remove ComputeBudget instructions from the message when estimating the base fee @@ -39,13 +42,7 @@ export const getPriorityFee = async (api: Connection, message: Message) => { lockedWritableAccounts: affectedAccounts.map(a => new PublicKey(a)), }); - // https://solana.com/developers/guides/advanced/how-to-request-optimal-compute#special-considerations - const simulationResult = await api.simulateTransaction(new VersionedTransaction(message)); - const simulatedUnitsConsumed = simulationResult.value.unitsConsumed; - const computeUnitLimit = - simulatedUnitsConsumed != null - ? Math.ceil(simulatedUnitsConsumed * 1.2) // 20% buffer - 10% is recommended by the article above, but we double it just to be sure - : DEFAULT_COMPUTE_UNIT_LIMIT; + const computeUnitLimit = DEFAULT_COMPUTE_UNIT_LIMIT; const networkPriorityFee = recentFees.map(a => a.prioritizationFee).sort((a, b) => b - a)[ Math.floor(recentFees.length / 4) diff --git a/packages/connect/src/data/defaultFeeLevels.ts b/packages/connect/src/data/defaultFeeLevels.ts index fb097aaaf06..2cf5900f1f5 100644 --- a/packages/connect/src/data/defaultFeeLevels.ts +++ b/packages/connect/src/data/defaultFeeLevels.ts @@ -97,8 +97,8 @@ const SOLANA_FEE_INFO: FeeInfoWithLevels = { { label: 'normal', feePerUnit: '100000', - feeLimit: '50000', - feePerTx: '10000', + feeLimit: '200000', + feePerTx: '25000', blocks: -1, }, ], diff --git a/packages/suite/src/utils/wallet/solanaUtils.ts b/packages/suite/src/utils/wallet/solanaUtils.ts index 5f4252c6a9a..867208738f6 100644 --- a/packages/suite/src/utils/wallet/solanaUtils.ts +++ b/packages/suite/src/utils/wallet/solanaUtils.ts @@ -46,7 +46,7 @@ type PriorityFees = { computeUnitPrice: string; computeUnitLimit: string }; export const dummyPriorityFeesForFeeEstimation: PriorityFees = { computeUnitPrice: '100000', - computeUnitLimit: '50000', + computeUnitLimit: '200000', }; const addPriorityFees = async (transaction: Transaction, priorityFees: PriorityFees) => {