lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.1
/**
 * @dev Give away attribution
 *
 * Requirements:
 * 
 * The recipient must be different than 0
 * The amount of token requested must be within the reverse
 * The amount requested must be supperior to 0
 *  
 */
function giveAway (address to, uint amountToMint) external onlyOwner{
         require (to != address(0), "address 0 requested");
         require (amountToMint <= _reserved, "You requested more than the reserved token");
         require (amountToMint > 0, "Amount Issue");
        
        uint currentSupply = totalSupply();   
        _reserved = _reserved - amountToMint;
         for (uint i; i < amountToMint ; i++) {
            _safeMint(to, currentSupply + i);
        }      
     }
// Solidity 0.8.1
/**
 * @dev Return an array of token Id owned by `owner`
 */
function getWallet(address _owner) public view returns(uint [] memory){
        uint numberOwned = balanceOf(_owner);
        uint [] memory idItems = new uint[](numberOwned);
        
        for (uint i = 0; i < numberOwned; i++){
            idItems[i] = tokenOfOwnerByIndex(_owner,i);
        }
        return idItems;
    }
// Solidity 0.5.9
// https://ethereum.stackexchange.com/questions/19341/address-send-vs-address-transfer-best-practice-usage
function approve(
        address payable _destination,
        uint256 _amount
    ) public isMember sufficient(_amount) returns (bool) {
        Approval storage approval  = approvals[_destination][_amount]; // Create new project

        if (!approval.coinciedeParties[msg.sender]) {
            approval.coinciedeParties[msg.sender] = true;
            approval.coincieded += 1;

            emit ConfirmationReceived(msg.sender, _destination, ETHER_ADDRESS, _amount);

            if (
                approval.coincieded >= signatureMinThreshold &&
                !approval.transfered
            ) {
                approval.transfered = true;

                uint256 _amountToWithhold = _amount.mul(serviceFeeMicro).div(1000000);
                uint256 _amountToRelease = _amount.sub(_amountToWithhold);

                _destination.transfer(_amountToRelease);    // Release funds
                serviceAddress.transfer(_amountToWithhold); // Take service margin

                emit ConsensusAchived(_destination, ETHER_ADDRESS, _amount);
            }

            return true;
        } else {
            // Raise will eat rest of gas. Lets not waist it. Just record this approval instead
            return false;
        }
    }
// Solidity 0.4.25
// @notice owner can start the sale by transferring in required amount of MYB
// @dev the start time is used to determine which day the sale is on (day 0 = first day)
function startSale(uint _timestamp)
  external
  onlyOwner
  returns (bool){
    require(start == 0, 'Already started');
    require(_timestamp >= now  && _timestamp.sub(now) < 2592000, 'Start time not in range');
    uint saleAmount = tokensPerDay.mul(365);
    require(mybToken.transferFrom(msg.sender, address(this), saleAmount));
    start = _timestamp;
    emit LogSaleStarted(msg.sender, mybitFoundation, developmentFund, saleAmount, _timestamp);
    return true;
  }
// Solidity 0.4.25
// @notice Send an index of days and your payment will be divided equally among them
// @dev WEI sent must divide equally into number of days.
function batchFund(uint16[] _day)
  payable
  external
  returns (bool) {
    require(_day.length <= 50);       // Limit to 50 days to avoid exceeding blocklimit
    require(msg.value >= _day.length);   // need at least 1 wei per day
    uint256 amountPerDay = msg.value.div(_day.length);
    assert (amountPerDay.mul(_day.length) == msg.value);   // Don't allow any rounding error
    for (uint8 i = 0; i < _day.length; i++){
      require(addContribution(msg.sender, amountPerDay, _day[i]));
    }
    return true;
  }
// Solidity 0.4.25
// @notice Updates claimableTokens, sends all wei to the token holder
function withdraw(uint16 _day)
  external
  returns (bool) {
      require(dayFinished(_day), "day has not finished funding");
      Day storage thisDay = day[_day];
      uint256 amount = getTokensOwed(msg.sender, _day);
      delete thisDay.weiContributed[msg.sender];
      mybToken.transfer(msg.sender, amount);
      emit LogTokensCollected(msg.sender, amount, _day);
      return true;
  }
