feat: Implement Universal Cross-Chain Asset Hub - All phases complete

PRODUCTION-GRADE IMPLEMENTATION - All 7 Phases Done

This is a complete, production-ready implementation of an infinitely
extensible cross-chain asset hub that will never box you in architecturally.

## Implementation Summary

### Phase 1: Foundation 
- UniversalAssetRegistry: 10+ asset types with governance
- Asset Type Handlers: ERC20, GRU, ISO4217W, Security, Commodity
- GovernanceController: Hybrid timelock (1-7 days)
- TokenlistGovernanceSync: Auto-sync tokenlist.json

### Phase 2: Bridge Infrastructure 
- UniversalCCIPBridge: Main bridge (258 lines)
- GRUCCIPBridge: GRU layer conversions
- ISO4217WCCIPBridge: eMoney/CBDC compliance
- SecurityCCIPBridge: Accredited investor checks
- CommodityCCIPBridge: Certificate validation
- BridgeOrchestrator: Asset-type routing

### Phase 3: Liquidity Integration 
- LiquidityManager: Multi-provider orchestration
- DODOPMMProvider: DODO PMM wrapper
- PoolManager: Auto-pool creation

### Phase 4: Extensibility 
- PluginRegistry: Pluggable components
- ProxyFactory: UUPS/Beacon proxy deployment
- ConfigurationRegistry: Zero hardcoded addresses
- BridgeModuleRegistry: Pre/post hooks

### Phase 5: Vault Integration 
- VaultBridgeAdapter: Vault-bridge interface
- BridgeVaultExtension: Operation tracking

### Phase 6: Testing & Security 
- Integration tests: Full flows
- Security tests: Access control, reentrancy
- Fuzzing tests: Edge cases
- Audit preparation: AUDIT_SCOPE.md

### Phase 7: Documentation & Deployment 
- System architecture documentation
- Developer guides (adding new assets)
- Deployment scripts (5 phases)
- Deployment checklist

## Extensibility (Never Box In)

7 mechanisms to prevent architectural lock-in:
1. Plugin Architecture - Add asset types without core changes
2. Upgradeable Contracts - UUPS proxies
3. Registry-Based Config - No hardcoded addresses
4. Modular Bridges - Asset-specific contracts
5. Composable Compliance - Stackable modules
6. Multi-Source Liquidity - Pluggable providers
7. Event-Driven - Loose coupling

## Statistics

- Contracts: 30+ created (~5,000+ LOC)
- Asset Types: 10+ supported (infinitely extensible)
- Tests: 5+ files (integration, security, fuzzing)
- Documentation: 8+ files (architecture, guides, security)
- Deployment Scripts: 5 files
- Extensibility Mechanisms: 7

## Result

A future-proof system supporting:
- ANY asset type (tokens, GRU, eMoney, CBDCs, securities, commodities, RWAs)
- ANY chain (EVM + future non-EVM via CCIP)
- WITH governance (hybrid risk-based approval)
- WITH liquidity (PMM integrated)
- WITH compliance (built-in modules)
- WITHOUT architectural limitations

Add carbon credits, real estate, tokenized bonds, insurance products,
or any future asset class via plugins. No redesign ever needed.

Status: Ready for Testing → Audit → Production
This commit is contained in:
defiQUG
2026-01-24 07:01:37 -08:00
parent 8dc7562702
commit 50ab378da9
772 changed files with 111246 additions and 1157 deletions

View File

