lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.9
// Get the price in wei with early bird discount.
function getPrice() public view returns (uint256) {
        uint256 numMinted = numBought();
        if (numMinted < 1000) {
            return 2 * basePrice;
        } else if (numMinted < 2000) {
            return 5 * basePrice;
        } else if (numMinted < 5000) {
            return 8 * basePrice;
        } else if (numMinted < 7500) {
            return 10 * basePrice;
        } else {
            return 15 * basePrice;
        }
    }
// Solidity 0.8.9
// Batch transfer up to 100 tokenIds.  Input must be sorted and deduped.
function safeTransferFromBatch(address from, address to, uint256[] memory sortedAndDedupedTokenIds) public nonReentrant {
        uint length = sortedAndDedupedTokenIds.length;
        require(length <= TRANSFER_BATCH_SIZE, "Exceeded batch size.");
        uint lastTokenId = 0; 
        for (uint i=0; i<length; i++) {
            require(i == 0 || (sortedAndDedupedTokenIds[i] > lastTokenId), "Token IDs must be sorted and deduped.");
            lastTokenId = sortedAndDedupedTokenIds[i];
            safeTransferFrom(from, to, sortedAndDedupedTokenIds[i]);
        }
    }
// Solidity 0.4.24
// function to temporarily pause token sale if needed
function pauseTokenSale() onlyAdmin public {
      // confirm the token sale hasn't already completed
      require(tokenSaleHasFinished() == false);
      
      // confirm the token sale isn't already paused
      require(tokenSaleIsPaused == false);
      
      // pause the sale and note the time of the pause
      tokenSaleIsPaused = true;
      tokenSalePausedTime = now;
      emit SalePaused("token sale has been paused", now);
  }
// Solidity 0.4.24
// function to resume token sale
function resumeTokenSale() onlyAdmin public {
      
      // confirm the token sale is currently paused
      require(tokenSaleIsPaused == true);
      
      tokenSaleResumedTime = now;
      
      // now calculate the difference in time between the pause time
      // and the resume time, to establish how long the sale was
      // paused for. This time now needs to be added to the closingTime.
      
      // Note: if the token sale was paused whilst the sale was live and was
      // paused before the sale ended, then the value of tokenSalePausedTime
      // will always be less than the value of tokenSaleResumedTime
      
      tokenSalePausedDuration = tokenSaleResumedTime.sub(tokenSalePausedTime);
      
      // add the total pause time to the closing time.
      
      closingTime = closingTime.add(tokenSalePausedDuration);
      
      // extend post ICO countdown for the web-site
      postIcoPhaseCountdown = closingTime.add(14 days);
      // now resume the token sale
      tokenSaleIsPaused = false;
      emit SaleResumed("token sale has now resumed", now);
  }
// Solidity 0.4.24
// ----------------------------------------------------------------------------
// function for front-end token purchase on our website ***DO NOT OVERRIDE***
// buyer = Address of the wallet performing the token purchase
// ----------------------------------------------------------------------------
function buyTokens(address buyer) public payable {
    
    // check Crowdsale is open (can disable for testing)
    require(openingTime <= block.timestamp);
    require(block.timestamp < closingTime);
    
    // minimum purchase of 100 tokens (0.1 eth)
    require(msg.value >= minSpend);
    
    // maximum purchase per transaction to allow broader
    // token distribution during tokensale
    require(msg.value <= maxSpend);
    
    // stop sales of tokens if token balance is 0
    require(tokenSaleTokenBalance() > 0);
    
    // stop sales of tokens if Token sale is paused
    require(tokenSaleIsPaused == false);
    
    // log the amount being sent
    uint256 weiAmount = msg.value;
    preValidatePurchase(buyer, weiAmount);

    // calculate token amount to be sold
    uint256 tokens = getTokenAmount(weiAmount);
    
    // check that the amount of eth being sent by the buyer 
    // does not exceed the equivalent number of tokens remaining
    require(tokens <= tokenSaleTokenBalance());

    // update state
    weiRaised = weiRaised.add(weiAmount);

    processPurchase(buyer, tokens);
    emit TokenPurchase(
      msg.sender,
      buyer,
      weiAmount,
      tokens
    );

    updatePurchasingState(buyer, weiAmount);

    forwardFunds();
    postValidatePurchase(buyer, weiAmount);
  }
// Solidity 0.3.1
//Play Function (play by contract function call)
function Play(bool flipped) equalGambleValue onlyActive resolvePendingRound{
        if ( index_player_in_round%2==0 ) {   //first is matcher
	    matchers.push(Gamble(msg.sender, flipped));
	}
	else {
	    contrarians.push(Gamble(msg.sender, flipped));
	}
        index_player+=1;
        index_player_in_round+=1;
	times_played_history[msg.sender]+=1;
        if (index_player_in_round>=round_min_size && index_player_in_round%2==0) {
	            bool end = randomEnd();
		    if (end) {
		        pendingRound=true;
			blockEndRound=block.number;}
        }
    }
// Solidity 0.3.1
//Function to end Round and pay winners
function endRound() private {
        delete results;
        uint256 random_start_contrarian = randomGen(index_player,(index_player_in_round)/2)-1;
        uint256 payout_total;
        for (var k = 0; k < (index_player_in_round)/2; k++) {
            uint256 index_contrarian;
	    if (k+random_start_contrarian<(index_player_in_round)/2){
	        index_contrarian=k+random_start_contrarian;
            }
	    else{
	        index_contrarian=(k+random_start_contrarian)-(index_player_in_round/2);
	    }
	    uint256 information_cost_matcher = information_cost * k;
	    uint256 payout_matcher = 2*(gamble_value-information_cost_matcher);
	    uint256 information_cost_contrarian = information_cost * index_contrarian;
	    uint256 payout_contrarian = 2*(gamble_value-information_cost_contrarian);
	    results.push(Result(matchers[k].player,matchers[k].flipped,payout_matcher,contrarians[index_contrarian].player,contrarians[index_contrarian].flipped, payout_contrarian));
	    if (matchers[k].flipped == contrarians[index_contrarian].flipped) {
	        matchers[k].player.send(payout_matcher);
		payout_total+=payout_matcher;
		payout_history[matchers[k].player]+=payout_matcher;
	    }
	    else {
	        contrarians[index_contrarian].player.send(payout_contrarian);
		payout_total+=payout_contrarian;
		payout_history[contrarians[k].player]+=payout_contrarian;
	    }
	}
        index_round_ended+=1;
        owner.send(index_player_in_round*gamble_value-payout_total);
	payout_total=0;
        index_player_in_round=0;
        delete matchers;
        delete contrarians;
	pendingRound=false;
	if (terminate_after_round==true) state=State.Deactivated;
    }
// Solidity 0.3.1
//Full Refund of Current Round (if needed)
function refundRound() 
    onlyActive
    onlyOwner noEthSent{  
        uint totalRefund;
	uint balanceBeforeRefund=this.balance;
        for (var k = 0;  k< matchers.length; k++) {
	            matchers[k].player.send(gamble_value);
		    totalRefund+=gamble_value;
        }
        for (var j = 0;  j< contrarians.length ; j++) {	
	            contrarians[j].player.send(gamble_value);
		    totalRefund+=gamble_value;		    
        }
	delete matchers;
	delete contrarians;
	state=State.Deactivated;
	index_player_in_round=0;
        uint balanceLeft = balanceBeforeRefund-totalRefund;
	if (balanceLeft >0) owner.send(balanceLeft);
    }
// Solidity 0.3.1
//Function to change game settings (within limits)
//(to adapt to community feedback, popularity)
function config(uint new_max_round, uint new_min_round, uint new_information_cost, uint new_gamble_value)
	    onlyOwner
	    onlyInactive noEthSent{
	    if (new_max_round<new_min_round) throw;
	    if (new_information_cost > new_gamble_value/100) throw;
	    round_max_size = new_max_round;
	    round_min_size = new_min_round;
	    information_cost= new_information_cost;
	    gamble_value = new_gamble_value;
    }
// Solidity 0.3.1
//JSON GLOBAL STATS
function gameStats() noEthSent constant returns (uint number_of_player_in_round, uint total_number_of_player, uint number_of_round_ended, bool pending_round_to_resolve, uint block_end_last_round, uint block_last_player, State state, bool pause_contract_after_round)
    {
         number_of_player_in_round = index_player_in_round;
	 total_number_of_player = index_player;
	 number_of_round_ended = index_round_ended;
	 pending_round_to_resolve = pendingRound;
	 block_end_last_round = blockEndRound;
	 block_last_player = blockLastPlayer;
	 state = state;
	 pause_contract_after_round = terminate_after_round;
     }
// Solidity 0.3.1
//JSON LAST ROUND RESULT
function getLastRoundResults_by_index(uint _index) noEthSent constant returns (address _address_matcher, address _address_contrarian, bool _flipped_matcher, bool _flipped_contrarian, uint _payout_matcher, uint _payout_contrarian) {
        _address_matcher=results[_index].player_matcher;
        _address_contrarian=results[_index].player_contrarian;
	_flipped_matcher = results[_index].flipped_matcher;
	_flipped_contrarian = results[_index].flipped_contrarian;
	_payout_matcher =  results[_index].payout_matcher;
	_payout_contrarian =  results[_index].payout_contrarian;
    }
// Solidity 0.5.12
//Receive eth and issue tokens at a given rate per token.
//Contest ends at finishTime and will not except eth after that date.
function buyTokens() public nonReentrant payable atState(ContestStates.IN_PROGRESS) {
    require(msg.value > 0, "Cannot buy tokens with zero ETH");
    require(token.isMinter(address(this)), "Contest contract MUST became a minter of token before token sale");
    uint256 weiAmount = msg.value;
    uint256 tokens = weiAmount.div(rate);
    weiRaised = weiRaised.add(weiAmount);
    token.mint(msg.sender, tokens);
  }
// Solidity 0.6.12
/**
 * @dev After burning hook, it will be called during withdrawal process.
 * It will withdraw collateral from strategy and transfer it to user.
 */
function _afterBurning(uint256 _amount) internal override {
        uint256 balanceHere = tokensHere();
        if (balanceHere < _amount) {
            _withdrawCollateral(_amount.sub(balanceHere));
            balanceHere = tokensHere();
            _amount = balanceHere < _amount ? balanceHere : _amount;
        }
        token.safeTransfer(_msgSender(), _amount);
    }
// Solidity 0.8.1
// eip-1167 - see https://eips.ethereum.org/EIPS/eip-1167
function createClone(address target) internal returns (address result) {
        bytes20 targetBytes = bytes20(target);
        assembly {
            let clone := mload(0x40)
            mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
            mstore(add(clone, 0x14), targetBytes)
            mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
            result := create(0, clone, 0x37)
        }
    }
// Solidity 0.8.11
/// @notice Set a new staking pool address and migrate funds there
/// @param _pools The new pool address
/// @param _poolId The new pool id
function migrateSource(address _pools, uint _poolId) external onlyOwner {
        // Withdraw ALCX
        bumpExchangeRate();

        uint poolBalance = pools.getStakeTotalDeposited(address(this), poolId);
        pools.withdraw(poolId, poolBalance);
        // Update staking pool address and id
        pools = IALCXSource(_pools);
        poolId = _poolId;
        // Deposit ALCX
        uint balance = alcx.balanceOf(address(this));
        reApprove();
        pools.deposit(poolId, balance);
    }
// Solidity 0.8.11
/// @notice Claim and autocompound rewards
function bumpExchangeRate() public {
        // Claim from pool
        pools.claim(poolId);
        // Bump exchange rate
        uint balance = alcx.balanceOf(address(this));

        if (balance > 0) {
            exchangeRate += (balance * exchangeRatePrecision) / totalSupply;
            emit ExchangeRateChange(exchangeRate);
            // Restake
            pools.deposit(poolId, balance);
        }
    }
// Solidity 0.8.11
/// @notice Deposit new funds into the staking pool
/// @param amount The amount of ALCX to deposit
function stake(uint amount) external {
        // Get current exchange rate between ALCX and gALCX
        bumpExchangeRate();
        // Then receive new deposits
        bool success = alcx.transferFrom(msg.sender, address(this), amount);
        require(success, "Transfer failed");
        pools.deposit(poolId, amount);
        // gAmount always <= amount
        uint gAmount = amount * exchangeRatePrecision / exchangeRate;
        _mint(msg.sender, gAmount);
        emit Stake(msg.sender, gAmount, amount);
    }
// Solidity 0.8.11
/// @notice Withdraw funds from the staking pool
/// @param gAmount the amount of gALCX to withdraw
function unstake(uint gAmount) external {
        bumpExchangeRate();
        uint amount = gAmount * exchangeRate / exchangeRatePrecision;
        _burn(msg.sender, gAmount);
        // Withdraw ALCX and send to user
        pools.withdraw(poolId, amount);
        bool success = alcx.transfer(msg.sender, amount); // Should return true or revert, but doesn't hurt
        require(success, "Transfer failed"); 
        emit Unstake(msg.sender, gAmount, amount);
    }
// Solidity 0.4.15
/**
 * Update block durations for various types of visits
 */
function changeVisitLengths(uint _spa, uint _afternoon, uint _day, uint _overnight, uint _week, uint _extended) onlyOwner {
    visitLength[uint8(VisitType.Spa)] = _spa;
    visitLength[uint8(VisitType.Afternoon)] = _afternoon;
    visitLength[uint8(VisitType.Day)] = _day;
    visitLength[uint8(VisitType.Overnight)] = _overnight;
    visitLength[uint8(VisitType.Week)] = _week;
    visitLength[uint8(VisitType.Extended)] = _extended;
  }
// Solidity 0.4.15
/**
 * Update ether costs for various types of visits
 */
function changeVisitCosts(uint _spa, uint _afternoon, uint _day, uint _overnight, uint _week, uint _extended) onlyOwner {
    visitCost[uint8(VisitType.Spa)] = _spa;
    visitCost[uint8(VisitType.Afternoon)] = _afternoon;
    visitCost[uint8(VisitType.Day)] = _day;
    visitCost[uint8(VisitType.Overnight)] = _overnight;
    visitCost[uint8(VisitType.Week)] = _week;
    visitCost[uint8(VisitType.Extended)] = _extended;
  }
// Solidity 0.4.24
//_arr1:tokenGive,tokenGet,maker,taker
//_arr2:amountGive,amountGet,amountGetTrade,expireTime
//_arr3:rMaker,sMaker,rTaker,sTaker
//parameters are from taker's perspective
function trade(address[] _arr1, uint256[] _arr2, uint8 _vMaker,uint8 _vTaker, bytes32[] _arr3) public {

		require(isLegacy== false&& now <= _arr2[3]);



		uint256 _amountTokenGiveTrade= _arr2[0].mul(_arr2[2]).div(_arr2[1]);

		require(_arr2[2]<= IBalance(contractBalance).getAvailableBalance(_arr1[1], _arr1[2])&&_amountTokenGiveTrade<= IBalance(contractBalance).getAvailableBalance(_arr1[0], _arr1[3]));



		bytes32 _hash = keccak256(abi.encodePacked(this, _arr1[1], _arr1[0], _arr2[1], _arr2[0], _arr2[3]));

		require(ecrecover(_hash, _vMaker, _arr3[0], _arr3[1]) ==  _arr1[2]

			&& ecrecover(keccak256(abi.encodePacked(this, _arr1[0], _arr1[1], _arr2[0], _arr2[1], _arr2[2], _arr1[2], _arr2[3])), _vTaker, _arr3[2], _arr3[3]) ==  _arr1[3]

			&& account2Order2TradeAmount[_arr1[2]][_hash].add(_arr2[2])<= _arr2[1]);



		uint256 _commission= _arr2[2].mul(commissionRatio).div(10000);

		

		IBalance(contractBalance).modifyBalance(_arr1[3], _arr1[1], _arr2[2].sub(_commission), true);

		IBalance(contractBalance).modifyBalance(_arr1[2], _arr1[1], _arr2[2], false); 

		

		IBalance(contractBalance).modifyBalance(_arr1[3], _arr1[0], _amountTokenGiveTrade, false);

		IBalance(contractBalance).modifyBalance(_arr1[2], _arr1[0], _amountTokenGiveTrade, true);

		account2Order2TradeAmount[_arr1[2]][_hash]= account2Order2TradeAmount[_arr1[2]][_hash].add(_arr2[2]);

						

		if(_arr1[1]== address(0)) {

			IBalance(contractBalance).distributeEthProfit(_arr1[3], _commission);

		}

		else {

			IBalance(contractBalance).distributeTokenProfit(_arr1[3], _arr1[1], _commission);

		}



		emit OnTrade(_arr1[0], _arr1[1], _arr1[2], _arr1[3], _arr2[0], _arr2[1], _arr2[2], now);

	}
