Skip to main content

Monetary System

The Shamwari Monetary System (nxt.ms / ShamwariPay) is a protocol-native framework for creating, issuing, controlling, and exchanging custom digital currencies directly on the blockchain ledger.

By executing monetary primitives natively within the core runtime—rather than through virtual machine smart contracts—Shamwari eliminates VM execution risks, reentrancy vulnerabilities, and gas-fee friction while delivering high-throughput compliance controls, velocity limits, bulk payment processing, time-locked commitments, and atomic cross-currency trading across BetaChains.


Core Capabilities & Architecture

  • Protocol-Native Execution: Currency operations run directly inside nxt.ms, removing VM overhead and gas dependencies.
  • Bitmask Programmability: Currencies inherit composite capabilities via bitmask flags (EXCHANGEABLE, CONTROLLABLE, MINTABLE, NON_SHUFFLEABLE, SOVEREIGN, PRIVATE).
  • Sovereign Fee Settlement: Built-in support for chain-native fee-settlement tokens (SOVEREIGN) tied directly to sovereign BetaChains (e.g., domestic fiat stablecoins or central bank digital currencies).
  • Issuer Velocity Controls: Real-time per-transaction (transactionLimitQNT) and daily total limits (dailyLimitQNT) to prevent capital flight and protect account security.
  • Batched Payment Settlement: Efficient multi-recipient settlement via CurrencyBulkPayment with automatic tax aggregation and proportional fee allocation.
  • Immutable Tax Audit Ledger: Protocol-enforced tax deductions recorded in an append-only audit table (CurrencyTaxRecord) linked directly to transaction hashes and tax collector accounts.
  • Goal & Time-Locked Financial Products: Native primitives for goal-based accumulation (CurrencySavings) and block-height time-locked commitments (VaultCurrency).
  • Supply Burning & Cash Redemptions: Permanent unit destruction via CurrencyWithdraw for cash redemption or off-chain asset balancing.
  • On-Chain Order-Book Exchange: Decentralized currency-to-currency trading pairs processed by ExchangeHome and ExchangeOfferHome.
  • Granular Account Guardrails: Enforces compliance checks based on recipient account classifications (e.g., restricting payments to SAVINGS or AUTONOMOUS AI agent accounts).

Currency Types & Bitmask Capabilities

Currencies derive operational behavior from a composite bitmask constructed from nxt.ms.CurrencyType flag values:

FlagValueEnumDescription
EXCHANGEABLE0x01CurrencyType.EXCHANGEABLEEnables open order-book trading against other EXCHANGEABLE currencies.
CONTROLLABLE0x02CurrencyType.CONTROLLABLEPermits the issuer to set dynamic per-transaction and daily transfer caps.
MINTABLE0x04CurrencyType.MINTABLEAllows additional supply generation up to maxSupplyQNT using proof-of-work hash functions.
NON_SHUFFLEABLE0x08CurrencyType.NON_SHUFFLEABLEProhibits inclusion in privacy coin-shuffling operations to maintain strict regulatory auditability.
SOVEREIGN0x10CurrencyType.SOVEREIGNPermanently binds the currency as the primary fee-settlement token for a BetaChain. Cannot be deleted or shuffled.
PRIVATE0x20CurrencyType.PRIVATERestricts transfers, exchange offers, and dividend distributions to involve or be routed through the issuer account.

Data Model & Relational Schema

Currency metadata, supply changes, velocity parameters, transaction logs, and immutable tax records are maintained in versioned relational database tables indexed by block height and full transaction hashes.

1. Primary Currency & Protocol Entities

TablePrimary / Composite KeyEntity ClassDescription
public.currencyidCurrencyMaster currency definitions, decimals, minting parameters, and issuer settings.
public.currency_supplyid, heightCurrencySupplyVersioned record tracking dynamic circulating supply for minting and withdrawals.
public.currency_controlid, heightCurrencyControlMutable per-transaction and 24-hour daily velocity limits.
public.currency_transferfull_hash, idCurrencyTransferPeer-to-peer transfers with associated tax units (QNTQNT).
public.currency_paymentfull_hash, idCurrencyPaymentDirect merchant and business institutional payment entries.
public.currency_bulk_paymentfull_hash, recipient_idCurrencyBulkPaymentMulti-recipient batched payment entries sharing a single transaction hash.
public.currency_savingsfull_hash, idCurrencySavingsGoal-based savings deposits removed from liquid balances.
public.vault_currencyfull_hash, idVaultCurrencyTime-locked commitments scheduled for block-height release.
public.currency_withdrawfull_hash, idCurrencyWithdrawSupply destruction / cash redemption records.
public.currency_tax_recordtransaction_full_hash, transaction_idCurrencyTaxRecordImmutable, append-only tax audit trail for protocol revenue collection.

2. Primary Currency Record (public.currency)

FieldTypeDescription
idlongTransaction ID of initial currency issuance (globally unique handle).
issuerIdlongAccount ID of the issuing authority.
chainBetaChainTarget BetaChain context hosting the currency.
nameStringFull currency identifier (min 33 characters).
codeStringTicker symbol (3–10 uppercase ASCII characters).
typeintBitmask combination of CurrencyType codes.
initialSupplyQNTlongInitial supply minted at issuance in atomic units (QNTQNT).
maxSupplyQNTlongHard upper bound on total supply in atomic units (QNTQNT).
decimalsbyteDecimal resolution (00 to 88 places, where 1 Unit=10decimals QNT1 \text{ Unit} = 10^{\text{decimals}} \text{ QNT}).
algorithmbyteHash function ID used if MINTABLE (e.g., SHA-256, SHA3-256).
minDifficultybyteMinimum proof-of-work mining difficulty (11 to 255255).
maxDifficultybyteMaximum proof-of-work mining difficulty (11 to 255255).
whitelistPropertyStringOptional account property key required for non-issuers to hold or transfer units.
isDeletedbooleanFlag set when a currency is purged from active circulation.

3. Dynamic Supply Formula

For MINTABLE and burnable currencies, the circulating supply is updated dynamically during block execution:

Current Supply (QNT)=initialSupplyQNT+MintedQNTWithdrawnQNT\text{Current Supply } (QNT) = \text{initialSupplyQNT} + \sum \text{MintedQNT} - \sum \text{WithdrawnQNT}


Currency Lifecycle & Operations

┌──────────────────────────────────────┐
│ betaChainCurrency() / Issuance │
└──────────────────┬───────────────────┘


┌───────────────────────────┐
│ Active Currency │
│ (is_deleted == false) │
└─────┬───────────┬───┬─────┘
│ │ │
Minting (PoW) │ │ │ Velocity Limits
& Supply Adjust │ │ │ (CONTROLLABLE)
▼ │ ▼
┌───────────┐ │ ┌───────────────────┐
│ Dynamic │ │ │ Transaction/Daily │
│ Supply │ │ │ Cap Enforcement │
└───────────┘ │ └───────────────────┘
│ │
Redemption/Burn │ │ Issuer Purge
(CurrencyWithdraw) │ │ (Prohibited if SOVEREIGN)
▼ ▼
┌───────────┐ ┌───────────┐
│ Supply │ │ Deleted │
│ Burned │ │ (is_del) │
└───────────┘ └───────────┘

1. Issuance & Sovereign Currency Registration

A standard currency is created using a CURRENCY_ISSUANCE transaction, specifying the bitmask flags, supply parameters, and decimal precision.

For sovereign BetaChains, fee currencies are initialized programmatically at genesis or fork activation via Currency.betaChainCurrency():

// Registering a sovereign fiat currency for a regional BetaChain
Currency.betaChainCurrency(
betaChain, // Target BetaChain instance
currencyId, // Static numeric ID
issuerAccountId, // Central Bank / Authority Account ID
"Zimbabwe Gold", // Full Name
"ZWG", // Code / Ticker
"Sovereign Reserve Currency",
CurrencyType.SOVEREIGN.getCode(), // SOVEREIGN bitmask forced internally
100_000_000_000L, // Initial Supply QNT
1_000_000_000_000L, // Max Supply QNT
(byte) 0, // Algorithm (0 = None)
(byte) 2 // Decimals (2 decimal places)
);

2. Batched Bulk Payments (CurrencyBulkPayment)

To optimize payroll, disbursement, and dividend workflows, Shamwari supports multi-recipient transactions. A single CURRENCY_BULK_PAYMENT transaction expands into individual recipient payment logs while executing unified tax deduction logic:

  • Row Key Uniqueness: Rows in public.currency_bulk_payment are keyed by (full_hash, recipient_id).
  • Proportional Tax Calculation: The total transaction tax (TtotalT_{\text{total}}) is calculated on aggregate volume, stored in full on the first recipient entry (tax_units), and proportionally calculated per recipient entry:

taxUnitsQNTi=unitsQNTitotalUnitsQNT×Ttotal\text{taxUnitsQNT}_i = \left\lfloor \frac{\text{unitsQNT}_i}{\text{totalUnitsQNT}} \times T_{\text{total}} \right\rfloor

  • Event Notification: Emits CurrencyBulkPayment.Event.BULK_PAYMENT upon commit.

3. Supply Redemptions & Burning (CurrencyWithdraw)

When currency holders redeem digital tokens for physical fiat or bank deposits, the tokens are permanently destroyed rather than transferred to a reserve account:

// Security validation prior to executing withdrawal/burn logic
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new BlockchainPermission("withdrawCurrency"));
}
  • Supply Impact: Reduces circulating supply in public.currency_supply without altering maxSupplyQNT.
  • Record Persistence: Recorded in public.currency_withdraw and triggers CurrencyWithdraw.Event.CURRENCY_WITHDRAWAL.

4. Deletion Rules

A currency can be purged using a CURRENCY_DELETION transaction if and only if:

  1. isSovereign() == false (Sovereign fee currencies can never be deleted).
  2. The sender account holds 100%100\% of the active circulating supply (QNTQNT).

Velocity Controls & Compliance Safeguards

Daily and Per-Transaction Limits

When transferring a CONTROLLABLE currency, the protocol enforces velocity guardrails prior to executing ledger balance updates:

TransferUnitstransactionLimitQNT\text{TransferUnits} \le \text{transactionLimitQNT}

DailySpent+TransferUnitsdailyLimitQNT\text{DailySpent} + \text{TransferUnits} \le \text{dailyLimitQNT}

If a non-corporate account attempts a transfer exceeding these bounds, CurrencyType.CONTROLLABLE.validate() rejects the transaction with a NotValidException.

// Adjusting velocity limits (Issuer only)
Currency.changeTransactionLimits(
currencyId,
newTransactionLimitQNT,
newDailyLimitQNT
);

Account Type Restrictions

To protect institutional and retail workflows, CURRENCY_PAYMENT transactions enforce strict destination account filtering:

  • Prohibited Destinations: Payments cannot be sent directly to NONE, AUTONOMOUS (uncontrolled AI agent), or PERSONAL default accounts without explicit merchant capability.
  • Savings Guard: Accounts typed as SAVINGS can only receive currency payments originating from verified BUSINESS accounts.

Immutable Tax Architecture (CurrencyTaxRecord)

Shamwari incorporates an automated, append-only fiscal tax collection framework managed by CurrencyTaxRecord. Tax is deducted directly during settlement of transfers, payments, exchange trades, and loan repayments.

┌────────────────────────────────────────────────────────┐
│ Taxable Event (Transfer / Payment / Trade / Repayment) │
└───────────────────────────┬────────────────────────────┘


┌────────────────────────────────────────────────────────┐
│ CurrencyTaxRecord.creditTaxAccount(transactionId, │
│ fullHash, event, payerId, taxAccountId, units) │
└───────────────────────────┬────────────────────────────┘


┌────────────────────────────────────────────────────────┐
│ 1. Credit taxAccountId balance via AccountLedger │
│ 2. INSERT/MERGE into public.currency_tax_record │
│ 3. Fire Event.TAX_COLLECTED listener │
└────────────────────────────────────────────────────────┘

Persistence and Audit Trail

  • Primary Key: (transaction_full_hash, transaction_id).
  • SQL Persistence: Uses atomic merge operations to guarantee idempotency and prevent duplicate tax credits:
    MERGE INTO currency_tax_record
    (transaction_id, transaction_full_hash, currency_id, payer_id, tax_collector_id, units, timestamp, height, latest)
    KEY (transaction_full_hash, transaction_id)
    VALUES (?, ?, ?, ?, ?, ?, ?, ?, TRUE)
  • Append-Only Integrity: Tax records can never be deleted, updated, or rolled back by issuers or node operators.

Time-Locks and Goal-Based Accumulation

Goal-Based Savings (CurrencySavings)

Allows accounts to lock units into designated goal targets tracked in public.currency_savings. Locked funds are isolated from liquid currency balances until goal criteria are satisfied. Emits CurrencySavings.Event.SAVINGS.

Time-Locked Vaults (VaultCurrency)

Provides native programmatic timelocks. Deposited units are recorded in public.vault_currency and remain locked in account_currency_vault until the target block height is reached:

IsReleased(height)={trueif currentHeightreleaseHeightfalseotherwise\text{IsReleased}(\text{height}) = \begin{cases} \text{true} & \text{if } \text{currentHeight} \ge \text{releaseHeight} \\ \text{false} & \text{otherwise} \end{cases}

Vault releases are processed automatically in the core ledger's AFTER_BLOCK_APPLY phase without requiring user-initiated unlock transactions. Emits VaultCurrency.Event.VAULT.


Order-Book Decentralized Exchange (ExchangeHome)

Currencies flagged as EXCHANGEABLE can be traded peer-to-peer on the native order-book engine managed by ExchangeHome and ExchangeOfferHome.

┌──────────────────────────────────┐
│ publishExchangeOffer() │
│ (BUY / SELL Offer Created) │
└────────────────┬─────────────────┘


┌──────────────────────────────────┐
│ Order Matching Engine │
│ (Rate & Quantity Validation) │
└────────────────┬─────────────────┘


┌──────────────────────────────────┐
│ Atomic Exchange Executed │
│ Seller Units <──> Buyer Base │
└──────────────────────────────────┘

Pair Validation

To execute an order or publish an exchange offer, both the base currency and quote currency must satisfy:

IsExchangeable(Ctarget)IsExchangeable(Cbase)=True\text{IsExchangeable}(C_{\text{target}}) \land \text{IsExchangeable}(C_{\text{base}}) = \text{True}

Atomic Settlement

When a buy or sell offer matches an incoming offer:

  1. ExchangeOfferHome validates balance availability.
  2. Units are transferred atomically between seller and buyer accounts.
  3. Applicable network taxes (taxQNT\text{taxQNT}) are calculated via TaxCalculator, recorded in CurrencyTaxRecord, and processed in the same block execution phase.
  4. An immutable Exchange event record is logged to the child-chain schema (public.exchange).

Event Listener Matrix

The Monetary System exposes strongly-typed event listeners across all entity classes to support real-time indexers, analytics, and external service hooks:

Entity ClassEvent EnumListener Trigger
CurrencyTransferEvent.TRANSFERSingle peer-to-peer unit transfer processed.
CurrencyPaymentEvent.PAYMENTInstitutional or business payment completed.
CurrencyBulkPaymentEvent.BULK_PAYMENTBatched multi-recipient payment executed.
CurrencySavingsEvent.SAVINGSGoal-based deposit logged into savings bucket.
VaultCurrencyEvent.VAULTTime-locked vault commitment established.
CurrencyWithdrawEvent.CURRENCY_WITHDRAWALUnits permanently burned / withdrawn from circulation.
CurrencyTaxRecordEvent.TAX_COLLECTEDTax deduction credited to designated governance tax collector account.

APIDescription
IssueCurrencyCreate new currency
DeleteCurrencyDelete currency
AdjustCurrencyLimitsSet velocity limits
TransferCurrencyTransfer currency
CurrencyBulkPaymentBatched payments
CurrencyPaymentSingle payment
CurrencySavingsGoal-based savings
VaultCurrencyTime-locked vaults
CurrencyWithdrawBurn/redeem currency
PublishExchangeOfferPost exchange offer
LendCurrencyLend currency
LoanApplicationCreate loan application
LoanRepaymentRepay loan
RescueLoanRescue defaulted loan

Institutional & Regional Use Cases

  • Central Bank Digital Currencies (CBDC): Central monetary authorities issue SOVEREIGN currencies bound to dedicated BetaChains, guaranteeing zero-gas end-user transactions and instant settlement.
  • Automated Tax Collection: Revenue authorities configure chain-level tax collector accounts, receiving verifiable receipts logged continuously in public.currency_tax_record.
  • Targeted Social Subsidies: Governments deploy PRIVATE + CONTROLLABLE currencies with whitelist restrictions, ensuring subsidy funds can only be spent at approved food and agricultural merchants.
  • Cross-Border Trade Liquidity Pools: Financial service providers (FSPs) run order-book trading pairs between regional stablecoins (ZWG, ZAR, KES, BRL) to reduce FX trade settlement latency across emerging markets.