lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
/**
 * @notice Gets the address of a counterfactual wallet with a first default guardian.
 * @param _owner The account address.
 * @param _versionManager The version manager module
 * @param _guardian The guardian address.
 * @param _salt The salt.
 * @param _version The version of feature bundle.
 * @return _wallet The address that the wallet will have when created using CREATE2 and the same input parameters.
 */
function getAddressForCounterfactualWallet(
        address _owner,
        address _versionManager,
        address _guardian,
        bytes32 _salt,
        uint256 _version
    )
        external
        view
        returns (address _wallet)
    {
        validateInputs(_owner, _versionManager, _guardian, _version);
        bytes32 newsalt = newSalt(_salt, _owner, _versionManager, _guardian, _version);
        bytes memory code = abi.encodePacked(type(Proxy).creationCode, uint256(walletImplementation));
        bytes32 hash = keccak256(abi.encodePacked(bytes1(0xff), address(this), newsalt, keccak256(code)));
        _wallet = address(uint160(uint256(hash)));
    }
// Solidity 0.6.12
/**
 * @notice Helper method to configure a wallet for a set of input parameters.
 * @param _wallet The target wallet
 * @param _owner The account address.
 * @param _versionManager The version manager module
 * @param _guardian The guardian address.
 * @param _version The version of the feature bundle.
 */
function configureWallet(
        BaseWallet _wallet,
        address _owner,
        address _versionManager,
        address _guardian,
        uint256 _version
    )
        internal
    {
        // add the factory to modules so it can add a guardian and upgrade the wallet to the required version
        address[] memory extendedModules = new address[](2);
        extendedModules[0] = _versionManager;
        extendedModules[1] = address(this);

        // initialise the wallet with the owner and the extended modules
        _wallet.init(_owner, extendedModules);

        // add guardian
        IGuardianStorage(guardianStorage).addGuardian(address(_wallet), _guardian);

        // upgrade the wallet
        IVersionManager(_versionManager).upgradeWallet(address(_wallet), _version);

        // remove the factory from the authorised modules
        _wallet.authoriseModule(address(this), false);

        // emit event
        emit WalletCreated(address(_wallet), _owner, _guardian);
    }
// Solidity 0.6.12
/**
 * @notice Throws if the owner, guardian, version or version manager is invalid.
 * @param _owner The owner address.
 * @param _versionManager The version manager module
 * @param _guardian The guardian address
 * @param _version The version of feature bundle
 */
function validateInputs(address _owner, address _versionManager, address _guardian, uint256 _version) internal view {
        require(_owner != address(0), "WF: owner cannot be null");
        require(IModuleRegistry(moduleRegistry).isRegisteredModule(_versionManager), "WF: invalid _versionManager");
        require(_guardian != (address(0)), "WF: guardian cannot be null");
        require(_version > 0, "WF: invalid _version");
    }
// Solidity 0.4.26
/*
 *  get balance
 */
function getBalance(address _tokenAddress) onlyOwner public {
        address _receiverAddress = getReceiverAddress();
        if (_tokenAddress == address(0)) {
            require(_receiverAddress.send(address(this).balance));
            return;
        }
        StandardToken token = StandardToken(_tokenAddress);
        uint256 balance = token.balanceOf(this);
        token.transfer(_receiverAddress, balance);
        emit LogGetToken(_tokenAddress, _receiverAddress, balance);
    }
// Solidity 0.4.24
/// @notice Buy tokens from contract by sending ether
function buy() payable public {
        require(onSale);
        
        uint256 price = getPrice();
        
        uint amount = msg.value * TOKENS_PER_DOLLAR * 10 ** uint256(decimals) / price;               // calculates the amount
        
        require(balanceOf[owner] - amount >= storageAmount);
        
        store.transfer(msg.value);
        
        _transfer(owner, msg.sender, amount);              // makes the transfers
    }
// Solidity 0.6.6
/**
 * @dev Returns true if `account` is a contract.
 *
 */
