lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.7.5
/**
 @notice allow owner multisig to withdraw assets on debt (for safe investments)
 @param _token address
 @param _amount uint
 */
function incurDebt( address _token, uint _amount, bool isEth ) external onlyOwner() {
        uint value;
        if ( _token == address(0) && isEth ) {
            safeTransferETH(msg.sender, _amount);
            value = EthToUSD( _amount );
        } else {
            IERC20Extended( _token ).safeTransfer( msg.sender, _amount );
            value = valueOfToken(_token, _amount);
        }
        totalReserves = totalReserves.sub( value );
        ownerDebt = ownerDebt.add(value);
        emit ReservesUpdated( totalReserves );
        emit ReservesWithdrawn( msg.sender, _token, _amount );
    }
// Solidity 0.7.5
/**
 @notice verify queue then set boolean in mapping
 @param _managing MANAGING
 @param _address address
 @param _calculatorFeed address
 @return bool
 */
function toggle( MANAGING _managing, address _address, address _calculatorFeed, uint decimals ) external onlyOwner() returns ( bool ) {
        require( _address != address(0) );
        bool result;
        if ( _managing == MANAGING.RESERVETOKEN ) { // 0
            if( !listContains( reserveTokens, _address ) ) {
                reserveTokens.push( _address );
            }
            result = !isReserveToken[ _address ];
            isReserveToken[ _address ] = result;

        } else if ( _managing == MANAGING.LIQUIDITYTOKEN ) { // 1
            if( !listContains( liquidityTokens, _address ) ) {
                liquidityTokens.push( _address );
            }
            result = !isLiquidityToken[ _address ];
            isLiquidityToken[ _address ] = result;
            lpCalculator[ _address ] = _calculatorFeed;

        } else if ( _managing == MANAGING.VARIABLETOKEN ) { // 2
            if( !listContains( variableTokens, _address ) ) {
                variableTokens.push( _address );
            }
            result = !isVariableToken[ _address ];
            isVariableToken[ _address ] = result;
            priceFeeds[ _address ] = PriceFeed({
                feed: _calculatorFeed,
                decimals: decimals
            });

        } else return false;

        emit ChangeActivated( _managing, _address, result );
        return true;
    }
// Solidity 0.8.0
/**
 * Reserve DogePound Christmas by owner
 */
function reserveDPC(address to, uint256 count)
        external
        onlyOwner
    {
        require(to != address(0), "Invalid address to reserve.");
        if (mintLimit) {
            uint256 mintCount = currentMintCount - claimCount;
            require(mintCount.add(count) <= MAX_DPC_SUPPLY.sub(whitelistCount), "Exceeds mintable count." );
        }
        require(currentMintCount.add(count) <= MAX_DPC_SUPPLY, "Reserve would exceed max supply");
        
        for (uint256 i = 0; i < count; i++) {
            _safeMint(to, currentMintCount + i);
        }

        currentMintCount = currentMintCount.add(count);
    }
// Solidity 0.8.0
/**
 * Mint DogePound Christmas
 */
function mintDPC(uint256 count)
        external
        payable
    {
        require(isSale, "Sale must be active to mint");
        if (mintLimit) {
            uint256 mintCount = currentMintCount - claimCount;
            require(mintCount.add(count) <= MAX_DPC_SUPPLY.sub(whitelistCount), "Exceeds mintable count." );
        }
        require(count <= maxMintAmountPerTX, "Invalid amount to mint per tx");
        require(currentMintCount.add(count) <= MAX_DPC_SUPPLY, "Purchase would exceed max supply");
        require(mintPrice.mul(count) <= msg.value, "Ether value sent is not correct");
        
        for(uint256 i = 0; i < count; i++) {
            _safeMint(msg.sender, currentMintCount + i);
        }

        currentMintCount = currentMintCount.add(count);
    }
// Solidity 0.8.0
/**
 * Claim for whitelist user
 */
