Module balance

Source
Expand description

Balance-level accessors and initialization utilities.

Provides a field-oriented interface over LazyBalance::Balance, treating it as a virtual struct composed via discriminants.

§Logical Structure

struct <T as LazyBalance>::Balance {
    BalanceAsset.0: T::Asset,       // effective
    BalanceAsset.1: T::Asset,       // issued
    BalanceRational: T::Rational,   // bias
    BalanceTime.0: T::Time,         // checkpoint
    BalanceTime.1: T::Time,         // drainpoint
}
  • discriminants = field identifiers
  • .0, .1 = multiple values (Many)
BalanceAsset    => Many(T::Asset)
BalanceRational => Some(T::Rational)
BalanceTime     => Many(T::Time)

This is a type projection:

  • T defines the schema
  • storage is discriminant-keyed and resolved via VirtualDynField
  • this decouples logical structure from storage layout.

§Semantics

  • Asset: effective, issued
  • Rational: bias
  • Time: checkpoint, drainpoint

§Initialization

balance::is_fresh_balance lazily initializes:

  • effective = 0, issued = 0
  • bias = 1
  • checkpoint = 0, drainpoint = 0

§Context

ShareBalanceContext supplies:

Structure stays abstract (but here implemented concretely); layout and limits come from the context.

Functions§

bias
Returns the scaling factor (share-price) applied to the balance value.
checkpoint
Returns the most recent time at which the balance state was adjusted i.e., reap or mint.
drainpoint
Returns the most recent time at which the balance state was drained.
effective
Returns the current effective value of the balance.
init_balance
Initializes a LazyBalance::Balance forcefully.
is_fresh_balance
Initializes a LazyBalance::Balance only if not already initialized.
issued
Returns the base value (total shares) backing the balance.
set_bias
Sets the scaling factor (share-price) applied to the balance value.
set_checkpoint
Sets the most recent adjusted (reap/mint) time of the balance.
set_drainpoint
Sets the most recent drained time of the balance.
set_effective
Sets the current effective value of the balance.
set_issued
Sets the base value (total shares) of the balance.