lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.4
//==================================================================================//
// Swapping functions
function swap(uint inputAmount, address withAsset, address toAsset) public payable returns (uint outputAmount, uint fee) {
        require(now < poolData[address(0)].genesis + DAYCAP, "Must not be after Day Cap");
        require(withAsset != toAsset, "Asset must not be the same");
        uint _actualAmount = _handleTransferIn(withAsset, inputAmount); uint _transferAmount;
        if(withAsset == VETHER){
            (outputAmount, fee) = _swapVetherToAsset(_actualAmount, toAsset);
            emit Swapped(VETHER, toAsset, _actualAmount, 0, outputAmount, fee, msg.sender);
        } else if(toAsset == VETHER) {
            (outputAmount, fee) = _swapAssetToVether(_actualAmount, withAsset);
            emit Swapped(withAsset, VETHER, _actualAmount, 0, outputAmount, fee, msg.sender);
        } else {
            (_transferAmount, outputAmount, fee) = _swapAssetToAsset(_actualAmount, withAsset, toAsset);
            emit Swapped(withAsset, toAsset, _actualAmount, _transferAmount, outputAmount, fee, msg.sender);
        }
        _handleTransferOut(toAsset, outputAmount, msg.sender);
        return (outputAmount, fee);
    }
// Solidity 0.6.4
//==================================================================================//
// Asset Transfer Functions
function _handleTransferIn(address _asset, uint _amount) internal returns(uint actual){
        if(_amount > 0) {
            if(_asset == address(0)){
                require((_amount == msg.value), "Must get Eth");
                actual = _amount;
            } else {
                uint startBal = ERC20(_asset).balanceOf(address(this)); 
                ERC20(_asset).transferFrom(msg.sender, address(this), _amount); 
                actual = ERC20(_asset).balanceOf(address(this)).sub(startBal);
            }
        }
    }
// Solidity 0.5.0
/// @title Dequeus a Play
/// @notice Removes the oldest play from the queue.
/// @dev reverts if an attempt is made to deueue when the queue is empty.
/// Only the owner may call this method.
/// @return player address fo the player
/// @return amount the original value of hte player's bet.
function dequeue() public returns (address payable player, uint amount) {
        require(msg.sender == owner, 'Access Denied');
        require(!isEmpty(),'Queue is empty');
        (player,amount) = (queue[first].player,queue[first].amount);
        delete queue[first];
        first += 1;
        if(last < first) {
            first = 1;
            last = 0;
        }
    }
// Solidity 0.5.0
/// @title Total value of bets from players in queue.
/// @notice Enumerates the players in the queu and returns the
/// sum of the value of all the bets associated with the players.
/// @dev only the owner may call this method.
/// @return total the total value of the bets for the players contained
/// within this queue.
function totalAmount() public view returns (uint total)
    {
        require(msg.sender == owner, 'Access Denied');
        total = 0;
        for(uint i = first; i <= last; i ++ ) {
            total = total + queue[i].amount;
        }
    }
// Solidity 0.5.0
/// @title Ends the Game
/// @notice Ends the game, returning any unresolved plays to their
/// originating addresses, if possible.  If transfers fail, a
/// `RefundFailure` event will be raised and it will be up to the
/// owner of the contract to manually resolve any issues.
/// @dev Only the owner of the contract may call this method.
function end() external
    {
        require(owner == msg.sender, 'Access Denied');
        require(open, 'Game is already finished.');
        open = false;
        openingMove = Move.None;
        while(!openingMovers.isEmpty())
        {
            (address payable player, uint bet) = openingMovers.dequeue();
            if(!player.send(bet))
            {
                emit RefundFailure(player,bet);
            }
        }
        emit GameClosed();
    }
// Solidity 0.4.18
/*!	Transfer tokens to multipe destination addresses
 		Returns list with appropriate (by index) successful statuses.
 		(string with 0 or 1 chars)
 	 */
function transferMulti(address [] _tos, uint256 [] _values) public onlyMigrationGate returns (string) {
		require(_tos.length == _values.length);
		bytes memory return_values = new bytes(_tos.length);

		for (uint256 i = 0; i < _tos.length; i++) {
			address _to = _tos[i];
			uint256 _value = _values[i];
			return_values[i] = byte(48); //'0'

			if (_to != address(0) &&
				_value <= balances[msg.sender]) {

				bool ok = transfer(_to, _value);
				if (ok) {
					return_values[i] = byte(49); //'1'
				}
			}
		}
		return string(return_values);
	}
// Solidity 0.4.18
/*!	Migrate tokens to the new token contract
 		The method can be only called when migration agent is set.
 
 		Can be called by user(holder) that would like to transfer
 		coins to new contract immediately.
 	 */
function migrate() public returns (bool) {
		require(migrationAgent != 0x0);
		uint256 value = balances[msg.sender];
		balances[msg.sender] = balances[msg.sender].sub(value);
		totalSupply_ = totalSupply_.sub(value);
		MigrationAgent(migrationAgent).migrateFrom(msg.sender, value);
		// Notify anyone listening that this migration took place
		Migrate(msg.sender, value);
		return true;
	}
// Solidity 0.4.18
/*!	Migrate holders of tokens to the new contract
 		The method can be only called when migration agent is set.
 
 		Can be called only by owner (onlyOwner)
 	 */
function migrateHolders(uint256 count) public onlyOwner returns (bool) {
		require(count > 0);
		require(migrationAgent != 0x0);
		// Calculate bounds for processing
		count = migrationCountComplete.add(count);
		if (count > holders.length) {
			count = holders.length;
		}
		// Process migration
		for (uint256 i = migrationCountComplete; i < count; i++) {
			address holder = holders[i];
			uint value = balances[holder];
			balances[holder] = balances[holder].sub(value);
			totalSupply_ = totalSupply_.sub(value);
			MigrationAgent(migrationAgent).migrateFrom(holder, value);
			// Notify anyone listening that this migration took place
			Migrate(holder, value);
		}
		migrationCountComplete = count;
		return true;
	}
// Solidity 0.6.7
/*
 * @notify Modify escrowPaused
 * @param parameter Must be "escrowPaused"
 * @param data The new value for escrowPaused
 */
function modifyParameters(bytes32 parameter, uint256 data) external isAuthorized {
        if (parameter == "minStakedTokensToKeep") {
            require(data <= maxStakedTokensToKeep, "MinimalLenderFirstResortOverlay/minStakedTokensToKeep-over-limit");
            staking.modifyParameters(parameter, data);
        } else if (
            parameter == "escrowPaused"    ||
            parameter == "bypassAuctions"  ||
            parameter == "tokensToAuction" ||
            parameter == "systemCoinsToRequest"
            ) staking.modifyParameters(parameter, data);
        else revert("MinimalLenderFirstResortOverlay/modify-forbidden-param");
    }
// Solidity 0.8.6
/*
 * The mint function
 */
function summonEggZFromSpace(uint256 num, uint256 price) internal {
        uint256 supply = totalSupply();
        require( canMint,                              "Sale paused" );
        require( supply + num <= 10000 - _reserved,      "No EggZ left :'(" );
        require( msg.value >= price * num,             "Not enough ether sent" );
        require( earlySupportersGiveawayDone,           "You can't summon EggZ till early supporters and team haven't had their EggZ");

        for(uint256 i; i < num; i++){
            _safeMint( msg.sender, supply + i );
        }
    }
// Solidity 0.8.6
/*
 *   Used to airdrop 1 egg to each _addrs
 *   I'm not using airdropToWallet in this function to avoid
 *   calling require _addrs.length amounts of time
 *
 */
function airdropOneEggToWallets(address[] memory _addrs) external onlyOwner() {
        uint256 supply = totalSupply();
        uint256 amount = _addrs.length;
        require( earlySupportersGiveawayDone, "You can't summon EggZ till early supporters and team haven't had their EggZ");
        require( supply + amount <= _reserved, "Not enough reserved EggZ");


        for(uint256 i; i < amount; i++) {
            _safeMint( _addrs[i], supply + i);
        }

        _reserved -= amount;
    }
// Solidity 0.8.6
/*
 *   Used to airdrop amount egg to addr
 *
 */
function airdropToWallet(address addr, uint256 amount) external onlyOwner() {
        uint256 supply = totalSupply();
        require( earlySupportersGiveawayDone, "You can't summon EggZ till early supporters and team haven't had their EggZ");
        require( supply + amount <= _reserved, "Not enough reserved EggZ");

        for(uint256 i; i < amount; i++) {
            _safeMint( addr, supply + i);
        }
        
        _reserved -= amount;
    }
// Solidity 0.8.6
/*
 *   Used to airdrop the 50 EggZ with early supporter custom trait
 *   Can only be called once
 */
function earlySupportersGiveaway(address[] memory _addrs) external onlyOwner() {
        uint256 supply = totalSupply();
        require( !earlySupportersGiveawayDone, "Early supporters giveaway has already been done !");
        require( _addrs.length == 50,   "There should be 50 adresses to run the early supporters giveaway");
        
        for(uint256 i; i < _addrs.length; i++) {
            _safeMint( _addrs[i], supply + i );
        }
        
        earlySupportersGiveawayDone = true;
        _reserved -= 50;
        
    }
