Skip to main content

_currentTotalOverflowOf

Contract: JBSingleTokenPaymentTerminalStore​‌

Gets the amount that is currently overflowing across all of a project's terminals.

This amount changes as the value of the balances changes in relation to the currency being used to measure the project's distribution limits.

Definition

function _currentTotalOverflowOf(
uint256 _projectId,
uint256 _decimals,
uint256 _currency
) private view returns (uint256) { ... }
  • Arguments:
    • _projectId is the ID of the project to get the total overflow for.
    • _decimals is the number of decimals that the fixed point overflow should include.
    • _currency is the currency that the overflow should be in terms of.
  • The view function is private to this contract.
  • The view function does not alter state on the blockchain.
  • The function returns the total overflow of a project's funds.

Body

  1. Get a reference to all of the project's current terminals.

    // Get a reference to the project's terminals.
    IJBPaymentTerminal[] memory _terminals = directory.terminalsOf(_projectId);

    Internal references:

  2. Create a reference where the total balance across all terminals is be stored in terms of ETH.

    // Keep a reference to the ETH overflow across all terminals, as a fixed point number with 18 decimals.
    uint256 _ethOverflow;
  3. For each terminal, add its balance in terms of ETH to the total ETH balance.

    // Add the current ETH overflow for each terminal.
    for (uint256 _i; _i < _terminals.length; ) {
    _ethOverflow = _ethOverflow + _terminals[_i].currentEthOverflowOf(_projectId);
    unchecked {
    ++_i;
    }
    }

    External references:

  4. If the total overflow is to be returned in a currency other than ETH, make the conversion while maintaining 18 decimals of fidelity.

    // Convert the ETH overflow to the specified currency if needed, maintaining a fixed point number with 18 decimals.
    uint256 _totalOverflow18Decimal = _currency == JBCurrencies.ETH
    ? _ethOverflow
    : PRBMath.mulDiv(_ethOverflow, 10**18, prices.priceFor(JBCurrencies.ETH, _currency, 18));

    Library references:

    External references:

  5. If the fixed point overflow is to be returned with a number of decimals other than 18, adjust the number accordingly.

    // Adjust the decimals of the fixed point number if needed to match the target decimals.
    return
    (_decimals == 18)
    ? _totalOverflow18Decimal
    : JBFixedPointNumber.adjustDecimals(_totalOverflow18Decimal, 18, _decimals);

    Library references: