DSwap - Spot Trading

DSwap enables spot trading of synthetic assets using DUSD as the base currency. The system uses oracle-based pricing with enhanced multi-layer security architecture, dynamic fee structures, and mathematical solvency guarantees for maximum protocol security.

Overview

DSwap provides:

  • Virtual synthetic asset positions (no ERC20 tokens)

  • Mathematical solvency guarantees through hard invariants

  • Dynamic risk management with stress-based fees

  • Insurance fund integration for emergency support

  • Settlement locks for MEV protection

  • Gas-efficient clone factory for new assets

Architecture

User Interface (SwapRouter)

    Core Logic (DSwap)

   Enhanced Risk Management (Hard Invariants + Dynamic Fees + Insurance)

   Virtual Asset Tracking (SynthManager)

   Clone Factory (Gas-Efficient Deployment)

Core Components

  • SwapRouter: User-facing interface with slippage protection

  • DSwap: Enhanced core logic with multi-layer security

  • SynthManager: Clone factory and virtual asset registry

  • DUSDProvider: Dynamic backing calculation and limits

  • Insurance Fund: Emergency DUSD reserves for danger zone support

  • Virtual Assets: Position tracking without token deployment

Supported Operations

1. Mint Synthetic

Convert DUSD to virtual synthetic assets at oracle prices:

2. Burn Synthetic

Convert virtual synthetic assets back to DUSD with dynamic fees:

3. Swap Synthetic

Direct swap between virtual synthetic assets:

Enhanced Security Architecture

Hard Invariants (Mathematical Guarantees)

The enhanced DSwap system implements three non-negotiable invariants that provide mathematical guarantees of protocol solvency:

Invariant #1 — Global Solvency (Absolute)

  • Enforced: At every state transition

  • Components: syntheticDebtDUSD = Σ (assetSupply × oraclePrice)

  • Emergency Insurance: Insurance fund DUSD reserves (only in danger zone)

  • Guarantee: Mathematical impossibility of protocol insolvency

Invariant #2 — Rate Limiting (Time-Based Protection)

  • Purpose: Prevents flash minting during oracle spikes

  • Scope: Global per asset and per user cooldowns

  • Protection: Limits rapid exploitation of price movements

Invariant #3 — Asset Debt Caps (Diversification)

  • Purpose: Prevents single asset from destabilizing system

  • Configuration: Independent caps per synthetic asset

  • Risk Management: Ensures portfolio diversification

Enhanced Stress Metrics

The system uses a comprehensive stress calculation that accounts for all outstanding liabilities:

Where:

  • syntheticDebtDUSD = Σ (assetSupply × oraclePrice) - Total synthetic asset debt

  • totalDUSDSupply - All minted DUSD tokens

  • maxBorrowableDUSD = (totalCollateralValue × maintenanceRatio) / 10000

Stress Zones:

  • Healthy (< 95%): Base fees, normal operations

  • Normal (95-100%): Linear fee escalation

  • Danger (100-105%): Exponential fees + insurance fund support

  • Blocked (> 105%): Operations halted by hard cap

Advanced Fee System

The enhanced fee system provides both revenue generation and risk mitigation:

Dynamic Fee Structure

Fee Distribution System

Fee Allocation:

  • Insurance Fund: 50% (configurable) - Builds protocol reserves

  • Fee Recipient: 50% (configurable) - Protocol revenue/stakers

  • Dynamic Rates: Stress-based escalation for burn operations

Insurance Fund Integration

The insurance fund provides additional backing during stress periods:

Emergency Insurance Activation

Stress-Based DUSD Minting

Insurance Fund Features:

  • Automatic Activation: Engages when stress ≥ 100%

  • Reserve Utilization: Uses accumulated DUSD reserves

  • Solvency Protection: Prevents new DUSD minting in danger zone

  • Fee Funding: Built from 50% of all trading fees

Settlement Lock Protection

Anti-MEV Features:

  • 1-Minute Cooldown: Prevents rapid arbitrage cycles

  • User-Specific: Each user has independent cooldown

  • Comprehensive Coverage: Applies to all swap operations

  • Price Stabilization: Reduces oracle front-running opportunities

Multi-Layer Defense System

Layer 1: Hard Mathematical Invariants

  • Global Solvency: totalDebt ≤ maxBorrowable + insurance

  • Rate Limiting: Prevents flash exploitation

  • Asset Caps: Diversification enforcement

  • Guarantee: Mathematical impossibility of insolvency

Layer 2: Dynamic Economic Controls

  • Stress-Based Fees: 0.3% to 5% based on system stress

  • Insurance Fund: Automatic activation in danger zone

  • Fee Distribution: 50% to insurance, 50% to protocol

  • Exponential Escalation: Rapid fee increase in danger zone

Layer 3: Operational Protections

  • Settlement Locks: 1-minute MEV protection

  • Oracle Validation: Staleness and deviation checks

  • Access Control: Role-based admin functions

  • Emergency Pause: Immediate halt capability

Layer 4: Real-Time Monitoring

  • Continuous Stress Calculation: Real-time solvency tracking

  • Asset-Level Monitoring: Per-asset debt tracking

  • Rate Limit Tracking: Global and per-user limits

  • Insurance Fund Status: Reserve level monitoring

Key Features

Virtual Asset System

  • No ERC20 Tokens: Positions tracked in SynthManager contract

  • Clone Factory: 97.5% gas savings on new asset deployment

  • Instant Addition: Add new assets without token deployment

  • Upgradeable Logic: Update implementation without migration

Oracle-Based Pricing

  • Real-time price feeds from Chainlink and Pyth

  • Zero slippage on oracle price

  • Instant execution without liquidity constraints

  • Staleness and deviation protection

Dynamic Fee Structure

  • Mint fee: 0.3% base (safe operation - no DUSD minting)

  • Burn fee: 0.3-5% dynamic based on stress ratio (risky - mints DUSD)

  • Swap fee: 0.3% base (synthetic-to-synthetic, no DUSD involved)

  • Settlement lock: 1-minute cooldown after all operations

Trading Flow Example

Enhanced Mint Flow with Security Checks

  1. User approves 1000 DUSD to SwapRouter

  2. Hard Invariant Check: Verify global solvency constraints

  3. Rate Limiting: Check per-asset and per-user mint limits

  4. Asset Cap Check: Verify asset debt cap not exceeded

  5. Oracle provides AAPL price ($150)

  6. Fee calculation: 1000 × 0.003 = 3 DUSD (base mint fee)

  7. Fee distribution: 1.5 DUSD to insurance fund, 1.5 DUSD to fee recipient

  8. Net amount: 997 DUSD

  9. xAAPL amount: 997 ÷ 150 = 6.64 xAAPL

  10. Burn 1000 DUSD from user

  11. SynthManager tracks 6.64 xAAPL virtual position

  12. Settlement lock: 1 minute (no transfers/swaps)

Enhanced Burn Flow with Insurance Support

  1. User has 6.64 xAAPL virtual position (after settlement lock expires)

  2. Cooldown Check: Verify mint cooldown period has passed

  3. Oracle provides AAPL price ($160)

  4. Value: 6.64 × 160 = 1,062 DUSD

  5. Stress Calculation: Current stress ratio = 0.98 (98% of max borrowable)

  6. Dynamic Fee: 0.4% = 4.25 DUSD (normal zone linear escalation)

  7. Global Solvency Check: Verify hard invariants

  8. Insurance Fund Check: Stress < 100%, normal minting

  9. Net amount: 1,058 DUSD

  10. Mint 1,058 DUSD to user

  11. Fee distribution: 2.125 DUSD to insurance fund, 2.125 DUSD to fee recipient

  12. Settlement lock: 1 minute (new lock period)

Risk Classification Matrix

Operation
Risk Level
Fee Structure
Insurance Support

Mint Synthetic

Low

Base fee (0.3%)

No

Swap Synthetic

Low

Base fee (0.3%)

No

Burn Synthetic

High

Dynamic (0.3-5%)

Yes (danger zone)

Stress Response System

Stress Level
Range
Fee Rate
Insurance
Operations

Healthy

0-95%

0.3%

Inactive

Full

Normal

95-100%

0.3-0.5%

Inactive

Full

Danger

100-105%

0.5-5%

Active

Restricted

Blocked

>105%

N/A

N/A

Halted

Virtual Asset Architecture

SyntheticToken (Clone Implementation)

File: src/tokens/SyntheticToken.sol

Minimal ERC20 implementation designed for cloning:

SynthManager (Clone Factory)

File: src/tokens/SynthManager.sol

Factory and registry for synthetic tokens:

Supported Assets (Virtual Positions)

Equities (Primary Focus)

  • xAAPL: Apple Inc. (virtual position)

  • xTSLA: Tesla Inc. (virtual position)

  • xMSFT: Microsoft Corp. (virtual position)

  • xAMZN: Amazon.com Inc. (virtual position)

  • xGOOGL: Alphabet Inc. (virtual position)

Commodities

  • xGOLD: Gold futures (virtual position)

  • xSILVER: Silver futures (virtual position)

  • xOIL: Crude Oil futures (virtual position)

  • xCOPPER: Copper futures (virtual position)

Indices

  • xSP500: S&P 500 Index (virtual position)

  • xNASDAQ: NASDAQ Composite (virtual position)

  • xDOW: Dow Jones Industrial Average (virtual position)

Crypto (Synthetic Versions)

  • xBTC: Synthetic Bitcoin (virtual position)

  • xETH: Synthetic Ethereum (virtual position)

Note: All assets are virtual positions tracked in SynthManager, not ERC20 tokens. This eliminates deployment costs and enables instant asset addition with 97.5% gas savings.

Integration

Smart Contract Integration

Benefits

For Traders

  • Access to global markets 24/7

  • Zero slippage oracle-based pricing

  • Mathematical solvency guarantees

  • Enhanced MEV protection

  • Dynamic fees reflect system health

For the Protocol

  • Mathematical impossibility of insolvency

  • Self-balancing through dynamic fees and insurance

  • Scalable virtual asset system

  • Comprehensive risk management

  • Revenue generation through fee distribution

Key Insight: The enhanced DSwap system provides mathematical guarantees of protocol solvency through hard invariants while maintaining economic incentives through dynamic fees and insurance fund support. Only burning synthetics creates solvency risk by minting new DUSD, hence the sophisticated multi-layer security architecture.

Last updated