package tezos-protocol-alpha

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Simple abstraction from low-level storage to handle unstaked frozen deposits.

Unstaked frozen deposits are tez coming from frozen deposits that have been unstaked, either:

  • manually with the "unstake" pseudo-operation,
  • automatically at cycle ends with the auto-staking mechanism, or
  • when a delegator changes delegate. The amounts are attached to a given cycle, the cycle at which the unstake happened, and are slashable for another consensus_rights_delay + max_slashing_period - 1 cycles. After this, they can be finalized either with the "finalize_unstake" pseudo-operation, via auto-staking (for bakers only), or when staking or unstaking.

Unstaked frozen deposits contain, for each cycle, a current_amount and an initial_amount. Only unstaked frozen deposits for the current cycles can be increased, via unstaking. After a cycle has ended, the initial amount becomes the basis for forthcoming slashings. It can only be decreased by the "stake from unstake" mechanism. Slashings only affects the current_amount of the slashed cycles.

Unstaked frozen deposits of finished cycles can be decreased by the "stake from unstake" mechanism, but only if the cycles haven't been slashed (to avoid shooting ourselves in the feet).

To avoid the list of cycles growing unboundedly, amounts for finalizable cycles are squashed together, lazily, when the list needs to be updated, only.

This module is responsible for maintaining the Storage.Contract.Unstaked_frozen_deposits table.

balance ctxt delegate cycle returns the amount of unstaked frozen deposits for delegate at cycle. If cycle is an unslashable cycle, the returned amount is the squashed amount of all the unslashable cycles.

credit_only_call_from_token ctxt staker cycle amount credits the unstaked frozen deposits for staker at cycle by amount. If cycle is an unslashable cycle, the credited cycle is the last unslashable cycle.

spend_only_call_from_token ctxt staker cycle amount spends amount from the unstaked frozen deposits for staker at cycle. If cycle is an unslashable cycle, the amount is spent from the last unslashable cycle. The function returns the error Subtraction_underflow if the balance is too low.

decrease_initial_amount_only_for_stake_from_unstake ctxt staker cycle amount decreases amount from the unstaked frozen deposits for staker at cycle. It is only called if the cycle hasn't been slashed, so the amount removed is the same as the amount spent in current_amount.

OCaml

Innovation. Community. Security.