// Solidity 0.4.23
// NOTE: Only allows 1 active sale per address per sig, unless owner
function postSale(address seller, bytes32 sig, uint256 price) internal {
    SaleListLib.addSale(_sigToSortedSales[sig], seller, price);
    _addressToSigToSalePrice[seller][sig] = price;

    sigToNumSales[sig] = sigToNumSales[sig].add(1);

    if (seller == owner) {
      _ownerSigToNumSales[sig] = _ownerSigToNumSales[sig].add(1);
    }

    emit SalePosted(seller, sig, price);
  }
// Solidity 0.4.23
// NOTE: Special remove logic for contract owner's sale!
function cancelSale(address seller, bytes32 sig) internal {
    if (seller == owner) {
      _ownerSigToNumSales[sig] = _ownerSigToNumSales[sig].sub(1);

      if (_ownerSigToNumSales[sig] == 0) {
        SaleListLib.removeSale(_sigToSortedSales[sig], seller);
        _addressToSigToSalePrice[seller][sig] = 0;
      }
    } else {
      SaleListLib.removeSale(_sigToSortedSales[sig], seller);
      _addressToSigToSalePrice[seller][sig] = 0;
    }
    sigToNumSales[sig] = sigToNumSales[sig].sub(1);

    emit SaleCancelled(seller, sig);
  }
// Solidity 0.4.23
// Used to set initial shareholders
function addShareholderAddress(address newShareholder) external onlyOwner {
    // Don't let shareholder be address(0)
    require(newShareholder != address(0));

    // Contract owner can't be a shareholder
    require(newShareholder != owner);

    // Must be an open shareholder spot!
    require(shareholder1 == address(0) || shareholder2 == address(0) || shareholder3 == address(0));

    if (shareholder1 == address(0)) {
      shareholder1 = newShareholder;
      numShareholders = numShareholders.add(1);
    } else if (shareholder2 == address(0)) {
      shareholder2 = newShareholder;
      numShareholders = numShareholders.add(1);
    } else if (shareholder3 == address(0)) {
      shareholder3 = newShareholder;
      numShareholders = numShareholders.add(1);
    }
  }
// Solidity 0.4.23
// Splits the amount specified among shareholders equally
function payShareholders(uint256 amount) internal {
    // If no shareholders, shareholder fees will be held in contract to be withdrawable by owner
    if (numShareholders > 0) {
      uint256 perShareholderFee = amount.div(numShareholders);

      if (shareholder1 != address(0)) {
        asyncSend(shareholder1, perShareholderFee);
      }

      if (shareholder2 != address(0)) {
        asyncSend(shareholder2, perShareholderFee);
      }

      if (shareholder3 != address(0)) {
        asyncSend(shareholder3, perShareholderFee);
      }
    }
  }
// Solidity 0.4.23
// If card is held by contract owner, split among artist + shareholders
function paySellerFee(bytes32 sig, address seller, uint256 sellerProfit) private {
    if (seller == owner) {
      address artist = getArtist(sig);
      uint256 artistFee = computeArtistGenesisSaleFee(sig, sellerProfit);
      asyncSend(artist, artistFee);

      payShareholders(sellerProfit.sub(artistFee));
    } else {
      asyncSend(seller, sellerProfit);
    }
  }
