Skip to content

CryptoInnovators/Betlify-x-Layerzero

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Betlify.fun: Cross-Chain Prediction Markets Builder on Solana

Decentralized prediction markets with seamless cross-chain interoperability

Betlify.fun is a no-code prediction market platform that enables anyone to create, participate in, and profit from custom prediction markets. Built on Solana with LayerZero v2 OApp integration, it provides true cross-chain functionality allowing users from any blockchain to participate seamlessly.

Click the image to watch the Demo

Watch Demo

🎯 Core Concept

Unlike traditional prediction markets that restrict users to curated markets, Betlify.fun empowers individuals to create markets around any topic or event. Market creators earn a percentage of pool funds, incentivizing high-quality, engaging markets. The platform's cross-chain architecture breaks down blockchain silos, opening up liquidity and participation from across the entire ecosystem.

πŸ”„ Cross-Chain Architecture Flow

                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                    β”‚   Betlify.fun   β”‚
                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                              β”‚
                                              β–Ό
                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                    β”‚  User Actions   β”‚
                                    β”‚ Create Pool, Place Bet, Claim Winnings β”‚
                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                              β”‚
                                              β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚                                                 β”‚
                    β–Ό                                                 β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚ EVM Users           β”‚                         β”‚ Solana Users        β”‚
            β”‚ (Ethereum, Polygon, etc.)                     β”‚                     β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β”‚                                                 β”‚
                      β–Ό                                                 β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚ Borsh Serialization β”‚                         β”‚ Betlify Solana      β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                         β”‚ Program             β”‚
                      β”‚                                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚ EVM Contract        β”‚
            β”‚ (BetlifyEvm Adapter)β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β”‚
                      β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚ LayerZero Executor  β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β”‚
                      β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚ Betlify Solana      β”‚
            β”‚ Program             β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ—οΈ Technical Architecture Deep Dive

πŸ¦€ Rust/Anchor Smart Contracts

The core of Betlify.fun is built with Rust and the Anchor framework, providing type-safe, efficient smart contracts on Solana.

Program Structure

programs/my_oapp/src/
β”œβ”€β”€ lib.rs                    # Main program entry point
β”œβ”€β”€ instructions/             # Core betting logic
β”‚   β”œβ”€β”€ create_pool.rs        # Market creation with PDA
β”‚   β”œβ”€β”€ place_bet.rs          # Bet placement with validation
β”‚   β”œβ”€β”€ resolve_market.rs     # Market resolution
β”‚   β”œβ”€β”€ claim_winnings.rs     # Payout processing
β”‚   └── lz_receive.rs         # Cross-chain message handler
β”œβ”€β”€ state/                    # Account data structures
β”‚   β”œβ”€β”€ bet_pool.rs           # Pool state management
β”‚   β”œβ”€β”€ bet.rs                # Individual bet tracking
β”‚   β”œβ”€β”€ store.rs              # Global program state
β”‚   └── peer_config.rs        # LayerZero peer configuration
└── msg_codec.rs              # Anchor serialization/deserialization of BetlifyMessage

πŸ“¨ Cross-Chain Message Serialization

Borsh Serialization Architecture

Betlify.fun uses Borsh serialization for efficient cross-chain message passing:

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, PartialEq)]
pub enum BetlifyMessage {
    CreatePool {
        question: String,
        options: Vec<String>,
        pool_id: u64,
        start_time: i64,
        lock_time: i64,
        end_time: i64,
    },
    PlaceBet {
        pool_id: u64,
        option: u8,
        amount: u64,
    },
    ResolveMarket {
        pool_id: u64,
        winning_option: u8,
    },
    ClaimWinnings {
        pool_id: u64,
    },
}

Frontend Encoding Using Borsh (TypeScript)

To pass structured BetlifyMessage that is compatible with Anchor's Deserialize, we used borsh to encode and serialize messages.

// Borsh schema for CreatePool message
const createPoolSchema = borsh.struct([
  borsh.u8("variant"),
  borsh.str("question"),
  borsh.vec(borsh.str(), "options"),
  borsh.u64("pool_id"),
  borsh.i64("start_time"),
  borsh.i64("lock_time"),
  borsh.i64("end_time"),
]);

// Encode message for cross-chain transmission
export function encodeBetlifyMessage(message: BetlifyMessage): Buffer {
  const buffer = Buffer.alloc(1000);
  schema.encode(data, buffer);
  return buffer.subarray(0, schema.getSpan(buffer));
}

Solana Deserialization

Function to handle deserialization in Betlify Solana Program

// Decode incoming cross-chain messages
pub fn decode_betlify_message(data: &[u8]) -> std::result::Result<BetlifyMessage,        MsgCodecError> {
    BetlifyMessage::try_from_slice(data).map_err(|_| MsgCodecError::InvalidUtf8)
}

// Example using it in the Program's logic
match msg_codec::decode_betlify_message(&params.message) {
    Ok(betlify_msg) => {
        match betlify_msg {
            BetlifyMessage::CreatePool { question, options, pool_id, .. } => {
                // Create new pool with deterministic PDA
                let bet_pool = &mut ctx.accounts.bet_pool;
                bet_pool.id = pool_id;
                bet_pool.question = question;
                // ... initialize pool state
            }
            // ... handle other message types
        }
    }
    Err(err) => return Err(BetlifyError::InvalidMessage.into())
}

πŸ” Program Derived Addresses (PDAs)

Betlify.fun leverages deterministic PDAs for efficient account management and cross-chain coordination:

Core PDA Seeds

// Store account - Global program state
seeds = [b"Store"]

// BetPool accounts - Unique per creator and pool ID
seeds = [b"betpool", creator.key().as_ref(), &pool_id.to_le_bytes()]

// Bet accounts - Unique per user and pool
seeds = [b"bet", user.key().as_ref(), bet_pool.key().as_ref()]

// Peer configuration - LayerZero cross-chain setup
seeds = [PEER_SEED, &store.key().to_bytes(), &src_eid.to_be_bytes()]

PDA Benefits

  • Deterministic Addressing: Predictable account addresses across chains
  • Gas Efficiency: No need to store account addresses in messages
  • Cross-Chain Coordination: EVM contracts can derive Solana account addresses
  • Security: Prevents account collision and unauthorized access

πŸ”— EVM contract logic to send BetlifyMessages

The EVM contract contains one primary method to send Betlify Messages.

EVM Side (Solidity)

// BetlifyEvmAdapter.sol - Cross-chain interface
contract BetlifyEvmAdapter is Ownable, OApp, OAppOptionsType3 {
    function sendBetlifyAction(
        uint32 dstEid,
        bytes calldata message,
        bytes calldata optionsData
    ) external payable returns (MessagingReceipt memory receipt) {
        bytes memory lzOptions = combineOptions(dstEid, 1, optionsData);
        receipt = _lzSend(dstEid, message, lzOptions, MessagingFee(msg.value, 0), payable(msg.sender));
    }
}

🎨 Frontend Architecture

Modern React + TypeScript frontend with comprehensive cross-chain support:

frontend/client/src/
β”œβ”€β”€ components/                # Reusable UI components
β”‚   β”œβ”€β”€ market-card.tsx        # Market display component
β”‚   β”œβ”€β”€ market-carousel.tsx    # Market browsing
β”‚   β”œβ”€β”€ wallet-connect-modal.tsx # Multi-chain wallet support
β”‚   └── ui/                    # Design system components
β”œβ”€β”€ pages/                     # Main application pages
β”‚   β”œβ”€β”€ home.tsx               # Market discovery
β”‚   β”œβ”€β”€ create-market.tsx      # Market creation interface
β”‚   └── bet-details.tsx        # Detailed market view
β”œβ”€β”€ contexts/                  # State management
β”‚   └── WalletContext.tsx      # Multi-chain wallet context
β”œβ”€β”€ hooks/                     # Custom React hooks
β”œβ”€β”€ lib/                       # Contract interactions
β”‚   β”œβ”€β”€ contracts.ts           # Solana program client
β”‚   β”œβ”€β”€ encodeBetlifyMessage.ts # Borsh encoding utilities
β”‚   └── solana-contracts.ts    # Solana-specific utilities
└── types/                     # TypeScript type definitions