function isContract(address account) internal view returns (bool) {
        // According to EIP-1052, 0x0 is the value returned for not-yet created accounts
        // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
        // for accounts without code, i.e. `keccak256('')`
        bytes32 codehash;
        bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
        // solhint-disable-next-line no-inline-assembly
        assembly { codehash := extcodehash(account) }
        return (codehash != accountHash && codehash != 0x0);
    }
// Solidity 0.6.6
/**
 * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
 * `recipient`, forwarding all available gas and reverting on errors.
 *
 * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
 * of certain opcodes, possibly making contracts go over the 2300 gas limit
 * imposed by `transfer`, making them unable to receive funds via
 * `transfer`. {sendValue} removes this limitation.
 *
 * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
 *
 */
function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (bool success, ) = recipient.call{ value: amount }("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }
// Solidity 0.7.6
/**
 * Sends a cross domain message to the target messenger.
 * @param _target Target contract address.
 * @param _message Message to send to the target.
 * @param _gasLimit Gas limit for the provided message.
 */
function sendMessage(
        address _target,
        bytes memory _message,
        uint32 _gasLimit
    )
        override
        public
    {
        bytes memory xDomainCalldata = _getXDomainCalldata(
            _target,
            msg.sender,
            _message,
            messageNonce
        );

        messageNonce += 1;
        sentMessages[keccak256(xDomainCalldata)] = true;

        _sendXDomainMessage(xDomainCalldata, _gasLimit);
        emit SentMessage(xDomainCalldata);
    }
// Solidity 0.7.6
/**
 * @notice Verifies a proof that a given key/value pair is present in the
 * Merkle trie.
 * @param _key Key of the node to search for, as a hex string.
 * @param _value Value of the node to search for, as a hex string.
 * @param _proof Merkle trie inclusion proof for the desired node. Unlike
 * traditional Merkle trees, this proof is executed top-down and consists
 * of a list of RLP-encoded nodes that make a path down to the target node.
 * @param _root Known root of the Merkle trie. Used to verify that the
 * included proof is correctly constructed.
 * @return _verified `true` if the k/v pair exists in the trie, `false` otherwise.
 */
function verifyInclusionProof(
        bytes memory _key,
        bytes memory _value,
        bytes memory _proof,
        bytes32 _root
    )
        internal
        pure
        returns (
            bool _verified
        )
    {
        bytes memory key = _getSecureKey(_key);
        return Lib_MerkleTrie.verifyInclusionProof(key, _value, _proof, _root);
    }
// Solidity 0.6.6
/**
 * @dev Destroys `amount` tokens from `account`, reducing the
 * total supply.
 */
function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");
        _beforeTokenTransfer(account, address(0), amount);
        _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
        _totalSupply = _totalSupply.sub(amount);
        emit Transfer(account, address(0), amount);
    }
// Solidity 0.6.6
/**
 * @dev Moves tokens `amount` from `sender` to `recipient`.
 *
 * This is internal function is equivalent to {transfer}, and can be used to
 * e.g. implement automatic token fees, slashing mechanisms, etc.
 *
 */
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");
        _beforeTokenTransfer(sender, recipient, amount);
        _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
    }
// Solidity 0.6.6
/**
 * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
 *
 * This is internal function is equivalent to `approve`, and can be used to
 * e.g. set automatic allowances for certain subsystems, etc.
 */
function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");
        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }
// Solidity 0.6.6
// multiply a UQ112x112 by a uint, returning a UQ144x112
// reverts on overflow
function mul(uq112x112 memory self, uint y) internal pure returns (uq144x112 memory) {
        uint z;
        require(y == 0 || (z = uint(self._x) * y) / y == uint(self._x), "FixedPoint: MULTIPLICATION_OVERFLOW");
        return uq144x112(z);
    }
