lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.12
/**
 @notice This function gives the amount of tokens on zapping out from given BPool
 @param _FromBalancerPoolAddress Address of balancer pool to zapout from
 @param _IncomingBPT The amount of BPT to zapout
 @param _toToken Address of token to zap out with
 @return Amount of ERC token
 */
function getBPT2Token(
        address _FromBalancerPoolAddress,
        uint256 _IncomingBPT,
        address _toToken
    ) internal view returns (uint256 tokensReturned) {
        uint256 totalSupply = IBPool_Balancer_Unzap_V1_1(
            _FromBalancerPoolAddress
        ).totalSupply();
        uint256 swapFee = IBPool_Balancer_Unzap_V1_1(_FromBalancerPoolAddress)
            .getSwapFee();
        uint256 totalWeight = IBPool_Balancer_Unzap_V1_1(
            _FromBalancerPoolAddress
        ).getTotalDenormalizedWeight();
        uint256 balance = IBPool_Balancer_Unzap_V1_1(_FromBalancerPoolAddress)
            .getBalance(_toToken);
        uint256 denorm = IBPool_Balancer_Unzap_V1_1(_FromBalancerPoolAddress)
            .getDenormalizedWeight(_toToken);

        tokensReturned = IBPool_Balancer_Unzap_V1_1(_FromBalancerPoolAddress)
            .calcSingleOutGivenPoolIn(
            balance,
            denorm,
            totalSupply,
            totalWeight,
            _IncomingBPT,
            swapFee
        );
    }
// Solidity 0.5.12
/**
 @notice This function is used to zap out of the given balancer pool
 @param _FromBalancerPoolAddress The address of balancer pool to zap out
 @param _ToTokenContractAddress The Token address which will be zapped out
 @param _amount The amount of token for zapout
 @return The amount of tokens received after zap out
 */
function _exitBalancer(
        address _FromBalancerPoolAddress,
        address _ToTokenContractAddress,
        uint256 _amount
    ) internal returns (uint256 returnedTokens) {
        require(
            IBPool_Balancer_Unzap_V1_1(_FromBalancerPoolAddress).isBound(
                _ToTokenContractAddress
            ),
            "Token not bound"
        );

        returnedTokens = IBPool_Balancer_Unzap_V1_1(_FromBalancerPoolAddress)
            .exitswapPoolAmountIn(_ToTokenContractAddress, _amount, 1);

        require(returnedTokens > 0, "Error in exiting balancer pool");
    }
// Solidity 0.5.12
/**
 @notice This function is used to swap tokens
 @param _FromTokenContractAddress The token address to swap from
 @param _ToWhomToIssue The address to transfer after swap
 @param _ToTokenContractAddress The token address to swap to
 @param tokens2Trade The quantity of tokens to swap
 @return The amount of tokens returned after swap
 */
function _token2Token(
        address _FromTokenContractAddress,
        address _ToWhomToIssue,
        address _ToTokenContractAddress,
        uint256 tokens2Trade
    ) internal returns (uint256 tokenBought) {

        Iuniswap_Balancer_Unzap_V1_1 FromUniSwapExchangeContractAddress
        = Iuniswap_Balancer_Unzap_V1_1(
            UniSwapFactoryAddress.getExchange(_FromTokenContractAddress)
        );

        IERC20(_FromTokenContractAddress).approve(
            address(FromUniSwapExchangeContractAddress),
            tokens2Trade
        );

        tokenBought = FromUniSwapExchangeContractAddress
            .tokenToTokenTransferInput(
            tokens2Trade,
            1,
            1,
            SafeMath.add(now, 300),
            _ToWhomToIssue,
            _ToTokenContractAddress
        );
        require(tokenBought > 0, "Error in swapping ERC: 1");
    }
// Solidity 0.8.4
/**
 * @dev Attempt to send a user or contract ETH and if it fails store the amount owned for later withdrawal.
 */
function _sendValueWithFallbackWithdraw(
        address payable user,
        uint256 amount,
        uint256 gasLimit
    ) private {
        if (amount == 0) {
            return;
        }
        // Cap the gas to prevent consuming all available gas to block a tx from completing successfully
        // solhint-disable-next-line avoid-low-level-calls
        (bool success, ) = user.call{value: amount, gas: gasLimit}("");
        if (!success) {
            // Record failed sends for a withdrawal later
            // Transfers could fail if sent to a multisig with non-trivial receiver logic
            // solhint-disable-next-line reentrancy
            pendingWithdrawals[user] = pendingWithdrawals[user].add(amount);
            emit WithdrawPending(user, amount);
        }
    }
