Solana order book, zero-copy market primitives in MagicBlock ephemeral rollup.
Giuseppe is an exchange-oriented Solana program written in low-level Rust with Pinocchio. It is building toward a CLOB architecture where custody and durable state live on Solana L1, while the order book can be delegated to MagicBlock ephemeral rollups for lower-latency execution.
π¨ This repository is not a finished end-user DEX yet. It is the exchange kernel: the part that matters most for correctness, latency, and long-term architecture.
- Why Giuseppe
- What Exists Today
- Architecture
- Repository Layout
- Current Instruction Surface
- Software Architecture Gains
- Testing
- Known Gaps
- Getting Started
- Roadmap
- References
Most on-chain exchange projects talk about performance after they already committed to a slow or hard-to-evolve contract shape. Giuseppe starts at the opposite end.
It is designed around:
- a reusable matching engine instead of instruction-coupled business logic,
- zero-copy fixed-layout state instead of heavy serialization,
- explicit locked/free balance accounting,
- and a first-class L1-to-ephemeral-rollup lifecycle instead of bolted-on scaling later.
The current repository implements a meaningful slice of the exchange stack.
- Program entrypoint and instruction dispatch
- Market initialization path
- IOC taker
Swapflow - FIFO price-time-priority matching engine
- Zero-copy market header and in-account order book state
- Trader balance accounting for locked/free lots
- MagicBlock delegation, commit, and undelegation instruction hooks
- Unit tests for matching behavior
- LiteSVM integration tests for end-to-end swap execution
- Production-grade market initialization
- Full maker lifecycle
- Deposit and withdrawal flows
- Limit-order placement and cancellation instructions
- Internal persistent balance ledger
- Finalized delegated-market PDA and authority model
So the right way to read this repo is:
implemented exchange core, incomplete product surface
Giuseppe is structured around a clean split between matching, settlement, and delegated execution.
+----------------------------------+
| Solana L1 (durable) |
|----------------------------------|
| market config |
| vault custody |
| fee accounting |
| final committed state |
+----------------+-----------------+
|
| delegate / commit / undelegate
|
+----------------v-----------------+
| MagicBlock Ephemeral Rollup |
|----------------------------------|
| low-latency market execution |
| mutable order book state |
| fast matching path |
+----------------------------------+
This module contains the exchange core:
- walks the opposite side of the book,
- enforces price crossing,
- applies FIFO priority,
- computes fill amounts,
- updates maker state,
- returns aggregate matching results.
It does not own account parsing or token transfer logic. That separation is one of the strongest parts of the repository.
The Swap instruction is intentionally thin:
- validate accounts and market header,
- load zero-copy state,
- call the matcher,
- apply fill thresholds,
- compute taker fees,
- settle SPL token transfers,
- update fee counters and sequence state.
Matching is business logic. Settlement is chain interaction. Giuseppe separates those layers correctly.
This file defines durable market metadata:
- market status,
- size configuration,
- base/quote token parameters,
- fee recipient,
- sequence number,
- lot and tick configuration.
src/state/fifo.rs
src/state/trader_state.rs
The order book uses FIFO semantics over typed order IDs and resting orders, with trader state tracking:
- locked quote lots,
- free quote lots,
- locked base lots,
- free base lots.
That balance model is essential for any serious exchange implementation.
src/instructions/delegate_book.rs
src/instructions/commit_book.rs
src/instructions/undelegate_book.rs
These instructions already model the intended runtime lifecycle:
- delegate market state to MagicBlock,
- commit delegated state back to L1,
- undelegate and return ownership,
- handle the callback path.
.
βββ src/
β βββ engine/ # matching engine and engine tests
β βββ instructions/ # initialize, swap, delegate/commit/undelegate
β βββ macros/ # typed wrappers and enum helpers
β βββ state/ # market header, order book, trader state, enums
β βββ tests/ # LiteSVM integration tests
β βββ lib.rs # program entrypoint
βββ research/
β βββ EXCHANGE_DESIGN_V1.md
βββ tests/
β βββ devnet_initialize.rs
βββ Cargo.toml
βββ README.md
From src/instructions/mod.rs:
| Instruction | Purpose |
|---|---|
Initialize |
Set up market state and vault structure |
Swap |
IOC taker flow over the current book |
DelegateBook |
Move market account into delegated execution |
CommitBook |
Sync delegated market state back to L1 |
UndelegateBook |
Return delegated market to L1 ownership |
UndelegationCallback |
Finalize undelegation callback flow |
This is where the repository is strongest.
The state layer uses #[repr(C)], Pod, fixed-size wrappers, and direct byte casting. That gives:
- predictable layout,
- lower overhead,
- easier account sizing,
- and a more realistic base for performance-sensitive trading logic.
The locked/free split in TraderState gives the codebase a clean foundation for:
- reservations,
- execution,
- settlement,
- cancellations,
- and eventual withdrawal flows.
By separating matching from token movement, Giuseppe can evolve toward:
- L1 execution,
- delegated execution,
- and simulation environments
without rewriting the exchange rules each time.
Most projects write a monolithic contract first and only later discover that rollup delegation changes everything. Giuseppe already includes delegation lifecycle instructions, which is a major architectural advantage.
The repository has real verification coverage, not just notes and stubs.
src/engine/tests.rs covers:
- full fills,
- partial fills,
- multi-level sweeps,
- non-crossing orders,
- empty book behavior,
- match limits,
- quote-budget caps,
- taker fee math.
src/tests/swap_integration.rs validates:
- market account construction,
- seeded resting liquidity,
- vault token account setup,
- IOC swap execution through LiteSVM,
- actual token balance changes after settlement.
src/tests/initialize_market.rs also captures the fact that initialization is still incomplete while ensuring the path is at least structurally exercised.
- Rust
- Cargo
- Solana-compatible toolchain for building/testing dependencies
cargo testsrc/lib.rssrc/instructions/swap.rssrc/engine/matching.rssrc/state/market_header.rssrc/state/fifo.rsresearch/EXCHANGE_DESIGN_V1.md
The next high-value milestones are straightforward:
- Finish and harden market initialization.
- Add deposits, withdrawals, and maker seat lifecycle.
- Implement limit-order placement and cancellation.
- Replace manually seeded liquidity in integration tests with natural instruction flows.
- Harden delegated market PDA derivation and authority checks.
- Add richer event and receipt structures for fills and settlement.
