project screenshot 1
project screenshot 2
project screenshot 3
project screenshot 4
project screenshot 5
project screenshot 6

BetSwap AI

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

BetSwap AI

Created At

Unite Defi

Project Description

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.

How it's Made

šŸ—ļø Project Architecture & Technology Stack Core Technologies

  1. 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
  2. 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
  3. Smart Contracts Solidity - Ethereum smart contract language Hardhat - Development environment and deployment framework Sepolia Testnet - Ethereum test network for deployment šŸ›ļø Smart Contract Architecture
  4. 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
  5. 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
  6. Wallet Management ; šŸ¤– AI Integration & Resolution System
  7. AI Resolution Engine ;
  8. 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
  9. Client-side Storage ;
  10. SSR/Hydration Handling ; šŸŽÆ Advanced Features
  11. Partial Fill System ;
  12. Dynamic Event Creation ;
  13. Cross-Chain Betting Logic ; šŸ”§ Notable Technical Implementations
  14. RPC Fallback System }
  15. Contract Deployment Automation ;
  16. Error Handling & Recovery ; šŸŽØ UI/UX Innovations
  17. Dynamic Button States ;
  18. Real-time Dashboard Updates ;
  19. Progressive Enhancement ; šŸ” Security Considerations
  20. 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
  21. Input Validation ; šŸš€ Deployment & Infrastructure
  22. Multi-Environment Support Local Development - Hardhat local node Sepolia Testnet - Production-like testing environment Environment Configuration - .env.sepolia for testnet deployment
  23. 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! šŸš€
background image mobile

Join the mailing list

Get the latest news and updates