Skip to main content

pay

Contract: JBPayoutRedemptionPaymentTerminal​‌

Interface: IJBPaymentTerminal

Contribute tokens to a project.

Definition

function pay(
uint256 _projectId,
uint256 _amount,
address _token,
address _beneficiary,
uint256 _minReturnedTokens,
bool _preferClaimedTokens,
string calldata _memo,
bytes calldata _metadata
) external payable virtual override isTerminalOf(_projectId) returns (uint256) { ... }
  • Arguments:
    • _projectId is the ID of the project being paid.
    • _amount is the amount of terminal tokens being received, as a fixed point number with the same amount of decimals as this terminal. If this terminal's token is ETH, this is ignored and msg.value is used in its place.
    • _token is the token being paid. This terminal ignores this property since it only manages one token.
    • _beneficiary is the address to mint tokens for and pass along to the funding cycle's data source and delegate.
    • _minReturnedTokens is the minimum number of project tokens expected in return, as a fixed point number with the same amount of decimals as this terminal.
    • _preferClaimedTokens is a flag indicating whether the request prefers to mint project tokens into the beneficiaries wallet rather than leaving them unclaimed. This is only possible if the project has an attached token contract. Leaving them unclaimed saves gas.
    • _memo is 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.
    • _metadata are bytes to send along to the data source, delegate, and emitted event, if provided.
  • 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 returns the number of tokens minted for the beneficiary, as a fixed point number with 18 decimals.

Body

  1. If this terminal's token is not ETH, make sure ETH wasn't sent to it. Then transfer the specified 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.

    // ETH shouldn't be sent if this terminal's token isn't ETH.
    if (token != JBTokens.ETH) {
    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 this terminal's token is ETH, override _amount with msg.value.
    else _amount = msg.value;

    Library references:

    Virtual references:

  2. Forward the call to the internal version of the function that is also used by other operations.

    return
    _pay(
    _amount,
    msg.sender,
    _projectId,
    _beneficiary,
    _minReturnedTokens,
    _preferClaimedTokens,
    _memo,
    _metadata
    );

    Internal references: