跳到主要内容

addToBalanceOf

Contract: JBPayoutRedemptionPaymentTerminal​‌

Interface: IJBPaymentTerminal

Receives funds belonging to the specified project.

Definition

function addToBalanceOf(
uint256 _projectId,
uint256 _amount,
address,
string calldata _memo,
bytes calldata _metadata
) external payable virtual override isTerminalOf(_projectId) { ... }
  • Arguments:
    • _projectId is the ID of the project to which the funds received belong.
    • _amount is the amount of tokens to add, as a fixed point number with the same number of decimals as this terminal. If this is an ETH terminal, this is ignored and msg.value is used instead.
    • _token is the token being paid. This terminal ignores this property since it only manages one token.
    • _memo is a memo to pass along to the emitted event.
    • _metadata is metadata to pass along to the emitted event.
  • The function can be accessed externally by anyone.
  • The function can be overriden by inheriting contracts.
  • Through the isTerminalOf modifier, this transaction reverts if this terminal is not one of the project's terminals.
  • The function accepts ETH. The transaction reverts if receives ETH but the terminal's token type isn't ETH.
  • The resulting function overrides a function definition from the IJBPaymentTerminal interface.
  • The function doesn't return anything.

Body

  1. If this terminal's token isn't ETH, make sure ETH wasn't sent to the function, then transfer the amount of tokens from the message sender to this contract. If this terminal's contract is ETH, override the specified amount value with with amount of ETH sent to the function.

    // If this terminal's token isn't ETH, make sure no msg.value was sent, then transfer the tokens in from msg.sender.
    if (token != JBTokens.ETH) {
    // Amount must be greater than 0.
    if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED();

    // Get a reference to the balance before receiving tokens.
    uint256 _balanceBefore = _balance();

    // Transfer tokens to this terminal from the msg sender.
    _transferFrom(msg.sender, payable(address(this)), _amount);

    // The amount should reflect the change in balance.
    _amount = _balance() - _balanceBefore;
    }
    // If the terminal's token is ETH, override `_amount` with msg.value.
    else _amount = msg.value;

    Library references:

    Virtual references:

  2. Forward to the internal function to properly account for the added balance. If the message sender is a feeless address, don't refund held fees.

    _addToBalanceOf(_projectId, _amount, _memo, !isFeelessAddress[msg.sender] _metadata);

    Internal references: