Skip to main content

JBETHERC20ProjectPayer

Sends ETH or ERC20's to a project treasury as it receives direct payments or has it's functions called.

Git Source

Inherits: Ownable, ERC165, IJBProjectPayer

Inherit from this contract or borrow from its logic to forward ETH or ERC20's to project treasuries from within other contracts.

Adheres to:

  • IJBProjectPayer: General interface for the methods in this contract that interact with the blockchain's state according to the protocol's rules.*

Inherits from:

  • Ownable: Includes convenience functionality for checking a message sender's permissions before executing certain transactions.
  • ERC165: Introspection on interface adherance.

State Variables

directory

A contract storing directories of terminals and controllers for each project.

IJBDirectory public immutable override directory;

projectPayerDeployer

The deployer associated with this implementation. Used to rule out double initialization.

address public immutable override projectPayerDeployer;

defaultProjectId

The ID of the project that should be used to forward this contract's received payments.

uint256 public override defaultProjectId;

defaultBeneficiary

The beneficiary that should be used in the payment made when this contract receives payments.

address payable public override defaultBeneficiary;

defaultPreferClaimedTokens

A flag indicating whether issued tokens should be automatically claimed into the beneficiary's wallet. Leaving tokens unclaimed saves gas.

bool public override defaultPreferClaimedTokens;

defaultMemo

The memo that should be used in the payment made when this contract receives payments.

string public override defaultMemo;

defaultMetadata

The metadata that should be used in the payment made when this contract receives payments.

bytes public override defaultMetadata;

defaultPreferAddToBalance

A flag indicating if received payments should call the pay function or the addToBalance function of a project.

bool public override defaultPreferAddToBalance;

Functions

supportsInterface

Indicates if this contract adheres to the specified interface.

See {IERC165-supportsInterface}.

function supportsInterface(bytes4 _interfaceId)
public
view
virtual
override(ERC165, IERC165)
returns (bool);

Parameters

NameTypeDescription
_interfaceIdbytes4The ID of the interface to check for adherance to.

constructor

This is the constructor of the implementation. The directory is shared between project payers and is immutable. If a new JBDirectory is needed, a new JBProjectPayerDeployer should be deployed.

constructor(IJBDirectory _directory);

Parameters

NameTypeDescription
_directoryIJBDirectoryA contract storing directories of terminals and controllers for each project.

initialize

function initialize(
uint256 _defaultProjectId,
address payable _defaultBeneficiary,
bool _defaultPreferClaimedTokens,
string memory _defaultMemo,
bytes memory _defaultMetadata,
bool _defaultPreferAddToBalance,
address _owner
) public;

Parameters

NameTypeDescription
_defaultProjectIduint256The ID of the project whose treasury should be forwarded this contract's received payments.
_defaultBeneficiaryaddress payableThe address that'll receive the project's tokens.
_defaultPreferClaimedTokensboolA flag indicating whether issued tokens should be automatically claimed into the beneficiary's wallet.
_defaultMemostringA 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.
_defaultMetadatabytesBytes to send along to the project's data source and delegate, if provided.
_defaultPreferAddToBalanceboolA flag indicating if received payments should call the pay function or the addToBalance function of a project.
_owneraddressThe address that will own the contract.

receive

Received funds are paid to the default project ID using the stored default properties.

Use the addToBalance function if there's a preference to do so. Otherwise use pay.

This function is called automatically when the contract receives an ETH payment.

receive() external payable virtual override;

setDefaultValues

Sets the default values that determine how to interact with a protocol treasury when this contract receives ETH directly.

function setDefaultValues(
uint256 _projectId,
address payable _beneficiary,
bool _preferClaimedTokens,
string memory _memo,
bytes memory _metadata,
bool _defaultPreferAddToBalance
) external virtual override onlyOwner;

Parameters

NameTypeDescription
_projectIduint256The ID of the project whose treasury should be forwarded this contract's received payments.
_beneficiaryaddress payableThe address that'll receive the project's tokens.
_preferClaimedTokensboolA flag indicating whether issued tokens should be automatically claimed into the beneficiary's wallet.
_memostringThe memo that'll be used.
_metadatabytesThe metadata that'll be sent.
_defaultPreferAddToBalanceboolA flag indicating if received payments should call the pay function or the addToBalance function of a project.

pay

Make a payment to the specified project.

function pay(
uint256 _projectId,
address _token,
uint256 _amount,
uint256 _decimals,
address _beneficiary,
uint256 _minReturnedTokens,
bool _preferClaimedTokens,
string calldata _memo,
bytes calldata _metadata
) public payable virtual override;

Parameters

NameTypeDescription
_projectIduint256The ID of the project that is being paid.
_tokenaddressThe token being paid in.
_amountuint256The 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.
_decimalsuint256The 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.
_beneficiaryaddressThe address who will receive tokens from the payment.
_minReturnedTokensuint256The minimum number of project tokens expected in return, as a fixed point number with 18 decimals.
_preferClaimedTokensboolA 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.
_memostringA 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.
_metadatabytesBytes to send along to the data source, delegate, and emitted event, if provided.

addToBalanceOf

Add to the balance of the specified project.

function addToBalanceOf(
uint256 _projectId,
address _token,
uint256 _amount,
uint256 _decimals,
string calldata _memo,
bytes calldata _metadata
) public payable virtual override;

Parameters

NameTypeDescription
_projectIduint256The ID of the project that is being paid.
_tokenaddressThe token being paid in.
_amountuint256The 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.
_decimalsuint256The 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.
_memostringA memo to pass along to the emitted event.
_metadatabytesExtra data to pass along to the terminal.

_pay

Make a payment to the specified project.

function _pay(
uint256 _projectId,
address _token,
uint256 _amount,
uint256 _decimals,
address _beneficiary,
uint256 _minReturnedTokens,
bool _preferClaimedTokens,
string memory _memo,
bytes memory _metadata
) internal virtual;

Parameters

NameTypeDescription
_projectIduint256The ID of the project that is being paid.
_tokenaddressThe token being paid in.
_amountuint256The amount of tokens being paid, as a fixed point number.
_decimalsuint256The number of decimals in the _amount fixed point number.
_beneficiaryaddressThe address who will receive tokens from the payment.
_minReturnedTokensuint256The minimum number of project tokens expected in return, as a fixed point number with 18 decimals.
_preferClaimedTokensboolA 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.
_memostringA 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.
_metadatabytesBytes to send along to the data source and delegate, if provided.

_addToBalanceOf

Add to the balance of the specified project.

function _addToBalanceOf(
uint256 _projectId,
address _token,
uint256 _amount,
uint256 _decimals,
string memory _memo,
bytes memory _metadata
) internal virtual;

Parameters

NameTypeDescription
_projectIduint256The ID of the project that is being paid.
_tokenaddressThe token being paid in.
_amountuint256The 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.
_decimalsuint256The 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.
_memostringA memo to pass along to the emitted event.
_metadatabytesExtra data to pass along to the terminal.

Errors

INCORRECT_DECIMAL_AMOUNT

error INCORRECT_DECIMAL_AMOUNT();

ALREADY_INITIALIZED

error ALREADY_INITIALIZED();

NO_MSG_VALUE_ALLOWED

error NO_MSG_VALUE_ALLOWED();

TERMINAL_NOT_FOUND

error TERMINAL_NOT_FOUND();