Kompwnd
A high-frequency yield compounding protocol with graph-based referral structures on Alacrity.
Architecture Overview
A heavy Event-Sourced architecture. We used 'Demux' to listen to the Alacrity blockchain deterministically. Staking actions trigger complex graph traversals in Neo4j to calculate multi-level bonuses, which are then written back to the user's ledger.
The Challenges
Problem
The client proposed a 'Binary Marketing' structure: Users earn bonuses based on the balanced volume of their 'Left' and 'Right' referral legs. Calculating this recursively for thousands of users in a relational DB (SQL) would be too slow.
Solution
Used Neo4j (Graph Database) to model the user hierarchy. We wrote optimized Cypher queries to traverse the tree, calculate the `weak_leg_volume`, apply the commission cap, and distribute 'Matching Bonuses' in O(log n) time whenever a downline user deposits.
binary-bonus.service.ts
Problem
EOSIO-based chains have micro-forks (reversible blocks). If we credited a bonus on a block that later got orphaned, the platform would lose money.
Solution
Implemented the `Demux` pattern (Deterministic Multiplexer). The backend indexes blockchain events sequentially. If a fork is detected, the system automatically rolls back the Neo4j/MongoDB state to the last 'Irreversible Block' and re-plays the new valid history, ensuring zero ledger drift.
object-action-handler.ts
Problem
Users wanted to 'Compound' (Restake) rewards without paying the gas/tax of withdrawing and re-depositing. This required moving funds between internal contract buckets atomically.
Solution
Engineered a smart contract `roll()` action. It checks the `claimable_rewards`, verifies the `15-minute` cooldown, and atomically moves the asset from the 'Payout Pool' to the 'Staking Pool' in a single transaction. This triggers a virtual 'Deposit Event' which feeds back into the Binary Bonus engine, creating a recursive reward loop.
kompwnd.cpp