// Solidity 0.4.25
// @notice Updates claimableTokens, sends all tokens to contributor from previous days
// @param (uint16[]) _day, list of token sale days msg.sender contributed wei towards
function batchWithdraw(uint16[] _day)
  external
  returns (bool) {
    uint256 amount;
    require(_day.length <= 50);     // Limit to 50 days to avoid exceeding blocklimit
    for (uint8 i = 0; i < _day.length; i++){
      require(dayFinished(_day[i]));
      uint256 amountToAdd = getTokensOwed(msg.sender, _day[i]);
      amount = amount.add(amountToAdd);
      delete day[_day[i]].weiContributed[msg.sender];
      emit LogTokensCollected(msg.sender, amountToAdd, _day[i]);
    }
    mybToken.transfer(msg.sender, amount);
    return true;
  }
// Solidity 0.4.25
// @notice updates ledger with the contribution from _investor
// @param (address) _investor: The sender of WEI to the contract
// @param (uint) _amount: The amount of WEI to add to _day
// @param (uint16) _day: The day to fund
function addContribution(address _investor, uint _amount, uint16 _day)
  internal
  returns (bool) {
    require(_amount > 0, "must send ether with the call");
    require(duringSale(_day), "day is not during the sale");
    require(!dayFinished(_day), "day has already finished");
    Day storage today = day[_day];
    today.totalWeiContributed = today.totalWeiContributed.add(_amount);
    today.weiContributed[_investor] = today.weiContributed[_investor].add(_amount);
    emit LogTokensPurchased(_investor, _amount, _day);
    return true;
  }
// Solidity 0.4.25
// @notice gets the total amount of mybit owed to the contributor
// @dev this function doesn't check for duplicate days. Output may not reflect actual amount owed if this happens.
function getTotalTokensOwed(address _contributor, uint16[] _days)
  public
  view
  returns (uint256 amount) {
    require(_days.length < 100);          // Limit to 100 days to avoid exceeding block gas limit
    for (uint16 i = 0; i < _days.length; i++){
      amount = amount.add(getTokensOwed(_contributor, _days[i]));
    }
    return amount;
  }
// Solidity 0.4.25
// @notice returns true if _day is finished
function dayFinished(uint16 _day)
  public
  view
  returns (bool) {
    if (now <= start) { return false; }   // hasn't yet reached first day, so cannot be finished
    return dayFor(now) > _day;
  }
// Solidity 0.6.2
/**
 * @dev Implementation of IERC777Recipient.
 */
function tokensReceived(
        address /*operator*/,
        address from,
        address to,
        uint256 amount,
        bytes calldata userData,
        bytes calldata /*operatorData*/
    ) external override {
        address _tokenAddress = msg.sender;
        require(supportedTokens.contains(_tokenAddress), "caller is not a supported ERC777 token!");
        require(to == address(this), "Token receiver is not this contract");
        if (userData.length > 0) {
            require(amount > 0, "Token amount must be greater than zero!");
            (bytes32 tag, string memory _destinationAddress) = abi.decode(userData, (bytes32, string));
            require(tag == keccak256("ERC777-pegIn"), "Invalid tag for automatic pegIn on ERC777 send");
            emit PegIn(_tokenAddress, from, amount, _destinationAddress);
        }
    }
// Solidity 0.4.16
// Called to reward current KOTH winner and start new game
function rewardKoth() public {
        if (msg.sender == feeAddress && lastBlock > 0 && block.number > lastBlock) {
            uint fee = pot / 20; // 5%
            KothWin(gameId, betId, koth, highestBet, pot, fee, firstBlock, lastBlock);

            uint netPot = pot - fee;
            address winner = koth;
            resetKoth();
            winner.transfer(netPot);

            // Make sure we never go below minPot
            if (this.balance - fee >= minPot) {
                feeAddress.transfer(fee);
            }
        }
    }
// Solidity 0.4.18
//a new 'block' to be mined
function _startNewMiningEpoch() internal 
      {
      //if max supply for the era will be exceeded next reward round then enter the new era before that happens
      //4 is the final reward era, almost all tokens minted
      //once the final era is reached, more tokens will not be given out because the assert function

      if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 12)
         {
         rewardEra = rewardEra + 1;
         maxSupplyForEra = eraVsMaxSupplyFactor[rewardEra].mul(1000000000) * 10**uint(decimals);
         }

      epochCount = epochCount.add(1);

      //every so often, readjust difficulty. Dont readjust when deploying
      if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
         {
         _reAdjustDifficulty();
         }

      //make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
      //do this last since this is a protection mechanism in the mint() function
      challengeNumber = block.blockhash(block.number - 1);
      }
// Solidity 0.4.18
//10,000,000,000 coins total
//reward begins at 100,000 and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) 
      {
      //once we get half way thru the coins, only get 50,000 per block
      //every reward era, the reward amount halves.
      return (100000 * 10**uint(decimals) ).div(5).mul(eraVsMaxSupplyFactor[rewardEra]) ;
      }
