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
- Creation: User creates order → Deploy vault → Transfer tokens → Optionally stake in Aave
- Execution: Filler calls fillOrder → Verify prices → Calculate swap → Transfer tokens → Update state
- 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 quoteDotFun 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 shareDcaVaultFactory 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
| Parameter | Description | Constraints |
|---|---|---|
recipient | Output token recipient | Valid address |
tokenIn/Out | Trading pair | Whitelisted tokens |
spendAmount | Amount per fill | > min execution value |
repeats | Number of executions | > 0 |
freqInterval | Time between fills | ≥ 1 hour |
scalingInterval | Dutch auction duration | ≤ 7 days |
slippage | Price tolerance | 0.1% - 5% |
stakeAssetIn/Out | Aave staking flags | If 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
- Clone Pattern: Minimal proxy vaults
- Immutable Storage: Core addresses
- Packed Structs: Efficient order data
- Batch Operations: Multi-order cancellation
- CREATE2: Predictable addresses
Protocol Configuration
| Parameter | Description | Typical Value |
|---|---|---|
protocolFee | Output token fee | 0.5% |
minExecutionValue | Minimum order USD | $10 |
maxFeedAge | Price staleness limit | 5 seconds |
minFrequency | Min time between fills | 1 minute |
yieldSplit | Protocol yield share | 20% |
Integration Flows
For Users
- Connect wallet → Select tokens → Configure DCA
- Approve tokens → Create order → Monitor fills
- Cancel anytime → Receive remaining funds + yield
For Fillers
- Monitor executable orders via API/WebSocket
- Check profitability with gas costs
- Call fillOrder with price reports
- 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.