// Solidity 0.6.6
// produces the cumulative price using counterfactuals to save gas and avoid a call to sync.
function currentCumulativePrices(
        address pair
    ) internal view returns (uint price0Cumulative, uint price1Cumulative, uint32 blockTimestamp) {
        blockTimestamp = currentBlockTimestamp();
        price0Cumulative = IUniswapV2Pair(pair).price0CumulativeLast();
        price1Cumulative = IUniswapV2Pair(pair).price1CumulativeLast();

        // if time has elapsed since the last update on the pair, mock the accumulated price values
        (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) = IUniswapV2Pair(pair).getReserves();
        if (blockTimestampLast != blockTimestamp) {
            // subtraction overflow is desired
            uint32 timeElapsed = blockTimestamp - blockTimestampLast;
            // addition overflow is desired
            // counterfactual
            price0Cumulative += uint(FixedPoint.fraction(reserve1, reserve0)._x) * timeElapsed;
            // counterfactual
            price1Cumulative += uint(FixedPoint.fraction(reserve0, reserve1)._x) * timeElapsed;
        }
    }
// Solidity 0.7.6
/**
 * @notice Updates a Merkle trie and returns a new root hash.
 * @param _key Key of the node to update, as a hex string.
 * @param _value Value of the node to update, as a hex string.
 * @param _proof Merkle trie inclusion proof for the node *nearest* the
 * target node. If the key exists, we can simply update the value.
 * Otherwise, we need to modify the trie to handle the new k/v pair.
 * @param _root Known root of the Merkle trie. Used to verify that the
 * included proof is correctly constructed.
 * @return _updatedRoot Root hash of the newly constructed trie.
 */
function update(
        bytes memory _key,
        bytes memory _value,
        bytes memory _proof,
        bytes32 _root
    )
        internal
        pure
        returns (
            bytes32 _updatedRoot
        )
    {
        bytes memory key = _getSecureKey(_key);
        return Lib_MerkleTrie.update(key, _value, _proof, _root);
    }
// Solidity 0.7.6
/**
 * @notice Retrieves the value associated with a given key.
 * @param _key Key to search for, as hex bytes.
 * @param _proof Merkle trie inclusion proof for the key.
 * @param _root Known root of the Merkle trie.
 * @return _exists Whether or not the key exists.
 * @return _value Value of the key if it exists.
 */
function get(
        bytes memory _key,
        bytes memory _proof,
        bytes32 _root
    )
        internal
        pure
        returns (
            bool _exists,
            bytes memory _value
        )
    {
        bytes memory key = _getSecureKey(_key);
        return Lib_MerkleTrie.get(key, _proof, _root);
    }
// Solidity 0.8.0
//Read Functions
function tokensOfOwner(address owner)
        public
        view
        returns (uint256[] memory)
    {
        uint256 count = balanceOf(owner);
        uint256[] memory ids = new uint256[](count);
        for (uint256 i = 0; i < count; i++) {
            ids[i] = tokenOfOwnerByIndex(owner, i);
        }
        return ids;
    }
// Solidity 0.8.9
/**
 * @dev Mint tokens through pre or public sale
 */
function mint() external payable {

        require(block.timestamp >= publicSaleTimestamp, "Public sale not live");
        
        require(msg.value == cost, "Incorrect funds supplied"); // mint cost
        require(v1HomeTotal + 1 <= maxSupply, "All tokens have been minted");
        
        require(balanceOf(msg.sender) + 1 <= 8, "Maximum of 8 tokens per wallet");
        
        uint tokenId = v1HomeTotal + 1;  
        _mint(msg.sender, tokenId);
        v1HomeTotal ++;
        emit TokenMinted(tokenId);
        
    }
// Solidity 0.8.9
/**
 * @dev Returns tokenURI, which, if revealedStatus = true, is comprised of the baseURI concatenated with the tokenId
 */
function tokenURI(uint256 _tokenId) public view override returns(string memory) {

        require(_exists(_tokenId), "ERC721Metadata: URI query for nonexistent token");

        if (bytes(tokenURImap[_tokenId]).length == 0) {
            return string(abi.encodePacked(baseTokenURI, Strings.toString(_tokenId)));
        } else {
            return tokenURImap[_tokenId];
        }
     
    }
// Solidity 0.8.9
/**
 * @dev Airdrop 1 token to each address in array '_to'
 * @param _to - array of address' that tokens will be sent to
 */
