Documentation

On-chain OTC for tokenized US stocks.

A trader asks for a quote. Several market makers answer with signed, firm prices. The trader picks one and it settles on Robinhood Chain in a single transaction. Large size gets a competing price instead of moving a pool.

Two products. Spot swaps a tokenized stock for USDG atomically. Forwards fix a price for a future official market close and settle in cash (USDG) with margin on both sides.

Testnet only. Everything below runs on Robinhood Chain testnet (46630) with mock tokens and simulated market makers. Contracts are unaudited. Do not use them with real funds.

01How a trade works

  1. The trader sends a request to the relay: ticker, side, size. For a forward, also a maturity date.
  2. The relay checks the request, fixes a reference price, and sends it to every connected maker over WebSocket.
  3. Each maker replies within the deadline with an EIP-712 signed quote. The relay verifies the signature, the fee, the price band against the reference, the size and the expiry, then simulates the fill on chain.
  4. The app shows the valid quotes, best first. Rejected quotes are counted, with a reason kept in the maker's history.
  5. The trader submits the chosen quote. Spot: fillQuote swaps both legs. Forward: openForward locks margin from both sides.
  6. A forward settles at the official close on its maturity date. Anyone can call settle. Before that, a side that falls below required margin can be flagged, then liquidated after the window.

The relay never holds funds and cannot move them. It only routes quotes. If it goes down, a signed quote that is still valid can still be submitted to the contract directly.

02Contracts

Network: Robinhood Chain testnet, chain id 46630. Deployer and owner: 0x9178B573219C55586BbAf51Ecb24ACfb27BB7681. Source is verified on the explorer for every contract below, including the 36 TestnetFeed price mocks.

ColdHarborSettlement

0x188C42CB8B6FE9ED8CB654d5e5d10c913b31A25b

Spot RFQ settlement. Verifies the maker's EIP-712 quote and swaps both legs atomically in one transaction. Fee is paid by the taker and must equal the on-chain rate.

Functions
fillQuote(quote, makerSig), cancelNonce(bucket, nonce), registerSigner(signer, allowed), hashQuote, isNonceUsed. Owner: setTokenAllowed, setFeeRecipient, setFeeBps, pause, unpause.
Events
QuoteFilled, NonceCancelled, SignerRegistered, TokenAllowedSet, FeeRecipientSet, FeeBpsSet
Errors
QuoteExpired, NotTaker, NonceAlreadyUsed, InvalidSignature, TokenNotAllowed, NotUsdgPair, ZeroAmount, SameParty, FeeMismatch, FeeTooHigh

ForwardEngine

0xAa0962c6585FFbD83A6F0AF74E648985355B34d8

Cash-settled forwards on a tokenized stock, settled in USDG at an official market close. No share delivery.

Functions
openForward(quote, makerSig), topUp(id, amount), flagMarginCall(id), liquidate(id), settle(id), closeByMutual(id, price, makerSig, takerSig), getPosition, markToMarket, requiredMargin. Owner: setUnderlying, setParams, pause, unpause.
Events
ForwardOpened, MarginToppedUp, MarginCall, MarginCallCleared, ForwardLiquidated, ForwardSettled, ForwardClosed, ObservationDeferred, UnderlyingSet
Errors
UnderlyingNotActive, InvalidTerms, FeeMismatch, NotOfficialClose, TenorOutOfRange, NotionalOutOfRange, NotLiquidatable, NoMarginCall, TopUpWindowOpen, PriceNotLive, OraclePausedByToken

MarginVault

0x6c488Ea047C95632595e57934B5E5d0155E1478F

Holds USDG margin. Only the engine can lock, unlock, seize or charge. Owners withdraw only what is not locked. The engine address is set once.

Functions
deposit(amount), withdraw(amount), freeMargin(account). Engine only: lock, unlock, seize, charge. Owner: setEngine (once).
Events
Deposited, Withdrawn, Locked, Unlocked, Seized, EngineSet
Errors
NotEngine, EngineAlreadySet, InsufficientFree, InsufficientLocked, ZeroAmount

OracleAdapter

0x5258F62ea758AAd29cF7a2E88BC124381E9cd475

Pins the price at an official close. Primary feed first, backup feed if the primary is stale. A pinned price cannot be changed.

Functions
observe(feed, closeTs), referencePrice(feed), pinned(feed, closeTs). Owner: setBackupFeed, setParams.
Events
ObservationPinned, BackupFeedSet, ParamsSet
Errors
TooEarly, BadParam

MarketCalendar

0xd19ba08943BF4A308D9305a3eFCB2ae8A1c91248

US equity close times in UTC with daylight saving, plus owner-set holidays and early closes. Forwards can only mature on a business day.

Functions
isBusinessDay, closeOf, nextClose, lastCloseAtOrBefore, isOfficialClose, isDst. Owner: setHoliday, setEarlyClose.
Events
HolidaySet, EarlyCloseSet
Errors
NoCloseFound, InvalidEarlyClose

Other testnet addresses: USDG mock 0x3aafFfdfa4CDBbF915351C0d35699c1c61B743B6, 36 mock stock tokens and 36 test price feeds. The full list is in contracts/deployments/rh-testnet.json and rh-testnet-forwards.json.

