Skip to Content
Scalar

How Scalar works

Offchain matching, onchain settlement on Base.

Scalar is a hybrid exchange. A matching engine matches orders offchain. A contract on Base settles every matched trade onchain and holds all funds. Only a signature from the owner can move funds out of an account.

An order passes through five stages:

  1. SignYour wallet signs the order. No gas.
  2. MatchOffchain, by price then time, under 1 ms.
  3. SettleThe contract checks both signatures and locks $10.
  4. ResolveA settler reads signed Pyth prices.
  5. Pay outEach side gets its share of the $10.

Offchain: the matching engine

The matching engine runs a central limit order book. A central limit order book, or CLOB, lists every resting buy and sell order for a market by price. The engine is written in Rust.

  • Orders match by price first, then by time. The best price fills first. At one price, the oldest order fills first.
  • A fill confirms at once. You do not wait for a block.
  • An order cannot match against your own order on the other side. The engine cancels it instead.
  • Every fill goes to the contract. The engine cannot drop a trade or change it, because the contract checks your signature on the exact order you signed.

Placing and canceling orders costs no gas. Market makers can quote and cancel as fast as the network allows, over REST or WebSocket. See Build on Scalar.

Onchain: the Scalar contract

One contract on Base holds every balance and every position. It is the Scalar protocol contract. A Scalar executor posts each matched pair to it, in order. For each trade, the contract:

  1. Checks the signatures of the buyer and the seller against the orders they signed.
  2. Checks that the prices cross, that the market is live and that the fees are under the cap.
  3. Takes the price from the buyer and $10 minus the price from the seller, so the contract holds $10 per contract.
  4. Records the new positions, and nets them against any opposite position you already hold.

The contract counts every action that the executor posts and tracks how much of each order has filled. An order can never fill for more than its size, and the same withdrawal can never be paid twice.

Onchain: resolution

At the end of a cycle, a settler contract decides the settlement value. Anyone can submit the Pyth prices that the settler needs. Scalar runs a service that submits them for every market, but it has no special right to do so. A wrong price cannot be submitted, because the contract checks each Pyth signature. Settlers explains the full process.

What Scalar can and cannot do

Scalar is non-custodial. Non-custodial means that Scalar never holds your funds or your keys.

Scalar cannotBecause
Trade for youEvery trade needs an order that you signed.
Move or withdraw your USDCA withdrawal needs your signature. The admin cannot take user funds.
Lock you inIf Scalar stops, you can withdraw onchain by yourself. See Deposits and withdrawals.
Change a price-based resultA settler reads signed Pyth prices. The best proof wins the challenge window.

Scalar runs the services that make the exchange fast: the matching engine, the executor that posts trades, and the services that submit proofs and pay out positions. An operator can resolve a market by hand in two cases: an event market that has no settler, and a price market that nobody proved by the end of its challenge window. The admin sets the fee rates and lists new products.

Built on Base, powered by Pyth

PartRole
BaseThe Ethereum layer 2 network where the Scalar contract, the settlers and your USDC live.
Pyth LazerSigned, low-latency prices for every asset. The contract checks each signature onchain.
USDCThe only collateral. Every price, balance and payout is in USDC.

The addresses of every contract are on Contract addresses.

On this page