_addToBalanceOf
Contract: JBETHERC20ProjectPayer
- Step by step
 - Code
 - Errors
 - Bug bounty
 
Add to the balance of the specified project.
Definition
function _addToBalanceOf(
  uint256 _projectId,
  address _token,
  uint256 _amount,
  uint256 _decimals,
  string memory _memo,
  bytes memory _metadata
) internal virtual { ... }
- Arguments:
_projectIdis the ID of the project that is being paid._tokenis the token being paid in._amountis the amount of tokens being paid, as a fixed point number. If the token is ETH, this is ignored and msg.value is used in its place._decimalsis the number of decimals in the_amountfixed point number. If the token is ETH, this is ignored and 18 is used in its place, which corresponds to the amount of decimals expected in msg.value._memois a memo to pass along to the emitted event._metadatais extra data to pass along to the terminal.
 - The function is private to this contract.
 - The function doesn't return anything.
 
Body
- 
Get a reference to the terminal that should be sent the payment by checking for the project's stored primary terminal for the token being paid.
// Find the terminal for the specified project.
IJBPaymentTerminal _terminal = directory.primaryTerminalOf(_projectId, _token);Internal references:
External references:
 - 
Make sure there is a terminal to make a payment towards.
// There must be a terminal.
if (_terminal == IJBPaymentTerminal(address(0))) revert TERMINAL_NOT_FOUND(); - 
Make sure the number of decimals in the amount being paid matches the number of decimals expected by the terminal.
// The amount's decimals must match the terminal's expected decimals.
if (_terminal.decimalsForToken(_token) != _decimals) revert INCORRECT_DECIMAL_AMOUNT();External references:
 - 
If the token being paid is an ERC20, approve the terminal to spend the amount of tokens from this terminal.
// Approve the `_amount` of tokens from the destination terminal to transfer tokens from this contract.
if (_token != JBTokens.ETH) IERC20(_token).approve(address(_terminal), _amount);Library references:
JBTokens.ETH
External references:
 - 
Keep a reference to the amount to send in the transaction. If the token being paid is ETH, send the value along with the tx.
// If the token is ETH, send it in msg.value.
uint256 _payableValue = _token == JBTokens.ETH ? _amount : 0;Library references:
JBTokens.ETH
 - 
Add to the project's balance with the provided properties.
// Add to balance so tokens don't get issued.
_terminal.addToBalanceOf{value: _payableValue}(_projectId, _amount, _token, _memo);External references:
 
/**
  @notice
  Add to the balance of the specified project.
  @param _projectId The ID of the project that is being paid.
  @param _token The token being paid in.
  @param _amount The amount of tokens being paid, as a fixed point number. If the token is ETH, this is ignored and msg.value is used in its place.
  @param _decimals The number of decimals in the `_amount` fixed point number. If the token is ETH, this is ignored and 18 is used in its place, which corresponds to the amount of decimals expected in msg.value.
  @param _memo A memo to pass along to the emitted event, and passed along the the funding cycle's data source and delegate.  A data source can alter the memo before emitting in the event and forwarding to the delegate.
  @param _memo A memo to pass along to the emitted event.
  @param _metadata Extra data to pass along to the terminal.
*/
function _addToBalanceOf(
  uint256 _projectId,
  address _token,
  uint256 _amount,
  uint256 _decimals,
  string memory _memo,
  bytes memory _metadata
) internal virtual {
  // Find the terminal for the specified project.
  IJBPaymentTerminal _terminal = directory.primaryTerminalOf(_projectId, _token);
  // There must be a terminal.
  if (_terminal == IJBPaymentTerminal(address(0))) revert TERMINAL_NOT_FOUND();
  // The amount's decimals must match the terminal's expected decimals.
  if (_terminal.decimalsForToken(_token) != _decimals) revert INCORRECT_DECIMAL_AMOUNT();
  // Approve the `_amount` of tokens from the destination terminal to transfer tokens from this contract.
  if (_token != JBTokens.ETH) IERC20(_token).approve(address(_terminal), _amount);
  // If the token is ETH, send it in msg.value.
  uint256 _payableValue = _token == JBTokens.ETH ? _amount : 0;
  // Add to balance so tokens don't get issued.
  _terminal.addToBalanceOf{value: _payableValue}(_projectId, _amount, _token, _memo, _metadata);
}
| String | Description | 
|---|---|
TERMINAL_NOT_FOUND | Thrown if the project has no terminal for the specified token | 
INCORRECT_DECIMAL_AMOUNT | Thrown if the amount being paid is a fixed point number with a different amount of decimals than the terminal expects | 
| 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 |