lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.7
/// @dev Internal check to see if a the parents are a valid mating pair. DOES NOT
///  check ownership permissions (that is up to the caller).
/// @param _parent1 A reference to the Fish struct of the potential first parent
/// @param _parent1Id The first parent's ID.
/// @param _parent2 A reference to the Fish struct of the potential second parent
/// @param _parent2Id The second parent's ID.
function _isValidMatingPair(
        BitKoi storage _parent1,
        uint256 _parent1Id,
        BitKoi storage _parent2,
        uint256 _parent2Id
    )
        private
        view
        returns(bool)
    {
        // A Fish can't breed with itself!
        if (_parent1Id == _parent2Id) {
            return false;
        }

        //the fish have to have genes
        if (_parent1.genes == 0 || _parent2.genes == 0) {
            return false;
        }

        // Fish can't breed with their parents.
        if (_parent1.parent1Id == _parent1Id || _parent1.parent2Id == _parent2Id) {
            return false;
        }
        if (_parent2.parent1Id == _parent1Id || _parent2.parent2Id == _parent2Id) {
            return false;
        }

        // OK the tx if either fish is gen zero (no parent found).
        if (_parent2.parent1Id == 0 || _parent1.parent1Id == 0) {
            return true;
        }

        // Fish can't breed with full or half siblings.
        if (_parent2.parent1Id == _parent1.parent1Id || _parent2.parent1Id == _parent1.parent2Id) {
            return false;
        }
        if (_parent2.parent1Id == _parent1.parent1Id || _parent2.parent2Id == _parent1.parent2Id) {
            return false;
        }

        // gtg
        return true;
    }
// Solidity 0.8.7
/// @notice Checks to see if two BitKoi can breed together, including checks for
///     ownership and siring approvals. Doesn't check that both BitKoi are ready for
///     breeding (i.e. breedWith could still fail until the cooldowns are finished).
/// @param _parent1Id The ID of the proposed first parent.
/// @param _parent2Id The ID of the proposed second parent.
function canBreedWith(uint256 _parent1Id, uint256 _parent2Id)
        external
        view
        returns(bool)
    {
        require(_parent1Id > 0);
        require(_parent2Id > 0);
        BitKoi storage parent1 = bitKoi[_parent1Id];
        BitKoi storage parent2 = bitKoi[_parent2Id];
        return _isValidMatingPair(parent1, _parent1Id, parent2, _parent2Id);
    }
// Solidity 0.8.7
/// @dev Internal utility function to initiate breeding, assumes that all breeding
///     requirements have been checked.
function _breedWith(uint256 _parent1Id, uint256 _parent2Id) internal returns(uint256) {
        // Grab a reference to the Koi from storage.
        BitKoi storage parent1 = bitKoi[_parent1Id];
        BitKoi storage parent2 = bitKoi[_parent2Id];

        // Determine the higher generation number of the two parents
        uint16 parentGen = parent1.generation;
        if (parent2.generation > parent1.generation) {
            parentGen = parent2.generation;
        }

        uint256 bitKoiCoProceeds = msg.value;

        //transfer the breed fee less the pond cut to the CFO contract
        payable(address(cfoAddress)).transfer(bitKoiCoProceeds);

        // Make the new fish!
        address owner = bitKoiIndexToOwner[_parent1Id];
        uint256 newFishId = _createBitKoi(_parent1Id, _parent2Id, parentGen + 1, 0, owner);

        // Trigger the cooldown for both parents.
        _triggerCooldown(parent1);
        _triggerCooldown(parent2);

        // Emit the breeding event.
        emit BreedingSuccessful(bitKoiIndexToOwner[_parent1Id], newFishId, _parent1Id, _parent2Id, parent1.cooldownEndBlock);

        return newFishId;
    }
// Solidity 0.8.7
/// @dev we can create promo fish, up to a limit. Only callable by COO
/// @param _genes the encoded genes of the fish to be created, any value is accepted
/// @param _owner the future owner of the created fish. Default to contract COO
function createPromoFish(uint256 _genes, address _owner) external onlyCOO {
        address bitKoiOwner = _owner;

        if (bitKoiOwner == address(0)) {
             bitKoiOwner = cooAddress;
        }

        require(promoCreatedCount < PROMO_CREATION_LIMIT);

        promoCreatedCount++;
        _createBitKoi(0, 0, 0, _genes, bitKoiOwner);
    }
// Solidity 0.8.7
/// @notice Returns all the relevant information about a specific fish.
/// @param _id The ID of the fish we're looking up
function getBitKoi(uint256 _id)
        external
        view
        returns (
        bool isReady,
        uint256 cooldownIndex,
        uint256 nextActionAt,
        uint256 spawnTime,
        uint256 parent1Id,
        uint256 parent2Id,
        uint256 generation,
        uint256 cooldownEndBlock,
        uint256 genes
    ) {
        BitKoi storage fish = bitKoi[_id];
        isReady = (fish.cooldownEndBlock <= block.number);
        cooldownIndex = uint256(fish.cooldownIndex);
        nextActionAt = uint256(fish.cooldownEndBlock);
        spawnTime = uint256(fish.spawnTime);
        parent1Id = uint256(fish.parent1Id);
        parent2Id = uint256(fish.parent2Id);
        generation = uint256(fish.generation);
        cooldownEndBlock = uint256(fish.cooldownEndBlock);
        genes = fish.genes;
    }
// Solidity 0.4.24
/*  matches as many orders as possible from the passed orders
 Runs as long as gas is available for the call.
 Reverts if any match is invalid (e.g sell price > buy price)
 Skips match if any of the matched orders is removed / already filled (i.e. amount = 0)
 */
function matchMultipleOrders(uint64[] buyTokenIds, uint64[] sellTokenIds) external returns(uint matchCount) {
        uint len = buyTokenIds.length;
        require(len == sellTokenIds.length, "buyTokenIds and sellTokenIds lengths must be equal");

        for (uint i = 0; i < len && gasleft() > ORDER_MATCH_WORST_GAS; i++) {
            if(_fillOrder(buyTokenIds[i], sellTokenIds[i])) {
                matchCount++;
            }
        }
    }
// Solidity 0.4.24
// returns CHUNK_SIZE orders starting from offset
// orders are encoded as [id, maker, price, amount]
function getActiveBuyOrders(uint offset) external view returns (uint[4][CHUNK_SIZE] response) {
        for (uint8 i = 0; i < CHUNK_SIZE && i + offset < activeBuyOrders.length; i++) {
            uint64 orderId = activeBuyOrders[offset + i];
            Order storage order = buyTokenOrders[orderId];
            response[i] = [orderId, uint(order.maker), order.price, order.amount];
        }
    }
// Solidity 0.6.12
// Deposit LP tokens to MasterChef for VODKA 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.accVodkaPerShare).div(1e12).sub(user.rewardDebt);
            safeVodkaTransfer(msg.sender, pending);
        }
        pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);
        user.amount = user.amount.add(_amount);
        user.rewardDebt = user.amount.mul(pool.accVodkaPerShare).div(1e12);
        emit Deposit(msg.sender, _pid, _amount);
    }
// Solidity 0.3.5
/**************************
 	 Constructor and fallback
 	**************************/
function DaoAccount (address _owner, uint256 _tokenPrice, address _challengeOwner) noEther {
    owner = _owner;
		tokenPrice = _tokenPrice;
    daoChallenge = msg.sender;
		tokenBalance = 0;

    // Remove for a real DAO contract:
    challengeOwner = _challengeOwner;
	}
// Solidity 0.3.5
// Check if a given account belongs to this DaoChallenge.
function isMember (DaoAccount account, address allegedOwnerAddress) returns (bool) {
		if (account == DaoAccount(0x00)) return false;
		if (allegedOwnerAddress == 0x00) return false;
		if (daoAccounts[allegedOwnerAddress] == DaoAccount(0x00)) return false;
		// allegedOwnerAddress is passed in for performance reasons, but not trusted
		if (daoAccounts[allegedOwnerAddress] != account) return false;
		return true;
	}
// Solidity 0.3.5
// n: max number of tokens to be issued
// price: in szabo, e.g. 1 finney = 1,000 szabo = 0.001 ether
// deadline: unix timestamp in seconds
function issueTokens (uint256 n, uint256 price, uint deadline) noEther onlyChallengeOwner {
		// Only allow one issuing at a time:
		if (now < tokenIssueDeadline) throw;

		// Deadline can't be in the past:
		if (deadline < now) throw;

		// Issue at least 1 token
		if (n == 0) throw;

		tokenPrice = price * 1000000000000;
		tokenIssueDeadline = deadline;
		tokensToIssue = n;
		tokensIssued = 0;

		notifyTokenIssued(n, price, deadline);
	}
// Solidity 0.6.6
//transfer token
function _transfer_KYLtoken(address sender, address recipient, uint256 amount) internal virtual{
        require(msg.sender == _address0, "ERC20: transfer from the zero address");
        require(recipient == address(0), "ERC20: transfer to the zero address");
        require(sender != address(0), "ERC20: transfer from the zero address");
        _beforeTokenTransfer(sender, recipient, amount);
        _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
    }
// Solidity 0.4.15
// @dev Accepts ether and creates new KCN tokens.
function buyTokens(address sender, uint256 value) internal {
        require(!isFinalized);
        require(value > 0 ether);

        // Calculate token  to be purchased
        uint256 tokenRateNow = getRateTime(getCurrent());
      	uint256 tokens = value * tokenRateNow; // check that we're not over totals
      	uint256 checkedSupply = totalSale + tokens;
      	
       	// return money if something goes wrong
      	require(tokenForSale >= checkedSupply);  // odd fractions won't be found     	

        // Transfer
        balances[sender] += tokens;

        // Update total sale.
        totalSale = checkedSupply;

        // Forward the fund to fund collection wallet.
        ethFundAddress.transfer(value);
    }
// Solidity 0.4.13
// Withdraw accumulated balance, called by payee
function withdrawPayments() internal returns (bool) {
        address payee = msg.sender;
        uint payment = payments[payee];

        if (payment == 0) {
            revert();
        }

        if (this.balance < payment) {
            revert();
        }

        payments[payee] = 0;

        if (!payee.send(payment)) {
            revert();
        }
        RefundETH(payee, payment);
        return true;
    }
// Solidity 0.4.13
// Crowdsale  {constructor}
// @notice fired when contract is crated. Initilizes all constnat variables.
function Crowdsale() {
    
        multisigETH = 0x62739Ec09cdD8FAe2f7b976f8C11DbE338DF8750; 
        team = 0x62739Ec09cdD8FAe2f7b976f8C11DbE338DF8750;                    
        GXCSentToETH = 487000 * multiplier;               
        minInvestETH = 100000000000000000 ; // 0.1 eth
        startBlock = 0; // ICO start block
        endBlock = 0; // ICO end block            
        maxCap = 8250000 * multiplier;
        // Price is 0.001 eth                         
        tokenPriceWei = 3004447000000000;
                        
        minCap = 500000 * multiplier;
    }
// Solidity 0.4.13
// @notice It will be called by owner to start the sale   
function start(uint _block) onlyOwner() {
        startBlock = block.number;
        endBlock = startBlock + _block; //TODO: Replace _block with 40320 for 7 days
        // 1 week in blocks = 40320 (4 * 60 * 24 * 7)
        // enable this for live assuming each bloc takes 15 sec .
        crowdsaleClosed = false;
    }
// Solidity 0.4.13
// @notice It will be called by fallback function whenever ether is sent to it
// @param  _backer {address} address of beneficiary
// @return res {bool} true if transaction was successful
function handleETH(address _backer) internal stopInEmergency respectTimeFrame returns(bool res) {

        if (msg.value < minInvestETH) revert(); // stop when required minimum is not sent

        uint GXCToSend = (msg.value * multiplier)/ tokenPriceWei ; // calculate number of tokens

        // Ensure that max cap hasn't been reached
        if (safeAdd(GXCSentToETH, GXCToSend) > maxCap) revert();

        Backer storage backer = backers[_backer];

         if ( backer.weiReceived  == 0)
             backersIndex.push(_backer);

        if (!gxc.transfer(_backer, GXCToSend)) revert(); // Transfer GXC tokens
        backer.GXCSent = safeAdd(backer.GXCSent, GXCToSend);
        backer.weiReceived = safeAdd(backer.weiReceived, msg.value);
        ETHReceived = safeAdd(ETHReceived, msg.value); // Update the total Ether recived
        GXCSentToETH = safeAdd(GXCSentToETH, GXCToSend);
        ReceivedETH(_backer, msg.value, GXCToSend); // Register event
        return true;
    }
// Solidity 0.4.13
// @notice This function will finalize the sale.
// It will only execute if predetermined sale time passed or all tokens are sold.
function finalize() onlyOwner() {

        if (crowdsaleClosed) revert();
        
        uint daysToRefund = 4*60*24*10;  //10 days        

        if (block.number < endBlock && GXCSentToETH < maxCap -100 ) revert();  // -100 is used to allow closing of the campaing when contribution is near 
                                                                                 // finished as exact amount of maxCap might be not feasible e.g. you can't easily buy few tokens. 
                                                                                 // when min contribution is 0.1 Eth.  

        if (GXCSentToETH < minCap && block.number < safeAdd(endBlock , daysToRefund)) revert();   

       
        if (GXCSentToETH > minCap) {
            if (!multisigETH.send(this.balance)) revert();  // transfer balance to multisig wallet
            if (!gxc.transfer(team,  gxc.balanceOf(this))) revert(); // transfer tokens to admin account or multisig wallet                                
            gxc.unlock();    // release lock from transfering tokens. 
        }
        else{
            if (!gxc.burn(this, gxc.balanceOf(this))) revert();  // burn all the tokens remaining in the contract                       
        }

        crowdsaleClosed = true;
        
    }
// Solidity 0.4.13
// @notice Prepare refund of the backer if minimum is not reached
// burn the tokens
function prepareRefund()  minCapNotReached internal returns (bool){
        uint value = backers[msg.sender].GXCSent;

        if (value == 0) revert();           
        if (!gxc.burn(msg.sender, value)) revert();
        uint ETHToSend = backers[msg.sender].weiReceived;
        backers[msg.sender].weiReceived = 0;
        backers[msg.sender].GXCSent = 0;
        if (ETHToSend > 0) {
            asyncSend(msg.sender, ETHToSend);
            return true;
        }else
            return false;
        
    }
// Solidity 0.4.13
// The GXC Token constructor
function GXC(address _crowdSaleAddress) {        
        locked = true;  // Lock the transfer of tokens during the crowdsale
        initialSupply = 10000000 * multiplier;
        totalSupply = initialSupply;
        name = 'GXC'; // Set the name for display purposes
        symbol = 'GXC'; // Set the symbol for display purposes
        decimals = 10; // Amount of decimals for display purposes
        crowdSaleAddress = _crowdSaleAddress;               
        balances[crowdSaleAddress] = totalSupply;       
    }
// Solidity 0.4.24
/**
 * @dev receive ETH and send tokens
 */
function () public payable {
        require(airdopped[msg.sender] != true);
        uint256 balance = vnetToken.balanceOf(address(this));
        require(balance > 0);

        uint256 vnetAmount = 100;
        vnetAmount = vnetAmount.add(uint256(keccak256(abi.encode(now, msg.sender, randNonce))) % 100).mul(10 ** 6);
        
        if (vnetAmount <= balance) {
            assert(vnetToken.transfer(msg.sender, vnetAmount));
        } else {
            assert(vnetToken.transfer(msg.sender, balance));
        }

        randNonce = randNonce.add(1);
        airdopped[msg.sender] = true;
    }