// Solidity 0.8.4
/// @notice Create an option order for a given NFT
/// @param optionPrice the price of the option
/// @param strikePrice the strike price of the option
/// @param settlementTimestamp the option maturity timestamp
/// @param nftId the token ID of the NFT relevant of this order
/// @param nftContract the address of the NFT contract
/// @param optionType the type of the option (CallBuy, CallSale, PutBuy or PutSale)
function makeOrder(
        uint256 optionPrice,
        uint256 strikePrice,
        uint256 settlementTimestamp,
        uint256 nftId,
        address nftContract,
        NFTeacket.OptionType optionType
    ) external payable onlyWhenNFTeacketSet {
        require(
            settlementTimestamp > block.timestamp,
            "NFTea: Incorrect timestamp"
        );

        if (optionType == NFTeacket.OptionType.CallBuy) {
            _requireEthSent(optionPrice);
        } else if (optionType == NFTeacket.OptionType.CallSale) {
            _requireEthSent(0);
            _lockNft(nftId, nftContract);
        } else if (optionType == NFTeacket.OptionType.PutBuy) {
            _requireEthSent(optionPrice);
        } else {
            // OptionType.Putsale
            _requireEthSent(strikePrice);
        }

        NFTeacket.OptionDataMaker memory data = NFTeacket.OptionDataMaker({
            price: optionPrice,
            strike: strikePrice,
            settlementTimestamp: settlementTimestamp,
            nftId: nftId,
            nftContract: nftContract,
            takerTicketId: 0,
            optionType: optionType
        });

        uint256 makerTicketId = NFTeacket(nfteacket).mintMakerTicket(
            msg.sender,
            data
        );

        emit OrderCreated(makerTicketId, data);
    }
// Solidity 0.8.4
/// @notice Cancel a non filled order
/// @param makerTicketId the ticket ID associated with the order
function cancelOrder(uint256 makerTicketId) external onlyWhenNFTeacketSet {
        NFTeacket _nfteacket = NFTeacket(nfteacket);

        // Check the seender is the maker
        _requireTicketOwner(msg.sender, makerTicketId);

        NFTeacket.OptionDataMaker memory optionData = _nfteacket
            .ticketIdToOptionDataMaker(makerTicketId);

        require(optionData.takerTicketId == 0, "NFTea: Order already filled");

        if (optionData.optionType == NFTeacket.OptionType.CallBuy) {
            _transferEth(msg.sender, optionData.price);
        } else if (optionData.optionType == NFTeacket.OptionType.CallSale) {
            _transferNft(
                address(this),
                msg.sender,
                optionData.nftId,
                optionData.nftContract
            );
        } else if (optionData.optionType == NFTeacket.OptionType.PutBuy) {
            _transferEth(msg.sender, optionData.price);
        } else {
            // OptionType.Putsale
            _transferEth(msg.sender, optionData.strike);
        }

        _nfteacket.burnTicket(makerTicketId);

        emit OrderCancelled(makerTicketId);
    }
// Solidity 0.8.4
/// @dev When a trader wants to sell a call, he has to lock his NFT
/// until maturity
/// @param nftId the token ID of the NFT to lock
/// @param nftContractAddress address of the NFT contract
function _lockNft(uint256 nftId, address nftContractAddress) private {
        IERC721 nftContract = IERC721(nftContractAddress);
        address owner = nftContract.ownerOf(nftId);

        require(owner == msg.sender, "NFTea : Not nft owner");

        require(
            address(this) == owner ||
                nftContract.getApproved(nftId) == address(this) ||
                nftContract.isApprovedForAll(owner, address(this)),
            "NFTea : Contract not approved, can't lock nft"
        );

        // Lock the nft by transfering it to the contract
        nftContract.transferFrom(msg.sender, address(this), nftId);
    }
// Solidity 0.6.12
/**
 * @dev See {ERC20-_beforeTokenTransfer}.
 *
 * Requirements:
 *
 * - minted tokens must not cause the total supply to go over the cap.
 */
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
        super._beforeTokenTransfer(from, to, amount);

        if (from == address(0)) { // When minting tokens
            require(totalSupply().add(amount) <= cap(), "ERC20Capped: cap exceeded");
        }
    }
// Solidity 0.4.23
/* mapping (uint => address) public wikiToOwner;
 mapping (address => uint) ownerWikiCount; */
function createWikiPage(string _title, string _articleHash, string _imageHash, uint _price) public onlyOwner returns (uint) {
    uint id = wikiPages.push(WikiPage(_title, _articleHash, _imageHash, _price)) - 1;
    /* tokenOwner[id] = msg.sender;
    ownedTokensCount[msg.sender]++; */
    _ownMint(id);
  }
// Solidity 0.4.25
/**
 * @return The result of safely multiplying x and y, interpreting the operands
 * as fixed-point decimals of the specified precision unit.
 *
 * @dev The operands should be in the form of a the specified unit factor which will be
 * divided out after the product of x and y is evaluated, so that product must be
 * less than 2**256.
 *
 * Unlike multiplyDecimal, this function rounds the result to the nearest increment.
 * Rounding is useful when you need to retain fidelity for small decimal numbers
 * (eg. small fractions or percentages).
 */
function _multiplyDecimalRound(uint x, uint y, uint precisionUnit)
        private
        pure
        returns (uint)
    {
        /* Divide by UNIT to remove the extra factor introduced by the product. */
        uint quotientTimesTen = x.mul(y) / (precisionUnit / 10);

        if (quotientTimesTen % 10 >= 5) {
            quotientTimesTen += 10;
        }

        return quotientTimesTen / 10;
    }
// Solidity 0.4.25
/**
 * @return The result of safely dividing x and y. The return value is as a rounded
 * decimal in the precision unit specified in the parameter.
 *
 * @dev y is divided after the product of x and the specified precision unit
 * is evaluated, so the product of x and the specified precision unit must
 * be less than 2**256. The result is rounded to the nearest increment.
 */
function _divideDecimalRound(uint x, uint y, uint precisionUnit)
        private
        pure
        returns (uint)
    {
        uint resultTimesTen = x.mul(precisionUnit * 10).div(y);

        if (resultTimesTen % 10 >= 5) {
            resultTimesTen += 10;
        }

        return resultTimesTen / 10;
    }
// Solidity 0.4.25
/**
 * @dev Convert a high precision decimal to a standard decimal representation.
 */
function preciseDecimalToDecimal(uint i)
        internal
        pure
        returns (uint)
    {
        uint quotientTimesTen = i / (UNIT_TO_HIGH_PRECISION_CONVERSION_FACTOR / 10);

        if (quotientTimesTen % 10 >= 5) {
            quotientTimesTen += 10;
        }

        return quotientTimesTen / 10;
    }
// Solidity 0.4.25
/**
 * @dev Perform an ERC20 token transferFrom. Designed to be called by transferFrom functions
 * possessing the optionalProxy or optionalProxy modifiers.
 */
function _transferFrom_byProxy(address sender, address from, address to, uint value)
        internal
        returns (bool)
    {
        /* Insufficient allowance will be handled by the safe subtraction. */
        tokenState.setAllowance(from, sender, tokenState.allowance(from, sender).sub(value));
        return _internalTransfer(from, to, value);
    }
// Solidity 0.4.25
/**
 * @dev Uses "exponentiation by squaring" algorithm where cost is 0(logN)
 * vs 0(N) for naive repeated multiplication.
 * Calculates x^n with x as fixed-point and n as regular unsigned int.
 * Calculates to 18 digits of precision with SafeDecimalMath.unit()
 */
function powDecimal(uint x, uint n)
        internal
        pure
        returns (uint)
    {
        // https://mpark.github.io/programming/2014/08/18/exponentiation-by-squaring/

        uint result = SafeDecimalMath.unit();
        while (n > 0) {
            if (n % 2 != 0) {
                result = result.multiplyDecimal(x);
            }
            x = x.multiplyDecimal(x);
            n /= 2;
        }
        return result;
    }
// Solidity 0.4.25
/**
 * @notice ERC20 transferFrom function
 */
function transferFrom(address from, address to, uint value)
        public
        optionalProxy
        returns (bool)
    {        
        // Skip allowance update in case of infinite allowance
        if (tokenState.allowance(from, messageSender) != uint(-1)) {
            // Reduce the allowance by the amount we're transferring.
            // The safeSub call will handle an insufficient allowance.
            tokenState.setAllowance(from, messageSender, tokenState.allowance(from, messageSender).sub(value));
        }
        
        return super._internalTransfer(from, to, value);
    }
// Solidity 0.4.25
/**
 * @return A unit amount of decaying inflationary supply from the INITIAL_WEEKLY_SUPPLY
 * @dev New token supply reduces by the decay rate each week calculated as supply = INITIAL_WEEKLY_SUPPLY * ()
 */
