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,38 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @title ICollateralAdapter
* @notice Interface for Collateral Adapter
* @dev Handles M0 collateral deposits and withdrawals
*/
interface ICollateralAdapter {
/**
* @notice Deposit M0 collateral
* @param vault Vault address
* @param asset Collateral asset address
* @param amount Amount to deposit
*/
function deposit(address vault, address asset, uint256 amount) external payable;
/**
* @notice Withdraw M0 collateral
* @param vault Vault address
* @param asset Collateral asset address
* @param amount Amount to withdraw
*/
function withdraw(address vault, address asset, uint256 amount) external;
/**
* @notice Seize collateral during liquidation
* @param vault Vault address
* @param asset Collateral asset address
* @param amount Amount to seize
* @param liquidator Liquidator address
*/
function seize(address vault, address asset, uint256 amount, address liquidator) external;
event CollateralDeposited(address indexed vault, address indexed asset, uint256 amount);
event CollateralWithdrawn(address indexed vault, address indexed asset, uint256 amount);
event CollateralSeized(address indexed vault, address indexed asset, uint256 amount, address indexed liquidator);
}

View File

@@ -0,0 +1,119 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @title ILedger
* @notice Interface for the Core Ledger contract
* @dev Single source of truth for collateral and debt balances
*/
interface ILedger {
/**
* @notice Modify collateral balance for a vault
* @param vault Vault address
* @param asset Collateral asset address
* @param delta Amount to add (positive) or subtract (negative)
*/
function modifyCollateral(address vault, address asset, int256 delta) external;
/**
* @notice Modify debt balance for a vault
* @param vault Vault address
* @param currency Debt currency address (eMoney token)
* @param delta Amount to add (positive) or subtract (negative)
*/
function modifyDebt(address vault, address currency, int256 delta) external;
/**
* @notice Get vault health (collateralization ratio in XAU)
* @param vault Vault address
* @return healthRatio Collateralization ratio in basis points (10000 = 100%)
* @return collateralValue Total collateral value in XAU (18 decimals)
* @return debtValue Total debt value in XAU (18 decimals)
*/
function getVaultHealth(address vault) external view returns (
uint256 healthRatio,
uint256 collateralValue,
uint256 debtValue
);
/**
* @notice Check if a vault can borrow a specific amount
* @param vault Vault address
* @param currency Debt currency address
* @param amount Amount to borrow (in currency units)
* @return canBorrow True if borrow is allowed
* @return reasonCode Reason code if borrow is not allowed
*/
function canBorrow(address vault, address currency, uint256 amount) external view returns (
bool canBorrow,
bytes32 reasonCode
);
/**
* @notice Get collateral balance for a vault
* @param vault Vault address
* @param asset Collateral asset address
* @return balance Collateral balance
*/
function collateral(address vault, address asset) external view returns (uint256);
/**
* @notice Get debt balance for a vault
* @param vault Vault address
* @param currency Debt currency address
* @return balance Debt balance
*/
function debt(address vault, address currency) external view returns (uint256);
/**
* @notice Get debt ceiling for an asset
* @param asset Asset address
* @return ceiling Debt ceiling
*/
function debtCeiling(address asset) external view returns (uint256);
/**
* @notice Get liquidation ratio for an asset
* @param asset Asset address
* @return ratio Liquidation ratio in basis points
*/
function liquidationRatio(address asset) external view returns (uint256);
/**
* @notice Get credit multiplier for an asset
* @param asset Asset address
* @return multiplier Credit multiplier in basis points (50000 = 5x)
*/
function creditMultiplier(address asset) external view returns (uint256);
/**
* @notice Get rate accumulator for an asset
* @param asset Asset address
* @return accumulator Rate accumulator
*/
function rateAccumulator(address asset) external view returns (uint256);
/**
* @notice Set risk parameters for an asset
* @param asset Asset address
* @param debtCeiling_ Debt ceiling
* @param liquidationRatio_ Liquidation ratio in basis points
* @param creditMultiplier_ Credit multiplier in basis points
*/
function setRiskParameters(
address asset,
uint256 debtCeiling_,
uint256 liquidationRatio_,
uint256 creditMultiplier_
) external;
/**
* @notice Grant VAULT_ROLE to an address (for factory use)
* @param account Address to grant role to
*/
function grantVaultRole(address account) external;
event CollateralModified(address indexed vault, address indexed asset, int256 delta);
event DebtModified(address indexed vault, address indexed currency, int256 delta);
event RiskParametersSet(address indexed asset, uint256 debtCeiling, uint256 liquidationRatio, uint256 creditMultiplier);
}

View File