// Solidity 0.8.6
/*************************************************
 *
 *      UTILITY PART
 *
 * ***********************************************/
function listEggZOfOwner(address _owner) public view returns(uint256[] memory) {
        uint256 tokenCount = balanceOf(_owner);

        uint256[] memory tokensId = new uint256[](tokenCount);
        for(uint256 i; i < tokenCount; i++){
            tokensId[i] = tokenOfOwnerByIndex(_owner, i);
        }
        return tokensId;
    }
// Solidity 0.4.18
/// For creating Waifus
function _createWaifu(string _name, address _owner, uint256 _price) private {
    Waifu memory _waifu = Waifu({
      name: _name
    });
    uint256 newWaifuId = waifus.push(_waifu) - 1;

    // It's probably never going to happen, 4 billion tokens are A LOT, but
    // let's just be 100% sure we never let this happen.
    require(newWaifuId == uint256(uint32(newWaifuId)));

    Birth(newWaifuId, _name, _owner);

    waifuIndexToPrice[newWaifuId] = _price;

    // This will assign ownership, and also emit the Transfer event as
    // per ERC721 draft
    _transfer(address(0), _owner, newWaifuId);
  }
// Solidity 0.6.12
// add externalRandomNumber to prevent node validators exploiting
function drawing(uint256 _externalRandomNumber) external onlyAdmin {
        require(!drawed(), "reset?");	
        require(drawingPhase, "enter drawing phase first");
        bytes32 _structHash;
        uint256 _randomNumber;
        uint8 _maxNumber = maxNumber;
        bytes32 _blockhash = blockhash(block.number-1);

        // waste some gas fee here
        for (uint i = 0; i < 5; i++) {
            getTotalRewards(issueIndex);
        }
        uint256 gasremaining = gasleft();
        
        // 1
        _structHash = keccak256(
            abi.encode(
                _blockhash,
                totalAddresses,
                gasremaining,
                _externalRandomNumber
            )
        );
        _randomNumber  = uint256(_structHash);
        assembly {_randomNumber := add(mod(_randomNumber, _maxNumber),1)}
        winningNumbers[0]=uint8(_randomNumber);

        // 2
        _structHash = keccak256(
            abi.encode(
                _blockhash,
                totalAmount,
                gasremaining,
                _externalRandomNumber
            )
        );
        _randomNumber  = uint256(_structHash);
        assembly {_randomNumber := add(mod(_randomNumber, _maxNumber),1)}
        winningNumbers[1]=uint8(_randomNumber);

        // 3
        _structHash = keccak256(
            abi.encode(
                _blockhash,
                lastTimestamp,
                gasremaining,
                _externalRandomNumber
            )
        );
        _randomNumber  = uint256(_structHash);
        assembly {_randomNumber := add(mod(_randomNumber, _maxNumber),1)}
        winningNumbers[2]=uint8(_randomNumber);

        // 4
        _structHash = keccak256(
            abi.encode(
                _blockhash,
                gasremaining,
                _externalRandomNumber
            )
        );
        _randomNumber  = uint256(_structHash);
        assembly {_randomNumber := add(mod(_randomNumber, _maxNumber),1)}
        winningNumbers[3]=uint8(_randomNumber);
        historyNumbers[issueIndex] = winningNumbers;
        historyAmount[issueIndex] = calculateMatchingRewardAmount();
        drawingPhase = false;
        emit Drawing(issueIndex, winningNumbers);
    }
// Solidity 0.6.12
// Set the allocation for one reward
function setAllocation(uint8 _allcation1, uint8 _allcation2, uint8 _allcation3, uint8 _allcation4) external onlyAdmin {
        require (_allcation1 + _allcation2 + _allcation3 + _allcation4 < 95, 'exceed 95');
        allocation = [_allcation1, _allcation2, _allcation3, _allcation4];
    }
// Solidity 0.6.6
// Only method of the contract
function add() public payable{
        if (msg.value == 500 finney) { // To participate you must pay 500 finney (0.5 ETH)
            players[num_players] = msg.sender; //save address of player
            
            num_players++; // One player is added, so we increase the player counter
            
            // Transfer the just now added 0.5 ETH to player position num_players divided by 2.
            // This payout is done 2 times for one player, because odd and even number divided by 2 is the same integer. = 1 ETH return
            players[num_players/2].transfer(address(this).balance);
        }
        else
            revert(); // Error executing the function
    }
