2025-12-12 14:57:48 -08:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
pragma solidity ^0.8.20;
|
|
|
|
|
|
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
2026-01-24 07:01:37 -08:00
|
|
|
import {Script, console} from "forge-std/Script.sol";
|
|
|
|
|
import {OraclePriceFeed} from "../../contracts/reserve/OraclePriceFeed.sol";
|
|
|
|
|
import {MockPriceFeed} from "../../contracts/reserve/MockPriceFeed.sol";
|
2025-12-12 14:57:48 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @title SetupPriceFeeds
|
|
|
|
|
* @notice Script to set up price feeds for Reserve System
|
|
|
|
|
* @dev Configures aggregators and initial prices for supported assets
|
|
|
|
|
*/
|
|
|
|
|
contract SetupPriceFeeds is Script {
|
|
|
|
|
function run() external {
|
|
|
|
|
uint256 chainId = block.chainid;
|
|
|
|
|
require(chainId == 138, "This script is for ChainID 138 only");
|
|
|
|
|
|
|
|
|
|
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
|
|
|
|
|
vm.startBroadcast(deployerPrivateKey);
|
|
|
|
|
|
|
|
|
|
address deployer = vm.addr(deployerPrivateKey);
|
|
|
|
|
console.log("=== Setup Price Feeds (ChainID 138) ===");
|
|
|
|
|
console.log("Deployer:", deployer);
|
|
|
|
|
console.log("");
|
|
|
|
|
|
|
|
|
|
// Load addresses from environment
|
|
|
|
|
address reserveSystem = vm.envAddress("RESERVE_SYSTEM");
|
|
|
|
|
address oraclePriceFeed = vm.envOr("ORACLE_PRICE_FEED", address(0));
|
|
|
|
|
address admin = vm.envOr("RESERVE_ADMIN", deployer);
|
|
|
|
|
|
|
|
|
|
// Deploy OraclePriceFeed if not provided
|
|
|
|
|
if (oraclePriceFeed == address(0)) {
|
|
|
|
|
console.log("Deploying OraclePriceFeed...");
|
|
|
|
|
OraclePriceFeed priceFeed = new OraclePriceFeed(admin, reserveSystem);
|
|
|
|
|
oraclePriceFeed = address(priceFeed);
|
|
|
|
|
console.log("OraclePriceFeed deployed at:", oraclePriceFeed);
|
|
|
|
|
} else {
|
|
|
|
|
console.log("Using existing OraclePriceFeed:", oraclePriceFeed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OraclePriceFeed priceFeedContract = OraclePriceFeed(oraclePriceFeed);
|
|
|
|
|
|
|
|
|
|
// Configuration: Asset addresses and initial prices
|
|
|
|
|
// For production, use real Chainlink aggregators
|
|
|
|
|
// For testing, deploy MockPriceFeed contracts
|
|
|
|
|
|
|
|
|
|
bool useMockFeeds = vm.envOr("USE_MOCK_FEEDS", true);
|
|
|
|
|
|
|
|
|
|
if (useMockFeeds) {
|
|
|
|
|
console.log("");
|
|
|
|
|
console.log("=== Deploying Mock Price Feeds ===");
|
|
|
|
|
|
|
|
|
|
// Example assets with mock prices (in 8 decimals for Chainlink compatibility)
|
|
|
|
|
// Gold (XAU) - $2000 per ounce
|
|
|
|
|
address xauAsset = vm.envOr("XAU_ASSET", address(0x1111111111111111111111111111111111111111));
|
|
|
|
|
if (xauAsset != address(0)) {
|
|
|
|
|
console.log("Setting up XAU price feed...");
|
|
|
|
|
MockPriceFeed xauFeed = new MockPriceFeed(2000 * 1e8, 8);
|
|
|
|
|
// Multiplier: 1e10 to convert 8 decimals to 18 decimals
|
|
|
|
|
vm.prank(admin);
|
|
|
|
|
priceFeedContract.setAggregator(xauAsset, address(xauFeed), 1e10);
|
|
|
|
|
console.log("XAU MockPriceFeed:", address(xauFeed));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example: USDC - $1 per token
|
|
|
|
|
address usdcAsset = vm.envOr("USDC_ASSET", address(0x2222222222222222222222222222222222222222));
|
|
|
|
|
if (usdcAsset != address(0)) {
|
|
|
|
|
console.log("Setting up USDC price feed...");
|
|
|
|
|
MockPriceFeed usdcFeed = new MockPriceFeed(1 * 1e8, 8);
|
|
|
|
|
vm.prank(admin);
|
|
|
|
|
priceFeedContract.setAggregator(usdcAsset, address(usdcFeed), 1e10);
|
|
|
|
|
console.log("USDC MockPriceFeed:", address(usdcFeed));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example: ETH - $3000 per token
|
|
|
|
|
address ethAsset = vm.envOr("ETH_ASSET", address(0x3333333333333333333333333333333333333333));
|
|
|
|
|
if (ethAsset != address(0)) {
|
|
|
|
|
console.log("Setting up ETH price feed...");
|
|
|
|
|
MockPriceFeed ethFeed = new MockPriceFeed(3000 * 1e8, 8);
|
|
|
|
|
vm.prank(admin);
|
|
|
|
|
priceFeedContract.setAggregator(ethAsset, address(ethFeed), 1e10);
|
|
|
|
|
console.log("ETH MockPriceFeed:", address(ethFeed));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log("");
|
|
|
|
|
console.log("=== Updating Price Feeds ===");
|
|
|
|
|
|
|
|
|
|
// Update all price feeds
|
|
|
|
|
address[] memory assets = new address[](3);
|
|
|
|
|
if (xauAsset != address(0)) assets[0] = xauAsset;
|
|
|
|
|
if (usdcAsset != address(0)) assets[1] = usdcAsset;
|
|
|
|
|
if (ethAsset != address(0)) assets[2] = ethAsset;
|
|
|
|
|
|
|
|
|
|
vm.prank(admin);
|
|
|
|
|
priceFeedContract.updateMultiplePriceFeeds(assets);
|
|
|
|
|
|
|
|
|
|
console.log("Price feeds updated successfully");
|
|
|
|
|
} else {
|
|
|
|
|
console.log("");
|
|
|
|
|
console.log("=== Configuring Real Chainlink Aggregators ===");
|
|
|
|
|
console.log("Set USE_MOCK_FEEDS=false and provide aggregator addresses");
|
|
|
|
|
console.log("Example environment variables:");
|
|
|
|
|
console.log(" XAU_AGGREGATOR=<chainlink_xau_usd_aggregator>");
|
|
|
|
|
console.log(" USDC_AGGREGATOR=<chainlink_usdc_usd_aggregator>");
|
|
|
|
|
console.log(" ETH_AGGREGATOR=<chainlink_eth_usd_aggregator>");
|
|
|
|
|
|
|
|
|
|
// Configure real aggregators if provided
|
|
|
|
|
address xauAggregator = vm.envOr("XAU_AGGREGATOR", address(0));
|
|
|
|
|
address xauAsset = vm.envOr("XAU_ASSET", address(0));
|
|
|
|
|
if (xauAggregator != address(0) && xauAsset != address(0)) {
|
|
|
|
|
vm.prank(admin);
|
|
|
|
|
priceFeedContract.setAggregator(xauAsset, xauAggregator, 1e10);
|
|
|
|
|
console.log("XAU aggregator configured:", xauAggregator);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
address usdcAggregator = vm.envOr("USDC_AGGREGATOR", address(0));
|
|
|
|
|
address usdcAsset = vm.envOr("USDC_ASSET", address(0));
|
|
|
|
|
if (usdcAggregator != address(0) && usdcAsset != address(0)) {
|
|
|
|
|
vm.prank(admin);
|
|
|
|
|
priceFeedContract.setAggregator(usdcAsset, usdcAggregator, 1e10);
|
|
|
|
|
console.log("USDC aggregator configured:", usdcAggregator);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
address ethAggregator = vm.envOr("ETH_AGGREGATOR", address(0));
|
|
|
|
|
address ethAsset = vm.envOr("ETH_ASSET", address(0));
|
|
|
|
|
if (ethAggregator != address(0) && ethAsset != address(0)) {
|
|
|
|
|
vm.prank(admin);
|
|
|
|
|
priceFeedContract.setAggregator(ethAsset, ethAggregator, 1e10);
|
|
|
|
|
console.log("ETH aggregator configured:", ethAggregator);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log("");
|
|
|
|
|
console.log("=== Setup Complete ===");
|
|
|
|
|
console.log("OraclePriceFeed:", oraclePriceFeed);
|
|
|
|
|
console.log("");
|
|
|
|
|
console.log("=== Export to .env ===");
|
|
|
|
|
console.log("export ORACLE_PRICE_FEED=", vm.toString(oraclePriceFeed));
|
|
|
|
|
|
|
|
|
|
vm.stopBroadcast();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|