Inheritance Structure
Copy MetaVault
├── MetaVaultBase
│ └── MultiFacetProxy
│ └── OwnableRoles
├── Multicallable
└── NoDelegateCall
ERC7540Engine
└── ModuleBase
└── OwnableRoles
AssetsManager
└── ModuleBase
└── OwnableRoles
Gateway System
├── SuperformGateway
│ └── MultiFacetProxy
│ └── GatewayBase
├── InvestSuperform
│ └── GatewayBase
├── DivestSuperform
│ └── GatewayBase
└── LiquidateSuperform
└── GatewayBase
Core Contract Relationships
MetaVault Core
Copy contract MetaVault {
// Core state tracking
uint128 internal _totalIdle;
uint128 internal _totalDebt;
// Module interfaces
AssetsManager public assetsManager;
ERC7540Engine public engine;
ISuperformGateway public gateway;
// Access control
mapping(address => mapping(address => bool)) public isOperator;
mapping(address => uint256) public positions;
}
ERC7540Engine
Copy contract ERC7540Engine {
// Withdrawal state management
struct ProcessRedeemRequestCache {
uint256[WITHDRAWAL_QUEUE_SIZE][N_CHAINS] dstVaults;
uint256[WITHDRAWAL_QUEUE_SIZE][N_CHAINS] sharesPerVault;
uint256[WITHDRAWAL_QUEUE_SIZE][N_CHAINS] assetsPerVault;
uint256[N_CHAINS] lens;
// ... additional fields
}
// Withdrawal queue processing
function _prepareWithdrawalRoute(
ProcessRedeemRequestCache memory cache
) private view;
}
Gateway System
Copy contract GatewayBase {
// Core gateway state
ISuperPositions public superPositions;
IBaseRouter public superformRouter;
IMetaVault public vault;
address public receiverImplementation;
// Cross-chain tracking
mapping(bytes32 => address) public receivers;
mapping(uint256 => uint256) public pendingXChainInvests;
uint256 public totalpendingXChainInvests;
}
Copy // Receiver contract deployment
function getReceiver(bytes32 key) public returns (address receiverAddress) {
receiverAddress = LibClone.clone(receiverImplementation);
ERC20Receiver(receiverAddress).initialize(key);
}
Error Catalog
Copy error InsufficientAssets();
error VaultNotListed();
error RequestNotFound();
error InvalidController();
error MinimumBalanceNotMet();
error InvalidSuperformId();
error InvalidRecoveryAddress();
error InvalidAmount();
error TotalAmountMismatch();
error SharesLocked();
error VaultShutdown();
error Unauthorized();
error ExceedsMaxDeposit();
error ExceedsMaxMint();
State Flow Diagrams
Deposit Flow
User -> MetaVault: requestDeposit()
MetaVault: Update deposit request state
MetaVault -> User: deposit()
available
MetaVault: Share minting and accounting
Investment Flow
Copy // Example investment flow
function investSingleXChainSingleVault(
SingleXChainSingleVaultStateReq calldata req
) external payable onlyVault {
// 1. Validate and prepare
if (!isVaultListed(vaultAddress)) revert VaultNotListed();
// 2. Setup receiver
address receiver = getReceiver(key);
// 3. Track investment
pendingXChainInvests[superformId] += amount;
// 4. Initiate bridge
gateway.investSingleXChainSingleVault{value: msg.value}(req);
}
Withdrawal Flow
User -> MetaVault: requestRedeem()
ERC7540Engine: Process withdrawal route
Gateway: Handle cross-chain settlements
MetaVault -> User: Final redemption
Key Dependencies
External Protocol Integration
Copy interface ISuperformGateway {
function investSingleXChainSingleVault(
SingleXChainSingleVaultStateReq calldata req
) external payable;
function divestSingleXChainSingleVault(
SingleXChainSingleVaultStateReq calldata req
) external payable;
}
Oracle Integration
Copy interface ISharePriceOracle {
function getLatestSharePrice(
uint64 chainId,
address vault
) external view returns (uint256);
}
State Management
Copy // Request states
mapping(address => ERC7540_Request) private _pendingRedeemRequest;
mapping(address => ERC7540_FilledRequest) private _claimableRedeemRequest;
Critical State Variables
Copy struct VaultData {
uint16 deductedFees;
uint64 chainId;
uint192 lastReportedSharePrice;
uint256 superformId;
ISharePriceOracle oracle;
uint8 decimals;
uint128 totalDebt;
address vaultAddress;
}
// Vault positions
mapping(uint256 => VaultData) public vaults;
Cross-Chain State
Copy // Gateway state tracking
mapping(bytes32 => RequestData) public requests;
EnumerableSetLib.Bytes32Set internal _requestsQueue;
Security Architecture
Access Control Matrix
State Protection
Copy modifier nonReentrant() {
require(_locked != 2, "ReentrancyGuard: reentrant call");
_locked = 2;
_;
_locked = 1;
}
modifier noDelegateCall() {
require(address(this) == __self, "DelegateCall");
_;
}
Upgrade Architecture
Modular design through facet system
Role-based module management
State separation between core and modules
Critical Paths
Investment Critical Path
Cross-chain message verification
Position tracking updates
Withdrawal Critical Path
Withdrawal route calculation
Final redemption processing
Integration Points
Bridge Integration
Copy // Bridge configuration
function setGateway(ISuperformGateway _gateway) external onlyRoles(ADMIN_ROLE) {
gateway = _gateway;
asset().safeApprove(address(_gateway), type(uint256).max);
gateway.superPositions().setApprovalForAll(address(_gateway), true);
}
Oracle Integration
Copy function setHurdleRateOracle(IHurdleRateOracle hurdleRateOracle) external onlyRoles(ADMIN_ROLE) {
_hurdleRateOracle = hurdleRateOracle;
}