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
Description
The README and
.kiro/specs/fee-accounting-testsdescribe a configurableprotocol_fee_bpsdeducted from eachrelease_milestone, with accumulated fees tracked in treasury, butcontracts/escrow/src/lib.rscontains no fee logic —release_milestonecredits the full milestone amount andDataKey::ProtocolFeeBps/DataKey::AccumulatedProtocolFeesare declared yet unused. Implement fee calculation, net-amount accounting, and treasury accumulation.Requirements and context
escrowSoroban contract (contracts/escrow).set_protocol_fee_bps(admin, bps)(admin-gated viarequire_admin) storing underDataKey::ProtocolFeeBps; clamp to a max of 1000 bps (10%) per the fee spec.release_milestone, computefee = milestone_amount * bps / 10_000(round down),net = milestone_amount - fee, addfeetoDataKey::AccumulatedProtocolFees, and creditnetto the freelancer accounting.fee + net == milestone_amountafter rounding; accumulated fees never exceed total released; defaultbps == 0pays the full amount.Suggested execution
git checkout -b feature/protocol-fee-accountingcontracts/escrow/src/protocol_fees.rscontracts/escrow/src/test/protocol_fees.rsdocs/escrow/FUNDING_ACCOUNTING.mdTest and commit
cargo testExample commit message
Guidelines