lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.12
/**
 * @dev Moves the iterator to the next resource record.
 * @param iter The iterator to advance.
 */
function next(RRIterator memory iter) internal pure {
        iter.offset = iter.nextOffset;
        if (iter.offset >= iter.data.length) {
            return;
        }

        // Skip the name
        uint off = iter.offset + nameLength(iter.data, iter.offset);

        // Read type, class, and ttl
        iter.dnstype = iter.data.readUint16(off);
        off += 2;
        iter.class = iter.data.readUint16(off);
        off += 2;
        iter.ttl = iter.data.readUint32(off);
        off += 4;

        // Read the rdata
        uint rdataLength = iter.data.readUint16(off);
        off += 2;
        iter.rdataOffset = off;
        iter.nextOffset = off + rdataLength;
    }
// Solidity 0.5.12
/**
 * @dev Checks if a given RR type exists in a type bitmap.
 * @param self The byte string to read the type bitmap from.
 * @param offset The offset to start reading at.
 * @param rrtype The RR type to check for.
 * @return True if the type is found in the bitmap, false otherwise.
 */
function checkTypeBitmap(bytes memory self, uint offset, uint16 rrtype) internal pure returns (bool) {
        uint8 typeWindow = uint8(rrtype >> 8);
        uint8 windowByte = uint8((rrtype & 0xff) / 8);
        uint8 windowBitmask = uint8(uint8(1) << (uint8(7) - uint8(rrtype & 0x7)));
        for (uint off = offset; off < self.length;) {
            uint8 window = self.readUint8(off);
            uint8 len = self.readUint8(off + 1);
            if (typeWindow < window) {
                // We've gone past our window; it's not here.
                return false;
            } else if (typeWindow == window) {
                // Check this type bitmap
                if (len * 8 <= windowByte) {
                    // Our type is past the end of the bitmap
                    return false;
                }
                return (self.readUint8(off + windowByte + 2) & windowBitmask) != 0;
            } else {
                // Skip this type bitmap
                off += len + 2;
            }
        }

        return false;
    }
// Solidity 0.5.12
/**
 * Set one or more DNS records.  Records are supplied in wire-format.
 * Records with the same node/name/resource must be supplied one after the
 * other to ensure the data is updated correctly. For example, if the data
 * was supplied:
 *     a.example.com IN A 1.2.3.4
 *     a.example.com IN A 5.6.7.8
 *     www.example.com IN CNAME a.example.com.
 * then this would store the two A records for a.example.com correctly as a
 * single RRSET, however if the data was supplied:
 *     a.example.com IN A 1.2.3.4
 *     www.example.com IN CNAME a.example.com.
 *     a.example.com IN A 5.6.7.8
 * then this would store the first A record, the CNAME, then the second A
 * record which would overwrite the first.
 *
 * @param node the namehash of the node for which to set the records
 * @param data the DNS wire format records to set
 */
function setDNSRecords(bytes32 node, bytes calldata data) external authorised(node) {
        uint16 resource = 0;
        uint256 offset = 0;
        bytes memory name;
        bytes memory value;
        bytes32 nameHash;
        // Iterate over the data to add the resource records
        for (RRUtils.RRIterator memory iter = data.iterateRRs(0); !iter.done(); iter.next()) {
            if (resource == 0) {
                resource = iter.dnstype;
                name = iter.name();
                nameHash = keccak256(abi.encodePacked(name));
                value = bytes(iter.rdata());
            } else {
                bytes memory newName = iter.name();
                if (resource != iter.dnstype || !name.equals(newName)) {
                    setDNSRRSet(node, name, resource, data, offset, iter.offset - offset, value.length == 0);
                    resource = iter.dnstype;
                    offset = iter.offset;
                    name = newName;
                    nameHash = keccak256(name);
                    value = bytes(iter.rdata());
                }
            }
        }
        if (name.length > 0) {
            setDNSRRSet(node, name, resource, data, offset, data.length - offset, value.length == 0);
        }
    }
