Cached Data & Gas Efficiency
Cache System
The Node uses cached values to minimize external calls when calculating share price, reducing gas costs for users. This is particularly important for Nodes with many components, where calculating total assets requires calls to each component.
Total Assets Cache
uint256 public cacheTotalAssets; // Total value of all assets
function _updateTotalAssets() internal {
uint256 assets = IERC20(asset).balanceOf(address(this));
for (uint256 i = 0; i < components.length; i++) {
address component = components[i];
address router = componentAllocations[component].router;
assets += IRouter(router).getComponentAssets(component);
}
cacheTotalAssets = assets;
}
cacheTotalAssets
stores the total value of all Node assets to avoid expensive recalculations. It is updated:
When starting a rebalance
After investments or liquidations
After fee collection
Cache Validity
function isCacheValid() public view returns (bool) {
return (block.timestamp < lastRebalance + rebalanceWindow + rebalanceCooldown);
}
function maxDeposit(address) public view returns (uint256) {
return isCacheValid() ? maxDepositSize : 0;
}
The cache is considered valid during the rebalance window and cooldown period. When invalid:
New deposits are blocked (
maxDeposit
returns 0)Forces price updates via rebalance before accepting deposits
Protects users from stale pricing
Redemption Tracking
uint256 public sharesExiting; // Tracks shares pending redemption
function requestRedeem(uint256 shares, address controller, address owner) external {
// ... other checks ...
Request storage request = requests[controller];
request.pendingRedeemRequest += shares;
request.sharesAdjusted += adjustedShares;
sharesExiting += shares;
}
function _finalizeRedemption(address controller, uint256 assetsToReturn, uint256 sharesPending, uint256 sharesAdjusted) internal {
// ... other operations ...
sharesExiting -= sharesPending;
cacheTotalAssets -= assetsToReturn;
}
sharesExiting
tracks the total shares pending redemption to ensure the Node maintains sufficient reserves. This value is:
Increased when redemptions are requested
Decreased when redemptions are fulfilled
Used to calculate true reserve ratio
Prevents overinvestment of reserves needed for redemptions
Available Reserve Calculation
function getCashAfterRedemptions() public view returns (uint256) {
uint256 balance = IERC20(asset).balanceOf(address(this));
uint256 exitingAssets = convertToAssets(sharesExiting);
return balance >= exitingAssets ? balance - exitingAssets : 0;
}
This function returns the actual available reserve by:
Starting with current reserve balance
Subtracting value of all pending redemptions
Returns 0 if pending redemptions exceed balance
Used by routers to determine safe investment amounts
Last updated