ZaphWork's escrow protocol is designed as infrastructure, not application-specific backend. This document explains the split-based settlement architecture and design principles.
The protocol makes no assumptions about "freelancer" or "client" roles. It simply handles:
Business rules (fees, splits) are provided by the caller, not hardcoded in the program. This makes the protocol reusable for any use case.
Other programs and platforms can integrate without modification. The protocol is a primitive that can be composed with other Solana programs.
Version field allows handling both old and new escrows. Existing integrations continue to work.
Client → create_escrow(amount, EscrowType::Task)
→ Program calculates: worker=90%, platform=10%
→ Hardcoded in programClient → create_escrow(amount, splits=[{worker, 9000}, {platform, 1000}])
→ Program validates: sum(bps) == 10000
→ Generic, reusableThe core data structure is the Split:
pub struct Split {
pub recipient: Pubkey, // Who receives this portion
pub bps: u16, // Basis points (0-10000)
}bps must equal 10,000 (100%)Caller provides splits and total amount. Program validates splits and creates escrow account.
Payer transfers tokens into the escrow vault. Vault is a PDA controlled by the program.
For workflows requiring approval, the payer or admin can approve the escrow for settlement.
Program calculates amounts for each split and transfers from vault to recipients atomically. Remaining accounts must be provided for all recipients.
All critical accounts (escrow, vault) are PDAs derived from seeds. This prevents account confusion and ensures only the program can control funds.
The program verifies no duplicate accounts in remaining accounts to prevent double-spending.
All arithmetic uses checked operations. Calculations use u128 intermediate values to prevent overflow.
Mathematical invariants are proven across random inputs:
splits = [
{ recipient: freelancer, bps: 9000 }, // 90%
{ recipient: platform, bps: 1000 }, // 10%
]splits = [
{ recipient: contributor, bps: 9000 }, // 90%
{ recipient: platform, bps: 700 }, // 7%
{ recipient: referrer, bps: 300 }, // 3%
]splits = [
{ recipient: team_lead, bps: 4000 }, // 40%
{ recipient: developer1, bps: 3000 }, // 30%
{ recipient: developer2, bps: 2000 }, // 20%
{ recipient: dao_treasury, bps: 1000 },// 10%
]Call the program directly from your Solana program using CPI (Cross-Program Invocation).
Use the provided TypeScript SDK for easy integration from web applications.
For backward compatibility, use the V2 adapter that maintains V1 API while using V2 splits internally.
Potential future features (not yet implemented):