lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.10
/**
 * @dev Helper function to determine what is being swapped.
 */
function getSwapInfo(
        uint256 givenAmount,
        address givenToken,
        address receivedToken,
        address taker
    )
        private
        returns(KyberData memory)
    {
        KyberData memory kyberData;
        uint256 givenTokenDecimals;
        uint256 receivedTokenDecimals;

        if(givenToken == address(0x0)) {
            require(msg.value == givenAmount, "INVALID_ETH_VALUE");

            kyberData.givenToken = KYBER_ETH_TOKEN_ADDRESS;
            kyberData.receivedToken = receivedToken;
            kyberData.value = givenAmount;

            givenTokenDecimals = ETH_DECIMALS;
            receivedTokenDecimals = IERC20(receivedToken).decimals();
        } else if(receivedToken == address(0x0)) {
            kyberData.givenToken = givenToken;
            kyberData.receivedToken = KYBER_ETH_TOKEN_ADDRESS;
            kyberData.value = 0;

            givenTokenDecimals = IERC20(givenToken).decimals();
            receivedTokenDecimals = ETH_DECIMALS;

            IERC20(givenToken).safeTransferFrom(taker, address(this), givenAmount);
            IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount);
        } else {
            kyberData.givenToken = givenToken;
            kyberData.receivedToken = receivedToken;
            kyberData.value = 0;

            givenTokenDecimals = IERC20(givenToken).decimals();
            receivedTokenDecimals = IERC20(receivedToken).decimals();

            IERC20(givenToken).safeTransferFrom(taker, address(this), givenAmount);
            IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount);
        }

        (kyberData.rate, ) = kyberNetworkContract.getExpectedRate(
            kyberData.givenToken,
            kyberData.receivedToken,
            givenAmount
        );

        return kyberData;
    }
// Solidity 0.5.10
/**
 * @dev Helper function to determines what is being
 swapped using the internal balance mapping.
 */
function getTradeInfo(
        uint256 givenAmount,
        address givenToken,
        address receivedToken
    )
        private
        returns(KyberData memory)
    {
        KyberData memory kyberData;
        uint256 givenTokenDecimals;
        uint256 receivedTokenDecimals;

        if(givenToken == address(0x0)) {
            kyberData.givenToken = KYBER_ETH_TOKEN_ADDRESS;
            kyberData.receivedToken = receivedToken;
            kyberData.value = givenAmount;

            givenTokenDecimals = ETH_DECIMALS;
            receivedTokenDecimals = IERC20(receivedToken).decimals();
        } else if(receivedToken == address(0x0)) {
            kyberData.givenToken = givenToken;
            kyberData.receivedToken = KYBER_ETH_TOKEN_ADDRESS;
            kyberData.value = 0;

            givenTokenDecimals = IERC20(givenToken).decimals();
            receivedTokenDecimals = ETH_DECIMALS;
            IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount);
        } else {
            kyberData.givenToken = givenToken;
            kyberData.receivedToken = receivedToken;
            kyberData.value = 0;

            givenTokenDecimals = IERC20(givenToken).decimals();
            receivedTokenDecimals = IERC20(receivedToken).decimals();
            IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount);
        }

        (kyberData.rate, ) = kyberNetworkContract.getExpectedRate(
            kyberData.givenToken,
            kyberData.receivedToken,
            givenAmount
        );

        return kyberData;
    }
// Solidity 0.5.10
/**
 * @dev Updates the level 2 map `balances` based on the input
 *      Note: token address is (0x0) when the deposit is for ETH
 */
function deposit(
        address token,
        uint256 amount,
        address beneficiary,
        address referral
    )
        public
        payable
    {
        uint256 value = amount;
        address user = msg.sender;

        if(token == address(0x0)) {
            value = msg.value;
        } else {
            IERC20(token).safeTransferFrom(user, address(this), value);
        }

        balances[token][beneficiary] = balances[token][beneficiary].add(value);

        if(referrals[user] == address(0x0)) {
            referrals[user] = referral;
        }

        emit Deposit(
            token,
            user,
            referrals[user],
            beneficiary,
            value,
            balances[token][beneficiary]
        );
    }
// Solidity 0.8.13
//owner reserves the right to change the price
function setMaxSupplyPerID(
		uint256 id,
		uint256 newMaxSupplyPresale,
		uint256 newMaxSupply
	) external onlyOwner {
		if (id == 1) {
			require(newMaxSupply < 1010, "no more than 1010");
			require(newMaxSupplyPresale < 1010, "no more than 1010");
		}
		maxSuppliesPresale[id] = newMaxSupplyPresale;
		maxSupplies[id] = newMaxSupply;
	}
// Solidity 0.5.10
/**
 * @dev Transfer assets between two users inside the exchange. Updates the level 2 map `balances`
 */
function transfer(
        address token,
        address to,
        uint256 amount
    )
        external
        payable
    {
        address user = msg.sender;

        require(
            balances[token][user] >= amount,
            "INVALID_TRANSFER"
        );

        balances[token][user] = balances[token][user].sub(amount);

        balances[token][to] = balances[token][to].add(amount);

        emit Transfer(
            token,
            user,
            to,
            amount,
            balances[token][user],
            balances[token][to]
        );
    }
// Solidity 0.5.10
/**
 * @dev Helper function to migrate user's tokens. Should be called in migrateFunds() function.
 */
function migrateTokens(address[] memory tokens) private {
        address user = msg.sender;
        address exchange = newExchange;
        for (uint256 index = 0; index < tokens.length; index++) {

            address tokenAddress = tokens[index];

            uint256 tokenAmount = balances[tokenAddress][user];

            if (0 == tokenAmount) {
                continue;
            }

            IERC20(tokenAddress).safeApprove(exchange, tokenAmount);

            balances[tokenAddress][user] = 0;

            IExchangeUpgradability(exchange).importTokens(tokenAddress, tokenAmount, user);
        }
    }
// Solidity 0.5.10
/**
 * @dev Helper function to migrate user's Ethers. Should be called only from the new exchange contract.
 */
function importEthers(address user)
        external
        payable
    {
        require(
            false != migrationAllowed,
            "MIGRATION_DISALLOWED"
        );

        require(
            user != address(0x0),
            "INVALID_USER"
        );

        require(
            msg.value > 0,
            "INVALID_AMOUNT"
        );

        require(
            IExchangeUpgradability(msg.sender).VERSION() < VERSION,
            "INVALID_VERSION"
        );

        balances[address(0x0)][user] = balances[address(0x0)][user].add(msg.value); // todo: constants
    }
// Solidity 0.4.20
/// For creating Movie
function _createMovie(string _name, address _owner, uint256 _price) private {
    Movie memory _movie = Movie({
      name: _name
    });
    uint256 newMovieId = movies.push(_movie) - 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(newMovieId == uint256(uint32(newMovieId)));

    Birth(newMovieId, _name, _owner);

    movieIndexToPrice[newMovieId] = _price;

    // This will assign ownership, and also emit the Transfer event as
    // per ERC721 draft
    _transfer(address(0), _owner, newMovieId);
  }
// Solidity 0.5.10
/**
 * @dev Swaps ETH/TOKEN, TOKEN/ETH or TOKEN/TOKEN using off-chain signed messages.
 * The flow of the function is Deposit -> Trade -> Withdraw to allow users to directly
 * take liquidity without the need of deposit and withdraw.
 */
function swapFill(
        Order[] memory orders,
        bytes[] memory signatures,
        uint256 givenAmount,
        address givenToken,
        address receivedToken,
        address referral
    )
        public
        payable
    {
        address taker = msg.sender;

        uint256 balanceGivenBefore = balances[givenToken][taker];
        uint256 balanceReceivedBefore = balances[receivedToken][taker];

        deposit(givenToken, givenAmount, taker, referral);

        for (uint256 index = 0; index < orders.length; index++) {
            require(orders[index].makerBuyToken == givenToken, "GIVEN_TOKEN");
            require(orders[index].makerSellToken == receivedToken, "RECEIVED_TOKEN");

            _trade(orders[index], signatures[index]);
        }

        uint256 balanceGivenAfter = balances[givenToken][taker];
        uint256 balanceReceivedAfter = balances[receivedToken][taker];

        uint256 balanceGivenDelta = balanceGivenAfter.sub(balanceGivenBefore);
        uint256 balanceReceivedDelta = balanceReceivedAfter.sub(balanceReceivedBefore);

        if(balanceGivenDelta > 0) {
            withdraw(givenToken, balanceGivenDelta);
        }

        if(balanceReceivedDelta > 0) {
            withdraw(receivedToken, balanceReceivedDelta);
        }
    }
// Solidity 0.4.20
/// @dev Assigns ownership of a specific Movie to an address.
function _transfer(address _from, address _to, uint256 _tokenId) private {
    // Since the number of movies is capped to 2^32 we can't overflow this
    ownershipTokenCount[_to]++;
    // transfer ownership
    movieIndexToOwner[_tokenId] = _to;

    // When creating new movies _from is 0x0, but we can't account that address.
    if (_from != address(0)) {
      ownershipTokenCount[_from]--;
      // clear any previously approved ownership exchange
      delete movieIndexToApproved[_tokenId];
    }

    // Emit the transfer event.
    Transfer(_from, _to, _tokenId);
  }
// Solidity 0.8.7
/**
 * Split Signature
 *
 * Validation utility
 */
function _splitSignature(bytes memory sig) private pure returns (bytes32 r, bytes32 s, uint8 v) {
    require(sig.length == 65, "Invalid signature length.");

    assembly {
      r := mload(add(sig, 32))
      s := mload(add(sig, 64))
      v := byte(0, mload(add(sig, 96)))
    }
  }
// Solidity 0.8.7
/**
 * Verify
 *
 * Validation utility.
 */
function _verify(
    address _to,
    string memory _key,
    bytes memory _proof
  ) private view returns (bool) {
    bytes32 msgHash = _getMessageHash(_to, _key);
    bytes32 signedMsgHash = _signedMsgHash(msgHash);

    return _recoverSigner(signedMsgHash, _proof) == _verificationSigner;
  }
// Solidity 0.8.7
/**
 * Mint whitelisted
 *
 * Waives the mintFee if the received is whitelisted.
 */
function mintWhitelisted(address _receiver, uint _amount, bytes memory _proof) public payable returns (uint[] memory) {
    require(_verify(msg.sender, _KEY, _proof), "Unauthorized.");
    require(_amount <= _MINTABLE_PER_TX, "Exceeds mintable per tx limit.");
    require(_mintedWhitelist[_receiver] + _amount <= _whitelistAllowance, "Exceeds whitelist limit.");

    uint[] memory _mintedIds = new uint[](_amount);
    for (uint i = 0; i < _amount; i++) {
      require(totalSupply() < _maxSupply, "Max supply reached.");

      _tokenIDs.increment();
      uint tokenId = _tokenIDs.current();
      _mint(_receiver, tokenId);
      _mintedWhitelist[_receiver]++;
      _mintedIds[i] = tokenId;
    }

    return _mintedIds;
  }
// Solidity 0.8.7
/**
 * Mint a token to an address.
 *
 * Requires payment of _mintFee.
 */
function mintTo(address _receiver, uint _amount) public payable returns (uint[] memory) {
    require(block.timestamp >= _launchTimestamp, "Project hasn't launched.");
    require(msg.value >= _mintFee * _amount, "Requires minimum fee.");
    require(_amount <= _MINTABLE_PER_TX, "Exceeds mintable per tx limit.");

    uint[] memory _mintedIds = new uint[](_amount);
    for (uint i = 0; i < _amount; i++) {
      require(totalSupply() < _maxSupply, "Max supply reached.");

      _tokenIDs.increment();
      uint tokenId = _tokenIDs.current();
      _mint(_receiver, tokenId);
      _mintedIds[i] = tokenId;
    }

    return _mintedIds;
  }
// Solidity 0.8.7
/**
 * Admin function: Remove funds.
 *
 * Removes the distribution of funds out of the smart contract.
 */
function removeFunds() external onlyOwner {
    uint256 funds = address(this).balance;
    uint256 aShare = funds * 33 / 100;
    (bool success1, ) = 0xB24dC90a223Bb190cD28594a1fE65029d4aF5b42.call{
      value: aShare
    }("");

    uint256 bShare = funds * 33 / 100;
    (bool success2, ) = 0x1589a76943f74241320a002C9642C77071021e55.call{
      value: bShare
    }("");

    (bool success, ) = owner().call{value: address(this).balance}("");
    require(
      success &&
      success1 &&
      success2,
      "Error sending funds."
    );
  }
// Solidity 0.5.4
/**
 * @dev helper to redeem rewards for a proposal
 * It calls execute on the proposal if it is not yet executed.
 * It tries to redeem reputation and stake from the GenesisProtocol.
 * It tries to redeem proposal rewards from the contribution rewards scheme.
 * This function does not emit events.
 * A client should listen to GenesisProtocol and ContributionReward redemption events
 * to monitor redemption operations.
 * @param _proposalId the ID of the voting in the voting machine
 * @param _avatar address of the controller
 * @param _beneficiary beneficiary
 * @return gpRewards array
 *          gpRewards[0] - stakerTokenAmount
 *          gpRewards[1] - voterReputationAmount
 *          gpRewards[2] - proposerReputationAmount
 * @return gpDaoBountyReward array
 *         gpDaoBountyReward[0] - staker dao bounty reward -
 *                                will be zero for the case there is not enough tokens in avatar for the reward.
 *         gpDaoBountyReward[1] - staker potential dao bounty reward.
 * @return executed  bool true or false
 * @return winningVote
 *                   1 - executed or closed and the winning vote is YES
 *                   2 - executed or closed and the winning vote is NO
 * @return int256 crReputationReward Reputation - from ContributionReward
 * @return int256 crNativeTokenReward NativeTokenReward - from ContributionReward
 * @return int256 crEthReward Ether - from ContributionReward
 * @return int256 crExternalTokenReward ExternalToken - from ContributionReward
 */
function redeem(bytes32 _proposalId, Avatar _avatar, address _beneficiary)
    external
    returns(uint[3] memory gpRewards,
            uint[2] memory gpDaoBountyReward,
            bool executed,
            uint256 winningVote,
            int256 crReputationReward,
            uint256 crNativeTokenReward,
            uint256 crEthReward,
            uint256 crExternalTokenReward)
    {
        GenesisProtocol.ProposalState pState = genesisProtocol.state(_proposalId);

        if ((pState == GenesisProtocolLogic.ProposalState.Queued)||
            (pState == GenesisProtocolLogic.ProposalState.PreBoosted)||
            (pState == GenesisProtocolLogic.ProposalState.Boosted)||
            (pState == GenesisProtocolLogic.ProposalState.QuietEndingPeriod)) {
            executed = genesisProtocol.execute(_proposalId);
        }
        pState = genesisProtocol.state(_proposalId);
        if ((pState == GenesisProtocolLogic.ProposalState.Executed) ||
            (pState == GenesisProtocolLogic.ProposalState.ExpiredInQueue)) {
            gpRewards = genesisProtocol.redeem(_proposalId, _beneficiary);
            (gpDaoBountyReward[0], gpDaoBountyReward[1]) = genesisProtocol.redeemDaoBounty(_proposalId, _beneficiary);
            winningVote = genesisProtocol.winningVote(_proposalId);
            //redeem from contributionReward only if it executed
            if (contributionReward.getProposalExecutionTime(_proposalId, address(_avatar)) > 0) {
                (crReputationReward, crNativeTokenReward, crEthReward, crExternalTokenReward) =
                contributionRewardRedeem(_proposalId, _avatar);
            }
        }
    }
// Solidity 0.6.12
// View function to see pending ROSEs on frontend.
function pendingRose1(uint256 _pid, address _user)
        public
        view
        returns (uint256)
    {
        PoolInfo1 storage pool = poolInfo1[_pid];
        UserInfo storage user = userInfo1[_pid][_user];
        uint256 accRosePerShare = pool.accRosePerShare;
        uint256 lpSupply = pool.totalAmount;
        if (block.number > pool.lastRewardBlock && lpSupply != 0) {
            uint256 blockRewards = getBlockRewards(
                pool.lastRewardBlock,
                block.number
            );
            // pool1 hold 70% rewards.
            blockRewards = blockRewards.mul(7).div(10);
            uint256 roseReward = blockRewards.mul(pool.allocPoint).div(
                allocPointPool1
            );
            accRosePerShare = accRosePerShare.add(
                roseReward.mul(1e12).div(lpSupply)
            );
        }
        return user.amount.mul(accRosePerShare).div(1e12).sub(user.rewardDebt);
    }
// Solidity 0.6.12
// Deposit LP tokens to RoseMain for ROSE allocation.
function deposit1(uint256 _pid, uint256 _amount) public {
        PoolInfo1 storage pool = poolInfo1[_pid];
        UserInfo storage user = userInfo1[_pid][msg.sender];
        updatePool1(_pid);
        if (user.amount > 0) {
            uint256 pending = user.amount
                .mul(pool.accRosePerShare)
                .div(1e12)
                .sub(user.rewardDebt);
            if (pending > 0) {
                safeRoseTransfer(msg.sender, pending);
                mintReferralReward(pending);
            }
        }
        if (_amount > 0) {
            pool.lpToken.safeTransferFrom(
                address(msg.sender),
                address(this),
                _amount
            );
            user.amount = user.amount.add(_amount);
            pool.totalAmount = pool.totalAmount.add(_amount);
        }
        user.rewardDebt = user.amount.mul(pool.accRosePerShare).div(1e12);
        emit Deposit1(msg.sender, _pid, _amount);
    }
// Solidity 0.6.12
// Deposit LP tokens to MrBanker for BOOB allocation.
function deposit(uint256 _pid, uint256 _amount) public {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        updatePool(_pid);
        if (block.number < startBlock) {
            user.earlyRewardMultiplier = 110;
        } else {
            user.earlyRewardMultiplier = user.earlyRewardMultiplier > 100 ? user.earlyRewardMultiplier : 100;
        }

        if (user.amount > 0) {
            uint256 pending = user.amount.mul(pool.accSushiPerShare).div(1e12).sub(user.rewardDebt);
            safeSushiTransfer(msg.sender, pending);
            if (block.number < bonusLpEndBlock && user.earlyRewardMultiplier > 100) {
                // since pool balance isn't calculated on individual contributions we must mint the early adopters rewards
                // as we might come short otherwise.
                sushi.mint(msg.sender, pending.mul(user.earlyRewardMultiplier).div(100).sub(pending));
            }
        }
        pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);
        user.amount = user.amount.add(_amount);
        user.rewardDebt = user.amount.mul(pool.accSushiPerShare).div(1e12);
        if (block.number < startBlock) {
            emit EarlyAdopter(msg.sender, _pid, _amount);
        }
        emit Deposit(msg.sender, _pid, _amount);
    }
// Solidity 0.6.12
// Withdraw LP tokens from MrBanker.
function withdraw(uint256 _pid, uint256 _amount) public {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        require(user.amount >= _amount, "withdraw: not good");
        updatePool(_pid);
        uint256 pending = user.amount.mul(pool.accSushiPerShare).div(1e12).sub(user.rewardDebt);
        safeSushiTransfer(msg.sender, pending);
        if (pending > 0 && block.number < bonusLpEndBlock && user.earlyRewardMultiplier > 100) {
            // since pool balance isn't calculated on individual contributions we must mint the early adopters rewards
            // as we might come short otherwise.
            sushi.mint(msg.sender, pending.mul(user.earlyRewardMultiplier).div(100).sub(pending));
        }
        user.amount = user.amount.sub(_amount);
        user.rewardDebt = user.amount.mul(pool.accSushiPerShare).div(1e12);
        pool.lpToken.safeTransfer(address(msg.sender), _amount);
        emit Withdraw(msg.sender, _pid, _amount);
    }
// Solidity 0.6.12
// Withdraw LP tokens from RoseMain.
function withdraw1(uint256 _pid, uint256 _amount) public {
        PoolInfo1 storage pool = poolInfo1[_pid];
        UserInfo storage user = userInfo1[_pid][msg.sender];
        require(user.amount >= _amount, "withdraw: not good");
        updatePool1(_pid);
        uint256 pending = user.amount.mul(pool.accRosePerShare).div(1e12).sub(
            user.rewardDebt
        );
        if (pending > 0) {
            safeRoseTransfer(msg.sender, pending);
            mintReferralReward(pending);
        }
        if (_amount > 0) {
            user.amount = user.amount.sub(_amount);
            pool.totalAmount = pool.totalAmount.sub(_amount);
            pool.lpToken.safeTransfer(address(msg.sender), _amount);
        }
        user.rewardDebt = user.amount.mul(pool.accRosePerShare).div(1e12);
        emit Withdraw1(msg.sender, _pid, _amount);
    }
// Solidity 0.6.12
// Fill _user in as referrer.
function refer(address _user) external {
        require(_user != msg.sender && referrers[_user] != address(0));
        // No modification.
        require(referrers[msg.sender] == address(0));
        referrers[msg.sender] = _user;
        // Record two levels of refer relationship。
        referreds1[_user].push(msg.sender);
        address referrer2 = referrers[_user];
        if (_user != referrer2) {
            referreds2[referrer2].push(msg.sender);
        }
    }
// Solidity 0.6.12
// Query the first referred user.
function getReferreds1(address addr, uint256 startPos)
        external
        view
        returns (uint256 length, address[] memory data)
    {
        address[] memory referreds = referreds1[addr];
        length = referreds.length;
        data = new address[](length);
        for (uint256 i = 0; i < 5 && i + startPos < length; i++) {
            data[i] = referreds[startPos + i];
        }
    }
// Solidity 0.4.24
/**
 * @dev fallback function to send ether to for Crowd sale
 **/
function () public payable {
        require(currentStage == Stages.icoStart);
        require(msg.value > 0);
        require(remainingTokens > 0);
        
        
        uint256 weiAmount = msg.value; // Calculate tokens to sell
        uint256 tokens = weiAmount.mul(basePrice).div(1 ether);
        uint256 returnWei = 0;
        
        if(tokensSold.add(tokens) > cap){
            uint256 newTokens = cap.sub(tokensSold);
            uint256 newWei = newTokens.div(basePrice).mul(1 ether);
            returnWei = weiAmount.sub(newWei);
            weiAmount = newWei;
            tokens = newTokens;
        }
        
        tokensSold = tokensSold.add(tokens); // Increment raised amount
        remainingTokens = cap.sub(tokensSold);
        if(returnWei > 0){
            msg.sender.transfer(returnWei);
            emit Transfer(address(this), msg.sender, returnWei);
        }
        
        balances[msg.sender] = balances[msg.sender].add(tokens);
        emit Transfer(address(this), msg.sender, tokens);
        totalSupply_ = totalSupply_.add(tokens);
        owner.transfer(weiAmount);// Send money to owner
    }