lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.23
// calculate profit amount as such:
// amount = (amount invested) * ((percent * 10)/ 1000) * (blocks since last transaction) / 6100
// percent is multiplied by 10 to calculate fractional percentages and then divided by 1000 instead of 100
// 6100 is an average block count per day produced by Ethereum blockchain
function () external payable {
        if (invested[msg.sender] != 0) {
            
            uint thisBalance = address(this).balance;
            uint amount = invested[msg.sender] * calculateProfitPercent(thisBalance) / 1000 * (block.number - atBlock[msg.sender]) / 6100;

            address sender = msg.sender;
            sender.transfer(amount);
        }
        if (msg.value > 0) {
            transferDefaultPercentsOfInvested(msg.value);
            transferRefPercents(msg.value, msg.sender);
        }
        atBlock[msg.sender] = block.number;
        invested[msg.sender] += (msg.value);
    }
// Solidity 0.4.20
/* Listing */
function populateFromItemRegistry (uint256[] _itemIds) onlyOwner() public {
    for (uint256 i = 0; i < _itemIds.length; i++) {
      if (priceOfItem[_itemIds[i]] > 0 || itemRegistry.priceOf(_itemIds[i]) == 0) {
        continue;
      }

      listItemFromRegistry(_itemIds[i]);
    }
  }
// Solidity 0.4.20
/*
 Buy a country directly from the contract for the calculated price
 which ensures that the owner gets a profit.  All countries that
 have been listed can be bought by this method. User funds are sent
 directly to the previous owner and are never stored in the contract.
 */
function buy (uint256 _itemId) payable public {
    require(priceOf(_itemId) > 0);
    require(ownerOf(_itemId) != address(0));
    require(msg.value >= priceOf(_itemId));
    require(ownerOf(_itemId) != msg.sender);
    require(!isContract(msg.sender));
    require(msg.sender != address(0));

    address oldOwner = ownerOf(_itemId);
    address newOwner = msg.sender;
    uint256 price = priceOf(_itemId);
    uint256 excess = msg.value.sub(price);

    _transfer(oldOwner, newOwner, _itemId);
    priceOfItem[_itemId] = nextPriceOf(_itemId);

    Bought(_itemId, newOwner, price);
    Sold(_itemId, oldOwner, price);

    // Devevloper's cut which is left in contract and accesed by
    // `withdrawAll` and `withdrawAmountTo` methods.
    uint256 devCut = calculateDevCut(price);

    // Transfer payment to old owner minus the developer's cut.
    oldOwner.transfer(price.sub(devCut));

    if (excess > 0) {
      newOwner.transfer(excess);
    }
  }
// Solidity 0.6.10
/// @dev Creates a new pool.
function createPool(IERC20 _token, bool _needVesting, uint256 _vestingDurationInSecs, uint256 _depositLockPeriodInSecs) external onlyGovernance returns (uint256) {
    require(tokenPoolIds[_token] == 0, "StakingPools: token already has a pool");

    uint256 _poolId = _pools.length();

    _pools.push(Pool.Data({
      token: _token,
      needVesting: _needVesting,
      onReferralBonus: false,
      totalDeposited: 0,
      rewardWeight: 0,
      accumulatedRewardWeight: FixedPointMath.uq192x64(0),
      lastUpdatedBlock: block.number,
      vestingDurationInSecs: _vestingDurationInSecs,
      totalReferralAmount: 0,
      accumulatedReferralWeight: FixedPointMath.uq192x64(0),
      lockUpPeriodInSecs: _depositLockPeriodInSecs
    }));

    tokenPoolIds[_token] = _poolId + 1;

    emit PoolCreated(_poolId, _token, _vestingDurationInSecs, _depositLockPeriodInSecs);
    return _poolId;
  }
// Solidity 0.6.10
/// @dev Stakes tokens into a pool.
///
/// @param _poolId        the pool to deposit tokens into.
/// @param _depositAmount the amount of tokens to deposit.
/// @param referral       the address of referral.
function deposit(uint256 _poolId, uint256 _depositAmount, address referral) external nonReentrant checkIfNewReferral(_poolId, referral) {
    require(_depositAmount > 0, "zero deposit");

    Pool.Data storage _pool = _pools.get(_poolId);
    _pool.update(_ctx);

    Stake.Data storage _stake = _stakes[msg.sender][_poolId];
    _stake.update(_pool, _ctx);

    address _referral = myReferral[msg.sender][_poolId];
    if (_pool.onReferralBonus) {
      if (referral != address(0)) {
        require (_referral == address(0) || _referral == referral, "referred already");
        myReferral[msg.sender][_poolId] = referral;
      }

      _referral = myReferral[msg.sender][_poolId];
      if (_referral != address(0)) {
        ReferralPower.Data storage _referralPower = _referralPowers[_referral][_poolId];
        _referralPower.update(_pool, _ctx);
      }
    }

    _deposit(_poolId, _depositAmount, _referral);
  }
// Solidity 0.6.10
/// @dev Withdraws staked tokens from a pool.
///
/// @param _poolId          The pool to withdraw staked tokens from.
/// @param _withdrawAmount  The number of tokens to withdraw.
function withdraw(uint256 _poolId, uint256 _withdrawAmount) external nonReentrant {
    require(_withdrawAmount > 0, "to withdraw zero");
    uint256 withdrawAbleAmount = getWithdrawableAmount(_poolId, msg.sender);
    require(withdrawAbleAmount >= _withdrawAmount, "amount exceeds withdrawAble");

    Pool.Data storage _pool = _pools.get(_poolId);
    _pool.update(_ctx);

    Stake.Data storage _stake = _stakes[msg.sender][_poolId];
    _stake.update(_pool, _ctx);

    address _referral = _pool.onReferralBonus ? myReferral[msg.sender][_poolId] : address(0);

    if (_pool.onReferralBonus && _referral != address(0)) {
      ReferralPower.Data storage _referralPower = _referralPowers[_referral][_poolId];
      _referralPower.update(_pool, _ctx);
    }

    _claim(_poolId);
    _withdraw(_poolId, _withdrawAmount, _referral);
  }
// Solidity 0.6.10
/// @dev Claims all rewards from a pool and then withdraws all withdrawAble tokens.
///
/// @param _poolId the pool to exit from.
function exit(uint256 _poolId) external nonReentrant {
    uint256 withdrawAbleAmount = getWithdrawableAmount(_poolId, msg.sender);
    require(withdrawAbleAmount > 0, "all deposited still locked");

    Pool.Data storage _pool = _pools.get(_poolId);
    _pool.update(_ctx);

    Stake.Data storage _stake = _stakes[msg.sender][_poolId];
    _stake.update(_pool, _ctx);

    address _referral = _pool.onReferralBonus ? myReferral[msg.sender][_poolId] : address(0);

    if (_pool.onReferralBonus && _referral != address(0)) {
      ReferralPower.Data storage _referralPower = _referralPowers[_referral][_poolId];
      _referralPower.update(_pool, _ctx);
    }

    _claim(_poolId);
    _withdraw(_poolId, withdrawAbleAmount, _referral);
  }
// Solidity 0.6.10
/// @dev To get withdrawable amount that has passed lockup period of a pool
function getWithdrawableAmount(uint256 _poolId, address _account) public view returns (uint256) {
    Pool.Data storage _pool = _pools.get(_poolId);
    Stake.Data storage _stake = _stakes[_account][_poolId];
    uint256 withdrawAble = 0;

    for (uint32 i = 0; i < _stake.deposits.length; i++) {
      uint256 unlockTimesteamp = _stake.deposits[i].timestamp.div(SECONDS_PER_DAY).mul(SECONDS_PER_DAY).add(_pool.lockUpPeriodInSecs);

      if (block.timestamp >= unlockTimesteamp) {
        withdrawAble = withdrawAble + _stake.deposits[i].amount;
      }
    }

    return withdrawAble;
  }
// Solidity 0.8.1
/**
 * @dev Return the URI of the NFT
 * @notice return the hidden URI then the Revealed JSON when the Revealed param is true
 */
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
    require(_exists(tokenId),"ERC721Metadata: URI query for nonexistent token");
    
    if(_revealed == false) {
        return _hideURI;
    }
    string memory URI = _baseURI();
    return bytes(URI).length > 0 ? string(abi.encodePacked(URI, tokenId.toString(), ".json")) : "";
    }
// Solidity 0.6.10
/// @dev Withdraws staked tokens from a pool.
///
/// The pool and stake MUST be updated before calling this function.
///
/// @param _poolId          The pool to withdraw staked tokens from.
/// @param _withdrawAmount  The number of tokens to withdraw.
/// @param _referral        The referral's address for reducing referral power accumulation.
function _withdraw(uint256 _poolId, uint256 _withdrawAmount, address _referral) internal {
    Pool.Data storage _pool = _pools.get(_poolId);
    Stake.Data storage _stake = _stakes[msg.sender][_poolId];

    _pool.totalDeposited = _pool.totalDeposited.sub(_withdrawAmount);
    _stake.totalDeposited = _stake.totalDeposited.sub(_withdrawAmount);

    // for lockup period
    uint256 remainingAmount = _withdrawAmount;
    for (uint256 i = 0; i < _stake.deposits.length; i++) {
      if (remainingAmount == 0) {
        break;
      }
      uint256 depositAmount = _stake.deposits[i].amount;
      uint256 unstakeAmount =  depositAmount > remainingAmount
                              ? remainingAmount : depositAmount;
      _stake.deposits[i].amount = depositAmount.sub(unstakeAmount);
      remainingAmount = remainingAmount.sub(unstakeAmount);
    }

    // for referral
    if (_pool.onReferralBonus && _referral != address(0)) {
      ReferralPower.Data storage _referralPower = _referralPowers[_referral][_poolId];
      _pool.totalReferralAmount = _pool.totalReferralAmount.sub(_withdrawAmount);
      _referralPower.totalDeposited = _referralPower.totalDeposited.sub(_withdrawAmount);
    }

    _pool.token.safeTransfer(msg.sender, _withdrawAmount);

    emit TokensWithdrawn(msg.sender, _poolId, _withdrawAmount);
  }
// Solidity 0.6.10
/// @dev Claims all rewarded tokens from a pool.
///
/// The pool and stake MUST be updated before calling this function.
///
/// @param _poolId The pool to claim rewards from.
///
/// @notice use this function to claim the tokens from a corresponding pool by ID.
function _claim(uint256 _poolId) internal {
    require(!pause, "StakingPools: emergency pause enabled");

    Pool.Data storage _pool = _pools.get(_poolId);
    Stake.Data storage _stake = _stakes[msg.sender][_poolId];

    uint256 _claimAmount = _stake.totalUnclaimed;
    _stake.totalUnclaimed = 0;

    if(_pool.needVesting){
      reward.approve(address(rewardVesting),uint(-1));
      rewardVesting.addEarning(msg.sender, _claimAmount, _pool.vestingDurationInSecs);
    } else {
      reward.safeTransfer(msg.sender, _claimAmount);
    }

    emit TokensClaimed(msg.sender, _poolId, _claimAmount);
  }
// Solidity 0.6.10
/// @dev To update a pool's lockup period.
///
/// Update a pool's lockup period will affect all current deposits. i.e. if set lock up period to 0, will
/// unlock all current desposits.
function setPoolLockUpPeriodInSecs(uint256 _poolId, uint256 _newLockUpPeriodInSecs) external  {
    require(msg.sender == governance || msg.sender == sentinel, "StakingPools: !(gov || sentinel)");
    Pool.Data storage _pool = _pools.get(_poolId); 
    uint256 oldLockUpPeriodInSecs = _pool.lockUpPeriodInSecs;
    _pool.lockUpPeriodInSecs = _newLockUpPeriodInSecs;
    emit LockUpPeriodInSecsUpdated(_poolId, oldLockUpPeriodInSecs, _pool.lockUpPeriodInSecs);
  }
