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 {Test} from "forge-std/Test.sol";
|
|
|
|
|
import {ReserveSystem} from "../../contracts/reserve/ReserveSystem.sol";
|
|
|
|
|
import {IReserveSystem} from "../../contracts/reserve/IReserveSystem.sol";
|
|
|
|
|
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
2025-12-12 14:57:48 -08:00
|
|
|
|
|
|
|
|
contract MockERC20 is ERC20 {
|
|
|
|
|
constructor(string memory name, string memory symbol) ERC20(name, symbol) {}
|
|
|
|
|
|
|
|
|
|
function mint(address to, uint256 amount) external {
|
|
|
|
|
_mint(to, amount);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contract ReserveSystemTest is Test {
|
|
|
|
|
ReserveSystem public reserveSystem;
|
|
|
|
|
MockERC20 public asset1;
|
|
|
|
|
MockERC20 public asset2;
|
|
|
|
|
|
|
|
|
|
address public admin;
|
|
|
|
|
address public reserveManager;
|
|
|
|
|
address public priceFeedOperator;
|
|
|
|
|
address public conversionOperator;
|
|
|
|
|
|
|
|
|
|
function setUp() public {
|
|
|
|
|
admin = address(0x1);
|
|
|
|
|
reserveManager = address(0x2);
|
|
|
|
|
priceFeedOperator = address(0x3);
|
|
|
|
|
conversionOperator = address(0x4);
|
|
|
|
|
|
|
|
|
|
reserveSystem = new ReserveSystem(admin);
|
|
|
|
|
|
|
|
|
|
asset1 = new MockERC20("Asset1", "A1");
|
|
|
|
|
asset2 = new MockERC20("Asset2", "A2");
|
|
|
|
|
|
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
|
|
|
// Grant roles and add assets (admin has all roles from constructor)
|
|
|
|
|
vm.startPrank(admin);
|
2025-12-12 14:57:48 -08:00
|
|
|
reserveSystem.grantRole(reserveSystem.RESERVE_MANAGER_ROLE(), reserveManager);
|
|
|
|
|
reserveSystem.grantRole(reserveSystem.PRICE_FEED_ROLE(), priceFeedOperator);
|
|
|
|
|
reserveSystem.grantRole(reserveSystem.CONVERSION_OPERATOR_ROLE(), conversionOperator);
|
|
|
|
|
reserveSystem.addSupportedAsset(address(asset1), true);
|
|
|
|
|
reserveSystem.addSupportedAsset(address(asset2), true);
|
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
|
|
|
vm.stopPrank();
|
2025-12-12 14:57:48 -08:00
|
|
|
|
|
|
|
|
// Set up price feeds
|
|
|
|
|
vm.prank(priceFeedOperator);
|
|
|
|
|
reserveSystem.updatePriceFeed(address(asset1), 1000 * 1e18, block.timestamp);
|
|
|
|
|
|
|
|
|
|
vm.prank(priceFeedOperator);
|
|
|
|
|
reserveSystem.updatePriceFeed(address(asset2), 2000 * 1e18, block.timestamp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_depositReserve() public {
|
|
|
|
|
asset1.mint(reserveManager, 1000 * 1e18);
|
|
|
|
|
|
|
|
|
|
vm.prank(reserveManager);
|
|
|
|
|
asset1.approve(address(reserveSystem), 1000 * 1e18);
|
|
|
|
|
|
|
|
|
|
vm.prank(reserveManager);
|
|
|
|
|
bytes32 reserveId = reserveSystem.depositReserve(address(asset1), 1000 * 1e18);
|
|
|
|
|
|
|
|
|
|
assertEq(reserveSystem.getReserveBalance(address(asset1)), 1000 * 1e18);
|
|
|
|
|
assertTrue(reserveId != bytes32(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_withdrawReserve() public {
|
|
|
|
|
// First deposit
|
|
|
|
|
asset1.mint(reserveManager, 1000 * 1e18);
|
|
|
|
|
vm.prank(reserveManager);
|
|
|
|
|
asset1.approve(address(reserveSystem), 1000 * 1e18);
|
|
|
|
|
vm.prank(reserveManager);
|
|
|
|
|
reserveSystem.depositReserve(address(asset1), 1000 * 1e18);
|
|
|
|
|
|
|
|
|
|
// Then withdraw
|
|
|
|
|
vm.prank(reserveManager);
|
|
|
|
|
bytes32 withdrawalId = reserveSystem.withdrawReserve(address(asset1), 500 * 1e18, reserveManager);
|
|
|
|
|
|
|
|
|
|
assertEq(reserveSystem.getReserveBalance(address(asset1)), 500 * 1e18);
|
|
|
|
|
assertEq(asset1.balanceOf(reserveManager), 500 * 1e18);
|
|
|
|
|
assertTrue(withdrawalId != bytes32(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_convertAssets() public {
|
|
|
|
|
// Set up reserves
|
|
|
|
|
asset1.mint(reserveManager, 1000 * 1e18);
|
|
|
|
|
asset2.mint(reserveManager, 1000 * 1e18);
|
|
|
|
|
|
|
|
|
|
vm.startPrank(reserveManager);
|
|
|
|
|
asset1.approve(address(reserveSystem), 1000 * 1e18);
|
|
|
|
|
asset2.approve(address(reserveSystem), 1000 * 1e18);
|
|
|
|
|
reserveSystem.depositReserve(address(asset1), 1000 * 1e18);
|
|
|
|
|
reserveSystem.depositReserve(address(asset2), 1000 * 1e18);
|
|
|
|
|
vm.stopPrank();
|
|
|
|
|
|
|
|
|
|
// User has asset1 and wants to convert to asset2
|
|
|
|
|
asset1.mint(conversionOperator, 100 * 1e18);
|
|
|
|
|
vm.prank(conversionOperator);
|
|
|
|
|
asset1.approve(address(reserveSystem), 100 * 1e18);
|
|
|
|
|
|
|
|
|
|
uint256 asset2BalanceBefore = asset2.balanceOf(conversionOperator);
|
|
|
|
|
|
|
|
|
|
vm.prank(conversionOperator);
|
|
|
|
|
(bytes32 conversionId, uint256 targetAmount, uint256 fees) = reserveSystem.convertAssets(
|
|
|
|
|
address(asset1),
|
|
|
|
|
address(asset2),
|
|
|
|
|
100 * 1e18
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assertTrue(conversionId != bytes32(0));
|
|
|
|
|
assertGt(targetAmount, 0);
|
|
|
|
|
assertGt(fees, 0);
|
|
|
|
|
assertEq(asset2.balanceOf(conversionOperator), asset2BalanceBefore + targetAmount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_calculateConversion() public {
|
|
|
|
|
(uint256 targetAmount, uint256 fees, address[] memory path) = reserveSystem.calculateConversion(
|
|
|
|
|
address(asset1),
|
|
|
|
|
address(asset2),
|
|
|
|
|
100 * 1e18
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// asset1 price: 1000, asset2 price: 2000
|
2026-06-18 00:11:33 -07:00
|
|
|
// 100 * 1000 / 2000 = 50 asset2 (equal USD value)
|
|
|
|
|
assertEq(targetAmount, 50 * 1e18);
|
2025-12-12 14:57:48 -08:00
|
|
|
assertGt(fees, 0);
|
|
|
|
|
assertEq(path.length, 2);
|
|
|
|
|
assertEq(path[0], address(asset1));
|
|
|
|
|
assertEq(path[1], address(asset2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test_updatePriceFeed() public {
|
|
|
|
|
vm.prank(priceFeedOperator);
|
|
|
|
|
reserveSystem.updatePriceFeed(address(asset1), 1500 * 1e18, block.timestamp);
|
|
|
|
|
|
|
|
|
|
(uint256 price, uint256 timestamp) = reserveSystem.getPrice(address(asset1));
|
|
|
|
|
assertEq(price, 1500 * 1e18);
|
|
|
|
|
assertEq(timestamp, block.timestamp);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-18 00:11:33 -07:00
|
|
|
function test_getConversionPrice_targetPerSource() public {
|
|
|
|
|
// asset1 $1000, asset2 $2000 -> 0.5 asset2 per 1 asset1
|
|
|
|
|
uint256 conv = reserveSystem.getConversionPrice(address(asset1), address(asset2));
|
|
|
|
|
assertEq(conv, 0.5e18);
|
|
|
|
|
|
|
|
|
|
vm.prank(priceFeedOperator);
|
|
|
|
|
reserveSystem.updatePriceFeed(address(asset1), 1732e18, block.timestamp);
|
|
|
|
|
vm.prank(priceFeedOperator);
|
|
|
|
|
reserveSystem.updatePriceFeed(address(asset2), 1e18, block.timestamp);
|
|
|
|
|
conv = reserveSystem.getConversionPrice(address(asset1), address(asset2));
|
|
|
|
|
assertEq(conv, 1732e18);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-12 14:57:48 -08:00
|
|
|
function test_redeem() public {
|
|
|
|
|
// Set up reserves
|
|
|
|
|
asset1.mint(reserveManager, 1000 * 1e18);
|
|
|
|
|
vm.prank(reserveManager);
|
|
|
|
|
asset1.approve(address(reserveSystem), 1000 * 1e18);
|
|
|
|
|
vm.prank(reserveManager);
|
|
|
|
|
reserveSystem.depositReserve(address(asset1), 1000 * 1e18);
|
|
|
|
|
|
|
|
|
|
address recipient = address(0x5);
|
|
|
|
|
uint256 balanceBefore = asset1.balanceOf(recipient);
|
|
|
|
|
|
|
|
|
|
vm.prank(reserveManager);
|
|
|
|
|
bytes32 redemptionId = reserveSystem.redeem(address(asset1), 300 * 1e18, recipient);
|
|
|
|
|
|
|
|
|
|
assertEq(reserveSystem.getReserveBalance(address(asset1)), 700 * 1e18);
|
|
|
|
|
assertEq(asset1.balanceOf(recipient), balanceBefore + 300 * 1e18);
|
|
|
|
|
assertTrue(redemptionId != bytes32(0));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|