NightshadeDocs

Trade

The queue and batches

How a busy market fills swaps in batches, and who sends them.

On Midnight, a transaction that read something which changed before its block is refused. On a busy market that would mean most swaps fail. So Nightshade lets swaps wait in a queue, and fills the queue in batches.

Queued swaps

A queued swap holds what you pay in the contract, with your quote as its limit price. Joining the queue only writes your own entry, so any number of swaps can join in one block without clashing.

Your orders shows your queued swaps until they fill, with Cancel, which returns what's left in full.

Batches

A batch fills the oldest waiting swaps on one side of a market in one trade:

  • One price. Everyone in the batch trades at the batch's average price, which is never worse than any of their limits. The batch's limit is its strictest swap's.
  • Fair shares. Each swap's part of the trade is its share of what the batch holds, and its part of the proceeds is its share of that, checked by the contract to the smallest unit.
  • Its own fee. Each swap pays the 0.2% taker fee on its own part.
  • Up to 64 swaps in one batch. A swap the batch fills only partly stays queued for the next one. One left below the market's minimum is refunded.

Due stop orders wait in the same queue and fill in the same batches.

Who sends batches

Anyone can, and nobody is paid to. Nightshade arranges two:

  • Open tabs. A Nightshade tab with a passkey or in-browser wallet sends a small batch (up to 4) once a swap has waited 30 seconds, after a short random wait so many tabs don't all try at once. It pays a little DUST. Turn it off with Help fill queued orders in Settings. Lace and 1AM tabs never do it, since each one would need your approval.
  • Nightshade's keeper. Every minute it checks every market, and sends batches of up to 16 for anything that has waited 90 seconds, so a queue clears even when nobody has the site open.

You can also send one yourself: a swap or due stop that the book can fill shows Fill now in Your orders, and you pay the transaction.

The keeper is a convenience, not a promise. If it's down, a queue waits for the next tab or person to send a batch.

What the sender chooses

The contract checks every share, fee and limit, so whoever sends a batch can't change anyone's price or split. The only things they choose are which waiting swaps go in, and how many. Nightshade's tabs and keeper always take the oldest first.

What it means for you

On a quiet market, a swap fills at once. On a busy one, it may fill 30 to 90 seconds later, at the batch's price, and a big swap may fill over more than one batch. A batch that loses its own race to land is refused like any transaction, and the sender's DUST pays for it.