lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.7
// Public method which retrieves holders inventory of tokens
function getHoldersTokens(address _holder)
        public
        view
        returns (uint256[] memory)
    {
        uint256 tokenCount = balanceOf(_holder);

        uint256[] memory tokensId = new uint256[](tokenCount);

        for (uint256 i; i < tokenCount; i++) {
            tokensId[i] = tokenOfOwnerByIndex(_holder, i);
        }

        return tokensId;
    }
// Solidity 0.5.7
// BID
// Lets player pick number
// Locks his potential winnings
function Bid(uint256 _number) payable public {
        require(now < timerEnd, "game is over!");
        require(msg.value > bid, "not enough to beat current leader");
        require(_number >= numberMin, "number too low");
        require(_number <= numberMax, "number too high");

        bid = msg.value;
        pot = pot.add(msg.value);
        shareToWinner = ComputeShare();
        uint256 _share = 100;
        shareToThrone = _share.sub(shareToWinner);
        leader = msg.sender;
        number = _number;
            
        emit GameBid(msg.sender, msg.value, number, pot, shareToWinner);
    }
// Solidity 0.5.7
// END 
// Can be called manually after the game ends
// Sends pot to winner and snailthrone
function End() public {
        require(now > timerEnd, "game is still running!");
        
        uint256 _throneReward = pot.mul(shareToThrone).div(100);
        pot = pot.sub(_throneReward);
        (bool success, bytes memory data) = SNAILTHRONE.call.value(_throneReward)("");
        require(success);
        
        uint256 _winnerReward = pot;
        pot = 0;
        leader.transfer(_winnerReward);
        
        emit GameEnd(leader, _winnerReward, _throneReward, number);
    }
// Solidity 0.8.7
// ref: https://blogs.sas.com/content/iml/2016/05/16/babylonian-square-roots.html
function sqrt(uint256 x) internal pure returns (uint256 y) {
        uint256 z = (x + 1) / 2;
        y = x;
        while (z < y) {
            y = z;
            z = (x / z + z) / 2;
        }
    }
// Solidity 0.5.12
/**
 * @notice Hash an order into bytes32
 * @dev EIP-191 header and domain separator included
 * @param order Order The order to be hashed
 * @param domainSeparator bytes32
 * @return bytes32 A keccak256 abi.encodePacked value
 */
function hashOrder(
    Order calldata order,
    bytes32 domainSeparator
  ) external pure returns (bytes32) {
    return keccak256(abi.encodePacked(
      EIP191_HEADER,
      domainSeparator,
      keccak256(abi.encode(
        ORDER_TYPEHASH,
        order.nonce,
        order.expiry,
        keccak256(abi.encode(
          PARTY_TYPEHASH,
          order.signer.kind,
          order.signer.wallet,
          order.signer.token,
          order.signer.amount,
          order.signer.id
        )),
        keccak256(abi.encode(
          PARTY_TYPEHASH,
          order.sender.kind,
          order.sender.wallet,
          order.sender.token,
          order.sender.amount,
          order.sender.id
        )),
        keccak256(abi.encode(
          PARTY_TYPEHASH,
          order.affiliate.kind,
          order.affiliate.wallet,
          order.affiliate.token,
          order.affiliate.amount,
          order.affiliate.id
        ))
      ))
    ));
  }
// Solidity 0.5.12
/**
 * @notice Send an Order to be forwarded to Swap
 * @dev Sender must authorize this contract on the swapContract
 * @dev Sender must approve this contract on the wethContract
 * @param order Types.Order The Order
 */
function swap(
    Types.Order calldata order
  ) external payable {
    // Ensure msg.sender is sender wallet.
    require(order.sender.wallet == msg.sender,
      "MSG_SENDER_MUST_BE_ORDER_SENDER");
    // Ensure that the signature is present.
    // The signature will be explicitly checked in Swap.
    require(order.signature.v != 0,
      "SIGNATURE_MUST_BE_SENT");
    // Wraps ETH to WETH when the sender provides ETH and the order is WETH
    _wrapEther(order.sender);
    // Perform the swap.
    swapContract.swap(order);
    // Unwraps WETH to ETH when the sender receives WETH
    _unwrapEther(order.sender.wallet, order.signer.token, order.signer.amount);
  }
// Solidity 0.6.12
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint amount) public shouldStarted {
        require(amount <= _stakerTokenBalance[msg.sender] && _stakerTokenBalance[msg.sender] > 0, "Bad withdraw.");
        
        if(_stakerStakingPlan[msg.sender] == 4 || _stakerStakingPlan[msg.sender] == 5){
            require(block.timestamp >= _stakerStakingTime[msg.sender] + 30 days, "Early withdrawal available after 30 days");
        }
        
        updateRewards(msg.sender);
        
        _stakerTokenBalance[msg.sender] = _stakerTokenBalance[msg.sender].sub(amount);
        _stakerTokenRewardsClaimed[msg.sender] = 0;
        _stakerStakingPlan[msg.sender] = 0;


        if(_stakerWithdrawFeeRate[msg.sender] > 0){
            uint256 _burnedAmount = amount.mul(_stakerWithdrawFeeRate[msg.sender]).div(100);
            amount = amount.sub(_burnedAmount);
            token.burn(_burnedAmount);
        }
        
        token.safeTransfer(msg.sender, amount);
        
        emit Withdraw(msg.sender, amount);
    }
// Solidity 0.5.12
/**
 * @notice Send an Order to be forwarded to a Delegate
 * @dev Sender must authorize the Delegate contract on the swapContract
 * @dev Sender must approve this contract on the wethContract
 * @dev Delegate's tradeWallet must be order.sender - checked in Delegate
 * @param order Types.Order The Order
 * @param delegate IDelegate The Delegate to provide the order to
 */
function provideDelegateOrder(
    Types.Order calldata order,
    IDelegate delegate
  ) external payable {
    // Ensure that the signature is present.
    // The signature will be explicitly checked in Swap.
    require(order.signature.v != 0,
      "SIGNATURE_MUST_BE_SENT");
    // Wraps ETH to WETH when the signer provides ETH and the order is WETH
    _wrapEther(order.signer);
    // Provide the order to the Delegate.
    delegate.provideOrder(order);
    // Unwraps WETH to ETH when the signer receives WETH
    _unwrapEther(order.signer.wallet, order.sender.token, order.sender.amount);
  }
// Solidity 0.8.1
// Return accumulate rewards over the given _fromTime to _toTime.
function getGeneratedReward(uint256 _fromTime, uint256 _toTime) public view returns (uint256) {
        for (uint8 epochId = 2; epochId >= 1; --epochId) {
            if (_toTime >= epochEndTimes[epochId - 1]) {
                if (_fromTime >= epochEndTimes[epochId - 1]) {
                    return _toTime.sub(_fromTime).mul(epochApePerSecond[epochId]);
                }

                uint256 _generatedReward = _toTime.sub(epochEndTimes[epochId - 1]).mul(epochApePerSecond[epochId]);
                if (epochId == 1) {
                    return _generatedReward.add(epochEndTimes[0].sub(_fromTime).mul(epochApePerSecond[0]));
                }
                for (epochId = epochId - 1; epochId >= 1; --epochId) {
                    if (_fromTime >= epochEndTimes[epochId - 1]) {
                        return _generatedReward.add(epochEndTimes[epochId].sub(_fromTime).mul(epochApePerSecond[epochId]));
                    }
                    _generatedReward = _generatedReward.add(epochEndTimes[epochId].sub(epochEndTimes[epochId - 1]).mul(epochApePerSecond[epochId]));
                }
                return _generatedReward.add(epochEndTimes[0].sub(_fromTime).mul(epochApePerSecond[0]));
            }
        }
        return _toTime.sub(_fromTime).mul(epochApePerSecond[0]);
    }
// Solidity 0.5.12
/**
 * @notice Wraps ETH to WETH when a trade requires it
 * @param party Types.Party The side of the trade that may need wrapping
 */
function _wrapEther(Types.Party memory party) internal {
    // Check whether ether needs wrapping
    if (party.token == address(wethContract)) {
      // Ensure message value is param.
      require(party.amount == msg.value,
        "VALUE_MUST_BE_SENT");
      // Wrap (deposit) the ether.
      wethContract.deposit.value(msg.value)();
      // Transfer the WETH from the wrapper to party.
      // Return value not checked - WETH throws on error and does not return false
      wethContract.transfer(party.wallet, party.amount);
    } else {
      // Ensure no unexpected ether is sent.
      require(msg.value == 0,
        "VALUE_MUST_BE_ZERO");
    }
  }
// Solidity 0.5.12
/**
 * @notice Unwraps WETH to ETH when a trade requires it
 * @dev The unwrapping only succeeds if recipientWallet has approved transferFrom
 * @param recipientWallet address The trade recipient, who may have received WETH
 * @param receivingToken address The token address the recipient received
 * @param amount uint256 The amount of token the recipient received
 */
function _unwrapEther(address recipientWallet, address receivingToken, uint256 amount) internal {
    // Check whether ether needs unwrapping
    if (receivingToken == address(wethContract)) {
      // Transfer weth from the recipient to the wrapper.
      wethContract.transferFrom(recipientWallet, address(this), amount);
      // Unwrap (withdraw) the ether.
      wethContract.withdraw(amount);
      // Transfer ether to the recipient.
      // solium-disable-next-line security/no-call-value
      (bool success, ) = recipientWallet.call.value(amount)("");
      require(success, "ETH_RETURN_FAILED");
    }
  }
// Solidity 0.8.1
// Deposit LP tokens.
function deposit(uint256 _pid, uint256 _amount) public {
        address _sender = msg.sender;
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][_sender];
        updatePool(_pid);
        if (user.amount > 0) {
            uint256 _pending = user.amount.mul(pool.accApePerShare).div(1e18).sub(user.rewardDebt);
            if (_pending > 0) {
                safeApeTransfer(_sender, _pending);
                emit RewardPaid(_sender, _pending);
            }
        }
        if (_amount > 0) {
            pool.token.safeTransferFrom(_sender, address(this), _amount);
            user.amount = user.amount.add(_amount);
        }
        user.rewardDebt = user.amount.mul(pool.accApePerShare).div(1e18);
        emit Deposit(_sender, _pid, _amount);
    }
// Solidity 0.8.1
// Withdraw LP tokens.
function withdraw(uint256 _pid, uint256 _amount) public {
        address _sender = msg.sender;
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][_sender];
        require(user.amount >= _amount, "withdraw: not good");
        updatePool(_pid);
        uint256 _pending = user.amount.mul(pool.accApePerShare).div(1e18).sub(user.rewardDebt);
        if (_pending > 0) {
            safeApeTransfer(_sender, _pending);
            emit RewardPaid(_sender, _pending);
        }
        if (_amount > 0) {
            user.amount = user.amount.sub(_amount);
            pool.token.safeTransfer(_sender, _amount);
        }
        user.rewardDebt = user.amount.mul(pool.accApePerShare).div(1e18);
        emit Withdraw(_sender, _pid, _amount);
    }
// Solidity 0.8.1
// Safe ape transfer function, just in case if rounding error causes pool to not have enough Apes.
function safeApeTransfer(address _to, uint256 _amount) internal {
        uint256 _apeBal = ape.balanceOf(address(this));
        if (_apeBal > 0) {
            if (_amount > _apeBal) {
                ape.safeTransfer(_to, _apeBal);
            } else {
                ape.safeTransfer(_to, _amount);
            }
        }
    }
// Solidity 0.4.19
// Transfer amount of tokens from sender account to recipient.
// Only callable after the crowd fund is completed
function transfer(address _to, uint _value)
  {
    if (_to == msg.sender) return; // no-op, allow even during crowdsale, in order to work around using grantVestedTokens() while in crowdsale
   // if (!isCrowdfundCompleted()) throw;
    super.transfer(_to, _value);
  }
// Solidity 0.4.19
//constant function returns the current XFM price.
function getPriceRate()
      constant
      returns (uint o_rate)
  {
      uint delta = now;
      if (delta < PRESALE_START_WEEK1) return PRICE_PRESALE_START;
      if (delta < PRESALE_START_WEEK2) return PRICE_PRESALE_WEEK1;
      if (delta < PRESALE_START_WEEK3) return PRICE_PRESALE_WEEK2;
      if (delta < CROWDSALE_START) return PRICE_PRESALE_WEEK3;
      return (PRICE_CROWDSALE);
  }
// Solidity 0.4.19
// Returns `amount` in scope as the number of XFM tokens that it will purchase.
function processPurchase(uint _rate, uint _remaining)
    internal
    returns (uint o_amount)
  {
    o_amount = calcAmount(msg.value, _rate);

    if (o_amount > _remaining) throw;
    if (!multisigAddress.send(msg.value)) throw;

    balances[ownerAddress] = balances[ownerAddress].sub(o_amount);
    balances[msg.sender] = balances[msg.sender].add(o_amount);

    XFMSold += o_amount;
    etherRaised += msg.value;
  }
// Solidity 0.4.19
// To be called at the end of crowdfund period
// WARNING: transfer(), which is called by grantVestedTokens(), wants a minimum message length
function grantVested(address _XferMoneyTeamAddress, address _XferMoneyFundAddress)
    is_crowdfund_completed
    only_owner
    is_not_halted
  {
    // Grant tokens pre-allocated for the team
    grantVestedTokens(
      _XferMoneyTeamAddress, ALLOC_TEAM,
      uint64(now), uint64(now) + 91 days , uint64(now) + 365 days, 
      false, false
    );

    // Grant tokens that remain after crowdsale to the XferMoney fund, vested for 2 years
    grantVestedTokens(
      _XferMoneyFundAddress, balances[ownerAddress],
      uint64(now), uint64(now) + 182 days , uint64(now) + 730 days, 
      false, false
    );
  }
// Solidity 0.8.4
// List every tokens an owner owns
function tokensOfOwner(address _owner) public view returns (uint256[] memory) {
        uint256 tokenCount = balanceOf(_owner);
        if (tokenCount == 0) {
            return new uint256[](0);
        } else {
            uint256[] memory result = new uint256[](tokenCount);
            uint256 index;
            for (index = 0; index < tokenCount; index++) {
                result[index] = tokenOfOwnerByIndex(_owner, index);
            }
            return result;
        }
    }
// Solidity 0.8.4
// Before any transfer, add the new owner to the holders list of this token
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override {
        super._beforeTokenTransfer(from, to, tokenId);

        // Save the holder only once per token
        if (!_alreadyHoldToken[tokenId][to]) {
            cardInfo[tokenId].holders.push(to);
            _alreadyHoldToken[tokenId][to] = true;
        }
    }
// Solidity 0.7.1
//Safe Maths
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
    if (a == 0) {
      return 0;
    }
    uint256 c = a * b;
    assert(c / a == b);
    return c;
  }
// Solidity 0.4.19
/* Buy Token 1 token for x ether */
function buyTokens() public whenCrowdsaleNotPaused payable {
        require(!accounts[msg.sender].blacklisted);
        require(msg.value > 0);
        require(msg.value >= _tokenPrice);
        require(msg.value % _tokenPrice == 0);
        var numTokens = msg.value / _tokenPrice;
        require(numTokens >= _minimumTokens);
        balanceOf[msg.sender] += numTokens;
        Transfer(0, msg.sender, numTokens);
        wallet.transfer(msg.value);
        accounts[msg.sender].balance = accounts[msg.sender].balance.add(numTokens);
        insertShareholder(msg.sender);
        if (msg.sender != owner) {
            totalSupply += numTokens;
        }
    }
// Solidity 0.6.12
/**
 * @dev Function to mint tokens: uri must be is unique and msg.value sufficient
 * @param to The address that will receive the minted tokens.
 * @param tokenURI The token URI of the minted token.
 * @return A boolean that indicates if the operation was successful.
 */
