Contract Address Details

0x5eA9Eb73E006c38bc30C7Aa715F0ED30Bd28c704

Contract Name
Web3Entry
Creator
0xe01c8d–e085f7 at 0x202cd6–557616
Balance
0 CSB
Tokens
Fetching tokens...
Transactions
1 Transactions
Transfers
0 Transfers
Gas Used
160,807
Last Balance Update
81784283
Contract name:
Web3Entry




Optimization enabled
true
Compiler version
v0.8.18+commit.87f61d96




Optimization runs
200
Verified at
2023-08-25T03:04:20.727154Z

contracts/Web3Entry.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;

import {Web3EntryBase} from "./Web3EntryBase.sol";

// solhint-disable-next-line no-empty-blocks
contract Web3Entry is Web3EntryBase {

}
        

@openzeppelin/contracts/utils/Strings.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/Math.sol";
import "./math/SignedMath.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toString(int256 value) internal pure returns (string memory) {
        return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return keccak256(bytes(a)) == keccak256(bytes(b));
    }
}
          

@openzeppelin/contracts/utils/Context.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}
          

contracts/interfaces/IMintModule4Note.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;

interface IMintModule4Note {
    /**
     * @notice  Initialize the MintModule for a specific note.
     * @param   characterId  The character ID of the note to initialize.
     * @param   noteId  The note ID to initialize.
     * @param   data  The data passed from the user to be decoded.
     * @return  bytes  The returned data of calling initializeMintModule.
     */
    function initializeMintModule(
        uint256 characterId,
        uint256 noteId,
        bytes calldata data
    ) external returns (bytes memory);

    /**
     * @notice Processes the mint logic. <br>
     * Triggered when the `mintNote` of web3Entry is called, if mint module of note is set.
     * @param   to  The receive address of the NFT.
     * @param   characterId  The character ID of the note owner.
     * @param   noteId  The note ID.
     * @param   data  The data passed from the user to be decoded.
     */
    function processMint(
        address to,
        uint256 characterId,
        uint256 noteId,
        bytes calldata data
    ) external;
}
          

contracts/libraries/OperatorLogic.sol

// SPDX-License-Identifier: MIT
// solhint-disable private-vars-leading-underscore
pragma solidity 0.8.18;

import {Events} from "./Events.sol";
import {DataTypes} from "./DataTypes.sol";
import {OP} from "./OP.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

library OperatorLogic {
    using EnumerableSet for EnumerableSet.AddressSet;

    /**
     * @notice  Grants permission to a given operator for a character.
     * @param   characterId  The ID of the character to set operator for.
     * @param   operator  The operator address to set.
     * @param   permissionBitMap  The permission bitmap for the operator.
     */
    function grantOperatorPermissions(
        uint256 characterId,
        address operator,
        uint256 permissionBitMap,
        mapping(uint256 => EnumerableSet.AddressSet) storage _operatorsByCharacter,
        mapping(uint256 => mapping(address => uint256)) storage _operatorsPermissionBitMap
    ) external {
        if (permissionBitMap == 0) {
            _operatorsByCharacter[characterId].remove(operator);
        } else {
            _operatorsByCharacter[characterId].add(operator);
        }

        uint256 bitmap = _bitmapFilter(permissionBitMap);
        _operatorsPermissionBitMap[characterId][operator] = bitmap;
        emit Events.GrantOperatorPermissions(characterId, operator, bitmap);
    }

    /**
     @notice Sets blocklist and allowlist for a specific note. Blocklist and allowlist are overwritten every time.
     @param characterId The character ID of the note owner.
     @param noteId The note ID to grant.
     @param blocklist The addresses list of blocked operators.
     @param allowlist The addresses list of allowed operators.
     */
    function grantOperators4Note(
        uint256 characterId,
        uint256 noteId,
        address[] calldata blocklist,
        address[] calldata allowlist,
        mapping(uint256 => mapping(uint256 => DataTypes.Operators4Note)) storage _operators4Note
    ) external {
        DataTypes.Operators4Note storage operators4Note = _operators4Note[characterId][noteId];
        // clear all iterms in blocklist and allowlist first
        _clearOperators4Note(operators4Note);

        // update blocklist and allowlist
        _updateOperators4Note(operators4Note, blocklist, allowlist);

        emit Events.GrantOperators4Note(characterId, noteId, blocklist, allowlist);
    }

    function _clearOperators4Note(DataTypes.Operators4Note storage operators4Note) internal {
        uint256 blocklistLength = operators4Note.blocklist.length();
        for (uint256 i = blocklistLength; i > 0; ) {
            operators4Note.blocklist.remove(operators4Note.blocklist.at(i - 1));
            unchecked {
                i--;
            }
        }

        uint256 allowlistLength = operators4Note.allowlist.length();
        for (uint256 i = allowlistLength; i > 0; ) {
            operators4Note.allowlist.remove(operators4Note.allowlist.at(i - 1));
            unchecked {
                i--;
            }
        }
    }

    function _updateOperators4Note(
        DataTypes.Operators4Note storage operators4Note,
        address[] calldata blocklist,
        address[] calldata allowlist
    ) internal {
        // grant blocklist roles
        for (uint256 i = 0; i < blocklist.length; ) {
            operators4Note.blocklist.add(blocklist[i]);
            unchecked {
                i++;
            }
        }
        for (uint256 i = 0; i < allowlist.length; ) {
            operators4Note.allowlist.add(allowlist[i]);
            unchecked {
                i++;
            }
        }
    }

    /**
     * @dev _bitmapFilter unsets bits of non-existent permission IDs to zero. <br>
     * These unset permission IDs are meaningless now, but they are reserved for future use,
     * so it's best to leave them blank and avoid messing up with future methods.
     */
    function _bitmapFilter(uint256 bitmap) internal pure returns (uint256) {
        return bitmap & OP.ALLOWED_PERMISSION_BITMAP_MASK;
    }
}
          

contracts/interfaces/IMintNFT.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

interface IMintNFT {
    /**
     * @notice Initialize the mint nft.
     * @param characterId_  The character ID of the note to initialize.
     * @param noteId_  The note ID to initialize.
     * @param web3Entry_  The address of web3Entry contract.
     * @param name_ The name to set for this NFT.
     * @param symbol_ The symbol to set for this NFT.
     */
    function initialize(
        uint256 characterId_,
        uint256 noteId_,
        address web3Entry_,
        string calldata name_,
        string calldata symbol_
    ) external;

    /**
     * @notice Mints a note NFT to the specified address.
     * This can only be called by web3Entry, and is called upon note.
     * @param to The address to mint the NFT to.
     * @return uint256 The minted token ID.
     */
    function mint(address to) external returns (uint256);

    /**
     * @notice Changes the royalty percentage of specific token ID for secondary sales.
     * Can only be called by character owner of note.
     * @param tokenId The token ID to set.
     * @param recipient The receive address.
     * @param fraction The royalty percentage measured in basis points. Each basis point represents 0.01%.
     */
    function setTokenRoyalty(uint256 tokenId, address recipient, uint96 fraction) external;

    /**
     * @notice Changes the default royalty percentage for secondary sales.
     * Can only be called by character owner of note.
     * @param recipient The receive address.
     * @param fraction The royalty percentage measured in basis points. Each basis point represents 0.01%.
     */
    function setDefaultRoyalty(address recipient, uint96 fraction) external;

    /**
     * @notice Deletes the default royalty percentage.
     * Can only be called by character owner of note.
     */
    function deleteDefaultRoyalty() external;

    /**
     * @notice Returns the original receiver of specified NFT.
     * @return The address of original receiver.
     */
    function originalReceiver(uint256 tokenId) external view returns (address);

    /**
     * @notice Returns the source note pointer mapped to this note NFT.
     * @return characterId The character ID.
     * @return noteId The note ID.
     */
    function getSourceNotePointer() external view returns (uint256 characterId, uint256 noteId);
}
          

@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Metadata is IERC721 {
    /**
     * @dev Returns the token collection name.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the token collection symbol.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);
}
          

contracts/interfaces/ILinklist.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;

import {DataTypes} from "../libraries/DataTypes.sol";

interface ILinklist {
    /**
     * @notice Initializes the contract.
     * @param name_ The name of the token.
     * @param symbol_ The symbol of the token.
     * @param web3Entry_ The address of the Web3Entry contract.
     */
    function initialize(
        string calldata name_,
        string calldata symbol_,
        address web3Entry_
    ) external;

    /**
     * @notice Mints a Linklist NFT to the specified character with linkType.
     * This can only be called by web3Entry.
     * @param characterId The character ID to mint to.
     * @param linkType  The type of link.
     * @return tokenId The minted token ID.
     */
    function mint(uint256 characterId, bytes32 linkType) external returns (uint256 tokenId);

    /**
     * @notice Burns a Linklist NFT.
     * @dev Only web3Entry can burn the Linklist NFT.
     * @param tokenId The token ID to burn.
     */
    function burn(uint256 tokenId) external;

    /**
     * @notice Sets URI for a linklist.
     * @dev You can set any URI for your linklist, and the functionality of this URI
     * is undetermined and expandable. One scenario that comes to mind is setting a cover for your liked notes
     * or following list in your bookmarks.
     * @param tokenId The token ID to set URI.
     * @param uri The new URI to set.
     */
    function setUri(uint256 tokenId, string memory uri) external;

    /**
     * @notice Sets the link type of the linklist NFT.
     * @param tokenId The token ID of linklist to set.
     * @param linkType The link type to set.
     */
    function setLinkType(uint256 tokenId, bytes32 linkType) external;

    /////////////////////////////////
    // linking Character
    /////////////////////////////////
    /**
     * @notice Adds a linked character to a linklist.
     * @param tokenId The token ID of linklist.
     * @param toCharacterId The character ID to link.
     */
    function addLinkingCharacterId(uint256 tokenId, uint256 toCharacterId) external;

    /**
     * @notice Removes a linked character from a linklist.
     * @param tokenId The token ID of linklist.
     * @param toCharacterId The character ID to remove.
     */
    function removeLinkingCharacterId(uint256 tokenId, uint256 toCharacterId) external;

    /////////////////////////////////
    // linking Note
    /////////////////////////////////
    /**
     * @notice Adds a linked note to a linklist.
     * @param tokenId The token ID of linklist.
     * @param toCharacterId The character ID to link.
     * @param toNoteId The note ID to link.
     * @return linkKey The link key.
     */
    function addLinkingNote(
        uint256 tokenId,
        uint256 toCharacterId,
        uint256 toNoteId
    ) external returns (bytes32);

    /**
     * @notice Removes a linked note from a linklist.
     * @param tokenId The token ID of linklist.
     * @param toCharacterId The character ID to remove.
     * @param toNoteId The note ID to remove.
     */
    function removeLinkingNote(uint256 tokenId, uint256 toCharacterId, uint256 toNoteId) external;

    /////////////////////////////////
    // linking ERC721
    /////////////////////////////////
    /**
     * @notice Adds a linked ERC721 to a linklist.
     * @param tokenId The token ID of linklist.
     * @param tokenAddress The address of ERC721 contract.
     * @param erc721TokenId The token ID of ERC721.
     * @return linkKey The link key of ERC721.
     */
    function addLinkingERC721(
        uint256 tokenId,
        address tokenAddress,
        uint256 erc721TokenId
    ) external returns (bytes32);

    /**
     * @notice Removes a linked ERC721 from a linklist.
     * @param tokenId The token ID of linklist.
     * @param tokenAddress The address of ERC721 contract.
     * @param erc721TokenId The token ID of ERC721.
     */
    function removeLinkingERC721(
        uint256 tokenId,
        address tokenAddress,
        uint256 erc721TokenId
    ) external;

    /////////////////////////////////
    // linking Address
    /////////////////////////////////
    /**
     * @notice Adds a linked address to a linklist.
     * @param tokenId The token ID of linklist.
     * @param ethAddress The address to link.
     */
    function addLinkingAddress(uint256 tokenId, address ethAddress) external;

    /**
     * @notice Removes a linked address from a linklist.
     * @param tokenId The token ID of linklist.
     * @param ethAddress The address to remove.
     */
    function removeLinkingAddress(uint256 tokenId, address ethAddress) external;

    /////////////////////////////////
    // linking Any
    /////////////////////////////////
    /**
     * @notice Adds a linked anyURI to a linklist.
     * @param tokenId The token ID of linklist.
     * @param toUri The anyURI to link.
     * @return linkKey The link key of anyURI.
     */
    function addLinkingAnyUri(uint256 tokenId, string memory toUri) external returns (bytes32);

    /**
     * @notice Removes a linked anyURI from a linklist.
     * @param tokenId The token ID of linklist.
     * @param toUri The anyURI to remove.
     */
    function removeLinkingAnyUri(uint256 tokenId, string memory toUri) external;

    /////////////////////////////////
    // linking Linklist
    /////////////////////////////////
    /**
     * @notice Adds a linked linklist to a linklist.
     * @param tokenId The token ID of linklist.
     * @param linklistId The linklist ID to link.
     */
    function addLinkingLinklistId(uint256 tokenId, uint256 linklistId) external;

    /**
     * @notice Removes a linked linklist from a linklist.
     * @param tokenId The token ID of linklist.
     * @param linklistId The linklist ID to remove.
     */
    function removeLinkingLinklistId(uint256 tokenId, uint256 linklistId) external;

    /**
     * @notice Returns the linked character IDs of the linklist NFT.
     * @param tokenId The token ID of linklist to check.
     * @return The linked character IDs.
     */
    function getLinkingCharacterIds(uint256 tokenId) external view returns (uint256[] memory);

    /**
     * @notice Returns the length of linked character IDs of the linklist NFT.
     * @param tokenId The token ID of linklist to check.
     * @return The length of linked character IDs .
     */
    function getLinkingCharacterListLength(uint256 tokenId) external view returns (uint256);

    /**
     * @notice Returns the character ID who owns the linklist NFT.
     * @param tokenId The token ID of linklist to check.
     * @return The character ID who owns the linklist NFT.
     */
    function getOwnerCharacterId(uint256 tokenId) external view returns (uint256);

    /**
     * @notice Returns the linked notes of the linklist NFT.
     * @param tokenId The token ID of linklist to check.
     * @return results The linked notes.
     */
    function getLinkingNotes(
        uint256 tokenId
    ) external view returns (DataTypes.NoteStruct[] memory results);

    /**
     * @notice Return the linked note of the linklist NFT by linkKey.
     * @param linkKey The link key of the note.
     * @return The linked note.
     */
    function getLinkingNote(bytes32 linkKey) external view returns (DataTypes.NoteStruct memory);

    /**
     * @notice Returns the length of linked notes of the linklist NFT.
     * @param tokenId The token ID of linklist to check.
     * @return The length of linked notes.
     */
    function getLinkingNoteListLength(uint256 tokenId) external view returns (uint256);

    /**
     * @notice Returns the linked ERC721s of the linklist NFT.
     * @param tokenId The token ID of linklist to check.
     * @return results The linked ERC721s.
     */
    function getLinkingERC721s(
        uint256 tokenId
    ) external view returns (DataTypes.ERC721Struct[] memory results);

    /**
     * @notice Return the linked ERC721 of the linklist NFT by linkKey.
     * @param linkKey The link key of the ERC721.
     * @return The linked ERC721.
     */
    function getLinkingERC721(
        bytes32 linkKey
    ) external view returns (DataTypes.ERC721Struct memory);

    /**
     * @notice Returns the length of linked ERC721s of the linklist NFT.
     * @param tokenId The token ID of linklist to check.
     * @return The length of linked ERC721s.
     */
    function getLinkingERC721ListLength(uint256 tokenId) external view returns (uint256);

    /**
     * @notice Returns the linked addresses of the linklist NFT.
     * @param tokenId The token ID of linklist to check.
     * @return The linked addresses.
     */
    function getLinkingAddresses(uint256 tokenId) external view returns (address[] memory);

    /**
     * @notice Returns the linked address of the linklist NFT by linkKey.
     * @param tokenId The token ID of linklist to check.
     * @return  The length of linked address.
     */
    function getLinkingAddressListLength(uint256 tokenId) external view returns (uint256);

    /**
     * @notice Returns the linked anyURIs of the linklist NFT.
     * @param tokenId The token ID of linklist to check.
     * @return results The linked anyURIs.
     */
    function getLinkingAnyUris(uint256 tokenId) external view returns (string[] memory results);

    /**
     * @notice Return the linked anyURI of the linklist NFT by linkKey.
     * @param linkKey The link key of the anyURI.
     * @return The linked anyURI.
     */
    function getLinkingAnyUri(bytes32 linkKey) external view returns (string memory);

    /**
     * @notice Returns the length of linked anyURIs of the linklist NFT.
     * @param tokenId The token ID of linklist to check.
     * @return The length of linked anyURIs.
     */
    function getLinkingAnyUriKeys(uint256 tokenId) external view returns (bytes32[] memory);

    /**
     * @notice Returns the length of linked Uris of the linklist NFT.
     * @param tokenId The token ID of linklist to check.
     * @return The length of linked Uris.
     */
    function getLinkingAnyListLength(uint256 tokenId) external view returns (uint256);

    /**
     * @notice Returns the linked linklists of the linklist NFT.
     * @param tokenId The token ID of linklist to check.
     * @return The linked linklists.
     */
    function getLinkingLinklistIds(uint256 tokenId) external view returns (uint256[] memory);

    /**
     * @notice Return the length of linked linklist of the linklist NFT.
     * @param tokenId The token ID of linklist to check.
     * @return The length of linked linklist.
     */
    function getLinkingLinklistLength(uint256 tokenId) external view returns (uint256);

    /**
     * @dev This function is deprecated..
     */
    function getCurrentTakeOver(uint256 tokenId) external view returns (uint256);

    /**
     * @notice Returns the link type of the linklist NFT.
     * @param tokenId The token ID of linklist to check.
     * @return The link type.
     */
    function getLinkType(uint256 tokenId) external view returns (bytes32);

    /**
     * @notice Returns the URI of the linklist NFT.
     * @param tokenId The token ID of linklist to check.
     * @return The URI of the linklist NFT.
     */
    // slither-disable-next-line naming-convention
    function Uri(uint256 tokenId) external view returns (string memory); // solhint-disable func-name-mixedcase

    /**
     * @notice Returns the character ID who owns the Linklist NFT.
     * @param tokenId The token ID to check.
     * @return The character ID.
     */
    function characterOwnerOf(uint256 tokenId) external view returns (uint256);

    /**
     * @notice Returns the balance of the character.
     * @param characterId The character ID to check.
     * @return The balance of the character.
     */
    function balanceOf(uint256 characterId) external view returns (uint256);

    /**
     * @notice Returns the total supply of the Linklist NFTs.
     * @return The total supply of the Linklist NFTs.
     */
    function totalSupply() external view returns (uint256);
}
          

contracts/libraries/PostLogic.sol

// SPDX-License-Identifier: MIT
// solhint-disable private-vars-leading-underscore
pragma solidity 0.8.18;

import {DataTypes} from "./DataTypes.sol";
import {Events} from "./Events.sol";
import {ILinkModule4Note} from "../interfaces/ILinkModule4Note.sol";
import {IMintModule4Note} from "../interfaces/IMintModule4Note.sol";
import {IMintNFT} from "../interfaces/IMintNFT.sol";
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

library PostLogic {
    using Strings for uint256;

    function postNoteWithLink(
        DataTypes.PostNoteData calldata vars,
        uint256 noteId,
        bytes32 linkItemType,
        bytes32 linkKey,
        bytes calldata data,
        mapping(uint256 => mapping(uint256 => DataTypes.Note)) storage _noteByIdByCharacter
    ) external {
        uint256 characterId = vars.characterId;
        DataTypes.Note storage note = _noteByIdByCharacter[characterId][noteId];

        // save note
        note.contentUri = vars.contentUri;
        if (linkItemType != bytes32(0)) {
            note.linkItemType = linkItemType;
            note.linkKey = linkKey;
        }

        // init link module
        _setLinkModule4Note(
            characterId,
            noteId,
            vars.linkModule,
            vars.linkModuleInitData,
            _noteByIdByCharacter
        );

        // init mint module
        _setMintModule4Note(
            characterId,
            noteId,
            vars.mintModule,
            vars.mintModuleInitData,
            _noteByIdByCharacter
        );

        emit Events.PostNote(characterId, noteId, linkKey, linkItemType, data);
    }

    function mintNote(
        uint256 characterId,
        uint256 noteId,
        address to,
        bytes calldata mintModuleData,
        address mintNFTImpl,
        mapping(uint256 => mapping(uint256 => DataTypes.Note)) storage _noteByIdByCharacter
    ) external returns (uint256 tokenId) {
        DataTypes.Note storage note = _noteByIdByCharacter[characterId][noteId];
        address mintNFT = note.mintNFT;
        if (mintNFT == address(0)) {
            mintNFT = _deployMintNFT(characterId, noteId, mintNFTImpl);
            note.mintNFT = mintNFT;
        }

        // mint nft
        tokenId = IMintNFT(mintNFT).mint(to);

        address mintModule = note.mintModule;
        if (mintModule != address(0)) {
            IMintModule4Note(mintModule).processMint(to, characterId, noteId, mintModuleData);
        }

        emit Events.MintNote(to, characterId, noteId, mintNFT, tokenId);
    }

    function setNoteUri(
        uint256 characterId,
        uint256 noteId,
        string calldata newUri,
        mapping(uint256 => mapping(uint256 => DataTypes.Note)) storage _noteByIdByCharacter
    ) external {
        _noteByIdByCharacter[characterId][noteId].contentUri = newUri;

        emit Events.SetNoteUri(characterId, noteId, newUri);
    }

    /**
     * @notice  Sets link module for a given note.
     * @param   characterId  The character ID to set link module for.
     * @param   noteId  The note ID to set link module for.
     * @param   linkModule  The link module to set.
     * @param   linkModuleInitData  The data to pass to the link module for initialization, if any.
     */
    function setLinkModule4Note(
        uint256 characterId,
        uint256 noteId,
        address linkModule,
        bytes calldata linkModuleInitData,
        mapping(uint256 => mapping(uint256 => DataTypes.Note)) storage _noteByIdByCharacter
    ) external {
        _setLinkModule4Note(
            characterId,
            noteId,
            linkModule,
            linkModuleInitData,
            _noteByIdByCharacter
        );
    }

    /**
     * @notice  Sets the mint module for a given note.
     * @param   characterId  The character ID of note to set the mint module for.
     * @param   noteId  The note ID of note.
     * @param   mintModule  The mint module to set for note.
     * @param   mintModuleInitData  The data to pass to the mint module.
     */
    function setMintModule4Note(
        uint256 characterId,
        uint256 noteId,
        address mintModule,
        bytes calldata mintModuleInitData,
        mapping(uint256 => mapping(uint256 => DataTypes.Note)) storage _noteByIdByCharacter
    ) external {
        _setMintModule4Note(
            characterId,
            noteId,
            mintModule,
            mintModuleInitData,
            _noteByIdByCharacter
        );
    }

    function _deployMintNFT(
        uint256 characterId,
        uint256 noteId,
        address mintNFTImpl
    ) internal returns (address mintNFT) {
        string memory symbol = string.concat(
            "Note-",
            characterId.toString(),
            "-",
            noteId.toString()
        );

        // deploy nft contract
        mintNFT = Clones.clone(mintNFTImpl);
        // initialize nft
        IMintNFT(mintNFT).initialize(characterId, noteId, address(this), symbol, symbol);
    }

    function _setLinkModule4Note(
        uint256 characterId,
        uint256 noteId,
        address linkModule,
        bytes calldata linkModuleInitData,
        mapping(uint256 => mapping(uint256 => DataTypes.Note)) storage _noteByIdByCharacter
    ) internal {
        if (linkModule != address(0)) {
            _noteByIdByCharacter[characterId][noteId].linkModule = linkModule;

            bytes memory returnData = ILinkModule4Note(linkModule).initializeLinkModule(
                characterId,
                noteId,
                linkModuleInitData
            );

            emit Events.SetLinkModule4Note(
                characterId,
                noteId,
                linkModule,
                linkModuleInitData,
                returnData
            );
        }
    }

    function _setMintModule4Note(
        uint256 characterId,
        uint256 noteId,
        address mintModule,
        bytes calldata mintModuleInitData,
        mapping(uint256 => mapping(uint256 => DataTypes.Note)) storage _noteByIdByCharacter
    ) internal {
        if (mintModule != address(0)) {
            _noteByIdByCharacter[characterId][noteId].mintModule = mintModule;

            bytes memory returnData = IMintModule4Note(mintModule).initializeMintModule(
                characterId,
                noteId,
                mintModuleInitData
            );

            emit Events.SetMintModule4Note(
                characterId,
                noteId,
                mintModule,
                mintModuleInitData,
                returnData
            );
        }
    }
}
          

@openzeppelin/contracts/utils/cryptography/ECDSA.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.0;

import "../Strings.sol";

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS,
        InvalidSignatureV // Deprecated in v4.8
    }

    function _throwError(RecoverError error) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert("ECDSA: invalid signature");
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert("ECDSA: invalid signature length");
        } else if (error == RecoverError.InvalidSignatureS) {
            revert("ECDSA: invalid signature 's' value");
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature` or error string. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength);
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, signature);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) {
        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
        uint8 v = uint8((uint256(vs) >> 255) + 27);
        return tryRecover(hash, v, r, s);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     *
     * _Available since v4.2._
     */
    function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, r, vs);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature);
        }

        return (signer, RecoverError.NoError);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, "\x19Ethereum Signed Message:\n32")
            mstore(0x1c, hash)
            message := keccak256(0x00, 0x3c)
        }
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from `s`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
    }

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, "\x19\x01")
            mstore(add(ptr, 0x02), domainSeparator)
            mstore(add(ptr, 0x22), structHash)
            data := keccak256(ptr, 0x42)
        }
    }

    /**
     * @dev Returns an Ethereum Signed Data with intended validator, created from a
     * `validator` and `data` according to the version 0 of EIP-191.
     *
     * See {recover}.
     */
    function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x00", validator, data));
    }
}
          

@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)

pragma solidity ^0.8.0;

import "../IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Enumerable is IERC721 {
    /**
     * @dev Returns the total amount of tokens stored by the contract.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns a token ID owned by `owner` at a given `index` of its token list.
     * Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);

    /**
     * @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
     * Use along with {totalSupply} to enumerate all tokens.
     */
    function tokenByIndex(uint256 index) external view returns (uint256);
}
          

@openzeppelin/contracts/proxy/utils/Initializable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

import "../../utils/Address.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
     * constructor.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!Address.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: setting the version to 255 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized != type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint8) {
        return _initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _initializing;
    }
}
          

@openzeppelin/contracts/interfaces/IERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC165.sol)

pragma solidity ^0.8.0;

import "../utils/introspection/IERC165.sol";
          

@openzeppelin/contracts/utils/math/Math.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1, "Math: mulDiv overflow");

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
        }
    }
}
          

contracts/interfaces/ILinkModule4Note.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

interface ILinkModule4Note {
    function initializeLinkModule(
        uint256 characterId,
        uint256 noteId,
        bytes calldata data
    ) external returns (bytes memory);

    function processLink(
        address caller,
        uint256 characterId,
        uint256 noteId,
        bytes calldata data
    ) external;
}
          

@openzeppelin/contracts/token/ERC721/IERC721.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}
          

@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.0;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721Receiver {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
     *
     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}
          

@openzeppelin/contracts/utils/introspection/IERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
          

contracts/libraries/Error.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

/// @dev Character ID not exists
error ErrCharacterNotExists(uint256 characterId);

/// @dev Not owner of address
error ErrNotAddressOwner();

/// @dev Caller is not the owner of character
error ErrNotCharacterOwner();

/// @dev Note has been locked
error ErrNoteLocked();

/// @dev Handle does not exist
error ErrHandleExists();

/// @dev Social token address does not exist
error ErrSocialTokenExists();

/// @dev Handle length too long or too short
error ErrHandleLengthInvalid();

/// @dev Handle contains invalid characters
error ErrHandleContainsInvalidCharacters();

/// @dev  Operator has not enough permission for this character
error ErrNotEnoughPermission();

/// @dev Operator has not enough permissions for this note
error ErrNotEnoughPermissionForThisNote();

/// @dev Target address already has primary character
error ErrTargetAlreadyHasPrimaryCharacter();

/// @dev Note has been deleted
error ErrNoteIsDeleted();

/// @dev Note does not exist
error ErrNoteNotExists();

/// @dev Array length mismatch
error ErrArrayLengthMismatch();

/// @dev Caller is not web3Entry contract
error ErrCallerNotWeb3Entry();

/// @dev Caller is not web3Entry contract, and not the owner of character
error ErrCallerNotWeb3EntryOrNotOwner();

/// @dev Token id already exists
error ErrTokenIdAlreadyExists();

/// @dev Character does not exist
error ErrNotExistingCharacter();

/// @dev Token id of linklist does not exist
error ErrNotExistingLinklistToken();

/// @dev Invalid web3Entry address
error ErrInvalidWeb3Entry();

/// @dev Not approved by module or exceed the approval amount
error ErrNotApprovedOrExceedApproval();

/// @dev Exceed max supply
error ErrExceedMaxSupply();

/// @dev Exceed the approval amount
error ErrExceedApproval();

/// @dev Signature is expired
error ErrSignatureExpired();

/// @dev Signature is invalid
error ErrSignatureInvalid();

/// @dev Caller not owner
error ErrNotOwner();

/// @dev Token not exists
error ErrTokenNotExists();

/// @dev LinkType already exists
error ErrLinkTypeExists(uint256 characterId, bytes32 linkType);
          

contracts/base/ERC721Enumerable.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

import {
    IERC721Enumerable
} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
import {ERC721} from "./ERC721.sol";
import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol";

abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
    // Mapping from owner to list of owned token IDs
    mapping(address => mapping(uint256 => uint256)) private _ownedTokens;

    // Mapping from token ID to index of the owner tokens list
    mapping(uint256 => uint256) private _ownedTokensIndex;

    // Array with all token ids, used for enumeration
    uint256[] private _allTokens;

    // Mapping from token id to position in the allTokens array
    mapping(uint256 => uint256) private _allTokensIndex;

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(
        bytes4 interfaceId
    ) public view virtual override(IERC165, ERC721) returns (bool) {
        return
            interfaceId == type(IERC721Enumerable).interfaceId ||
            super.supportsInterface(interfaceId);
    }

    /**
     * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
     */
    function tokenOfOwnerByIndex(
        address owner,
        uint256 index
    ) public view virtual override returns (uint256) {
        require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
        return _ownedTokens[owner][index];
    }

    /**
     * @dev See {IERC721Enumerable-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _allTokens.length;
    }

    /**
     * @dev See {IERC721Enumerable-tokenByIndex}.
     */
    function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
        require(
            index < ERC721Enumerable.totalSupply(),
            "ERC721Enumerable: global index out of bounds"
        );
        return _allTokens[index];
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting
     * and burning.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
     * transferred to `to`.
     * - When `from` is zero, `tokenId` will be minted for `to`.
     * - When `to` is zero, ``from``'s `tokenId` will be burned.
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual override {
        super._beforeTokenTransfer(from, to, tokenId);

        if (from == address(0)) {
            _addTokenToAllTokensEnumeration(tokenId);
        } else if (from != to) {
            _removeTokenFromOwnerEnumeration(from, tokenId);
        }
        if (to == address(0)) {
            _removeTokenFromAllTokensEnumeration(tokenId);
        } else if (to != from) {
            _addTokenToOwnerEnumeration(to, tokenId);
        }
    }

    /**
     * @dev Private function to add a token to this extension's ownership-tracking data structures.
     * @param to address representing the new owner of the given token ID
     * @param tokenId uint256 ID of the token to be added to the tokens list of the given address
     */
    function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
        uint256 length = ERC721.balanceOf(to);
        _ownedTokens[to][length] = tokenId;
        _ownedTokensIndex[tokenId] = length;
    }

    /**
     * @dev Private function to add a token to this extension's token tracking data structures.
     * @param tokenId uint256 ID of the token to be added to the tokens list
     */
    function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
        _allTokensIndex[tokenId] = _allTokens.length;
        _allTokens.push(tokenId);
    }

    /**
     * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
     * while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
     * gas optimizations e.g. when performing a transfer operation (avoiding double writes).
     * This has O(1) time complexity, but alters the order of the _ownedTokens array.
     * @param from address representing the previous owner of the given token ID
     * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
     */
    function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
        // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
        // then delete the last slot (swap and pop).

        uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
        uint256 tokenIndex = _ownedTokensIndex[tokenId];

        // When the token to delete is the last token, the swap operation is unnecessary
        if (tokenIndex != lastTokenIndex) {
            uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];

            _ownedTokens[from][tokenIndex] = lastTokenId;
            // Move the last token to the slot of the to-delete token
            _ownedTokensIndex[lastTokenId] = tokenIndex;
            // Update the moved token's index
        }

        // This also deletes the contents at the last position of the array
        delete _ownedTokensIndex[tokenId];
        delete _ownedTokens[from][lastTokenIndex];
    }

    /**
     * @dev Private function to remove a token from this extension's token tracking data structures.
     * This has O(1) time complexity, but alters the order of the _allTokens array.
     * @param tokenId uint256 ID of the token to be removed from the tokens list
     */
    function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
        // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
        // then delete the last slot (swap and pop).

        uint256 lastTokenIndex = _allTokens.length - 1;
        uint256 tokenIndex = _allTokensIndex[tokenId];

        // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
        // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
        // an 'if' statement (like in _removeTokenFromOwnerEnumeration)
        uint256 lastTokenId = _allTokens[lastTokenIndex];

        _allTokens[tokenIndex] = lastTokenId;
        // Move the last token to the slot of the to-delete token
        _allTokensIndex[lastTokenId] = tokenIndex;
        // Update the moved token's index

        // This also deletes the contents at the last position of the array
        delete _allTokensIndex[tokenId];
        _allTokens.pop();
    }
}
          

contracts/libraries/LinkLogic.sol

// SPDX-License-Identifier: MIT
// solhint-disable  private-vars-leading-underscore
pragma solidity 0.8.18;

import {Events} from "./Events.sol";
import {ILinklist} from "../interfaces/ILinklist.sol";
import {ILinkModule4Character} from "../interfaces/ILinkModule4Character.sol";
import {ILinkModule4Note} from "../interfaces/ILinkModule4Note.sol";
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

library LinkLogic {
    using EnumerableSet for EnumerableSet.Bytes32Set;

    /**
     * @notice  Links any characterId.
     * @param   fromCharacterId  The character ID to sponsor a link action.
     * @param   toCharacterId  The character ID to be linked.
     * @param   linkType  linkType, like “follow”.
     * @param   data  The data to pass to the link module, if any.
     * @param   linklist  The linklist contract address.
     * @param   linkModule  The linkModule address of the character to link.
     */
    function linkCharacter(
        uint256 fromCharacterId,
        uint256 toCharacterId,
        bytes32 linkType,
        bytes memory data,
        address linklist,
        address linkModule,
        mapping(uint256 => mapping(bytes32 => uint256)) storage _attachedLinklists
    ) external {
        address linker = IERC721(address(this)).ownerOf(fromCharacterId);
        uint256 linklistId = _mintLinklist(fromCharacterId, linkType, linklist, _attachedLinklists);

        // add to link list
        ILinklist(linklist).addLinkingCharacterId(linklistId, toCharacterId);

        // process link module
        if (linkModule != address(0)) {
            try
                ILinkModule4Character(linkModule).processLink(linker, toCharacterId, data)
            {} catch {} // solhint-disable-line no-empty-blocks
        }

        emit Events.LinkCharacter(linker, fromCharacterId, toCharacterId, linkType, linklistId);
    }

    /**
     * @notice  Unlinks a given character.
     * @param   fromCharacterId  The character ID to sponsor a unlink action.
     * @param   toCharacterId  The character ID to be unlinked.
     * @param   linkType  linkType, like “follow”.
     * @param   linklist  The linklist contract address.
     * @param   linklistId  The ID of the linklist to unlink.
     */
    function unlinkCharacter(
        uint256 fromCharacterId,
        uint256 toCharacterId,
        bytes32 linkType,
        address linklist,
        uint256 linklistId
    ) external {
        address linker = IERC721(address(this)).ownerOf(fromCharacterId);
        // remove from link list
        ILinklist(linklist).removeLinkingCharacterId(linklistId, toCharacterId);

        emit Events.UnlinkCharacter(linker, fromCharacterId, toCharacterId, linkType);
    }

    /**
     * @notice  Links a given note.
     * @param   fromCharacterId  The character ID to sponsor a link action.
     * @param   toCharacterId  The owner characterId of the note to link.
     * @param   toNoteId  The id of the note to link.
     * @param   linkType  The linkType, like “follow”.
     * @param   data  The data to pass to the link module, if any.
     * @param   linklist  The linklist contract address.
     * @param   linkModule  The linkModule address of the note to link
     */
    function linkNote(
        uint256 fromCharacterId,
        uint256 toCharacterId,
        uint256 toNoteId,
        bytes32 linkType,
        bytes calldata data,
        address linklist,
        address linkModule,
        mapping(uint256 => mapping(bytes32 => uint256)) storage _attachedLinklists
    ) external {
        address linker = IERC721(address(this)).ownerOf(fromCharacterId);
        uint256 linklistId = _mintLinklist(fromCharacterId, linkType, linklist, _attachedLinklists);

        // add to link list
        ILinklist(linklist).addLinkingNote(linklistId, toCharacterId, toNoteId);

        // process link
        if (linkModule != address(0)) {
            try
                ILinkModule4Note(linkModule).processLink(linker, toCharacterId, toNoteId, data)
            {} catch {} // solhint-disable-line no-empty-blocks
        }

        emit Events.LinkNote(fromCharacterId, toCharacterId, toNoteId, linkType, linklistId);
    }

    /**
     * @notice  Unlinks a given note.
     * @param   fromCharacterId  The character ID to sponsor an unlink action.
     * @param   toCharacterId  The character ID of note to unlink.
     * @param   toNoteId  The id of note to unlink.
     * @param   linkType  LinkType, like “follow”.
     * @param   linklist  The linklist contract address.
     */
    function unlinkNote(
        uint256 fromCharacterId,
        uint256 toCharacterId,
        uint256 toNoteId,
        bytes32 linkType,
        address linklist,
        mapping(uint256 => mapping(bytes32 => uint256)) storage _attachedLinklists
    ) external {
        // do note check note
        // _validateNoteExists(vars.toCharacterId, vars.toNoteId);

        uint256 linklistId = _attachedLinklists[fromCharacterId][linkType];

        // remove from link list
        ILinklist(linklist).removeLinkingNote(linklistId, toCharacterId, toNoteId);

        emit Events.UnlinkNote(fromCharacterId, toCharacterId, toNoteId, linkType, linklistId);
    }

    /**
     * @notice  Links a linklist.
     * @param   fromCharacterId  The character ID to sponsor an link action.
     * @param   toLinkListId  The linklist if to link.
     * @param   linkType  LinkType, like “follow”.
     * @param   linklist  The linklist contract address.
     */
    function linkLinklist(
        uint256 fromCharacterId,
        uint256 toLinkListId,
        bytes32 linkType,
        address linklist,
        mapping(uint256 => mapping(bytes32 => uint256)) storage _attachedLinklists
    ) external {
        uint256 linklistId = _mintLinklist(fromCharacterId, linkType, linklist, _attachedLinklists);

        // add to link list
        ILinklist(linklist).addLinkingLinklistId(linklistId, toLinkListId);

        emit Events.LinkLinklist(fromCharacterId, toLinkListId, linkType, linklistId);
    }

    /**
     * @notice  Unlinks a linklist.
     * @param   fromCharacterId  The character ID to sponsor an unlink action.
     * @param   toLinkListId  The linklist if to unlink.
     * @param   linkType  LinkType, like “follow”.
     * @param   linklist  The linklist contract address.
     * @param   linklistId  The ID of the linklist to unlink.
     */
    function unlinkLinklist(
        uint256 fromCharacterId,
        uint256 toLinkListId,
        bytes32 linkType,
        address linklist,
        uint256 linklistId
    ) external {
        // add to link list
        ILinklist(linklist).removeLinkingLinklistId(linklistId, toLinkListId);

        emit Events.UnlinkLinklist(fromCharacterId, toLinkListId, linkType, linklistId);
    }

    /**
     * @notice  Links an ERC721 token.
     * @param   fromCharacterId  The character ID to sponsor an link action.
     * @param   tokenAddress  The token address of ERC721 to link.
     * @param   tokenId  The token ID of ERC721 to link.
     * @param   linkType  linkType, like “follow”.
     * @param   linklist  The linklist contract address.
     */
    function linkERC721(
        uint256 fromCharacterId,
        address tokenAddress,
        uint256 tokenId,
        bytes32 linkType,
        address linklist,
        mapping(uint256 => mapping(bytes32 => uint256)) storage _attachedLinklists
    ) external {
        uint256 linklistId = _mintLinklist(fromCharacterId, linkType, linklist, _attachedLinklists);

        // add to link list
        ILinklist(linklist).addLinkingERC721(linklistId, tokenAddress, tokenId);

        emit Events.LinkERC721(fromCharacterId, tokenAddress, tokenId, linkType, linklistId);
    }

    /**
     * @notice  Unlinks an ERC721 token.
     * @param   fromCharacterId  The character ID to sponsor an unlink action.
     * @param   tokenAddress  The token address of ERC721 to unlink.
     * @param   tokenId  The token ID of ERC721 to unlink.
     * @param   linkType  LinkType, like “follow”.
     * @param   linklist  The linklist contract address.
     * @param   linklistId  The ID of the linklist to unlink.
     */
    function unlinkERC721(
        uint256 fromCharacterId,
        address tokenAddress,
        uint256 tokenId,
        bytes32 linkType,
        address linklist,
        uint256 linklistId
    ) external {
        // remove from link list
        ILinklist(linklist).removeLinkingERC721(linklistId, tokenAddress, tokenId);

        emit Events.UnlinkERC721(fromCharacterId, tokenAddress, tokenId, linkType, linklistId);
    }

    /**
     * @notice  Creates a link to a given address.
     * @param   fromCharacterId  The character ID to init the link.
     * @param   ethAddress  The address to link.
     * @param   linkType  LinkType, like “follow”.
     * @param   linklist  The linklist contract address.
     */
    function linkAddress(
        uint256 fromCharacterId,
        address ethAddress,
        bytes32 linkType,
        address linklist,
        mapping(uint256 => mapping(bytes32 => uint256)) storage _attachedLinklists
    ) external {
        uint256 linklistId = _mintLinklist(fromCharacterId, linkType, linklist, _attachedLinklists);

        // add to link list
        ILinklist(linklist).addLinkingAddress(linklistId, ethAddress);

        emit Events.LinkAddress(fromCharacterId, ethAddress, linkType, linklistId);
    }

    /**
     * @notice  Unlinks a given address.
     * @param   fromCharacterId  The character ID to init the unlink.
     * @param   ethAddress  The address to unlink.
     * @param   linkType  LinkType, like “follow”.
     * @param   linklist  The linklist contract address.
     * @param   linklistId  The ID of the linklist to unlink.
     */
    function unlinkAddress(
        uint256 fromCharacterId,
        address ethAddress,
        bytes32 linkType,
        address linklist,
        uint256 linklistId
    ) external {
        // remove from link list
        ILinklist(linklist).removeLinkingAddress(linklistId, ethAddress);

        emit Events.UnlinkAddress(fromCharacterId, ethAddress, linkType);
    }

    /**
     * @notice  Links any uri.
     * @param   fromCharacterId  The character ID to sponsor an link action.
     * @param   toUri  The uri to link.
     * @param   linkType  LinkType, like “follow”.
     * @param   linklist  The linklist contract address.
     */
    function linkAnyUri(
        uint256 fromCharacterId,
        string calldata toUri,
        bytes32 linkType,
        address linklist,
        mapping(uint256 => mapping(bytes32 => uint256)) storage _attachedLinklists
    ) external {
        uint256 linklistId = _mintLinklist(fromCharacterId, linkType, linklist, _attachedLinklists);

        // add to link list
        ILinklist(linklist).addLinkingAnyUri(linklistId, toUri);

        emit Events.LinkAnyUri(fromCharacterId, toUri, linkType, linklistId);
    }

    /**
     * @notice  Unlinks any uri.
     * @param   fromCharacterId  The character ID to sponsor an unlink action.
     * @param   toUri  The uri to unlink.
     * @param   linkType  LinkType, like “follow”.
     * @param   linklist  The linklist contract address.
     * @param   linklistId  The ID of the linklist to unlink.
     */
    function unlinkAnyUri(
        uint256 fromCharacterId,
        string calldata toUri,
        bytes32 linkType,
        address linklist,
        uint256 linklistId
    ) external {
        // remove from link list
        ILinklist(linklist).removeLinkingAnyUri(linklistId, toUri);

        emit Events.UnlinkAnyUri(fromCharacterId, toUri, linkType);
    }

    /**
     * @notice  Returns the linklistId if the linklist already exists, Otherwise, creates a new 
        linklist and return its ID.
     */
    function _mintLinklist(
        uint256 fromCharacterId,
        bytes32 linkType,
        address linklist,
        mapping(uint256 => mapping(bytes32 => uint256)) storage _attachedLinklists
    ) internal returns (uint256 linklistId) {
        linklistId = _attachedLinklists[fromCharacterId][linkType];
        if (linklistId == 0) {
            // mint linkList nft
            linklistId = ILinklist(linklist).mint(fromCharacterId, linkType);

            // attach linkList
            _attachedLinklists[fromCharacterId][linkType] = linklistId;
            emit Events.AttachLinklist(linklistId, fromCharacterId, linkType);
        }
    }
}
          

@openzeppelin/contracts/utils/Multicall.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Multicall.sol)

pragma solidity ^0.8.0;

import "./Address.sol";

/**
 * @dev Provides a function to batch together multiple calls in a single external call.
 *
 * _Available since v4.1._
 */
abstract contract Multicall {
    /**
     * @dev Receives and executes a batch of function calls on this contract.
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function multicall(bytes[] calldata data) external virtual returns (bytes[] memory results) {
        results = new bytes[](data.length);
        for (uint256 i = 0; i < data.length; i++) {
            results[i] = Address.functionDelegateCall(address(this), data[i]);
        }
        return results;
    }
}
          

contracts/interfaces/IWeb3Entry.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

import {DataTypes} from "../libraries/DataTypes.sol";

interface IWeb3Entry {
    /**
     * @notice Initializes the Web3Entry.
     * @param name_ The name to set for the web3Entry character NFT.
     * @param symbol_ The symbol to set for the web3Entry character NFT.
     * @param linklist_ The address of linklist contract to set.
     * @param mintNFTImpl_ The address of mintNFTImpl contract to set.
     * @param periphery_ The address of periphery contract to set.
     * @param newbieVilla_ The address of newbieVilla contract to set.
     */
    function initialize(
        string calldata name_,
        string calldata symbol_,
        address linklist_,
        address mintNFTImpl_,
        address periphery_,
        address newbieVilla_
    ) external;

    /**
     * This method creates a character with the given parameters to the given address.
     *
     * @param vars The CreateCharacterData struct containing the following parameters:
     * `to`: The address receiving the character.<br>
     * `handle`: The handle to set for the character.<br>
     * `uri`: The URI to set for the character metadata.<br>
     * `linkModule`: The link module to use, can be the zero address.<br>
     * `linkModuleInitData`: The link module initialization data, if any.<br>
     */
    function createCharacter(
        DataTypes.CreateCharacterData calldata vars
    ) external returns (uint256 characterId);

    /**
     * @notice  Sets new handle for a given character.
     * @dev Owner permission only.
     * @param   characterId  The character id to set new handle for.
     * @param   newHandle  New handle to set.
     */
    function setHandle(uint256 characterId, string calldata newHandle) external;

    /**
     * @notice  Sets a social token for a given character.
     * @dev Owner permission only.
     * @param   characterId  The characterId to set social token for.
     * @param   tokenAddress  Token address to be set.
     */
    function setSocialToken(uint256 characterId, address tokenAddress) external;

    /**
     * @notice  Sets a new URI for a given character.
     * @param   characterId  The characterId to to be set.
     * @param   newUri  New URI to be set.
     */
    function setCharacterUri(uint256 characterId, string calldata newUri) external;

    /**
     * @notice  Sets a given character as primary.
     * @dev Owner permission only.
     * @param   characterId  The character id to to be set.
     */
    function setPrimaryCharacterId(uint256 characterId) external;

    /**
     * @notice Grant an address as an operator and authorize it with custom permissions.
     * @param characterId ID of your character that you want to authorize.
     * @param operator Address to grant operator permissions to.
     * @param permissionBitMap Bitmap used for finer grained operator permissions controls.
     * @dev Every bit in permissionBitMap stands for a corresponding method in Web3Entry. more details in OP.sol.
     */
    function grantOperatorPermissions(
        uint256 characterId,
        address operator,
        uint256 permissionBitMap
    ) external;

    /**
     * @notice Grant an address as an operator and authorize it with custom permissions via signature.
     * @dev Only character owner can call.
     * @param characterId ID of your character that you want to authorize.
     * @param operator Address to grant operator permissions to.
     * @param permissionBitMap Bitmap used for finer grained operator permissions controls.
     * @param sig The EIP712Signature struct containing the character owner's signature.
     * @dev Every bit in permissionBitMap stands for a corresponding method in Web3Entry. more details in OP.sol.
     */
    function grantOperatorPermissionsWithSig(
        uint256 characterId,
        address operator,
        uint256 permissionBitMap,
        DataTypes.EIP712Signature calldata sig
    ) external;

    /**
     * @notice Grant operators allowlist and blocklist roles of a note.
     * @param characterId ID of character that you want to set.
     * @param noteId ID of note that you want to set.
     * @param blocklist blocklist addresses that you want to grant.
     * @param allowlist allowlist addresses that you want to grant.
     */
    function grantOperators4Note(
        uint256 characterId,
        uint256 noteId,
        address[] calldata blocklist,
        address[] calldata allowlist
    ) external;

    /**
     * @notice  Sets a new metadataURI for a given link list.
     * @param   linkListId  The linklist id to set for.
     * @param   uri  The metadata uri to set.
     */
    function setLinklistUri(uint256 linkListId, string calldata uri) external;

    /**
     * @notice Sets a link type for a given linklist.
     * @dev Linklist is the group of all linking objects with the same link type, like "like".
     * Each character can only have one linklist for each link type.
     * It will fail if you try to set a link type which is already set for some linklist owned by the same character.
     * @param linkListId The linklist ID to set for.
     * @param linkType The link type to set.
     */
    function setLinklistType(uint256 linkListId, bytes32 linkType) external;

    /**
     * @notice Links an address with the given parameters.
     * @param vars The linkAddressData struct containing the linking parameters:<br>
     * `fromCharacterId`: The character ID to sponsor a link action.<br>
     * `ethAddress`: The address to be linked.<br>
     * `linkType`: The link type, like "like", which is a bytes32 format.<br>
     * `data`: The data passed to the link module to use, if any.<br>
     */
    function linkAddress(DataTypes.linkAddressData calldata vars) external;

    /**
     * @notice Unlinks an address with the given parameters.
     * @param vars The unlinkAddressData struct containing the unlinking parameters:<br>
     * `fromCharacterId`: The character ID to sponsor a unlink action.<br>
     * `ethAddress`: The address to be unlinked.<br>
     * `linkType`: The link type, like "like", which is a bytes32 format.<br>
     */
    function unlinkAddress(DataTypes.unlinkAddressData calldata vars) external;

    /**
     * @notice Links a character with the given parameters.
     * @param vars The linkCharacterData struct containing the linking parameters:<br>
     * `fromCharacterId`: The character ID to sponsor a link action.<br>
     * `toCharacterId`: The character ID to be linked.<br>
     * `linkType`: The link type, like "follow", which is a bytes32 format.<br>
     * `data`: The data passed to the link module to use, if any.<br>
     */
    function linkCharacter(DataTypes.linkCharacterData calldata vars) external;

    /**
     * @notice Unlinks a character with the given parameters.
     * @param vars The unlinkCharacterData struct containing the unlinking parameters:
     * `fromCharacterId`: The character ID to sponsor a unlink action.<br>
     * `toCharacterId`: The character ID to be unlinked.<br>
     * `linkType`: The link type, like "follow", which is a bytes32 format.<br>
     */
    function unlinkCharacter(DataTypes.unlinkCharacterData calldata vars) external;

    /**
     * @notice Create a character and then link it.
     * @param vars The createThenLinkCharacterData struct containing the parameters:<br>
     * `fromCharacterId`: The character ID to sponsor a link action.<br>
     * `to`: The address to receive the new character nft.<br>
     * `linkType`: The link type, like "follow", which is a bytes32 format.<br>
     */
    function createThenLinkCharacter(
        DataTypes.createThenLinkCharacterData calldata vars
    ) external returns (uint256 characterId);

    /**
     * @notice Links a note with the given parameters.
     * @param vars The linkNoteData struct containing the linking parameters:<br>
     * `fromCharacterId`: The character ID to sponsor a link action.<br>
     * `toCharacterId`: The character ID of note to be linked.<br>
     * `toNoteId`: The note ID of note to be linked.<br>
     * `linkType`: The link type, like "like", which is a bytes32 format.<br>
     * `data`: The data passed to the link module to use, if any.<br>
     */
    function linkNote(DataTypes.linkNoteData calldata vars) external;

    /**
     * @notice UnLinks a note with the given parameters.
     * @param vars The unlinkNoteData struct containing the unlinking parameters:<br>
     * `fromCharacterId`: The character ID to sponsor a unlink action.<br>
     * `toCharacterId`: The character ID of note to be unlinked.<br>
     * `toNoteId`: The note ID of note to be unlinked.<br>
     * `linkType`: The link type, like "like", which is a bytes32 format.<br>
     */
    function unlinkNote(DataTypes.unlinkNoteData calldata vars) external;

    /**
     * @notice Links an ERC721 with the given parameters.
     * @param vars The linkERC721Data struct containing the linking parameters:<br>
     * `fromCharacterId`: The character ID to sponsor a link action.<br>
     * `tokenAddress`: The token address of ERC721 to be linked.<br>
     * `tokenId`: The token ID of ERC721 to be linked.<br>
     * `linkType`: The link type, like "like", which is a bytes32 format.<br>
     * `data`: The data passed to the link module to use, if any.<br>
     */
    function linkERC721(DataTypes.linkERC721Data calldata vars) external;

    /**
     * @notice Unlinks an ERC721 with the given parameters.
     * @param vars The unlinkERC721Data struct containing the unlinking parameters:<br>
     * `fromCharacterId`: The character ID to sponsor a unlink action.<br>
     * `tokenAddress`: The token address of ERC721 to be unlinked.<br>
     * `tokenId`: The token ID of ERC721 to be unlinked.<br>
     * `linkType`: The link type, like "like", which is a bytes32 format.<br>
     */
    function unlinkERC721(DataTypes.unlinkERC721Data calldata vars) external;

    /**
     * @notice Links any uri with the given parameters.
     * @param vars The linkAnyUriData struct containing the linking parameters:<br>
     * `fromCharacterId`: The character ID to sponsor a link action.<br>
     * `toUri`: The uri to be linked.<br>
     * `linkType`: The link type, like "like", which is a bytes32 format.<br>
     * `data`: The data passed to the link module to use, if any.<br>
     */
    function linkAnyUri(DataTypes.linkAnyUriData calldata vars) external;

    /**
     * @notice Unlinks any uri with the given parameters.
     * @param vars The unlinkAnyUriData struct containing the unlinking parameters:<br>
     * `fromCharacterId`: The character ID to sponsor a unlink action.<br>
     * `toUri`: The uri to be unlinked.<br>
     * `linkType`: The link type, like "like", which is a bytes32 format.<br>
     */
    function unlinkAnyUri(DataTypes.unlinkAnyUriData calldata vars) external;

    /**
     * @notice Links a linklist with the given parameters.
     * @param vars The linkLinklistData struct containing the linking parameters:<br>
     * `fromCharacterId`: The character ID to sponsor a link action.<br>
     * `toLinkListId`: The linklist ID to be linked.<br>
     * `linkType`: The link type, like "like", which is a bytes32 format.<br>
     * `data`: The data passed to the link module to use, if any.<br>
     */
    function linkLinklist(DataTypes.linkLinklistData calldata vars) external;

    /**
     * @notice Unlinks a linklist with the given parameters.
     * @param vars The unlinkLinklistData struct containing the unlinking parameters:<br>
     * `fromCharacterId`: The character ID to sponsor a unlink action.<br>
     * `toLinkListId`: The linklist ID to be unlinked.<br>
     * `linkType`: The link type, like "like", which is a bytes32 format.<br>
     */
    function unlinkLinklist(DataTypes.unlinkLinklistData calldata vars) external;

    /**
     * @notice Sets a link module for a given character.
     * @param vars The setLinkModule4CharacterData struct containing the parameters:<br>
     * `characterId`: The character ID to set for.<br>
     * `linkModule`: The address of link module contract to set.<br>
     * `linkModuleInitData`: The data passed to the link module to use, if any.<br>
     */
    function setLinkModule4Character(DataTypes.setLinkModule4CharacterData calldata vars) external;

    /**
     * @notice Sets a link module for a given note.
     * @param vars The setLinkModule4NoteData struct containing the parameters:<br>
     * `characterId`: The character ID to set for.<br>
     * `noteId`: The note ID to set for.<br>
     * `linkModule`: The address of link module contract to set.<br>
     * `linkModuleInitData`: The data passed to the link module to use, if any.<br>
     */
    function setLinkModule4Note(DataTypes.setLinkModule4NoteData calldata vars) external;

    /**
     * @notice Mints an nft with the given note.
     * @param vars The MintNoteData struct containing the minting parameters:<br>
     * `characterId`: The character ID of the note.<br>
     * `noteId`: The note ID of the note.<br>
     * `to`: The address to receive the minted nft.<br>
     * `data`: The data passed to the mint module to use, if any.<br>
     */
    function mintNote(DataTypes.MintNoteData calldata vars) external returns (uint256 tokenId);

    /**
     * @notice Sets a mint module for the given note.
     * @param vars The setMintModule4NoteData struct containing the setting parameters:<br>
     * `characterId`: The character ID of the note.<br>
     * `noteId`: The note ID of the note.<br>
     * `mintModule`: The address of mint module to set.<br>
     * `mintModuleInitData`: The data passed to the mint module to init, if any.<br>
     */
    function setMintModule4Note(DataTypes.setMintModule4NoteData calldata vars) external;

    /**
     * @notice Posts a note with the given parameters.
     * @param vars The postNoteData struct containing the posting parameters:<br>
     * `characterId`: The character ID to post to.<br>
     * `contentUri`: The uri to set for the new post.<br>
     * `linkModule`: The address of link module to set for the new post.<br>
     * `linkModuleInitData`: The data passed to the link module to init, if any.<br>
     * `mintModule`: The address of mint module to set for the new post.<br>
     * `mintModuleInitData`: The data passed to the mint module to init, if any.<br>
     */
    function postNote(DataTypes.PostNoteData calldata vars) external returns (uint256 noteId);

    /**
     * @notice  Set URI for a note.
     * @param   characterId  The character ID of the note owner.
     * @param   noteId  The ID of the note to set.
     * @param   newUri  The new URI.
     */
    function setNoteUri(uint256 characterId, uint256 noteId, string calldata newUri) external;

    /**
     * @notice  Lock a note and put it into a immutable state where no modifications are 
     allowed. Locked notes are usually assumed as final versions.
     * @param   characterId  The character ID of the note owner.
     * @param   noteId  The ID of the note to lock.
     */
    function lockNote(uint256 characterId, uint256 noteId) external;

    /**
     * @notice  Delete a note.
     * @dev     Deleting a note doesn't essentially mean that the txs or contents are being removed due to the
     * immutability of blockchain itself, but the deleted notes will be tagged as `deleted` after calling `deleteNote`.
     * @param   characterId  The character ID of the note owner.
     * @param   noteId  The ID of the note to delete.
     */
    function deleteNote(uint256 characterId, uint256 noteId) external;

    /**
     * @notice Posts a note for a given character.
     * @param vars The postNoteData struct containing the posting parameters:<br>
     * `characterId`: The character ID to post to.<br>
     * `contentUri`: The uri to set for the new post.<br>
     * `linkModule`: The address of link module to set for the new post.<br>
     * `linkModuleInitData`: The data passed to the link module to init, if any.<br>
     * `mintModule`: The address of mint module to set for the new post.<br>
     * `mintModuleInitData`: The data passed to the mint module to init, if any.<br>
     * @param toCharacterId The target character ID.
     */
    function postNote4Character(
        DataTypes.PostNoteData calldata vars,
        uint256 toCharacterId
    ) external returns (uint256);

    /**
     * @notice Posts a note for a given address.
     * @param vars The postNoteData struct containing the posting parameters:<br>
     * `characterId`: The character ID to post to.<br>
     * `contentUri`: The uri to set for the new post.<br>
     * `linkModule`: The address of link module to set for the new post.<br>
     * `linkModuleInitData`: The data passed to the link module to init, if any.<br>
     * `mintModule`: The address of mint module to set for the new post.<br>
     * `mintModuleInitData`: The data passed to the mint module to init, if any.<br>
     * @param ethAddress The target address.
     */
    function postNote4Address(
        DataTypes.PostNoteData calldata vars,
        address ethAddress
    ) external returns (uint256);

    /**
     * @notice Posts a note for a given linklist.
     * @param vars The postNoteData struct containing the posting parameters:<br>
     * `characterId`: The character ID to post to.<br>
     * `contentUri`: The uri to set for the new post.<br>
     * `linkModule`: The address of link module to set for the new post.<br>
     * `linkModuleInitData`: The data passed to the link module to init, if any.<br>
     * `mintModule`: The address of mint module to set for the new post.<br>
     * `mintModuleInitData`: The data passed to the mint module to init, if any.<br>
     * @param toLinklistId The target linklist.
     */
    function postNote4Linklist(
        DataTypes.PostNoteData calldata vars,
        uint256 toLinklistId
    ) external returns (uint256);

    /**
     * @notice Posts a note for a given note.
     * @param vars The postNoteData struct containing the posting parameters:<br>
     * `characterId`: The character ID to post to.<br>
     * `contentUri`: The uri to set for the new post.<br>
     * `linkModule`: The address of link module to set for the new post.<br>
     * `linkModuleInitData`: The data passed to the link module to init, if any.<br>
     * `mintModule`: The address of mint module to set for the new post.<br>
     * `mintModuleInitData`: The data passed to the mint module to init, if any.<br>
     * @param note The target note struct containing the parameters:<br>
     * `characterId`: The character ID of target note.<br>
     * `noteId`: The note ID of target note.
     */
    function postNote4Note(
        DataTypes.PostNoteData calldata vars,
        DataTypes.NoteStruct calldata note
    ) external returns (uint256);

    /**
     * @notice Posts a note for a given ERC721.
     * @param vars The postNoteData struct containing the posting parameters:<br>
     * `characterId`: The character ID to post to.<br>
     * `contentUri`: The uri to set for the new post.<br>
     * `linkModule`: The address of link module to set for the new post.<br>
     * `linkModuleInitData`: The data passed to the link module to init, if any.<br>
     * `mintModule`: The address of mint module to set for the new post.<br>
     * `mintModuleInitData`: The data passed to the mint module to init, if any.<br>
     * @param erc721 The target ERC721 struct containing the parameters:<br>
     * `tokenAddress`: The token address of target ERC721.<br>
     * `erc721TokenId`: The token ID of target ERC721.
     */
    function postNote4ERC721(
        DataTypes.PostNoteData calldata vars,
        DataTypes.ERC721Struct calldata erc721
    ) external returns (uint256);

    /**
     * @notice Posts a note for a given uri.
     * @param vars The postNoteData struct containing the posting parameters:<br>
     * `characterId`: The character ID to post to.<br>
     * `contentUri`: The uri to set for the new post.<br>
     * `linkModule`: The address of link module to set for the new post.<br>
     * `linkModuleInitData`: The data passed to the link module to init, if any.<br>
     * `mintModule`: The address of mint module to set for the new post.<br>
     * `mintModuleInitData`: The data passed to the mint module to init, if any.<br>
     * @param uri The target uri(could be an url link).
     */
    function postNote4AnyUri(
        DataTypes.PostNoteData calldata vars,
        string calldata uri
    ) external returns (uint256);

    /**
     * @notice Burns a linklist NFT.
     * @dev It will burn the linklist NFT and remove the links from a character.
     * @param linklistId The linklist ID to burn.
     */
    function burnLinklist(uint256 linklistId) external;

    /**
     * @notice Get operator list of a character. This operator list has only a sole purpose, which is
     * keeping records of keys of `operatorsPermissionBitMap`. Thus, addresses queried by this function
     * not always have operator permissions. Keep in mind don't use this function to check
     * authorizations!!!
     * @param characterId ID of your character that you want to check.
     * @return All keys of operatorsPermission4NoteBitMap.
     */
    function getOperators(uint256 characterId) external view returns (address[] memory);

    /**
     * @notice Get permission bitmap of an operator.
     * @param characterId ID of character that you want to check.
     * @param operator Address to grant operator permissions to.
     * @return Permission bitmap of this operator.
     */
    function getOperatorPermissions(
        uint256 characterId,
        address operator
    ) external view returns (uint256);

    /**
     * @notice Get operators blocklist and allowlist for a note.
     * @param characterId ID of character to query.
     * @param noteId ID of note to query.
     */
    function getOperators4Note(
        uint256 characterId,
        uint256 noteId
    ) external view returns (address[] memory blocklist, address[] memory allowlist);

    /**
     * @notice Query if a operator has permission for a note.
     * @param characterId ID of character that you want to query.
     * @param noteId ID of note that you want to query.
     * @param operator Address to query.
     * @return true if Operator has permission for a note, otherwise false.
     */
    function isOperatorAllowedForNote(
        uint256 characterId,
        uint256 noteId,
        address operator
    ) external view returns (bool);

    /**
     * @notice Returns primary character for a given account.
     * @param account The address to query.
     * @return uint256 The primary character ID, which will be 0 if not mapped.
     */
    function getPrimaryCharacterId(address account) external view returns (uint256);

    /**
     * @notice Returns whether or not a character is primary character.
     * @param characterId The character ID to query.
     * @return bool True if the character is primary, false otherwise.
     */
    function isPrimaryCharacter(uint256 characterId) external view returns (bool);

    /**
     * @notice Returns the full character struct associated with a given character token ID.
     * @param characterId The token ID of the character to query.
     * @return The full character struct of given character.
     */
    function getCharacter(uint256 characterId) external view returns (DataTypes.Character memory);

    /**
     * @notice Returns the full character struct associated with a given character handle.
     * @param handle The handle of the character to query.
     * @return The full character struct of given character.
     */
    function getCharacterByHandle(
        string calldata handle
    ) external view returns (DataTypes.Character memory);

    /**
     * @notice Returns the handle of character with a given character.
     * @param characterId The token ID of the character to query.
     * @return The handle of given character.
     */
    function getHandle(uint256 characterId) external view returns (string memory);

    /**
     * @notice Returns the uri of character with a given character.
     * @param characterId The token ID of the character to query.
     * @return The uri of given character.
     */
    function getCharacterUri(uint256 characterId) external view returns (string memory);

    /**
     * @notice Returns the full note struct associated with a given note.
     * @param characterId The token ID of the character to query.
     * @param noteId The token ID of the note to query.
     * @return The full note struct of given note.
     */
    function getNote(
        uint256 characterId,
        uint256 noteId
    ) external view returns (DataTypes.Note memory);

    /**
     * @notice Returns the uri of linklist with a given linklist.
     * @param tokenId The token ID of the linklist to query.
     * @return string The uri of given linklist.
     */
    function getLinklistUri(uint256 tokenId) external view returns (string memory);

    /**
     * @notice Returns the token ID of linklist with a given character and linkType.
     * @param characterId The token ID of the character to query.
     * @param linkType The linkType.
     * @return The token ID of linklist.
     */
    function getLinklistId(uint256 characterId, bytes32 linkType) external view returns (uint256);

    /**
     * @notice Returns the linkType of linklist with a given linklist.
     * @param linkListId The token ID of the linklist to query.
     * @return bytes32 The linkType of given linklist.
     */
    function getLinklistType(uint256 linkListId) external view returns (bytes32);

    /**
     * @notice Returns the address of linklist contract.
     * @return The address of linklist contract.
     */
    function getLinklistContract() external view returns (address);

    /**
     * @notice Returns the domain separator for this NFT contract.
     * @return bytes32 The domain separator.
     */
    function getDomainSeparator() external view returns (bytes32);

    /**
     * @notice Returns the current nonce for `owner`. This value must be included
     * whenever a signature is generated by `grantOperatorPermissionsWithSig`.
     * Every successful call to `grantOperatorPermissionsWithSig` increases `owner`'s nonce by one. This
     * prevents a signature from being used multiple times.
     * @param owner The owner address to query.
     * @return uint256 The current nonce for `owner`.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @notice Returns the revision number of web3Entry contract.
     * @return The the revision number of web3Entry contract.
     */
    function getRevision() external pure returns (uint256);
}
          

contracts/interfaces/ILinkModule4Character.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

interface ILinkModule4Character {
    function initializeLinkModule(
        uint256 characterId,
        bytes calldata data
    ) external returns (bytes memory);

    function processLink(address caller, uint256 characterId, bytes calldata data) external;
}
          

contracts/libraries/Events.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

library Events {
    event BaseInitialized(string name, string symbol, uint256 timestamp);

    event Web3EntryInitialized(uint256 timestamp);

    event LinklistNFTInitialized(uint256 timestamp);

    event MintNFTInitialized(uint256 characterId, uint256 noteId, uint256 timestamp);

    event CharacterCreated(
        uint256 indexed characterId,
        address indexed creator,
        address indexed to,
        string handle,
        uint256 timestamp
    );

    event SetPrimaryCharacterId(
        address indexed account,
        uint256 indexed characterId,
        uint256 indexed oldCharacterId
    );

    event SetHandle(address indexed account, uint256 indexed characterId, string newHandle);

    event SetSocialToken(
        address indexed account,
        uint256 indexed characterId,
        address indexed tokenAddress
    );

    event GrantOperatorPermissions(
        uint256 indexed characterId,
        address indexed operator,
        uint256 permissionBitMap
    );

    event GrantOperators4Note(
        uint256 indexed characterId,
        uint256 indexed noteId,
        address[] blocklist,
        address[] allowlist
    );

    event SetCharacterUri(uint256 indexed characterId, string newUri);

    event PostNote(
        uint256 indexed characterId,
        uint256 indexed noteId,
        bytes32 indexed linkKey,
        bytes32 linkItemType,
        bytes data
    );

    event SetNoteUri(uint256 indexed characterId, uint256 noteId, string newUri);

    event DeleteNote(uint256 indexed characterId, uint256 noteId);

    event LockNote(uint256 indexed characterId, uint256 noteId);

    event LinkCharacter(
        address indexed account,
        uint256 indexed fromCharacterId,
        uint256 indexed toCharacterId,
        bytes32 linkType,
        uint256 linklistId
    );

    event UnlinkCharacter(
        address indexed account,
        uint256 indexed fromCharacterId,
        uint256 indexed toCharacterId,
        bytes32 linkType
    );

    event LinkNote(
        uint256 indexed fromCharacterId,
        uint256 indexed toCharacterId,
        uint256 indexed toNoteId,
        bytes32 linkType,
        uint256 linklistId
    );

    event UnlinkNote(
        uint256 indexed fromCharacterId,
        uint256 indexed toCharacterId,
        uint256 indexed toNoteId,
        bytes32 linkType,
        uint256 linklistId
    );

    event LinkERC721(
        uint256 indexed fromCharacterId,
        address indexed tokenAddress,
        uint256 indexed toNoteId,
        bytes32 linkType,
        uint256 linklistId
    );

    event LinkAddress(
        uint256 indexed fromCharacterId,
        address indexed ethAddress,
        bytes32 linkType,
        uint256 linklistId
    );

    event UnlinkAddress(
        uint256 indexed fromCharacterId,
        address indexed ethAddress,
        bytes32 linkType
    );

    event LinkAnyUri(
        uint256 indexed fromCharacterId,
        string toUri,
        bytes32 linkType,
        uint256 linklistId
    );

    event UnlinkAnyUri(uint256 indexed fromCharacterId, string toUri, bytes32 linkType);

    event LinkCharacterLink(
        uint256 indexed fromCharacterId,
        bytes32 indexed linkType,
        uint256 clFromCharacterId,
        uint256 clToCharacterId,
        bytes32 clLinkType
    );

    event UnlinkCharacterLink(
        uint256 indexed fromCharacterId,
        bytes32 indexed linkType,
        uint256 clFromCharactereId,
        uint256 clToCharacterId,
        bytes32 clLinkType
    );

    event UnlinkERC721(
        uint256 indexed fromCharacterId,
        address indexed tokenAddress,
        uint256 indexed toNoteId,
        bytes32 linkType,
        uint256 linklistId
    );

    event LinkLinklist(
        uint256 indexed fromCharacterId,
        uint256 indexed toLinklistId,
        bytes32 linkType,
        uint256 indexed linklistId
    );

    event UnlinkLinklist(
        uint256 indexed fromCharacterId,
        uint256 indexed toLinklistId,
        bytes32 linkType,
        uint256 indexed linklistId
    );

    event MintNote(
        address indexed to,
        uint256 indexed characterId,
        uint256 indexed noteId,
        address tokenAddress,
        uint256 tokenId
    );

    event SetLinkModule4Character(
        uint256 indexed characterId,
        address indexed linkModule,
        bytes linkModuleInitData,
        bytes returnData
    );

    event SetLinkModule4Note(
        uint256 indexed characterId,
        uint256 indexed noteId,
        address indexed linkModule,
        bytes linkModuleInitData,
        bytes returnData
    );

    event SetLinkModule4Address(
        address indexed account,
        address indexed linkModule,
        bytes linkModuleInitData,
        bytes returnData
    );

    event SetLinkModule4ERC721(
        address indexed tokenAddress,
        uint256 indexed tokenId,
        address indexed linkModule,
        bytes linkModuleInitData,
        bytes returnData
    );

    event SetLinkModule4Linklist(
        uint256 indexed linklistId,
        address indexed linkModule,
        bytes linkModuleInitData,
        bytes returnData
    );

    event SetMintModule4Note(
        uint256 indexed characterId,
        uint256 indexed noteId,
        address indexed mintModule,
        bytes mintModuleInitData,
        bytes returnData
    );

    event AttachLinklist(
        uint256 indexed linklistId,
        uint256 indexed characterId,
        bytes32 indexed linkType
    );

    event DetachLinklist(
        uint256 indexed linklistId,
        uint256 indexed characterId,
        bytes32 indexed linkType
    );

    event SetApprovedMintAmount4Addresses(
        uint256 indexed characterId,
        uint256 indexed noteId,
        uint256 indexed amount,
        address[] approvedAddresses
    );
}
          

contracts/libraries/CharacterLogic.sol

// SPDX-License-Identifier: MIT
// solhint-disable  private-vars-leading-underscore
pragma solidity 0.8.18;

import {DataTypes} from "./DataTypes.sol";
import {Events} from "./Events.sol";
import {ILinkModule4Character} from "../interfaces/ILinkModule4Character.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

library CharacterLogic {
    using EnumerableSet for EnumerableSet.Bytes32Set;

    /**
     * @notice  Creates a character.
     * @param   to  The address to mint the character to.
     * @param   handle  The handle to set for the new character.
     * @param   uri  The URI to set for the new character’s metadata.
     * @param   linkModule  The link module to set for the new character or the zero address.
     * @param   linkModuleInitData  Arbitrary data to be decoded in the link module for initialization.
     * @param   characterId The ID of the new character.
     */
    function createCharacter(
        address to,
        string memory handle,
        string memory uri,
        address linkModule,
        bytes memory linkModuleInitData,
        uint256 characterId,
        mapping(bytes32 => uint256) storage _characterIdByHandleHash,
        mapping(uint256 => DataTypes.Character) storage _characterById
    ) external {
        bytes32 handleHash = keccak256(bytes(handle));
        _characterIdByHandleHash[handleHash] = characterId;

        _characterById[characterId].characterId = characterId;
        _characterById[characterId].handle = handle;
        _characterById[characterId].uri = uri;

        // init link module
        if (linkModule != address(0)) {
            _characterById[characterId].linkModule = linkModule;

            ILinkModule4Character(linkModule).initializeLinkModule(characterId, linkModuleInitData);
        }

        emit Events.CharacterCreated(characterId, msg.sender, to, handle, block.timestamp);
    }

    /**
     * @notice  Sets a social token for a given character.
     * @param   characterId  	The character ID to set social token for.
     * @param   tokenAddress  Token address to be set.
     */
    function setSocialToken(
        uint256 characterId,
        address tokenAddress,
        mapping(uint256 => DataTypes.Character) storage _characterById
    ) external {
        _characterById[characterId].socialToken = tokenAddress;

        emit Events.SetSocialToken(msg.sender, characterId, tokenAddress);
    }

    /**
     * @notice  Sets link module for a given character.
     * @param   characterId  The character ID to set link module for.
     * @param   linkModule  The link module to set.
     * @param   linkModuleInitData  The data to pass to the link module for initialization, if any.
     */
    function setCharacterLinkModule(
        uint256 characterId,
        address linkModule,
        bytes calldata linkModuleInitData,
        DataTypes.Character storage _character
    ) external {
        _character.linkModule = linkModule;

        bytes memory returnData = "";
        if (linkModule != address(0)) {
            returnData = ILinkModule4Character(linkModule).initializeLinkModule(
                characterId,
                linkModuleInitData
            );
        }
        emit Events.SetLinkModule4Character(
            characterId,
            linkModule,
            linkModuleInitData,
            returnData
        );
    }

    /**
     * @notice  Sets new handle for a given character.
     * @param   characterId  The character ID to set new handle for.
     * @param   newHandle  New handle to set.
     */
    function setHandle(
        uint256 characterId,
        string calldata newHandle,
        mapping(bytes32 => uint256) storage _characterIdByHandleHash,
        mapping(uint256 => DataTypes.Character) storage _characterById
    ) external {
        // remove old handle
        string memory oldHandle = _characterById[characterId].handle;
        bytes32 oldHandleHash = keccak256(bytes(oldHandle));
        delete _characterIdByHandleHash[oldHandleHash];

        // set new handle
        bytes32 handleHash = keccak256(bytes(newHandle));
        _characterIdByHandleHash[handleHash] = characterId;
        _characterById[characterId].handle = newHandle;

        emit Events.SetHandle(msg.sender, characterId, newHandle);
    }
}
          

@openzeppelin/contracts/utils/math/SignedMath.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two signed numbers.
     */
    function min(int256 a, int256 b) internal pure returns (int256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}
          

contracts/libraries/DataTypes.sol

// SPDX-License-Identifier: MIT
// solhint-disable contract-name-camelcase
pragma solidity 0.8.18;

import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

/**
 * @title DataTypes
 * @notice A standard library of data types.
 */
library DataTypes {
    struct MigrateData {
        address account;
        string handle;
        string uri;
        address[] toAddresses;
        bytes32 linkType;
    }

    struct CreateCharacterData {
        address to;
        string handle;
        string uri;
        address linkModule;
        bytes linkModuleInitData;
    }

    struct createThenLinkCharacterData {
        uint256 fromCharacterId;
        address to;
        bytes32 linkType;
    }

    struct linkNoteData {
        uint256 fromCharacterId;
        uint256 toCharacterId;
        uint256 toNoteId;
        bytes32 linkType;
        bytes data;
    }

    struct unlinkNoteData {
        uint256 fromCharacterId;
        uint256 toCharacterId;
        uint256 toNoteId;
        bytes32 linkType;
    }

    struct linkCharacterData {
        uint256 fromCharacterId;
        uint256 toCharacterId;
        bytes32 linkType;
        bytes data;
    }

    struct unlinkCharacterData {
        uint256 fromCharacterId;
        uint256 toCharacterId;
        bytes32 linkType;
    }

    struct linkERC721Data {
        uint256 fromCharacterId;
        address tokenAddress;
        uint256 tokenId;
        bytes32 linkType;
        bytes data;
    }

    struct unlinkERC721Data {
        uint256 fromCharacterId;
        address tokenAddress;
        uint256 tokenId;
        bytes32 linkType;
    }

    struct linkAddressData {
        uint256 fromCharacterId;
        address ethAddress;
        bytes32 linkType;
        bytes data;
    }

    struct unlinkAddressData {
        uint256 fromCharacterId;
        address ethAddress;
        bytes32 linkType;
    }

    struct linkAnyUriData {
        uint256 fromCharacterId;
        string toUri;
        bytes32 linkType;
        bytes data;
    }

    struct unlinkAnyUriData {
        uint256 fromCharacterId;
        string toUri;
        bytes32 linkType;
    }

    struct linkLinklistData {
        uint256 fromCharacterId;
        uint256 toLinkListId;
        bytes32 linkType;
        bytes data;
    }

    struct unlinkLinklistData {
        uint256 fromCharacterId;
        uint256 toLinkListId;
        bytes32 linkType;
    }

    struct setLinkModule4CharacterData {
        uint256 characterId;
        address linkModule;
        bytes linkModuleInitData;
    }

    struct setLinkModule4NoteData {
        uint256 characterId;
        uint256 noteId;
        address linkModule;
        bytes linkModuleInitData;
    }

    struct setLinkModule4LinklistData {
        uint256 linklistId;
        address linkModule;
        bytes linkModuleInitData;
    }

    struct setLinkModule4ERC721Data {
        address tokenAddress;
        uint256 tokenId;
        address linkModule;
        bytes linkModuleInitData;
    }

    struct setLinkModule4AddressData {
        address account;
        address linkModule;
        bytes linkModuleInitData;
    }

    struct setMintModule4NoteData {
        uint256 characterId;
        uint256 noteId;
        address mintModule;
        bytes mintModuleInitData;
    }

    struct linkCharactersInBatchData {
        uint256 fromCharacterId;
        uint256[] toCharacterIds;
        bytes[] data;
        address[] toAddresses;
        bytes32 linkType;
    }

    struct LinkData {
        uint256 linklistId;
        uint256 linkItemType;
        uint256 linkingCharacterId;
        address linkingAddress;
        uint256 linkingLinklistId;
        bytes32 linkKey;
    }

    struct PostNoteData {
        uint256 characterId;
        string contentUri;
        address linkModule;
        bytes linkModuleInitData;
        address mintModule;
        bytes mintModuleInitData;
        bool locked;
    }

    struct MintNoteData {
        uint256 characterId;
        uint256 noteId;
        address to;
        bytes mintModuleData;
    }

    // character struct
    struct Character {
        uint256 characterId;
        string handle;
        string uri;
        uint256 noteCount;
        address socialToken;
        address linkModule;
    }

    /**
     * @dev A struct containing data associated with each new note.
     * @param linkItemType The link type of this note, if the note is a note with link.
     * @param linkKey If linkKey is not empty, it is a note with link(eg.a comment to a character or a note).
     * @param contentURI The URI associated with this note.
     * @param linkModule The address of the current link module of this note, can be empty.
     * @param mintModule  The address of the current mint module of this note, can be empty.
     * @param mintNFT The address of the mintNFT associated with this note, if any.
     * @param deleted Whether the note is deleted.
     * @param locked Whether the note is locked. If the note is locked, its owner can't set not uri anymore.
     */
    struct Note {
        bytes32 linkItemType;
        bytes32 linkKey;
        string contentUri;
        address linkModule;
        address mintModule;
        address mintNFT;
        bool deleted;
        bool locked;
    }

    struct CharacterLinkStruct {
        uint256 fromCharacterId;
        uint256 toCharacterId;
        bytes32 linkType;
    }

    struct NoteStruct {
        uint256 characterId;
        uint256 noteId;
    }

    struct ERC721Struct {
        address tokenAddress;
        uint256 erc721TokenId;
    }

    /**
     @param blocklist The list of blocklist addresses.
     @param allowlist The list of allowlist addresses.
     */
    struct Operators4Note {
        EnumerableSet.AddressSet blocklist;
        EnumerableSet.AddressSet allowlist;
    }

    /**
     * @dev A struct containing the necessary information to reconstruct an EIP-712 typed data signature.
     * @param v The signature's recovery parameter.
     * @param r The signature's r parameter.
     * @param s The signature's s parameter
     * @param deadline The signature's deadline.
     */
    struct EIP712Signature {
        uint8 v;
        bytes32 r;
        bytes32 s;
        uint256 deadline;
    }
}
          

@openzeppelin/contracts/utils/Address.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @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://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}
          

contracts/base/NFTBase.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

import {ERC721} from "./ERC721.sol";
import {ERC721Enumerable} from "./ERC721Enumerable.sol";
import {Events} from "../libraries/Events.sol";

abstract contract NFTBase is ERC721Enumerable {
    function _initialize(string calldata name, string calldata symbol) internal {
        ERC721.__ERC721_Init(name, symbol);

        emit Events.BaseInitialized(name, symbol, block.timestamp);
    }

    // solhint-disable ordering
    function burn(uint256 tokenId) public virtual {
        require(_isApprovedOrOwner(msg.sender, tokenId), "NFTBase: NotOwnerOrApproved");
        _burn(tokenId);
    }
}
          

contracts/libraries/OP.sol

// SPDX-License-Identifier: MIT
// solhint-disable private-vars-leading-underscore
pragma solidity 0.8.18;

/**
* In Crossbell's operator system, every uint8 stands for a single method in Web3Entry.sol. <br>
* For most cases, we recommend simply granting operators the `OPERATOR_SIGN_PERMISSION_BITMAP`,
* which gives operator full permissions aside from owner permissions and future permissions, but for
* those who're more aware of access control, the custom permission bitmap is all yours,
* and you can find every customizable methods below. <br>

* `OPERATOR_SIGN_PERMISSION_BITMAP` have access to all methods in `OPERATOR_SYNC_PERMISSION_BITMAP`
* plus more permissions for signing. <br>

* Permissions are laid out in a increasing order of power.
* so the bitmap looks like this:

<table>
    <colgroup>
        <col style="width: 25%">
        <col style="width: 25%">
        <col style="width: 25%">
        <col style="width: 25%">
    </colgroup>
    <tr>
        <td>operator sync</td>
        <td>operator sign</td>
        <td>future reserved</td>
        <td>owner</td>
    <tr>
    <tr>
        <td>[255 - 236]</td>
        <td>[235 - 176]</td>
        <td>[175 - 21]</td>
        <td>[20 - 0]</td>
    <tr>
</table>


*/

library OP {
    uint256 internal constant UINT256_MAX = ~uint256(0);

    // [0,20] for owner permissions
    uint8 internal constant SET_HANDLE = 0;
    uint8 internal constant SET_SOCIAL_TOKEN = 1;
    uint8 internal constant GRANT_OPERATOR_PERMISSIONS = 2;
    // uint8 internal constant GRANT_OPERATOR_PERMISSIONS_FOR_NOTE = 3;
    uint8 internal constant GRANT_OPERATORS_FOR_NOTE = 3;
    // set [0, 3] bit index
    uint256 internal constant OWNER_PERMISSION_BITMAP = ~(UINT256_MAX << 4);

    // [21, 175] are reserved for future

    // [176, 235] for operator sign permissions
    uint8 internal constant SET_CHARACTER_URI = 176;
    uint8 internal constant SET_LINKLIST_URI = 177;
    uint8 internal constant LINK_CHARACTER = 178;
    uint8 internal constant UNLINK_CHARACTER = 179;
    uint8 internal constant CREATE_THEN_LINK_CHARACTER = 180;
    uint8 internal constant LINK_NOTE = 181;
    uint8 internal constant UNLINK_NOTE = 182;
    uint8 internal constant LINK_ERC721 = 183;
    uint8 internal constant UNLINK_ERC721 = 184;
    uint8 internal constant LINK_ADDRESS = 185;
    uint8 internal constant UNLINK_ADDRESS = 186;
    uint8 internal constant LINK_ANYURI = 187;
    uint8 internal constant UNLINK_ANYURI = 188;
    uint8 internal constant LINK_LINKLIST = 189;
    uint8 internal constant UNLINK_LINKLIST = 190;
    uint8 internal constant SET_LINK_MODULE_FOR_CHARACTER = 191;
    uint8 internal constant SET_LINK_MODULE_FOR_NOTE = 192;
    uint8 internal constant SET_LINK_MODULE_FOR_LINKLIST = 193;
    // slither-disable-next-line similar-names
    uint8 internal constant SET_MINT_MODULE_FOR_NOTE = 194;
    uint8 internal constant SET_NOTE_URI = 195;
    uint8 internal constant LOCK_NOTE = 196;
    uint8 internal constant DELETE_NOTE = 197;
    // post note
    uint8 internal constant POST_NOTE_FOR_CHARACTER = 198;
    uint8 internal constant POST_NOTE_FOR_ADDRESS = 199;
    uint8 internal constant POST_NOTE_FOR_LINKLIST = 200;
    uint8 internal constant POST_NOTE_FOR_NOTE = 201;
    uint8 internal constant POST_NOTE_FOR_ERC721 = 202;
    uint8 internal constant POST_NOTE_FOR_ANYURI = 203;
    // set linklist type
    uint8 internal constant SET_LINKLIST_TYPE = 204;
    // set [176,204] bit index

    // [236, 255] for operator sync permissions
    uint8 internal constant POST_NOTE = 236;
    // set 236 bit index
    uint256 internal constant POST_NOTE_PERMISSION_BITMAP = 1 << POST_NOTE;

    // POST_NOTE_DEFAULT_PERMISSION_BITMAP has post note related permissions
    uint256 internal constant POST_NOTE_DEFAULT_PERMISSION_BITMAP =
        ((UINT256_MAX << 198) & ~(UINT256_MAX << 204)) | POST_NOTE_PERMISSION_BITMAP;

    // DEFAULT_PERMISSION_BITMAP has operator sign permissions and operator sync permissions
    uint256 internal constant DEFAULT_PERMISSION_BITMAP =
        ((UINT256_MAX << 176) & ~(UINT256_MAX << 205)) | POST_NOTE_PERMISSION_BITMAP;

    // bitmap mask with all current-in-use methods to 1
    uint256 internal constant ALLOWED_PERMISSION_BITMAP_MASK =
        OWNER_PERMISSION_BITMAP | DEFAULT_PERMISSION_BITMAP;
}
          

contracts/Web3EntryBase.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

import {IWeb3Entry} from "./interfaces/IWeb3Entry.sol";
import {ILinklist} from "./interfaces/ILinklist.sol";
import {NFTBase} from "./base/NFTBase.sol";
import {Web3EntryStorage} from "./storage/Web3EntryStorage.sol";
import {Web3EntryExtendStorage} from "./storage/Web3EntryExtendStorage.sol";
import {DataTypes} from "./libraries/DataTypes.sol";
import {Constants} from "./libraries/Constants.sol";
import {Events} from "./libraries/Events.sol";
import {CharacterLogic} from "./libraries/CharacterLogic.sol";
import {PostLogic} from "./libraries/PostLogic.sol";
import {OperatorLogic} from "./libraries/OperatorLogic.sol";
import {LinkLogic} from "./libraries/LinkLogic.sol";
import {LinklistLogic} from "./libraries/LinklistLogic.sol";
import {OP} from "./libraries/OP.sol";
import {
    ErrSocialTokenExists,
    ErrHandleExists,
    ErrNotCharacterOwner,
    ErrNotEnoughPermission,
    ErrNotEnoughPermissionForThisNote,
    ErrCharacterNotExists,
    ErrNoteIsDeleted,
    ErrNoteNotExists,
    ErrNoteLocked,
    ErrHandleLengthInvalid,
    ErrHandleContainsInvalidCharacters,
    ErrSignatureExpired,
    ErrSignatureInvalid,
    ErrTokenNotExists
} from "./libraries/Error.sol";
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {Multicall} from "@openzeppelin/contracts/utils/Multicall.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

contract Web3EntryBase is
    IWeb3Entry,
    Multicall,
    NFTBase,
    Web3EntryStorage,
    Initializable,
    Web3EntryExtendStorage
{
    using EnumerableSet for EnumerableSet.Bytes32Set;
    using EnumerableSet for EnumerableSet.AddressSet;

    // solhint-disable-next-line private-vars-leading-underscore
    uint256 internal constant REVISION = 4;

    modifier onlyExistingToken(uint256 tokenId) {
        if (!_exists(tokenId)) revert ErrTokenNotExists();
        _;
    }

    /// @inheritdoc IWeb3Entry
    function initialize(
        string calldata name_,
        string calldata symbol_,
        address linklist_,
        address mintNFTImpl_,
        address periphery_,
        address newbieVilla_
    ) external override reinitializer(3) {
        super._initialize(name_, symbol_);
        _linklist = linklist_;
        MINT_NFT_IMPL = mintNFTImpl_;
        _periphery = periphery_;
        _newbieVilla = newbieVilla_;

        emit Events.Web3EntryInitialized(block.timestamp);
    }

    /// @inheritdoc IWeb3Entry
    function grantOperatorPermissions(
        uint256 characterId,
        address operator,
        uint256 permissionBitMap
    ) external override {
        _validateCallerPermission(characterId, OP.GRANT_OPERATOR_PERMISSIONS);
        _grantOperatorPermissions(characterId, operator, permissionBitMap);
    }

    /// @inheritdoc IWeb3Entry
    function grantOperatorPermissionsWithSig(
        uint256 characterId,
        address operator,
        uint256 permissionBitMap,
        DataTypes.EIP712Signature calldata sig
    ) external override {
        address owner = ownerOf(characterId);

        unchecked {
            bytes32 hashedMessage = keccak256(
                abi.encode(
                    GRANT_OPERATOR_PERMISSIONS_WITH_SIG_TYPEHASH,
                    characterId,
                    operator,
                    permissionBitMap,
                    _sigNonces[owner]++,
                    sig.deadline
                )
            );
            _validateRecoveredAddress(
                ECDSA.toTypedDataHash(_calculateDomainSeparator(), hashedMessage),
                owner,
                sig
            );
        }

        _grantOperatorPermissions(characterId, operator, permissionBitMap);
    }

    /// @inheritdoc IWeb3Entry
    function grantOperators4Note(
        uint256 characterId,
        uint256 noteId,
        address[] calldata blocklist,
        address[] calldata allowlist
    ) external override {
        _validateCallerPermission(characterId, OP.GRANT_OPERATORS_FOR_NOTE);
        _validateNoteExists(characterId, noteId);
        OperatorLogic.grantOperators4Note(
            characterId,
            noteId,
            blocklist,
            allowlist,
            _operators4Note
        );
    }

    /// @inheritdoc IWeb3Entry
    function createCharacter(
        DataTypes.CreateCharacterData calldata vars
    ) external override returns (uint256 characterId) {
        return _createCharacter(vars, true);
    }

    /// @inheritdoc IWeb3Entry
    function setHandle(uint256 characterId, string calldata newHandle) external override {
        _validateCallerPermission(characterId, OP.SET_HANDLE);

        // check if the handle exists
        _checkHandleExists(keccak256(bytes(newHandle)));

        // check if the handle is valid
        _validateHandle(newHandle);

        CharacterLogic.setHandle(characterId, newHandle, _characterIdByHandleHash, _characterById);
    }

    /// @inheritdoc IWeb3Entry
    function setSocialToken(uint256 characterId, address tokenAddress) external override {
        _validateCallerPermission(characterId, OP.SET_SOCIAL_TOKEN);

        // check if the social token exists
        if (_characterById[characterId].socialToken != address(0)) revert ErrSocialTokenExists();

        CharacterLogic.setSocialToken(characterId, tokenAddress, _characterById);
    }

    /// @inheritdoc IWeb3Entry
    function setPrimaryCharacterId(uint256 characterId) external override {
        _validateCallerIsCharacterOwner(characterId);

        // `tx.origin` is used here because the caller may be the periphery contract
        uint256 oldCharacterId = _primaryCharacterByAddress[tx.origin];
        _primaryCharacterByAddress[tx.origin] = characterId;

        emit Events.SetPrimaryCharacterId(msg.sender, characterId, oldCharacterId);
    }

    /// @inheritdoc IWeb3Entry
    function setCharacterUri(uint256 characterId, string calldata newUri) external override {
        _validateCallerPermission(characterId, OP.SET_CHARACTER_URI);
        _characterById[characterId].uri = newUri;

        emit Events.SetCharacterUri(characterId, newUri);
    }

    /// @inheritdoc IWeb3Entry
    function setLinklistUri(uint256 linklistId, string calldata uri) external override {
        uint256 characterId = ILinklist(_linklist).getOwnerCharacterId(linklistId);
        _validateCallerPermission(characterId, OP.SET_LINKLIST_URI);

        LinklistLogic.setLinklistUri(linklistId, uri, _linklist);
    }

    /// @inheritdoc IWeb3Entry
    function setLinklistType(uint256 linklistId, bytes32 linkType) external override {
        uint256 characterId = ILinklist(_linklist).getOwnerCharacterId(linklistId);
        _validateCallerPermission(characterId, OP.SET_LINKLIST_TYPE);

        LinklistLogic.setLinklistType(
            characterId,
            linklistId,
            linkType,
            _linklist,
            _attachedLinklists
        );
    }

    /// @inheritdoc IWeb3Entry
    function linkCharacter(DataTypes.linkCharacterData calldata vars) external override {
        _validateCallerPermission(vars.fromCharacterId, OP.LINK_CHARACTER);
        _validateCharacterExists(vars.toCharacterId);

        LinkLogic.linkCharacter(
            vars.fromCharacterId,
            vars.toCharacterId,
            vars.linkType,
            vars.data,
            _linklist,
            _characterById[vars.toCharacterId].linkModule,
            _attachedLinklists
        );
    }

    /// @inheritdoc IWeb3Entry
    function unlinkCharacter(DataTypes.unlinkCharacterData calldata vars) external override {
        _validateCallerPermission(vars.fromCharacterId, OP.LINK_CHARACTER);

        LinkLogic.unlinkCharacter(
            vars.fromCharacterId,
            vars.toCharacterId,
            vars.linkType,
            _linklist,
            _attachedLinklists[vars.fromCharacterId][vars.linkType]
        );
    }

    /// @inheritdoc IWeb3Entry
    function createThenLinkCharacter(
        DataTypes.createThenLinkCharacterData calldata vars
    ) external override returns (uint256 characterId) {
        _validateCallerPermission(vars.fromCharacterId, OP.CREATE_THEN_LINK_CHARACTER);

        // create character
        characterId = _createCharacter(
            DataTypes.CreateCharacterData({
                to: vars.to,
                handle: _addressToHexString(vars.to),
                uri: "",
                linkModule: address(0),
                linkModuleInitData: ""
            }),
            false
        );

        // link character
        LinkLogic.linkCharacter(
            vars.fromCharacterId,
            characterId,
            vars.linkType,
            "",
            _linklist,
            address(0),
            _attachedLinklists
        );
    }

    /// @inheritdoc IWeb3Entry
    function linkNote(DataTypes.linkNoteData calldata vars) external override {
        _validateCallerPermission(vars.fromCharacterId, OP.LINK_NOTE);
        _validateNoteExists(vars.toCharacterId, vars.toNoteId);

        LinkLogic.linkNote(
            vars.fromCharacterId,
            vars.toCharacterId,
            vars.toNoteId,
            vars.linkType,
            vars.data,
            _linklist,
            _noteByIdByCharacter[vars.toCharacterId][vars.toNoteId].linkModule,
            _attachedLinklists
        );
    }

    /// @inheritdoc IWeb3Entry
    function unlinkNote(DataTypes.unlinkNoteData calldata vars) external override {
        _validateCallerPermission(vars.fromCharacterId, OP.UNLINK_NOTE);

        LinkLogic.unlinkNote(
            vars.fromCharacterId,
            vars.toCharacterId,
            vars.toNoteId,
            vars.linkType,
            _linklist,
            _attachedLinklists
        );
    }

    /// @inheritdoc IWeb3Entry
    function linkERC721(DataTypes.linkERC721Data calldata vars) external override {
        _validateCallerPermission(vars.fromCharacterId, OP.LINK_ERC721);

        LinkLogic.linkERC721(
            vars.fromCharacterId,
            vars.tokenAddress,
            vars.tokenId,
            vars.linkType,
            _linklist,
            _attachedLinklists
        );
    }

    /// @inheritdoc IWeb3Entry
    function unlinkERC721(DataTypes.unlinkERC721Data calldata vars) external override {
        _validateCallerPermission(vars.fromCharacterId, OP.UNLINK_ERC721);

        LinkLogic.unlinkERC721(
            vars.fromCharacterId,
            vars.tokenAddress,
            vars.tokenId,
            vars.linkType,
            _linklist,
            _attachedLinklists[vars.fromCharacterId][vars.linkType]
        );
    }

    /// @inheritdoc IWeb3Entry
    function linkAddress(DataTypes.linkAddressData calldata vars) external override {
        _validateCallerPermission(vars.fromCharacterId, OP.LINK_ADDRESS);

        LinkLogic.linkAddress(
            vars.fromCharacterId,
            vars.ethAddress,
            vars.linkType,
            _linklist,
            _attachedLinklists
        );
    }

    /// @inheritdoc IWeb3Entry
    function unlinkAddress(DataTypes.unlinkAddressData calldata vars) external override {
        _validateCallerPermission(vars.fromCharacterId, OP.UNLINK_ADDRESS);

        LinkLogic.unlinkAddress(
            vars.fromCharacterId,
            vars.ethAddress,
            vars.linkType,
            _linklist,
            _attachedLinklists[vars.fromCharacterId][vars.linkType]
        );
    }

    /// @inheritdoc IWeb3Entry
    function linkAnyUri(DataTypes.linkAnyUriData calldata vars) external override {
        _validateCallerPermission(vars.fromCharacterId, OP.LINK_ANYURI);

        LinkLogic.linkAnyUri(
            vars.fromCharacterId,
            vars.toUri,
            vars.linkType,
            _linklist,
            _attachedLinklists
        );
    }

    /// @inheritdoc IWeb3Entry
    function unlinkAnyUri(DataTypes.unlinkAnyUriData calldata vars) external override {
        _validateCallerPermission(vars.fromCharacterId, OP.UNLINK_ANYURI);

        LinkLogic.unlinkAnyUri(
            vars.fromCharacterId,
            vars.toUri,
            vars.linkType,
            _linklist,
            _attachedLinklists[vars.fromCharacterId][vars.linkType]
        );
    }

    /// @inheritdoc IWeb3Entry
    function linkLinklist(DataTypes.linkLinklistData calldata vars) external override {
        _validateCallerPermission(vars.fromCharacterId, OP.LINK_LINKLIST);

        LinkLogic.linkLinklist(
            vars.fromCharacterId,
            vars.toLinkListId,
            vars.linkType,
            _linklist,
            _attachedLinklists
        );
    }

    /// @inheritdoc IWeb3Entry
    function unlinkLinklist(DataTypes.unlinkLinklistData calldata vars) external override {
        _validateCallerPermission(vars.fromCharacterId, OP.UNLINK_LINKLIST);

        LinkLogic.unlinkLinklist(
            vars.fromCharacterId,
            vars.toLinkListId,
            vars.linkType,
            _linklist,
            _attachedLinklists[vars.fromCharacterId][vars.linkType]
        );
    }

    /// @inheritdoc IWeb3Entry
    function setLinkModule4Character(
        DataTypes.setLinkModule4CharacterData calldata vars
    ) external override {
        _validateCallerPermission(vars.characterId, OP.SET_LINK_MODULE_FOR_CHARACTER);

        CharacterLogic.setCharacterLinkModule(
            vars.characterId,
            vars.linkModule,
            vars.linkModuleInitData,
            _characterById[vars.characterId]
        );
    }

    /// @inheritdoc IWeb3Entry
    function setLinkModule4Note(DataTypes.setLinkModule4NoteData calldata vars) external override {
        _validateCallerPermission(vars.characterId, OP.SET_LINK_MODULE_FOR_NOTE);
        _validateCallerPermission4Note(vars.characterId, vars.noteId);
        _validateNoteExists(vars.characterId, vars.noteId);
        _validateNoteNotLocked(vars.characterId, vars.noteId);

        PostLogic.setLinkModule4Note(
            vars.characterId,
            vars.noteId,
            vars.linkModule,
            vars.linkModuleInitData,
            _noteByIdByCharacter
        );
    }

    /// @inheritdoc IWeb3Entry
    function mintNote(
        DataTypes.MintNoteData calldata vars
    ) external override returns (uint256 tokenId) {
        _validateNoteExists(vars.characterId, vars.noteId);

        tokenId = PostLogic.mintNote(
            vars.characterId,
            vars.noteId,
            vars.to,
            vars.mintModuleData,
            MINT_NFT_IMPL,
            _noteByIdByCharacter
        );
    }

    /// @inheritdoc IWeb3Entry
    function setMintModule4Note(DataTypes.setMintModule4NoteData calldata vars) external override {
        _validateCallerPermission(vars.characterId, OP.SET_MINT_MODULE_FOR_NOTE);
        _validateNoteExists(vars.characterId, vars.noteId);
        _validateNoteNotLocked(vars.characterId, vars.noteId);

        PostLogic.setMintModule4Note(
            vars.characterId,
            vars.noteId,
            vars.mintModule,
            vars.mintModuleInitData,
            _noteByIdByCharacter
        );
    }

    /// @inheritdoc IWeb3Entry
    function postNote(
        DataTypes.PostNoteData calldata vars
    ) external override returns (uint256 noteId) {
        _validateCallerPermission(vars.characterId, OP.POST_NOTE);

        noteId = _nextNoteId(vars.characterId);
        PostLogic.postNoteWithLink(vars, noteId, 0, 0, "", _noteByIdByCharacter);
    }

    /// @inheritdoc IWeb3Entry
    function setNoteUri(
        uint256 characterId,
        uint256 noteId,
        string calldata newUri
    ) external override {
        _validateCallerPermission4Note(characterId, noteId);
        _validateNoteExists(characterId, noteId);
        _validateNoteNotLocked(characterId, noteId);

        PostLogic.setNoteUri(characterId, noteId, newUri, _noteByIdByCharacter);
    }

    /// @inheritdoc IWeb3Entry
    function lockNote(uint256 characterId, uint256 noteId) external override {
        _validateCallerPermission(characterId, OP.LOCK_NOTE);
        _validateNoteExists(characterId, noteId);

        _noteByIdByCharacter[characterId][noteId].locked = true;

        emit Events.LockNote(characterId, noteId);
    }

    /// @inheritdoc IWeb3Entry
    function deleteNote(uint256 characterId, uint256 noteId) external override {
        _validateCallerPermission(characterId, OP.DELETE_NOTE);
        _validateNoteExists(characterId, noteId);

        _noteByIdByCharacter[characterId][noteId].deleted = true;

        emit Events.DeleteNote(characterId, noteId);
    }

    /// @inheritdoc IWeb3Entry
    function postNote4Character(
        DataTypes.PostNoteData calldata vars,
        uint256 toCharacterId
    ) external override returns (uint256) {
        _validateCallerPermission(vars.characterId, OP.POST_NOTE_FOR_CHARACTER);

        bytes32 linkItemType = Constants.LINK_ITEM_TYPE_CHARACTER;
        uint256 noteId = _nextNoteId(vars.characterId);
        bytes32 linkKey = bytes32(toCharacterId);

        PostLogic.postNoteWithLink(
            vars,
            noteId,
            linkItemType,
            linkKey,
            abi.encodePacked(toCharacterId),
            _noteByIdByCharacter
        );

        return noteId;
    }

    /// @inheritdoc IWeb3Entry
    function postNote4Address(
        DataTypes.PostNoteData calldata vars,
        address ethAddress
    ) external override returns (uint256) {
        _validateCallerPermission(vars.characterId, OP.POST_NOTE_FOR_ADDRESS);

        bytes32 linkItemType = Constants.LINK_ITEM_TYPE_ADDRESS;
        uint256 noteId = _nextNoteId(vars.characterId);
        bytes32 linkKey = bytes32(uint256(uint160(ethAddress)));

        PostLogic.postNoteWithLink(
            vars,
            noteId,
            linkItemType,
            linkKey,
            abi.encodePacked(ethAddress),
            _noteByIdByCharacter
        );

        return noteId;
    }

    /// @inheritdoc IWeb3Entry
    function postNote4Linklist(
        DataTypes.PostNoteData calldata vars,
        uint256 toLinklistId
    ) external override returns (uint256) {
        _validateCallerPermission(vars.characterId, OP.POST_NOTE_FOR_LINKLIST);

        bytes32 linkItemType = Constants.LINK_ITEM_TYPE_LINKLIST;
        uint256 noteId = _nextNoteId(vars.characterId);
        bytes32 linkKey = bytes32(toLinklistId);

        PostLogic.postNoteWithLink(
            vars,
            noteId,
            linkItemType,
            linkKey,
            abi.encodePacked(toLinklistId),
            _noteByIdByCharacter
        );

        return noteId;
    }

    /// @inheritdoc IWeb3Entry
    function postNote4Note(
        DataTypes.PostNoteData calldata vars,
        DataTypes.NoteStruct calldata note
    ) external override returns (uint256) {
        _validateCallerPermission(vars.characterId, OP.POST_NOTE_FOR_NOTE);

        bytes32 linkItemType = Constants.LINK_ITEM_TYPE_NOTE;
        uint256 noteId = _nextNoteId(vars.characterId);
        bytes32 linkKey = ILinklist(_linklist).addLinkingNote(0, note.characterId, note.noteId);

        PostLogic.postNoteWithLink(
            vars,
            noteId,
            linkItemType,
            linkKey,
            abi.encodePacked(note.characterId, note.noteId),
            _noteByIdByCharacter
        );

        return noteId;
    }

    /// @inheritdoc IWeb3Entry
    function postNote4ERC721(
        DataTypes.PostNoteData calldata vars,
        DataTypes.ERC721Struct calldata erc721
    ) external override returns (uint256) {
        _validateCallerPermission(vars.characterId, OP.POST_NOTE_FOR_ERC721);

        bytes32 linkItemType = Constants.LINK_ITEM_TYPE_ERC721;
        uint256 noteId = _nextNoteId(vars.characterId);
        bytes32 linkKey = ILinklist(_linklist).addLinkingERC721(
            0,
            erc721.tokenAddress,
            erc721.erc721TokenId
        );

        PostLogic.postNoteWithLink(
            vars,
            noteId,
            linkItemType,
            linkKey,
            abi.encodePacked(erc721.tokenAddress, erc721.erc721TokenId),
            _noteByIdByCharacter
        );

        return noteId;
    }

    /// @inheritdoc IWeb3Entry
    function postNote4AnyUri(
        DataTypes.PostNoteData calldata vars,
        string calldata uri
    ) external override returns (uint256) {
        _validateCallerPermission(vars.characterId, OP.POST_NOTE_FOR_ANYURI);

        bytes32 linkItemType = Constants.LINK_ITEM_TYPE_ANYURI;
        uint256 noteId = _nextNoteId(vars.characterId);
        bytes32 linkKey = ILinklist(_linklist).addLinkingAnyUri(0, uri);

        PostLogic.postNoteWithLink(
            vars,
            noteId,
            linkItemType,
            linkKey,
            abi.encodePacked(uri),
            _noteByIdByCharacter
        );

        return noteId;
    }

    /// @inheritdoc IWeb3Entry
    function burnLinklist(uint256 linklistId) external override {
        // only the owner of the character can burn the linklist through web3Entry contract
        uint256 characterId = ILinklist(_linklist).getOwnerCharacterId(linklistId);
        _validateCallerIsCharacterOwner(characterId);

        LinklistLogic.burnLinklist(characterId, linklistId, _linklist, _attachedLinklists);
    }

    /// @inheritdoc IWeb3Entry
    function getOperators(uint256 characterId) external view override returns (address[] memory) {
        return _operatorsByCharacter[characterId].values();
    }

    /// @inheritdoc IWeb3Entry
    function getOperatorPermissions(
        uint256 characterId,
        address operator
    ) external view override returns (uint256) {
        return _operatorsPermissionBitMap[characterId][operator];
    }

    /// @inheritdoc IWeb3Entry
    function getOperators4Note(
        uint256 characterId,
        uint256 noteId
    ) external view override returns (address[] memory blocklist, address[] memory allowlist) {
        blocklist = _operators4Note[characterId][noteId].blocklist.values();
        allowlist = _operators4Note[characterId][noteId].allowlist.values();
    }

    /// @inheritdoc IWeb3Entry
    function isOperatorAllowedForNote(
        uint256 characterId,
        uint256 noteId,
        address operator
    ) external view override returns (bool) {
        return _isOperatorAllowedForNote(characterId, noteId, operator);
    }

    /// @inheritdoc IWeb3Entry
    function getPrimaryCharacterId(address account) external view override returns (uint256) {
        return _primaryCharacterByAddress[account];
    }

    /// @inheritdoc IWeb3Entry
    function isPrimaryCharacter(uint256 characterId) external view override returns (bool) {
        address account = ownerOf(characterId);
        return characterId == _primaryCharacterByAddress[account];
    }

    /// @inheritdoc IWeb3Entry
    function getCharacter(
        uint256 characterId
    ) external view override onlyExistingToken(characterId) returns (DataTypes.Character memory) {
        return _characterById[characterId];
    }

    /// @inheritdoc IWeb3Entry
    function getCharacterByHandle(
        string calldata handle
    ) external view override returns (DataTypes.Character memory) {
        bytes32 handleHash = keccak256(bytes(handle));
        uint256 characterId = _characterIdByHandleHash[handleHash];
        return _characterById[characterId];
    }

    /// @inheritdoc IWeb3Entry
    function getHandle(
        uint256 characterId
    ) external view override onlyExistingToken(characterId) returns (string memory) {
        return _characterById[characterId].handle;
    }

    /// @inheritdoc IWeb3Entry
    function getCharacterUri(uint256 characterId) external view override returns (string memory) {
        return tokenURI(characterId);
    }

    /// @inheritdoc IWeb3Entry
    function getNote(
        uint256 characterId,
        uint256 noteId
    ) external view override returns (DataTypes.Note memory) {
        return _noteByIdByCharacter[characterId][noteId];
    }

    /// @inheritdoc IWeb3Entry
    function getLinklistUri(uint256 tokenId) external view override returns (string memory) {
        return ILinklist(_linklist).Uri(tokenId);
    }

    /// @inheritdoc IWeb3Entry
    function getLinklistId(
        uint256 characterId,
        bytes32 linkType
    ) external view override returns (uint256) {
        return _attachedLinklists[characterId][linkType];
    }

    /// @inheritdoc IWeb3Entry
    function getLinklistType(uint256 linkListId) external view override returns (bytes32) {
        return ILinklist(_linklist).getLinkType(linkListId);
    }

    /// @inheritdoc IWeb3Entry
    function getLinklistContract() external view override returns (address) {
        return _linklist;
    }

    /// @inheritdoc IWeb3Entry
    function getDomainSeparator() external view override returns (bytes32) {
        return _calculateDomainSeparator();
    }

    /// @inheritdoc IWeb3Entry
    function nonces(address owner) external view override returns (uint256) {
        return _sigNonces[owner];
    }

    /// @inheritdoc IWeb3Entry
    function getRevision() external pure override returns (uint256) {
        return REVISION;
    }

    /**
     * @notice Burns a web3Entry character nft.
     * @param tokenId The token ID to burn.
     */
    function burn(uint256 tokenId) public virtual override {
        // clear handle
        bytes32 handleHash = keccak256(bytes(_characterById[tokenId].handle));
        _characterIdByHandleHash[handleHash] = 0;

        // clear character
        delete _characterById[tokenId];

        // burn token
        super.burn(tokenId);
    }

    /**
     * @notice Returns the associated URI with a given character.
     * @param characterId The character ID to query.
     * @return The token URI.
     */
    function tokenURI(
        uint256 characterId
    ) public view override onlyExistingToken(characterId) returns (string memory) {
        return _characterById[characterId].uri;
    }

    function _createCharacter(
        DataTypes.CreateCharacterData memory vars,
        bool validateHandle
    ) internal returns (uint256 characterId) {
        // check if the handle exists
        _checkHandleExists(keccak256(bytes(vars.handle)));

        // check if the handle is valid
        if (validateHandle) {
            _validateHandle(vars.handle);
        }

        characterId = ++_characterCounter;
        // mint character nft
        _safeMint(vars.to, characterId);

        CharacterLogic.createCharacter(
            vars.to,
            vars.handle,
            vars.uri,
            vars.linkModule,
            vars.linkModuleInitData,
            characterId,
            _characterIdByHandleHash,
            _characterById
        );
    }

    /**
     * @dev Operators will be reset to blank before the characters are transferred in order to grant the
     * whole control power to receivers of character transfers.
     * If character is transferred from newbieVilla contract, don't clear operators.
     *
     * Permissions4Note is left unset, because permissions for notes are always stricter than default.
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual override {
        //  clear operators if character is transferred from non-newbieVilla contract
        if (from != _newbieVilla) {
            // clear operators
            uint256 len = _operatorsByCharacter[tokenId].length();
            address[] memory operators = _operatorsByCharacter[tokenId].values();
            for (uint256 i = 0; i < len; i++) {
                _clearOperator(tokenId, operators[i]);
            }

            // reset if `tokenId` is primary character of `from` account
            if (_primaryCharacterByAddress[from] == tokenId) {
                _primaryCharacterByAddress[from] = 0;
            }
        }

        super._beforeTokenTransfer(from, to, tokenId);
    }

    function _afterTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual override {
        // set primary character if `to` account has no primary character
        if (_primaryCharacterByAddress[to] == 0) {
            _primaryCharacterByAddress[to] = tokenId;
        }

        super._afterTokenTransfer(from, to, tokenId);
    }

    function _nextNoteId(uint256 characterId) internal returns (uint256) {
        return ++_characterById[characterId].noteCount;
    }

    function _clearOperator(uint256 tokenId, address operator) internal {
        delete _operatorsPermissionBitMap[tokenId][operator];
        // slither-disable-next-line unused-return
        _operatorsByCharacter[tokenId].remove(operator);
    }

    function _grantOperatorPermissions(
        uint256 characterId,
        address operator,
        uint256 permissionBitMap
    ) internal {
        OperatorLogic.grantOperatorPermissions(
            characterId,
            operator,
            permissionBitMap,
            _operatorsByCharacter,
            _operatorsPermissionBitMap
        );
    }

    function _isOperatorAllowedForNote(
        uint256 characterId,
        uint256 noteId,
        address operator
    ) internal view returns (bool) {
        DataTypes.Operators4Note storage op = _operators4Note[characterId][noteId];

        // check blocklist
        if (op.blocklist.contains(operator)) {
            return false;
        }
        // check allowlist
        if (op.allowlist.contains(operator)) {
            return true;
        }
        // check character operator permission
        return _checkBit(_operatorsPermissionBitMap[characterId][operator], OP.SET_NOTE_URI);
    }

    // check if the handle exists
    function _checkHandleExists(bytes32 handleHash) internal view {
        if (_characterIdByHandleHash[handleHash] != 0) revert ErrHandleExists();
    }

    function _validateCallerIsCharacterOwner(uint256 characterId) internal view {
        address owner = ownerOf(characterId);

        // tx.origin is character owner, and msg.sender is periphery
        // solhint-disable-next-line avoid-tx-origin
        if (msg.sender == _periphery && tx.origin == owner) {
            return;
        }

        // msg.sender is character owner
        if (msg.sender == owner) {
            return;
        }

        revert ErrNotCharacterOwner();
    }

    function _validateCallerPermission(uint256 characterId, uint256 permissionId) internal view {
        // check character owner
        if (_callerIsCharacterOwner(characterId)) {
            return;
        }

        // check operator permission for tx.origin
        if (msg.sender == _periphery) {
            // solhint-disable-next-line avoid-tx-origin
            if (_checkBit(_operatorsPermissionBitMap[characterId][tx.origin], permissionId)) {
                return;
            }
        }

        //  check operator permission for msg.sender
        if (_checkBit(_operatorsPermissionBitMap[characterId][msg.sender], permissionId)) {
            return;
        }

        revert ErrNotEnoughPermission();
    }

    function _callerIsCharacterOwner(uint256 characterId) internal view returns (bool) {
        address owner = ownerOf(characterId);

        if (msg.sender == owner) {
            // caller is character owner
            return true;
        }

        // solhint-disable-next-line avoid-tx-origin
        if (msg.sender == _periphery && tx.origin == owner) {
            // caller is periphery, and tx.origin is character owner
            return true;
        }

        return false;
    }

    function _validateCallerPermission4Note(uint256 characterId, uint256 noteId) internal view {
        // check character owner
        if (_callerIsCharacterOwner(characterId)) {
            return;
        }

        // check note permission for tx.origin
        if (msg.sender == _periphery) {
            // solhint-disable-next-line avoid-tx-origin
            if (_isOperatorAllowedForNote(characterId, noteId, tx.origin)) {
                return;
            }
        }

        // check note permission for caller
        if (_isOperatorAllowedForNote(characterId, noteId, msg.sender)) {
            return;
        }

        revert ErrNotEnoughPermissionForThisNote();
    }

    function _validateCharacterExists(uint256 characterId) internal view {
        if (!_exists(characterId)) revert ErrCharacterNotExists(characterId);
    }

    function _validateNoteExists(uint256 characterId, uint256 noteId) internal view {
        if (_noteByIdByCharacter[characterId][noteId].deleted) revert ErrNoteIsDeleted();
        if (noteId > _characterById[characterId].noteCount) revert ErrNoteNotExists();
    }

    function _validateNoteNotLocked(uint256 characterId, uint256 noteId) internal view {
        if (_noteByIdByCharacter[characterId][noteId].locked) revert ErrNoteLocked();
    }

    /**
     * @dev Calculates EIP712 DOMAIN_SEPARATOR based on the current contract and chain ID.
     */
    function _calculateDomainSeparator() internal view returns (bytes32) {
        return
            keccak256(
                abi.encode(
                    EIP712_DOMAIN_TYPEHASH,
                    keccak256(bytes(name())),
                    1,
                    block.chainid,
                    address(this)
                )
            );
    }

    /**
     * @dev Wrapper for ecrecover to reduce code size, used in meta-tx specific functions.
     */
    function _validateRecoveredAddress(
        bytes32 digest,
        address expectedAddress,
        DataTypes.EIP712Signature calldata sig
    ) internal view {
        // slither-disable-next-line timestamp
        if (sig.deadline < block.timestamp) revert ErrSignatureExpired();
        address recoveredAddress = ecrecover(digest, sig.v, sig.r, sig.s);
        if (recoveredAddress == address(0) || recoveredAddress != expectedAddress)
            revert ErrSignatureInvalid();
    }

    function _validateHandle(string memory handle) internal pure {
        bytes memory byteHandle = bytes(handle);
        uint256 len = byteHandle.length;
        if (len > Constants.MAX_HANDLE_LENGTH || len < Constants.MIN_HANDLE_LENGTH)
            revert ErrHandleLengthInvalid();

        for (uint256 i = 0; i < len; ) {
            _validateChar(byteHandle[i]);

            unchecked {
                ++i;
            }
        }
    }

    function _validateChar(bytes1 c) internal pure {
        // char range: [0,9][a,z][-][_]
        if ((c < "0" || c > "z" || (c > "9" && c < "a")) && c != "-" && c != "_")
            revert ErrHandleContainsInvalidCharacters();
    }

    /**
     * @dev _checkBit checks if the value of the i'th bit of x is 1
     */
    function _checkBit(uint256 x, uint256 i) internal pure returns (bool) {
        return (x >> i) & 1 == 1;
    }

    /**
     * @dev _addressToHexString converts an address to its ASCII `string hexadecimal representation.
     */
    function _addressToHexString(address addr) internal pure returns (string memory) {
        bytes16 symbols = "0123456789abcdef";
        uint256 value = uint256(uint160(addr));

        bytes memory buffer = new bytes(42);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 41; i > 1; ) {
            buffer[i] = symbols[value & 0xf];
            value >>= 4;

            unchecked {
                --i;
            }
        }
        return string(buffer);
    }
}
          

@openzeppelin/contracts/utils/structs/EnumerableSet.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner);
        bytes32[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}
          

contracts/base/ERC721.sol

// SPDX-License-Identifier: MIT
// solhint-disable ordering
pragma solidity 0.8.18;

import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import {IERC721Metadata} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {Context} from "@openzeppelin/contracts/utils/Context.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol";

/**
 * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
 * the Metadata extension, but not including the Enumerable extension, which is available separately as
 * {ERC721Enumerable}.
 */
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
    using Address for address;
    using Strings for uint256;

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

    // Mapping from token ID to owner address
    mapping(uint256 => address) private _owners;

    // Mapping owner address to token count
    mapping(address => uint256) private _balances;

    // Mapping from token ID to approved address
    mapping(uint256 => address) private _tokenApprovals;

    // Mapping from owner to operator approvals
    mapping(address => mapping(address => bool)) private _operatorApprovals;

    // slither-disable-start naming-convention
    // solhint-disable-next-line func-name-mixedcase
    function __ERC721_Init(string calldata name_, string calldata symbol_) internal {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(
        bytes4 interfaceId
    ) public view virtual override(ERC165, IERC165) returns (bool) {
        return
            interfaceId == type(IERC721).interfaceId ||
            interfaceId == type(IERC721Metadata).interfaceId ||
            super.supportsInterface(interfaceId);
    }

    /**
     * @dev See {IERC721-balanceOf}.
     */
    function balanceOf(address owner) public view virtual override returns (uint256) {
        require(owner != address(0), "ERC721: balance query for the zero address");
        return _balances[owner];
    }

    /**
     * @dev See {IERC721-ownerOf}.
     */
    function ownerOf(uint256 tokenId) public view virtual override returns (address) {
        address owner = _owners[tokenId];
        require(owner != address(0), "ERC721: owner query for nonexistent token");
        return owner;
    }

    /**
     * @dev See {IERC721Metadata-name}.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev See {IERC721Metadata-symbol}.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev See {IERC721Metadata-tokenURI}.
     */
    function tokenURI(uint256) public view virtual override returns (string memory) {
        return "";
    }

    /**
     * @dev See {IERC721-approve}.
     */
    function approve(address to, uint256 tokenId) public virtual override {
        address owner = ERC721.ownerOf(tokenId);
        require(to != owner, "ERC721: approval to current owner");

        require(
            _msgSender() == owner || isApprovedForAll(owner, _msgSender()),
            "ERC721: approve caller is not owner nor approved for all"
        );

        _approve(to, tokenId);
    }

    /**
     * @dev See {IERC721-getApproved}.
     */
    function getApproved(uint256 tokenId) public view virtual override returns (address) {
        require(_exists(tokenId), "ERC721: approved query for nonexistent token");

        return _tokenApprovals[tokenId];
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        _setApprovalForAll(_msgSender(), operator, approved);
    }

    /**
     * @dev See {IERC721-isApprovedForAll}.
     */
    function isApprovedForAll(
        address owner,
        address operator
    ) public view virtual override returns (bool) {
        return _operatorApprovals[owner][operator];
    }

    /**
     * @dev See {IERC721-transferFrom}.
     */
    function transferFrom(address from, address to, uint256 tokenId) public virtual override {
        //solhint-disable-next-line max-line-length
        require(
            _isApprovedOrOwner(_msgSender(), tokenId),
            "ERC721: transfer caller is not owner nor approved"
        );

        _transfer(from, to, tokenId);
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
        safeTransferFrom(from, to, tokenId, "");
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data // solhint-disable private-vars-leading-underscore
    ) public virtual override {
        require(
            _isApprovedOrOwner(_msgSender(), tokenId),
            "ERC721: transfer caller is not owner nor approved"
        );
        _safeTransfer(from, to, tokenId, _data);
    }

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * `_data` is additional data, it has no specified format and it is sent in call to `to`.
     *
     * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
     * implement alternative mechanisms to perform token transfer, such as signature-based.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received},
     * which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeTransfer(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data // solhint-disable private-vars-leading-underscore
    ) internal virtual {
        _transfer(from, to, tokenId);
        require(
            _checkOnERC721Received(from, to, tokenId, _data),
            "ERC721: transfer to non ERC721Receiver implementer"
        );
    }

    /**
     * @dev Returns whether `tokenId` exists.
     *
     * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
     *
     * Tokens start existing when they are minted (`_mint`),
     * and stop existing when they are burned (`_burn`).
     */
    function _exists(uint256 tokenId) internal view virtual returns (bool) {
        return _owners[tokenId] != address(0);
    }

    /**
     * @dev Returns whether `spender` is allowed to manage `tokenId`.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function _isApprovedOrOwner(
        address spender,
        uint256 tokenId
    ) internal view virtual returns (bool) {
        require(_exists(tokenId), "ERC721: operator query for nonexistent token");
        address owner = ERC721.ownerOf(tokenId);
        return (spender == owner ||
            getApproved(tokenId) == spender ||
            isApprovedForAll(owner, spender));
    }

    /**
     * @dev Safely mints `tokenId` and transfers it to `to`.
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received},
     * which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeMint(address to, uint256 tokenId) internal virtual {
        _safeMint(to, tokenId, "");
    }

    /**
     * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
     */
    function _safeMint(
        address to,
        uint256 tokenId,
        bytes memory _data // solhint-disable private-vars-leading-underscore
    ) internal virtual {
        _mint(to, tokenId);
        require(
            _checkOnERC721Received(address(0), to, tokenId, _data),
            "ERC721: transfer to non ERC721Receiver implementer"
        );
    }

    /**
     * @dev Mints `tokenId` and transfers it to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - `to` cannot be the zero address.
     *
     * Emits a {Transfer} event.
     */
    function _mint(address to, uint256 tokenId) internal virtual {
        require(to != address(0), "ERC721: mint to the zero address");
        require(!_exists(tokenId), "ERC721: token already minted");

        _beforeTokenTransfer(address(0), to, tokenId);

        _balances[to] += 1;
        _owners[tokenId] = to;

        emit Transfer(address(0), to, tokenId);

        _afterTokenTransfer(address(0), to, tokenId);
    }

    /**
     * @dev Destroys `tokenId`.
     * The approval is cleared when the token is burned.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     *
     * Emits a {Transfer} event.
     */
    function _burn(uint256 tokenId) internal virtual {
        address owner = ERC721.ownerOf(tokenId);

        _beforeTokenTransfer(owner, address(0), tokenId);

        // Clear approvals
        _approve(address(0), tokenId);

        _balances[owner] -= 1;
        delete _owners[tokenId];

        emit Transfer(owner, address(0), tokenId);

        _afterTokenTransfer(owner, address(0), tokenId);
    }

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     *
     * Emits a {Transfer} event.
     */
    function _transfer(address from, address to, uint256 tokenId) internal virtual {
        require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
        require(to != address(0), "ERC721: transfer to the zero address");

        _beforeTokenTransfer(from, to, tokenId);

        // Clear approvals from the previous owner
        _approve(address(0), tokenId);

        _balances[from] -= 1;
        _balances[to] += 1;
        _owners[tokenId] = to;

        emit Transfer(from, to, tokenId);

        _afterTokenTransfer(from, to, tokenId);
    }

    /**
     * @dev Approve `to` to operate on `tokenId`
     *
     * Emits a {Approval} event.
     */
    function _approve(address to, uint256 tokenId) internal virtual {
        _tokenApprovals[tokenId] = to;
        emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
    }

    /**
     * @dev Approve `operator` to operate on all of `owner` tokens
     *
     * Emits a {ApprovalForAll} event.
     */
    function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
        require(owner != operator, "ERC721: approve to caller");
        _operatorApprovals[owner][operator] = approved;
        emit ApprovalForAll(owner, operator, approved);
    }

    /**
     * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
     * The call is not executed if the target address is not a contract.
     *
     * @param from address representing the previous owner of the given token ID
     * @param to target address that will receive the tokens
     * @param tokenId uint256 ID of the token to be transferred
     * @param _data bytes optional data to send along with the call
     * @return bool whether the call correctly returned the expected magic value
     */
    // slither-disable-next-line unused-return
    function _checkOnERC721Received(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data // solhint-disable private-vars-leading-underscore
    ) private returns (bool) {
        if (to.isContract()) {
            // slither-disable-start variable-scope
            try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (
                bytes4 retval
            ) {
                return retval == IERC721Receiver.onERC721Received.selector;
            } catch (bytes memory reason) {
                if (reason.length == 0) {
                    revert("ERC721: transfer to non ERC721Receiver implementer");
                } else {
                    /* solhint-disable no-inline-assembly */
                    assembly {
                        revert(add(32, reason), mload(reason))
                    }
                    /* solhint-enable no-inline-assembly */
                }
            }
            // slither-disable-end variable-scope
        } else {
            return true;
        }
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting
     * and burning.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
     * transferred to `to`.
     * - When `from` is zero, `tokenId` will be minted for `to`.
     * - When `to` is zero, ``from``'s `tokenId` will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    // solhint-disable-next-line no-empty-blocks
    function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    // solhint-disable-next-line no-empty-blocks
    function _afterTokenTransfer(address from, address to, uint256 tokenId) internal virtual {}
    // slither-disable-end naming-convention
}
          

contracts/libraries/LinklistLogic.sol

// SPDX-License-Identifier: MIT
// solhint-disable  private-vars-leading-underscore
pragma solidity 0.8.18;

import {Events} from "./Events.sol";
import {ILinklist} from "../interfaces/ILinklist.sol";
import {ErrLinkTypeExists} from "./Error.sol";

library LinklistLogic {
    function setLinklistUri(uint256 linklistId, string calldata uri, address linklist) external {
        ILinklist(linklist).setUri(linklistId, uri);
    }

    function setLinklistType(
        uint256 characterId,
        uint256 linklistId,
        bytes32 linkType,
        address linklist,
        mapping(uint256 => mapping(bytes32 => uint256)) storage _attachedLinklists
    ) external {
        // check linklist exists
        if (0 != _attachedLinklists[characterId][linkType])
            revert ErrLinkTypeExists(characterId, linkType);

        // detach linklist
        bytes32 oldLinkType = ILinklist(linklist).getLinkType(linklistId);
        delete _attachedLinklists[characterId][oldLinkType];
        emit Events.DetachLinklist(linklistId, characterId, oldLinkType);

        // attach linklist
        _attachedLinklists[characterId][linkType] = linklistId;
        emit Events.AttachLinklist(linklistId, characterId, linkType);

        // set linklist type
        ILinklist(linklist).setLinkType(linklistId, linkType);
    }

    function burnLinklist(
        uint256 characterId,
        uint256 linklistId,
        address linklist,
        mapping(uint256 => mapping(bytes32 => uint256)) storage _attachedLinklists
    ) external {
        // delete _attachedLinklist
        bytes32 linkType = ILinklist(linklist).getLinkType(linklistId);
        delete _attachedLinklists[characterId][linkType];

        // burn linklist
        ILinklist(linklist).burn(linklistId);
    }
}
          

contracts/storage/Web3EntryExtendStorage.sol

// SPDX-License-Identifier: MIT
// slither-disable-start naming-convention
pragma solidity 0.8.18;

import {DataTypes} from "../libraries/DataTypes.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

contract Web3EntryExtendStorage {
    address internal _periphery; // slot 21
    // slither-disable-next-line unused-state
    mapping(uint256 => address) internal _operatorByCharacter; // unused slot 22
    // slither-disable-next-line constable-states
    address public resolver; // unused slot 23
    mapping(uint256 => EnumerableSet.AddressSet) internal _operatorsByCharacter; //slot 24
    // characterId => operator => permissionsBitMap
    mapping(uint256 => mapping(address => uint256)) internal _operatorsPermissionBitMap; // slot 25
    // characterId => noteId => Operators4Note
    // only for set note uri
    mapping(uint256 => mapping(uint256 => DataTypes.Operators4Note)) internal _operators4Note; // slot 26

    address internal _newbieVilla; // address of newbieVilla contract

    mapping(address => uint256) internal _sigNonces; // for replay protection // slot 28
}
// slither-disable-end naming-convention
          

contracts/storage/Web3EntryStorage.sol

// SPDX-License-Identifier: MIT
// slither-disable-start naming-convention
pragma solidity 0.8.18;

import {DataTypes} from "../libraries/DataTypes.sol";

contract Web3EntryStorage {
    // solhint-disable-next-line private-vars-leading-underscore, var-name-mixedcase
    bytes32 internal constant EIP712_DOMAIN_TYPEHASH =
        keccak256(
            "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
        );
    // solhint-disable-next-line private-vars-leading-underscore, var-name-mixedcase
    bytes32 internal constant GRANT_OPERATOR_PERMISSIONS_WITH_SIG_TYPEHASH =
        keccak256( // solhint-disable-next-line max-line-length
            "grantOperatorPermissions(uint256 characterId,address operator,uint256 permissionBitMap,uint256 nonce,uint256 deadline)"
        );

    // characterId => Character
    mapping(uint256 => DataTypes.Character) internal _characterById;
    // handleHash => characterId
    mapping(bytes32 => uint256) internal _characterIdByHandleHash;
    // address => characterId
    mapping(address => uint256) internal _primaryCharacterByAddress;

    // characterId =>  (linkType => linklistId)
    mapping(uint256 => mapping(bytes32 => uint256)) internal _attachedLinklists;

    // characterId => noteId => Note
    mapping(uint256 => mapping(uint256 => DataTypes.Note)) internal _noteByIdByCharacter; // slot 14

    /////////////////////////////////
    // link modules
    /////////////////////////////////

    // tokenId => linkModule4Linklist
    mapping(uint256 => address) internal _linkModules4Linklist;

    // tokenAddress => tokenId => linkModule4ERC721
    /// @dev disable `uninitialized-state` check, as linkmodule for erc721 is not enabled currently
    // slither-disable-next-line uninitialized-state
    mapping(address => mapping(uint256 => address)) internal _linkModules4ERC721;

    // address => linkModule4Address
    mapping(address => address) internal _linkModules4Address;

    uint256 internal _characterCounter;
    // LinkList NFT token contract
    address internal _linklist;
    // solhint-disable-next-line private-vars-leading-underscore, var-name-mixedcase
    address internal MINT_NFT_IMPL;
}
// slither-disable-end naming-convention
          

@openzeppelin/contracts/proxy/Clones.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/Clones.sol)

pragma solidity ^0.8.0;

/**
 * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for
 * deploying minimal proxy contracts, also known as "clones".
 *
 * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
 * > a minimal bytecode implementation that delegates all calls to a known, fixed address.
 *
 * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
 * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
 * deterministic method.
 *
 * _Available since v3.4._
 */
library Clones {
    /**
     * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
     *
     * This function uses the create opcode, which should never revert.
     */
    function clone(address implementation) internal returns (address instance) {
        /// @solidity memory-safe-assembly
        assembly {
            // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
            // of the `implementation` address with the bytecode before the address.
            mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
            // Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
            mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
            instance := create(0, 0x09, 0x37)
        }
        require(instance != address(0), "ERC1167: create failed");
    }

    /**
     * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
     *
     * This function uses the create2 opcode and a `salt` to deterministically deploy
     * the clone. Using the same `implementation` and `salt` multiple time will revert, since
     * the clones cannot be deployed twice at the same address.
     */
    function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
        /// @solidity memory-safe-assembly
        assembly {
            // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
            // of the `implementation` address with the bytecode before the address.
            mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
            // Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
            mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
            instance := create2(0, 0x09, 0x37, salt)
        }
        require(instance != address(0), "ERC1167: create2 failed");
    }

    /**
     * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
     */
    function predictDeterministicAddress(
        address implementation,
        bytes32 salt,
        address deployer
    ) internal pure returns (address predicted) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(add(ptr, 0x38), deployer)
            mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff)
            mstore(add(ptr, 0x14), implementation)
            mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73)
            mstore(add(ptr, 0x58), salt)
            mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37))
            predicted := keccak256(add(ptr, 0x43), 0x55)
        }
    }

    /**
     * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
     */
    function predictDeterministicAddress(
        address implementation,
        bytes32 salt
    ) internal view returns (address predicted) {
        return predictDeterministicAddress(implementation, salt, address(this));
    }
}
          

@openzeppelin/contracts/utils/introspection/ERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}
          

contracts/libraries/Constants.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

library Constants {
    uint8 public constant MAX_HANDLE_LENGTH = 31;
    uint8 public constant MIN_HANDLE_LENGTH = 3;

    // constants for linkItemType of note struct
    bytes32 public constant LINK_ITEM_TYPE_CHARACTER = "Character";
    bytes32 public constant LINK_ITEM_TYPE_ADDRESS = "Address";
    bytes32 public constant LINK_ITEM_TYPE_LINKLIST = "Linklist";
    bytes32 public constant LINK_ITEM_TYPE_NOTE = "Note";
    bytes32 public constant LINK_ITEM_TYPE_ERC721 = "ERC721";
    bytes32 public constant LINK_ITEM_TYPE_ANYURI = "AnyUri";
}
          

Compiler Settings

{"outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers","metadata"],"":["ast"]}},"optimizer":{"runs":200,"enabled":true},"libraries":{"contracts/libraries/PostLogic.sol":{"PostLogic":"0xbb3c660ad95306d4b3e6844a89f236a0233d52f2"},"contracts/libraries/OperatorLogic.sol":{"OperatorLogic":"0xf29b2c1b0722a9ab38062622133503c21a853e8f"},"contracts/libraries/LinklistLogic.sol":{"LinklistLogic":"0xc8f036a975b7a64cc05808779aedb58d859852a6"},"contracts/libraries/LinkLogic.sol":{"LinkLogic":"0x1e58988e34177c407a639f380a9d835223ab79f7"},"contracts/libraries/CharacterLogic.sol":{"CharacterLogic":"0x681be951fa8b6731e9330291331aef94e8b9905c"}}}
              

Contract ABI

[{"type":"error","name":"ErrCharacterNotExists","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"}]},{"type":"error","name":"ErrHandleContainsInvalidCharacters","inputs":[]},{"type":"error","name":"ErrHandleExists","inputs":[]},{"type":"error","name":"ErrHandleLengthInvalid","inputs":[]},{"type":"error","name":"ErrNotCharacterOwner","inputs":[]},{"type":"error","name":"ErrNotEnoughPermission","inputs":[]},{"type":"error","name":"ErrNotEnoughPermissionForThisNote","inputs":[]},{"type":"error","name":"ErrNoteIsDeleted","inputs":[]},{"type":"error","name":"ErrNoteLocked","inputs":[]},{"type":"error","name":"ErrNoteNotExists","inputs":[]},{"type":"error","name":"ErrSignatureExpired","inputs":[]},{"type":"error","name":"ErrSignatureInvalid","inputs":[]},{"type":"error","name":"ErrSocialTokenExists","inputs":[]},{"type":"error","name":"ErrTokenNotExists","inputs":[]},{"type":"event","name":"Approval","inputs":[{"type":"address","name":"owner","internalType":"address","indexed":true},{"type":"address","name":"approved","internalType":"address","indexed":true},{"type":"uint256","name":"tokenId","internalType":"uint256","indexed":true}],"anonymous":false},{"type":"event","name":"ApprovalForAll","inputs":[{"type":"address","name":"owner","internalType":"address","indexed":true},{"type":"address","name":"operator","internalType":"address","indexed":true},{"type":"bool","name":"approved","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"Initialized","inputs":[{"type":"uint8","name":"version","internalType":"uint8","indexed":false}],"anonymous":false},{"type":"event","name":"Transfer","inputs":[{"type":"address","name":"from","internalType":"address","indexed":true},{"type":"address","name":"to","internalType":"address","indexed":true},{"type":"uint256","name":"tokenId","internalType":"uint256","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"approve","inputs":[{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"balanceOf","inputs":[{"type":"address","name":"owner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"burn","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"burnLinklist","inputs":[{"type":"uint256","name":"linklistId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"characterId","internalType":"uint256"}],"name":"createCharacter","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.CreateCharacterData","components":[{"type":"address","name":"to","internalType":"address"},{"type":"string","name":"handle","internalType":"string"},{"type":"string","name":"uri","internalType":"string"},{"type":"address","name":"linkModule","internalType":"address"},{"type":"bytes","name":"linkModuleInitData","internalType":"bytes"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"characterId","internalType":"uint256"}],"name":"createThenLinkCharacter","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.createThenLinkCharacterData","components":[{"type":"uint256","name":"fromCharacterId","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"bytes32","name":"linkType","internalType":"bytes32"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"deleteNote","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"uint256","name":"noteId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"getApproved","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct DataTypes.Character","components":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"string","name":"handle","internalType":"string"},{"type":"string","name":"uri","internalType":"string"},{"type":"uint256","name":"noteCount","internalType":"uint256"},{"type":"address","name":"socialToken","internalType":"address"},{"type":"address","name":"linkModule","internalType":"address"}]}],"name":"getCharacter","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct DataTypes.Character","components":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"string","name":"handle","internalType":"string"},{"type":"string","name":"uri","internalType":"string"},{"type":"uint256","name":"noteCount","internalType":"uint256"},{"type":"address","name":"socialToken","internalType":"address"},{"type":"address","name":"linkModule","internalType":"address"}]}],"name":"getCharacterByHandle","inputs":[{"type":"string","name":"handle","internalType":"string"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"getCharacterUri","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"getDomainSeparator","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"getHandle","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"getLinklistContract","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getLinklistId","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"bytes32","name":"linkType","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"getLinklistType","inputs":[{"type":"uint256","name":"linkListId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"getLinklistUri","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct DataTypes.Note","components":[{"type":"bytes32","name":"linkItemType","internalType":"bytes32"},{"type":"bytes32","name":"linkKey","internalType":"bytes32"},{"type":"string","name":"contentUri","internalType":"string"},{"type":"address","name":"linkModule","internalType":"address"},{"type":"address","name":"mintModule","internalType":"address"},{"type":"address","name":"mintNFT","internalType":"address"},{"type":"bool","name":"deleted","internalType":"bool"},{"type":"bool","name":"locked","internalType":"bool"}]}],"name":"getNote","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"uint256","name":"noteId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getOperatorPermissions","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"address","name":"operator","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address[]","name":"","internalType":"address[]"}],"name":"getOperators","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address[]","name":"blocklist","internalType":"address[]"},{"type":"address[]","name":"allowlist","internalType":"address[]"}],"name":"getOperators4Note","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"uint256","name":"noteId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getPrimaryCharacterId","inputs":[{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"pure","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getRevision","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"grantOperatorPermissions","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"address","name":"operator","internalType":"address"},{"type":"uint256","name":"permissionBitMap","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"grantOperatorPermissionsWithSig","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"address","name":"operator","internalType":"address"},{"type":"uint256","name":"permissionBitMap","internalType":"uint256"},{"type":"tuple","name":"sig","internalType":"struct DataTypes.EIP712Signature","components":[{"type":"uint8","name":"v","internalType":"uint8"},{"type":"bytes32","name":"r","internalType":"bytes32"},{"type":"bytes32","name":"s","internalType":"bytes32"},{"type":"uint256","name":"deadline","internalType":"uint256"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"grantOperators4Note","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"uint256","name":"noteId","internalType":"uint256"},{"type":"address[]","name":"blocklist","internalType":"address[]"},{"type":"address[]","name":"allowlist","internalType":"address[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[{"type":"string","name":"name_","internalType":"string"},{"type":"string","name":"symbol_","internalType":"string"},{"type":"address","name":"linklist_","internalType":"address"},{"type":"address","name":"mintNFTImpl_","internalType":"address"},{"type":"address","name":"periphery_","internalType":"address"},{"type":"address","name":"newbieVilla_","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isApprovedForAll","inputs":[{"type":"address","name":"owner","internalType":"address"},{"type":"address","name":"operator","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isOperatorAllowedForNote","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"uint256","name":"noteId","internalType":"uint256"},{"type":"address","name":"operator","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isPrimaryCharacter","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"linkAddress","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.linkAddressData","components":[{"type":"uint256","name":"fromCharacterId","internalType":"uint256"},{"type":"address","name":"ethAddress","internalType":"address"},{"type":"bytes32","name":"linkType","internalType":"bytes32"},{"type":"bytes","name":"data","internalType":"bytes"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"linkAnyUri","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.linkAnyUriData","components":[{"type":"uint256","name":"fromCharacterId","internalType":"uint256"},{"type":"string","name":"toUri","internalType":"string"},{"type":"bytes32","name":"linkType","internalType":"bytes32"},{"type":"bytes","name":"data","internalType":"bytes"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"linkCharacter","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.linkCharacterData","components":[{"type":"uint256","name":"fromCharacterId","internalType":"uint256"},{"type":"uint256","name":"toCharacterId","internalType":"uint256"},{"type":"bytes32","name":"linkType","internalType":"bytes32"},{"type":"bytes","name":"data","internalType":"bytes"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"linkERC721","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.linkERC721Data","components":[{"type":"uint256","name":"fromCharacterId","internalType":"uint256"},{"type":"address","name":"tokenAddress","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"bytes32","name":"linkType","internalType":"bytes32"},{"type":"bytes","name":"data","internalType":"bytes"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"linkLinklist","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.linkLinklistData","components":[{"type":"uint256","name":"fromCharacterId","internalType":"uint256"},{"type":"uint256","name":"toLinkListId","internalType":"uint256"},{"type":"bytes32","name":"linkType","internalType":"bytes32"},{"type":"bytes","name":"data","internalType":"bytes"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"linkNote","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.linkNoteData","components":[{"type":"uint256","name":"fromCharacterId","internalType":"uint256"},{"type":"uint256","name":"toCharacterId","internalType":"uint256"},{"type":"uint256","name":"toNoteId","internalType":"uint256"},{"type":"bytes32","name":"linkType","internalType":"bytes32"},{"type":"bytes","name":"data","internalType":"bytes"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"lockNote","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"uint256","name":"noteId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"}],"name":"mintNote","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.MintNoteData","components":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"uint256","name":"noteId","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"bytes","name":"mintModuleData","internalType":"bytes"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bytes[]","name":"results","internalType":"bytes[]"}],"name":"multicall","inputs":[{"type":"bytes[]","name":"data","internalType":"bytes[]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"name","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"nonces","inputs":[{"type":"address","name":"owner","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"ownerOf","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"noteId","internalType":"uint256"}],"name":"postNote","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.PostNoteData","components":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"string","name":"contentUri","internalType":"string"},{"type":"address","name":"linkModule","internalType":"address"},{"type":"bytes","name":"linkModuleInitData","internalType":"bytes"},{"type":"address","name":"mintModule","internalType":"address"},{"type":"bytes","name":"mintModuleInitData","internalType":"bytes"},{"type":"bool","name":"locked","internalType":"bool"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"postNote4Address","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.PostNoteData","components":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"string","name":"contentUri","internalType":"string"},{"type":"address","name":"linkModule","internalType":"address"},{"type":"bytes","name":"linkModuleInitData","internalType":"bytes"},{"type":"address","name":"mintModule","internalType":"address"},{"type":"bytes","name":"mintModuleInitData","internalType":"bytes"},{"type":"bool","name":"locked","internalType":"bool"}]},{"type":"address","name":"ethAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"postNote4AnyUri","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.PostNoteData","components":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"string","name":"contentUri","internalType":"string"},{"type":"address","name":"linkModule","internalType":"address"},{"type":"bytes","name":"linkModuleInitData","internalType":"bytes"},{"type":"address","name":"mintModule","internalType":"address"},{"type":"bytes","name":"mintModuleInitData","internalType":"bytes"},{"type":"bool","name":"locked","internalType":"bool"}]},{"type":"string","name":"uri","internalType":"string"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"postNote4Character","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.PostNoteData","components":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"string","name":"contentUri","internalType":"string"},{"type":"address","name":"linkModule","internalType":"address"},{"type":"bytes","name":"linkModuleInitData","internalType":"bytes"},{"type":"address","name":"mintModule","internalType":"address"},{"type":"bytes","name":"mintModuleInitData","internalType":"bytes"},{"type":"bool","name":"locked","internalType":"bool"}]},{"type":"uint256","name":"toCharacterId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"postNote4ERC721","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.PostNoteData","components":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"string","name":"contentUri","internalType":"string"},{"type":"address","name":"linkModule","internalType":"address"},{"type":"bytes","name":"linkModuleInitData","internalType":"bytes"},{"type":"address","name":"mintModule","internalType":"address"},{"type":"bytes","name":"mintModuleInitData","internalType":"bytes"},{"type":"bool","name":"locked","internalType":"bool"}]},{"type":"tuple","name":"erc721","internalType":"struct DataTypes.ERC721Struct","components":[{"type":"address","name":"tokenAddress","internalType":"address"},{"type":"uint256","name":"erc721TokenId","internalType":"uint256"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"postNote4Linklist","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.PostNoteData","components":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"string","name":"contentUri","internalType":"string"},{"type":"address","name":"linkModule","internalType":"address"},{"type":"bytes","name":"linkModuleInitData","internalType":"bytes"},{"type":"address","name":"mintModule","internalType":"address"},{"type":"bytes","name":"mintModuleInitData","internalType":"bytes"},{"type":"bool","name":"locked","internalType":"bool"}]},{"type":"uint256","name":"toLinklistId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"postNote4Note","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.PostNoteData","components":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"string","name":"contentUri","internalType":"string"},{"type":"address","name":"linkModule","internalType":"address"},{"type":"bytes","name":"linkModuleInitData","internalType":"bytes"},{"type":"address","name":"mintModule","internalType":"address"},{"type":"bytes","name":"mintModuleInitData","internalType":"bytes"},{"type":"bool","name":"locked","internalType":"bool"}]},{"type":"tuple","name":"note","internalType":"struct DataTypes.NoteStruct","components":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"uint256","name":"noteId","internalType":"uint256"}]}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"resolver","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"safeTransferFrom","inputs":[{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"safeTransferFrom","inputs":[{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"bytes","name":"_data","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setApprovalForAll","inputs":[{"type":"address","name":"operator","internalType":"address"},{"type":"bool","name":"approved","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setCharacterUri","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"string","name":"newUri","internalType":"string"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setHandle","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"string","name":"newHandle","internalType":"string"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setLinkModule4Character","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.setLinkModule4CharacterData","components":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"address","name":"linkModule","internalType":"address"},{"type":"bytes","name":"linkModuleInitData","internalType":"bytes"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setLinkModule4Note","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.setLinkModule4NoteData","components":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"uint256","name":"noteId","internalType":"uint256"},{"type":"address","name":"linkModule","internalType":"address"},{"type":"bytes","name":"linkModuleInitData","internalType":"bytes"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setLinklistType","inputs":[{"type":"uint256","name":"linklistId","internalType":"uint256"},{"type":"bytes32","name":"linkType","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setLinklistUri","inputs":[{"type":"uint256","name":"linklistId","internalType":"uint256"},{"type":"string","name":"uri","internalType":"string"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setMintModule4Note","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.setMintModule4NoteData","components":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"uint256","name":"noteId","internalType":"uint256"},{"type":"address","name":"mintModule","internalType":"address"},{"type":"bytes","name":"mintModuleInitData","internalType":"bytes"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setNoteUri","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"uint256","name":"noteId","internalType":"uint256"},{"type":"string","name":"newUri","internalType":"string"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setPrimaryCharacterId","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setSocialToken","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"},{"type":"address","name":"tokenAddress","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"supportsInterface","inputs":[{"type":"bytes4","name":"interfaceId","internalType":"bytes4"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"symbol","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"tokenByIndex","inputs":[{"type":"uint256","name":"index","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"tokenOfOwnerByIndex","inputs":[{"type":"address","name":"owner","internalType":"address"},{"type":"uint256","name":"index","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"tokenURI","inputs":[{"type":"uint256","name":"characterId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalSupply","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferFrom","inputs":[{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unlinkAddress","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.unlinkAddressData","components":[{"type":"uint256","name":"fromCharacterId","internalType":"uint256"},{"type":"address","name":"ethAddress","internalType":"address"},{"type":"bytes32","name":"linkType","internalType":"bytes32"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unlinkAnyUri","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.unlinkAnyUriData","components":[{"type":"uint256","name":"fromCharacterId","internalType":"uint256"},{"type":"string","name":"toUri","internalType":"string"},{"type":"bytes32","name":"linkType","internalType":"bytes32"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unlinkCharacter","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.unlinkCharacterData","components":[{"type":"uint256","name":"fromCharacterId","internalType":"uint256"},{"type":"uint256","name":"toCharacterId","internalType":"uint256"},{"type":"bytes32","name":"linkType","internalType":"bytes32"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unlinkERC721","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.unlinkERC721Data","components":[{"type":"uint256","name":"fromCharacterId","internalType":"uint256"},{"type":"address","name":"tokenAddress","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"bytes32","name":"linkType","internalType":"bytes32"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unlinkLinklist","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.unlinkLinklistData","components":[{"type":"uint256","name":"fromCharacterId","internalType":"uint256"},{"type":"uint256","name":"toLinkListId","internalType":"uint256"},{"type":"bytes32","name":"linkType","internalType":"bytes32"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unlinkNote","inputs":[{"type":"tuple","name":"vars","internalType":"struct DataTypes.unlinkNoteData","components":[{"type":"uint256","name":"fromCharacterId","internalType":"uint256"},{"type":"uint256","name":"toCharacterId","internalType":"uint256"},{"type":"uint256","name":"toNoteId","internalType":"uint256"},{"type":"bytes32","name":"linkType","internalType":"bytes32"}]}]}]
              

Contract Creation Code

0x608060405234801561001057600080fd5b50615f5180620000216000396000f3fe608060405234801561001057600080fd5b50600436106104545760003560e01c806392f7070b11610241578063cb8e757e1161013b578063e56f2fe4116100c3578063f2ad807511610087578063f2ad807514610a7c578063f316bacd14610a8f578063f6479d7714610aa2578063f7ea450814610ab5578063fd2d866f14610ac857600080fd5b8063e56f2fe4146109ff578063e985e9c514610a12578063ec81d19414610a4e578063ed24911d14610a61578063ef0828ab14610a6957600080fd5b8063dabb05311161010a578063dabb053114610993578063db491e80146109a6578063db8c198d146109c6578063dc17b6de146109d9578063dca27135146109ec57600080fd5b8063cb8e757e1461092f578063cd69fe6114610942578063d23b320b14610955578063d70e10c61461096857600080fd5b8063a6e6178d116101c9578063b9d328451161018d578063b9d32845146108d2578063bac62d43146108e5578063c053f6b8146108f8578063c2a6fe3b14610909578063c87b56dd1461091c57600080fd5b8063a6e6178d14610866578063a7ccb4bf14610879578063ac9650d81461088c578063af90b112146108ac578063b88d4fde146108bf57600080fd5b806395d9fa7d1161021057806395d9fa7d146107fa5780639864c3071461080d5780639a4dec18146108205780639a50248d14610833578063a22cb4651461085357600080fd5b806392f7070b1461079657806393f057e5146107a9578063952be0ef146107bc57806395d89b41146107f257600080fd5b806340ad34d811610352578063628b644a116102da578063753d662d1161029e578063753d662d146107215780637ecebe0014610734578063867884e61461075d5780638734bbfc146107705780638b4ca06a1461078357600080fd5b8063628b644a146106b55780636352211e146106c85780636bf55d5f146106db57806370a08231146106fb57806374f345cf1461070e57600080fd5b806347f94de71161032157806347f94de714610648578063491869531461065b5780634f6ccce71461067c5780635a936d101461068f5780635fb88183146106a257600080fd5b806340ad34d8146105fc57806342842e0e1461060f57806342966c681461062257806344b82a241461063557600080fd5b8063188b04b3116103e05780632abc6bf6116103a45780632abc6bf6146105875780632f745c59146105b0578063327b2a03146105c357806333f06ee6146105d6578063388f5083146105e957600080fd5b8063188b04b314610528578063206657f21461053b57806323b872dd1461054e57806328fbb8051461056157806329c301c21461057457600080fd5b8063095ea7b311610427578063095ea7b3146104d45780630ff98244146104e95780631316529d146104fc578063144a3e831461050d57806318160ddd1461052057600080fd5b806301ffc9a71461045957806304f3bcec1461048157806306fdde03146104ac578063081812fc146104c1575b600080fd5b61046c61046736600461496f565b610adb565b60405190151581526020015b60405180910390f35b601754610494906001600160a01b031681565b6040516001600160a01b039091168152602001610478565b6104b4610b06565b60405161047891906149dc565b6104946104cf3660046149ef565b610b98565b6104e76104e2366004614a24565b610c25565b005b6104e76104f7366004614a60565b610d3a565b60045b604051908152602001610478565b6104b461051b3660046149ef565b610de6565b6008546104ff565b6104e7610536366004614a8e565b610df1565b6104e7610549366004614ac2565b610e8f565b6104e761055c366004614af7565b610ea5565b61046c61056f366004614b23565b610ed6565b6104ff610582366004614b6a565b610eed565b6104ff610595366004614b9e565b6001600160a01b03166000908152600c602052604090205490565b6104ff6105be366004614a24565b610f7e565b6104ff6105d1366004614bcb565b611014565b6104e76105e4366004614c58565b6111a3565b6104e76105f7366004614a8e565b61129e565b6104e761060a366004614ca3565b611323565b6104e761061d366004614af7565b61139f565b6104e76106303660046149ef565b6113ba565b6104ff610643366004614cbf565b611457565b6104e7610656366004614c58565b6114b8565b61066e610669366004614d03565b61151f565b604051610478929190614d69565b6104ff61068a3660046149ef565b611577565b6104e761069d366004614a60565b61160a565b6104e76106b0366004614a8e565b611683565b6104e76106c3366004614d8e565b6116f1565b6104946106d63660046149ef565b611752565b6106ee6106e93660046149ef565b6117c9565b6040516104789190614de0565b6104ff610709366004614b9e565b6117e3565b6104e761071c366004614d03565b61186a565b6104e761072f366004614df3565b6118e4565b6104ff610742366004614b9e565b6001600160a01b03166000908152601c602052604090205490565b6104e761076b366004614ca3565b6119c7565b61046c61077e3660046149ef565b611a71565b6104ff6107913660046149ef565b611a9f565b6104ff6107a4366004614e3a565b611b0b565b6104e76107b7366004614a60565b611b86565b6104ff6107ca366004614e7e565b60009182526019602090815260408084206001600160a01b0393909316845291905290205490565b6104b4611c26565b6104e7610808366004614e7e565b611c35565b6104e761081b366004614a8e565b611cf7565b6104ff61082e366004614bcb565b611d58565b610846610841366004614ea1565b611e43565b6040516104789190614ee2565b6104e7610861366004614f6e565b611ff2565b6104e7610874366004614c58565b611ffd565b6104ff610887366004614a8e565b6120dd565b61089f61089a366004614fdc565b61217e565b6040516104789190615011565b6104ff6108ba366004614cbf565b612272565b6104e76108cd36600461515e565b612299565b6104e76108e03660046151d7565b6122d1565b6104e76108f3366004614d03565b612384565b6013546001600160a01b0316610494565b6104e7610917366004614d03565b61244c565b6104b461092a3660046149ef565b6124be565b6104e761093d3660046151d7565b61258a565b6104ff6109503660046151d7565b612619565b6104e7610963366004614a8e565b61262e565b6104ff610976366004614d03565b6000918252600d6020908152604080842092845291905290205490565b6108466109a13660046149ef565b6126b9565b6109b96109b4366004614d03565b612868565b604051610478919061520b565b6104e76109d4366004614a8e565b6129c9565b6104e76109e73660046152a1565b612a33565b6104b46109fa3660046149ef565b612ac4565b6104e7610a0d366004615323565b612b36565b61046c610a203660046153d4565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b6104b4610a5c3660046149ef565b612cc3565b6104ff612d08565b6104e7610a773660046153fe565b612d17565b6104e7610a8a3660046149ef565b612da1565b6104ff610a9d366004615432565b612df2565b6104ff610ab0366004614a60565b612f33565b6104e7610ac33660046149ef565b61304e565b6104e7610ad63660046153fe565b613120565b60006001600160e01b0319821663780e9d6360e01b1480610b005750610b008261319b565b92915050565b606060008054610b159061548d565b80601f0160208091040260200160405190810160405280929190818152602001828054610b419061548d565b8015610b8e5780601f10610b6357610100808354040283529160200191610b8e565b820191906000526020600020905b815481529060010190602001808311610b7157829003601f168201915b5050505050905090565b6000610ba3826131eb565b610c095760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b6000610c3082611752565b9050806001600160a01b0316836001600160a01b031603610c9d5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610c00565b336001600160a01b0382161480610cb95750610cb98133610a20565b610d2b5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610c00565b610d358383613208565b505050565b610d46813560b2613276565b60135481356000818152600d6020908152604080832081870135808552908352928190205490516337fb824760e11b8152731e58988e34177c407a639f380a9d835223ab79f795636ff7048e95610db39590948901359390926001600160a01b03909216916004016154c1565b60006040518083038186803b158015610dcb57600080fd5b505af4158015610ddf573d6000803e3d6000fd5b5050505050565b6060610b00826124be565b610dfd813560b2613276565b610e0a8160200135613307565b731e58988e34177c407a639f380a9d835223ab79f7639ec52a23823560208401356040850135610e3d60608701876154ed565b6013546020808a01356000908152600a9091526040908190206005015490516001600160e01b031960e08a901b168152610db39796959493926001600160a01b03908116921690600d9060040161555c565b610e9a836002613276565b610d35838383613333565b610eaf338261338f565b610ecb5760405162461bcd60e51b8152600401610c00906155a9565b610d35838383613479565b6000610ee3848484613626565b90505b9392505050565b6000610efb823560ec613276565b610f0582356136b0565b6040516342a34a5360e01b815290915073bb3c660ad95306d4b3e6844a89f236a0233d52f2906342a34a5390610f4990859085906000908190600e90600401615701565b60006040518083038186803b158015610f6157600080fd5b505af4158015610f75573d6000803e3d6000fd5b50505050919050565b6000610f89836117e3565b8210610feb5760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608401610c00565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b6000611022833560ca613276565b6545524337323160d01b600061103885356136b0565b6013549091506000906001600160a01b0316632ea24efc8261105d6020890189614b9e565b6040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152602088013560448201526064016020604051808303816000875af11580156110b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110d79190615746565b905073bb3c660ad95306d4b3e6844a89f236a0233d52f26342a34a538784868561110460208c018c614b9e565b8b6020013560405160200161113792919060609290921b6bffffffffffffffffffffffff19168252601482015260340190565b604051602081830303815290604052600e6040518763ffffffff1660e01b81526004016111699695949392919061575f565b60006040518083038186803b15801561118157600080fd5b505af4158015611195573d6000803e3d6000fd5b509398975050505050505050565b6013546040516367880d6160e11b8152600481018590526000916001600160a01b03169063cf101ac290602401602060405180830381865afa1580156111ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112119190615746565b905061121e8160b1613276565b6013546040516337dfe8e360e21b815273c8f036a975b7a64cc05808779aedb58d859852a69163df7fa38c91611268918891889188916001600160a01b03909116906004016157aa565b60006040518083038186803b15801561128057600080fd5b505af4158015611294573d6000803e3d6000fd5b5050505050505050565b6112aa813560b9613276565b731e58988e34177c407a639f380a9d835223ab79f763a4159c6b82356112d66040850160208601614b9e565b6013546040805160e086901b6001600160e01b031916815260048101949094526001600160a01b0392831660248501528601356044840152166064820152600d608482015260a401610db3565b61132f813560b6613276565b60135460408051631d4deabf60e01b81528335600482015260208401356024820152908301356044820152606083013560648201526001600160a01b039091166084820152600d60a4820152731e58988e34177c407a639f380a9d835223ab79f790631d4deabf9060c401610db3565b610d3583838360405180602001604052806000815250612299565b6000818152600a602052604080822090516113d891600101906157dd565b60408051918290039091206000818152600b6020908152838220829055858252600a90529182208281559092509061141360018301826148be565b6114216002830160006148be565b50600060038201556004810180546001600160a01b0319908116909155600590910180549091169055611453826136d9565b5050565b6000611465833560c8613276565b67131a5b9adb1a5cdd60c21b600061147d85356136b0565b905060008460001b905073bb3c660ad95306d4b3e6844a89f236a0233d52f26342a34a53878486858a60405160200161113791815260200190565b6114c38360b0613276565b6000838152600a602052604090206002016114df828483615899565b50827f17d7c9f69270ba135480ef16837f38b9d37d3ab291cbd3ba03982290c66319978383604051611512929190615958565b60405180910390a2505050565b6000828152601a602090815260408083208484529091529020606090819061154690613738565b6000858152601a60209081526040808320878452909152902090925061156e90600201613738565b90509250929050565b600061158260085490565b82106115e55760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608401610c00565b600882815481106115f8576115f861596c565b90600052602060002001549050919050565b611616813560be613276565b60135481356000818152600d602090815260408083208187013580855290835292819020549051633fe4fe3960e11b8152731e58988e34177c407a639f380a9d835223ab79f795637fc9fc7295610db39590948901359390926001600160a01b03909216916004016154c1565b61168f813560bb613276565b731e58988e34177c407a639f380a9d835223ab79f76348391dcb82356116b860208501856154ed565b601354604080516001600160e01b031960e088901b168152610db39594939291890135916001600160a01b031690600d90600401615982565b6116fb8484613745565b61170584846137aa565b61170f8484613821565b6040516001626802bf60e01b0319815273bb3c660ad95306d4b3e6844a89f236a0233d52f29063ff97fd4190611268908790879087908790600e906004016159c3565b6000818152600260205260408120546001600160a01b031680610b005760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610c00565b6000818152601860205260409020606090610b0090613738565b60006001600160a01b03821661184e5760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610c00565b506001600160a01b031660009081526003602052604090205490565b6118758260c4613276565b61187f82826137aa565b6000828152600e60209081526040808320848452825291829020600501805460ff60a81b1916600160a81b179055905182815283917f036469f3e73c83520cdefa197d7a9c854c2f8bc0164b82e9f2bd4aa7e150fd3091015b60405180910390a25050565b60006118ef85611752565b6001600160a01b038181166000908152601c6020908152604080832080546001810190915581517f53f5e122d65c239c5936ed0eb8ce8ea2c1e77831749ec178c59c5cd4a792fe04938101939093529082018a90529288166060808301919091526080820188905260a08201939093529185013560c083015291925060e0016040516020818303038152906040528051906020012090506119bb6119b4611994613866565b8360405161190160f01b8152600281019290925260228201526042902090565b83856138dc565b50610ddf858585613333565b6119d3813560b8613276565b731e58988e34177c407a639f380a9d835223ab79f7631542463682356119ff6040850160208601614b9e565b60135485356000908152600d6020908152604080832060608a013580855292529182902054825160e088901b6001600160e01b031916815260048101969096526001600160a01b03948516602487015291880135604486015260648501529116608483015260a482015260c401610db3565b600080611a7d83611752565b6001600160a01b03166000908152600c60205260409020549290921492915050565b60135460405162fba02760e01b8152600481018390526000916001600160a01b03169062fba02790602401602060405180830381865afa158015611ae7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b009190615746565b6000611b19833560c7613276565b664164647265737360c81b6000611b3085356136b0565b6040516bffffffffffffffffffffffff19606087901b1660208201529091506001600160a01b0385169073bb3c660ad95306d4b3e6844a89f236a0233d52f2906342a34a53908890859087908690603401611137565b611b92813560ba613276565b731e58988e34177c407a639f380a9d835223ab79f76393c96a528235611bbe6040850160208601614b9e565b60135485356000908152600d60209081526040808320818a013580855292529182902054915160e087901b6001600160e01b031916815260048101959095526001600160a01b039384166024860152604485015291166064830152608482015260a401610db3565b606060018054610b159061548d565b611c40826001613276565b6000828152600a60205260409020600401546001600160a01b031615611c795760405163fe6f50e560e01b815260040160405180910390fd5b6040516384b44a2f60e01b8152600481018390526001600160a01b0382166024820152600a604482015273681be951fa8b6731e9330291331aef94e8b9905c906384b44a2f906064015b60006040518083038186803b158015611cdb57600080fd5b505af4158015611cef573d6000803e3d6000fd5b505050505050565b611d03813560bd613276565b60135460408051632ca904df60e01b8152731e58988e34177c407a639f380a9d835223ab79f792632ca904df92610db392863592602088013592880135916001600160a01b0390911690600d906004016154c1565b6000611d66833560c9613276565b634e6f746560e01b6000611d7a85356136b0565b601354604051635cb46be760e01b815260006004820181905287356024830152602088013560448301529293506001600160a01b0390911690635cb46be7906064016020604051808303816000875af1158015611ddb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dff9190615746565b905073bb3c660ad95306d4b3e6844a89f236a0233d52f26342a34a53878486858a600001358b60200135604051602001611137929190918252602082015260400190565b611e4b6148f8565b60008383604051611e5d9291906159f5565b604080519182900382206000818152600b602090815283822054808352600a82529184902060c0860190945283548552600184018054939650919493929084019190611ea89061548d565b80601f0160208091040260200160405190810160405280929190818152602001828054611ed49061548d565b8015611f215780601f10611ef657610100808354040283529160200191611f21565b820191906000526020600020905b815481529060010190602001808311611f0457829003601f168201915b50505050508152602001600282018054611f3a9061548d565b80601f0160208091040260200160405190810160405280929190818152602001828054611f669061548d565b8015611fb35780601f10611f8857610100808354040283529160200191611fb3565b820191906000526020600020905b815481529060010190602001808311611f9657829003601f168201915b50505091835250506003820154602082015260048201546001600160a01b03908116604083015260059092015490911660609091015295945050505050565b6114533383836139b9565b612008836000613276565b612028828260405161201b9291906159f5565b6040518091039020613a87565b61206782828080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250613ab492505050565b60405163130f361d60e01b815273681be951fa8b6731e9330291331aef94e8b9905c9063130f361d906120a890869086908690600b90600a90600401615a05565b60006040518083038186803b1580156120c057600080fd5b505af41580156120d4573d6000803e3d6000fd5b50505050505050565b60006120ee823560208401356137aa565b73bb3c660ad95306d4b3e6844a89f236a0233d52f2639d2e06f08335602085013561211f6060870160408801614b9e565b61212c60608801886154ed565b6014546040516001600160e01b031960e089901b1681526121619695949392916001600160a01b031690600e90600401615a33565b602060405180830381865af4158015611ae7573d6000803e3d6000fd5b6060816001600160401b0381111561219857612198615073565b6040519080825280602002602001820160405280156121cb57816020015b60608152602001906001900390816121b65790505b50905060005b8281101561226b5761223b308585848181106121ef576121ef61596c565b905060200281019061220191906154ed565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250613b2192505050565b82828151811061224d5761224d61596c565b6020026020010181905250808061226390615a8d565b9150506121d1565b5092915050565b6000612280833560c6613276565b6821b430b930b1ba32b960b91b600061147d85356136b0565b6122a3338361338f565b6122bf5760405162461bcd60e51b8152600401610c00906155a9565b6122cb84848484613b46565b50505050565b6122dd813560b5613276565b6122ef816020013582604001356137aa565b731e58988e34177c407a639f380a9d835223ab79f76371bd9b06823560208401356040850135606086013561232760808801886154ed565b6013546020808b01356000908152600e82526040808220818e013583529092528190206003015490516001600160e01b031960e08b901b168152610db3989796959493926001600160a01b03908116921690600d90600401615aa6565b6013546040516367880d6160e11b8152600481018490526000916001600160a01b03169063cf101ac290602401602060405180830381865afa1580156123ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123f29190615746565b90506123ff8160cc613276565b60135460405163015800dd60e71b815273c8f036a975b7a64cc05808779aedb58d859852a69163ac006e80916120a8918591889188916001600160a01b0390911690600d906004016154c1565b6124578260c5613276565b61246182826137aa565b6000828152600e60209081526040808320848452825291829020600501805460ff60a01b1916600160a01b179055905182815283917f4f1db9708b537c1d26a7af4b235fd079bf2342d92a276e27eb6c8717e8bbcf9391016118d8565b6060816124ca816131eb565b6124e7576040516366012df560e11b815260040160405180910390fd5b6000838152600a6020526040902060020180546125039061548d565b80601f016020809104026020016040519081016040528092919081815260200182805461252f9061548d565b801561257c5780601f106125515761010080835404028352916020019161257c565b820191906000526020600020905b81548152906001019060200180831161255f57829003601f168201915b505050505091505b50919050565b612596813560b7613276565b731e58988e34177c407a639f380a9d835223ab79f763f35deae182356125c26040850160208601614b9e565b6013546040805160e086901b6001600160e01b031916815260048101949094526001600160a01b039283166024850152860135604484015260608601356064840152166084820152600d60a482015260c401610db3565b6000610b0061262783615afc565b6001613b79565b61263a813560c2613276565b612649813560208301356137aa565b61265881356020830135613821565b73bb3c660ad95306d4b3e6844a89f236a0233d52f26320828a02823560208401356126896060860160408701614b9e565b61269660608701876154ed565b600e6040518763ffffffff1660e01b8152600401610db396959493929190615baf565b6126c16148f8565b816126cb816131eb565b6126e8576040516366012df560e11b815260040160405180910390fd5b600a60008481526020019081526020016000206040518060c0016040529081600082015481526020016001820180546127209061548d565b80601f016020809104026020016040519081016040528092919081815260200182805461274c9061548d565b80156127995780601f1061276e57610100808354040283529160200191612799565b820191906000526020600020905b81548152906001019060200180831161277c57829003601f168201915b505050505081526020016002820180546127b29061548d565b80601f01602080910402602001604051908101604052809291908181526020018280546127de9061548d565b801561282b5780601f106128005761010080835404028352916020019161282b565b820191906000526020600020905b81548152906001019060200180831161280e57829003601f168201915b50505091835250506003820154602082015260048201546001600160a01b0390811660408301526005909201549091166060909101529392505050565b60408051610100808201835260008083526020808401829052606084860181905284018290526080840182905260a0840182905260c0840182905260e08401829052868252600e815284822086835281529084902084519283018552805483526001810154918301919091526002810180549394929391928401916128ec9061548d565b80601f01602080910402602001604051908101604052809291908181526020018280546129189061548d565b80156129655780601f1061293a57610100808354040283529160200191612965565b820191906000526020600020905b81548152906001019060200180831161294857829003601f168201915b505050918352505060038201546001600160a01b039081166020830152600483015481166040830152600590920154918216606082015260ff600160a01b8304811615156080830152600160a81b909204909116151560a090910152905092915050565b6129d5813560c0613276565b6129e481356020830135613745565b6129f3813560208301356137aa565b612a0281356020830135613821565b73bb3c660ad95306d4b3e6844a89f236a0233d52f2631f2ffb69823560208401356126896060860160408701614b9e565b612a3e866003613276565b612a4886866137aa565b604051630afb883f60e41b815273f29b2c1b0722a9ab38062622133503c21a853e8f9063afb883f090612a8c90899089908990899089908990601a90600401615c2c565b60006040518083038186803b158015612aa457600080fd5b505af4158015612ab8573d6000803e3d6000fd5b50505050505050505050565b601354604051632b05429560e21b8152600481018390526060916001600160a01b03169063ac150a5490602401600060405180830381865afa158015612b0e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610b009190810190615c74565b601454600390600160a81b900460ff16158015612b61575060145460ff808316600160a01b90920416105b612bc45760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610c00565b6014805460ff60a81b1960ff8416600160a01b021661ffff60a01b1990911617600160a81b179055612bf889898989613c56565b601380546001600160a01b03199081166001600160a01b0388811691909117909255601480548216878416179055601580548216868416179055601b80549091169184169190911790556040514281527f400175a56dd3710794078f7b9dbe8296ac94c5a248dfd51bb22ed4ab9eaa9fbf9060200160405180910390a16014805460ff60a81b1916905560405160ff821681527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a1505050505050505050565b606081612ccf816131eb565b612cec576040516366012df560e11b815260040160405180910390fd5b6000838152600a6020526040902060010180546125039061548d565b6000612d12613866565b905090565b612d23813560bc613276565b731e58988e34177c407a639f380a9d835223ab79f7631873e2188235612d4c60208501856154ed565b60135486356000908152600d60209081526040808320818b01358085529252918290205491516001600160e01b031960e089901b168152610db39695949391926001600160a01b039092169190600401615982565b612daa81613ca7565b326000908152600c6020526040808220805490849055905190918291849133917fce95332e6082aebeb8058a7b56d1a109f67d6550552ed04d36aca4a6acd4d7de9190a45050565b6000612e00843560cb613276565b65416e7955726960d01b6000612e1686356136b0565b601354604051633610bf0960e11b81529192506000916001600160a01b0390911690636c217e1290612e509084908a908a90600401615ce1565b6020604051808303816000875af1158015612e6f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e939190615746565b905073bb3c660ad95306d4b3e6844a89f236a0233d52f26342a34a53888486858b8b604051602001612ec69291906159f5565b604051602081830303815290604052600e6040518763ffffffff1660e01b8152600401612ef89695949392919061575f565b60006040518083038186803b158015612f1057600080fd5b505af4158015612f24573d6000803e3d6000fd5b50939998505050505050505050565b6000612f41823560b4613276565b612fcf6040518060a00160405280846020016020810190612f629190614b9e565b6001600160a01b03168152602001612f8b856020016020810190612f869190614b9e565b613d0d565b815260200160405180602001604052806000815250815260200160006001600160a01b03168152602001604051806020016040528060008152508152506000613b79565b60135460408051639ec52a2360e01b8152853560048201526024810184905290850135604482015260e06064820152600060e482018190526001600160a01b03909216608482015260a4810191909152600d60c4820152909150731e58988e34177c407a639f380a9d835223ab79f790639ec52a239061010401610f49565b6013546040516367880d6160e11b8152600481018390526000916001600160a01b03169063cf101ac290602401602060405180830381865afa158015613098573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130bc9190615746565b90506130c781613ca7565b6013546040516318abcde360e01b815260048101839052602481018490526001600160a01b039091166044820152600d606482015273c8f036a975b7a64cc05808779aedb58d859852a6906318abcde390608401611cc3565b61312c813560bf613276565b73681be951fa8b6731e9330291331aef94e8b9905c631dc8313382356131586040850160208601614b9e565b61316560408601866154ed565b86356000908152600a60205260409081902090516001600160e01b031960e088901b168152610db3959493929190600401615cfb565b60006001600160e01b031982166380ac58cd60e01b14806131cc57506001600160e01b03198216635b5e139f60e01b145b80610b0057506301ffc9a760e01b6001600160e01b0319831614610b00565b6000908152600260205260409020546001600160a01b0316151590565b600081815260046020526040902080546001600160a01b0319166001600160a01b038416908117909155819061323d82611752565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b61327f82613e16565b15613288575050565b6015546001600160a01b031633036132c4576000828152601960209081526040808320328452909152902054600190821c8116036132c4575050565b6000828152601960209081526040808320338452909152902054600190821c8116036132ee575050565b604051632c4bc2b960e21b815260040160405180910390fd5b613310816131eb565b613330576040516375af0fc960e11b815260048101829052602401610c00565b50565b604051631f8c0b6760e11b8152600481018490526001600160a01b038316602482015260448101829052601860648201526019608482015273f29b2c1b0722a9ab38062622133503c21a853e8f90633f1816ce9060a4016120a8565b600061339a826131eb565b6133fb5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610c00565b600061340683611752565b9050806001600160a01b0316846001600160a01b031614806134415750836001600160a01b031661343684610b98565b6001600160a01b0316145b8061347157506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b031661348c82611752565b6001600160a01b0316146134f05760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b6064820152608401610c00565b6001600160a01b0382166135525760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610c00565b61355d838383613e76565b613568600082613208565b6001600160a01b0383166000908152600360205260408120805460019290613591908490615d26565b90915550506001600160a01b03821660009081526003602052604081208054600192906135bf908490615d39565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4610d35838383613f48565b6000838152601a6020908152604080832085845290915281206136498184613f85565b15613658576000915050610ee6565b6136656002820184613f85565b15613674576001915050610ee6565b60008581526019602090815260408083206001600160a01b03871684529091529020546136a79060c31c60019081161490565b95945050505050565b6000818152600a60205260408120600301805482906136ce90615a8d565b918290555092915050565b6136e3338261338f565b61372f5760405162461bcd60e51b815260206004820152601b60248201527f4e4654426173653a204e6f744f776e65724f72417070726f76656400000000006044820152606401610c00565b61333081613fa7565b60606000610ee683614056565b61374e82613e16565b15613757575050565b6015546001600160a01b0316330361377d57613774828232613626565b1561377d575050565b613788828233613626565b15613791575050565b604051631a1d1d4760e11b815260040160405180910390fd5b6000828152600e60209081526040808320848452909152902060050154600160a01b900460ff16156137ef57604051631f0fc8f560e11b815260040160405180910390fd5b6000828152600a6020526040902060030154811115611453576040516364783acb60e01b815260040160405180910390fd5b6000828152600e60209081526040808320848452909152902060050154600160a81b900460ff161561145357604051630bc06a0f60e21b815260040160405180910390fd5b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f613891610b06565b8051602091820120604080519283019390935291810191909152600160608201524660808201523060a082015260c00160405160208183030381529060405280519060200120905090565b4281606001351015613900576040516275e96160e01b815260040160405180910390fd5b60006001846139126020850185615d4c565b604080516000815260208181018084529490945260ff9092168282015291850135606082015290840135608082015260a0016020604051602081039080840390855afa158015613966573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116158061399b5750826001600160a01b0316816001600160a01b031614155b156122cb57604051636a9ca51760e01b815260040160405180910390fd5b816001600160a01b0316836001600160a01b031603613a1a5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610c00565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b6000818152600b60205260409020541561333057604051631b659b9f60e21b815260040160405180910390fd5b80518190601f811180613ac75750600381105b15613ae557604051636f819c2160e11b815260040160405180910390fd5b60005b818110156122cb57613b19838281518110613b0557613b0561596c565b01602001516001600160f81b0319166140b2565b600101613ae8565b6060610ee68383604051806060016040528060278152602001615ef560279139614160565b613b51848484613479565b613b5d848484846141d8565b6122cb5760405162461bcd60e51b8152600401610c0090615d6f565b6000613b8f836020015180519060200120613a87565b8115613ba257613ba28360200151613ab4565b601260008154613bb190615a8d565b91829055508351909150613bc590826142d9565b73681be951fa8b6731e9330291331aef94e8b9905c634daae5688460000151856020015186604001518760600151886080015187600b600a6040518963ffffffff1660e01b8152600401613c20989796959493929190615dc1565b60006040518083038186803b158015613c3857600080fd5b505af4158015613c4c573d6000803e3d6000fd5b5050505092915050565b613c62848484846142f3565b7f414cd0b34676984f09a5f76ce9718d4062e50283abe0e7e274a9a5b4e0c99c308484848442604051613c99959493929190615e38565b60405180910390a150505050565b6000613cb282611752565b6015549091506001600160a01b031633148015613cd75750326001600160a01b038216145b15613ce0575050565b6001600160a01b0381163303613cf4575050565b604051631b0c476f60e11b815260040160405180910390fd5b60408051602a80825260608281019093526f181899199a1a9b1b9c1cb0b131b232b360811b916001600160a01b0385169160009190602082018180368337019050509050600360fc1b81600081518110613d6957613d6961596c565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110613d9857613d9861596c565b60200101906001600160f81b031916908160001a90535060295b6001811115613e0d578383600f1660108110613dd057613dd061596c565b1a60f81b828281518110613de657613de661596c565b60200101906001600160f81b031916908160001a90535060049290921c9160001901613db2565b50949350505050565b600080613e2283611752565b90506001600160a01b0381163303613e3d5750600192915050565b6015546001600160a01b031633148015613e5f5750326001600160a01b038216145b15613e6d5750600192915050565b50600092915050565b601b546001600160a01b03848116911614613f3d576000818152601860205260408120613ea29061430e565b600083815260186020526040812091925090613ebd90613738565b905060005b82811015613eff57613eed84838381518110613ee057613ee061596c565b6020026020010151614318565b80613ef781615a8d565b915050613ec2565b506001600160a01b0385166000908152600c6020526040902054839003613f3a576001600160a01b0385166000908152600c60205260408120555b50505b610d35838383614351565b6001600160a01b0382166000908152600c60205260408120549003610d35576001600160a01b03919091166000908152600c602052604090205550565b6001600160a01b03811660009081526001830160205260408120541515610ee6565b6000613fb282611752565b9050613fc081600084613e76565b613fcb600083613208565b6001600160a01b0381166000908152600360205260408120805460019290613ff4908490615d26565b909155505060008281526002602052604080822080546001600160a01b0319169055518391906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a461145381600084613f48565b6060816000018054806020026020016040519081016040528092919081815260200182805480156140a657602002820191906000526020600020905b815481526020019060010190808311614092575b50505050509050919050565b600360fc1b6001600160f81b0319821610806140db5750603d60f91b6001600160f81b03198216115b8061410b5750603960f81b6001600160f81b0319821611801561410b5750606160f81b6001600160f81b03198216105b80156141255750602d60f81b6001600160f81b0319821614155b801561413f5750605f60f81b6001600160f81b0319821614155b15613330576040516001621693dd60e01b0319815260040160405180910390fd5b6060600080856001600160a01b03168560405161417d9190615e72565b600060405180830381855af49150503d80600081146141b8576040519150601f19603f3d011682016040523d82523d6000602084013e6141bd565b606091505b50915091506141ce86838387614409565b9695505050505050565b60006001600160a01b0384163b156142ce57604051630a85bd0160e11b81526001600160a01b0385169063150b7a029061421c903390899088908890600401615e8e565b6020604051808303816000875af1925050508015614257575060408051601f3d908101601f1916820190925261425491810190615ec1565b60015b6142b4573d808015614285576040519150601f19603f3d011682016040523d82523d6000602084013e61428a565b606091505b5080516000036142ac5760405162461bcd60e51b8152600401610c0090615d6f565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050613471565b506001949350505050565b611453828260405180602001604052806000815250614482565b6000614300848683615899565b506001610ddf828483615899565b6000610b00825490565b60008281526019602090815260408083206001600160a01b0385168452825280832083905584835260189091529020610d3590826144b5565b6001600160a01b0383166143ac576143a781600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b6143cf565b816001600160a01b0316836001600160a01b0316146143cf576143cf83826144ca565b6001600160a01b0382166143e657610d3581614567565b826001600160a01b0316826001600160a01b031614610d3557610d358282614616565b60608315614478578251600003614471576001600160a01b0385163b6144715760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610c00565b5081613471565b613471838361465a565b61448c8383614684565b61449960008484846141d8565b610d355760405162461bcd60e51b8152600401610c0090615d6f565b6000610ee6836001600160a01b0384166147cb565b600060016144d7846117e3565b6144e19190615d26565b600083815260076020526040902054909150808214614534576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b60085460009061457990600190615d26565b600083815260096020526040812054600880549394509092849081106145a1576145a161596c565b9060005260206000200154905080600883815481106145c2576145c261596c565b60009182526020808320909101929092558281526009909152604080822084905585825281205560088054806145fa576145fa615ede565b6001900381819060005260206000200160009055905550505050565b6000614621836117e3565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b81511561466a5781518083602001fd5b8060405162461bcd60e51b8152600401610c0091906149dc565b6001600160a01b0382166146da5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610c00565b6146e3816131eb565b156147305760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610c00565b61473c60008383613e76565b6001600160a01b0382166000908152600360205260408120805460019290614765908490615d39565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a461145360008383613f48565b600081815260018301602052604081205480156148b45760006147ef600183615d26565b855490915060009061480390600190615d26565b90508181146148685760008660000182815481106148235761482361596c565b90600052602060002001549050808760000184815481106148465761484661596c565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061487957614879615ede565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610b00565b6000915050610b00565b5080546148ca9061548d565b6000825580601f106148da575050565b601f0160209004906000526020600020908101906133309190614940565b6040518060c001604052806000815260200160608152602001606081526020016000815260200160006001600160a01b0316815260200160006001600160a01b031681525090565b5b808211156149555760008155600101614941565b5090565b6001600160e01b03198116811461333057600080fd5b60006020828403121561498157600080fd5b8135610ee681614959565b60005b838110156149a757818101518382015260200161498f565b50506000910152565b600081518084526149c881602086016020860161498c565b601f01601f19169290920160200192915050565b602081526000610ee660208301846149b0565b600060208284031215614a0157600080fd5b5035919050565b80356001600160a01b0381168114614a1f57600080fd5b919050565b60008060408385031215614a3757600080fd5b614a4083614a08565b946020939093013593505050565b60006060828403121561258457600080fd5b600060608284031215614a7257600080fd5b610ee68383614a4e565b60006080828403121561258457600080fd5b600060208284031215614aa057600080fd5b81356001600160401b03811115614ab657600080fd5b61347184828501614a7c565b600080600060608486031215614ad757600080fd5b83359250614ae760208501614a08565b9150604084013590509250925092565b600080600060608486031215614b0c57600080fd5b614b1584614a08565b9250614ae760208501614a08565b600080600060608486031215614b3857600080fd5b8335925060208401359150614b4f60408501614a08565b90509250925092565b600060e0828403121561258457600080fd5b600060208284031215614b7c57600080fd5b81356001600160401b03811115614b9257600080fd5b61347184828501614b58565b600060208284031215614bb057600080fd5b610ee682614a08565b60006040828403121561258457600080fd5b60008060608385031215614bde57600080fd5b82356001600160401b03811115614bf457600080fd5b614c0085828601614b58565b92505061156e8460208501614bb9565b60008083601f840112614c2257600080fd5b5081356001600160401b03811115614c3957600080fd5b602083019150836020828501011115614c5157600080fd5b9250929050565b600080600060408486031215614c6d57600080fd5b8335925060208401356001600160401b03811115614c8a57600080fd5b614c9686828701614c10565b9497909650939450505050565b600060808284031215614cb557600080fd5b610ee68383614a7c565b60008060408385031215614cd257600080fd5b82356001600160401b03811115614ce857600080fd5b614cf485828601614b58565b95602094909401359450505050565b60008060408385031215614d1657600080fd5b50508035926020909101359150565b600081518084526020808501945080840160005b83811015614d5e5781516001600160a01b031687529582019590820190600101614d39565b509495945050505050565b604081526000614d7c6040830185614d25565b82810360208401526136a78185614d25565b60008060008060608587031215614da457600080fd5b843593506020850135925060408501356001600160401b03811115614dc857600080fd5b614dd487828801614c10565b95989497509550505050565b602081526000610ee66020830184614d25565b60008060008060e08587031215614e0957600080fd5b84359350614e1960208601614a08565b925060408501359150614e2f8660608701614a7c565b905092959194509250565b60008060408385031215614e4d57600080fd5b82356001600160401b03811115614e6357600080fd5b614e6f85828601614b58565b92505061156e60208401614a08565b60008060408385031215614e9157600080fd5b8235915061156e60208401614a08565b60008060208385031215614eb457600080fd5b82356001600160401b03811115614eca57600080fd5b614ed685828601614c10565b90969095509350505050565b60208152815160208201526000602083015160c06040840152614f0860e08401826149b0565b90506040840151601f19848303016060850152614f2582826149b0565b91505060608401516080840152608084015160018060a01b0380821660a08601528060a08701511660c086015250508091505092915050565b80358015158114614a1f57600080fd5b60008060408385031215614f8157600080fd5b614f8a83614a08565b915061156e60208401614f5e565b60008083601f840112614faa57600080fd5b5081356001600160401b03811115614fc157600080fd5b6020830191508360208260051b8501011115614c5157600080fd5b60008060208385031215614fef57600080fd5b82356001600160401b0381111561500557600080fd5b614ed685828601614f98565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561506657603f198886030184526150548583516149b0565b94509285019290850190600101615038565b5092979650505050505050565b634e487b7160e01b600052604160045260246000fd5b60405160a081016001600160401b03811182821017156150ab576150ab615073565b60405290565b604051601f8201601f191681016001600160401b03811182821017156150d9576150d9615073565b604052919050565b60006001600160401b038211156150fa576150fa615073565b50601f01601f191660200190565b600082601f83011261511957600080fd5b813561512c615127826150e1565b6150b1565b81815284602083860101111561514157600080fd5b816020850160208301376000918101602001919091529392505050565b6000806000806080858703121561517457600080fd5b61517d85614a08565b935061518b60208601614a08565b92506040850135915060608501356001600160401b038111156151ad57600080fd5b6151b987828801615108565b91505092959194509250565b600060a0828403121561258457600080fd5b6000602082840312156151e957600080fd5b81356001600160401b038111156151ff57600080fd5b613471848285016151c5565b6020815281516020820152602082015160408201526000604083015161010080606085015261523e6101208501836149b0565b9150606085015160018060a01b0380821660808701528060808801511660a0870152505060a085015161527c60c08601826001600160a01b03169052565b5060c085015180151560e08601525060e0850151801515858301525090949350505050565b600080600080600080608087890312156152ba57600080fd5b863595506020870135945060408701356001600160401b03808211156152df57600080fd5b6152eb8a838b01614f98565b9096509450606089013591508082111561530457600080fd5b5061531189828a01614f98565b979a9699509497509295939492505050565b60008060008060008060008060c0898b03121561533f57600080fd5b88356001600160401b038082111561535657600080fd5b6153628c838d01614c10565b909a50985060208b013591508082111561537b57600080fd5b506153888b828c01614c10565b909750955061539b905060408a01614a08565b93506153a960608a01614a08565b92506153b760808a01614a08565b91506153c560a08a01614a08565b90509295985092959890939650565b600080604083850312156153e757600080fd5b6153f083614a08565b915061156e60208401614a08565b60006020828403121561541057600080fd5b81356001600160401b0381111561542657600080fd5b61347184828501614a4e565b60008060006040848603121561544757600080fd5b83356001600160401b038082111561545e57600080fd5b61546a87838801614b58565b9450602086013591508082111561548057600080fd5b50614c9686828701614c10565b600181811c908216806154a157607f821691505b60208210810361258457634e487b7160e01b600052602260045260246000fd5b948552602085019390935260408401919091526001600160a01b03166060830152608082015260a00190565b6000808335601e1984360301811261550457600080fd5b8301803591506001600160401b0382111561551e57600080fd5b602001915036819003821315614c5157600080fd5b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b88815287602082015286604082015260e06060820152600061558260e083018789615533565b6001600160a01b0395861660808401529390941660a082015260c001529695505050505050565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6000808335601e1984360301811261561157600080fd5b83016020810192503590506001600160401b0381111561563057600080fd5b803603821315614c5157600080fd5b80358252600061565260208301836155fa565b60e0602086015261566760e086018284615533565b91505061567660408401614a08565b6001600160a01b03818116604087015261569360608601866155fa565b925086840360608801526156a8848483615533565b935050806156b860808701614a08565b16608087015250506156cd60a08401846155fa565b85830360a08701526156e0838284615533565b925050506156f060c08401614f5e565b151560c08501528091505092915050565b60c08152600061571460c083018861563f565b602083810197909752604083019590955250606081019290925281830360808301526000835260a09091015201919050565b60006020828403121561575857600080fd5b5051919050565b60c08152600061577260c083018961563f565b876020840152866040840152856060840152828103608084015261579681866149b0565b9150508260a0830152979650505050505050565b8481526060602082015260006157c4606083018587615533565b905060018060a01b038316604083015295945050505050565b60008083546157eb8161548d565b60018281168015615803576001811461581857615847565b60ff1984168752821515830287019450615847565b8760005260208060002060005b8581101561583e5781548a820152908401908201615825565b50505082870194505b50929695505050505050565b601f821115610d3557600081815260208120601f850160051c8101602086101561587a5750805b601f850160051c820191505b81811015611cef57828155600101615886565b6001600160401b038311156158b0576158b0615073565b6158c4836158be835461548d565b83615853565b6000601f8411600181146158f857600085156158e05750838201355b600019600387901b1c1916600186901b178355610ddf565b600083815260209020601f19861690835b828110156159295786850135825560209485019460019092019101615909565b50868210156159465760001960f88860031b161c19848701351681555b505060018560011b0183555050505050565b602081526000610ee3602083018486615533565b634e487b7160e01b600052603260045260246000fd5b86815260a06020820152600061599c60a083018789615533565b6040830195909552506001600160a01b039290921660608301526080909101529392505050565b8581528460208201526080604082015260006159e3608083018587615533565b90508260608301529695505050505050565b8183823760009101908152919050565b858152608060208201526000615a1f608083018688615533565b604083019490945250606001529392505050565b878152866020820152600060018060a01b03808816604084015260c06060840152615a6260c084018789615533565b941660808301525060a0015295945050505050565b634e487b7160e01b600052601160045260246000fd5b600060018201615a9f57615a9f615a77565b5060010190565b60006101008b83528a6020840152896040840152886060840152806080840152615ad3818401888a615533565b6001600160a01b0396871660a08501529490951660c08301525060e00152979650505050505050565b600060a08236031215615b0e57600080fd5b615b16615089565b615b1f83614a08565b815260208301356001600160401b0380821115615b3b57600080fd5b615b4736838701615108565b60208401526040850135915080821115615b6057600080fd5b615b6c36838701615108565b6040840152615b7d60608601614a08565b60608401526080850135915080821115615b9657600080fd5b50615ba336828601615108565b60808301525092915050565b86815285602082015260018060a01b038516604082015260a060608201526000615bdd60a083018587615533565b9050826080830152979650505050505050565b8183526000602080850194508260005b85811015614d5e576001600160a01b03615c1983614a08565b1687529582019590820190600101615c00565b87815286602082015260a060408201526000615c4c60a083018789615bf0565b8281036060840152615c5f818688615bf0565b91505082608083015298975050505050505050565b600060208284031215615c8657600080fd5b81516001600160401b03811115615c9c57600080fd5b8201601f81018413615cad57600080fd5b8051615cbb615127826150e1565b818152856020838501011115615cd057600080fd5b6136a782602083016020860161498c565b8381526040602082015260006136a7604083018486615533565b8581526001600160a01b03851660208201526080604082018190526000906159e39083018587615533565b81810381811115610b0057610b00615a77565b80820180821115610b0057610b00615a77565b600060208284031215615d5e57600080fd5b813560ff81168114610ee657600080fd5b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6001600160a01b03898116825261010060208301819052600091615de78483018c6149b0565b91508382036040850152615dfb828b6149b0565b908916606085015283810360808501529050615e1781886149b0565b60a0840196909652505060c081019290925260e09091015295945050505050565b606081526000615e4c606083018789615533565b8281036020840152615e5f818688615533565b9150508260408301529695505050505050565b60008251615e8481846020870161498c565b9190910192915050565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906141ce908301846149b0565b600060208284031215615ed357600080fd5b8151610ee681614959565b634e487b7160e01b600052603160045260246000fdfe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220b42b876718621722bfaab42c9763116a3e2896f34b0df979d356b6727834e38064736f6c63430008120033

Deployed ByteCode

0x608060405234801561001057600080fd5b50600436106104545760003560e01c806392f7070b11610241578063cb8e757e1161013b578063e56f2fe4116100c3578063f2ad807511610087578063f2ad807514610a7c578063f316bacd14610a8f578063f6479d7714610aa2578063f7ea450814610ab5578063fd2d866f14610ac857600080fd5b8063e56f2fe4146109ff578063e985e9c514610a12578063ec81d19414610a4e578063ed24911d14610a61578063ef0828ab14610a6957600080fd5b8063dabb05311161010a578063dabb053114610993578063db491e80146109a6578063db8c198d146109c6578063dc17b6de146109d9578063dca27135146109ec57600080fd5b8063cb8e757e1461092f578063cd69fe6114610942578063d23b320b14610955578063d70e10c61461096857600080fd5b8063a6e6178d116101c9578063b9d328451161018d578063b9d32845146108d2578063bac62d43146108e5578063c053f6b8146108f8578063c2a6fe3b14610909578063c87b56dd1461091c57600080fd5b8063a6e6178d14610866578063a7ccb4bf14610879578063ac9650d81461088c578063af90b112146108ac578063b88d4fde146108bf57600080fd5b806395d9fa7d1161021057806395d9fa7d146107fa5780639864c3071461080d5780639a4dec18146108205780639a50248d14610833578063a22cb4651461085357600080fd5b806392f7070b1461079657806393f057e5146107a9578063952be0ef146107bc57806395d89b41146107f257600080fd5b806340ad34d811610352578063628b644a116102da578063753d662d1161029e578063753d662d146107215780637ecebe0014610734578063867884e61461075d5780638734bbfc146107705780638b4ca06a1461078357600080fd5b8063628b644a146106b55780636352211e146106c85780636bf55d5f146106db57806370a08231146106fb57806374f345cf1461070e57600080fd5b806347f94de71161032157806347f94de714610648578063491869531461065b5780634f6ccce71461067c5780635a936d101461068f5780635fb88183146106a257600080fd5b806340ad34d8146105fc57806342842e0e1461060f57806342966c681461062257806344b82a241461063557600080fd5b8063188b04b3116103e05780632abc6bf6116103a45780632abc6bf6146105875780632f745c59146105b0578063327b2a03146105c357806333f06ee6146105d6578063388f5083146105e957600080fd5b8063188b04b314610528578063206657f21461053b57806323b872dd1461054e57806328fbb8051461056157806329c301c21461057457600080fd5b8063095ea7b311610427578063095ea7b3146104d45780630ff98244146104e95780631316529d146104fc578063144a3e831461050d57806318160ddd1461052057600080fd5b806301ffc9a71461045957806304f3bcec1461048157806306fdde03146104ac578063081812fc146104c1575b600080fd5b61046c61046736600461496f565b610adb565b60405190151581526020015b60405180910390f35b601754610494906001600160a01b031681565b6040516001600160a01b039091168152602001610478565b6104b4610b06565b60405161047891906149dc565b6104946104cf3660046149ef565b610b98565b6104e76104e2366004614a24565b610c25565b005b6104e76104f7366004614a60565b610d3a565b60045b604051908152602001610478565b6104b461051b3660046149ef565b610de6565b6008546104ff565b6104e7610536366004614a8e565b610df1565b6104e7610549366004614ac2565b610e8f565b6104e761055c366004614af7565b610ea5565b61046c61056f366004614b23565b610ed6565b6104ff610582366004614b6a565b610eed565b6104ff610595366004614b9e565b6001600160a01b03166000908152600c602052604090205490565b6104ff6105be366004614a24565b610f7e565b6104ff6105d1366004614bcb565b611014565b6104e76105e4366004614c58565b6111a3565b6104e76105f7366004614a8e565b61129e565b6104e761060a366004614ca3565b611323565b6104e761061d366004614af7565b61139f565b6104e76106303660046149ef565b6113ba565b6104ff610643366004614cbf565b611457565b6104e7610656366004614c58565b6114b8565b61066e610669366004614d03565b61151f565b604051610478929190614d69565b6104ff61068a3660046149ef565b611577565b6104e761069d366004614a60565b61160a565b6104e76106b0366004614a8e565b611683565b6104e76106c3366004614d8e565b6116f1565b6104946106d63660046149ef565b611752565b6106ee6106e93660046149ef565b6117c9565b6040516104789190614de0565b6104ff610709366004614b9e565b6117e3565b6104e761071c366004614d03565b61186a565b6104e761072f366004614df3565b6118e4565b6104ff610742366004614b9e565b6001600160a01b03166000908152601c602052604090205490565b6104e761076b366004614ca3565b6119c7565b61046c61077e3660046149ef565b611a71565b6104ff6107913660046149ef565b611a9f565b6104ff6107a4366004614e3a565b611b0b565b6104e76107b7366004614a60565b611b86565b6104ff6107ca366004614e7e565b60009182526019602090815260408084206001600160a01b0393909316845291905290205490565b6104b4611c26565b6104e7610808366004614e7e565b611c35565b6104e761081b366004614a8e565b611cf7565b6104ff61082e366004614bcb565b611d58565b610846610841366004614ea1565b611e43565b6040516104789190614ee2565b6104e7610861366004614f6e565b611ff2565b6104e7610874366004614c58565b611ffd565b6104ff610887366004614a8e565b6120dd565b61089f61089a366004614fdc565b61217e565b6040516104789190615011565b6104ff6108ba366004614cbf565b612272565b6104e76108cd36600461515e565b612299565b6104e76108e03660046151d7565b6122d1565b6104e76108f3366004614d03565b612384565b6013546001600160a01b0316610494565b6104e7610917366004614d03565b61244c565b6104b461092a3660046149ef565b6124be565b6104e761093d3660046151d7565b61258a565b6104ff6109503660046151d7565b612619565b6104e7610963366004614a8e565b61262e565b6104ff610976366004614d03565b6000918252600d6020908152604080842092845291905290205490565b6108466109a13660046149ef565b6126b9565b6109b96109b4366004614d03565b612868565b604051610478919061520b565b6104e76109d4366004614a8e565b6129c9565b6104e76109e73660046152a1565b612a33565b6104b46109fa3660046149ef565b612ac4565b6104e7610a0d366004615323565b612b36565b61046c610a203660046153d4565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b6104b4610a5c3660046149ef565b612cc3565b6104ff612d08565b6104e7610a773660046153fe565b612d17565b6104e7610a8a3660046149ef565b612da1565b6104ff610a9d366004615432565b612df2565b6104ff610ab0366004614a60565b612f33565b6104e7610ac33660046149ef565b61304e565b6104e7610ad63660046153fe565b613120565b60006001600160e01b0319821663780e9d6360e01b1480610b005750610b008261319b565b92915050565b606060008054610b159061548d565b80601f0160208091040260200160405190810160405280929190818152602001828054610b419061548d565b8015610b8e5780601f10610b6357610100808354040283529160200191610b8e565b820191906000526020600020905b815481529060010190602001808311610b7157829003601f168201915b5050505050905090565b6000610ba3826131eb565b610c095760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b6000610c3082611752565b9050806001600160a01b0316836001600160a01b031603610c9d5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610c00565b336001600160a01b0382161480610cb95750610cb98133610a20565b610d2b5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610c00565b610d358383613208565b505050565b610d46813560b2613276565b60135481356000818152600d6020908152604080832081870135808552908352928190205490516337fb824760e11b8152731e58988e34177c407a639f380a9d835223ab79f795636ff7048e95610db39590948901359390926001600160a01b03909216916004016154c1565b60006040518083038186803b158015610dcb57600080fd5b505af4158015610ddf573d6000803e3d6000fd5b5050505050565b6060610b00826124be565b610dfd813560b2613276565b610e0a8160200135613307565b731e58988e34177c407a639f380a9d835223ab79f7639ec52a23823560208401356040850135610e3d60608701876154ed565b6013546020808a01356000908152600a9091526040908190206005015490516001600160e01b031960e08a901b168152610db39796959493926001600160a01b03908116921690600d9060040161555c565b610e9a836002613276565b610d35838383613333565b610eaf338261338f565b610ecb5760405162461bcd60e51b8152600401610c00906155a9565b610d35838383613479565b6000610ee3848484613626565b90505b9392505050565b6000610efb823560ec613276565b610f0582356136b0565b6040516342a34a5360e01b815290915073bb3c660ad95306d4b3e6844a89f236a0233d52f2906342a34a5390610f4990859085906000908190600e90600401615701565b60006040518083038186803b158015610f6157600080fd5b505af4158015610f75573d6000803e3d6000fd5b50505050919050565b6000610f89836117e3565b8210610feb5760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608401610c00565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b6000611022833560ca613276565b6545524337323160d01b600061103885356136b0565b6013549091506000906001600160a01b0316632ea24efc8261105d6020890189614b9e565b6040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152602088013560448201526064016020604051808303816000875af11580156110b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110d79190615746565b905073bb3c660ad95306d4b3e6844a89f236a0233d52f26342a34a538784868561110460208c018c614b9e565b8b6020013560405160200161113792919060609290921b6bffffffffffffffffffffffff19168252601482015260340190565b604051602081830303815290604052600e6040518763ffffffff1660e01b81526004016111699695949392919061575f565b60006040518083038186803b15801561118157600080fd5b505af4158015611195573d6000803e3d6000fd5b509398975050505050505050565b6013546040516367880d6160e11b8152600481018590526000916001600160a01b03169063cf101ac290602401602060405180830381865afa1580156111ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112119190615746565b905061121e8160b1613276565b6013546040516337dfe8e360e21b815273c8f036a975b7a64cc05808779aedb58d859852a69163df7fa38c91611268918891889188916001600160a01b03909116906004016157aa565b60006040518083038186803b15801561128057600080fd5b505af4158015611294573d6000803e3d6000fd5b5050505050505050565b6112aa813560b9613276565b731e58988e34177c407a639f380a9d835223ab79f763a4159c6b82356112d66040850160208601614b9e565b6013546040805160e086901b6001600160e01b031916815260048101949094526001600160a01b0392831660248501528601356044840152166064820152600d608482015260a401610db3565b61132f813560b6613276565b60135460408051631d4deabf60e01b81528335600482015260208401356024820152908301356044820152606083013560648201526001600160a01b039091166084820152600d60a4820152731e58988e34177c407a639f380a9d835223ab79f790631d4deabf9060c401610db3565b610d3583838360405180602001604052806000815250612299565b6000818152600a602052604080822090516113d891600101906157dd565b60408051918290039091206000818152600b6020908152838220829055858252600a90529182208281559092509061141360018301826148be565b6114216002830160006148be565b50600060038201556004810180546001600160a01b0319908116909155600590910180549091169055611453826136d9565b5050565b6000611465833560c8613276565b67131a5b9adb1a5cdd60c21b600061147d85356136b0565b905060008460001b905073bb3c660ad95306d4b3e6844a89f236a0233d52f26342a34a53878486858a60405160200161113791815260200190565b6114c38360b0613276565b6000838152600a602052604090206002016114df828483615899565b50827f17d7c9f69270ba135480ef16837f38b9d37d3ab291cbd3ba03982290c66319978383604051611512929190615958565b60405180910390a2505050565b6000828152601a602090815260408083208484529091529020606090819061154690613738565b6000858152601a60209081526040808320878452909152902090925061156e90600201613738565b90509250929050565b600061158260085490565b82106115e55760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608401610c00565b600882815481106115f8576115f861596c565b90600052602060002001549050919050565b611616813560be613276565b60135481356000818152600d602090815260408083208187013580855290835292819020549051633fe4fe3960e11b8152731e58988e34177c407a639f380a9d835223ab79f795637fc9fc7295610db39590948901359390926001600160a01b03909216916004016154c1565b61168f813560bb613276565b731e58988e34177c407a639f380a9d835223ab79f76348391dcb82356116b860208501856154ed565b601354604080516001600160e01b031960e088901b168152610db39594939291890135916001600160a01b031690600d90600401615982565b6116fb8484613745565b61170584846137aa565b61170f8484613821565b6040516001626802bf60e01b0319815273bb3c660ad95306d4b3e6844a89f236a0233d52f29063ff97fd4190611268908790879087908790600e906004016159c3565b6000818152600260205260408120546001600160a01b031680610b005760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610c00565b6000818152601860205260409020606090610b0090613738565b60006001600160a01b03821661184e5760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610c00565b506001600160a01b031660009081526003602052604090205490565b6118758260c4613276565b61187f82826137aa565b6000828152600e60209081526040808320848452825291829020600501805460ff60a81b1916600160a81b179055905182815283917f036469f3e73c83520cdefa197d7a9c854c2f8bc0164b82e9f2bd4aa7e150fd3091015b60405180910390a25050565b60006118ef85611752565b6001600160a01b038181166000908152601c6020908152604080832080546001810190915581517f53f5e122d65c239c5936ed0eb8ce8ea2c1e77831749ec178c59c5cd4a792fe04938101939093529082018a90529288166060808301919091526080820188905260a08201939093529185013560c083015291925060e0016040516020818303038152906040528051906020012090506119bb6119b4611994613866565b8360405161190160f01b8152600281019290925260228201526042902090565b83856138dc565b50610ddf858585613333565b6119d3813560b8613276565b731e58988e34177c407a639f380a9d835223ab79f7631542463682356119ff6040850160208601614b9e565b60135485356000908152600d6020908152604080832060608a013580855292529182902054825160e088901b6001600160e01b031916815260048101969096526001600160a01b03948516602487015291880135604486015260648501529116608483015260a482015260c401610db3565b600080611a7d83611752565b6001600160a01b03166000908152600c60205260409020549290921492915050565b60135460405162fba02760e01b8152600481018390526000916001600160a01b03169062fba02790602401602060405180830381865afa158015611ae7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b009190615746565b6000611b19833560c7613276565b664164647265737360c81b6000611b3085356136b0565b6040516bffffffffffffffffffffffff19606087901b1660208201529091506001600160a01b0385169073bb3c660ad95306d4b3e6844a89f236a0233d52f2906342a34a53908890859087908690603401611137565b611b92813560ba613276565b731e58988e34177c407a639f380a9d835223ab79f76393c96a528235611bbe6040850160208601614b9e565b60135485356000908152600d60209081526040808320818a013580855292529182902054915160e087901b6001600160e01b031916815260048101959095526001600160a01b039384166024860152604485015291166064830152608482015260a401610db3565b606060018054610b159061548d565b611c40826001613276565b6000828152600a60205260409020600401546001600160a01b031615611c795760405163fe6f50e560e01b815260040160405180910390fd5b6040516384b44a2f60e01b8152600481018390526001600160a01b0382166024820152600a604482015273681be951fa8b6731e9330291331aef94e8b9905c906384b44a2f906064015b60006040518083038186803b158015611cdb57600080fd5b505af4158015611cef573d6000803e3d6000fd5b505050505050565b611d03813560bd613276565b60135460408051632ca904df60e01b8152731e58988e34177c407a639f380a9d835223ab79f792632ca904df92610db392863592602088013592880135916001600160a01b0390911690600d906004016154c1565b6000611d66833560c9613276565b634e6f746560e01b6000611d7a85356136b0565b601354604051635cb46be760e01b815260006004820181905287356024830152602088013560448301529293506001600160a01b0390911690635cb46be7906064016020604051808303816000875af1158015611ddb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dff9190615746565b905073bb3c660ad95306d4b3e6844a89f236a0233d52f26342a34a53878486858a600001358b60200135604051602001611137929190918252602082015260400190565b611e4b6148f8565b60008383604051611e5d9291906159f5565b604080519182900382206000818152600b602090815283822054808352600a82529184902060c0860190945283548552600184018054939650919493929084019190611ea89061548d565b80601f0160208091040260200160405190810160405280929190818152602001828054611ed49061548d565b8015611f215780601f10611ef657610100808354040283529160200191611f21565b820191906000526020600020905b815481529060010190602001808311611f0457829003601f168201915b50505050508152602001600282018054611f3a9061548d565b80601f0160208091040260200160405190810160405280929190818152602001828054611f669061548d565b8015611fb35780601f10611f8857610100808354040283529160200191611fb3565b820191906000526020600020905b815481529060010190602001808311611f9657829003601f168201915b50505091835250506003820154602082015260048201546001600160a01b03908116604083015260059092015490911660609091015295945050505050565b6114533383836139b9565b612008836000613276565b612028828260405161201b9291906159f5565b6040518091039020613a87565b61206782828080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250613ab492505050565b60405163130f361d60e01b815273681be951fa8b6731e9330291331aef94e8b9905c9063130f361d906120a890869086908690600b90600a90600401615a05565b60006040518083038186803b1580156120c057600080fd5b505af41580156120d4573d6000803e3d6000fd5b50505050505050565b60006120ee823560208401356137aa565b73bb3c660ad95306d4b3e6844a89f236a0233d52f2639d2e06f08335602085013561211f6060870160408801614b9e565b61212c60608801886154ed565b6014546040516001600160e01b031960e089901b1681526121619695949392916001600160a01b031690600e90600401615a33565b602060405180830381865af4158015611ae7573d6000803e3d6000fd5b6060816001600160401b0381111561219857612198615073565b6040519080825280602002602001820160405280156121cb57816020015b60608152602001906001900390816121b65790505b50905060005b8281101561226b5761223b308585848181106121ef576121ef61596c565b905060200281019061220191906154ed565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250613b2192505050565b82828151811061224d5761224d61596c565b6020026020010181905250808061226390615a8d565b9150506121d1565b5092915050565b6000612280833560c6613276565b6821b430b930b1ba32b960b91b600061147d85356136b0565b6122a3338361338f565b6122bf5760405162461bcd60e51b8152600401610c00906155a9565b6122cb84848484613b46565b50505050565b6122dd813560b5613276565b6122ef816020013582604001356137aa565b731e58988e34177c407a639f380a9d835223ab79f76371bd9b06823560208401356040850135606086013561232760808801886154ed565b6013546020808b01356000908152600e82526040808220818e013583529092528190206003015490516001600160e01b031960e08b901b168152610db3989796959493926001600160a01b03908116921690600d90600401615aa6565b6013546040516367880d6160e11b8152600481018490526000916001600160a01b03169063cf101ac290602401602060405180830381865afa1580156123ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123f29190615746565b90506123ff8160cc613276565b60135460405163015800dd60e71b815273c8f036a975b7a64cc05808779aedb58d859852a69163ac006e80916120a8918591889188916001600160a01b0390911690600d906004016154c1565b6124578260c5613276565b61246182826137aa565b6000828152600e60209081526040808320848452825291829020600501805460ff60a01b1916600160a01b179055905182815283917f4f1db9708b537c1d26a7af4b235fd079bf2342d92a276e27eb6c8717e8bbcf9391016118d8565b6060816124ca816131eb565b6124e7576040516366012df560e11b815260040160405180910390fd5b6000838152600a6020526040902060020180546125039061548d565b80601f016020809104026020016040519081016040528092919081815260200182805461252f9061548d565b801561257c5780601f106125515761010080835404028352916020019161257c565b820191906000526020600020905b81548152906001019060200180831161255f57829003601f168201915b505050505091505b50919050565b612596813560b7613276565b731e58988e34177c407a639f380a9d835223ab79f763f35deae182356125c26040850160208601614b9e565b6013546040805160e086901b6001600160e01b031916815260048101949094526001600160a01b039283166024850152860135604484015260608601356064840152166084820152600d60a482015260c401610db3565b6000610b0061262783615afc565b6001613b79565b61263a813560c2613276565b612649813560208301356137aa565b61265881356020830135613821565b73bb3c660ad95306d4b3e6844a89f236a0233d52f26320828a02823560208401356126896060860160408701614b9e565b61269660608701876154ed565b600e6040518763ffffffff1660e01b8152600401610db396959493929190615baf565b6126c16148f8565b816126cb816131eb565b6126e8576040516366012df560e11b815260040160405180910390fd5b600a60008481526020019081526020016000206040518060c0016040529081600082015481526020016001820180546127209061548d565b80601f016020809104026020016040519081016040528092919081815260200182805461274c9061548d565b80156127995780601f1061276e57610100808354040283529160200191612799565b820191906000526020600020905b81548152906001019060200180831161277c57829003601f168201915b505050505081526020016002820180546127b29061548d565b80601f01602080910402602001604051908101604052809291908181526020018280546127de9061548d565b801561282b5780601f106128005761010080835404028352916020019161282b565b820191906000526020600020905b81548152906001019060200180831161280e57829003601f168201915b50505091835250506003820154602082015260048201546001600160a01b0390811660408301526005909201549091166060909101529392505050565b60408051610100808201835260008083526020808401829052606084860181905284018290526080840182905260a0840182905260c0840182905260e08401829052868252600e815284822086835281529084902084519283018552805483526001810154918301919091526002810180549394929391928401916128ec9061548d565b80601f01602080910402602001604051908101604052809291908181526020018280546129189061548d565b80156129655780601f1061293a57610100808354040283529160200191612965565b820191906000526020600020905b81548152906001019060200180831161294857829003601f168201915b505050918352505060038201546001600160a01b039081166020830152600483015481166040830152600590920154918216606082015260ff600160a01b8304811615156080830152600160a81b909204909116151560a090910152905092915050565b6129d5813560c0613276565b6129e481356020830135613745565b6129f3813560208301356137aa565b612a0281356020830135613821565b73bb3c660ad95306d4b3e6844a89f236a0233d52f2631f2ffb69823560208401356126896060860160408701614b9e565b612a3e866003613276565b612a4886866137aa565b604051630afb883f60e41b815273f29b2c1b0722a9ab38062622133503c21a853e8f9063afb883f090612a8c90899089908990899089908990601a90600401615c2c565b60006040518083038186803b158015612aa457600080fd5b505af4158015612ab8573d6000803e3d6000fd5b50505050505050505050565b601354604051632b05429560e21b8152600481018390526060916001600160a01b03169063ac150a5490602401600060405180830381865afa158015612b0e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610b009190810190615c74565b601454600390600160a81b900460ff16158015612b61575060145460ff808316600160a01b90920416105b612bc45760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610c00565b6014805460ff60a81b1960ff8416600160a01b021661ffff60a01b1990911617600160a81b179055612bf889898989613c56565b601380546001600160a01b03199081166001600160a01b0388811691909117909255601480548216878416179055601580548216868416179055601b80549091169184169190911790556040514281527f400175a56dd3710794078f7b9dbe8296ac94c5a248dfd51bb22ed4ab9eaa9fbf9060200160405180910390a16014805460ff60a81b1916905560405160ff821681527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a1505050505050505050565b606081612ccf816131eb565b612cec576040516366012df560e11b815260040160405180910390fd5b6000838152600a6020526040902060010180546125039061548d565b6000612d12613866565b905090565b612d23813560bc613276565b731e58988e34177c407a639f380a9d835223ab79f7631873e2188235612d4c60208501856154ed565b60135486356000908152600d60209081526040808320818b01358085529252918290205491516001600160e01b031960e089901b168152610db39695949391926001600160a01b039092169190600401615982565b612daa81613ca7565b326000908152600c6020526040808220805490849055905190918291849133917fce95332e6082aebeb8058a7b56d1a109f67d6550552ed04d36aca4a6acd4d7de9190a45050565b6000612e00843560cb613276565b65416e7955726960d01b6000612e1686356136b0565b601354604051633610bf0960e11b81529192506000916001600160a01b0390911690636c217e1290612e509084908a908a90600401615ce1565b6020604051808303816000875af1158015612e6f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e939190615746565b905073bb3c660ad95306d4b3e6844a89f236a0233d52f26342a34a53888486858b8b604051602001612ec69291906159f5565b604051602081830303815290604052600e6040518763ffffffff1660e01b8152600401612ef89695949392919061575f565b60006040518083038186803b158015612f1057600080fd5b505af4158015612f24573d6000803e3d6000fd5b50939998505050505050505050565b6000612f41823560b4613276565b612fcf6040518060a00160405280846020016020810190612f629190614b9e565b6001600160a01b03168152602001612f8b856020016020810190612f869190614b9e565b613d0d565b815260200160405180602001604052806000815250815260200160006001600160a01b03168152602001604051806020016040528060008152508152506000613b79565b60135460408051639ec52a2360e01b8152853560048201526024810184905290850135604482015260e06064820152600060e482018190526001600160a01b03909216608482015260a4810191909152600d60c4820152909150731e58988e34177c407a639f380a9d835223ab79f790639ec52a239061010401610f49565b6013546040516367880d6160e11b8152600481018390526000916001600160a01b03169063cf101ac290602401602060405180830381865afa158015613098573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130bc9190615746565b90506130c781613ca7565b6013546040516318abcde360e01b815260048101839052602481018490526001600160a01b039091166044820152600d606482015273c8f036a975b7a64cc05808779aedb58d859852a6906318abcde390608401611cc3565b61312c813560bf613276565b73681be951fa8b6731e9330291331aef94e8b9905c631dc8313382356131586040850160208601614b9e565b61316560408601866154ed565b86356000908152600a60205260409081902090516001600160e01b031960e088901b168152610db3959493929190600401615cfb565b60006001600160e01b031982166380ac58cd60e01b14806131cc57506001600160e01b03198216635b5e139f60e01b145b80610b0057506301ffc9a760e01b6001600160e01b0319831614610b00565b6000908152600260205260409020546001600160a01b0316151590565b600081815260046020526040902080546001600160a01b0319166001600160a01b038416908117909155819061323d82611752565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b61327f82613e16565b15613288575050565b6015546001600160a01b031633036132c4576000828152601960209081526040808320328452909152902054600190821c8116036132c4575050565b6000828152601960209081526040808320338452909152902054600190821c8116036132ee575050565b604051632c4bc2b960e21b815260040160405180910390fd5b613310816131eb565b613330576040516375af0fc960e11b815260048101829052602401610c00565b50565b604051631f8c0b6760e11b8152600481018490526001600160a01b038316602482015260448101829052601860648201526019608482015273f29b2c1b0722a9ab38062622133503c21a853e8f90633f1816ce9060a4016120a8565b600061339a826131eb565b6133fb5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610c00565b600061340683611752565b9050806001600160a01b0316846001600160a01b031614806134415750836001600160a01b031661343684610b98565b6001600160a01b0316145b8061347157506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b031661348c82611752565b6001600160a01b0316146134f05760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b6064820152608401610c00565b6001600160a01b0382166135525760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610c00565b61355d838383613e76565b613568600082613208565b6001600160a01b0383166000908152600360205260408120805460019290613591908490615d26565b90915550506001600160a01b03821660009081526003602052604081208054600192906135bf908490615d39565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4610d35838383613f48565b6000838152601a6020908152604080832085845290915281206136498184613f85565b15613658576000915050610ee6565b6136656002820184613f85565b15613674576001915050610ee6565b60008581526019602090815260408083206001600160a01b03871684529091529020546136a79060c31c60019081161490565b95945050505050565b6000818152600a60205260408120600301805482906136ce90615a8d565b918290555092915050565b6136e3338261338f565b61372f5760405162461bcd60e51b815260206004820152601b60248201527f4e4654426173653a204e6f744f776e65724f72417070726f76656400000000006044820152606401610c00565b61333081613fa7565b60606000610ee683614056565b61374e82613e16565b15613757575050565b6015546001600160a01b0316330361377d57613774828232613626565b1561377d575050565b613788828233613626565b15613791575050565b604051631a1d1d4760e11b815260040160405180910390fd5b6000828152600e60209081526040808320848452909152902060050154600160a01b900460ff16156137ef57604051631f0fc8f560e11b815260040160405180910390fd5b6000828152600a6020526040902060030154811115611453576040516364783acb60e01b815260040160405180910390fd5b6000828152600e60209081526040808320848452909152902060050154600160a81b900460ff161561145357604051630bc06a0f60e21b815260040160405180910390fd5b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f613891610b06565b8051602091820120604080519283019390935291810191909152600160608201524660808201523060a082015260c00160405160208183030381529060405280519060200120905090565b4281606001351015613900576040516275e96160e01b815260040160405180910390fd5b60006001846139126020850185615d4c565b604080516000815260208181018084529490945260ff9092168282015291850135606082015290840135608082015260a0016020604051602081039080840390855afa158015613966573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116158061399b5750826001600160a01b0316816001600160a01b031614155b156122cb57604051636a9ca51760e01b815260040160405180910390fd5b816001600160a01b0316836001600160a01b031603613a1a5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610c00565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b6000818152600b60205260409020541561333057604051631b659b9f60e21b815260040160405180910390fd5b80518190601f811180613ac75750600381105b15613ae557604051636f819c2160e11b815260040160405180910390fd5b60005b818110156122cb57613b19838281518110613b0557613b0561596c565b01602001516001600160f81b0319166140b2565b600101613ae8565b6060610ee68383604051806060016040528060278152602001615ef560279139614160565b613b51848484613479565b613b5d848484846141d8565b6122cb5760405162461bcd60e51b8152600401610c0090615d6f565b6000613b8f836020015180519060200120613a87565b8115613ba257613ba28360200151613ab4565b601260008154613bb190615a8d565b91829055508351909150613bc590826142d9565b73681be951fa8b6731e9330291331aef94e8b9905c634daae5688460000151856020015186604001518760600151886080015187600b600a6040518963ffffffff1660e01b8152600401613c20989796959493929190615dc1565b60006040518083038186803b158015613c3857600080fd5b505af4158015613c4c573d6000803e3d6000fd5b5050505092915050565b613c62848484846142f3565b7f414cd0b34676984f09a5f76ce9718d4062e50283abe0e7e274a9a5b4e0c99c308484848442604051613c99959493929190615e38565b60405180910390a150505050565b6000613cb282611752565b6015549091506001600160a01b031633148015613cd75750326001600160a01b038216145b15613ce0575050565b6001600160a01b0381163303613cf4575050565b604051631b0c476f60e11b815260040160405180910390fd5b60408051602a80825260608281019093526f181899199a1a9b1b9c1cb0b131b232b360811b916001600160a01b0385169160009190602082018180368337019050509050600360fc1b81600081518110613d6957613d6961596c565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110613d9857613d9861596c565b60200101906001600160f81b031916908160001a90535060295b6001811115613e0d578383600f1660108110613dd057613dd061596c565b1a60f81b828281518110613de657613de661596c565b60200101906001600160f81b031916908160001a90535060049290921c9160001901613db2565b50949350505050565b600080613e2283611752565b90506001600160a01b0381163303613e3d5750600192915050565b6015546001600160a01b031633148015613e5f5750326001600160a01b038216145b15613e6d5750600192915050565b50600092915050565b601b546001600160a01b03848116911614613f3d576000818152601860205260408120613ea29061430e565b600083815260186020526040812091925090613ebd90613738565b905060005b82811015613eff57613eed84838381518110613ee057613ee061596c565b6020026020010151614318565b80613ef781615a8d565b915050613ec2565b506001600160a01b0385166000908152600c6020526040902054839003613f3a576001600160a01b0385166000908152600c60205260408120555b50505b610d35838383614351565b6001600160a01b0382166000908152600c60205260408120549003610d35576001600160a01b03919091166000908152600c602052604090205550565b6001600160a01b03811660009081526001830160205260408120541515610ee6565b6000613fb282611752565b9050613fc081600084613e76565b613fcb600083613208565b6001600160a01b0381166000908152600360205260408120805460019290613ff4908490615d26565b909155505060008281526002602052604080822080546001600160a01b0319169055518391906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a461145381600084613f48565b6060816000018054806020026020016040519081016040528092919081815260200182805480156140a657602002820191906000526020600020905b815481526020019060010190808311614092575b50505050509050919050565b600360fc1b6001600160f81b0319821610806140db5750603d60f91b6001600160f81b03198216115b8061410b5750603960f81b6001600160f81b0319821611801561410b5750606160f81b6001600160f81b03198216105b80156141255750602d60f81b6001600160f81b0319821614155b801561413f5750605f60f81b6001600160f81b0319821614155b15613330576040516001621693dd60e01b0319815260040160405180910390fd5b6060600080856001600160a01b03168560405161417d9190615e72565b600060405180830381855af49150503d80600081146141b8576040519150601f19603f3d011682016040523d82523d6000602084013e6141bd565b606091505b50915091506141ce86838387614409565b9695505050505050565b60006001600160a01b0384163b156142ce57604051630a85bd0160e11b81526001600160a01b0385169063150b7a029061421c903390899088908890600401615e8e565b6020604051808303816000875af1925050508015614257575060408051601f3d908101601f1916820190925261425491810190615ec1565b60015b6142b4573d808015614285576040519150601f19603f3d011682016040523d82523d6000602084013e61428a565b606091505b5080516000036142ac5760405162461bcd60e51b8152600401610c0090615d6f565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050613471565b506001949350505050565b611453828260405180602001604052806000815250614482565b6000614300848683615899565b506001610ddf828483615899565b6000610b00825490565b60008281526019602090815260408083206001600160a01b0385168452825280832083905584835260189091529020610d3590826144b5565b6001600160a01b0383166143ac576143a781600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b6143cf565b816001600160a01b0316836001600160a01b0316146143cf576143cf83826144ca565b6001600160a01b0382166143e657610d3581614567565b826001600160a01b0316826001600160a01b031614610d3557610d358282614616565b60608315614478578251600003614471576001600160a01b0385163b6144715760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610c00565b5081613471565b613471838361465a565b61448c8383614684565b61449960008484846141d8565b610d355760405162461bcd60e51b8152600401610c0090615d6f565b6000610ee6836001600160a01b0384166147cb565b600060016144d7846117e3565b6144e19190615d26565b600083815260076020526040902054909150808214614534576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b60085460009061457990600190615d26565b600083815260096020526040812054600880549394509092849081106145a1576145a161596c565b9060005260206000200154905080600883815481106145c2576145c261596c565b60009182526020808320909101929092558281526009909152604080822084905585825281205560088054806145fa576145fa615ede565b6001900381819060005260206000200160009055905550505050565b6000614621836117e3565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b81511561466a5781518083602001fd5b8060405162461bcd60e51b8152600401610c0091906149dc565b6001600160a01b0382166146da5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610c00565b6146e3816131eb565b156147305760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610c00565b61473c60008383613e76565b6001600160a01b0382166000908152600360205260408120805460019290614765908490615d39565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a461145360008383613f48565b600081815260018301602052604081205480156148b45760006147ef600183615d26565b855490915060009061480390600190615d26565b90508181146148685760008660000182815481106148235761482361596c565b90600052602060002001549050808760000184815481106148465761484661596c565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061487957614879615ede565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610b00565b6000915050610b00565b5080546148ca9061548d565b6000825580601f106148da575050565b601f0160209004906000526020600020908101906133309190614940565b6040518060c001604052806000815260200160608152602001606081526020016000815260200160006001600160a01b0316815260200160006001600160a01b031681525090565b5b808211156149555760008155600101614941565b5090565b6001600160e01b03198116811461333057600080fd5b60006020828403121561498157600080fd5b8135610ee681614959565b60005b838110156149a757818101518382015260200161498f565b50506000910152565b600081518084526149c881602086016020860161498c565b601f01601f19169290920160200192915050565b602081526000610ee660208301846149b0565b600060208284031215614a0157600080fd5b5035919050565b80356001600160a01b0381168114614a1f57600080fd5b919050565b60008060408385031215614a3757600080fd5b614a4083614a08565b946020939093013593505050565b60006060828403121561258457600080fd5b600060608284031215614a7257600080fd5b610ee68383614a4e565b60006080828403121561258457600080fd5b600060208284031215614aa057600080fd5b81356001600160401b03811115614ab657600080fd5b61347184828501614a7c565b600080600060608486031215614ad757600080fd5b83359250614ae760208501614a08565b9150604084013590509250925092565b600080600060608486031215614b0c57600080fd5b614b1584614a08565b9250614ae760208501614a08565b600080600060608486031215614b3857600080fd5b8335925060208401359150614b4f60408501614a08565b90509250925092565b600060e0828403121561258457600080fd5b600060208284031215614b7c57600080fd5b81356001600160401b03811115614b9257600080fd5b61347184828501614b58565b600060208284031215614bb057600080fd5b610ee682614a08565b60006040828403121561258457600080fd5b60008060608385031215614bde57600080fd5b82356001600160401b03811115614bf457600080fd5b614c0085828601614b58565b92505061156e8460208501614bb9565b60008083601f840112614c2257600080fd5b5081356001600160401b03811115614c3957600080fd5b602083019150836020828501011115614c5157600080fd5b9250929050565b600080600060408486031215614c6d57600080fd5b8335925060208401356001600160401b03811115614c8a57600080fd5b614c9686828701614c10565b9497909650939450505050565b600060808284031215614cb557600080fd5b610ee68383614a7c565b60008060408385031215614cd257600080fd5b82356001600160401b03811115614ce857600080fd5b614cf485828601614b58565b95602094909401359450505050565b60008060408385031215614d1657600080fd5b50508035926020909101359150565b600081518084526020808501945080840160005b83811015614d5e5781516001600160a01b031687529582019590820190600101614d39565b509495945050505050565b604081526000614d7c6040830185614d25565b82810360208401526136a78185614d25565b60008060008060608587031215614da457600080fd5b843593506020850135925060408501356001600160401b03811115614dc857600080fd5b614dd487828801614c10565b95989497509550505050565b602081526000610ee66020830184614d25565b60008060008060e08587031215614e0957600080fd5b84359350614e1960208601614a08565b925060408501359150614e2f8660608701614a7c565b905092959194509250565b60008060408385031215614e4d57600080fd5b82356001600160401b03811115614e6357600080fd5b614e6f85828601614b58565b92505061156e60208401614a08565b60008060408385031215614e9157600080fd5b8235915061156e60208401614a08565b60008060208385031215614eb457600080fd5b82356001600160401b03811115614eca57600080fd5b614ed685828601614c10565b90969095509350505050565b60208152815160208201526000602083015160c06040840152614f0860e08401826149b0565b90506040840151601f19848303016060850152614f2582826149b0565b91505060608401516080840152608084015160018060a01b0380821660a08601528060a08701511660c086015250508091505092915050565b80358015158114614a1f57600080fd5b60008060408385031215614f8157600080fd5b614f8a83614a08565b915061156e60208401614f5e565b60008083601f840112614faa57600080fd5b5081356001600160401b03811115614fc157600080fd5b6020830191508360208260051b8501011115614c5157600080fd5b60008060208385031215614fef57600080fd5b82356001600160401b0381111561500557600080fd5b614ed685828601614f98565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561506657603f198886030184526150548583516149b0565b94509285019290850190600101615038565b5092979650505050505050565b634e487b7160e01b600052604160045260246000fd5b60405160a081016001600160401b03811182821017156150ab576150ab615073565b60405290565b604051601f8201601f191681016001600160401b03811182821017156150d9576150d9615073565b604052919050565b60006001600160401b038211156150fa576150fa615073565b50601f01601f191660200190565b600082601f83011261511957600080fd5b813561512c615127826150e1565b6150b1565b81815284602083860101111561514157600080fd5b816020850160208301376000918101602001919091529392505050565b6000806000806080858703121561517457600080fd5b61517d85614a08565b935061518b60208601614a08565b92506040850135915060608501356001600160401b038111156151ad57600080fd5b6151b987828801615108565b91505092959194509250565b600060a0828403121561258457600080fd5b6000602082840312156151e957600080fd5b81356001600160401b038111156151ff57600080fd5b613471848285016151c5565b6020815281516020820152602082015160408201526000604083015161010080606085015261523e6101208501836149b0565b9150606085015160018060a01b0380821660808701528060808801511660a0870152505060a085015161527c60c08601826001600160a01b03169052565b5060c085015180151560e08601525060e0850151801515858301525090949350505050565b600080600080600080608087890312156152ba57600080fd5b863595506020870135945060408701356001600160401b03808211156152df57600080fd5b6152eb8a838b01614f98565b9096509450606089013591508082111561530457600080fd5b5061531189828a01614f98565b979a9699509497509295939492505050565b60008060008060008060008060c0898b03121561533f57600080fd5b88356001600160401b038082111561535657600080fd5b6153628c838d01614c10565b909a50985060208b013591508082111561537b57600080fd5b506153888b828c01614c10565b909750955061539b905060408a01614a08565b93506153a960608a01614a08565b92506153b760808a01614a08565b91506153c560a08a01614a08565b90509295985092959890939650565b600080604083850312156153e757600080fd5b6153f083614a08565b915061156e60208401614a08565b60006020828403121561541057600080fd5b81356001600160401b0381111561542657600080fd5b61347184828501614a4e565b60008060006040848603121561544757600080fd5b83356001600160401b038082111561545e57600080fd5b61546a87838801614b58565b9450602086013591508082111561548057600080fd5b50614c9686828701614c10565b600181811c908216806154a157607f821691505b60208210810361258457634e487b7160e01b600052602260045260246000fd5b948552602085019390935260408401919091526001600160a01b03166060830152608082015260a00190565b6000808335601e1984360301811261550457600080fd5b8301803591506001600160401b0382111561551e57600080fd5b602001915036819003821315614c5157600080fd5b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b88815287602082015286604082015260e06060820152600061558260e083018789615533565b6001600160a01b0395861660808401529390941660a082015260c001529695505050505050565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6000808335601e1984360301811261561157600080fd5b83016020810192503590506001600160401b0381111561563057600080fd5b803603821315614c5157600080fd5b80358252600061565260208301836155fa565b60e0602086015261566760e086018284615533565b91505061567660408401614a08565b6001600160a01b03818116604087015261569360608601866155fa565b925086840360608801526156a8848483615533565b935050806156b860808701614a08565b16608087015250506156cd60a08401846155fa565b85830360a08701526156e0838284615533565b925050506156f060c08401614f5e565b151560c08501528091505092915050565b60c08152600061571460c083018861563f565b602083810197909752604083019590955250606081019290925281830360808301526000835260a09091015201919050565b60006020828403121561575857600080fd5b5051919050565b60c08152600061577260c083018961563f565b876020840152866040840152856060840152828103608084015261579681866149b0565b9150508260a0830152979650505050505050565b8481526060602082015260006157c4606083018587615533565b905060018060a01b038316604083015295945050505050565b60008083546157eb8161548d565b60018281168015615803576001811461581857615847565b60ff1984168752821515830287019450615847565b8760005260208060002060005b8581101561583e5781548a820152908401908201615825565b50505082870194505b50929695505050505050565b601f821115610d3557600081815260208120601f850160051c8101602086101561587a5750805b601f850160051c820191505b81811015611cef57828155600101615886565b6001600160401b038311156158b0576158b0615073565b6158c4836158be835461548d565b83615853565b6000601f8411600181146158f857600085156158e05750838201355b600019600387901b1c1916600186901b178355610ddf565b600083815260209020601f19861690835b828110156159295786850135825560209485019460019092019101615909565b50868210156159465760001960f88860031b161c19848701351681555b505060018560011b0183555050505050565b602081526000610ee3602083018486615533565b634e487b7160e01b600052603260045260246000fd5b86815260a06020820152600061599c60a083018789615533565b6040830195909552506001600160a01b039290921660608301526080909101529392505050565b8581528460208201526080604082015260006159e3608083018587615533565b90508260608301529695505050505050565b8183823760009101908152919050565b858152608060208201526000615a1f608083018688615533565b604083019490945250606001529392505050565b878152866020820152600060018060a01b03808816604084015260c06060840152615a6260c084018789615533565b941660808301525060a0015295945050505050565b634e487b7160e01b600052601160045260246000fd5b600060018201615a9f57615a9f615a77565b5060010190565b60006101008b83528a6020840152896040840152886060840152806080840152615ad3818401888a615533565b6001600160a01b0396871660a08501529490951660c08301525060e00152979650505050505050565b600060a08236031215615b0e57600080fd5b615b16615089565b615b1f83614a08565b815260208301356001600160401b0380821115615b3b57600080fd5b615b4736838701615108565b60208401526040850135915080821115615b6057600080fd5b615b6c36838701615108565b6040840152615b7d60608601614a08565b60608401526080850135915080821115615b9657600080fd5b50615ba336828601615108565b60808301525092915050565b86815285602082015260018060a01b038516604082015260a060608201526000615bdd60a083018587615533565b9050826080830152979650505050505050565b8183526000602080850194508260005b85811015614d5e576001600160a01b03615c1983614a08565b1687529582019590820190600101615c00565b87815286602082015260a060408201526000615c4c60a083018789615bf0565b8281036060840152615c5f818688615bf0565b91505082608083015298975050505050505050565b600060208284031215615c8657600080fd5b81516001600160401b03811115615c9c57600080fd5b8201601f81018413615cad57600080fd5b8051615cbb615127826150e1565b818152856020838501011115615cd057600080fd5b6136a782602083016020860161498c565b8381526040602082015260006136a7604083018486615533565b8581526001600160a01b03851660208201526080604082018190526000906159e39083018587615533565b81810381811115610b0057610b00615a77565b80820180821115610b0057610b00615a77565b600060208284031215615d5e57600080fd5b813560ff81168114610ee657600080fd5b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6001600160a01b03898116825261010060208301819052600091615de78483018c6149b0565b91508382036040850152615dfb828b6149b0565b908916606085015283810360808501529050615e1781886149b0565b60a0840196909652505060c081019290925260e09091015295945050505050565b606081526000615e4c606083018789615533565b8281036020840152615e5f818688615533565b9150508260408301529695505050505050565b60008251615e8481846020870161498c565b9190910192915050565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906141ce908301846149b0565b600060208284031215615ed357600080fd5b8151610ee681614959565b634e487b7160e01b600052603160045260246000fdfe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220b42b876718621722bfaab42c9763116a3e2896f34b0df979d356b6727834e38064736f6c63430008120033