// Solidity 0.5.12
/**
 * Returns the address of a contract that implements the specified interface for this name.
 * If an implementer has not been set for this interfaceID and name, the resolver will query
 * the contract at `addr()`. If `addr()` is set, a contract exists at that address, and that
 * contract implements EIP165 and returns `true` for the specified interfaceID, its address
 * will be returned.
 * @param node The ENS node to query.
 * @param interfaceID The EIP 165 interface ID to check for.
 * @return The address that implements this interface, or 0 if the interface is unsupported.
 */
function interfaceImplementer(bytes32 node, bytes4 interfaceID) external view returns (address) {
        address implementer = interfaces[node][interfaceID];
        if(implementer != address(0)) {
            return implementer;
        }

        address a = addr(node);
        if(a == address(0)) {
            return address(0);
        }

        (bool success, bytes memory returnData) = a.staticcall(abi.encodeWithSignature("supportsInterface(bytes4)", INTERFACE_META_ID));
        if(!success || returnData.length < 32 || returnData[31] == 0) {
            // EIP 165 not supported by target
            return address(0);
        }

        (success, returnData) = a.staticcall(abi.encodeWithSignature("supportsInterface(bytes4)", interfaceID));
        if(!success || returnData.length < 32 || returnData[31] == 0) {
            // Specified interface not supported by target
            return address(0);
        }

        return a;
    }
// Solidity 0.5.4
/**
 	 * @dev Advocate of Setting's _associatedTAOId submits an address setting update after an update has been proposed
 	 * @param _settingId The ID of the setting to be updated
 	 * @param _newValue The new address value for this setting
 	 * @param _proposalTAOId The child of the associatedTAOId with the update Logos
 	 * @param _signatureV The V part of the signature of proposalTAOId, newValue and associatedTAOId's Advocate
 	 * @param _signatureR The R part of the signature of proposalTAOId, newValue and associatedTAOId's Advocate
 	 * @param _signatureS The S part of the signature of proposalTAOId, newValue and associatedTAOId's Advocate
 	 * @param _extraData Catch-all string value to be stored if exist
 	 */
function updateAddressSetting(
		uint256 _settingId,
		address _newValue,
		address _proposalTAOId,
		uint8 _signatureV,
		bytes32 _signatureR,
		bytes32 _signatureS,
		string memory _extraData)
		public
		canUpdate(_proposalTAOId)
		isAddressSetting(_settingId) {

		// Verify and store update address signature
		require (_verifyAndStoreUpdateAddressSignature(_settingId, _newValue, _proposalTAOId, _signatureV, _signatureR, _signatureS));

		// Store the setting state data
		require (_aoSettingAttribute.update(_settingId, _nameFactory.ethAddressToNameId(msg.sender), _proposalTAOId, _extraData));

		// Store the value as pending value
		_aoSettingValue.setPendingValue(_settingId, _newValue, false, '', '', 0);

		// Store the update hash key lookup
		_storeUpdateAddressHashLookup(_settingId, _newValue, _proposalTAOId, _extraData);

		emit SettingUpdate(_settingId, _nameFactory.ethAddressToNameId(msg.sender), _proposalTAOId);
	}
// Solidity 0.5.4
/**
 	 * @dev Advocate of Setting's proposalTAOId approves the setting update
 	 * @param _settingId The ID of the setting to be approved
 	 * @param _approved Whether to approve or reject
 	 */
function approveSettingUpdate(uint256 _settingId, bool _approved) public senderIsName senderNameNotCompromised {
		// Make sure setting exist
		require (_aoSetting.settingTypeLookup(_settingId) > 0);

		address _proposalTAOAdvocate = _nameFactory.ethAddressToNameId(msg.sender);
		(,,, address _proposalTAOId,,) = _aoSettingAttribute.getSettingState(_settingId);

		require (_aoSettingAttribute.approveUpdate(_settingId, _proposalTAOAdvocate, _approved));

		emit ApproveSettingUpdate(_settingId, _proposalTAOId, _proposalTAOAdvocate, _approved);
	}
