BetSwap AI, enables users to place and swap bets on real-world events (e.g., sports outcomes) between Ethereum and NEAR blockchains. Bets are represented as tokenized positions (e.g., ERC-20 on Ethereum or NEP-141 on NEAR) that can be swapped cross-chain. Payoffs are AI-driven, using oracle-fed data analyzed by AI models to determine outcomes automatically and trigger distributions. This ensures trustless, transparent resolutions without human intervention.
Key features:
- Cross-chain swaps: Bidirectional swaps of bet tokens between Ethereum and NEAR using an extension of 1inch Fusion+.
- AI-driven payoffs: Integrates AI (via NEAR's Shade Agents) to analyze real-world data from oracles (e.g., Chainlink on Ethereum, or custom oracles on NEAR) for event outcomes.
- Enhancements: Dutch auctions for price discovery, partial fills for flexible swaps, and incentives (e.g., token rewards for liquidity providers and solvers).
- Decentralized solver: A custom solver built with NEAR's Shade Agent Framework, deployed in a Trusted Execution Environment (TEE), that generates quotes and meta-orders for 1inch Fusion+.
The dApp preserves hashlock and timelock for atomicity on NEAR (non-EVM), ensuring secure, intent-based swaps. For the demo, we'll use testnets (Sepolia for Ethereum, NEAR Testnet) with on-chain token transfers.
Frontend (Stretch Goal - UI): A simple React-based UI for placing bets, initiating swaps, and viewing payoffs. Users connect wallets (MetaMask for Ethereum, NEAR Wallet).
Smart Contracts:
Ethereum: Bet contract (ERC-20 tokens for bets), integrated with 1inch Limit Order Protocol for Fusion+.
NEAR: Bet contract (NEP-141 tokens), hashlock/timelock logic for atomic swaps.
Cross-Chain Layer: Extended 1inch Fusion+ for ETH-NEAR swaps, using NEAR Chain Signatures for signing Ethereum txns from NEAR.
Solver: Decentralized AI agent (Shade Framework in TEE) that listens for intents, generates Fusion+ meta-orders.
AI Payoffs: Shade Agent queries oracles, runs AI models (e.g., simple ML for outcome prediction), and triggers payoffs.
Incentives: Reward tokens (e.g., custom ERC-20/NEP-141) for solvers and LPs via staking yields.
The system uses intents: Users express "bet swap intents" (e.g., "Swap my ETH bet token for NEAR equivalent at best rate"), solved cross-chain.
šļø Project Architecture & Technology Stack
Core Technologies
- Frontend Framework
Next.js 14 with TypeScript - Modern React framework with server-side rendering
Tailwind CSS - Utility-first CSS framework for rapid UI development
React Hooks - State management using useState, useEffect, useCallback
Client-side Hydration - Handles SSR/client mismatch with isHydrated state
- Blockchain Integration
Ethers.js v6 - Ethereum interaction library
NEAR Protocol SDK - For NEAR blockchain integration
MetaMask Integration - Browser wallet connection
NEAR Wallet - NEAR blockchain wallet connection
- Smart Contracts
Solidity - Ethereum smart contract language
Hardhat - Development environment and deployment framework
Sepolia Testnet - Ethereum test network for deployment
šļø Smart Contract Architecture
- Core Contracts
BetSwap AI Contract (BetSwapAI.sol)
details
HTLC Contract (HTLC.sol)
met
Dutch Auction Contract (DutchAuction.sol)
calculation
Bet Auction Contract (BetAuction.sol)
bets
Mock USDC Contract (MockUSDC.sol)
queries
š Cross-Chain Integration
- Ethereum ā NEAR Bridge
HTLC (Hash Time-Locked Contracts) - Enables trustless cross-chain swaps
Secret/Preimage Mechanism - Cryptographic proof for cross-chain verification
Time-locked Escrows - Prevents double-spending attacks
- Wallet Management
;
š¤ AI Integration & Resolution System
- AI Resolution Engine
;
- Notification System
Real-time Toast Notifications - Instant feedback for AI resolutions
Persistent Notification History - localStorage-based notification tracking
Read/Unread Status - User interaction tracking
Visual Badges - Unread notification indicators
š¾ Data Persistence Strategy
- Client-side Storage
;
- SSR/Hydration Handling
;
šÆ Advanced Features
- Partial Fill System
;
- Dynamic Event Creation
;
- Cross-Chain Betting Logic
;
š§ Notable Technical Implementations
- RPC Fallback System
}
- Contract Deployment Automation
;
- Error Handling & Recovery
;
šØ UI/UX Innovations
- Dynamic Button States
;
- Real-time Dashboard Updates
;
- Progressive Enhancement
;
š Security Considerations
- Private Key Management
Environment Variables - Secure storage of deployment keys
Wallet Integration - No private key exposure in frontend
HTLC Security - Cryptographic time-locks for cross-chain safety
- Input Validation
;
š Deployment & Infrastructure
- Multi-Environment Support
Local Development - Hardhat local node
Sepolia Testnet - Production-like testing environment
Environment Configuration - .env.sepolia for testnet deployment
- Contract Management
}
šÆ Key Technical Achievements
Cross-Chain Interoperability - Seamless Ethereum ā NEAR integration
AI-Powered Resolution - Automated event resolution with notification system
Partial Fill Support - Advanced auction mechanics for better liquidity
Real-time Notifications - Comprehensive notification system for user engagement
Persistent State Management - Robust data persistence across sessions
Graceful Error Handling - Comprehensive error recovery and user feedback
Modular Architecture - Clean separation of concerns and maintainable code
š§ Hacky but Effective Solutions
Mock Contract Addresses - Using 0x0000... for undeployed contracts with UI warnings
localStorage for State - Client-side persistence instead of backend database
Simulated NEAR Operations - Frontend simulation for NEAR interactions during development
RPC Fallback Chain - Multiple RPC endpoints to handle rate limiting
SSR Hydration Workarounds - isHydrated state to prevent server/client mismatches
This architecture demonstrates a sophisticated approach to building a cross-chain DeFi application with real-world usability, comprehensive error handling, and user-friendly interfaces! š