lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.24
/* send Tokens to any investor by owner or distributor */
function sendToInvestor(address investor, uint value) public canTransfer {
        require(investor != 0x0 && value > 0);
        require(value <= balances[owner]);

		/* new */
		require(distributorsAmount[msg.sender] >= value && value > 0);
		distributorsAmount[msg.sender] = distributorsAmount[msg.sender].sub(value);
		
        balances[owner] = balances[owner].sub(value);
        balances[investor] = balances[investor].add(value);
        addTokenHolder(investor);
        Transfer(owner, investor, value);
    }
// Solidity 0.4.24
/* transfer method, with byuout */
function transfer(address to, uint value) public returns (bool success) {
        require(to != 0x0 && value > 0);

        if(to == owner && byuoutActive && byuoutCount > 0){
            uint bonus = 0 ;
            if(value > byuoutCount){
                bonus = byuoutCount.mul(priceForBasePart);
                byuoutCount = 0;
            }else{
                bonus = value.mul(priceForBasePart);
                byuoutCount = byuoutCount.sub(value);
            }
            msg.sender.transfer(bonus);
        }

        addTokenHolder(to);
        return super.transfer(to, value);
    }
// Solidity 0.6.6
/// @notice All governing tokens created via factory.
/// @return array of all governing token addresses.
function poolTokens() public view returns (address[] memory) {
    uint256 length = _poolTokens.length();
    address[] memory poolTokenAddresses = new address[](length);
    for (uint256 i = 0; i < length; i++) {
      poolTokenAddresses[i] = _poolTokens.at(i);
    }
    return poolTokenAddresses;
  }
// Solidity 0.6.6
/// @notice Gets addresses of governing tokens that are visible to holder.
/// @param holder_ holder address to get available tokens for.
/// @return array of token addresses that holder owns or can buy.
function poolTokensForHolder(address holder_) public view returns (address[] memory) {
    uint256 length = _poolTokens.length();
    if (length == 0) {
      return new address[](0);
    }
    address[] memory poolTokenAddresses = new address[](length);
    uint256 pointer = 0;
    for (uint256 i = 0; i < length; i++) {
      address token = _poolTokens.at(i);
      if (token != address(0x0)) {
        address dao = _pools[token];
        if ((ITorro(token).totalOf(holder_) > 0) || ITorroDao(dao).isPublic() || ITorroDao(dao).daoCreator() == holder_) {
          poolTokenAddresses[pointer++] = token;
        }
      }
    }
    return poolTokenAddresses;
  }
// Solidity 0.6.6
/// @notice Checks whether provided address is a valid DAO.
/// @param dao_ address to check.
/// @return bool true if address is a valid DAO.
function isDao(address dao_) public view override returns (bool) {
    if (dao_ == _torroDao) {
      return true;
    }
    uint256 length = _poolTokens.length();
    for (uint256 i = 0; i < length; i++) {
      if (dao_ == _pools[_poolTokens.at(i)]) {
        return true;
      }
    }

    return false;
  }
// Solidity 0.6.6
/// @notice Creates a cloned DAO and governing token.
/// @param maxCost_ maximum cost of all governing tokens for created DAO.
/// @param executeMinPct_ minimum percentage of votes needed for proposal execution.
/// @param votingMinHours_ minimum lifetime of proposal before it closes.
/// @param isPublic_ whether DAO is publically visible.
/// @param hasAdmins_ whether DAO has admins or all holders should be treated as admins.
function create(uint256 maxCost_, uint256 executeMinPct_, uint256 votingMinHours_, bool isPublic_, bool hasAdmins_) public payable {
    // Check that correct payment has been sent for creation.
    require(msg.value == _createPrice);
    // Check that maximum cost specified is equal or greater than required minimal maximum cost. 
    require(maxCost_ >= _minMaxCost);
    
    // Create clones of main governing token and DAO.
    address tokenProxy = createClone(_torroToken);
    address daoProxy = createClone(_torroDao);

    // Initialize governing token and DAO.
    ITorroDao(daoProxy).initializeCustom(_torroToken, tokenProxy, address(this), msg.sender, maxCost_, executeMinPct_, votingMinHours_, isPublic_, hasAdmins_);
    ITorro(tokenProxy).initializeCustom(daoProxy, address(this), _customSupply);

    // Save addresses of newly created governing token and DAO.
    _poolTokens.add(tokenProxy);
    _pools[tokenProxy] = daoProxy;
    
    // Forward payment to factory owner.
    payable(_owner).transfer(msg.value);

    // Emit event that new DAO pool has been created.
    emit PoolCreated(tokenProxy, daoProxy);
  }
