NightshadeDocs

Start

How Nightshade works

The contracts, the proofs your device makes, and what the site reads.

Nightshade is a few contracts on Midnight, a website that reads them, and your wallet, which proves and sends every change. One small Nightshade service helps: it sends batches for busy markets, runs the Dark Pool and hosts chat.

The contracts

ContractWhat it holds
Order bookEvery public market, pool of liquidity, queued swap, stop and trade, and the tokens in them. This is the Public Book.
ShieldThe public tokens behind every private twin (sNIGHT, sSHADE and the rest), and the Private Book, which runs the same book engine over twins.
SaleThe SHADE sale's tokens until each buyer's share is paid out. NIGHT paid in waits in an escrow script on Cardano until the close.

Tokens you put into an order, a pool or the Shield are held by its contract until they fill or you take them back. The contract's rules decide where they can go, and nobody can move them otherwise, Nightshade included. Contracts and security lists what each admin key can and can't do.

Pools, not single orders

The book is made of pools. Every price sits on a grid of four significant digits (1.234, 0.05678, 12,340), and everyone who wants the same thing at the same price shares one pool: plain pools that sell or buy at one price, and auto-flip pools that sell at one price and buy back a fixed step lower. A trade takes the best pools one at a time, so a price with a thousand makers costs a trade the same as a price with one.

Your wallet proves every change

Midnight checks transactions with zero-knowledge proofs. When you trade, your wallet runs the contract's rules on your device, proves it followed them, and sends the proof. Midnight checks the proof and applies the change. That's why sending takes longer than on most chains: a few seconds with a proof server, one to four minutes in the browser.

The proof is also what makes private trading possible. A private token is a coin only your wallet can see, and your wallet proves it owns one without showing which.

Fees are paid in DUST, not in the tokens you trade (DUST).

The site reads the chain

The website has no database for trading. It reads each contract's public state from Midnight's indexer every few seconds and works out the book, charts and your positions in the page. If the indexer falls behind, the figures fall behind with it.

Two things use a server: chat, which needs a signed message to post, and the Dark Pool, whose orders wait off chain until they're filled.

Why a trade can be refused, and the queue

A transaction is proved against the contract as it was when your wallet read it. If something it read changes before it reaches a block, Midnight refuses it. Nothing moves, and the DUST fee may still be charged.

On a busy market that happens to two buys (or two sells) at once, since both want the same best pool. Nightshade keeps it from costing you: a swap that loses that race waits in the market's queue, and a batch fills everything waiting on that side in one trade, at one price. Open Nightshade tabs and Nightshade's keeper send those batches. See The queue and batches.

Each market keeps its own state, and each side of it too, so a buy never clashes with a sell, and markets never slow each other down.