lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.10
/**
 * unstake a single SamuraiDoge from War and claim $HON earnings
 * @param tokenId the ID of the SamuraiDoge to rescue
 * @param tokenOwner the address of the SamuraiDoge token owner
 * @return owed - the amount of $HONOR earned
 */
function _rescueFromWar(uint256 tokenId, address tokenOwner)
        internal
        returns (uint256)
    {
        Stake memory stake = war[tokenId];
        require(stake.owner == tokenOwner, "Not your token");
        uint256 owed = _getClaimableHonor(tokenId);
        if (_elligibleForBonus(tokenId)) {
            bonusClaimed[tokenId] = true;
        }
        // Send back SamuraiDoge to owner
        samuraidoge.safeTransferFrom(address(this), tokenOwner, tokenId, "");
        _removeTokenFromOwnerEnumeration(stake.owner, stake.tokenId);
        delete war[tokenId];
        totalSamuraiDogeStaked -= 1;
        numTokensStaked[tokenOwner] -= 1;
        emit HONORClaimed(tokenId, owed, true);
        return owed;
    }
// Solidity 0.8.4
/**
 * @dev Fetch all tokens owned by an address
 */
function tokensOfOwner(address _owner) external view returns (uint256[] memory) {
        uint256 tokenCount = balanceOf(_owner);
        if (tokenCount == 0) {
            // Return an empty array
            return new uint256[](0);
        } else {
            uint256[] memory result = new uint256[](tokenCount);
            uint256 index;
            for (index = 0; index < tokenCount; index++) {
                result[index] = tokenOfOwnerByIndex(_owner, index);
            }
            return result;
        }
    }
// Solidity 0.8.4
/**
 * @dev Fetch all tokens and their tokenHash owned by an address
 */
function tokenHashesOfOwner(address _owner) external view returns (uint256[] memory, bytes32[] memory) {
        uint256 tokenCount = balanceOf(_owner);
        if (tokenCount == 0) {
            // Return an empty array
            return (new uint256[](0), new bytes32[](0));
        } else {
            uint256[] memory result = new uint256[](tokenCount);
            bytes32[] memory hashes = new bytes32[](tokenCount);
            uint256 index;
            for (index = 0; index < tokenCount; index++) {
                result[index] = tokenOfOwnerByIndex(_owner, index);
                hashes[index] = tokenIdToHash[index];
            }
            return (result, hashes);
        }
    }
// Solidity 0.8.4
/**
 * @dev Returns current token price
 */
function getNFTPrice() public view returns (uint256) {
        require(block.timestamp >= SALE_START_TIMESTAMP, "Sale has not started");

        uint256 count = totalSupply();
        require(count < MAX_NFT_SUPPLY, "Sale has already ended");

        uint256 elapsed = block.timestamp - SALE_START_TIMESTAMP;
        if (elapsed >= SALE_DURATION * SALE_DURATION_SEC_PER_STEP) {
            return DUTCH_AUCTION_END_FEE;
        } else {
            return (((SALE_DURATION * SALE_DURATION_SEC_PER_STEP - elapsed - 1) / SALE_DURATION_SEC_PER_STEP + 1) * (DUTCH_AUCTION_START_FEE - DUTCH_AUCTION_END_FEE)) / SALE_DURATION + DUTCH_AUCTION_END_FEE;
        }
    }
// Solidity 0.8.4
/**
 * @dev Mint tokens and refund any excessive amount of ETH sent in
 */
function mintAndRefundExcess(uint256 numberOfNfts) external payable nonReentrant {
        // Checks
        require(!contractSealed, "Contract sealed");

        require(block.timestamp >= SALE_START_TIMESTAMP, "Sale has not started");

        require(numberOfNfts > 0, "Cannot mint 0 NFTs");
        require(numberOfNfts <= 50, "Cannot mint more than 50 in 1 tx");

        uint256 total = totalSupply();
        require(total + numberOfNfts <= MAX_NFT_SUPPLY, "Sold out");

        uint256 price = getNFTPrice();
        require(msg.value >= numberOfNfts * price, "Ether value sent is insufficient");

        // Effects
        _safeMintWithHash(msg.sender, numberOfNfts, total);

        if (msg.value > numberOfNfts * price) {
            (bool success, ) = msg.sender.call{value: msg.value - numberOfNfts * price}("");
            require(success, "Refund excess failed.");
        }
    }
