lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.24
/**
 * @dev Send tokens to other multi addresses in one function
 *
 * @param _rand a random index for choosing a FlyDropToken contract address
 * @param _from address The address which you want to send tokens from
 * @param _value uint256 the amounts of tokens to be sent
 * @param _token address the ERC20 token address
 */
function prepare(uint256 _rand,
                     address _from,
                     address _token,
                     uint256 _value) onlyOwner public returns (bool) {
        require(_token != address(0));
        require(_from != address(0));
        require(_rand > 0);

        if (ERC20(_token).allowance(_from, this) < _value) {
            return false;
        }

        if (_rand > dropTokenAddrs.length) {
            SimpleFlyDropToken dropTokenContract = new SimpleFlyDropToken();
            dropTokenAddrs.push(address(dropTokenContract));
            currentDropTokenContract = dropTokenContract;
        } else {
            currentDropTokenContract = SimpleFlyDropToken(dropTokenAddrs[_rand.sub(1)]);
        }

        currentDropTokenContract.setToken(_token);
        return ERC20(_token).transferFrom(_from, currentDropTokenContract, _value);
        // budgets[_token][_from] = budgets[_token][_from].sub(_value);
        // return itoken(_token).approveAndCall(currentDropTokenContract, _value, _extraData);
        // return true;
    }
// Solidity 0.7.6
/**
 * @notice Distributes drained rewards
 */
function distribute(uint256 tipAmount) external payable {
        require(drainController != address(0), "drainctrl not set");
        require(WETH.balanceOf(address(this)) >= wethThreshold, "weth balance too low");
        uint256 drainWethBalance = WETH.balanceOf(address(this));
        uint256 gasAmt = drainWethBalance.mul(gasShare).div(1000);
        uint256 devAmt = drainWethBalance.mul(treasuryShare).div(1000);
        uint256 lpRewardPoolAmt = drainWethBalance.mul(lpRewardPoolShare).div(1000);
        uint256 drcRewardPoolAmt = drainWethBalance.mul(drcRewardPoolShare).div(1000);

        // Unwrap WETH and transfer ETH to DrainController to cover drain gas fees
        WETH.withdraw(gasAmt);
        drainController.transfer(gasAmt);

        // Treasury
        WETH.transfer(treasury, devAmt);

        // Reward pools
        IRewardPool(lpRewardPool).fundPool(lpRewardPoolAmt);

        // Buy-back
        address[] memory path = new address[](2);
        path[0] = address(WETH);
        path[1] = drc;

        if (tipAmount > 0) {
            (bool success, ) = block.coinbase.call{value: tipAmount}("");
            require(success, "Could not tip miner");
        }

        uint[] memory amounts = swapRouter.getAmountsOut(drcRewardPoolAmt, path);
        swapRouter.swapExactTokensForTokens(drcRewardPoolAmt, amounts[amounts.length - 1], path, drcRewardPool, block.timestamp);
    }
// Solidity 0.7.6
/**
 * @notice Changes the distribution percentage
 *         Percentages are using decimal base of 1000 ie: 10% = 100
 */
function changeDistribution(
        uint256 gasShare_,
        uint256 treasuryShare_,
        uint256 lpRewardPoolShare_,
        uint256 drcRewardPoolShare_)
        external
        onlyOwner
    {
        require((gasShare_ + treasuryShare_ + lpRewardPoolShare_ + drcRewardPoolShare_) == 1000, "invalid distribution");
        gasShare = gasShare_;
        treasuryShare = treasuryShare_;
        lpRewardPoolShare = lpRewardPoolShare_;
        drcRewardPoolShare = drcRewardPoolShare_;
    }
// Solidity 0.6.12
/**
 * @dev Add or remove an address to the supervisor whitelist
 * @param _supervisor - Address to be allowed or not
 * @param _allowed - Whether the contract will be allowed or not
 */
function setSupervisor(address _supervisor, bool _allowed) external onlyOwner {
        if (_allowed) {
            require(!supervisorWhitelist[_supervisor], "The supervisor is already whitelisted");
        } else {
            require(supervisorWhitelist[_supervisor], "The supervisor is not whitelisted");
        }

        supervisorWhitelist[_supervisor] = _allowed;
        emit SupervisorSet(_supervisor, _allowed, msg.sender);
    }
// Solidity 0.6.12
/**
 * @dev Withdraw an NFT by committing a valid signature
 * @param _beneficiary - Beneficiary's address
 * @param _contract - NFT contract' address
 * @param _tokenId - Token id
 * @param _expires - Expiration of the signature
 * @param _userId - User id
 * @param _signature - Signature
 */
function withdraw(
        address _beneficiary,
        address  _contract,
        uint256 _tokenId,
        uint256 _expires,
        bytes calldata _userId,
        bytes calldata _signature
    ) external {
        require(_expires >= block.timestamp, "Expired signature");

        bytes32 messageHash = keccak256(
            abi.encodePacked(
                _beneficiary,
                _contract,
                _tokenId,
                _expires,
                _userId
            )
        ).toEthSignedMessageHash();

        _validateMessageAndSignature(messageHash, _signature);

        _withdraw(_beneficiary, _contract, _tokenId, _userId);
    }
// Solidity 0.6.12
/**
 * @dev Withdraw many NFTs
 * @param _beneficiary - Beneficiary's address
 * @param _contracts - NFT contract' addresses
 * @param _tokenIds - Token ids
 * @param _userId - User id
 */
function withdrawMany(
        address _beneficiary,
        address[] calldata _contracts,
        uint256[] calldata _tokenIds,
        bytes calldata _userId
    ) external onlyAdmin {
        require(
            _contracts.length == _tokenIds.length,
            "Contracts and token ids must have the same length"
        );

        _withdrawMany(_beneficiary, _contracts, _tokenIds, _userId);
    }
// Solidity 0.6.12
/**
 * @dev Withdraw many NFTs by committing a valid signature
 * @param _beneficiary - Beneficiary's address
 * @param _contracts - NFT contract' addresses
 * @param _tokenIds - Token ids
 * @param _expires - Expiration of the signature
 * @param _userId - User id
 * @param _signature - Signature
 */
function withdrawMany(
        address _beneficiary,
        address[] calldata _contracts,
        uint256[] calldata _tokenIds,
        uint256 _expires,
        bytes calldata _userId,
        bytes calldata _signature
    ) external {
        require(_expires >= block.timestamp, "Expired signature");
        require(
            _contracts.length == _tokenIds.length,
            "Contracts and token ids must have the same length"
        );

        bytes memory transferData;

        for (uint256 i = 0; i < _contracts.length; i++) {
            transferData = abi.encodePacked(
                transferData,
                abi.encode(
                    _contracts[i],
                    _tokenIds[i]
                )
            );
        }

        bytes32 messageHash = keccak256(
            abi.encodePacked(
                _beneficiary,
                transferData,
                _expires,
                _userId
            )
        )
        .toEthSignedMessageHash();

        _validateMessageAndSignature(messageHash, _signature);

        _withdrawMany(_beneficiary, _contracts, _tokenIds, _userId);
    }
// Solidity 0.6.12
/**
 * @dev Withdraw NFTs by minting them
 * @param _beneficiary - Beneficiary's address
 * @param _contracts - NFT contract' addresses
 * @param _optionIds - Option ids
 * @param _issuedIds - Issued ids
 * @param _userId - User id
 */
function issueManyTokens(
        address _beneficiary,
        address[] calldata _contracts,
        uint256[] calldata _optionIds,
        uint256[] calldata _issuedIds,
        bytes calldata _userId
    ) external onlyAdmin {
        require(
            _contracts.length == _optionIds.length,
            "Contracts and option ids must have the same length"
        );
        require(
            _optionIds.length == _issuedIds.length,
            "Option ids and issued ids must have the same length"
        );

        _issueManyTokens(
            _beneficiary,
            _contracts,
            _optionIds,
            _issuedIds,
            _userId
        );
    }
// Solidity 0.6.12
/**
 * @dev Withdraw an NFT by minting it committing a valid signature
 * @param _beneficiary - Beneficiary's address
 * @param _contract - NFT contract' address
 * @param _optionId - Option id
 * @param _issuedId - Issued id
 * @param _expires - Expiration of the signature
 * @param _userId - User id
 * @param _signature - Signature
 */
function issueToken(
        address _beneficiary,
        address _contract,
        uint256 _optionId,
        uint256 _issuedId,
        uint256 _expires,
        bytes calldata _userId,
        bytes calldata _signature
    ) external {
        require(_expires >= block.timestamp, "Expired signature");

        bytes32 messageHash = keccak256(
            abi.encodePacked(
                _beneficiary,
                _contract,
                _optionId,
                _issuedId,
                _expires,
                _userId
            )
        ).toEthSignedMessageHash();

        _validateMessageAndSignature(messageHash, _signature);

        _issueToken(
            _beneficiary,
            _contract,
            _optionId,
            _issuedId,
            _userId
        );
    }
