SPHINX Docs

AI-recommended, self-executed liquidity routing for Robinhood Chain Stock Tokens. Chain ID 4663.

Architecture

SPHINX separates recommendation from execution. Three signers, three roles. The agent's key is isolated — it can only call publishRecommendation, a pure event-emitting function with zero fund movement.

Off-Chain Agent
Polls venues
Compares vs Chainlink
Publishes recommendation
SPHINX.sol
Registers venues
Enforces guardrails
Emits events
User Wallet
Reads recommendation
Sets slippage floor
Calls executeSwap

Contracts

SPHINX.sol

The core router. Registers venue adapters, compares live quotes, publishes agent-gated recommendations, and executes user-authorized swaps under on-chain guardrails.

FunctionCallerDescription
registerVenue(address)ownerAdd a venue adapter to the router's registry
bestVenue(tokenIn, tokenOut, amountIn)anyone (view)Compare live quotes across all active venues for a pair
publishRecommendation(...)agent onlyEmit Recommendation event — no custody, no execution
executeSwap(venueId, tokenIn, tokenOut, amountIn, minAmountOut)anyoneExecute swap with full guardrail checks
setPairGuardrails(tokenIn, tokenOut, maxSize, slippageBps, refDeviationBps)ownerConfigure per-pair safety parameters
setReferenceFeed(tokenIn, tokenOut, feed)ownerWire a Chainlink price feed for a pair
revokeAgent()ownerDisable the agent's ability to publish
removeVenue(index)ownerRemove a venue and compact the array

UniswapV2Adapter.sol

Wraps any Uniswap V2-style DEX router into the IVenueAdapter shape. Implements quote() via getAmountsOut and swap() via swapExactTokensForTokens. Use as a template for wrapping Arcus, RFQ desks, or any other venue.

Guardrails

Every protection sits on-chain, per trading pair, enforced by the router — not by trusting the frontend.

GuardrailMechanismProtects against
Slippage floorminAmountOut too loose → rejected on-chainSandwich attacks, frontend bugs
Oracle deviationQuote vs Chainlink ≤ thresholdManipulated venue quotes
Order size capsPer-pair maxOrderSizeLiquidity crushing, whale exploits
Agent key isolationAgent signer ≠ executor signerCompromised agent moving funds
Reference stalenessChainlink updatedAt checkStale oracle data

Deploy

Deploy to Robinhood Chain mainnet (chain ID 4663). Requires DEPLOYER_PRIVATE_KEY and the agent's address as constructor argument.

forge create contracts/SPHINX.sol:SPHINX \
  --rpc-url https://rpc.mainnet.chain.robinhood.com \
  --private-key $DEPLOYER_PRIVATE_KEY \
  --constructor-args $AGENT_ADDRESS \
  --broadcast

Verify on Blockscout →

Off-Chain Agent

The agent lives in agent/. It polls bestVenue() across configured pairs on a schedule, compares results against a live Chainlink reference price, and calls publishRecommendation with a human-readable reason string. Its private key is separate from any execution-capable key.

cd agent
cp .env.example .env
# Set AGENT_PRIVATE_KEY, RPC_URL, ROUTER_ADDRESS
node src/index.js