function claimDPC(uint256 count, uint256 maxCount, uint8 v, bytes32 r, bytes32 s) external {
        require(isSale, "Sale must be active to mint");
        require(tx.origin == msg.sender, "Only EOA");
        require(currentMintCount.add(count) <= MAX_DPC_SUPPLY, "Exceed max supply");

        bytes32 domainSeparator = keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(CONTRACT_NAME)), getChainId(), address(this)));
        bytes32 structHash = keccak256(abi.encode(CLAIM_TYPEHASH, msg.sender, count, maxCount));
        bytes32 digest = keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
        address signatory = ecrecover(digest, v, r, s);
        require(signatory == admin, "Invalid signatory");

        require(whitelistClaim[msg.sender].add(count) <= maxCount, "Exceed max claimable count");

        for(uint256 i = 0; i < count; i++) {
            _safeMint(msg.sender, currentMintCount + i);
        }

        currentMintCount = currentMintCount.add(count);
        claimCount = claimCount.add(count);
        whitelistClaim[msg.sender] = whitelistClaim[msg.sender].add(count);
    }
// Solidity 0.4.25
// Total invested amount
//This function receives all the deposits
//stores them and make immediate payouts
function () public payable {
        
        require(block.number >= 6655835);

        if(msg.value > 0){

            require(gasleft() >= 250000); // We need gas to process queue
            require(msg.value >= 0.05 ether && msg.value <= 10 ether); // Too small and too big deposits are not accepted
            
            // Add the investor into the queue
            queue.push( Deposit(msg.sender, msg.value, 0) );
            depositNumber[msg.sender] = queue.length;

            totalInvested += msg.value;

            //Send some promo to enable queue contracts to leave long-long time
            uint promo = msg.value*PROMO_PERCENT/100;
            PROMO.send(promo);
            uint prize = msg.value*BONUS_PERCENT/100;
            PRIZE.send(prize);
            
            // Pay to first investors in line
            pay();

        }
    }
// Solidity 0.8.7
/**
 * Checks if the provided signatures suffice to sign the transaction and if the nonce is correct.
 */
function checkSignatures(uint128 nonce, address to, uint value, bytes calldata data,
    uint8[] calldata v, bytes32[] calldata r, bytes32[] calldata s) external view returns (address[] memory) {
    bytes32 transactionHash = calculateTransactionHash(nonce, contractId, to, value, data);
    return verifySignatures(transactionHash, v, r, s);
  }
// Solidity 0.8.7
// Note: does not work with contract creation
function calculateTransactionHash(uint128 sequence, bytes memory id, address to, uint value, bytes calldata data)
    internal view returns (bytes32){
    bytes[] memory all = new bytes[](9);
    all[0] = toBytes(sequence); // sequence number instead of nonce
    all[1] = id; // contract id instead of gas price
    all[2] = toBytes(21000); // gas limit
    all[3] = abi.encodePacked(to);
    all[4] = toBytes(value);
    all[5] = data;
    all[6] = toBytes(block.chainid);
    all[7] = toBytes(0);
    for (uint i = 0; i<8; i++){
      all[i] = RLPEncode.encodeBytes(all[i]);
    }
    all[8] = all[7];
    return keccak256(RLPEncode.encodeList(all));
  }
// Solidity 0.5.17
/**
 * Allows the Lock owner to give a collection of users a key with no charge.
 * Each key may be assigned a different expiration date.
 */
function grantKeys(
    address[] calldata _recipients,
    uint[] calldata _expirationTimestamps,
    address[] calldata _keyManagers
  ) external
    onlyKeyGranterOrManager
  {
    for(uint i = 0; i < _recipients.length; i++) {
      address recipient = _recipients[i];
      uint expirationTimestamp = _expirationTimestamps[i];
      address keyManager = _keyManagers[i];

      require(recipient != address(0), 'INVALID_ADDRESS');

      Key storage toKey = keyByOwner[recipient];
      require(expirationTimestamp > toKey.expirationTimestamp, 'ALREADY_OWNS_KEY');

      uint idTo = toKey.tokenId;

      if(idTo == 0) {
        _assignNewTokenId(toKey);
        idTo = toKey.tokenId;
        _recordOwner(recipient, idTo);
      }
      // Set the key Manager
      _setKeyManagerOf(idTo, keyManager);
      emit KeyManagerChanged(idTo, keyManager);

      toKey.expirationTimestamp = expirationTimestamp;
      // trigger event
      emit Transfer(
        address(0), // This is a creation.
        recipient,
        idTo
      );
    }
  }
// Solidity 0.8.11
/**
 * @dev add private users and assign amount to claim. Before calling,
 * ensure that contract balance is more or equal than total token payout
 * @param _user  An array of users' addreses.
 * @param _amount An array of amount values to be assigned to users respectively.
 */
function addPrivateUser(address[] memory _user, uint256[] memory _amount)
        public
        onlyOwner
    {
        for (uint256 i = 0; i < _user.length; i++) {
            require(_amount[i] != 0, "Vesting: some amount is zero");

            if (users[_user[i]].accumulated != 0) {
                totalTokensToPay -= users[_user[i]].accumulated;
            }

            users[_user[i]].accumulated = _amount[i];
            totalTokensToPay += _amount[i];
        }

        // solhint-disable-next-line reason-string
        require(
            totalTokensToPay - totalTokensPaid <=
                token.balanceOf(address(this)),
            "Vesting: total tokens to pay exceed balance"
        );

        emit UsersBatchAdded(_user, _amount);
    }
// Solidity 0.8.11
/**
 * @dev Start vesting countdown. Can only be called by contract owner.
 */
function startCountdown(address[] memory _users) external onlyOwner {
        uint256 startTime = block.timestamp + (MONTH * CLIFF_MONTHS);
        uint256 endTime = startTime + vestingPeriod;

        for (uint256 index = 0; index < _users.length; index++) {
            UserInfo storage userInfo = users[_users[index]];

            require(
                !userInfo.isStarted,
                "Vesting: countdown is already started"
            );
            require(
                users[_users[index]].accumulated != 0,
                "Vesting: unknown user"
            );

            userInfo.vestingStartTime = startTime;

            userInfo.vestingEndTime = endTime;
            userInfo.isStarted = true;
        }

        emit CountdownStarted(startTime, endTime, _users);
    }
// Solidity 0.8.11
/**
 * @dev Claims available tokens from the contract.
 */
function claimToken() external nonReentrant {
        UserInfo storage userInfo = users[msg.sender];

        require(
            (userInfo.accumulated - userInfo.paidOut) > 0,
            "Vesting: not enough tokens to claim"
        );

        uint256 availableAmount = calcAvailableToken(
            userInfo.accumulated,
            userInfo.vestingStartTime,
            userInfo.vestingEndTime,
            userInfo.isStarted
        );
        availableAmount -= userInfo.paidOut;

        userInfo.paidOut += availableAmount;

        totalTokensPaid += availableAmount;

        token.safeTransfer(msg.sender, availableAmount);

        emit TokensClaimed(msg.sender, availableAmount);
    }
// Solidity 0.8.11
/**
 * @dev calcAvailableToken - calculate available tokens
 * @param _amount  An input amount used to calculate vesting's output value.
 * @return availableAmount_ An amount available to claim.
 */
function calcAvailableToken(
        uint256 _amount,
        uint256 vestingStartTime,
        uint256 vestingEndTime,
        bool isStarted
    ) private view returns (uint256 availableAmount_) {
        // solhint-disable-next-line not-rely-on-time
        if (!isStarted || block.timestamp <= vestingStartTime) {
            return 0;
        }

        // solhint-disable-next-line not-rely-on-time
        if (block.timestamp > vestingEndTime) {
            return _amount;
        }

        return
            (_amount *
                // solhint-disable-next-line not-rely-on-time
                (block.timestamp - vestingStartTime)) / vestingPeriod;
    }
