lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.24
/**
 * @dev Create robot liability smart contract
 * @param _demand ABI-encoded demand message 
 * @param _offer ABI-encoded offer message 
 */
function createLiability(
        bytes _demand,
        bytes _offer
    )
        external 
        onlyLighthouse
        gasPriceEstimated
        returns (RobotLiability liability) { // Store in memory available gas
        uint256 gasinit = gasleft();

        // Create liability
        liability = new RobotLiability(robotLiabilityLib);
        emit NewLiability(liability);

        // Parse messages
        require(liability.call(abi.encodePacked(bytes4(0xd9ff764a), _demand))); // liability.demand(...)
        singletonHash(liability.demandHash());

        require(liability.call(abi.encodePacked(bytes4(0xd5056962), _offer))); // liability.offer(...)
        singletonHash(liability.offerHash());

        // Transfer lighthouse fee to lighthouse worker directly
        if (liability.lighthouseFee() > 0)
            xrt.safeTransferFrom(liability.promisor(),
                                 tx.origin,
                                 liability.lighthouseFee());

        // Transfer liability security and hold on contract
        ERC20 token = liability.token();
        if (liability.cost() > 0)
            token.safeTransferFrom(liability.promisee(),
                                   liability,
                                   liability.cost());

        // Transfer validator fee and hold on contract
        if (address(liability.validator()) != 0 && liability.validatorFee() > 0)
            xrt.safeTransferFrom(liability.promisee(),
                                 liability,
                                 liability.validatorFee());

        // Accounting gas usage of transaction
        uint256 gas = gasinit - gasleft() + 110525; // Including observation error
        totalGasUtilizing       += gas;
        gasUtilizing[liability] += gas;
     }
// Solidity 0.4.24
/**
 * @dev Create lighthouse smart contract
 * @param _minimalFreeze Minimal freeze value of XRT token
 * @param _timeoutBlocks Max time of lighthouse silence in blocks
 * @param _name Lighthouse subdomain,
 *              example: for 'my-name' will created 'my-name.lighthouse.1.robonomics.eth' domain
 */
function createLighthouse(
        uint256 _minimalFreeze,
        uint256 _timeoutBlocks,
        string  _name
    )
        external
        returns (address lighthouse)
    {
        bytes32 lighthouseNode
            // lighthouse.3.robonomics.eth
            = 0x87bd923a85f096b00a4a347fb56cef68e95319b3d9dae1dff59259db094afd02;

        // Name reservation check
        bytes32 subnode = keccak256(abi.encodePacked(lighthouseNode, keccak256(_name)));
        require(ens.resolver(subnode) == 0);

        // Create lighthouse
        lighthouse = new Lighthouse(lighthouseLib, _minimalFreeze, _timeoutBlocks);
        emit NewLighthouse(lighthouse, _name);
        isLighthouse[lighthouse] = true;

        // Register subnode
        ens.setSubnodeOwner(lighthouseNode, keccak256(_name), this);

        // Register lighthouse address
        PublicResolver resolver = PublicResolver(ens.resolver(lighthouseNode));
        ens.setResolver(subnode, resolver);
        resolver.setAddr(subnode, lighthouse);
    }
// Solidity 0.4.24
/**
 * @dev Is called whan after liability finalization
 * @param _gas Liability finalization gas expenses
 */
function liabilityFinalized(
        uint256 _gas
    )
        external
        gasPriceEstimated
        returns (bool)
    {
        require(gasUtilizing[msg.sender] > 0);

        uint256 gas = _gas - gasleft();
        require(_gas > gas);

        totalGasUtilizing        += gas;
        gasUtilizing[msg.sender] += gas;

        require(xrt.mint(tx.origin, wnFromGas(gasUtilizing[msg.sender])));
        return true;
    }
// Solidity 0.6.6
/**
 * @dev Deploys a contract using `CREATE2`. The address where the contract
 * will be deployed can be known in advance via {computeAddress}. Note that
 * a contract cannot be deployed twice using the same salt.
 */
function deploy(bytes32 salt, bytes memory bytecode) internal returns (address) {
        address addr;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            addr := create2(0, add(bytecode, 0x20), mload(bytecode), salt)
        }
        require(addr != address(0), "Create2: Failed on deploy");
        return addr;
    }
// Solidity 0.4.24
/**
 * @dev Tokens transfer will not work if sender or recipient has dividends
 */
function _transfer(address _from, address _to, uint256 _value) internal {
        require(_to != address(0));
        require(_value <= accounts[_from].balance);
        require(accounts[_to].balance + _value >= accounts[_to].balance);
    
        uint256 fromOwing = dividendBalanceOf(_from);
        uint256 toOwing = dividendBalanceOf(_to);
        require(fromOwing <= 0 && toOwing <= 0);
    
        accounts[_from].balance = accounts[_from].balance.sub(_value);
        accounts[_to].balance = accounts[_to].balance.add(_value);
    
        accounts[_to].lastDividends = accounts[_from].lastDividends;
    
        emit Transfer(_from, _to, _value);
    }
// Solidity 0.7.6
/// @dev Get All Official Vaults List
function getAllVaultAddress() external view returns(address[] memory workingVaults) {
        address[] memory vaults = vaultLists;
        uint256 length = vaults.length;
        bool[] memory status = new bool[](length);
        // get abandon Vaults status
        uint256 workNumber;
        for (uint256 i; i < length; i++) {
            if (vaultStatus[vaults[i]] == Status.working) {
                status[i] = true;
                workNumber++;
            }
        }
        if(workNumber > 0){
            // get working vaults list
            workingVaults = new address[](workNumber);
            uint256 idx;
            for (uint256 i; i < length; i++) {
                if (status[i]) {
                    workingVaults[idx] = vaults[i];
                    idx += 1;
                }
            }
        }
    }
// Solidity 0.8.4
/**
 * @notice Transfers some tokens on behalf of address `_from' (token owner)
 *      to some other address `_to`
 *
 * @dev ERC20 `function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)`
 *
 * @dev Called by token owner on his own or approved address,
 *      an address approved earlier by token owner to
 *      transfer some amount of tokens on its behalf
 * @dev Throws on any error like
 *      * insufficient token balance or
 *      * incorrect `_to` address:
 *          * zero address or
 *          * same as `_from` address (self transfer)
 *          * smart contract which doesn't support ERC20
 *
 * @param _from token owner which approved caller (transaction sender)
 *      to transfer `_value` of tokens on its behalf
 * @param _to an address to transfer tokens to,
 *      must be either an external address or a smart contract,
 *      compliant with the ERC20 standard
 * @param _value amount of tokens to be transferred, must
 *      be greater than zero
 * @return success true on success, throws otherwise
 */
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
    // depending on `FEATURE_UNSAFE_TRANSFERS` we execute either safe (default)
    // or unsafe transfer
    // if `FEATURE_UNSAFE_TRANSFERS` is enabled
    // or receiver has `ROLE_ERC20_RECEIVER` permission
    // or sender has `ROLE_ERC20_SENDER` permission
    if(isFeatureEnabled(FEATURE_UNSAFE_TRANSFERS)
      || isOperatorInRole(_to, ROLE_ERC20_RECEIVER)
      || isSenderInRole(ROLE_ERC20_SENDER)) {
      // we execute unsafe transfer - delegate call to `unsafeTransferFrom`,
      // `FEATURE_TRANSFERS` is verified inside it
      unsafeTransferFrom(_from, _to, _value);
    }
    // otherwise - if `FEATURE_UNSAFE_TRANSFERS` is disabled
    // and receiver doesn't have `ROLE_ERC20_RECEIVER` permission
    else {
      // we execute safe transfer - delegate call to `safeTransferFrom`, passing empty `_data`,
      // `FEATURE_TRANSFERS` is verified inside it
      safeTransferFrom(_from, _to, _value, "");
    }

    // both `unsafeTransferFrom` and `safeTransferFrom` throw on any error, so
    // if we're here - it means operation successful,
    // just return true
    return true;
  }
// Solidity 0.8.4
/**
 * @notice Transfers some tokens on behalf of address `_from' (token owner)
 *      to some other address `_to`
 *
 * @dev Inspired by ERC721 safeTransferFrom, this function allows to
 *      send arbitrary data to the receiver on successful token transfer
 * @dev Called by token owner on his own or approved address,
 *      an address approved earlier by token owner to
 *      transfer some amount of tokens on its behalf
 * @dev Throws on any error like
 *      * insufficient token balance or
 *      * incorrect `_to` address:
 *          * zero address or
 *          * same as `_from` address (self transfer)
 *          * smart contract which doesn't support ERC20Receiver interface
 * @dev Returns silently on success, throws otherwise
 *
 * @param _from token owner which approved caller (transaction sender)
 *      to transfer `_value` of tokens on its behalf
 * @param _to an address to transfer tokens to,
 *      must be either an external address or a smart contract,
 *      compliant with the ERC20 standard
 * @param _value amount of tokens to be transferred, must
 *      be greater than zero
 * @param _data [optional] additional data with no specified format,
 *      sent in onERC20Received call to `_to` in case if its a smart contract
 */
function safeTransferFrom(address _from, address _to, uint256 _value, bytes memory _data) public {
    // first delegate call to `unsafeTransferFrom`
    // to perform the unsafe token(s) transfer
    unsafeTransferFrom(_from, _to, _value);

    // after the successful transfer - check if receiver supports
    // ERC20Receiver and execute a callback handler `onERC20Received`,
    // reverting whole transaction on any error:
    // check if receiver `_to` supports ERC20Receiver interface
    if(AddressUtils.isContract(_to)) {
      // if `_to` is a contract - execute onERC20Received
      bytes4 response = ERC20Receiver(_to).onERC20Received(msg.sender, _from, _value, _data);

      // expected response is ERC20_RECEIVED
      require(response == ERC20_RECEIVED, "invalid onERC20Received response");
    }
  }
// Solidity 0.8.4
/**
 * @notice Approves address called `_spender` to transfer some amount
 *      of tokens on behalf of the owner
 *
 * @dev ERC20 `function approve(address _spender, uint256 _value) public returns (bool success)`
 *
 * @dev Caller must not necessarily own any tokens to grant the permission
 *
 * @param _spender an address approved by the caller (token owner)
 *      to spend some tokens on its behalf
 * @param _value an amount of tokens spender `_spender` is allowed to
 *      transfer on behalf of the token owner
 * @return success true on success, throws otherwise
 */
function approve(address _spender, uint256 _value) public returns (bool success) {
    // non-zero spender address check - Zeppelin
    // obviously, zero spender address is a client mistake
    // it's not part of ERC20 standard but it's reasonable to fail fast
    require(_spender != address(0), "ERC20: approve to the zero address"); // Zeppelin msg

    // read old approval value to emmit an improved event (ISBN:978-1-7281-3027-9)
    uint256 _oldValue = transferAllowances[msg.sender][_spender];

    // perform an operation: write value requested into the storage
    transferAllowances[msg.sender][_spender] = _value;

    // emit an improved atomic approve event (ISBN:978-1-7281-3027-9)
    emit Approved(msg.sender, _spender, _oldValue, _value);

    // emit an ERC20 approval event
    emit Approval(msg.sender, _spender, _value);

    // operation successful, return true
    return true;
  }
