Skip to content

Transaction Fee History Trend Analyzer #584

Description

@Kingsman-99

Description

The SDK cannot currently advise callers on appropriate base fees because it has no visibility into recent ledger fee trends. Fee spikes during network congestion cause submitted transactions to be rejected without useful guidance, and manual fee tuning is tedious. A fee trend analyzer would query Horizon's /fee_stats endpoint on a rolling basis, compute percentile estimates over a sliding window, and expose a recommended fee for a caller-specified acceptance-percentile target.

Technical Context

New module src/fees/trend.ts exposing a FeeTrendAnalyzer class. Calls Horizon.Server.feeStats() from @stellar/stellar-sdk. Stores a configurable rolling window of samples using a fixed-capacity circular buffer in src/utils/circularBuffer.ts. Percentile computation extracted to src/utils/stats.ts. Configuration via FeeTrendOptions interface in src/types.ts.

Acceptance Criteria

  • FeeTrendAnalyzer.sample() fetches the current fee stats snapshot and appends it to the rolling window, evicting the oldest entry when capacity is reached
  • FeeTrendAnalyzer.recommendedFee(percentile: 50 | 75 | 95 | 99): number returns the fee (in stroops) at the requested percentile across all stored samples
  • Window capacity is configurable (default 20, min 5, max 100) and enforced with a compile-time branded-number type
  • Samples older than a configurable TTL (default 5 minutes) are automatically evicted before any percentile computation
  • Unit tests verify percentile accuracy against a known 20-sample dataset, correct eviction by both capacity and TTL, and partial-window behavior
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions