Skip to main content

SolanaFees

Defined in: atomiq-chain-solana/src/solana/chain/modules/SolanaFees.ts:43

Fee estimation service for the Solana network. Uses client-side fee estimation algorithm by default, which fetches a bunch (default 8) random blocks in the past period (default 150) and computes the average fee. It automatically detects whether the underlying RPC endpoint is a Helius one which features the getPriorityFeeEstimate endpoint, and if available uses that one.

Constructors​

Constructor​

new SolanaFees(
connection,
maxFeeMicroLamports,
numSamples,
period,
useHeliusApi,
heliusFeeLevel,
getStaticFee?,
bribeData?): SolanaFees;

Defined in: atomiq-chain-solana/src/solana/chain/modules/SolanaFees.ts:77

Parameters​

ParameterTypeDefault valueDescription
connectionConnectionundefinedUnderlying Solana network connection to use for read access to Solana
maxFeeMicroLamportsnumber250000Maximum allowed fee in microLamports/CU (1/1,000,000 of a lamport per compute unit)
numSamplesnumber8Number of samples to use when estimating the global fee on the client-side, this many blocks are sampled from the last period blocks to estimate an average fee rate
periodnumber150Period of past blocks to sample random blocks from when estimating the global fee on the client-side
useHeliusApi"yes" | "no" | "auto""auto"Whether to use the helius API or not, default to "auto", which automatically detects if the underlying RPC supports Helius's getPriorityFeeEstimate RPC call
heliusFeeLevel"min" | "low" | "medium" | "high" | "veryHigh" | "unsafeMax""veryHigh"Fee level to use when fetching the fee rate from Helius's getPriorityFeeEstimate RPC endpoint, for the meaning of the different levels refer to https://www.helius.dev/docs/priority-fee-api#priority-levels-explained
getStaticFee?(feeRate) => bigintundefinedOptional function for adding a base fee to transactions (this function returns the base fee in lamports to be added to the transaction) - this fee doesn't scale with CUs of the transaction and is instead applied as-is
bribeData?FeeBribeDataundefinedBribe fee configuration (used for e.g. Jito tips)

Returns​

SolanaFees

Methods​

applyFeeRateBegin()​

static applyFeeRateBegin(
tx,
computeBudget,
feeRate): void;

Defined in: atomiq-chain-solana/src/solana/chain/modules/SolanaFees.ts:428

Applies fee rate to a transaction, should be called before adding instructions to the transaction, specifically it adds the setComputeUnitLimit & setComputeUnitPrice instruction.

Parameters​

ParameterTypeDescription
txTransaction
computeBudgetnumber
feeRatestring

Returns​

void

Example​

const feeRate = solanaFees.getFeeRate([...writeableAccounts]);
const tx = new Transaction();
//Apply the fee rate part at the beginning of the transaction (specifically setComputeUnitLimit & setComputeUnitPrice)
SolanaFees.applyFeeRateBegin(tx, feeRate);
//Add instructions here
tx.add(instruction1);
tx.add(instruction2);
//Set the fee payer
tx.feePayer = feePayerPublicKey;
//Apply the fee rate part at the end of the transaction (specifically the transfer to the bribe account, e.g. Jito tip)
SolanaFees.applyFeeRateEnd(tx, feeRate);

applyFeeRateEnd()​

static applyFeeRateEnd(
tx,
computeBudget,
feeRate): void;

Defined in: atomiq-chain-solana/src/solana/chain/modules/SolanaFees.ts:481

Applies fee rate to a transaction, should be called after adding instructions to the transaction, specifically it adds the adds the bribe SystemProgram.transfer instruction.

Parameters​

ParameterTypeDescription
txTransaction
computeBudgetnumber
feeRatestring

Returns​

void

Example​

const feeRate = solanaFees.getFeeRate([...writeableAccounts]);
const tx = new Transaction();
//Apply the fee rate part at the beginning of the transaction (specifically setComputeUnitLimit & setComputeUnitPrice)
SolanaFees.applyFeeRateBegin(tx, feeRate);
//Add instructions here
tx.add(instruction1);
tx.add(instruction2);
//Set the fee payer
tx.feePayer = feePayerPublicKey;
//Apply the fee rate part at the end of the transaction (specifically the transfer to the bribe account, e.g. Jito tip)
SolanaFees.applyFeeRateEnd(tx, feeRate);

getGlobalFeeRate()​

getGlobalFeeRate(): Promise<bigint>;

Defined in: atomiq-chain-solana/src/solana/chain/modules/SolanaFees.ts:341

Gets global fee rate, with caching

Returns​

Promise<bigint>

global fee rate microLamports/CU


getPriorityFee()​

getPriorityFee(
computeUnits,
feeRate,
includeStaticFee): bigint;

Defined in: atomiq-chain-solana/src/solana/chain/modules/SolanaFees.ts:390

Calculates the total priority fee paid for a given compute budget at a given fee rate

Parameters​

ParameterTypeDefault valueDescription
computeUnitsnumberundefined
feeRatestringundefined
includeStaticFeebooleantruewhether the include the static/base part of the fee rate

Returns​

bigint


submitTx()​

submitTx(tx, options?): Promise<string>;

Defined in: atomiq-chain-solana/src/solana/chain/modules/SolanaFees.ts:513

Checks if the transaction should be submitted over Jito and if yes submits it

Parameters​

ParameterTypeDescription
txBufferRaw signed transaction to be attempted to be sent over Jito
options?SendOptionsSend options for the sendTransaction RPC call

Returns​

Promise<string>

null if the transaction was not sent over Jito, tx signature when tx was sent over Jito