Skip to content

Commit

Permalink
chore: break out lazy sovereign into own factory
Browse files Browse the repository at this point in the history
  • Loading branch information
charlescrain committed Oct 18, 2023
1 parent 3584da8 commit aca7f4b
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 48 deletions.
19 changes: 19 additions & 0 deletions scripts/token/sovereign/LazySovereignNFTFactoryDeploy.s.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}
48 changes: 2 additions & 46 deletions src/token/ERC721/sovereign/SovereignNFTContractFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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 {
Expand All @@ -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.");
}

Expand Down Expand Up @@ -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."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
107 changes: 107 additions & 0 deletions src/token/ERC721/sovereign/lazy/LazySovereignNFTContractFactory.sol
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit aca7f4b

Please sign in to comment.