lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.10
/**
 * The winners of the pool can call this function to transfer their winnings
 * from the pool contract to their own address.
 */
function collectRewards() external {
        require(poolStatus == PoolStatus.CLOSED, "not settled");

        for (uint256 i = 0; i < poolConfig.participantLimit; i = i.add(1)) {
            address player = participants[i];
            if (winnerIndexes.contains(i)) {
                // if winner
                _transferEnterToken(player, rewardPerParticipant);
            } else {
                // if loser
                IChanceToken(controller.getChanceToken()).mint(player, chanceTokenId, 1);
            }
        }
        _resetPool();
    }
// Solidity 0.8.7
/**
 * adds DeezNuts NFT to the CasinoEmployees (staking)
 * @param account the address of the staker
 * @param tokenIds the IDs of the Sheep and Wolves to stake
 */
function addManyToCasino(address account, uint16[] calldata tokenIds, bytes32[][] calldata employmentProof) external whenNotPaused nonReentrant {
    require(account == _msgSender(), "Rechek sender of transaction");
    require(tokenIds.length > 0, "No tokens sent"); 

    for (uint i = 0; i < tokenIds.length; i++) {
        require(deezNutsNFT.ownerOf(tokenIds[i]) == _msgSender(), "Token isn't yours!");
        deezNutsNFT.transferFrom(_msgSender(), address(this), tokenIds[i]);
        _addTokenToCasino(account, tokenIds[i], employmentProof[i]);
        ownershipMapping[account].push(tokenIds[i]);
    }

    totalStaked += tokenIds.length;
    nuts.mint(msg.sender, tokenIds.length * 1000000000000000000);
  }
// Solidity 0.8.7
/**
 * adds a single Sheep to the Barn
 * @param account the address of the staker
 * @param tokenId the ID of the Sheep to add to the Barn
 */
function _addTokenToCasino(address account, uint16 tokenId, bytes32[] calldata proofOfEmployment) internal whenNotPaused _updateEarnings {
    uint72 tokenDailyRate = getDailyRateForToken(tokenId, proofOfEmployment);
    casinoEmployees[tokenId] = Stake({
      owner: account,
      tokenId: uint16(tokenId),
      value: uint40(block.timestamp),
      dailyRate: tokenDailyRate
    });
    DAILY_NUTS_RATE += tokenDailyRate;
  }
// Solidity 0.8.7
/**
 * realize $NUTS earnings for a single Nut
 * @param tokenId the ID of the Sheep to claim earnings from
 * @param unstake whether or not to unstake the Sheep
 * @return owed - the amount of $NUTS earned
 */
function _claimNutFromCasino(uint16 tokenId, bool unstake) internal returns (uint128 owed) {
    Stake memory stake = casinoEmployees[tokenId];
    require(stake.owner == _msgSender(), "Not the stake owner");

    if (totalNutsEarned < MAXIMUM_GLOBAL_NUTS) {
        owed = uint128(((block.timestamp.sub(stake.value)).mul(stake.dailyRate)).div(1 days));
      } else if (stake.value > lastClaimTimestamp) {
        owed = 0; // $NUTS production stopped already
      } else {
        owed = uint128((lastClaimTimestamp.sub(stake.value)).mul(stake.dailyRate / 1 days)); // stop earning additional $NUTS if it's all been earned
      }

    if (unstake) {
      deezNutsNFT.safeTransferFrom(address(this), _msgSender(), tokenId, ""); // send back Nut
      DAILY_NUTS_RATE -= stake.dailyRate;
      delete casinoEmployees[tokenId];
    } else {
      casinoEmployees[tokenId] = Stake({
        owner: stake.owner,
        tokenId: uint16(tokenId),
        value: uint40(block.timestamp),
        dailyRate: stake.dailyRate
      });
    }
  }
// Solidity 0.8.7
/**
 * emergency unstake tokens
 * @param tokenIds the IDs of the tokens to claim earnings from
 */
