_currentTotalOverflowOf
Contract: JBSingleTokenPaymentTerminalStore
- Step by step
 - Code
 - Bug bounty
 
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:
_projectIdis the ID of the project to get the total overflow for._decimalsis the number of decimals that the fixed point overflow should include._currencyis 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
- 
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:
 - 
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; - 
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:
 - 
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:
PRBMath.mulDiv(...)
JBCurrencies.ETH
External references:
 - 
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:
PRBMath.mulDiv(...)
JBFixedPointNumber.adjustDecimals(...)
 
/**
  @notice
  Gets the amount that is currently overflowing across all of a project's terminals.
  @dev
  This amount changes as the value of the balances changes in relation to the currency being used to measure the project's distribution limits.
  @param _projectId The ID of the project to get the total overflow for.
  @param _decimals The number of decimals that the fixed point overflow should include.
  @param _currency The currency that the overflow should be in terms of.
  @return overflow The total overflow of a project's funds.
*/
function _currentTotalOverflowOf(
  uint256 _projectId,
  uint256 _decimals,
  uint256 _currency
) private view returns (uint256) {
  // Get a reference to the project's terminals.
  IJBPaymentTerminal[] memory _terminals = directory.terminalsOf(_projectId);
  // Keep a reference to the ETH overflow across all terminals, as a fixed point number with 18 decimals.
  uint256 _ethOverflow;
  // Add the current ETH overflow for each terminal.
  for (uint256 _i; _i < _terminals.length; ) {
    _ethOverflow = _ethOverflow + _terminals[_i].currentEthOverflowOf(_projectId);
    unchecked {
      ++_i;
    }
  }
  // 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));
  // Adjust the decimals of the fixed point number if needed to match the target decimals.
  return
    (_decimals == 18)
      ? _totalOverflow18Decimal
      : JBFixedPointNumber.adjustDecimals(_totalOverflow18Decimal, 18, _decimals);
}
| Category | Description | Reward | 
|---|---|---|
| Optimization | Help make this operation more efficient. | 0.5ETH | 
| Low severity | Identify a vulnerability in this operation that could lead to an inconvenience for a user of the protocol or for a protocol developer. | 1ETH | 
| High severity | Identify a vulnerability in this operation that could lead to data corruption or loss of funds. | 5+ETH |