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.
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.
βββββββββββββββββββ
β 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 β
βββββββββββββββββββββββ
The core of Betlify.fun is built with Rust and the Anchor framework, providing type-safe, efficient smart contracts on Solana.
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
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,
},
}
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));
}
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(¶ms.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())
}
Betlify.fun leverages deterministic PDAs for efficient account management and cross-chain coordination:
// 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()]
- 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
The EVM contract contains one primary method to send Betlify Messages.
// 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));
}
}
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
- Solana OApp Program ID: EzSWvfipsRAQxPspMFm9QVot1jHwAGxKYWtnNi8YFT5R
- Solana OApp Address (Store): 7zT3rAb8tNAK8mSewyxRz7ubbDtnXEcSaoJnyVyg4f8n
- EVM OApp Address: 0x2ED9929e3AA3CAd3553aA90014894300D3Fa224d
- LayerZero Scan: https://testnet.layerzeroscan.com/address/7zT3rAb8tNAK8mSewyxRz7ubbDtnXEcSaoJnyVyg4f8n
- Node.js 18+
- Rust 1.70+
- Solana CLI
- Anchor CLI
-
Clone and setup
git clone https://github.com/yourusername/betlify.fun.git cd betlify.fun
-
Build Solana programs
cd programs/my_oapp cargo build anchor build
-
Deploy contracts
# Deploy Solana program anchor deploy # Deploy EVM adapter npx hardhat deploy --network <network>
-
Configure LayerZero endpoints
# Update lib/config.ts with your LayerZero endpoints
-
Run frontend
cd frontend/client npm install npm run dev
# 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
# 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
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
- Solana smart contracts with PDA architecture
- LayerZero v2 OApp integration
- Borsh cross-chain message serialization
- Basic frontend interface
- OFT (Omnichain Fungible Token) integration for cross-chain payouts
- Advanced market resolution mechanisms
- Dispute resolution system
- Community governance features
- Open API for third-party integrations
- Mobile app development
- Advanced analytics dashboard
- Institutional features
We welcome contributions! Please see our Contributing Guidelines for details.
- 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
This project is licensed under the MIT License - see the LICENSE file for details.
- 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.