Skip to content

Commit

Permalink
feat: update factory
Browse files Browse the repository at this point in the history
  • Loading branch information
SigismundSchlomo committed Nov 18, 2024
1 parent 95244ce commit 4e590c2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 158 deletions.
25 changes: 3 additions & 22 deletions contracts/multisig/IMultisigFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

}

157 changes: 21 additions & 136 deletions contracts/multisig/MultisigFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
Expand All @@ -97,90 +47,25 @@ 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);
}
}

// 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) {}
}

0 comments on commit 4e590c2

Please sign in to comment.