This module adds configurable protocol fee settings for the escrow milestone model.
protocol_fee_bpsconfigurable increate_contract(0-10000 basis points).protocol_fee_accountset at creation time; only this account can withdraw fees and update fee rate.- Per-milestone fee accounting via
Milestone.protocol_feeandEscrowContract.protocol_fee_accrued. get_protocol_fee_accruedto query current fee balance.withdraw_protocol_feesfor controlled withdrawal.set_protocol_fee_bpsto update protocol fee rate with authorization.
- Only the
protocol_fee_accountcan adjust fee rate or withdraw accrued fees. - Fee account is authenticated with
caller.require_auth(). - Fee bounds enforced at 0..=10000.
- All protocol fee operations use persisted state and safe integer arithmetic.
On each milestone release:
- Compute fee:
milestone.amount * protocol_fee_bps / 10000. - Save fee to milestone object.
- Increment
protocol_fee_accrued. - Mark milestone released and contract status completed when all milestones done.
Mainnet readiness (limits, events, risks): mainnet-readiness.md
This document summarizes the reviewer-facing architecture for contracts/escrow.
The contract persists:
- escrow lifecycle state for each contract
- participant metadata for the client and freelancer
- milestone release state
- funded and released accounting
- pending and issued reputation aggregates
- protocol governance parameters
- pause and emergency flags
Core escrow endpoints:
create_contract(client, freelancer, milestone_amounts) -> u32deposit_funds(contract_id, amount) -> boolrelease_milestone(contract_id, milestone_id) -> boolissue_reputation(contract_id, rating) -> boolget_contract(contract_id) -> EscrowContractDataget_reputation(freelancer) -> Option<ReputationRecord>get_pending_reputation_credits(freelancer) -> u32
Operational controls:
initialize(admin) -> boolpause() -> boolunpause() -> boolactivate_emergency_pause() -> boolresolve_emergency() -> boolis_paused() -> boolis_emergency() -> bool
Governance:
initialize_protocol_governance(admin, min_milestone_amount, max_milestones, min_reputation_rating, max_reputation_rating) -> boolupdate_protocol_parameters(...) -> boolpropose_governance_admin(next_admin) -> boolaccept_governance_admin() -> boolget_protocol_parameters() -> ProtocolParametersget_governance_admin() -> Option<Address>get_pending_governance_admin() -> Option<Address>
The escrow tests are grouped into dedicated modules:
To prevent out-of-gas or infinite-loop denial of service attacks, the escrow contract enforces creation limits:
- maximum milestone count is capped by
ProtocolParameters.max_milestones(defaults to 16) - total escrow amount is bounded by the immutable mainnet cap (
MAINNET_MAX_TOTAL_ESCROW_PER_CONTRACT_STROOPS)
Supported lifecycle transitions:
Created -> Fundedafter any positive depositFunded -> Completedafter the final unreleased milestone is released
Operational invariants:
- client and freelancer addresses are immutable after creation
- milestone amounts are immutable after creation
- each milestone can transition from
released = falsetoreleased = trueexactly once released_amountis the sum of released milestone amountsreleased_milestonesmatches the number of released milestone flagsreputation_issuedcan only becometrueafterCompleted
- Detect incident and call
activate_emergency_pause. - Investigate and remediate root cause.
- Validate mitigations in test/staging.
- Call
resolve_emergencyto restore service. - Publish incident summary for ecosystem transparency.
Each EscrowContractData record stores:
- participant addresses
- milestone vector and cached milestone count
- total escrow amount
- funded and released balances
- released milestone count
- contract status
- reputation issuance flag
- creation and update timestamps
Detailed storage-key coverage is documented in state-persistence.md.
The escrow regression suite is split by concern:
flows.rs: happy-path lifecycle and reputation aggregationlifecycle.rs: state transition persistencepersistence.rs: storage round-trip assertionssecurity.rs: failure paths and validation checksgovernance.rs: admin and parameter persistencepause_controls.rsandemergency_controls.rs: operational safety controlsperformance.rs: resource regression ceilings