@rpc-bastion/fees
v0.4.1
Published
Priority-fee oracle with pluggable providers and quorum logic.
Readme
@rpc-bastion/fees
A priority-fee oracle with pluggable providers and quorum logic, plus a helper
to apply an estimate to a web3.js v2.0 (@solana/kit) transaction message.
Oracle
import { createFeeOracle, nativeFeeProvider, heliusFeeProvider, staticFeeProvider } from '@rpc-bastion/fees';
const oracle = createFeeOracle({
providers: [
heliusFeeProvider({ rpcUrl: HELIUS_URL }),
nativeFeeProvider({ rpc }), // your resilient @rpc-bastion/core rpc
staticFeeProvider({ values: 10_000n }), // offline floor
],
strategy: 'median', // 'first-success' | 'median' | 'max'
cacheTtlMs: 2_000,
timeoutPerProviderMs: 1_500,
fallbackEstimate: 10_000n,
bus, // optional @rpc-bastion/core event bus
});
const fee = await oracle.estimate({ level: 'high' });
// { microLamportsPerCu, level, source, fetchedAt }The oracle never throws while any provider succeeds. If they all fail it
returns fallbackEstimate and emits fee.estimate with source: 'fallback'
(treat that as a warning), and does not cache it.
| Provider | Source |
|---|---|
| nativeFeeProvider | getRecentPrioritizationFees → percentiles (p50/p75/p90/p99 → levels). The dependable fallback. |
| heliusFeeProvider | Helius getPriorityFeeEstimate |
| tritonFeeProvider | Triton / RPCPool fee API (experimental) |
| staticFeeProvider | Fixed values (tests / offline / floors) |
Applying a fee
import { applyFeeToTransactionMessage } from '@rpc-bastion/fees';
// Fixed limit:
const withFee = await applyFeeToTransactionMessage(message, fee, { computeUnitLimit: 200_000 });
// Or simulate to size the limit (sets limit = ceil(units × 1.1)):
const sized = await applyFeeToTransactionMessage(message, fee, { computeUnitLimit: 'simulate', rpc });It sets SetComputeUnitPrice to fee.microLamportsPerCu and SetComputeUnitLimit
to the chosen limit, replacing any existing ComputeBudget limit/price
instructions and placing the new pair at the front.
