lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.14
/**
 * @dev To buy the next level by User
 * @param _level level wants to buy
 * @param _mrs _mrs[0] - message hash _mrs[1] - r of signature _mrs[2] - s of signature 
 * @param _v  v of signature
 */
function buyLevel(uint256 _level, bytes32[3] calldata _mrs, uint8 _v) external payable {
        require(lockStatus == false, "Contract Locked");
        require(users[msg.sender].isExist, "User not exist");
        require(hashConfirmation[_mrs[0]] == false, "Hash Exits");
        require(_level > 0 && _level <= 9, "Incorrect level");

        if (_level == 1) {
            require(msg.value == LEVEL_PRICE[1], "Incorrect Value");
            users[msg.sender].levelExpired[1] =  users[msg.sender].levelExpired[1].add(PERIOD_LENGTH);
            users[msg.sender].currentLevel = 1;
        }else {
            require(msg.value == LEVEL_PRICE[_level], "Incorrect Value");
            
            users[msg.sender].currentLevel = _level;

            for (uint i =_level - 1; i > 0; i--) require(users[msg.sender].levelExpired[i] >= now, "Buy the previous level");
            
            if(users[msg.sender].levelExpired[_level] == 0)
                users[msg.sender].levelExpired[_level] = now + PERIOD_LENGTH;
            else 
                users[msg.sender].levelExpired[_level] += PERIOD_LENGTH;
        }
       
        loopCheck[msg.sender] = 0;
       
        payForLevels(_level, msg.sender, ((LEVEL_PRICE[_level].mul(adminFee)).div(10**20)), _mrs, _v);
       
        hashConfirmation[_mrs[0]] = true;

        emit buyLevelEvent(msg.sender, _level, now);
    }
// Solidity 0.5.14
/**
 * @dev Internal function
 */
function payForRegister(uint _level,address _userAddress,uint _adminPrice,bytes32[3] memory _mrs,uint8 _v) internal {

        address referer;

        referer = userList[users[_userAddress].referrerID];

        if (!users[referer].isExist) referer = userList[1];

        if (users[referer].levelExpired[_level] >= now) {
            uint256 tobeminted = ((LEVEL_PRICE[_level]).mul(10**3)).div(0.005 ether);
            require((address(uint160(ownerAddress)).send(_adminPrice)) && address(uint160(referer)).send(LEVEL_PRICE[_level].sub(_adminPrice)) && Token.mint(msg.sender,tobeminted,_mrs,_v), "Transaction Failure");
            users[referer].totalEarningEth = users[referer].totalEarningEth.add(LEVEL_PRICE[_level].sub(_adminPrice));
            EarnedEth[referer][_level] =  EarnedEth[referer][_level].add(LEVEL_PRICE[_level].sub(_adminPrice));
        }else {
            emit lostMoneyForLevelEvent(msg.sender,users[msg.sender].id,referer,users[referer].id, _level, LEVEL_PRICE[_level],now);
            revert("Referer Not Active");
        }

    }
// Solidity 0.5.14
/**
 * @dev View free Referrer Address
 */
function findFreeReferrer(address _userAddress) public view returns (address) {
        if (users[_userAddress].referral.length < referrer1Limit) 
            return _userAddress;

        address[] memory referrals = new address[](254);
        referrals[0] = users[_userAddress].referral[0];
        referrals[1] = users[_userAddress].referral[1];

        address freeReferrer;
        bool noFreeReferrer = true;

        for (uint i = 0; i < 254; i++) { 
            if (users[referrals[i]].referral.length == referrer1Limit) {
                if (i < 126) {
                    referrals[(i+1)*2] = users[referrals[i]].referral[0];
                    referrals[(i+1)*2+1] = users[referrals[i]].referral[1];
                }
            } else {
                noFreeReferrer = false;
                freeReferrer = referrals[i];
                break;
            }
        }
        require(!noFreeReferrer, "No Free Referrer");
        return freeReferrer;
    }
// Solidity 0.8.9
// Locks vader and mints xVader
function enter(uint _amount) external nonReentrant {
        // Gets the amount of vader locked in the contract
        uint totalVader = vader.balanceOf(address(this));
        // Gets the amount of xVader in existence
        uint totalShares = totalSupply();

        // If no xVader exists, mint it 1:1 to the amount put in.
        // Calculate and mint the amount of xVader the vader is worth.
        // The ratio will change overtime, as xVader is burned/minted and
        // vader deposited + gained from fees / withdrawn.
        uint xVADERToMint = totalShares == 0 || totalVader == 0
            ? _amount
            : (_amount * totalShares) / totalVader;

        _mint(msg.sender, xVADERToMint);

        // Lock the vader in the contract
        vader.transferFrom(msg.sender, address(this), _amount);
    }
