Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

L2/naming #42

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
'interfaces/IJBController.sol',
'interfaces/IJBControllerUtility.sol',
'interfaces/IJBDirectory.sol',
'interfaces/IJBETHERC20ProjectPayerDeployer.sol',
'interfaces/IJBGasTokenERC20ProjectPayerDeployer.sol',
'interfaces/IJBFeeGauge.sol',
'interfaces/IJBFundingCycleBallot.sol',
'interfaces/IJBFundingCycleDataSource.sol',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import './libraries/JBTokens.sol';
Ownable: Includes convenience functionality for checking a message sender's permissions before executing certain transactions.
ERC165: Introspection on interface adherance.
*/
contract JBETHERC20ProjectPayer is Ownable, ERC165, IJBProjectPayer {
contract JBGasTokenERC20ProjectPayer is Ownable, ERC165, IJBProjectPayer {
using SafeERC20 for IERC20;

//*********************************************************************//
Expand Down Expand Up @@ -104,13 +104,9 @@ contract JBETHERC20ProjectPayer is Ownable, ERC165, IJBProjectPayer {

@param _interfaceId The ID of the interface to check for adherance to.
*/
function supportsInterface(bytes4 _interfaceId)
public
view
virtual
override(ERC165, IERC165)
returns (bool)
{
function supportsInterface(
bytes4 _interfaceId
) public view virtual override(ERC165, IERC165) returns (bool) {
return
_interfaceId == type(IJBProjectPayer).interfaceId || super.supportsInterface(_interfaceId);
}
Expand Down Expand Up @@ -147,7 +143,7 @@ contract JBETHERC20ProjectPayer is Ownable, ERC165, IJBProjectPayer {
bool _defaultPreferAddToBalance,
address _owner
) public {
if(msg.sender != projectPayerDeployer) revert ALREADY_INITIALIZED();
if (msg.sender != projectPayerDeployer) revert ALREADY_INITIALIZED();

defaultProjectId = _defaultProjectId;
defaultBeneficiary = _defaultBeneficiary;
Expand Down Expand Up @@ -176,7 +172,7 @@ contract JBETHERC20ProjectPayer is Ownable, ERC165, IJBProjectPayer {
if (defaultPreferAddToBalance)
_addToBalanceOf(
defaultProjectId,
JBTokens.ETH,
JBTokens.GAS_TOKEN,
address(this).balance,
18, // balance is a fixed point number with 18 decimals.
defaultMemo,
Expand All @@ -185,7 +181,7 @@ contract JBETHERC20ProjectPayer is Ownable, ERC165, IJBProjectPayer {
else
_pay(
defaultProjectId,
JBTokens.ETH,
JBTokens.GAS_TOKEN,
address(this).balance,
18, // balance is a fixed point number with 18 decimals.
defaultBeneficiary == address(0) ? tx.origin : defaultBeneficiary,
Expand Down Expand Up @@ -282,7 +278,7 @@ contract JBETHERC20ProjectPayer is Ownable, ERC165, IJBProjectPayer {
bytes calldata _metadata
) public payable virtual override {
// ETH shouldn't be sent if the token isn't ETH.
if (address(_token) != JBTokens.ETH) {
if (address(_token) != JBTokens.GAS_TOKEN) {
if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED();

// Get a reference to the balance before receiving tokens.
Expand Down Expand Up @@ -332,7 +328,7 @@ contract JBETHERC20ProjectPayer is Ownable, ERC165, IJBProjectPayer {
bytes calldata _metadata
) public payable virtual override {
// ETH shouldn't be sent if the token isn't ETH.
if (address(_token) != JBTokens.ETH) {
if (address(_token) != JBTokens.GAS_TOKEN) {
if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED();

// Get a reference to the balance before receiving tokens.
Expand Down Expand Up @@ -391,16 +387,16 @@ contract JBETHERC20ProjectPayer is Ownable, ERC165, IJBProjectPayer {
if (_terminal.decimalsForToken(_token) != _decimals) revert INCORRECT_DECIMAL_AMOUNT();

// Approve the `_amount` of tokens from the destination terminal to transfer tokens from this contract.
if (_token != JBTokens.ETH) IERC20(_token).safeApprove(address(_terminal), _amount);
if (_token != JBTokens.GAS_TOKEN) IERC20(_token).safeApprove(address(_terminal), _amount);

// If the token is ETH, send it in msg.value.
uint256 _payableValue = _token == JBTokens.ETH ? _amount : 0;
uint256 _payableValue = _token == JBTokens.GAS_TOKEN ? _amount : 0;

// Send funds to the terminal.
// If the token is ETH, send it in msg.value.
_terminal.pay{value: _payableValue}(
_projectId,
_amount, // ignored if the token is JBTokens.ETH.
_amount, // ignored if the token is JBTokens.GAS_TOKEN.
_token,
_beneficiary != address(0) ? _beneficiary : defaultBeneficiary != address(0)
? defaultBeneficiary
Expand Down Expand Up @@ -441,10 +437,10 @@ contract JBETHERC20ProjectPayer is Ownable, ERC165, IJBProjectPayer {
if (_terminal.decimalsForToken(_token) != _decimals) revert INCORRECT_DECIMAL_AMOUNT();

// Approve the `_amount` of tokens from the destination terminal to transfer tokens from this contract.
if (_token != JBTokens.ETH) IERC20(_token).safeApprove(address(_terminal), _amount);
if (_token != JBTokens.GAS_TOKEN) IERC20(_token).safeApprove(address(_terminal), _amount);

// If the token is ETH, send it in msg.value.
uint256 _payableValue = _token == JBTokens.ETH ? _amount : 0;
uint256 _payableValue = _token == JBTokens.GAS_TOKEN ? _amount : 0;

// Add to balance so tokens don't get issued.
_terminal.addToBalanceOf{value: _payableValue}(_projectId, _amount, _token, _memo, _metadata);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import { Clones } from '@openzeppelin/contracts/proxy/Clones.sol';
import {Clones} from '@openzeppelin/contracts/proxy/Clones.sol';

import './interfaces/IJBETHERC20ProjectPayerDeployer.sol';
import './JBETHERC20ProjectPayer.sol';
import './interfaces/IJBGasTokenERC20ProjectPayerDeployer.sol';
import './JBGasTokenERC20ProjectPayer.sol';

/**
@notice
Deploys project payer contracts.

@dev
Adheres to -
IJBETHERC20ProjectPayerDeployer: General interface for the methods in this contract that interact with the blockchain's state according to the protocol's rules.
IJBGasTokenERC20ProjectPayerDeployer: General interface for the methods in this contract that interact with the blockchain's state according to the protocol's rules.
*/
contract JBETHERC20ProjectPayerDeployer is IJBETHERC20ProjectPayerDeployer {

contract JBGasTokenERC20ProjectPayerDeployer is IJBGasTokenERC20ProjectPayerDeployer {
address immutable implementation;

IJBDirectory immutable directory;
Expand All @@ -24,7 +23,7 @@ contract JBETHERC20ProjectPayerDeployer is IJBETHERC20ProjectPayerDeployer {
@param _directory A contract storing directories of terminals and controllers for each project.
*/
constructor(IJBDirectory _directory) {
implementation = address(new JBETHERC20ProjectPayer(_directory));
implementation = address(new JBGasTokenERC20ProjectPayer(_directory));
directory = _directory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import '@paulrberg/contracts/math/PRBMath.sol';
import './interfaces/IJBSplitsPayer.sol';
import './interfaces/IJBSplitsStore.sol';
import './libraries/JBConstants.sol';
import './JBETHERC20ProjectPayer.sol';
import './JBGasTokenERC20ProjectPayer.sol';

/**
@notice
Expand All @@ -23,10 +23,14 @@ import './JBETHERC20ProjectPayer.sol';

@dev
Inherits from -
JBETHERC20ProjectPayer: Sends ETH or ERC20's to a project treasury as it receives direct payments or has it's functions called.
JBGasTokenERC20ProjectPayer: Sends ETH or ERC20's to a project treasury as it receives direct payments or has it's functions called.
ReentrancyGuard: Contract module that helps prevent reentrant calls to a function.
*/
contract JBETHERC20SplitsPayer is JBETHERC20ProjectPayer, ReentrancyGuard, IJBSplitsPayer {
contract JBGasTokenERC20SplitsPayer is
JBGasTokenERC20ProjectPayer,
ReentrancyGuard,
IJBSplitsPayer
{
using SafeERC20 for IERC20;

//*********************************************************************//
Expand Down Expand Up @@ -76,32 +80,23 @@ contract JBETHERC20SplitsPayer is JBETHERC20ProjectPayer, ReentrancyGuard, IJBSp

@return A flag indicating if this contract adheres to the specified interface.
*/
function supportsInterface(bytes4 _interfaceId)
public
view
virtual
override(JBETHERC20ProjectPayer, IERC165)
returns (bool)
{
function supportsInterface(
bytes4 _interfaceId
) public view virtual override(JBGasTokenERC20ProjectPayer, IERC165) returns (bool) {
return
_interfaceId == type(IJBSplitsPayer).interfaceId || super.supportsInterface(_interfaceId);
}

//*********************************************************************//
// -------------------------- constructor ---------------------------- //
//*********************************************************************//
/**
/**
@param _splitsStore A contract that stores splits for each project.
*/
constructor(
IJBSplitsStore _splitsStore
)
JBETHERC20ProjectPayer(
_splitsStore.directory()
)
{
constructor(IJBSplitsStore _splitsStore) JBGasTokenERC20ProjectPayer(_splitsStore.directory()) {
splitsStore = _splitsStore;
}

/**
@dev The re-initialize check is done in the inherited paroject payer

Expand All @@ -128,7 +123,6 @@ contract JBETHERC20SplitsPayer is JBETHERC20ProjectPayer, ReentrancyGuard, IJBSp
bool _preferAddToBalance,
address _owner
) external override {

super.initialize(
_defaultProjectId,
_defaultBeneficiary,
Expand All @@ -144,8 +138,6 @@ contract JBETHERC20SplitsPayer is JBETHERC20ProjectPayer, ReentrancyGuard, IJBSp
defaultSplitsGroup = _defaultSplitsGroup;
}



//*********************************************************************//
// ------------------------- default receive ------------------------- //
//*********************************************************************//
Expand All @@ -163,7 +155,7 @@ contract JBETHERC20SplitsPayer is JBETHERC20ProjectPayer, ReentrancyGuard, IJBSp
defaultSplitsProjectId,
defaultSplitsDomain,
defaultSplitsGroup,
JBTokens.ETH,
JBTokens.GAS_TOKEN,
address(this).balance,
18, // decimals.
defaultBeneficiary != address(0) ? defaultBeneficiary : tx.origin
Expand All @@ -178,7 +170,7 @@ contract JBETHERC20SplitsPayer is JBETHERC20ProjectPayer, ReentrancyGuard, IJBSp
// Pay the project by adding to its balance if prefered.
_addToBalanceOf(
defaultProjectId,
JBTokens.ETH,
JBTokens.GAS_TOKEN,
_leftoverAmount,
18, // decimals.
defaultMemo,
Expand All @@ -188,7 +180,7 @@ contract JBETHERC20SplitsPayer is JBETHERC20ProjectPayer, ReentrancyGuard, IJBSp
else
_pay(
defaultProjectId,
JBTokens.ETH,
JBTokens.GAS_TOKEN,
_leftoverAmount,
18, // decimals.
defaultBeneficiary != address(0) ? defaultBeneficiary : tx.origin,
Expand Down Expand Up @@ -286,7 +278,7 @@ contract JBETHERC20SplitsPayer is JBETHERC20ProjectPayer, ReentrancyGuard, IJBSp
bytes calldata _metadata
) public payable virtual override nonReentrant {
// ETH shouldn't be sent if the token isn't ETH.
if (address(_token) != JBTokens.ETH) {
if (address(_token) != JBTokens.GAS_TOKEN) {
if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED();

// Get a reference to the balance before receiving tokens.
Expand Down Expand Up @@ -335,7 +327,7 @@ contract JBETHERC20SplitsPayer is JBETHERC20ProjectPayer, ReentrancyGuard, IJBSp
// If no project was specified, send the funds directly to the beneficiary or the tx.origin.
else {
// Transfer the ETH.
if (_token == JBTokens.ETH)
if (_token == JBTokens.GAS_TOKEN)
Address.sendValue(
// If there's a beneficiary, send the funds directly to the beneficiary. Otherwise send to the tx.origin.
_beneficiary != address(0) ? payable(_beneficiary) : defaultBeneficiary != address(0)
Expand Down Expand Up @@ -392,7 +384,7 @@ contract JBETHERC20SplitsPayer is JBETHERC20ProjectPayer, ReentrancyGuard, IJBSp
bytes calldata _metadata
) public payable virtual override nonReentrant {
// ETH shouldn't be sent if this terminal's token isn't ETH.
if (address(_token) != JBTokens.ETH) {
if (address(_token) != JBTokens.GAS_TOKEN) {
if (msg.value > 0) revert NO_MSG_VALUE_ALLOWED();

// Get a reference to the balance before receiving tokens.
Expand Down Expand Up @@ -430,7 +422,7 @@ contract JBETHERC20SplitsPayer is JBETHERC20ProjectPayer, ReentrancyGuard, IJBSp
// Otherwise, send a payment to the beneficiary.
else {
// Transfer the ETH.
if (_token == JBTokens.ETH)
if (_token == JBTokens.GAS_TOKEN)
Address.sendValue(
// If there's a default beneficiary, send the funds directly to the beneficiary. Otherwise send to the tx.origin.
defaultBeneficiary != address(0) ? defaultBeneficiary : payable(tx.origin),
Expand Down Expand Up @@ -546,11 +538,11 @@ contract JBETHERC20SplitsPayer is JBETHERC20ProjectPayer, ReentrancyGuard, IJBSp
);

// Approve the `_amount` of tokens for the split allocator to transfer tokens from this contract.
if (_token != JBTokens.ETH)
if (_token != JBTokens.GAS_TOKEN)
IERC20(_token).safeApprove(address(_split.allocator), _splitAmount);

// If the token is ETH, send it in msg.value.
uint256 _payableValue = _token == JBTokens.ETH ? _splitAmount : 0;
uint256 _payableValue = _token == JBTokens.GAS_TOKEN ? _splitAmount : 0;

// Trigger the allocator's `allocate` function.
_split.allocator.allocate{value: _payableValue}(_data);
Expand Down Expand Up @@ -580,7 +572,7 @@ contract JBETHERC20SplitsPayer is JBETHERC20ProjectPayer, ReentrancyGuard, IJBSp
);
} else {
// Transfer the ETH.
if (_token == JBTokens.ETH)
if (_token == JBTokens.GAS_TOKEN)
Address.sendValue(
// Get a reference to the address receiving the tokens. If there's a beneficiary, send the funds directly to the beneficiary. Otherwise send to _defaultBeneficiary.
_split.beneficiary != address(0) ? _split.beneficiary : payable(_defaultBeneficiary),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import { Clones } from '@openzeppelin/contracts/proxy/Clones.sol';
import {Clones} from '@openzeppelin/contracts/proxy/Clones.sol';

import './interfaces/IJBETHERC20SplitsPayerDeployer.sol';
import './interfaces/IJBGasTokenERC20SplitsPayerDeployer.sol';
import './structs/JBSplit.sol';
import './structs/JBGroupedSplits.sol';
import './JBETHERC20SplitsPayer.sol';
import './JBGasTokenERC20SplitsPayer.sol';

/**
@notice
Deploys splits payer contracts.

@dev
Adheres to -
IJBETHERC20SplitsPayerDeployer: General interface for the methods in this contract that interact with the blockchain's state according to the protocol's rules.
IJBGasTokenERC20SplitsPayerDeployer: General interface for the methods in this contract that interact with the blockchain's state according to the protocol's rules.
*/
contract JBETHERC20SplitsPayerDeployer is IJBETHERC20SplitsPayerDeployer {

contract JBGasTokenERC20SplitsPayerDeployer is IJBGasTokenERC20SplitsPayerDeployer {
address immutable implementation;

IJBSplitsStore immutable splitsStore;

constructor(IJBSplitsStore _splitsStore) {
implementation = address(new JBETHERC20SplitsPayer(_splitsStore));
implementation = address(new JBGasTokenERC20SplitsPayer(_splitsStore));
splitsStore = _splitsStore;
}

Expand Down Expand Up @@ -123,7 +122,6 @@ contract JBETHERC20SplitsPayerDeployer is IJBETHERC20SplitsPayerDeployer {
bool _defaultPreferAddToBalance,
address _owner
) public override returns (IJBSplitsPayer splitsPayer) {

// Deploy the splits payer.
splitsPayer = IJBSplitsPayer(payable(Clones.clone(implementation)));

Expand Down
Loading