function rescue(uint16[] calldata tokenIds) external nonReentrant {
    require(rescueEnabled, "RESCUE DISABLED");
    uint16 tokenId;
    Stake memory stake;
    for (uint i = 0; i < tokenIds.length; i++) {
        tokenId = tokenIds[i];
        stake = casinoEmployees[tokenId];
        require(stake.owner == _msgSender(), "Only owner can withdraw");
        deezNutsNFT.safeTransferFrom(address(this), _msgSender(), tokenId, ""); // send back Nut
        delete casinoEmployees[tokenId];
        DAILY_NUTS_RATE -= stake.dailyRate;
    }                                                       
  }
// Solidity 0.6.10
/**
 * Creates a ProphetPool smart contract set the manager(owner) of the pool.
 *
 * @param _poolName             Pool name
 * @param _buyToken             ERC20 token to enter the pool
 * @param _manager              Manager of the pool
 * @param _feeRecipient         Where the fee of the prophet pool go
 * @param _chanceTokenId        ERC1155 Token id for chance token
 */
function createProphetPool(
        string memory _poolName,
        address _buyToken,
        address _manager,
        address _feeRecipient,
        uint256 _chanceTokenId
    ) external onlyAllowedCreator(msg.sender) returns (address) {
        require(_buyToken != address(0), "invalid buyToken");
        require(_manager != address(0), "invalid manager");

        // Creates a new pool instance
        ProphetPool prophetPool =
            new ProphetPool(
                _poolName,
                _buyToken,
                address(this),
                _feeRecipient,
                _chanceTokenId
            );

        // Set the manager for the pool
        prophetPool.transferOwnership(_manager);
        prophetPools.push(address(prophetPool));

        emit ProphetPoolCreated(address(prophetPool), _poolName, _buyToken, _manager, _feeRecipient, _chanceTokenId);

        return address(prophetPool);
    }
// Solidity 0.6.10
/**
 * Creates a SecondChancePool smart contract set the manager(owner) of the pool.
 *
 * @param _poolName             Pool name
 * @param _rewardToken          Reward token of the pool
 * @param _manager              Manager of the pool
 * @param _chanceTokenId        ERC1155 Token id for chance token
 */
function createSecondChancePool(
        string memory _poolName,
        address _rewardToken,
        address _manager,
        uint256 _chanceTokenId
    ) external onlyAllowedCreator(msg.sender) returns (address) {
        require(_rewardToken != address(0), "invalid rewardToken");
        require(_manager != address(0), "invalid manager");

        // Creates a new pool instance
        SecondChancePool secondChancePool =
            new SecondChancePool(
                _poolName,
                _rewardToken,
                address(this),
                _chanceTokenId
            );

        // Set the manager for the pool
        secondChancePool.transferOwnership(_manager);
        secondChancePools.push(address(secondChancePool));

        emit SecondChancePoolCreated(
            address(secondChancePool),
            _poolName,
            _rewardToken,
            _manager,
            _chanceTokenId
        );

        return address(secondChancePool);
    }
// Solidity 0.6.10
/**
 * OWNER ONLY: Toggle ability for passed addresses to create a prophet pool 
 *
 * @param _creators          Array creator addresses to toggle status
 * @param _statuses          Booleans indicating if matching creator can create
 */
function updateCreatorStatus(address[] calldata _creators, bool[] calldata _statuses) external onlyOwner {
        require(_creators.length == _statuses.length, "array mismatch");
        require(_creators.length > 0, "invalid length");

        for (uint256 i = 0; i < _creators.length; i++) {
            address creator = _creators[i];
            bool status = _statuses[i];
            createAllowList[creator] = status;
            emit CreatorStatusUpdated(creator, status);
        }
    }
// Solidity 0.5.16
/**
 	 * @param _startIndex start index
 	 * @param _endIndex end index
 	 * @param _revert sort array asc or desc
 	 * @return the list of the beneficiary addresses
 	 */
