Battle-tested Soroban smart contracts powering TrustFlow's decentralized escrow protocol.
TrustFlow Contract is the on-chain layer of the TrustFlow Protocol — a suite of Rust smart contracts deployed on the Stellar/Soroban network. It handles milestone-based escrow, community dispute resolution, fee management, oracle integration, and on-chain governance for the gig economy.
- 🔒 Milestone Escrow: Trustless vault contracts that release funds tranche-by-tranche as work is approved.
- ⚖️ Dispute Resolution: Decentralized courtroom with juror voting, settlement logic, and appeals.
- 🏛️ On-Chain Governance: Protocol parameter changes governed by token holders.
- 🔮 Oracle Integration: External price feeds and data anchoring for real-world settlement.
- 💸 Fee Engine: Configurable fee collection and distribution across protocol participants.
- 🪙 Abundance Token: Native fungible token contract for protocol incentives.
- 🌱 Crowdfund Contract: Milestone-based fundraising with built-in accountability.
contracts/
├── src/ # Core protocol contracts
│ ├── dispute.rs # Dispute creation, voting, and resolution
│ ├── settlement.rs # Fund release and settlement logic
│ ├── governance.rs # On-chain governance and voting
│ ├── oracle.rs # External data feed integration
│ ├── fee.rs # Fee collection and distribution
│ ├── storage.rs # Persistent contract storage definitions
│ ├── types.rs # Shared data types and structs
│ ├── events.rs # Contract event definitions
│ └── errors.rs # Error codes and handling
├── abundance/ # Abundance token (SAC-compatible fungible token)
├── crowdfund/ # Crowdfund contract
scripts/
├── deploy.sh # Deploy contracts to network
├── migrate.sh # Run contract migrations
├── seed.sh # Seed test data
└── setup.sh # Environment setup
tests/
├── escrow.test.ts # Escrow contract tests
├── dispute.test.ts # Dispute resolution tests
├── auth.test.ts # Auth and access control tests
├── stellar.test.ts # Stellar network integration tests
└── integration.test.ts # Full end-to-end integration tests
- Rust >= 1.74.0
- Soroban CLI
- Stellar account funded on testnet
rustup target add wasm32-unknown-unknown
cargo install --locked soroban-climake build
# or
cargo build --target wasm32-unknown-unknown --release./scripts/setup.sh
./scripts/deploy.sh testnetcargo test- Client creates an escrow vault via the SDK or backend API.
- Funds are locked into the contract.
- Milestones are released as work is approved.
- If disputed, jurors vote on-chain — settlement is executed automatically.
Protocol parameters (fees, quorum thresholds, juror rewards) are controlled by on-chain proposals and token-weighted voting.
Price feeds are anchored via the oracle contract, enabling USDC-denominated payouts at fair market rates.
Soroban archives persistent and instance storage entries once their time-to-live (TTL) expires; an archived entry can only be read again after a separate RestoreFootprintOp. Because TrustFlow escrows and disputes are often long-lived (milestone projects, jurors slow to vote), the trustflow contract (contracts/trustflow/src/lib.rs) manages this explicitly instead of relying on the SDK's short default TTL:
- Every persistent write (escrow, dispute, votes, juror stake) is immediately followed by a TTL bump to a 90-day horizon, refreshed once the entry drops under 30 days remaining.
- The contract instance (admin/token/config) is bumped on the same 90-day/30-day schedule on every call. This is intentional: the instance must outlive any single escrow's dormancy window, since a call is needed just to invoke anything — including the maintenance calls below — and an archived instance bricks the whole contract, not just one escrow.
bump_escrow_ttl(escrow_id)andbump_juror_stake_ttl(juror)are permissionless maintenance entrypoints a keeper/cron job can call periodically to keep a fully dormant escrow or an idle juror's stake alive without mutating any state. Both emit events (EscrowTtlBumped) for indexers to track rent health.
release_milestone_tranche(escrow_id, milestone_index, gross_amount, caller) (in contracts/trustflow/src/lib.rs) lets a depositor release a milestone's funded amount in one or more partial tranches, splitting a protocol fee to the treasury atomically in the same call:
- Default fee & treasury:
initializesets a default protocol fee of 50 bps (0.50%), paid to the admin address, without changing the existinginitialize(admin, token, slash_bps)signature. The admin can raise or lower the global default fee (up to a 1,000 bps / 10% cap) viaset_fee_bps, and repoint the global default treasury viaset_treasury— both require the stored admin's authorization.get_fee_bps/get_treasuryexpose the current global defaults; there are no getters for per-escrow or per-milestone accounting, which is internal contract state. - Per-escrow fee snapshot:
create_escrowandinit_escrowboth snapshot the current global fee bps and treasury address onto the escrow at creation time. Laterset_fee_bps/set_treasurycalls only affect escrows created afterward — an escrow's fee terms never change mid-flight. - Cumulative fee-delta rounding: each tranche's fee is charged as
cumulative_fee(released_after) - cumulative_fee(released_before), wherecumulative_fee(x) = floor(x * fee_bps / 10_000)is computed with checked, overflow-safe quotient/remainder arithmetic. This guarantees splitting one release into many tranches never changes the total fee collected, and every tranche satisfiesgross_amount = beneficiary_payout + treasury_feeexactly. - Atomic two-recipient settlement: cumulative-release accounting is validated and persisted before any token transfer; the beneficiary payout and treasury fee are then both transferred in the same invocation, and a zero-valued fee is simply skipped. If either transfer fails, Soroban rolls back the entire call, so books can never end up mismatched. A milestone's
approvedflag is set on every authorized release, and the escrow is markedSettledonly once its full funded amount has been released.resolve_disputetransfers only the amount still locked, using checked subtraction (unaffected when no partial release occurred). - Event: each release emits
MilestoneTrancheReleased, withescrow_id/milestone_indexcarried as indexed topics (not duplicated in the event data) so indexers can filter without decoding every event. - No new dependencies: the feature is implemented entirely with the existing
soroban-sdkprimitives already used elsewhere in the contract (persistent storage, checkedi128arithmetic, events) — no new crates were added.
- Overflow checks enabled in all release builds.
- LTO and symbol stripping applied for minimal attack surface.
- All contract errors are explicitly typed via
errors.rs. - Events emitted for every state transition — fully auditable on-chain.
- Multi-sig Escrow: Corporate escrow requiring M-of-N approvals.
- Reputation Oracle: On-chain reputation scores anchored to work history.
- DAO Treasury: Protocol fee accumulation and community-governed spending.
- Formal Verification: TLA+ spec for core escrow state machine.
- Documentation: Full Protocol Docs
- Issues: Report bugs or request features
- Discussions: Stellar Community Forum
Securing the future of work, one transaction at a time.
MIT License. Copyright (c) 2026 TrustFlow Protocol.