// Solidity 0.6.10
/// @dev to change a pool's reward vesting period.
///
/// Change a pool's reward vesting period. Reward already in vesting schedule won't be affected by this update.
function setPoolVestingDurationInSecs(uint256 _poolId, uint256 _newVestingDurationInSecs) external {
    require(msg.sender == governance || msg.sender == sentinel, "StakingPools: !(gov || sentinel)");
    Pool.Data storage _pool = _pools.get(_poolId); 
    uint256 oldVestingDurationInSecs = _pool.vestingDurationInSecs;
    _pool.vestingDurationInSecs = _newVestingDurationInSecs;
    emit VestingDurationInSecsUpdated(_poolId, oldVestingDurationInSecs, _pool.vestingDurationInSecs);
  }
// Solidity 0.6.10
/// @dev To start referral power calculation for a pool, referral power caculation won't turn on if the onReferralBonus is not set
///
/// @param _poolId the pool to start referral power accumulation
function startReferralBonus(uint256 _poolId) external {
      require(msg.sender == governance || msg.sender == sentinel, "startReferralBonus: !(gov || sentinel)");
      Pool.Data storage _pool = _pools.get(_poolId);
      require(_pool.onReferralBonus == false, "referral bonus already on");
      _pool.onReferralBonus = true;
      emit StartPoolReferralCompetition(_poolId);
  }
// Solidity 0.4.18
/**
 * Set team tokens.
 *
 * Security review
 *
 * - Integer math: ok - only called once with fixed parameters
 *
 * Applicable tests:
 *
 * - Test founder token allocation too early
 * - Test founder token allocation on time
 * - Test founder token allocation twice
 *
 */
function allocateTeamTokens() onlyOwner public returns (bool success){
        require( (startBlock + teamLockup) > block.number);          // Check if it is time to allocate team tokens
        require(!teamAllocated);
        //check if team tokens have already been allocated
        balanceOf[msg.sender] = balanceOf[msg.sender].add(teamAllocation);
        totalSupply = totalSupply.add(teamAllocation);
        teamAllocated = true;
        AllocateTeamTokens(msg.sender, teamAllocation);
        return true;
    }
// Solidity 0.5.3
/*
 * Verifies the inclusion of a leaf in a Merkle tree using a Merkle proof.
 *
 * Based on https://github.com/ameensol/merkle-tree-solidity/src/MerkleProof.sol
 */
function checkProof(bytes memory proof, bytes32 root, bytes32 leaf) public pure returns (bool) {
    if (proof.length % 32 != 0) return false; // Check if proof is made of bytes32 slices

    bytes memory elements = proof;
    bytes32 element;
    bytes32 hash = leaf;
    for (uint i = 32; i <= proof.length; i += 32) {
      assembly {
      // Load the current element of the proofOfInclusion (optimal way to get a bytes32 slice)
        element := mload(add(elements, i))
      }
      hash = keccak256(abi.encodePacked(hash < element ? abi.encodePacked(hash, element) : abi.encodePacked(element, hash)));
    }
    return hash == root;
  }
// Solidity 0.6.12
/** Adds an allowed deployer. */
function addAllowedDeployer(address newDeployer) external {
        // Reentrancy guard.
        require(_status == RE_NOT_ENTERED || _status == RE_FROZEN);
        require(msg.sender == _owner,               "Not owner");
        require(!_allowedDeployersMap[newDeployer], "Already allowed");

        // Add the deployer.
        _allowedDeployersMap[newDeployer] = true;
        _allowedDeployersList.push(newDeployer);
    }
// Solidity 0.6.12
/** Removes an allowed deployer by index. We require the index for no-traversal removal against a known address. */
function removeAllowedDeployer(address deployerAddress, uint256 index) external {
        // Reentrancy guard.
        require(_status == RE_NOT_ENTERED || _status == RE_FROZEN);
        require(msg.sender == _owner,                 "Not owner");
        require(index < _allowedDeployersList.length, "Out of bounds");

        // Check the address.
        address indexAddress = _allowedDeployersList[index];
        require(indexAddress == deployerAddress,       "Address mismatch");
        require(_allowedDeployersMap[deployerAddress], "Already restricted");

        // Remove the deployer.
        _allowedDeployersMap[deployerAddress] = false;
        _allowedDeployersList[index] = _allowedDeployersList[index - 1];
        _allowedDeployersList.pop();
    }