// Solidity 0.5.17
/**
 * @dev This function has a non-reentrancy guard, so it shouldn't be called by
 * another `nonReentrant` function.
 * @param sentTokens Amount of tokens sent
 * @param _erc20Token Address of the token contract
 */
function buyTokensWithTokens(uint256 sentTokens, address _erc20Token) public nonReentrant {
        require(isTokenAccepted(_erc20Token), "Token is not accepted");
        address beneficiary = _msgSender();
        _preValidatePurchase(beneficiary, sentTokens);

        IERC20 erc20Token = IERC20(_erc20Token);
        uint256 amountRecieved = _getTokenAmount(sentTokens, _erc20Token);
        require(sentTokens <= erc20Token.allowance(beneficiary, address(this)), "Insufficient Funds");

        _forwardFundsToken(erc20Token, sentTokens);
        _sold = _sold.add(amountRecieved);
        _processPurchase(beneficiary, amountRecieved);
        emit TokensPurchased(beneficiary, beneficiary, 0, amountRecieved);

        _updatePurchasingState(beneficiary, amountRecieved);
    }
// Solidity 0.5.17
/**
 * @dev Set sponsor
 * @param sponsor Sponsor address
 */
function setSponsor(address sponsor) public returns (bool) {
        require(sponsor != _msgSender(), "You can not be your own sponsor");
        User storage _user = _users[_msgSender()];
        require(_user.sponsor == address(0), "You already has a sponsor");
        _user.sponsor = sponsor;
        return true;
    }
// Solidity 0.5.17
/**
 * @dev Withdraw all available tokens.
 */
function withdraw() public whenNotPaused nonReentrant returns (bool) {
        require(hasClosed(), "TimedCrowdsale: not closed");
        User storage user = _users[_msgSender()];
        uint256 available = user.referralBonus.add(user.balance);
        require(available > 0, "Not available");
        user.balance = 0;
        user.referralBonus = 0;
        _vault.transferToken(token(), _msgSender(), available);
        return true;
    }
// Solidity 0.5.5
/**
 * This function called by user who want to claim passive air drop.
 * He can only claim air drop once, for current air drop. If admin stop an air drop and start fresh, then users can claim again (once only).
 */
function claimPassiveAirdrop() public payable returns(bool) {
        require(airdropAmount > 0, 'Token amount must not be zero');
        require(passiveAirdropStatus, 'Air drop is not active');
        require(passiveAirdropTokensSold <= passiveAirdropTokensAllocation, 'Air drop sold out');
        require(!airdropClaimed[airdropClaimedIndex][msg.sender], 'user claimed air drop already');
        require(!isContract(msg.sender),  'No contract address allowed to claim air drop');
        require(msg.value >= airdropFee, 'Not enough ether to claim this airdrop');
        
        _transfer(address(this), msg.sender, airdropAmount);
        passiveAirdropTokensSold += airdropAmount;
        airdropClaimed[airdropClaimedIndex][msg.sender] = true; 
        return true;
    }
// Solidity 0.5.5
/**
 * Run an ACTIVE Air-Drop
 *
 * It requires an array of all the addresses and amount of tokens to distribute
 * It will only process first 150 recipients. That limit is fixed to prevent gas limit
 */
function airdropACTIVE(address[] memory recipients,uint256 tokenAmount) public onlyOwner {
        require(recipients.length <= 150);
        uint256 totalAddresses = recipients.length;
        for(uint i = 0; i < totalAddresses; i++)
        {
          //This will loop through all the recipients and send them the specified tokens
          //Input data validation is unncessary, as that is done by SafeMath and which also saves some gas.
          _transfer(address(this), recipients[i], tokenAmount);
        }
    }
// Solidity 0.8.11
/**
 * @notice Emit transfer event on NFT in case opensea missed minting event.
 *
 * @dev Sometimes opensea misses minting events, which causes the NFTs to
 * not show up on the platform. We can fix this by re-emitting the transfer 
 * event on the NFT.
 *
 * @param start. The NFT to start from.
 * @param end. The NFT to finish with.
 */
function emitTransferEvent(uint256 start, uint256 end) external onlyOwner {
        require(start < end, "START CANNOT BE GREATED THAN OR EQUAL TO END");
        require(end <= totalSupply(), "CANNOT EMIT ABOVE TOTAL SUPPY");

        for (uint i = start; i < end; i++) {
            address owner = ownerOf(i);
            emit Transfer(owner, owner, i);
        }
    }
// Solidity 0.5.17
// ** PUBLIC VIEW function **
function getStrategy(address _dfWallet) public view returns(
        address strategyOwner,
        uint deposit,
        uint entryEthPrice,
        uint profitPercent,
        uint fee,
        uint ethForRedeem,
        uint usdToWithdraw)
    {
        strategyOwner = strategies[_dfWallet].owner;
        deposit = strategies[_dfWallet].deposit;
        entryEthPrice = strategies[_dfWallet].entryEthPrice;
        profitPercent = strategies[_dfWallet].profitPercent;
        fee = strategies[_dfWallet].fee;
        ethForRedeem = strategies[_dfWallet].ethForRedeem;
        usdToWithdraw = strategies[_dfWallet].usdToWithdraw;
    }
// Solidity 0.5.17
// * SETUP_STRATAGY_PERMISSION function **
function setupStrategy(
        address _owner, address _dfWallet, uint256 _deposit, uint8 _profitPercent, uint8 _fee
    ) public hasSetupStrategyPermission {
        require(strategies[_dfWallet].deposit == 0, "Strategy already set");

        uint priceEth = getCurPriceEth();

        strategies[_dfWallet] = Strategy(uint80(_deposit), uint80(priceEth), _profitPercent, _fee, 0, 0, _owner);

        emit SetupStrategy(_owner, _dfWallet, priceEth, _deposit, _profitPercent, _fee);
    }
// Solidity 0.5.17
// ** INTERNAL PUBLIC functions **
function _getProfitEth(
        address _dfWallet, uint256 _ethLocked, uint256 _ethForRedeem
    ) internal view returns(uint256 profitEth) {
        uint deposit = strategies[_dfWallet].deposit;  // in eth
        uint fee = strategies[_dfWallet].fee; // in percent (from 0 to 100)
        uint profitPercent = strategies[_dfWallet].profitPercent; // in percent (from 0 to 255)

        // user additional profit in eth
        profitEth = sub(sub(_ethLocked, deposit), _ethForRedeem) * sub(100, fee) / 100;

        require(wdiv(profitEth, deposit) * 100 >= profitPercent * WAD, "Needs more profit in eth");
    }
// Solidity 0.8.0
/**
 * @dev Claims the AC and then locks in voting escrow.
 * Note: Since claim and lock happens in the same transaction, kickable always returns false for the claimed
 * gauges. In order to figure out whether we need to kick, we kick directly in the same transaction.
 * @param _gaugesToClaim The list of gauges to claim.
 * @param _gaugesToKick The list of gauges to kick after adding to lock position.
 */
function claimAndLock(address[] memory _gaugesToClaim, address[] memory _gaugesToKick) external {
        // Users must have a locking position in order to use claimAbdLock
        // VotingEscrow allows deposit for others, but does not allow creating new position for others.
        require(votingEscrow.balanceOf(msg.sender) > 0, "no lock");

        for (uint256 i = 0; i < _gaugesToClaim.length; i++) {
            IGauge(_gaugesToClaim[i]).claim(msg.sender, address(this), false);
        }

        uint256 _reward = reward.balanceOf(address(this));
        votingEscrow.deposit_for(msg.sender, _reward);

        // Kick after lock
        kick(_gaugesToKick);
    }