From aca7f4b9f996ea57a9dae12ea0e9ac436813c105 Mon Sep 17 00:00:00 2001 From: Charles Crain Date: Wed, 18 Oct 2023 13:35:21 -0400 Subject: [PATCH] chore: break out lazy sovereign into own factory --- .../LazySovereignNFTFactoryDeploy.s.sol | 19 ++++ .../sovereign/SovereignNFTContractFactory.sol | 48 +------- .../sovereign/{ => lazy}/LazySovereignNFT.sol | 4 +- .../lazy/LazySovereignNFTContractFactory.sol | 107 ++++++++++++++++++ .../LazySovereignNFTRoyaltyGuard.sol | 0 ...SovereignNFTRoyaltyGuardDeadmanTrigger.sol | 0 6 files changed, 130 insertions(+), 48 deletions(-) create mode 100644 scripts/token/sovereign/LazySovereignNFTFactoryDeploy.s.sol rename src/token/ERC721/sovereign/{ => lazy}/LazySovereignNFT.sol (99%) create mode 100644 src/token/ERC721/sovereign/lazy/LazySovereignNFTContractFactory.sol rename src/token/ERC721/sovereign/{ => lazy}/extensions/LazySovereignNFTRoyaltyGuard.sol (100%) rename src/token/ERC721/sovereign/{ => lazy}/extensions/LazySovereignNFTRoyaltyGuardDeadmanTrigger.sol (100%) diff --git a/scripts/token/sovereign/LazySovereignNFTFactoryDeploy.s.sol b/scripts/token/sovereign/LazySovereignNFTFactoryDeploy.s.sol new file mode 100644 index 0000000..8644cc2 --- /dev/null +++ b/scripts/token/sovereign/LazySovereignNFTFactoryDeploy.s.sol @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import "forge-std/Script.sol"; + +import "../../../src/token/ERC721/sovereign/lazy/LazySovereignNFTContractFactory.sol"; + +contract LazySovereignNFTContractFactoryDeploy is Script { + function run() external { + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + + vm.startBroadcast(deployerPrivateKey); + + // Deploy Logic Contracts + new LazySovereignNFTContractFactory(); + + vm.stopBroadcast(); + } +} diff --git a/src/token/ERC721/sovereign/SovereignNFTContractFactory.sol b/src/token/ERC721/sovereign/SovereignNFTContractFactory.sol index dc345d8..da933a7 100644 --- a/src/token/ERC721/sovereign/SovereignNFTContractFactory.sol +++ b/src/token/ERC721/sovereign/SovereignNFTContractFactory.sol @@ -7,9 +7,6 @@ import "openzeppelin-contracts/proxy/Clones.sol"; import "./SovereignNFT.sol"; import "./extensions/SovereignNFTRoyaltyGuard.sol"; import "./extensions/SovereignNFTRoyaltyGuardDeadmanTrigger.sol"; -import "./LazySovereignNFT.sol"; -import "./extensions/LazySovereignNFTRoyaltyGuard.sol"; -import "./extensions/LazySovereignNFTRoyaltyGuardDeadmanTrigger.sol"; contract SovereignNFTContractFactory is Ownable { @@ -47,15 +44,6 @@ contract SovereignNFTContractFactory is Ownable { SovereignNFTRoyaltyGuardDeadmanTrigger sovNFTRGDT = new SovereignNFTRoyaltyGuardDeadmanTrigger(); sovereignNFTRoyaltyGuardDeadmanTrigger = address(sovNFTRGDT); - - LazySovereignNFT lsovNFT = new LazySovereignNFT(); - lazySovereignNFT = address(lsovNFT); - - LazySovereignNFTRoyaltyGuard lsovNFTRG = new LazySovereignNFTRoyaltyGuard(); - lazySovereignNFTRoyaltyGuard = address(lsovNFTRG); - - LazySovereignNFTRoyaltyGuardDeadmanTrigger lsovNFTRGDT = new LazySovereignNFTRoyaltyGuardDeadmanTrigger(); - lazySovereignNFTRoyaltyGuardDeadmanTrigger = address(lsovNFTRGDT); } function setSovereignNFT(address _sovereignNFT) external onlyOwner { @@ -80,18 +68,7 @@ contract SovereignNFTContractFactory is Ownable { sovereignNFTRoyaltyGuardDeadmanTrigger = _sovereignNFT; return; } - if (_contractType == LAZY_SOVEREIGN_NFT) { - lazySovereignNFT = _sovereignNFT; - return; - } - if (_contractType == LAZY_ROYALTY_GUARD) { - lazySovereignNFTRoyaltyGuard = _sovereignNFT; - return; - } - if (_contractType == LAZY_ROYALTY_GUARD_DEADMAN) { - lazySovereignNFTRoyaltyGuardDeadmanTrigger = _sovereignNFT; - return; - } + require(false, "setSovereignNFT::Unsupported _contractType."); } @@ -164,28 +141,7 @@ contract SovereignNFTContractFactory is Ownable { _maxTokens ); } - if (_contractType == LAZY_SOVEREIGN_NFT) { - sovAddr = Clones.clone(lazySovereignNFT); - LazySovereignNFT(sovAddr).init(_name, _symbol, msg.sender, _maxTokens); - } - if (_contractType == LAZY_ROYALTY_GUARD) { - sovAddr = Clones.clone(lazySovereignNFTRoyaltyGuard); - LazySovereignNFTRoyaltyGuard(sovAddr).init( - _name, - _symbol, - msg.sender, - _maxTokens - ); - } - if (_contractType == LAZY_ROYALTY_GUARD_DEADMAN) { - sovAddr = Clones.clone(lazySovereignNFTRoyaltyGuardDeadmanTrigger); - LazySovereignNFTRoyaltyGuardDeadmanTrigger(sovAddr).init( - _name, - _symbol, - msg.sender, - _maxTokens - ); - } + require( sovAddr != address(0), "createSovereignNFTContract::_contractType unsupported contract type." diff --git a/src/token/ERC721/sovereign/LazySovereignNFT.sol b/src/token/ERC721/sovereign/lazy/LazySovereignNFT.sol similarity index 99% rename from src/token/ERC721/sovereign/LazySovereignNFT.sol rename to src/token/ERC721/sovereign/lazy/LazySovereignNFT.sol index 1970219..5e112a0 100644 --- a/src/token/ERC721/sovereign/LazySovereignNFT.sol +++ b/src/token/ERC721/sovereign/lazy/LazySovereignNFT.sol @@ -8,8 +8,8 @@ import "openzeppelin-contracts-upgradeable/utils/introspection/ERC165Upgradeable import "openzeppelin-contracts-upgradeable/access/OwnableUpgradeable.sol"; import "openzeppelin-contracts-upgradeable/utils/CountersUpgradeable.sol"; import "openzeppelin-contracts-upgradeable/utils/math/SafeMathUpgradeable.sol"; -import "../../extensions/ITokenCreator.sol"; -import "../../extensions/ERC2981Upgradeable.sol"; +import "../../../extensions/ITokenCreator.sol"; +import "../../../extensions/ERC2981Upgradeable.sol"; /** * @title LazySovereignNFT diff --git a/src/token/ERC721/sovereign/lazy/LazySovereignNFTContractFactory.sol b/src/token/ERC721/sovereign/lazy/LazySovereignNFTContractFactory.sol new file mode 100644 index 0000000..80b145f --- /dev/null +++ b/src/token/ERC721/sovereign/lazy/LazySovereignNFTContractFactory.sol @@ -0,0 +1,107 @@ +// contracts/token/ERC721/sovereign/SovereignNFTContractFactory.sol +// SPDX-License-Identifier: MIT +pragma solidity 0.8.15; + +import "openzeppelin-contracts/access/Ownable.sol"; +import "openzeppelin-contracts/proxy/Clones.sol"; +import "./LazySovereignNFT.sol"; +import "./extensions/LazySovereignNFTRoyaltyGuard.sol"; +import "./extensions/LazySovereignNFTRoyaltyGuardDeadmanTrigger.sol"; + +contract LazySovereignNFTContractFactory is Ownable { + + bytes32 public constant LAZY_SOVEREIGN_NFT = keccak256("LAZY_SOVEREIGN_NFT"); + bytes32 public constant LAZY_ROYALTY_GUARD = keccak256("LAZY_ROYALTY_GUARD"); + bytes32 public constant LAZY_ROYALTY_GUARD_DEADMAN = keccak256("LAZY_ROYALTY_GUARD_DEADMAN"); + + address public lazySovereignNFT; + address public lazySovereignNFTRoyaltyGuard; + address public lazySovereignNFTRoyaltyGuardDeadmanTrigger; + + event SovereignNFTContractCreated( + address indexed contractAddress, + address indexed owner + ); + + event SovereignNFTContractCreated( + address indexed contractAddress, + address indexed owner, + bytes32 indexed contractType + ); + + constructor() { + LazySovereignNFT lsovNFT = new LazySovereignNFT(); + lazySovereignNFT = address(lsovNFT); + + LazySovereignNFTRoyaltyGuard lsovNFTRG = new LazySovereignNFTRoyaltyGuard(); + lazySovereignNFTRoyaltyGuard = address(lsovNFTRG); + + LazySovereignNFTRoyaltyGuardDeadmanTrigger lsovNFTRGDT = new LazySovereignNFTRoyaltyGuardDeadmanTrigger(); + lazySovereignNFTRoyaltyGuardDeadmanTrigger = address(lsovNFTRGDT); + } + + function setSovereignNFT(address _sovereignNFT, bytes32 _contractType) + external + onlyOwner + { + require(_sovereignNFT != address(0)); + if (_contractType == LAZY_SOVEREIGN_NFT) { + lazySovereignNFT = _sovereignNFT; + return; + } + if (_contractType == LAZY_ROYALTY_GUARD) { + lazySovereignNFTRoyaltyGuard = _sovereignNFT; + return; + } + if (_contractType == LAZY_ROYALTY_GUARD_DEADMAN) { + lazySovereignNFTRoyaltyGuardDeadmanTrigger = _sovereignNFT; + return; + } + require(false, "setSovereignNFT::Unsupported _contractType."); + } + + + function createSovereignNFTContract( + string memory _name, + string memory _symbol, + uint256 _maxTokens, + bytes32 _contractType + ) public returns (address) { + require( + _maxTokens != 0, + "createSovereignNFTContract::_maxTokens cant be zero" + ); + + address sovAddr; + if (_contractType == LAZY_SOVEREIGN_NFT) { + sovAddr = Clones.clone(lazySovereignNFT); + LazySovereignNFT(sovAddr).init(_name, _symbol, msg.sender, _maxTokens); + } + if (_contractType == LAZY_ROYALTY_GUARD) { + sovAddr = Clones.clone(lazySovereignNFTRoyaltyGuard); + LazySovereignNFTRoyaltyGuard(sovAddr).init( + _name, + _symbol, + msg.sender, + _maxTokens + ); + } + if (_contractType == LAZY_ROYALTY_GUARD_DEADMAN) { + sovAddr = Clones.clone(lazySovereignNFTRoyaltyGuardDeadmanTrigger); + LazySovereignNFTRoyaltyGuardDeadmanTrigger(sovAddr).init( + _name, + _symbol, + msg.sender, + _maxTokens + ); + } + require( + sovAddr != address(0), + "createSovereignNFTContract::_contractType unsupported contract type." + ); + emit SovereignNFTContractCreated(sovAddr, msg.sender); + emit SovereignNFTContractCreated(sovAddr, msg.sender, _contractType); + + return address(sovAddr); + } +} diff --git a/src/token/ERC721/sovereign/extensions/LazySovereignNFTRoyaltyGuard.sol b/src/token/ERC721/sovereign/lazy/extensions/LazySovereignNFTRoyaltyGuard.sol similarity index 100% rename from src/token/ERC721/sovereign/extensions/LazySovereignNFTRoyaltyGuard.sol rename to src/token/ERC721/sovereign/lazy/extensions/LazySovereignNFTRoyaltyGuard.sol diff --git a/src/token/ERC721/sovereign/extensions/LazySovereignNFTRoyaltyGuardDeadmanTrigger.sol b/src/token/ERC721/sovereign/lazy/extensions/LazySovereignNFTRoyaltyGuardDeadmanTrigger.sol similarity index 100% rename from src/token/ERC721/sovereign/extensions/LazySovereignNFTRoyaltyGuardDeadmanTrigger.sol rename to src/token/ERC721/sovereign/lazy/extensions/LazySovereignNFTRoyaltyGuardDeadmanTrigger.sol