// Solidity 0.8.4
/**
 * @dev Returns the creator and a destination address for any payments to the creator,
 * returns address(0) if the creator is unknown.
 */
function _getCreatorAndPaymentAddress(address nftContract, uint256 tokenId)
        internal
        view
        returns (address payable, address payable)
    {
        address payable creator = _getCreator(nftContract, tokenId);
        try
            IBLSNFT721(nftContract).getTokenCreatorPaymentAddress(tokenId)
        returns (address payable tokenCreatorPaymentAddress) {
            if (tokenCreatorPaymentAddress != address(0)) {
                return (creator, tokenCreatorPaymentAddress);
            }
        } catch // solhint-disable-next-line no-empty-blocks
        {
            // Fall through to return (creator, creator) below
        }
        return (creator, creator);
    }
// Solidity 0.7.1
/**
 * @dev Deploys a new `StablePool`.
 */
function create(
        string memory name,
        string memory symbol,
        IERC20[] memory tokens,
        uint256 amplificationParameter,
        uint256 swapFeePercentage,
        address owner
    ) external returns (address) {
        (uint256 pauseWindowDuration, uint256 bufferPeriodDuration) = getPauseConfiguration();

        address pool = address(
            new StablePool(
                getVault(),
                name,
                symbol,
                tokens,
                amplificationParameter,
                swapFeePercentage,
                pauseWindowDuration,
                bufferPeriodDuration,
                owner
            )
        );
        _register(pool);
        return pool;
    }
// Solidity 0.5.16
// the value which is incremeted in the struct after the waitingTime
function addValueCustomTime(uint256 _transferedValue, uint256 _waitingTime)   public onlyOwner
    {
       if(_transferedValue > 0 ) // otherwise there is no need to add a value in the array
        {
            uint256 unlockTime = block.timestamp + _waitingTime;
            bool found = false;
            uint256 index;

            for(uint i = 0; i<_latencyArray.length; i++)
            {
                if (_latencyArray[i].time > unlockTime)
                {
                    index = i;
                    found = true;
                    break;
                }
            }

            if (found)
            {  // we need to shift all the indices
            _latencyArray.push(LatencyPoint(_latencyArray[_latencyArray.length-1].time, _latencyArray[_latencyArray.length-1].value + _transferedValue));

                 for(uint i = _latencyArray.length - 2; i>index; i--)
                 {
                     _latencyArray[i].time = _latencyArray[i-1].time;
                     _latencyArray[i].value = _latencyArray[i-1].value + _transferedValue;
                 }

                 _latencyArray[index].time = unlockTime;

                 if (index>0){
                    _latencyArray[index].value = _latencyArray[index-1].value + _transferedValue;
                 }else
                 {
                    _latencyArray[index].value = _transferedValue;
                 }
            }else
            { // the timestamp is after all the others
                 if (_latencyArray.length>0){
                    _latencyArray.push(LatencyPoint(unlockTime,_latencyArray[_latencyArray.length-1].value + _transferedValue));
                 }
                 else
                 {
                    _latencyArray.push(LatencyPoint(unlockTime, _transferedValue));
                 }
            }
        }
    }
// Solidity 0.5.16
// you need to keep at least the last one such that you know how much you can withdraw
function removePastPoints() private
    {
        uint i = 0;
        while (i < _latencyArray.length && _latencyArray[i].time < block.timestamp)
        {
            i++;
        }
        if (i==0) // everything is still in the future
        {
            //_latencyArray.length=0;
        }
        else if (i == _latencyArray.length) // then we need to keep the last entry
        {
          _latencyArray[0] = _latencyArray[i-1];
          _latencyArray.length = 1;
        }
        else // i is the first item that is bigger -> so we need to keep all the coming ones
        {
            i--; // you need to keep the last entry of the past if its not zero
            uint j = 0;
            while (j<_latencyArray.length-i)
            {
              _latencyArray[j] = _latencyArray[j+i];
              j++;
            }
            _latencyArray.length = _latencyArray.length-i;
        }
    }
// Solidity 0.5.16
//if you transfer token from one address to the other you reduce the total amount
function reduceValue(uint256 _value) public onlyOwner
    {
        removePastPoints();

        for(uint i=0; i<_latencyArray.length; i++)
        {
            if(_latencyArray[i].value<_value)
            {
                _latencyArray[i].value = 0;
            }
            else
            {
                _latencyArray[i].value -= _value;
            }
        }
        removeZeroValues(); //removes zero values form the array
    }