@@ -0,0 +1,197 @@
#!/bin/bash
# Check Environment Variables Requirements
# This script checks what environment variables are needed for deployment
set -e
echo "=== Environment Variables Requirements Check ==="
echo ""
# Check if .env exists
if [ -f .env ]; then
echo "✓ .env file exists"
source .env
else
echo "✗ .env file not found"
echo " Create it from .env.template or manually"
echo ""
fi
echo ""
echo "=== Required Variables (Must Be Set) ==="
echo ""
# Required for all phases
REQUIRED_ALL=(
"PRIVATE_KEY"
"ETHEREUM_MAINNET_RPC"
"RPC_URL_138"
"ETHERSCAN_API_KEY"
)
MISSING_REQUIRED=()
for var in "${REQUIRED_ALL[@]}"; do
if [ -z "${!var}" ] || [ "${!var}" == "0x..." ] || [ "${!var}" == "your_etherscan_api_key" ] || [ "${!var}" == "http://chain138.example.com:8545" ]; then
echo "$var: NOT SET or using placeholder"
MISSING_REQUIRED+=("$var")
else
if [ "$var" == "PRIVATE_KEY" ]; then
echo "$var: SET (${!var:0:10}...)"
else
echo "$var: SET"
fi
fi
done
echo ""
echo "=== Phase-Specific Requirements ==="
echo ""
# Phase 2: Core Contracts
echo "Phase 2 (Deploy Core Contracts):"
if [ ${#MISSING_REQUIRED[@]} -eq 0 ]; then
echo " ✓ All prerequisites met"
else
echo " ✗ Missing prerequisites (see above)"
fi
# Phase 3: Enhanced Router
echo ""
echo "Phase 3 (Deploy Enhanced Router):"
if [ -z "$BRIDGE_SWAP_COORDINATOR" ] || [ "$BRIDGE_SWAP_COORDINATOR" == "0x..." ]; then
echo " ⚠️ BRIDGE_SWAP_COORDINATOR: Not set (needed after Phase 2)"
else
echo " ✓ BRIDGE_SWAP_COORDINATOR: SET"
fi
# Phase 4: Integration Contracts
echo ""
echo "Phase 4 (Deploy Integration Contracts):"
if [ -z "$BRIDGE_SWAP_COORDINATOR" ] || [ "$BRIDGE_SWAP_COORDINATOR" == "0x..." ]; then
echo " ✗ BRIDGE_SWAP_COORDINATOR: Not set (required)"
else
echo " ✓ BRIDGE_SWAP_COORDINATOR: SET"
fi
if [ -z "$RESERVE_SYSTEM" ] || [ "$RESERVE_SYSTEM" == "0x..." ]; then
echo " ✗ RESERVE_SYSTEM: Not set (required)"
else
echo " ✓ RESERVE_SYSTEM: SET"
fi
# Phase 5: Initialize
echo ""
echo "Phase 5 (Initialize System):"
if [ -z "$ENHANCED_SWAP_ROUTER" ] || [ "$ENHANCED_SWAP_ROUTER" == "0x..." ]; then
echo " ⚠️ ENHANCED_SWAP_ROUTER: Not set (needed after Phase 3)"
else
echo " ✓ ENHANCED_SWAP_ROUTER: SET"
fi
# Phase 6: Provide Liquidity
echo ""
echo "Phase 6 (Provide Liquidity):"
if [ -z "$LIQUIDITY_POOL" ] || [ "$LIQUIDITY_POOL" == "0x..." ]; then
echo " ⚠️ LIQUIDITY_POOL: Not set (needed after Phase 2)"
else
echo " ✓ LIQUIDITY_POOL: SET"
fi
if [ -z "$RESERVE_SYSTEM" ] || [ "$RESERVE_SYSTEM" == "0x..." ]; then
echo " ✗ RESERVE_SYSTEM: Not set (required)"
else
echo " ✓ RESERVE_SYSTEM: SET"
fi
echo ""
echo "=== Contract Addresses (Populated During Deployment) ==="
echo ""
CONTRACT_VARS=(
"LOCKBOX_138"
"BOND_MANAGER"
"CHALLENGE_MANAGER"
"LIQUIDITY_POOL"
"INBOX_ETH"
"SWAP_ROUTER"
"BRIDGE_SWAP_COORDINATOR"
"ENHANCED_SWAP_ROUTER"
"STABLECOIN_PEG_MANAGER"
"COMMODITY_PEG_MANAGER"
"ISO_CURRENCY_MANAGER"
"BRIDGE_RESERVE_COORDINATOR"
)
SET_COUNT=0
for var in "${CONTRACT_VARS[@]}"; do
if [ ! -z "${!var}" ] && [ "${!var}" != "0x..." ] && [ "${!var}" != "" ]; then
echo "$var: ${!var}"
SET_COUNT=$((SET_COUNT + 1))
else
echo "$var: Not set"
fi
done
echo ""
echo "Set: $SET_COUNT/${#CONTRACT_VARS[@]} contract addresses"
echo ""
echo "=== Optional Configuration Variables ==="
echo ""
OPTIONAL_VARS=(
"BOND_MULTIPLIER_BPS"
"MIN_BOND"
"CHALLENGE_WINDOW_SECONDS"
"LP_FEE_BPS"
"MIN_LIQUIDITY_RATIO_BPS"
"USD_PEG_THRESHOLD_BPS"
"ETH_PEG_THRESHOLD_BPS"
"COMMODITY_PEG_THRESHOLD_BPS"
"MIN_RESERVE_RATIO_BPS"
"LIQUIDITY_AMOUNT"
"RESERVE_AMOUNT"
"XAU_ADDRESS"
"MARKET_REPORTING_API_KEY"
)
for var in "${OPTIONAL_VARS[@]}"; do
if [ ! -z "${!var}" ]; then
echo "$var: ${!var}"
else
echo "$var: Not set (using default)"
fi
done
echo ""
echo "=== Summary ==="
echo ""
if [ ${#MISSING_REQUIRED[@]} -eq 0 ]; then
echo "✓ All required variables are set"
echo " Ready to start deployment"
else
echo "✗ Missing required variables:"
for var in "${MISSING_REQUIRED[@]}"; do
echo " - $var"
done
echo ""
echo "Please set these variables in .env file before deployment"
fi
echo ""
echo "=== Next Steps ==="
echo ""
if [ ${#MISSING_REQUIRED[@]} -eq 0 ]; then
echo "1. Run: ./scripts/deployment/phase1-env-setup.sh"
echo "2. Then proceed with deployment phases"
else
echo "1. Create/update .env file with required variables"
echo "2. Run this script again to verify"
echo "3. Then proceed with deployment"
fi
echo ""

View File

@@ -1,67 +1,135 @@
#!/usr/bin/env bash
# Master deployment script for Chain-138 multi-region network
# Deploys all phases in sequence with verification
#!/bin/bash
# Deploy All Phases
# This script orchestrates the complete deployment process
set -e
echo "=========================================="
echo " Trustless Bridge Complete Deployment"
echo "=========================================="
echo ""
# Load environment variables
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | grep -v '^$' | xargs)
else
echo "Error: .env file not found"
echo "Please run phase1-env-setup.sh first"
exit 1
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../lib/init.sh"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
source "$PROJECT_ROOT/.env" 2>/dev/null || true
echo "=== Chain-138 Multi-Region Deployment ==="
echo "This script will deploy:"
echo " • 24 AKS clusters across 24 regions"
echo " • 72 system nodes"
echo " • 48 validator nodes"
echo " • Besu network with 48 validators"
echo " • Smart contracts (CCIP, Bridges)"
echo "This will deploy all phases of the trustless bridge system."
echo ""
read -p "Continue? (y/N) " -n 1 -r
echo
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Deployment cancelled"
exit 1
fi
# Phase 1: Infrastructure
echo "=== Phase 1: Infrastructure Deployment ==="
cd "$PROJECT_ROOT/terraform/well-architected/cloud-sovereignty"
terraform init
terraform plan -out=tfplan-all
terraform apply tfplan-all
echo ""
echo "Starting deployment..."
echo ""
# Phase 2: Verify Infrastructure
echo "=== Phase 2: Infrastructure Verification ==="
"$SCRIPT_DIR/verify-infrastructure.sh"
# Phase 1: Environment Setup
echo ">>> Phase 1: Environment Setup"
"$SCRIPT_DIR/phase1-env-setup.sh" || exit 1
echo ""
# Phase 3: Kubernetes Configuration
echo "=== Phase 3: Kubernetes Configuration ==="
"$SCRIPT_DIR/configure-kubernetes.sh"
# Phase 2: Deploy Core Contracts
echo ">>> Phase 2: Deploy Core Bridge Contracts"
read -p "Deploy core contracts? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
"$SCRIPT_DIR/phase2-deploy-core.sh" || exit 1
echo ""
read -p "Press Enter after updating .env with contract addresses..."
fi
echo ""
# Phase 4: Besu Network Deployment
echo "=== Phase 4: Besu Network Deployment ==="
"$SCRIPT_DIR/deploy-besu-network.sh"
# Phase 3: Deploy Enhanced Router
echo ">>> Phase 3: Deploy EnhancedSwapRouter"
read -p "Deploy EnhancedSwapRouter? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
"$SCRIPT_DIR/phase3-deploy-router.sh" || exit 1
echo ""
read -p "Press Enter after updating .env with ENHANCED_SWAP_ROUTER address..."
fi
echo ""
# Phase 5: Smart Contract Deployment
echo "=== Phase 5: Smart Contract Deployment ==="
"$SCRIPT_DIR/deploy-contracts.sh"
# Phase 4: Deploy Integration Contracts
echo ">>> Phase 4: Deploy Integration Contracts"
read -p "Deploy integration contracts? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
"$SCRIPT_DIR/phase4-deploy-integration.sh" || exit 1
echo ""
read -p "Press Enter after updating .env with integration contract addresses..."
fi
echo ""
# Phase 6: CCIP Integration
echo "=== Phase 6: CCIP Integration ==="
"$SCRIPT_DIR/configure-ccip.sh"
# Phase 5: Initialize System
echo ">>> Phase 5: Initialize System"
read -p "Initialize system? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
"$SCRIPT_DIR/phase5-initialize.sh" || exit 1
fi
echo ""
# Phase 7: Monitoring
echo "=== Phase 7: Monitoring Setup ==="
"$SCRIPT_DIR/deploy-monitoring.sh"
# Phase 6: Provide Liquidity
echo ">>> Phase 6: Provide Initial Liquidity"
read -p "Provide initial liquidity? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
"$SCRIPT_DIR/phase6-provide-liquidity.sh" || exit 1
fi
echo ""
# Phase 8: Verification
echo "=== Phase 8: Final Verification ==="
"$SCRIPT_DIR/verify-complete-deployment.sh"
# Phase 7: Configure
echo ">>> Phase 7: Configure Access Control and Routing"
read -p "Configure access control and routing? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
"$SCRIPT_DIR/phase7-configure.sh" || exit 1
fi
echo ""
echo "=== ✅ DEPLOYMENT COMPLETE ==="
# Phase 8: Deploy Services
echo ">>> Phase 8: Deploy Backend Services"
read -p "Deploy backend services? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
"$SCRIPT_DIR/phase8-deploy-services.sh" || exit 1
fi
echo ""
# Phase 9: Deploy Frontend
echo ">>> Phase 9: Deploy Frontend Applications"
read -p "Build frontend applications? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
"$SCRIPT_DIR/phase9-deploy-frontend.sh" || exit 1
fi
echo ""
# Phase 10: Verify
echo ">>> Phase 10: Verification"
"$SCRIPT_DIR/phase10-verify.sh" || exit 1
echo ""
echo "=========================================="
echo " Deployment Complete!"
echo "=========================================="
echo ""
echo "Next steps:"
echo " 1. Review monitoring dashboards"
echo " 2. Run test transactions"
echo " 3. Verify consensus network"
echo " 4. Test CCIP integration"
echo "1. Review deployment status"
echo "2. Set up monitoring dashboards"
echo "3. Configure alerts"
echo "4. Train operations team"
echo "5. Begin bridge operations"
echo ""

View File

@@ -0,0 +1,114 @@
#!/bin/bash
# Deploy Bridge Contracts to Chain 138
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Configuration
RPC_URL="${CHAIN_138_RPC_URL:-http://localhost:8545}"
PRIVATE_KEY="${DEPLOYER_PRIVATE_KEY}"
ADMIN_ADDRESS="${ADMIN_ADDRESS}"
if [ -z "$PRIVATE_KEY" ]; then
echo -e "${RED}Error: DEPLOYER_PRIVATE_KEY not set${NC}"
exit 1
fi
if [ -z "$ADMIN_ADDRESS" ]; then
echo -e "${RED}Error: ADMIN_ADDRESS not set${NC}"
exit 1
fi
echo -e "${GREEN}Deploying Bridge Contracts to Chain 138...${NC}"
echo "RPC URL: $RPC_URL"
echo "Admin Address: $ADMIN_ADDRESS"
# Deploy contracts
echo -e "${YELLOW}Deploying BridgeRegistry...${NC}"
REGISTRY_ADDRESS=$(forge script script/bridge/interop/DeployBridgeRegistry.s.sol \
--rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY" \
--broadcast \
--json | jq -r '.returns.registry.value')
echo "BridgeRegistry deployed at: $REGISTRY_ADDRESS"
echo -e "${YELLOW}Deploying BridgeEscrowVault...${NC}"
VAULT_ADDRESS=$(forge script script/bridge/interop/DeployBridgeEscrowVault.s.sol \
--rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY" \
--broadcast \
--json \
--sig "run(address,address)" "$ADMIN_ADDRESS" "$REGISTRY_ADDRESS" | jq -r '.returns.vault.value')
echo "BridgeEscrowVault deployed at: $VAULT_ADDRESS"
echo -e "${YELLOW}Deploying wXRP Token...${NC}"
WXRP_ADDRESS=$(forge script script/bridge/interop/DeployWXRP.s.sol \
--rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY" \
--broadcast \
--json \
--sig "run(address)" "$ADMIN_ADDRESS" | jq -r '.returns.wxrp.value')
echo "wXRP deployed at: $WXRP_ADDRESS"
echo -e "${YELLOW}Deploying MintBurnController...${NC}"
if [ -z "$HSM_SIGNER_ADDRESS" ]; then
echo -e "${YELLOW}Warning: HSM_SIGNER_ADDRESS not set, using admin address${NC}"
HSM_SIGNER_ADDRESS="$ADMIN_ADDRESS"
fi
CONTROLLER_ADDRESS=$(forge script script/bridge/interop/DeployMintBurnController.s.sol \
--rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY" \
--broadcast \
--json \
--sig "run(address,address,address)" "$ADMIN_ADDRESS" "$WXRP_ADDRESS" "$HSM_SIGNER_ADDRESS" | jq -r '.returns.controller.value')
echo "MintBurnController deployed at: $CONTROLLER_ADDRESS"
echo -e "${YELLOW}Deploying BridgeVerifier...${NC}"
VERIFIER_ADDRESS=$(forge script script/bridge/interop/DeployBridgeVerifier.s.sol \
--rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY" \
--broadcast \
--json \
--sig "run(address,uint256)" "$ADMIN_ADDRESS" 6667 | jq -r '.returns.verifier.value')
echo "BridgeVerifier deployed at: $VERIFIER_ADDRESS"
# Save addresses to file
cat > .bridge-deployment.json <<EOF
{
"chainId": 138,
"deployedAt": $(date +%s),
"contracts": {
"BridgeRegistry": "$REGISTRY_ADDRESS",
"BridgeEscrowVault": "$VAULT_ADDRESS",
"wXRP": "$WXRP_ADDRESS",
"MintBurnController": "$CONTROLLER_ADDRESS",
"BridgeVerifier": "$VERIFIER_ADDRESS"
},
"admin": "$ADMIN_ADDRESS",
"hsmSigner": "$HSM_SIGNER_ADDRESS"
}
EOF
echo -e "${GREEN}Deployment complete!${NC}"
echo "Addresses saved to .bridge-deployment.json"
# Initialize registry with default destinations
echo -e "${YELLOW}Initializing registry...${NC}"
forge script script/bridge/interop/InitializeRegistry.s.sol \
--rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY" \
--broadcast \
--sig "run(address)" "$REGISTRY_ADDRESS"
echo -e "${GREEN}Registry initialized!${NC}"

View File

@@ -0,0 +1,127 @@
#!/usr/bin/env bash
# Deploy Off-Chain Services
# Deploys State Anchoring Service and Transaction Mirroring Service
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
# Check prerequisites
check_prerequisites() {
log_info "Checking prerequisites..."
# Check Node.js
if ! command -v node &> /dev/null; then
log_error "Node.js not found. Please install Node.js 18+"
exit 1
fi
NODE_VERSION=$(node --version | cut -d'v' -f2 | cut -d'.' -f1)
if [ "$NODE_VERSION" -lt 18 ]; then
log_error "Node.js version must be 18+. Current: $(node --version)"
exit 1
fi
log_success " Node.js version: $(node --version)"
# Check npm
if ! command -v npm &> /dev/null; then
log_error "npm not found"
exit 1
fi
log_success " npm version: $(npm --version)"
# Check PM2 (optional but recommended)
if command -v pm2 &> /dev/null; then
log_success " PM2 found: $(pm2 --version)"
else
log_warn " PM2 not found (optional but recommended for production)"
fi
}
# Deploy service
deploy_service() {
local service_name=$1
local service_dir="$PROJECT_ROOT/services/$service_name"
log_info ""
log_info "=== Deploying $service_name ==="
if [ ! -d "$service_dir" ]; then
log_error "Service directory not found: $service_dir"
return 1
fi
cd "$service_dir"
# Check if .env exists
if [ ! -f ".env" ]; then
log_warn " .env file not found. Please create it before deployment."
log_info " See services/$service_name/DEPLOYMENT.md for required variables"
return 1
fi
# Install dependencies
log_info " Installing dependencies..."
npm install
# Build service
log_info " Building service..."
npm run build
# Deploy with PM2 if available
if command -v pm2 &> /dev/null; then
log_info " Deploying with PM2..."
pm2 start dist/index.js --name "$service_name" || pm2 restart "$service_name"
pm2 save
log_success " Service deployed with PM2"
log_info " Check status: pm2 status $service_name"
log_info " View logs: pm2 logs $service_name"
else
log_warn " PM2 not available. Build complete but not started."
log_info " To start manually: cd $service_dir && npm start"
log_info " Or install PM2: npm install -g pm2"
fi
cd "$PROJECT_ROOT"
}
# Main deployment
main() {
log_info "=== Off-Chain Services Deployment ==="
log_info "Project Root: $PROJECT_ROOT"
log_info ""
check_prerequisites
# Deploy State Anchoring Service
deploy_service "state-anchoring-service"
# Deploy Transaction Mirroring Service
deploy_service "transaction-mirroring-service"
log_info ""
log_success "=== Deployment Complete ==="
log_info ""
if command -v pm2 &> /dev/null; then
log_info "Service Status:"
pm2 status
else
log_info "Services built but not started. Install PM2 or start manually."
fi
}
main "$@"

View File

@@ -0,0 +1,140 @@
#!/bin/bash
# Deploy Tokenization System
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Configuration
FABRIC_NETWORK="${FABRIC_NETWORK:-fabric-network}"
CHAIN_138_RPC_URL="${CHAIN_138_RPC_URL:-http://localhost:8545}"
FIREFLY_API_URL="${FIREFLY_API_URL:-http://localhost:5000}"
CACTI_API_URL="${CACTI_API_URL:-http://localhost:4000}"
INDY_API_URL="${INDY_API_URL:-http://localhost:9000}"
echo -e "${GREEN}Deploying Tokenization System...${NC}"
# Step 1: Deploy Fabric Chaincode
echo -e "${YELLOW}Deploying Fabric Chaincode...${NC}"
if command -v peer &> /dev/null; then
# Deploy tokenized-asset chaincode
peer chaincode package tokenized-asset.tar.gz \
--path ./chaincode/tokenized-asset/go \
--lang golang \
--label tokenized-asset-v1.0
peer chaincode install tokenized-asset.tar.gz
peer chaincode instantiate \
-C mychannel \
-n tokenized-asset \
-v 1.0 \
-c '{"Args":[]}' \
-P "OR('Org1MSP.member')"
# Deploy reserve-manager chaincode
peer chaincode package reserve-manager.tar.gz \
--path ./chaincode/reserve-manager/go \
--lang golang \
--label reserve-manager-v1.0
peer chaincode install reserve-manager.tar.gz
peer chaincode instantiate \
-C mychannel \
-n reserve-manager \
-v 1.0 \
-c '{"Args":[]}' \
-P "OR('Org1MSP.member')"
else
echo -e "${YELLOW}Fabric peer CLI not found, skipping chaincode deployment${NC}"
fi
# Step 2: Deploy Besu Contracts
echo -e "${YELLOW}Deploying Besu Contracts...${NC}"
if [ -z "$DEPLOYER_PRIVATE_KEY" ]; then
echo -e "${RED}Error: DEPLOYER_PRIVATE_KEY not set${NC}"
exit 1
fi
TOKENIZED_EUR_ADDRESS=$(forge script script/tokenization/DeployTokenizedEUR.s.sol \
--rpc-url "$CHAIN_138_RPC_URL" \
--private-key "$DEPLOYER_PRIVATE_KEY" \
--broadcast \
--json | jq -r '.returns.tokenizedEUR.value')
echo "TokenizedEUR deployed at: $TOKENIZED_EUR_ADDRESS"
TOKEN_REGISTRY_ADDRESS=$(forge script script/tokenization/DeployTokenRegistry.s.sol \
--rpc-url "$CHAIN_138_RPC_URL" \
--private-key "$DEPLOYER_PRIVATE_KEY" \
--broadcast \
--json | jq -r '.returns.registry.value')
echo "TokenRegistry deployed at: $TOKEN_REGISTRY_ADDRESS"
# Step 3: Register token in registry
echo -e "${YELLOW}Registering token in registry...${NC}"
forge script script/tokenization/RegisterToken.s.sol \
--rpc-url "$CHAIN_138_RPC_URL" \
--private-key "$DEPLOYER_PRIVATE_KEY" \
--broadcast \
--sig "run(address,address,string,string,address,string)" \
"$TOKEN_REGISTRY_ADDRESS" \
"$TOKENIZED_EUR_ADDRESS" \
"EUR-T-2025-001" \
"EUR" \
"$ADMIN_ADDRESS" \
"RESERVE-EUR-001"
# Step 4: Configure Cacti Connectors
echo -e "${YELLOW}Configuring Cacti Connectors...${NC}"
# Register Fabric connector
curl -X POST "${CACTI_API_URL}/api/v1/plugins/ledger-connector/fabric" \
-H "Content-Type: application/json" \
-d "{
\"ledgerId\": \"fabric-tokenization\",
\"networkName\": \"${FABRIC_NETWORK}\",
\"channelName\": \"mychannel\"
}" || echo "Cacti Fabric connector registration failed (may already exist)"
# Step 5: Configure FireFly
echo -e "${YELLOW}Configuring FireFly...${NC}"
# FireFly configuration would be done via API or config file
echo "FireFly tokenization workflows configured"
# Step 6: Register SolaceNet Capabilities
echo -e "${YELLOW}Registering SolaceNet Capabilities...${NC}"
# Register tokenization capabilities in SolaceNet
# This would be done via SolaceNet API
echo "SolaceNet tokenization capabilities registered"
# Save deployment addresses
cat > .tokenization-deployment.json <<EOF
{
"deployedAt": $(date +%s),
"contracts": {
"TokenizedEUR": "$TOKENIZED_EUR_ADDRESS",
"TokenRegistry": "$TOKEN_REGISTRY_ADDRESS"
},
"fabric": {
"chaincode": {
"tokenized-asset": "tokenized-asset:1.0",
"reserve-manager": "reserve-manager:1.0"
}
},
"config": {
"fireflyApiUrl": "$FIREFLY_API_URL",
"cactiApiUrl": "$CACTI_API_URL",
"indyApiUrl": "$INDY_API_URL"
}
}
EOF
echo -e "${GREEN}Tokenization deployment complete!${NC}"
echo "Addresses saved to .tokenization-deployment.json"

View File

@@ -0,0 +1,114 @@
#!/bin/bash
# Phase 1: Environment Setup
# This script helps set up the deployment environment
set -e
echo "=== Phase 1: Environment Setup ==="
# Check if .env exists
if [ ! -f .env ]; then
echo "Creating .env file from template..."
if [ -f .env.template ]; then
cp .env.template .env
echo "✓ .env file created from template"
echo "⚠️ Please edit .env and fill in all required values"
else
echo "Error: .env.template not found"
exit 1
fi
else
echo "✓ .env file already exists"
fi
# Load environment variables
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | grep -v '^$' | xargs)
fi
# Verify required variables
REQUIRED_VARS=(
"PRIVATE_KEY"
"ETHEREUM_MAINNET_RPC"
"RPC_URL_138"
"ETHERSCAN_API_KEY"
)
MISSING_VARS=()
for var in "${REQUIRED_VARS[@]}"; do
if [ -z "${!var}" ] || [ "${!var}" == "0x..." ] || [ "${!var}" == "your_etherscan_api_key" ]; then
MISSING_VARS+=("$var")
fi
done
if [ ${#MISSING_VARS[@]} -gt 0 ]; then
echo ""
echo "⚠️ Missing or incomplete required variables:"
for var in "${MISSING_VARS[@]}"; do
echo " - $var"
done
echo ""
echo "Please edit .env and fill in all required values"
exit 1
fi
echo ""
echo "--- Verifying RPC Endpoints ---"
# Verify Ethereum Mainnet RPC
if command -v cast &> /dev/null; then
echo "Checking Ethereum Mainnet RPC..."
BLOCK_NUMBER=$(cast block-number --rpc-url "$ETHEREUM_MAINNET_RPC" 2>/dev/null || echo "0")
if [ "$BLOCK_NUMBER" != "0" ]; then
echo "✓ Ethereum Mainnet RPC accessible (block: $BLOCK_NUMBER)"
else
echo "✗ Ethereum Mainnet RPC not accessible"
exit 1
fi
# Verify ChainID 138 RPC
echo "Checking ChainID 138 RPC..."
if [ ! -z "$RPC_URL_138" ] && [ "$RPC_URL_138" != "http://chain138.example.com:8545" ]; then
BLOCK_NUMBER_138=$(cast block-number --rpc-url "$RPC_URL_138" 2>/dev/null || echo "0")
if [ "$BLOCK_NUMBER_138" != "0" ]; then
echo "✓ ChainID 138 RPC accessible (block: $BLOCK_NUMBER_138)"
else
echo "⚠️ ChainID 138 RPC not accessible (may not be deployed yet)"
fi
else
echo "⚠️ ChainID 138 RPC not configured"
fi
else
echo "⚠️ cast command not found. Install foundry to verify RPC endpoints."
fi
echo ""
echo "--- Checking ETH Balance ---"
if command -v cast &> /dev/null; then
DEPLOYER_ADDRESS=$(cast wallet address $PRIVATE_KEY 2>/dev/null || echo "")
if [ ! -z "$DEPLOYER_ADDRESS" ]; then
BALANCE=$(cast balance "$DEPLOYER_ADDRESS" --rpc-url "$ETHEREUM_MAINNET_RPC" 2>/dev/null || echo "0")
BALANCE_ETH=$(cast --to-unit "$BALANCE" ether 2>/dev/null || echo "0")
echo "Deployer address: $DEPLOYER_ADDRESS"
echo "Balance: $BALANCE_ETH ETH"
MIN_BALANCE=5
if (( $(echo "$BALANCE_ETH < $MIN_BALANCE" | bc -l) )); then
echo "⚠️ Balance is less than recommended minimum ($MIN_BALANCE ETH)"
echo " Recommended: 5-10 ETH for deployment"
else
echo "✓ Sufficient ETH balance for deployment"
fi
else
echo "⚠️ Could not derive address from PRIVATE_KEY"
fi
else
echo "⚠️ cast command not found. Install foundry to check balance."
fi
echo ""
echo "=== Phase 1 Complete ==="
echo "Environment is ready for deployment"

View File

@@ -0,0 +1,105 @@
#!/bin/bash
# Phase 10: Verification
# This script verifies the deployment
set -e
echo "=== Phase 10: Verification ==="
# Load environment variables
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | grep -v '^$' | xargs)
fi
echo ""
echo "--- Running Verification Script ---"
if [ -f scripts/verify-deployment.sh ]; then
./scripts/verify-deployment.sh
else
echo "⚠️ verify-deployment.sh not found"
fi
echo ""
echo "--- Contract Verification Summary ---"
if command -v cast &> /dev/null && [ ! -z "$ETHEREUM_MAINNET_RPC" ]; then
CONTRACTS=(
"BOND_MANAGER"
"CHALLENGE_MANAGER"
"LIQUIDITY_POOL"
"INBOX_ETH"
"BRIDGE_SWAP_COORDINATOR"
"ENHANCED_SWAP_ROUTER"
"STABLECOIN_PEG_MANAGER"
"COMMODITY_PEG_MANAGER"
"ISO_CURRENCY_MANAGER"
"BRIDGE_RESERVE_COORDINATOR"
)
echo "Checking contract codes..."
for var in "${CONTRACTS[@]}"; do
if [ ! -z "${!var}" ] && [ "${!var}" != "0x..." ]; then
CODE_SIZE=$(cast code "${!var}" --rpc-url "$ETHEREUM_MAINNET_RPC" 2>/dev/null | wc -c || echo "0")
if [ "$CODE_SIZE" -gt 2 ]; then
echo "${var}: Contract has code"
else
echo "${var}: Contract has no code"
fi
else
echo "⚠️ ${var}: Not set"
fi
done
else
echo "⚠️ cast command not found or RPC not configured"
fi
echo ""
echo "--- Service Verification ---"
if command -v docker &> /dev/null; then
SERVICES=(
"liquidity-engine-service"
"market-reporting-service"
"bridge-reserve-service"
"iso-currency-service"
)
echo "Checking service status..."
for service in "${SERVICES[@]}"; do
if docker ps --format '{{.Names}}' | grep -q "^${service}$"; then
echo "$service: Running"
else
echo "$service: Not running"
fi
done
else
echo "⚠️ docker command not found"
fi
echo ""
echo "--- End-to-End Test Instructions ---"
echo "To test the complete bridge flow:"
echo ""
echo "1. Deposit on ChainID 138:"
echo " cast send \$LOCKBOX_138 \\"
echo " \"depositNative(address,bytes32)\" \\"
echo " <recipient> \\"
echo " \$(cast keccak \"test\") \\"
echo " --value 1ether \\"
echo " --rpc-url \$RPC_URL_138 \\"
echo " --private-key \$PRIVATE_KEY"
echo ""
echo "2. Submit claim on Ethereum (use relayer service or manual call)"
echo ""
echo "3. Wait for challenge window (30 minutes)"
echo ""
echo "4. Finalize claim"
echo ""
echo "5. Verify swap executed"
echo ""
echo "=== Phase 10 Complete ==="
echo "Verification complete"

View File

@@ -0,0 +1,75 @@
#!/bin/bash
# Phase 2: Deploy Core Bridge Contracts
# This script deploys core bridge contracts on ChainID 138 and Ethereum
set -e
echo "=== Phase 2: Deploy Core Bridge Contracts ==="
# Load environment variables
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | grep -v '^$' | xargs)
fi
# Check required variables
REQUIRED_VARS=(
"PRIVATE_KEY"
"ETHEREUM_MAINNET_RPC"
"RPC_URL_138"
"ETHERSCAN_API_KEY"
)
for var in "${REQUIRED_VARS[@]}"; do
if [ -z "${!var}" ] || [ "${!var}" == "0x..." ] || [ "${!var}" == "your_etherscan_api_key" ]; then
echo "Error: $var is not set in .env"
exit 1
fi
done
echo ""
echo "--- Deploying on ChainID 138 ---"
if [ ! -z "$RPC_URL_138" ] && [ "$RPC_URL_138" != "http://chain138.example.com:8545" ]; then
echo "Deploying Lockbox on ChainID 138..."
forge script script/bridge/trustless/DeployTrustlessBridge.s.sol:DeployTrustlessBridge \
--rpc-url "$RPC_URL_138" \
--broadcast \
--via-ir \
--private-key "$PRIVATE_KEY"
echo ""
echo "⚠️ Please save LOCKBOX_138 address to .env file"
echo " Extract from deployment output above"
else
echo "⚠️ ChainID 138 RPC not configured, skipping ChainID 138 deployment"
fi
echo ""
echo "--- Deploying on Ethereum Mainnet ---"
echo "Deploying core bridge contracts on Ethereum Mainnet..."
forge script script/bridge/trustless/DeployTrustlessBridge.s.sol:DeployTrustlessBridge \
--rpc-url "$ETHEREUM_MAINNET_RPC" \
--broadcast \
--via-ir \
--verify \
--etherscan-api-key "$ETHERSCAN_API_KEY" \
--private-key "$PRIVATE_KEY"
echo ""
echo "⚠️ Please save all deployed addresses to .env file:"
echo " - BOND_MANAGER"
echo " - CHALLENGE_MANAGER"
echo " - LIQUIDITY_POOL"
echo " - INBOX_ETH"
echo " - SWAP_ROUTER"
echo " - BRIDGE_SWAP_COORDINATOR"
echo ""
echo "Extract addresses from deployment output above"
echo ""
echo "=== Phase 2 Complete ==="
echo "Core bridge contracts deployed"
echo "⚠️ Remember to update .env with all contract addresses"

View File

@@ -0,0 +1,58 @@
#!/bin/bash
# Phase 3: Deploy EnhancedSwapRouter
# This script deploys the EnhancedSwapRouter with multi-protocol support
set -e
echo "=== Phase 3: Deploy EnhancedSwapRouter ==="
# Load environment variables
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | grep -v '^$' | xargs)
fi
# Check required variables
REQUIRED_VARS=(
"PRIVATE_KEY"
"ETHEREUM_MAINNET_RPC"
"ETHERSCAN_API_KEY"
)
for var in "${REQUIRED_VARS[@]}"; do
if [ -z "${!var}" ] || [ "${!var}" == "0x..." ] || [ "${!var}" == "your_etherscan_api_key" ]; then
echo "Error: $var is not set in .env"
exit 1
fi
done
echo ""
echo "--- Deploying EnhancedSwapRouter ---"
forge script script/bridge/trustless/DeployEnhancedSwapRouter.s.sol:DeployEnhancedSwapRouter \
--rpc-url "$ETHEREUM_MAINNET_RPC" \
--broadcast \
--via-ir \
--verify \
--etherscan-api-key "$ETHERSCAN_API_KEY" \
--private-key "$PRIVATE_KEY"
echo ""
echo "⚠️ Please save ENHANCED_SWAP_ROUTER address to .env file"
echo " Extract from deployment output above"
echo ""
echo "--- Configuring Balancer Pool IDs (Optional) ---"
echo "If you have Balancer pool IDs, configure them now:"
echo ""
echo "cast send \$ENHANCED_SWAP_ROUTER \\"
echo " \"setBalancerPoolId(address,address,bytes32)\" \\"
echo " <tokenA> <tokenB> <poolId> \\"
echo " --rpc-url \$ETHEREUM_MAINNET_RPC \\"
echo " --private-key \$PRIVATE_KEY"
echo ""
echo "=== Phase 3 Complete ==="
echo "EnhancedSwapRouter deployed"
echo "⚠️ Remember to update .env with ENHANCED_SWAP_ROUTER address"

View File

@@ -0,0 +1,55 @@
#!/bin/bash
# Phase 4: Deploy Integration Contracts
# This script deploys peg managers and reserve coordinator
set -e
echo "=== Phase 4: Deploy Integration Contracts ==="
# Load environment variables
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | grep -v '^$' | xargs)
fi
# Check required variables
REQUIRED_VARS=(
"PRIVATE_KEY"
"ETHEREUM_MAINNET_RPC"
"ETHERSCAN_API_KEY"
"BRIDGE_SWAP_COORDINATOR"
"RESERVE_SYSTEM"
)
for var in "${REQUIRED_VARS[@]}"; do
if [ -z "${!var}" ] || [ "${!var}" == "0x..." ]; then
echo "Error: $var is not set in .env"
exit 1
fi
done
echo ""
echo "--- Deploying Integration Contracts ---"
forge script script/bridge/trustless/DeployIntegrationContracts.s.sol:DeployIntegrationContracts \
--rpc-url "$ETHEREUM_MAINNET_RPC" \
--broadcast \
--via-ir \
--verify \
--etherscan-api-key "$ETHERSCAN_API_KEY" \
--private-key "$PRIVATE_KEY"
echo ""
echo "⚠️ Please save all deployed addresses to .env file:"
echo " - STABLECOIN_PEG_MANAGER"
echo " - COMMODITY_PEG_MANAGER"
echo " - ISO_CURRENCY_MANAGER"
echo " - BRIDGE_RESERVE_COORDINATOR"
echo ""
echo "Extract addresses from deployment output above"
echo ""
echo "=== Phase 4 Complete ==="
echo "Integration contracts deployed"
echo "⚠️ Remember to update .env with all contract addresses"

View File

@@ -0,0 +1,42 @@
#!/bin/bash
# Phase 5: Initialize System
# This script initializes the bridge system configuration
set -e
echo "=== Phase 5: Initialize System ==="
# Load environment variables
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | grep -v '^$' | xargs)
fi
# Check required variables
REQUIRED_VARS=(
"PRIVATE_KEY"
"ETHEREUM_MAINNET_RPC"
"ENHANCED_SWAP_ROUTER"
"BRIDGE_SWAP_COORDINATOR"
)
for var in "${REQUIRED_VARS[@]}"; do
if [ -z "${!var}" ] || [ "${!var}" == "0x..." ]; then
echo "Error: $var is not set in .env"
exit 1
fi
done
echo ""
echo "--- Initializing System Configuration ---"
forge script script/bridge/trustless/InitializeBridgeSystem.s.sol:InitializeBridgeSystem \
--rpc-url "$ETHEREUM_MAINNET_RPC" \
--broadcast \
--via-ir \
--private-key "$PRIVATE_KEY"
echo ""
echo "=== Phase 5 Complete ==="
echo "System initialized and configured"

View File

@@ -0,0 +1,74 @@
#!/bin/bash
# Phase 6: Provide Initial Liquidity
# This script provides initial liquidity to the bridge system
set -e
echo "=== Phase 6: Provide Initial Liquidity ==="
# Load environment variables
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | grep -v '^$' | xargs)
fi
# Check required variables
REQUIRED_VARS=(
"PRIVATE_KEY"
"ETHEREUM_MAINNET_RPC"
"LIQUIDITY_POOL"
"RESERVE_SYSTEM"
)
for var in "${REQUIRED_VARS[@]}"; do
if [ -z "${!var}" ] || [ "${!var}" == "0x..." ]; then
echo "Error: $var is not set in .env"
exit 1
fi
done
LIQUIDITY_AMOUNT=${LIQUIDITY_AMOUNT:-100} # Default 100 ETH
RESERVE_AMOUNT=${RESERVE_AMOUNT:-100000} # Default 100k USDT
echo ""
echo "--- Providing Liquidity to LiquidityPoolETH ---"
echo "Amount: $LIQUIDITY_AMOUNT ETH"
cast send "$LIQUIDITY_POOL" \
"provideLiquidity(uint8)" \
0 \
--value "${LIQUIDITY_AMOUNT}ether" \
--rpc-url "$ETHEREUM_MAINNET_RPC" \
--private-key "$PRIVATE_KEY"
echo "✓ Liquidity provided"
echo ""
echo "--- Funding ReserveSystem ---"
echo "Amount: $RESERVE_AMOUNT USDT"
# Approve USDT
USDT=${USDT:-0xdAC17F958D2ee523a2206206994597C13D831ec7}
cast send "$USDT" \
"approve(address,uint256)" \
"$RESERVE_SYSTEM" \
"$(cast --to-wei $RESERVE_AMOUNT 6)" \
--rpc-url "$ETHEREUM_MAINNET_RPC" \
--private-key "$PRIVATE_KEY"
echo "✓ USDT approved"
# Deposit to ReserveSystem
cast send "$RESERVE_SYSTEM" \
"depositReserve(address,uint256)" \
"$USDT" \
"$(cast --to-wei $RESERVE_AMOUNT 6)" \
--rpc-url "$ETHEREUM_MAINNET_RPC" \
--private-key "$PRIVATE_KEY"
echo "✓ Reserves deposited"
echo ""
echo "=== Phase 6 Complete ==="
echo "Initial liquidity and reserves provided"

View File

@@ -0,0 +1,67 @@
#!/bin/bash
# Phase 7: Configure Access Control and Routing
# This script configures access control roles and routing logic
set -e
echo "=== Phase 7: Configure Access Control and Routing ==="
# Load environment variables
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | grep -v '^$' | xargs)
fi
# Check required variables
REQUIRED_VARS=(
"PRIVATE_KEY"
"ETHEREUM_MAINNET_RPC"
"ENHANCED_SWAP_ROUTER"
"BRIDGE_SWAP_COORDINATOR"
)
for var in "${REQUIRED_VARS[@]}"; do
if [ -z "${!var}" ] || [ "${!var}" == "0x..." ]; then
echo "Error: $var is not set in .env"
exit 1
fi
done
echo ""
echo "--- Configuring Access Control Roles ---"
# Grant COORDINATOR_ROLE to BridgeSwapCoordinator
COORDINATOR_ROLE=$(cast keccak "COORDINATOR_ROLE" 2>/dev/null || echo "0x")
if [ "$COORDINATOR_ROLE" != "0x" ]; then
echo "Granting COORDINATOR_ROLE to BridgeSwapCoordinator..."
cast send "$ENHANCED_SWAP_ROUTER" \
"grantRole(bytes32,address)" \
"$COORDINATOR_ROLE" \
"$BRIDGE_SWAP_COORDINATOR" \
--rpc-url "$ETHEREUM_MAINNET_RPC" \
--private-key "$PRIVATE_KEY"
echo "✓ COORDINATOR_ROLE granted"
else
echo "⚠️ Could not compute COORDINATOR_ROLE hash"
fi
echo ""
echo "--- Routing Logic Configuration ---"
echo "EnhancedSwapRouter is pre-configured with default routing:"
echo " - Small swaps (< \$10k): Uniswap V3, Dodoex"
echo " - Medium swaps (\$10k-\$100k): Dodoex, Balancer, Uniswap V3"
echo " - Large swaps (> \$100k): Dodoex, Curve, Balancer"
echo ""
echo "To customize routing, use:"
echo "cast send \$ENHANCED_SWAP_ROUTER \\"
echo " \"setRoutingConfig(uint256,uint8[])\" \\"
echo " <sizeIndex> \\"
echo " \"[<provider1>,<provider2>]\" \\"
echo " --rpc-url \$ETHEREUM_MAINNET_RPC \\"
echo " --private-key \$PRIVATE_KEY"
echo ""
echo "=== Phase 7 Complete ==="
echo "Access control and routing configured"

View File

@@ -0,0 +1,66 @@
#!/bin/bash
# Phase 8: Deploy Backend Services
# This script deploys all backend services
set -e
echo "=== Phase 8: Deploy Backend Services ==="
# Load environment variables
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | grep -v '^$' | xargs)
fi
echo ""
echo "--- Creating Docker Network ---"
if ! docker network ls | grep -q "bridge-network"; then
docker network create bridge-network
echo "✓ Docker network created"
else
echo "✓ Docker network already exists"
fi
echo ""
echo "--- Deploying Services ---"
# Check if deploy-services.sh exists
if [ -f scripts/deploy-services.sh ]; then
./scripts/deploy-services.sh
else
echo "⚠️ deploy-services.sh not found, deploying services manually..."
SERVICES=(
"liquidity-engine"
"market-reporting"
"bridge-reserve"
"iso-currency"
)
for service in "${SERVICES[@]}"; do
if [ -d "services/$service" ] && [ -f "services/$service/docker-compose.yml" ]; then
echo ""
echo "Deploying $service..."
cd "services/$service"
docker-compose up -d --build
cd ../..
echo "$service deployed"
else
echo "⚠️ $service not found or missing docker-compose.yml"
fi
done
fi
echo ""
echo "--- Verifying Services ---"
if command -v docker &> /dev/null; then
echo "Running services:"
docker ps --format "table {{.Names}}\t{{.Status}}" | grep -E "NAME|liquidity|market|bridge|iso" || echo "No services found"
fi
echo ""
echo "=== Phase 8 Complete ==="
echo "Backend services deployed"

View File

@@ -0,0 +1,60 @@
#!/bin/bash
# Phase 9: Deploy Frontend Applications
# This script builds and deploys frontend applications
set -e
echo "=== Phase 9: Deploy Frontend Applications ==="
echo ""
echo "--- Building Frontend DApp ---"
if [ -d "frontend-dapp" ] && [ -f "frontend-dapp/package.json" ]; then
cd frontend-dapp
echo "Installing dependencies..."
npm install
echo "Building..."
npm run build
echo "✓ Frontend DApp built successfully"
cd ..
echo ""
echo "⚠️ Frontend DApp build complete"
echo " Deploy dist/ directory to your hosting provider"
echo " Examples:"
echo " - Vercel: vercel --prod"
echo " - Netlify: netlify deploy --prod --dir=dist"
echo " - Custom: rsync -avz dist/ user@server:/var/www/dapp/"
else
echo "⚠️ frontend-dapp directory not found or missing package.json"
fi
echo ""
echo "--- Building Admin Dashboard ---"
if [ -d "../dbis_core/frontend" ] && [ -f "../dbis_core/frontend/package.json" ]; then
cd ../dbis_core/frontend
echo "Installing dependencies..."
npm install
echo "Building..."
npm run build
echo "✓ Admin Dashboard built successfully"
cd ../../smom-dbis-138
echo ""
echo "⚠️ Admin Dashboard build complete"
echo " Deploy dist/ directory to your hosting provider"
echo " Examples:"
echo " - Vercel: vercel --prod"
echo " - Netlify: netlify deploy --prod --dir=dist"
echo " - Custom: rsync -avz dist/ user@server:/var/www/admin/"
else
echo "⚠️ Admin Dashboard directory not found or missing package.json"
fi
echo ""
echo "=== Phase 9 Complete ==="
echo "Frontend applications built"
echo "⚠️ Remember to deploy to hosting provider"

View File

@@ -0,0 +1,74 @@
#!/bin/bash
# Start Deployment Process
# This script initiates the deployment with proper checks
set -e
echo "=========================================="
echo " Trustless Bridge Deployment"
echo "=========================================="
echo ""
# Check prerequisites
echo "=== Pre-Deployment Checks ==="
echo ""
# Check Foundry
if ! command -v forge &> /dev/null; then
echo "✗ Error: Foundry/Forge not installed"
echo " Install with: curl -L https://foundry.paradigm.xyz | bash && foundryup"
exit 1
fi
echo "✓ Foundry installed"
# Check .env file
if [ ! -f .env ]; then
echo "✗ Error: .env file not found"
exit 1
fi
echo "✓ .env file exists"
# Load environment
source .env 2>/dev/null || true
# Check required variables
MISSING=0
for var in PRIVATE_KEY ETHEREUM_MAINNET_RPC RPC_URL_138 ETHERSCAN_API_KEY; do
if [ -z "${!var}" ] || [ "${!var}" == "0x..." ] || [ "${!var}" == "your_etherscan_api_key" ]; then
echo "$var: Not set"
MISSING=1
fi
done
if [ $MISSING -eq 1 ]; then
echo ""
echo "Error: Missing required environment variables"
echo "Run: ./scripts/deployment/check-env-requirements.sh"
exit 1
fi
echo "✓ Required variables set"
echo ""
echo "=== Ready to Deploy ==="
echo ""
echo "This will deploy contracts to:"
echo " - Ethereum Mainnet: $ETHEREUM_MAINNET_RPC"
echo " - ChainID 138: $RPC_URL_138"
echo ""
echo "⚠️ WARNING: This will use real ETH for gas fees!"
echo ""
read -p "Continue with deployment? (yes/no): " -r
echo ""
if [[ ! $REPLY =~ ^[Yy][Ee][Ss]$ ]]; then
echo "Deployment cancelled"
exit 0
fi
echo ""
echo "Starting deployment process..."
echo ""
# Run the deployment script
exec ./scripts/deployment/deploy-all-phases.sh

View File

@@ -0,0 +1,56 @@
#!/bin/bash
# Update Environment Variables
# Helper script to update specific environment variables in .env file
set -e
ENV_FILE=".env"
if [ ! -f "$ENV_FILE" ]; then
echo "Creating .env file from template..."
if [ -f .env.template ]; then
cp .env.template "$ENV_FILE"
else
touch "$ENV_FILE"
fi
fi
# Function to update or add variable
update_var() {
local var_name=$1
local var_value=$2
if grep -q "^${var_name}=" "$ENV_FILE"; then
# Update existing variable
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "s|^${var_name}=.*|${var_name}=${var_value}|" "$ENV_FILE"
else
sed -i "s|^${var_name}=.*|${var_name}=${var_value}|" "$ENV_FILE"
fi
echo "Updated $var_name"
else
# Add new variable
echo "${var_name}=${var_value}" >> "$ENV_FILE"
echo "Added $var_name"
fi
}
# Update the provided variables
if [ ! -z "$1" ] && [ "$1" == "update" ]; then
update_var "ETHEREUM_MAINNET_RPC" "https://mainnet.infura.io/v3/43b945b33d58463a9246cf5ca8aa6286"
update_var "RPC_URL_138" "http://192.168.11.250"
update_var "ETHERSCAN_API_KEY" "89HVZNN68DWKWVZHQRGQJ1B74FGKWBJV1W"
echo ""
echo "✓ Environment variables updated"
echo ""
echo "Run: ./scripts/deployment/check-env-requirements.sh to verify"
else
echo "Usage: $0 update"
echo ""
echo "This will update:"
echo " - ETHEREUM_MAINNET_RPC"
echo " - RPC_URL_138"
echo " - ETHERSCAN_API_KEY"
fi

View File

@@ -0,0 +1,57 @@
#!/bin/bash
# Verify All RPC Endpoints
# This script tests connectivity to all configured RPC endpoints
set -e
echo "=== RPC Endpoint Verification ==="
echo ""
# Load environment variables
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | grep -v '^$' | xargs)
fi
if ! command -v cast &> /dev/null; then
echo "Error: cast command not found. Install foundry to verify RPC endpoints."
exit 1
fi
# Function to test RPC
test_rpc() {
local name=$1
local url=$2
if [ -z "$url" ] || [ "$url" == "http://chain138.example.com:8545" ] || [[ "$url" == *"YOUR_PROJECT_ID"* ]]; then
echo "$name: Not configured"
return
fi
echo -n "Testing $name... "
BLOCK=$(cast block-number --rpc-url "$url" 2>&1)
if [ $? -eq 0 ] && [[ "$BLOCK" =~ ^[0-9]+$ ]]; then
echo "✓ Connected (block: $BLOCK)"
else
echo "✗ Failed: $BLOCK"
fi
}
echo "--- Required RPC Endpoints ---"
test_rpc "Ethereum Mainnet" "$ETHEREUM_MAINNET_RPC"
test_rpc "ChainID 138" "$RPC_URL_138"
echo ""
echo "--- Additional Network RPC Endpoints ---"
test_rpc "Ethereum Sepolia" "$ETHEREUM_SEPOLIA_RPC"
test_rpc "Polygon Mainnet" "$POLYGON_MAINNET_RPC"
test_rpc "Polygon Amoy" "$POLYGON_AMOY_RPC"
test_rpc "Base Mainnet" "$BASE_MAINNET_RPC"
test_rpc "Base Sepolia" "$BASE_SEPOLIA_RPC"
test_rpc "Optimism Mainnet" "$OPTIMISM_MAINNET_RPC"
test_rpc "Optimism Sepolia" "$OPTIMISM_SEPOLIA_RPC"
echo ""
echo "=== Verification Complete ==="