Deployment details.

πŸš€ Getting Started

Prerequisites

  • Node.js 18+
  • Rust 1.70+
  • Solana CLI
  • Anchor CLI

Quick Start

  1. Clone and setup

    git clone https://github.com/yourusername/betlify.fun.git
    cd betlify.fun
  2. Build Solana programs

    cd programs/my_oapp
    cargo build
    anchor build
  3. Deploy contracts

    # Deploy Solana program
    anchor deploy
    
    # Deploy EVM adapter
    npx hardhat deploy --network <network>
  4. Configure LayerZero endpoints

    # Update lib/config.ts with your LayerZero endpoints
  5. Run frontend

    cd frontend/client
    npm install
    npm run dev

πŸ”§ Development

Building and Testing

# Solana program development
anchor build
anchor test

# EVM contract testing
npx hardhat test

# Cross-chain integration testing
cd test/betlify-test
npm run test:cross-chain

Key Development Commands

# Verifiable build with environment variable
anchor build -v -e MYOAPP_ID=<OAPP_PROGRAM_ID>

# Generate client SDK
cd lib && npm run generate

# Deploy to specific networks
npx hardhat deploy --network optimism-testnet
npx hardhat deploy --network solana-testnet

πŸ“Š Project Structure

betlify.fun/
β”œβ”€β”€ programs/my_oapp/          # πŸ¦€ Solana smart contracts (Rust/Anchor)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ instructions/      # Core betting logic
β”‚   β”‚   β”œβ”€β”€ state/             # Account data structures
β”‚   β”‚   β”œβ”€β”€ msg_codec.rs       # Borsh serialization
β”‚   β”‚   └── lib.rs             # Program entry point
β”‚   └── Cargo.toml
β”œβ”€β”€ contracts/                 # πŸ”— EVM contracts (Solidity)
β”‚   β”œβ”€β”€ BetlifyOApp.sol        # Cross-chain adapter
β”‚   └── libs/BetlifyMsgCodec.sol # Message encoding
β”œβ”€β”€ frontend/client/           # 🎨 React frontend
β”œβ”€β”€ lib/                       # πŸ“š SDK and utilities
β”‚   β”œβ”€β”€ client/                # Generated Solana client
β”‚   └── scripts/               # Deployment and testing
β”œβ”€β”€ deploy/                    # πŸš€ Deployment scripts
β”œβ”€β”€ test/                      # πŸ§ͺ Test suites
└── docs/                      # πŸ“– Documentation

πŸ—ΊοΈ Roadmap

Phase 1: Core Platform βœ…

  • Solana smart contracts with PDA architecture
  • LayerZero v2 OApp integration
  • Borsh cross-chain message serialization
  • Basic frontend interface

Phase 2: Enhanced Features 🚧

  • OFT (Omnichain Fungible Token) integration for cross-chain payouts
  • Advanced market resolution mechanisms
  • Dispute resolution system
  • Community governance features

Phase 3: Ecosystem Growth πŸ“ˆ

  • Open API for third-party integrations
  • Mobile app development
  • Advanced analytics dashboard
  • Institutional features

🀝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Guidelines

  • Follow Rust/Anchor best practices for Solana programs
  • Use TypeScript for frontend development
  • Write comprehensive tests for all new features
  • Document your code and APIs
  • Ensure cross-chain compatibility

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgements

  • LayerZero - Cross-chain messaging infrastructure
  • Anchor - Solana smart contract framework
  • Solana - High-performance blockchain platform
  • Borsh - Binary serialization format

Betlify.fun β€” Own the market. Predict the future. From any chain.

About

A basic integration of LayerZero V2 OApp into Betlify.Fun

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 88.8%
  • Rust 9.3%
  • Other 1.9%