A privacy-preserving decentralized exchange with MEV protection powered by iExec DataProtector
Demo Video β’ Features β’ Quick Start β’ Documentation
Built for iExec Confidential DeFi Hackathon
| Criteria | Implementation |
|---|---|
| β Deployed on Arbitrum Sepolia | View on Arbiscan |
| β iExec DataProtector Integration | Order encryption for MEV protection (details) |
| β Real-World DeFi Problem | Solves front-running & sandwich attacks |
| β Code Quality | TypeScript, Foundry, OpenZeppelin, comprehensive docs |
| β User Experience | Modern UI, real-time updates, intuitive flow |
| π Feedback Document | FEEDBACK.md |
ShadowSwap is a next-generation decentralized exchange that combines batch auctions with confidential computing to provide:
- MEV Protection: Orders are encrypted using iExec DataProtector, preventing front-running and sandwich attacks
- Fair Price Discovery: Batch auction mechanism ensures uniform clearing price for all orders
- Limit Orders: Set target prices and let the automated keeper bot execute when conditions are met
- Instant Swaps: Real-time swaps with live price feeds for immediate execution
Traditional DEXs suffer from:
- Front-running: Validators/miners can see pending transactions and extract value
- Sandwich attacks: Attackers profit by placing orders before and after user transactions
- Poor price execution: Individual trades can significantly impact prices
ShadowSwap addresses these issues by:
- Encrypting orders with iExec DataProtector before on-chain submission
- Batching orders to execute at a single clearing price
- Automated execution via keeper bot when limit order conditions are met
| Feature | Description |
|---|---|
| π Confidential Orders | Orders encrypted with iExec DataProtector |
| π Batch Auctions | Fair price discovery through order batching |
| β‘ Instant Swaps | Real-time swaps with live CoinGecko prices |
| π Limit Orders | Set target prices with automatic execution |
| π€ Keeper Bot | Automated price monitoring and order execution |
| π± Modern UI | Beautiful, responsive interface with dark mode |
| π Transaction History | Persistent history synced from blockchain |
| π Analytics Dashboard | Real-time DEX statistics and metrics |
ShadowSwap leverages iExec DataProtector for order confidentiality:
βββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββ
β User Order ββββββΆβ iExec DataProt ββββββΆβ ShadowPool ββββββΆβ Batch β
β (Plain) β β (Encrypt) β β (On-chain) β β Settlement β
βββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββ
β β β β
βΌ βΌ βΌ βΌ
- tokenIn Encrypted blob Store encrypted Decrypt & match
- tokenOut + dataset addr Wait for batch at uniform price
- amountIn
- limitPrice
Why iExec DataProtector?
| Without Encryption | With iExec DataProtector |
|---|---|
| β Order visible in mempool | β Order details hidden |
| β Validators can front-run | β No front-running possible |
| β Sandwich attacks possible | β Attack impossible without data |
| β Poor execution price | β Fair batch settlement |
Technical Implementation:
// frontend/src/lib/encryption.ts
import { IExecDataProtector } from '@iexec/dataprotector';
const protectedData = await dataProtector.protectData({
data: {
tokenIn: order.tokenIn,
tokenOut: order.tokenOut,
amountIn: order.amountIn.toString(),
limitPrice: order.limitPrice.toString(),
},
name: `ShadowSwap-Order-${Date.now()}`,
});iExec iApp (TEE Application):
The order processor iApp runs inside Intel SGX enclaves to decrypt and process orders:
iexec-app/src/app.js β Deployed iApp: 0x834255dF01eE89d5096371a7eeFaF4332d4e2bfF
Docker Image: cryptoeights/shadowswap-order-processor:1.0.0-tee-scone-5.9.1-v16-prod-59e7aa07604b
The iApp handles:
- Decrypting order data inside TEE (invisible to outside)
- Validating order parameters (tokens, amounts, prices)
- Matching orders at uniform clearing price
- Outputting settlement results
π Full iExec Integration | π iApp Deployment Guide | π Feedback
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (Next.js) β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββββββββββ β
β β Swap β β Limit β βDashboard β β Analytics β β
β β Card β β Orders β β β β β β
β ββββββ¬ββββββ ββββββ¬ββββββ ββββββ¬ββββββ ββββββββββ¬ββββββββββ β
β β β β β β
β βΌ βΌ β β β
β ββββββββββββββββββββββββββββ β β β
β β iExec DataProtector SDK β β β β
β β β’ protectData() β β β β
β β β’ grantAccess() β β β β
β ββββββββββββββ¬ββββββββββββββ β β β
βββββββββββββββββΌβββββββββββββββββββΌβββββββββββββββββββΌββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Smart Contracts (Arbitrum Sepolia) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β ShadowPool β β
β β β’ submitOrder() β’ instantSwap() β β
β β β’ submitLimitOrder() β’ executeLimitOrder() β β
β β β’ triggerBatch() β’ cancelOrder() β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β βββββββββββββββββ βββββββββββββββββ βββββββββββββββββββββ β
β β MockPriceFeed β β Mock ERC20 β β MockWETH/mETH β β
β βββββββββββββββββ βββββββββββββββββ βββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β² β
β βΌ
βββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β iExec iApp (TEE - Intel SGX) β
β iexec-app/src/app.js β
β β’ Decrypts order data inside TEE enclave β
β β’ Validates order parameters β
β β’ Matches orders at uniform clearing price β
β β’ Settlement results output β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β²
β
βββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Keeper Bot (Node.js) β
β β’ Fetches live prices from CoinGecko β
β β’ Updates on-chain price feed β
β β’ Monitors pending limit orders β
β β’ Auto-executes when conditions are met β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Node.js v18+ and npm
- Foundry (for smart contracts)
- MetaMask wallet with Arbitrum Sepolia testnet
git clone https://github.com/pebfriantiya/shadowswap.git
cd shadowswap# Frontend
cd frontend
npm install
# Keeper Bot
cd ../keeper-bot
npm install
# iExec iApp
cd ../iexec-app
npm install
# Smart Contracts (Foundry)
cd ../contracts_foundry
forge install# Frontend
cp frontend/.env.example frontend/.env.local
# Edit with your values
# Keeper Bot
cp keeper-bot/.env.example keeper-bot/.env
# Add your private keycd frontend
npm run devcd keeper-bot
npm start| Document | Description |
|---|---|
| Setup Guide | Detailed installation instructions |
| Deployment Guide | How to deploy smart contracts |
| Architecture | System design and flow |
| iExec Integration | DataProtector usage |
| iApp Deployment | Build & deploy the iExec iApp |
| API Reference | Smart contract functions |
πΊ Watch Demo Video
The demo showcases:
- Connecting wallet to Arbitrum Sepolia
- Minting test tokens from faucet
- Performing instant swap with live prices
- Creating a limit order with target price
- Viewing order status and execution
- Transaction history and analytics
| Contract | Address | Arbiscan |
|---|---|---|
| ShadowPool | 0xfFCdCE40dfD214F2e13F67d9337B0E0e22024F09 |
View |
| MockPriceFeed | 0xb87889a99AcCF70a2aeA7F63Fdcde302fCd2e006 |
View |
| mUSDC | 0xcC5f8FC3CcAB02157F82afb7E19Fc65f4808849e |
View |
| mDAI | 0xda222533d71C37A9370C6b5a26BcB4C07EcB0454 |
View |
| mWETH | 0xe160dc7BD1E9d63A47a1d4CD082c332DD19D870c |
View |
| mETH | 0x62b64cC9B1Aa2F2c9d612f0b4a58Cfba0eEc9bE2 |
View |
| iExec iApp (TEE) | 0x834255dF01eE89d5096371a7eeFaF4332d4e2bfF |
View |
// Submit encrypted order for batch auction
function submitOrder(
bytes calldata encryptedData,
bytes32 datasetAddress,
address tokenIn,
address tokenOut,
uint256 amountIn
) external returns (bytes32 orderId)
// Create limit order
function submitLimitOrder(
bytes calldata encryptedData,
bytes32 datasetAddress,
address tokenIn,
address tokenOut,
uint256 amountIn,
uint256 limitPrice,
uint256 expiry
) external returns (bytes32 orderId)
// Instant swap with price feed
function instantSwap(
address tokenIn,
address tokenOut,
uint256 amountIn,
uint256 minAmountOut
) external nonReentrant
// Execute limit order when conditions met
function executeLimitOrder(bytes32 orderId) external nonReentrant- Next.js 16 - React framework
- TypeScript - Type safety
- Tailwind CSS - Styling
- wagmi/viem - Ethereum interactions
- RainbowKit - Wallet connection
- Solidity 0.8.20 - Contract language
- Foundry - Development framework
- OpenZeppelin - Security libraries
- Node.js - Keeper bot runtime
- viem - Blockchain interactions
- CoinGecko API - Price feeds
// 1. Create order data
const orderData = {
tokenIn: "0x...",
tokenOut: "0x...",
amountIn: "1000000000000000000",
minAmountOut: "990000000000000000"
};
// 2. Encrypt with DataProtector
const encryptedData = await dataProtector.encrypt(orderData);
// 3. Submit encrypted order
await shadowPool.submitOrder(
encryptedData,
datasetAddress,
tokenIn,
tokenOut,
amountIn
);- Order details (amounts, prices) are encrypted
- Only the batch settlement can decrypt
- Prevents front-running and MEV extraction
# Run contract tests
cd contracts_foundry
forge test -vvv
# Run frontend in development
cd frontend
npm run dev- Confidential batch auctions with iExec DataProtector
- Instant swaps with price feeds
- Limit orders with auto-execution
- Keeper bot for price monitoring
- Transaction history from blockchain
- Analytics dashboard
- Multi-chain deployment (Mainnet, Base, Optimism)
- Advanced order types (stop-loss, trailing stop)
- Liquidity provider incentives
- Governance token
This project was built from scratch during the hackathon:
- Smart Contracts: ShadowPool with batch auctions, limit orders, instant swaps
- iExec iApp: TEE application for confidential order processing (
iexec-app/) - iExec DataProtector: Order encryption in frontend (
frontend/src/lib/encryption.ts) - Frontend: Complete dApp with swap interface, limit orders, dashboard
- Keeper Bot: Automated price monitoring and order execution
- Documentation: Comprehensive setup, deployment, and usage guides
- iExec DataProtector: Order encryption and confidential computing
- Arbitrum Sepolia: L2 deployment for low gas costs
- CoinGecko API: Real-time price feeds
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please read our Contributing Guide for details.
Built with β€οΈ by the ShadowSwap Team