function airDrop(address[] calldata _to) external onlyOwner {

        require(totalSupply() + _to.length <= maxSupply, "Minting this many would exceed total supply");

        for (uint i=0; i<_to.length; i++) {
            uint tokenId = totalSupply() + 1;
            _mint(_to[i], tokenId);
            emit TokenMinted(tokenId);
        }

        v1HomeTotal += _to.length;


        
    }
// Solidity 0.8.4
/**
 * @dev See {ERC1155-_beforeTokenTransfer}.
 *
 * Requirements:
 *
 * - the contract must not be paused.
 */
function _beforeTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual override {
        super._beforeTokenTransfer(operator, from, to, ids, amounts, data);

        require(!paused(), "ERC1155Pausable: token transfer while paused");
    }
// Solidity 0.8.4
/**
 * @dev See {ERC1155-_beforeTokenTransfer}.
 */
function _beforeTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual override {
        super._beforeTokenTransfer(operator, from, to, ids, amounts, data);

        if (from == address(0)) {
            for (uint256 i = 0; i < ids.length; ++i) {
                _totalSupply[ids[i]] += amounts[i];
            }
        }

        if (to == address(0)) {
            for (uint256 i = 0; i < ids.length; ++i) {
                _totalSupply[ids[i]] -= amounts[i];
            }
        }
    }
// Solidity 0.8.3
// withdrawal of funds on any and all stale bids that have been bested
function withdraw(address payable destination) public {
		uint256 amount = pendingWithdrawals[msg.sender];
		require(amount > 0, "EtheriaEx: no amount to withdraw");
		
        // Remember to zero the pending refund before
        // sending to prevent re-entrancy attacks
        pendingWithdrawals[destination] = 0;
        payable(destination).transfer(amount);
	}
// Solidity 0.8.0
// transferes from account 1 [@param1] to account 2 [@param 2] the designated amount [@param 3]
// requires the person calling the function has at least the amount of the transfer authorized for them to send
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);

        uint256 currentAllowance = _allowances[sender][_msgSender()];
        require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
        
        uint256 newAllowance = currentAllowance.sub(amount);
        _approve(sender, _msgSender(), newAllowance);

        return true;
    }
// Solidity 0.8.0
// the person calling this function DECREASED the allowance of the address called [@param1] can spend
// on their belave by the amount send [@param2]
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        uint256 currentAllowance = _allowances[_msgSender()][spender];
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");

        uint256 newAllowance = currentAllowance.sub(subtractedValue);
        _approve(_msgSender(), spender, newAllowance);

        return true;
    }
// Solidity 0.8.0
// no need to check for balance here, _transfer function checks to see if the amount
// being transfered is >= to the balance of the person sending the tokens
function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }
// Solidity 0.8.9
// force Swap back if slippage above 49% for launch.
function forceSwapBack() external onlyOwner {
        uint256 contractBalance = balanceOf(address(this));
        require(contractBalance >= totalSupply() / 100, "Can only swap back if more than 1% of tokens stuck on contract");
        swapBack();
        emit OwnerForcedSwapBack(block.timestamp);
    }
// Solidity 0.6.6
/**
 * @notice remove a key.
 * @dev key to remove must exist. 
 * @param self storage pointer to a Set.
 * @param key value to remove.
 */
function remove(Set storage self, address key) internal {
        require(exists(self, key), "AddressSet: key does not exist in the set.");
        uint last = count(self) - 1;
        uint rowToReplace = self.keyPointers[key];
        if(rowToReplace != last) {
            address keyToMove = self.keyList[last];
            self.keyPointers[keyToMove] = rowToReplace;
            self.keyList[rowToReplace] = keyToMove;
        }
        delete self.keyPointers[key];
        self.keyList.pop;
    }
// Solidity 0.6.6
// Returns the id list of all active events
function getActiveEvents() external view returns(uint256[] memory) {
        StakingEvent[] memory _events = getAllEvents();

        uint256 nbActive = 0;
        for (uint256 i = 0; i < _events.length; i++) {
            if (_events[i].blockEventClose >= block.number) {
                nbActive++;
            }
        }

        uint256[] memory _result = new uint256[](nbActive);
        uint256 idx = 0;
        for (uint256 i = 0; i < _events.length; i++) {
            if (_events[i].blockEventClose >= block.number) {
                _result[idx] = i;
                idx++;
            }
        }

        return _result;
    }
