Skip to content

Dynamic Fee Surge Detector #497

Description

@Kingsman-99

Description

Stellar's base fee rises during network congestion, making hard-coded fee values cause transaction failures during surges. The SDK currently uses a fixed fee from StellarSplitConfig and does not react to real-time ledger fee data. A surge detector should monitor recent ledger fee statistics via Horizon and automatically recommend or apply an adjusted fee multiplier when the network is congested.

Technical Context

Extend src/feeEstimator.ts and src/fee.ts. Uses @stellar/stellar-sdk Server.feeStats() which returns FeeStatsRecord with p10, p50, p95 fee percentiles. Add FeeSurgeConfig and FeeRecommendation to src/types.ts. Integrate with src/txBuilder.ts so the surge-adjusted fee is applied before transaction signing. Optionally emits a feeSurgeDetected event via src/events.ts.

Acceptance Criteria

  • detectFeeSurge(): Promise<FeeRecommendation> fetches current fee stats and computes a recommended base fee at a configurable percentile (default p75)
  • A surge threshold (e.g. 2× the 30-ledger average) triggers a feeSurgeDetected event with the recommended fee
  • src/txBuilder.ts calls detectFeeSurge() before building each transaction and applies the recommendation when autoFeeAdjust: true is set in config
  • Fee history is sampled over a configurable rolling window (default: last 10 ledgers) fetched from feeStats()
  • Unit tests mock feeStats() responses and assert correct surge detection at various percentile thresholds
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions