Skip to content

Implement protocol fee accounting on milestone release (protocol_fee_bps) #313

@mikewheeleer

Description

@mikewheeleer

Description

The README and .kiro/specs/fee-accounting-tests describe a configurable protocol_fee_bps deducted from each release_milestone, with accumulated fees tracked in treasury, but contracts/escrow/src/lib.rs contains no fee logic — release_milestone credits the full milestone amount and DataKey::ProtocolFeeBps / DataKey::AccumulatedProtocolFees are declared yet unused. Implement fee calculation, net-amount accounting, and treasury accumulation.

Requirements and context

  • Scoped to TalentTrust escrow Soroban contract (contracts/escrow).
  • Add set_protocol_fee_bps(admin, bps) (admin-gated via require_admin) storing under DataKey::ProtocolFeeBps; clamp to a max of 1000 bps (10%) per the fee spec.
  • In release_milestone, compute fee = milestone_amount * bps / 10_000 (round down), net = milestone_amount - fee, add fee to DataKey::AccumulatedProtocolFees, and credit net to the freelancer accounting.
  • Invariant: fee + net == milestone_amount after rounding; accumulated fees never exceed total released; default bps == 0 pays the full amount.
  • Must be secure, tested, and documented.

Suggested execution

  • Fork the repo and create a branch:
    • git checkout -b feature/protocol-fee-accounting
  • Implement changes:
    • contracts/escrow/src/protocol_fees.rs
    • Tests: contracts/escrow/src/test/protocol_fees.rs
    • Docs: docs/escrow/FUNDING_ACCOUNTING.md
    • Include rustdoc/NatSpec-style doc comments on public functions
    • Validate security assumptions (auth, overflow, fail-closed state machine, storage TTL, fee accounting)

Test and commit

  • Run tests: cargo test
  • Cover edge cases (unauthorized callers, double release/refund, expired approvals, fee rounding, paused state)
  • Include test output and security notes in the PR

Example commit message

feat(escrow): add protocol_fee_bps deduction on release

Guidelines

  • Minimum 95% test coverage on new/changed code
  • Clear documentation
  • Timeframe: 96 hours from assignment

Metadata

Metadata

Assignees

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions