DSwap - Spot Trading

DSwap enables spot trading of synthetic assets using DUSD as the base currency. The system uses oracle-based pricing with advanced risk management, dynamic fee structures, and virtual asset tracking for maximum protocol security and capital efficiency.

Overview

DSwap provides:

  • Virtual synthetic asset positions (no ERC20 tokens)

  • Dynamic risk management with stress-based fees

  • Settlement locks for MEV protection

  • Gas-efficient clone factory for new assets

  • Mathematical solvency guarantees

Architecture

User Interface (SwapRouter)

    Core Logic (DSwap)

   Risk Management (Dynamic Backing + Fees)

   Virtual Asset Tracking (SynthManager)

   Clone Factory (Gas-Efficient Deployment)

Core Components

  • SwapRouter: User-facing interface with slippage protection

  • DSwap: Core swap logic with dynamic fee management

  • SynthManager: Clone factory and virtual asset registry

  • DUSDProvider: Dynamic backing calculation and limits

  • 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:

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

Advanced Risk Management

  • Hard Invariants: Mathematical impossibility of protocol insolvency

  • Dynamic Backing: Real-time collateral monitoring

  • Stress-Based Fees: Dynamic burn fees (0.3-2%)

  • Settlement Locks: 1-minute MEV protection

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% flat (safe operation - no DUSD minting)

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

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

  • Settlement lock: 1-minute cooldown after all operations

Clone Factory Benefits

Gas Efficiency

  • First deployment: ~2M gas (implementation)

  • Subsequent deployments: ~50K gas (clones)

  • Savings: 97.5% gas reduction per new synthetic

Upgradeability

  • Update implementation address in SynthManager

  • New synthetics use new implementation

  • Existing synthetics unchanged

  • No migration needed

Consistency

  • All synthetics share same logic

  • Uniform behavior across assets

  • Easier auditing and testing

Trading Flow Example

Mint xAAPL with 1000 DUSD (Virtual Position)

  1. User approves 1000 DUSD to SwapRouter

  2. Check: totalSupply + 1000 ≤ maxBorrowableDUSD ✓

  3. Oracle provides AAPL price ($150)

  4. Fee calculation: 1000 × 0.003 = 3 DUSD (flat mint fee)

  5. Net amount: 997 DUSD

  6. xAAPL amount: 997 ÷ 150 = 6.64 xAAPL

  7. Burn 997 DUSD from user

  8. SynthManager tracks 6.64 xAAPL virtual position

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

Burn xAAPL back to DUSD (Dynamic Fee)

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

  2. Oracle provides AAPL price ($160)

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

  4. Check: totalSupply + 1,062 ≤ maxBorrowableDUSD ✓

  5. Calculate stress ratio: 0.7 (example)

  6. Dynamic burn fee: 1.5% = 16 DUSD

  7. Net amount: 1,046 DUSD

  8. Mint 1,046 DUSD to user

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

Risk Management Architecture

Hard Invariant Protection

Dynamic Fee Calculation

Settlement Lock Protection

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:

Key Functions:

  • updateImplementation(): Upgrade token implementation

  • deploySynthetic(): Clone and initialize new synthetic

  • setSyntheticStatus(): Enable/disable trading

  • mint(): Mint synthetic tokens (virtual positions)

  • burn(): Burn synthetic tokens (virtual positions)

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

Deployment Sequence

  1. Deploy SyntheticToken implementation

  2. Deploy SynthManager with implementation address

  3. Deploy DSwap with oracle, DUSD, and SynthManager

  4. Deploy SwapRouter with DSwap, SynthManager, and DUSD

  5. Grant DSwap permission to call SynthManager

  6. Deploy synthetics via SynthManager.deploySynthetic()

  7. Configure fees in DSwap

  8. Set fee collector address

Example Deployment Script

Advanced Security Features

Protocol Solvency Protection

  • Dynamic Backing Limits: Real-time calculation prevents over-issuance

  • Stress Monitoring: Continuous ratio tracking and fee adjustment

  • Hard Caps: Mathematical impossibility of insolvency

  • Emergency Controls: Governance pause and parameter adjustment

MEV and Arbitrage Protection

  • Settlement Locks: 1-minute cooldown prevents rapid arbitrage

  • Oracle Anchoring: No AMM manipulation possible

  • Fee Curves: Economic disincentives for destabilizing behavior

Operational Security

  • Multi-signature governance for parameter changes

  • Oracle staleness and validity checks

  • Role-based access control

  • Comprehensive event logging

Benefits

For Traders

  • Access to global markets 24/7

  • Zero slippage oracle-based pricing

  • Instant settlement with MEV protection

  • No counterparty risk

  • Dynamic fees reflect market conditions

For the Protocol

  • Guaranteed solvency through hard limits

  • Self-balancing through dynamic fees

  • Scalable virtual asset system

  • Minimal operational overhead

  • Advanced risk management

Security Features

Four-Layer Defense System

  1. Hard Invariant: Dynamic backing limits prevent insolvency

  2. Dynamic Fees: Economic pressure maintains balance

  3. Settlement Locks: MEV and arbitrage protection

  4. Real-time Monitoring: Continuous risk assessment

Risk Classification

Operation
Risk Level
Fee Type

Mint Synthetic

Low

0.3% flat

Swap Synthetic

Low

0.3% flat

Burn Synthetic

High

0.3-2% dynamic

Key Insight: Only burning synthetics (synthetic → DUSD) creates solvency risk by minting new DUSD, hence the dynamic fee structure. Minting and swapping are safe operations with flat fees.

Last updated