← Back to home

Betly

APT/USD binary options on Aptos with Pyth pull oracle. Bet UP/DOWN on 60 second rounds, win 1.8x

Problem Statement

Betly is a decentralized binary options platform built on Aptos that enables users to bet on APT/USD price movements using real-time Pyth Network price feeds.CORE FEATURES:Binary Options Trading: Users bet UP or DOWN on APT/USD price movements60 second Rounds: Fast-paced betting with automated round cycling1.8x Payout: Winners receive 1.8x their bet amountReal-Time Prices: Live APT/USD price feeds from Pyth NetworkAutomated Settlement: Keeper services handle round management and payoutsTransparent Fees: 2% protocol fee collected from losing betsPYTH INTEGRATION: Betly implements the complete Pyth pull oracle pattern required for hackathon qualification:Fetch: Pulls price data from Pyth Hermes APIUpdate: Updates price feeds on-chain via smart contractConsume: Consumes prices directly from smart contract for settlementUSER EXPERIENCE:Clean, intuitive interface with real-time price chartsWebSocket integration for live price updatesAutomated claiming system for winningsComprehensive round history and statisticsINNOVATION:First binary options platform on Aptos with Pyth integrationComplete pull oracle pattern implementationAutomated keeper service with price verificationOn-chain price tracking with transaction hash verification

Solution

ARCHITECTURE OVERVIEW: Betly is built as a full-stack DeFi application with three main components: Move smart contracts, Next.js frontend, and automated keeper services.SMART CONTRACT LAYER (Move on Aptos):Core Module: betly_betting::betting handles all betting logicPyth Integration: Custom price feed management with on-chain storageKey Functions:start_round_with_pyth() - Starts rounds using Pyth pricessettle_with_pyth() - Settles rounds with Pyth price verificationupdate_pyth_price_feed() - Updates on-chain price dataData Structures: Enhanced Round struct with Pyth fields, PythPriceFeed for price trackingEvents: Comprehensive event system for price consumption and settlement trackingFRONTEND LAYER (Next.js + TypeScript):Framework: Next.js 15 with App RouterUI: Tailwind CSS for styling, Lucide React for iconsCharts: Lightweight Charts for real-time price visualizationState Management: Zustand for global stateWallet Integration: Aptos wallet adapter for Petra walletReal-Time Updates: WebSocket connection to Pyth Hermes for live pricesBACKEND SERVICES (API Routes):Price API: /api/price - Enhanced with Pyth pull oracle integrationKeeper Services:/api/keeper/start - Starts rounds using Pyth pull oracle/api/keeper/settle - Settles rounds with Pyth price verificationPyth Integration: /api/pyth-pull-oracle - Dedicated endpoint for pull oracle operationsContract Interaction: Direct Aptos SDK integration for smart contract callsPYTH PULL ORACLE IMPLEMENTATION:// Step 1: Fetch from Hermes const priceData = await pythPullOracle.fetchPriceFromHermes(priceId) // Step 2: Update on-chain via smart contract await pythPullOracle.updatePriceFeedsOnChain([priceId]) // Step 3: Consume from smart contract const onChainPrice = await pythPullOracle.getPriceFromOnChain(priceId)KEY TECHNOLOGIES:Blockchain: Aptos (Move smart contracts)Oracle: Pyth Network (Hermes API + pull oracle pattern)Frontend: Next.js, React, TypeScript, Tailwind CSSCharts: Lightweight Charts for price visualizationWallet: Aptos wallet adapterDeployment: Vercel for frontend, Aptos testnet for contractsPARTNER TECHNOLOGY BENEFITS:Pyth Network: Provides accurate, real-time APT/USD prices with sub-second updatesAptos: Fast transaction finality and low fees for optimal user experienceVercel: Seamless deployment and edge functions for API routesNOTABLE TECHNICAL ACHIEVEMENTS:Complete Pull Oracle Pattern: Full implementation of fetch → update → consume flowOn-Chain Price Verification: Transaction hashes track price update provenanceAutomated Keeper Integration: Seamless round management with Pyth price feedsFallback Mechanisms: Multiple layers of reliability for price dataGas Optimization: Batch operations and efficient smart contract designReal-Time UI: WebSocket + REST API hybrid for optimal user experienceHACKY SOLUTIONS:Mock Transaction Hashes: Used for demonstration when actual Pyth contract integration isn't availableFallback Price Sources: Hermes API fallback when on-chain prices aren't availableSequence Number Retry Logic: Handles Aptos transaction sequence number issuesPrice Precision Handling: Micro-dollar conversion for accurate price storageKEY FILES:move/sources/betting.move - Smart contract with Pyth integrationsrc/lib/pyth-pull-oracle.ts - Pyth pull oracle servicesrc/app/api/pyth-pull-oracle/route.ts - Pyth API endpointsrc/tests/pyth-pull-oracle.test.ts - Comprehensive test suite

Hackathon

ETHGlobal New Delhi

2025

Contributors