Module Tezos_raw_protocol_017_PtNairob.Token

The aim of this module is to manage operations involving tokens such as minting, transferring, and burning. Every constructor of the types giver, container, or receiver represents a kind of account that holds a given (or possibly infinite) amount of tokens.

Tokens can be transferred from a giver to a receiver. To uniformly handle all cases, special constructors of givers and receivers may be used. For example, the giver `Minted is used to express a transfer of minted tokens to a receiver, and the receiver `Burned is used to express the action of burning a given amount of tokens taken from a giver. Thanks to uniformity, it is easier to track transfers of tokens throughout the protocol by running grep -R "Token.transfer" src/proto_alpha.

For backward compatibility purpose, an ANTI-PATTERN is used to redistribute slashing to denunciator; this redistribution technic should not be mimicked if it can be avoided (see https://gitlab.com/tezos/tezos/-/issues/4787). The anti-pattern works as follows: The part of slashed amounts that goes to the author of the denunciation are not directly distributed to him. Tokens are transferred to a burning sink, then minted from an infinite source ( see `Double_signing_punishments, `Tx_rollup_rejection_rewards and `Sc_rollup_refutation_rewards ). Again, this is an ANTI-PATTERN that should not be mimicked.

container is the type of token holders with finite capacity, and whose assets are contained in the context. An account may have several token holders, that can serve as sources and/or sinks. For example, an implicit account d serving as a delegate has a token holder for its own spendable balance, and another token holder for its frozen deposits. Be aware that transferring to/from `Delegate_balance d will not update d's stake, while transferring to/from `Contract (Contract_repr.Implicit d) will update d's stake.

type container = [
  1. | `Contract of Contract_repr.t
    (*

    Implicit account's or Originated contract's spendable balance

    *)
  2. | `Collected_commitments of Blinded_public_key_hash.t
    (*

    Pre-funded account waiting for the commited pkh and activation code to be revealed to unlock the funds

    *)
  3. | `Delegate_balance of Tezos_protocol_environment_017_PtNairob.Signature.Public_key_hash.t
    (*

    Delegate's implicit account spendable balance

    *)
  4. | `Frozen_deposits of Tezos_protocol_environment_017_PtNairob.Signature.Public_key_hash.t
    (*

    Frozen tokens of a delegate for consensus security deposits

    *)
  5. | `Block_fees
    (*

    Current block's fees collection

    *)
  6. | `Frozen_bonds of Contract_repr.t * Bond_id_repr.t
    (*

    Frozen tokens of a contract for bond deposits (currently used by rollups)

    *)
]
type infinite_source = [
  1. | `Invoice
    (*

    Tokens minted during a protocol upgrade, typically to fund the development of some part of the amendment.

    *)
  2. | `Bootstrap
    (*

    Bootstrap accounts funding

    *)
  3. | `Initial_commitments
    (*

    Funding of Genesis' prefunded accounts requiring an activation

    *)
  4. | `Revelation_rewards
    (*

    Seed nonce revelation rewards

    *)
  5. | `Double_signing_evidence_rewards
    (*

    Double signing denunciation rewards (consensus slashing redistribution)

    *)
  6. | `Endorsing_rewards
    (*

    Consensus endorsing rewards

    *)
  7. | `Baking_rewards
    (*

    Consensus baking fixed rewards

    *)
  8. | `Baking_bonuses
    (*

    Consensus baking variable bonus

    *)
  9. | `Minted
    (*

    Generic source for test purpose

    *)
  10. | `Liquidity_baking_subsidies
    (*

    Subsidy for liquidity-baking contract

    *)
  11. | `Tx_rollup_rejection_rewards
    (*

    Tx_rollup rejection rewards (slashing redistribution)

    *)
  12. | `Sc_rollup_refutation_rewards
    (*

    Sc_rollup refutation rewards (slashing redistribution)

    *)
]

infinite_source defines types of tokens providers which are considered to be ** of infinite capacity.

type giver = [
  1. | infinite_source
  2. | container
]

giver is the type of token providers. Token providers that are not containers are considered to have infinite capacity.

type infinite_sink = [
  1. | `Storage_fees
    (*

    Fees burnt to compensate storage usage

    *)
  2. | `Double_signing_punishments
    (*

    Consensus slashing

    *)
  3. | `Lost_endorsing_rewards of Tezos_protocol_environment_017_PtNairob.Signature.Public_key_hash.t * bool * bool
    (*

    Consensus rewards not distributed because the participation of the delegate was too low.

    *)
  4. | `Tx_rollup_rejection_punishments
    (*

    Transactional rollups rejection slashing

    *)
  5. | `Sc_rollup_refutation_punishments
    (*

    Smart rollups refutation slashing

    *)
  6. | `Burned
    (*

    Generic sink mainly for test purpose

    *)
]
type receiver = [
  1. | infinite_sink
  2. | container
]

receiver is the type of token receivers. Token receivers that are not containers are considered to have infinite capacity.

allocated ctxt container returns a new context because of possible access to carbonated data, and a boolean that is true when balance ctxt container is guaranteed not to fail, and false when balance ctxt container may fail.

balance ctxt container returns a new context because of an access to carbonated data, and the balance associated to the token holder. This function may fail if allocated ctxt container returns false. Returns an error with the message "get_balance" if container refers to an originated contract that is not allocated. Returns a Storage_ErrorMissing_key error if container is of the form `Delegate_balance pkh, where pkh refers to an implicit contract that is not allocated.

transfer_n ?origin ctxt givers receiver transfers amount Tez from giver to receiver for each (giver, amount) pair in givers, and returns a new context, and the list of corresponding balance updates. The function behaves as though transfer ?origin ctxt giver receiver amount was invoked for each pair (giver, amount) in givers, however a single balance update is generated for the total amount transferred to receiver. When givers is an empty list, the function does nothing to the context, and returns an empty list of balance updates.

transfer ?origin ctxt giver receiver amount transfers amount Tez from giver giver to receiver receiver, and returns a new context, and the list of corresponding balance updates tagged with origin. By default, ~origin is set to Receipt_repr.Block_application. Returns Storage_ErrorMissing_key if giver refers to a contract that is not allocated. Returns a Balance_too_low error if giver refers to a contract whose balance is less than amount. Returns a Subtraction_underflow error if giver is not a contract and its balance is less than amount. Returns a Empty_implicit_delegated_contract error if giver is an implicit contract that delegates to a different contract, and whose balance is equal to amount. Returns a Non_existing_contract error if receiver refers to an originated contract that is not allocated. Returns a Non_existing_contract error if amount <> Tez_repr.zero, and receiver refers to an originated contract that is not allocated. Returns a Addition_overflow error if receiver refers to a receiver whose balance is greater than Int64.max - amount. Returns a Wrong_level error if src or receiver refer to a level that is not the current level.