function paginationBeneficiaries(uint256 _startIndex, uint256 _endIndex, bool _revert) public view returns (address[] memory) {
		uint256 startIndex = _startIndex;
		uint256 endIndex = _endIndex;
		if (startIndex >= _lockupBeneficiaries.length) {
			return new address[](0);
		}
		if (endIndex > _lockupBeneficiaries.length) {
			endIndex = _lockupBeneficiaries.length;
		}
		// make memory array
		address[] memory beneficiaries = new address[](endIndex.sub(startIndex));
		if (_revert) {
			for (uint256 i = endIndex; i > startIndex; i--) {
				beneficiaries[endIndex.sub(i)] = _lockupBeneficiaries[i.sub(1)];
			}
			return beneficiaries;
		}
		for (uint256 i = startIndex; i < endIndex; i++) {
			beneficiaries[i.sub(startIndex)] = _lockupBeneficiaries[i];
		}
		return beneficiaries;
	}
// Solidity 0.5.16
/**
 	 * @param _beneficiary beneficiary address
 	 * @param _startIndex start index
 	 * @param _endIndex end index
 	 * @param _revert sort array asc or desc
 	 * @return the list of the bundle identifies of beneficiary address
 	 */
function paginationBundleIdentifiesOf(address _beneficiary, uint256 _startIndex, uint256 _endIndex, bool _revert) public view returns (uint256[] memory) {
		uint256 startIndex = _startIndex;
		uint256 endIndex = _endIndex;
		if (startIndex >= _lockupIdsOfBeneficiary[_beneficiary].length) {
			return new uint256[](0);
		}
		if (endIndex >= _lockupIdsOfBeneficiary[_beneficiary].length) {
			endIndex = _lockupIdsOfBeneficiary[_beneficiary].length;
		}
		// make memory array
		uint256[] memory identifies = new uint256[](endIndex.sub(startIndex));
		if (_revert) {
			for (uint256 i = endIndex; i > startIndex; i--) {
				identifies[endIndex.sub(i)] = _lockupIdsOfBeneficiary[_beneficiary][i.sub(1)];
			}
			return identifies;
		}
		for (uint256 i = startIndex; i < endIndex; i++) {
			identifies[i.sub(startIndex)] = _lockupIdsOfBeneficiary[_beneficiary][i];
		}
		return identifies;
	}
// Solidity 0.4.13
// @param _startBlock
// @param _endBlock
// @param _wolkWallet
// @return success
// @dev Wolk Genesis Event [only accessible by Contract Owner]
function wolkGenesis(uint256 _startBlock, uint256 _endBlock, address _wolkWallet) onlyOwner returns (bool success){
        require( (totalTokens < 1) && (!settlers[msg.sender]) && (_endBlock > _startBlock) );
        start_block = _startBlock;
        end_block = _endBlock;
        multisigWallet = _wolkWallet;
        settlers[msg.sender] = true;
        return true;
    }
// Solidity 0.4.13
// @dev Token Generation Event for Wolk Protocol Token. TGE Participant send Eth into this func in exchange of Wolk Protocol Token
function tokenGenerationEvent() payable external {
        require(!saleCompleted);
        require( (block.number >= start_block) && (block.number <= end_block) );
        uint256 tokens = safeMul(msg.value, 5*10**9); //exchange rate
        uint256 checkedSupply = safeAdd(totalTokens, tokens);
        require(checkedSupply <= tokenGenerationMax);
        totalTokens = checkedSupply;
        balances[msg.sender] = safeAdd(balances[msg.sender], tokens);  
        contribution[msg.sender] = safeAdd(contribution[msg.sender], msg.value);  
        WolkCreated(msg.sender, tokens); // logs token creation
    }
// Solidity 0.4.13
// @dev If Token Generation Minimum is Not Met, TGE Participants can call this func and request for refund
function refund() external {
        require( (contribution[msg.sender] > 0) && (!saleCompleted) && (totalTokens < tokenGenerationMin) && (block.number > end_block) );
        uint256 tokenBalance = balances[msg.sender];
        uint256 refundBalance = contribution[msg.sender];
        balances[msg.sender] = 0;
        contribution[msg.sender] = 0;
        totalTokens = safeSub(totalTokens, tokenBalance);
        WolkDestroyed(msg.sender, tokenBalance);
        LogRefund(msg.sender, refundBalance);
        msg.sender.transfer(refundBalance); 
    }
// Solidity 0.4.13
// @param  _serviceProvider
// @param  _feeBasisPoints
// @return success
// @dev Set Service Provider fee -- only Contract Owner can do this, affects Service Provider settleSeller
function setServiceFee(address _serviceProvider, uint256 _feeBasisPoints) onlyOwner returns (bool success) {
        if ( _feeBasisPoints <= 0 || _feeBasisPoints > 4000){
            // revoke Settler privilege
            settlers[_serviceProvider] = false;
            feeBasisPoints[_serviceProvider] = 0;
            return false;
        }else{
            feeBasisPoints[_serviceProvider] = _feeBasisPoints;
            settlers[_serviceProvider] = true;
            SetServiceProviderFee(_serviceProvider, _feeBasisPoints);
            return true;
        }
    }
// Solidity 0.4.13
// @param  _buyer
// @param  _value
// @return success
// @dev Service Provider Settlement with Buyer: a small percent is burnt (set in setBurnRate, stored in burnBasisPoints) when funds are transferred from buyer to Service Provider [only accessible by settlers]
function settleBuyer(address _buyer, uint256 _value) onlySettler returns (bool success) {
        require( (burnBasisPoints > 0) && (burnBasisPoints <= 1000) && authorized[_buyer][msg.sender] ); // Buyer must authorize Service Provider 
        if ( balances[_buyer] >= _value && _value > 0) {
            var burnCap = safeDiv(safeMul(_value, burnBasisPoints), 10000);
            var transferredToServiceProvider = safeSub(_value, burnCap);
            balances[_buyer] = safeSub(balances[_buyer], _value);
            balances[msg.sender] = safeAdd(balances[msg.sender], transferredToServiceProvider);
            totalTokens = safeSub(totalTokens, burnCap);
            Transfer(_buyer, msg.sender, transferredToServiceProvider);
            BurnTokens(_buyer, msg.sender, burnCap);
            return true;
        } else {
            return false;
        }
    }
// Solidity 0.5.16
/**
 	 * @return the all phases detail
 	 */
function getLockupPhases() public view returns (uint256[] memory ids, uint256[] memory percentages, uint256[] memory extraTimes, bool[] memory hasWithdrawals, bool[] memory canWithdrawals) {
		ids = new uint256[](_lockupPhases.length);
		percentages = new uint256[](_lockupPhases.length);
		extraTimes = new uint256[](_lockupPhases.length);
		hasWithdrawals = new bool[](_lockupPhases.length);
		canWithdrawals = new bool[](_lockupPhases.length);

		for (uint256 i = 0; i < _lockupPhases.length; i++) {
			LockupPhase memory phase = _lockupPhases[i];
			ids[i] = phase.id;
			percentages[i] = phase.percentage;
			extraTimes[i] = phase.extraTime;
			hasWithdrawals[i] = phase.hasWithdrawal;
			canWithdrawals[i] = checkPhaseCanWithdrawal(phase.id);
		}
	}
// Solidity 0.4.13
// @param _owner
// @param _providerToAdd
// @return authorizationStatus
// @dev Grant authorization between account and Service Provider on buyers' behalf [only accessible by Contract Owner]
// @note Explicit permission from balance owner MUST be obtained beforehand
function grantService(address _owner, address _providerToAdd) onlyOwner returns (bool authorizationStatus) {
        var isPreauthorized = authorized[_owner][msg.sender];
        if (isPreauthorized && settlers[_providerToAdd] ) {
            authorized[_owner][_providerToAdd] = true;
            AuthorizeServiceProvider(msg.sender, _providerToAdd);
            return true;
        }else{
            return false;
        }
    }