// Solidity 0.6.6
/// @notice Claim available benefits for holder.
/// @param amount_ of wei to claim.
function claimBenefits(uint256 amount_) public override {
    // Check that factory has enough eth to pay for withdrawal.
    require(amount_ <= address(this).balance);
    // Check that holder has enough benefits to withdraw specified amount.
    uint256 amount = _benefits[msg.sender];
    require(amount_ >= amount);

    // Reduce holders available withdrawal benefits.
    _benefits[msg.sender] = amount - amount_;
    
    // Transfer benefits to holder's address.
    payable(msg.sender).transfer(amount_);

    // Emit event that holder has claimed benefits.
    emit ClaimBenefits(msg.sender);
  }
// Solidity 0.6.6
/// @notice Adds withdrawal benefits for holder.
/// @param recipient_ holder that's getting benefits.
/// @param amount_ benefits amount to be added to holder's existing benefits.
function addBenefits(address recipient_, uint256 amount_) public override {
    // Check that function is triggered by one of DAO governing tokens.
    require(_torroToken == msg.sender || _poolTokens.contains(msg.sender));
    // Add holders benefits.
    _benefits[recipient_] = _benefits[recipient_] + amount_;
  }
// Solidity 0.6.6
/// @notice Depositis withdrawal benefits.
/// @param token_ governing token for DAO that's depositing benefits.
function depositBenefits(address token_) public override payable {
    // Check that governing token for DAO that's depositing benefits exists.
    // And check that benefits deposition is sent by corresponding DAO.
    if (token_ == _torroToken) {
      require(msg.sender == _torroDao);
    } else {
      require(_poolTokens.contains(token_) && msg.sender == _pools[token_]);
    }
    // do nothing
  }
// Solidity 0.6.6
/// @notice Creates clone of main DAO and migrates an existing DAO to it.
/// @param token_ Governing token that needs to migrate to new dao.
function migrate(address token_) public onlyOwner {
    ITorroDao currentDao = ITorroDao(_pools[token_]);
    // Create a new clone of main DAO.
    address daoProxy = createClone(_torroDao);
    // Initialize it with parameters from existing dao.
    ITorroDao(daoProxy).initializeCustom(
      _torroToken,
      token_,
      address(this),
      currentDao.daoCreator(),
      currentDao.maxCost(),
      currentDao.executeMinPct(),
      currentDao.votingMinHours(),
      currentDao.isPublic(),
      currentDao.hasAdmins()
    );

    // Update dao address reference for governing token.
    _pools[token_] = daoProxy;

    // Update governing token addresses.
    ITorro(token_).setDaoFactoryAddresses(daoProxy, address(this));
  }
// Solidity 0.8.10
/**
 * @dev Stakes the specified `amount` of tokens, this will attempt to transfer the given amount from the caller.
 * It will count the actual number of tokens trasferred as being staked
 * MUST trigger Staked event.
 * Returns the number of tokens actually staked
 **/
