Position Closure Payout Rules

General Payout Rules

These rules apply to any Position closure, whether it be liquidation, full closure, or partial closure.

Per the concept of locked_amount covered here, every Position has an allotment of tokens set aside from the Custody at initialization to pay back collateral, the loan, and some profits/losses. Beyond that limit, other rules apply. Let's walk through them in a waterfall.

We'll focus on a generic token being removed from a Position first, and then talk about specific things that happen for a token that represents a unit of collateral, a unit of loan, or a unit of profit/loss in a sidebar.

  1. First, locked_amount is decremented during disbursement (by convention, locked_amount is generally guaranteed to be above loan + collateral) and while the tokens do reside in the actual Custody token account literally, the accounting is considered to come out of this locked pile tied to Position and the locked variable on Assets for the Custody where it is tracked as a whole.

    1. Note that when the trader is paid out, he is being paid from the Custody token account.

  2. Now locked_amount is expired to 0, locked is decremented by the removed amount, and we enter the Insurance Fund territory. We attempt to payout what is owed to the trader entirely from this separate token account that's tied to each Custody and funded entirely by separate fees, unredeemable by LPs, until it is empty.

    1. Note that when the trader is paid out during this case, he is being paid from the Custody's insurance token account. The trader will receive funds from two different accounts at this stage (due to steps #1 and #2).

  3. Finally, once the Insurance Fund is expired to 0, we start taking impairment losses on tokens that aren't locked and available for lending as determined as the difference between base and locked on Assets and incrementing the impairment_losses variable on Assets to permanently represent those losses taken.

    1. Note that when the trader is paid out in this case, he may be receiving payments from both the insurance token account of the Custody (if it has funds) and tokens from the Custody's own token account representing those tokens under the locked_amount limit and the impairment losses here.

  4. If all available tokens from the Custody's token account are used to pay out the trader and still more is owed, the trader will take the loss, and the user_losses variable on Assets for the Custody is permanently increased to log the pain the trader felt.

  5. Finally, if locked_amount goes below the new size_usd if the Position, and it isn't being completely closed or liquidated, it is reallocated to be at least the size_usd of the Position, and locked is similarly increased, if available. If these tokens aren't available to be locked, then the entire requested change (update_position) of the Position will fail in-transaction since it cannot be topped up with new allocated locked tokens meeting at least it's loan + collateral size.

There are three different types of token closure payouts: collateral, loan, and profit/loss. Each touches different variables in the system. All involve locked_amount and locked being adjusted, as mentioned above, if the decrement takes place when moving tokens beneath the amount of locked_amount tokens.

If you want to learn more about the accounting fields in the Custody, you can do so here.

  1. Collateral: When collateral is being withdrawn, owned decreases but base does not, because owned represents base + collateral.

  2. Loan: When loan is being wound down, nothing is being touched, so nothing other than locked_amount and locked change.

  3. Profit/Loss: When a trader is making profit, both owned and base on Assets for the Custody must be adjusted downwards to reflect the loss to the Custody, whereas the reverse must be true if the trader is taking a loss.

Last updated