ETH Price: $1,884.74 (-0.46%)

Transaction Decoder

Block:
5080871 at Feb-13-2018 04:31:06 AM +UTC
Transaction Fee:
0.000203288 ETH $0.38
Gas Used:
203,288 Gas / 1 Gwei

Emitted Events:

38 FundRequestToken.Transfer( _from=0x0000000000000000000000000000000000000000, _to=[Sender] 0x2fcf7629d13166d067d35f99a5614a16fa22683d, _amount=1800000000000000000000 )
39 FundRequestToken.Transfer( _from=0x0000000000000000000000000000000000000000, _to=0x00c7B194d85e9c5f924577337790603b532588b4, _amount=2700000000000000000000 )
40 FundRequestTokenGeneration.Paid( _beneficiary=[Sender] 0x2fcf7629d13166d067d35f99a5614a16fa22683d, _weiAmount=1000000000000000000, _tokenAmount=1800000000000000000000, _personalCapActive=True )
41 Wallet.Deposit( from=[Receiver] FundRequestTokenGeneration, value=1000000000000000000 )

Account State Difference:

  Address   Before After State Difference Code
0x2Fcf7629...6fA22683D
4.73059863202 Eth
Nonce: 31
3.73039534402 Eth
Nonce: 32
1.000203288
0x4DF47B49...89493953b
0x72101D19...9646E751f
(FundRequest: MultiSig)
1,023.415629149599054557 Eth1,024.415629149599054557 Eth1
(MiningPoolHub: Old Address)
16,281.112722740634713417 Eth16,281.112926028634713417 Eth0.000203288
0xBCC546EB...19893729c
(FundRequest: Token Sale)

Execution Trace