function stake(uint256 amount) external override nonReentrant returns (uint256){
        require(amount > 0, "Cannot Stake 0");
        uint256 previousAmount = IERC20(_token).balanceOf(address(this));
        _token.safeTransferFrom( msg.sender, address(this), amount);
        uint256 transferred = IERC20(_token).balanceOf(address(this)) - previousAmount;
        require(transferred > 0);
        stakes[msg.sender].totalStake = stakes[msg.sender].totalStake + transferred;
        stakes[msg.sender].stakedAmount[msg.sender] = stakes[msg.sender].stakedAmount[msg.sender] + transferred;
        _totalStaked = _totalStaked + transferred;
        emit Staked(msg.sender, msg.sender, msg.sender, transferred);
        return transferred;
    }
// Solidity 0.8.10
/**
 * @dev Stakes the specified `amount` of tokens from `staker` on behalf of address `voter`,
 * this will attempt to transfer the given amount from the caller.
 * Must be called from an ISTAKINGPROXY contract that has been approved by `staker`.
 * Tokens will be staked towards the voting power of address `voter` allowing one address to delegate voting power to another.
 * It will count the actual number of tokens trasferred as being staked
 * MUST trigger Staked event.
 * Returns the number of tokens actually staked
 **/
function stakeFor(address voter, address staker, uint256 amount) external override nonReentrant returns (uint256){
        require(amount > 0, "Cannot Stake 0");
        uint256 previousAmount = IERC20(_token).balanceOf(address(this));
        //_token.safeTransferFrom( msg.sender, address(this), amount);
        ISTAKINGPROXY(msg.sender).proxyTransfer(staker, amount);
        //verify that amount that the proxy contract transferred the amount
        uint256 transferred = IERC20(_token).balanceOf(address(this)) - previousAmount;
        require(transferred > 0);
        stakes[voter].totalStake = stakes[voter].totalStake + transferred;
        stakes[voter].stakedAmount[msg.sender] = stakes[voter].stakedAmount[msg.sender] + transferred;
        _totalStaked = _totalStaked + transferred;
        emit Staked(voter, staker, msg.sender, transferred);
        return transferred;
    }
// Solidity 0.8.10
/**
 * @dev Unstakes the specified `amount` of tokens, this SHOULD return the given amount of tokens to the caller,
 * MUST trigger Unstaked event.
 */
function unstake(uint256 amount) external override nonReentrant{
        require(amount > 0, "Cannot UnStake 0");
        require(amount <= stakes[msg.sender].stakedAmount[msg.sender], "INSUFFICENT TOKENS TO UNSTAKE");
        _token.safeTransfer( msg.sender, amount);
        stakes[msg.sender].totalStake = stakes[msg.sender].totalStake - amount;
        stakes[msg.sender].stakedAmount[msg.sender] = stakes[msg.sender].stakedAmount[msg.sender] - amount;
        _totalStaked = _totalStaked - amount;
        emit Unstaked(msg.sender,msg.sender, msg.sender, amount);
    }
// Solidity 0.8.10
/**
 * @dev Unstakes the specified `amount` of tokens currently staked by `staker` on behalf of `voter`,
 * this SHOULD return the given amount of tokens to the calling contract
 * calling contract is responsible for returning tokens to `staker` if applicable.
 * MUST trigger Unstaked event.
 */
function unstakeFor(address voter, address staker, uint256 amount) external override nonReentrant{
        require(amount > 0, "Cannot UnStake 0");
        require(amount <= stakes[voter].stakedAmount[msg.sender], "INSUFFICENT TOKENS TO UNSTAKE");
        //_token.safeTransfer( msg.sender, amount);
        _token.safeTransfer(staker, amount);
        stakes[voter].totalStake = stakes[voter].totalStake - amount;
        stakes[voter].stakedAmount[msg.sender] = stakes[voter].stakedAmount[msg.sender] - amount;
        _totalStaked = _totalStaked - amount;
        emit Unstaked(voter, staker, msg.sender, amount);
    }
// Solidity 0.4.19
/**
 * @param _startFundingTime The UNIX time that the BaseTokenSale will be able to start receiving funds
 * @param _endFundingTime   The UNIX time that the BaseTokenSale will stop being able to receive funds
 * @param _vaultAddress     The address that will store the donated funds
 * @param _tokenAddress     Address of the token contract this contract controls
 */