function mintWithTokenURI(address to, string memory tokenURI) public payable returns (bool) {
        require(_enabled == true, "Minting has been disabled");

        // Confirm payment
        require(msg.value == mintPrice, "");

        uint256 tokenId = ++_totalMinted;

        require(bytes(tokenURI).length > 0, "Invalid tokenURI");

        // Set and validate tokenURI unique
        _mapTokenURIToId(tokenURI, tokenId);

        _mint(to, tokenId);
        _setTokenURI(tokenId, tokenURI);
        return true;
    }
// Solidity 0.4.21
//An identifier: eg SBX
function scearu(
        uint256 _initialAmount,
        string _tokenName,
        uint8 _decimalUnits,
        string _tokenSymbol
    ) public {
        balances[msg.sender] = _initialAmount;               // Give the creator all initial tokens
        totalSupply = _initialAmount;                        // Update total supply
        name = _tokenName;                                   // Set the name for display purposes
        decimals = _decimalUnits;                            // Amount of decimals for display purposes
        symbol = _tokenSymbol;                               // Set the symbol for display purposes
    }
// Solidity 0.8.7
/// @notice Harvest profits while preventing a sandwich attack exploit.
/// @param maxBalance The maximum balance of the underlying token that is allowed to be in BentoBox.
/// @param rebalance Whether BentoBox should rebalance the strategy assets to acheive it's target allocation.
/// @param maxChangeAmount When rebalancing - the maximum amount that will be deposited to or withdrawn from a strategy to BentoBox.
/// @param harvestRewards If we want to claim any accrued reward tokens
/// @dev maxBalance can be set to 0 to keep the previous value.
/// @dev maxChangeAmount can be set to 0 to allow for full rebalancing.
function safeHarvest(
        uint256 maxBalance,
        bool rebalance,
        uint256 maxChangeAmount,
        bool harvestRewards
    ) external onlyExecutor {
        if (harvestRewards) {
            _harvestRewards();
        }

        if (maxBalance > 0) {
            maxBentoBoxBalance = maxBalance;
        }

        IBentoBoxMinimal(bentoBox).harvest(strategyToken, rebalance, maxChangeAmount);
    }
// Solidity 0.6.12
// Deposit LP tokens to TravelAgency for CITY allocation.
function deposit(uint256 _pid, uint256 _amount) public {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        updatePool(_pid);
        if (user.amount > 0) {
            uint256 pending = user.amount.mul(pool.accCityPerShare).div(1e12).sub(user.rewardDebt);
            safeCityTransfer(msg.sender, pending);
        }
        pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);
        user.amount = user.amount.add(_amount);
        user.rewardDebt = user.amount.mul(pool.accCityPerShare).div(1e12);
        emit Deposit(msg.sender, _pid, _amount);
    }
// Solidity 0.8.7
/// @inheritdoc IStrategy
function withdraw(uint256 amount) external override isActive onlyBentoBox returns (uint256 actualAmount) {
        _withdraw(amount);
        /// @dev Make sure we send and report the exact same amount of tokens by using balanceOf.
        actualAmount = IERC20(strategyToken).balanceOf(address(this));
        IERC20(strategyToken).safeTransfer(bentoBox, actualAmount);
    }
// Solidity 0.8.7
/// @inheritdoc IStrategy
/// @dev do not use isActive modifier here; allow bentobox to call strategy.exit() multiple times
function exit(uint256 balance) external override onlyBentoBox returns (int256 amountAdded) {
        _exit();
        /// @dev Check balance of token on the contract.
        uint256 actualBalance = IERC20(strategyToken).balanceOf(address(this));
        /// @dev Calculate tokens added (or lost).
        amountAdded = int256(actualBalance) - int256(balance);
        /// @dev Transfer all tokens to bentoBox.
        IERC20(strategyToken).safeTransfer(bentoBox, actualBalance);
        /// @dev Flag as exited, allowing the owner to manually deal with any amounts available later.
        exited = true;
    }
