Recurring Finance is a decentralized application that automates cryptocurrency payments through a singleton distributor contract architecture. The system leverages smart wallet delegation and session keys to enable users to set up recurring payments with custom schedules, beneficiaries, and spending limits.
- Singleton Distributor Contract:
- Single smart contract that manages all recurring payments across all users
- Added
CREATOR_ROLEto restrict access to scheduled payment creation - Added pausable functionality to prevent contract exploits
- Added a default 2% platform fee which can be customized by the
ADMIN
- Session Key Management with EIP 7702: Handles delegation of spending authority with daily limits and expiration dates
- Gas Optimization:
- Eliminates per-user distributor contract deployment costs
- Reduces storage slots by packing related variables
- Replaced EnumerableSet with Arrays
- Optimized cron schedule validation with bitmasking to do validation in O(n) time which was previously O(n^2)
-
Cron Job Scheduler
- Automated Execution: Runs on hourly basis to trigger payment distributions
- Smart Triggering: Calls the distribute() function on the singleton contract
-
Frontend Application (Next.js)
-
Relayer Infrastructure: Relayers execute transactions on behalf of users to create the recurring payment schedule
- Cost Efficiency: No contract deployment costs per user
- Simplified Maintenance: Single contract to maintain and upgrade
- Cross-User Operations: Easy implementation of global features
- Reduced Attack Surface: One well-audited contract
- Platform Economics: Centralized fee collection and analytics
- Smart Wallet Integration: Generate and manage smart EOA (Externally Owned Account) wallets
- Session Key Management: Delegate spending authority to relayers with daily limits and expiration dates
- Recurring Payments: Set up automated payments with complex cron-like schedules
- Multi-Beneficiary Support: Send payments to multiple recipients in a single transaction
- Token Flexibility: Support for any ERC-20 token (USDC, ETH, etc.)
- Flexible Timing: Set start and end dates for payment schedules
- Cron-like Scheduling: Configure payments to run on specific:
- Hours (24-hour format)
- Days of the week
- Days of the month
- Months of the year
- Real-time Preview: Visual feedback showing your configured schedule
- Spending Limits: Set daily spending limits for delegated accounts
- Time-bound Delegation: Session keys automatically expire
- Smart Contract Security: Built on audited smart contract patterns
- Relayer Architecture: Secure execution through trusted relayers
- Distributor: Handles recurring payment logic and execution
- Session Key System: Manages delegation and spending limits
- Next.js 14: React framework with App Router
- TypeScript: Type-safe development
- Tailwind CSS: Utility-first styling
- Wagmi: Ethereum React hooks
- Viem: TypeScript Ethereum library
- Lucide React: Beautiful icons
- Smart Wallet Support: ERC-7702 compatible
- Multi-chain Ready: Ethereum and compatible networks
-
Clone the repository
git clone https://github.com/rahulbansal123/recurring-finance.git cd recurring-finance/client -
Install dependencies
npm install # or yarn install -
Environment Setup
Create a
.envfile in the root directory:NEXT_PUBLIC_PRIVATE_KEY=
For local development, you can use the following private key:
NEXT_PUBLIC_PRIVATE_KEY=0x22ea21180cde9a963a303deb128a1d04bcf8e4735492d53c1dfd040522c18b04
-
Start the development server
npm run dev # or yarn dev -
Open your browser Navigate to http://localhost:3000 to see the application.
-
Connect Your Wallet
- Click "Generate Wallet" to create a new smart wallet
-
Add Session Key
- Distributor contract address is used as the delegated relayer address
- Choose plan
- Sign the delegation transaction
-
Distribute
- Anyone can distribute the payments to all beneficiaries
- OpenZeppelin
- Viem and Wagmi
- Tailwind CSS
- Next.js