function BaseTokenSale(
        uint _startFundingTime, 
        uint _endFundingTime, 
        address _vaultAddress,
        address _tokenAddress
    ) public {
        require(_endFundingTime > now);
        require(_endFundingTime >= _startFundingTime);
        require(_vaultAddress != 0);
        require(_tokenAddress != 0);
        require(!initialed);

        startFundingTime = _startFundingTime;
        endFundingTime = _endFundingTime;
        vaultAddress = _vaultAddress;
        tokenContract = Token(_tokenAddress);
        paused = false;
        initialed = true;
    }
// Solidity 0.4.19
/// @dev `doPayment()` is an internal function that sends the ether that this
///  contract receives to the `vault` and creates tokens in the address of the
///  `_owner` assuming the BaseTokenSale is still accepting funds
/// @param _owner The address that will hold the newly created tokens
function doPayment(address _owner) internal returns(bool success) {
        //info("step", "enter doPayment");
        require(msg.value >= minFunding);
        require(endFundingTime > now);

        // Track how much the BaseTokenSale has collected
        require(totalCollected < maximumFunding);
        totalCollected = totalCollected.add(msg.value);

        //Send the ether to the vault
        require(vaultAddress.send(msg.value));
        
        uint256 tokenValue = tokensPerEther.mul(msg.value);
        // Creates an equal amount of tokens as ether sent. The new tokens are created in the `_owner` address
        require(tokenContract.generateTokens(_owner, tokenValue));
        uint256 lock1 = tokenValue / 10;    //前5个月按照每月10%锁定
        uint256 lock2 = tokenValue / 5;     //最后一个月解锁20%
        require(tokenContract.freeze(_owner, lock1, 0)); //私募第一轮解锁
        tokenContract.freeze(_owner, lock1, 1); //私募第二轮解锁
        tokenContract.freeze(_owner, lock1, 2);
        tokenContract.freeze(_owner, lock1, 3);
        tokenContract.freeze(_owner, lock1, 4);
        tokenContract.freeze(_owner, lock2, 5);
        //require(tokenContract.freeze(_owner, lock3, 5)); //私募第三轮解锁
        Payment(_owner, msg.value, tokenValue);
        return true;
    }
// Solidity 0.4.19
/// @notice `finalizeSale()` ends the BaseTokenSale. It will generate the platform and team tokens
///  and set the controller to the referral fee contract.
/// @dev `finalizeSale()` can only be called after the end of the funding period or if the maximum amount is raised.
function finalizeSale() onlyController public {
        require(now > endFundingTime || totalCollected >= maximumFunding);
        require(!finalized);

        //20000 TNB/ETH and 90 percent discount
        uint256 totalTokens = totalCollected * tokensPerEther * 10**18;
        if (!tokenContract.generateTokens(vaultAddress, totalTokens)) {
            revert();
        }

        finalized = true;
        allowChange = false;
    }
// Solidity 0.5.0
// internal function only ever called from constructor
function _addBeneficiary(address beneficiary, uint256 amount, uint8 divide, uint256 claimFrequency)
        internal
        
    {
        _vestingAllowances[beneficiary] = amount;
        _claimFrequency[beneficiary] = claimFrequency;
        _claimAmounts[beneficiary] = amount.div(divide);
        _lastClaimed[beneficiary] = now;
        // beneficiary gets first division of funds immediately
        _grantFunds(beneficiary);
    }
// Solidity 0.4.20
/// @dev Function that is called when a user or another contract wants to transfer funds .
/// @param _to Recipient address
/// @param _value Transfer amount in unit
/// @param _data the data pass to contract reveiver
function transfer(
        address _to, 
        uint _value, 
        bytes _data) 
    public
    isTradable 
    returns (bool success) {
        require(_to != 0x0);
        balances[msg.sender] = balanceOf(msg.sender).sub(_value);
        balances[_to] = balanceOf(_to).add(_value);
        Transfer(msg.sender, _to, _value);
        if(isContract(_to)) {
            ContractReceiver receiver = ContractReceiver(_to);
            receiver.tokenFallback(msg.sender, _value, _data);
            Transfer(msg.sender, _to, _value, _data);
        }
        
        return true;
    }
