From 4e590c26be0abf18fdbf6994bb2f76e4b80641e2 Mon Sep 17 00:00:00 2001 From: SigismundSchlomo Date: Mon, 18 Nov 2024 16:24:10 +0200 Subject: [PATCH] feat: update factory --- contracts/multisig/IMultisigFactory.sol | 25 +--- contracts/multisig/MultisigFactory.sol | 157 ++++-------------------- 2 files changed, 24 insertions(+), 158 deletions(-) diff --git a/contracts/multisig/IMultisigFactory.sol b/contracts/multisig/IMultisigFactory.sol index 39f3c9a..c51825e 100644 --- a/contracts/multisig/IMultisigFactory.sol +++ b/contracts/multisig/IMultisigFactory.sol @@ -4,20 +4,6 @@ pragma solidity ^0.8.17; import "./Multisig.sol"; import "./MasterMultisig.sol"; -address constant Igor = 0x55d46039e187b37a0201068dE189ecB63eaE87d2; -address constant Igor2 = 0x85e5e089782a3cAd89D1672DFBd7A9300d635Aa6; -address constant Aleksandr = 0x125854A4Ce5875ca46d1504ECf08897976022563; -address constant Andrii = 0xb16398c0698149Ae6EC342614830bC0511b83CAf; -address constant Seth = 0x6fA040aD7e94f905a29536Ba786D433638FeD19b; -address constant Valerii = 0x5700F8e0ae3d80964f7718EA625E3a2CB4D2096d; -address constant Oleksii = 0xa5E32D3fB342D9Ed3135fD5cb59a102AC8ED7B85; -address constant Olena = 0xe620e1F969Bc3a24Ac96D527220AD6B6e2d12843; -address constant Alina = 0x787afc1E7a61af49D7B94F8E774aC566D1B60e99; -address constant Alex = 0xe8592B3a9ee54472A0115262871eF43B5F3e8E53; -address constant Sophie = 0xBc2e61822443b18070E387F045CcFAD33E6958d0; -address constant Matthieu = 0x37d6bF7e8875137EefA8286e6AEA2cc4bFAF1247; -address constant Michael = 0xB72aDaffEb3419487C49690Dc68e963F7d7D81AC; - interface IMultisigFactory { struct MultisigSettings { address[] signers; @@ -30,15 +16,10 @@ interface IMultisigFactory { event MultisigCreated(address indexed multisig); event MultisigRegistered(address indexed multisig); - function createEcosystemMultisig() external returns (address); - function createCommonMultisig() external returns (address); + function createMultisig(MultisigSettings calldata settings) external returns (address); function registerMultisigs(address[] calldata _multisigs) external; - function getEcosystemMultisigsCount() external view returns (uint256); - function getCommonMultisigsCount() external view returns (uint256); - function getAllMultisigsAddresses() external view returns (address[] memory); - function getEcosystemMultisigsAddresses() external view returns (address[] memory); - function getCommonMultisigsAddresses() external view returns (address[] memory); - + function getMultisigsCount() external view returns (uint256); + function getMultisigsAddresses() external view returns (address[] memory); } diff --git a/contracts/multisig/MultisigFactory.sol b/contracts/multisig/MultisigFactory.sol index 8e6a3cc..58175d7 100644 --- a/contracts/multisig/MultisigFactory.sol +++ b/contracts/multisig/MultisigFactory.sol @@ -10,15 +10,10 @@ import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol" contract MultisigFactory is IMultisigFactory, UUPSUpgradeable, AccessControlUpgradeable { bytes32 constant public CREATOR_ROLE = keccak256("CREATOR_ROLE"); - // Master multisigs - MultisigSettings public ecosystemMultisigSettings; - MultisigSettings public commonMultisigSettings; // Track ecosystem and common multisigs separately - Multisig[] public ecosystemMultisigs; - Multisig[] public commonMultisigs; + Multisig[] public multisigs; mapping(address => bool) public isRegisteredMultisig; - mapping(address => bool) public isEcosystemMultisig; function initialize(address ecosystemMaster, address commonMaster) public initializer { require(ecosystemMaster != address(0), "Invalid ecosystem master"); @@ -27,66 +22,21 @@ contract MultisigFactory is IMultisigFactory, UUPSUpgradeable, AccessControlUpgr _setupRole(DEFAULT_ADMIN_ROLE, msg.sender); _setupRole(CREATOR_ROLE, msg.sender); __UUPSUpgradeable_init(); + } - address[] memory ecoSigners = new address[](3); - ecoSigners[0] = Aleksandr; - ecoSigners[1] = Andrii; - ecoSigners[2] = Igor2; - - bool[] memory ecoFlags = new bool[](3); - ecoFlags[0] = true; - ecoFlags[1] = true; - ecoFlags[2] = true; - - ecosystemMultisigSettings = MultisigSettings({ - signers: ecoSigners, - isInitiatorFlags: ecoFlags, - threshold: 51, - owner: ecosystemMaster - }); - - address[] memory commonSigners = new address[](11); - commonSigners[0] = Valerii; - commonSigners[1] = Oleksii; - commonSigners[2] = Olena; - commonSigners[3] = Igor; - commonSigners[4] = Andrii; - commonSigners[5] = Alina; - commonSigners[6] = Alex; - commonSigners[7] = Seth; - commonSigners[8] = Sophie; - commonSigners[9] = Matthieu; - commonSigners[10] = Michael; - - bool[] memory commonFlags = new bool[](11); - commonFlags[0] = true; - commonFlags[1] = true; - commonFlags[2] = true; - commonFlags[3] = true; - commonFlags[4] = true; - commonFlags[5] = true; - commonFlags[6] = true; - commonFlags[7] = true; - commonFlags[8] = true; - commonFlags[9] = true; - commonFlags[10] = true; + function createMultisig(MultisigSettings calldata settings) external onlyRole(CREATOR_ROLE) returns (address) { + Multisig newMultisig = new Multisig( + settings.signers, + settings.isInitiatorFlags, + settings.threshold, + settings.owner + ); - commonMultisigSettings = MultisigSettings({ - signers: commonSigners, - isInitiatorFlags: commonFlags, - threshold: 50, - owner: commonMaster - }); - } - - // Create new multisig under ecosystem master - function createEcosystemMultisig() external onlyRole(CREATOR_ROLE) returns (address) { - return _createMultisig(ecosystemMultisigSettings); - } - - // Create new multisig under common master - function createCommonMultisig() external onlyRole(CREATOR_ROLE) returns (address) { - return _createMultisig(commonMultisigSettings); + multisigs.push(newMultisig); + isRegisteredMultisig[address(newMultisig)] = true; + + emit MultisigCreated(address(newMultisig)); + return address(newMultisig); } // Register previously deployed multisigs in batch @@ -97,16 +47,7 @@ contract MultisigFactory is IMultisigFactory, UUPSUpgradeable, AccessControlUpgr require(!isRegisteredMultisig[multisigAddress], "Already registered"); Multisig multisig = Multisig(multisigAddress); - address master = multisig.owner(); - - if (master == address(ecosystemMultisigSettings.owner)) { - ecosystemMultisigs.push(multisig); - isEcosystemMultisig[multisigAddress] = true; - } else if (master == address(commonMultisigSettings.owner)) { - commonMultisigs.push(multisig); - } else { - revert("Invalid master multisig"); - } + multisigs.push(multisig); isRegisteredMultisig[multisigAddress] = true; emit MultisigRegistered(multisigAddress); @@ -114,73 +55,17 @@ contract MultisigFactory is IMultisigFactory, UUPSUpgradeable, AccessControlUpgr } // View functions - function getEcosystemMultisigSettings() external view returns (MultisigSettings memory) { - return ecosystemMultisigSettings; - } - - function getCommonMultisigSettings() external view returns (MultisigSettings memory) { - return commonMultisigSettings; - } - - function getEcosystemMultisigsCount() external view returns (uint256) { - return ecosystemMultisigs.length; - } - - function getCommonMultisigsCount() external view returns (uint256) { - return commonMultisigs.length; + function getMultisigsCount() external view returns (uint256) { + return multisigs.length; } - function getAllMultisigsAddresses() external view returns (address[] memory) { - uint256 totalLength = ecosystemMultisigs.length + commonMultisigs.length; - address[] memory addresses = new address[](totalLength); - - for (uint i = 0; i < ecosystemMultisigs.length; i++) { - addresses[i] = address(ecosystemMultisigs[i]); - } - - for (uint i = 0; i < commonMultisigs.length; i++) { - addresses[ecosystemMultisigs.length + i] = address(commonMultisigs[i]); + function getMultisigsAddresses() external view returns (address[] memory) { + address[] memory addresses = new address[](multisigs.length); + for (uint i = 0; i < multisigs.length; i++) { + addresses[i] = address(multisigs[i]); } - return addresses; } - - function getEcosystemMultisigsAddresses() external view returns (address[] memory) { - address[] memory addresses = new address[](ecosystemMultisigs.length); - for (uint i = 0; i < ecosystemMultisigs.length; i++) { - addresses[i] = address(ecosystemMultisigs[i]); - } - return addresses; - } - - function getCommonMultisigsAddresses() external view returns (address[] memory) { - address[] memory addresses = new address[](commonMultisigs.length); - for (uint i = 0; i < commonMultisigs.length; i++) { - addresses[i] = address(commonMultisigs[i]); - } - return addresses; - } - - // Internal function to create multisig - function _createMultisig(MultisigSettings memory settings) internal returns (address) { - Multisig newMultisig = new Multisig( - settings.signers, - settings.isInitiatorFlags, - settings.threshold, - settings.owner - ); - - if (settings.owner == address(ecosystemMultisigSettings.owner)) { - ecosystemMultisigs.push(newMultisig); - isEcosystemMultisig[address(newMultisig)] = true; - } else { - commonMultisigs.push(newMultisig); - } - isRegisteredMultisig[address(newMultisig)] = true; - - emit MultisigCreated(address(newMultisig)); - return address(newMultisig); - } function _authorizeUpgrade(address) internal override onlyRole(DEFAULT_ADMIN_ROLE) {} }