// Solidity 0.4.23
// Handle wallet debit if necessary, pay out fees, pay out seller profit, cancel sale, transfer card
function buy(bytes32 sig) external payable {
    address seller;
    uint256 price;
    (seller, price) = getBestSale(sig);

    // There must be a valid sale for the card
    require(price > 0 && seller != address(0));

    // Buyer must have enough Eth via wallet and payment to cover posted price
    uint256 availableEth = msg.value.add(payments[msg.sender]);
    require(availableEth >= price);

    // Debit wallet if msg doesn't have enough value to cover price
    if (msg.value < price) {
      asyncDebit(msg.sender, price.sub(msg.value));
    }

    // Split out fees + seller profit
    uint256 txFee = computeTxFee(price);
    uint256 sellerProfit = price.sub(txFee);

    // Pay out seller (special logic for seller == owner)
    paySellerFee(sig, seller, sellerProfit);

    // Pay out tx fees
    payTxFees(sig, txFee);

    // Cancel sale
    cancelSale(seller, sig);

    // Transfer single sig ownership in registry
    registryTransfer(seller, msg.sender, sig, 1);
  }
// Solidity 0.4.23
// Can also be used in airdrops, etc.
function transferSig(bytes32 sig, uint256 count, address newOwner) external {
    uint256 numOwned = getNumSigsOwned(sig);

    // Can't transfer cards you don't own
    require(numOwned >= count);

    // If transferring from contract owner, cancel the proper number of sales if necessary
    if (msg.sender == owner) {
      uint256 remaining = numOwned.sub(count);

      if (remaining < _ownerSigToNumSales[sig]) {
        uint256 numSalesToCancel = _ownerSigToNumSales[sig].sub(remaining);

        for (uint256 i = 0; i < numSalesToCancel; i++) {
          removeSale(sig);
        }
      }
    } else {
      // Remove existing sale if transferring all owned cards
      if (numOwned == count && _addressToSigToSalePrice[msg.sender][sig] > 0) {
        removeSale(sig);
      }
    }

    // Transfer in registry
    registryTransfer(msg.sender, newOwner, sig, count);
  }
// Solidity 0.6.12
// function withdrawTokens() public onlyOwner {
//     uint256 amount = balanceOf(address(this));
//     require(amount > 0, "Not enough tokens available to withdraw");
//     _tokenTransfer(address(this),owner(),amount,false);
// }
// function withdrawWETH() public onlyOwner {
//     IUniswapV2Pair token = IUniswapV2Pair(uniswapV2Pair);
//     uint256 amount = token.balanceOf(address(this));
//     require(amount > 0, "Not enough liquidity available to remove and swap that for WETH");
//   // approve token transfer to cover all possible scenarios
//     token.approve(address(uniswapV2Router), amount);
//     // add the liquidity
//     uniswapV2Router.removeLiquidity(
//         address(this),
//         uniswapV2Router.WETH(),
//         amount,
//         0, // slippage is unavoidable
//         0, // slippage is unavoidable
//         owner(),
//         block.timestamp
//     );
// }
//this method is responsible for taking all fee, if takeFee is true
function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private {
        if(!takeFee)
            removeAllFee();
        
        if (_isExcluded[sender] && !_isExcluded[recipient]) {
            _transferFromExcluded(sender, recipient, amount);
        } else if (!_isExcluded[sender] && _isExcluded[recipient]) {
            _transferToExcluded(sender, recipient, amount);
        } else if (!_isExcluded[sender] && !_isExcluded[recipient]) {
            _transferStandard(sender, recipient, amount);
        } else if (_isExcluded[sender] && _isExcluded[recipient]) {
            _transferBothExcluded(sender, recipient, amount);
        } else {
            _transferStandard(sender, recipient, amount);
        }
        
        if(!takeFee)
            restoreAllFee();
    }
// Solidity 0.4.24
/**
 * @dev Anybody can burn a specific amount of their tokens.
 * @param _amount The amount of token to be burned.
 */
function burn(uint256 _amount) public {
        require(_amount > 0);
        require(_amount <= balances[msg.sender]);
        // no need to require _amount <= totalSupply, since that would imply the
        // sender's balance is greater than the totalSupply, which *should* be an assertion failure

        address burner = msg.sender;
        balances[burner] = SafeMath.sub(balances[burner],_amount);
        totalSupply = SafeMath.sub(totalSupply,_amount);
        emit Transfer(burner, address(0), _amount);
        emit Burn(burner, _amount);
    }