Appearance
The Vault: solvency and queue
The Vault is a double-entry ledger over the USDC it holds. It is where the rule "a deposit never pays another trader" is enforced.
Live on the testnetAccounts
| Account | Holds |
|---|---|
| A user | That wallet's balance: its own money plus profit the pool owes it |
pending | Stakes of open positions: fuse premiums and perp margins |
pool | The pool's cash less everything it owes. It may be negative |
queue | Profit that is waiting to be paid out to a wallet |
stakers, dev | Fees taken for each |
external | A mirror of USDC outside the Vault. The only account allowed below zero by design; its negative is the money supply |
Every movement debits one account and credits another by the same integer amount. The sum of all accounts is always zero.
Own money and profit
Beside each user balance the Vault keeps profitOf: the part of the balance that is profit owed by the pool. The rest is the user's own money.
- A deposit adds own money.
- A win adds profit.
- A loss comes off profit first.
- A queue payment turns profit into own money.
Own money is always backed by USDC the Vault holds. Profit is backed only as far as the pool has earned it.
When a position ends
settle does three things in one transaction:
- returns what is left of the stake from
pendingto the user; - moves what was lost from
pendingtopool; - credits a payout above the stake to the user as profit, in full, from
pool.
Step 3 can take pool below zero. It can never take it below what it owes: the contract reverts with PoolShort if a movement would have the pool spend cash it does not hold.
Withdrawing
withdraw pays, in order:
- own money, at once;
- profit, from the pool's cash, after claims already waiting;
- nothing more. An unpaid remainder of at least $1 becomes the wallet's one queued claim.
cancelQueued takes a waiting claim back into the balance.
Paying the queue
payQueue(max) pays waiting claims oldest first, at most max of them a call, from the pool's cash. Anyone may call it; the server does as the pool earns.
It is deliberately its own call. Nothing on the trade path reads or pays the queue, so a long queue of small claims cannot make a trade more expensive or block one.
Fees and the sweep
takeGainFee: when a position ends having left the pool a gain, 2% of the gain leaves the pool, half todevand half tostakers. Only while the queue is empty and the pool holds the fee above what it owes.dailySweep: once a day, 98% of the pool's money above $1,000,000 moves tostakers.
Invariants
checkInvariants() is a public view the admin page shows. It is true only when all of these hold:
- every account sums to zero;
- the held stakes, the queue, and the stakers' and dev accounts are not negative;
- the pool is never further below zero than the profit and queued claims it owes;
- the profit owed is no more than users' balances and held stakes together;
- the queue's total equals the sum of its open claims;
- the USDC the Vault holds is at least the money supply.