Architecture
NeutronX is built on CometBFT and the Cosmos SDK. CometBFT handles consensus and block order; Cosmos SDK modules hold the trading logic. The key feature: the order book and the oracle are built into block production itself.
Stack
| Layer | What it does |
|---|---|
| CometBFT v0.39 | Consensus, transaction order, single-block finality. ABCI++ lets the application take part in building the block |
| Cosmos SDK v0.54 | State modules: subaccounts, orders, oracle, governance, staking, IBC |
| Storage | State lives in an IAVL tree. The order book and positions are also kept in memory and rebuilt from state |
Block lifecycle
- Prices. In the previous block every validator signs a vote extension with prices from its oracle sidecar.
- Building. The proposer aggregates the prices (stake-weighted median) and matches orders from the mempool. It places the result as the first transaction of the block: prices, validator signatures, trades and evidence of wrong prices.
- Verification. Every validator re-checks the first transaction: signatures, the median and the trades. Any mismatch rejects the block.
- Start of execution. The new prices are applied, then the trades are settled: margin, fees, positions. Trades are therefore settled before the transactions that created them run.
- User transactions. They run in order. An order picks up its already settled fills; the remainder rests on the book or is cancelled according to its time-in-force.
- End of block. Protocol processes run in a fixed order, see below.
End of block
- Orders of transactions that failed after matching are recorded: their fills stand.
- Short-term and good-til-block orders and agent keys expire.
- Funding prices are recorded: mark from the book, index from the oracle.
- Liquidations.
- Delisted markets are settled; markets with a frozen price are auto-paused, and pairs without votes get the circuit breaker.
- Route deposits from IBC and vault quotes.
- Chase orders are repriced, promo vouchers expire, old records are pruned.
- Conditional orders, then TWAP and POV.
- Funding for markets whose interval has come.
- The in-memory book is rebuilt, orders without margin and post-only orders that would take liquidity are removed, invariants are checked. If an invariant breaks, trading stops.
The order matters. For example, liquidations run before conditional orders: if a liquidation and a stop-loss both trigger in the same block, the liquidation goes first.
The first transaction of a block
The proposer builds it, not a user. It carries the prices, the signed vote extensions, the evidence and the trades. It has no signatures and cannot be sent from outside: every validator checks its content.
The authority field holds the address of the governance module. This is a formal protobuf requirement, not a transaction from governance. Explorers should show it as a consensus batch confirmed by the validators.
Determinism
Every validator must reach a bit-for-bit identical state. Calculations therefore use fixed-point numbers only, data is iterated in sorted order, time comes only from the block header and never from the node's clock, and a block's prices are fixed by the votes of the previous block.