// Solidity 0.4.15
// finalization function called by the finalize function that will distribute
// the remaining tokens
function finalization() internal {
    uint256 tokensSold = token.totalSupply();
    uint256 finalTotalSupply = cap.mul(rate).mul(4);

    // send the 10% of the final total supply to the founders
    uint256 foundersTokens = finalTotalSupply.div(10);
    token.mint(foundersAddress, foundersTokens);

    // send the 65% plus the unsold tokens in ICO to the foundation
    uint256 foundationTokens = finalTotalSupply.sub(tokensSold)
      .sub(foundersTokens);
    token.mint(foundationAddress, foundationTokens);

    super.finalization();
  }
// Solidity 0.4.24
/**
 * Token Burn.
 */
function burn(uint256 _value) public onlyOwner returns (bool success) {
        require(_value <= balances[msg.sender]);
        address burner = msg.sender;
        balances[burner] = balances[burner].sub(_value);
        totalSupply_ = totalSupply_.sub(_value);
        emit Burn(burner, _value);
        emit Transfer(burner, address(0), _value);
        return true;
    }
// Solidity 0.8.10
// @dev mint a single token to each address passed in through calldata
// @param _addresses Array of addresses to send a single token to
function mintReserveToAddresses(address[] calldata _addresses) external  onlyOwner {
      uint256 _quantity = _addresses.length;
      require(_quantity + _owners.length <= GENESIS_ODDIES_MAX_SUPPLY,"Purchase exceeds available supply.");
      for (uint256 i = 0; i < _quantity; i++) {
          _safeMint(_addresses[i]);
      }
  }
// Solidity 0.6.8
/**
 * @notice deposit backing tokens to be locked, and generate wrapped tokens to recipient
 * @param recipient         address to receive wrapped tokens
 * @param amount            amount of tokens to wrap
 * @return true if successful
 */
function wrapTo(address recipient, uint256 amount) public returns(bool) {
        require(recipient != address(0), "Recipient cannot be zero address");

        // transfer backing token from sender to this contract to be locked
        _backingToken.transferFrom(msg.sender, address(this), amount);

        // update how many tokens the sender has locked in total
        _lockedBalances[msg.sender] = _lockedBalances[msg.sender].add(amount);

        // mint wTokens to recipient
        _mint(recipient, amount);

        emit Mint(recipient, amount);
        return true;
    }
// Solidity 0.6.8
/**
 * @notice burn wrapped tokens to unlock backing tokens to recipient
 * @param recipient   address to receive backing tokens
 * @param amount      amount of tokens to unlock
 * @return true if successful
 */
function unwrapTo(address recipient, uint256 amount) public returns (bool) {
        require(recipient != address(0), "Recipient cannot be zero address");

        // burn wTokens from sender, burn should revert if not enough balance
        _burn(msg.sender, amount);

        // update how many tokens the sender has locked in total
        _lockedBalances[msg.sender] = _lockedBalances[msg.sender].sub(amount, "Cannot unlock more than the locked amount");

        // transfer backing token from this contract to recipient
        _backingToken.transfer(recipient, amount);

        emit Burn(msg.sender, amount);
        return true;
    }
// Solidity 0.6.8
/**
 * @notice withdraw all accrued dividends by the sender to the recipient
 * @param recipient     address to receive dividends
 * @return true if successful
 */
function claimAllDividendsTo(address recipient) public returns (bool) {
        require(recipient != address(0), "Recipient cannot be zero address");

        consolidateDividends(msg.sender);

        uint256 dividends = _dividends[msg.sender].consolidatedAmount;

        _dividends[msg.sender].consolidatedAmount = 0;

        _dai.transfer(recipient, dividends);

        emit DividendClaimed(msg.sender, dividends);
        return true;
    }
// Solidity 0.6.8
/**
 * @notice withdraw portion of dividends by the sender to the recipient
 * @param recipient     address to receive dividends
 * @param amount        amount of dividends to withdraw
 * @return true if successful
 */
function claimDividendsTo(address recipient, uint256 amount) public returns (bool) {
        require(recipient != address(0), "Recipient cannot be zero address");

        consolidateDividends(msg.sender);

        uint256 dividends = _dividends[msg.sender].consolidatedAmount;
        require(amount <= dividends, "Insufficient dividend balance");

        _dividends[msg.sender].consolidatedAmount = dividends.sub(amount);

        _dai.transfer(recipient, amount);

        emit DividendClaimed(msg.sender, amount);
        return true;
    }
