PortfoliOne is an intelligent crypto portfolio rebalancing platform built on Base mainnet that enables users to achieve optimal asset allocation with a single click. The project solves the complex problem of maintaining target portfolio allocations in the volatile crypto market by automating the entire rebalancing process through 1inch swap integration and swap optimization.
The platform fetches real-time portfolio data from users' wallets, allows them to set custom target allocations for their holdings, and then calculates the minimal number of swaps needed to achieve those targets. Using a greedy optimization algorithm, PortfoliOne determines the most efficient swap routes and executes them atomically through Alchemy Account Kit's UserOperation batching, ensuring either all swaps succeed or none do.
Key features include:
- Real-time portfolio tracking with USD valuations via 1inch API integration
- Intuitive input interface for setting target allocations
- Intelligent swap optimization that minimizes transaction costs and slippage
- Atomic transaction execution through Account Abstraction (EIP-4337)
- Gas-sponsored transactions for seamless user experience
- Beautiful progress tracking with step-by-step rebalancing feedback
- Integration with BaseScan for transaction transparency
The project addresses a real pain point in DeFi where users manually rebalance portfolios through multiple transactions, often losing money to MEV, slippage, and gas fees. PortfoliOne automates this entirely while providing institutional-grade execution through smart account infrastructure.
PortfoliOne is built as a modern full-stack Web3 application using cutting-edge technologies and innovative architectural patterns:
Frontend Architecture:
- Next.js 14 with App Router for server-side rendering and optimal performance
- TypeScript for type safety and developer experience
- Tailwind CSS for responsive, beautiful UI design
- React Portals for proper modal rendering and UX consistency
- Custom React hooks for state management and wallet integration
Smart Account Integration:
- Alchemy Account Kit (v4.35.1) for EIP-4337 Account Abstraction implementation
- Smart contract wallets enable gas sponsorship and transaction batching
- UserOperation batching allows atomic execution of multiple swaps
- Eliminates the need for users to hold ETH for gas fees
DeFi Integration:
- 1inch Aggregation Protocol for optimal swap routing and execution
- Real-time portfolio data fetching with token metadata and pricing
- Base mainnet integration for fast, low-cost transactions
- Custom proxy API calls to avoid CORS issues and API key exposure
Algorithmic Innovation:
The core innovation is our greedy swap optimization algorithm that:
- Calculates deltas between current and target allocations
- Separates tokens into surplus (sell) and deficit (buy) categories
- Optimally pairs swaps to minimize the total number of transactions
- Converts USD amounts to precise wei values for blockchain execution
Notable Technical Achievements:
- Implemented React Portal pattern for proper modal overlay effects across the entire app
- Created atomic transaction batching where either all swaps execute or none do
- Designed a beautiful stepper UI with real-time progress tracking and BaseScan integration
Partner Technology Benefits:
- Alchemy Account Kit enabled gasless transactions and improved UX through smart accounts
- 1inch Protocol provided optimal swap routing with minimal slippage
- Base L2 offered fast, cheap transactions perfect for frequent rebalancing
Particularly Hacky/Notable Elements:
- Custom hash extraction logic to handle Account Kit's UserOperation response format variations
- Intelligent threshold-based rebalancing (minimum $0.01) to support portfolios of all sizes
- Portal-based modal rendering to achieve proper app-wide background blur effects
- Sophisticated error suppression for expected Account Kit initialization warnings
- Real-time portfolio value calculation and display in the header navbar
The entire application is designed with production-grade patterns, comprehensive error handling, and a focus on user experience that rivals traditional fintech applications.