NeapDocs
Launch app
Docs · Architecture

Protocol

Architecture

One contract holds all value and all rules. Everything off-chain is replaceable.

Components

ComponentWhat it doesHolds funds
ContractOne NEAR contract: custody, markets, oracle checks, orders, the risk engine, pools, fees and liquidations.Yes
Risk enginePercolator, compiled into the contract. Margin, profit and loss, funding, liquidation and insurance maths. Integer arithmetic only.Part of the contract
KeeperRefreshes prices, activates new markets, executes pending orders, triggers TP / SL, liquidates. Every call is permissionless and re-checked by the contract.No
Indexer and APIReads contract events into Postgres and serves REST and WebSocket data for the app. Display only, rebuildable from chain.No
Web appNext.js on Cloudflare Workers. Builds transactions for your wallet to sign. Never holds keys.No

Order flow

wallet ── request_order ──▶ contract  (order stored, block recorded)
keeper ── refresh_price ──▶ contract ──▶ DEX pool ──▶ observation stored
keeper ── execute_order ──▶ contract  (checks price is newer, fills vs pool)
contract ── events ──▶ indexer ──▶ REST / WebSocket ──▶ app

Design rules

  • The chain is the only state. There is no off-chain matching, so the app and the chain cannot disagree about a fill.
  • Every change to balances completes inside one transaction receipt. Calls to other contracts only read a price or send USDC out, and a failed send is credited back.
  • USDC held by the contract is always at least the sum of every user balance, vault and unclaimed fee. This is checked after every call in tests.
  • No call touches more than one market.
  • Admin keys can pause and tighten risk. No admin method can move a user balance.

Source code

PathContents
crates/neapThe contract.
crates/engineThe Percolator risk engine and its proofs.
services/keeperKeeper.
services/indexerIndexer and API.
docsContract spec, architecture, decisions and the security review.