Skip to content

OTC Bridge: Peer-to-peer RTC trading with RIP-302 escrow (Bounty #695)#1459

Merged
Scottcjn merged 1 commit intoScottcjn:mainfrom
mtarcure:feat/otc-bridge-695
Mar 17, 2026
Merged

OTC Bridge: Peer-to-peer RTC trading with RIP-302 escrow (Bounty #695)#1459
Scottcjn merged 1 commit intoScottcjn:mainfrom
mtarcure:feat/otc-bridge-695

Conversation

@mtarcure
Copy link
Contributor

Bounty Claim: #695 — Tier 2 (150 RTC)

Full Tier 2 OTC Bridge implementation with RIP-302 escrow and HTLC smart contract.

Deliverables

Backend (otc_bridge.py — Flask, 9 API endpoints):

  • POST /api/orders — Create buy/sell order (sell orders auto-lock RTC in escrow)
  • GET /api/orders — List open orders with pair/side filters
  • GET /api/orderbook — Aggregated bids/asks with spread calculation
  • POST /api/orders/{id}/match — Match an order (counterparty)
  • POST /api/orders/{id}/confirm — Confirm settlement (reveals HTLC secret, releases escrow)
  • POST /api/orders/{id}/cancel — Cancel with escrow refund
  • GET /api/trades — Trade history with audit trail
  • GET /api/stats — Market stats (volume, open orders, prices)
  • SQLite persistence (shared order book — fixes the localStorage gap from Tier 1)
  • Rate limiting (10 req/min per IP), self-match prevention, auto-expiry

Frontend (static/index.html — single-file SPA):

  • Dark theme matching RustChain branding (#0d1117 bg, #f39c12 gold accents)
  • Live order book with depth bars, spread display
  • Buy/sell order form with escrow cost preview
  • Match modal for counterparty matching
  • Trade history table
  • Wallet balance check against live node
  • 15-second auto-refresh

HTLC Smart Contract (contracts/HTLC.sol):

  • Hash Time-Locked Contract for ETH/USDC side on Base
  • Supports both native ETH and ERC20 (USDC) swaps
  • createSwapETH() / createSwapERC20() — Lock funds with hashlock + timelock
  • claim() — Seller reveals preimage to claim
  • refund() — Buyer reclaims after timeout
  • OpenZeppelin ReentrancyGuard + SafeERC20
  • Cross-referenced with OTC Bridge order IDs

Settlement Flow:

Seller posts sell order → RTC locked in RIP-302 escrow
Buyer matches → locks ETH/USDC in HTLC (hashlock = seller's hash)
Seller confirms → HTLC secret revealed, RTC escrow releases to buyer
Buyer claims ETH/USDC from HTLC using revealed secret

Tests: 23 unit tests, all passing — covers order CRUD, escrow locking/refund, matching, settlement, rate limiting, auth checks.

Docker: Production-ready with gunicorn.

Tier 2 Checklist

  • Everything in Tier 1 (order book, create/list/match orders, hosted)
  • RTC side uses RIP-302 escrow (/agent/jobs with escrow lock)
  • ETH/USDC side has HTLC escrow (Solidity smart contract)
  • Near-atomic settlement (HTLC secret reveal links both sides)
  • Transaction history / audit trail
  • Rate limiting and abuse prevention

Supported Pairs

RTC/USDC, RTC/ETH, RTC/ERG

Wallet: wirework

Peer-to-peer RTC trading with on-chain escrow via RIP-302 Agent Economy
and HTLC smart contract for ETH/USDC side on Base.

- Flask backend with 9 API endpoints (order book, matching, settlement)
- Dark-themed SPA frontend with depth visualization and auto-refresh
- RTC sell orders auto-lock in RIP-302 escrow
- Solidity HTLC for cross-chain atomic settlement (ETH + ERC20)
- SQLite persistence (shared order book between users)
- Rate limiting, self-match prevention, order expiry with auto-refund
- 23 unit tests, all passing
- Docker support for production deployment

Supported pairs: RTC/USDC, RTC/ETH, RTC/ERG

Wallet: wirework
@github-actions github-actions bot added documentation Improvements or additions to documentation BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) size/XL PR: 500+ lines labels Mar 17, 2026
@Scottcjn Scottcjn merged commit 90f2c22 into Scottcjn:main Mar 17, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) documentation Improvements or additions to documentation size/XL PR: 500+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants