Design Philosophy
The economy is designed around several key principles:“imagine a blockchain but without the blocks or the chain” - Heliodex
- Append-only ledger: All transactions are immutable
- No database dependencies: Ledger is a simple JSONL file
- In-memory computation: Balances calculated from ledger on startup
- Microservice architecture: Independent of Site and Database services
- Transaction atomicity: All operations are all-or-nothing
Currency System
Currency Units
Currency is stored as an unsigned 64-bit integer with micro-precision:10000000 in storage
Display Format: 10.000000 unit
Economy Limits
- Maximum per-user balance: ~18 trillion units (uint64 max)
- Maximum economy size: Sum of all balances ≤ uint64 max
- Precision: 6 decimal places (micro-units)
Stipends
Users receive free currency daily:- Amount: 10 units per claim
- Cooldown: 12 hours between claims
- Purpose: Bootstrap new users and keep economy flowing
Transaction Types
Transaction (User-to-User)
Transfer currency between users.- Sender must have sufficient balance
- From and To must be different users
- Amount or Returns must be non-zero
- Note is required
Mint (Currency Creation)
Create new currency from thin air (admin/stipend).- Recipient must exist
- Amount must be positive
- Note is required
Burn (Currency Destruction)
Remove currency from circulation (e.g., creation fees).- Sender must have sufficient balance
- Amount must be positive
- Note and Link are required
Ledger Architecture
Storage Format
The ledger is stored as a JSONL (JSON Lines) file:Startup Process
- Opens the ledger file (creates if missing)
- Reads all transactions into memory
- Replays each transaction to build current state
- Validates transaction integrity
- Starts HTTP server
In-Memory State
The service maintains three maps:Write Process
- Validated before writing
- Appended to ledger file (atomic write)
- Applied to in-memory state
- Logged to console
Pricing Structure
Creation fees are calculated based on a base fee:- Asset creation: 7.5 units (burned)
- Group creation: 5.0 units (burned)
- Place creation: Free (commented out)
Economy Metrics
The service tracks key metrics:User Count
Economy Size
Currency per User (CCU)
Asset System
The economy service supports asset ownership (currently unused):API Client (TypeScript)
The Site service includes a typed client:Error Handling
Insufficient Balance
Circular Transaction
Stipend Cooldown
Missing Fields
Ledger Integrity
The service validates ledger integrity on startup:- No balance manipulation
- No currency duplication
- Append-only ledger is source of truth
- Stop the economy service
- Edit
data/economy/ledgerto remove invalid lines - Restart the service
- Verify balances with
/balance/:id
Transaction History
Get recent transactions:User Display Transformation
The Site service transforms internal IDs to usernames:Economic Balance
Inflationary Forces
- Stipends: 10 units per user every 12 hours
- Daily rate: ~20 units per active user
Deflationary Forces
- Asset creation: 7.5 units burned per asset
- Group creation: 5.0 units burned per group
Target Economics
Performance Characteristics
Startup Time
O(n) where n = number of transactions in ledger- 1,000 transactions: ~10ms
- 10,000 transactions: ~100ms
- 100,000 transactions: ~1s
Runtime Performance
All operations are O(1) hash map lookups:- Balance query: < 1μs
- Transaction write: < 100μs (file append)
- Transaction history: O(n) scan of ledger
Memory Usage
Approximate memory per user:- Balance: 8 bytes (uint64)
- User ID: ~20 bytes (string)
- Stipend time: 8 bytes (uint64)
Backup and Recovery
Backup
Simply copy the ledger file:Restore
Disaster Recovery
If the ledger is lost but database is intact:- Query all user balances from your records
- Create a new ledger with Mint transactions
- Restart the economy service
Future Enhancements
Potential improvements to the economy system:- Dynamic fees: Adjust based on economy size (TCU target)
- Asset transfers: Use ledger for asset ownership instead of database
- Sharding: Split ledger by time period for faster startup
- Snapshots: Periodic balance snapshots to speed up loading
- Analytics: Transaction graphs, velocity metrics, inflation rate
- Multi-currency: Support for multiple currency types