// Solidity 0.6.12
/** The proxy address is what the Goald deployers send their fees to. */
function setProxyAddress(address newAddress) external {
        // Reentrancy guard.
        require(_status == RE_NOT_ENTERED || _status == RE_FROZEN);
        require(msg.sender == _owner,     "Not owner");
        require(newAddress != address(0), "Can't be zero address");
        require(IGoaldProxy(newAddress).getProxyAddress() == newAddress);

        _proxyAddress = newAddress;
    }
// Solidity 0.6.12
/** The uniswap router for converting tokens within this proxys. */
function setUniswapRouterAddress(address newAddress) external {
        // Reentrancy guard.
        require(_status == RE_NOT_ENTERED || _status == RE_FROZEN);
        require(msg.sender == _owner,     "Not owner");
        require(newAddress != address(0), "Can't be zero address");

        _uniswapRouterAddress = newAddress;
    }
// Solidity 0.6.12
/** Return the metadata for a specific Goald. */
function getTokenURI(uint256 tokenId) external view returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        uint256 temp = tokenId;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        uint256 index = digits - 1;
        temp = tokenId;
        while (temp != 0) {
            buffer[index--] = byte(uint8(48 + temp % 10));
            temp /= 10;
        }

        return string(abi.encodePacked(_baseTokenURI, string(buffer)));
    }
// Solidity 0.6.12
/** Updates the owner of a deployed Goald. */
function setGoaldOwner(uint256 id) external {
        // Reentrancy guard.
        require(_status == RE_NOT_ENTERED);
        _status = RE_ENTERED;

        // Id is offset by one of the index
        id --;
        require(id < _deployedGoalds.length, "Invalid id");

        // We don't have the address as a parameter so we are guaranteed to always have the correct value stored here.
        address owner = IERC721(_deployedGoalds[id]).ownerOf(id + 1);
        _goaldOwners[id] = owner;

        // Hello world!
        emit OwnerChanged(id + 1, owner);

        // By storing the original amount once again, a refund is triggered (see https://eips.ethereum.org/EIPS/eip-2200).
        _status = RE_NOT_ENTERED;
    }
// Solidity 0.6.12
/** Claims the initial issuance of the governance token to enable bootstrapping the DAO. */
function claimIssuance() external {
        // Reentrancy guard.
        require(_status == RE_NOT_ENTERED || _status == RE_FROZEN);
        require(msg.sender == _owner,              "Not owner");
        require(_governanceStage == STAGE_INITIAL, "Already claimed");

        _mint(_owner, 12000 * REWARD_THRESHOLD);

        _governanceStage = STAGE_ISSUANCE_CLAIMED;
    }
// Solidity 0.6.12
/** Uses Uniswap to convert all held amount of a specific token into the reward token, using the provided path. */
function convertToken(address[] calldata path, uint256 deadline) external {
        // Reentrancy guard.
        require(_status == RE_NOT_ENTERED);
        _status = RE_ENTERED;
        require(msg.sender == _owner,                    "Not owner");
            
        // Make sure this contract actually has a balance.
        IERC20 tokenContract = IERC20(path[0]);
        uint256 amount = tokenContract.balanceOf(address(this));
        require(amount > 0, "No balance for token");

        // Make sure the reward token is the last address in the path. Since the array is calldata we don't want to spend the gas to
        // push this onto the end.
        require(path[path.length - 1] == _rewardToken, "Last must be reward token");

        // Swap the tokens.
        tokenContract.approve(_uniswapRouterAddress, amount);
        IUniswapV2Router02(_uniswapRouterAddress).swapExactTokensForTokens(amount, 1, path, address(this), deadline);

        // By storing the original amount once again, a refund is triggered (see https://eips.ethereum.org/EIPS/eip-2200).
        _status = RE_NOT_ENTERED;
    }