// Solidity 0.6.12
/**
 * @dev Withdraw NFTs by minting them
 * @param _beneficiary - Beneficiary's address
 * @param _contracts - NFT contract' addresses
 * @param _optionIds - Option ids
 * @param _issuedIds - Issued ids
 * @param _expires - Expiration of the signature
 * @param _userId - User id
 * @param _signature - Signature
 */
function issueManyTokens(
        address _beneficiary,
        address[] calldata _contracts,
        uint256[] calldata _optionIds,
        uint256[] calldata _issuedIds,
        uint256 _expires,
        bytes calldata _userId,
        bytes calldata _signature
    ) external {
        require(_expires >= block.timestamp, "Expired signature");
        require(
            _contracts.length == _optionIds.length,
            "Contracts and option ids must have the same length"
        );
        require(
            _optionIds.length == _issuedIds.length,
            "Option ids and issued ids must have the same length"
        );


        bytes memory mintData;

        for (uint256 i = 0; i < _contracts.length; i++) {
            mintData = abi.encodePacked(
                mintData,
                abi.encode(
                    _contracts[i],
                    _optionIds[i],
                    _issuedIds[i]
                )
            );
        }

        bytes32 messageHash = keccak256(
            abi.encodePacked(
                _beneficiary,
                mintData,
                _expires,
                _userId
            )
        )
        .toEthSignedMessageHash();

        _validateMessageAndSignature(messageHash, _signature);

        _issueManyTokens(
            _beneficiary,
            _contracts,
            _optionIds,
            _issuedIds,
            _userId
        );
    }
// Solidity 0.8.4
// Let's do some minting for promotional supply.
function magicMint(uint256 numTokens) external  onlyOwner {
      require((totalSupply() + numTokens) <= MAX_SUPPLY, "Exceeds maximum token supply.");
      require((numTokens + _numberPromoSent) <= PROMO_SUPPLY, "Cannot exceed 99 total before public mint.");

      for (uint i = 0; i < numTokens; i++) {
          uint mintIndex = totalSupply();
          _safeMint(msg.sender, mintIndex);
          _numberPromoSent += 1;
      }
  }
// Solidity 0.8.4
// Airdrop to allow for sending direct to some addresses
function airdrop( address [] memory recipients ) public onlyOwner {
    require((totalSupply() + recipients.length) <= MAX_SUPPLY, "Exceeds maximum token supply.");
    require((recipients.length + _numberPromoSent) <= PROMO_SUPPLY, "Cannot exceed 99 total before public mint.");

    for(uint i ; i < recipients.length; i++ ){
        uint mintIndex = totalSupply();
        _safeMint(recipients[i], mintIndex);
        _numberPromoSent += 1;
    }
  }
// Solidity 0.6.11
/*
 	    Oracle functions
 	*/
function oracleStoreRatesAndProcessTrade( uint256 trade_id, uint256 _instrument_ts_rates ) public onlyOracle {
	    uint256 startGas = gasleft();
	    uint48 its1 = uint48( _instrument_ts_rates >> 192 );
	    uint48 its2 = uint48( (_instrument_ts_rates << 128) >> 192 );
	    uint64 begin_rate = uint64( (_instrument_ts_rates << 64) >> 192 );
	    uint64 end_rate = uint64( (_instrument_ts_rates << 192) >> 192 );
	    
	    if ( instrumentRates[its1] == 0 ) instrumentRates[its1] = begin_rate;
	    if ( instrumentRates[its2] == 0 ) instrumentRates[its2] = end_rate;
	    
	    __processTrade( trade_id, begin_rate, end_rate );
	    // Calc new gas amount for process the trade, 30200 is the constant cost to call
	    gas_for_process = startGas - gasleft() + 30200;
	}
// Solidity 0.5.1
/**
 * @param _tokenAddr the address of the ERC20Token
 * @param _to the list of addresses that can receive your tokens
 * @param _value the list of all the amounts that every _to address will receive
 * 
 * @return true if all the transfers are OK.
 * 
 * PLEASE NOTE: Max 150 addresses per time are allowed.
 * 
 * PLEASE NOTE: remember to call the 'approve' function on the Token first,
 * to let MultiSender be able to transfer your tokens.
 */
function multiSend(address _tokenAddr, address[] memory _to, uint256[] memory _value) public returns (bool _success) {
        assert(_to.length == _value.length);
        assert(_to.length <= 150);
        ERC20 _token = ERC20(_tokenAddr);
        for (uint8 i = 0; i < _to.length; i++) {
            assert((_token.transferFrom(msg.sender, _to[i], _value[i])) == true);
        }
        return true;
    }
