NashPoint
NashPoint
  • Introduction
    • Introduction To Nashpoint
    • Current Features & Capabilities
    • Post Launch Roadmap
  • User Documentation
    • Node Contract Overview
    • Node Owner & Rebalancer Roles
    • Portfolio Management
    • Rebalancing & Strategy Execution
    • User Deposits & Shares
    • Asynchronous Redemptions
      • Two Step Process
    • Swing Pricing
    • Processing User Redemptions
    • Management & Execution Fees
  • Developer Documentation
    • Overview
    • Role-Based Access Control
    • Smart Contract Architecture
  • Routers
    • ERC-4626 Router
    • ERC-7540 Router
    • Router Tolerance
  • Creating A Node
  • Asynchronous Redemptions
  • Managing a Node
    • Adding & Removing Components
    • Updating Component Allocations
    • Rebalance Window & Cooldown
    • Rebalancing a Node
    • Managing Rebalancers
    • Processing User Redemptions
      • Reserve vs Component Fulfillment
    • Reserve Management
    • Fees Configuration
    • Liquidation Queue Configuration
    • Max Deposit Limits
    • Operator Permissions
    • Emergency Controls
  • Upgrading a Node
    • Adding Quoters & Routers
    • Custom Router Development
    • Multi-Tier Permissioning
  • Cached Data & Gas Efficiency
  • Swing Pricing Calculations
  • Adding Routers and Components - Step by Step Guide
  • Node Execute Function
  • Resources
    • FAQ
    • Glossary
    • Supported Networks & Protocols
    • Deployments
    • Audits
    • GitHub
    • Telegram
    • NashPoint
  • Node Strategies
    • Test Node A
Powered by GitBook
On this page
Edit on GitHub

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

PreviousMulti-Tier PermissioningNextSwing Pricing Calculations

Last updated 2 months ago