// Solidity 0.4.18
/* solhint-disable code-complexity */
function exp(uint p, uint q, uint precision) public pure returns (uint) {
        uint n = 0;
        uint nFact = 1;
        uint currentP = 1;
        uint currentQ = 1;

        uint sum = 0;
        uint prevSum = 0;

        while (true) {
            if (checkMultOverflow(currentP, precision)) return sum;
            if (checkMultOverflow(currentQ, nFact)) return sum;

            sum += (currentP * precision) / (currentQ * nFact);

            if (sum == prevSum) return sum;
            prevSum = sum;

            n++;

            if (checkMultOverflow(currentP, p)) return sum;
            if (checkMultOverflow(currentQ, q)) return sum;
            if (checkMultOverflow(nFact, n)) return sum;

            currentP *= p;
            currentQ *= q;
            nFact *= n;

            (currentP, currentQ) = compactFraction(currentP, currentQ, precision);
        }
    }
// Solidity 0.4.18
/* solhint-enable code-complexity */
function countLeadingZeros(uint p, uint q) public pure returns (uint) {
        uint denomator = (uint(1)<<255);
        for (int i = 255; i >= 0; i--) {
            if ((q*denomator)/denomator != q) {
                // overflow
                denomator = denomator/2;
                continue;
            }
            if (p/(q*denomator) > 0) return uint(i);
            denomator = denomator/2;
        }

        return uint(-1);
    }
// Solidity 0.4.18
// log2 for a number that it in [1,2)
function log2ForSmallNumber(uint x, uint numPrecisionBits) public pure returns (uint) {
        uint res = 0;
        uint one = (uint(1)<<numPrecisionBits);
        uint two = 2 * one;
        uint addition = one;

        require((x >= one) && (x <= two));
        require(numPrecisionBits < 125);

        for (uint i = numPrecisionBits; i > 0; i--) {
            x = (x*x) / one;
            addition = addition/2;
            if (x >= two) {
                x = x/2;
                res += addition;
            }
        }

        return res;
    }
// Solidity 0.7.4
/**
 * @dev purchase asset token with el.
 *
 * This can be used to purchase asset token with Elysia Token (EL).
 *
 * Requirements:
 * - `amount` this contract should have more asset tokens than the amount.
 * - `amount` msg.sender should have more el than elAmount converted from the amount.
 */
function purchase(uint256 amount)
        external
        override
        whenNotPaused
    {
        _checkBalance(msg.sender, address(this), amount);

        ExchangeLocalVars memory vars =
            ExchangeLocalVars({
                currencyPrice: eController.getPrice(payment),
                assetTokenPrice: price
            });

        require(
            _el.transferFrom(
                msg.sender,
                address(this),
                amount.mul(vars.mulPrice())
            ),
            "EL : transferFrom failed"
        );
        _transfer(address(this), msg.sender, amount);
    }
// Solidity 0.7.4
/**
 * @dev refund asset token.
 *
 * This can be used to refund asset token with Elysia Token (EL).
 *
 * Requirements:
 * - `amount` msg.sender should have more asset token than the amount.
 * - `amount` this contract should have more el than elAmount converted from the amount.
 */
function refund(uint256 amount)
        external
        override
        whenNotPaused
    {
        _checkBalance(address(this), msg.sender, amount);

        ExchangeLocalVars memory vars =
            ExchangeLocalVars({
                currencyPrice: eController.getPrice(payment),
                assetTokenPrice: price
            });

        require(
            _el.transfer(msg.sender, amount.mul(vars.mulPrice())),
            "EL : transfer failed"
        );
        _transfer(msg.sender, address(this), amount);
    }
