Stake
Slashing and cover
When a batch is slashed, what it takes from a solver's stakes, and how the people in the batch claim the cover.
A batch is cleared with a solver's bond locked behind it, and the proof releases the bond. When no proof verifies inside the proof window, the bond is taken instead and becomes the batch's cover. The bond invariant says how much bond a batch locks.
This page has two parts. The first is for a staker: when a slash happens and what it takes from a stake. The second is for a trader or liquidity provider whose batch was slashed: what comes back and how to claim.
For stakers
When a batch can be slashed
clear_batch sets the batch's proof deadline:
proof_deadline_slot = slot of the clearing + proof_window_slots
The default proof window is 300 slots. prove_batch is accepted while the current slot is at or before the deadline. slash_batch is accepted once the current slot is past it and the batch is still Cleared. A batch that is Proven can never be slashed, and a batch is slashed once.
The batch page shows the deadline while a batch is Cleared, as Proof due in with the slot. una.batch(id) returns it as proofDeadlineSlot and proofDeadlineAt.
Who sends it
Anyone. slash_batch takes no arguments and needs one signer, who pays the rent of the cover account and of one cover vault per bond mint slashed.
How much is taken
The slash takes the bond the batch locked, bond_locked, in lamports. It is capped at everything the solver's pools hold:
pool_lamports[m] = pool_amount[m] valued in lamports at the current rate total_lamports = sum of pool_lamports over the solver's bond mints slash_target = min(bond_locked, total_lamports)
A liquid staking token is valued at its stake pool's rate, read in the same instruction, as it is when staking.
How it is shared across stakes
The slash is split across the solver's pools by their value, then converted back to atoms of each pool's mint:
slash_lamports[m] = floor(slash_target * pool_lamports[m] / total_lamports) slash_tokens[m] = min(slash_lamports[m] converted to atoms at the pool's rate, rounded down, pool_amount[m])
slash_tokens[m] atoms move from the solver's vault for that mint to the batch's cover vault for that mint, and the pool's amount falls by the same. The pool's shares do not change. A stake is worth floor(stake_shares * pool_amount / pool_shares), so every stake in the pool loses the same fraction of its worth, and every pool loses the same fraction of its value: slash_target / total_lamports.
Shares in a cooldown are still in the pool and take the same fraction. A slash does not change any stake's reward weight.
With sample inputs: a solver has one pool of 2,000,000,000 lamports of SOL over 2,000,000,000 shares, and a batch with 1,000,000,000 lamports of bond locked is slashed. 1,000,000,000 lamports move to the cover. The pool holds 1,000,000,000 over the same 2,000,000,000 shares, and a stake of 500,000,000 shares goes from 500,000,000 lamports to 250,000,000.
What else changes
The solver's locked bond falls by bond_locked, its slash_count rises by one, and the batch's status becomes Slashed. The program emits BatchSlashed with batch_id, solver, cover and bond_slashed, which is slash_target.
Clearing fees are credited in prove_batch, so a batch pays them to its solver and stakers when it is proven.
On /solvers/[address] the Slashes panel lists each slashed batch with the time, the bond moved to cover and the transaction. una.solver(address) returns the same as slashes. A stake's row shows what slashes have taken from it beside its status, from the stake's slashedLamports.
Errors of slash_batch
| Error | Raised when |
|---|---|
BatchNotCleared | The batch is Open, Sealed or Rolled. |
BatchAlreadyProven | The batch is Proven. |
BatchAlreadySlashed | The batch is Slashed. |
ProofWindowOpen | The current slot is at or before proof_deadline_slot. |
InvalidBatchAccounts | The accounts for a pool are missing or are not that pool's mint, token program, solver vault and cover vault. Each pool with stake in it needs five: the mint, the solver vault, the cover vault, the token program and the stake pool. |
InvalidStakePool | A pool's mint is a liquid staking token and the stake pool account passed is not the listed one or fails the checks on its rate. |
MathOverflow | A sum or product leaves 64 bits. |
For the people in a slashed batch
What the cover is
slash_batch creates one Cover account for the batch, at the seeds "cover" and the batch number, and one cover vault per bond mint slashed, at "cover_vault", the batch number and the mint's index. The vaults hold the slashed bond in the mints it was staked in: wrapped SOL and liquid staking tokens.
Cover
batch_idu64- The slashed batch.
vault_amounts[u64; 4]- Atoms moved into each bond mint's cover vault.
claimed_amounts[u64; 4]- Atoms claimed from each so far.
total_weightu64- The batch's value moved, in lamports. At least 1.
claimed_weightu64- The weight of the claims made so far.
What returns untouched
An order in a slashed batch that has not been settled returns its whole sell amount. settle_order on a Slashed batch sends the order's full amount of the sell token back to the owner's token account and marks the order settled. The order does not roll into a later batch.
Orders settle as soon as their batch is cleared, so an order may already have been settled at the cleared prices when the slash lands. It keeps what it received.
Both kinds of order claim cover while the order's batch is still the slashed one. The claim is counted from the order's sell amount, whether or not the order filled. An order whose remainder rolled into a later batch before the slash belongs to that later batch.
How a share is computed
Every claim has a weight in lamports.
For an order whose batch is the slashed one:
weight = ceil(amount * price(sell token) / 2^64)
amount is the order's sell amount in atoms and price is the slashed batch's cleared price of the sell token, in lamports per atom as a Q64.64 number. The batch account keeps its prices after the slash, so the weight is the same whenever the claim is made.
For a position with liquidity on a pair the batch moved:
weight = floor(pair_moved_value * min(liquidity, pair_active_liquidity) / pair_active_liquidity)
pair_moved_value is what the pair paid out in the clearing, in lamports at the posted price, and pair_active_liquidity is the larger of the pair's active liquidity before and after the move. The batch account records both when it is cleared.
The share is the same fraction of every cover vault:
share[m] = min(floor(vault_amounts[m] * weight / total_weight), vault_amounts[m] - claimed_amounts[m])
With sample inputs: a batch holds two orders, one selling 500,000,000 lamports of SOL and one selling 50,000,000,000 atoms of a token the batch cleared at a hundredth of a lamport per atom. Each offers 500,000,000 lamports of value, the batch's value moved is 1,000,000,000 lamports, and that much bond was locked and slashed into a SOL cover vault. The first order's weight is 500,000,000, and its share is 1,000,000,000 × 500,000,000 / 1,000,000,000 = 500,000,000 lamports. Settling the same order returns its 500,000,000 lamports of SOL as well.
Claim cover
Open the slashed batch at /batches/[id]. Its Cover panel shows three figures: Cover, the bond that moved to it; Claimed so far; and Your share, for the connected wallet. When the wallet has a share to claim the panel has a Claim cover button. Press it and sign. Each press claims with one of the wallet's orders or positions in the batch, and Your share falls by that claim. When all of them have claimed, the panel reads Claimed under Your share.
const { items: slashed } = await una.batches({ status: 'slashed', limit: 10 })
for (const b of slashed) {
const batch = await una.batch(b.batchId) // the bound client sends its wallet, so `cover` holds this wallet's share
for (const p of batch.cover?.participants ?? []) {
if (p.claimed || p.claimableLamports === '0') continue
const claimed = await una.claimCover(b.batchId, { participant: p.address })
console.log(`claimed ${p.claimableLamports} lamports of cover for ${p.kind} ${p.address} in ${claimed.signature}`)
}
}una.batch(id) returns cover on a slashed batch, a BatchCover with totalLamports, claimedLamports, remainingLamports, walletClaimableLamports, walletClaimed and participants.
participants lists what the wallet can claim with: each of its orders in the batch that was not cancelled, and each of its positions with liquidity on a pair the batch moved. Each is a CoverParticipant with address, kind (order or position), claimableLamports and claimed. claimableLamports is the participant's weight as a share of totalLamports, and 0 once it has claimed. walletClaimableLamports is the sum over the participants still to claim, and walletClaimed is true when every one of them has claimed.
una.claimCover(batchId, { participant }) takes the batch number and the address of the order or position to claim with. One call makes one claim. Without participant the API picks: the first of the wallet's orders in that batch with no claim recorded, or, when there is none, the first of its positions with liquidity on one of the batch's pairs with no claim recorded. The transaction creates the wallet's associated token account for each bond mint the cover holds, if it does not exist, then sends claim_cover. The call signs, submits and follows it, and resolves with build, tx and signature.
The API answers NOTHING_TO_CLAIM when the batch has no cover, when the participant named is not an order of the wallet in that batch or a position of the wallet with liquidity on one of its pairs, or, with no participant, when the wallet has nothing left to claim with.
The claim_cover instruction
It takes no arguments. What it pays follows from its accounts.
Accounts that decide the claim
claimantsignerrequired- The owner of the order or position.
batchBatchrequired- The slashed batch.
coverCoverrequired- That batch's cover.
participantOrder or Positionrequired- What the claim is made with. One claim per instruction.
ref_accountToken or Pairrequired- For an order, the Token account of its sell token. For a position, its Pair account.
After those come four accounts for each bond mint the cover holds, in the order of the bond mint list: the mint, the cover vault, the claimant's associated token account for the mint, and the token program.
The program checks that the batch is Slashed, that the participant is an Order or Position of this program owned by the claimant, and that it has not claimed from this batch. An order is marked with cover_claimed, so it claims once. A position records the batch in last_cover_batch_id, so it claims once per slashed batch. Each order and each position claims on its own.
Each share moves from its cover vault to the claimant's associated token account for that mint. The program adds the shares to claimed_amounts and the weight to claimed_weight, and emits CoverClaimed with batch_id, cover, claimant, participant, weight and total_paid_lamports, the sum of the atoms paid across the vaults.
Errors of claim_cover
| Error | Raised when |
|---|---|
BatchNotSlashed | The batch's status is not Slashed. |
Unauthorized | The participant is not an Order or Position account of this program, its owner is not the claimant, or a destination is not the claimant's associated token account for that bond mint. |
NoCoverWeight | The order's batch is not this one, the batch has no price for the order's sell token, or its weight is 0. For a position: it has no liquidity, its pair is not among the batch's pairs, the pair moved no value in the batch, or its weight is 0. |
CoverAlreadyClaimed | The order's cover_claimed is set, or the position's last_cover_batch_id is this batch. |
InvalidIndex | With an order: ref_account is not the Token account of the order's sell token. |
InvalidBatchAccounts | The four accounts for a bond mint are missing, or the mint, token program or cover vault is not the one for that mint. |
NothingToClaim | Every share comes to 0 atoms. |
MathOverflow | A product leaves 64 bits. |
What it costs
The program takes no fee on a claim. The claimant pays the network fee and the rent of a token account for each bond mint of the cover it has never held.