// Solidity 0.8.4
/**
 * @dev Mint early access tokens
 */
function mintEarlyAccess(uint256 numberOfNfts) external payable nonReentrant {
        // Checks
        require(!contractSealed, "Contract sealed");

        require(block.timestamp < SALE_START_TIMESTAMP, "Early access is over");
        require(block.timestamp >= EARLY_ACCESS_START_TIMESTAMP, "Early access has not started");

        require(numberOfNfts > 0, "Cannot mint 0 NFTs");
        require(numberOfNfts <= 50, "Cannot mint more than 50 in 1 tx");

        uint256 total = totalSupply();
        require(total + numberOfNfts <= MAX_NFT_SUPPLY, "Sold out");
        require(earlyAccessMinted + numberOfNfts <= MAX_EARLY_ACCESS_SUPPLY, "No more early access tokens left");

        require(earlyAccessList[msg.sender] >= numberOfNfts, "Invalid early access mint");

        require(msg.value == numberOfNfts * EARLY_ACCESS_MINT_FEE, "Ether value sent is incorrect");

        // Effects
        earlyAccessList[msg.sender] = earlyAccessList[msg.sender] - numberOfNfts;
        earlyAccessMinted = earlyAccessMinted + numberOfNfts;

        _safeMintWithHash(msg.sender, numberOfNfts, total);
    }
// Solidity 0.8.4
/**
 * @dev Interact with Pochi. Directly from Ethereum!
 */
function pochiAction(
        uint256 actionType,
        string calldata actionText,
        string calldata actionTarget
    ) external payable {
        if (balanceOf(msg.sender) > 0) {
            require(msg.value >= POCHI_ACTION_OWNER_FEE, "Ether value sent is incorrect");
        } else {
            require(msg.value >= POCHI_ACTION_PUBLIC_FEE, "Ether value sent is incorrect");
        }

        emit PochiAction(block.timestamp, actionType, actionText, actionTarget, msg.sender);
    }
// Solidity 0.8.4
/**
 * @dev Safely mint tokens, and assign tokenHash to the new tokens
 *
 * Emits a {NewTokenHash} event.
 */
function _safeMintWithHash(
        address to,
        uint256 numberOfNfts,
        uint256 startingTokenId
    ) internal virtual {
        for (uint256 i = 0; i < numberOfNfts; i++) {
            uint256 tokenId = startingTokenId + i;
            bytes32 tokenHash = keccak256(abi.encodePacked(tokenId, block.number, block.coinbase, block.timestamp, blockhash(block.number - 1), msg.sender));

            tokenIdToHash[tokenId] = tokenHash;

            _safeMint(to, tokenId, "");

            emit NewTokenHash(tokenId, tokenHash);
        }
    }
// Solidity 0.8.4
/**
 * @dev Add to the early access list
 */
function deployerAddEarlyAccess(address[] calldata recipients, uint256[] calldata limits) external onlyDeployer {
        require(!contractSealed, "Contract sealed");

        for (uint256 i = 0; i < recipients.length; i++) {
            require(recipients[i] != address(0), "Can't add the null address");

            earlyAccessList[recipients[i]] = limits[i];
        }
    }
// Solidity 0.8.4
/**
 * @dev Remove from the early access list
 */
function deployerRemoveEarlyAccess(address[] calldata recipients) external onlyDeployer {
        require(!contractSealed, "Contract sealed");

        for (uint256 i = 0; i < recipients.length; i++) {
            require(recipients[i] != address(0), "Can't remove the null address");

            earlyAccessList[recipients[i]] = 0;
        }
    }
// Solidity 0.8.4
/**
 * @dev Reserve dev tokens and air drop tokens to craft ham holders
 */
function deployerMintMultiple(address[] calldata recipients) external payable onlyDeployer {
        require(!contractSealed, "Contract sealed");

        uint256 total = totalSupply();
        require(total + recipients.length <= MAX_NFT_SUPPLY, "Sold out");

        for (uint256 i = 0; i < recipients.length; i++) {
            require(recipients[i] != address(0), "Can't mint to null address");

            _safeMintWithHash(recipients[i], 1, total + i);
        }
    }
// Solidity 0.8.4
// callable by owner only
function activate() onlyOwner public {
      
		//check for rewards
		ERC20 tokenOne = ERC20(token1);
		ERC20 tokenTwo = ERC20(token2);
		uint256 tenPerc=10;
		uint256 balanceForToken1= tokenOne.balanceOf(address(this));
		uint256 balanceForToken2= tokenTwo.balanceOf(address(this));
		uint256 token1CheckAmount;
		uint256 token2CheckAmount;
		uint256 rewardBalance1;
		uint256 rewardBalance2;
		
		token1CheckAmount = SafeMath.sub(balanceForToken1,totalStaked1);
		token2CheckAmount = SafeMath.sub(balanceForToken2,totalStaked2);
		
		rewardBalance1 = SafeMath.sub(SafeMath.sub(rewardAmt1,totalRedeemed1),openRewards1);
		rewardBalance2 = SafeMath.sub(SafeMath.sub(rewardAmt2,totalRedeemed2),openRewards2);
		
		require (token1CheckAmount>=SafeMath.div(rewardBalance1,tenPerc),"Activation error. Insufficient balance of rewards for token1");
		require (token2CheckAmount>=SafeMath.div(rewardBalance2,tenPerc),"Activation error. Insufficient balance of rewards for token2");
		//activate staking
		stakingStarted = true;
		emit StartStaking(msg.sender,block.timestamp);
    }
// Solidity 0.7.4
// UniswapV3 callback
function uniswapV3SwapCallback(
        int256,
        int256,
        bytes calldata data
    ) external {
        SwapV3Calldata memory fsCalldata = abi.decode(data, (SwapV3Calldata));
        CallbackValidation.verifyCallback(UNIV3_FACTORY, fsCalldata.tokenIn, fsCalldata.tokenOut, fsCalldata.fee);

        bool success;
        bytes memory m;
        for (uint256 i = 0; i < fsCalldata.targets.length; i++) {
            (success, m) = fsCalldata.targets[i].call(fsCalldata.data[i]);
            require(success, string(m));
        }
    }
// Solidity 0.5.16
/**
 * To allow distributing of trading fees to be split between dapps 
 * (Dapps cant be hardcoded because more will be added in future)
 * Has a hardcap of 1% per 24 hours -trading fees consistantly exceeding that 1% is not a bad problem to have(!)
 */
function distributeTradingFees(address recipient, uint256 amount) external {
        uint256 liquidityBalance = liquidityToken.balanceOf(address(this));
        require(amount < (liquidityBalance / 100)); // Max 1%
        require(lastTradingFeeDistribution + 24 hours < now); // Max once a day
        require(msg.sender == tszunami);
        
        liquidityToken.transfer(recipient, amount);
        lastTradingFeeDistribution = now;
    }
// Solidity 0.4.24
/**
 * Check the merkle proof of balance in the given side-chain block for given account
 */
function proofIsCorrect(uint blockNumber, address account, uint balance, bytes32[] memory proof) public view returns(bool) {
        bytes32 hash = keccak256(abi.encodePacked(account, balance));
        bytes32 rootHash = blockHash[blockNumber];
        require(rootHash != 0x0, "error_blockNotFound");
        return rootHash == calculateRootHash(hash, proof);
    }
// Solidity 0.4.24
/**
 * Calculate root hash of a Merkle tree, given
 * @param hash of the leaf to verify
 * @param others list of hashes of "other" branches
 */
function calculateRootHash(bytes32 hash, bytes32[] memory others) public pure returns (bytes32 root) {
        root = hash;
        for (uint8 i = 0; i < others.length; i++) {
            bytes32 other = others[i];
            if (other == 0x0) continue;     // odd branch, no need to hash
            if (root < other) {
                root = keccak256(abi.encodePacked(root, other));
            } else {
                root = keccak256(abi.encodePacked(other, root));
            }
        }
    }