// Solidity 0.5.16
// returns the first point that is strictly larger than the amount
function withdrawSteps(uint256 _amount) public view returns (uint256 Steps)
    {
        uint256 steps = 0;
        // we need the first index, that is larger or euqal to the amount
        for(uint i = 0;i<_latencyArray.length;i++)
        {
            steps = i;
            if(_latencyArray[i].value > _amount)
            {
                break;
            }

        }
        return steps;
    }
// Solidity 0.5.16
//everyone can deposit ether into the contract
function deposit() public payable
    {
        // nothing else to do!
       // require(msg.value>0); // value is always unsigned -> if someone sends negative values it will increase the balance
        emit TransferWei(msg.sender, msg.value);
    }
// Solidity 0.5.16
// optional functions useful for debugging
function withdrawableAmount(address _addr) public view returns(uint256 value)
    {
        if (balanceOf(_addr)==0) {
            return 0;
        }
        if (_addr != owner)
        {
            return  _latencyOf[_addr].withdrawableAmount();
        }
        else
        {
            return balanceOf(_addr); // the owner can always access its token
        }
    }
// Solidity 0.8.4
/**
 * @notice Returns how funds will be distributed for a sale at the given price point.
 * @dev This could be used to present exact fee distributing on listing or before a bid is placed.
 */
function getFees(
        address nftContract,
        uint256 tokenId,
        uint256 price
    )
        public
        view
        returns (
            uint256 blocksportFee,
            uint256 creatorSecondaryFee,
            uint256 ownerRev
        )
    {
        (blocksportFee, , creatorSecondaryFee, , ownerRev) = _getFees(
            nftContract,
            tokenId,
            _getSellerFor(nftContract, tokenId),
            price
        );
    }
// Solidity 0.8.4
/**
 * @dev Distributes funds to blocksport, creator, and NFT owner after a sale.
 */
function _distributeFunds(
        address nftContract,
        uint256 tokenId,
        address payable seller,
        uint256 price
    )
        internal
        returns (
            uint256 blocksportFee,
            uint256 creatorFee,
            uint256 ownerRev
        )
    {
        address payable creatorFeeTo;
        address payable ownerRevTo;
        (
            blocksportFee,
            creatorFeeTo,
            creatorFee,
            ownerRevTo,
            ownerRev
        ) = _getFees(nftContract, tokenId, seller, price);

        // Anytime fees are distributed that indicates the first sale is complete,
        // which will not change state during a secondary sale.
        // This must come after the `_getFees` call above as this state is considered in the function.
        nftContractToTokenIdToFirstSaleCompleted[nftContract][tokenId] = true;

        _sendValueWithFallbackWithdrawWithLowGasLimit(
            getBlocksportTreasury(),
            blocksportFee
        );
        _sendValueWithFallbackWithdrawWithMediumGasLimit(
            creatorFeeTo,
            creatorFee
        );
        _sendValueWithFallbackWithdrawWithMediumGasLimit(ownerRevTo, ownerRev);
    }
// Solidity 0.8.4
/**
 * @notice Allows blocksport to change the market fees.
 */
function _updateMarketFees(
        uint256 primaryBlocksportFeeBasisPoints,
        uint256 secondaryBlocksportFeeBasisPoints,
        uint256 secondaryCreatorFeeBasisPoints
    ) internal {
        require(
            primaryBlocksportFeeBasisPoints < BASIS_POINTS,
            "NFTMarketFees: Fees >= 100%"
        );
        require(
            secondaryBlocksportFeeBasisPoints.add(
                secondaryCreatorFeeBasisPoints
            ) < BASIS_POINTS,
            "NFTMarketFees: Fees >= 100%"
        );
        _primaryBlocksportFeeBasisPoints = primaryBlocksportFeeBasisPoints;
        _secondaryBlocksportFeeBasisPoints = secondaryBlocksportFeeBasisPoints;
        _secondaryCreatorFeeBasisPoints = secondaryCreatorFeeBasisPoints;

        emit MarketFeesUpdated(
            primaryBlocksportFeeBasisPoints,
            secondaryBlocksportFeeBasisPoints,
            secondaryCreatorFeeBasisPoints
        );
    }
// Solidity 0.7.1
// Swap Hooks
function onSwap(
        SwapRequest memory swapRequest,
        uint256[] memory balances,
        uint256 indexIn,
        uint256 indexOut
    ) external view virtual override returns (uint256) {
        _validateIndexes(indexIn, indexOut, _getTotalTokens());
        uint256[] memory scalingFactors = _scalingFactors();

        return
            swapRequest.kind == IVault.SwapKind.GIVEN_IN
                ? _swapGivenIn(swapRequest, balances, indexIn, indexOut, scalingFactors)
                : _swapGivenOut(swapRequest, balances, indexIn, indexOut, scalingFactors);
    }
