lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.7
//Public sale minting
function mint(uint lootId) public payable nonReentrant {
        require(publicPrice <= msg.value, "Ether value sent is not correct");
        require(lootId > 8000 && lootId <= 12000, "Token ID invalid");
        require(!_exists(lootId), "This token has already been minted");

        _safeMint(msg.sender, lootId);
    }
// Solidity 0.5.8
/**
 *   Should allow any address to trigger it, but since the calls are atomic it should do only once per day
 */
function triggerTokenSend() external whenNotPaused  {
        /* Require TGE Date already been set */
        require(TGEDate != 0, "TGE date not set yet");
        /* TGE has not started */
        require(block.timestamp > TGEDate, "TGE still hasn´t started");
        /* Test that the call be only done once per day */
        require(block.timestamp.sub(lastDateDistribution) > 1 days, "Can only be called once a day");
        lastDateDistribution = block.timestamp;
        /* Go thru all tokenOwners */
        for(uint i = 0; i < tokenOwners.length; i++) {
            /* Get Address Distribution */
            DistributionStep[] memory d = distributions[tokenOwners[i]];
            /* Go thru all distributions array */
            for(uint j = 0; j < d.length; j++){
                if( (block.timestamp.sub(TGEDate) > d[j].unlockDay) /* Verify if unlockDay has passed */
                    && (d[j].currentAllocated > 0) /* Verify if currentAllocated > 0, so that address has tokens to be sent still */
                ){
                    uint256 sendingAmount;
                    sendingAmount = d[j].currentAllocated;
                    distributions[tokenOwners[i]][j].currentAllocated = distributions[tokenOwners[i]][j].currentAllocated.sub(sendingAmount);
                    distributions[tokenOwners[i]][j].amountSent = distributions[tokenOwners[i]][j].amountSent.add(sendingAmount);
                    require(erc20.transfer(tokenOwners[i], sendingAmount));
                }
            }
        }   
    }
// Solidity 0.5.7
/**
 * @dev Allows to lock an amount of tokens of specific addresses.
 * Available only to the owner.
 * Can be called once.
 * @param addresses array of addresses.
 * @param values array of amounts of tokens.
 * @param times array of Unix times.
 */
function lock(address[] calldata addresses, uint256[] calldata values, uint256[] calldata times) external onlyOwner {
        require(!_started);
        require(addresses.length == values.length && values.length == times.length);

        for (uint256 i = 0; i < addresses.length; i++) {
            require(balanceOf(addresses[i]) >= values[i]);

            if (!_locked[addresses[i]].locked) {
                _locked[addresses[i]].locked = true;
            }

            _locked[addresses[i]].batches.push(Batch(values[i], block.timestamp + times[i]));

            if (_locked[addresses[i]].batches.length > 1) {
                assert(
                    _locked[addresses[i]].batches[_locked[addresses[i]].batches.length - 1].amount
                    < _locked[addresses[i]].batches[_locked[addresses[i]].batches.length - 2].amount
                    &&
                    _locked[addresses[i]].batches[_locked[addresses[i]].batches.length - 1].time
                    > _locked[addresses[i]].batches[_locked[addresses[i]].batches.length - 2].time
                );
            }
        }

        _started = true;
    }
// Solidity 0.5.7
/**
 * @dev modified internal transfer function that prevents any transfer of locked tokens.
 * @param from address The address which you want to send tokens from
 * @param to The address to transfer to.
 * @param value The amount to be transferred.
 */
function _transfer(address from, address to, uint256 value) internal {
        if (_locked[from].locked) {
            for (uint256 i = 0; i < _locked[from].batches.length; i++) {
                if (block.timestamp <= _locked[from].batches[i].time) {
                    require(value <= balanceOf(from).sub(_locked[from].batches[i].amount));
                    break;
                }
            }
        }
        super._transfer(from, to, value);
    }