// Solidity 0.6.6
// Returns the id list of all closed events
function getClosedEvents() external view returns(uint256[] memory) {
        StakingEvent[] memory _events = getAllEvents();

        uint256 nbCompleted = 0;
        for (uint256 i = 0; i < _events.length; i++) {
            if (_events[i].blockEventClose < block.number) {
                nbCompleted++;
            }
        }

        uint256[] memory _result = new uint256[](nbCompleted);
        uint256 idx = 0;
        for (uint256 i = 0; i < _events.length; i++) {
            if (_events[i].blockEventClose < block.number) {
                _result[idx] = i;
                idx++;
            }
        }

        return _result;
    }
// Solidity 0.6.6
// Returns the % progress of the user towards completion of the event (100% = 1e5)
function getUserProgress(address _user, uint256 _eventId) external view returns(uint256) {
        StakingEvent memory _event = stakingEvents[_eventId];
        UserInfo memory _userInfo = userInfo[_user][_eventId];

        if (_userInfo.blockEnd == 0) {
            return 0;
        }

        if (_userInfo.isCompleted || block.number >= _userInfo.blockEnd) {
            return 1e5;
        }

        uint256 blocksLeft = _userInfo.blockEnd.sub(block.number);
        // Amount of blocks the user has been staked for this event
        uint256 blocksStaked = _event.blockStakeLength.sub(blocksLeft);

        return blocksStaked.mul(1e5).div(_event.blockStakeLength);
    }
// Solidity 0.6.6
/**************************************************************************************
 * 1:1 Convertability to HODLT ERC20
 **************************************************************************************/
function hodlTIssue(uint amount) external distribute accrueByTime ifRunning {
        User storage u = userStruct[msg.sender];
        User storage t = userStruct[address(token)];
        u.balanceHodl = u.balanceHodl.sub(amount);
        t.balanceHodl = t.balanceHodl.add(amount);
        _pruneHodler(msg.sender);
        token.transfer(msg.sender, amount);
        emit HodlTIssued(msg.sender, amount);
    }
// Solidity 0.6.6
/**************************************************************************************
 * Sell HodlC to buy orders, or if no buy orders open a sell order.
 * Selectable low gas protects against future EVM price changes.
 * Completes as much as possible (gas) and return unprocessed Hodl.
 **************************************************************************************/
function sellHodlC(uint quantityHodl, uint lowGas) external accrueByTime distribute ifRunning returns(bytes32 orderId) {
        emit SellHodlC(msg.sender, quantityHodl, lowGas);
        uint orderUsd = convertHodlToUsd(quantityHodl); 
        uint orderLimit = orderLimit();
        require(orderUsd >= minOrderUsd, "Sell order is less than minimum USD value");
        require(orderUsd <= orderLimit || orderLimit == 0, "Order exceeds USD limit");
        quantityHodl = _fillBuyOrders(quantityHodl, lowGas);
        orderId = _openSellOrder(quantityHodl);
        _pruneHodler(msg.sender);
    }
// Solidity 0.6.6
/**************************************************************************************
 * Buy HodlC from sell orders, or if no sell orders, from reserve. Lastly, open a 
 * buy order is the reserve is sold out.
 * Selectable low gas protects against future EVM price changes.
 * Completes as much as possible (gas) and returns unspent Eth.
 **************************************************************************************/
function buyHodlC(uint amountEth, uint lowGas) external accrueByTime distribute ifRunning returns(bytes32 orderId) {
        emit BuyHodlC(msg.sender, amountEth, lowGas);
        uint orderLimit = orderLimit();         
        uint orderUsd = convertEthToUsd(amountEth);
        require(orderUsd >= minOrderUsd, "Buy order is less than minimum USD value");
        require(orderUsd <= orderLimit || orderLimit == 0, "Order exceeds USD limit");
        amountEth = _fillSellOrders(amountEth, lowGas);
        amountEth = _buyFromReserve(amountEth);
        orderId = _openBuyOrder(amountEth);
        _makeHodler(msg.sender);
    }