Automated DeFi investing with fair execution, real-time prices, and subscription-based portfolios.
DIP (Decentralized Investment Platform) is a comprehensive DeFi protocol that enables users to build long-term wealth through automated, subscription-based investing in diversified crypto portfolios. The platform is designed to democratize access to sophisticated financial tools by simplifying the investment process, ensuring fair execution, and protecting users from common DeFi vulnerabilities like MEV attacks and price manipulation.
At its core, DIP allows users to subscribe to recurring investment plans—daily, weekly, bi-weekly, or monthly—using stablecoins like PyUSD as a base currency. These contributions are automatically invested into portfolios consisting of assets like ETH, BTC, and stablecoins based on chosen risk profiles (e.g., Conservative, Balanced, Aggressive), or custom plans created by the user.
Key Innovations:
Fair Investment Processing: DIP uses Pyth Entropy, a cryptographic randomness engine, to eliminate MEV (Miner Extractable Value), front-running, and timing manipulation. It introduces a commit-reveal batch execution system where user transactions are processed in a randomized, verifiable order, ensuring equal opportunity for all users, regardless of gas fees or timing.
Real-Time Pricing with Pyth Hermes: Unlike traditional oracles that have delays, DIP uses Pyth Hermes API to fetch sub-second, high-confidence price feeds directly from market makers and exchanges, ensuring accurate and slippage-minimized execution.
Dollar-Cost Averaging (DCA): Subscriptions use DCA strategies to reduce timing risks, smooth out volatility, and encourage long-term wealth accumulation. Each investment plan is fully automated, gas-optimized, and supports features like pause/resume, auto-rebalancing, and performance tracking.
Seamless DeFi Experience: Built with a full-stack architecture—Solidity smart contracts, a RESTful Node.js API, and Uniswap V3 integration—DIP abstracts complex DeFi interactions into a simple, user-friendly interface, enabling one-click portfolio creation and automated investing.
Why it Matters:
Bridges TradFi and DeFi: Brings subscription-based investing—common in traditional finance—to the decentralized world.
Promotes Financial Inclusion: Allows small and large investors alike to grow wealth habitually without needing active trading expertise.
First-of-its-kind Fairness Guarantees: Uses cutting-edge cryptographic randomness to bring fairness into smart contract execution—something most DeFi platforms ignore.
In essence, DIP is the first DeFi platform that combines automation, fairness, accuracy, and accessibility into one seamless investment experience. It empowers anyone—regardless of technical skill or capital size—to participate in wealth-building through decentralized finance.
🔗 Smart Contracts (Solidity + Foundry)
Our core protocol logic is written in Solidity, and we used Foundry as our testing and deployment framework for its speed and flexibility.
Key Contracts:
PlanManager.sol: Handles creation and management of investment portfolios (pre-built and custom), each with token allocation strategies.
InvestmentEngineV3.sol: The heart of the execution logic. It supports:
Normal Mode: Immediate investments for users who want fast execution.
Fair Mode: Queued investments with randomized batch execution using Pyth Entropy.
Other Notable Contracts:
Mock tokens & price feeds for testing and local simulation.
Subscription logic built into smart contracts for auto-investing, DCA, and rebalancing.
We used OpenZeppelin libraries for security primitives (ownership, access control, and token handling), ensuring safety and standardization.
🧠 Fair Investment Processing (Pyth Entropy Integration)
We integrated Pyth Entropy to eliminate MEV and front-running:
Users queue investments with a commit-reveal mechanism.
Batch executions are shuffled using on-chain randomness (Fisher-Yates algorithm).
Entropy values are fetched via off-chain API (Hermes), then revealed on-chain for verifiable fairness.
This approach brings provably fair execution to DeFi investing—a first-of-its-kind integration for recurring investment plans.
📈 Real-Time Price Feeds (Pyth Hermes)
We used Pyth Network's Hermes API to fetch millisecond-accurate price data directly from exchanges and market makers.
Why Hermes?
Sub-second latency (~400ms updates)
Confidence intervals ensure price reliability
Reduced price slippage in swaps
Enabled investment simulation, slippage-aware execution, and UI performance tracking
This gave us the most accurate and timely data in DeFi—critical for fair execution.
🔄 Token Swapping via Uniswap V3
All investments execute through Uniswap V3, chosen for:
Concentrated liquidity (better pricing)
Multi-hop routing support
Slippage protection
Custom fee tier selection per portfolio
We integrated Uniswap Router into our smart contracts and exposed investment actions through the backend API for user abstraction.
🧱 Backend/API (Node.js + Express)
We built a full RESTful API server in Node.js with Express to handle:
Investment lifecycle (queueing, executing, tracking)
Subscription management
Real-time price fetching (Hermes client)
On-chain price update workflow
Portfolio and performance analytics
We used Ethers.js to interact with the blockchain and handle:
Wallet simulation
On-chain price updates
Transaction sending
Event listening for contract interactions
🔗 Oracle Integration Details
The platform supports two oracle workflows:
Hermes API for real-time reads
Traditional on-chain Pyth updates (via updatePriceFeeds)
We support both pull-based on-chain price updates and gas-efficient batch reads, giving users a choice between performance and cost.
💡 Hacky / Notable Implementations 🔄 Dual Execution Modes
We built a dual execution engine (Normal and Fair) within the same smart contract. This let us:
Keep backward compatibility
Let users opt into fairness
Benchmark the performance tradeoffs
This was tricky to balance in the contract logic and required custom queue management and investment ID mapping.
🧪 Deterministic Testing with Foundry
To test randomness fairly, we mocked entropy and controlled execution order deterministically using hardcoded entropy values. This allowed us to verify the fairness math on-chain using Fisher-Yates shuffle simulations in Foundry.
🧰 API-Facilitated Oracle Updates
Because Pyth price updates involve fetching, posting, and consuming within the same transaction, we built an automated fee calculator + update bundler in our API. This removed the need for users to manually handle oracle updates or fees, streamlining UX.
⚙️ Gas Optimization in Batch Execution
Queued investments are executed in a gas-optimized loop, and transactions are batched using the Pyth batch pricing + Uniswap router's multi-swap capabilities to minimize fees.
🔁 Auto-Rebalancing Logic
Within subscriptions, we wrote logic to:
Detect drift in portfolio allocation
Rebalance on a rolling window (e.g., every 4th execution)
Minimize swap counts to reduce gas fees