// Solidity 0.4.2
/**
 * transfer() - transfer tokens from msg.sender balance 
 *              to requested account
 *
 *  @param to    - target address to transfer tokens
 *  @param value - ammount of tokens to transfer
 *
 *  @return - success / failure of the transaction
 */
function transfer(address to, uint256 value) returns (bool success) {
        
        
        if (balances[msg.sender] >= value && value > 0) {

            // do actual tokens transfer       
            balances[msg.sender] -= value;
            balances[to]         += value;
            
            // rise the Transfer event
            Transfer(msg.sender, to, value);
            return true;
        } else {
            
            return false; 
        }
    }
// Solidity 0.4.2
/**
 * transferFrom() - 
 *
 *  @param from  - 
 *  @param to    - 
 *  @param value - 
 *
 *  @return 
 */
function transferFrom(address from, address to, uint256 value) returns (bool success) {
    
        if ( balances[from] >= value && 
             allowed[from][msg.sender] >= value && 
             value > 0) {
                                          
    
            // do the actual transfer
            balances[from] -= value;    
            balances[to] =+ value;            
            

            // addjust the permision, after part of 
            // permited to spend value was used
            allowed[from][msg.sender] -= value;
            
            // rise the Transfer event
            Transfer(from, to, value);
            return true;
        } else { 
            
            return false; 
        }
    }
// Solidity 0.4.2
/**
 *
 * approve() - function approves to a person to spend some tokens from 
 *           owner balance. 
 *
 *  @param spender - person whom this right been granted.
 *  @param value   - value to spend.
 * 
 *  @return true in case of succes, otherwise failure
 * 
 */
function approve(address spender, uint256 value) returns (bool success) {
        
        // now spender can use balance in 
        // ammount of value from owner balance
        allowed[msg.sender][spender] = value;
        
        // rise event about the transaction
        Approval(msg.sender, spender, value);
        
        return true;
    }
// Solidity 0.4.2
/**
 * Constructor of the contract.
 * 
 * Passes address of the account holding the value.
 * HackerGold contract itself does not hold any value
 * 
 * @param multisig address of MultiSig wallet which will hold the value
 */
function HackerGold(address multisig) {
        
        wallet = multisig;

        // set time periods for sale
        milestones = milestones_struct(
        
          1476799200,  // P1: GMT: 18-Oct-2016 14:00  => The Sale Starts
          1478181600,  // P2: GMT: 03-Nov-2016 14:00  => 1st Price Ladder 
          1479391200,  // P3: GMT: 17-Nov-2016 14:00  => Price Stable, 
                       //                                Hackathon Starts
          1480600800,  // P4: GMT: 01-Dec-2016 14:00  => 2nd Price Ladder
          1481810400,  // P5: GMT: 15-Dec-2016 14:00  => Price Stable
          1482415200   // P6: GMT: 22-Dec-2016 14:00  => Sale Ends, Hackathon Ends
        );
                
    }
// Solidity 0.4.2
/**
 * Creates HKG tokens.
 * 
 * Runs sanity checks including safety cap
 * Then calculates current price by getPrice() function, creates HKG tokens
 * Finally sends a value of transaction to the wallet
 * 
 * Note: due to lack of floating point types in Solidity,
 * contract assumes that last 3 digits in tokens amount are stood after the point.
 * It means that if stored HKG balance is 100000, then its real value is 100 HKG
 * 
 * @param holder token holder
 */
function createHKG(address holder) payable {
        
        if (now < milestones.p1) throw;
        if (now >= milestones.p6) throw;
        if (msg.value == 0) throw;
    
        // safety cap
        if (getTotalValue() + msg.value > SAFETY_LIMIT) throw; 
    
        uint tokens = msg.value * getPrice() * DECIMAL_ZEROS / 1 ether;

        totalSupply += tokens;
        balances[holder] += tokens;
        totalValue += msg.value;
        
        if (!wallet.send(msg.value)) throw;
    }