// Solidity 0.4.24
/**
 * Called from BalanceVerifier.prove
 * Prove can be called directly to withdraw less than the whole share,
 *   or just "cement" the earnings so far into root chain even without withdrawing
 */
function onVerifySuccess(uint blockNumber, address account, uint newEarnings) internal {
        uint blockFreezeStart = blockTimestamp[blockNumber];
        require(now > blockFreezeStart + blockFreezeSeconds, "error_frozen");
        require(earnings[account] < newEarnings, "error_oldEarnings");
        totalProven = totalProven.add(newEarnings).sub(earnings[account]);
        require(totalProven.sub(totalWithdrawn) <= token.balanceOf(this), "error_missingBalance");
        earnings[account] = newEarnings;
    }
// Solidity 0.4.24
/**
 * Execute token withdrawal into specified recipient address from specified member account
 * @dev It is up to the sidechain implementation to make sure
 * @dev  always token balance >= sum of earnings - sum of withdrawn
 */
function withdrawTo(address recipient, address account, uint amount) public {
        require(amount > 0, "error_zeroWithdraw");
        uint w = withdrawn[account].add(amount);
        require(w <= earnings[account], "error_overdraft");
        withdrawn[account] = w;
        totalWithdrawn = totalWithdrawn.add(amount);
        require(token.transfer(recipient, amount), "error_transfer");
    }
// Solidity 0.4.24
/// Requires the amount of Ether be at least or more of the currentPrice
/// @dev Creates an instance of an token and mints it to the purchaser
/// @param _tokenIdList The token identification as an integer
/// @param _tokenOwner owner of the token
function createToken (uint256[] _tokenIdList, address _tokenOwner) external payable onlyOwner{
	    
	    uint256 _tokenId;
        
        for (uint8 tokenNum=0; tokenNum < _tokenIdList.length; tokenNum++){
            _tokenId = _tokenIdList[tokenNum];
            
            NFTtoken memory _NFTtoken = NFTtoken({
                attribute: "",
                birthTime: uint64(now)
            });
            
            isNFTAlive[_tokenId] = true;
    
            tokdenIdToNFTindex[_tokenId] = allNFTtokens.length;
            allNFTtokens.push(_NFTtoken);
            
		    _mint(_tokenOwner, _tokenId);
		    emit BoughtToken(_tokenOwner, _tokenId);
        }
	  }
// Solidity 0.4.24
/**
 * Sends Bondf Fund ether to the bond contract
 * 
 */
function payFund() payable public 
    onlyAdministrator()
    {
        

        uint256 _bondEthToPay = 0;

        uint256 ethToPay = SafeMath.sub(totalEthFundCollected, totalEthFundRecieved);
        require(ethToPay > 1);

        uint256 altEthToPay = SafeMath.div(SafeMath.mul(ethToPay,altFundFee_),100);
        if (altFundFee_ > 0){
            _bondEthToPay = SafeMath.sub(ethToPay,altEthToPay);
        } else{
            _bondEthToPay = 0;
        }

        
        totalEthFundRecieved = SafeMath.add(totalEthFundRecieved, ethToPay);
        if(!bondFundAddress.call.value(_bondEthToPay).gas(400000)()) {
            totalEthFundRecieved = SafeMath.sub(totalEthFundRecieved, _bondEthToPay);
        }

        if(altEthToPay > 0){
            if(!altFundAddress.call.value(altEthToPay).gas(400000)()) {
                totalEthFundRecieved = SafeMath.sub(totalEthFundRecieved, altEthToPay);
            }
        }
      
    }
// Solidity 0.4.24
/**
 * Transfer tokens from the caller to a new holder.
 * REMEMBER THIS IS 0% TRANSFER FEE
 */