// Solidity 0.4.26
//***************************** TRANSFER TOKENS FROM YOUR ACCOUNT **************
function transfer(address _to, uint256 _val)
public returns (bool) {
require(holders[msg.sender] >= _val);
require(msg.sender != _to);
assert(_val <= holders[msg.sender]);
holders[msg.sender] = holders[msg.sender] - _val;
holders[_to] = holders[_to] + _val;
assert(holders[_to] >= _val);
emit Transfer(msg.sender, _to, _val);
return true;
}
// Solidity 0.4.26
//**************************** TRANSFER TOKENS FROM ANOTHER ACCOUNT ************
function transferFrom(address _from, address _to, uint256 _val)
public returns (bool) {
require(holders[_from] >= _val);
require(approach[_from][msg.sender] >= _val);
assert(_val <= holders[_from]);
holders[_from] = holders[_from] - _val;
assert(_val <= approach[_from][msg.sender]);
approach[_from][msg.sender] = approach[_from][msg.sender] - _val;
holders[_to] = holders[_to] + _val;
assert(holders[_to] >= _val);
emit Transfer(_from, _to, _val);
return true;
}
// Solidity 0.8.7
/**
 * @notice Buy function. Used to buy tokens using ETH, USDT or USDC
 * @param _paymentAmount    --> Result of multiply number of tokens to buy per price per token. Must be always multiplied per 1000 to avoid decimals
 * @param _tokenPayment     --> Address of the payment token (or 0x0 if payment is ETH)
 */
function buy(uint256 _paymentAmount, address _tokenPayment) external payable {
        require(_isICOActive() == true, "ICONotActive");
               
        uint256 paidTokens = 0;

        if (msg.value == 0) {
            // Stable coin payment
            require(_paymentAmount > 0, "BadPayment");
            require(_tokenPayment == usdtToken || _tokenPayment == usdcToken, "TokenNotSupported");
            require(IERC20(_tokenPayment).transferFrom(msg.sender, address(this), _paymentAmount));
            paidTokens = _paymentAmount * 2666666666666666667 / 1000000000000000000;   // 0.375$ per token in the ICO
        } else {
            // ETH Payment
            uint256 usdETH = _getUSDETHPrice();
            uint256 paidUSD = msg.value * usdETH / 10**18;
            paidTokens = paidUSD * 2666666666666666666 / 1000000000000000000;   // 0.375$ per token in the ICO
        }

        require((paidTokens + 1*10**18) >= minTokensBuyAllowed, "BadTokensQuantity");    // One extra token as threshold rounding decimals
        require(maxICOTokens - icoTokensBought >= paidTokens, "NoEnoughTokensInICO");
        userBoughtTokens[msg.sender] += paidTokens;
        icoTokensBought += paidTokens;
        if (maxICOTokens - icoTokensBought < minTokensBuyAllowed) {
            // We finish the ICO
            icoFinished = true;
            emit onICOFinished(block.timestamp);
        }

        emit onTokensBought(msg.sender, paidTokens, _paymentAmount, _tokenPayment);
    }
// Solidity 0.8.7
/**
 * @notice Get the vesting unlock dates
 * @param _period --> There are 4 periods (0,1,2,3)
 * @return _date Returns the date in UnixDateTime UTC format
 */
function getVestingDate(uint256 _period) external view returns(uint256 _date) {
        if (_period == 0) {
            _date = tokenListingDate;
        } else if (_period == 1) {
            _date = tokenListingDate + _3_MONTHS_IN_SECONDS;
        } else if (_period == 2) {
            _date = tokenListingDate + _6_MONTHS_IN_SECONDS;
        } else if (_period == 3) {
            _date = tokenListingDate + _9_MONTHS_IN_SECONDS;
        }
    }
// Solidity 0.8.7
/**
 * @notice Uses Chainlink to query the USDETH price
 * @return Returns the ETH amount in weis (Fixed value of 3932.4 USDs in localhost development environments)
 */
function _getUSDETHPrice() internal view returns(uint256) {
        int price = 0;

        if (address(priceFeed) != address(0)) {
            (, price, , , ) = priceFeed.latestRoundData();
        } else {
            // For local testing
            price = 393240000000;
        }

        return uint256(price * 10**10);
    }