Skip to content
Dash-TradePublic

About

Dash - Smart Contracts

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Dash - Smart Contracts

Solidity Foundry License

Perpetual futures trading protocol with up to 100x leverage, built on Base with Account Abstraction (USDC gas payments) and privileged smart wallets integration.

🌟 Key Features

  • ⚑ Instant Market Orders - Execute trades immediately at current oracle price
  • πŸ“Š High Leverage - Up to 100x on BTC/ETH, 20x on altcoins
  • 🎯 Advanced Orders - Limit orders, stop-loss, take-profit, grid trading
  • πŸ’΅ USDC Gas Payments - Pay transaction fees in USDC via Account Abstraction
  • πŸ” Privy Smart Wallets - Embedded wallets with email/social login
  • πŸ’Ž Dual Token Economy - USDC for trading, DASH for governance & rewards

πŸš€ Quick Start

Prerequisites

Installation

# Clone repository
git clone <your-repo-url>
cd dash-sc

# Install dependencies
forge install

# Compile contracts
forge build

Testing

# Run all tests
forge test

# Run with gas report
forge test --gas-report

# Run with verbose output
forge test -vvv

πŸ“ Project Structure

dash-sc/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ token/
β”‚   β”‚   β”œβ”€β”€ DashToken.sol          # DASH governance token (10M supply)
β”‚   β”‚   └── MockUSDC.sol             # Test USDC with faucet
β”‚   β”œβ”€β”€ risk/
β”‚   β”‚   └── RiskManager.sol          # Trade validation & risk checks
β”‚   β”œβ”€β”€ trading/
β”‚   β”‚   β”œβ”€β”€ PositionManager.sol      # Position tracking & PnL calculation
β”‚   β”‚   β”œβ”€β”€ MarketExecutor.sol       # Market order execution
β”‚   β”‚   β”œβ”€β”€ LimitExecutor.sol      # Limit/stop-loss orders
β”‚   β”‚   β”œβ”€β”€ TapToTradeExecutor.sol   # Fast tap-to-trade orders
β”‚   β”‚   └── OneTapProfit.sol         # Price prediction betting
β”‚   β”œβ”€β”€ treasury/
β”‚   β”‚   └── StabilityFund.sol      # Buffer first-loss, fee splitter, streaming
β”‚   β”œβ”€β”€ paymaster/
β”‚   β”‚   └── USDCPaymaster.sol        # Account Abstraction paymaster
β”‚   └── staking/
β”‚       β”œβ”€β”€ DashStaking.sol        # Stake DASH β†’ Earn USDC
β”‚       └── VaultPool.sol      # LP vault (USDC shares)
β”œβ”€β”€ script/
β”‚   └── FullDeploy.s.sol             # Complete deployment script
β”œβ”€β”€ test/                             # Foundry tests
└── foundry.toml                      # Foundry configuration

πŸ“¦ Smart Contracts Overview

Core Trading Contracts (5)

Contract Description Key Features
RiskManager Trade validation & risk management Leverage limits (100x BTC/ETH, 20x alts), Liquidation checks
PositionManager Position tracking & PnL Real-time PnL calculation, Position history
MarketExecutor Market order execution Instant fills, Signed price verification
LimitExecutor Advanced orders Limit orders, Stop-loss, Take-profit, Grid trading
StabilityFund Buffer first-loss, fee splitter, pays wins before pool Absorbs losses, pays wins, streams surplus to pool

Infrastructure Contracts (3)

Contract Description Purpose
DashToken DASH governance token 10M supply, Staking rewards, Governance
MockUSDC Test USDC Faucet (1,000 USDC/claim) for testing
USDCPaymaster Account Abstraction Pay gas fees with USDC

Incentive Contracts (2)

Contract Description Rewards
DashStaking Stake DASH tokens Earn 30% of trading fees in USDC
VaultPool Provide USDC liquidity Share-based LP pool backing trader payouts

Specialty Trading (2)

Contract Description Features
TapToTradeExecutor Fast order execution Backend-managed instant trades
OneTapProfit Price prediction betting 30s-5min duration, 2x multiplier

πŸ”§ Deployment

Quick Deploy (All Contracts)

forge script script/FullDeploy.s.sol \
  --rpc-url https://sepolia.base.org \
  --private-key YOUR_PRIVATE_KEY \
  --broadcast

This will:

  1. Deploy core contracts (VaultPool, StabilityFund, Market/Limit/Tap/OTP, token, staking, paymaster)
  2. Grant roles (SETTLER/KEEPER + backend signer)
  3. Initialize DashToken distribution
  4. Wire executors to StabilityFund and StabilityFund to VaultPool
  5. Save deployment addresses to deployments/base-sepolia-latest.json

Deploy to Different Networks

Base Sepolia (Testnet):

forge script script/FullDeploy.s.sol \
  --rpc-url https://sepolia.base.org \
  --private-key YOUR_PRIVATE_KEY \
  --broadcast

Base Mainnet (Production):

forge script script/FullDeploy.s.sol \
  --rpc-url https://mainnet.base.org \
  --private-key YOUR_PRIVATE_KEY \
  --broadcast \
  --verify

Post-Deployment

After deployment, you'll get a JSON file at deployments/base-sepolia-latest.json with all contract addresses. Copy these addresses to your backend .env file!

πŸ’° Token Distribution

DASH Token (10,000,000 total):

  • 50% (5M) β†’ Staking Rewards
  • 20% (2M) -> VaultPool liquidity allocation
  • 20% (2M) β†’ Team
  • 10% (1M) β†’ Treasury

Distribution is automatic during deployment via DashToken.initialize().

πŸ’΅ Fee Structure

Action Fee Recipient
Market Trade 0.05% of position size Protocol (split 50/30/20)
Limit Order Execution 0.5 USDC Keeper
Liquidation 0.5% of position Liquidator
Early Unstake (Staking) 10% Treasury
Early Withdrawal (LP) 15% Treasury

Fee Distribution:

  • 50% β†’ Liquidity Pool (backs trader profits)
  • 30% β†’ DASH Stakers (via DashStaking)
  • 20% β†’ Protocol Treasury

πŸ” Access Control & Roles

The deployment script automatically grants these roles:

StabilityFund

  • EXECUTOR_ROLE β†’ MarketExecutor, LimitExecutor, TapToTradeExecutor, OneTapProfit
  • KEEPER_ROLE β†’ Backend keeper address (for liquidations)

LimitExecutor

  • KEEPER_ROLE β†’ Backend keeper address (for limit order execution)

MarketExecutor

  • PRICE_SIGNER_ROLE β†’ Backend price signer address

πŸ›‘οΈ Security Features

  • βœ… OpenZeppelin Contracts - Battle-tested security libraries
  • βœ… ReentrancyGuard - All state-changing functions protected
  • βœ… Access Control - Role-based permissions (RBAC)
  • βœ… SafeERC20 - Safe token transfers
  • βœ… Signed Prices - ECDSA verification (5-minute validity)
  • βœ… Immutable Contracts - No upgradability (trustless)
  • βœ… Oracle Validation - Price freshness checks

πŸ“Š Leverage Limits

Asset Max Leverage Min Collateral
BTC 100x 10 USDC
ETH 100x 10 USDC
SOL, AVAX, NEAR 50x 10 USDC
BNB, XRP, LINK, MATIC 20x 10 USDC
AAVE, ARB, DOGE 20x 10 USDC

πŸ§ͺ Testing

# Run all tests
forge test

# Test specific contract
forge test --match-contract PositionManagerTest

# Test with gas report
forge test --gas-report

# Test with coverage
forge coverage

πŸš€ Next Steps

After deploying contracts:

  1. Update Backend

    • Copy contract addresses to dash-be/.env
    • Grant PRICE_SIGNER_ROLE to backend signer
    • Fund relay wallet with ETH
  2. Update Frontend

    • Update contract addresses in frontend config
    • Test market orders
    • Test limit orders
  3. Add Liquidity

    • Fund StabilityFund (buffer) and VaultPool with USDC (mint/transfer for testing)
    • Initial recommendation: 10,000 USDC minimum
  4. Test Trading

    • Claim Mock USDC from faucet
    • Open test positions
    • Verify PnL calculations

πŸ”— Important Links

πŸ“„ License

MIT License - see LICENSE file for details


Built with ❀️ by Dash DEX Team using Foundry

For questions or support, please open an issue on GitHub.

About

Dash - Smart Contracts

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages