Solvency and queue
The pool can be temporarily insolvent. A first-in, first-out payout queue and a parked-funds side bucket make sure winners are paid eventually, in order, without blocking new trades.
The pool can be temporarily insolvent. A first-in, first-out payout queue and a parked-funds side bucket make sure winners are always paid eventually, in order, without ever blocking new trades. This is Papertrade's Martingaler accounting, adapted to tradeeverything's fees, funding and $TRADE rules.
The model
The exchange keeps three accounting buckets:
- Pool cash: the part of the exchange's USDC that is not owed to anyone else. Take all the USDC the exchange holds, subtract users' available balances, margin locked in open positions and accrued fees; what remains is free pool cash. It cannot go negative.
sideBucket: loss proceeds parked while the queue has anyone in it, earmarked inside that cash for queued winners. Harvest drains it first.- Payout queue: a first-in, first-out list of unpaid winning closes. Each entry is
(account, amount).
Instead of holding a pre-funded pool that pays winners on demand, the exchange queues winners when the pool is short and clears them as later losses refill it.
What enters the queue, and what doesn't
The queue holds only what the pool owes on a close but cannot pay from its available cash at that moment: the profit (after the haircut and win fee) on a close funded from available balance, or the surviving claim on a close funded from queued balance. Several things never enter it:
- Margin on a close funded from available balance. It goes straight back to the trader's balance. They can withdraw it or reuse it without waiting on the queue.
- Fees ahead of queued winners. Every winner pays the win fee, but the fee reaches stakers and the foundation only when the queue is empty and the pool can fund it as well. Otherwise it is not paid out, and the winner's queued claim is that much smaller. The 2% loss-side fee is waived while the queue is not empty.
- Losses while the queue is not empty. They are parked in
sideBucketinstead of becoming free pool cash. They still count toward the tracked pool in full when they settle, and harvest uses them first. - The stakers' share of pool gains. Nothing is swept to stakers while anyone is queued.
Winning closes
When a trader closes at a profit, the deadband, haircut and toxicity win fee come off the profit whatever state the pool is in. Then:
- If the queue is empty, the trader is paid immediately from free pool cash, up to the full payout. The win fee goes to stakers and the foundation only if free cash covers it too; otherwise it is not paid out.
- Whatever the pool could not pay (the whole payout, if the queue already has anyone in it) joins the back of the queue as
(account, payout). Pool cash does not change for the queued part.
A position funded from queued balance settles the same way, except the pool owes its whole surviving claim: margin plus profit after fees, or margin minus the loss. The queue claim it used as margin was a promise of future payment, not money the trader held.
Losing closes and liquidations
When a position funded from available balance closes at a loss, or is liquidated:
- If the queue is empty, the pool's share (the loss minus the 2% loss-side fee) becomes free pool cash.
- If the queue is not empty, the loss stays in the exchange but is parked in
sideBucketfor queued winners instead of becoming free pool cash, and the loss-side fee is waived. It still counts toward the tracked pool when it settles.
Either way, the loss counts as eligible loss toward that period's $TRADE emissions. Parking the cash in sideBucket does not change that.
A loss or liquidation on a position funded from queued balance brings in no cash: the destroyed part of the trader's queue claim simply stops being owed, so nothing becomes pool cash or goes to sideBucket. On a losing close, the surviving claim is paid or queued like a win, and the 2% loss-side fee is charged only when the queue is empty and free cash covers the surviving claim plus the fee. A liquidation destroys the whole claim and charges no fee.
Funding
Funding never touches the pool's cash or the queue. Crowded-side funding is collected hourly from margin into each stock's funding pot, and receivers are paid only from that pot. The house receives only what is left in the pot after receivers are paid, and never pays funding. Funding paid by a losing position is never eligible loss for $TRADE. See Funding.
Harvest
harvest(maxEntries) pays the queue down:
- Walk forward from the front of the queue, paying each
(account, amount)from cash available to back the queue. - Take it from
sideBucketfirst. If the cash runs out before the queue is clear, stop; later losses or freed cash fund later harvests. - If the queue empties with money left in
sideBucket, the rest is released back into ordinary pool cash. Neither harvest nor this release changes the tracked pool; the loss already counted when it settled.
Harvest is permissionless: anyone can call it, though the caller is not paid. The foundation's keeper calls harvest(32) on every new block whenever there is cash to pay out, so nobody has to.
Invariants
- Pool cash and
sideBucketare unsigned, so neither can go negative. - Free pool cash available for new payouts is zero whenever anyone is queued, so a new winner can never be paid ahead of earlier queued ones.
- Pool equity = pool cash (including
sideBucket) − total queued. This can go negative. That is the Martingaler's temporary insolvency, by design.
What the trader sees
Opening a position does not depend on the queue, apart from the normal risk limits. Closing at a profit either pays straight away or joins the queue, depending on the pool. The app shows two balances: available (already paid) and queued (waiting for harvest). Both can be used as margin for new positions, because a queued balance can be put up as collateral.