// Solidity 0.4.2
/**
 * Denotes complete price structure during the sale.
 *
 * @return HKG amount per 1 ETH for the current moment in time
 */
function getPrice() constant returns (uint result) {
        
        if (now < milestones.p1) return 0;
        
        if (now >= milestones.p1 && now < milestones.p2) {
        
            return BASE_PRICE;
        }
        
        if (now >= milestones.p2 && now < milestones.p3) {
            
            uint days_in = 1 + (now - milestones.p2) / 1 days; 
            return BASE_PRICE - days_in * 25 / 7;  // daily decrease 3.5
        }

        if (now >= milestones.p3 && now < milestones.p4) {
        
            return MID_PRICE;
        }
        
        if (now >= milestones.p4 && now < milestones.p5) {
            
            days_in = 1 + (now - milestones.p4) / 1 days; 
            return MID_PRICE - days_in * 25 / 7;  // daily decrease 3.5
        }

        if (now >= milestones.p5 && now < milestones.p6) {
        
            return FIN_PRICE;
        }
        
        if (now >= milestones.p6){

            return 0;
        }

     }
// Solidity 0.4.25
// ONLY-STAKING-CONTRACT FUNCTIONS
function validateJoinPackage(address _from, address _to, uint8 _type, uint _dabAmount, uint _gemAmount)
  onlyContractAContract
  public
  view
  returns (bool)
  {
    Package storage package = packages[_to];
    Balance storage balance = balances[_from];
    return _type > uint8(PackageType.M0) &&
      _type <= uint8(PackageType.M18) &&
      _type >= uint8(package.packageType) &&
      _dabAmount.add(_gemAmount) >= package.lastPackage &&
      (_gemAmount == 0 || balance.gemBalance >= int(_gemAmount));
  }
// Solidity 0.4.25
// PRIVATE-FUNCTIONS
function updatePackageInfo(address _to, PackageType _packageType, uint _dabAmount, uint _gemAmount) private {
    Package storage package = packages[_to];
    package.packageType = _packageType;
    package.lastPackage = _dabAmount.add(_gemAmount);
    package.dabAmount = package.dabAmount.add(_dabAmount);
    package.gemAmount = package.gemAmount.add(_gemAmount);
    package.startAt = now;
    package.endAt = package.startAt + parseEndAt(_packageType);
  }
// Solidity 0.4.24
/**
 * @dev Remove party.
 * @param _participantIndex Index of the participant in the participants array.
 */
function removeParty(uint256 _participantIndex) onlyOwner canRemoveParty external {
        require(_participantIndex < participants.length, "Participant does not exist");

        address participant = participants[_participantIndex];
        address token = tokenByParticipant[participant];

        delete isParticipant[participant];
        participants[_participantIndex] = participants[participants.length - 1];
        participants.length--;
        delete offerByToken[token];
        delete tokenByParticipant[participant];

        emit RemoveParty(participant);
    }
// Solidity 0.4.24
/**
 * @dev Withdraw tokens
 */
function withdraw() onlyParticipant canWithdraw external {
        for (uint i = 0; i < participants.length; i++) {
            address token = tokenByParticipant[participants[i]];
            SwapOffer storage offer = offerByToken[token];

            if (offer.participant == msg.sender) {
                continue;
            }

            uint256 tokenReceivers = participants.length - 1;
            uint256 tokensAmount = _withdrawableAmount(offer).div(tokenReceivers);

            offer.token.safeTransfer(msg.sender, tokensAmount);
            emit Withdraw(msg.sender, offer.token, tokensAmount);
            offer.withdrawnTokensForSwap = offer.withdrawnTokensForSwap.add(tokensAmount);
            offer.withdrawnTokensTotal = offer.withdrawnTokensTotal.add(tokensAmount);
        }
    }
// Solidity 0.4.24
/**
 * @dev Withdraw swap fee
 */
