TradeGuard
Human-reviewed AI trade agreement extraction, delivery-evidence tracking and Solidity escrow prototype on Monad testnet.
Overview
TradeGuard is a full-stack trade workflow and escrow prototype keeping commercial agreements, delivery evidence and settlement allocations on one auditable trail. AI (Qwen Plus) assists solely with draft field extraction for human approval; it never holds wallet keys, decides disputes or releases funds. Important: TradeGuard is a Monad testnet prototype using valueless TGT test tokens, not an audited or production financial service.
Problem Statement
When physical deliveries fall short of contracted quantities (for example, 90 bags delivered out of 100 ordered), informal chat agreements, delivery receipts and payment releases fragment across disconnected channels, making partial-settlement arbitration slow and error-prone.
Technical Architecture
React and TypeScript frontend on Vite/Vinext backed by Cloudflare Workers, Cloudflare D1 relational storage, Cloudflare R2 evidence object storage, Singapore Qwen Plus structured extraction (with deterministic parser fallback), and OpenZeppelin Solidity escrow contracts on Monad Testnet via viem.
Human-Reviewed Extraction
Server validates Qwen Plus extracted fields and filters source quotes; buyers and suppliers review and explicitly approve terms before persistence.
Off-Chain Evidence & State (Cloudflare Worker + D1 + R2)
Stores full trade records in D1 and delivery shortage attachments in R2 while publishing only salted commitments on-chain.
Monad Testnet Solidity Escrow
Deployed TGT token (0xfcc8...5f3b) and Escrow contract (0x27ba...f83a) on Chain ID 10143 enforcing buyer, supplier and arbitrator wallet signatures via viem.
Technology Stack
Application & Architecture Captures
Key Engineering Decisions & Challenges
Engineering Decisions
- Strictly separated AI assistance from financial authority: AI drafts structured fields with source quotes, while humans and role-specific wallet signatures control every state transition and withdrawal.
- Kept sensitive trade documents and evidence blobs off-chain in R2, writing only salted cryptographic commitments to Monad testnet.
- Built dual workspaces (a persisted local/sandbox rehearsal mode and a three-wallet Monad testnet contract mode), plus a deterministic parser fallback when Qwen is disabled.
Implementation Challenges
- Preventing stale state transitions across concurrent buyer/supplier approvals and enforcing cross-owner workspace isolation in Worker routes.
- Designing exact proportional split accounting (e.g., 2,250 TGT to supplier and 250 TGT to buyer in the 90/100-bag shortage scenario) across both D1 sandbox records and 6-decimal Solidity token math.
Testing Strategy & Demonstrated Outcomes
Testing & Verification
- 11 passing domain state-machine and extraction validation tests (tests/domain.test.ts, tests/extraction.test.ts).
- 7 passing local EVM smart-contract tests (tests/contracts.test.mjs) verifying funding, dispute arbitration and split withdrawals.
- Persisted Worker API verification scripts checking cross-owner access denial, stale-version rejection and read-only Monad testnet contract verification (verify-testnet.mjs).
Demonstrated Outcomes
- Verified deployed contracts on Monad Testnet (Chain ID 10143) passing bytecode, token linkage and decimal checks.
- End-to-end 100/90-bag delivery shortage rehearsal verified across persisted D1/R2 APIs, TypeScript strict checks and all 7 UI navigation views.
Lessons Learned
- Explicitly documenting contract and operational limits, such as advisory post-funding deadlines if an arbitrator becomes unavailable, communicates stronger engineering rigor than overstating testnet readiness.