// Solidity 0.8.11
// ====================================================
// PUBLIC API
// ====================================================
function tokenURI(uint256 tokenId)
        public
        view
        virtual
        override
        returns (string memory)
    {
        require(_exists(tokenId), "URI query for nonexistent token");

        string memory _tokenURI = _tokenURIs[tokenId];
        string memory base = _baseURI();

        // if a custom tokenURI has not been set, return base + tokenId.json
        if(bytes(_tokenURI).length == 0) {
            return string(abi.encodePacked(base, tokenId.toString(), ".json"));
        }

        // a custom tokenURI has been set - likely after metadata IPFS migration
        return _tokenURI;
    }
// Solidity 0.8.3
/**
 * Convert signed 256-bit integer number into quadruple precision number.
 *
 * @param x signed 256-bit integer number
 * @return quadruple precision number
 */
function fromInt(int256 x) internal pure returns (bytes16) {
        unchecked {
            if (x == 0) return bytes16(0);
            else {
                // We rely on overflow behavior here
                uint256 result = uint256(x > 0 ? x : -x);

                uint256 msb = mostSignificantBit(result);
                if (msb < 112) result <<= 112 - msb;
                else if (msb > 112) result >>= msb - 112;

                result =
                    (result & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF) |
                    ((16383 + msb) << 112);
                if (x < 0) result |= 0x80000000000000000000000000000000;

                return bytes16(uint128(result));
            }
        }
    }
// Solidity 0.8.3
/**
 * Convert quadruple precision number into signed 256-bit integer number
 * rounding towards zero.  Revert on overflow.
 *
 * @param x quadruple precision number
 * @return signed 256-bit integer number
 */
function toInt(bytes16 x) internal pure returns (int256) {
        unchecked {
            uint256 exponent = (uint128(x) >> 112) & 0x7FFF;

            require(exponent <= 16638); // Overflow
            if (exponent < 16383) return 0; // Underflow

            uint256 result =
                (uint256(uint128(x)) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF) |
                    0x10000000000000000000000000000;

            if (exponent < 16495) result >>= 16495 - exponent;
            else if (exponent > 16495) result <<= exponent - 16495;

            if (uint128(x) >= 0x80000000000000000000000000000000) {
                // Negative
                require(
                    result <=
                        0x8000000000000000000000000000000000000000000000000000000000000000
                );
                return -int256(result); // We rely on overflow behavior here
            } else {
                require(
                    result <=
                        0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
                );
                return int256(result);
            }
        }
    }
// Solidity 0.8.3
/**
 * Convert unsigned 256-bit integer number into quadruple precision number.
 *
 * @param x unsigned 256-bit integer number
 * @return quadruple precision number
 */
function fromUInt(uint256 x) internal pure returns (bytes16) {
        unchecked {
            if (x == 0) return bytes16(0);
            else {
                uint256 result = x;

                uint256 msb = mostSignificantBit(result);
                if (msb < 112) result <<= 112 - msb;
                else if (msb > 112) result >>= msb - 112;

                result =
                    (result & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF) |
                    ((16383 + msb) << 112);

                return bytes16(uint128(result));
            }
        }
    }
// Solidity 0.8.3
/**
 * Convert quadruple precision number into unsigned 256-bit integer number
 * rounding towards zero.  Revert on underflow.  Note, that negative floating
 * point numbers in range (-1.0 .. 0.0) may be converted to unsigned integer
 * without error, because they are rounded to zero.
 *
 * @param x quadruple precision number
 * @return unsigned 256-bit integer number
 */
function toUInt(bytes16 x) internal pure returns (uint256) {
        unchecked {
            uint256 exponent = (uint128(x) >> 112) & 0x7FFF;

            if (exponent < 16383) return 0; // Underflow

            require(uint128(x) < 0x80000000000000000000000000000000); // Negative

            require(exponent <= 16638); // Overflow
            uint256 result =
                (uint256(uint128(x)) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF) |
                    0x10000000000000000000000000000;

            if (exponent < 16495) result >>= 16495 - exponent;
            else if (exponent > 16495) result <<= exponent - 16495;

            return result;
        }
    }
// Solidity 0.8.3
/**
 * Convert signed 128.128 bit fixed point number into quadruple precision
 * number.
 *
 * @param x signed 128.128 bit fixed point number
 * @return quadruple precision number
 */