// Solidity 0.8.9
/**
 * @dev Converts an unsigned uint256 into a signed int256.
 *
 * Requirements:
 *
 * - input must be less than or equal to maxInt256.
 */
function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
// Solidity 0.6.12
// Deposit LP tokens to CraneMasterFarmer for Crane allocation.
function deposit(uint256 _pid, uint256 _amount) public {
        require(_amount > 0, "CraneMasterFarmer::deposit: amount must be greater than 0");

        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        updatePool(_pid);
        _harvest(_pid);
        pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);
        if (user.amount == 0) {
            user.rewardDebtAtBlock = block.number;
        }
        user.amount = user.amount.add(_amount);
        user.rewardDebt = user.amount.mul(pool.accCranePerShare).div(1e12);
        emit Deposit(msg.sender, _pid, _amount);
    }
// Solidity 0.6.12
// Withdraw LP tokens from CraneMasterFarmer.
function withdraw(uint256 _pid, uint256 _amount) public {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        require(user.amount >= _amount, "CraneMasterFarmer::withdraw: not good");

        updatePool(_pid);
        _harvest(_pid);
        
        if(_amount > 0) {
            user.amount = user.amount.sub(_amount);
            pool.lpToken.safeTransfer(address(msg.sender), _amount);
        }
        user.rewardDebt = user.amount.mul(pool.accCranePerShare).div(1e12);
        emit Withdraw(msg.sender, _pid, _amount);
    }
// Solidity 0.7.4
/**
 * @dev Returns price after `_bagsCount` will bought
 *.
 * @param _bagsCount - bags that will  bought.
 */
function _nextPrice(uint256 _bagsCount) internal view returns (uint256) {
        //Because last_price expressed in wei we dont need mul(1e18)
        //but still need div(1e4) - see comment above near A and B declaration
        //uint256 _price = last_price.mul(A**_bagsCount).div(10**(4*_bagsCount));
        return bagPrice;
    }
// Solidity 0.8.10
/// @dev Deploys a Proxy account for the given owner
/// @param owner Owner of the Proxy account
/// @return account Address of the deployed Proxy account
/// @notice This deploys a "minimal proxy" contract with the proxy owner address added to the deployed bytecode. The
/// owner address can be read within a delegatecall by using `extcodecopy`. Minimal proxy bytecode is from
/// https://medium.com/coinmonks/the-more-minimal-proxy-5756ae08ee48 and https://eips.ethereum.org/EIPS/eip-1167. It
/// utilizes the "vanity address optimization" from EIP 1167
function deployAccount(address owner) external returns (address account) {
    bytes memory initCode = abi.encodePacked(
      //  [* constructor **] [** minimal proxy ***] [******* implementation *******] [**** minimal proxy *****]
      hex'603c3d8160093d39f3_3d3d3d3d363d3d37363d6f_afcbce78c080f96032a5c1cb1b832d7b_5af43d3d93803e602657fd5bf3',
      owner
    );
    assembly {
      account := create2(0, add(initCode, 0x20), mload(initCode), 0)
    }
    if(account == address(0)) {
      revert DeployFailed();
    }
  }
// Solidity 0.6.12
/**
 * @dev Returns true if `account` is a contract.
 *`isContract` will return false for the following types of addresses:
 *  - an externally-owned account
 *  - a contract in construction
 *  - an address where a contract will be created
 *  - an address where a contract lived, but was destroyed
 */
function isContract(address account) internal view returns (bool) {
        // According to EIP-1052, 0x0 is the value returned for not-yet created accounts
        // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
        // for accounts without code, i.e. `keccak256('')`
        bytes32 codehash;
        bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
        // solhint-disable-next-line no-inline-assembly
        assembly { codehash := extcodehash(account) }
        return (codehash != accountHash && codehash != 0x0);
    }
// Solidity 0.8.9
/**
 * @dev Delegates votes from signer to `delegatee`
 */
function delegateBySig(
        address delegatee,
        uint256 nonce,
        uint256 expiry,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual {
        require(block.timestamp <= expiry, "ERC20Votes: signature expired");
        address signer = ECDSAUpgradeable.recover(
            _hashTypedDataV4(keccak256(abi.encode(_DELEGATION_TYPEHASH, delegatee, nonce, expiry))),
            v,
            r,
            s
        );
        require(nonce == _useNonce(signer), "ERC20Votes: invalid nonce");
        return _delegate(signer, delegatee);
    }
// Solidity 0.5.8
/**
 * @notice Used to packed the KYC data
 */
function packKYC(uint64 _a, uint64 _b, uint64 _c, uint8 _d) internal pure returns(uint256) {
        // this function packs 3 uint64 and a uint8 together in a uint256 to save storage cost
        // a is rotated left by 136 bits, b is rotated left by 72 bits and c is rotated left by 8 bits.
        // rotation pads empty bits with zeroes so now we can safely do a bitwise OR operation to pack
        // all the variables together.
        return (uint256(_a) << 136) | (uint256(_b) << 72) | (uint256(_c) << 8) | uint256(_d);
    }
// Solidity 0.5.8
/**
 * @notice Used to convert packed data into KYC data
 * @param _packedVersion Packed data
 */
function unpackKYC(uint256 _packedVersion) internal pure returns(uint64 canSendAfter, uint64 canReceiveAfter, uint64 expiryTime, uint8 added) {
        canSendAfter = uint64(_packedVersion >> 136);
        canReceiveAfter = uint64(_packedVersion >> 72);
        expiryTime = uint64(_packedVersion >> 8);
        added = uint8(_packedVersion);
    }
// Solidity 0.5.8
/**
 * @notice Used to initialize the module
 * @param _module Address of module
 * @param _data Data used for the intialization of the module factory variables
 */
function _initializeModule(address _module, bytes memory _data) internal {
        uint256 polySetupCost = _takeFee();
        bytes4 initFunction = IModule(_module).getInitFunction();
        if (initFunction != bytes4(0)) {
            require(Util.getSig(_data) == initFunction, "Provided data is not valid");
            /*solium-disable-next-line security/no-low-level-calls*/
            (bool success, ) = _module.call(_data);
            require(success, "Unsuccessful initialization");
        }
        /*solium-disable-next-line security/no-block-members*/
        emit GenerateModuleFromFactory(_module, name, address(this), msg.sender, setupCost, polySetupCost);
    }
// Solidity 0.5.8
/**
 * @notice Used to upgrade the module factory
 * @param _version Version of upgraded module
 * @param _logicContract Address of deployed module logic contract referenced from proxy
 * @param _upgradeData Data to be passed in call to upgradeToAndCall when a token upgrades its module
 */
function setLogicContract(string calldata _version, address _logicContract, bytes calldata _upgradeData) external onlyOwner {
        require(keccak256(abi.encodePacked(_version)) != keccak256(abi.encodePacked(logicContracts[latestUpgrade].version)), "Same version");
        require(_logicContract != logicContracts[latestUpgrade].logicContract, "Same version");
        require(_logicContract != address(0), "Invalid address");
        latestUpgrade++;
        _modifyLogicContract(latestUpgrade, _version, _logicContract, _upgradeData);
    }
// Solidity 0.5.8
/**
 * @notice Used to update an existing token logic contract
 * @param _upgrade logic contract to upgrade
 * @param _version Version of upgraded module
 * @param _logicContract Address of deployed module logic contract referenced from proxy
 * @param _upgradeData Data to be passed in call to upgradeToAndCall when a token upgrades its module
 */
function updateLogicContract(uint256 _upgrade, string calldata _version, address _logicContract, bytes calldata _upgradeData) external onlyOwner {
        require(_upgrade <= latestUpgrade, "Invalid upgrade");
        // version & contract must differ from previous version, otherwise upgrade proxy will fail
        if (_upgrade > 0) {
          require(keccak256(abi.encodePacked(_version)) != keccak256(abi.encodePacked(logicContracts[_upgrade - 1].version)), "Same version");
          require(_logicContract != logicContracts[_upgrade - 1].logicContract, "Same version");
        }
        require(_logicContract != address(0), "Invalid address");
        require(_upgradeData.length > 4, "Invalid Upgrade");
        _modifyLogicContract(_upgrade, _version, _logicContract, _upgradeData);
    }
// Solidity 0.5.8
/**
 * @notice Used by a security token to upgrade a given module
 * @param _module Address of (proxy) module to be upgraded
 */
function upgrade(address _module) external {
        // Only allow the owner of a module to upgrade it
        require(moduleToSecurityToken[_module] == msg.sender, "Incorrect caller");
        // Only allow issuers to upgrade in single step verisons to preserve upgradeToAndCall semantics
        uint256 newVersion = modules[msg.sender][_module] + 1;
        require(newVersion <= latestUpgrade, "Incorrect version");
        OwnedUpgradeabilityProxy(address(uint160(_module))).upgradeToAndCall(logicContracts[newVersion].version, logicContracts[newVersion].logicContract, logicContracts[newVersion].upgradeData);
        modules[msg.sender][_module] = newVersion;
        emit ModuleUpgraded(
            _module,
            msg.sender,
            newVersion
        );
    }
// Solidity 0.4.11
/// @dev Accepts ether and creates new DDFT tokens.
function createTokens(uint256 _value)  internal {
      if (isFinalized) throw;
      if (now < fundingStartTime) throw;
      if (now > fundingEndTime) throw;
      if (msg.value == 0) throw;

      uint256 tokens = safeMult(_value, tokenExchangeRate); // check that we're not over totals
      uint256 checkedSupply = safeAdd(totalSupply, tokens);

      // DA 8/6/2017 to fairly allocate the last few tokens
      if (tokenCreationCap < checkedSupply) {
        if (tokenCreationCap <= totalSupply) throw;  // CAP reached no more please
        uint256 tokensToAllocate = safeSubtract(tokenCreationCap,totalSupply);
        uint256 tokensToRefund   = safeSubtract(tokens,tokensToAllocate);
        totalSupply = tokenCreationCap;
        balances[msg.sender] += tokensToAllocate;  // safeAdd not needed; bad semantics to use here
        uint256 etherToRefund = tokensToRefund / tokenExchangeRate;
        msg.sender.transfer(etherToRefund);
        CreateDDFT(msg.sender, tokensToAllocate);  // logs token creation
        LogRefund(msg.sender,etherToRefund);
        splitterContract(splitter).update(msg.sender,balances[msg.sender]);
        return;
      }
      // DA 8/6/2017 end of fair allocation code
      totalSupply = checkedSupply;
      balances[msg.sender] += tokens;  // safeAdd not needed; bad semantics to use here
      CreateDDFT(msg.sender, tokens);  // logs token creation
      splitterContract(splitter).update(msg.sender,balances[msg.sender]);
    }
// Solidity 0.7.6
/**
 * @notice Set network fee tier
 * @notice Details for network fee tier can view at deposit() function below
 * @param _networkFeeTier2  Array [tier2 minimun, tier2 maximun], view additional info below
 * Requirements:
 * - Only owner of this contract can call this function
 * - First element in array must greater than 0
 * - Second element must greater than first element
 */
function setNetworkFeeTier2(uint256[] calldata _networkFeeTier2) external onlyOwner {
    require(_networkFeeTier2[0] != 0, "Minimun amount cannot be 0");
    require(_networkFeeTier2[1] > _networkFeeTier2[0], "Maximun amount must greater than minimun amount");
    /**
     * Network fees have three tier, but it is sufficient to have minimun and maximun amount of tier 2
     * Tier 1: deposit amount < minimun amount of tier 2
     * Tier 2: minimun amount of tier 2 <= deposit amount <= maximun amount of tier 2
     * Tier 3: amount > maximun amount of tier 2
     */
    uint256[] memory oldNetworkFeeTier2 = networkFeeTier2;
    networkFeeTier2 = _networkFeeTier2;
    emit SetNetworkFeeTier2(oldNetworkFeeTier2, _networkFeeTier2);
  }
// Solidity 0.7.6
/**
 * @notice Set network fee in percentage
 * @param _networkFeePercentage An array of integer, view additional info below
 * Requirements:
 * - Only owner of this contract can call this function
 * - Each of the element in the array must less than 4000 (40%)
 */
function setNetworkFeePercentage(uint256[] calldata _networkFeePercentage) external onlyOwner {
    /** 
     * _networkFeePercentage content a array of 3 element, representing network fee of tier 1, tier 2 and tier 3
     * For example networkFeePercentage is [100, 75, 50]
     * which mean network fee for Tier 1 = 1%, Tier 2 = 0.75% and Tier 3 = 0.5%
     */
    require(
      _networkFeePercentage[0] < 4000 &&
      _networkFeePercentage[1] < 4000 &&
      _networkFeePercentage[2] < 4000, "Network fee percentage cannot be more than 40%"
    );

    uint256[] memory oldNetworkFeePercentage = networkFeePercentage;
    networkFeePercentage = _networkFeePercentage;
    emit SetNetworkFeePercentage(oldNetworkFeePercentage, _networkFeePercentage);
  }
// Solidity 0.7.6
/**
 * @notice Approve Yearn Finance contracts to deposit token from this contract
 * @dev This function only need execute once in contract contructor
 */
function _approvePooling() private {
    uint256 earnAllowance = token.allowance(address(this), address(earn));
    if (earnAllowance == uint256(0)) {
      token.safeApprove(address(earn), MAX_UNIT);
    }
    uint256 vaultAllowance = token.allowance(address(this), address(vault));
    if (vaultAllowance == uint256(0)) {
      token.safeApprove(address(vault), MAX_UNIT);
    }
  }
// Solidity 0.7.6
/**
 * @notice Withdraw from Yearn Earn and Vault contracts
 * @param _shares amount of earn and vault to withdraw in list: [earn withdraw amount, vault withdraw amount]
 * Requirements:
 * - This contract is not in vesting state
 * - Only Vault can call this function
 */
function withdraw(uint256[] memory _shares) external {
    require(!isVesting, "Contract in vesting state");
    require(msg.sender == address(daoVault), "Only can call from Vault");

    if (_shares[0] > 0) {
      _withdrawEarn(_shares[0]);
    }

    if (_shares[1] > 0) {
      _withdrawVault(_shares[1]);
    }
  }
// Solidity 0.7.6
/**
 * @notice Withdraw from Yearn Earn contract
 * @dev Only call within function withdraw()
 * @param _shares Amount of shares to withdraw
 * Requirements:
 * - Amount input must less than or equal to sender current total amount of earn deposit in contract
 */
function _withdrawEarn(uint256 _shares) private {
    uint256 _d = pool.mul(_shares).div(totalSupply()); // Initial Deposit Amount
    require(earnDepositBalance[tx.origin] >= _d, "Insufficient balance");
    uint256 _earnShares = (_d.mul(earn.totalSupply())).div(earn.calcPoolValueInToken()); // Find earn shares based on deposit amount 
    uint256 _r = ((earn.calcPoolValueInToken()).mul(_earnShares)).div(earn.totalSupply()); // Actual earn withdraw amount

    earn.withdraw(_earnShares);
    earnDepositBalance[tx.origin] = earnDepositBalance[tx.origin].sub(_d);
    
    _burn(address(daoVault), _shares);
    pool = pool.sub(_d);

    if (_r > _d) {
      uint256 _p = _r.sub(_d); // Profit
      uint256 _fee = _p.mul(profileSharingFeePercentage).div(DENOMINATOR);
      token.safeTransfer(tx.origin, _r.sub(_fee));
      token.safeTransfer(treasuryWallet, _fee.mul(treasuryFee).div(DENOMINATOR));
      token.safeTransfer(communityWallet, _fee.mul(communityFee).div(DENOMINATOR));
    } else {
      token.safeTransfer(tx.origin, _r);
    }
  }
// Solidity 0.7.6
/**
 * @notice Vesting this contract, withdraw all the token from Yearn contracts
 * @notice Disabled the deposit and withdraw functions for public, only allowed users to do refund from this contract
 * Requirements:
 * - Only owner of this contract can call this function
 * - This contract is not in vesting state
 */
function vesting() external onlyOwner {
    require(!isVesting, "Already in vesting state");

    // Withdraw all funds from Yearn Earn and Vault contracts
    isVesting = true;
    uint256 _earnBalance = earn.balanceOf(address(this));
    uint256 _vaultBalance = vault.balanceOf(address(this));
    if (_earnBalance > 0) {
      earn.withdraw(_earnBalance);
    }
    if (_vaultBalance > 0) {
      vault.withdraw(_vaultBalance);
    }

    // Collect all profits
    uint256 balance_ = token.balanceOf(address(this));
    if (balance_ > pool) {
      uint256 _profit = balance_.sub(pool);
      uint256 _fee = _profit.mul(profileSharingFeePercentage).div(DENOMINATOR);
      token.safeTransfer(treasuryWallet, _fee.mul(treasuryFee).div(DENOMINATOR));
      token.safeTransfer(communityWallet, _fee.mul(communityFee).div(DENOMINATOR));
    }
    pool = 0;
  }
// Solidity 0.7.6
/**
 * @notice Get token amount based on daoToken hold by account after contract in vesting state
 * @param _address Address of account to check
 * @return Token amount based on on daoToken hold by account. 0 if contract is not in vesting state
 */
function getSharesValue(address _address) external view returns (uint256) {
    if (!isVesting) {
      return 0;
    } else {
      uint256 _shares = daoVault.balanceOf(_address);
      if (_shares > 0) {
        return token.balanceOf(address(this)).mul(_shares).div(daoVault.totalSupply());
      } else {
        return 0;
      }
    }
  }