@@ -0,0 +1,45 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @title ILiquidation
* @notice Interface for Liquidation Module
* @dev Handles liquidation of undercollateralized vaults
*/
interface ILiquidation {
/**
* @notice Liquidate an undercollateralized vault
* @param vault Vault address to liquidate
* @param currency Debt currency address
* @param maxDebt Maximum debt to liquidate
* @return seizedCollateral Amount of collateral seized
* @return repaidDebt Amount of debt repaid
*/
function liquidate(
address vault,
address currency,
uint256 maxDebt
) external returns (uint256 seizedCollateral, uint256 repaidDebt);
/**
* @notice Check if a vault can be liquidated
* @param vault Vault address
* @return canLiquidate True if vault can be liquidated
* @return healthRatio Current health ratio in basis points
*/
function canLiquidate(address vault) external view returns (bool canLiquidate, uint256 healthRatio);
/**
* @notice Get liquidation bonus (penalty)
* @return bonus Liquidation bonus in basis points
*/
function liquidationBonus() external view returns (uint256);
event VaultLiquidated(
address indexed vault,
address indexed currency,
uint256 seizedCollateral,
uint256 repaidDebt,
address indexed liquidator
);
}

View File

@@ -0,0 +1,48 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @title IRateAccrual
* @notice Interface for Rate & Accrual Module
* @dev Applies time-based interest to outstanding debt
*/
interface IRateAccrual {
/**
* @notice Accrue interest for an asset
* @param asset Asset address
* @return newAccumulator Updated rate accumulator
*/
function accrueInterest(address asset) external returns (uint256 newAccumulator);
/**
* @notice Get current rate accumulator for an asset
* @param asset Asset address
* @return accumulator Current rate accumulator
*/
function getRateAccumulator(address asset) external view returns (uint256 accumulator);
/**
* @notice Set interest rate for an asset
* @param asset Asset address
* @param rate Annual interest rate in basis points (e.g., 500 = 5%)
*/
function setInterestRate(address asset, uint256 rate) external;
/**
* @notice Get interest rate for an asset
* @param asset Asset address
* @return rate Annual interest rate in basis points
*/
function interestRate(address asset) external view returns (uint256);
/**
* @notice Calculate debt with accrued interest
* @param asset Asset address
* @param principal Principal debt amount
* @return debtWithInterest Debt amount with accrued interest
*/
function calculateDebtWithInterest(address asset, uint256 principal) external view returns (uint256 debtWithInterest);
event InterestAccrued(address indexed asset, uint256 oldAccumulator, uint256 newAccumulator);
event InterestRateSet(address indexed asset, uint256 rate);
}

View File

@@ -0,0 +1,100 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @title IRegulatedEntityRegistry
* @notice Interface for Regulated Entity Registry
* @dev Tracks regulated financial entities eligible for vault operations
*/
interface IRegulatedEntityRegistry {
/**
* @notice Register a regulated entity
* @param entity Entity address
* @param jurisdictionHash Hash of jurisdiction identifier
* @param authorizedWallets Initial authorized wallets
*/
function registerEntity(
address entity,
bytes32 jurisdictionHash,
address[] calldata authorizedWallets
) external;
/**
* @notice Check if an entity is registered and eligible
* @param entity Entity address
* @return isEligible True if entity is registered and not suspended
*/
function isEligible(address entity) external view returns (bool);
/**
* @notice Check if a wallet is authorized for an entity
* @param entity Entity address
* @param wallet Wallet address
* @return isAuthorized True if wallet is authorized
*/
function isAuthorized(address entity, address wallet) external view returns (bool);
/**
* @notice Check if an address is an operator for an entity
* @param entity Entity address
* @param operator Operator address
* @return isOperator True if address is an operator
*/
function isOperator(address entity, address operator) external view returns (bool);
/**
* @notice Add authorized wallet to an entity
* @param entity Entity address
* @param wallet Wallet address to authorize
*/
function addAuthorizedWallet(address entity, address wallet) external;
/**
* @notice Remove authorized wallet from an entity
* @param entity Entity address
* @param wallet Wallet address to remove
*/
function removeAuthorizedWallet(address entity, address wallet) external;
/**
* @notice Set operator status for an entity
* @param entity Entity address
* @param operator Operator address
* @param status True to grant operator status, false to revoke
*/
function setOperator(address entity, address operator, bool status) external;
/**
* @notice Suspend an entity
* @param entity Entity address
*/
function suspendEntity(address entity) external;
/**
* @notice Unsuspend an entity
* @param entity Entity address
*/
function unsuspendEntity(address entity) external;
/**
* @notice Get entity information
* @param entity Entity address
* @return registered True if entity is registered
* @return suspended True if entity is suspended
* @return jurisdictionHash Jurisdiction hash
* @return authorizedWallets List of authorized wallets
*/
function getEntity(address entity) external view returns (
bool registered,
bool suspended,
bytes32 jurisdictionHash,
address[] memory authorizedWallets
);
event EntityRegistered(address indexed entity, bytes32 jurisdictionHash, uint256 timestamp);
event EntitySuspended(address indexed entity, uint256 timestamp);
event EntityUnsuspended(address indexed entity, uint256 timestamp);
event AuthorizedWalletAdded(address indexed entity, address indexed wallet);
event AuthorizedWalletRemoved(address indexed entity, address indexed wallet);
event OperatorSet(address indexed entity, address indexed operator, bool status);
}