// Solidity 0.4.13
/**
 @dev given a token supply, reserve, CRR and a deposit amount (in the reserve token), calculates the return for a given change (in the main token)
 
 Formula:
 Return = _supply * ((1 + _depositAmount / _reserveBalance) ^ (_reserveRatio / 100) - 1)
 
 @param _supply             token total supply
 @param _reserveBalance     total reserve
 @param _reserveRatio       constant reserve ratio, 1-100
 @param _depositAmount      deposit amount, in reserve token
 
 @return purchase return amount
 */
function calculatePurchaseReturn(uint256 _supply, uint256 _reserveBalance, uint16 _reserveRatio, uint256 _depositAmount) public constant returns (uint256) {
        // validate input
        require(_supply != 0 && _reserveBalance != 0 && _reserveRatio > 0 && _reserveRatio <= 100);

        // special case for 0 deposit amount
        if (_depositAmount == 0)
            return 0;

        uint256 baseN = safeAdd(_depositAmount, _reserveBalance);
        uint256 temp;

        // special case if the CRR = 100
        if (_reserveRatio == 100) {
            temp = safeMul(_supply, baseN) / _reserveBalance;
            return safeSub(temp, _supply); 
        }

        uint256 resN = power(baseN, _reserveBalance, _reserveRatio, 100);

        temp = safeMul(_supply, resN) / FIXED_ONE;

        uint256 result =  safeSub(temp, _supply);
        // from the result, we deduct the minimal increment, which is a         
        // function of S and precision.       
        return safeSub(result, _supply / 0x100000000);
     }
// Solidity 0.4.13
/**
 @dev given a token supply, reserve, CRR and a sell amount (in the main token), calculates the return for a given change (in the reserve token)
 
 Formula:
 Return = _reserveBalance * (1 - (1 - _sellAmount / _supply) ^ (1 / (_reserveRatio / 100)))
 
 @param _supply             token total supply
 @param _reserveBalance     total reserve
 @param _reserveRatio       constant reserve ratio, 1-100
 @param _sellAmount         sell amount, in the token itself
 
 @return sale return amount
 */
function calculateSaleReturn(uint256 _supply, uint256 _reserveBalance, uint16 _reserveRatio, uint256 _sellAmount) public constant returns (uint256) {
        // validate input
        require(_supply != 0 && _reserveBalance != 0 && _reserveRatio > 0 && _reserveRatio <= 100 && _sellAmount <= _supply);

        // special case for 0 sell amount
        if (_sellAmount == 0)
            return 0;

        uint256 baseN = safeSub(_supply, _sellAmount);
        uint256 temp1;
        uint256 temp2;

        // special case if the CRR = 100
        if (_reserveRatio == 100) {
            temp1 = safeMul(_reserveBalance, _supply);
            temp2 = safeMul(_reserveBalance, baseN);
            return safeSub(temp1, temp2) / _supply;
        }

        // special case for selling the entire supply
        if (_sellAmount == _supply)
            return _reserveBalance;

        uint256 resN = power(_supply, baseN, 100, _reserveRatio);

        temp1 = safeMul(_reserveBalance, resN);
        temp2 = safeMul(_reserveBalance, FIXED_ONE);

        uint256 result = safeSub(temp1, temp2) / resN;

        // from the result, we deduct the minimal increment, which is a         
        // function of R and precision.       
        return safeSub(result, _reserveBalance / 0x100000000);
    }
// Solidity 0.4.13
/**
 @dev Calculate (_baseN / _baseD) ^ (_expN / _expD)
 Returns result upshifted by PRECISION
 
 This method is overflow-safe
 */
function power(uint256 _baseN, uint256 _baseD, uint32 _expN, uint32 _expD) internal returns (uint256 resN) {
        uint256 logbase = ln(_baseN, _baseD);
        // Not using safeDiv here, since safeDiv protects against
        // precision loss. It’s unavoidable, however
        // Both `ln` and `fixedExp` are overflow-safe. 
        resN = fixedExp(safeMul(logbase, _expN) / _expD);
        return resN;
    }
// Solidity 0.4.13
/**
 input range: 
 - numerator: [1, uint256_max >> PRECISION]    
 - denominator: [1, uint256_max >> PRECISION]
 output range:
 [0, 0x9b43d4f8d6]
 
 This method asserts outside of bounds
 
 */
