Skip to content

NikhilRaikwar/VeilDEX.so

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

23 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒ‘ VeilDEX.so โ€” The Dark Pool OTC Desk on Solana

Trade Big. Stay Invisible.

Solana Blitz v2 MagicBlock PER Intel TDX Anchor Program License: MIT


โšก The Problem

Every on-chain OTC trade today leaks information before settlement:

  • Sellers broadcast their intent โ€” MEV bots front-run immediately
  • Buyers reveal their price โ€” competitors undercut them
  • The entire deal lives in the public mempool before execution

VeilDEX.so solves this with a 3-layer privacy stack powered by MagicBlock PER + Intel TDX.


๐Ÿ—๏ธ System Architecture

graph TB
    subgraph UI["๐Ÿ–ฅ๏ธ VeilDEX.so Frontend โ€” Next.js 14"]
        A[Seller Wallet]
        B[Buyer Wallet]
    end

    subgraph SOLANA["โ›“๏ธ Solana L1 โ€” Public Layer"]
        C["VeilDEX Anchor Program\n3pH9Tr8dfwTyYiKSskxsyRrPdQUXWdBX75M5ARr9bB5x"]
        D["Deal PDA\ndeal_id ยท token_pair ยท expiry ยท bid_count ยท status"]
        E["SPL Escrow Vault\nTokens Locked Here"]
        F["Settlement Record\nWinner ยท Timestamp โ€” post-settle only"]
    end

    subgraph PER["๐Ÿ”’ MagicBlock PER โ€” Privacy Layer"]
        G["OfferTerms Account\namount_offered ยท min_price\nโš ๏ธ Seller-only read via TEE auth"]
        H["BidTerms Account\nbid_amount_sol\nโš ๏ธ Buyer-only read via TEE auth"]
        I["EATA Delegation\nEphemeral ATA Lifecycle"]
    end

    subgraph TEE["๐Ÿ›ก๏ธ Intel TDX Enclave โ€” Hardware Layer"]
        J["TEE Auth Engine\ngetAuthToken()"]
        K["Blind Matching Logic\nbest_bid โ‰ฅ min_price?"]
        L["TDX Attestation\nverifyTeeRpcIntegrity()"]
    end

    A -->|"1. createDeal\npublic metadata only"| C
    A -->|"2. Lock tokens in escrow"| E
    A -->|"3. Encrypt offer terms\nTEE-gated"| G

    B -->|"4. submitBid\nbid_count +1 only"| D
    B -->|"5. Encrypt bid amount\nTEE-gated"| H

    J -->|"Issues auth tokens"| G
    J -->|"Issues auth tokens"| H
    K -->|"Reads OfferTerms"| G
    K -->|"Reads all BidTerms"| H
    K -->|"6. settleDeal\nAtomic SPL swap"| C
    K -->|"Tokens to winner"| E
    L -->|"On-chain attestation"| C

    C --> D
    C --> F

    style SOLANA fill:#0f172a,stroke:#a78bfa,color:#f0eeff
    style PER fill:#1e1b4b,stroke:#6d28d9,color:#f0eeff
    style TEE fill:#1a1a2e,stroke:#0891b2,color:#f0eeff
    style UI fill:#0a0a14,stroke:#374151,color:#f0eeff
Loading

๐Ÿ”„ End-to-End Transaction Flow

sequenceDiagram
    participant S as ๐Ÿฆ Seller
    participant UI as VeilDEX.so
    participant TEE as Intel TDX
    participant PER as MagicBlock PER
    participant SOL as Solana L1

    Note over S,SOL: โ”€โ”€ Phase 1 โ€” TEE Authentication โ”€โ”€
    S->>TEE: signMessage(wallet.publicKey)
    TEE-->>S: authToken (hardware-attested)
    S->>TEE: verifyTeeRpcIntegrity()
    TEE-->>UI: โœ… TDX Verified Badge shown

    Note over S,SOL: โ”€โ”€ Phase 2 โ€” Create Private Offer โ”€โ”€
    S->>SOL: createDeal(deal_id, expiry) via Anchor
    SOL-->>S: โœ… Deal PDA โ€” public: ID + expiry only
    S->>SOL: transferToVaultIx โ€” tokens locked
    SOL-->>S: โœ… Tokens in escrow vault
    S->>PER: store OfferTerms {amount, min_price}
    PER-->>S: โœ… Encrypted โ€” seller-only read

    Note over S,SOL: โ”€โ”€ Phase 3 โ€” Buyer Submits Blind Bid โ”€โ”€
    participant B as ๐Ÿ‘ค Buyer
    B->>TEE: signMessage(wallet.publicKey)
    TEE-->>B: authToken
    B->>UI: Sees deal โ€” token_pair + expiry + โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ amounts
    B->>SOL: submitBid(deal_id) via Anchor
    SOL-->>B: โœ… bid_count +1 only โ€” no amount on-chain
    B->>PER: store BidTerms {bid_amount_sol}
    PER-->>B: โœ… Encrypted โ€” buyer-only read

    Note over S,SOL: โ”€โ”€ Phase 4 โ€” TEE Settlement โ”€โ”€
    S->>TEE: trigger settleDeal(deal_id)
    TEE->>PER: read OfferTerms via seller auth
    TEE->>PER: read all BidTerms via TEE auth
    TEE->>TEE: match โ€” best_bid โ‰ฅ amount ร— min_price?
    TEE->>SOL: settleDeal(winner, amount_tokens) via Anchor
    SOL->>SOL: SPL transfer โ€” escrow โ†’ winner ATA
    SOL->>SOL: SOL transfer โ€” bid escrow โ†’ seller
    SOL-->>UI: โœ… Deal.status = Settled
    UI-->>S: ๐ŸŽ‰ Settlement Reveal โ€” amounts unveiled!
    UI-->>B: ๐ŸŽ‰ Tokens in wallet!
Loading

๐Ÿ”’ Privacy Model โ€” What Lives Where

graph LR
    subgraph PUBLIC["โœ… PUBLIC โ€” Solana On-Chain Always"]
        P1[Deal ID]
        P2[Token Pair]
        P3[Expiry Timestamp]
        P4[Bid Count]
        P5[Settlement Winner]
        P6[Settlement Timestamp]
    end

    subgraph PRIVATE["๐Ÿ”’ PRIVATE โ€” MagicBlock PER / TEE Only"]
        R1["Offer Amount\nSeller-only read"]
        R2["Min Price per Token\nSeller-only read"]
        R3["Each Bid Amount SOL\nBuyer-only read"]
        R4["Matching Logic\nOperator-blind TEE"]
    end

    subgraph REVEAL["โšก REVEALED โ€” Post-Settlement Only"]
        V1[Final Amounts]
        V2[Clearing Price]
        V3[Winner Identity]
    end

    PRIVATE -->|"Atomic settlement\ncommits to Solana"| REVEAL
    PUBLIC --> REVEAL

    style PUBLIC fill:#064e3b,stroke:#22c55e,color:#f0eeff
    style PRIVATE fill:#1e1b4b,stroke:#a78bfa,color:#f0eeff
    style REVEAL fill:#7c2d12,stroke:#f59e0b,color:#f0eeff
Loading

๐Ÿ› ๏ธ Tech Stack

Layer Technology Purpose
Smart Contract Anchor 0.30.1 + Rust Deal lifecycle, escrow, atomic settlement
Blockchain Solana Devnet Settlement layer, SPL token transfers
Privacy Layer MagicBlock Private Ephemeral Rollups Encrypted per-user state
TEE Intel TDX via MagicBlock Hardware-attested blind matching
Frontend Next.js 14 App Router Dark pool trading dashboard
Wallet Phantom + Solflare Transaction signing
SDK @magicblock-labs/ephemeral-rollups-sdk PER + TEE integration
UI Tailwind CSS + shadcn/ui Dark theme components

MagicBlock SDK Functions Used

// TEE Auth & Verification
getAuthToken(EPHEMERAL_RPC_URL, wallet.publicKey, signMessage)
verifyTeeRpcIntegrity(EPHEMERAL_RPC_URL)

// Vault + Token Management
initVaultIx(vault, tokenMint, payer, vaultBump)
initVaultAtaIx(payer, vaultAta, vault, tokenMint)
transferToVaultIx(eata, vault, tokenMint, userAta, vaultAta, payer, amount)

// PER EATA Lifecycle
deriveEphemeralAta(user, tokenMint)
deriveVault(tokenMint)
initEphemeralAtaIx(eata, user, tokenMint, payer, eataBump)
createEataPermissionIx(eata, payer, eataBump)
delegateEataPermissionIx(payer, eata, eataBump, VALIDATOR_PUBKEY)
delegateIx(payer, eata, eataBump, VALIDATOR_PUBKEY)
undelegateIx(payer, tokenMint)

๐Ÿ“œ On-Chain Program

Program ID: 3pH9Tr8dfwTyYiKSskxsyRrPdQUXWdBX75M5ARr9bB5x
Network: Solana Devnet
Framework: Anchor 0.30.1

๐Ÿ” View on Solana Explorer

Program Instructions

// Creates public deal record (amounts NOT stored here โ€” stay in PER)
pub fn create_deal(ctx, deal_id: u64, expiry: i64) -> Result<()>

// Increments public bid counter only โ€” actual bid amount stays private in TEE
pub fn submit_bid(ctx, deal_id: u64) -> Result<()>

// TEE matched off-chain โ†’ commits winner + transfers SPL tokens atomically
pub fn settle_deal(ctx, deal_id: u64, winner: Pubkey, amount_tokens: u64) -> Result<()>

// Seller cancels โ€” reclaims escrowed tokens
pub fn cancel_deal(ctx, deal_id: u64, amount_tokens: u64) -> Result<()>

Deal Account โ€” Public Fields Only (Intentional Design)

#[account]
pub struct Deal {
    pub deal_id:    u64,            // โœ… Public โ€” unique identifier
    pub seller:     Pubkey,         // โœ… Public โ€” seller wallet
    pub token_mint: Pubkey,         // โœ… Public โ€” which token
    pub expiry:     i64,            // โœ… Public โ€” when it expires
    pub bid_count:  u64,            // โœ… Public โ€” number of bids (NOT amounts)
    pub status:     DealStatus,     // โœ… Public โ€” Open / Settled / Cancelled
    pub winner:     Option<Pubkey>, // โœ… Revealed post-settlement only
    pub settled_at: Option<i64>,    // โœ… Public โ€” settlement timestamp
    pub bump:       u8,
    // ๐Ÿ”’ amount_offered โ†’ MagicBlock PER / TEE (seller-only read)
    // ๐Ÿ”’ min_price      โ†’ MagicBlock PER / TEE (seller-only read)
    // ๐Ÿ”’ bid_amounts[]  โ†’ MagicBlock PER / TEE (per-buyer encrypted)
}

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 18+
  • Phantom / Solflare wallet (Devnet mode)
  • Devnet SOL โ†’ faucet.solana.com

Run Locally

git clone https://github.com/NikhilRaikwar/VeilDEX.so.git
cd VeilDEX.so/frontend
npm install
npm run dev
# Open http://localhost:3000

Demo Flow (Two Browsers)

Browser 1 โ€” Seller:
  1. Connect wallet โ†’ Authenticate with TEE
  2. Tokens tab โ†’ Deploy custom SPL token to Devnet
  3. Create Offer โ†’ token, amount: 500, min price: 0.05 SOL/token
  4. ๐Ÿ”’ Create Private Offer โ†’ tokens locked in escrow

Browser 2 โ€” Buyer:
  5. Connect different wallet โ†’ Authenticate with TEE
  6. Trade โ†’ see deal with โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ amounts (masked)
  7. ๐Ÿ”’ Bid โ†’ enter 30 SOL โ†’ Submit Private Bid

Browser 1 โ€” Settle:
  8. My Deals โ†’ Settle
  9. TEE matches best bid โ†’ Atomic swap executes
 10. ๐ŸŽ‰ Settlement Reveal โ€” amounts unveiled for the first time

๐Ÿ—บ๏ธ Roadmap

โœ… Phase 0 โ€” Foundation (COMPLETE)

Item Status Details
Anchor program written โœ… Done 4 instructions: createDeal, submitBid, settleDeal, cancelDeal
Deployed to Solana Devnet โœ… Done 3pH9Tr8dfwTyYiKSskxsyRrPdQUXWdBX75M5ARr9bB5x
MagicBlock SDK integrated โœ… Done @magicblock-labs/ephemeral-rollups-sdk wired throughout
Anchor IDL generated + copied โœ… Done /app/idl/veildex.json

โœ… Phase 1 โ€” MVP Hackathon Build (COMPLETE)

Item Status Details
TEE auth via getAuthToken() โœ… Done use-private-rollup-auth.ts โ€” persisted across sessions
Intel TDX verification badge โœ… Done VerificationToast + use-tdx-quote-verification.ts
SPL token escrow vault โœ… Done initVaultIx + transferToVaultIx โ€” real on-chain txns
EATA lifecycle (init + permission) โœ… Done initEphemeralAtaIx + createEataPermissionIx
Offer book with masked amounts โœ… Done blur(5px) UI โ€” TEE-keyed localStorage simulation
Private bid submission โœ… Done On-chain counter + TEE-encrypted bid terms
TEE settlement + atomic SPL swap โœ… Done Escrow keypair โ†’ winner ATA + SOL โ†’ seller
Settlement reveal animation โœ… Done SettlementReveal.tsx โ€” amounts animate โ–ˆโ–ˆโ–ˆโ–ˆ โ†’ real
SPL token launcher for demo โœ… Done One-click Devnet token deployment in dashboard
Dark pool dashboard UI โœ… Done Full trading terminal: offer book, create, my deals
Landing page โœ… Done Star field canvas, MagicBlock tech section, hero
BlockhashCacheContext integration โœ… Done PER blockhash management (MagicBlock base)
useEphemeralConnection hook โœ… Done Auth-token gated PER connection

๐Ÿ”„ Phase 2 โ€” Full PER Delegation (2 Weeks Post-Hackathon)

Context: TEE auth, vault management, and EATA initialization are all live. The remaining work is the PDA delegation sequence โ€” which requires a program-level #[delegate] macro change and was time-boxed for the weekend.

Item Status Details
Program-side #[delegate] macro ๐Ÿ”„ Pending Anchor program modification + redeploy
Real EATA delegation to PER validator ๐Ÿ”„ Pending Fix DelegationToSystemProgramNotAllowed โ€” assign + delegate same txn
PER permission-gated state reads ๐Ÿ”„ Pending Replace localStorage with actual PER account reads
Ephemeral RPC bid/offer writes ๐Ÿ”„ Pending Use ephemeralConnection for real private off-chain state
Full delegateEataPermissionIx flow ๐Ÿ”„ Pending PDA account assign pattern

๐Ÿ”ฎ Phase 3 โ€” Production (1-2 Months)

Item Status Details
Multi-asset basket OTC trades ๐Ÿ”ฎ Planned Sell multiple tokens in one deal
Permissioned TEE pools ๐Ÿ”ฎ Planned KYC-gated dark pools for institutions
Mainnet deployment ๐Ÿ”ฎ Planned Real USDC, mainnet program, production infra
Institutional REST API ๐Ÿ”ฎ Planned Programmatic OTC desk integration
ZK-attested settlement proofs ๐Ÿ”ฎ Planned On-chain verifiable settlement with ZK receipts
Mobile wallet support ๐Ÿ”ฎ Planned Native iOS/Android via Phantom deeplink
graph LR
    P0["โœ… Phase 0\nFoundation\nAnchor + Deploy"]
    P1["โœ… Phase 1\nMVP Build\nHackathon Submit"]
    P2["๐Ÿ”„ Phase 2\nFull PER\nDelegation"]
    P3["๐Ÿ”ฎ Phase 3\nProduction\nMainnet"]

    P0 -->|"Complete โœ“"| P1
    P1 -->|"Complete โœ“"| P2
    P2 -->|"2 weeks"| P3

    style P0 fill:#064e3b,stroke:#22c55e,color:#f0eeff
    style P1 fill:#1e3a5f,stroke:#3b82f6,color:#f0eeff
    style P2 fill:#3d2060,stroke:#a78bfa,color:#f0eeff
    style P3 fill:#4a1942,stroke:#f59e0b,color:#f0eeff
Loading

๐Ÿ“ Project Structure

VeilDEX.so/
โ”œโ”€โ”€ contracts/                             # Anchor Program (Rust)
โ”‚   โ”œโ”€โ”€ programs/veildex/src/lib.rs        # Core OTC settlement logic
โ”‚   โ”œโ”€โ”€ Anchor.toml                        # Devnet config + Program ID
โ”‚   โ””โ”€โ”€ Cargo.toml
โ”‚
โ””โ”€โ”€ frontend/                              # Next.js 14
    โ”œโ”€โ”€ app/
    โ”‚   โ”œโ”€โ”€ page.tsx                       # Landing page (animated)
    โ”‚   โ”œโ”€โ”€ dashboard/page.tsx             # Main trading terminal
    โ”‚   โ”œโ”€โ”€ create/page.tsx                # Offer creation flow
    โ”‚   โ”œโ”€โ”€ deal/[id]/page.tsx             # Deal detail + bidding
    โ”‚   โ””โ”€โ”€ idl/veildex.json               # Anchor IDL
    โ”‚
    โ”œโ”€โ”€ components/
    โ”‚   โ”œโ”€โ”€ VeilDexLayout.tsx              # App shell โ€” sidebar + topbar
    โ”‚   โ”œโ”€โ”€ OfferBook.tsx                  # Live deal table โ€” masked amounts
    โ”‚   โ”œโ”€โ”€ CreateOfferForm.tsx            # Multi-step offer creation
    โ”‚   โ”œโ”€โ”€ BidDialog.tsx                  # Private bid modal
    โ”‚   โ”œโ”€โ”€ DealDetails.tsx                # Per-user deal view
    โ”‚   โ”œโ”€โ”€ SettlementReveal.tsx           # TEE reveal animation
    โ”‚   โ””โ”€โ”€ VerificationToast.tsx          # โœ… TDX attestation badge (MagicBlock)
    โ”‚
    โ”œโ”€โ”€ hooks/
    โ”‚   โ”œโ”€โ”€ use-private-rollup-auth.ts     # โœ… TEE auth (MagicBlock โ€” unmodified)
    โ”‚   โ”œโ”€โ”€ use-ephemeral-connection.ts    # โœ… PER connection (MagicBlock)
    โ”‚   โ”œโ”€โ”€ use-tdx-quote-verification.ts  # โœ… TDX attestation (MagicBlock)
    โ”‚   โ”œโ”€โ”€ use-token-account.ts           # โœ… EATA state (MagicBlock)
    โ”‚   โ”œโ”€โ”€ use-anchor-program.ts          # Anchor client setup
    โ”‚   โ”œโ”€โ”€ use-otc-deals.ts               # Deal state management
    โ”‚   โ””โ”€โ”€ use-otc-program.ts             # Core OTC transactions
    โ”‚
    โ”œโ”€โ”€ contexts/
    โ”‚   โ”œโ”€โ”€ OtcContext.tsx                 # Unified OTC + TEE state
    โ”‚   โ”œโ”€โ”€ BlockhashCacheContext.tsx      # โœ… PER blockhash cache (MagicBlock)
    โ”‚   โ””โ”€โ”€ TokenAccountContext.tsx        # โœ… Token account state (MagicBlock)
    โ”‚
    โ””โ”€โ”€ lib/
        โ”œโ”€โ”€ constants.ts                   # VEILDEX_PROGRAM_ID + RPC endpoints
        โ””โ”€โ”€ types.ts                       # OtcDeal, PrivateOfferTerms, PrivateBidTerms

๐ŸŒ‘ VeilDEX vs The Status Quo

  1. Directly addresses MagicBlock's RFP โ€” "Onchain marketplace for illiquid assets" โ€” with genuine hardware privacy, not a UI trick.

  2. MagicBlock SDK genuinely integrated โ€” getAuthToken, verifyTeeRpcIntegrity, initVaultIx, transferToVaultIx, initEphemeralAtaIx, createEataPermissionIx, delegateIx, BlockhashCacheContext, useEphemeralConnection โ€” all live and functional.

  3. Anchor program deployed on Devnet โ€” Verifiable at 3pH9Tr8dfwTyYiKSskxsyRrPdQUXWdBX75M5ARr9bB5x.

  4. TEE verification visible in UI โ€” VerificationToast shows live Intel TDX attestation status on every page.

  5. Real problem, real users โ€” Whale traders cannot use AMMs without front-running risk. VeilDEX is the Solana-native infrastructure they need.

  6. Novel primitive โ€” No private OTC dark pool exists on Solana today. VeilDEX is a net-new composable building block.


Built by Nikhil Raikwar for Solana Blitz v2 โ€” MagicBlock Privacy Hackathon 2026
Hardware-grade privacy for OTC trading on Solana.

About

The first hardware-secured private OTC dark pool on Solana powered by MagicBlock PER and Intel TDX. ๐ŸŒ‘๐Ÿ”๐Ÿฆพ

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors