Skip to content

[438] [High] Configurable Protocol Fee Engine with Tiering and Fee Ledger - #551

Merged
james2177 merged 2 commits into
stellar-vortex-protocol:mainfrom
Goodnessukaigwe:fix/438-high-configurable-protocol-fee-engine-with-tiering-and-fee-ledger
Sep 30, 2026
Merged

james2177 merged 2 commits into
stellar-vortex-protocol:mainfrom
Goodnessukaigwe:fix/438-high-configurable-protocol-fee-engine-with-tiering-and-fee-ledger

Conversation

@Goodnessukaigwe

Copy link
Copy Markdown

Summary

  • Adds src/fees/ with versioned rules. Precedence is specific pair, then source chain, then the built-in 5 bps default. Rules support basis points, min/max caps, and volume tiers. Integrator referral codes take a floored share of the fee; the remainder stays with the treasury.
  • Quotes and fills use the same function. The charged fee is ceil(amount * bps / 10_000) (at most one base unit above truncating division) before caps. QuoteResponseDto includes treasuryFee, integratorFee, feeRuleVersion, and referralCode.
  • Each fill posts a double-entry batch (debit user, credit treasury, credit integrator). The ledger rejects a batch unless debits equal credits. Treasury stats use the ledger once it has postings. On-chain fee collection is unchanged.

Closes #438

Problem

feeAmount was a flat truncated 5 bps with no rule version, no integrator share, and no ledger to reconcile treasury and integrator balances.

Solution

Rules and referrals come from FEE_RULES_JSON and FEE_REFERRALS_JSON (empty uses the built-in default and no referrals). ADR 0006 records rounding and the ledger invariant. Migration 20260929120000_fee_ledger creates fee_ledger. The running service posts to an in-memory ledger with that shape, matching the other default memory adapters.

Test plan

  • Quote a round amount and confirm the fee is 5 bps, feeRuleVersion is 1, and integratorFee is 0
  • Quote the same amount with a known referral code and confirm treasury plus integrator equals the fee
  • Fill that quoted amount with the same referral and confirm the realized feeAmount matches the quote
  • Confirm an unknown referral code does not create an integrator credit
  • Confirm treasury stats report ledger totals after a fill, and that debits equal credits

Made with Cursor

Pair, chain, and default rules set the fee, referral share, and a balanced debit and credit for each fill.

Co-authored-by: Cursor <cursoragent@cursor.com>
@drips-wave

drips-wave Bot commented Sep 29, 2026

Copy link
Copy Markdown

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

…urable-protocol-fee-engine-with-tiering-and-fee-ledger

# Conflicts:
#	.env.example
#	CHANGELOG.md
#	jest.config.js
#	package-lock.json
#	package.json
#	prisma/schema.prisma
#	src/app.module.ts
#	src/common/stellar-signature.ts
#	src/config/configuration.ts
#	src/config/env.validation.ts
#	src/governance/governance.module.ts
#	src/intents/dto/fill-intent.dto.ts
#	src/intents/intents.controller.ts
#	src/intents/intents.gateway.spec.ts
#	src/intents/intents.gateway.ts
#	src/intents/intents.module.ts
#	src/intents/intents.service.shadow.spec.ts
#	src/intents/intents.service.spec.ts
#	src/intents/solver-intent-matcher.ts
#	src/intents/ws/connection-state.ts
#	src/solvers/solvers.controller.ts
#	src/soroban/event-ingestion.service.ts
#	src/soroban/signer.service.spec.ts
#	src/soroban/solver-registry.service.spec.ts
#	src/soroban/soroban.controller.spec.ts
#	src/soroban/soroban.module.ts
#	src/soroban/soroban.service.ts
#	src/soroban/stellar-tx.service.spec.ts
#	src/soroban/stellar-tx.service.ts
#	src/soroban/tx-confirmation.service.ts
#	src/stats/stats.service.ts
#	src/tokens/in-memory-tokens.repository.ts
#	src/tokens/tokens.service.ts
#	src/treasury/treasury.service.spec.ts
#	src/treasury/treasury.service.ts
#	test/jest-e2e.json
@james2177
james2177 merged commit 6355dee into stellar-vortex-protocol:main Sep 30, 2026
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.

[High] Configurable Protocol Fee Engine with Tiering and Fee Ledger

2 participants