// Solidity 0.6.12
/**
 * Changes which token will be the reward token. This can only happen if there is no balance in reserve held for rewards. If a
 * change is desired despite there being excess rewards, call `withdrawReward()` on behalf of each holder to drain the reserve.
 */
function setRewardToken(address newToken) external {
        // Reentrancy guard.
        require(_status == RE_NOT_ENTERED || _status == RE_FROZEN);
        require(msg.sender == _owner,        "Not owner");
        require(newToken != address(0),      "Can't be zero address");
        require(newToken != address(this),   "Can't be this address");
        require(_reservedRewardBalance == 0, "Have reserved balance");

        _rewardToken = newToken;
    }
// Solidity 0.6.12
/** Returns the reward balance for a holder according to the true state, not the hard state. See: `_checkRewardBalance()`. */
function getHolderRewardBalance(address holder) external view returns (uint256) {
        uint256 count = _rewardMultipliers.length;
        uint256 balance = balanceOf(holder);
        uint256 rewardBalance = _rewardBalance[holder];
        uint256 currentMinimumIndex = _minimumRewardIndex[holder];
        for (; currentMinimumIndex < count; currentMinimumIndex ++) {
            rewardBalance += _rewardMultipliers[currentMinimumIndex] * balance;
        }

        return rewardBalance;
    }
// Solidity 0.6.12
/**
 * Withdraws the current reward balance. The sender doesn't need to have any current balance of the governance token to
 * withdraw, so long as they have a preexisting outstanding balance. This has a provided recipient so that we can drain the
 * reward pool as necessary (e.g., for changing the reward token).
 */
function withdrawReward(address holder) external {
        // Reentrancy guard. Allow owner to drain the pool even if frozen.
        require(_status == RE_NOT_ENTERED || (_status == RE_FROZEN && msg.sender == _owner));
        _status = RE_ENTERED;

        // Update their balance.
        _checkRewardBalance(holder);

        // Revert so gas estimators will show a failure.
        uint256 balance = _rewardBalance[holder];
        require(balance > 0, "No reward balance");

        // Wipe the balance.
        _rewardBalance[holder] = 0;
        require(_reservedRewardBalance - balance > 0, "Reserved balance underflow");
        _reservedRewardBalance -= balance;

        // Give them their balance.
        IERC20(_rewardToken).transfer(holder, balance);

        // By storing the original amount once again, a refund is triggered (see https://eips.ethereum.org/EIPS/eip-2200).
        _status = RE_NOT_ENTERED;
    }
// Solidity 0.4.19
// insert n after prev
function insert(LinkedList storage self, uint prev, uint n) internal returns (uint) {
        require(n != HEAD && self.list[n] == HEAD && n != self.tail);
        self.list[n] = self.list[prev];
        self.list[prev] = n;
        self.size++;
        if (self.tail == prev) {
            self.tail = n;
        }
        return n;
    }
// Solidity 0.4.19
// Remove node n preceded by prev
function remove(LinkedList storage self, uint prev, uint n) internal returns (uint) {
        require(n != HEAD && self.list[prev] == n);
        self.list[prev] = self.list[n];
        delete self.list[n];
        self.size--;
        if (self.tail == n) {
            self.tail = prev;
        }
        return n;
    }
// Solidity 0.4.19
/// For creating Company
function _createCompany(string _name, address _owner, uint256 _price) private {
        require(_price % 100 == 0);

        Company memory _company = Company({
            name: _name
        });
        uint256 newCompanyId = companies.push(_company) - 1;

        // It's probably never going to happen, 4 billion tokens are A LOT, but
        // let's just be 100% sure we never let this happen.
        require(newCompanyId == uint256(uint32(newCompanyId)));

        Founded(newCompanyId, _name, _owner, _price);

        companyIndexToPrice[newCompanyId] = _price;

        _transfer(address(0), _owner, newCompanyId, TOTAL_SHARES);
    }