lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.1
/**
 * @dev For a given ENS Node ID, return the value associated with a given text key.
 * If the key is "avatar", and the matching value is not explicitly set, a url pointing to the MoonCat's image is returned
 * EIP634 functionality
 */
function text(bytes32 nodeID, string calldata key) public view returns (string memory) {
        uint256 rescueOrder = getRescueOrderFromNodeId(nodeID);

        string memory value = TextKeyMapping[rescueOrder][key];
        if (bytes(value).length > 0) {
            // This value has been set explicitly; return that
            return value;
        }

        // Check if there's a default value for this key
        bytes memory keyBytes = bytes(key);
        if (keyBytes.length == avatarKeyLength && keccak256(keyBytes) == avatarKeyHash){
            // Avatar default
            return string(abi.encodePacked(avatarBaseURI,  uint2str(rescueOrder)));
        }

        // No default; just return the empty string
        return value;
    }
// Solidity 0.8.1
/**
 * @dev Update a text record for subdomains owned by a specific MoonCat rescue order.
 */
function setText(uint256 rescueOrder, string calldata key, string calldata value) public onlyMoonCatOwner(rescueOrder) {
        bytes memory keyBytes = bytes(key);
        bytes32 orderHash = getSubdomainNameHash(uint2str(rescueOrder));
        bytes32 hexHash = getSubdomainNameHash(bytes5ToHexString(MCR.rescueOrder(rescueOrder)));

        if (bytes(value).length == 0 && keyBytes.length == avatarKeyLength && keccak256(keyBytes) == avatarKeyHash){
            // Avatar default
            string memory avatarRecordValue = string(abi.encodePacked(avatarBaseURI,  uint2str(rescueOrder)));
            emit TextChanged(orderHash, key, avatarRecordValue);
            emit TextChanged(hexHash, key, avatarRecordValue);
        } else {
            emit TextChanged(orderHash, key, value);
            emit TextChanged(hexHash, key, value);
        }
        TextKeyMapping[rescueOrder][key] = value;
    }
// Solidity 0.8.1
/**
 * @dev Allow calling multiple functions on this contract in one transaction.
 */
function multicall(bytes[] calldata data) external returns(bytes[] memory results) {
        results = new bytes[](data.length);
        for (uint i = 0; i < data.length; i++) {
            (bool success, bytes memory result) = address(this).delegatecall(data[i]);
            require(success);
            results[i] = result;
        }
        return results;
    }
// Solidity 0.8.1
/**
 * @dev Reverse lookup for ENS Node ID, to determine the MoonCat rescue order of the MoonCat associated with it.
 */
function getRescueOrderFromNodeId(bytes32 nodeID) public view returns (uint256) {
        uint256 rescueOrder = NamehashMapping[nodeID];
        if (rescueOrder == 0) {
            // Are we actually dealing with MoonCat #0?
            require(
                nodeID == 0x8bde039a2a7841d31e0561fad9d5cfdfd4394902507c72856cf5950eaf9e7d5a // 0.ismymooncat.eth
                || nodeID == 0x1002474938c26fb23080c33c3db026c584b30ec6e7d3edf4717f3e01e627da26, // 0x00d658d50b.ismymooncat.eth
                "Unknown Node ID"
            );
        }
        return rescueOrder;
    }
// Solidity 0.8.1
/**
 * @dev Cache a single MoonCat's (identified by Rescue Order) subdomain hashes.
 */
function mapMoonCat(uint256 rescueOrder) public {
        string memory orderSubdomain = uint2str(rescueOrder);
        string memory hexSubdomain = bytes5ToHexString(MCR.rescueOrder(rescueOrder));

        bytes32 orderHash = getSubdomainNameHash(orderSubdomain);
        bytes32 hexHash = getSubdomainNameHash(hexSubdomain);

        if (uint256(NamehashMapping[orderHash]) != 0) {
            // Already Mapped
            return;
        }

        NamehashMapping[orderHash] = rescueOrder;
        NamehashMapping[hexHash] = rescueOrder;

        if(MCR.catOwners(MCR.rescueOrder(rescueOrder)) != address(MCA)) {
            // MoonCat is not Acclimated
            return;
        }

        IRegistry registry = IRegistry(0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e);
        registry.setSubnodeRecord(rootHash, keccak256(bytes(orderSubdomain)), address(this), address(this), defaultTTL);
        registry.setSubnodeRecord(rootHash, keccak256(bytes(hexSubdomain)), address(this), address(this), defaultTTL);

        address moonCatOwner = MCA.ownerOf(rescueOrder);
        lastAnnouncedAddress[rescueOrder] = moonCatOwner;
        emit AddrChanged(orderHash, moonCatOwner);
        emit AddrChanged(hexHash, moonCatOwner);
        emit AddressChanged(orderHash, 60, abi.encodePacked(moonCatOwner));
        emit AddressChanged(hexHash, 60, abi.encodePacked(moonCatOwner));

        string memory avatarRecordValue = string(abi.encodePacked(avatarBaseURI,  uint2str(rescueOrder)));
        emit TextChanged(orderHash, "avatar", avatarRecordValue);
        emit TextChanged(hexHash, "avatar", avatarRecordValue);
    }
// Solidity 0.8.0
/**
 * @dev Helper function to reduce pixel size within contract
 */
function letterToNumber(string memory _inputLetter, string[] memory LETTERS)
        public
        pure
        returns (uint8)
    {
        for (uint8 i = 0; i < LETTERS.length; i++) {
            if (
                keccak256(abi.encodePacked((LETTERS[i]))) ==
                keccak256(abi.encodePacked((_inputLetter)))
            ) return (i + 1);
        }
        revert();
    }
// Solidity 0.8.1
/**
 * @dev Announce a single MoonCat's (identified by Rescue Order) assigned address.
 */
function announceMoonCat(uint256 rescueOrder) public {
        require(MCR.catOwners(MCR.rescueOrder(rescueOrder)) == address(MCA), "Not Acclimated");
        address moonCatOwner = MCA.ownerOf(rescueOrder);

        lastAnnouncedAddress[rescueOrder] = moonCatOwner;
        bytes32 orderHash = getSubdomainNameHash(uint2str(rescueOrder));
        bytes32 hexHash = getSubdomainNameHash(bytes5ToHexString(MCR.rescueOrder(rescueOrder)));

        emit AddrChanged(orderHash, moonCatOwner);
        emit AddrChanged(hexHash, moonCatOwner);
        emit AddressChanged(orderHash, 60, abi.encodePacked(moonCatOwner));
        emit AddressChanged(hexHash, 60, abi.encodePacked(moonCatOwner));
    }
// Solidity 0.8.1
/**
 * @dev Convenience function to iterate through all MoonCats owned by an address to check if they need announcing.
 */
function needsAnnouncing(address moonCatOwner) public view returns (uint256[] memory) {
        uint256 balance = MCA.balanceOf(moonCatOwner);
        uint256 announceCount = 0;
        uint256[] memory tempRescueOrders = new uint256[](balance);
        for (uint256 i = 0; i < balance; i++) {
            uint256 rescueOrder = MCA.tokenOfOwnerByIndex(moonCatOwner, i);
            if (lastAnnouncedAddress[rescueOrder] != moonCatOwner){
                tempRescueOrders[announceCount] = rescueOrder;
                announceCount++;
            }
        }
        uint256[] memory rescueOrders = new uint256[](announceCount);
        for (uint256 i = 0; i < announceCount; i++){
            rescueOrders[i] = tempRescueOrders[i];
        }
        return rescueOrders;
    }
// Solidity 0.8.1
/**
 * @dev Set a manual list of MoonCats (identified by Rescue Order) to announce or cache their subdomain hashes.
 */
function mapMoonCats(uint256[] memory rescueOrders) public {
        for (uint256 i = 0; i < rescueOrders.length; i++) {
            address lastAnnounced = lastAnnouncedAddress[rescueOrders[i]];
            if (lastAnnounced == address(0)){
                mapMoonCat(rescueOrders[i]);
            } else if (lastAnnounced != MCA.ownerOf(rescueOrders[i])){
                announceMoonCat(rescueOrders[i]);
            }
        }
    }
// Solidity 0.8.1
/**
 * @dev Convenience function to iterate through all MoonCats owned by an address and announce or cache their subdomain hashes.
 */
function mapMoonCats(address moonCatOwner) public {
        for (uint256 i = 0; i < MCA.balanceOf(moonCatOwner); i++) {
            uint256 rescueOrder = MCA.tokenOfOwnerByIndex(moonCatOwner, i);
            address lastAnnounced = lastAnnouncedAddress[rescueOrder];
            if (lastAnnounced == address(0)){
                mapMoonCat(rescueOrder);
            } else if (lastAnnounced != moonCatOwner){
                announceMoonCat(rescueOrder);
            }
        }
    }
// Solidity 0.8.1
/**
 * @dev Utility function to convert a uint256 variable into a decimal string.
 */
function uint2str(uint value) internal pure returns (string memory) {
        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }
// Solidity 0.8.0
/**
 * @dev Mint internal, this is to avoid code duplication.
 */
function mintInternal(address _account, string memory _hash) internal {
        uint256 rand = _rand();

        uint256 _totalSupply = totalSupply();        
       
        uint256 thisTokenId = _totalSupply;

        tokenIdToHash[thisTokenId] = _hash;

        hashToMinted[tokenIdToHash[thisTokenId]] = true;

        // QUESTS 

        (uint8 health,uint8 accuracy,uint8 defense) = (0,0,0);
        
        {

            // Helpers to get Percentages
            uint256 eightyPct     = type(uint16).max / 100 * 80;
            uint256 nineFivePct   = type(uint16).max / 100 * 95;

            // Getting Random traits
            uint16 randHelm = uint16(_randomize(rand, "HEALTH", thisTokenId));
                    health     = uint8(randHelm < eightyPct ? 0 : randHelm % 4 + 5);

            uint16 randOffhand = uint16(_randomize(rand, "ACCURACY", thisTokenId));
                    defense     = uint8(randOffhand < eightyPct ? 0 : randOffhand % 4 + 5);

            uint16 randMainhand = uint16(_randomize(rand, "DEFENSE", thisTokenId));
                    accuracy     = uint8(randMainhand < nineFivePct ? randMainhand % 4 + 1: randMainhand % 4 + 5);
        }

        _mint(_account, thisTokenId);

        uint16 meowModifier = ZombieCatsLibrary._tier(health) + ZombieCatsLibrary._tier(accuracy) + ZombieCatsLibrary._tier(defense);
        zombiekatz[uint256(thisTokenId)] = ZombieKat({health: health, accuracy: accuracy, defense: defense, level: 0, lvlProgress: 0, meowModifier:meowModifier});
    }
// Solidity 0.8.0
/**
 * @dev Mints a zombie. Only the Graveyard contract can call this function.
 */
function mintZombie(address _account, string memory _hash) public {
        require(msg.sender == graveyardAddress);

        // In the Graveyard contract, the Katz head stored in the hash in position 1 
        // while the character in the ZombieKatz contract is stored in position 8        
        // so we swap the traits. 

        // We let the graveyard contract to mint whatever is the total supply, just in case 
        // to avoid a situation of zombies stucked in a grave, since you need to claim your zombie
        // before unstake a grave digging zombie. 
                
        mintInternal(_account, 
            string(
                abi.encodePacked(
                    "0",                                       // not burnt
                    ZombieCatsLibrary.substring(_hash, 8, 9),  // grave 
                    ZombieCatsLibrary.substring(_hash, 2, 8),  // rest
                    ZombieCatsLibrary.substring(_hash, 1, 2)   // hand
                )
            )
        );        
    }
// Solidity 0.8.0
/**
 * @dev Mutates a zombie.
 * @param _tokenId The token to burn.
 */
function mutateZombie(uint256 _tokenId) public ownerOfZombieKat(_tokenId) noCheaters {
        // require(ownerOf(_tokenId) == msg.sender
        // //, "You must own this zombie to mutate"
        // );

        IMiece(mieceAddress).burnFrom(msg.sender, 30 ether);

        tokenIdToHash[_tokenId] =  mutatedHash(_tokenIdToHash(_tokenId), _tokenId, msg.sender, 0); 
        
        hashToMinted[tokenIdToHash[_tokenId]] = true;

    }
// Solidity 0.4.25
/// @dev Constructor: takes list of parties and their slices.
/// @param addresses List of addresses of the parties
/// @param slices Slices of the parties. Will be added to totalSlices.
function PaymentSplitter(address[] addresses, uint[] slices) public {
    require(addresses.length == slices.length, "addresses and slices must be equal length.");
    require(addresses.length > 0 && addresses.length < MAX_PARTIES, "Amount of parties is either too many, or zero.");

    for(uint i=0; i<addresses.length; i++) {
      parties.push(Party(addresses[i], slices[i]));
      totalSlices = totalSlices.add(slices[i]);
    }
  }
// Solidity 0.4.24
/**
 * @dev Confirm that airDrop is available.
 * @return A bool to confirm that airDrop is available.
 */
function isValidAirDropForAll() public view returns (bool) {
        bool validNotStop = !stop;
        bool validAmount = getRemainingToken() >= airDropAmount;
        bool validPeriod = now >= startTime && now <= endTime;
        return validNotStop && validAmount && validPeriod;
    }
// Solidity 0.4.24
/**
 * @dev Do the airDrop to msg.sender
 */
function receiveAirDrop() public {
        require(isValidAirDropForIndividual());

        // set invalidAirDrop of msg.sender to true
        invalidAirDrop[msg.sender] = true;

        // set msg.sender to the array of the airDropReceiver
        arrayAirDropReceivers.push(msg.sender);

        // execute transfer
        erc20.transfer(msg.sender, airDropAmount);

        emit LogAirDrop(msg.sender, airDropAmount);
    }
// Solidity 0.4.24
/**
 * @dev Update the information regarding to period and amount.
 * @param _startTime The start time this airdrop starts.
 * @param _endTime The end time this sirdrop ends.
 * @param _airDropAmount The airDrop Amount that user can get via airdrop.
 */
function updateInfo(uint256 _startTime, uint256 _endTime, uint256 _airDropAmount) public onlyOwner {
        require(stop || now > endTime);
        require(
            _startTime >= now &&
            _endTime >= _startTime &&
            _airDropAmount > 0
        );

        startTime = _startTime;
        endTime = _endTime;
        uint tokenDecimals = erc20.decimals();
        airDropAmount = _airDropAmount.mul(10 ** tokenDecimals);

        emit LogInfoUpdate(startTime, endTime, airDropAmount);
    }
// Solidity 0.8.0
// needs div /10
function getDigitWidth(uint256 tokenId) public pure returns (uint16) {
        require(tokenId >= 0 && tokenId <= 9, "Token Id invalid");

        if (tokenId == 0)
            return 2863;
    
        if (tokenId == 1)
            return 1944;
            
        if (tokenId == 2)
            return 2491;
            
        if (tokenId == 3)
            return 2503;
            
        if (tokenId == 4)
            return 2842;
            
        if (tokenId == 5)
            return 2502;
            
        if (tokenId == 6)
            return 2667;
            
        if (tokenId == 7)
            return 2638;
            
        if (tokenId == 8)
            return 2591;
            
        if (tokenId == 9)
            return 2661;
            
        return 0;
    }
// Solidity 0.5.15
/**
 * Return the ethereum received on selling 1 individual token.
 * We are not deducting the penalty over here as it's a general sell price
 * the user can use the `calculateEthereumReceived` to get the sell price specific to them
 */
function sellPrice() public view returns (uint256) {
        if (tokenSupply_ == 0) {
            return tokenPriceInitial_ - tokenPriceIncremental_;
        } else {
            uint256 _ethereum = tokensToEthereum_(1e18);
            uint256 _dividends = SafeMath.div(_ethereum, dividendFee_);
            uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
            return _taxedEthereum;
        }
    }
// Solidity 0.5.15
/**
 * Return the ethereum required for buying 1 individual token.
 */
function buyPrice() public view returns (uint256) {
        if (tokenSupply_ == 0) {
            return tokenPriceInitial_ + tokenPriceIncremental_;
        } else {
            uint256 _ethereum = tokensToEthereum_(1e18);
            uint256 _taxedEthereum =
                mulDiv(_ethereum, dividendFee_, (dividendFee_ - 1));
            return _taxedEthereum;
        }
    }
// Solidity 0.5.15
/**
 * Calculate the early exit penalty for selling x tokens
 */
function calculateAveragePenalty(
        uint256 _amountOfTokens,
        address _customerAddress
    ) public view onlyBagholders() returns (uint256) {
        require(_amountOfTokens <= tokenBalanceLedger_[_customerAddress]);

        uint256 tokensFound = 0;
        Cursor storage _customerCursor =
            tokenTimestampedBalanceCursor[_customerAddress];
        uint256 counter = _customerCursor.start;
        uint256 averagePenalty = 0;

        while (counter <= _customerCursor.end) {
            TimestampedBalance storage transaction =
                tokenTimestampedBalanceLedger_[_customerAddress][counter];
            uint256 tokensAvailable =
                SafeMath.sub(transaction.value, transaction.valueSold);

            uint256 tokensRequired = SafeMath.sub(_amountOfTokens, tokensFound);

            if (tokensAvailable < tokensRequired) {
                tokensFound += tokensAvailable;
                averagePenalty = SafeMath.add(
                    averagePenalty,
                    SafeMath.mul(
                        _calculatePenalty(transaction.timestamp),
                        tokensAvailable
                    )
                );
            } else if (tokensAvailable <= tokensRequired) {
                averagePenalty = SafeMath.add(
                    averagePenalty,
                    SafeMath.mul(
                        _calculatePenalty(transaction.timestamp),
                        tokensRequired
                    )
                );
                break;
            } else {
                averagePenalty = SafeMath.add(
                    averagePenalty,
                    SafeMath.mul(
                        _calculatePenalty(transaction.timestamp),
                        tokensRequired
                    )
                );
                break;
            }

            counter = SafeMath.add(counter, 1);
        }
        return SafeMath.div(averagePenalty, _amountOfTokens);
    }
