A strategic realm-based faction war game built on Solana using Anchor and MagicBlock Ephemeral Rollups.
Players join one of three rival ninja realms. Every player within a realm shares a single collective village — contributing resources, upgrading defenses together, and launching attacks against rival realms. War loot flows back into the shared village, fueling further upgrades. Battle simulations run inside MagicBlock Ephemeral Rollups for high-performance execution, while economic settlement and permanent state remain on Solana L1.
The system is split into two execution layers.
🟢 Solana L1 — Permanent State Layer handles player identity, village structure, realm state, battle declarations, final settlement, and resource accounting. All persistent game state lives here.
⚡ MagicBlock Ephemeral Rollup — Execution Layer handles battle simulation, tick-based combat resolution, damage calculations, critical rolls, and producing the final BattleResult. This allows complex simulations to run off-chain while remaining verifiable, without excessive on-chain compute costs.
The world has three persistent ninja realms. When a player joins they choose a realm — from that point, their village is the realm's shared village.
All players within the same realm collectively contribute war_metal to the shared Base, upgrade the same village structures, and share a realm treasury that receives a cut of every battle victory.
Each realm has a distinct passive bonus:
| Realm | Passive Bonus |
|---|---|
| Realm 0 | +5% attack buff |
| Realm 1 | +5% defense buff |
| Realm 2 | Enhanced resource generation |
Every win or loss shifts the realm-level dominance_score, which gates realm-wide combat buffs for all members.
| Account | Description |
|---|---|
Player |
Permanent player identity, realm allegiance, lifetime stats, and economic resources |
Base |
The realm's shared village — holds upgrade levels, resource rate, and stored war metal. One per realm, not per player. |
Realm |
Geopolitical state including dominance score, treasury, and global combat buffs |
GameConfig |
Global protocol config — rollup authority, battle nonce, and dominance boundaries |
PendingBattle |
Bridge between L1 and Rollup — records a declared battle and its settlement status |
For full field definitions see
programs/ninja-wars/src/state.rs.
These exist only during rollup execution and are never persisted on L1.
| Structure | Description |
|---|---|
BattleSimulation |
Transient tick-by-tick combat state during a battle |
BattleResult |
Final outcome produced by the rollup and passed to L1 for settlement |
Each realm has one shared village represented by the Base account. There are no personal bases — all members build together.
The village passively generates war_metal. Any realm member can call collect_resources to pull it into the shared pool, and any member can spend from that pool via upgrade_base to strengthen the village.
| Slot | Structure | Effect |
|---|---|---|
| 0 | Wall | Increases defensive HP against attackers |
| 1 | Tower | Increases tower damage dealt to attackers |
| 2 | Storage | Increases maximum war metal capacity |
| 3 | Troop Capacity | Increases attacker combat strength |
Upgrade costs are fixed flat values per level. No timers or build queues — upgrades resolve instantly on-chain.
Realm village generates war_metal
↓
Any realm member collects + upgrades structures
↓
Stronger village = better combat stats for all
↓
Players attack rival realm villages
↓
War loot splits — 80% to attacker, 20% to realm treasury
↓
Treasury feeds back into further village upgrades
Realm Village (Base) Player (L1) Ephemeral Rollup L1 Settlement
| | | |
|<-- collect() ------| | |
|<-- upgrade() ------| | |
| (shared by all realm members) | |
| | | |
| |-- declare_attack() -->| |
| | Creates PendingBattle |
| | Snapshots base versions |
| | | |
| | Load Base levels |
| | Apply Realm buffs |
| | Run tick simulation |
| | Produce BattleResult |
| | | |
| | |-- settle_battle() ----->|
| | Verify rollup authority
| | Verify base versions
| | Split loot → player + realm treasury
| | Update realm dominance
| | Mark battle settled
- Solana — Layer 1 blockchain
- Anchor — Solana smart contract framework
- MagicBlock — Ephemeral Rollup infrastructure