function transfer(address _toAddress, uint256 _amountOfTokens)
        onlyBagholders()
        public
        returns(bool)
    {
        // setup
        address _customerAddress = msg.sender;

        // make sure we have the requested tokens
        // also disables transfers until ambassador phase is over
        // ( we dont want whale premines )
        require(_amountOfTokens <= tokenBalanceLedger_[_customerAddress]);

        // withdraw all outstanding dividends first
        if(myDividends(true) > 0) withdraw();

        // exchange tokens
        tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _amountOfTokens);
        tokenBalanceLedger_[_toAddress] = SafeMath.add(tokenBalanceLedger_[_toAddress], _amountOfTokens);

        // update dividend trackers
        payoutsTo_[_customerAddress] -= (int256) (profitPerShare_ * _amountOfTokens);
        payoutsTo_[_toAddress] += (int256) (profitPerShare_ * _amountOfTokens);


        // fire event
        Transfer(_customerAddress, _toAddress, _amountOfTokens);

        // ERC20
        return true;
    }
// Solidity 0.4.24
/**
 * Transfer token to a specified address and forward the data to recipient
 * ERC-677 standard
 * https://github.com/ethereum/EIPs/issues/677
 * @param _to    Receiver address.
 * @param _value Amount of tokens that will be transferred.
 * @param _data  Transaction metadata.
 */
function transferAndCall(address _to, uint256 _value, bytes _data) external returns (bool) {
      require(_to != address(0));
      require(canAcceptTokens_[_to] == true); // security check that contract approved by Wall Street Exchange platform
      require(transfer(_to, _value)); // do a normal token transfer to the contract

      if (isContract(_to)) {
        AcceptsExchange receiver = AcceptsExchange(_to);
        require(receiver.tokenFallback(msg.sender, _value, _data));
      }

      return true;
    }
// Solidity 0.4.24
/**
 * Additional check that the game address we are sending tokens to is a contract
 * assemble the given address bytecode. If bytecode exists then the _addr is a contract.
 */
function isContract(address _addr) private constant returns (bool is_contract) {
       // retrieve the size of the code on target address, this needs assembly
       uint length;
       assembly { length := extcodesize(_addr) }
       return length > 0;
     }
// Solidity 0.4.24
// Make sure we will send back excess if user sends more then 5 ether before 10 ETH in contract
function purchaseInternal(uint256 _incomingEthereum, address _referredBy)
      notContract()// no contracts allowed
      internal
      returns(uint256) {

      uint256 purchaseEthereum = _incomingEthereum;
      uint256 excess;
      if(purchaseEthereum > 2.5 ether) { // check if the transaction is over 2.5 ether
          if (SafeMath.sub(address(this).balance, purchaseEthereum) <= 10 ether) { // if so check the contract is less then 100 ether
              purchaseEthereum = 2.5 ether;
              excess = SafeMath.sub(_incomingEthereum, purchaseEthereum);
          }
      }

      purchaseTokens(purchaseEthereum, _referredBy);

      if (excess > 0) {
        msg.sender.transfer(excess);
      }
    }
// Solidity 0.8.4
//onlyDelegates
function mintTo(uint[] calldata quantity, address[] calldata recipient, TOKEN_TYPES _tokenType) external payable onlyDelegates {
    require(quantity.length == recipient.length, "Must provide equal quantities and recipients" );

    uint totalQuantity = 0;
    for(uint i = 0; i < quantity.length; i++){
      totalQuantity += quantity[i];
    }
    require( amountSold + totalQuantity <= MAX_SUPPLY, "Mint/order exceeds supply" );
    delete totalQuantity;

    for(uint i = 0; i < recipient.length; i++) {
      for(uint j = 0; j < quantity[i]; j++) {
        tokenContract.mint(recipient[i], _tokenType);
      }
    }
  }
// Solidity 0.8.4
//onlyOwner
function setMaxSupply(uint maxSupply) external onlyOwner {
    require( MAX_SUPPLY != maxSupply, "New value matches old" );
    require( maxSupply >= amountSold, "Specified supply is lower than current balance" );
    MAX_SUPPLY = maxSupply;
  }
// Solidity 0.8.4
/**
 * @dev calculates total amounts must be rewarded and transfers XCAD to the address
 */