// Solidity 0.8.4
/**
 * @notice Increases the allowance granted to `spender` by the transaction sender
 *
 * @dev Resolution for the Multiple Withdrawal Attack on ERC20 Tokens (ISBN:978-1-7281-3027-9)
 *
 * @dev Throws if value to increase by is zero or too big and causes arithmetic overflow
 *
 * @param _spender an address approved by the caller (token owner)
 *      to spend some tokens on its behalf
 * @param _value an amount of tokens to increase by
 * @return success true on success, throws otherwise
 */
function increaseAllowance(address _spender, uint256 _value) public virtual returns (bool) {
    // read current allowance value
    uint256 currentVal = transferAllowances[msg.sender][_spender];

    // non-zero _value and arithmetic overflow check on the allowance
    require(currentVal + _value > currentVal, "zero value approval increase or arithmetic overflow");

    // delegate call to `approve` with the new value
    return approve(_spender, currentVal + _value);
  }
// Solidity 0.8.4
/**
 * @notice Decreases the allowance granted to `spender` by the caller.
 *
 * @dev Resolution for the Multiple Withdrawal Attack on ERC20 Tokens (ISBN:978-1-7281-3027-9)
 *
 * @dev Throws if value to decrease by is zero or is bigger than currently allowed value
 *
 * @param _spender an address approved by the caller (token owner)
 *      to spend some tokens on its behalf
 * @param _value an amount of tokens to decrease by
 * @return success true on success, throws otherwise
 */
function decreaseAllowance(address _spender, uint256 _value) public virtual returns (bool) {
    // read current allowance value
    uint256 currentVal = transferAllowances[msg.sender][_spender];

    // non-zero _value check on the allowance
    require(_value > 0, "zero value approval decrease");

    // verify allowance decrease doesn't underflow
    require(currentVal >= _value, "ERC20: decreased allowance below zero");

    // delegate call to `approve` with the new value
    return approve(_spender, currentVal - _value);
  }
// Solidity 0.8.4
/**
 * @notice Gets current voting power of the account `_of`
 * @param _of the address of account to get voting power of
 * @return current cumulative voting power of the account,
 *      sum of token balances of all its voting delegators
 */
function getVotingPower(address _of) public view returns (uint256) {
    // get a link to an array of voting power history records for an address specified
    VotingPowerRecord[] storage history = votingPowerHistory[_of];

    // lookup the history and return latest element
    return history.length == 0? 0: history[history.length - 1].votingPower;
  }
// Solidity 0.8.4
/**
 * @dev Auxiliary function to delegate delegator's `_from` voting power to the delegate `_to`
 * @dev Writes to `votingDelegates` and `votingPowerHistory` mappings
 *
 * @param _from delegator who delegates his voting power
 * @param _to delegate who receives the voting power
 */
function __delegate(address _from, address _to) private {
    // read current delegate to be replaced by a new one
    address _fromDelegate = votingDelegates[_from];

    // read current voting power (it is equal to token balance)
    uint256 _value = tokenBalances[_from];

    // reassign voting delegate to `_to`
    votingDelegates[_from] = _to;

    // update voting power for `_fromDelegate` and `_to`
    __moveVotingPower(_fromDelegate, _to, _value);

    // emit an event
    emit DelegateChanged(_from, _fromDelegate, _to);
  }
// Solidity 0.8.4
/**
 * @dev Auxiliary function to update voting power of the delegate `_of`
 *      from value `_fromVal` to value `_toVal`
 *
 * @param _of delegate to update its voting power
 * @param _fromVal old voting power of the delegate
 * @param _toVal new voting power of the delegate
 */
function __updateVotingPower(address _of, uint256 _fromVal, uint256 _toVal) private {
    // get a link to an array of voting power history records for an address specified
    VotingPowerRecord[] storage history = votingPowerHistory[_of];

    // if there is an existing voting power value stored for current block
    if(history.length != 0 && history[history.length - 1].blockNumber == block.number) {
      // update voting power which is already stored in the current block
      history[history.length - 1].votingPower = uint192(_toVal);
    }
    // otherwise - if there is no value stored for current block
    else {
      // add new element into array representing the value for current block
      history.push(VotingPowerRecord(uint64(block.number), uint192(_toVal)));
    }

    // emit an event
    emit VotingPowerChanged(_of, _fromVal, _toVal);
  }
// Solidity 0.4.24
//Anyone can pay the gas to create their very own Tester token
function create() public returns (uint256 _tokenId) {

    bytes32 sudoRandomButTotallyPredictable = keccak256(abi.encodePacked(totalSupply(),blockhash(block.number - 1)));
    uint8 body = (uint8(sudoRandomButTotallyPredictable[0])%5)+1;
    uint8 feet = (uint8(sudoRandomButTotallyPredictable[1])%5)+1;
    uint8 head = (uint8(sudoRandomButTotallyPredictable[2])%5)+1;
    uint8 mouth = (uint8(sudoRandomButTotallyPredictable[3])%5)+1;
    uint8 extra = (uint8(sudoRandomButTotallyPredictable[4])%5)+1;

    //this is about half of all the gas it takes because I'm doing some string manipulation
    //I could skip this, or make it way more efficient but the is just a silly hackathon project
    string memory tokenUri = createTokenUri(body,feet,head,mouth,extra);

    Token memory _newToken = Token({
        body: body,
        feet: feet,
        head: head,
        mouth: mouth,
        extra: extra,
        birthBlock: uint64(block.number)
    });
    _tokenId = tokens.push(_newToken) - 1;
    _mint(msg.sender,_tokenId);
    _setTokenURI(_tokenId, tokenUri);
    emit Create(_tokenId,msg.sender,body,feet,head,mouth,extra,_newToken.birthBlock,tokenUri);
    return _tokenId;
  }
// Solidity 0.6.11
// --- 'require' functions ---
function _requireValidRecipient(address _recipient) internal view {
        require(
            _recipient != address(0) && 
            _recipient != address(this),
            "LQTY: Cannot transfer tokens directly to the LQTY token contract or the zero address"
        );
        // require(
        //     _recipient != communityIssuanceAddress &&
        //     _recipient != lqtyStakingAddress,
        //     "LQTY: Cannot transfer tokens directly to the community issuance or staking contract"
        // );
    }
// Solidity 0.8.9
/** requires an encrypted bidToken (generated on marsmaiers.com)
 
 ======================================
 == DO NOT CALL THIS METHOD DIRECTLY ==
 ======================================
 
 if you call this method directly (through etherscan or by hand), your bid
 will NOT be counted. your funds will be unrefundable, and you will have to
 wait for the project to be concluded, once refund() is available
 
 ======================================
 ==                                  ==
 ==    ONLY BID ON MARSMAIERS.COM    ==
 ==                                  ==
 ======================================
 **/
function bid(string calldata bidToken) public payable {
    // validate input
    bytes memory bidTokenCheck = bytes(bidToken);
    require(bidTokenCheck.length > 0, 'invalid input');

    // ensure project is still ongoing
    require(!projectConcluded, 'project has concluded');

    // ensure bid meets min
    require(msg.value >= MIN_BID, 'below min bid');

    // if bidToken is already set, ensure _msgSender is the original bidder
    require(bidders[bidToken] == address(0x0) || bidders[bidToken] == _msgSender(), 'not your bid');

    // increment bidToken to new cumulative total
    bids[bidToken] = bids[bidToken] + msg.value;

    // mark _msgSender as bidder
    bidders[bidToken] = _msgSender();

    // emit event
    emit BidPlaced(bidToken, msg.sender, msg.value, bids[bidToken]);
  }
// Solidity 0.8.9
/// @notice chooses a winner, and moves value ofbidToken to winnings
/// @param tokenId day of year to mint
/// @param bidToken winning bid token
function settle(uint256 tokenId, string memory bidToken) public onlyRole(SETTLER_ROLE) {
    // validate input
    bytes memory bidTokenCheck = bytes(bidToken);
    require(tokenId >= 1 && tokenId <= 365 && bidTokenCheck.length > 0, 'invalid input');

    // no more winners allowed
    require(!projectConcluded, 'project has concluded');

    // look up bid total and winner by bidToken
    address winner = bidders[bidToken];
    uint256 amount = bids[bidToken];

    // ensure bidToken is not zero
    require(winner != address(0x0) && amount > 0, 'unknown bidToken');

    // zero bid
    bids[bidToken] = 0;

    // add amount to winnings
    winnings = winnings + amount;

    // close it up after final mint
    if (tokenId == 365) {
      projectConcluded = true;
    }

    // mint NFT to winner
    _safeMint(winner, tokenId);
  }
// Solidity 0.8.9
/// @notice allows owner to cash out, from the designated winnings only
/// @param amount value in wei to transfer
/// @param to address to transfer funds to
function withdraw(uint256 amount, address to) external onlyRole(MANAGER_ROLE) {
    require(amount > 0, 'invalid input');
    require(amount <= winnings, 'amount exceeds winnings');

    // subtract amount
    winnings = winnings - amount;

    // send funds to destination
    payable(to).sendValue(amount);
  }
// Solidity 0.8.9
/// @notice transfers funds for a lost bid back to original bidder. requires a signed signature generated on marsmaiers.com
/// @param bidToken bid token representing the lost bid you are refunding
/// @param nonce nonce string, generated along with signature
/// @param signature signature containing bidToken and nonce. generated on marsmaiers.com
function signedRefund(
    string memory bidToken,
    string memory nonce,
    bytes memory signature
  ) public nonReentrant {
    // infer message by hashing input params. signature must contain a hash with the same message
    bytes32 message = keccak256(abi.encode(bidToken, nonce));

    // validate inferred message matches input params, and was signed by an address with RECEIPT_SIGNER_ROLE
    // if this passes we can trust the input params match
    require(hasRole(RECEIPT_SIGNER_ROLE, message.toEthSignedMessageHash().recover(signature)), 'invalid receipt');

    // execute refund
    _refund(bidToken);
  }
// Solidity 0.8.9
/// @notice generic mechanism to return the value of a list of bidTokens to their original bidder. only enabled once project has concluded.
/// @param bidTokens array of bid tokens to refund
function refund(string[] memory bidTokens) public nonReentrant {
    // only allow unsigned refunds once project is concluded
    require(projectConcluded, 'project has not concluded');

    // execute refund for each bidToken
    for (uint256 i = 0; i < bidTokens.length; i++) {
      _refund(bidTokens[i]);
    }
  }
// Solidity 0.8.9
/// allows *anyone* to mark the project as concluded, if the entire year has elapsed.
/// this should normally never be needed, as minting the final piece also marks
/// the project as concluded. in the unlikely event the final piece is never minted,
/// this gives the community a way to release all pending bids.
function concludeProject() public {
    // require block time to be after January 2, 2023 1:00:00 AM GMT (one day of buffer)
    require(block.timestamp > 1672621200, 'year is not over');

    // mark project as concluded
    projectConcluded = true;
  }
// Solidity 0.8.9
// === PRIVATE ===
// internal method to validate and process return a bid, using bidder and amount keyed to bidToken
function _refund(string memory bidToken) private {
    // ensure bidToken exists with a balance, and was placed by _msgSender
    require(bids[bidToken] > 0, 'bid does not exist');

    // stash and zero bid
    uint256 amount = bids[bidToken];
    bids[bidToken] = 0;

    // don't zero bidder (prevents future reuse of bidToken)
    address bidder = bidders[bidToken];

    // emit event
    emit Refunded(bidToken, bidder, amount);

    // issue refund to bidder
    payable(bidder).sendValue(amount);
  }