2025-12-12 14:57:48 -08:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
pragma solidity ^0.8.20;
|
|
|
|
|
|
|
|
|
|
import "@openzeppelin/contracts/access/AccessControl.sol";
|
|
|
|
|
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
|
|
|
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
|
|
|
|
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
2026-03-02 12:14:09 -08:00
|
|
|
import "../emoney/interfaces/IeMoneyToken.sol";
|
|
|
|
|
import "../emoney/interfaces/ITokenFactory138.sol";
|
2025-12-12 14:57:48 -08:00
|
|
|
import "./IReserveSystem.sol";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @title ReserveTokenIntegration
|
|
|
|
|
* @notice Integrates Reserve System with eMoney Token Factory
|
|
|
|
|
* @dev Enables eMoney tokens to be backed by reserves and converted via the reserve system
|
|
|
|
|
*/
|
|
|
|
|
contract ReserveTokenIntegration is AccessControl, ReentrancyGuard {
|
|
|
|
|
using SafeERC20 for IERC20;
|
|
|
|
|
|
|
|
|
|
bytes32 public constant INTEGRATION_OPERATOR_ROLE = keccak256("INTEGRATION_OPERATOR_ROLE");
|
|
|
|
|
|
|
|
|
|
IReserveSystem public reserveSystem;
|
|
|
|
|
ITokenFactory138 public tokenFactory;
|
|
|
|
|
|
|
|
|
|
// Token to reserve asset mapping
|
|
|
|
|
mapping(address => address) public tokenReserveAsset;
|
|
|
|
|
// Reserve asset to token mapping
|
|
|
|
|
mapping(address => address) public reserveAssetToken;
|
|
|
|
|
|
|
|
|
|
// Reserve backing ratio (basis points: 10000 = 100%)
|
|
|
|
|
mapping(address => uint256) public reserveBackingRatio;
|
|
|
|
|
|
|
|
|
|
event TokenBackedByReserve(
|
|
|
|
|
address indexed token,
|
|
|
|
|
address indexed reserveAsset,
|
|
|
|
|
uint256 backingRatio
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
event ReserveBackingUpdated(
|
|
|
|
|
address indexed token,
|
|
|
|
|
address indexed reserveAsset,
|
|
|
|
|
uint256 newBackingRatio
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
event TokenConvertedViaReserve(
|
|
|
|
|
address indexed sourceToken,
|
|
|
|
|
address indexed targetToken,
|
|
|
|
|
uint256 sourceAmount,
|
|
|
|
|
uint256 targetAmount,
|
|
|
|
|
bytes32 conversionId
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
address admin,
|
|
|
|
|
address reserveSystem_,
|
|
|
|
|
address tokenFactory_
|
|
|
|
|
) {
|
|
|
|
|
_grantRole(DEFAULT_ADMIN_ROLE, admin);
|
|
|
|
|
_grantRole(INTEGRATION_OPERATOR_ROLE, admin);
|
|
|
|
|
|
|
|
|
|
reserveSystem = IReserveSystem(reserveSystem_);
|
|
|
|
|
tokenFactory = ITokenFactory138(tokenFactory_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notice Set reserve asset backing for an eMoney token
|
|
|
|
|
* @param token Address of the eMoney token
|
|
|
|
|
* @param reserveAsset Address of the reserve asset
|
|
|
|
|
* @param backingRatio Backing ratio in basis points (10000 = 100%)
|
|
|
|
|
*/
|
|
|
|
|
function setTokenBacking(
|
|
|
|
|
address token,
|
|
|
|
|
address reserveAsset,
|
|
|
|
|
uint256 backingRatio
|
|
|
|
|
) external onlyRole(INTEGRATION_OPERATOR_ROLE) {
|
|
|
|
|
require(token != address(0), "ReserveTokenIntegration: zero token");
|
|
|
|
|
require(reserveAsset != address(0), "ReserveTokenIntegration: zero reserve asset");
|
|
|
|
|
require(backingRatio <= 10000, "ReserveTokenIntegration: invalid backing ratio");
|
|
|
|
|
|
|
|
|
|
tokenReserveAsset[token] = reserveAsset;
|
|
|
|
|
reserveAssetToken[reserveAsset] = token;
|
|
|
|
|
reserveBackingRatio[token] = backingRatio;
|
|
|
|
|
|
|
|
|
|
emit TokenBackedByReserve(token, reserveAsset, backingRatio);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notice Update reserve backing ratio for a token
|
|
|
|
|
* @param token Address of the eMoney token
|
|
|
|
|
* @param newBackingRatio New backing ratio in basis points
|
|
|
|
|
*/
|
|
|
|
|
function updateBackingRatio(
|
|
|
|
|
address token,
|
|
|
|
|
uint256 newBackingRatio
|
|
|
|
|
) external onlyRole(INTEGRATION_OPERATOR_ROLE) {
|
|
|
|
|
require(token != address(0), "ReserveTokenIntegration: zero token");
|
|
|
|
|
require(newBackingRatio <= 10000, "ReserveTokenIntegration: invalid backing ratio");
|
|
|
|
|
require(tokenReserveAsset[token] != address(0), "ReserveTokenIntegration: token not backed");
|
|
|
|
|
|
|
|
|
|
address reserveAsset = tokenReserveAsset[token];
|
|
|
|
|
reserveBackingRatio[token] = newBackingRatio;
|
|
|
|
|
|
|
|
|
|
emit ReserveBackingUpdated(token, reserveAsset, newBackingRatio);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notice Convert eMoney tokens via reserve system
|
|
|
|
|
* @param sourceToken Address of the source eMoney token
|
|
|
|
|
* @param targetToken Address of the target eMoney token
|
|
|
|
|
* @param amount Amount of source tokens to convert
|
|
|
|
|
* @return targetAmount Amount of target tokens received
|
|
|
|
|
* @return conversionId Conversion ID from reserve system
|
|
|
|
|
*/
|
|
|
|
|
function convertTokensViaReserve(
|
|
|
|
|
address sourceToken,
|
|
|
|
|
address targetToken,
|
|
|
|
|
uint256 amount
|
|
|
|
|
) external nonReentrant returns (uint256 targetAmount, bytes32 conversionId) {
|
|
|
|
|
require(sourceToken != address(0), "ReserveTokenIntegration: zero source token");
|
|
|
|
|
require(targetToken != address(0), "ReserveTokenIntegration: zero target token");
|
|
|
|
|
require(amount > 0, "ReserveTokenIntegration: zero amount");
|
|
|
|
|
|
|
|
|
|
address sourceReserveAsset = tokenReserveAsset[sourceToken];
|
|
|
|
|
address targetReserveAsset = tokenReserveAsset[targetToken];
|
|
|
|
|
|
|
|
|
|
require(sourceReserveAsset != address(0), "ReserveTokenIntegration: source not backed");
|
|
|
|
|
require(targetReserveAsset != address(0), "ReserveTokenIntegration: target not backed");
|
|
|
|
|
|
|
|
|
|
// Burn source tokens
|
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
|
|
|
IeMoneyToken(sourceToken).burn(msg.sender, amount, "0x00");
|
2025-12-12 14:57:48 -08:00
|
|
|
|
|
|
|
|
// Calculate reserve asset amount based on backing ratio
|
|
|
|
|
uint256 sourceReserveAmount = (amount * reserveBackingRatio[sourceToken]) / 10000;
|
|
|
|
|
|
|
|
|
|
// Convert via reserve system
|
|
|
|
|
uint256 targetReserveAmount;
|
|
|
|
|
uint256 fees;
|
|
|
|
|
(conversionId, targetReserveAmount, fees) = reserveSystem.convertAssets(
|
|
|
|
|
sourceReserveAsset,
|
|
|
|
|
targetReserveAsset,
|
|
|
|
|
sourceReserveAmount
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Calculate target token amount based on backing ratio
|
|
|
|
|
targetAmount = (targetReserveAmount * 10000) / reserveBackingRatio[targetToken];
|
|
|
|
|
|
|
|
|
|
// Mint target tokens
|
|
|
|
|
IeMoneyToken(targetToken).mint(msg.sender, targetAmount, bytes32(0));
|
|
|
|
|
|
|
|
|
|
emit TokenConvertedViaReserve(sourceToken, targetToken, amount, targetAmount, conversionId);
|
|
|
|
|
|
|
|
|
|
return (targetAmount, conversionId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notice Get reserve backing information for a token
|
|
|
|
|
* @param token Address of the eMoney token
|
|
|
|
|
* @return reserveAsset Address of the reserve asset
|
|
|
|
|
* @return backingRatio Backing ratio in basis points
|
|
|
|
|
* @return reserveBalance Current reserve balance
|
|
|
|
|
*/
|
|
|
|
|
function getTokenBacking(address token) external view returns (
|
|
|
|
|
address reserveAsset,
|
|
|
|
|
uint256 backingRatio,
|
|
|
|
|
uint256 reserveBalance
|
|
|
|
|
) {
|
|
|
|
|
reserveAsset = tokenReserveAsset[token];
|
|
|
|
|
backingRatio = reserveBackingRatio[token];
|
|
|
|
|
if (reserveAsset != address(0)) {
|
|
|
|
|
reserveBalance = reserveSystem.getReserveBalance(reserveAsset);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notice Check if token has adequate reserve backing
|
|
|
|
|
* @param token Address of the eMoney token
|
|
|
|
|
* @return isAdequate True if reserves are adequate
|
|
|
|
|
* @return requiredReserve Required reserve amount
|
|
|
|
|
* @return currentReserve Current reserve amount
|
|
|
|
|
*/
|
|
|
|
|
function checkReserveAdequacy(address token) external view returns (
|
|
|
|
|
bool isAdequate,
|
|
|
|
|
uint256 requiredReserve,
|
|
|
|
|
uint256 currentReserve
|
|
|
|
|
) {
|
|
|
|
|
address reserveAsset = tokenReserveAsset[token];
|
|
|
|
|
require(reserveAsset != address(0), "ReserveTokenIntegration: token not backed");
|
|
|
|
|
|
|
|
|
|
uint256 totalSupply = IERC20(token).totalSupply();
|
|
|
|
|
uint256 backingRatio = reserveBackingRatio[token];
|
|
|
|
|
|
|
|
|
|
requiredReserve = (totalSupply * backingRatio) / 10000;
|
|
|
|
|
currentReserve = reserveSystem.getReserveBalance(reserveAsset);
|
|
|
|
|
|
|
|
|
|
isAdequate = currentReserve >= requiredReserve;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|