function ln(uint256 _numerator, uint256 _denominator) internal returns (uint256) {
        // denominator > numerator: less than one yields negative values. Unsupported
        assert(_denominator <= _numerator);

        // log(1) is the lowest we can go
        assert(_denominator != 0 && _numerator != 0);

        // Upper 32 bits are scaled off by PRECISION
        assert(_numerator < MAX_VAL);
        assert(_denominator < MAX_VAL);

        return fixedLoge( (_numerator * FIXED_ONE) / _denominator);
    }
// Solidity 0.4.13
/**
 input range: 
 [0x100000000,uint256_max]
 output range:
 [0, 0x9b43d4f8d6]
 
 This method asserts outside of bounds
 
 */
function fixedLoge(uint256 _x) internal returns (uint256 logE) {
        /*
        Since `fixedLog2_min` output range is max `0xdfffffffff` 
        (40 bits, or 5 bytes), we can use a very large approximation
        for `ln(2)`. This one is used since it’s the max accuracy 
        of Python `ln(2)`

        0xb17217f7d1cf78 = ln(2) * (1 << 56)
        
        */
        //Cannot represent negative numbers (below 1)
        assert(_x >= FIXED_ONE);

        uint256 log2 = fixedLog2(_x);
        logE = (log2 * 0xb17217f7d1cf78) >> 56;
    }
// Solidity 0.4.13
/**
 Returns log2(x >> 32) << 32 [1]
 So x is assumed to be already upshifted 32 bits, and 
 the result is also upshifted 32 bits. 
 
 [1] The function returns a number which is lower than the 
 actual value
 
 input-range : 
 [0x100000000,uint256_max]
 output-range: 
 [0,0xdfffffffff]
 
 This method asserts outside of bounds
 
 */
function fixedLog2(uint256 _x) internal returns (uint256) {
        // Numbers below 1 are negative. 
        assert( _x >= FIXED_ONE);

        uint256 hi = 0;
        while (_x >= FIXED_TWO) {
            _x >>= 1;
            hi += FIXED_ONE;
        }

        for (uint8 i = 0; i < PRECISION; ++i) {
            _x = (_x * _x) / FIXED_ONE;
            if (_x >= FIXED_TWO) {
                _x >>= 1;
                hi += uint256(1) << (PRECISION - 1 - i);
            }
        }

        return hi;
    }
// Solidity 0.4.13
// @return Estimated Liquidation Cap
// @dev Liquidation Cap per transaction is used to ensure proper price discovery for Wolk Exchange 
function EstLiquidationCap() public constant returns (uint256) {
        if (saleCompleted){
            var liquidationMax  = safeDiv(safeMul(totalTokens, maxPerExchangeBP), 10000);
            if (liquidationMax < 100 * 10**decimals){ 
                liquidationMax = 100 * 10**decimals;
            }
            return liquidationMax;   
        }else{
            return 0;
        }
    }
// Solidity 0.4.13
// @param _wolkAmount
// @return ethReceivable
// @dev send Wolk into contract in exchange for eth, at an exchange rate based on the Bancor Protocol derivation and decrease totalSupply accordingly
function sellWolk(uint256 _wolkAmount) isTransferable() external returns(uint256) {
        uint256 sellCap = EstLiquidationCap();
        uint256 ethReceivable = calculateSaleReturn(totalTokens, reserveBalance, percentageETHReserve, _wolkAmount);
        require( (sellCap >= _wolkAmount) && (balances[msg.sender] >= _wolkAmount) && (this.balance > ethReceivable) );
        balances[msg.sender] = safeSub(balances[msg.sender], _wolkAmount);
        totalTokens = safeSub(totalTokens, _wolkAmount);
        reserveBalance = safeSub(this.balance, ethReceivable);
        WolkDestroyed(msg.sender, _wolkAmount);
        msg.sender.transfer(ethReceivable);
        return ethReceivable;     
    }