Contract Architecture
The Native DEX contract is a specialized decentralized exchange built for yield-bearing tokens. Unlike standard AMMs, the AREAL DEX passes through the embedded yield of tokens in liquidity pools to LP providers — on top of regular swap fees. The DEX runs on — all swaps execute with sub-millisecond finality inside the rollup, and LP yield accrual happens in real time. Pool state is periodically committed to Solana L1. The DEX supports two pool types, handles automatic rebalancing of master pools, and serves as the exclusive trading venue for RWT Vault portfolio operations.On-Chain Accounts
PoolState
Main state account for each liquidity pool. Stores pool type (concentrated/standard), token mints, total liquidity, fee parameters, and current price. Seeds:
["pool", token_a_mint, token_b_mint].BinArray
For concentrated pools: stores the bin-based liquidity distribution. Each bin represents a discrete price range with its own liquidity depth. Seeds:
["bins", pool].LpPosition
Represents an individual LP’s liquidity position. Tracks deposited amounts, fee earnings, yield accrued, and the bin range (for concentrated pools). Seeds:
["lp", pool, owner].DexConfig
Global DEX configuration: base fee rate (0.5%), fee split (50/50 LP/DAO), rebalance threshold (1%), and AREAL DAO fee destination. Seeds:
["dex_config"].PoolCreators
Whitelist of wallet addresses authorized to create new liquidity pools. Managed by the Engine Authority (AREAL DAO). Only whitelisted AREAL Foundation team members can call
create_pool. External users cannot create pools. Seeds: ["pool_creators"].Core Instructions
create_pool
create_pool
Creates a new liquidity pool for a token pair. All pairs are denominated in RWT. The pool type (concentrated or standard) is set at creation and cannot be changed.Only wallets whitelisted in
PoolCreators can call this instruction. External users cannot create pools — this is restricted to AREAL Foundation team members who have been granted this right by the DAO.Authority: Whitelisted pool creator onlyupdate_pool_creators
update_pool_creators
Adds or removes wallet addresses from the
PoolCreators whitelist. The AREAL DAO grants pool creation rights to specific Foundation team members. Multiple wallets can be whitelisted simultaneously.Authority: Engine Authority (DAO governance)swap
swap
Executes a token swap through a pool inside the MagicBlock Ephemeral Rollup with sub-millisecond finality. Applies the base fee (0.5%), split between LPs and AREAL DAO. Supports exact-input and exact-output modes. Swap results are committed to Solana L1 on the next commit cycle.Authority: Permissionless
add_liquidity
add_liquidity
Deposits tokens into a pool as a liquidity provider. For concentrated pools, the LP specifies a bin range. For standard pools, liquidity covers the full price range.Authority: Permissionless
remove_liquidity
remove_liquidity
Withdraws liquidity from a pool. Returns tokens to the LP plus any accumulated fees and yield.Authority: LP owner (must sign)
collect_incentives
collect_incentives
Claims accumulated protocol incentive rewards for an LP position. Swap fees and token yield are auto-compounded into the position (withdrawn via
remove_liquidity), but protocol incentive rewards are tracked separately and claimed here.Authority: LP owner (must sign)Pool Types
- Concentrated Liquidity
- Standard Curve
Bin-based pools where liquidity is distributed across discrete price bins. Used exclusively for RWT master pools:
- RWT / USDY — primary pool, 50 bins centered on NAV Book Value
- RWT / USDC — secondary pool, same concentrated structure
rebalance_pool when NAV deviates by >1%. This ensures maximum capital efficiency — deep liquidity exactly where trading occurs.Yield Pass-Through
The AREAL DEX captures the embedded yield of tokens in pools and passes it through to LPs. This means LPs earn from three sources:Swap fees
0.25% of every trade (LP share of the 0.5% base fee) — auto-compounded into the LP position
Token yield
NAV Book Value growth (RWT), real-world yield (OTs), stablecoin yield (USDY) — grows the position value
Protocol incentives
Additional rewards from protocol-level and project-level incentive programs
How LP yield accrual works
LP earnings (swap fees + token yield) are not transferred to the LP’s wallet — instead, they are auto-compounded directly into the LP position, increasing its size. This means the LP’s position grows over time without any manual action — the capital compounds automatically. When the LP callsremove_liquidity, they withdraw their original capital plus all accumulated yield in a single transaction.
This auto-compounding model eliminates the need for LPs to manually collect and reinvest fees. The position grows every second as swaps occur and yield-bearing tokens appreciate inside the pool.
Fee Structure
The DEX applies a base swap fee of 0.5%, split equally — but the two halves are handled differently:| Destination | Share | Mechanism |
|---|---|---|
| Liquidity Providers | 0.25% | Capitalized into LP positions — increases position size automatically, compounding over time |
| AREAL DAO | 0.25% | Transferred directly to the DAO wallet on every swap — immediately available in the Treasury |
The 0.5% base fee is the initial model. A dynamic fee system is in development that will adjust fees based on market conditions, volatility, and pool utilization.
Protocol Liquidity & Auto-Rebalancing
AREAL DAO provides its own liquidity in the master pools through the Master Pool Rebalancer — an independent protocol module that manages protocol-owned LP positions and auto-rebalances them around NAV Book Value.Master Pool Rebalancer
Autonomous protocol module for depositing, rebalancing, and withdrawing DAO liquidity in master pools. Only protocol liquidity is auto-rebalanced — user LP positions are never touched.
The rebalancer is a separate program that interacts with this DEX via CPI. It calls standard
add_liquidity / remove_liquidity instructions — no special access to DEX internals.MagicBlock Integration
The entire DEX execution layer runs on . This is critical for two reasons: real-time swap execution and per-second LP yield accrual.Delegated Accounts
The following accounts are delegated to the Ephemeral Rollup:| Account | Why delegated |
|---|---|
PoolState | Swap execution updates pool reserves and price — must be writable in ER for real-time trading |
BinArray | Concentrated pool bin state changes on every swap — requires ER write access |
LpPosition | Fee and yield accrual is updated on every swap — real-time tracking per LP |
Real-time swaps
All
swap instructions execute inside the Ephemeral Rollup with sub-millisecond finality. Traders experience near-instant execution without waiting for Solana L1 block confirmation.Per-second yield accrual
LP fee earnings and yield-bearing token appreciation are tracked every second inside the ER. When an LP calls
collect_fees, the latest accrued balance is available immediately.Periodic L1 commits
Pool state is committed to Solana L1 on a configurable interval (default every 60 seconds). L1 reflects the latest committed snapshot for external reads and cross-program interactions.
Execution Flow
Account delegation
PoolState, BinArray, and LpPosition accounts are delegated to MagicBlock via the delegation program. They become writable in the ER while remaining readable on L1.Swaps in ER
All
swap calls execute inside the Ephemeral Rollup. Pool reserves, bin state, and LP fee counters are updated in real time with each trade.Yield accrual in ER
The embedded yield of tokens (RWT NAV growth, USDY appreciation, OT yield) is calculated and credited to
LpPosition accounts every second by a crank inside the ER.Non-trading operations like
create_pool, add_liquidity, remove_liquidity, and rebalance_pool execute on Solana L1 — they modify structural state that should be finalized on the base layer. Only high-frequency operations (swaps, fee accrual) run in the Ephemeral Rollup.Security Considerations
Pool immutability
Pool type (concentrated/standard) is set at creation and cannot be changed. Prevents governance manipulation of existing pool mechanics.
Slippage protection
All swaps require a
min_out parameter. Transactions revert if output falls below the specified minimum.External rebalancing
Auto-rebalancing is handled by the Master Pool Rebalancer module — a separate program that only manages DAO capital via CPI. User LP positions are never touched.
RWT denomination
All pools are denominated in RWT. This constrains the DEX to the AREAL ecosystem and prevents unauthorized token listings.
Whitelisted pool creation
Only DAO-whitelisted AREAL Foundation team members can create pools. External users cannot deploy arbitrary pools — preventing spam, scam tokens, and unvetted listings.