This repository contains the smart contract implementation for the DECAStream Protocol - a revolutionary DeFi protocol that automatically routes trades across multiple DEXs and executes them in optimal chunks to minimize slippage and maximize efficiency.
Ever gone through the laborious process of checking each DEX to get the best trade? What if you don't care and just send it on whichever DEX you happen to be used to? This exposure to front running, pool manipulation and unpredictable slippage rates will be a thing of the past.
NOW RUNNING AGAINST 6 DEXs!!!
One click and the DECAStream Protocol will route your trade across the DEXs with the optimum trade conditions and 'Stream' it out chunk by chunk, block by block. As market conditions change, we adapt, finding the best performing DEX on this stream by stream basis. When your trade is fully settled, you receive your tokens in precisely the threshold you defined. Taking too long? Cancel the trade at any time and return tokens exchanged to that point.
Instasettle furthermore allows anyone to instantly settle a trade across the contract in full. Users get to define thresholds in BPS and viewing traders can settle at these rates in one click. Both maker and taker get instant (block) settling.
Hot Pairs lists vetter token pairs which yield the maximum savings by using the protocol. Stream out highly illliquid tokens chunk by trunk to experience less than 10BPS in splippage and experience up to 99% price accuracy across massive volumes.
What makes DECAStream epic...
- Automated DEX Routing: Automatically finds the best DEX for each trade based on price, liquidity, and gas costs
- Stream Execution: Breaks large trades into optimal chunks executed block-by-block to yield price accuracy up to 99%
- Dynamic Adaptation: Continuously monitors market conditions and adjusts execution strategy which can yield millions of dollars worth of savings
- Instasettle: Allows instant settlement of trades at predefined thresholds in OTC style. Define your settlement price and experience ZERO slippage.
- Cancellation: Enables trade cancellation at any time with full return of settled and unsettled tokens.
- Network Fees: Network fee of just 0.2% across all trade environments.
- Multi-DEX Support: Integrates with UniswapV2, UniswapV3 (all fee tiers now included!), Sushiswap, Balancer and Curve
- Price Optimization: Automatically selects the DEX offering the best price for each trade
- Liquidity Analysis: Evaluates pool depths to determine optimal trade sizes
- Chunked Trading: Breaks large trades into smaller, optimal chunks
- Block-by-Block: Executes trades across multiple blocks to minimize market impact
- Sweet Spot Algorithm: Proprietary algorithm determines optimal chunk sizes based on pool reserves and gas costs
- Instant Settlement: Anyone can instantly settle a trade at predefined BPS thresholds
- Maker-Taker Benefits: Both parties benefit from instant, predictable settlement
- Trade Cancellation: Cancel trades at any time and receive tokens exchanged to that point
- Owner Controls: Configurable fee rates and DEX registrations
- Audit Ready: Comprehensive testing and security measures
Core.sol: Main protocol contract handling trade execution, fee management, and user interactionsStreamDaemon.sol: Manages DEX selection and sweet spot calculationsExecutor.sol: Executes trades on various DEXs through standardized interfacesRegistry.sol: Maintains DEX configurations and parameter encodingsUtils.sol: Shared utilities and data structures
- Fetcher Contracts: Interface with specific DEXs to get prices and reserves
- Router Management: Configurable router addresses for each DEX type
- Parameter Encoding: Standardized parameter encoding for cross-DEX compatibility
- Stream Fees: 10 bps for protocol + 10 bps for bots (configurable)
- Instasettle Fees: 10 bps for protocol (configurable)
- Maximum Cap: 100 bps (1%) for all fee types
- Foundry (latest version)
- Node.js 16+ (for additional tooling)
- Git
# Clone the repository
git clone https://github.com/your-org/DECAStream.git
cd DECAStream
# Install Foundry dependencies
forge install
# Build contracts
forge build# Copy environment template
cp .env.example .env
# Fill in your configuration
# MAINNET_RPC_URL=your_mainnet_rpc
# ETHERSCAN_API_KEY=your_etherscan_key
# DEPLOYER_PRIVATE_KEY=your_private_key# Run all tests
forge test
# Run with verbose output
forge test -vvv
# Run specific test file
forge test --match-path test/Core.t.sol
# Run with gas reporting
forge test --gas-report# Test against mainnet fork
forge test --fork-url $MAINNET_RPC_URL
# Test with specific block number
forge test --fork-url $MAINNET_RPC_URL --fork-block-number 18000000# Start local anvil instance
anvil
# Run tests against anvil
forge test --fork-url http://localhost:8545The protocol supports two deployment strategies:
# Deploy with 3 core DEXs
npm run deploy:barebones:create2:complete
# Or run step by step
npm run deploy:barebones:create2
npm run extract:addresses# Deploy with all supported DEXs
npm run deploy:mainnet:create2:complete# Test deployment without broadcasting
npm run deploy:barebones:dry-run# Compute expected CREATE2 addresses
npm run compute:addressesforge buildforge fmt# Generate gas snapshots
forge snapshot
# Compare gas usage
forge snapshot --diff# Generate coverage report
forge coverage- Status: Pre-audit
- Scope: Core contracts, DEX integrations, fee mechanisms
- Timeline: Q1 2024
- Access Control: Owner-only functions for critical operations
- Fee Caps: Maximum fee limits to prevent excessive charges
- Input Validation: Comprehensive parameter validation
- Emergency Controls: Ability to pause or update critical functions
- Centralization Risk: Owner controls for fee updates and DEX registration
- DEX Dependencies: Relies on external DEX contracts and oracles
- Gas Price Volatility: Execution costs may vary significantly
- Protocol Overview: Detailed protocol mechanics
- DEX Integration Guide: How to add new DEXs
- Maintenance Guide: Contract upgrade procedures
- API Reference: Contract function documentation
We welcome contributions! Please see our Contributing Guide for details.
Feel free to jump in, propose enhancements, fixes and features! Just:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the UNLICENSED License - see the LICENSE file for details.
This software is provided "as is", without warranty of any kind. Use at your own risk. The authors are not responsible for any financial losses incurred through the use of this protocol.
- Foundry Team: For the excellent development framework
- OpenZeppelin: For secure contract libraries
- DEX Communities: For building the infrastructure we integrate with
- Early Contributors: For helping shape the protocol
Built with β€οΈ by the DECAStream Team