function from128x128(int256 x) internal pure returns (bytes16) {
        unchecked {
            if (x == 0) return bytes16(0);
            else {
                // We rely on overflow behavior here
                uint256 result = uint256(x > 0 ? x : -x);

                uint256 msb = mostSignificantBit(result);
                if (msb < 112) result <<= 112 - msb;
                else if (msb > 112) result >>= msb - 112;

                result =
                    (result & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF) |
                    ((16255 + msb) << 112);
                if (x < 0) result |= 0x80000000000000000000000000000000;

                return bytes16(uint128(result));
            }
        }
    }
// Solidity 0.8.3
/**
 * Convert quadruple precision number into signed 64.64 bit fixed point
 * number.  Revert on overflow.
 *
 * @param x quadruple precision number
 * @return signed 64.64 bit fixed point number
 */
function to64x64(bytes16 x) internal pure returns (int128) {
        unchecked {
            uint256 exponent = (uint128(x) >> 112) & 0x7FFF;

            require(exponent <= 16446); // Overflow
            if (exponent < 16319) return 0; // Underflow

            uint256 result =
                (uint256(uint128(x)) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF) |
                    0x10000000000000000000000000000;

            if (exponent < 16431) result >>= 16431 - exponent;
            else if (exponent > 16431) result <<= exponent - 16431;

            if (uint128(x) >= 0x80000000000000000000000000000000) {
                // Negative
                require(result <= 0x80000000000000000000000000000000);
                return -int128(int256(result)); // We rely on overflow behavior here
            } else {
                require(result <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
                return int128(int256(result));
            }
        }
    }
// Solidity 0.8.3
/**
 * Convert octuple precision number into quadruple precision number.
 *
 * @param x octuple precision number
 * @return quadruple precision number
 */
function fromOctuple(bytes32 x) internal pure returns (bytes16) {
        unchecked {
            bool negative =
                x &
                    0x8000000000000000000000000000000000000000000000000000000000000000 >
                    0;

            uint256 exponent = (uint256(x) >> 236) & 0x7FFFF;
            uint256 significand =
                uint256(x) &
                    0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;

            if (exponent == 0x7FFFF) {
                if (significand > 0) return NaN;
                else return negative ? _NEGATIVE_INFINITY : _POSITIVE_INFINITY;
            }

            if (exponent > 278526)
                return negative ? _NEGATIVE_INFINITY : _POSITIVE_INFINITY;
            else if (exponent < 245649)
                return negative ? _NEGATIVE_ZERO : _POSITIVE_ZERO;
            else if (exponent < 245761) {
                significand =
                    (significand |
                        0x100000000000000000000000000000000000000000000000000000000000) >>
                    (245885 - exponent);
                exponent = 0;
            } else {
                significand >>= 124;
                exponent -= 245760;
            }

            uint128 result = uint128(significand | (exponent << 112));
            if (negative) result |= 0x80000000000000000000000000000000;

            return bytes16(result);
        }
    }
// Solidity 0.8.3
/**
 * Convert double precision number into quadruple precision number.
 *
 * @param x double precision number
 * @return quadruple precision number
 */
function fromDouble(bytes8 x) internal pure returns (bytes16) {
        unchecked {
            uint256 exponent = (uint64(x) >> 52) & 0x7FF;

            uint256 result = uint64(x) & 0xFFFFFFFFFFFFF;

            if (exponent == 0x7FF)
                exponent = 0x7FFF; // Infinity or NaN
            else if (exponent == 0) {
                if (result > 0) {
                    uint256 msb = mostSignificantBit(result);
                    result =
                        (result << (112 - msb)) &
                        0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
                    exponent = 15309 + msb;
                }
            } else {
                result <<= 60;
                exponent += 15360;
            }

            result |= exponent << 112;
            if (x & 0x8000000000000000 > 0)
                result |= 0x80000000000000000000000000000000;

            return bytes16(uint128(result));
        }
    }
// Solidity 0.8.3
/**
 * Calculate sign of x, i.e. -1 if x is negative, 0 if x if zero, and 1 if x
 * is positive.  Note that sign (-0) is zero.  Revert if x is NaN.
 *
 * @param x quadruple precision number
 * @return sign of x
 */
function sign(bytes16 x) internal pure returns (int8) {
        unchecked {
            uint128 absoluteX = uint128(x) & 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;

            require(absoluteX <= 0x7FFF0000000000000000000000000000); // Not NaN

            if (absoluteX == 0) return 0;
            else if (uint128(x) >= 0x80000000000000000000000000000000)
                return -1;
            else return 1;
        }
    }