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

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

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

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