// Solidity 0.5.4
/**
 	 * @dev Advocate of Setting's _associatedTAOId finalizes the setting update once the setting is approved
 	 * @param _settingId The ID of the setting to be finalized
 	 */
function finalizeSettingUpdate(uint256 _settingId) public senderIsName senderNameNotCompromised {
		// Make sure setting exist
		require (_aoSetting.settingTypeLookup(_settingId) > 0);

		address _associatedTAOAdvocate = _nameFactory.ethAddressToNameId(msg.sender);
		require (_aoSettingAttribute.finalizeUpdate(_settingId, _associatedTAOAdvocate));

		(,,, address _associatedTAOId,,,,,) = _aoSettingAttribute.getSettingData(_settingId);

		require (_aoSettingValue.movePendingToSetting(_settingId));

		emit FinalizeSettingUpdate(_settingId, _associatedTAOId, _associatedTAOAdvocate);
	}
// Solidity 0.5.4
/**
 	 * @dev Verify the signature for the address update and store the signature info
 	 * @param _settingId The ID of the setting to be updated
 	 * @param _newValue The new address value for this setting
 	 * @param _proposalTAOId The child of the associatedTAOId with the update Logos
 	 * @param _v The V part of the signature of proposalTAOId, newValue and associatedTAOId's Advocate
 	 * @param _r The R part of the signature of proposalTAOId, newValue and associatedTAOId's Advocate
 	 * @param _s The S part of the signature of proposalTAOId, newValue and associatedTAOId's Advocate
 	 * @return true if valid, false otherwise
 	 */
function _verifyAndStoreUpdateAddressSignature(
		uint256 _settingId,
		address _newValue,
		address _proposalTAOId,
		uint8 _v,
		bytes32 _r,
		bytes32 _s
		) internal returns (bool) {
		bytes32 _hash = keccak256(abi.encodePacked(address(this), _settingId, _proposalTAOId, _newValue, _nameFactory.ethAddressToNameId(msg.sender)));
		if (ecrecover(_hash, _v, _r, _s) != msg.sender) {
			return false;
		}
		_storeUpdateSignature(_settingId, _v, _r, _s);
		return true;
	}
// Solidity 0.4.24
// This is an incredibly trustfull ENS deployment, only use for testing
function newENS(address _owner) public returns (ENS) {
        ENS ens = new ENS();

        // Setup .eth TLD
        ens.setSubnodeOwner(ENS_ROOT, ETH_TLD_LABEL, this);

        // Setup public resolver
        PublicResolver resolver = new PublicResolver(ens);
        ens.setSubnodeOwner(ETH_TLD_NODE, PUBLIC_RESOLVER_LABEL, this);
        ens.setResolver(PUBLIC_RESOLVER_NODE, resolver);
        resolver.setAddr(PUBLIC_RESOLVER_NODE, resolver);

        ens.setOwner(ETH_TLD_NODE, _owner);
        ens.setOwner(ENS_ROOT, _owner);

        emit DeployENS(ens);

        return ens;
    }
// Solidity 0.5.4
/**
 	 * @dev Store the update hash lookup for this address setting
 	 * @param _settingId The ID of the setting to be updated
 	 * @param _newValue The new address value for this setting
 	 * @param _proposalTAOId The child of the associatedTAOId with the update Logos
 	 * @param _extraData Catch-all string value to be stored if exist
 	 */
function _storeUpdateAddressHashLookup(
		uint256 _settingId,
		address _newValue,
		address _proposalTAOId,
		string memory _extraData)
		internal {
		// Store the update hash key lookup
		(address _addressValue,,,,) = _aoSettingValue.settingValue(_settingId);
		updateHashLookup[keccak256(abi.encodePacked(address(this), _proposalTAOId, _addressValue, _newValue, _extraData, _settingId))] = _settingId;
	}
// Solidity 0.8.4
/**
 * Hack to get things to work automatically on OpenSea.
 * Use isApprovedForAll so the frontend doesn't have to worry about different method names.
 */
function isApprovedForAll(address _owner, address _operator)
        public
        view
        returns (bool)
    {
        if (owner() == _owner && _owner == _operator) {
            return true;
        }

        ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
        if (
            owner() == _owner &&
            address(proxyRegistry.proxies(_owner)) == _operator
        ) {
            return true;
        }
        return false;
    }
// Solidity 0.8.11
/* ///////////////////////////////////////////////////////////////
 EIP - 2612 LOGIC
 //////////////////////////////////////////////////////////////*/
function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual {
        if (block.timestamp > deadline) revert SignatureExpired();

        // cannot realistically overflow on human timescales
        unchecked {
            bytes32 digest = keccak256(
                abi.encodePacked(
                    '\x19\x01',
                    DOMAIN_SEPARATOR(),
                    keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline))
                )
            );

            address recoveredAddress = ecrecover(digest, v, r, s);

            if (recoveredAddress == address(0) || recoveredAddress != owner) revert InvalidSignature();

            allowance[recoveredAddress][spender] = value;
        }

        emit Approval(owner, spender, value);
    }
// Solidity 0.8.11
/* ///////////////////////////////////////////////////////////////
 MINT / BURN LOGIC
 //////////////////////////////////////////////////////////////*/
function _mint(address to, uint256 amount) internal virtual {
        totalSupply += amount;

        // cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value
        unchecked {
            balanceOf[to] += amount;
        }

        _moveDelegates(address(0), delegates(to), amount);

        emit Transfer(address(0), to, amount);
    }
// Solidity 0.8.4
// VRAgent was here!
function checkIfDuckOwner(uint16 _duckID) external view returns (bool) {
        require(_duckID >= 1 && _duckID <= 333, "Duck ID should be in range");
        uint56 offset = ducks[_duckID - 1];
        uint256 tokenID = uint256(offset) + baseNumber;
        OpenStoreContract nft = OpenStoreContract(openStoreNFTAddress);
        return nft.balanceOf(tx.origin, tokenID) == 1;
    }
// Solidity 0.6.12
///@dev claims the base token after it has been transmuted
///
///This function reverts if there is no realisedToken balance
function claim(bool asEth) public nonReentrant() noContractAllowed() {
        address sender = msg.sender;
        require(realisedTokens[sender] > 0);
        uint256 value = realisedTokens[sender];
        realisedTokens[sender] = 0;
        ensureSufficientFundsExistLocally(value);
        if (asEth) {
            IWETH9(token).withdraw(value);
            payable(sender).transfer(value);
        } else {
            IERC20Burnable(token).safeTransfer(sender, value);
        }
        emit TokenClaimed(sender, token, value);
    }
// Solidity 0.8.4
/**
 * @dev Transfers ownership of the contract to the Cosmic Vault (`cosmicVault`) and
 * sets the time (`unlockTime`) at which the now stored contract can be transferred back to
 * the previous owner.
 
 * NOTE Can only be called by the current owner.
 */
function storeInCosmicVault(address cosmicVault, uint256 unlockTime) public virtual onlyOwner {
        require(cosmicVault != address(0), "CVOwnable: new owner is the zero address");
        _previousOwner = _owner;
        _unlockTime = unlockTime;
        emit OwnershipTransferred(_previousOwner, cosmicVault);
        _owner = cosmicVault;
    }
// Solidity 0.8.13
/**
 * @notice GoldFinch PoolToken Value in Value in term of USDC
 */
function getGoldFinchPoolTokenBalanceInUSDC() public view returns (uint256) {
    uint256 total = 0;
    uint256 balance = goldFinchPoolToken.balanceOf(address(this));
    for (uint256 i = 0; i < balance; i++) {
      total = total.add(
        getJuniorTokenValue(
          address(goldFinchPoolToken),
          goldFinchPoolToken.tokenOfOwnerByIndex(address(this), i)
        )
      );
    }
    return total.mul(usdcMantissa());
  }
// Solidity 0.8.13
/**
 * @notice An Alloy token holder can deposit their tokens and redeem them for USDC
 * @param _tokenAmount Number of Alloy Tokens
 */
function depositAlloyxBronzeTokens(uint256 _tokenAmount)
    external
    whenNotPaused
    whenVaultStarted
    returns (bool)
  {
    require(
      alloyxTokenBronze.balanceOf(msg.sender) >= _tokenAmount,
      "User has insufficient alloyx coin"
    );
    require(
      alloyxTokenBronze.allowance(msg.sender, address(this)) >= _tokenAmount,
      "User has not approved the vault for sufficient alloyx coin"
    );
    uint256 amountToWithdraw = alloyxBronzeToUSDC(_tokenAmount);
    require(amountToWithdraw > 0, "The amount of stable coin to get is not larger than 0");
    require(
      usdcCoin.balanceOf(address(this)) >= amountToWithdraw,
      "The vault does not have sufficient stable coin"
    );
    alloyxTokenBronze.burn(msg.sender, _tokenAmount);
    usdcCoin.safeTransfer(msg.sender, amountToWithdraw);
    emit DepositAlloyx(address(alloyxTokenBronze), msg.sender, _tokenAmount);
    emit Burn(msg.sender, _tokenAmount);
    return true;
  }
// Solidity 0.8.13
/**
 * @notice A Liquidity Provider can deposit supported stable coins for Alloy Tokens
 * @param _tokenAmount Number of stable coin
 */
function depositUSDCCoin(uint256 _tokenAmount)
    external
    whenNotPaused
    whenVaultStarted
    returns (bool)
  {
    require(usdcCoin.balanceOf(msg.sender) >= _tokenAmount, "User has insufficient stable coin");
    require(
      usdcCoin.allowance(msg.sender, address(this)) >= _tokenAmount,
      "User has not approved the vault for sufficient stable coin"
    );
    uint256 amountToMint = USDCtoAlloyxBronze(_tokenAmount);
    require(amountToMint > 0, "The amount of alloyx bronze coin to get is not larger than 0");
    usdcCoin.safeTransferFrom(msg.sender, address(this), _tokenAmount);
    alloyxTokenBronze.mint(msg.sender, amountToMint);
    emit DepositStable(address(usdcCoin), msg.sender, amountToMint);
    emit Mint(msg.sender, amountToMint);
    return true;
  }
// Solidity 0.8.13
/**
 * @notice A Junior token holder can deposit their NFT for stable coin
 * @param _tokenAddress NFT Address
 * @param _tokenID NFT ID
 */
function depositNFTToken(address _tokenAddress, uint256 _tokenID)
    external
    whenNotPaused
    whenVaultStarted
    returns (bool)
  {
    require(_tokenAddress == address(goldFinchPoolToken), "Not Goldfinch Pool Token");
    require(isValidPool(_tokenAddress, _tokenID) == true, "Not a valid pool");
    require(IERC721(_tokenAddress).ownerOf(_tokenID) == msg.sender, "User does not own this token");
    require(
      IERC721(_tokenAddress).getApproved(_tokenID) == address(this),
      "User has not approved the vault for this token"
    );
    uint256 purchasePrice = getJuniorTokenValue(_tokenAddress, _tokenID);
    require(purchasePrice > 0, "The amount of stable coin to get is not larger than 0");
    require(
      usdcCoin.balanceOf(address(this)) >= purchasePrice,
      "The vault does not have sufficient stable coin"
    );
    IERC721(_tokenAddress).safeTransferFrom(msg.sender, address(this), _tokenID);
    usdcCoin.safeTransfer(msg.sender, purchasePrice);
    emit DepositNFT(_tokenAddress, msg.sender, _tokenID);
    return true;
  }
// Solidity 0.8.13
/**
 * @notice Using the Goldfinch contracts, read the principal, redeemed and redeemable values
 * @param _tokenAddress The backer NFT address
 * @param _tokenID The backer NFT id
 */
