addToBalanceOf
Contract: JBETHERC20ProjectPayer
Interface: IJBProjectPayer
- 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 calldata _memo,
bytes calldata _metadata
) public payable virtual override { ... }
- 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 can be accessed externally by anyone, or internally from this contract or one that inherits it.
- The function can be overriden by inheriting contracts.
- The function overrides a function definition from the
IJBProjectPayer
interface. - The function doesn't return anything.
Bodyβ
-
If the 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 the token is ETH, override the specified amount and decimals values with with amount of ETH sent to the function, which is denoted as a fixed point number with 18 decimals.
// ETH shouldn't be sent if the token isn't ETH.
if (address(_token) != JBTokens.ETH) {
if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED();
// Transfer tokens to this contract from the msg sender.
IERC20(_token).transferFrom(msg.sender, address(this), _amount);
} else {
// If ETH is being paid, set the amount to the message value, and decimals to 18.
_amount = msg.value;
_decimals = 18;
}Library references:
JBTokens
.ETH
External references:
-
Add to the project's balance.
_addToBalanceOf(_projectId, _token, _amount, _decimals, _memo, _metadata);
Internal 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.
@param _metadata Extra data to pass along to the terminal.
*/
function addToBalanceOf(
uint256 _projectId,
address _token,
uint256 _amount,
uint256 _decimals,
string calldata _memo,
bytes calldata _metadata
) public payable virtual override {
// ETH shouldn't be sent if the token isn't ETH.
if (address(_token) != JBTokens.ETH) {
if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED();
// Transfer tokens to this contract from the msg sender.
IERC20(_token).transferFrom(msg.sender, address(this), _amount);
} else {
// If ETH is being paid, set the amount to the message value, and decimals to 18.
_amount = msg.value;
_decimals = 18;
}
_addToBalanceOf(_projectId, _token, _amount, _decimals, _memo, _metadata);
}
String | Description |
---|---|
NO_MSG_VALUE_ALLOWED | Thrown if ETH was sent to a non-ETH terminal. |
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 |