Skip to content

Feature/contract dynamic fees - #804

Merged
Abdulazeem-code merged 13 commits into
Abdulazeem-code:mainfrom
Tekprecious:feature/contract-dynamic-fees
Oct 3, 2026
Merged

Abdulazeem-code merged 13 commits into
Abdulazeem-code:mainfrom
Tekprecious:feature/contract-dynamic-fees

Conversation

@Tekprecious

Copy link
Copy Markdown
Contributor

Closes #670
Smart Contracts: Implement Dynamic Fees Based on Network Congestion

Description

The platform currently charges a static fee, which can be unprofitable during periods of high network congestion on the Stellar network. This PR introduces a dynamic fee model that scales the platform fee based on the current ledger's base fee, protecting the protocol's profitability during network spikes while keeping fees reasonable for users.

Changes Made

  • Dynamic Fee Multiplier: Updated process_single_payment in payment_router/src/lib.rs to calculate a dynamic multiplier based on the current network base fee (env.ledger().base_fee() / 100 stroops). The configured fee_bps is multiplied by this dynamic factor.
  • Upper Bound Protection: Introduced a MAX_FEE_MULTIPLIER constant set to 10. The fee multiplier is strictly capped at 10x the normal rate to protect users from exorbitant fees during extreme network congestion events. The absolute fee_cap continues to enforce an overarching maximum fee limit.
  • Accurate Fee Estimation: Updated the get_effective_fee_bps endpoint with identical multiplier logic, ensuring accurate preflight fee estimations for clients interacting with the contract.

Acceptance Criteria

  • Platform fees adjust dynamically based on the ledger's base fee.
  • An upper bound (max 10x multiplier) is implemented to protect users.
  • Accurate fee estimation endpoints (get_effective_fee_bps) are updated to reflect the dynamic fee.

How to Test

  1. Deploy the updated payment_router contract on a local network or testnet.
  2. Call get_effective_fee_bps during normal conditions (base fee = 100 stroops) to confirm the baseline fee is returned.
  3. Simulate a network surge or explicitly set the base fee to a higher value (e.g., 500 stroops) and verify the fee returned scales proportionally (e.g., 5x).
  4. Simulate extreme congestion (base fee > 1000 stroops) to ensure the fee multiplier correctly clamps at 10x and does not exceed it.

@drips-wave

drips-wave Bot commented Sep 25, 2026

Copy link
Copy Markdown

@Tekprecious 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

@vercel

vercel Bot commented Sep 25, 2026

Copy link
Copy Markdown

@Tekprecious is attempting to deploy a commit to the Abdulazeem's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Abdulazeem-code

Copy link
Copy Markdown
Owner

Resolve conflicts and fix failed checks

@Abdulazeem-code

Copy link
Copy Markdown
Owner

Resolve conflicts

@Abdulazeem-code

Copy link
Copy Markdown
Owner

Resolve conflicts and fix failed checks

- Fix cargo fmt issues in payment_proxy and payment_router
- Exclude payment_router/fuzz from cargo workspace to fix build errors
- Add SOROSWAP and COOLDOWN to cspell dictionary
…mic-fees

# Conflicts:
#	.cspell.json
#	payment_router/src/lib.rs
#	stellar-payment-platform/src/middleware/signatureRateLimit.js
@Abdulazeem-code

Copy link
Copy Markdown
Owner

Please Resolve conflicts

@Tekprecious

Copy link
Copy Markdown
Contributor Author

Please Resolve conflicts

@Abdulazeem-code conflicts resolved

@Abdulazeem-code

Copy link
Copy Markdown
Owner

Kindly fix failed checks

@Abdulazeem-code

Copy link
Copy Markdown
Owner

Please resolve conflicts

@Abdulazeem-code

Copy link
Copy Markdown
Owner

Conflicts is not resolved yet

@Abdulazeem-code
Abdulazeem-code merged commit 41089aa into Abdulazeem-code:main Oct 3, 2026
15 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Smart Contracts: Implement Dynamic Fees Based on Network Congestion

2 participants