03Design decisions

The forward decisions need sign-off before mainnet. Each one trades simplicity for a stated risk.

Feed comes from owner configThe maker cannot choose the price source in a quote. The engine reads the feed registered for that token.
Loss capped at the losing side's marginNo insurance fund. A party can lose at most what it posted. The counterparty bears the rest of the gap risk.
Margin call window is 4 ordinary hoursAfter a flag, the party has 4 hours to top up before liquidation is allowed.
Liquidation penalty 2%90% goes to the counterparty, 10% to the protocol. Opening fee is 20 bps.
Pyth backup is not wrapped yetTestnet uses TestnetFeed. Mainnet plan is Chainlink primary, Pyth backup.
Dividends are not adjustedA forward on a dividend-paying stock does not pay or adjust for the dividend.
Not upgradeableContracts have no proxy. A fix means a new deployment. OpenZeppelin v5.1.0, solc 0.8.28.
Taker pays the spot feeThe relay forces the quote fee to equal the on-chain fee, or the quote is rejected.

04Parameters

Defaults carry an assumption flag until confirmed against the brief.

Margin20% initial, 10% for ETFs (EWY, USO are placed in the ETF group, to be confirmed).
Tenor7 to 92 days, on an official close.
Notional10,000 to 1,000,000 USDG per forward.
KeepersNone required. Anyone can call flag, liquidate and settle.

05Run it

Contracts, Foundry:

cd contracts
forge build
forge test          # 135 tests
forge coverage      # about 94% of lines

Relay, Node and Postgres. Set DATABASE_URL in relay/.env first:

cd relay
pnpm install
pnpm migrate
pnpm start          # http and websocket on :8080
pnpm sim:setup      # once: registers 4 simulated makers
pnpm sim:maker      # simulated makers answer RFQs

Web:

cd web
pnpm install
cp .env.example .env.local     # set NEXT_PUBLIC_RELAY_URL
pnpm dev -p 3005

Deploy: web on Vercel, relay and indexer on Railway (root relay, start pnpm start, health /health), Postgres on Neon. The web app never touches the database.

06Relay API

GET /healthRelay, database, chain and indexer status. Includes how many makers are connected.
POST /rfqBody: product (spot or forward), ticker, side, amount, taker, and for forwards the maturity date. Returns every valid signed quote, best first, plus a count of rejected ones.
GET /fills/:walletSpot fills for a wallet, read from the indexer.
GET /forwards/:walletForward positions and their outcomes for a wallet.
GET /rfqs/:walletRFQ history for a wallet.
WS /mm/wsMaker socket. Header X-API-Key. Relay sends rfq.request, maker replies quote.submit, relay answers quote.ack.
POST /mm/nonce, /mm/loginWallet sign-in for the maker portal. One signed message, no transaction.
GET /mm/me, /mm/quotesMaker profile, connection status, limits and recent quotes.
POST /mm/key, PUT /mm/limits, DELETE /mm/limits/:tickerCreate or replace the API key, set or remove per ticker limits.

Makers: sign in at /mm, create an API key, set limits. A quote above a limit is rejected before a taker sees it.

07Proof transactions

Mock tokens, simulated makers. Collected from the broadcast file and QuoteFilled logs. Every hash links to the testnet explorer.

Spot fills (3)

Real fillQuote calls: NVDA bought and sold against simulated makers.

Forward lifecycle: open and mutual close (2 transactions)

First real forward fully opened and closed on this testnet, used to verify the maker portal, relay quoting and the mutual-close handshake end to end. Taker is the agent's throwaway test wallet; maker is Sim Maker A.

Spot stack deployment (78 transactions)

All 78 deployment transactions

Forward stack (77 transactions)

MarketCalendar 1, OracleAdapter 1, MarginVault 2, ForwardEngine 37, TestnetFeed 36. Deploy and wiring succeeded on all 77. The price feeds were seeded with reference prices, and four simulated makers received 1,000,000 USDG of margin each.

All forward deployment transactions
36 feed seed transactions
Simulated maker margin setup

Not yet proven on chain: topping up margin, flagging a margin call, liquidating, and a settle at an official close. Opening a forward and an early mutual close are proven above. All of it needs a wallet holding testnet tokens; this section is updated as each run is done.

08Status and risks

  • No external audit. Internal tests: 135 passing, about 94% line coverage. Slither static analysis run: no High or Medium findings; the Low/informational results (timestamp comparisons, naming convention, missing interface inheritance) are reviewed in contracts/slither-report.txt.
  • Source is verified on the explorer for all 5 live contracts plus the 36 TestnetFeed mocks.
  • Tested with a read-only wallet shim and local keys. Not yet tested with MetaMask or Rabby, or with transaction buttons end to end.
  • Testnet uses mock tokens, a test price feed and simulated makers. The real Robinhood stock tokens and their decimals are not confirmed.
  • The indexer has no reorg handling. Add a confirmation depth before mainnet.
  • Maker sessions live in relay memory. A relay restart means signing in again. One relay instance only.
  • Mainnet needs Chainlink and Pyth wiring, a final fee and margin review, and an audit.