ETH 1 FundRequestTokenGeneration.CALL( )
  • FundRequestToken.CALL( )
  • FundRequestToken.generateTokens( _owner=0x2Fcf7629d13166D067D35F99a5614A16fA22683D, _amount=1800000000000000000000 ) => ( True )
  • FundRequestToken.generateTokens( _owner=0x00c7B194d85e9c5f924577337790603b532588b4, _amount=2700000000000000000000 ) => ( True )
  • ETH 1 Wallet.CALL( )
    File 1 of 3: FundRequestTokenGeneration
    pragma solidity ^0.4.18;
    
    // FundRequest Token Sale
    //
    // @authors:
    // Davy Van Roy <[email protected]>
    // Quinten De Swaef <[email protected]>
    //
    // By sending ETH to this contract, you agree to the terms and conditions for participating in the FundRequest Token Sale:
    // https://sale.fundrequest.io/assets/Terms-Conditions.pdf
    //
    // Security audit performed by LeastAuthority:
    // https://github.com/FundRequest/audit-reports/raw/master/2018-02-06 - Least Authority - ICO Contracts Audit Report.pdf
    
    
    contract ApproveAndCallFallBack {
        function receiveApproval(address from, uint256 _amount, address _token, bytes _data) public;
    }
    
    /// @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 { require (msg.sender == owner); _; }
    
        address public owner;
    
        /// @notice The Constructor assigns the message sender to be `owner`
        function Owned() public { 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 unowned neutral vault, however that cannot be undone
        function changeOwner(address _newOwner) public onlyOwner {
            owner = _newOwner;
        }
    }
    
    /**
     * @title SafeMath
     * @dev Math operations with safety checks that throw on error
     */
    library SafeMath {
      function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a * b;
        assert(a == 0 || c / a == b);
        return c;
      }
    
      function div(uint256 a, uint256 b) internal pure returns (uint256) {
        // assert(b > 0); // Solidity automatically throws when dividing by 0
        uint256 c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold
        return c;
      }
    
      function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        assert(b <= a);
        return a - b;
      }
    
      function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        assert(c >= a);
        return c;
      }
    }
    
    
    
    
    
    
    /**
     * @title Pausable
     * @dev Base contract which allows children to implement an emergency stop mechanism.
     */
    contract Pausable is Owned {
      event Pause();
      event Unpause();
    
      bool public paused = false;
    
    
      /**
       * @dev modifier to allow actions only when the contract IS paused
       */
      modifier whenNotPaused() {
        require(!paused);
        _;
      }
    
      /**
       * @dev modifier to allow actions only when the contract IS NOT paused
       */
      modifier whenPaused() {
        require(paused);
        _;
      }
    
      /**
       * @dev called by the owner to pause, triggers stopped state
       */
      function pause() public onlyOwner whenNotPaused {
        paused = true;
        Pause();
      }
    
      /**
       * @dev called by the owner to unpause, returns to normal state
       */
      function unpause() public onlyOwner whenPaused {
        paused = false;
        Unpause();
      }
    }
    
    
    contract Controlled {
        /// @notice The address of the controller is the only address that can call
        ///  a function with this modifier
        modifier onlyController { require(msg.sender == controller); _; }
    
        address public controller;
    
        function Controlled() public { controller = msg.sender;}
    
        /// @notice Changes the controller of the contract
        /// @param _newController The new controller of the contract
        function changeController(address _newController) public onlyController {
            controller = _newController;
        }
    }
    
    
    /// @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(
        address _parentToken,
        uint _snapshotBlock,
        string _tokenName,
        uint8 _decimalUnits,
        string _tokenSymbol,
        bool _transfersEnabled
        ) public returns (MiniMeToken)
        {
            MiniMeToken newToken = new MiniMeToken(
            this,
            _parentToken,
            _snapshotBlock,
            _tokenName,
            _decimalUnits,
            _tokenSymbol,
            _transfersEnabled
            );
    
            newToken.changeController(msg.sender);
            return newToken;
        }
    }
    
    
    /*
        Copyright 2016, Jordi Baylina
    
        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
     */
    
    /// @title MiniMeToken Contract
    /// @author Jordi Baylina
    /// @dev This token contract's goal is to make it easy for anyone to clone this
    ///  token using the token distribution at a given block, this will allow DAO's
    ///  and DApps to upgrade their features in a decentralized manner without
    ///  affecting the original token
    /// @dev It is ERC20 compliant, but still needs to under go further testing.
    /// @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"
    contract MiniMeToken is Controlled {
    
        string public name;                //The Token's name: e.g. DigixDAO Tokens
        uint8 public decimals;             //Number of decimals of the smallest unit
        string public symbol;              //An identifier: e.g. REP
        string public version = "1.0.0"; 
    
        /// @dev `Checkpoint` is the structure that attaches a block number to a
        ///  given value, the block number attached is the one that last changed the
        ///  value
        struct Checkpoint {
    
            // `fromBlock` is the block number that the value was generated from
            uint128 fromBlock;
    
            // `value` is the amount of tokens at a specific block number
            uint128 value;
        }
    
        // `parentToken` is the Token address that was cloned to produce this token;
        //  it will be 0x0 for a token that was not cloned
        MiniMeToken public parentToken;
    
        // `parentSnapShotBlock` is the block number from the Parent Token that was
        //  used to determine the initial distribution of the Clone Token
        uint public parentSnapShotBlock;
    
        // `creationBlock` is the block number that the Clone Token was created
        uint public creationBlock;
    
        // `balances` is the map that tracks the balance of each address, in this
        //  contract when the balance changes the block number that the change
        //  occurred is also included in the map
        mapping (address => Checkpoint[]) balances;
    
        // `allowed` tracks any extra transfer rights as in all ERC20 tokens
        mapping (address => mapping (address => uint256)) allowed;
    
        // Tracks the history of the `totalSupply` of the token
        Checkpoint[] totalSupplyHistory;
    
        // Flag that determines if the token is transferable or not.
        bool public transfersEnabled;
    
        // The factory used to create new clone tokens
        MiniMeTokenFactory public tokenFactory;
    
    ////////////////
    // Constructor
    ////////////////
    
        /// @notice Constructor to create a MiniMeToken
        /// @param _tokenFactory The address of the MiniMeTokenFactory contract that
        ///  will create the Clone token contracts, the token factory needs to be
        ///  deployed first
        /// @param _parentToken Address of the parent token, set to 0x0 if it is a
        ///  new token
        /// @param _parentSnapShotBlock Block of the parent token that will
        ///  determine the initial distribution of the clone token, set to 0 if it
        ///  is a new 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
        function MiniMeToken(
            address _tokenFactory,
            address _parentToken,
            uint _parentSnapShotBlock,
            string _tokenName,
            uint8 _decimalUnits,
            string _tokenSymbol,
            bool _transfersEnabled
        ) public 
        {
            tokenFactory = MiniMeTokenFactory(_tokenFactory);
            name = _tokenName;                                 // Set the name
            decimals = _decimalUnits;                          // Set the decimals
            symbol = _tokenSymbol;                             // Set the symbol
            parentToken = MiniMeToken(_parentToken);
            parentSnapShotBlock = _parentSnapShotBlock;
            transfersEnabled = _transfersEnabled;
            creationBlock = block.number;
        }
    
    
    ///////////////////
    // ERC20 Methods
    ///////////////////
    
        /// @notice Send `_amount` tokens to `_to` from `msg.sender`
        /// @param _to The address of the recipient
        /// @param _amount The amount of tokens to be transferred
        /// @return Whether the transfer was successful or not
        function transfer(address _to, uint256 _amount) public returns (bool success) {
            require(transfersEnabled);
            return doTransfer(msg.sender, _to, _amount);
        }
    
        /// @notice Send `_amount` tokens to `_to` from `_from` on the condition it
        ///  is approved by `_from`
        /// @param _from The address holding the tokens being transferred
        /// @param _to The address of the recipient
        /// @param _amount The amount of tokens to be transferred
        /// @return True if the transfer was successful
        function transferFrom(address _from, address _to, uint256 _amount) 
            public returns (bool success) 
            {
            // The controller of this contract can move tokens around at will,
            //  this is important to recognize! Confirm that you trust the
            //  controller of this contract, which in most situations should be
            //  another open source smart contract or 0x0
            if (msg.sender != controller) {
                require(transfersEnabled);
    
                // The standard ERC 20 transferFrom functionality
                if (allowed[_from][msg.sender] < _amount) {
                    return false;
                }
                allowed[_from][msg.sender] -= _amount;
            }
            return doTransfer(_from, _to, _amount);
        }
    
        /// @dev This is the actual transfer function in the token contract, it can
        ///  only be called by other functions in this contract.
        /// @param _from The address holding the tokens being transferred
        /// @param _to The address of the recipient
        /// @param _amount The amount of tokens to be transferred
        /// @return True if the transfer was successful
        function doTransfer(address _from, address _to, uint _amount
        ) internal returns(bool) 
        {
    
               if (_amount == 0) {
                   return true;
               }
    
               require(parentSnapShotBlock < block.number);
    
               // Do not allow transfer to 0x0 or the token contract itself
               require((_to != 0) && (_to != address(this)));
    
               // If the amount being transfered is more than the balance of the
               //  account the transfer returns false
               var previousBalanceFrom = balanceOfAt(_from, block.number);
               if (previousBalanceFrom < _amount) {
                   return false;
               }
    
               // Alerts the token controller of the transfer
               if (isContract(controller)) {
                   require(TokenController(controller).onTransfer(_from, _to, _amount));
               }
    
               // First update the balance array with the new value for the address
               //  sending the tokens
               updateValueAtNow(balances[_from], previousBalanceFrom - _amount);
    
               // Then update the balance array with the new value for the address
               //  receiving the tokens
               var previousBalanceTo = balanceOfAt(_to, block.number);
               require(previousBalanceTo + _amount >= previousBalanceTo); // Check for overflow
               updateValueAtNow(balances[_to], previousBalanceTo + _amount);
    
               // An event to make the transfer easy to find on the blockchain
               Transfer(_from, _to, _amount);
    
               return true;
        }
    
        /// @param _owner The address that's balance is being requested
        /// @return The balance of `_owner` at the current block
        function balanceOf(address _owner) public constant returns (uint256 balance) {
            return balanceOfAt(_owner, block.number);
        }
    
        /// @notice `msg.sender` approves `_spender` to spend `_amount` tokens on
        ///  its behalf. This is a modified version of the ERC20 approve function
        ///  to be a little bit safer
        /// @param _spender The address of the account able to transfer the tokens
        /// @param _amount The amount of tokens to be approved for transfer
        /// @return True if the approval was successful
        function approve(address _spender, uint256 _amount) public returns (bool success) {
            require(transfersEnabled);
    
            // To change the approve amount you first have to reduce the addresses`
            //  allowance to zero by calling `approve(_spender,0)` if it is not
            //  already 0 to mitigate the race condition described here:
            //  https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
            require((_amount == 0) || (allowed[msg.sender][_spender] == 0));
            return doApprove(_spender, _amount);
        }
    
        function doApprove(address _spender, uint256 _amount) internal returns (bool success) {
            require(transfersEnabled);
            if (isContract(controller)) {
                require(TokenController(controller).onApprove(msg.sender, _spender, _amount));
            }
            allowed[msg.sender][_spender] = _amount;
            Approval(msg.sender, _spender, _amount);
            return true;
        }
    
        /// @dev This function makes it easy to read the `allowed[]` map
        /// @param _owner The address of the account that owns the token
        /// @param _spender The address of the account able to transfer the tokens
        /// @return Amount of remaining tokens of _owner that _spender is allowed
        ///  to spend
        function allowance(address _owner, address _spender
        ) public constant returns (uint256 remaining) 
        {
            return allowed[_owner][_spender];
        }
    
        /// @notice `msg.sender` approves `_spender` to send `_amount` tokens on
        ///  its behalf, and then a function is triggered in the contract that is
        ///  being approved, `_spender`. This allows users to use their tokens to
        ///  interact with contracts in one function call instead of two
        /// @param _spender The address of the contract able to transfer the tokens
        /// @param _amount The amount of tokens to be approved for transfer
        /// @return True if the function call was successful
        function approveAndCall(address _spender, uint256 _amount, bytes _extraData
        ) public returns (bool success) 
        {
            require(approve(_spender, _amount));
    
            ApproveAndCallFallBack(_spender).receiveApproval(
                msg.sender,
                _amount,
                this,
                _extraData
            );
    
            return true;
        }
    
        /// @dev This function makes it easy to get the total number of tokens
        /// @return The total number of tokens
        function totalSupply() public constant returns (uint) {
            return totalSupplyAt(block.number);
        }
    
    
    ////////////////
    // Query balance and totalSupply in History
    ////////////////
    
        /// @dev Queries the balance of `_owner` at a specific `_blockNumber`
        /// @param _owner The address from which the balance will be retrieved
        /// @param _blockNumber The block number when the balance is queried
        /// @return The balance at `_blockNumber`
        function balanceOfAt(address _owner, uint _blockNumber) public constant
            returns (uint) 
        {
            // These next few lines are used when the balance of the token is
            //  requested before a check point was ever created for this token, it
            //  requires that the `parentToken.balanceOfAt` be queried at the
            //  genesis block for that token as this contains initial balance of
            //  this token
            if ((balances[_owner].length == 0) || (balances[_owner][0].fromBlock > _blockNumber)) {
                if (address(parentToken) != 0) {
                    return parentToken.balanceOfAt(_owner, min(_blockNumber, parentSnapShotBlock));
                } else {
                    // Has no parent
                    return 0;
                }
    
            // This will return the expected balance during normal situations
            } else {
                return getValueAt(balances[_owner], _blockNumber);
            }
        }
    
        /// @notice Total amount of tokens at a specific `_blockNumber`.
        /// @param _blockNumber The block number when the totalSupply is queried
        /// @return The total amount of tokens at `_blockNumber`
        function totalSupplyAt(uint _blockNumber) public constant returns(uint) {
    
            // These next few lines are used when the totalSupply of the token is
            //  requested before a check point was ever created for this token, it
            //  requires that the `parentToken.totalSupplyAt` be queried at the
            //  genesis block for this token as that contains totalSupply of this
            //  token at this block number.
            if ((totalSupplyHistory.length == 0) || (totalSupplyHistory[0].fromBlock > _blockNumber)) {
                if (address(parentToken) != 0) {
                    return parentToken.totalSupplyAt(min(_blockNumber, parentSnapShotBlock));
                } else {
                    return 0;
                }
    
            // This will return the expected totalSupply during normal situations
            } else {
                return getValueAt(totalSupplyHistory, _blockNumber);
            }
        }
    
    ////////////////
    // Clone Token Method
    ////////////////
    
        /// @notice Creates a new clone token with the initial distribution being
        ///  this token at `_snapshotBlock`
        /// @param _cloneTokenName Name of the clone token
        /// @param _cloneDecimalUnits Number of decimals of the smallest unit
        /// @param _cloneTokenSymbol Symbol of the clone token
        /// @param _snapshotBlock Block when the distribution of the parent token is
        ///  copied to set the initial distribution of the new clone token;
        ///  if the block is zero than the actual block, the current block is used
        /// @param _transfersEnabled True if transfers are allowed in the clone
        /// @return The address of the new MiniMeToken Contract
        function createCloneToken(
            string _cloneTokenName,
            uint8 _cloneDecimalUnits,
            string _cloneTokenSymbol,
            uint _snapshotBlock,
            bool _transfersEnabled
            ) public returns(address) 
        {
            if (_snapshotBlock == 0) {
                _snapshotBlock = block.number;
            }
    
            MiniMeToken cloneToken = tokenFactory.createCloneToken(
                this,
                _snapshotBlock,
                _cloneTokenName,
                _cloneDecimalUnits,
                _cloneTokenSymbol,
                _transfersEnabled
                );
    
            cloneToken.changeController(msg.sender);
    
            // An event to make the token easy to find on the blockchain
            NewCloneToken(address(cloneToken), _snapshotBlock);
            return address(cloneToken);
        }
    
    ////////////////
    // Generate and destroy tokens
    ////////////////
    
        /// @notice Generates `_amount` tokens that are assigned to `_owner`
        /// @param _owner The address that will be assigned the new tokens
        /// @param _amount The quantity of tokens generated
        /// @return True if the tokens are generated correctly
        function generateTokens(address _owner, uint _amount) 
            public onlyController returns (bool) 
        {
            uint curTotalSupply = totalSupply();
            require(curTotalSupply + _amount >= curTotalSupply); // Check for overflow
            uint previousBalanceTo = balanceOf(_owner);
            require(previousBalanceTo + _amount >= previousBalanceTo); // Check for overflow
            updateValueAtNow(totalSupplyHistory, curTotalSupply + _amount);
            updateValueAtNow(balances[_owner], previousBalanceTo + _amount);
            Transfer(0, _owner, _amount);
            return true;
        }
    
    
        /// @notice Burns `_amount` tokens from `_owner`
        /// @param _owner The address that will lose the tokens
        /// @param _amount The quantity of tokens to burn
        /// @return True if the tokens are burned correctly
        function destroyTokens(address _owner, uint _amount
        ) onlyController public returns (bool) 
        {
            uint curTotalSupply = totalSupply();
            require(curTotalSupply >= _amount);
            uint previousBalanceFrom = balanceOf(_owner);
            require(previousBalanceFrom >= _amount);
            updateValueAtNow(totalSupplyHistory, curTotalSupply - _amount);
            updateValueAtNow(balances[_owner], previousBalanceFrom - _amount);
            Transfer(_owner, 0, _amount);
            return true;
        }
    
    ////////////////
    // Enable tokens transfers
    ////////////////
    
    
        /// @notice Enables token holders to transfer their tokens freely if true
        /// @param _transfersEnabled True if transfers are allowed in the clone
        function enableTransfers(bool _transfersEnabled) public onlyController {
            transfersEnabled = _transfersEnabled;
        }
    
    ////////////////
    // Internal helper functions to query and set a value in a snapshot array
    ////////////////
    
        /// @dev `getValueAt` retrieves the number of tokens at a given block number
        /// @param checkpoints The history of values being queried
        /// @param _block The block number to retrieve the value at
        /// @return The number of tokens being queried
        function getValueAt(Checkpoint[] storage checkpoints, uint _block) 
            constant internal returns (uint) 
        {
            if (checkpoints.length == 0) {
                return 0;
            }
    
            // Shortcut for the actual value
            if (_block >= checkpoints[checkpoints.length-1].fromBlock) {
                return checkpoints[checkpoints.length-1].value;
            }
                
            if (_block < checkpoints[0].fromBlock) {
                return 0;
            }
    
            // Binary search of the value in the array
            uint min = 0;
            uint max = checkpoints.length - 1;
            while (max > min) {
                uint mid = (max + min + 1) / 2;
                if (checkpoints[mid].fromBlock<=_block) {
                    min = mid;
                } else {
                    max = mid-1;
                }
            }
            return checkpoints[min].value;
        }
    
        /// @dev `updateValueAtNow` used to update the `balances` map and the
        ///  `totalSupplyHistory`
        /// @param checkpoints The history of data being updated
        /// @param _value The new number of tokens
        function updateValueAtNow(Checkpoint[] storage checkpoints, uint _value
        ) internal  
        {
            if ((checkpoints.length == 0) || (checkpoints[checkpoints.length-1].fromBlock < block.number)) {
                   Checkpoint storage newCheckPoint = checkpoints[checkpoints.length++];
                   newCheckPoint.fromBlock = uint128(block.number);
                   newCheckPoint.value = uint128(_value);
               } else {
                   Checkpoint storage oldCheckPoint = checkpoints[checkpoints.length-1];
                   oldCheckPoint.value = uint128(_value);
               }
        }
    
        /// @dev Internal function to determine if an address is a contract
        /// @param _addr The address being queried
        /// @return True if `_addr` is a contract
        function isContract(address _addr) constant internal returns(bool) {
            uint size;
            if (_addr == 0) {
                return false;
            }
            assembly {
                size := extcodesize(_addr)
            }
            return size>0;
        }
    
        /// @dev Helper function to return a min betwen the two uints
        function min(uint a, uint b) pure internal returns (uint) {
            return a < b ? a : b;
        }
    
        /// @notice The fallback function: If the contract's controller has not been
        ///  set to 0, then the `proxyPayment` method is called which relays the
        ///  ether and creates tokens as described in the token controller contract
        function () public payable {
            require(isContract(controller));
            require(TokenController(controller).proxyPayment.value(msg.value)(msg.sender));
        }
    
    //////////
    // Safety Methods
    //////////
    
        /// @notice This method can be used by the controller to extract mistakenly
        ///  sent tokens to this contract.
        /// @param _token The address of the token contract that you want to recover
        ///  set to 0 in case you want to extract ether.
        function claimTokens(address _token) public onlyController {
            if (_token == 0x0) {
                controller.transfer(this.balance);
                return;
            }
    
            MiniMeToken token = MiniMeToken(_token);
            uint balance = token.balanceOf(this);
            token.transfer(controller, balance);
            ClaimedTokens(_token, controller, balance);
        }
    
    ////////////////
    // Events
    ////////////////
        event ClaimedTokens(address indexed _token, address indexed _controller, uint _amount);
        event Transfer(address indexed _from, address indexed _to, uint256 _amount);
        event NewCloneToken(address indexed _cloneToken, uint _snapshotBlock);
        event Approval(
            address indexed _owner,
            address indexed _spender,
            uint256 _amount
            );
    
    }
    
    
    
    /// @dev The token controller contract must implement these functions
    contract TokenController {
      /// @notice Called when `_owner` sends ether to the MiniMe Token contract
      /// @param _owner The address that sent the ether to create tokens
      /// @return True if the ether is accepted, false if it throws
      function proxyPayment(address _owner) public payable returns(bool);
    
      /// @notice Notifies the controller about a token transfer allowing the
      ///  controller to react if desired
      /// @param _from The origin of the transfer
      /// @param _to The destination of the transfer
      /// @param _amount The amount of the transfer
      /// @return False if the controller does not authorize the transfer
      function onTransfer(address _from, address _to, uint _amount) public returns(bool);
    
      /// @notice Notifies the controller about an approval allowing the
      ///  controller to react if desired
      /// @param _owner The address that calls `approve()`
      /// @param _spender The spender in the `approve()` call
      /// @param _amount The amount in the `approve()` call
      /// @return False if the controller does not authorize the approval
      function onApprove(address _owner, address _spender, uint _amount)
      public
      returns(bool);
    }
    
    
    
    contract FundRequestTokenGeneration is Pausable, TokenController {
        using SafeMath for uint256;
    
        MiniMeToken public tokenContract;
    
        address public tokensaleWallet;
    
        address public founderWallet;
    
        uint public rate;
    
        mapping (address => uint) public deposits;
    
        mapping (address => Countries) public allowed;
    
        uint public maxCap;         // In wei
        uint256 public totalCollected;         // In wei
    
        // personal caps and activations
        bool public personalCapActive = true;
    
        uint256 public personalCap;
    
        //country whitelisting
        enum Countries {NOT_WHITELISTED, CHINA, KOREA, USA, OTHER}
        mapping (uint => bool) public allowedCountries;
    
        //events
        event Paid(address indexed _beneficiary, uint256 _weiAmount, uint256 _tokenAmount, bool _personalCapActive);
    
        function FundRequestTokenGeneration(
        address _tokenAddress,
        address _founderWallet,
        address _tokensaleWallet,
        uint _rate,
        uint _maxCap,
        uint256 _personalCap) public
        {
            tokenContract = MiniMeToken(_tokenAddress);
            tokensaleWallet = _tokensaleWallet;
            founderWallet = _founderWallet;
    
            rate = _rate;
            maxCap = _maxCap;
            personalCap = _personalCap;
    
            allowedCountries[uint(Countries.CHINA)] = true;
            allowedCountries[uint(Countries.KOREA)] = true;
            allowedCountries[uint(Countries.USA)] = true;
            allowedCountries[uint(Countries.OTHER)] = true;
        }
    
        function() public payable whenNotPaused {
            doPayment(msg.sender);
        }
    
        /// @notice `proxyPayment()` allows the caller to send ether to the Campaign and
        /// have the tokens created in an address of their choosing
        /// @param _owner The address that will hold the newly created tokens
    
        function proxyPayment(address _owner) public payable whenNotPaused returns (bool) {
            doPayment(_owner);
            return true;
        }
    
        function doPayment(address beneficiary) whenNotPaused internal {
            require(validPurchase(beneficiary));
            require(maxCapNotReached());
            require(personalCapNotReached(beneficiary));
            uint256 weiAmount = msg.value;
            uint256 updatedWeiRaised = totalCollected.add(weiAmount);
            uint256 tokensInWei = weiAmount.mul(rate);
            totalCollected = updatedWeiRaised;
            deposits[beneficiary] = deposits[beneficiary].add(msg.value);
            distributeTokens(beneficiary, tokensInWei);
            Paid(beneficiary, weiAmount, tokensInWei, personalCapActive);
            forwardFunds();
            return;
        }
    
        function allocateTokens(address beneficiary, uint256 tokensSold) public onlyOwner {
            distributeTokens(beneficiary, tokensSold);
        }
    
        function finalizeTokenSale() public onlyOwner {
            pause();
            tokenContract.changeController(owner);
        }
    
        function distributeTokens(address beneficiary, uint256 tokensSold) internal {
            uint256 totalTokensInWei = tokensSold.mul(100).div(40);
            require(tokenContract.generateTokens(beneficiary, tokensSold));
            require(generateExtraTokens(totalTokensInWei, tokensaleWallet, 60));
        }
    
        function validPurchase(address beneficiary) internal view returns (bool) {
            require(tokenContract.controller() != 0);
            require(msg.value >= 0.01 ether);
    
            Countries beneficiaryCountry = allowed[beneficiary];
    
            /* the country needs to > 0 (whitelisted) */
            require(uint(beneficiaryCountry) > uint(Countries.NOT_WHITELISTED));
    
            /* country needs to be allowed */
            require(allowedCountries[uint(beneficiaryCountry)] == true);
            return true;
        }
    
        function generateExtraTokens(uint256 _total, address _owner, uint _pct) internal returns (bool) {
            uint256 tokensInWei = _total.div(100).mul(_pct);
            require(tokenContract.generateTokens(_owner, tokensInWei));
            return true;
        }
    
        function allow(address beneficiary, Countries _country) public onlyOwner {
            allowed[beneficiary] = _country;
        }
    
        function allowMultiple(address[] _beneficiaries, Countries _country) public onlyOwner {
            for (uint b = 0; b < _beneficiaries.length; b++) {
                allow(_beneficiaries[b], _country);
            }
        }
    
        function allowCountry(Countries _country, bool _allowed) public onlyOwner {
            require(uint(_country) > 0);
            allowedCountries[uint(_country)] = _allowed;
        }
    
        function maxCapNotReached() internal view returns (bool) {
            return totalCollected.add(msg.value) <= maxCap;
        }
    
        function personalCapNotReached(address _beneficiary) internal view returns (bool) {
            if (personalCapActive) {
                return deposits[_beneficiary].add(msg.value) <= personalCap;
            }
            else {
                return true;
            }
        }
    
        function setMaxCap(uint _maxCap) public onlyOwner {
            maxCap = _maxCap;
        }
    
        /* setters for wallets */
        function setTokensaleWallet(address _tokensaleWallet) public onlyOwner {
            tokensaleWallet = _tokensaleWallet;
        }
    
        function setFounderWallet(address _founderWallet) public onlyOwner {
            founderWallet = _founderWallet;
        }
    
    
        function setPersonalCap(uint256 _capInWei) public onlyOwner {
            personalCap = _capInWei;
        }
    
        function setPersonalCapActive(bool _active) public onlyOwner {
            personalCapActive = _active;
        }
    
        function forwardFunds() internal {
            founderWallet.transfer(msg.value);
        }
    
        /* fix for accidental token sending */
        function withdrawToken(address _token, uint256 _amount) public onlyOwner {
            require(MiniMeToken(_token).transfer(owner, _amount));
        }
    
        //incase something does a suicide and funds end up here, we need to be able to withdraw them
        function withdraw(address _to) public onlyOwner {
            _to.transfer(this.balance);
        }
    
        function onTransfer(address _from, address _to, uint _amount) public returns (bool) {
            return true;
        }
    
        function onApprove(address _owner, address _spender, uint _amount) public returns (bool) {
            return true;
        }
    }

    File 2 of 3: FundRequestToken
    pragma solidity ^0.4.18;
    
    // FundRequest Token
    //
    // @authors:
    // Davy Van Roy <[email protected]>
    // Quinten De Swaef <[email protected]>
    //
    // Security audit performed by LeastAuthority:
    // https://github.com/FundRequest/audit-reports/raw/master/2018-02-06 - Least Authority - ICO Contracts Audit Report.pdf
    
    contract ApproveAndCallFallBack {
        function receiveApproval(address from, uint256 _amount, address _token, bytes _data) public;
    }
    
    contract Controlled {
        /// @notice The address of the controller is the only address that can call
        ///  a function with this modifier
        modifier onlyController { require(msg.sender == controller); _; }
    
        address public controller;
    
        function Controlled() public { controller = msg.sender;}
    
        /// @notice Changes the controller of the contract
        /// @param _newController The new controller of the contract
        function changeController(address _newController) public onlyController {
            controller = _newController;
        }
    }
    
    
    /// @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(
        address _parentToken,
        uint _snapshotBlock,
        string _tokenName,
        uint8 _decimalUnits,
        string _tokenSymbol,
        bool _transfersEnabled
        ) public returns (MiniMeToken)
        {
            MiniMeToken newToken = new MiniMeToken(
            this,
            _parentToken,
            _snapshotBlock,
            _tokenName,
            _decimalUnits,
            _tokenSymbol,
            _transfersEnabled
            );
    
            newToken.changeController(msg.sender);
            return newToken;
        }
    }
    
    /*
        Copyright 2016, Jordi Baylina
    
        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
     */
    
    /// @title MiniMeToken Contract
    /// @author Jordi Baylina
    /// @dev This token contract's goal is to make it easy for anyone to clone this
    ///  token using the token distribution at a given block, this will allow DAO's
    ///  and DApps to upgrade their features in a decentralized manner without
    ///  affecting the original token
    /// @dev It is ERC20 compliant, but still needs to under go further testing.
    /// @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"
    contract MiniMeToken is Controlled {
    
        string public name;                //The Token's name: e.g. DigixDAO Tokens
        uint8 public decimals;             //Number of decimals of the smallest unit
        string public symbol;              //An identifier: e.g. REP
        string public version = "1.0.0"; 
    
        /// @dev `Checkpoint` is the structure that attaches a block number to a
        ///  given value, the block number attached is the one that last changed the
        ///  value
        struct Checkpoint {
    
            // `fromBlock` is the block number that the value was generated from
            uint128 fromBlock;
    
            // `value` is the amount of tokens at a specific block number
            uint128 value;
        }
    
        // `parentToken` is the Token address that was cloned to produce this token;
        //  it will be 0x0 for a token that was not cloned
        MiniMeToken public parentToken;
    
        // `parentSnapShotBlock` is the block number from the Parent Token that was
        //  used to determine the initial distribution of the Clone Token
        uint public parentSnapShotBlock;
    
        // `creationBlock` is the block number that the Clone Token was created
        uint public creationBlock;
    
        // `balances` is the map that tracks the balance of each address, in this
        //  contract when the balance changes the block number that the change
        //  occurred is also included in the map
        mapping (address => Checkpoint[]) balances;
    
        // `allowed` tracks any extra transfer rights as in all ERC20 tokens
        mapping (address => mapping (address => uint256)) allowed;
    
        // Tracks the history of the `totalSupply` of the token
        Checkpoint[] totalSupplyHistory;
    
        // Flag that determines if the token is transferable or not.
        bool public transfersEnabled;
    
        // The factory used to create new clone tokens
        MiniMeTokenFactory public tokenFactory;
    
    ////////////////
    // Constructor
    ////////////////
    
        /// @notice Constructor to create a MiniMeToken
        /// @param _tokenFactory The address of the MiniMeTokenFactory contract that
        ///  will create the Clone token contracts, the token factory needs to be
        ///  deployed first
        /// @param _parentToken Address of the parent token, set to 0x0 if it is a
        ///  new token
        /// @param _parentSnapShotBlock Block of the parent token that will
        ///  determine the initial distribution of the clone token, set to 0 if it
        ///  is a new 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
        function MiniMeToken(
            address _tokenFactory,
            address _parentToken,
            uint _parentSnapShotBlock,
            string _tokenName,
            uint8 _decimalUnits,
            string _tokenSymbol,
            bool _transfersEnabled
        ) public 
        {
            tokenFactory = MiniMeTokenFactory(_tokenFactory);
            name = _tokenName;                                 // Set the name
            decimals = _decimalUnits;                          // Set the decimals
            symbol = _tokenSymbol;                             // Set the symbol
            parentToken = MiniMeToken(_parentToken);
            parentSnapShotBlock = _parentSnapShotBlock;
            transfersEnabled = _transfersEnabled;
            creationBlock = block.number;
        }
    
    
    ///////////////////
    // ERC20 Methods
    ///////////////////
    
        /// @notice Send `_amount` tokens to `_to` from `msg.sender`
        /// @param _to The address of the recipient
        /// @param _amount The amount of tokens to be transferred
        /// @return Whether the transfer was successful or not
        function transfer(address _to, uint256 _amount) public returns (bool success) {
            require(transfersEnabled);
            return doTransfer(msg.sender, _to, _amount);
        }
    
        /// @notice Send `_amount` tokens to `_to` from `_from` on the condition it
        ///  is approved by `_from`
        /// @param _from The address holding the tokens being transferred
        /// @param _to The address of the recipient
        /// @param _amount The amount of tokens to be transferred
        /// @return True if the transfer was successful
        function transferFrom(address _from, address _to, uint256 _amount) 
            public returns (bool success) 
            {
            // The controller of this contract can move tokens around at will,
            //  this is important to recognize! Confirm that you trust the
            //  controller of this contract, which in most situations should be
            //  another open source smart contract or 0x0
            if (msg.sender != controller) {
                require(transfersEnabled);
    
                // The standard ERC 20 transferFrom functionality
                if (allowed[_from][msg.sender] < _amount) {
                    return false;
                }
                allowed[_from][msg.sender] -= _amount;
            }
            return doTransfer(_from, _to, _amount);
        }
    
        /// @dev This is the actual transfer function in the token contract, it can
        ///  only be called by other functions in this contract.
        /// @param _from The address holding the tokens being transferred
        /// @param _to The address of the recipient
        /// @param _amount The amount of tokens to be transferred
        /// @return True if the transfer was successful
        function doTransfer(address _from, address _to, uint _amount
        ) internal returns(bool) 
        {
    
               if (_amount == 0) {
                   return true;
               }
    
               require(parentSnapShotBlock < block.number);
    
               // Do not allow transfer to 0x0 or the token contract itself
               require((_to != 0) && (_to != address(this)));
    
               // If the amount being transfered is more than the balance of the
               //  account the transfer returns false
               var previousBalanceFrom = balanceOfAt(_from, block.number);
               if (previousBalanceFrom < _amount) {
                   return false;
               }
    
               // Alerts the token controller of the transfer
               if (isContract(controller)) {
                   require(TokenController(controller).onTransfer(_from, _to, _amount));
               }
    
               // First update the balance array with the new value for the address
               //  sending the tokens
               updateValueAtNow(balances[_from], previousBalanceFrom - _amount);
    
               // Then update the balance array with the new value for the address
               //  receiving the tokens
               var previousBalanceTo = balanceOfAt(_to, block.number);
               require(previousBalanceTo + _amount >= previousBalanceTo); // Check for overflow
               updateValueAtNow(balances[_to], previousBalanceTo + _amount);
    
               // An event to make the transfer easy to find on the blockchain
               Transfer(_from, _to, _amount);
    
               return true;
        }
    
        /// @param _owner The address that's balance is being requested
        /// @return The balance of `_owner` at the current block
        function balanceOf(address _owner) public constant returns (uint256 balance) {
            return balanceOfAt(_owner, block.number);
        }
    
        /// @notice `msg.sender` approves `_spender` to spend `_amount` tokens on
        ///  its behalf. This is a modified version of the ERC20 approve function
        ///  to be a little bit safer
        /// @param _spender The address of the account able to transfer the tokens
        /// @param _amount The amount of tokens to be approved for transfer
        /// @return True if the approval was successful
        function approve(address _spender, uint256 _amount) public returns (bool success) {
            require(transfersEnabled);
    
            // To change the approve amount you first have to reduce the addresses`
            //  allowance to zero by calling `approve(_spender,0)` if it is not
            //  already 0 to mitigate the race condition described here:
            //  https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
            require((_amount == 0) || (allowed[msg.sender][_spender] == 0));
            return doApprove(_spender, _amount);
        }
    
        function doApprove(address _spender, uint256 _amount) internal returns (bool success) {
            require(transfersEnabled);
            if (isContract(controller)) {
                require(TokenController(controller).onApprove(msg.sender, _spender, _amount));
            }
            allowed[msg.sender][_spender] = _amount;
            Approval(msg.sender, _spender, _amount);
            return true;
        }
    
        /// @dev This function makes it easy to read the `allowed[]` map
        /// @param _owner The address of the account that owns the token
        /// @param _spender The address of the account able to transfer the tokens
        /// @return Amount of remaining tokens of _owner that _spender is allowed
        ///  to spend
        function allowance(address _owner, address _spender
        ) public constant returns (uint256 remaining) 
        {
            return allowed[_owner][_spender];
        }
    
        /// @notice `msg.sender` approves `_spender` to send `_amount` tokens on
        ///  its behalf, and then a function is triggered in the contract that is
        ///  being approved, `_spender`. This allows users to use their tokens to
        ///  interact with contracts in one function call instead of two
        /// @param _spender The address of the contract able to transfer the tokens
        /// @param _amount The amount of tokens to be approved for transfer
        /// @return True if the function call was successful
        function approveAndCall(address _spender, uint256 _amount, bytes _extraData
        ) public returns (bool success) 
        {
            require(approve(_spender, _amount));
    
            ApproveAndCallFallBack(_spender).receiveApproval(
                msg.sender,
                _amount,
                this,
                _extraData
            );
    
            return true;
        }
    
        /// @dev This function makes it easy to get the total number of tokens
        /// @return The total number of tokens
        function totalSupply() public constant returns (uint) {
            return totalSupplyAt(block.number);
        }
    
    
    ////////////////
    // Query balance and totalSupply in History
    ////////////////
    
        /// @dev Queries the balance of `_owner` at a specific `_blockNumber`
        /// @param _owner The address from which the balance will be retrieved
        /// @param _blockNumber The block number when the balance is queried
        /// @return The balance at `_blockNumber`
        function balanceOfAt(address _owner, uint _blockNumber) public constant
            returns (uint) 
        {
            // These next few lines are used when the balance of the token is
            //  requested before a check point was ever created for this token, it
            //  requires that the `parentToken.balanceOfAt` be queried at the
            //  genesis block for that token as this contains initial balance of
            //  this token
            if ((balances[_owner].length == 0) || (balances[_owner][0].fromBlock > _blockNumber)) {
                if (address(parentToken) != 0) {
                    return parentToken.balanceOfAt(_owner, min(_blockNumber, parentSnapShotBlock));
                } else {
                    // Has no parent
                    return 0;
                }
    
            // This will return the expected balance during normal situations
            } else {
                return getValueAt(balances[_owner], _blockNumber);
            }
        }
    
        /// @notice Total amount of tokens at a specific `_blockNumber`.
        /// @param _blockNumber The block number when the totalSupply is queried
        /// @return The total amount of tokens at `_blockNumber`
        function totalSupplyAt(uint _blockNumber) public constant returns(uint) {
    
            // These next few lines are used when the totalSupply of the token is
            //  requested before a check point was ever created for this token, it
            //  requires that the `parentToken.totalSupplyAt` be queried at the
            //  genesis block for this token as that contains totalSupply of this
            //  token at this block number.
            if ((totalSupplyHistory.length == 0) || (totalSupplyHistory[0].fromBlock > _blockNumber)) {
                if (address(parentToken) != 0) {
                    return parentToken.totalSupplyAt(min(_blockNumber, parentSnapShotBlock));
                } else {
                    return 0;
                }
    
            // This will return the expected totalSupply during normal situations
            } else {
                return getValueAt(totalSupplyHistory, _blockNumber);
            }
        }
    
    ////////////////
    // Clone Token Method
    ////////////////
    
        /// @notice Creates a new clone token with the initial distribution being
        ///  this token at `_snapshotBlock`
        /// @param _cloneTokenName Name of the clone token
        /// @param _cloneDecimalUnits Number of decimals of the smallest unit
        /// @param _cloneTokenSymbol Symbol of the clone token
        /// @param _snapshotBlock Block when the distribution of the parent token is
        ///  copied to set the initial distribution of the new clone token;
        ///  if the block is zero than the actual block, the current block is used
        /// @param _transfersEnabled True if transfers are allowed in the clone
        /// @return The address of the new MiniMeToken Contract
        function createCloneToken(
            string _cloneTokenName,
            uint8 _cloneDecimalUnits,
            string _cloneTokenSymbol,
            uint _snapshotBlock,
            bool _transfersEnabled
            ) public returns(address) 
        {
            if (_snapshotBlock == 0) {
                _snapshotBlock = block.number;
            }
    
            MiniMeToken cloneToken = tokenFactory.createCloneToken(
                this,
                _snapshotBlock,
                _cloneTokenName,
                _cloneDecimalUnits,
                _cloneTokenSymbol,
                _transfersEnabled
                );
    
            cloneToken.changeController(msg.sender);
    
            // An event to make the token easy to find on the blockchain
            NewCloneToken(address(cloneToken), _snapshotBlock);
            return address(cloneToken);
        }
    
    ////////////////
    // Generate and destroy tokens
    ////////////////
    
        /// @notice Generates `_amount` tokens that are assigned to `_owner`
        /// @param _owner The address that will be assigned the new tokens
        /// @param _amount The quantity of tokens generated
        /// @return True if the tokens are generated correctly
        function generateTokens(address _owner, uint _amount) 
            public onlyController returns (bool) 
        {
            uint curTotalSupply = totalSupply();
            require(curTotalSupply + _amount >= curTotalSupply); // Check for overflow
            uint previousBalanceTo = balanceOf(_owner);
            require(previousBalanceTo + _amount >= previousBalanceTo); // Check for overflow
            updateValueAtNow(totalSupplyHistory, curTotalSupply + _amount);
            updateValueAtNow(balances[_owner], previousBalanceTo + _amount);
            Transfer(0, _owner, _amount);
            return true;
        }
    
    
        /// @notice Burns `_amount` tokens from `_owner`
        /// @param _owner The address that will lose the tokens
        /// @param _amount The quantity of tokens to burn
        /// @return True if the tokens are burned correctly
        function destroyTokens(address _owner, uint _amount
        ) onlyController public returns (bool) 
        {
            uint curTotalSupply = totalSupply();
            require(curTotalSupply >= _amount);
            uint previousBalanceFrom = balanceOf(_owner);
            require(previousBalanceFrom >= _amount);
            updateValueAtNow(totalSupplyHistory, curTotalSupply - _amount);
            updateValueAtNow(balances[_owner], previousBalanceFrom - _amount);
            Transfer(_owner, 0, _amount);
            return true;
        }
    
    ////////////////
    // Enable tokens transfers
    ////////////////
    
    
        /// @notice Enables token holders to transfer their tokens freely if true
        /// @param _transfersEnabled True if transfers are allowed in the clone
        function enableTransfers(bool _transfersEnabled) public onlyController {
            transfersEnabled = _transfersEnabled;
        }
    
    ////////////////
    // Internal helper functions to query and set a value in a snapshot array
    ////////////////
    
        /// @dev `getValueAt` retrieves the number of tokens at a given block number
        /// @param checkpoints The history of values being queried
        /// @param _block The block number to retrieve the value at
        /// @return The number of tokens being queried
        function getValueAt(Checkpoint[] storage checkpoints, uint _block) 
            constant internal returns (uint) 
        {
            if (checkpoints.length == 0) {
                return 0;
            }
    
            // Shortcut for the actual value
            if (_block >= checkpoints[checkpoints.length-1].fromBlock) {
                return checkpoints[checkpoints.length-1].value;
            }
                
            if (_block < checkpoints[0].fromBlock) {
                return 0;
            }
    
            // Binary search of the value in the array
            uint min = 0;
            uint max = checkpoints.length - 1;
            while (max > min) {
                uint mid = (max + min + 1) / 2;
                if (checkpoints[mid].fromBlock<=_block) {
                    min = mid;
                } else {
                    max = mid-1;
                }
            }
            return checkpoints[min].value;
        }
    
        /// @dev `updateValueAtNow` used to update the `balances` map and the
        ///  `totalSupplyHistory`
        /// @param checkpoints The history of data being updated
        /// @param _value The new number of tokens
        function updateValueAtNow(Checkpoint[] storage checkpoints, uint _value
        ) internal  
        {
            if ((checkpoints.length == 0) || (checkpoints[checkpoints.length-1].fromBlock < block.number)) {
                   Checkpoint storage newCheckPoint = checkpoints[checkpoints.length++];
                   newCheckPoint.fromBlock = uint128(block.number);
                   newCheckPoint.value = uint128(_value);
               } else {
                   Checkpoint storage oldCheckPoint = checkpoints[checkpoints.length-1];
                   oldCheckPoint.value = uint128(_value);
               }
        }
    
        /// @dev Internal function to determine if an address is a contract
        /// @param _addr The address being queried
        /// @return True if `_addr` is a contract
        function isContract(address _addr) constant internal returns(bool) {
            uint size;
            if (_addr == 0) {
                return false;
            }
            assembly {
                size := extcodesize(_addr)
            }
            return size>0;
        }
    
        /// @dev Helper function to return a min betwen the two uints
        function min(uint a, uint b) pure internal returns (uint) {
            return a < b ? a : b;
        }
    
        /// @notice The fallback function: If the contract's controller has not been
        ///  set to 0, then the `proxyPayment` method is called which relays the
        ///  ether and creates tokens as described in the token controller contract
        function () public payable {
            require(isContract(controller));
            require(TokenController(controller).proxyPayment.value(msg.value)(msg.sender));
        }
    
    //////////
    // Safety Methods
    //////////
    
        /// @notice This method can be used by the controller to extract mistakenly
        ///  sent tokens to this contract.
        /// @param _token The address of the token contract that you want to recover
        ///  set to 0 in case you want to extract ether.
        function claimTokens(address _token) public onlyController {
            if (_token == 0x0) {
                controller.transfer(this.balance);
                return;
            }
    
            MiniMeToken token = MiniMeToken(_token);
            uint balance = token.balanceOf(this);
            token.transfer(controller, balance);
            ClaimedTokens(_token, controller, balance);
        }
    
    ////////////////
    // Events
    ////////////////
        event ClaimedTokens(address indexed _token, address indexed _controller, uint _amount);
        event Transfer(address indexed _from, address indexed _to, uint256 _amount);
        event NewCloneToken(address indexed _cloneToken, uint _snapshotBlock);
        event Approval(
            address indexed _owner,
            address indexed _spender,
            uint256 _amount
            );
    
    }
    
    /// @dev The token controller contract must implement these functions
    contract TokenController {
        /// @notice Called when `_owner` sends ether to the MiniMe Token contract
        /// @param _owner The address that sent the ether to create tokens
        /// @return True if the ether is accepted, false if it throws
        function proxyPayment(address _owner) public payable returns(bool);
    
        /// @notice Notifies the controller about a token transfer allowing the
        ///  controller to react if desired
        /// @param _from The origin of the transfer
        /// @param _to The destination of the transfer
        /// @param _amount The amount of the transfer
        /// @return False if the controller does not authorize the transfer
        function onTransfer(address _from, address _to, uint _amount) public returns(bool);
    
        /// @notice Notifies the controller about an approval allowing the
        ///  controller to react if desired
        /// @param _owner The address that calls `approve()`
        /// @param _spender The spender in the `approve()` call
        /// @param _amount The amount in the `approve()` call
        /// @return False if the controller does not authorize the approval
        function onApprove(address _owner, address _spender, uint _amount)
        public
        returns(bool);
    }
    
    // FundRequest Token
    //
    // @authors:
    // Davy Van Roy <[email protected]>
    // Quinten De Swaef <[email protected]>
    //
    // Security audit performed by LeastAuthority:
    // https://github.com/FundRequest/audit-reports/raw/master/2018-02-06 - Least Authority - ICO Contracts Audit Report.pdf
    contract FundRequestToken is MiniMeToken {
    
      function FundRequestToken(
        address _tokenFactory,
        address _parentToken, 
        uint _parentSnapShotBlock, 
        string _tokenName, 
        uint8 _decimalUnits, 
        string _tokenSymbol, 
        bool _transfersEnabled) 
        public 
        MiniMeToken(
          _tokenFactory,
          _parentToken, 
          _parentSnapShotBlock, 
          _tokenName, 
          _decimalUnits, 
          _tokenSymbol, 
          _transfersEnabled) 
      {
        //constructor
      }
    
      function safeApprove(address _spender, uint256 _currentValue, uint256 _amount) public returns (bool success) {
        require(allowed[msg.sender][_spender] == _currentValue);
        return doApprove(_spender, _amount);
      }
    
      function isFundRequestToken() public pure returns (bool) {
        return true;
      }
    }

    File 3 of 3: Wallet
    //sol Wallet
    // Multi-sig, daily-limited account proxy/wallet.
    // @authors:
    // Gav Wood <[email protected]>
    // inheritable "property" contract that enables methods to be protected by requiring the acquiescence of either a
    // single, or, crucially, each of a number of, designated owners.
    // usage:
    // use modifiers onlyowner (just own owned) or onlymanyowners(hash), whereby the same hash must be provided by
    // some number (specified in constructor) of the set of owners (specified in the constructor, modifiable) before the
    // interior is executed.
    contract multiowned {
    
        // TYPES
    
        // struct for the status of a pending operation.
        struct PendingState {
            uint yetNeeded;
            uint ownersDone;
            uint index;
        }
    
        // EVENTS
    
        // this contract only has five types of events: it can accept a confirmation, in which case
        // we record owner and operation (hash) alongside it.
        event Confirmation(address owner, bytes32 operation);
        event Revoke(address owner, bytes32 operation);
        // some others are in the case of an owner changing.
        event OwnerChanged(address oldOwner, address newOwner);
        event OwnerAdded(address newOwner);
        event OwnerRemoved(address oldOwner);
        // the last one is emitted if the required signatures change
        event RequirementChanged(uint newRequirement);
    
        // MODIFIERS
    
        // simple single-sig function modifier.
        modifier onlyowner {
            if (isOwner(msg.sender))
                _
        }
        // multi-sig function modifier: the operation must have an intrinsic hash in order
        // that later attempts can be realised as the same underlying operation and
        // thus count as confirmations.
        modifier onlymanyowners(bytes32 _operation) {
            if (confirmAndCheck(_operation))
                _
        }
    
        // METHODS
    
        // constructor is given number of sigs required to do protected "onlymanyowners" transactions
        // as well as the selection of addresses capable of confirming them.
        function multiowned(address[] _owners, uint _required) {
            m_numOwners = _owners.length + 1;
            m_owners[1] = uint(msg.sender);
            m_ownerIndex[uint(msg.sender)] = 1;
            for (uint i = 0; i < _owners.length; ++i)
            {
                m_owners[2 + i] = uint(_owners[i]);
                m_ownerIndex[uint(_owners[i])] = 2 + i;
            }
            m_required = _required;
        }
        
        // Revokes a prior confirmation of the given operation
        function revoke(bytes32 _operation) external {
            uint ownerIndex = m_ownerIndex[uint(msg.sender)];
            // make sure they're an owner
            if (ownerIndex == 0) return;
            uint ownerIndexBit = 2**ownerIndex;
            var pending = m_pending[_operation];
            if (pending.ownersDone & ownerIndexBit > 0) {
                pending.yetNeeded++;
                pending.ownersDone -= ownerIndexBit;
                Revoke(msg.sender, _operation);
            }
        }
        
        // Replaces an owner `_from` with another `_to`.
        function changeOwner(address _from, address _to) onlymanyowners(sha3(msg.data, block.number)) external {
            if (isOwner(_to)) return;
            uint ownerIndex = m_ownerIndex[uint(_from)];
            if (ownerIndex == 0) return;
    
            clearPending();
            m_owners[ownerIndex] = uint(_to);
            m_ownerIndex[uint(_from)] = 0;
            m_ownerIndex[uint(_to)] = ownerIndex;
            OwnerChanged(_from, _to);
        }
        
        function addOwner(address _owner) onlymanyowners(sha3(msg.data, block.number)) external {
            if (isOwner(_owner)) return;
    
            clearPending();
            if (m_numOwners >= c_maxOwners)
                reorganizeOwners();
            if (m_numOwners >= c_maxOwners)
                return;
            m_numOwners++;
            m_owners[m_numOwners] = uint(_owner);
            m_ownerIndex[uint(_owner)] = m_numOwners;
            OwnerAdded(_owner);
        }
        
        function removeOwner(address _owner) onlymanyowners(sha3(msg.data, block.number)) external {
            uint ownerIndex = m_ownerIndex[uint(_owner)];
            if (ownerIndex == 0) return;
            if (m_required > m_numOwners - 1) return;
    
            m_owners[ownerIndex] = 0;
            m_ownerIndex[uint(_owner)] = 0;
            clearPending();
            reorganizeOwners(); //make sure m_numOwner is equal to the number of owners and always points to the optimal free slot
            OwnerRemoved(_owner);
        }
        
        function changeRequirement(uint _newRequired) onlymanyowners(sha3(msg.data, block.number)) external {
            if (_newRequired > m_numOwners) return;
            m_required = _newRequired;
            clearPending();
            RequirementChanged(_newRequired);
        }
        
        function isOwner(address _addr) returns (bool) {
            return m_ownerIndex[uint(_addr)] > 0;
        }
        
        function hasConfirmed(bytes32 _operation, address _owner) constant returns (bool) {
            var pending = m_pending[_operation];
            uint ownerIndex = m_ownerIndex[uint(_owner)];
    
            // make sure they're an owner
            if (ownerIndex == 0) return false;
    
            // determine the bit to set for this owner.
            uint ownerIndexBit = 2**ownerIndex;
            if (pending.ownersDone & ownerIndexBit == 0) {
                return false;
            } else {
                return true;
            }
        }
        
        // INTERNAL METHODS
    
        function confirmAndCheck(bytes32 _operation) internal returns (bool) {
            // determine what index the present sender is:
            uint ownerIndex = m_ownerIndex[uint(msg.sender)];
            // make sure they're an owner
            if (ownerIndex == 0) return;
    
            var pending = m_pending[_operation];
            // if we're not yet working on this operation, switch over and reset the confirmation status.
            if (pending.yetNeeded == 0) {
                // reset count of confirmations needed.
                pending.yetNeeded = m_required;
                // reset which owners have confirmed (none) - set our bitmap to 0.
                pending.ownersDone = 0;
                pending.index = m_pendingIndex.length++;
                m_pendingIndex[pending.index] = _operation;
            }
            // determine the bit to set for this owner.
            uint ownerIndexBit = 2**ownerIndex;
            // make sure we (the message sender) haven't confirmed this operation previously.
            if (pending.ownersDone & ownerIndexBit == 0) {
                Confirmation(msg.sender, _operation);
                // ok - check if count is enough to go ahead.
                if (pending.yetNeeded <= 1) {
                    // enough confirmations: reset and run interior.
                    delete m_pendingIndex[m_pending[_operation].index];
                    delete m_pending[_operation];
                    return true;
                }
                else
                {
                    // not enough: record that this owner in particular confirmed.
                    pending.yetNeeded--;
                    pending.ownersDone |= ownerIndexBit;
                }
            }
        }
    
        function reorganizeOwners() private returns (bool) {
            uint free = 1;
            while (free < m_numOwners)
            {
                while (free < m_numOwners && m_owners[free] != 0) free++;
                while (m_numOwners > 1 && m_owners[m_numOwners] == 0) m_numOwners--;
                if (free < m_numOwners && m_owners[m_numOwners] != 0 && m_owners[free] == 0)
                {
                    m_owners[free] = m_owners[m_numOwners];
                    m_ownerIndex[m_owners[free]] = free;
                    m_owners[m_numOwners] = 0;
                }
            }
        }
        
        function clearPending() internal {
            uint length = m_pendingIndex.length;
            for (uint i = 0; i < length; ++i)
                if (m_pendingIndex[i] != 0)
                    delete m_pending[m_pendingIndex[i]];
            delete m_pendingIndex;
        }
            
        // FIELDS
    
        // the number of owners that must confirm the same operation before it is run.
        uint public m_required;
        // pointer used to find a free slot in m_owners
        uint public m_numOwners;
        
        // list of owners
        uint[256] m_owners;
        uint constant c_maxOwners = 250;
        // index on the list of owners to allow reverse lookup
        mapping(uint => uint) m_ownerIndex;
        // the ongoing operations.
        mapping(bytes32 => PendingState) m_pending;
        bytes32[] m_pendingIndex;
    }
    
    // inheritable "property" contract that enables methods to be protected by placing a linear limit (specifiable)
    // on a particular resource per calendar day. is multiowned to allow the limit to be altered. resource that method
    // uses is specified in the modifier.
    contract daylimit is multiowned {
    
        // MODIFIERS
    
        // simple modifier for daily limit.
        modifier limitedDaily(uint _value) {
            if (underLimit(_value))
                _
        }
    
        // METHODS
    
        // constructor - stores initial daily limit and records the present day's index.
        function daylimit(uint _limit) {
            m_dailyLimit = _limit;
            m_lastDay = today();
        }
        // (re)sets the daily limit. needs many of the owners to confirm. doesn't alter the amount already spent today.
        function setDailyLimit(uint _newLimit) onlymanyowners(sha3(msg.data, block.number)) external {
            m_dailyLimit = _newLimit;
        }
        // (re)sets the daily limit. needs many of the owners to confirm. doesn't alter the amount already spent today.
        function resetSpentToday() onlymanyowners(sha3(msg.data, block.number)) external {
            m_spentToday = 0;
        }
        
        // INTERNAL METHODS
        
        // checks to see if there is at least `_value` left from the daily limit today. if there is, subtracts it and
        // returns true. otherwise just returns false.
        function underLimit(uint _value) internal onlyowner returns (bool) {
            // reset the spend limit if we're on a different day to last time.
            if (today() > m_lastDay) {
                m_spentToday = 0;
                m_lastDay = today();
            }
            // check to see if there's enough left - if so, subtract and return true.
            if (m_spentToday + _value >= m_spentToday && m_spentToday + _value <= m_dailyLimit) {
                m_spentToday += _value;
                return true;
            }
            return false;
        }
        // determines today's index.
        function today() private constant returns (uint) { return now / 1 days; }
    
        // FIELDS
    
        uint public m_dailyLimit;
        uint public m_spentToday;
        uint public m_lastDay;
    }
    
    // interface contract for multisig proxy contracts; see below for docs.
    contract multisig {
    
        // EVENTS
    
        // logged events:
        // Funds has arrived into the wallet (record how much).
        event Deposit(address from, uint value);
        // Single transaction going out of the wallet (record who signed for it, how much, and to whom it's going).
        event SingleTransact(address owner, uint value, address to, bytes data);
        // Multi-sig transaction going out of the wallet (record who signed for it last, the operation hash, how much, and to whom it's going).
        event MultiTransact(address owner, bytes32 operation, uint value, address to, bytes data);
        // Confirmation still needed for a transaction.
        event ConfirmationNeeded(bytes32 operation, address initiator, uint value, address to, bytes data);
        
        // FUNCTIONS
        
        // TODO: document
        function changeOwner(address _from, address _to) external;
        function execute(address _to, uint _value, bytes _data) external returns (bytes32);
        function confirm(bytes32 _h) returns (bool);
    }
    
    // usage:
    // bytes32 h = Wallet(w).from(oneOwner).transact(to, value, data);
    // Wallet(w).from(anotherOwner).confirm(h);
    contract Wallet is multisig, multiowned, daylimit {
    
        uint public version = 2;
    
        // TYPES
    
        // Transaction structure to remember details of transaction lest it need be saved for a later call.
        struct Transaction {
            address to;
            uint value;
            bytes data;
        }
    
        // METHODS
    
        // constructor - just pass on the owner array to the multiowned and
        // the limit to daylimit
        function Wallet(address[] _owners, uint _required, uint _daylimit)
                multiowned(_owners, _required) daylimit(_daylimit) {
        }
        
        // kills the contract sending everything to `_to`.
        function kill(address _to) onlymanyowners(sha3(msg.data, block.number)) external {
            suicide(_to);
        }
        
        // gets called when no other function matches
        function() {
            // just being sent some cash?
            if (msg.value > 0)
                Deposit(msg.sender, msg.value);
        }
        
        // Outside-visible transact entry point. Executes transacion immediately if below daily spend limit.
        // If not, goes into multisig process. We provide a hash on return to allow the sender to provide
        // shortcuts for the other confirmations (allowing them to avoid replicating the _to, _value
        // and _data arguments). They still get the option of using them if they want, anyways.
        function execute(address _to, uint _value, bytes _data) external onlyowner returns (bytes32 _r) {
            // first, take the opportunity to check that we're under the daily limit.
            if (underLimit(_value)) {
                SingleTransact(msg.sender, _value, _to, _data);
                // yes - just execute the call.
                _to.call.value(_value)(_data);
                return 0;
            }
            // determine our operation hash.
            _r = sha3(msg.data, block.number);
            if (!confirm(_r) && m_txs[_r].to == 0) {
                m_txs[_r].to = _to;
                m_txs[_r].value = _value;
                m_txs[_r].data = _data;
                ConfirmationNeeded(_r, msg.sender, _value, _to, _data);
            }
        }
        
        // confirm a transaction through just the hash. we use the previous transactions map, m_txs, in order
        // to determine the body of the transaction from the hash provided.
        function confirm(bytes32 _h) onlymanyowners(_h) returns (bool) {
            if (m_txs[_h].to != 0) {
                m_txs[_h].to.call.value(m_txs[_h].value)(m_txs[_h].data);
                MultiTransact(msg.sender, _h, m_txs[_h].value, m_txs[_h].to, m_txs[_h].data);
                delete m_txs[_h];
                return true;
            }
        }
        
        // INTERNAL METHODS
        
        function clearPending() internal {
            uint length = m_pendingIndex.length;
            for (uint i = 0; i < length; ++i)
                delete m_txs[m_pendingIndex[i]];
            super.clearPending();
        }
    
        // FIELDS
    
        // pending transactions we have at present.
        mapping (bytes32 => Transaction) m_txs;
    }