// Solidity 0.5.15
/**
 * Calculate the early exit penalty for selling after x days
 */
function _calculatePenalty(uint256 timestamp)
        public
        view
        returns (uint256)
    {
        uint256 gap = block.timestamp - timestamp;

        if (gap > 30 days) {
            return 0;
        } else if (gap > 20 days) {
            return 25;
        } else if (gap > 10 days) {
            return 50;
        }
        return 75;
    }
// Solidity 0.5.15
/**
 * Calculate Token price based on an amount of incoming ethereum
 * Some conversions occurred to prevent decimal errors or underflows / overflows in solidity code.
 */
function ethereumToTokens_(uint256 _ethereum)
        public
        view
        returns (uint256)
    {
        uint256 _tokenPriceInitial = tokenPriceInitial_ * 1e18;
        uint256 _tokensReceived =
            ((
                SafeMath.sub(
                    (
                        sqrt(
                            (_tokenPriceInitial**2) +
                                (2 *
                                    (tokenPriceIncremental_ * 1e18) *
                                    (_ethereum * 1e18)) +
                                (((tokenPriceIncremental_)**2) *
                                    (tokenSupply_**2)) +
                                (2 *
                                    (tokenPriceIncremental_) *
                                    _tokenPriceInitial *
                                    tokenSupply_)
                        )
                    ),
                    _tokenPriceInitial
                )
            ) / (tokenPriceIncremental_)) - (tokenSupply_);

        return _tokensReceived;
    }
// Solidity 0.5.15
/**
 * Calculate token sell value.
 * Some conversions occurred to prevent decimal errors or underflows / overflows in solidity code.
 */
function tokensToEthereum_(uint256 _tokens) public view returns (uint256) {
        uint256 tokens_ = (_tokens + 1e18);
        uint256 _tokenSupply = (tokenSupply_ + 1e18);
        uint256 _ethereumReceived =
            (SafeMath.sub(
                (((tokenPriceInitial_ +
                    (tokenPriceIncremental_ * (_tokenSupply / 1e18))) -
                    tokenPriceIncremental_) * (tokens_ - 1e18)),
                (tokenPriceIncremental_ * ((tokens_**2 - tokens_) / 1e18)) / 2
            ) / 1e18);

        return _ethereumReceived;
    }
// Solidity 0.5.15
/**
 * Update ledger after transferring x tokens
 */
function _updateLedgerForTransfer(
        uint256 _amountOfTokens,
        address _customerAddress
    ) internal {
        // Parse through the list of transactions
        uint256 tokensFound = 0;
        Cursor storage _customerCursor =
            tokenTimestampedBalanceCursor[_customerAddress];
        uint256 counter = _customerCursor.start;

        while (counter <= _customerCursor.end) {
            TimestampedBalance storage transaction =
                tokenTimestampedBalanceLedger_[_customerAddress][counter];
            uint256 tokensAvailable =
                SafeMath.sub(transaction.value, transaction.valueSold);

            uint256 tokensRequired = SafeMath.sub(_amountOfTokens, tokensFound);

            if (tokensAvailable < tokensRequired) {
                tokensFound += tokensAvailable;

                delete tokenTimestampedBalanceLedger_[_customerAddress][
                    counter
                ];
            } else if (tokensAvailable <= tokensRequired) {
                delete tokenTimestampedBalanceLedger_[_customerAddress][
                    counter
                ];
                _customerCursor.start = counter + 1;
                break;
            } else {
                transaction.valueSold += tokensRequired;
                _customerCursor.start = counter;
                break;
            }
            counter += 1;
        }
    }