View File

@@ -0,0 +1,60 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @title IVault
* @notice Interface for Vault contract
* @dev Aave-style vault operations (deposit, borrow, repay, withdraw)
*/
interface IVault {
/**
* @notice Deposit M0 collateral into vault
* @param asset Collateral asset address
* @param amount Amount to deposit
*/
function deposit(address asset, uint256 amount) external payable;
/**
* @notice Borrow eMoney against collateral
* @param currency eMoney currency address
* @param amount Amount to borrow
*/
function borrow(address currency, uint256 amount) external;
/**
* @notice Repay borrowed eMoney
* @param currency eMoney currency address
* @param amount Amount to repay
*/
function repay(address currency, uint256 amount) external;
/**
* @notice Withdraw collateral from vault
* @param asset Collateral asset address
* @param amount Amount to withdraw
*/
function withdraw(address asset, uint256 amount) external;
/**
* @notice Get vault owner
* @return owner Vault owner address
*/
function owner() external view returns (address);
/**
* @notice Get vault health
* @return healthRatio Collateralization ratio in basis points
* @return collateralValue Total collateral value in XAU
* @return debtValue Total debt value in XAU
*/
function getHealth() external view returns (
uint256 healthRatio,
uint256 collateralValue,
uint256 debtValue
);
event Deposited(address indexed asset, uint256 amount, address indexed depositor);
event Borrowed(address indexed currency, uint256 amount, address indexed borrower);
event Repaid(address indexed currency, uint256 amount, address indexed repayer);
event Withdrawn(address indexed asset, uint256 amount, address indexed withdrawer);
}

View File

@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @title IVaultStrategy
* @notice Interface for vault strategies (deferred implementation)
* @dev Defined now for forward compatibility
*/
interface IVaultStrategy {
function onDeposit(address token, uint256 amount) external;
function onWithdraw(address token, uint256 amount) external;
function onBridgePending(address token, uint256 amount, uint256 estimatedWait) external;
function execute(bytes calldata strategyData) external;
function getStrategyType() external pure returns (string memory);
}

View File

@@ -0,0 +1,66 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @title IXAUOracle
* @notice Interface for XAU Oracle Module
* @dev Multi-source oracle aggregator for ETH/XAU pricing
*/
interface IXAUOracle {
/**
* @notice Get ETH price in XAU
* @return price ETH price in XAU (18 decimals)
* @return timestamp Last update timestamp
*/
function getETHPriceInXAU() external view returns (uint256 price, uint256 timestamp);
/**
* @notice Get liquidation price for a vault
* @param vault Vault address
* @return price Liquidation threshold price in XAU
*/
function getLiquidationPrice(address vault) external view returns (uint256 price);
/**
* @notice Add a price feed source
* @param feed Price feed address (must implement Aggregator interface)
* @param weight Weight for this feed (sum of all weights should be 10000)
*/
function addPriceFeed(address feed, uint256 weight) external;
/**
* @notice Remove a price feed source
* @param feed Price feed address to remove
*/
function removePriceFeed(address feed) external;
/**
* @notice Update feed weight
* @param feed Price feed address
* @param weight New weight
*/
function updateFeedWeight(address feed, uint256 weight) external;
/**
* @notice Freeze oracle (emergency)
*/
function freeze() external;
/**
* @notice Unfreeze oracle
*/
function unfreeze() external;
/**
* @notice Check if oracle is frozen
* @return frozen True if frozen
*/
function isFrozen() external view returns (bool);
event PriceFeedAdded(address indexed feed, uint256 weight);
event PriceFeedRemoved(address indexed feed);
event FeedWeightUpdated(address indexed feed, uint256 oldWeight, uint256 newWeight);
event OracleFrozen(uint256 timestamp);
event OracleUnfrozen(uint256 timestamp);
event PriceUpdated(uint256 price, uint256 timestamp);
}

View File

@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @title IeMoneyJoin
* @notice Interface for eMoney Join Adapter
* @dev Handles minting and burning of eMoney tokens
*/
interface IeMoneyJoin {
/**
* @notice Mint eMoney to a borrower
* @param currency eMoney currency address
* @param to Recipient address
* @param amount Amount to mint
*/
function mint(address currency, address to, uint256 amount) external;
/**
* @notice Burn eMoney from a repayer
* @param currency eMoney currency address
* @param from Source address
* @param amount Amount to burn
*/
function burn(address currency, address from, uint256 amount) external;
event eMoneyMinted(address indexed currency, address indexed to, uint256 amount);
event eMoneyBurned(address indexed currency, address indexed from, uint256 amount);
}