-
-
Tributary Overview & Hero: Indie game collaborator conflict scenario and Tributary's core executable revenue-share architecture.
-
Deal Studio (Contract Compilation): Gemini 2.5 Flash extracting structured agreement AST and surfacing 3 interactive ambiguity chips.
-
Waterfall Simulator: Real-time integer-cent slider with 100/100 fast-check mathematical property conservation proof.
-
Live Settlement Ledger: PayPal Orders v2 capture ($100), $3.98 fee, and verified 4-way Batch Payouts ($52.57 / $16.93 / $11.28 / $5.64).
-
Refund Clawback Engine: $50 refund draining the $9.60 rolling reserve & allocating pro-rata recovery deficits(-$16.16/-$12.12/-$8.08/-$4.04)
-
Payee Statements: Itemized collaborator balances and AI statement generation verified against the integer engine trace allowlist.
-
8-Test Chaos Suite: In-process failure injection verifying webhook deduplication, signature rejection, and audit integrity.
-
System Architecture: Clean separation between the untrusted AI compiler plane and the deterministic monetary execution plane.
Inspiration
Revenue-share agreements power the modern creator, freelance, indie game, and startup economies. Whether it is an indie dev team splitting game sales, a podcast network dividing sponsorship revenue, creators launching courses with marketing partners, or developers collaborating on client projects, revenue-sharing aligns incentives without requiring upfront capital.
Yet in practice, revenue-sharing is fragile and error-prone:
- The Spreadsheet Trap: Payout calculations are typically done manually in spreadsheets weeks or months after sales occur. Collaborators have little visibility into how deductions or fees were calculated.
- The Recoup & Tier Straddle Dilemma: Deals frequently involve recoupment (e.g. Maya fronting $400 for art) followed by tiered revenue splits (e.g. 40/30/20/10 until $2,000 net, then 25/25/25/25). Single transactions that straddle boundary thresholds almost always cause spreadsheet calculation errors.
- The Post-Payout Refund Crisis: What happens when a customer requests a $50 refund after payouts have already cleared into collaborator accounts? In traditional setups, the merchant absorbs the loss or attempts awkward manual clawbacks.
- The LLM Math Risk: While Large Language Models excel at understanding contract legalese, LLMs cannot perform exact financial arithmetic. Floating-point roundoffs and hallucinated numbers in financial transactions break trust and violate accounting integrity.
I built Tributary to solve this with a neuro-symbolic architecture: an LLM parses natural-language agreements and interrogates ambiguous clauses; but a pure, deterministic integer-cent engine handles 100% of the financial math, backed by SQLite 3-layer idempotency, PayPal Orders v2, and PayPal Payouts v1.
What It Does
Tributary is a complete revenue settlement platform organized across four cohesive screens:
- Deal Studio (Contract Compilation & Ambiguity Interrogation): Users paste any plain-English agreement. Google Gemini 2.5 Flash extracts payees, basis points, recoupment terms, and reserve holdbacks into a strictly validated
DealSpecschema. Crucially, Tributary flags latent contract ambiguities (such as whether recoupment occurs before or after PayPal processing fees) and requires human signatories to resolve them interactively before locking the terms with an immutable SHA-256 deal hash. - Waterfall Simulator (Property-Based Prover): An interactive FinOps sandbox featuring an integer-cent volume slider and recoupment tracker. It runs 100 randomized property tests via
fast-checkto prove that not a single cent is created or lost across arbitrary sales volumes ($1 to $50,000). - Live Settlement Ledger (Orders v2 + Payouts v1): Captures customer checkouts via PayPal Orders v2, ingests exact merchant processing fees (
sellerReceivableBreakdown.paypalFee), and dispatches multi-party batch payouts via PayPal Payouts v1 directly to collaborator personal sandbox accounts. When a customer refund occurs post-payout, Tributary's Refund Clawback Engine drains rolling reserves first, records any remaining deficit pro-rata, and automatically nets it out against each payee's future sales. - Payee Statements & Allowlist Verifier: Individual collaborator dashboards detailing Total Earned, Total Paid via PayPal, Carried Forward Balance, and Recovery Deficits. Gemini drafts natural-language statement explanations, while a Strict Allowlist Number Verifier extracts every currency token via regex and validates it against the deterministic engine trace allowlist. Any number not present in the engine trace is intercepted and rejected.
- 8-Test Chaos Drawer: Slide-over failure injection harness testing duplicate webhooks, tampered signatures, out-of-order refunds, batch replays, unclaimed timeouts, concurrent double-clicks, and deliberate 1-cent invariant tampering—all simulated locally in-process with continuous audit continuity.
How I Built It
Tributary was built around 5 Core Invariants:
1. Modular Boundary: AI Plane Never Touches Money
The ai-compiler module is strictly separated from financial execution. It never imports from paypal-gateway, never accesses PayPal credentials, and never performs monetary arithmetic. It is strictly limited to extracting structured contract schemas and explaining verified ledger traces.
2. Pure Integer-Cent Financial Core
Zero floating-point arithmetic. All monetary strings are converted into exact integer cents ("100.02" $\rightarrow$ 10002). Every settlement enforces the hard conservation invariant:
$$\text{feeCents} + \text{reserveCents} + \sum \text{payoutCents} + \sum \text{carriedForwardCents} + \text{withheldRecoveryCents} \equiv \text{grossCents}$$
If this equation fails by even a single cent, the engine halts immediately with an InvariantViolationError and logs a halt event in the audit chain.
3. 3-Layer Idempotency Architecture
- Transport Layer: Deterministic
PayPal-Request-Idheaders generated for all capture and refund calls. - Database Mutex: Deterministic
sender_batch_id = "trib_" + SHA256(saleId + ":" + dealHash)enforced by SQLiteUNIQUE PRIMARY KEYconstraints before network dispatch. - Webhook Deduplication: Dedicated
webhook_eventstable withevent_id PRIMARY KEYdeduplication prior to processing.
4. Technical Stack
- Backend: Node.js 22 (ESM), TypeScript 5.7, Hono, SQLite with
better-sqlite3. - PayPal Integration:
@paypal/paypal-server-sdkv2.5.0 for Orders v2 & Captures/Refunds v2; typed REST client for Payouts v1 and Webhook Signature Verification. - AI Compiler: Google Gemini 2.5 Flash (
temperature: 0, strict JSON mode) with an SHA-256 Record/Replay cache (fixtures/replay-cache.json) for zero-key offline reproducibility. - Frontend: React 18, Vite 6, Tailwind CSS 3.4, Lucide Icons, formatted with tabular numerals (
.tabular-nums). - Testing: Vitest (49 unit, integration, and chaos tests),
fast-check(2,000 property-based testing runs).
Challenges I Faced
- APIMatic SDK v2.5.0 Method Migration: During Day-1 sandbox smoke tests, I noticed legacy methods (
ordersCreate,ordersCapture) had evolved into controller-scoped methods (ordersController.createOrder,ordersController.captureOrder). I mapped these into typed wrappers and documented the signatures inAPIMATIC_DEVLOG.md. - Defensive Fee Extraction: PayPal captures return
seller_receivable_breakdownin snake_case over REST, whereas the APIMatic SDK exposes camelCasesellerReceivableBreakdown. I implemented defensive extraction to safely convert string fees into integer cents without float loss. - Canonical JSON Serialization for Audit Continuity: In SQLite audit logging, JavaScript objects with undefined fields can cause hash discrepancies when re-serialized. I wrote a lexicographically sorted
canonicalJson()serializer to guarantee consistent SHA-256 hash chaining. - Net Revenue Tier Straddling: When a single transaction crosses a boundary threshold, Tributary dynamically divides the sale into pre-tier and post-tier pools, applies distinct basis-point splits, and awards remaining cents using the Largest-Remainder (Hamilton) method.
What I Learned & What's Next
- Neuro-Symbolic Design is Essential in FinTech: Generative AI should interpret human intent, while deterministic state machines handle the math. This separation provides the natural-language flexibility of LLMs alongside the exactness of double-entry bookkeeping.
- Next Steps: Multi-currency FX conversion for global teams, automated 1099 tax exports directly from the audit log, and recurring subscription stream-splitting via PayPal Subscriptions.
Built With
- apimatic
- better-sqlite3
- fast-check
- gemini-2.5-flash
- google-genai
- hono
- node.js
- paypal
- paypal-server-sdk
- react
- render
- sqlite
- tailwindcss
- typescript
- vite
- vitest
Log in or sign up for Devpost to join the conversation.