Deployment Guide

Deployment Guide

Complete deployment procedures and network configuration for production environments

Overview

This guide covers the complete deployment process for the Bet0x Protocol smart contracts, from local testing to production deployment on Arbitrum and other networks.

Local Development

Setup and testing environment

Testnet Deployment

Deploy and verify on testnets

Production Launch

Mainnet deployment and monitoring

Prerequisites

Development Environment

  • Node.js 18+ and npm/yarn/pnpm
  • Hardhat development framework
  • Git for version control
  • Code editor (VS Code recommended)

Network Requirements

  • Ethereum wallet with deployment funds
  • RPC endpoints for target networks
  • Block explorer API keys (optional)
  • Security audit completion
Local Development Setup

1. Clone and Install

Terminal
git clone <repository-url>
cd bet-protocol/contracts
npm install
# or
pnpm install

2. Environment Configuration

Create .env file:

.env
# Network Configuration
ARBITRUM_RPC_URL=https://arb1.arbitrum.io/rpc
ARBITRUM_SEPOLIA_RPC_URL=https://sepolia-rollup.arbitrum.io/rpc
ETHEREUM_RPC_URL=https://mainnet.infura.io/v3/YOUR_KEY

# Deployment Keys (NEVER commit to git)
DEPLOYER_PRIVATE_KEY=your_private_key_here
ADMIN_PRIVATE_KEY=your_admin_private_key_here

# Verification Keys
ARBISCAN_API_KEY=your_arbiscan_api_key
ETHERSCAN_API_KEY=your_etherscan_api_key

# Protocol Configuration
PLATFORM_FEE_RATE=250  # 2.5%
TREASURY_ADDRESS=0x...
INITIAL_ADMIN_ADDRESS=0x...

3. Run Tests

Testing Commands
# Run all tests
npx hardhat test

# Run specific test file
npx hardhat test test/BettingCore.test.ts

# Run tests with gas reporting
REPORT_GAS=true npx hardhat test

# Run tests with coverage
npx hardhat coverage
Deployment Scripts

Main Deployment Script

Create scripts/deploy.ts:

import { ethers } from "hardhat";

async function main() {
  console.log("šŸš€ Starting Bet0x Protocol deployment...");
  
  const [deployer] = await ethers.getSigners();
  const network = await ethers.provider.getNetwork();
  
  console.log("Deploying with account:", deployer.address);
  console.log("Network:", network.name);
  console.log("Chain ID:", network.chainId);
  
  // 1. Deploy DiamondCutFacet
  console.log("\nšŸ“¦ Deploying DiamondCutFacet...");
  const DiamondCutFacet = await ethers.getContractFactory("DiamondCutFacet");
  const diamondCutFacet = await DiamondCutFacet.deploy();
  await diamondCutFacet.deployed();
  console.log("āœ… DiamondCutFacet deployed to:", diamondCutFacet.address);
  
  // 2. Deploy Diamond
  console.log("\nšŸ’Ž Deploying Diamond...");
  const Diamond = await ethers.getContractFactory("Diamond");
  const diamond = await Diamond.deploy(deployer.address, diamondCutFacet.address);
  await diamond.deployed();
  console.log("āœ… Diamond deployed to:", diamond.address);
  
  // Continue with other facets...
  
  console.log("\nšŸŽ‰ Deployment completed successfully!");
  console.log("Diamond address:", diamond.address);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error("āŒ Deployment failed:", error);
    process.exit(1);
  });

Verification Script

Create scripts/verify.ts:

import { run } from "hardhat";

async function main() {
  const network = process.env.HARDHAT_NETWORK || "arbitrum";
  const deployment = JSON.parse(readFileSync(`deployments/${network}-latest.json`, "utf8"));
  
  console.log("šŸ” Verifying contracts on", network);
  
  const contracts = [
    { name: "DiamondCutFacet", address: deployment.diamondCutFacet, args: [] },
    { name: "Diamond", address: deployment.diamond, args: [deployment.deployerAddress, deployment.diamondCutFacet] },
    // Add other contracts...
  ];
  
  for (const contract of contracts) {
    try {
      console.log(`Verifying ${contract.name} at ${contract.address}...`);
      await run("verify:verify", {
        address: contract.address,
        constructorArguments: contract.args,
      });
      console.log(`āœ… ${contract.name} verified`);
    } catch (error) {
      console.log(`āŒ Failed to verify ${contract.name}:`, error.message);
    }
  }
}
Testnet Deployment

Arbitrum Sepolia

Deployment Commands
# Deploy to Arbitrum Sepolia testnet
npx hardhat run scripts/deploy.ts --network arbitrumSepolia

# Verify contracts
npx hardhat run scripts/verify.ts --network arbitrumSepolia

Testing on Testnet

# Run integration tests against testnet deployment
npx hardhat test test/integration/ --network arbitrumSepolia
Mainnet Deployment

Pre-deployment Checklist

All tests passing locally
Security audit completed
Testnet deployment successful
Gas optimization analysis complete
Multi-sig wallet set up
Emergency procedures documented
Monitoring and alerting configured
Backup and recovery plan ready

Production Deployment

Production Commands
# Deploy to Arbitrum mainnet
npx hardhat run scripts/deploy.ts --network arbitrum

# Verify all contracts
npx hardhat run scripts/verify.ts --network arbitrum

# Transfer ownership to multi-sig
npx hardhat run scripts/transfer-ownership.ts --network arbitrum
Post-Deployment Setup

Initial Configuration

// Set up initial roles and parameters
async function postDeploymentSetup(diamondAddress: string) {
  const diamond = await ethers.getContractAt("BettingCoreFacet", diamondAddress);
  
  // Grant oracle roles
  const oracleAddresses = [
    "0x...", // Oracle 1
    "0x...", // Oracle 2
  ];
  
  for (const oracle of oracleAddresses) {
    await diamond.grantRole(
      ethers.utils.keccak256(ethers.utils.toUtf8Bytes("ORACLE_ROLE")),
      oracle
    );
  }
  
  // Set up platform parameters
  await diamond.setPlatformFeeRate(250); // 2.5%
  await diamond.setTreasury("0x..."); // Treasury address
}

Monitoring Setup

// Set up monitoring for critical events
const monitoringEvents = [
  'EventCreated',
  'BetPlaced', 
  'EventResolved',
  'EmergencyPause',
  'BlacklistAdded'
];

for (const eventName of monitoringEvents) {
  diamond.on(eventName, (...args) => {
    console.log(`Event ${eventName} detected:`, args);
    // Send to monitoring service
    sendToMonitoring(eventName, args);
  });
}