Overview
The EVM contracts package provides betting infrastructure for BSC and Base networks:- GoldClob - Central Limit Order Book for duel outcome betting
- AgentPerpEngine - Perpetual futures for agent skill ratings (ERC20 margin)
- AgentPerpEngineNative - Perpetual futures with native token margin
- SkillOracle - Oracle for agent skill updates
- MockERC20 - Test token for local development
Deployment Metadata System
All contract addresses are managed in a centralized deployment manifest:packages/gold-betting-demo/deployments/contracts.json- Single source of truthpackages/gold-betting-demo/deployments/index.ts- Typed configuration with runtime validation
- Eliminates hardcoded addresses scattered across codebase
- Type-safe access to deployment metadata
- Automatic validation of manifest structure
- Shared across frontend, keeper, deployment scripts, and tests
Preflight Validation
Before deploying to any network, run preflight checks:- ✅ Solana program keypairs match deployment manifest
- ✅ Anchor IDL files match deployment manifest
- ✅ App and keeper IDL files are in sync
- ✅ EVM deployment environment variables are configured
- ✅ EVM RPC URLs are available (configured or using Hardhat fallbacks)
- ✅ Contract addresses are present in deployment manifest
- Warnings: Missing RPC URLs (will use fallbacks), pending contract addresses
- Failures: Mismatched program IDs, missing required env vars, invalid addresses
Deploy to Testnet
Deploy GoldClob contracts to testnet networks:PRIVATE_KEY- Deployer private key (required)BSC_RPC_URL- BSC RPC endpoint (optional, uses Hardhat fallback if not set)BASE_RPC_URL- Base RPC endpoint (optional, uses Hardhat fallback if not set)GOLD_TOKEN_ADDRESS- GOLD token address (optional, recorded in deployment receipt)
- Validates treasury and market maker addresses (uses deployer address for testnet)
- Deploys GoldClob contract
- Writes deployment receipt to
deployments/<network>.json - Updates central manifest at
../gold-betting-demo/deployments/contracts.json
Deploy to Mainnet
Deploy GoldClob contracts to mainnet networks:PRIVATE_KEY- Deployer private key (required)TREASURY_ADDRESS- Treasury address for fee collection (required for mainnet)MARKET_MAKER_ADDRESS- Market maker address for fee collection (required for mainnet)GOLD_TOKEN_ADDRESS- GOLD token address (optional, recorded in deployment receipt)BSC_RPC_URL/BASE_RPC_URL- RPC endpoints (optional, uses Hardhat fallbacks if not set)
- Mainnet deployments require explicit
TREASURY_ADDRESSandMARKET_MAKER_ADDRESS - Deployment fails if these are not set (prevents accidental use of deployer address)
- Validates all addresses before deployment
Deployment Receipts
Each deployment writes a detailed receipt topackages/evm-contracts/deployments/<network>.json:
contracts.json manifest after successful deployment.
Typed Contract Helpers
Thetyped-contracts.ts module provides type-safe contract deployment and interaction:
GoldClobContract- CLOB market with typed methodsSkillOracleContract- Oracle with typed skill updatesMockERC20Contract- Test token with typed mint/approveAgentPerpEngineContract- Perps engine with typed position managementAgentPerpEngineNativeContract- Native token perps engine
- Compile-time type checking for all contract interactions
- IntelliSense support in tests and scripts
- Prevents common errors (wrong parameter types, missing overrides)
- Consistent deployment patterns across test suites
Local Testing
Run the full EVM contract test suite:- GoldClob basic functionality
- GoldClob exploit resistance (post-fix validation)
- GoldClob fuzz testing (randomized invariants)
- GoldClob round 2 security fixes
- AgentPerpEngine security regressions
- AgentPerpEngineNative security regressions
Local Simulation
Run local EVM simulation with PnL reporting:- Whale round trip (large position open/close)
- Funding rate drift
- Isolated insurance containment
- Positive equity liquidation
- Local insurance shortfall
- Fee recycling into isolated insurance
- Model deprecation lifecycle
simulations/gold-clob-localnet-report.json
Fee Structure
GoldClob fees:tradeTreasuryFeeBps- Fee to treasury on every trade (default: 100 BPS = 1%)tradeMarketMakerFeeBps- Fee to market maker on every trade (default: 100 BPS = 1%)winningsMarketMakerFeeBps- Fee to market maker on claim (default: 200 BPS = 2%)
- Trade fees: Split between treasury and market maker
- Claim fees: Route to market maker
- Market maker fees can be recycled into liquidity
Troubleshooting
Deployment fails with “Invalid TREASURY_ADDRESS”:- Ensure
TREASURY_ADDRESSis set for mainnet deployments - Verify address is a valid Ethereum address (checksummed)
- Check deployer wallet balance
- Ensure wallet has enough native tokens for gas (BNB for BSC, ETH for Base)
- Verify RPC URL is correct and accessible
- Check RPC provider rate limits
- Try using Hardhat fallback RPC (remove custom RPC_URL env var)
- Verify
packages/gold-betting-demo/deployments/contracts.jsonexists - Check file permissions (must be writable)
- Ensure network key exists in manifest (bsc, bscTestnet, base, baseSepolia)
- Ensure
typed-contracts.tsis up to date with contract ABIs - Regenerate types if contract interfaces changed
- Check that all tests import from
typed-contracts.ts
Related Documentation
- Betting Production Deploy - Full deployment guide
- Gold Betting Demo - Betting stack overview
- Configuration - Environment variables