function getJuniorTokenValue(address _tokenAddress, uint256 _tokenID)
    public
    view
    returns (uint256)
  {
    // first get the amount redeemed and the principal
    IPoolTokens poolTokenContract = IPoolTokens(_tokenAddress);
    IPoolTokens.TokenInfo memory tokenInfo = poolTokenContract.getTokenInfo(_tokenID);
    uint256 principalAmount = tokenInfo.principalAmount;
    uint256 totalRedeemed = tokenInfo.principalRedeemed.add(tokenInfo.interestRedeemed);

    // now get the redeemable values for the given token
    address tranchedPoolAddress = tokenInfo.pool;
    ITranchedPool tranchedTokenContract = ITranchedPool(tranchedPoolAddress);
    (uint256 interestRedeemable, uint256 principalRedeemable) = tranchedTokenContract
      .availableToWithdraw(_tokenID);
    uint256 totalRedeemable = interestRedeemable;
    // only add principal here if there have been drawdowns otherwise it overstates the value
    if (principalRedeemable < principalAmount) {
      totalRedeemable.add(principalRedeemable);
    }
    return principalAmount.sub(totalRedeemed).add(totalRedeemable).mul(usdcMantissa());
  }
// Solidity 0.4.20
// Change bet expected end time
function setExpectedEnd(uint _EXPECTED_END) payable public onlyOwnerLevel {
    require(_EXPECTED_END > EXPECTED_START);

    EXPECTED_END = _EXPECTED_END;
    CANCELATION_DATE = EXPECTED_END + 60 * 60 * 24;
    RETURN_DATE = EXPECTED_END + 60 * 60 * 24 * 30;

    callOracle(EXPECTED_END, ORACLIZE_GAS); // Kickoff Oracle checking for winner
  }
// Solidity 0.4.20
// Callback from Oraclize
function __callback(bytes32 queryId, string result, bytes proof) public canDetermineWinner {
    require(msg.sender == oraclize_cbAddress());

    // The Oracle must always return
    // an integer (either 0 or 1, or if not then)
    // it should be 2
    if (keccak256(result) != keccak256("0") && keccak256(result) != keccak256("1")) {
      // Reschedule winner determination,
      // unless we're past the point of
      // cancelation. If nextScheduledQuery is
      // not the current query, it means that
      // there's a scheduled future query, so
      // we can wait for that instead of scheduling
      // another one now (otherwise this would cause
      // dupe queries).

      if (now >= CANCELATION_DATE) {
        cancel();
      }
      else if (nextScheduledQuery == queryId) {
        callOracle(PING_ORACLE_INTERVAL, ORACLIZE_GAS);
      }
    }
    else {
      setWinner(parseInt(result));
    }
  }
// Solidity 0.4.20
// Returns whether winning collections are
// now available, or not.
function collectionsAvailable() public constant returns(bool) {
    return (completed && winningOption != 2 && now >= (winnerDeterminedDate + 600)); // At least 10 mins has to pass between determining winner and enabling payout, so that we have time to revert the bet in case we detect suspicious betting activty (eg. a hacker bets a lot to steal the entire losing pot, and hacks the oracle)
  }
// Solidity 0.4.20
// Function for user to bet on launch
// outcome
function bet(uint option) public payable {
    require(canBet() == true);
    require(msg.value >= MIN_BET);
    require(betterInfo[msg.sender].betAmount == 0 || betterInfo[msg.sender].betOption == option);

    // Add better to better list if they
    // aren't already in it
    if (betterInfo[msg.sender].betAmount == 0) {
      betterInfo[msg.sender].betOption = option;
      numberOfBets[option]++;

      betters.push(msg.sender);
    }

    // Perform bet
    betterInfo[msg.sender].betAmount += msg.value;
    totalBetAmount += msg.value;
    totalAmountsBet[option] += msg.value;

    BetMade(); // Trigger event
  }