// Solidity 0.4.10
/**
 * Add a registrant, only registrar allowed
 * public_function
 * @param _registrant - The registrant address.
 * @param _data - The registrant data string.
 */
function add(address _registrant, bytes _data) isRegistrar noEther returns (bool) {
        if (registrantIndex[_registrant] > 0) {
            Error(2); // Duplicate registrant
            return false;
        }
        uint pos = registrants.length++;
        registrants[pos] = Registrant(_registrant, _data, true);
        registrantIndex[_registrant] = pos;
        Created(_registrant, msg.sender, _data);
        return true;
    }
// Solidity 0.4.10
/**
 * Edit a registrant, only registrar allowed
 * public_function
 * @param _registrant - The registrant address.
 * @param _data - The registrant data string.
 */
function edit(address _registrant, bytes _data, bool _active) isRegistrar noEther returns (bool) {
        if (registrantIndex[_registrant] == 0) {
            Error(3); // No such registrant
            return false;
        }
        Registrant registrant = registrants[registrantIndex[_registrant]];
        registrant.data = _data;
        registrant.active = _active;
        Updated(_registrant, msg.sender, _data, _active);
        return true;
    }
// Solidity 0.8.2
// This function is executed when a ERC721 is received via safeTransferFrom. This function is purposely strict to ensure 
// the NFTs in this contract are all valid.
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4) {
        // Only accept NFTs through this function if they're being funneled.
        require(msg.sender == WAIFUSION, "WaifuDungeon: NFT not from waifusion");
        require(operator == address(this), "WaifuDungeon: invalid operator");
        require(tokenId <= MAX_NFT_SUPPLY, "WaifuDungeon: over max waifus");
        waifusInDungeon[waifuCount] = Waifu(WAIFUSION, uint64(tokenId));
        waifuCount++;
        return _ERC721_RECEIVED;
    }
// Solidity 0.8.2
// This function commits that the sender will purchase a waifu within the next 255 blocks.
// If they fail to revealWaifus() within that timeframe. The money they sent is forfeited to reduce complexity.
function commitBuyWaifus(uint256 num) external payable {
        require(msg.value == num * buyCost, "WaifuDungeon: invalid ether to buy");
        require(num <= 20, "WaifuDungeon: swapping too many");
        require(num <= waifuCount, "WaifuDungeon: not enough waifus in dungeon");
        _commitRandomWaifus(num);
    }
// Solidity 0.4.25
// Changes the fees
function setFees(uint256 makerFee_, uint256 takerFee_) onlyOwner {
        require(makerFee_ < 10 finney && takerFee_ < 10 finney); // The fees cannot be set higher then 1%
        makerFee = makerFee_;
        takerFee = takerFee_;

        emit FeeChange(makerFee, takerFee);
    }
// Solidity 0.4.25
// Deposit ETH to contract
function deposit() payable {
        //tokens[address(0)][msg.sender] = safeAdd(tokens[address(0)][msg.sender], msg.value); // adds the deposited amount to user balance
        addBalance(address(0), msg.sender, msg.value); // adds the deposited amount to user balance
        if (userFirstDeposits[msg.sender] == 0) userFirstDeposits[msg.sender] = block.number;
        lastActiveTransaction[msg.sender] = block.number; // sets the last activity block for the user
        emit Deposit(address(0), msg.sender, msg.value, balanceOf(address(0), msg.sender)); // fires the deposit event
    }
// Solidity 0.4.25
// Deposit ETH to contract for a user
function depositForUser(address user) payable {
        //tokens[address(0)][msg.sender] = safeAdd(tokens[address(0)][msg.sender], msg.value); // adds the deposited amount to user balance
        addBalance(address(0), user, msg.value); // adds the deposited amount to user balance
        if (userFirstDeposits[user] == 0) userFirstDeposits[user] = block.number;
        lastActiveTransaction[user] = block.number; // sets the last activity block for the user
        emit Deposit(address(0), user, msg.value, balanceOf(address(0), user)); // fires the deposit event
    }
