UNPKG

@btc-stamps/tx-builder

Version:

Transaction builder for Bitcoin Stamps and SRC-20 tokens with advanced UTXO selection

104 lines (98 loc) 3.09 kB
import { Buffer } from 'node:buffer'; /** * Enhanced Fee Estimation Interface * Handles fee calculation and estimation strategies with accurate witness size calculation */ interface FeeRate { low: number; medium: number; high: number; urgent?: number | undefined; } interface FeeEstimate { feeRate: number; totalFee: number; confidence: number; blocks: number; confirmationTime?: string; priority: 'low' | 'medium' | 'high' | 'urgent'; } type OutputType = 'P2PKH' | 'P2WPKH' | 'P2SH' | 'P2WSH' | 'P2TR' | 'OP_RETURN'; type InputType = 'P2PKH' | 'P2WPKH' | 'P2SH' | 'P2WSH' | 'P2TR'; interface SizeCalculation { inputSize: number; outputSize: number; witnessSize: number; virtualSize: number; } interface DustThresholds { P2PKH: number; P2WPKH: number; P2SH: number; P2WSH: number; P2TR: number; } interface IFeeEstimator { /** * Get current fee rates with historical context */ getFeeRates(): Promise<FeeRate>; /** * Estimate fee for transaction with enhanced calculation */ estimateFee(size: number, priority: 'low' | 'medium' | 'high' | 'urgent'): Promise<FeeEstimate>; /** * Calculate accurate transaction size with witness data */ calculateTransactionSize(inputs: Array<{ type: InputType; witnessScript?: Buffer; }>, outputs: Array<{ type: OutputType; size?: number; }>): SizeCalculation; /** * Calculate output type specific sizes */ getOutputSize(type: OutputType, scriptSize?: number): number; /** * Calculate input type specific sizes */ getInputSize(type: InputType, witnessScript?: Buffer): SizeCalculation; /** * Get dynamic dust thresholds based on fee rates */ getDustThresholds(feeRate?: number): DustThresholds; /** * Calculate CPFP (Child Pays For Parent) fee */ calculateCPFP(_parentTxid: string, parentFee: number, childSize: number, targetFeeRate: number): Promise<number>; /** * Calculate RBF (Replace By Fee) fee */ calculateRBF(originalFee: number, minRelayFee?: number): number; } interface FeeEstimatorOptions { provider?: 'mempool' | 'blockstream' | 'electrum' | 'custom'; fallbackFeeRate?: number; minFeeRate?: number; maxFeeRate?: number; enableSrc20Rules?: boolean; networkType?: 'mainnet' | 'testnet' | 'regtest'; useMockProvider?: boolean; electrumXProvider?: any; } /** * Fee Normalizer - Standardizes all fee handling to use satsPerVB * Ensures consistency with BTCStampsExplorer production API */ type FeeUnit = 'sat/byte' | 'sat/vB' | 'btc/kb'; type FeeSource = 'electrum' | 'explorer' | 'mempool'; interface NormalizedFeeRate { satsPerVB: number; unit: FeeUnit; confidence: number; source: FeeSource; timestamp: number; } export type { DustThresholds as D, FeeSource as F, IFeeEstimator as I, NormalizedFeeRate as N, OutputType as O, SizeCalculation as S, FeeRate as a, FeeEstimatorOptions as b, FeeEstimate as c, InputType as d };