Skip to main content

_addToBalanceOf

Contract: JBETHERC20ProjectPayer

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:
    • _projectId is the ID of the project that is being paid.
    • _token is the token being paid in.
    • _amount is 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.
    • _decimals is 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.
    • _memo is a memo to pass along to the emitted event.
    • _metadata is extra data to pass along to the terminal.
  • The function is private to this contract.
  • The function doesn't return anything.

Body​

  1. 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:

  2. 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();
  3. 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:

  4. 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:

    External references:

  5. 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:

  6. 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: