Skip to content

Feature/dynamic fees - #711

Merged
Sadeequ merged 6 commits into
StellarFlow-Network:mainfrom
nafsonig:feature/dynamic-fees
Jul 29, 2026
Merged

Feature/dynamic fees#711
Sadeequ merged 6 commits into
StellarFlow-Network:mainfrom
nafsonig:feature/dynamic-fees

Conversation

@nafsonig

Copy link
Copy Markdown
Contributor

Changes Made:

  1. Added dynamic fee tracking in fees.rs:
    • Added VolumeHistory struct to track previous and current period volumes
    • Added DynamicFeeState struct to manage fee bounds and current fee rate
    • Implemented update_volume_and_adjust_fee() to automatically adjust fees based on volume changes
    • Added calculate_and_deduct_fee() to accurately deduct fees during swap calculations
    • Added admin function set_dynamic_fee_config() to configure fee parameters

closes #602

  1. Updated swap calculation in invariant.rs:
    • Modified compute_swap_out() to integrate dynamic fee deduction
    • The function now returns both the final amount after fees and the collected fee amount
    • Automatically updates volume history and recalculates fees when periods elapse

closes #691

  1. Added contract interface in lib.rs:
    • Exposed public functions to get current dynamic fee and configure fee parameters
    • Added internal helper functions for swap execution
    • Added missing InvalidInput error code

Key Features:

  • Fee range: Automatically adjusts between 0.05% (5 bps) and 0.30% (30 bps)
  • Volume-based adjustments:
    • Increases fee by 5 bps when volume spikes >50% to reduce congestion
    • Decreases fee by 5 bps when volume drops >30% to attract more trading
  • Periodic recalculation: Defaults to 1-hour periods (configurable by admin)
  • Proper clamping: Fees never exceed the allowed bounds
  • Accurate calculation: Uses basis point arithmetic for precise fee deductions

closes #695

How it works:

  1. During each swap, the volume is added to the current period's total
  2. When the period expires (1 hour by default), the volume delta is calculated
  3. The fee is adjusted based on whether volume increased or decreased significantly
  4. The new fee is applied to all subsequent swaps until the next recalculation
  5. Fees are accurately deducted from swap outputs and accumulated in the pool

The implementation satisfies all requirements: dynamic fee calculation based on volume delta, accurate fee deduction during output calculations, and keeps fees within the specified 0.05% to 0.30% range.

closes #700

nafsonig added 5 commits July 29, 2026 17:25
…volume shifts

- Add VolumeHistory and DynamicFeeState structs to track volume and fees
- Implement automatic fee adjustment based on volume delta (>50% increase, >30% decrease)
- Integrate dynamic fee deduction with swap output calculation
- Add admin configuration for fee parameters
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@nafsonig Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Sadeequ
Sadeequ merged commit bd09ee3 into StellarFlow-Network:main Jul 29, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants