diff --git a/contracts/ApproveAndCallFallBack.sol b/contracts/ApproveAndCallFallBack.sol new file mode 100644 index 0000000..1a410a0 --- /dev/null +++ b/contracts/ApproveAndCallFallBack.sol @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity ^0.8.0; + +/// @title Approve And Call Fallback Token Interface +/// @dev This interface must be implemented by other contracts +/// wishing to accept approve and call from MiniMe token contracts. +abstract contract ApproveAndCallFallBack { + function receiveApproval(address from, uint256 _amount, address _token, bytes memory _data) public virtual; +} diff --git a/contracts/MiniMeToken.sol b/contracts/MiniMeToken.sol index c51e411..e03d65a 100644 --- a/contracts/MiniMeToken.sol +++ b/contracts/MiniMeToken.sol @@ -39,12 +39,10 @@ error ControllerNotSet(); import { Controlled } from "./Controlled.sol"; import { TokenController } from "./TokenController.sol"; +import { ApproveAndCallFallBack } from "./ApproveAndCallFallBack.sol"; +import { MiniMeTokenFactory } from "./MiniMeTokenFactory.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -abstract contract ApproveAndCallFallBack { - function receiveApproval(address from, uint256 _amount, address _token, bytes memory _data) public virtual; -} - /// @dev The actual token contract, the default controller is the msg.sender /// that deploys the contract, so usually this token will be deployed by a /// token controller contract, which Giveth will call a "Campaign" @@ -500,47 +498,3 @@ contract MiniMeToken is Controlled, IERC20 { event ClaimedTokens(address indexed _token, address indexed _controller, uint256 _amount); event NewCloneToken(address indexed _cloneToken, uint256 _snapshotBlock); } - -//////////////// -// MiniMeTokenFactory -//////////////// - -/// @dev This contract is used to generate clone contracts from a contract. -/// In solidity this is the way to create a contract from a contract of the -/// same class -contract MiniMeTokenFactory { - /// @notice Update the DApp by creating a new token with new functionalities - /// the msg.sender becomes the controller of this clone token - /// @param _parentToken Address of the token being cloned - /// @param _snapshotBlock Block of the parent token that will - /// determine the initial distribution of the clone token - /// @param _tokenName Name of the new token - /// @param _decimalUnits Number of decimals of the new token - /// @param _tokenSymbol Token Symbol for the new token - /// @param _transfersEnabled If true, tokens will be able to be transferred - /// @return The address of the new token contract - function createCloneToken( - MiniMeToken _parentToken, - uint256 _snapshotBlock, - string memory _tokenName, - uint8 _decimalUnits, - string memory _tokenSymbol, - bool _transfersEnabled - ) - public - returns (MiniMeToken) - { - MiniMeToken newToken = new MiniMeToken( - this, - _parentToken, - _snapshotBlock, - _tokenName, - _decimalUnits, - _tokenSymbol, - _transfersEnabled - ); - - newToken.changeController(payable(msg.sender)); - return newToken; - } -} diff --git a/contracts/MiniMeTokenFactory.sol b/contracts/MiniMeTokenFactory.sol new file mode 100644 index 0000000..7461fc9 --- /dev/null +++ b/contracts/MiniMeTokenFactory.sol @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity ^0.8.0; + +import "./MiniMeToken.sol"; + +/// @title MiniMeToken Factory Contract +/// @dev This contract is used to generate clone contracts from a contract. +/// In solidity this is the way to create a contract from a contract of the +/// same class +contract MiniMeTokenFactory { + /// @notice Update the DApp by creating a new token with new functionalities + /// the msg.sender becomes the controller of this clone token + /// @param _parentToken Address of the token being cloned + /// @param _snapshotBlock Block of the parent token that will + /// determine the initial distribution of the clone token + /// @param _tokenName Name of the new token + /// @param _decimalUnits Number of decimals of the new token + /// @param _tokenSymbol Token Symbol for the new token + /// @param _transfersEnabled If true, tokens will be able to be transferred + /// @return The address of the new token contract + function createCloneToken( + MiniMeToken _parentToken, + uint256 _snapshotBlock, + string memory _tokenName, + uint8 _decimalUnits, + string memory _tokenSymbol, + bool _transfersEnabled + ) + public + returns (MiniMeToken) + { + MiniMeToken newToken = new MiniMeToken( + this, + _parentToken, + _snapshotBlock, + _tokenName, + _decimalUnits, + _tokenSymbol, + _transfersEnabled + ); + + newToken.changeController(payable(msg.sender)); + return newToken; + } +} diff --git a/contracts/sample/Owned.sol b/contracts/sample/Owned.sol new file mode 100644 index 0000000..27eb803 --- /dev/null +++ b/contracts/sample/Owned.sol @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity ^0.8.0; + +error NotAuthorized(); + +/// @dev `Owned` is a base level contract that assigns an `owner` that can be +/// later changed +contract Owned { + /// @dev `owner` is the only address that can call a function with this + /// modifier + modifier onlyOwner() { + if (msg.sender != owner) revert NotAuthorized(); + _; + } + + address public owner; + + /// @notice The Constructor assigns the message sender to be `owner` + constructor() { + owner = msg.sender; + } + + /// @notice `owner` can step down and assign some other address to this role + /// @param _newOwner The address of the new owner. 0x0 can be used to create + /// an ublock.timestampned neutral vault, however that cannot be undone + function changeOwner(address _newOwner) public onlyOwner { + owner = _newOwner; + } +} diff --git a/contracts/SampleCampaign-TokenController.sol b/contracts/sample/SampleCampaign-TokenController.sol similarity index 88% rename from contracts/SampleCampaign-TokenController.sol rename to contracts/sample/SampleCampaign-TokenController.sol index 1bacb86..95eb154 100755 --- a/contracts/SampleCampaign-TokenController.sol +++ b/contracts/sample/SampleCampaign-TokenController.sol @@ -25,8 +25,9 @@ pragma solidity ^0.8.0; /// funds for non-profit causes, but it can be customized for any variety of /// purposes. -import { MiniMeToken } from "./MiniMeToken.sol"; -import { TokenController } from "./TokenController.sol"; +import { MiniMeToken } from "../MiniMeToken.sol"; +import { TokenController } from "../TokenController.sol"; +import { Owned } from "./Owned.sol"; error NotAuthorized(); error InvalidParameters(); @@ -35,31 +36,6 @@ error TransferFailed(address destination); error TokenMintFailed(); error FundingPeriodNotOver(); -/// @dev `Owned` is a base level contract that assigns an `owner` that can be -/// later changed -contract Owned { - /// @dev `owner` is the only address that can call a function with this - /// modifier - modifier onlyOwner() { - if (msg.sender != owner) revert NotAuthorized(); - _; - } - - address public owner; - - /// @notice The Constructor assigns the message sender to be `owner` - constructor() { - owner = msg.sender; - } - - /// @notice `owner` can step down and assign some other address to this role - /// @param _newOwner The address of the new owner. 0x0 can be used to create - /// an ublock.timestampned neutral vault, however that cannot be undone - function changeOwner(address _newOwner) public onlyOwner { - owner = _newOwner; - } -} - /// @dev This is designed to control the issuance of a MiniMe Token for a /// non-profit Campaign. This contract effectively dictates the terms of the /// funding round.