Asset Swapping

Asset swapping enables direct exchange between synthetic assets with oracle-based pricing, dynamic fee structures, and advanced risk management to maintain protocol stability.

Swap Mechanisms

1. Direct Synthetic Swaps

Swap between synthetic assets without DUSD intermediary:

// Swap xAAPL to xTSLA directly
await swapRouter.swapSynthetic(
  keccak256("xAAPL"),  // From asset
  keccak256("xTSLA"),  // To asset  
  parseEther("6.6"),   // 6.6 xAAPL shares
  parseEther("4.9")    // Min 4.9 xTSLA shares
)

2. DUSD-Mediated Swaps

For complex swaps or when direct pairs aren't optimal:

// Two-step swap via DUSD (if needed)
// Step 1: Burn synthetic to DUSD (dynamic fee applies)
await swapRouter.burnSynthetic(
  keccak256("xAAPL"),
  parseEther("6.6"),
  parseEther("980") // Min DUSD after dynamic burn fee
)

// Wait for settlement lock (1 minute)
// Step 2: Mint new synthetic from DUSD (flat fee)
await swapRouter.mintSynthetic(
  keccak256("xGOLD"),
  parseEther("980"),
  parseEther("0.48") // Min gold units
)

Swap Calculation

Direct Swap Pricing

Direct swaps use oracle prices with flat fees:

Implementation

Supported Swap Pairs

From
To
Description
Fee Type

xAAPL

xTSLA

Tech stocks

0.3% flat

xGOLD

xSILVER

Precious metals

0.3% flat

xSP500

xNASDAQ

Index rotation

0.3% flat

xBTC

xETH

Crypto majors

0.3% flat

Cross-Category Swaps

All synthetic assets can swap to any other synthetic asset:

  • Equity to Commodity: xAAPL ↔ xGOLD

  • Commodity to Index: xGOLD ↔ xSP500

  • Index to Crypto: xSP500 ↔ xBTC

  • Any to Any: Universal compatibility

Fee Structure

Flat Swap Fees

Direct synthetic swaps use flat 0.3% fees:

Fee Comparison by Operation

Operation
Risk Level
Fee Structure
Reason

Mint Synthetic

Low

0.3% flat

Converts DUSD to position

Swap Synthetic

Low

0.3% flat

Position-to-position only

Burn Synthetic

High

0.3-2% dynamic

Creates new DUSD supply

Key Insight: Swaps only change position allocations without affecting DUSD supply, hence the flat fee structure.

Settlement Lock System

Lock Mechanics

Every swap triggers a 1-minute settlement lock:

Lock Applications

Blocked During Lock:

  • Additional swaps

  • Burning synthetics to DUSD

  • Transferring synthetic positions

  • Any position-changing operations

Allowed During Lock:

  • Viewing positions and balances

  • Checking prices and quotes

  • Reading contract state

  • Planning next moves

MEV Protection

Settlement locks prevent:

  • Sandwich Attacks: Can't immediately reverse trades

  • Flash Arbitrage: Eliminates rapid price exploitation

  • Oracle Front-running: Reduces timing-based advantages

Swap Examples

Example 1: Tech Stock Rotation

Example 2: Diversification Swap

Example 3: Cross-Asset Class Swap

Advanced Swapping

Batch Swap Strategy

Since each swap triggers settlement lock, plan efficiently:

Portfolio Rebalancing

Integration Patterns

React Hook for Swapping

Swap Quote Calculator

Risk Management

Oracle Risk

Price Feed Dependencies:

  • All swaps rely on accurate oracle prices

  • Stale prices can cause unfavorable swaps

  • Multiple oracle sources provide redundancy

Mitigation Strategies:

Settlement Lock Risk

Liquidity Constraints:

  • Cannot immediately reverse positions

  • Must wait 1 minute between operations

  • Plan swap sequences carefully

Risk Mitigation:

Monitoring and Analytics

Swap Metrics

User Swap History

Best Practices

Efficient Swapping

  • Plan Sequences: Minimize settlement locks through strategic planning

  • Batch Thinking: Consider final target allocation vs multiple small swaps

  • Timing Awareness: Account for 1-minute locks in user experience

  • Oracle Monitoring: Verify price freshness before large swaps

Risk Management

  • Slippage Protection: Always set reasonable minimum output amounts

  • Settlement Planning: Don't assume immediate liquidity after swaps

  • Oracle Validation: Check price feed status before swapping

  • Position Sizing: Consider swap fees in position sizing decisions

User Experience

  • Lock Indicators: Show settlement lock status clearly in UI

  • Fee Transparency: Display exact fees before swap execution

  • Price Updates: Refresh quotes regularly for accuracy

  • Error Handling: Gracefully handle settlement lock errors

Last updated