DCA.fun Pig LogoDCA.fun

Protocol Architecture

Deep dive into DCA.fun system design and architecture

Overview

DCA.fun is a decentralized Dollar Cost Averaging protocol built on Ethereum and EVM-compatible chains. It enables automated, recurring token swaps with yield generation through Aave, accurate pricing via Chainlink Data Streams, and gas-efficient vault isolation.

Core Architecture

Contract Hierarchy

DcaDotFun (Main Entry Point)
├── Inherits: DotFun (Price Feed Base)
├── Uses: VerifierDotFun (Chainlink Verifier)
├── Deploys via: DcaVaultFactory
└── Creates: DcaVault (Per Order)

External Integrations:
- Chainlink Data Streams (Price feeds)
- Aave V3 Pool (Yield generation)
- Permit2 (Token transfers)

Order Lifecycle

  1. Creation: User creates order → Deploy vault → Transfer tokens → Optionally stake in Aave
  2. Execution: Filler calls fillOrder → Verify prices → Calculate swap → Transfer tokens → Update state
  3. Completion: Order exhausted or cancelled → Withdraw funds → Distribute yield → Return to user

Component Details

DcaDotFun Contract

Main protocol contract handling user interactions:

  • Order creation, validation, and storage
  • Fill logic and price calculations
  • Permit2 integration for transfers
  • Aave staking/unstaking
  • Protocol fee collection

Key Functions:

createOrder()       // Create new DCA order
fillOrder()         // Execute a DCA swap
cancelOrders()      // Cancel and refund
quote()            // Get execution quote

DotFun Contract

Base contract for price feeds and token management:

  • Chainlink Data Streams integration
  • Token whitelist and properties
  • Aave reserve validation
  • Global protocol settings

DcaVault Contract

Isolated smart contract wallet per order:

  • Complete fund isolation
  • Yield tracking and distribution
  • Minimal proxy pattern (gas efficient)
  • Strict access control

State Variables:

orderId        // Unique order identifier
tokenIn/Out    // Trading pair
aTokenIn/Out   // Aave yield tokens
spendAmount    // Amount per execution
yieldSplit     // Protocol yield share

DcaVaultFactory Contract

Deploys vault clones using CREATE2:

  • Deterministic addresses
  • Gas-efficient deployment
  • Immutable implementation

VerifierDotFun Contract

Chainlink verification supporting:

  • V3 Reports: Crypto assets
  • V4 Reports: Real World Assets

Order Parameters

ParameterDescriptionConstraints
recipientOutput token recipientValid address
tokenIn/OutTrading pairWhitelisted tokens
spendAmountAmount per fill> min execution value
repeatsNumber of executions> 0
freqIntervalTime between fills≥ 1 hour
scalingIntervalDutch auction duration≤ 7 days
slippagePrice tolerance0.1% - 5%
stakeAssetIn/OutAave staking flagsIf token stakeable

Security Architecture

Access Control

  • DEFAULT_ADMIN_ROLE: Protocol configuration
  • PAUSER_ROLE: Emergency pause
  • User: Create/cancel own orders
  • Filler: Execute any ready order

Security Features

  • ReentrancyGuard on critical functions
  • Vault isolation per order
  • Time-based execution windows
  • Slippage protection bounds
  • Chainlink price verification
  • Emergency pause functionality

Gas Optimization

  1. Clone Pattern: Minimal proxy vaults
  2. Immutable Storage: Core addresses
  3. Packed Structs: Efficient order data
  4. Batch Operations: Multi-order cancellation
  5. CREATE2: Predictable addresses

Protocol Configuration

ParameterDescriptionTypical Value
protocolFeeOutput token fee0.5%
minExecutionValueMinimum order USD$10
maxFeedAgePrice staleness limit5 seconds
minFrequencyMin time between fills1 minute
yieldSplitProtocol yield share20%

Integration Flows

For Users

  1. Connect wallet → Select tokens → Configure DCA
  2. Approve tokens → Create order → Monitor fills
  3. Cancel anytime → Receive remaining funds + yield

For Fillers

  1. Monitor executable orders via API/WebSocket
  2. Check profitability with gas costs
  3. Call fillOrder with price reports
  4. Receive input tokens as payment

Price Feed Architecture

Chainlink Data Streams provide:

  • Real-time price updates
  • Cryptographic signatures
  • Multi-source aggregation
  • Staleness protection

Yield Architecture

Aave integration enables:

  • Automatic staking of idle funds
  • Yield accrual between fills
  • 80/20 yield split (user/protocol)
  • Compound interest on deposits

Scaling Factor Algorithm

Dutch auction mechanism for filler incentives:

  • Starts at 0% bonus
  • Increases linearly over scaling interval
  • Caps at configured maximum
  • Resets after each fill

Future Extensibility

Architecture supports:

  • Additional yield sources
  • Cross-chain orders
  • Advanced order types
  • DEX aggregation
  • Order delegation

Conclusion

DCA.fun provides robust, gas-efficient, and secure infrastructure for automated dollar-cost averaging on-chain. The modular architecture with battle-tested integrations creates a reliable platform for both retail and institutional DCA strategies.