function withdrawFee() onlyOwner canWithdrawFee external {
        for (uint i = 0; i < participants.length; i++) {
            address token = tokenByParticipant[participants[i]];
            SwapOffer storage offer = offerByToken[token];

            uint256 tokensAmount = _withdrawableFee(offer);

            offer.token.safeTransfer(msg.sender, tokensAmount);
            emit WithdrawFee(offer.token, tokensAmount);
            offer.withdrawnFee = offer.withdrawnFee.add(tokensAmount);
            offer.withdrawnTokensTotal = offer.withdrawnTokensTotal.add(tokensAmount);
        }
    }
// Solidity 0.4.24
/**
 * @dev Reclaim tokens if a participant has deposited too much or if the swap has been canceled.
 */
function reclaim() onlyParticipant canReclaim external {
        address token = tokenByParticipant[msg.sender];

        SwapOffer storage offer = offerByToken[token];
        uint256 currentBalance = offer.token.balanceOf(address(this));
        uint256 availableForReclaim = currentBalance
            .sub(offer.tokensTotal.sub(offer.withdrawnTokensTotal));

        if (status == Status.SwapCanceled) {
            availableForReclaim = currentBalance;
        }

        offer.token.safeTransfer(offer.participant, availableForReclaim);
        emit Reclaim(offer.participant, offer.token, availableForReclaim);
    }
// Solidity 0.8.3
/**
 * @notice Create keeper and maintainer list
 * @dev Create lists and add governor into the list.
 * NOTE: Any function with onlyKeeper and onlyMaintainer modifier will not work until this function is called.
 * NOTE: Due to gas constraint this function cannot be called in constructor.
 */
function init() external onlyGovernor {
        require(address(keepers) == address(0), "list-already-created");
        IAddressListFactory _factory = IAddressListFactory(0xded8217De022706A191eE7Ee0Dc9df1185Fb5dA3);
        keepers = IAddressList(_factory.createList());
        maintainers = IAddressList(_factory.createList());
        // List creator i.e. governor can do job of keeper and maintainer.
        keepers.add(governor);
        maintainers.add(governor);
    }
// Solidity 0.8.3
/// @dev Add strategy
function addStrategy(
        address _strategy,
        uint256 _interestFee,
        uint256 _debtRatio,
        uint256 _debtRate
    ) public onlyGovernor {
        require(_strategy != address(0), "strategy-address-is-zero");
        require(!strategy[_strategy].active, "strategy-already-added");
        totalDebtRatio = totalDebtRatio + _debtRatio;
        require(totalDebtRatio <= MAX_BPS, "totalDebtRatio-above-max_bps");
        require(_interestFee <= MAX_BPS, "interest-fee-above-max_bps");
        StrategyConfig memory newStrategy =
            StrategyConfig({
                active: true,
                interestFee: _interestFee,
                debtRatio: _debtRatio,
                totalDebt: 0,
                totalProfit: 0,
                totalLoss: 0,
                debtRate: _debtRate,
                lastRebalance: block.number
            });
        strategy[_strategy] = newStrategy;
        strategies.push(_strategy);
        withdrawQueue.push(_strategy);
        emit StrategyAdded(_strategy, _interestFee, _debtRatio, _debtRate);
    }
// Solidity 0.8.3
/**
 * @dev Revoke and remove strategy from array. Update withdraw queue.
 * Withdraw queue order should not change after remove.
 * Strategy can be removed only after it has paid all debt.
 * Use migrate strategy if debt is not paid and want to upgrade strat.
 */
function removeStrategy(uint256 _index) external onlyGovernor {
        address _strategy = strategies[_index];
        require(strategy[_strategy].active, "strategy-not-active");
        require(strategy[_strategy].totalDebt == 0, "strategy-has-debt");
        delete strategy[_strategy];
        strategies[_index] = strategies[strategies.length - 1];
        strategies.pop();
        address[] memory _withdrawQueue = new address[](strategies.length);
        uint256 j;
        // After above update, withdrawQueue.length > strategies.length
        for (uint256 i = 0; i < withdrawQueue.length; i++) {
            if (withdrawQueue[i] != _strategy) {
                _withdrawQueue[j] = withdrawQueue[i];
                j++;
            }
        }
        withdrawQueue = _withdrawQueue;
    }
