Expand description
A collection of composable, type-driven balance models built on
virtual abstractions and
plugin-based execution.
§Motivation
Traditional balance systems tightly couple:
- storage layout
- accounting logic
- and update propagation
This leads to:
- costly updates across all dependent states
- rigid data structures that are hard to evolve
- difficulty composing new behaviors or extending models
This module addresses these limitations by:
- decoupling structure, storage, and behavior
- deferring computation until it is actually needed
- allowing logic to be injected via plugins
§Lazy Balance Model
The primary model is LazyBalance, a receipt-based,
lazily evaluated accounting system.
deposit -> issue receipt
mutate balance -> affect global state only
withdraw -> resolve receipt value lazilyIn this model:
- deposits create receipts (claims)
- balance mutations affect global state only
- receipt value is computed at withdrawal time
This avoids eagerly updating all receipts while preserving correctness.
§Design
§Virtual Architecture
All balance models are built on shared virtual primitives:
VirtualDynField-> defines structured components (asset, rational, time)VirtualDynExtension-> enables extensibility via addonsVirtualDynBound-> provides external constraints (e.g. capacity)VirtualNMap-> externalizes heavy or dynamic storage
These abstractions allow:
- structure to remain representation-agnostic
- storage to be externalized or optimized independently
- components to be composed across contexts
§Plugin-Driven Execution
Behavior is defined through plugin families via:
This enables:
- compile-time dispatch of operations
- modular and replaceable logic
- context-driven customization
Each operation (deposit, withdraw, etc.) is selected via a discriminant and resolved through the plugin family.
§Summary
This module provides a foundation for building diverse balance systems where:
- accounting is lazy and efficient
- structure is flexible and composable
- behavior is modular and replaceable
enabling multiple accounting strategies to coexist under a unified, type-driven architecture.
Modules§
- lazy_
balance_ 🔒model_ checker - Model checker module for
LazyBalanceimplementations.
Structs§
- Balance
Addon - Discriminant for additional balance-specific extensions.
- Balance
Asset - Discriminant for the asset type within
LazyBalance::Balance. - Balance
Exit - Represents a successful withdrawal where the lazy and manual models produce different outputs.
- Balance
Failure - Represents a failure encountered during execution of an operation sequence.
- Balance
Model Results - Aggregates results produced during state exploration.
- Balance
Rational - Discriminant for the numeric representation within
LazyBalance::Balance. - Balance
State - Primary state container for executing and tracking a sequence of operations.
- Balance
Time - Discriminant for the time dimension within
LazyBalance::Balance. - Balance
Traps - Defines trap behavior for state exploration.
- CanDeposit
- Discriminant for deposit validation.
- CanMint
- Discriminant for mint validation.
- CanReap
- Discriminant for reap validation.
- CanWithdraw
- Discriminant for withdrawal validation.
- Deposit
- Discriminant for deposit execution.
- Deposit
Limits - Discriminant for deposit limits query.
- Drain
- Discriminant for drain execution.
- HasDeposits
- Discriminant for deposit presence query.
- Lazy
Balance Error - Discriminant for error types within the
LazyBalancesystem. - Lazy
Container - Convenience container holding the owned state required to operate
on a
LazyBalanceinstance. - Limits
Asset - Discriminant for the asset type used in operation limits.
- Mint
- Discriminant for mint execution.
- Mint
Limits - Discriminant for mint limits query.
- Reap
- Discriminant for reap execution.
- Reap
Limits - Discriminant for reap limits query.
- Receipt
Active Value - Discriminant for active receipt value query.
- Receipt
Addon - Discriminant for additional receipt-specific extensions.
- Receipt
Asset - Discriminant for the asset type within
LazyBalance::Receipt. - Receipt
Deposit Value - Discriminant for receipt deposit value query.
- Receipt
Rational - Discriminant for the numeric representation within
LazyBalance::Receipt. - Receipt
Time - Discriminant for the time dimension within
LazyBalance::Receipt. - Snap
Shot Addon - Discriminant for additional snapshot-specific extensions.
- Snap
Shot Asset - Discriminant for the asset type within
LazyBalance::SnapShot. - Snap
Shot Rational - Discriminant for the numeric representation within
LazyBalance::SnapShot. - Snap
Shot Storage - Discriminant identifying the storage domain for snapshots within
LazyBalancesystems. - Snap
Shot Time - Discriminant for the time dimension within
LazyBalance::SnapShot. - Total
Value - Discriminant for total balance query.
- Withdraw
- Discriminant for withdrawal execution.
Enums§
- Balance
Op - Operation descriptor for driving both
LazyBalanceandManualBalanceModelexecutions in a consistent manner.
Traits§
- Balance
Guards - Defines validity checks for operations during state exploration.
- Balance
State Hasher - Defines a primary hashing strategy for
BalanceStateinstances. - Lazy
Balance - A composable, plugin-driven balance system with lazy receipt-based accounting.
- Lazy
Balance Component - A abstract-container representation of a structured value participating in the lazy balance system (e.g. Balance, SnapShot, Receipt).
- Lazy
Balance Context - Execution context for the
LazyBalancesystem. - Lazy
Balance Input - Input contract for all
LazyBalanceoperations. - Lazy
Balance Limits - Lazy
Balance Marker - Convenience trait alias for a
LazyBalanceimplementor used in model checking and testing. - Lazy
Balance Model Checker - Unified model checker interface over the lazy balance model checker module.
- Lazy
Balance Output - Output contract for all
LazyBalanceoperations. - Lazy
Balance Root Plugin FamilyRoot trait forLazyBalance- Manual
Balance Model - A user-indexed eager balance model over a
LazyBalancesystem, primarily intended for testing and validation.
Type Aliases§
- Context
- Resolved context type for a given
LazyBalanceimplementation. - Error
- Resolved error type for a given
LazyBalanceimplementation.