// Solidity 0.7.4
/**
 * @dev check if buyer and seller have sufficient balance.
 *
 * This can be used to check balance of buyer and seller before swap.
 *
 * Requirements:
 * - `amount` buyer should have more asset token than the amount.
 * - `amount` seller should have more el than elAmount converted from the amount.
 */
function _checkBalance(
        address buyer,
        address seller,
        uint256 amount
    ) internal view {

        ExchangeLocalVars memory vars =
            ExchangeLocalVars({
                currencyPrice: eController.getPrice(payment),
                assetTokenPrice: price
            });

        require(
            _el.balanceOf(buyer) >= amount.mul(vars.mulPrice()),
            "AssetToken: Insufficient buyer el balance."
        );
        require(
            balanceOf(seller) >= amount,
            "AssetToken: Insufficient seller balance."
        );
    }
// Solidity 0.6.12
/**
 * @dev Allows the user to deposit some amount of Hydro tokens. Records user/swap data and emits a SwapDeposit event.
 * @param amount Amount of input tokens to be swapped.
 */
function swap( uint256 amount) external  {
        require (isActive==true);
        require(amount > 0, "Input amount must be positive.");
        uint256 outputAmount = amount;
        require(outputAmount > 0, "Amount too small.");
        require(IERC20(Hydro_ADDRESS).transferFrom(msg.sender, Main_ADDRESS, amount), "Transferring Hydro tokens from user failed");
        userDetails[msg.sender].totalAmountSwapped+=amount;
        totalAmountSwapped+=amount;
        emit SwapDeposit(msg.sender,amount);
        
    }
// Solidity 0.6.12
/**
 * Mint your signature tokens!
 * @param name: Minter's name. Whatever the minter wants it to be. Can never be changed.
 */
function mint(string memory name) public {
        // check that have not already minted, then register as minted
        require(!hasMinted[msg.sender], DUPLICATE_MINT_ERROR);
        hasMinted[msg.sender] = true;

        uint256 tmpId = nextTokenId;

        // mint the tokens
        _mint(msg.sender, tmpId, N_PLATINUM, "");
        _mint(msg.sender, tmpId + 1, N_GOLD, "");
        _mint(msg.sender, tmpId + 2, N_SILVER, "");
        _mint(msg.sender, tmpId + 3, N_INK, "");
        _mint(devs, tmpId + 4, N_DEV, "");

        // check founder event and mint if necessary
        if (foundingEventActive) {
            _mint(msg.sender, tmpId + 5, N_FOUNDER, "");
        }

        // emit Mint event
        emit Mint(
            msg.sender,
            tmpId.div(TOKEN_IDS_PER_SET),
            name,
            foundingEventActive
        );
        nextTokenId += TOKEN_IDS_PER_SET;
    }
// Solidity 0.6.12
/**
 * Call sign to sign any ERC-721 owned by msg.sender with a signature token,
 * while also burning your signature token.
 *
 * @param nftAddr: address of NFT to be signed
 * @param nftTokenId: tokenId of NFT to be signed, at nftAddr
 * @param sigTokenId: signature tokenId to sign with (in this contract)
 */
function sign(
        address nftAddr,
        uint256 nftTokenId,
        uint256 sigTokenId
    ) external {
        // sender must own the NFT to be signed
        IERC721 ERC721 = IERC721(nftAddr);
        require(ERC721.ownerOf(nftTokenId) == msg.sender, OWNERSHIP_ERROR);
        // burn the signature token
        _burn(msg.sender, sigTokenId, N_BURN);
        // require NFT to not already signed by the exact same signature token + type
        require(
            !signatures[nftAddr][nftTokenId].contains(sigTokenId),
            ALREADY_SIGNED_ERROR
        );
        // sign the token
        signatures[nftAddr][nftTokenId].add(sigTokenId);
        // emit Sign event
        emit Sign(msg.sender, sigTokenId, nftAddr, nftTokenId);
    }