diff --git a/contracts/core/FollowNFT.sol b/contracts/core/FollowNFT.sol index 38e36d0..505f3a8 100644 --- a/contracts/core/FollowNFT.sol +++ b/contracts/core/FollowNFT.sol @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.15; +pragma solidity 0.8.15; import {IFollowNFT} from '../interfaces/IFollowNFT.sol'; import {IFollowModule} from '../interfaces/IFollowModule.sol'; @@ -10,7 +10,7 @@ import {Errors} from '../libraries/Errors.sol'; import {Events} from '../libraries/Events.sol'; import {DataTypes} from '../libraries/DataTypes.sol'; import {LensNFTBase} from './base/LensNFTBase.sol'; -import {ModuleBase} from './modules/ModuleBase.sol'; +import {HubRestricted} from './base/HubRestricted.sol'; import {IERC721} from '@openzeppelin/contracts/token/ERC721/IERC721.sol'; import {ERC721Time} from './base/ERC721Time.sol'; import '../libraries/Constants.sol'; @@ -35,7 +35,7 @@ struct FollowData { uint96 followTimestamp; } -contract FollowNFT is ModuleBase, LensNFTBase, IFollowNFT { +contract FollowNFT is HubRestricted, LensNFTBase, IFollowNFT { bytes32 internal constant DELEGATE_BY_SIG_TYPEHASH = keccak256( 'DelegateBySig(address delegator,address delegatee,uint256 nonce,uint256 deadline)' @@ -57,7 +57,7 @@ contract FollowNFT is ModuleBase, LensNFTBase, IFollowNFT { mapping(uint256 => uint256) internal _approvedToFollowByFollowerId; mapping(uint256 => address) internal _approvedToSetFollowerByFollowId; - constructor(address hub) ModuleBase(hub) { + constructor(address hub) HubRestricted(hub) { _initialized = true; } @@ -534,7 +534,7 @@ contract FollowNFT is ModuleBase, LensNFTBase, IFollowNFT { } function _delegate(address delegator, address delegatee) internal { - uint256 delegatorBalance = balanceOf(delegator); + uint256 delegatorBalance = balanceOf(delegator); // TODO: This is only getting the wrapped tokens balance address previousDelegate = _delegates[delegator]; _delegates[delegator] = delegatee; _moveDelegate(previousDelegate, delegatee, delegatorBalance); diff --git a/contracts/core/base/HubRestricted.sol b/contracts/core/base/HubRestricted.sol new file mode 100644 index 0000000..df10884 --- /dev/null +++ b/contracts/core/base/HubRestricted.sol @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.15; + +import {Errors} from '../../libraries/Errors.sol'; +import {Events} from '../../libraries/Events.sol'; + +/** + * @title HubRestricted + * @author Lens Protocol + * + * @notice This abstract contract adds a public `HUB` immutable field, validations when setting it, 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) { + if (hub == address(0)) { + revert Errors.InitParamsInvalid(); + } + HUB = hub; + } +} diff --git a/contracts/core/modules/ModuleBase.sol b/contracts/core/modules/ModuleBase.sol index 9bbbd74..e0e9757 100644 --- a/contracts/core/modules/ModuleBase.sol +++ b/contracts/core/modules/ModuleBase.sol @@ -4,25 +4,17 @@ pragma solidity 0.8.15; import {Errors} from '../../libraries/Errors.sol'; import {Events} from '../../libraries/Events.sol'; +import {HubRestricted} from '../base/HubRestricted.sol'; /** * @title ModuleBase * @author Lens Protocol * - * @notice This abstract contract adds a public `HUB` immutable to inheriting modules, as well as an - * `onlyHub` modifier. + * @notice This contract fires an event at construction, to be inherited by other modules, in addition to the + * HubRestricted contract features. */ -abstract contract ModuleBase { - address public immutable HUB; - - modifier onlyHub() { - if (msg.sender != HUB) revert Errors.NotHub(); - _; - } - - constructor(address hub) { - if (hub == address(0)) revert Errors.InitParamsInvalid(); - HUB = hub; +abstract contract ModuleBase is HubRestricted { + constructor(address hub) HubRestricted(hub) { emit Events.ModuleBaseConstructed(hub, block.timestamp); } }