// Solidity 0.8.4
/**
 * @dev Random draw lottery winners from an array of addresses, mint NFT,
 * and emit an event to record winners.
 *
 * Emits a {LotteryWinners} event.
 */
function drawLottery(address[] calldata addresses_, uint256 amount_)
        public
        onlyOwner
    {
        // empty array to store winner addresses
        address[] memory winners = _randomDraw(addresses_, amount_);

        // batch mint NFT for winners
        batchMint(winners, 1);

        // record lottery winners
        emit LotteryWinners(winners);
    }
// Solidity 0.8.4
/**
 * @dev Random draw from an array of addresses and return the result.
 */
function _randomDraw(address[] memory addresses_, uint256 amount_)
        public
        view
        returns (address[] memory result)
    {
        require(
            amount_ <= addresses_.length,
            "amount_ must be less than or equal to addresses_.length"
        );

        // empty array to store result
        result = new address[](amount_);

        for (uint256 i = 0; i < amount_; i++) {
            uint256 random = uint256(
                keccak256(
                    abi.encodePacked(
                        i,
                        msg.sender,
                        block.coinbase,
                        block.difficulty,
                        block.gaslimit,
                        block.timestamp
                    )
                )
            ) % (addresses_.length - i);

            result[i] = addresses_[random];

            addresses_[random] = addresses_[addresses_.length - i - 1];
        }

        return result;
    }
// Solidity 0.8.4
/**
 * @dev Append a new log to logbook
 *
 * Emits a {LogbookNewLog} event.
 */
function appendLog(uint256 tokenId_, string calldata message_) public {
        require(
            _isApprovedOrOwner(_msgSender(), tokenId_),
            "caller is not owner nor approved"
        );
        require(!logbook[tokenId_].isLocked, "logbook is locked");

        address owner = ERC721.ownerOf(tokenId_);
        Log memory newLog = Log({
            sender: owner,
            message: message_,
            createdAt: block.timestamp
        });

        logbook[tokenId_].logs.push(newLog);
        logbook[tokenId_].isLocked = true;

        emit LogbookNewLog(tokenId_, logbook[tokenId_].logs.length - 1, owner);
    }
// Solidity 0.8.4
/**
 * @dev Batch mint NFTs to an array of addresses, require enough supply left.
 * @return the minted token ids
 */
function batchMint(address[] memory addresses_, uint16 amount_)
        public
        onlyOwner
        returns (uint256[] memory)
    {
        require(
            totalSupply >= addresses_.length * amount_ + _tokenIds.current(),
            "not enough supply"
        );

        uint256[] memory ids = new uint256[](addresses_.length * amount_);
        for (uint16 i = 0; i < addresses_.length; i++) {
            for (uint16 j = 0; j < amount_; j++) {
                _tokenIds.increment();

                uint256 newItemId = _tokenIds.current();
                _safeMint(addresses_[i], newItemId);

                ids[i * amount_ + j] = newItemId;
            }
        }

        return ids;
    }
// Solidity 0.8.4
// start or stop pre-order
// @param start_: start or end pre-order flag
// @param amount_: minimum contribution amount
// @param supply_: pre-order supply
function setInPreOrder(
        bool start_,
        uint256 amount_,
        uint256 supply_
    ) public onlyOwner {
        if (start_ == true) {
            require(amount_ > 0, "zero amount");
            // number of pre-order supply shall be less or equal to the number of total supply
            require(
                supply_ > 0 && supply_ <= totalSupply,
                "incorrect pre-order supply"
            );
            preOrderMinAmount = amount_;
            preOrderSupply = supply_;
            inPreOrder = true;
        } else {
            inPreOrder = false;
        }
    }
// Solidity 0.8.4
// place a pre-order
// @param n - number of NFTs to order
function preOrder(uint256 n) public payable {
        require(inPreOrder == true, "pre-order not started");
        require(preOrderMinAmount > 0, "zero minimum amount");
        // validation against the minimum contribution amount
        require(
            n > 0 && msg.value >= preOrderMinAmount * n,
            "amount too small"
        );
        // shall not exceed pre-order supply
        require(
            _preOrderMintIndex.current() + n <= preOrderSupply,
            "reach pre-order supply"
        );

        if (_preOrders[msg.sender] <= 0) {
            // shall not exceed pre-order limit
            require(n <= preOrderLimit, "reach order limit");

            _preOrders[msg.sender] = n;
        } else {
            // shall not exceed pre-order limit
            require(
                n + _preOrders[msg.sender] <= preOrderLimit,
                "reach order limit"
            );

            // if the participant has ordered before
            _preOrders[msg.sender] += n;
        }

        for (uint256 i = 0; i < n; i++) {
            _tokenIds.increment();
            _preOrderMintIndex.increment();

            uint256 newItemId = _tokenIds.current();
            _safeMint(msg.sender, newItemId);
        }
        emit PreOrderMinted(msg.sender, n);
    }