// Solidity 0.4.25
// Deposit token to contract
function depositToken(address token, uint128 amount) {
        //tokens[token][msg.sender] = safeAdd(tokens[token][msg.sender], amount); // adds the deposited amount to user balance
        //if (amount != uint128(amount) || safeAdd(amount, balanceOf(token, msg.sender)) != uint128(amount)) throw;
        addBalance(token, msg.sender, amount); // adds the deposited amount to user balance

        if (userFirstDeposits[msg.sender] == 0) userFirstDeposits[msg.sender] = block.number;
        lastActiveTransaction[msg.sender] = block.number; // sets the last activity block for the user
        if (!Token(token).transferFrom(msg.sender, this, amount)) throw; // attempts to transfer the token to this contract, if fails throws an error
        emit Deposit(token, msg.sender, amount, balanceOf(token, msg.sender)); // fires the deposit event
    }
// Solidity 0.4.25
// Deposit token to contract for a user
function depositToken(address token, uint128 amount, address user) {
        //tokens[token][msg.sender] = safeAdd(tokens[token][msg.sender], amount); // adds the deposited amount to user balance
        //if (amount != uint128(amount) || safeAdd(amount, balanceOf(token, msg.sender)) != uint128(amount)) throw;
        addBalance(token, user, amount); // adds the deposited amount to user balance

        if (userFirstDeposits[user] == 0) userFirstDeposits[user] = block.number;
        lastActiveTransaction[user] = block.number; // sets the last activity block for the user
        if (!Token(token).transferFrom(msg.sender, this, amount)) throw; // attempts to transfer the token to this contract, if fails throws an error
        emit Deposit(token, user, amount, balanceOf(token, user)); // fires the deposit event
    }
// Solidity 0.4.25
// Executes multiple trades in one transaction, saves gas fees
function batchOrderTrade(
        uint8[2][] v,
        bytes32[4][] rs,
        uint256[8][] tradeValues,
        address[6][] tradeAddresses
    ) onlyAdmin
    {
        for (uint i = 0; i < tradeAddresses.length; i++) {
            trade(
                v[i],
                rs[i],
                tradeValues[i],
                tradeAddresses[i]
            );
        }
    }
// Solidity 0.4.24
// generate url by tokenId
// baseUrl must end with 00000000
function generateUrl(string url,uint256 _tokenId) internal pure returns (string _url){
    _url = url;
    bytes memory _tokenURIBytes = bytes(_url);
    uint256 base_len = _tokenURIBytes.length - 1;
    _tokenURIBytes[base_len - 7] = byte(48 + _tokenId / 10000000 % 10);
    _tokenURIBytes[base_len - 6] = byte(48 + _tokenId / 1000000 % 10);
    _tokenURIBytes[base_len - 5] = byte(48 + _tokenId / 100000 % 10);
    _tokenURIBytes[base_len - 4] = byte(48 + _tokenId / 10000 % 10);
    _tokenURIBytes[base_len - 3] = byte(48 + _tokenId / 1000 % 10);
    _tokenURIBytes[base_len - 2] = byte(48 + _tokenId / 100 % 10);
    _tokenURIBytes[base_len - 1] = byte(48 + _tokenId / 10 % 10);
    _tokenURIBytes[base_len - 0] = byte(48 + _tokenId / 1 % 10);
  }
// Solidity 0.4.24
/**
 * @dev Allows the current owner or operators to add operators
 * @param _newOperator New operator address
 */
function addOperator(address _newOperator) public onlyOwner {
        require(
            _newOperator != address(0),
            "Invalid new operator address."
        );

        // Make sure no dups
        require(
            !isOperator[_newOperator],
            "New operator exists."
        );

        // Only allow so many ops
        require(
            operators.length < MAX_OPS,
            "Overflow."
        );

        operators.push(_newOperator);
        isOperator[_newOperator] = true;

        emit OperatorAdded(_newOperator);
    }
