This guide explains how to deploy the complete USX system to different Scroll environments using the hybrid approach that combines OpenZeppelin's security features with our custom diamond deployment logic.
Note: The deployment script was recently renamed from
DeployScrollFork.s.soltoDeployScroll.s.solto better reflect its capability to deploy to local forks, testnets, and mainnet, not just forks.
The deployment system consists of three main components:
- DeployScroll.s.sol - Main deployment script with hybrid approach
- DeployHelper.s.sol - Verification and testing helper
- RunDeployment.s.sol - Orchestrator that runs the complete deployment
- Foundry (latest version)
- OpenZeppelin Foundry Upgrades plugin
- Access to Scroll RPC endpoints
- Install Foundry:
curl -L https://foundry.paradigm.xyz | bash - Install OpenZeppelin Foundry Upgrades:
forge install OpenZeppelin/openzeppelin-foundry-upgrades - Set up your environment variables
# Create .env file
cp .env.example .env
# Fill in your values
PRIVATE_KEY=your_private_key_here
DEPLOYMENT_TARGET=local # Options: local, sepolia, mainnet# Deploy to local fork (development)
export DEPLOYMENT_TARGET=local
forge script script/RunDeployment.s.sol:RunDeployment \
--broadcast \
--verify \
-vvvv
# Deploy to testnet
export DEPLOYMENT_TARGET=sepolia
forge script script/RunDeployment.s.sol:RunDeployment \
--broadcast \
--verify \
-vvvv
# Deploy to mainnet
export DEPLOYMENT_TARGET=mainnet
forge script script/RunDeployment.s.sol:RunDeployment \
--broadcast \
--verify \
-vvvv- DEPLOYMENT_TARGET:
local - Purpose: Development and testing
- Network: Scroll mainnet fork
- RPC:
https://rpc.scroll.io - Chain ID: 31337 (local fork)
- Gas: No real costs
- DEPLOYMENT_TARGET:
sepolia - Purpose: Staging and community testing
- Network: Scroll Sepolia testnet
- RPC:
https://sepolia-rpc.scroll.io - Chain ID: 534351
- Gas: Testnet ETH required
- DEPLOYMENT_TARGET:
mainnet - Purpose: Production deployment
- Network: Scroll mainnet
- RPC:
https://rpc.scroll.io - Chain ID: 534352
- Gas: Real ETH required
β οΈ Warning: Permanent deployment
The deployment follows this sequence:
- Deploy USX Token with UUPS proxy
- Deploy sUSX Vault with UUPS proxy
- Use OpenZeppelin's security features and validation
- Deploy Treasury Diamond implementation
- Deploy Treasury proxy with real contract addresses
- Deploy all facets (AssetManager, InsuranceBuffer, ProfitAndLoss)
- Link USX to Treasury using
setInitialTreasury - Link sUSX to Treasury using
setInitialTreasury - Add facets to diamond with proper selectors
- Verify all contract addresses and configurations
- Test facet functionality through diamond
- Validate contract linking
- Test basic operations on all contracts
- Verify default values and configurations
- Test diamond pattern functionality
- Contract address validation
- Configuration parameter verification
- Facet accessibility testing
- Contract linking validation
# Check deployed addresses
forge script script/RunDeployment.s.sol:RunDeployment \
--sig "getDeployedAddresses()"
# Run post-deployment tests
forge script script/RunDeployment.s.sol:RunDeployment \
--sig "runPostDeploymentTests()"
# Check contract state
forge script script/RunDeployment.s.sol:RunDeployment \
--sig "checkContractState()"- Automated security checks during deployment
- Proxy validation and upgrade safety
- Storage layout verification
- Access control validation
- Diamond pattern validation
- Facet selector verification
- Contract linking verification
- Comprehensive testing
Note: RPC URLs are automatically determined based on your
DEPLOYMENT_TARGETsetting. You don't need to specify them in the command line anymore.
# Required: Your private key
PRIVATE_KEY=your_private_key_here
# Required: Contract addresses
USDC_ADDRESS=0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4
# Required: Governance addresses
GOVERNANCE_ADDRESS=0x1000000000000000000000000000000000000001
GOVERNANCE_WARCHEST_ADDRESS=0x2000000000000000000000000000000000000002
ASSET_MANAGER_ADDRESS=0x3000000000000000000000000000000000000003
ADMIN_ADDRESS=0x4000000000000000000000000000000000000004
# Required: Deployment target
DEPLOYMENT_TARGET=local # Options: local, sepolia, mainnet
# Required: RPC URLs
SCROLL_MAINNET_RPC=https://rpc.scroll.io
SCROLL_SEPOLIA_RPC=https://sepolia-rpc.scroll.io# deploy.config.toml
[network]
fork_url = "https://rpc.scroll.io"
chain_id = 534352
name = "Scroll Mainnet Fork"[contracts]
usdc_address = "0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4"[addresses]
governance = "0x1000000000000000000000000000000000000001"
governance_warchest = "0x2000000000000000000000000000000000000002"
asset_manager = "0x3000000000000000000000000000000000000003"
admin = "0x4000000000000000000000000000000000000004"The deployment includes comprehensive testing:
- Contract initialization verification
- Facet functionality testing
- Diamond pattern validation
- Contract linking verification
# Test specific functionality
forge script script/DeployHelper.s.sol:DeployHelper \
--sig "testBasicOperations()" \
--rpc-url <your-rpc-url># Ensure OpenZeppelin Foundry Upgrades is installed
forge install OpenZeppelin/openzeppelin-foundry-upgrades# Check RPC endpoint
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' \
https://rpc.scroll.io# Increase gas limit
forge script script/RunDeployment.s.sol:RunDeployment \
--gas-limit 30000000 \
--rpc-url <your-rpc-url># Run with maximum verbosity
forge script script/RunDeployment.s.sol:RunDeployment \
--rpc-url <your-rpc-url> \
-vvvvvπ STARTING FULL SYSTEM DEPLOYMENT
=====================================
Deployment Target: local
RPC URL: https://rpc.scroll.io
=====================================
π STEP 1: Running Main Deployment
-------------------------------------
=== DEPLOYING TO local ===
Deployer: 0x...
Governance: 0x1000000000000000000000000000000000000001
Asset Manager: 0x3000000000000000000000000000000000000003
Chain ID: 534352
=========================================
=== STEP 1: Deploying Core Contracts with OpenZeppelin ===
1.1. Deploying USX Token...
β USX Token deployed at: 0x...
1.2. Deploying sUSX Vault...
β sUSX Vault deployed at: 0x...
=== STEP 2: Deploying Diamond with Custom Logic ===
2.1. Deploying Treasury Diamond...
2.2. Deploying Treasury Proxy...
β Treasury Diamond deployed at: 0x...
2.3. Deploying Facets...
β Profit/Loss Facet: 0x...
β Insurance Buffer Facet: 0x...
β Asset Manager Facet: 0x...
=== STEP 3: Linking Contracts with OpenZeppelin Security ===
3.1. Linking USX to Treasury...
β USX linked to Treasury
3.2. Linking sUSX to Treasury...
β sUSX linked to Treasury
3.3. Adding Facets to Diamond...
3.3.1. Adding Profit/Loss Facet...
β Profit/Loss Facet added
3.3.2. Adding Insurance Buffer Facet...
β Insurance Buffer Facet added
3.3.3. Adding Asset Manager Facet...
β Asset Manager Facet added
=== STEP 4: Comprehensive Verification ===
β USX verification passed
β sUSX verification passed
β Treasury verification passed
β Facet accessibility verification passed
=== STEP 5: Testing Basic Functionality ===
5.1. Testing USX basic functionality...
β USX basic functionality verified
5.2. Testing sUSX basic functionality...
β sUSX basic functionality verified
5.3. Testing Treasury basic functionality...
β Treasury basic functionality verified
5.4. Testing facet functionality through diamond...
β Facet functionality verified
β
Main deployment completed successfully
USX Proxy: 0x...
sUSX Proxy: 0x...
Treasury Proxy: 0x...
π STEP 2: Verifying Deployment
--------------------------------
=== DEPLOYMENT HELPER SETUP ===
USX: 0x...
sUSX: 0x...
Treasury: 0x...
=================================
=== COMPLETE SYSTEM VERIFICATION ===
--- USX Configuration Verification ---
Name: USX Token
Symbol: USX
Decimals: 18
USDC Address: 0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4
Treasury Address: 0x...
Governance Warchest: 0x2000000000000000000000000000000000000002
Admin: 0x4000000000000000000000000000000000000004
β USX USDC address verified
β USX treasury linking verified
--- sUSX Configuration Verification ---
Name: sUSX Token
Symbol: sUSX
Decimals: 18
USX Address: 0x...
Treasury Address: 0x...
Governance: 0x1000000000000000000000000000000000000001
β sUSX USX linking verified
β sUSX treasury linking verified
--- Treasury Configuration Verification ---
USDC Address: 0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4
USX Address: 0x...
sUSX Address: 0x...
Governance: 0x1000000000000000000000000000000000000001
Asset Manager: 0x3000000000000000000000000000000000000003
β Treasury address linking verified
--- Facet Functionality Verification ---
Testing AssetManagerAllocatorFacet...
maxLeverage: 0
netDeposits: 0
Testing InsuranceBufferFacet...
bufferTarget: 0
bufferRenewalRate: 100000
Testing ProfitAndLossReporterFacet...
successFee: 50000
profitLatestEpoch: 0
β All facet functionality verified
--- Contract Linking Verification ---
β USX -> Treasury link verified
β sUSX -> Treasury link verified
β Treasury -> USX link verified
β Treasury -> sUSX link verified
β Treasury -> USDC link verified
β
ALL VERIFICATIONS PASSED!
System is fully deployed and functional!
β
Deployment verification completed successfully
π§ͺ STEP 3: Testing Basic Functionality
---------------------------------------
=== TESTING BASIC OPERATIONS ===
Testing USX minting...
β οΈ USX minting failed (expected if not admin)
Testing sUSX operations...
sharePrice: 1000000000000000000
lastEpochBlock: 1000000
epochDuration: 216000
Testing Treasury operations...
maxLeverageFraction: 100000
successFeeFraction: 50000
bufferTargetFraction: 50000
β All basic operations tested successfully
β
Basic functionality testing completed successfully
π DEPLOYMENT SUMMARY
=====================
Network: local
RPC URL: https://rpc.scroll.io
Deployed Contracts:
β’ USX Token: 0x...
β’ sUSX Vault: 0x...
β’ Treasury Diamond: 0x...
Facets Added:
β’ AssetManagerAllocatorFacet
β’ InsuranceBufferFacet
β’ ProfitAndLossReporterFacet
Configuration:
β’ USDC Address: 0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4
β’ Governance: 0x1000000000000000000000000000000000000001
β’ Asset Manager: 0x3000000000000000000000000000000000000003
Default Values:
β’ Max Leverage Fraction: 10% (100000)
β’ Success Fee Fraction: 5% (50000)
β’ Buffer Target Fraction: 5% (50000)
β’ Buffer Renewal Fraction: 10% (100000)
π DEPLOYMENT COMPLETE AND VERIFIED!
=====================================
- Deploy new implementation contracts
- Upgrade proxies using OpenZeppelin tools
- Verify new functionality
- Test all facets through diamond
# Upgrade specific contracts
forge script script/UpgradeContracts.s.sol:UpgradeContracts \
--rpc-url <your-rpc-url> \
--broadcast- GitHub Issues: USX Repository
- Documentation: USX Docs
After successful deployment:
- Test all functionality thoroughly
- Verify security with external auditors
- Deploy to testnet for community testing
- Prepare for mainnet deployment
Note: This deployment system combines the best of both worlds - OpenZeppelin's proven security tools with our custom diamond pattern expertise. Always test thoroughly before deploying to production networks.