function tokenDecaySupplyForWeek(uint counter)
        public 
        pure
        returns (uint)
    {   
        // Apply exponential decay function to number of weeks since
        // start of inflation smoothing to calculate diminishing supply for the week.
        uint effectiveDecay = (SafeDecimalMath.unit().sub(DECAY_RATE)).powDecimal(counter);
        uint supplyForWeek = INITIAL_WEEKLY_SUPPLY.multiplyDecimal(effectiveDecay);

        return supplyForWeek;
    }
// Solidity 0.4.25
/**
 * @return A unit amount of terminal inflation supply
 * @dev Weekly compound rate based on number of weeks
 */
function terminalInflationSupply(uint totalSupply, uint numOfWeeks)
        public
        pure
        returns (uint)
    {   
        // rate = (1 + weekly rate) ^ num of weeks
        uint effectiveCompoundRate = SafeDecimalMath.unit().add(TERMINAL_SUPPLY_RATE_ANNUAL.div(52)).powDecimal(numOfWeeks);

        // return Supply * (effectiveRate - 1) for extra supply to issue based on number of weeks
        return totalSupply.multiplyDecimal(effectiveCompoundRate.sub(SafeDecimalMath.unit()));
    }
// Solidity 0.4.25
/**
 * @dev Take timeDiff in seconds (Dividend) and MINT_PERIOD_DURATION as (Divisor)
 * @return Calculate the numberOfWeeks since last mint rounded down to 1 week
 */
function weeksSinceLastIssuance()
        public
        view
        returns (uint)
    {
        // Get weeks since lastMintEvent
        // If lastMintEvent not set or 0, then start from inflation start date.
        uint timeDiff = lastMintEvent > 0 ? now.sub(lastMintEvent) : now.sub(INFLATION_START_DATE);
        return timeDiff.div(MINT_PERIOD_DURATION);
    }
// Solidity 0.4.25
/**
 * @notice Record the mint event from Synthetix by incrementing the inflation
 * week counter for the number of weeks minted (probabaly always 1)
 * and store the time of the event.
 * @param supplyMinted the amount of SNX the total supply was inflated by.
 * */
function recordMintEvent(uint supplyMinted)
        external
        onlySynthetix
        returns (bool)
    {
        uint numberOfWeeksIssued = weeksSinceLastIssuance();

        // add number of weeks minted to weekCounter
        weekCounter = weekCounter.add(numberOfWeeksIssued);

        // Update mint event to latest week issued (start date + number of weeks issued * seconds in week)
        // 1 day time buffer is added so inflation is minted after feePeriod closes 
        lastMintEvent = INFLATION_START_DATE.add(weekCounter.mul(MINT_PERIOD_DURATION)).add(MINT_BUFFER);

        emit SupplyMinted(supplyMinted, numberOfWeeksIssued, lastMintEvent, now);
        return true;
    }
// Solidity 0.4.25
/**
 * @notice Retrieve the last update time for a list of currencies
 */
function lastRateUpdateTimesForCurrencies(bytes32[] currencyKeys)
        public
        view
        returns (uint[])
    {
        uint[] memory lastUpdateTimes = new uint[](currencyKeys.length);

        for (uint i = 0; i < currencyKeys.length; i++) {
            lastUpdateTimes[i] = lastRateUpdateTimes(currencyKeys[i]);
        }

        return lastUpdateTimes;
    }
// Solidity 0.4.25
/**
 * @notice Remove an inverse price for the currency key
 * @param currencyKey The currency to remove inverse pricing for
 */
function removeInversePricing(bytes32 currencyKey) external onlyOwner
    {
        require(inversePricing[currencyKey].entryPoint > 0, "No inverted price exists");

        inversePricing[currencyKey].entryPoint = 0;
        inversePricing[currencyKey].upperLimit = 0;
        inversePricing[currencyKey].lowerLimit = 0;
        inversePricing[currencyKey].frozen = false;

        // now remove inverted key from array
        bool wasRemoved = removeFromArray(currencyKey, invertedKeys);

        if (wasRemoved) {
            emit InversePriceConfigured(currencyKey, 0, 0, 0);
        }
    }
// Solidity 0.4.25
/**
 * @notice Add a pricing aggregator for the given key. Note: existing aggregators may be overridden.
 * @param currencyKey The currency key to add an aggregator for
 */
function addAggregator(bytes32 currencyKey, address aggregatorAddress) external onlyOwner {
        AggregatorInterface aggregator = AggregatorInterface(aggregatorAddress);
        require(aggregator.latestTimestamp() >= 0, "Given Aggregator is invalid");
        if (aggregators[currencyKey] == address(0)) {
            aggregatorKeys.push(currencyKey);
        }
        aggregators[currencyKey] = aggregator;
        emit AggregatorAdded(currencyKey, aggregator);
    }