Skip to main content

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

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 only
Accounts:
  - creator:             Signer (must be in PoolCreators whitelist)
  - pool_creators:       PDA (whitelist check)
  - pool_state:          PDA (init)
  - bin_array:           PDA (init, concentrated pools only)
  - rebalance_state:     PDA (init, master pools only)
  - dex_config:          PDA
  - token_a_mint:        RWT mint
  - token_b_mint:        Paired token mint
  - system_program

Args:
  - pool_type: enum      { Concentrated, StandardCurve }
  - bin_step: u16         Price step per bin (concentrated only)
  - initial_price: u64    Initial price of token B in token A
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)
Accounts:
  - engine_authority:    Signer (current engine authority)
  - pool_creators:       PDA (mut)

Args:
  - wallet: Pubkey       Team member wallet address
  - action: enum         { Add, Remove }
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
Accounts:
  - user:                Signer
  - pool_state:          PDA (mut)
  - bin_array:           PDA (mut, concentrated only)
  - user_token_a_ata:    User's token A account (mut)
  - user_token_b_ata:    User's token B account (mut)
  - pool_token_a_vault:  Pool's token A vault (mut)
  - pool_token_b_vault:  Pool's token B vault (mut)
  - dao_fee_ata:         AREAL DAO fee destination (mut)
  - token_program

Args:
  - amount: u64          Input or output amount
  - min_out: u64         Minimum output (slippage protection)
  - direction: enum      { AtoB, BtoA }
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
Accounts:
  - lp:                  Signer
  - pool_state:          PDA (mut)
  - bin_array:           PDA (mut, concentrated only)
  - lp_position:         PDA (init or mut)
  - lp_token_a_ata:      LP's token A account (mut)
  - lp_token_b_ata:      LP's token B account (mut)
  - pool_token_a_vault:  Pool's token A vault (mut)
  - pool_token_b_vault:  Pool's token B vault (mut)
  - token_program

Args:
  - amount_a: u64        Token A deposit
  - amount_b: u64        Token B deposit
  - lower_bin: i32       Lower bin ID (concentrated only)
  - upper_bin: i32       Upper bin ID (concentrated only)
Withdraws liquidity from a pool. Returns tokens to the LP plus any accumulated fees and yield.Authority: LP owner (must sign)
Accounts:
  - lp:                  Signer
  - pool_state:          PDA (mut)
  - bin_array:           PDA (mut, concentrated only)
  - lp_position:         PDA (mut)
  - lp_token_a_ata:      LP's token A account (mut)
  - lp_token_b_ata:      LP's token B account (mut)
  - pool_token_a_vault:  Pool's token A vault (mut)
  - pool_token_b_vault:  Pool's token B vault (mut)
  - token_program

Args:
  - liquidity_amount: u64  Amount of liquidity to withdraw (0 = full position)
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)
Accounts:
  - lp:                  Signer
  - lp_position:         PDA (mut)
  - pool_state:          PDA
  - lp_reward_ata:       LP's reward token account (mut)
  - incentive_vault:     Protocol incentive reserve (mut)
  - token_program

Pool Types

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
Liquidity is automatically rebalanced via 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 calls remove_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:
DestinationShareMechanism
Liquidity Providers0.25%Capitalized into LP positions — increases position size automatically, compounding over time
AREAL DAO0.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:
AccountWhy delegated
PoolStateSwap execution updates pool reserves and price — must be writable in ER for real-time trading
BinArrayConcentrated pool bin state changes on every swap — requires ER write access
LpPositionFee 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

1

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.
2

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.
3

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.
4

L1 commit

Periodically, the ER commits all delegated account state back to Solana L1. After commit, collect_fees, remove_liquidity, and rebalance_pool can execute on L1 with up-to-date balances.
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.
The Native DEX contract is currently in development. This documentation describes the target architecture. Contract code has not yet been audited.