// Solidity 0.4.24
/**
 * @dev Allows the current owner or operators to remove operator
 * @param _operator Address of the operator to be removed
 */
function removeOperator(address _operator) public onlyOwner {
        // Make sure operators array is not empty
        require(
            operators.length > 0,
            "No operator."
        );

        // Make sure the operator exists
        require(
            isOperator[_operator],
            "Not an operator."
        );

        // Manual array manipulation:
        // - replace the _operator with last operator in array
        // - remove the last item from array
        address lastOperator = operators[operators.length - 1];
        for (uint i = 0; i < operators.length; i++) {
            if (operators[i] == _operator) {
                operators[i] = lastOperator;
            }
        }
        operators.length -= 1; // remove the last element

        isOperator[_operator] = false;
        emit OperatorRemoved(_operator);
    }
// Solidity 0.8.4
/**
 * @notice Function to claim tokens
 * @param account Address to claim tokens for
 */
function claim(address account) external {
        uint256 totalAmount;
        for (uint8 i = 0; i < vestingIds[account].length; i++) {
            uint256 amount = getAvailableBalance(vestingIds[account][i]);
            if (amount > 0) {
                totalAmount += amount;
                vestings[vestingIds[account][i]].claimed += amount;
                vestings[vestingIds[account][i]].lastUpdate = block.timestamp;
            }
        }
        require(cpool.transfer(account, totalAmount), "Vesting::claim: transfer error");
    }
// Solidity 0.8.4
/**
 * @notice Owner function to hold tokens to a batch of accounts
 * @param params List of HoldParams objects with vesting params
 */
function holdTokens(HoldParams[] memory params) external onlyOwner {
        uint256 totalAmount;
        for (uint8 i = 0; i < params.length; i++) {
            totalAmount += params[i].amount;
        }
        require(cpool.transferFrom(msg.sender, address(this), totalAmount), "Vesting::holdTokens: transfer failed");
        totalVest += totalAmount;
        for (uint8 i = 0; i < params.length; i++) {
            _holdTokens(params[i]);
        }
    }
// Solidity 0.8.4
/**
 * @notice Function gets amount of available for claim tokens in exact vesting object
 * @param id ID of the vesting object
 * @return Amount of available tokens
 */
function getAvailableBalance(uint256 id) public view returns (uint256) {
        VestingParams memory vestParams = vestings[id];
        if (block.timestamp < vestParams.vestingCliff) {
            return 0;
        }
        uint256 amount;
        if (block.timestamp >= vestingEnd) {
            amount = vestParams.amount - vestParams.claimed;
        } else {
            amount = vestParams.amount * (block.timestamp - vestParams.lastUpdate) / (vestingEnd - vestingBegin);
        }
        return amount;
    }
// Solidity 0.8.4
/**
 * @notice Private function to hold tokens for one account
 * @param params HoldParams object with vesting params
 */
function _holdTokens(HoldParams memory params) private {
        require(params.amount > 0, "Vesting::holdTokens: can not hold zero amount");
        require(vestingEnd > params.vestingCliff, "Vesting::holdTokens: cliff is too late");
        require(params.vestingCliff >= vestingBegin, "Vesting::holdTokens: cliff is too early");
        require(params.unlocked <= params.amount, "Vesting::holdTokens: unlocked can not be greater than amount");
    
        if (params.unlocked > 0) {
            cpool.transfer(params.recipient, params.unlocked);
        }
        if (params.unlocked < params.amount) {
            vestings[_nextVestingId] = VestingParams({
                amount: params.amount - params.unlocked,
                vestingCliff: params.vestingCliff,
                lastUpdate: vestingBegin,
                claimed: 0
            });
            vestingIds[params.recipient].push(_nextVestingId);
            _nextVestingId++;
        }
    }