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

fixed bug, tests, compiles #51

Merged
merged 26 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
102 changes: 102 additions & 0 deletions contracts/JBERC20PaymentTerminal3_1_2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {IERC20Metadata} from '@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol';
import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import {JBPayoutRedemptionPaymentTerminal3_1_2} from './abstract/JBPayoutRedemptionPaymentTerminal3_1_2.sol';
import {IJBDirectory} from './interfaces/IJBDirectory.sol';
import {IJBOperatorStore} from './interfaces/IJBOperatorStore.sol';
import {IJBProjects} from './interfaces/IJBProjects.sol';
import {IJBSplitsStore} from './interfaces/IJBSplitsStore.sol';
import {IJBPrices} from './interfaces/IJBPrices.sol';

/// @notice Manages the inflows and outflows of an ERC-20 token.
contract JBERC20PaymentTerminal3_1_2 is JBPayoutRedemptionPaymentTerminal3_1_2 {
using SafeERC20 for IERC20;

//*********************************************************************//
// -------------------------- internal views ------------------------- //
//*********************************************************************//

/// @notice Checks the balance of tokens in this contract.
/// @return The contract's balance, as a fixed point number with the same amount of decimals as this terminal.
function _balance() internal view override returns (uint256) {
return IERC20(token).balanceOf(address(this));
}

//*********************************************************************//
// -------------------------- constructor ---------------------------- //
//*********************************************************************//

/// @param _token The token that this terminal manages.
/// @param _currency The currency that this terminal's token adheres to for price feeds.
/// @param _baseWeightCurrency The currency to base token issuance on.
/// @param _payoutSplitsGroup The group that denotes payout splits from this terminal in the splits store.
/// @param _operatorStore A contract storing operator assignments.
/// @param _projects A contract which mints ERC-721's that represent project ownership and transfers.
/// @param _directory A contract storing directories of terminals and controllers for each project.
/// @param _splitsStore A contract that stores splits for each project.
/// @param _prices A contract that exposes price feeds.
/// @param _store A contract that stores the terminal's data.
/// @param _owner The address that will own this contract.
constructor(
IERC20Metadata _token,
uint256 _currency,
uint256 _baseWeightCurrency,
uint256 _payoutSplitsGroup,
IJBOperatorStore _operatorStore,
IJBProjects _projects,
IJBDirectory _directory,
IJBSplitsStore _splitsStore,
IJBPrices _prices,
address _store,
address _owner
)
JBPayoutRedemptionPaymentTerminal3_1_2(
address(_token),
_token.decimals(),
_currency,
_baseWeightCurrency,
_payoutSplitsGroup,
_operatorStore,
_projects,
_directory,
_splitsStore,
_prices,
_store,
_owner
)
// solhint-disable-next-line no-empty-blocks
{

}

//*********************************************************************//
// ---------------------- internal transactions ---------------------- //
//*********************************************************************//

/// @notice Transfers tokens.
/// @param _from The address from which the transfer should originate.
/// @param _to The address to which the transfer should go.
/// @param _amount The amount of the transfer, as a fixed point number with the same number of decimals as this terminal.
function _transferFrom(address _from, address payable _to, uint256 _amount) internal override {
_from == address(this)
? IERC20(token).safeTransfer(_to, _amount)
: IERC20(token).safeTransferFrom(_from, _to, _amount);
}

/// @notice Logic to be triggered before transferring tokens from this terminal.
/// @param _to The address to which the transfer is going.
/// @param _amount The amount of the transfer, as a fixed point number with the same number of decimals as this terminal.
function _beforeTransferTo(address _to, uint256 _amount) internal override {
IERC20(token).safeIncreaseAllowance(_to, _amount);
}

/// @notice Logic to be triggered if a transfer should be undone
/// @param _to The address to which the transfer went.
/// @param _amount The amount of the transfer, as a fixed point number with the same number of decimals as this terminal.
function _cancelTransferTo(address _to, uint256 _amount) internal override {
IERC20(token).safeDecreaseAllowance(_to, _amount);
}
}
81 changes: 81 additions & 0 deletions contracts/JBETHPaymentTerminal3_1_2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import {Address} from '@openzeppelin/contracts/utils/Address.sol';
import {JBPayoutRedemptionPaymentTerminal3_1_2} from './abstract/JBPayoutRedemptionPaymentTerminal3_1_2.sol';
import {IJBDirectory} from './interfaces/IJBDirectory.sol';
import {IJBOperatorStore} from './interfaces/IJBOperatorStore.sol';
import {IJBProjects} from './interfaces/IJBProjects.sol';
import {IJBSplitsStore} from './interfaces/IJBSplitsStore.sol';
import {IJBPrices} from './interfaces/IJBPrices.sol';
import {JBCurrencies} from './libraries/JBCurrencies.sol';
import {JBSplitsGroups} from './libraries/JBSplitsGroups.sol';
import {JBTokens} from './libraries/JBTokens.sol';

/// @notice Manages all inflows and outflows of ETH funds into the protocol ecosystem.
contract JBETHPaymentTerminal3_1_2 is JBPayoutRedemptionPaymentTerminal3_1_2 {
//*********************************************************************//
// -------------------------- internal views ------------------------- //
//*********************************************************************//

/// @notice Checks the balance of tokens in this contract.
/// @return The contract's balance, as a fixed point number with the same amount of decimals as this terminal.
function _balance() internal view override returns (uint256) {
return address(this).balance;
}

//*********************************************************************//
// -------------------------- constructor ---------------------------- //
//*********************************************************************//

/// @param _baseWeightCurrency The currency to base token issuance on.
/// @param _operatorStore A contract storing operator assignments.
/// @param _projects A contract which mints ERC-721's that represent project ownership and transfers.
/// @param _directory A contract storing directories of terminals and controllers for each project.
/// @param _splitsStore A contract that stores splits for each project.
/// @param _prices A contract that exposes price feeds.
/// @param _store A contract that stores the terminal's data.
/// @param _owner The address that will own this contract.
constructor(
uint256 _baseWeightCurrency,
IJBOperatorStore _operatorStore,
IJBProjects _projects,
IJBDirectory _directory,
IJBSplitsStore _splitsStore,
IJBPrices _prices,
address _store,
address _owner
)
JBPayoutRedemptionPaymentTerminal3_1_2(
JBTokens.ETH,
18, // 18 decimals.
JBCurrencies.ETH,
_baseWeightCurrency,
JBSplitsGroups.ETH_PAYOUT,
_operatorStore,
_projects,
_directory,
_splitsStore,
_prices,
_store,
_owner
)
// solhint-disable-next-line no-empty-blocks
{

}

//*********************************************************************//
// ---------------------- internal transactions ---------------------- //
//*********************************************************************//

/// @notice Transfers tokens.
/// @param _from The address from which the transfer should originate.
/// @param _to The address to which the transfer should go.
/// @param _amount The amount of the transfer, as a fixed point number with the same number of decimals as this terminal.
function _transferFrom(address _from, address payable _to, uint256 _amount) internal override {
_from; // Prevents unused var compiler and natspec complaints.

Address.sendValue(_to, _amount);
}
}
Loading
Loading