// Solidity 0.8.3
/// @dev update withdrawal queue
function updateWithdrawQueue(address[] memory _withdrawQueue) external onlyMaintainer {
        uint256 _length = _withdrawQueue.length;
        require(_length > 0, "withdrawal-queue-blank");
        require(_length == withdrawQueue.length && _length == strategies.length, "incorrect-withdraw-queue-length");
        for (uint256 i = 0; i < _length; i++) {
            require(strategy[_withdrawQueue[i]].active, "invalid-strategy");
        }
        withdrawQueue = _withdrawQueue;
    }
// Solidity 0.8.3
/**
 @dev Strategy call this in regular interval.
 @param _profit yield generated by strategy. Strategy get performance fee on this amount
 @param _loss  Reduce debt ,also reduce debtRatio, increase loss in record.
 @param _payback strategy willing to payback outstanding above debtLimit. no performance fee on this amount.
 when governance has reduced debtRatio of strategy, strategy will report profit and payback amount separately.
 */
function reportEarning(
        uint256 _profit,
        uint256 _loss,
        uint256 _payback
    ) external onlyStrategy {
        require(token.balanceOf(_msgSender()) >= (_profit + _payback), "insufficient-balance-in-strategy");
        if (_loss != 0) {
            _reportLoss(_msgSender(), _loss);
        }

        uint256 _overLimitDebt = _excessDebt(_msgSender());
        uint256 _actualPayback = _min(_overLimitDebt, _payback);
        if (_actualPayback != 0) {
            strategy[_msgSender()].totalDebt -= _actualPayback;
            totalDebt -= _actualPayback;
        }
        uint256 _creditLine = _availableCreditLimit(_msgSender());
        if (_creditLine != 0) {
            strategy[_msgSender()].totalDebt += _creditLine;
            totalDebt += _creditLine;
        }
        uint256 _totalPayback = _profit + _actualPayback;
        if (_totalPayback < _creditLine) {
            token.safeTransfer(_msgSender(), _creditLine - _totalPayback);
        } else if (_totalPayback > _creditLine) {
            token.safeTransferFrom(_msgSender(), address(this), _totalPayback - _creditLine);
        }
        if (_profit != 0) {
            strategy[_msgSender()].totalProfit += _profit;
            _transferInterestFee(_profit);
        }
        emit EarningReported(
            _msgSender(),
            _profit,
            _loss,
            _actualPayback,
            strategy[_msgSender()].totalDebt,
            totalDebt,
            _creditLine
        );
    }
// Solidity 0.8.3
/**
 * @dev Before burning hook.
 * withdraw amount from strategies
 */
function _beforeBurning(uint256 _share) internal override returns (uint256 actualWithdrawn) {
        uint256 _amount = (_share * pricePerShare()) / 1e18;
        uint256 _balanceNow = tokensHere();
        if (_amount > _balanceNow) {
            _withdrawCollateral(_amount - _balanceNow);
            _balanceNow = tokensHere();
        }
        actualWithdrawn = _balanceNow < _amount ? _balanceNow : _amount;
    }
// Solidity 0.8.3
/**
 @dev when a strategy report loss, its debtRatio decrease to get fund back quickly.
 */
function _reportLoss(address _strategy, uint256 _loss) internal {
        uint256 _currentDebt = strategy[_strategy].totalDebt;
        require(_currentDebt >= _loss, "loss-too-high");
        strategy[_strategy].totalLoss += _loss;
        strategy[_strategy].totalDebt -= _loss;
        totalDebt -= _loss;
        uint256 _deltaDebtRatio = _min((_loss * MAX_BPS) / totalValue(), strategy[_strategy].debtRatio);
        strategy[_strategy].debtRatio -= _deltaDebtRatio;
        totalDebtRatio -= _deltaDebtRatio;
    }