// Solidity 0.5.17
/**
 * @notice Fetch Award from airdrop
 * @param _id Airdrop id
 * @param _recipient Airdrop recipient
 * @param _amount The token amount
 * @param _proof Merkle proof to correspond to data supplied
 */
function award(
        uint256 _id,
        address _recipient,
        uint256 _amount,
        bytes32[] memory _proof
    ) public {
        require(_id <= airdropsCount, ERROR_INVALID);

        Airdrop storage airdrop = airdrops[_id];
        require(!airdrop.paused, ERROR_PAUSED);

        bytes32 hash = keccak256(abi.encodePacked(_recipient, _amount));
        require(validate(airdrop.root, _proof, hash), ERROR_INVALID);

        require(!airdrops[_id].awarded[_recipient], ERROR_AWARDED);

        airdrops[_id].awarded[_recipient] = true;

        uint256 bal = token.balanceOf(address(this));
        if (bal >= _amount) {
            token.transfer(_recipient, _amount);
        } else {
            revert("INVALID_CONTRACT_BALANCE");
        }

        emit Award(_id, _recipient, _amount);
    }
// Solidity 0.5.17
/**
 * @notice Fetch Award from many airdrops
 * @param _ids Airdrop ids
 * @param _recipient Recepient of award
 * @param _amounts The amounts
 * @param _proofs Merkle proofs
 * @param _proofLengths Merkle proof lengths
 */
function awardFromMany(
        uint256[] memory _ids,
        address _recipient,
        uint256[] memory _amounts,
        bytes memory _proofs,
        uint256[] memory _proofLengths
    ) public {
        uint256 totalAmount;

        uint256 marker = 32;

        for (uint256 i = 0; i < _ids.length; i++) {
            uint256 id = _ids[i];
            require(id <= airdropsCount, ERROR_INVALID);
            require(!airdrops[id].paused, ERROR_PAUSED);

            bytes32[] memory proof =
                extractProof(_proofs, marker, _proofLengths[i]);
            marker += _proofLengths[i] * 32;

            bytes32 hash = keccak256(abi.encodePacked(_recipient, _amounts[i]));
            require(validate(airdrops[id].root, proof, hash), ERROR_INVALID);

            require(!airdrops[id].awarded[_recipient], ERROR_AWARDED);

            airdrops[id].awarded[_recipient] = true;

            totalAmount += _amounts[i];

            emit Award(id, _recipient, _amounts[i]);
        }

        uint256 bal = token.balanceOf(address(this));
        if (bal >= totalAmount) {
            token.transfer(_recipient, totalAmount);
        } else {
            revert("INVALID_CONTRACT_BALANCE");
        }
    }
// Solidity 0.4.25
//
// Implements IAccessControlled
//
function setAccessPolicy(IAccessPolicy newPolicy, address newAccessController)
        public
        only(ROLE_ACCESS_CONTROLLER)
    {
        // ROLE_ACCESS_CONTROLLER must be present
        // under the new policy. This provides some
        // protection against locking yourself out.
        require(newPolicy.allowed(newAccessController, ROLE_ACCESS_CONTROLLER, this, msg.sig));

        // We can now safely set the new policy without foot shooting.
        IAccessPolicy oldPolicy = _accessPolicy;
        _accessPolicy = newPolicy;

        // Log event
        emit LogAccessPolicyChanged(msg.sender, oldPolicy, newPolicy);
    }
// Solidity 0.4.25
////////////////////////
/// translates uint256 to struct
function deserializeClaims(bytes32 data) internal pure returns (IdentityClaims memory claims) {
        // for memory layout of struct, each field below word length occupies whole word
        assembly {
            mstore(claims, and(data, 0x1))
            mstore(add(claims, 0x20), div(and(data, 0x2), 0x2))
            mstore(add(claims, 0x40), div(and(data, 0x4), 0x4))
            mstore(add(claims, 0x60), div(and(data, 0x8), 0x8))
        }
    }