POL Price: $0.579556 (-13.36%)
Gas: 36.9 GWei
 

Overview

POL Balance

Polygon PoS Chain LogoPolygon PoS Chain LogoPolygon PoS Chain Logo0 POL

POL Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

Parent Transaction Hash Block From To
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
FollowNFT

Compiler Version
v0.8.21+commit.d9974bed

Optimization Enabled:
Yes with 10 runs

Other Settings:
paris EvmVersion, MIT license
File 1 of 33 : FollowNFT.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.15;

import {Types} from 'contracts/libraries/constants/Types.sol';
import {ERC2981CollectionRoyalties} from 'contracts/base/ERC2981CollectionRoyalties.sol';
import {Errors} from 'contracts/libraries/constants/Errors.sol';
import {HubRestricted} from 'contracts/base/HubRestricted.sol';
import {IERC721} from '@openzeppelin/contracts/token/ERC721/IERC721.sol';
import {IERC721Timestamped} from 'contracts/interfaces/IERC721Timestamped.sol';
import {IFollowNFT} from 'contracts/interfaces/IFollowNFT.sol';
import {ILensHub} from 'contracts/interfaces/ILensHub.sol';
import {LensBaseERC721} from 'contracts/base/LensBaseERC721.sol';
import {Strings} from '@openzeppelin/contracts/utils/Strings.sol';
import {StorageLib} from 'contracts/libraries/StorageLib.sol';
import {Types} from 'contracts/libraries/constants/Types.sol';
import {IFollowTokenURI} from 'contracts/interfaces/IFollowTokenURI.sol';

/**
 * @custom:upgradeable Beacon proxy. The beacon, responsible for returning the implementation address, is the LensHub.
 */
contract FollowNFT is HubRestricted, LensBaseERC721, ERC2981CollectionRoyalties, IFollowNFT {
    using Strings for uint256;

    string constant FOLLOW_NFT_NAME_SUFFIX = '-Follower';
    string constant FOLLOW_NFT_SYMBOL_SUFFIX = '-Fl';

    uint256[5] ___DEPRECATED_SLOTS; // Deprecated slots, previously used for delegations.
    uint256 internal _followedProfileId;

    // Old uint256 `_lastFollowTokenId` slot splitted into two uint128s to include `_followerCount`.
    uint128 internal _lastFollowTokenId;
    // `_followerCount` will not be decreased when a follower profile is burned, making the counter not fully accurate.
    // New variable added in V2 in the same slot, lower-ordered to not conflict with previous storage layout.
    uint128 internal _followerCount;

    bool private _initialized;

    // Introduced in v2
    mapping(uint256 => Types.FollowData) internal _followDataByFollowTokenId;
    mapping(uint256 => uint256) internal _followTokenIdByFollowerProfileId;
    mapping(uint256 => uint256) internal _followApprovalByFollowTokenId;
    uint256 internal _royaltiesInBasisPoints;

    event FollowApproval(uint256 indexed followerProfileId, uint256 indexed followTokenId);

    modifier whenNotPaused() {
        if (ILensHub(HUB).getState() == Types.ProtocolState.Paused) {
            revert Errors.Paused();
        }
        _;
    }

    constructor(address hub) HubRestricted(hub) {
        _initialized = true;
    }

    /// @inheritdoc IFollowNFT
    function initialize(uint256 profileId) external override {
        // This is called right after deployment by the LensHub, so we can skip the onlyHub check.
        if (_initialized) {
            revert Errors.Initialized();
        }
        _initialized = true;
        _followedProfileId = profileId;
        _setRoyalty(1000); // 10% of royalties
    }

    /// @inheritdoc IFollowNFT
    function follow(
        uint256 followerProfileId,
        address transactionExecutor,
        uint256 followTokenId
    ) external override onlyHub returns (uint256) {
        if (_followTokenIdByFollowerProfileId[followerProfileId] != 0) {
            revert AlreadyFollowing();
        }

        if (followTokenId == 0) {
            // Fresh follow.
            return _followMintingNewToken(followerProfileId);
        }

        address followTokenOwner = _unsafeOwnerOf(followTokenId);
        if (followTokenOwner != address(0)) {
            // Provided follow token is wrapped.
            return
                _followWithWrappedToken({
                    followerProfileId: followerProfileId,
                    transactionExecutor: transactionExecutor,
                    followTokenId: followTokenId
                });
        }

        uint256 currentFollowerProfileId = _followDataByFollowTokenId[followTokenId].followerProfileId;
        if (currentFollowerProfileId != 0) {
            // Provided follow token is unwrapped.
            // It has a follower profile set already, it can only be used to follow if that profile was burnt.
            return
                _followWithUnwrappedTokenFromBurnedProfile({
                    followerProfileId: followerProfileId,
                    followTokenId: followTokenId,
                    currentFollowerProfileId: currentFollowerProfileId,
                    transactionExecutor: transactionExecutor
                });
        }

        // Provided follow token does not exist anymore, it can only be used if the profile attempting to follow is
        // allowed to recover it.
        return _followByRecoveringToken({followerProfileId: followerProfileId, followTokenId: followTokenId});
    }

    /// @inheritdoc IFollowNFT
    function unfollow(uint256 unfollowerProfileId) external override onlyHub {
        uint256 followTokenId = _followTokenIdByFollowerProfileId[unfollowerProfileId];
        if (followTokenId == 0) {
            revert NotFollowing();
        }
        address followTokenOwner = _unsafeOwnerOf(followTokenId);
        // LensHub already validated that this action can only be performed by the unfollower profile's owner or one of
        // his approved delegated executors.
        _unfollow({unfollower: unfollowerProfileId, followTokenId: followTokenId});
        if (followTokenOwner == address(0)) {
            // Follow token was unwrapped, allowing recovery.
            _followDataByFollowTokenId[followTokenId].profileIdAllowedToRecover = unfollowerProfileId;
        }
    }

    /// @inheritdoc IFollowNFT
    function removeFollower(uint256 followTokenId) external override whenNotPaused {
        if (_isApprovedOrOwner(msg.sender, followTokenId)) {
            _unfollowIfHasFollower(followTokenId, msg.sender);
        } else {
            revert DoesNotHavePermissions();
        }
    }

    /// @inheritdoc IFollowNFT
    function approveFollow(uint256 followerProfileId, uint256 followTokenId) external override {
        if (!IERC721Timestamped(HUB).exists(followerProfileId)) {
            revert Errors.TokenDoesNotExist();
        }
        // `followTokenId` allowed to be zero as a way to clear the approval.
        if (followTokenId != 0 && _unsafeOwnerOf(followTokenId) == address(0)) {
            revert OnlyWrappedFollowTokens();
        }
        if (_isApprovedOrOwner(msg.sender, followTokenId)) {
            _approveFollow(followerProfileId, followTokenId);
        } else {
            revert DoesNotHavePermissions();
        }
    }

    /// @inheritdoc IFollowNFT
    function wrap(uint256 followTokenId, address wrappedTokenReceiver) external override whenNotPaused {
        if (wrappedTokenReceiver == address(0)) {
            revert Errors.InvalidParameter();
        }
        _wrap(followTokenId, wrappedTokenReceiver);
    }

    /// @inheritdoc IFollowNFT
    function wrap(uint256 followTokenId) external override whenNotPaused {
        _wrap(followTokenId, address(0));
    }

    function _wrap(uint256 followTokenId, address wrappedTokenReceiver) internal {
        if (_isFollowTokenWrapped(followTokenId)) {
            revert AlreadyWrapped();
        }
        uint256 followerProfileId = _followDataByFollowTokenId[followTokenId].followerProfileId;
        if (followerProfileId == 0) {
            followerProfileId = _followDataByFollowTokenId[followTokenId].profileIdAllowedToRecover;
            if (followerProfileId == 0) {
                revert FollowTokenDoesNotExist();
            }
            delete _followDataByFollowTokenId[followTokenId].profileIdAllowedToRecover;
        }
        address followerProfileOwner = IERC721(HUB).ownerOf(followerProfileId);
        if (msg.sender != followerProfileOwner) {
            revert DoesNotHavePermissions();
        }
        _mint(wrappedTokenReceiver == address(0) ? followerProfileOwner : wrappedTokenReceiver, followTokenId);
    }

    /// @inheritdoc IFollowNFT
    function unwrap(uint256 followTokenId) external override whenNotPaused {
        if (_followDataByFollowTokenId[followTokenId].followerProfileId == 0) {
            revert NotFollowing();
        }
        super.burn(followTokenId);
    }

    /// @inheritdoc IFollowNFT
    function processBlock(uint256 followerProfileId) external override onlyHub returns (bool) {
        bool hasUnfollowed;
        uint256 followTokenId = _followTokenIdByFollowerProfileId[followerProfileId];
        if (followTokenId != 0) {
            if (!_isFollowTokenWrapped(followTokenId)) {
                // Wrap it first, so the user stops following but does not lose the token when being blocked.
                _mint(IERC721(HUB).ownerOf(followerProfileId), followTokenId);
            }
            _unfollow(followerProfileId, followTokenId);
            hasUnfollowed = true;
        }
        return hasUnfollowed;
    }

    /// @inheritdoc IFollowNFT
    function getFollowerProfileId(uint256 followTokenId) external view override returns (uint256) {
        return _followDataByFollowTokenId[followTokenId].followerProfileId;
    }

    /// @inheritdoc IFollowNFT
    function isFollowing(uint256 followerProfileId) external view override returns (bool) {
        return _followTokenIdByFollowerProfileId[followerProfileId] != 0;
    }

    /// @inheritdoc IFollowNFT
    function getFollowTokenId(uint256 followerProfileId) external view override returns (uint256) {
        return _followTokenIdByFollowerProfileId[followerProfileId];
    }

    /// @inheritdoc IFollowNFT
    function getOriginalFollowTimestamp(uint256 followTokenId) external view override returns (uint256) {
        return _followDataByFollowTokenId[followTokenId].originalFollowTimestamp;
    }

    /// @inheritdoc IFollowNFT
    function getFollowTimestamp(uint256 followTokenId) external view override returns (uint256) {
        return _followDataByFollowTokenId[followTokenId].followTimestamp;
    }

    /// @inheritdoc IFollowNFT
    function getProfileIdAllowedToRecover(uint256 followTokenId) external view override returns (uint256) {
        return _followDataByFollowTokenId[followTokenId].profileIdAllowedToRecover;
    }

    /// @inheritdoc IFollowNFT
    function getFollowData(uint256 followTokenId) external view override returns (Types.FollowData memory) {
        return _followDataByFollowTokenId[followTokenId];
    }

    /// @inheritdoc IFollowNFT
    function getFollowApproved(uint256 followTokenId) external view override returns (uint256) {
        return _followApprovalByFollowTokenId[followTokenId];
    }

    /// @inheritdoc IFollowNFT
    function getFollowerCount() external view override returns (uint256) {
        return _followerCount;
    }

    function burn(uint256 followTokenId) public override whenNotPaused {
        _unfollowIfHasFollower(followTokenId, msg.sender);
        super.burn(followTokenId);
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(
        bytes4 interfaceId
    ) public view virtual override(LensBaseERC721, ERC2981CollectionRoyalties) returns (bool) {
        return
            LensBaseERC721.supportsInterface(interfaceId) || ERC2981CollectionRoyalties.supportsInterface(interfaceId);
    }

    function name() public view override returns (string memory) {
        return string(abi.encodePacked(_followedProfileId.toString(), FOLLOW_NFT_NAME_SUFFIX));
    }

    function symbol() public view override returns (string memory) {
        return string(abi.encodePacked(_followedProfileId.toString(), FOLLOW_NFT_SYMBOL_SUFFIX));
    }

    /**
     * @dev This returns the follow NFT URI fetched from the hub.
     */
    function tokenURI(uint256 followTokenId) public view override returns (string memory) {
        if (!_exists(followTokenId)) {
            revert Errors.TokenDoesNotExist();
        }
        return
            IFollowTokenURI(ILensHub(HUB).getFollowTokenURIContract()).getTokenURI(
                followTokenId,
                _followedProfileId,
                _followDataByFollowTokenId[followTokenId].originalFollowTimestamp
            );
    }

    function _followMintingNewToken(uint256 followerProfileId) internal returns (uint256) {
        uint256 followTokenIdAssigned;
        unchecked {
            followTokenIdAssigned = ++_lastFollowTokenId;
            _followerCount++;
        }
        _baseFollow({
            followerProfileId: followerProfileId,
            followTokenId: followTokenIdAssigned,
            isOriginalFollow: true
        });
        return followTokenIdAssigned;
    }

    function _followWithWrappedToken(
        uint256 followerProfileId,
        address transactionExecutor,
        uint256 followTokenId
    ) internal returns (uint256) {
        bool isFollowApproved = _followApprovalByFollowTokenId[followTokenId] == followerProfileId;
        address followerProfileOwner = IERC721(HUB).ownerOf(followerProfileId);
        if (
            !isFollowApproved &&
            !_isApprovedOrOwner(followerProfileOwner, followTokenId) &&
            !_isApprovedOrOwner(transactionExecutor, followTokenId)
        ) {
            revert DoesNotHavePermissions();
        }
        // The transactionExecutor is allowed to write the follower in that wrapped token.
        if (isFollowApproved) {
            // The `_followApprovalByFollowTokenId` was used, and now it needs to be cleared.
            _approveFollow(0, followTokenId);
        }
        _replaceFollower({
            currentFollowerProfileId: _followDataByFollowTokenId[followTokenId].followerProfileId,
            newFollowerProfileId: followerProfileId,
            followTokenId: followTokenId,
            transactionExecutor: transactionExecutor
        });
        return followTokenId;
    }

    function _followWithUnwrappedTokenFromBurnedProfile(
        uint256 followerProfileId,
        uint256 followTokenId,
        uint256 currentFollowerProfileId,
        address transactionExecutor
    ) internal returns (uint256) {
        if (IERC721Timestamped(HUB).exists(currentFollowerProfileId)) {
            revert DoesNotHavePermissions();
        }
        _replaceFollower({
            currentFollowerProfileId: currentFollowerProfileId,
            newFollowerProfileId: followerProfileId,
            followTokenId: followTokenId,
            transactionExecutor: transactionExecutor
        });
        return followTokenId;
    }

    function _followByRecoveringToken(uint256 followerProfileId, uint256 followTokenId) internal returns (uint256) {
        if (_followDataByFollowTokenId[followTokenId].profileIdAllowedToRecover != followerProfileId) {
            revert FollowTokenDoesNotExist();
        }
        unchecked {
            _followerCount++;
        }
        _baseFollow({followerProfileId: followerProfileId, followTokenId: followTokenId, isOriginalFollow: false});
        return followTokenId;
    }

    function _replaceFollower(
        uint256 currentFollowerProfileId,
        uint256 newFollowerProfileId,
        uint256 followTokenId,
        address transactionExecutor
    ) internal {
        if (currentFollowerProfileId != 0) {
            // As it has a follower, unfollow first, removing the current follower.
            delete _followTokenIdByFollowerProfileId[currentFollowerProfileId];
            ILensHub(HUB).emitUnfollowedEvent(currentFollowerProfileId, _followedProfileId, transactionExecutor);
        } else {
            unchecked {
                _followerCount++;
            }
        }
        // Perform the follow, setting a new follower.
        _baseFollow({followerProfileId: newFollowerProfileId, followTokenId: followTokenId, isOriginalFollow: false});
    }

    function _baseFollow(uint256 followerProfileId, uint256 followTokenId, bool isOriginalFollow) internal {
        _followTokenIdByFollowerProfileId[followerProfileId] = followTokenId;
        _followDataByFollowTokenId[followTokenId].followerProfileId = uint160(followerProfileId);
        _followDataByFollowTokenId[followTokenId].followTimestamp = uint48(block.timestamp);
        delete _followDataByFollowTokenId[followTokenId].profileIdAllowedToRecover;
        if (isOriginalFollow) {
            _followDataByFollowTokenId[followTokenId].originalFollowTimestamp = uint48(block.timestamp);
        } else {
            // Migration code.
            // If the follow token was minted before the originalFollowTimestamp was introduced, it will be 0.
            // In that case, we need to fetch the mint timestamp from the token data.
            if (_followDataByFollowTokenId[followTokenId].originalFollowTimestamp == 0) {
                uint48 mintTimestamp = uint48(StorageLib.getTokenData(followTokenId).mintTimestamp);
                _followDataByFollowTokenId[followTokenId].originalFollowTimestamp = mintTimestamp;
            }
        }
    }

    function _unfollowIfHasFollower(uint256 followTokenId, address transactionExecutor) internal {
        uint256 followerProfileId = _followDataByFollowTokenId[followTokenId].followerProfileId;
        if (followerProfileId != 0) {
            _unfollow(followerProfileId, followTokenId);
            ILensHub(HUB).emitUnfollowedEvent(followerProfileId, _followedProfileId, transactionExecutor);
        }
    }

    function _unfollow(uint256 unfollower, uint256 followTokenId) internal {
        unchecked {
            // This is safe, as this line can only be reached if the unfollowed profile is being followed by the
            // unfollower profile, so _followerCount is guaranteed to be greater than zero.
            _followerCount--;
        }
        delete _followTokenIdByFollowerProfileId[unfollower];
        delete _followDataByFollowTokenId[followTokenId].followerProfileId;
        delete _followDataByFollowTokenId[followTokenId].followTimestamp;
        delete _followDataByFollowTokenId[followTokenId].profileIdAllowedToRecover;
    }

    function _approveFollow(uint256 approvedProfileId, uint256 followTokenId) internal {
        _followApprovalByFollowTokenId[followTokenId] = approvedProfileId;
        emit FollowApproval(approvedProfileId, followTokenId);
    }

    /**
     * @dev Upon transfers, we clear follow approvals and emit the transfer event in the hub.
     */
    function _beforeTokenTransfer(address from, address to, uint256 followTokenId) internal override whenNotPaused {
        if (from != address(0)) {
            // It is cleared on unwrappings and transfers, and it can not be set on unwrapped tokens.
            // As a consequence, there is no need to clear it on wrappings.
            _approveFollow(0, followTokenId);
        }
        super._beforeTokenTransfer(from, to, followTokenId);
    }

    function _getReceiver(uint256 /* followTokenId */) internal view override returns (address) {
        if (!ILensHub(HUB).exists(_followedProfileId)) {
            return address(0);
        }
        return IERC721(HUB).ownerOf(_followedProfileId);
    }

    function _beforeRoyaltiesSet(uint256 /* royaltiesInBasisPoints */) internal view override {
        if (IERC721(HUB).ownerOf(_followedProfileId) != msg.sender) {
            revert Errors.NotProfileOwner();
        }
    }

    function _isFollowTokenWrapped(uint256 followTokenId) internal view returns (bool) {
        return _exists(followTokenId);
    }

    function _getRoyaltiesInBasisPointsSlot() internal pure override returns (uint256) {
        uint256 slot;
        assembly {
            slot := _royaltiesInBasisPoints.slot
        }
        return slot;
    }

    //////////////////
    /// Migrations ///
    //////////////////

    // This function shouldn't fail under no circumstances, except if wrong parameters are passed.
    function tryMigrate(
        uint256 followerProfileId,
        address followerProfileOwner,
        uint256 followTokenId
    ) external onlyHub returns (uint48) {
        // Migrated FollowNFTs should have `originalFollowTimestamp` set
        if (_followDataByFollowTokenId[followTokenId].originalFollowTimestamp != 0) {
            return 0; // Already migrated
        }

        if (_followTokenIdByFollowerProfileId[followerProfileId] != 0) {
            return 0; // Already following
        }

        Types.TokenData memory tokenData = StorageLib.getTokenData(followTokenId);

        address followTokenOwner = tokenData.owner;

        if (followTokenOwner == address(0)) {
            return 0; // Doesn't exist
        }

        // ProfileNFT and FollowNFT should be in the same account
        if (followerProfileOwner != followTokenOwner) {
            return 0; // Not holding both Profile & Follow NFTs together
        }

        unchecked {
            ++_followerCount;
        }

        _followTokenIdByFollowerProfileId[followerProfileId] = followTokenId;

        _followDataByFollowTokenId[followTokenId].followerProfileId = uint160(followerProfileId);
        _followDataByFollowTokenId[followTokenId].originalFollowTimestamp = uint48(tokenData.mintTimestamp);
        _followDataByFollowTokenId[followTokenId].followTimestamp = uint48(tokenData.mintTimestamp);

        super._burn(followTokenId);
        return uint48(tokenData.mintTimestamp);
    }
}

File 2 of 33 : ERC2981CollectionRoyalties.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import {Errors} from 'contracts/libraries/constants/Errors.sol';
import {IERC165} from '@openzeppelin/contracts/utils/introspection/IERC165.sol';
import {IERC2981} from '@openzeppelin/contracts/interfaces/IERC2981.sol';

abstract contract ERC2981CollectionRoyalties is IERC2981 {
    uint16 internal constant BASIS_POINTS = 10000;
    // bytes4(keccak256('royaltyInfo(uint256,uint256)')) == 0x2a55205a
    bytes4 internal constant INTERFACE_ID_ERC2981 = 0x2a55205a;

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

    /**
     * @notice Changes the royalty percentage for secondary sales.
     *
     * @param royaltiesInBasisPoints The royalty percentage (measured in basis points).
     */
    function setRoyalty(uint256 royaltiesInBasisPoints) external {
        _beforeRoyaltiesSet(royaltiesInBasisPoints);
        _setRoyalty(royaltiesInBasisPoints);
    }

    /**
     * @notice Called with the sale price to determine how much royalty is owed and to whom.
     *
     * @param tokenId The ID of the token queried for royalty information.
     * @param salePrice The sale price of the token specified.
     * @return A tuple with the address that should receive the royalties and the royalty
     * payment amount for the given sale price.
     */
    function royaltyInfo(uint256 tokenId, uint256 salePrice) external view returns (address, uint256) {
        return (_getReceiver(tokenId), _getRoyaltyAmount(tokenId, salePrice));
    }

    function _setRoyalty(uint256 royaltiesInBasisPoints) internal virtual {
        if (royaltiesInBasisPoints > BASIS_POINTS) {
            revert Errors.InvalidParameter();
        }
        _storeRoyaltiesInBasisPoints(royaltiesInBasisPoints);
    }

    function _getRoyaltyAmount(uint256 /* tokenId */, uint256 salePrice) internal view virtual returns (uint256) {
        return (salePrice * _loadRoyaltiesInBasisPoints()) / BASIS_POINTS;
    }

    function _storeRoyaltiesInBasisPoints(uint256 royaltiesInBasisPoints) internal virtual {
        uint256 royaltiesInBasisPointsSlot = _getRoyaltiesInBasisPointsSlot();
        assembly {
            sstore(royaltiesInBasisPointsSlot, royaltiesInBasisPoints)
        }
    }

    function _loadRoyaltiesInBasisPoints() internal view virtual returns (uint256) {
        uint256 royaltiesInBasisPointsSlot = _getRoyaltiesInBasisPointsSlot();
        uint256 royaltyAmount;
        assembly {
            royaltyAmount := sload(royaltiesInBasisPointsSlot)
        }
        return royaltyAmount;
    }

    function _beforeRoyaltiesSet(uint256 royaltiesInBasisPoints) internal view virtual;

    function _getRoyaltiesInBasisPointsSlot() internal view virtual returns (uint256);

    function _getReceiver(uint256 tokenId) internal view virtual returns (address);
}

File 3 of 33 : HubRestricted.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.15;

import {Errors} from 'contracts/libraries/constants/Errors.sol';

/**
 * @title HubRestricted
 * @author Lens Protocol
 *
 * @notice This abstract contract adds a public `HUB` immutable field, as well as an `onlyHub` modifier,
 * to inherit from contracts that have functions restricted to be only called by the Lens hub.
 */
abstract contract HubRestricted {
    address public immutable HUB;

    modifier onlyHub() {
        if (msg.sender != HUB) {
            revert Errors.NotHub();
        }
        _;
    }

    constructor(address hub) {
        HUB = hub;
    }
}

File 4 of 33 : LensBaseERC721.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import {Errors} from 'contracts/libraries/constants/Errors.sol';
import {Types} from 'contracts/libraries/constants/Types.sol';
import {MetaTxLib} from 'contracts/libraries/MetaTxLib.sol';
import {ILensERC721} from 'contracts/interfaces/ILensERC721.sol';
import {IERC721Timestamped} from 'contracts/interfaces/IERC721Timestamped.sol';
import {IERC721Burnable} from 'contracts/interfaces/IERC721Burnable.sol';
import {IERC721MetaTx} from 'contracts/interfaces/IERC721MetaTx.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 {Strings} from '@openzeppelin/contracts/utils/Strings.sol';
import {ERC165} from '@openzeppelin/contracts/utils/introspection/ERC165.sol';
import {IERC165} from '@openzeppelin/contracts/utils/introspection/IERC165.sol';
import {IERC721} from '@openzeppelin/contracts/token/ERC721/IERC721.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}.
 *
 * Modifications:
 * 1. Refactored _operatorApprovals setter into an internal function to allow meta-transactions.
 * 2. Constructor replaced with an initializer.
 * 3. Mint timestamp is now stored in a TokenData struct alongside the owner address.
 */
abstract contract LensBaseERC721 is ERC165, ILensERC721 {
    using Address for address;
    using Strings for uint256;

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

    // Mapping from token ID to token Data (owner address and mint timestamp uint96), this
    // replaces the original mapping(uint256 => address) private _owners;
    mapping(uint256 => Types.TokenData) private _tokenData;

    // 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;

    // Deprecated in V2 after removing ERC712Enumerable logic.
    mapping(address => mapping(uint256 => uint256)) private __DEPRECATED__ownedTokens;
    mapping(uint256 => uint256) private __DEPRECATED__ownedTokensIndex;

    // Dirty hack on a deprecated slot:
    uint256 private _totalSupply; // uint256[] private __DEPRECATED__allTokens;

    // Deprecated in V2 after removing ERC712Enumerable logic.
    mapping(uint256 => uint256) private __DEPRECATED__allTokensIndex;

    mapping(address => uint256) private _nonces;

    /**
     * @dev Initializes the ERC721 name and symbol.
     *
     * @param name_ The name to set.
     * @param symbol_ The symbol to set.
     */
    function _initialize(string calldata name_, string calldata symbol_) internal {
        _name = name_;
        _symbol = symbol_;
    }

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

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

    function nonces(address signer) public view override returns (uint256) {
        return _nonces[signer];
    }

    /// @inheritdoc IERC721MetaTx
    function getDomainSeparator() external view virtual override returns (bytes32) {
        return MetaTxLib.calculateDomainSeparator();
    }

    /**
     * @dev See {IERC721-balanceOf}.
     */
    function balanceOf(address owner) public view virtual override returns (uint256) {
        if (owner == address(0)) {
            revert Errors.InvalidParameter();
        }
        return _balances[owner];
    }

    /**
     * @dev See {IERC721-ownerOf}.
     */
    function ownerOf(uint256 tokenId) public view virtual override returns (address) {
        address owner = _tokenData[tokenId].owner;
        if (owner == address(0)) {
            revert Errors.TokenDoesNotExist();
        }
        return owner;
    }

    /**
     * @dev See {IERC721Timestamped-mintTimestampOf}
     */
    function mintTimestampOf(uint256 tokenId) public view virtual override returns (uint256) {
        uint96 mintTimestamp = _tokenData[tokenId].mintTimestamp;
        if (mintTimestamp == 0) {
            revert Errors.TokenDoesNotExist();
        }
        return mintTimestamp;
    }

    /**
     * @dev See {IERC721Timestamped-tokenDataOf}
     */
    function tokenDataOf(uint256 tokenId) public view virtual override returns (Types.TokenData memory) {
        if (!_exists(tokenId)) {
            revert Errors.TokenDoesNotExist();
        }
        return _tokenData[tokenId];
    }

    /**
     * @dev See {IERC721Timestamped-exists}
     */
    function exists(uint256 tokenId) public view virtual override returns (bool) {
        return _exists(tokenId);
    }

    /**
     * @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;
    }

    function totalSupply() external view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC721-approve}.
     */
    function approve(address to, uint256 tokenId) public virtual override {
        address owner = ownerOf(tokenId);
        if (to == owner) {
            revert Errors.InvalidParameter();
        }

        if (msg.sender != owner && !isApprovedForAll(owner, msg.sender)) {
            revert Errors.NotOwnerOrApproved();
        }

        _approve(to, tokenId);
    }

    /**
     * @dev See {IERC721-getApproved}.
     */
    function getApproved(uint256 tokenId) public view virtual override returns (address) {
        if (!_exists(tokenId)) {
            revert Errors.TokenDoesNotExist();
        }

        return _tokenApprovals[tokenId];
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        if (operator == msg.sender) {
            revert Errors.InvalidParameter();
        }

        _setOperatorApproval(msg.sender, 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
        if (!_isApprovedOrOwner(msg.sender, tokenId)) {
            revert Errors.NotOwnerOrApproved();
        }

        _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
    ) public virtual override {
        if (!_isApprovedOrOwner(msg.sender, tokenId)) {
            revert Errors.NotOwnerOrApproved();
        }
        _safeTransfer(from, to, tokenId, _data);
    }

    /**
     * @dev Burns `tokenId`.
     *
     * Requirements:
     *
     * - The caller must own `tokenId` or be an approved operator.
     */
    function burn(uint256 tokenId) public virtual override {
        if (!_isApprovedOrOwner(msg.sender, tokenId)) {
            revert Errors.NotOwnerOrApproved();
        }
        _burn(tokenId);
    }

    /**
     * @notice Returns the owner of the `tokenId` token.
     *
     * @dev It is prefixed as `unsafe` as it does not revert when the token does not exist.
     *
     * @param tokenId The token whose owner is being queried.
     *
     * @return address The address owning the given token, zero address if the token does not exist.
     */
    function _unsafeOwnerOf(uint256 tokenId) internal view returns (address) {
        return _tokenData[tokenId].owner;
    }

    /**
     * @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 a 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
    ) internal virtual {
        _transfer(from, to, tokenId);
        if (!_checkOnERC721Received(from, to, tokenId, _data)) {
            revert Errors.NonERC721ReceiverImplementer();
        }
    }

    /**
     * @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 _tokenData[tokenId].owner != 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) {
        address owner = ownerOf(tokenId);
        // We don't check owner for != address(0) cause it's done inside ownerOf()
        return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
    }

    /**
     * @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 {
        if (to == address(0) || _exists(tokenId)) {
            revert Errors.InvalidParameter();
        }

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

        unchecked {
            ++_balances[to];
            ++_totalSupply;
        }
        _tokenData[tokenId].owner = to;
        _tokenData[tokenId].mintTimestamp = uint96(block.timestamp);

        emit Transfer(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 = ownerOf(tokenId);

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

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

        unchecked {
            --_balances[owner];
            --_totalSupply;
        }
        delete _tokenData[tokenId];

        emit Transfer(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 {
        if (ownerOf(tokenId) != from) {
            revert Errors.InvalidOwner();
        }
        if (to == address(0)) {
            revert Errors.InvalidParameter();
        }

        _beforeTokenTransfer(from, to, tokenId);

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

        unchecked {
            --_balances[from];
            ++_balances[to];
        }
        _tokenData[tokenId].owner = to;

        emit Transfer(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(ownerOf(tokenId), to, tokenId);
    }

    /**
     * @dev Refactored from the original OZ ERC721 implementation: approve or revoke approval from
     * `operator` to operate on all tokens owned by `owner`.
     *
     * Emits a {ApprovalForAll} event.
     */
    function _setOperatorApproval(
        address owner,
        address operator,
        bool approved
    ) internal virtual {
        _operatorApprovals[owner][operator] = approved;
        emit ApprovalForAll(owner, operator, approved);
    }

    /**
     * @dev Private 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
     */
    function _checkOnERC721Received(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) private returns (bool) {
        if (to.isContract()) {
            try IERC721Receiver(to).onERC721Received(msg.sender, from, tokenId, _data) returns (bytes4 retval) {
                return retval == IERC721Receiver.onERC721Received.selector;
            } catch (bytes memory reason) {
                if (reason.length == 0) {
                    revert Errors.NonERC721ReceiverImplementer();
                } else {
                    assembly {
                        revert(add(32, reason), mload(reason))
                    }
                }
            }
        } 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].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual {}
}

File 5 of 33 : IERC721Burnable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

/**
 * @title IERC721Burnable
 * @author Lens Protocol
 *
 * @notice Extension of ERC-721 including a function that allows the token to be burned.
 */
interface IERC721Burnable {
    /**
     * @notice Burns an NFT, removing it from circulation and essentially destroying it.
     * @custom:permission Owner of the NFT.
     *
     * @param tokenId The token ID of the token to burn.
     */
    function burn(uint256 tokenId) external;
}

File 6 of 33 : IERC721MetaTx.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

/**
 * @title IERC721MetaTx
 * @author Lens Protocol
 *
 * @notice Extension of ERC-721 including meta-tx signatures related functions.
 */
interface IERC721MetaTx {
    /**
     * @notice Returns the current signature nonce of the given signer.
     *
     * @param signer The address for which to query the nonce.
     *
     * @return uint256 The current nonce of the given signer.
     */
    function nonces(address signer) external view returns (uint256);

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

File 7 of 33 : IERC721Timestamped.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

import {Types} from 'contracts/libraries/constants/Types.sol';

/**
 * @title IERC721Timestamped
 * @author Lens Protocol
 *
 * @notice Extension of ERC-721 including a struct for token data, which contains the owner and the mint timestamp, as
 * well as their associated getters.
 */
interface IERC721Timestamped {
    /**
     * @notice Returns the mint timestamp associated with a given NFT.
     *
     * @param tokenId The token ID of the NFT to query the mint timestamp for.
     *
     * @return uint256 Mint timestamp, this is stored as a uint96 but returned as a uint256 to reduce unnecessary
     * padding.
     */
    function mintTimestampOf(uint256 tokenId) external view returns (uint256);

    /**
     * @notice Returns the token data associated with a given NFT. This allows fetching the token owner and
     * mint timestamp in a single call.
     *
     * @param tokenId The token ID of the NFT to query the token data for.
     *
     * @return TokenData A struct containing both the owner address and the mint timestamp.
     */
    function tokenDataOf(uint256 tokenId) external view returns (Types.TokenData memory);

    /**
     * @notice Returns whether a token with the given token ID exists.
     *
     * @param tokenId The token ID of the NFT to check existence for.
     *
     * @return bool True if the token exists.
     */
    function exists(uint256 tokenId) external view returns (bool);

    /**
     * @notice Returns the amount of tokens in circulation.
     *
     * @return uint256 The current total supply of tokens.
     */
    function totalSupply() external view returns (uint256);
}

File 8 of 33 : IFollowNFT.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

import {Types} from 'contracts/libraries/constants/Types.sol';

/**
 * @title IFollowNFT
 * @author Lens Protocol
 *
 * @notice This is the interface for the FollowNFT contract, which is cloned upon the first follow for any profile.
 * By default the Follow tokens are tied to the follower profile, which means that they will be automatically
 * transferred with it.
 * This is achieved by them not being ERC-721 initially. However, the Follow NFT collections support converting them to
 * ERC-721 tokens (i.e. wrapping) natively, enabling composability with existing ERC-721-based protocols.
 */
interface IFollowNFT {
    error AlreadyFollowing();
    error NotFollowing();
    error FollowTokenDoesNotExist();
    error AlreadyWrapped();
    error OnlyWrappedFollowTokens();
    error DoesNotHavePermissions();

    /**
     * @notice Initializes the follow NFT.
     * @custom:permissions LensHub.
     *
     * @dev Sets the targeted profile, and the token royalties.
     *
     * @param profileId The ID of the profile targeted by the follow tokens minted by this collection.
     */
    function initialize(uint256 profileId) external;

    /**
     * @notice Makes the passed profile follow the profile targeted in this contract.
     * @custom:permissions LensHub.
     *
     * @param followerProfileId The ID of the profile acting as the follower.
     * @param transactionExecutor The address of the transaction executor (e.g. for any funds to transferFrom).
     * @param followTokenId The ID of the follow token to be used for this follow operation. Zero if a new follow token
     * should be minted.
     *
     * @return uint256 The ID of the token used to follow.
     */
    function follow(
        uint256 followerProfileId,
        address transactionExecutor,
        uint256 followTokenId
    ) external returns (uint256);

    /**
     * @notice Makes the passed profile unfollow the profile targeted in this contract.
     * @custom:permissions LensHub.
     *
     * @param unfollowerProfileId The ID of the profile that is performing the unfollow operation.
     */
    function unfollow(uint256 unfollowerProfileId) external;

    /**
     * @notice Removes the follower from the given follow NFT.
     * @custom:permissions Follow token owner or approved-for-all.

     * @dev Only on wrapped token.
     *
     * @param followTokenId The ID of the follow token to remove the follower from.
     */
    function removeFollower(uint256 followTokenId) external;

    /**
     * @notice Approves the given profile to follow with the given wrapped token.
     * @custom:permissions Follow token owner or approved-for-all.
     *
     * @dev Only on wrapped tokens.
     * It approves setting a follower on the given wrapped follow token, which lets the follow token owner to allow
     * a profile to follow with his token without losing its ownership. This approval is cleared on transfers, as well
     * as when unwrapping.
     *
     * @param approvedProfileId The ID of the profile approved to follow with the given token.
     * @param followTokenId The ID of the follow token to be approved for the given profile.
     */
    function approveFollow(uint256 approvedProfileId, uint256 followTokenId) external;

    /**
     * @notice Unties the follow token from the follower's profile one, and wraps it into the ERC-721 untied follow
     * tokens collection. Untied follow tokens will NOT be automatically transferred with their follower profile.
     * @custom:permissions Follower profile owner.
     *
     * @dev Only on unwrapped follow tokens.
     *
     * @param followTokenId The ID of the follow token to untie and wrap.
     */
    function wrap(uint256 followTokenId) external;

    /**
     * @notice Unties the follow token from the follower's profile one, and wraps it into the ERC-721 untied follow
     * tokens collection. Untied follow tokens will NOT be automatically transferred with their follower profile.
     * @custom:permissions Follower profile owner.
     *
     * @dev Only on unwrapped follow tokens.
     *
     * @param followTokenId The ID of the follow token to untie and wrap.
     * @param wrappedTokenReceiver The address where the follow token is minted to when being wrapped as ERC-721.
     */
    function wrap(uint256 followTokenId, address wrappedTokenReceiver) external;

    /**
     * @notice Unwraps the follow token from the ERC-721 untied follow tokens collection, and ties it to the follower's
     * profile token. Tokens that are tied to the follower profile will be automatically transferred with it.
     *
     * @param followTokenId The ID of the follow token to unwrap and tie to its follower.
     */
    function unwrap(uint256 followTokenId) external;

    /**
     * @notice Processes logic when the given profile is being blocked. If it was following the targeted profile,
     * this will make it unfollow.
     * @custom:permissions LensHub.
     *
     * @param followerProfileId The ID of the follow token to unwrap and tie.
     *
     * @return bool True if the given profile was following and now has unfollowed, false otherwise.
     */
    function processBlock(uint256 followerProfileId) external returns (bool);

    ///////////////////////////
    ///       GETTERS       ///
    ///////////////////////////

    /**
     * @notice Gets the ID of the profile following with the given follow token.
     *
     * @param followTokenId The ID of the follow token whose follower should be queried.
     *
     * @return uint256 The ID of the profile following with the given token, zero if it is not being used to follow.
     */
    function getFollowerProfileId(uint256 followTokenId) external view returns (uint256);

    /**
     * @notice Gets the original follow timestamp of the given follow token.
     *
     * @param followTokenId The ID of the follow token whose original follow timestamp should be queried.
     *
     * @return uint256 The timestamp of the first follow performed with the token, zero if was not used to follow yet.
     */
    function getOriginalFollowTimestamp(uint256 followTokenId) external view returns (uint256);

    /**
     * @notice Gets the current follow timestamp of the given follow token.
     *
     * @param followTokenId The ID of the follow token whose follow timestamp should be queried.
     *
     * @return uint256 The timestamp of the current follow of the token, zero if it is not being used to follow.
     */
    function getFollowTimestamp(uint256 followTokenId) external view returns (uint256);

    /**
     * @notice Gets the ID of the profile allowed to recover the given follow token.
     *
     * @param followTokenId The ID of the follow token whose allowed profile to recover should be queried.
     *
     * @return uint256 The ID of the profile allowed to recover the given follow token, zero if none of them is allowed.
     */
    function getProfileIdAllowedToRecover(uint256 followTokenId) external view returns (uint256);

    /**
     * @notice Gets the follow data of the given follow token.
     *
     * @param followTokenId The ID of the follow token whose follow data should be queried.
     *
     * @return FollowData The token data associated with the given follow token.
     */
    function getFollowData(uint256 followTokenId) external view returns (Types.FollowData memory);

    /**
     * @notice Tells if the given profile is following the profile targeted in this contract.
     *
     * @param followerProfileId The ID of the profile whose following state should be queried.
     *
     * @return uint256 The ID of the profile set as a follower in the given token, zero if it is not being used to follow.
     */
    function isFollowing(uint256 followerProfileId) external view returns (bool);

    /**
     * @notice Gets the ID of the token being used to follow by the given follower.
     *
     * @param followerProfileId The ID of the profile whose follow ID should be queried.
     *
     * @return uint256 The ID of the token being used to follow by the given follower, zero if he is not following.
     */
    function getFollowTokenId(uint256 followerProfileId) external view returns (uint256);

    /**
     * @notice Gets the ID of the profile approved to follow with the given token.
     *
     * @param followTokenId The ID of the token whose approved to follow should be queried.
     *
     * @return uint256 The ID of the profile approved to follow with the given token, zero if none of them is approved.
     */
    function getFollowApproved(uint256 followTokenId) external view returns (uint256);

    /**
     * @notice Gets the count of the followers of the profile targeted in this contract.
     * @notice This number might be out of sync if one of the followers burns their profile.
     *
     * @return uint256 The count of the followers of the profile targeted in this contract.
     */
    function getFollowerCount() external view returns (uint256);
}

File 9 of 33 : IFollowTokenURI.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.15;

interface IFollowTokenURI {
    function getTokenURI(
        uint256 followTokenId,
        uint256 followedProfileId,
        uint256 originalFollowTimestamp
    ) external pure returns (string memory);
}

File 10 of 33 : ILensERC721.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

import {IERC721} from '@openzeppelin/contracts/token/ERC721/IERC721.sol';
import {IERC721Timestamped} from 'contracts/interfaces/IERC721Timestamped.sol';
import {IERC721Burnable} from 'contracts/interfaces/IERC721Burnable.sol';
import {IERC721MetaTx} from 'contracts/interfaces/IERC721MetaTx.sol';
import {IERC721Metadata} from '@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol';

interface ILensERC721 is IERC721, IERC721Timestamped, IERC721Burnable, IERC721MetaTx, IERC721Metadata {}

File 11 of 33 : ILensGovernable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

import {Types} from 'contracts/libraries/constants/Types.sol';

/**
 * @title ILensGovernable
 * @author Lens Protocol
 *
 * @notice This is the interface for the Lens Protocol main governance functions.
 */
interface ILensGovernable {
    /**
     * @notice Sets the privileged governance role.
     * @custom:permissions Governance.
     *
     * @param newGovernance The new governance address to set.
     */
    function setGovernance(address newGovernance) external;

    /**
     * @notice Sets the emergency admin, which is a permissioned role able to set the protocol state.
     * @custom:permissions Governance.
     *
     * @param newEmergencyAdmin The new emergency admin address to set.
     */
    function setEmergencyAdmin(address newEmergencyAdmin) external;

    /**
     * @notice Sets the protocol state to either a global pause, a publishing pause or an unpaused state.
     * @custom:permissions Governance or Emergency Admin. Emergency Admin can only restrict more.
     *
     * @param newState The state to set. It can be one of the following:
     *  - Unpaused: The protocol is fully operational.
     *  - PublishingPaused: The protocol is paused for publishing, but it is still operational for others operations.
     *  - Paused: The protocol is paused for all operations.
     */
    function setState(Types.ProtocolState newState) external;

    /**
     * @notice Adds or removes a profile creator from the whitelist.
     * @custom:permissions Governance.
     *
     * @param profileCreator The profile creator address to add or remove from the whitelist.
     * @param whitelist Whether or not the profile creator should be whitelisted.
     */
    function whitelistProfileCreator(address profileCreator, bool whitelist) external;

    /**
     * @notice Sets the profile token URI contract.
     * @custom:permissions Governance.
     *
     * @param profileTokenURIContract The profile token URI contract to set.
     */
    function setProfileTokenURIContract(address profileTokenURIContract) external;

    /**
     * @notice Sets the follow token URI contract.
     * @custom:permissions Governance.
     *
     * @param followTokenURIContract The follow token URI contract to set.
     */
    function setFollowTokenURIContract(address followTokenURIContract) external;

    /**
     * @notice Sets the treasury address.
     * @custom:permissions Governance
     *
     * @param newTreasury The new treasury address to set.
     */
    function setTreasury(address newTreasury) external;

    /**
     * @notice Sets the treasury fee.
     * @custom:permissions Governance
     *
     * @param newTreasuryFee The new treasury fee to set.
     */
    function setTreasuryFee(uint16 newTreasuryFee) external;

    /**
     * @notice Returns the currently configured governance address.
     *
     * @return address The address of the currently configured governance.
     */
    function getGovernance() external view returns (address);

    /**
     * @notice Gets the state currently set in the protocol. It could be a global pause, a publishing pause or an
     * unpaused state.
     * @custom:permissions Anyone.
     *
     * @return Types.ProtocolState The state currently set in the protocol.
     */
    function getState() external view returns (Types.ProtocolState);

    /**
     * @notice Returns whether or not a profile creator is whitelisted.
     *
     * @param profileCreator The address of the profile creator to check.
     *
     * @return bool True if the profile creator is whitelisted, false otherwise.
     */
    function isProfileCreatorWhitelisted(address profileCreator) external view returns (bool);

    /**
     * @notice Returns the treasury address.
     *
     * @return address The treasury address.
     */
    function getTreasury() external view returns (address);

    /**
     * @notice Returns the treasury fee.
     *
     * @return uint16 The treasury fee.
     */
    function getTreasuryFee() external view returns (uint16);

    /**
     * @notice Returns the treasury address and treasury fee in a single call.
     *
     * @return tuple First, the treasury address, second, the treasury fee.
     */
    function getTreasuryData() external view returns (address, uint16);

    /**
     * @notice Gets the profile token URI contract.
     *
     * @return address The profile token URI contract.
     */
    function getProfileTokenURIContract() external view returns (address);

    /**
     * @notice Gets the follow token URI contract.
     *
     * @return address The follow token URI contract.
     */
    function getFollowTokenURIContract() external view returns (address);
}

File 12 of 33 : ILensHub.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

import {ILensProtocol} from 'contracts/interfaces/ILensProtocol.sol';
import {ILensGovernable} from 'contracts/interfaces/ILensGovernable.sol';
import {ILensHubEventHooks} from 'contracts/interfaces/ILensHubEventHooks.sol';
import {ILensImplGetters} from 'contracts/interfaces/ILensImplGetters.sol';
import {ILensProfiles} from 'contracts/interfaces/ILensProfiles.sol';
import {ILensVersion} from 'contracts/interfaces/ILensVersion.sol';

interface ILensHub is
    ILensProfiles,
    ILensProtocol,
    ILensGovernable,
    ILensHubEventHooks,
    ILensImplGetters,
    ILensVersion
{}

File 13 of 33 : ILensHubEventHooks.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

/**
 * @title ILensHubEventHooks
 * @author Lens Protocol
 *
 * @notice This is the interface for the LensHub contract's event hooks. As we want most of the core events to be
 * emitted by the LensHub contract, event hooks are needed for core events generated by pheripheral contracts.
 */
interface ILensHubEventHooks {
    /**
     * @dev Helper function to emit an `Unfollowed` event from the hub, to be consumed by indexers to track unfollows.
     * @custom:permissions FollowNFT of the Profile unfollowed.
     *
     * @param unfollowerProfileId The ID of the profile that executed the unfollow.
     * @param idOfProfileUnfollowed The ID of the profile that was unfollowed.
     * @param transactionExecutor The address of the account executing the unfollow operation.
     */
    function emitUnfollowedEvent(
        uint256 unfollowerProfileId,
        uint256 idOfProfileUnfollowed,
        address transactionExecutor
    ) external;
}

File 14 of 33 : ILensImplGetters.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

/**
 * @title ILensImplGetters
 * @author Lens Protocol
 *
 * @notice This is the interface for the LensHub contract's implementation getters. These implementations will be used
 * for deploying each respective contract for each profile.
 */
interface ILensImplGetters {
    /**
     * @notice Returns the Follow NFT implementation address that is used for all deployed Follow NFTs.
     *
     * @return address The Follow NFT implementation address.
     */
    function getFollowNFTImpl() external view returns (address);

    /**
     * @notice Returns the Collect NFT implementation address that is used for each new deployed Collect NFT.
     * @custom:pending-deprecation
     *
     * @return address The Collect NFT implementation address.
     */
    function getLegacyCollectNFTImpl() external view returns (address);

    /**
     * @notice Returns the address of the registry that stores all modules that are used by the Lens Protocol.
     *
     * @return address The address of the Module Registry contract.
     */
    function getModuleRegistry() external view returns (address);
}

File 15 of 33 : ILensProfiles.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

import {ILensERC721} from 'contracts/interfaces/ILensERC721.sol';

interface ILensProfiles is ILensERC721 {
    /**
     * @notice DANGER: Triggers disabling the profile protection mechanism for the msg.sender, which will allow
     * transfers or approvals over profiles held by it.
     * Disabling the mechanism will have a timelock before it becomes effective, allowing the owner to re-enable
     * the protection back in case of being under attack.
     * The protection layer only applies to EOA wallets.
     */
    function DANGER__disableTokenGuardian() external;

    /**
     * @notice Enables back the profile protection mechanism for the msg.sender, preventing profile transfers or
     * approvals (except when revoking them).
     * The protection layer only applies to EOA wallets.
     */
    function enableTokenGuardian() external;

    /**
     * @notice Returns the timestamp at which the Token Guardian will become effectively disabled.
     *
     * @param wallet The address to check the timestamp for.
     *
     * @return uint256 The timestamp at which the Token Guardian will become effectively disabled. Zero if enabled.
     */
    function getTokenGuardianDisablingTimestamp(address wallet) external view returns (uint256);
}

File 16 of 33 : ILensProtocol.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

import {Types} from 'contracts/libraries/constants/Types.sol';

/**
 * @title ILensProtocol
 * @author Lens Protocol
 *
 * @notice This is the interface for Lens Protocol's core functions. It contains all the entry points for performing
 * social operations.
 */
interface ILensProtocol {
    /**
     * @notice Creates a profile with the specified parameters, minting a Profile NFT to the given recipient.
     * @custom:permissions Any whitelisted profile creator.
     *
     * @param createProfileParams A CreateProfileParams struct containing the needed params.
     */
    function createProfile(Types.CreateProfileParams calldata createProfileParams) external returns (uint256);

    /**
     * @notice Sets the metadata URI for the given profile.
     * @custom:permissions Profile Owner or Delegated Executor.
     *
     * @param profileId The token ID of the profile to set the metadata URI for.
     * @param metadataURI The metadata URI to set for the given profile.
     */
    function setProfileMetadataURI(uint256 profileId, string calldata metadataURI) external;

    /**
     * @custom:meta-tx setProfileMetadataURI.
     */
    function setProfileMetadataURIWithSig(
        uint256 profileId,
        string calldata metadataURI,
        Types.EIP712Signature calldata signature
    ) external;

    /**
     * @notice Sets the follow module for the given profile.
     * @custom:permissions Profile Owner or Delegated Executor.
     *
     * @param profileId The token ID of the profile to set the follow module for.
     * @param followModule The follow module to set for the given profile, must be whitelisted.
     * @param followModuleInitData The data to be passed to the follow module for initialization.
     */
    function setFollowModule(uint256 profileId, address followModule, bytes calldata followModuleInitData) external;

    /**
     * @custom:meta-tx setFollowModule.
     */
    function setFollowModuleWithSig(
        uint256 profileId,
        address followModule,
        bytes calldata followModuleInitData,
        Types.EIP712Signature calldata signature
    ) external;

    /**
     * @notice Changes the delegated executors configuration for the given profile. It allows setting the approvals for
     * delegated executors in the specified configuration, as well as switching to it.
     * @custom:permissions Profile Owner.
     *
     * @param delegatorProfileId The ID of the profile to which the delegated executor is being changed for.
     * @param delegatedExecutors The array of delegated executors to set the approval for.
     * @param approvals The array of booleans indicating the corresponding executor's new approval status.
     * @param configNumber The number of the configuration where the executor approval state is being set.
     * @param switchToGivenConfig A boolean indicating if the configuration must be switched to the one with the given
     * number.
     */
    function changeDelegatedExecutorsConfig(
        uint256 delegatorProfileId,
        address[] calldata delegatedExecutors,
        bool[] calldata approvals,
        uint64 configNumber,
        bool switchToGivenConfig
    ) external;

    /**
     * @notice Changes the delegated executors configuration for the given profile under the current configuration.
     * @custom:permissions Profile Owner.
     *
     * @param delegatorProfileId The ID of the profile to which the delegated executor is being changed for.
     * @param delegatedExecutors The array of delegated executors to set the approval for.
     * @param approvals The array of booleans indicating the corresponding executor's new approval status.
     */
    function changeDelegatedExecutorsConfig(
        uint256 delegatorProfileId,
        address[] calldata delegatedExecutors,
        bool[] calldata approvals
    ) external;

    /**
     * @custom:meta-tx changeDelegatedExecutorsConfig.
     */
    function changeDelegatedExecutorsConfigWithSig(
        uint256 delegatorProfileId,
        address[] calldata delegatedExecutors,
        bool[] calldata approvals,
        uint64 configNumber,
        bool switchToGivenConfig,
        Types.EIP712Signature calldata signature
    ) external;

    /**
     * @notice Publishes a post.
     * Post is the most basic publication type, and can be used to publish any kind of content.
     * Posts can have these types of modules initialized:
     *  - Action modules: any number of publication actions (e.g. collect, tip, etc.)
     *  - Reference module: a module handling the rules when referencing this post (e.g. token-gated comments)
     * @custom:permissions Profile Owner or Delegated Executor.
     *
     * @param postParams A PostParams struct containing the needed parameters.
     *
     * @return uint256 An integer representing the post's publication ID.
     */
    function post(Types.PostParams calldata postParams) external returns (uint256);

    /**
     * @custom:meta-tx post.
     */
    function postWithSig(
        Types.PostParams calldata postParams,
        Types.EIP712Signature calldata signature
    ) external returns (uint256);

    /**
     * @notice Publishes a comment on the given publication.
     * Comment is a type of reference publication that points to another publication.
     * Comments can have these types of modules initialized:
     *  - Action modules: any number of publication actions (e.g. collect, tip, etc.)
     *  - Reference module: a module handling the rules when referencing this comment (e.g. token-gated mirrors)
     * Comments can have referrers (e.g. publications or profiles that helped to discover the pointed publication).
     * @custom:permissions Profile Owner or Delegated Executor.
     *
     * @param commentParams A CommentParams struct containing the needed parameters.
     *
     * @return uint256 An integer representing the comment's publication ID.
     */
    function comment(Types.CommentParams calldata commentParams) external returns (uint256);

    /**
     * @custom:meta-tx comment.
     */
    function commentWithSig(
        Types.CommentParams calldata commentParams,
        Types.EIP712Signature calldata signature
    ) external returns (uint256);

    /**
     * @notice Publishes a mirror of the given publication.
     * Mirror is a type of reference publication that points to another publication but doesn't have content.
     * Mirrors don't have any modules initialized.
     * Mirrors can have referrers (e.g. publications or profiles that allowed to discover the pointed publication).
     * You cannot mirror a mirror, comment on a mirror, or quote a mirror.
     * @custom:permissions Profile Owner or Delegated Executor.
     *
     * @param mirrorParams A MirrorParams struct containing the necessary parameters.
     *
     * @return uint256 An integer representing the mirror's publication ID.
     */
    function mirror(Types.MirrorParams calldata mirrorParams) external returns (uint256);

    /**
     * @custom:meta-tx mirror.
     */
    function mirrorWithSig(
        Types.MirrorParams calldata mirrorParams,
        Types.EIP712Signature calldata signature
    ) external returns (uint256);

    /**
     * @notice Publishes a quote of the given publication.
     * Quote is a type of reference publication similar to mirror, but it has content and modules.
     * Quotes can have these types of modules initialized:
     *  - Action modules: any number of publication actions (e.g. collect, tip, etc.)
     *  - Reference module: a module handling the rules when referencing this quote (e.g. token-gated comments on quote)
     * Quotes can have referrers (e.g. publications or profiles that allowed to discover the pointed publication).
     * Unlike mirrors, you can mirror a quote, comment on a quote, or quote a quote.
     * @custom:permissions Profile Owner or Delegated Executor.
     *
     * @param quoteParams A QuoteParams struct containing the needed parameters.
     *
     * @return uint256 An integer representing the quote's publication ID.
     */
    function quote(Types.QuoteParams calldata quoteParams) external returns (uint256);

    /**
     * @custom:meta-tx quote.
     */
    function quoteWithSig(
        Types.QuoteParams calldata quoteParams,
        Types.EIP712Signature calldata signature
    ) external returns (uint256);

    /**
     * @notice Follows given profiles, executing each profile's follow module logic (if any).
     * @custom:permissions Profile Owner or Delegated Executor.
     *
     * @dev Both the `idsOfProfilesToFollow`, `followTokenIds`, and `datas` arrays must be of the same length,
     * regardless if the profiles do not have a follow module set.
     *
     * @param followerProfileId The ID of the profile the follows are being executed for.
     * @param idsOfProfilesToFollow The array of IDs of profiles to follow.
     * @param followTokenIds The array of follow token IDs to use for each follow (0 if you don't own a follow token).
     * @param datas The arbitrary data array to pass to the follow module for each profile if needed.
     *
     * @return uint256[] An array of follow token IDs representing the follow tokens created for each follow.
     */
    function follow(
        uint256 followerProfileId,
        uint256[] calldata idsOfProfilesToFollow,
        uint256[] calldata followTokenIds,
        bytes[] calldata datas
    ) external returns (uint256[] memory);

    /**
     * @custom:meta-tx follow.
     */
    function followWithSig(
        uint256 followerProfileId,
        uint256[] calldata idsOfProfilesToFollow,
        uint256[] calldata followTokenIds,
        bytes[] calldata datas,
        Types.EIP712Signature calldata signature
    ) external returns (uint256[] memory);

    /**
     * @notice Unfollows given profiles.
     * @custom:permissions Profile Owner or Delegated Executor.
     *
     * @param unfollowerProfileId The ID of the profile the unfollows are being executed for.
     * @param idsOfProfilesToUnfollow The array of IDs of profiles to unfollow.
     */
    function unfollow(uint256 unfollowerProfileId, uint256[] calldata idsOfProfilesToUnfollow) external;

    /**
     * @custom:meta-tx unfollow.
     */
    function unfollowWithSig(
        uint256 unfollowerProfileId,
        uint256[] calldata idsOfProfilesToUnfollow,
        Types.EIP712Signature calldata signature
    ) external;

    /**
     * @notice Sets the block status for the given profiles. Changing a profile's block status to `true` (i.e. blocked),
     * when will also force them to unfollow.
     * Blocked profiles cannot perform any actions with the profile that blocked them: they cannot comment or mirror
     * their publications, they cannot follow them, they cannot collect, tip them, etc.
     * @custom:permissions Profile Owner or Delegated Executor.
     *
     * @dev Both the `idsOfProfilesToSetBlockStatus` and `blockStatus` arrays must be of the same length.
     *
     * @param byProfileId The ID of the profile that is blocking/unblocking somebody.
     * @param idsOfProfilesToSetBlockStatus The array of IDs of profiles to set block status.
     * @param blockStatus The array of block statuses to use for each (true is blocked).
     */
    function setBlockStatus(
        uint256 byProfileId,
        uint256[] calldata idsOfProfilesToSetBlockStatus,
        bool[] calldata blockStatus
    ) external;

    /**
     * @custom:meta-tx setBlockStatus.
     */
    function setBlockStatusWithSig(
        uint256 byProfileId,
        uint256[] calldata idsOfProfilesToSetBlockStatus,
        bool[] calldata blockStatus,
        Types.EIP712Signature calldata signature
    ) external;

    /**
     * @notice Collects a given publication via signature with the specified parameters.
     * Collect can have referrers (e.g. publications or profiles that allowed to discover the pointed publication).
     * @custom:permissions Collector Profile Owner or its Delegated Executor.
     * @custom:pending-deprecation Collect modules were replaced by PublicationAction Collect modules in V2. This method
     * is left here for backwards compatibility with posts made in V1 that had Collect modules.
     *
     * @param collectParams A CollectParams struct containing the parameters.
     *
     * @return uint256 An integer representing the minted token ID.
     */
    function collectLegacy(Types.LegacyCollectParams calldata collectParams) external returns (uint256);

    /**
     * @custom:meta-tx collect.
     * @custom:pending-deprecation
     */
    function collectLegacyWithSig(
        Types.LegacyCollectParams calldata collectParams,
        Types.EIP712Signature calldata signature
    ) external returns (uint256);

    /**
     * @notice Acts on a given publication with the specified parameters.
     * You can act on a publication except a mirror (if it has at least one action module initialized).
     * Actions can have referrers (e.g. publications or profiles that allowed to discover the pointed publication).
     * @custom:permissions Actor Profile Owner or its Delegated Executor.
     *
     * @param publicationActionParams A PublicationActionParams struct containing the parameters.
     *
     * @return bytes Arbitrary data the action module returns.
     */
    function act(Types.PublicationActionParams calldata publicationActionParams) external returns (bytes memory);

    /**
     * @custom:meta-tx act.
     */
    function actWithSig(
        Types.PublicationActionParams calldata publicationActionParams,
        Types.EIP712Signature calldata signature
    ) external returns (bytes memory);

    /**
     * @dev This function is used to invalidate signatures by incrementing the nonce of the signer.
     * @param increment The amount to increment the nonce by (max 255).
     */
    function incrementNonce(uint8 increment) external;

    /////////////////////////////////
    ///       VIEW FUNCTIONS      ///
    /////////////////////////////////

    /**
     * @notice Returns whether or not `followerProfileId` is following `followedProfileId`.
     *
     * @param followerProfileId The ID of the profile whose following state should be queried.
     * @param followedProfileId The ID of the profile whose followed state should be queried.
     *
     * @return bool True if `followerProfileId` is following `followedProfileId`, false otherwise.
     */
    function isFollowing(uint256 followerProfileId, uint256 followedProfileId) external view returns (bool);

    /**
     * @notice Returns whether the given address is approved as delegated executor, in the configuration with the given
     * number, to act on behalf of the given profile.
     *
     * @param delegatorProfileId The ID of the profile to check the delegated executor approval for.
     * @param delegatedExecutor The address to query the delegated executor approval for.
     * @param configNumber The number of the configuration where the executor approval state is being queried.
     *
     * @return bool True if the address is approved as a delegated executor to act on behalf of the profile in the
     * given configuration, false otherwise.
     */
    function isDelegatedExecutorApproved(
        uint256 delegatorProfileId,
        address delegatedExecutor,
        uint64 configNumber
    ) external view returns (bool);

    /**
     * @notice Returns whether the given address is approved as delegated executor, in the current configuration, to act
     * on behalf of the given profile.
     *
     * @param delegatorProfileId The ID of the profile to check the delegated executor approval for.
     * @param delegatedExecutor The address to query the delegated executor approval for.
     *
     * @return bool True if the address is approved as a delegated executor to act on behalf of the profile in the
     * current configuration, false otherwise.
     */
    function isDelegatedExecutorApproved(
        uint256 delegatorProfileId,
        address delegatedExecutor
    ) external view returns (bool);

    /**
     * @notice Returns the current delegated executor config number for the given profile.
     *
     * @param delegatorProfileId The ID of the profile from which the delegated executors config number is being queried
     *
     * @return uint256 The current delegated executor configuration number.
     */
    function getDelegatedExecutorsConfigNumber(uint256 delegatorProfileId) external view returns (uint64);

    /**
     * @notice Returns the previous used delegated executor config number for the given profile.
     *
     * @param delegatorProfileId The ID of the profile from which the delegated executors' previous configuration number
     * set is being queried.
     *
     * @return uint256 The delegated executor configuration number previously set. It will coincide with the current
     * configuration set if it was never switched from the default one.
     */
    function getDelegatedExecutorsPrevConfigNumber(uint256 delegatorProfileId) external view returns (uint64);

    /**
     * @notice Returns the maximum delegated executor config number for the given profile.
     * This is the maximum config number that was ever used by this profile.
     * When creating a new clean configuration, you can only use a number that is maxConfigNumber + 1.
     *
     * @param delegatorProfileId The ID of the profile from which the delegated executors' maximum configuration number
     * set is being queried.
     *
     * @return uint256 The delegated executor maximum configuration number set.
     */
    function getDelegatedExecutorsMaxConfigNumberSet(uint256 delegatorProfileId) external view returns (uint64);

    /**
     * @notice Returns whether `profileId` is blocked by `byProfileId`.
     * See setBlockStatus() for more information on how blocking works on the platform.
     *
     * @param profileId The ID of the profile whose blocked status should be queried.
     * @param byProfileId The ID of the profile whose blocker status should be queried.
     *
     * @return bool True if `profileId` is blocked by `byProfileId`, false otherwise.
     */
    function isBlocked(uint256 profileId, uint256 byProfileId) external view returns (bool);

    /**
     * @notice Returns the URI associated with a given publication.
     * This is used to store the publication's metadata, e.g.: content, images, etc.
     *
     * @param profileId The token ID of the profile that published the publication to query.
     * @param pubId The publication ID of the publication to query.
     *
     * @return string The URI associated with a given publication.
     */
    function getContentURI(uint256 profileId, uint256 pubId) external view returns (string memory);

    /**
     * @notice Returns the full profile struct associated with a given profile token ID.
     *
     * @param profileId The token ID of the profile to query.
     *
     * @return Profile The profile struct of the given profile.
     */
    function getProfile(uint256 profileId) external view returns (Types.Profile memory);

    /**
     * @notice Returns the full publication struct for a given publication.
     *
     * @param profileId The token ID of the profile that published the publication to query.
     * @param pubId The publication ID of the publication to query.
     *
     * @return Publication The publication struct associated with the queried publication.
     */
    function getPublication(uint256 profileId, uint256 pubId) external view returns (Types.PublicationMemory memory);

    /**
     * @notice Returns the type of a given publication.
     * The type can be one of the following (see PublicationType enum):
     * - Nonexistent
     * - Post
     * - Comment
     * - Mirror
     * - Quote
     *
     * @param profileId The token ID of the profile that published the publication to query.
     * @param pubId The publication ID of the publication to query.
     *
     * @return PublicationType The publication type of the queried publication.
     */
    function getPublicationType(uint256 profileId, uint256 pubId) external view returns (Types.PublicationType);

    /**
     * @notice Returns wether a given Action Module is enabled for a given publication.
     *
     * @param profileId The token ID of the profile that published the publication to query.
     * @param pubId The publication ID of the publication to query.
     * @param module The address of the Action Module to query.
     *
     * @return bool True if the Action Module is enabled for the queried publication, false if not.
     */
    function isActionModuleEnabledInPublication(
        uint256 profileId,
        uint256 pubId,
        address module
    ) external view returns (bool);
}

File 17 of 33 : ILensVersion.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

/**
 * @title ILensVersion
 * @author Lens Protocol
 *
 * @notice This is the interface for the LensHub Version getters and emitter.
 * It allows to emit a LensHub version during an upgrade, and also to get the current version.
 */
interface ILensVersion {
    /**
     * @notice Returns the LensHub current Version.
     *
     * @return version The LensHub current Version.
     */
    function getVersion() external view returns (string memory);

    /**
     * @notice Returns the LensHub current Git Commit.
     *
     * @return gitCommit The LensHub current Git Commit.
     */
    function getGitCommit() external view returns (bytes20);

    /**
     * @notice Emits the LensHub current Version. Used in upgradeAndCall().
     */
    function emitVersion() external;
}

File 18 of 33 : MetaTxLib.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

import {IERC1271} from '@openzeppelin/contracts/interfaces/IERC1271.sol';
import {ILensERC721} from 'contracts/interfaces/ILensERC721.sol';
import {Types} from 'contracts/libraries/constants/Types.sol';
import {Errors} from 'contracts/libraries/constants/Errors.sol';
import {Typehash} from 'contracts/libraries/constants/Typehash.sol';
import {StorageLib} from 'contracts/libraries/StorageLib.sol';
import {Events} from 'contracts/libraries/constants/Events.sol';

/**
 * @title MetaTxLib
 * @author Lens Protocol
 *
 * NOTE: the functions in this contract operate under the assumption that the passed signer is already validated
 * to either be the originator or one of their delegated executors.
 *
 * @dev User nonces are incremented from this library as well.
 */
library MetaTxLib {
    string constant EIP712_DOMAIN_VERSION = '2';
    bytes32 constant EIP712_DOMAIN_VERSION_HASH = keccak256(bytes(EIP712_DOMAIN_VERSION));
    bytes4 constant EIP1271_MAGIC_VALUE = 0x1626ba7e;

    /**
     * @dev We store the domain separator and LensHub Proxy address as constants to save gas.
     *
     * keccak256(
     *     abi.encode(
     *         keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
     *         keccak256('Lens Protocol Profiles'), // Contract Name
     *         keccak256('2'), // Version Hash
     *         137, // Polygon Chain ID
     *         address(0xDb46d1Dc155634FbC732f92E853b10B288AD5a1d) // Verifying Contract Address - LensHub Address
     *     )
     * );
     */
    bytes32 constant LENS_HUB_CACHED_POLYGON_DOMAIN_SEPARATOR =
        0xbf9544cf7d7a0338fc4f071be35409a61e51e9caef559305410ad74e16a05f2d;

    address constant LENS_HUB_ADDRESS = 0xDb46d1Dc155634FbC732f92E853b10B288AD5a1d;

    uint256 constant POLYGON_CHAIN_ID = 137;

    function validateSetProfileMetadataURISignature(
        Types.EIP712Signature calldata signature,
        uint256 profileId,
        string calldata metadataURI
    ) external {
        _validateRecoveredAddress(
            _calculateDigest(
                keccak256(
                    abi.encode(
                        Typehash.SET_PROFILE_METADATA_URI,
                        profileId,
                        _encodeUsingEip712Rules(metadataURI),
                        _getNonceIncrementAndEmitEvent(signature.signer),
                        signature.deadline
                    )
                )
            ),
            signature
        );
    }

    function validateSetFollowModuleSignature(
        Types.EIP712Signature calldata signature,
        uint256 profileId,
        address followModule,
        bytes calldata followModuleInitData
    ) external {
        _validateRecoveredAddress(
            _calculateDigest(
                keccak256(
                    abi.encode(
                        Typehash.SET_FOLLOW_MODULE,
                        profileId,
                        followModule,
                        _encodeUsingEip712Rules(followModuleInitData),
                        _getNonceIncrementAndEmitEvent(signature.signer),
                        signature.deadline
                    )
                )
            ),
            signature
        );
    }

    function validateChangeDelegatedExecutorsConfigSignature(
        Types.EIP712Signature calldata signature,
        uint256 delegatorProfileId,
        address[] calldata delegatedExecutors,
        bool[] calldata approvals,
        uint64 configNumber,
        bool switchToGivenConfig
    ) external {
        address signer = signature.signer;
        uint256 deadline = signature.deadline;
        _validateRecoveredAddress(
            _calculateDigest(
                keccak256(
                    abi.encode(
                        Typehash.CHANGE_DELEGATED_EXECUTORS_CONFIG,
                        delegatorProfileId,
                        _encodeUsingEip712Rules(delegatedExecutors),
                        _encodeUsingEip712Rules(approvals),
                        configNumber,
                        switchToGivenConfig,
                        _getNonceIncrementAndEmitEvent(signer),
                        deadline
                    )
                )
            ),
            signature
        );
    }

    function validatePostSignature(
        Types.EIP712Signature calldata signature,
        Types.PostParams calldata postParams
    ) external {
        _validateRecoveredAddress(
            _calculateDigest(
                keccak256(
                    abi.encode(
                        Typehash.POST,
                        postParams.profileId,
                        _encodeUsingEip712Rules(postParams.contentURI),
                        _encodeUsingEip712Rules(postParams.actionModules),
                        _encodeUsingEip712Rules(postParams.actionModulesInitDatas),
                        postParams.referenceModule,
                        _encodeUsingEip712Rules(postParams.referenceModuleInitData),
                        _getNonceIncrementAndEmitEvent(signature.signer),
                        signature.deadline
                    )
                )
            ),
            signature
        );
    }

    function validateCommentSignature(
        Types.EIP712Signature calldata signature,
        Types.CommentParams calldata commentParams
    ) external {
        bytes memory encodedAbi = abi.encode(
            Typehash.COMMENT,
            commentParams.profileId,
            _encodeUsingEip712Rules(commentParams.contentURI),
            commentParams.pointedProfileId,
            commentParams.pointedPubId,
            _encodeUsingEip712Rules(commentParams.referrerProfileIds),
            _encodeUsingEip712Rules(commentParams.referrerPubIds),
            _encodeUsingEip712Rules(commentParams.referenceModuleData),
            _encodeUsingEip712Rules(commentParams.actionModules),
            _encodeUsingEip712Rules(commentParams.actionModulesInitDatas),
            commentParams.referenceModule,
            _encodeUsingEip712Rules(commentParams.referenceModuleInitData),
            _getNonceIncrementAndEmitEvent(signature.signer),
            signature.deadline
        );
        _validateRecoveredAddress(_calculateDigest(keccak256(encodedAbi)), signature);
    }

    function validateQuoteSignature(
        Types.EIP712Signature calldata signature,
        Types.QuoteParams calldata quoteParams
    ) external {
        bytes memory encodedAbi = abi.encode(
            Typehash.QUOTE,
            quoteParams.profileId,
            _encodeUsingEip712Rules(quoteParams.contentURI),
            quoteParams.pointedProfileId,
            quoteParams.pointedPubId,
            _encodeUsingEip712Rules(quoteParams.referrerProfileIds),
            _encodeUsingEip712Rules(quoteParams.referrerPubIds),
            _encodeUsingEip712Rules(quoteParams.referenceModuleData),
            _encodeUsingEip712Rules(quoteParams.actionModules),
            _encodeUsingEip712Rules(quoteParams.actionModulesInitDatas),
            quoteParams.referenceModule,
            _encodeUsingEip712Rules(quoteParams.referenceModuleInitData),
            _getNonceIncrementAndEmitEvent(signature.signer),
            signature.deadline
        );
        _validateRecoveredAddress(_calculateDigest(keccak256(encodedAbi)), signature);
    }

    function validateMirrorSignature(
        Types.EIP712Signature calldata signature,
        Types.MirrorParams calldata mirrorParams
    ) external {
        _validateRecoveredAddress(
            _calculateDigest(
                keccak256(
                    abi.encode(
                        Typehash.MIRROR,
                        mirrorParams.profileId,
                        _encodeUsingEip712Rules(mirrorParams.metadataURI),
                        mirrorParams.pointedProfileId,
                        mirrorParams.pointedPubId,
                        _encodeUsingEip712Rules(mirrorParams.referrerProfileIds),
                        _encodeUsingEip712Rules(mirrorParams.referrerPubIds),
                        _encodeUsingEip712Rules(mirrorParams.referenceModuleData),
                        _getNonceIncrementAndEmitEvent(signature.signer),
                        signature.deadline
                    )
                )
            ),
            signature
        );
    }

    function validateFollowSignature(
        Types.EIP712Signature calldata signature,
        uint256 followerProfileId,
        uint256[] calldata idsOfProfilesToFollow,
        uint256[] calldata followTokenIds,
        bytes[] calldata datas
    ) external {
        _validateRecoveredAddress(
            _calculateDigest(
                keccak256(
                    abi.encode(
                        Typehash.FOLLOW,
                        followerProfileId,
                        _encodeUsingEip712Rules(idsOfProfilesToFollow),
                        _encodeUsingEip712Rules(followTokenIds),
                        _encodeUsingEip712Rules(datas),
                        _getNonceIncrementAndEmitEvent(signature.signer),
                        signature.deadline
                    )
                )
            ),
            signature
        );
    }

    function validateUnfollowSignature(
        Types.EIP712Signature calldata signature,
        uint256 unfollowerProfileId,
        uint256[] calldata idsOfProfilesToUnfollow
    ) external {
        _validateRecoveredAddress(
            _calculateDigest(
                keccak256(
                    abi.encode(
                        Typehash.UNFOLLOW,
                        unfollowerProfileId,
                        _encodeUsingEip712Rules(idsOfProfilesToUnfollow),
                        _getNonceIncrementAndEmitEvent(signature.signer),
                        signature.deadline
                    )
                )
            ),
            signature
        );
    }

    function validateSetBlockStatusSignature(
        Types.EIP712Signature calldata signature,
        uint256 byProfileId,
        uint256[] calldata idsOfProfilesToSetBlockStatus,
        bool[] calldata blockStatus
    ) external {
        _validateRecoveredAddress(
            _calculateDigest(
                keccak256(
                    abi.encode(
                        Typehash.SET_BLOCK_STATUS,
                        byProfileId,
                        _encodeUsingEip712Rules(idsOfProfilesToSetBlockStatus),
                        _encodeUsingEip712Rules(blockStatus),
                        _getNonceIncrementAndEmitEvent(signature.signer),
                        signature.deadline
                    )
                )
            ),
            signature
        );
    }

    function validateLegacyCollectSignature(
        Types.EIP712Signature calldata signature,
        Types.LegacyCollectParams calldata collectParams
    ) external {
        _validateRecoveredAddress(
            _calculateDigest(
                keccak256(
                    abi.encode(
                        Typehash.COLLECT_LEGACY,
                        collectParams.publicationCollectedProfileId,
                        collectParams.publicationCollectedId,
                        collectParams.collectorProfileId,
                        collectParams.referrerProfileId,
                        collectParams.referrerPubId,
                        _encodeUsingEip712Rules(collectParams.collectModuleData),
                        _getNonceIncrementAndEmitEvent(signature.signer),
                        signature.deadline
                    )
                )
            ),
            signature
        );
    }

    function validateActSignature(
        Types.EIP712Signature calldata signature,
        Types.PublicationActionParams calldata publicationActionParams
    ) external {
        _validateRecoveredAddress(
            _calculateDigest(
                keccak256(
                    abi.encode(
                        Typehash.ACT,
                        publicationActionParams.publicationActedProfileId,
                        publicationActionParams.publicationActedId,
                        publicationActionParams.actorProfileId,
                        _encodeUsingEip712Rules(publicationActionParams.referrerProfileIds),
                        _encodeUsingEip712Rules(publicationActionParams.referrerPubIds),
                        publicationActionParams.actionModuleAddress,
                        _encodeUsingEip712Rules(publicationActionParams.actionModuleData),
                        _getNonceIncrementAndEmitEvent(signature.signer),
                        signature.deadline
                    )
                )
            ),
            signature
        );
    }

    /// @dev This function is used to invalidate signatures by incrementing the nonce
    function incrementNonce(uint8 increment) external {
        uint256 currentNonce = StorageLib.nonces()[msg.sender];
        StorageLib.nonces()[msg.sender] = currentNonce + increment;
        emit Events.NonceUpdated(msg.sender, currentNonce + increment, block.timestamp);
    }

    function calculateDomainSeparator() internal view returns (bytes32) {
        if (address(this) == LENS_HUB_ADDRESS && block.chainid == POLYGON_CHAIN_ID) {
            return LENS_HUB_CACHED_POLYGON_DOMAIN_SEPARATOR;
        }
        return
            keccak256(
                abi.encode(
                    Typehash.EIP712_DOMAIN,
                    keccak256(bytes(ILensERC721(address(this)).name())),
                    EIP712_DOMAIN_VERSION_HASH,
                    block.chainid,
                    address(this)
                )
            );
    }

    /**
     * @dev Wrapper for ecrecover to reduce code size, used in meta-tx specific functions.
     */
    function _validateRecoveredAddress(bytes32 digest, Types.EIP712Signature calldata signature) private view {
        if (block.timestamp > signature.deadline) revert Errors.SignatureExpired();
        // If the expected address is a contract, check the signature there.
        if (signature.signer.code.length != 0) {
            bytes memory concatenatedSig = abi.encodePacked(signature.r, signature.s, signature.v);
            if (IERC1271(signature.signer).isValidSignature(digest, concatenatedSig) != EIP1271_MAGIC_VALUE) {
                revert Errors.SignatureInvalid();
            }
        } else {
            address recoveredAddress = ecrecover(digest, signature.v, signature.r, signature.s);
            if (recoveredAddress == address(0) || recoveredAddress != signature.signer) {
                revert Errors.SignatureInvalid();
            }
        }
    }

    /**
     * @dev Calculates EIP712 digest based on the current DOMAIN_SEPARATOR.
     *
     * @param hashedMessage The message hash from which the digest should be calculated.
     *
     * @return bytes32 A 32-byte output representing the EIP712 digest.
     */
    function _calculateDigest(bytes32 hashedMessage) private view returns (bytes32) {
        return keccak256(abi.encodePacked('\x19\x01', calculateDomainSeparator(), hashedMessage));
    }

    /**
     * @dev This fetches a signer's current nonce and increments it so it's ready for the next meta-tx. Also emits
     * the `NonceUpdated` event.
     *
     * @param signer The address to get and increment the nonce for.
     *
     * @return uint256 The current nonce for the given signer prior to being incremented.
     */
    function _getNonceIncrementAndEmitEvent(address signer) private returns (uint256) {
        uint256 currentNonce;
        unchecked {
            currentNonce = StorageLib.nonces()[signer]++;
        }
        emit Events.NonceUpdated(signer, currentNonce + 1, block.timestamp);
        return currentNonce;
    }

    function _encodeUsingEip712Rules(bytes[] memory bytesArray) private pure returns (bytes32) {
        bytes32[] memory bytesArrayEncodedElements = new bytes32[](bytesArray.length);
        uint256 i;
        while (i < bytesArray.length) {
            // A `bytes` type is encoded as its keccak256 hash.
            bytesArrayEncodedElements[i] = _encodeUsingEip712Rules(bytesArray[i]);
            unchecked {
                ++i;
            }
        }
        // An array is encoded as the keccak256 hash of the concatenation of their encoded elements.
        return _encodeUsingEip712Rules(bytesArrayEncodedElements);
    }

    function _encodeUsingEip712Rules(bool[] memory boolArray) private pure returns (bytes32) {
        return keccak256(abi.encodePacked(boolArray));
    }

    function _encodeUsingEip712Rules(address[] memory addressArray) private pure returns (bytes32) {
        return keccak256(abi.encodePacked(addressArray));
    }

    function _encodeUsingEip712Rules(uint256[] memory uint256Array) private pure returns (bytes32) {
        return keccak256(abi.encodePacked(uint256Array));
    }

    function _encodeUsingEip712Rules(bytes32[] memory bytes32Array) private pure returns (bytes32) {
        return keccak256(abi.encodePacked(bytes32Array));
    }

    function _encodeUsingEip712Rules(string memory stringValue) private pure returns (bytes32) {
        return keccak256(bytes(stringValue));
    }

    function _encodeUsingEip712Rules(bytes memory bytesValue) private pure returns (bytes32) {
        return keccak256(bytesValue);
    }
}

File 19 of 33 : StorageLib.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.15;

import {Types} from 'contracts/libraries/constants/Types.sol';
import {Errors} from 'contracts/libraries/constants/Errors.sol';

library StorageLib {
    // uint256 constant NAME_SLOT = 0;
    // uint256 constant SYMBOL_SLOT = 1;
    uint256 constant TOKEN_DATA_MAPPING_SLOT = 2;
    // uint256 constant BALANCES_SLOT = 3;
    // uint256 constant TOKEN_APPROVAL_MAPPING_SLOT = 4;
    // uint256 constant OPERATOR_APPROVAL_MAPPING_SLOT = 5;
    // Slot 6 is deprecated in Lens V2. In V1 it was used for ERC-721 Enumerable's `ownedTokens`.
    // Slot 7 is deprecated in Lens V2. In V1 it was used for ERC-721 Enumerable's `ownedTokensIndex`.
    // uint256 constant TOTAL_SUPPLY_SLOT = 8;
    // Slot 9 is deprecated in Lens V2. In V1 it was used for ERC-721 Enumerable's `allTokensIndex`.
    uint256 constant SIG_NONCES_MAPPING_SLOT = 10;
    uint256 constant LAST_INITIALIZED_REVISION_SLOT = 11; // VersionedInitializable's `lastInitializedRevision` field.
    uint256 constant PROTOCOL_STATE_SLOT = 12;
    uint256 constant PROFILE_CREATOR_WHITELIST_MAPPING_SLOT = 13;
    // Slot 14 is deprecated in Lens V2. In V1 it was used for the follow module address whitelist.
    // Slot 15 is deprecated in Lens V2. In V1 it was used for the collect module address whitelist.
    // Slot 16 is deprecated in Lens V2. In V1 it was used for the reference module address whitelist.
    // Slot 17 is deprecated in Lens V2. In V1 it was used for the dispatcher address by profile ID.
    uint256 constant PROFILE_ID_BY_HANDLE_HASH_MAPPING_SLOT = 18; // Deprecated slot, but still needed for V2 migration.
    uint256 constant PROFILES_MAPPING_SLOT = 19;
    uint256 constant PUBLICATIONS_MAPPING_SLOT = 20;
    // Slot 21 is deprecated in Lens V2. In V1 it was used for the default profile ID by address.
    uint256 constant PROFILE_COUNTER_SLOT = 22;
    uint256 constant GOVERNANCE_SLOT = 23;
    uint256 constant EMERGENCY_ADMIN_SLOT = 24;
    //////////////////////////////////
    ///  Introduced in Lens V1.3:  ///
    //////////////////////////////////
    uint256 constant TOKEN_GUARDIAN_DISABLING_TIMESTAMP_MAPPING_SLOT = 25;
    //////////////////////////////////
    ///   Introduced in Lens V2:   ///
    //////////////////////////////////
    uint256 constant DELEGATED_EXECUTOR_CONFIG_MAPPING_SLOT = 26;
    uint256 constant BLOCKED_STATUS_MAPPING_SLOT = 27;
    uint256 constant PROFILE_ROYALTIES_BPS_SLOT = 28;
    uint256 constant MIGRATION_ADMINS_WHITELISTED_MAPPING_SLOT = 29;
    uint256 constant TREASURY_DATA_SLOT = 30;
    uint256 constant PROFILE_TOKEN_URI_CONTRACT_SLOT = 31;
    uint256 constant FOLLOW_TOKEN_URI_CONTRACT_SLOT = 32;

    function getPublication(
        uint256 profileId,
        uint256 pubId
    ) internal pure returns (Types.Publication storage _publication) {
        assembly {
            mstore(0, profileId)
            mstore(32, PUBLICATIONS_MAPPING_SLOT)
            mstore(32, keccak256(0, 64))
            mstore(0, pubId)
            _publication.slot := keccak256(0, 64)
        }
    }

    function getPublicationMemory(
        uint256 profileId,
        uint256 pubId
    ) internal pure returns (Types.PublicationMemory memory) {
        Types.PublicationMemory storage _publicationStorage;
        assembly {
            mstore(0, profileId)
            mstore(32, PUBLICATIONS_MAPPING_SLOT)
            mstore(32, keccak256(0, 64))
            mstore(0, pubId)
            _publicationStorage.slot := keccak256(0, 64)
        }

        Types.PublicationMemory memory _publicationMemory;
        _publicationMemory = _publicationStorage;

        return _publicationMemory;
    }

    function getProfile(uint256 profileId) internal pure returns (Types.Profile storage _profiles) {
        assembly {
            mstore(0, profileId)
            mstore(32, PROFILES_MAPPING_SLOT)
            _profiles.slot := keccak256(0, 64)
        }
    }

    function getDelegatedExecutorsConfig(
        uint256 delegatorProfileId
    ) internal pure returns (Types.DelegatedExecutorsConfig storage _delegatedExecutorsConfig) {
        assembly {
            mstore(0, delegatorProfileId)
            mstore(32, DELEGATED_EXECUTOR_CONFIG_MAPPING_SLOT)
            _delegatedExecutorsConfig.slot := keccak256(0, 64)
        }
    }

    function tokenGuardianDisablingTimestamp()
        internal
        pure
        returns (mapping(address => uint256) storage _tokenGuardianDisablingTimestamp)
    {
        assembly {
            _tokenGuardianDisablingTimestamp.slot := TOKEN_GUARDIAN_DISABLING_TIMESTAMP_MAPPING_SLOT
        }
    }

    function getTokenData(uint256 tokenId) internal pure returns (Types.TokenData storage _tokenData) {
        assembly {
            mstore(0, tokenId)
            mstore(32, TOKEN_DATA_MAPPING_SLOT)
            _tokenData.slot := keccak256(0, 64)
        }
    }

    function blockedStatus(
        uint256 blockerProfileId
    ) internal pure returns (mapping(uint256 => bool) storage _blockedStatus) {
        assembly {
            mstore(0, blockerProfileId)
            mstore(32, BLOCKED_STATUS_MAPPING_SLOT)
            _blockedStatus.slot := keccak256(0, 64)
        }
    }

    function nonces() internal pure returns (mapping(address => uint256) storage _nonces) {
        assembly {
            _nonces.slot := SIG_NONCES_MAPPING_SLOT
        }
    }

    function profileIdByHandleHash()
        internal
        pure
        returns (mapping(bytes32 => uint256) storage _profileIdByHandleHash)
    {
        assembly {
            _profileIdByHandleHash.slot := PROFILE_ID_BY_HANDLE_HASH_MAPPING_SLOT
        }
    }

    function profileCreatorWhitelisted()
        internal
        pure
        returns (mapping(address => bool) storage _profileCreatorWhitelisted)
    {
        assembly {
            _profileCreatorWhitelisted.slot := PROFILE_CREATOR_WHITELIST_MAPPING_SLOT
        }
    }

    function migrationAdminWhitelisted()
        internal
        pure
        returns (mapping(address => bool) storage _migrationAdminWhitelisted)
    {
        assembly {
            _migrationAdminWhitelisted.slot := MIGRATION_ADMINS_WHITELISTED_MAPPING_SLOT
        }
    }

    function getGovernance() internal view returns (address _governance) {
        assembly {
            _governance := sload(GOVERNANCE_SLOT)
        }
    }

    function setGovernance(address newGovernance) internal {
        assembly {
            sstore(GOVERNANCE_SLOT, newGovernance)
        }
    }

    function getEmergencyAdmin() internal view returns (address _emergencyAdmin) {
        assembly {
            _emergencyAdmin := sload(EMERGENCY_ADMIN_SLOT)
        }
    }

    function setEmergencyAdmin(address newEmergencyAdmin) internal {
        assembly {
            sstore(EMERGENCY_ADMIN_SLOT, newEmergencyAdmin)
        }
    }

    function getState() internal view returns (Types.ProtocolState _state) {
        assembly {
            _state := sload(PROTOCOL_STATE_SLOT)
        }
    }

    function setState(Types.ProtocolState newState) internal {
        assembly {
            sstore(PROTOCOL_STATE_SLOT, newState)
        }
    }

    function getLastInitializedRevision() internal view returns (uint256 _lastInitializedRevision) {
        assembly {
            _lastInitializedRevision := sload(LAST_INITIALIZED_REVISION_SLOT)
        }
    }

    function setLastInitializedRevision(uint256 newLastInitializedRevision) internal {
        assembly {
            sstore(LAST_INITIALIZED_REVISION_SLOT, newLastInitializedRevision)
        }
    }

    function getTreasuryData() internal pure returns (Types.TreasuryData storage _treasuryData) {
        assembly {
            _treasuryData.slot := TREASURY_DATA_SLOT
        }
    }

    function setProfileTokenURIContract(address profileTokenURIContract) internal {
        assembly {
            sstore(PROFILE_TOKEN_URI_CONTRACT_SLOT, profileTokenURIContract)
        }
    }

    function setFollowTokenURIContract(address followTokenURIContract) internal {
        assembly {
            sstore(FOLLOW_TOKEN_URI_CONTRACT_SLOT, followTokenURIContract)
        }
    }

    function getProfileTokenURIContract() internal view returns (address _profileTokenURIContract) {
        assembly {
            _profileTokenURIContract := sload(PROFILE_TOKEN_URI_CONTRACT_SLOT)
        }
    }

    function getFollowTokenURIContract() internal view returns (address _followTokenURIContract) {
        assembly {
            _followTokenURIContract := sload(FOLLOW_TOKEN_URI_CONTRACT_SLOT)
        }
    }
}

File 20 of 33 : Errors.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

library Errors {
    error CannotInitImplementation();
    error Initialized();
    error SignatureExpired();
    error SignatureInvalid();
    error InvalidOwner();
    error NotOwnerOrApproved();
    error NotHub();
    error TokenDoesNotExist();
    error NotGovernance();
    error NotGovernanceOrEmergencyAdmin();
    error EmergencyAdminCanOnlyPauseFurther();
    error NotProfileOwner();
    error PublicationDoesNotExist();
    error CallerNotFollowNFT();
    error CallerNotCollectNFT(); // Legacy
    error ArrayMismatch();
    error NotWhitelisted();
    error NotRegistered();
    error InvalidParameter();
    error ExecutorInvalid();
    error Blocked();
    error SelfBlock();
    error NotFollowing();
    error SelfFollow();
    error InvalidReferrer();
    error InvalidPointedPub();
    error NonERC721ReceiverImplementer();
    error AlreadyEnabled();

    // Module Errors
    error InitParamsInvalid();
    error ActionNotAllowed();

    error CollectNotAllowed(); // Used in LegacyCollectLib (pending deprecation)

    // MultiState Errors
    error Paused();
    error PublishingPaused();

    // Profile Guardian Errors
    error GuardianEnabled();
    error NotEOA();
    error DisablingAlreadyTriggered();

    // Migration Errors
    error NotMigrationAdmin();
}

File 21 of 33 : Events.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

import {Types} from 'contracts/libraries/constants/Types.sol';

library Events {
    /**
     * @dev Emitted when the NFT contract's name and symbol are set at initialization.
     *
     * @param name The NFT name set.
     * @param symbol The NFT symbol set.
     * @param timestamp The current block timestamp.
     */
    event BaseInitialized(string name, string symbol, uint256 timestamp);

    /**
     * @dev Emitted when the hub state is set.
     *
     * @param caller The caller who set the state.
     * @param prevState The previous protocol state, an enum of either `Paused`, `PublishingPaused` or `Unpaused`.
     * @param newState The newly set state, an enum of either `Paused`, `PublishingPaused` or `Unpaused`.
     * @param timestamp The current block timestamp.
     */
    event StateSet(
        address indexed caller,
        Types.ProtocolState indexed prevState,
        Types.ProtocolState indexed newState,
        uint256 timestamp
    );

    /**
     * @dev Emitted when the governance address is changed. We emit the caller even though it should be the previous
     * governance address, as we cannot guarantee this will always be the case due to upgradeability.
     *
     * @param caller The caller who set the governance address.
     * @param prevGovernance The previous governance address.
     * @param newGovernance The new governance address set.
     * @param timestamp The current block timestamp.
     */
    event GovernanceSet(
        address indexed caller,
        address indexed prevGovernance,
        address indexed newGovernance,
        uint256 timestamp
    );

    /**
     * @dev Emitted when the emergency admin is changed. We emit the caller even though it should be the previous
     * governance address, as we cannot guarantee this will always be the case due to upgradeability.
     *
     * @param caller The caller who set the emergency admin address.
     * @param oldEmergencyAdmin The previous emergency admin address.
     * @param newEmergencyAdmin The new emergency admin address set.
     * @param timestamp The current block timestamp.
     */
    event EmergencyAdminSet(
        address indexed caller,
        address indexed oldEmergencyAdmin,
        address indexed newEmergencyAdmin,
        uint256 timestamp
    );

    /**
     * @dev Emitted when a profile creator is added to or removed from the whitelist.
     *
     * @param profileCreator The address of the profile creator.
     * @param whitelisted Whether or not the profile creator is being added to the whitelist.
     * @param timestamp The current block timestamp.
     */
    event ProfileCreatorWhitelisted(address indexed profileCreator, bool indexed whitelisted, uint256 timestamp);

    /**
     * @dev Emitted when a profile is created.
     *
     * @param profileId The newly created profile's token ID.
     * @param creator The profile creator, who created the token with the given profile ID.
     * @param to The address receiving the profile with the given profile ID.
     * @param timestamp The current block timestamp.
     */
    event ProfileCreated(uint256 indexed profileId, address indexed creator, address indexed to, uint256 timestamp);

    /**
     * @dev Emitted when a delegated executors configuration is changed.
     *
     * @param delegatorProfileId The ID of the profile for which the delegated executor was changed.
     * @param configNumber The number of the configuration where the executor approval state was set.
     * @param delegatedExecutors The array of delegated executors whose approval was set for.
     * @param approvals The array of booleans indicating the corresponding executor new approval status.
     * @param timestamp The current block timestamp.
     */
    event DelegatedExecutorsConfigChanged(
        uint256 indexed delegatorProfileId,
        uint256 indexed configNumber,
        address[] delegatedExecutors,
        bool[] approvals,
        uint256 timestamp
    );

    /**
     * @dev Emitted when a delegated executors configuration is applied.
     *
     * @param delegatorProfileId The ID of the profile applying the configuration.
     * @param configNumber The number of the configuration applied.
     * @param timestamp The current block timestamp.
     */
    event DelegatedExecutorsConfigApplied(
        uint256 indexed delegatorProfileId,
        uint256 indexed configNumber,
        uint256 timestamp
    );

    /**
     * @dev Emitted when a profile's follow module is set.
     *
     * @param profileId The profile's token ID.
     * @param followModule The profile's newly set follow module. This CAN be the zero address.
     * @param followModuleInitData The data passed to the follow module, if any.
     * @param followModuleReturnData The data returned from the follow module's initialization. This is ABI-encoded
     * and depends on the follow module chosen.
     * @param transactionExecutor The address of the account that executed this operation.
     * @param timestamp The current block timestamp.
     */
    event FollowModuleSet(
        uint256 indexed profileId,
        address followModule,
        bytes followModuleInitData,
        bytes followModuleReturnData,
        address transactionExecutor,
        uint256 timestamp
    );

    /**
     * @dev Emitted when a post is successfully published.
     *
     * @param postParams The parameters passed to create the post publication.
     * @param pubId The publication ID assigned to the created post.
     * @param actionModulesInitReturnDatas The data returned from the action modules' initialization for this given
     * publication. This is ABI-encoded and depends on the action module chosen.
     * @param referenceModuleInitReturnData The data returned from the reference module at initialization. This is
     * ABI-encoded and depends on the reference module chosen.
     * @param transactionExecutor The address of the account that executed this operation.
     * @param timestamp The current block timestamp.
     */
    event PostCreated(
        Types.PostParams postParams,
        uint256 indexed pubId,
        bytes[] actionModulesInitReturnDatas,
        bytes referenceModuleInitReturnData,
        address transactionExecutor,
        uint256 timestamp
    );

    /**
     * @dev Emitted when a comment is successfully published.
     *
     * @param commentParams The parameters passed to create the comment publication.
     * @param pubId The publication ID assigned to the created comment.
     * @param referenceModuleReturnData The data returned by the commented publication reference module's
     * processComment function, if the commented publication has a reference module set.
     * @param actionModulesInitReturnDatas The data returned from the action modules' initialization for this given
     * publication. This is ABI-encoded and depends on the action module chosen.
     * @param referenceModuleInitReturnData The data returned from the reference module at initialization. This is
     * ABI-encoded and depends on the reference module chosen.
     * @param transactionExecutor The address of the account that executed this operation.
     * @param timestamp The current block timestamp.
     */
    event CommentCreated(
        Types.CommentParams commentParams,
        uint256 indexed pubId,
        bytes referenceModuleReturnData,
        bytes[] actionModulesInitReturnDatas,
        bytes referenceModuleInitReturnData,
        address transactionExecutor,
        uint256 timestamp
    );

    /**
     * @dev Emitted when a mirror is successfully published.
     *
     * @param mirrorParams The parameters passed to create the mirror publication.
     * @param pubId The publication ID assigned to the created mirror.
     * @param referenceModuleReturnData The data returned by the mirrored publication reference module's
     * processMirror function, if the mirrored publication has a reference module set.
     * @param transactionExecutor The address of the account that executed this operation.
     * @param timestamp The current block timestamp.
     */
    event MirrorCreated(
        Types.MirrorParams mirrorParams,
        uint256 indexed pubId,
        bytes referenceModuleReturnData,
        address transactionExecutor,
        uint256 timestamp
    );

    /**
     * @dev Emitted when a quote is successfully published.
     *
     * @param quoteParams The parameters passed to create the quote publication.
     * @param pubId The publication ID assigned to the created quote.
     * @param referenceModuleReturnData The data returned by the quoted publication reference module's
     * processQuote function, if the quoted publication has a reference module set.
     * @param actionModulesInitReturnDatas The data returned from the action modules' initialization for this given
     * publication. This is ABI-encoded and depends on the action module chosen.
     * @param referenceModuleInitReturnData The data returned from the reference module at initialization. This is
     * ABI-encoded and depends on the reference module chosen.
     * @param transactionExecutor The address of the account that executed this operation.
     * @param timestamp The current block timestamp.
     */
    event QuoteCreated(
        Types.QuoteParams quoteParams,
        uint256 indexed pubId,
        bytes referenceModuleReturnData,
        bytes[] actionModulesInitReturnDatas,
        bytes referenceModuleInitReturnData,
        address transactionExecutor,
        uint256 timestamp
    );

    /**
     * @dev Emitted when a followNFT clone is deployed using a lazy deployment pattern.
     *
     * @param profileId The token ID of the profile to which this followNFT is associated.
     * @param followNFT The address of the newly deployed followNFT clone.
     * @param timestamp The current block timestamp.
     */
    event FollowNFTDeployed(uint256 indexed profileId, address indexed followNFT, uint256 timestamp);
    /**
     * @dev Emitted when a collectNFT clone is deployed using a lazy deployment pattern.
     *
     * @param profileId The publisher's profile token ID.
     * @param pubId The publication associated with the newly deployed collectNFT clone's ID.
     * @param collectNFT The address of the newly deployed collectNFT clone.
     * @param timestamp The current block timestamp.
     */
    event LegacyCollectNFTDeployed(
        uint256 indexed profileId,
        uint256 indexed pubId,
        address indexed collectNFT,
        uint256 timestamp
    );
    /**
     * @dev Emitted upon a successful action.
     *
     * @param publicationActionParams The parameters passed to act on a publication.
     * @param actionModuleReturnData The data returned from the action modules. This is ABI-encoded and the format
     * depends on the action module chosen.
     * @param transactionExecutor The address of the account that executed this operation.
     * @param timestamp The current block timestamp.
     */
    event Acted(
        Types.PublicationActionParams publicationActionParams,
        bytes actionModuleReturnData,
        address transactionExecutor,
        uint256 timestamp
    );

    /**
     * @dev Emitted upon a successful follow operation.
     *
     * @param followerProfileId The ID of the profile that executed the follow.
     * @param idOfProfileFollowed The ID of the profile that was followed.
     * @param followTokenIdAssigned The ID of the follow token assigned to the follower.
     * @param followModuleData The data to pass to the follow module, if any.
     * @param processFollowModuleReturnData The data returned by the followed profile follow module's processFollow
     * function, if the followed profile has a reference module set.
     * @param transactionExecutor The address of the account that executed this operation.
     * @param timestamp The timestamp of the follow operation.
     */
    event Followed(
        uint256 indexed followerProfileId,
        uint256 idOfProfileFollowed,
        uint256 followTokenIdAssigned,
        bytes followModuleData,
        bytes processFollowModuleReturnData,
        address transactionExecutor,
        uint256 timestamp
    );

    /**
     * @dev Emitted upon a successful unfollow operation.
     *
     * @param unfollowerProfileId The ID of the profile that executed the unfollow.
     * @param idOfProfileUnfollowed The ID of the profile that was unfollowed.
     * @param transactionExecutor The address of the account that executed this operation.
     * @param timestamp The timestamp of the unfollow operation.
     */
    event Unfollowed(
        uint256 indexed unfollowerProfileId,
        uint256 idOfProfileUnfollowed,
        address transactionExecutor,
        uint256 timestamp
    );

    /**
     * @dev Emitted upon a successful block, through a block status setting operation.
     *
     * @param byProfileId The ID of the profile that executed the block status change.
     * @param idOfProfileBlocked The ID of the profile whose block status have been set to blocked.
     * @param transactionExecutor The address of the account that executed this operation.
     * @param timestamp The timestamp of the block operation.
     */
    event Blocked(
        uint256 indexed byProfileId,
        uint256 idOfProfileBlocked,
        address transactionExecutor,
        uint256 timestamp
    );

    /**
     * @dev Emitted upon a successful unblock, through a block status setting operation.
     *
     * @param byProfileId The ID of the profile that executed the block status change.
     * @param idOfProfileUnblocked The ID of the profile whose block status have been set to unblocked.
     * @param transactionExecutor The address of the account that executed this operation.
     * @param timestamp The timestamp of the unblock operation.
     */
    event Unblocked(
        uint256 indexed byProfileId,
        uint256 idOfProfileUnblocked,
        address transactionExecutor,
        uint256 timestamp
    );

    /**
     * @dev Emitted via callback when a collectNFT is transferred.
     *
     * @param profileId The token ID of the profile associated with the collectNFT being transferred.
     * @param pubId The publication ID associated with the collectNFT being transferred.
     * @param collectNFTId The collectNFT being transferred's token ID.
     * @param from The address the collectNFT is being transferred from.
     * @param to The address the collectNFT is being transferred to.
     * @param timestamp The current block timestamp.
     */
    event CollectNFTTransferred(
        uint256 indexed profileId,
        uint256 indexed pubId,
        uint256 indexed collectNFTId,
        address from,
        address to,
        uint256 timestamp
    );

    /**
     * @notice Emitted when the treasury address is set.
     *
     * @param prevTreasury The previous treasury address.
     * @param newTreasury The new treasury address set.
     * @param timestamp The current block timestamp.
     */
    event TreasurySet(address indexed prevTreasury, address indexed newTreasury, uint256 timestamp);

    /**
     * @notice Emitted when the treasury fee is set.
     *
     * @param prevTreasuryFee The previous treasury fee in BPS.
     * @param newTreasuryFee The new treasury fee in BPS.
     * @param timestamp The current block timestamp.
     */
    event TreasuryFeeSet(uint16 indexed prevTreasuryFee, uint16 indexed newTreasuryFee, uint256 timestamp);

    /**
     * @dev Emitted when the metadata associated with a profile is set in the `LensPeriphery`.
     *
     * @param profileId The profile ID the metadata is set for.
     * @param metadata The metadata set for the profile and user.
     * @param transactionExecutor The address of the account that executed this operation.
     * @param timestamp The current block timestamp.
     */
    event ProfileMetadataSet(
        uint256 indexed profileId,
        string metadata,
        address transactionExecutor,
        uint256 timestamp
    );

    /**
     * @dev Emitted when an address' Profile Guardian state change is triggered.
     *
     * @param wallet The address whose Token Guardian state change is being triggered.
     * @param enabled True if the Token Guardian is being enabled, false if it is being disabled.
     * @param tokenGuardianDisablingTimestamp The UNIX timestamp when disabling the Token Guardian will take effect,
     * if disabling it. Zero if the protection is being enabled.
     * @param timestamp The UNIX timestamp of the change being triggered.
     */
    event TokenGuardianStateChanged(
        address indexed wallet,
        bool indexed enabled,
        uint256 tokenGuardianDisablingTimestamp,
        uint256 timestamp
    );

    /**
     * @dev Emitted when a signer's nonce is used and, as a consequence, the next available nonce is updated.
     *
     * @param signer The signer whose next available nonce was updated.
     * @param nonce The next available nonce that can be used to execute a meta-tx successfully.
     * @param timestamp The UNIX timestamp of the nonce being used.
     */
    event NonceUpdated(address indexed signer, uint256 nonce, uint256 timestamp);
}

File 22 of 33 : Typehash.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

library Typehash {

    bytes32 constant ACT = keccak256('Act(uint256 publicationActedProfileId,uint256 publicationActedId,uint256 actorProfileId,uint256[] referrerProfileIds,uint256[] referrerPubIds,address actionModuleAddress,bytes actionModuleData,uint256 nonce,uint256 deadline)');

    bytes32 constant CHANGE_DELEGATED_EXECUTORS_CONFIG = keccak256('ChangeDelegatedExecutorsConfig(uint256 delegatorProfileId,address[] delegatedExecutors,bool[] approvals,uint64 configNumber,bool switchToGivenConfig,uint256 nonce,uint256 deadline)');

    bytes32 constant COLLECT_LEGACY = keccak256('CollectLegacy(uint256 publicationCollectedProfileId,uint256 publicationCollectedId,uint256 collectorProfileId,uint256 referrerProfileId,uint256 referrerPubId,bytes collectModuleData,uint256 nonce,uint256 deadline)');

    bytes32 constant COMMENT = keccak256('Comment(uint256 profileId,string contentURI,uint256 pointedProfileId,uint256 pointedPubId,uint256[] referrerProfileIds,uint256[] referrerPubIds,bytes referenceModuleData,address[] actionModules,bytes[] actionModulesInitDatas,address referenceModule,bytes referenceModuleInitData,uint256 nonce,uint256 deadline)');

    bytes32 constant EIP712_DOMAIN = keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)');

    bytes32 constant FOLLOW = keccak256('Follow(uint256 followerProfileId,uint256[] idsOfProfilesToFollow,uint256[] followTokenIds,bytes[] datas,uint256 nonce,uint256 deadline)');

    bytes32 constant MIRROR = keccak256('Mirror(uint256 profileId,string metadataURI,uint256 pointedProfileId,uint256 pointedPubId,uint256[] referrerProfileIds,uint256[] referrerPubIds,bytes referenceModuleData,uint256 nonce,uint256 deadline)');

    bytes32 constant POST = keccak256('Post(uint256 profileId,string contentURI,address[] actionModules,bytes[] actionModulesInitDatas,address referenceModule,bytes referenceModuleInitData,uint256 nonce,uint256 deadline)');

    bytes32 constant QUOTE = keccak256('Quote(uint256 profileId,string contentURI,uint256 pointedProfileId,uint256 pointedPubId,uint256[] referrerProfileIds,uint256[] referrerPubIds,bytes referenceModuleData,address[] actionModules,bytes[] actionModulesInitDatas,address referenceModule,bytes referenceModuleInitData,uint256 nonce,uint256 deadline)');

    bytes32 constant SET_BLOCK_STATUS = keccak256('SetBlockStatus(uint256 byProfileId,uint256[] idsOfProfilesToSetBlockStatus,bool[] blockStatus,uint256 nonce,uint256 deadline)');

    bytes32 constant SET_FOLLOW_MODULE = keccak256('SetFollowModule(uint256 profileId,address followModule,bytes followModuleInitData,uint256 nonce,uint256 deadline)');

    bytes32 constant SET_PROFILE_METADATA_URI = keccak256('SetProfileMetadataURI(uint256 profileId,string metadataURI,uint256 nonce,uint256 deadline)');

    bytes32 constant UNFOLLOW = keccak256('Unfollow(uint256 unfollowerProfileId,uint256[] idsOfProfilesToUnfollow,uint256 nonce,uint256 deadline)');
}

File 23 of 33 : Types.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0;

/**
 * @title Types
 * @author Lens Protocol
 *
 * @notice A standard library of data types used throughout the Lens Protocol.
 */
library Types {
    /**
     * @notice ERC721Timestamped storage. Contains the owner address and the mint timestamp for every NFT.
     *
     * Note: Instead of the owner address in the _tokenOwners private mapping, we now store it in the
     * _tokenData mapping, alongside the mint timestamp.
     *
     * @param owner The token owner.
     * @param mintTimestamp The mint timestamp.
     */
    struct TokenData {
        address owner;
        uint96 mintTimestamp;
    }

    /**
     * @notice A struct containing token follow-related data.
     *
     * @param followerProfileId The ID of the profile using the token to follow.
     * @param originalFollowTimestamp The timestamp of the first follow performed with the token.
     * @param followTimestamp The timestamp of the current follow, if a profile is using the token to follow.
     * @param profileIdAllowedToRecover The ID of the profile allowed to recover the follow ID, if any.
     */
    struct FollowData {
        uint160 followerProfileId;
        uint48 originalFollowTimestamp;
        uint48 followTimestamp;
        uint256 profileIdAllowedToRecover;
    }

    /**
     * @notice An enum containing the different states the protocol can be in, limiting certain actions.
     *
     * @param Unpaused The fully unpaused state.
     * @param PublishingPaused The state where only publication creation functions are paused.
     * @param Paused The fully paused state.
     */
    enum ProtocolState {
        Unpaused,
        PublishingPaused,
        Paused
    }

    /**
     * @notice An enum specifically used in a helper function to easily retrieve the publication type for integrations.
     *
     * @param Nonexistent An indicator showing the queried publication does not exist.
     * @param Post A standard post, having an URI, action modules and no pointer to another publication.
     * @param Comment A comment, having an URI, action modules and a pointer to another publication.
     * @param Mirror A mirror, having a pointer to another publication, but no URI or action modules.
     * @param Quote A quote, having an URI, action modules, and a pointer to another publication.
     */
    enum PublicationType {
        Nonexistent,
        Post,
        Comment,
        Mirror,
        Quote
    }

    /**
     * @notice A struct containing the necessary information to reconstruct an EIP-712 typed data signature.
     *
     * @param signer The address of the signer. Specially needed as a parameter to support EIP-1271.
     * @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 {
        address signer;
        uint8 v;
        bytes32 r;
        bytes32 s;
        uint256 deadline;
    }

    /**
     * @notice A struct containing profile data.
     *
     * @param pubCount The number of publications made to this profile.
     * @param followModule The address of the current follow module in use by this profile, can be address(0) in none.
     * @param followNFT The address of the followNFT associated with this profile. It can be address(0) if the
     * profile has not been followed yet, as the collection is lazy-deployed upon the first follow.
     * @param __DEPRECATED__handle DEPRECATED in V2: handle slot, was replaced with LensHandles.
     * @param __DEPRECATED__imageURI DEPRECATED in V2: The URI to be used for the profile image.
     * @param __DEPRECATED__followNFTURI DEPRECATED in V2: The URI used for the follow NFT image.
     * @param metadataURI MetadataURI is used to store the profile's metadata, for example: displayed name, description,
     * interests, etc.
     */
    struct Profile {
        uint256 pubCount; // offset 0
        address followModule; // offset 1
        address followNFT; // offset 2
        string __DEPRECATED__handle; // offset 3
        string __DEPRECATED__imageURI; // offset 4
        string __DEPRECATED__followNFTURI; // Deprecated in V2 as we have a common tokenURI for all Follows, offset 5
        string metadataURI; // offset 6
    }

    /**
     * @notice A struct containing publication data.
     *
     * @param pointedProfileId The profile token ID to point the publication to.
     * @param pointedPubId The publication ID to point the publication to.
     * These are used to implement the "reference" feature of the platform and is used in:
     * - Mirrors
     * - Comments
     * - Quotes
     * There are (0,0) if the publication is not pointing to any other publication (i.e. the publication is a Post).
     * @param contentURI The URI to set for the content of publication (can be ipfs, arweave, http, etc).
     * @param referenceModule Reference module associated with this profile, if any.
     * @param __DEPRECATED__collectModule Collect module associated with this publication, if any. Deprecated in V2.
     * @param __DEPRECATED__collectNFT Collect NFT associated with this publication, if any. Deprecated in V2.
     * @param pubType The type of publication, can be Nonexistent, Post, Comment, Mirror or Quote.
     * @param rootProfileId The profile ID of the root post (to determine if comments/quotes and mirrors come from it).
     * Posts, V1 publications and publications rooted in V1 publications don't have it set.
     * @param rootPubId The publication ID of the root post (to determine if comments/quotes and mirrors come from it).
     * Posts, V1 publications and publications rooted in V1 publications don't have it set.
     * @param actionModuleEnabled The action modules enabled in a given publication.
     */
    struct Publication {
        uint256 pointedProfileId;
        uint256 pointedPubId;
        string contentURI;
        address referenceModule;
        address __DEPRECATED__collectModule; // Deprecated in V2
        address __DEPRECATED__collectNFT; // Deprecated in V2
        // Added in Lens V2, so these will be zero for old publications:
        PublicationType pubType;
        uint256 rootProfileId;
        uint256 rootPubId;
        mapping(address => bool) actionModuleEnabled;
    }

    struct PublicationMemory {
        uint256 pointedProfileId;
        uint256 pointedPubId;
        string contentURI;
        address referenceModule;
        address __DEPRECATED__collectModule; // Deprecated in V2
        address __DEPRECATED__collectNFT; // Deprecated in V2
        // Added in Lens V2, so these will be zero for old publications:
        PublicationType pubType;
        uint256 rootProfileId;
        uint256 rootPubId;
        // bytes32 __ACTION_MODULE_ENABLED_MAPPING; // Mappings are not supported in memory.
    }

    /**
     * @notice A struct containing the parameters required for the `createProfile()` function.
     *
     * @param to The address receiving the profile.
     * @param followModule The follow module to use, can be the zero address.
     * @param followModuleInitData The follow module initialization data, if any.
     */
    struct CreateProfileParams {
        address to;
        address followModule;
        bytes followModuleInitData;
    }

    /**
     * @notice A struct containing the parameters required for the `post()` function.
     *
     * @param profileId The token ID of the profile to publish to.
     * @param contentURI The URI to set for this new publication.
     * @param actionModules The action modules to set for this new publication.
     * @param actionModulesInitDatas The data to pass to the action modules' initialization.
     * @param referenceModule The reference module to set for the given publication, must be whitelisted.
     * @param referenceModuleInitData The data to be passed to the reference module for initialization.
     */
    struct PostParams {
        uint256 profileId;
        string contentURI;
        address[] actionModules;
        bytes[] actionModulesInitDatas;
        address referenceModule;
        bytes referenceModuleInitData;
    }

    /**
     * @notice A struct containing the parameters required for the `comment()` function.
     *
     * @param profileId The token ID of the profile to publish to.
     * @param contentURI The URI to set for this new publication.
     * @param pointedProfileId The profile token ID to point the comment to.
     * @param pointedPubId The publication ID to point the comment to.
     * @param referrerProfileId The profile token ID of the publication that referred to the publication being commented on/quoted.
     * @param referrerPubId The ID of the publication that referred to the publication being commented on/quoted.
     * @param referenceModuleData The data passed to the reference module.
     * @param actionModules The action modules to set for this new publication.
     * @param actionModulesInitDatas The data to pass to the action modules' initialization.
     * @param referenceModule The reference module to set for the given publication, must be whitelisted.
     * @param referenceModuleInitData The data to be passed to the reference module for initialization.
     */
    struct CommentParams {
        uint256 profileId;
        string contentURI;
        uint256 pointedProfileId;
        uint256 pointedPubId;
        uint256[] referrerProfileIds;
        uint256[] referrerPubIds;
        bytes referenceModuleData;
        address[] actionModules;
        bytes[] actionModulesInitDatas;
        address referenceModule;
        bytes referenceModuleInitData;
    }

    /**
     * @notice A struct containing the parameters required for the `quote()` function.
     *
     * @param profileId The token ID of the profile to publish to.
     * @param contentURI The URI to set for this new publication.
     * @param pointedProfileId The profile token ID of the publication author that is quoted.
     * @param pointedPubId The publication ID that is quoted.
     * @param referrerProfileId The profile token ID of the publication that referred to the publication being commented on/quoted.
     * @param referrerPubId The ID of the publication that referred to the publication being commented on/quoted.
     * @param referenceModuleData The data passed to the reference module.
     * @param actionModules The action modules to set for this new publication.
     * @param actionModulesInitDatas The data to pass to the action modules' initialization.
     * @param referenceModule The reference module to set for the given publication, must be whitelisted.
     * @param referenceModuleInitData The data to be passed to the reference module for initialization.
     */
    struct QuoteParams {
        uint256 profileId;
        string contentURI;
        uint256 pointedProfileId;
        uint256 pointedPubId;
        uint256[] referrerProfileIds;
        uint256[] referrerPubIds;
        bytes referenceModuleData;
        address[] actionModules;
        bytes[] actionModulesInitDatas;
        address referenceModule;
        bytes referenceModuleInitData;
    }

    /**
     * @notice A struct containing the parameters required for the `comment()` or `quote()` internal functions.
     *
     * @param profileId The token ID of the profile to publish to.
     * @param contentURI The URI to set for this new publication.
     * @param pointedProfileId The profile token ID of the publication author that is commented on/quoted.
     * @param pointedPubId The publication ID that is commented on/quoted.
     * @param referrerProfileId The profile token ID of the publication that referred to the publication being commented on/quoted.
     * @param referrerPubId The ID of the publication that referred to the publication being commented on/quoted.
     * @param referenceModuleData The data passed to the reference module.
     * @param actionModules The action modules to set for this new publication.
     * @param actionModulesInitDatas The data to pass to the action modules' initialization.
     * @param referenceModule The reference module to set for the given publication, must be whitelisted.
     * @param referenceModuleInitData The data to be passed to the reference module for initialization.
     */
    struct ReferencePubParams {
        uint256 profileId;
        string contentURI;
        uint256 pointedProfileId;
        uint256 pointedPubId;
        uint256[] referrerProfileIds;
        uint256[] referrerPubIds;
        bytes referenceModuleData;
        address[] actionModules;
        bytes[] actionModulesInitDatas;
        address referenceModule;
        bytes referenceModuleInitData;
    }

    /**
     * @notice A struct containing the parameters required for the `mirror()` function.
     *
     * @param profileId The token ID of the profile to publish to.
     * @param metadataURI the URI containing metadata attributes to attach to this mirror publication.
     * @param pointedProfileId The profile token ID to point the mirror to.
     * @param pointedPubId The publication ID to point the mirror to.
     * @param referenceModuleData The data passed to the reference module.
     */
    struct MirrorParams {
        uint256 profileId;
        string metadataURI;
        uint256 pointedProfileId;
        uint256 pointedPubId;
        uint256[] referrerProfileIds;
        uint256[] referrerPubIds;
        bytes referenceModuleData;
    }

    /**
     * Deprecated in V2: Will be removed after some time after upgrading to V2.
     * @notice A struct containing the parameters required for the legacy `collect()` function.
     * @dev The referrer can only be a mirror of the publication being collected.
     *
     * @param publicationCollectedProfileId The token ID of the profile that published the publication to collect.
     * @param publicationCollectedId The publication to collect's publication ID.
     * @param collectorProfileId The collector profile.
     * @param referrerProfileId The ID of a profile that authored a mirror that helped discovering the collected pub.
     * @param referrerPubId The ID of the mirror that helped discovering the collected pub.
     * @param collectModuleData The arbitrary data to pass to the collectModule if needed.
     */
    struct LegacyCollectParams {
        uint256 publicationCollectedProfileId;
        uint256 publicationCollectedId;
        uint256 collectorProfileId;
        uint256 referrerProfileId;
        uint256 referrerPubId;
        bytes collectModuleData;
    }

    /**
     * @notice A struct containing the parameters required for the `action()` function.
     *
     * @param publicationActedProfileId The token ID of the profile that published the publication to action.
     * @param publicationActedId The publication to action's publication ID.
     * @param actorProfileId The actor profile.
     * @param referrerProfileId
     * @param referrerPubId
     * @param actionModuleAddress
     * @param actionModuleData The arbitrary data to pass to the actionModule if needed.
     */
    struct PublicationActionParams {
        uint256 publicationActedProfileId;
        uint256 publicationActedId;
        uint256 actorProfileId;
        uint256[] referrerProfileIds;
        uint256[] referrerPubIds;
        address actionModuleAddress;
        bytes actionModuleData;
    }

    struct ProcessActionParams {
        uint256 publicationActedProfileId;
        uint256 publicationActedId;
        uint256 actorProfileId;
        address actorProfileOwner;
        address transactionExecutor;
        uint256[] referrerProfileIds;
        uint256[] referrerPubIds;
        Types.PublicationType[] referrerPubTypes;
        bytes actionModuleData;
    }

    struct ProcessCommentParams {
        uint256 profileId;
        uint256 pubId;
        address transactionExecutor;
        uint256 pointedProfileId;
        uint256 pointedPubId;
        uint256[] referrerProfileIds;
        uint256[] referrerPubIds;
        Types.PublicationType[] referrerPubTypes;
        bytes data;
    }

    struct ProcessQuoteParams {
        uint256 profileId;
        uint256 pubId;
        address transactionExecutor;
        uint256 pointedProfileId;
        uint256 pointedPubId;
        uint256[] referrerProfileIds;
        uint256[] referrerPubIds;
        Types.PublicationType[] referrerPubTypes;
        bytes data;
    }

    struct ProcessMirrorParams {
        uint256 profileId;
        uint256 pubId;
        address transactionExecutor;
        uint256 pointedProfileId;
        uint256 pointedPubId;
        uint256[] referrerProfileIds;
        uint256[] referrerPubIds;
        Types.PublicationType[] referrerPubTypes;
        bytes data;
    }

    /**
     * @notice A struct containing a profile's delegated executors configuration.
     *
     * @param isApproved Tells when an address is approved as delegated executor in the given configuration number.
     * @param configNumber Current configuration number in use.
     * @param prevConfigNumber Previous configuration number set, before switching to the current one.
     * @param maxConfigNumberSet Maximum configuration number ever used.
     */
    struct DelegatedExecutorsConfig {
        mapping(uint256 => mapping(address => bool)) isApproved; // isApproved[configNumber][delegatedExecutor]
        uint64 configNumber;
        uint64 prevConfigNumber;
        uint64 maxConfigNumberSet;
    }

    struct TreasuryData {
        address treasury;
        uint16 treasuryFeeBPS;
    }

    struct MigrationParams {
        address lensHandlesAddress;
        address tokenHandleRegistryAddress;
        address legacyFeeFollowModule;
        address legacyProfileFollowModule;
        address newFeeFollowModule;
    }
}

File 24 of 33 : IERC1271.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC1271.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC1271 standard signature validation method for
 * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].
 *
 * _Available since v4.1._
 */
interface IERC1271 {
    /**
     * @dev Should return whether the signature provided is valid for the provided data
     * @param hash      Hash of the data to be signed
     * @param signature Signature byte array associated with _data
     */
    function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}

File 25 of 33 : IERC2981.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (interfaces/IERC2981.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev Interface for the NFT Royalty Standard.
 *
 * A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal
 * support for royalty payments across all NFT marketplaces and ecosystem participants.
 *
 * _Available since v4.5._
 */
interface IERC2981 is IERC165 {
    /**
     * @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of
     * exchange. The royalty amount is denominated and should be paid in that same unit of exchange.
     */
    function royaltyInfo(uint256 tokenId, uint256 salePrice)
        external
        view
        returns (address receiver, uint256 royaltyAmount);
}

File 26 of 33 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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);
}

File 27 of 33 : 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);
}

File 28 of 33 : 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);
}

File 29 of 33 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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
     * ====
     *
     * [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://diligence.consensys.net/posts/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.5.11/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);
        }
    }
}

File 30 of 33 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/Math.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 `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);
    }
}

File 31 of 33 : 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;
    }
}

File 32 of 33 : 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);
}

File 33 of 33 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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) {
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1);

            ///////////////////////////////////////////////
            // 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 10, 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 * 8) < value ? 1 : 0);
        }
    }
}

Settings
{
  "remappings": [
    "@ensdomains/=node_modules/@ensdomains/",
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "@seadrop/=lib/seadrop/src/",
    "ERC721A-Upgradeable/=lib/seadrop/lib/ERC721A-Upgradeable/contracts/",
    "ERC721A/=lib/seadrop/lib/ERC721A/contracts/",
    "create2-helpers/=lib/seadrop/lib/create2-helpers/",
    "create2-scripts/=lib/seadrop/lib/create2-helpers/script/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/seadrop/lib/operator-filter-registry/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "eth-gas-reporter/=node_modules/eth-gas-reporter/",
    "forge-std/=lib/forge-std/src/",
    "hardhat/=node_modules/hardhat/",
    "murky/=lib/seadrop/lib/murky/src/",
    "openzeppelin-contracts-upgradeable/=lib/seadrop/lib/openzeppelin-contracts-upgradeable/contracts/",
    "openzeppelin-contracts/=lib/seadrop/lib/openzeppelin-contracts/contracts/",
    "operator-filter-registry/=lib/seadrop/lib/operator-filter-registry/src/",
    "seadrop/=lib/seadrop/",
    "solady/=lib/solady/src/",
    "solmate/=lib/seadrop/lib/solmate/src/",
    "utility-contracts/=lib/seadrop/lib/utility-contracts/src/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 10
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "paris",
  "viaIR": true,
  "libraries": {
    "contracts/libraries/ActionLib.sol": {
      "ActionLib": "0x7990dac84e3241fe314b980bba1466ac08715c4f"
    },
    "contracts/libraries/FollowLib.sol": {
      "FollowLib": "0xe280cb21fb36b6b2d584428b809a6b822a5c2260"
    },
    "contracts/libraries/LegacyCollectLib.sol": {
      "LegacyCollectLib": "0x5f0f24377c00f1517b4de496cf49eec8beb4ecb4"
    },
    "contracts/libraries/MetaTxLib.sol": {
      "MetaTxLib": "0xf191c489e4ba0f448ea08a5fd27e9c928643f5c7"
    },
    "contracts/libraries/MigrationLib.sol": {
      "MigrationLib": "0x0deced9ac3833b687d69d4eac6655f0f1279acee"
    },
    "contracts/libraries/ProfileLib.sol": {
      "ProfileLib": "0x3fce2475a92c185f9634f5638f6b33306d77bb10"
    },
    "contracts/libraries/PublicationLib.sol": {
      "PublicationLib": "0x90654f24a2c164a4da8f763ac8bc032d3d083a1b"
    },
    "contracts/libraries/ValidationLib.sol": {
      "ValidationLib": "0x9cafd24d2851d9eb56e5a8fd394ab2ac0ef99849"
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"hub","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyFollowing","type":"error"},{"inputs":[],"name":"AlreadyWrapped","type":"error"},{"inputs":[],"name":"DoesNotHavePermissions","type":"error"},{"inputs":[],"name":"FollowTokenDoesNotExist","type":"error"},{"inputs":[],"name":"Initialized","type":"error"},{"inputs":[],"name":"InvalidOwner","type":"error"},{"inputs":[],"name":"InvalidParameter","type":"error"},{"inputs":[],"name":"NonERC721ReceiverImplementer","type":"error"},{"inputs":[],"name":"NotFollowing","type":"error"},{"inputs":[],"name":"NotHub","type":"error"},{"inputs":[],"name":"NotOwnerOrApproved","type":"error"},{"inputs":[],"name":"NotProfileOwner","type":"error"},{"inputs":[],"name":"OnlyWrappedFollowTokens","type":"error"},{"inputs":[],"name":"Paused","type":"error"},{"inputs":[],"name":"TokenDoesNotExist","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"followerProfileId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"followTokenId","type":"uint256"}],"name":"FollowApproval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"HUB","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"followerProfileId","type":"uint256"},{"internalType":"uint256","name":"followTokenId","type":"uint256"}],"name":"approveFollow","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"followTokenId","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"exists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"followerProfileId","type":"uint256"},{"internalType":"address","name":"transactionExecutor","type":"address"},{"internalType":"uint256","name":"followTokenId","type":"uint256"}],"name":"follow","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getDomainSeparator","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"followTokenId","type":"uint256"}],"name":"getFollowApproved","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"followTokenId","type":"uint256"}],"name":"getFollowData","outputs":[{"components":[{"internalType":"uint160","name":"followerProfileId","type":"uint160"},{"internalType":"uint48","name":"originalFollowTimestamp","type":"uint48"},{"internalType":"uint48","name":"followTimestamp","type":"uint48"},{"internalType":"uint256","name":"profileIdAllowedToRecover","type":"uint256"}],"internalType":"struct Types.FollowData","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"followTokenId","type":"uint256"}],"name":"getFollowTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"followerProfileId","type":"uint256"}],"name":"getFollowTokenId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getFollowerCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"followTokenId","type":"uint256"}],"name":"getFollowerProfileId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"followTokenId","type":"uint256"}],"name":"getOriginalFollowTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"followTokenId","type":"uint256"}],"name":"getProfileIdAllowedToRecover","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"profileId","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"followerProfileId","type":"uint256"}],"name":"isFollowing","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"mintTimestampOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"signer","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"followerProfileId","type":"uint256"}],"name":"processBlock","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"followTokenId","type":"uint256"}],"name":"removeFollower","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"salePrice","type":"uint256"}],"name":"royaltyInfo","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"royaltiesInBasisPoints","type":"uint256"}],"name":"setRoyalty","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenDataOf","outputs":[{"components":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint96","name":"mintTimestamp","type":"uint96"}],"internalType":"struct Types.TokenData","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"followTokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"followerProfileId","type":"uint256"},{"internalType":"address","name":"followerProfileOwner","type":"address"},{"internalType":"uint256","name":"followTokenId","type":"uint256"}],"name":"tryMigrate","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"unfollowerProfileId","type":"uint256"}],"name":"unfollow","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"followTokenId","type":"uint256"}],"name":"unwrap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"followTokenId","type":"uint256"},{"internalType":"address","name":"wrappedTokenReceiver","type":"address"}],"name":"wrap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"followTokenId","type":"uint256"}],"name":"wrap","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60a03461011357601f62002c7638819003918201601f19168301916001600160401b038311848410176101185780849260209460405283398101031261011357516001600160a01b038116810361011357608052600160ff196012541617601255604051612b4790816200012f82396080518181816102d50152818161049f0152818161077a0152818161095a01528181610a4801528181610ad101528181610d0701528181610d6401528181610e430152818161105801528181611287015281816114990152818161158a015281816118b4015281816119cd01528181611b5a01528181611c3801528181611d1601528181611e9d0152818161213801528181612374015281816124a3015261259d0152f35b600080fd5b634e487b7160e01b600052604160045260246000fdfe6080604052600436101561001257600080fd5b60003560e01c806301998534146102b757806301ffc9a7146102b257806304aadff8146102ad57806306fdde03146102a8578063081812fc146102a3578063095ea7b31461029e57806311c763d61461029957806313bac8201461029457806318160ddd1461028f57806323b872dd1461028a5780632a55205a146102855780632af1544f146102805780633543a2771461027b5780634209a2e11461027657806342842e0e1461027157806342966c681461026c5780634cd32a4b146102675780634d71688d146102625780634f558e791461025d57806350ddf35c146102585780635cc65452146102535780636352211e1461024e57806370a0823114610249578063725971471461024457806373629dbc1461023f5780637829ae4a1461023a5780637ecebe00146102355780638448876214610230578063886a65c31461022b57806395d89b4114610226578063a22cb46514610221578063a4c52b861461021c578063b88d4fde14610217578063c0da9bcd14610212578063c87b56dd1461020d578063d1b3493414610208578063d6cbec5d14610203578063de0e9a3e146101fe578063e985e9c5146101f9578063ea598cb0146101f4578063ed24911d146101ef5763fe4b84df146101ea57600080fd5b611618565b6115fd565b611564565b61150c565b611473565b6113b3565b61137c565b611245565b6111b4565b611124565b611042565b610fb1565b610f4b565b610f17565b610e04565b610dc7565b610da6565b610d51565b610cf4565b610c94565b610c76565b610c4a565b610c02565b610bda565b610bac565b610abb565b610a22565b6109e2565b610921565b6108f2565b6108c3565b61085f565b610838565b6107ee565b610748565b61071c565b610674565b610633565b6105a2565b610479565b610384565b3461036d57602036600319011261036d576001600160a01b036004357f00000000000000000000000000000000000000000000000000000000000000008216330361035b576000918183526014602052604083205490811561034957818452600260205260408420541661032b8284611f16565b15610334578280f35b82526013602052600160408320015538808280f35b6040516322d9eef360e21b8152600490fd5b6040516313bd2e8360e31b8152600490fd5b600080fd5b6001600160e01b031981160361036d57565b3461036d57602036600319011261036d576103f56004356103a481610372565b63ffffffff60e01b166380ac58cd60e01b8114908115610468575b8115610457575b8115610446575b8115610435575b8115610424575b81156103f9575b5060405190151581529081906020820190565b0390f35b63152a902d60e11b811491508115610413575b50386103e2565b6301ffc9a760e01b1490503861040c565b6301ffc9a760e01b811491506103db565b635b5e139f60e01b811491506103d4565b6393ea2f1d60e01b811491506103cd565b630852cd8d60e31b811491506103c6565b63c744eb3560e01b811491506103bf565b3461036d57602036600319011261036d57604051631865c57d60e01b81526020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa801561053657600291600091610508575b506104e48161180d565b146104f6576104f460043561182d565b005b6040516313d0ff5960e31b8152600490fd5b610529915060203d811161052f575b61052181836110e6565b8101906117e9565b386104da565b503d610517565b611801565b600091031261036d57565b60005b8381106105595750506000910152565b8181015183820152602001610549565b9060209161058281518092818552858086019101610546565b601f01601f1916010190565b90602061059f928181520190610569565b90565b3461036d57600036600319011261036d576106136105c1601054612974565b61061f6040516105d08161109d565b600981526020928184809301906816a337b63637bbb2b960b91b825260405196836106048995518092888089019101610546565b84019151809386840190610546565b010380855201836110e6565b6103f5604051928284938452830190610569565b3461036d57602036600319011261036d57602061065160043561223c565b6040516001600160a01b039091168152f35b6001600160a01b0381160361036d57565b3461036d57604036600319011261036d5760043561069181610663565b6024356001600160a01b03806106a68361221b565b16809184161461070a578033141590816106db575b506106c9576104f4916126a6565b604051636d8a29e760e11b8152600490fd5b905060005260056020526107046107006106f9336040600020612204565b5460ff1690565b1590565b386106bb565b604051630309cb8760e51b8152600490fd5b3461036d57602036600319011261036d5760043560005260146020526020604060002054604051908152f35b3461036d57604036600319011261036d5760243561076581610663565b604051631865c57d60e01b81526020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa8015610536576002916000916107d0575b506107bf8161180d565b146104f6576104f49060043561185e565b6107e8915060203d811161052f5761052181836110e6565b386107b5565b3461036d57600036600319011261036d576020600854604051908152f35b606090600319011261036d5760043561082481610663565b9060243561083181610663565b9060443590565b3461036d576108463661080c565b9061085182336122d9565b156106c9576104f49261255b565b3461036d57604036600319011261036d5760243561087b612113565b601654918281029281840414901517156108ad57604080516001600160a01b0390921682526127109092046020820152f35b634e487b7160e01b600052601160045260246000fd5b3461036d57602036600319011261036d5760043560005260136020526020600160406000200154604051908152f35b3461036d57602036600319011261036d576004356000526013602052602060406000205460d01c604051908152f35b3461036d57602036600319011261036d576010546040516331a9108f60e11b815260048101919091526001600160a01b036020826024817f000000000000000000000000000000000000000000000000000000000000000085165afa918215610536576000926109b2575b50339116036109a0576104f46004356121dc565b60405163f194fae560e01b8152600490fd5b6109d491925060203d81116109db575b6109cc81836110e6565b810190611969565b903861098c565b503d6109c2565b3461036d576109f03661080c565b60405160208101939092906001600160401b03851184861017610a1d576104f49460405260008452612265565b611087565b3461036d57602036600319011261036d57604051631865c57d60e01b81526020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa801561053657600291600091610a9d575b50610a8d8161180d565b146104f6576104f4600435611a86565b610ab5915060203d811161052f5761052181836110e6565b38610a83565b3461036d57602036600319011261036d576004357f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03163381900361035b57600091610b0d8161165e565b549182610b22575b6040518415158152602090f35b610b2e610700846122bc565b610b4a575b50610b3e9250611f16565b60016103f53880610b15565b6040516331a9108f60e11b81526004810183905290602090829060249082905afa93841561053657610b3e94610b8892859291610b8e575b50612342565b38610b33565b610ba6915060203d81116109db576109cc81836110e6565b38610b82565b3461036d57602036600319011261036d57600435600052601460205260206040600020541515604051908152f35b3461036d57602036600319011261036d576020610bf86004356122bc565b6040519015158152f35b3461036d57602036600319011261036d57600435600052600260205260406000205460a01c8015610c3857602090604051908152f35b60405163677510db60e11b8152600490fd5b3461036d57602036600319011261036d5760043560005260156020526020604060002054604051908152f35b3461036d57602036600319011261036d57602061065160043561221b565b3461036d57602036600319011261036d57600435610cb181610663565b6001600160a01b0316801561070a5760005260036020526020604060002054604051908152f35b606090600319011261036d576004359060243561083181610663565b3461036d57610d0236610cd8565b9091907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316330361035b57602092610d4192611fef565b65ffffffffffff60405191168152f35b3461036d57610d5f36610cd8565b9091907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316330361035b57602092610d9e9261168e565b604051908152f35b3461036d57600036600319011261036d57602060115460801c604051908152f35b3461036d57602036600319011261036d57600435610de481610663565b60018060a01b0316600052600a6020526020604060002054604051908152f35b3461036d57604036600319011261036d57604051634f558e7960e01b8152600480359082018190529060248035916001600160a01b03916020908290817f000000000000000000000000000000000000000000000000000000000000000086165afa90811561053657600091610ee9575b5015610c38578115159081610ec6575b50610eb457610e9481336122d9565b15610ea2576104f491611fa5565b604051633f3c311960e01b8152600490fd5b60405163f614ad0560e01b8152600490fd5b9050610ee1610ed48361166e565b546001600160a01b031690565b161538610e85565b610f0a915060203d8111610f10575b610f0281836110e6565b810190611849565b38610e75565b503d610ef8565b3461036d57602036600319011261036d576004356000526013602052602060018060a01b0360406000205416604051908152f35b3461036d57600036600319011261036d57610613610f6a601054612974565b61061f604051610f798161109d565b60038152602092818480930190620b519b60ea1b825260405196836106048995518092888089019101610546565b8015150361036d57565b3461036d57604036600319011261036d57600435610fce81610663565b602435610fda81610fa7565b6001600160a01b0382169133831461070a57611003903360005260056020526040600020612204565b9015159060ff1981541660ff83161790556040519081527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3160203392a3005b3461036d57600036600319011261036d576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b634e487b7160e01b600052604160045260246000fd5b604081019081106001600160401b03821117610a1d57604052565b608081019081106001600160401b03821117610a1d57604052565b6001600160401b038111610a1d57604052565b601f909101601f19168101906001600160401b03821190821017610a1d57604052565b6001600160401b038111610a1d57601f01601f191660200190565b3461036d57608036600319011261036d5760043561114181610663565b60243561114d81610663565b606435916001600160401b03831161036d573660238401121561036d5782600401359161117983611109565b9261118760405194856110e6565b808452366024828701011161036d5760208160009260246104f49801838801378501015260443591612265565b3461036d57602036600319011261036d57600435600060206040516111d88161109d565b82815201526111e6816122bc565b15610c385760005260026020526103f56040600020604051906112088261109d565b546001600160a01b03811680835260a09190911c60209283019081526040805192835290516001600160601b031692820192909252918291820190565b3461036d57602036600319011261036d57600435611265610700826122bc565b610c385760405163c2907cdb60e01b81526001600160a01b03916020826004817f000000000000000000000000000000000000000000000000000000000000000087165afa80156105365761131793600093849261135c575b50601054906112de6112cf8561167e565b5460a01c65ffffffffffff1690565b93604051968795869485936308d63d7960e31b85526004850191604091949365ffffffffffff9160608501968552602085015216910152565b0392165afa8015610536576103f59160009161133b575b506040519182918261058e565b611356913d8091833e61134e81836110e6565b810190611a99565b3861132e565b61137591925060203d81116109db576109cc81836110e6565b90386112be565b3461036d57602036600319011261036d576004356000526013602052602065ffffffffffff60406000205460a01c16604051908152f35b3461036d57602036600319011261036d576103f5604080606081516113d7816110b8565b6000918183809352826020820152828582015201526004358152601360205220906001815192611406846110b8565b8054828060a01b038116855265ffffffffffff8160a01c16602086015260d01c83850152015460608301525191829182919091606080608083019460018060a01b038151168452602081015165ffffffffffff809116602086015260408201511660408501520151910152565b3461036d57602036600319011261036d57604051631865c57d60e01b81526020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa8015610536576002916000916114ee575b506114de8161180d565b146104f6576104f4600435611a60565b611506915060203d811161052f5761052181836110e6565b386114d4565b3461036d57604036600319011261036d57602060ff61155860043561153081610663565b6024359061153d82610663565b6001600160a01b031660009081526005855260409020612204565b54166040519015158152f35b3461036d57602036600319011261036d57604051631865c57d60e01b81526020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa8015610536576002916000916115df575b506115cf8161180d565b146104f6576104f460043561197e565b6115f7915060203d811161052f5761052181836110e6565b386115c5565b3461036d57600036600319011261036d576020610d9e612839565b3461036d57602036600319011261036d5760125460ff811661164c5760ff19166001176012556004356010556103e8601655005b6040516302ed543d60e51b8152600490fd5b6000526014602052604060002090565b6000526002602052604060002090565b6000526013602052604060002090565b91906116998361165e565b546117d75781156116fc576001600160a01b036116b8610ed48461166e565b166116f3576116d86116cc610ed48461167e565b6001600160a01b031690565b806116e857505061059f91611c9f565b909161059f93611c16565b61059f92611b1c565b505061175c6011549161173160018060801b036001818181881601168096828060801b031916178060115560801c0116611af7565b8060005260146020528260406000205582600052601360205260018060a01b03166040600020611dbe565b61059f65ffffffffffff4216611798816117758561167e565b80546001600160d01b031660d09290921b6001600160d01b031916919091179055565b600060016117a58561167e565b01556117b08361167e565b805465ffffffffffff60a01b191660a09290921b65ffffffffffff60a01b16919091179055565b60405163118c13c960e21b8152600490fd5b9081602091031261036d5751600381101561036d5790565b6040513d6000823e3d90fd5b6003111561181757565b634e487b7160e01b600052602160045260246000fd5b61183781336122d9565b15610ea257611847903390611e65565b565b9081602091031261036d575161059f81610fa7565b6001600160a01b038281161561070a57611877826122bc565b6119575761188a6116cc610ed48461167e565b8015611914575b6040516331a9108f60e11b8152600481019190915260208180602481015b0381857f0000000000000000000000000000000000000000000000000000000000000000165afa908115610536576000916118f6575b50163303610ea25761184791612342565b61190e915060203d81116109db576109cc81836110e6565b386118e5565b5060016119208361167e565b015480156119455760206118af916000600161193b8761167e565b0155915050611891565b604051631543d12360e01b8152600490fd5b6040516304f78f7d60e41b8152600490fd5b9081602091031261036d575161059f81610663565b611987816122bc565b6119575761199a6116cc610ed48361167e565b8015611a30575b6040516331a9108f60e11b81526004810191909152906001600160a01b0360208380602481015b0381847f0000000000000000000000000000000000000000000000000000000000000000165afa92831561053657600093611a10575b5082163303610ea25761184791612342565b611a2991935060203d81116109db576109cc81836110e6565b91386119fe565b506001611a3c8261167e565b0154908115611945576119c89160006001611a568461167e565b01559091506119a1565b6000818152601360205260409020546001600160a01b03161561034957611847906122a4565b61184790611a943382611e65565b6122a4565b60208183031261036d578051906001600160401b03821161036d570181601f8201121561036d578051611acb81611109565b92611ad960405194856110e6565b8184526020828401011161036d5761059f9160208085019101610546565b601180546001600160801b031660809290921b6001600160801b031916919091179055565b9081611b32846000526015602052604060002090565b546040516331a9108f60e11b8152600481018590529114906020816024816001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165afa90811561053657600091611bf8575b508482159182611be2575b505080611bcf575b610ea25761059f928491611bc1575b611bbc6116cc610ed48461167e565b611cfe565b611bca82611f81565b611bad565b50611bdd61070085846122d9565b611b9e565b611bf1925090610700916122d9565b8438611b96565b611c10915060203d81116109db576109cc81836110e6565b38611b8b565b604051634f558e7960e01b8152600481018490529193909290916020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa90811561053657600091611c81575b50610ea25761059f928491611cfe565b611c99915060203d8111610f1057610f0281836110e6565b38611c71565b81600052601360205280600160406000200154036119455760115461059f918391611cd89060801c6001016001600160801b0316611af7565b611ddd565b90815260208101919091526001600160a01b03909116604082015260600190565b8015611d9d576000611d0f8261165e565b55601054937f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316803b1561036d57611d6a956000809460405198899586948593630a2adbed60e21b855260048501611cdd565b03925af19283156105365761184793611d84575b50611ddd565b80611d91611d97926110d3565b8061053b565b38611d7e565b506011546118479350611cd89060801c6001016001600160801b0316611af7565b80546001600160a01b0319166001600160a01b03909216919091179055565b611e0c908060005260146020528260406000205582600052601360205260018060a01b03166040600020611dbe565b65ffffffffffff90611e238242166117758361167e565b60006001611e308361167e565b015581611e3c8261167e565b5460a01c1615611e4a575050565b6117b061184792611e5a8361166e565b5460a01c169161167e565b6000818152601360205260408120546001600160a01b039081169493919285611e91575b505050509050565b611e9b9086611f16565b7f000000000000000000000000000000000000000000000000000000000000000016601054813b15611f125783611eea959660405196879586948593630a2adbed60e21b855260048501611cdd565b03925af1801561053657611f03575b8080808493611e89565b611f0c906110d3565b38611ef9565b8380fd5b6011549091600191611f7d9190611f3c9060801c600019016001600160801b0316611af7565b60009384526014602052836040812055808452601360205260408420838060a01b03198154169055611f6d8161167e565b838060d01b03815416905561167e565b0155565b60008181526015602052806040812055600080516020612ab28339815191528180a3565b81600052601560205280604060002055600080516020612ab2833981519152600080a3565b90604051611fd78161109d565b91546001600160a01b038116835260a01c6020830152565b909165ffffffffffff6120046112cf8361167e565b1661210b576120128261165e565b5461210b576120286120238261166e565b611fca565b80516001600160a01b0394919391908516908115612100578516036120f75760206120b09361209861059f966120ea9461207e61207961206a60115460801c90565b6001016001600160801b031690565b611af7565b866120888261165e565b55166120938661167e565b611dbe565b0180519092906120c4906120bb906001600160601b03165b65ffffffffffff1690565b6117b08361167e565b82516120e5906120dc906001600160601b03166120b0565b6117758361167e565b61247c565b516001600160601b031690565b50505050600090565b505050505050600090565b505050600090565b601054604051634f558e7960e01b815260048101829052602091906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016908381602481855afa908115610536576000916121bf575b501561210b576040516331a9108f60e11b815260048101929092528290829060249082905afa918215610536576000926121a957505090565b61059f9250803d106109db576109cc81836110e6565b6121d69150843d8611610f1057610f0281836110e6565b38612170565b612710811161070a57601655565b6001600160a01b0316600090815260036020526040902090565b9060018060a01b0316600052602052604060002090565b6000908152600260205260409020546001600160a01b03168015610c385790565b612245816122bc565b15610c38576000908152600460205260409020546001600160a01b031690565b92919061227282336122d9565b156106c95783612286838361228b9761255b565b61275e565b1561229257565b6040516342eac10f60e11b8152600490fd5b6122ae81336122d9565b156106c9576118479061247c565b6000908152600260205260409020546001600160a01b0316151590565b6001600160a01b03806122eb8461221b565b16908083169082821494851561232a575b505050821561230a57505090565b60ff9250906123259160005260056020526040600020612204565b541690565b612337919293955061223c565b1614913880806122fc565b6001600160a01b03818116919082158015612454575b61070a57602060049160405192838092631865c57d60e01b82527f0000000000000000000000000000000000000000000000000000000000000000165afa801561053657600291600091612436575b506123b18161180d565b146104f657806123c36123e7926121ea565b805460010190556123de6123d960085460010190565b600855565b6120938461166e565b612420426001600160601b03166123fd8461166e565b80546001600160a01b031660a09290921b6001600160a01b031916919091179055565b6000600080516020612ad28339815191528180a4565b61244e915060203d811161052f5761052181836110e6565b386123a7565b5061245e846122bc565b612358565b6001600160a01b03166124735750565b61184790611f81565b6124858161221b565b604051631865c57d60e01b81526001600160a01b03906020816004817f000000000000000000000000000000000000000000000000000000000000000086165afa80156105365760029160009161253d575b506124e18161180d565b146104f657816124f384600094612463565b6124fc84612664565b612505816121ea565b805460001901905560085461251d9060001901600855565b826125278561166e565b5516600080516020612ad28339815191528280a4565b612555915060203d811161052f5761052181836110e6565b386124d7565b6125648361221b565b6001600160a01b0392838316929184168390036126525783811693841561070a57602060049160405192838092631865c57d60e01b82527f0000000000000000000000000000000000000000000000000000000000000000165afa801561053657600291600091612634575b506125da8161180d565b146104f6576125fe826125f08761261f95612463565b6125f987612664565b6121ea565b805460001901905561260f816121ea565b805460010190556120938561166e565b600080516020612ad2833981519152600080a4565b61264c915060203d811161052f5761052181836110e6565b386125d0565b6040516349e27cff60e01b8152600490fd5b600081815260046020526040812080546001600160a01b03191690556001600160a01b036126918361221b565b16600080516020612af28339815191528280a4565b8160005260046020526126bd816040600020611dbe565b6001600160a01b03806126cf8461221b565b16911690600080516020612af2833981519152600080a4565b9081602091031261036d575161059f81610372565b6001600160a01b03918216815291166020820152604081019190915260806060820181905261059f92910190610569565b3d15612759573d9061273f82611109565b9161274d60405193846110e6565b82523d6000602084013e565b606090565b92909190823b1561281157612791926020926000604051809681958294630a85bd0160e11b9a8b855233600486016126fd565b03926001600160a01b03165af1600091816127e1575b506127d3576127b461272e565b805190816127ce576040516342eac10f60e11b8152600490fd5b602001fd5b6001600160e01b0319161490565b61280391925060203d811161280a575b6127fb81836110e6565b8101906126e8565b90386127a7565b503d6127f1565b50505050600190565b6001602060405161282a8161109d565b82815201601960f91b81522090565b73db46d1dc155634fbc732f92e853b10b288ad5a1d301480612938575b612914576040516306fdde0360e01b8152600081600481305afa908115610536576000916128fb575b50602081519101206128e76128f561289561281a565b604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f602082019081529181019590955260608501919091524660808501523060a08501529291829060c0820190565b03601f1981018352826110e6565b51902090565b61290e913d8091833e61134e81836110e6565b3861287f565b7fbf9544cf7d7a0338fc4f071be35409a61e51e9caef559305410ad74e16a05f2d90565b5060894614612856565b9061294c82611109565b61295960405191826110e6565b828152809261296a601f1991611109565b0190602036910137565b6000908072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b80821015612aa3575b506904ee2d6d415b85acef8160201b80831015612a94575b50662386f26fc1000080831015612a85575b506305f5e10080831015612a76575b5061271080831015612a67575b506064821015612a57575b600a80921015612a4d575b600190816021612a05828701612942565b95860101905b612a17575b5050505090565b600019019083906f181899199a1a9b1b9c1cb0b131b232b360811b8282061a835304918215612a4857919082612a0b565b612a10565b91600101916129f4565b91906064600291049101916129e9565b600491939204910191386129de565b600891939204910191386129d1565b601091939204910191386129c2565b602091939204910191386129b0565b60409350810491503861299856febc450b46d588f82a774d661cdc80374e8fe147267030d1c81796a3e3df3579b2ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a26469706673582212201d1d96f04e953a548825277d3ae5f1e1cf3b9034e467ba6cd4a53381d0a4009664736f6c63430008150033000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d

Deployed Bytecode

0x6080604052600436101561001257600080fd5b60003560e01c806301998534146102b757806301ffc9a7146102b257806304aadff8146102ad57806306fdde03146102a8578063081812fc146102a3578063095ea7b31461029e57806311c763d61461029957806313bac8201461029457806318160ddd1461028f57806323b872dd1461028a5780632a55205a146102855780632af1544f146102805780633543a2771461027b5780634209a2e11461027657806342842e0e1461027157806342966c681461026c5780634cd32a4b146102675780634d71688d146102625780634f558e791461025d57806350ddf35c146102585780635cc65452146102535780636352211e1461024e57806370a0823114610249578063725971471461024457806373629dbc1461023f5780637829ae4a1461023a5780637ecebe00146102355780638448876214610230578063886a65c31461022b57806395d89b4114610226578063a22cb46514610221578063a4c52b861461021c578063b88d4fde14610217578063c0da9bcd14610212578063c87b56dd1461020d578063d1b3493414610208578063d6cbec5d14610203578063de0e9a3e146101fe578063e985e9c5146101f9578063ea598cb0146101f4578063ed24911d146101ef5763fe4b84df146101ea57600080fd5b611618565b6115fd565b611564565b61150c565b611473565b6113b3565b61137c565b611245565b6111b4565b611124565b611042565b610fb1565b610f4b565b610f17565b610e04565b610dc7565b610da6565b610d51565b610cf4565b610c94565b610c76565b610c4a565b610c02565b610bda565b610bac565b610abb565b610a22565b6109e2565b610921565b6108f2565b6108c3565b61085f565b610838565b6107ee565b610748565b61071c565b610674565b610633565b6105a2565b610479565b610384565b3461036d57602036600319011261036d576001600160a01b036004357f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d8216330361035b576000918183526014602052604083205490811561034957818452600260205260408420541661032b8284611f16565b15610334578280f35b82526013602052600160408320015538808280f35b6040516322d9eef360e21b8152600490fd5b6040516313bd2e8360e31b8152600490fd5b600080fd5b6001600160e01b031981160361036d57565b3461036d57602036600319011261036d576103f56004356103a481610372565b63ffffffff60e01b166380ac58cd60e01b8114908115610468575b8115610457575b8115610446575b8115610435575b8115610424575b81156103f9575b5060405190151581529081906020820190565b0390f35b63152a902d60e11b811491508115610413575b50386103e2565b6301ffc9a760e01b1490503861040c565b6301ffc9a760e01b811491506103db565b635b5e139f60e01b811491506103d4565b6393ea2f1d60e01b811491506103cd565b630852cd8d60e31b811491506103c6565b63c744eb3560e01b811491506103bf565b3461036d57602036600319011261036d57604051631865c57d60e01b81526020816004817f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d6001600160a01b03165afa801561053657600291600091610508575b506104e48161180d565b146104f6576104f460043561182d565b005b6040516313d0ff5960e31b8152600490fd5b610529915060203d811161052f575b61052181836110e6565b8101906117e9565b386104da565b503d610517565b611801565b600091031261036d57565b60005b8381106105595750506000910152565b8181015183820152602001610549565b9060209161058281518092818552858086019101610546565b601f01601f1916010190565b90602061059f928181520190610569565b90565b3461036d57600036600319011261036d576106136105c1601054612974565b61061f6040516105d08161109d565b600981526020928184809301906816a337b63637bbb2b960b91b825260405196836106048995518092888089019101610546565b84019151809386840190610546565b010380855201836110e6565b6103f5604051928284938452830190610569565b3461036d57602036600319011261036d57602061065160043561223c565b6040516001600160a01b039091168152f35b6001600160a01b0381160361036d57565b3461036d57604036600319011261036d5760043561069181610663565b6024356001600160a01b03806106a68361221b565b16809184161461070a578033141590816106db575b506106c9576104f4916126a6565b604051636d8a29e760e11b8152600490fd5b905060005260056020526107046107006106f9336040600020612204565b5460ff1690565b1590565b386106bb565b604051630309cb8760e51b8152600490fd5b3461036d57602036600319011261036d5760043560005260146020526020604060002054604051908152f35b3461036d57604036600319011261036d5760243561076581610663565b604051631865c57d60e01b81526020816004817f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d6001600160a01b03165afa8015610536576002916000916107d0575b506107bf8161180d565b146104f6576104f49060043561185e565b6107e8915060203d811161052f5761052181836110e6565b386107b5565b3461036d57600036600319011261036d576020600854604051908152f35b606090600319011261036d5760043561082481610663565b9060243561083181610663565b9060443590565b3461036d576108463661080c565b9061085182336122d9565b156106c9576104f49261255b565b3461036d57604036600319011261036d5760243561087b612113565b601654918281029281840414901517156108ad57604080516001600160a01b0390921682526127109092046020820152f35b634e487b7160e01b600052601160045260246000fd5b3461036d57602036600319011261036d5760043560005260136020526020600160406000200154604051908152f35b3461036d57602036600319011261036d576004356000526013602052602060406000205460d01c604051908152f35b3461036d57602036600319011261036d576010546040516331a9108f60e11b815260048101919091526001600160a01b036020826024817f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d85165afa918215610536576000926109b2575b50339116036109a0576104f46004356121dc565b60405163f194fae560e01b8152600490fd5b6109d491925060203d81116109db575b6109cc81836110e6565b810190611969565b903861098c565b503d6109c2565b3461036d576109f03661080c565b60405160208101939092906001600160401b03851184861017610a1d576104f49460405260008452612265565b611087565b3461036d57602036600319011261036d57604051631865c57d60e01b81526020816004817f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d6001600160a01b03165afa801561053657600291600091610a9d575b50610a8d8161180d565b146104f6576104f4600435611a86565b610ab5915060203d811161052f5761052181836110e6565b38610a83565b3461036d57602036600319011261036d576004357f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d6001600160a01b03163381900361035b57600091610b0d8161165e565b549182610b22575b6040518415158152602090f35b610b2e610700846122bc565b610b4a575b50610b3e9250611f16565b60016103f53880610b15565b6040516331a9108f60e11b81526004810183905290602090829060249082905afa93841561053657610b3e94610b8892859291610b8e575b50612342565b38610b33565b610ba6915060203d81116109db576109cc81836110e6565b38610b82565b3461036d57602036600319011261036d57600435600052601460205260206040600020541515604051908152f35b3461036d57602036600319011261036d576020610bf86004356122bc565b6040519015158152f35b3461036d57602036600319011261036d57600435600052600260205260406000205460a01c8015610c3857602090604051908152f35b60405163677510db60e11b8152600490fd5b3461036d57602036600319011261036d5760043560005260156020526020604060002054604051908152f35b3461036d57602036600319011261036d57602061065160043561221b565b3461036d57602036600319011261036d57600435610cb181610663565b6001600160a01b0316801561070a5760005260036020526020604060002054604051908152f35b606090600319011261036d576004359060243561083181610663565b3461036d57610d0236610cd8565b9091907f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d6001600160a01b0316330361035b57602092610d4192611fef565b65ffffffffffff60405191168152f35b3461036d57610d5f36610cd8565b9091907f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d6001600160a01b0316330361035b57602092610d9e9261168e565b604051908152f35b3461036d57600036600319011261036d57602060115460801c604051908152f35b3461036d57602036600319011261036d57600435610de481610663565b60018060a01b0316600052600a6020526020604060002054604051908152f35b3461036d57604036600319011261036d57604051634f558e7960e01b8152600480359082018190529060248035916001600160a01b03916020908290817f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d86165afa90811561053657600091610ee9575b5015610c38578115159081610ec6575b50610eb457610e9481336122d9565b15610ea2576104f491611fa5565b604051633f3c311960e01b8152600490fd5b60405163f614ad0560e01b8152600490fd5b9050610ee1610ed48361166e565b546001600160a01b031690565b161538610e85565b610f0a915060203d8111610f10575b610f0281836110e6565b810190611849565b38610e75565b503d610ef8565b3461036d57602036600319011261036d576004356000526013602052602060018060a01b0360406000205416604051908152f35b3461036d57600036600319011261036d57610613610f6a601054612974565b61061f604051610f798161109d565b60038152602092818480930190620b519b60ea1b825260405196836106048995518092888089019101610546565b8015150361036d57565b3461036d57604036600319011261036d57600435610fce81610663565b602435610fda81610fa7565b6001600160a01b0382169133831461070a57611003903360005260056020526040600020612204565b9015159060ff1981541660ff83161790556040519081527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3160203392a3005b3461036d57600036600319011261036d576040517f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d6001600160a01b03168152602090f35b634e487b7160e01b600052604160045260246000fd5b604081019081106001600160401b03821117610a1d57604052565b608081019081106001600160401b03821117610a1d57604052565b6001600160401b038111610a1d57604052565b601f909101601f19168101906001600160401b03821190821017610a1d57604052565b6001600160401b038111610a1d57601f01601f191660200190565b3461036d57608036600319011261036d5760043561114181610663565b60243561114d81610663565b606435916001600160401b03831161036d573660238401121561036d5782600401359161117983611109565b9261118760405194856110e6565b808452366024828701011161036d5760208160009260246104f49801838801378501015260443591612265565b3461036d57602036600319011261036d57600435600060206040516111d88161109d565b82815201526111e6816122bc565b15610c385760005260026020526103f56040600020604051906112088261109d565b546001600160a01b03811680835260a09190911c60209283019081526040805192835290516001600160601b031692820192909252918291820190565b3461036d57602036600319011261036d57600435611265610700826122bc565b610c385760405163c2907cdb60e01b81526001600160a01b03916020826004817f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d87165afa80156105365761131793600093849261135c575b50601054906112de6112cf8561167e565b5460a01c65ffffffffffff1690565b93604051968795869485936308d63d7960e31b85526004850191604091949365ffffffffffff9160608501968552602085015216910152565b0392165afa8015610536576103f59160009161133b575b506040519182918261058e565b611356913d8091833e61134e81836110e6565b810190611a99565b3861132e565b61137591925060203d81116109db576109cc81836110e6565b90386112be565b3461036d57602036600319011261036d576004356000526013602052602065ffffffffffff60406000205460a01c16604051908152f35b3461036d57602036600319011261036d576103f5604080606081516113d7816110b8565b6000918183809352826020820152828582015201526004358152601360205220906001815192611406846110b8565b8054828060a01b038116855265ffffffffffff8160a01c16602086015260d01c83850152015460608301525191829182919091606080608083019460018060a01b038151168452602081015165ffffffffffff809116602086015260408201511660408501520151910152565b3461036d57602036600319011261036d57604051631865c57d60e01b81526020816004817f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d6001600160a01b03165afa8015610536576002916000916114ee575b506114de8161180d565b146104f6576104f4600435611a60565b611506915060203d811161052f5761052181836110e6565b386114d4565b3461036d57604036600319011261036d57602060ff61155860043561153081610663565b6024359061153d82610663565b6001600160a01b031660009081526005855260409020612204565b54166040519015158152f35b3461036d57602036600319011261036d57604051631865c57d60e01b81526020816004817f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d6001600160a01b03165afa8015610536576002916000916115df575b506115cf8161180d565b146104f6576104f460043561197e565b6115f7915060203d811161052f5761052181836110e6565b386115c5565b3461036d57600036600319011261036d576020610d9e612839565b3461036d57602036600319011261036d5760125460ff811661164c5760ff19166001176012556004356010556103e8601655005b6040516302ed543d60e51b8152600490fd5b6000526014602052604060002090565b6000526002602052604060002090565b6000526013602052604060002090565b91906116998361165e565b546117d75781156116fc576001600160a01b036116b8610ed48461166e565b166116f3576116d86116cc610ed48461167e565b6001600160a01b031690565b806116e857505061059f91611c9f565b909161059f93611c16565b61059f92611b1c565b505061175c6011549161173160018060801b036001818181881601168096828060801b031916178060115560801c0116611af7565b8060005260146020528260406000205582600052601360205260018060a01b03166040600020611dbe565b61059f65ffffffffffff4216611798816117758561167e565b80546001600160d01b031660d09290921b6001600160d01b031916919091179055565b600060016117a58561167e565b01556117b08361167e565b805465ffffffffffff60a01b191660a09290921b65ffffffffffff60a01b16919091179055565b60405163118c13c960e21b8152600490fd5b9081602091031261036d5751600381101561036d5790565b6040513d6000823e3d90fd5b6003111561181757565b634e487b7160e01b600052602160045260246000fd5b61183781336122d9565b15610ea257611847903390611e65565b565b9081602091031261036d575161059f81610fa7565b6001600160a01b038281161561070a57611877826122bc565b6119575761188a6116cc610ed48461167e565b8015611914575b6040516331a9108f60e11b8152600481019190915260208180602481015b0381857f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d165afa908115610536576000916118f6575b50163303610ea25761184791612342565b61190e915060203d81116109db576109cc81836110e6565b386118e5565b5060016119208361167e565b015480156119455760206118af916000600161193b8761167e565b0155915050611891565b604051631543d12360e01b8152600490fd5b6040516304f78f7d60e41b8152600490fd5b9081602091031261036d575161059f81610663565b611987816122bc565b6119575761199a6116cc610ed48361167e565b8015611a30575b6040516331a9108f60e11b81526004810191909152906001600160a01b0360208380602481015b0381847f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d165afa92831561053657600093611a10575b5082163303610ea25761184791612342565b611a2991935060203d81116109db576109cc81836110e6565b91386119fe565b506001611a3c8261167e565b0154908115611945576119c89160006001611a568461167e565b01559091506119a1565b6000818152601360205260409020546001600160a01b03161561034957611847906122a4565b61184790611a943382611e65565b6122a4565b60208183031261036d578051906001600160401b03821161036d570181601f8201121561036d578051611acb81611109565b92611ad960405194856110e6565b8184526020828401011161036d5761059f9160208085019101610546565b601180546001600160801b031660809290921b6001600160801b031916919091179055565b9081611b32846000526015602052604060002090565b546040516331a9108f60e11b8152600481018590529114906020816024816001600160a01b037f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d165afa90811561053657600091611bf8575b508482159182611be2575b505080611bcf575b610ea25761059f928491611bc1575b611bbc6116cc610ed48461167e565b611cfe565b611bca82611f81565b611bad565b50611bdd61070085846122d9565b611b9e565b611bf1925090610700916122d9565b8438611b96565b611c10915060203d81116109db576109cc81836110e6565b38611b8b565b604051634f558e7960e01b8152600481018490529193909290916020816024817f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d6001600160a01b03165afa90811561053657600091611c81575b50610ea25761059f928491611cfe565b611c99915060203d8111610f1057610f0281836110e6565b38611c71565b81600052601360205280600160406000200154036119455760115461059f918391611cd89060801c6001016001600160801b0316611af7565b611ddd565b90815260208101919091526001600160a01b03909116604082015260600190565b8015611d9d576000611d0f8261165e565b55601054937f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d6001600160a01b0316803b1561036d57611d6a956000809460405198899586948593630a2adbed60e21b855260048501611cdd565b03925af19283156105365761184793611d84575b50611ddd565b80611d91611d97926110d3565b8061053b565b38611d7e565b506011546118479350611cd89060801c6001016001600160801b0316611af7565b80546001600160a01b0319166001600160a01b03909216919091179055565b611e0c908060005260146020528260406000205582600052601360205260018060a01b03166040600020611dbe565b65ffffffffffff90611e238242166117758361167e565b60006001611e308361167e565b015581611e3c8261167e565b5460a01c1615611e4a575050565b6117b061184792611e5a8361166e565b5460a01c169161167e565b6000818152601360205260408120546001600160a01b039081169493919285611e91575b505050509050565b611e9b9086611f16565b7f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d16601054813b15611f125783611eea959660405196879586948593630a2adbed60e21b855260048501611cdd565b03925af1801561053657611f03575b8080808493611e89565b611f0c906110d3565b38611ef9565b8380fd5b6011549091600191611f7d9190611f3c9060801c600019016001600160801b0316611af7565b60009384526014602052836040812055808452601360205260408420838060a01b03198154169055611f6d8161167e565b838060d01b03815416905561167e565b0155565b60008181526015602052806040812055600080516020612ab28339815191528180a3565b81600052601560205280604060002055600080516020612ab2833981519152600080a3565b90604051611fd78161109d565b91546001600160a01b038116835260a01c6020830152565b909165ffffffffffff6120046112cf8361167e565b1661210b576120128261165e565b5461210b576120286120238261166e565b611fca565b80516001600160a01b0394919391908516908115612100578516036120f75760206120b09361209861059f966120ea9461207e61207961206a60115460801c90565b6001016001600160801b031690565b611af7565b866120888261165e565b55166120938661167e565b611dbe565b0180519092906120c4906120bb906001600160601b03165b65ffffffffffff1690565b6117b08361167e565b82516120e5906120dc906001600160601b03166120b0565b6117758361167e565b61247c565b516001600160601b031690565b50505050600090565b505050505050600090565b505050600090565b601054604051634f558e7960e01b815260048101829052602091906001600160a01b037f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d16908381602481855afa908115610536576000916121bf575b501561210b576040516331a9108f60e11b815260048101929092528290829060249082905afa918215610536576000926121a957505090565b61059f9250803d106109db576109cc81836110e6565b6121d69150843d8611610f1057610f0281836110e6565b38612170565b612710811161070a57601655565b6001600160a01b0316600090815260036020526040902090565b9060018060a01b0316600052602052604060002090565b6000908152600260205260409020546001600160a01b03168015610c385790565b612245816122bc565b15610c38576000908152600460205260409020546001600160a01b031690565b92919061227282336122d9565b156106c95783612286838361228b9761255b565b61275e565b1561229257565b6040516342eac10f60e11b8152600490fd5b6122ae81336122d9565b156106c9576118479061247c565b6000908152600260205260409020546001600160a01b0316151590565b6001600160a01b03806122eb8461221b565b16908083169082821494851561232a575b505050821561230a57505090565b60ff9250906123259160005260056020526040600020612204565b541690565b612337919293955061223c565b1614913880806122fc565b6001600160a01b03818116919082158015612454575b61070a57602060049160405192838092631865c57d60e01b82527f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d165afa801561053657600291600091612436575b506123b18161180d565b146104f657806123c36123e7926121ea565b805460010190556123de6123d960085460010190565b600855565b6120938461166e565b612420426001600160601b03166123fd8461166e565b80546001600160a01b031660a09290921b6001600160a01b031916919091179055565b6000600080516020612ad28339815191528180a4565b61244e915060203d811161052f5761052181836110e6565b386123a7565b5061245e846122bc565b612358565b6001600160a01b03166124735750565b61184790611f81565b6124858161221b565b604051631865c57d60e01b81526001600160a01b03906020816004817f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d86165afa80156105365760029160009161253d575b506124e18161180d565b146104f657816124f384600094612463565b6124fc84612664565b612505816121ea565b805460001901905560085461251d9060001901600855565b826125278561166e565b5516600080516020612ad28339815191528280a4565b612555915060203d811161052f5761052181836110e6565b386124d7565b6125648361221b565b6001600160a01b0392838316929184168390036126525783811693841561070a57602060049160405192838092631865c57d60e01b82527f000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d165afa801561053657600291600091612634575b506125da8161180d565b146104f6576125fe826125f08761261f95612463565b6125f987612664565b6121ea565b805460001901905561260f816121ea565b805460010190556120938561166e565b600080516020612ad2833981519152600080a4565b61264c915060203d811161052f5761052181836110e6565b386125d0565b6040516349e27cff60e01b8152600490fd5b600081815260046020526040812080546001600160a01b03191690556001600160a01b036126918361221b565b16600080516020612af28339815191528280a4565b8160005260046020526126bd816040600020611dbe565b6001600160a01b03806126cf8461221b565b16911690600080516020612af2833981519152600080a4565b9081602091031261036d575161059f81610372565b6001600160a01b03918216815291166020820152604081019190915260806060820181905261059f92910190610569565b3d15612759573d9061273f82611109565b9161274d60405193846110e6565b82523d6000602084013e565b606090565b92909190823b1561281157612791926020926000604051809681958294630a85bd0160e11b9a8b855233600486016126fd565b03926001600160a01b03165af1600091816127e1575b506127d3576127b461272e565b805190816127ce576040516342eac10f60e11b8152600490fd5b602001fd5b6001600160e01b0319161490565b61280391925060203d811161280a575b6127fb81836110e6565b8101906126e8565b90386127a7565b503d6127f1565b50505050600190565b6001602060405161282a8161109d565b82815201601960f91b81522090565b73db46d1dc155634fbc732f92e853b10b288ad5a1d301480612938575b612914576040516306fdde0360e01b8152600081600481305afa908115610536576000916128fb575b50602081519101206128e76128f561289561281a565b604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f602082019081529181019590955260608501919091524660808501523060a08501529291829060c0820190565b03601f1981018352826110e6565b51902090565b61290e913d8091833e61134e81836110e6565b3861287f565b7fbf9544cf7d7a0338fc4f071be35409a61e51e9caef559305410ad74e16a05f2d90565b5060894614612856565b9061294c82611109565b61295960405191826110e6565b828152809261296a601f1991611109565b0190602036910137565b6000908072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b80821015612aa3575b506904ee2d6d415b85acef8160201b80831015612a94575b50662386f26fc1000080831015612a85575b506305f5e10080831015612a76575b5061271080831015612a67575b506064821015612a57575b600a80921015612a4d575b600190816021612a05828701612942565b95860101905b612a17575b5050505090565b600019019083906f181899199a1a9b1b9c1cb0b131b232b360811b8282061a835304918215612a4857919082612a0b565b612a10565b91600101916129f4565b91906064600291049101916129e9565b600491939204910191386129de565b600891939204910191386129d1565b601091939204910191386129c2565b602091939204910191386129b0565b60409350810491503861299856febc450b46d588f82a774d661cdc80374e8fe147267030d1c81796a3e3df3579b2ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a26469706673582212201d1d96f04e953a548825277d3ae5f1e1cf3b9034e467ba6cd4a53381d0a4009664736f6c63430008150033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d

-----Decoded View---------------
Arg [0] : hub (address): 0xDb46d1Dc155634FbC732f92E853b10B288AD5a1d

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000db46d1dc155634fbc732f92e853b10b288ad5a1d


Block Transaction Gas Used Reward
view all blocks produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.