// Solidity 0.4.24
/**
 * @dev Check whether every participant has deposited enough tokens for the swap to be confirmed.
 */
function _haveEveryoneDeposited() internal view returns(bool) {
        for (uint i = 0; i < participants.length; i++) {
            address token = tokenByParticipant[participants[i]];
            SwapOffer memory offer = offerByToken[token];

            if (offer.token.balanceOf(address(this)) < offer.tokensTotal) {
                return false;
            }
        }

        return true;
    }
// Solidity 0.4.24
/**
 * @dev Get percent of unlocked tokens
 */
function _getUnlockedTokensPercentage() internal view returns(uint256) {
        for (uint256 i = lockupStages.length; i > 0; i--) {
            LockupStage storage stage = lockupStages[i - 1];
            uint256 stageBecomesActiveAt = startLockupAt.add(stage.secondsSinceLockupStart);

            if (now < stageBecomesActiveAt) {
                continue;
            }

            return stage.unlockedTokensPercentage;
        }
    }
// Solidity 0.6.12
/// @dev Allows to send a bid to the auction.
function bid()
        external
        payable
        isValidPayload
        timedTransitions
        atStage(Stages.AuctionStarted)
        returns (uint amount)
    {
        require(msg.value > 0);
        amount = msg.value;

        address payable receiver = _msgSender();

        // Prevent that more than 90% of tokens are sold. Only relevant if cap not reached.
        uint maxWei = maxTokenSold * calcTokenPrice() / 10**9 - totalReceived;
        uint maxWeiBasedOnTotalReceived = ceiling - totalReceived;
        if (maxWeiBasedOnTotalReceived < maxWei)
            maxWei = maxWeiBasedOnTotalReceived;

        // Only invest maximum possible amount.
        if (amount > maxWei) {
            amount = maxWei;
            // Send change back to receiver address.
            receiver.transfer(msg.value - amount);
        }

        // Forward funding to ether wallet
        (bool success,) = wallet.call.value(amount)("");
        require(success);

        bids[receiver] += amount;
        totalReceived += amount;
        emit BidSubmission(receiver, amount);

        // Finalize auction when maxWei reached
        if (amount == maxWei)
            finalizeAuction();
    }
// Solidity 0.6.7
/**
 * @notice Modify uint256 parameters
 * @param parameter Name of the parameter to modify
 * @param data New parameter value
 **/
function modifyParameters(bytes32 parameter, uint256 data) external isAuthorized {
        if (parameter == "validityFlag") {
          require(either(data == 1, data == 0), "ConverterFeed/invalid-data");
          validityFlag = data;
        } else if (parameter == "scalingFactor") {
          require(data > 0, "ConverterFeed/invalid-data");
          converterFeedScalingFactor = data;
        }
        else revert("ConverterFeed/modify-unrecognized-param");
        emit ModifyParameters(parameter, data);
    }
// Solidity 0.6.12
/// @notice Method for deploy new PiNFTTradable contract
/// @param _name Name of NFT contract
/// @param _symbol Symbol of NFT contract
function createNFTContract(string memory _name, string memory _symbol)
        external
        payable
        returns (address)
    {
        require(msg.value >= platformFee, "Insufficient funds.");
        (bool success,) = feeRecipient.call{value: msg.value}("");
        require(success, "Transfer failed");

        PiNFTTradablePrivate nft = new PiNFTTradablePrivate(
            _name,
            _symbol,
            auction,
            marketplace,
            bundleMarketplace,
            mintFee,
            feeRecipient
        );
        exists[address(nft)] = true;
        nft.transferOwnership(_msgSender());
        emit ContractCreated(_msgSender(), address(nft));
        return address(nft);
    }