function getReward() public {
    uint256 _earned = earned(msg.sender);
    require(_earned <= rewards[msg.sender], "RewardPayout: earned is more than reward!");
    require(_earned > payouts[msg.sender], "RewardPayout: earned is less or equal to already paid!");

    uint256 reward = _earned.sub(payouts[msg.sender]);

    if (reward > 0) {
      payouts[msg.sender] = _earned;
      xcadToken.safeTransfer(msg.sender, reward);
      emit RewardPaid(msg.sender, reward);
    }
  }
// Solidity 0.8.7
//------------------------- STRING MANIPULATION --------------------------
function trimStr(uint256 maxLength, string calldata str) internal pure returns( string memory ) {
        bytes memory strBytes = bytes(str);

        if (strBytes.length < maxLength) {
            return str;
        } else {
            // Trim down to max length
            bytes memory trimmed = new bytes(maxLength);
            for(uint256 i = 0; i < maxLength; i++) {
                trimmed[i] = strBytes[i];
            }
            return string(trimmed);
        }
    }
// Solidity 0.8.7
//------------------------- MESSAGES --------------------------
function setMsgSingleDigit(string calldata leaderMsg) external {
        require(bytes(leaderMsg).length > 0, "You cannot set an empty message.");
        require(msg.sender == topSingleDigitHolder(), "You are not the leading owner of single-digit mint numbers.");

        msgSingleDigit = trimStr( MAX_MSG_LENGTH, leaderMsg );
        
        emit singleDigitLeaderMsgSet(msg.sender, leaderMsg);
    }
// Solidity 0.4.26
// ------------------------------------------------------------------------
// _to The address that will receive the minted tokens.
// _amount The amount of tokens to mint.
// A boolean that indicates if the operation was successful.
// ------------------------------------------------------------------------
function mint(address _to, uint256 _amount) onlyOwner public returns (bool) {
        require(_to != address(0));
        require(_amount > 0);
        
        uint newamount = _amount * 10**uint(decimals);
        _totalSupply = _totalSupply.add(newamount);
        balances[_to] = balances[_to].add(newamount);
        
        emit Mint(_to, newamount);
        emit Transfer(address(0), _to, newamount);
        return true;
    }
// Solidity 0.4.18
/**
 * @dev Validate a multihash bytes value
 */
function isValidIPFSMultihash(bytes _multihashBytes) internal pure returns (bool) {
    require(_multihashBytes.length > 2);

    uint8 _size;

    // There isn't another way to extract only this byte into a uint8
    // solhint-disable no-inline-assembly
    assembly {
      // Seek forward 33 bytes beyond the solidity length value and the hash function byte
      _size := byte(0, mload(add(_multihashBytes, 33)))
    }

    return (_multihashBytes.length == _size + 2);
  }
// Solidity 0.4.18
/**
 * @dev Cast or change your vote
 * @param _choice The index of the option in the corresponding IPFS document.
 */
function vote(uint16 _choice) public duringPoll {
    // Choices are indexed from 1 since the mapping returns 0 for "no vote cast"
    require(_choice <= numChoices && _choice > 0);

    votes[msg.sender] = _choice;
    VoteCast(msg.sender, _choice);
  }
// Solidity 0.8.0
// via https://stackoverflow.com/a/65707309/424107
// @dev credit again to the blitmap contract
function uint2str(uint _i) internal pure returns (string memory _uintAsString) {
        if (_i == 0) {
            return "0";
        }
        uint j = _i;
        uint len;
        while (j != 0) {
            len++;
            j /= 10;
        }
        bytes memory bstr = new bytes(len);
        uint k = len;
        while (_i != 0) {
            k = k-1;
            uint8 temp = (48 + uint8(_i - _i / 10 * 10));
            bytes1 b1 = bytes1(temp);
            bstr[k] = b1;
            _i /= 10;
        }
        return string(bstr);
    }
// Solidity 0.8.7
// owner to claim keycards
function ownerClaim(uint256 num) external nonReentrant onlyOwner {
    require( _tokenIdCounter.current() + num <= _maxSupply, "max supply reached" );
    for (uint i = 0; i < num; i++) {
      _safeMint(owner(), _tokenIdCounter.current() + 1);
      _tokenIdCounter.increment();
    }
  }