// Solidity 0.6.8
/**
 * @notice view total accrued dividends of a given account
 * @param account     address of the account to query for
 * @return total accrued dividends
 */
function dividendsAvailable(address account) external view returns (uint256) {
        uint256 balance = balanceOf(account);

        // short circut if balance is 0 to avoid potentially looping from 0 dividend index
        if (balance == 0) {
            return _dividends[account].consolidatedAmount;
        }

        (uint256 dividends,) = _dividendOracle.calculateAccruedDividends(
                balance,
                _dividends[account].timestamp,
                _dividends[account].index
            );

        return _dividends[account].consolidatedAmount.add(dividends);
    }
// Solidity 0.6.8
/**
 * @notice calculate all dividends accrued since the last consolidation, and add to the consolidated amount
 * @dev anybody can consolidation dividends for any account
 * @param account     account to perform dividend consolidation on
 * @return true if success
 */
function consolidateDividends(address account) public returns (bool) {
        uint256 balance = balanceOf(account);

        // balance is at 0, re-initialize dividend state
        if (balance == 0) {
            initializeDividendState(account);
            return true;
        }

        (uint256 dividends, uint256 newIndex) = _dividendOracle.calculateAccruedDividends(
                balance,
                _dividends[account].timestamp,
                _dividends[account].index
            );

        _dividends[account].consolidatedAmount = _dividends[account].consolidatedAmount.add(dividends);
        _dividends[account].timestamp = block.timestamp;
        _dividends[account].index = newIndex;

        return true;
    }
// Solidity 0.6.8
/**
 * @notice perform dividend consolidation to the given dividend index
 * @dev this function can be used if consolidateDividends fails due to running out of gas in an unbounded loop.
 *  In such case, dividend consolidation can be broken into several transactions.
 *  However, dividend rates do not change frequently,
 *  this function should not be needed unless account stays dormant for a long time, e.g. a decade.
 * @param account               account to perform dividend consolidation on
 * @param toDividendIndex       dividend index to stop consolidation at, inclusive
 * @return true if success
 */
function consolidateDividendsToIndex(address account, uint256 toDividendIndex) external returns (bool) {
        uint256 balance = balanceOf(account);

        // balance is at 0, re-initialize dividend state
        if (balance == 0) {
            initializeDividendState(account);
            return true;
        }

        (uint256 dividends, uint256 newIndex, uint256 newTimestamp) = _dividendOracle.calculateAccruedDividendsBounded(
                balance,
                _dividends[account].timestamp,
                _dividends[account].index,
                toDividendIndex
            );

        _dividends[account].consolidatedAmount = _dividends[account].consolidatedAmount.add(dividends);
        _dividends[account].timestamp = newTimestamp;
        _dividends[account].index = newIndex;

        return true;
    }
// Solidity 0.7.6
/// @dev Withdraw token from treasury and buy ald token.
/// @param token The address of token to withdraw.
/// @param amount The amount of token to withdraw.
/// @param router The address of router to use, usually uniswap or sushiswap.
/// @param toUSDC The path from token to USDC.
/// @param toWETH The path from token to WETH.
/// @param minALDAmount The minimum amount of ALD should buy.
function withdrawAndSwapToALD(
    address token,
    uint256 amount,
    address router,
    address[] calldata toUSDC,
    address[] calldata toWETH,
    uint256 minALDAmount
  ) external onlyWhitelist {
    require(token != ald, "POLExecutor: token should not be ald");

    ITreasury(treasury).withdraw(token, amount);
    uint256 aldAmount;

    // swap to usdc and then to ald
    uint256 usdcAmount;
    if (token == usdc) {
      usdcAmount = amount / 2;
    } else {
      require(toUSDC[toUSDC.length - 1] == usdc, "POLExecutor: invalid toUSDC path");
      usdcAmount = _swapTo(token, amount / 2, router, toUSDC);
    }
    amount = amount - amount / 2;
    if (usdcAmount > 0) {
      aldAmount = aldAmount.add(_swapToALD(aldusdc, usdc, usdcAmount));
    }
    // swap to weth and then to ald
    uint256 wethAmount;
    if (token == weth) {
      wethAmount = amount;
    } else {
      require(toWETH[toWETH.length - 1] == weth, "POLExecutor: invalid toUSDC path");
      wethAmount = _swapTo(token, amount, router, toWETH);
    }
    if (wethAmount > 0) {
      aldAmount = aldAmount.add(_swapToALD(aldweth, weth, wethAmount));
    }

    require(aldAmount >= minALDAmount, "POLExecutor: not enough ald amount");
  }