← Back to home

BetSwap AI

Enables users to swap bets on real-world events between Ethereum and NEAR, with AI driven payoffs

Problem Statement

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.

Solution

šŸ—ļø Project Architecture & Technology Stack Core TechnologiesFrontend 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 stateBlockchain Integration Ethers.js v6 - Ethereum interaction library NEAR Protocol SDK - For NEAR blockchain integration MetaMask Integration - Browser wallet connection NEAR Wallet - NEAR blockchain wallet connectionSmart Contracts Solidity - Ethereum smart contract language Hardhat - Development environment and deployment framework Sepolia Testnet - Ethereum test network for deployment šŸ›ļø Smart Contract ArchitectureCore 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 IntegrationEthereum ↔ 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 attacksWallet Management ; šŸ¤– AI Integration & Resolution SystemAI 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 StrategyClient-side Storage ;SSR/Hydration Handling ; šŸŽÆ Advanced FeaturesPartial Fill System ;Dynamic Event Creation ;Cross-Chain Betting Logic ; šŸ”§ Notable Technical ImplementationsRPC Fallback System }Contract Deployment Automation ;Error Handling & Recovery ; šŸŽØ UI/UX InnovationsDynamic Button States ;Real-time Dashboard Updates ;Progressive Enhancement ; šŸ” Security ConsiderationsPrivate 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 safetyInput Validation ; šŸš€ Deployment & InfrastructureMulti-Environment Support Local Development - Hardhat local node Sepolia Testnet - Production-like testing environment Environment Configuration - .env.sepolia for testnet deploymentContract 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! šŸš€

Hackathon

ETHGlobal Unite

2025

Contributors