From bf80360d78bc941f6c2dc7f36413ae2005bb9828 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Wed, 9 Oct 2024 10:32:39 -0400 Subject: [PATCH] use ModuleProxyFactory to deploy AutoAdmin --- contracts/DecentAutonomousAdmin.sol | 8 +-- contracts/DecentHats_0_2_0.sol | 51 +++++++++---------- .../core/019_deploy_DecentAutonomousAdmin.ts | 9 ++++ 3 files changed, 36 insertions(+), 32 deletions(-) create mode 100644 deploy/core/019_deploy_DecentAutonomousAdmin.ts diff --git a/contracts/DecentAutonomousAdmin.sol b/contracts/DecentAutonomousAdmin.sol index ce23043a..fd7b7cb4 100644 --- a/contracts/DecentAutonomousAdmin.sol +++ b/contracts/DecentAutonomousAdmin.sol @@ -8,8 +8,6 @@ contract DecentAutonomousAdmin { string public constant NAME = "DecentAutonomousAdmin"; string public version_ = "0.1.0"; - uint256 public adminHatId; - struct SablierStreamInfo { uint256 streamId; ISablierV2LockupLinear sablierV2LockupLinear; @@ -23,11 +21,9 @@ contract DecentAutonomousAdmin { } // ////////////////////////////////////////////////////////////// - // Constructor + // initializer // ////////////////////////////////////////////////////////////// - constructor(uint256 _adminHatId) { - adminHatId = _adminHatId; - } + function setUp() public {} // ////////////////////////////////////////////////////////////// // Public Functions diff --git a/contracts/DecentHats_0_2_0.sol b/contracts/DecentHats_0_2_0.sol index 7286aa80..58681c53 100644 --- a/contracts/DecentHats_0_2_0.sol +++ b/contracts/DecentHats_0_2_0.sol @@ -12,6 +12,8 @@ import {LockupLinear} from "./interfaces/sablier/LockupLinear.sol"; import {DecentAutonomousAdmin} from "./DecentAutonomousAdmin.sol"; import {IHatsModuleFactory} from "./interfaces/IHatModuleFactory.sol"; import {IHatsElectionEligibility} from "./interfaces/hats/IHatsElectionEligibility.sol"; +import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol"; +import {ModuleProxyFactory} from "@gnosis.pm/zodiac/contracts/factory/ModuleProxyFactory.sol"; contract DecentHats_0_2_0 { string public constant NAME = "DecentHats_0_2_0"; @@ -47,6 +49,8 @@ contract DecentHats_0_2_0 { IHats hatsProtocol; IERC6551Registry registry; IHatsModuleFactory hatsModuleFactory; + ModuleProxyFactory moduleProxyFactory; + address decentAutonomousAdminMasterCopy; address hatsAccountImplementation; address keyValuePairs; address hatsElectionEligibilityImplementation; @@ -75,11 +79,13 @@ contract DecentHats_0_2_0 { (uint256 adminHatId, ) = _createAdminHatAndAccount( params.hatsProtocol, - topHatId, - params.adminHat, - topHatAccount, params.registry, + params.moduleProxyFactory, + params.decentAutonomousAdminMasterCopy, params.hatsAccountImplementation, + topHatAccount, + topHatId, + params.adminHat, salt ); @@ -138,10 +144,12 @@ contract DecentHats_0_2_0 { address _keyValuePairs, uint256 topHatId ) internal { - string[] memory keys = new string[](1); - string[] memory values = new string[](1); + string[] memory keys = new string[](2); + string[] memory values = new string[](2); keys[0] = "topHatId"; values[0] = Strings.toString(topHatId); + keys[1] = "decentHatsAddress"; + values[1] = Strings.toHexString(address(this)); IAvatar(msg.sender).execTransactionFromModule( _keyValuePairs, @@ -281,11 +289,13 @@ contract DecentHats_0_2_0 { function _createAdminHatAndAccount( IHats hatsProtocol, - uint256 topHatId, - Hat calldata hat, - address topHatAccount, IERC6551Registry registry, + ModuleProxyFactory moduleProxyFactory, + address decentAutonomousAdminMasterCopy, address hatsAccountImplementation, + address topHatAccount, + uint256 topHatId, + Hat calldata hat, bytes32 salt ) internal returns (uint256 adminHatId, address accountAddress) { adminHatId = _createHat(hatsProtocol, topHatId, hat, topHatAccount); @@ -297,26 +307,15 @@ contract DecentHats_0_2_0 { address(hatsProtocol), adminHatId ); - address adminInstance = _deployDecentAutonomousAdmin(salt, topHatId); - hatsProtocol.mintHat(adminHatId, adminInstance); - } - - function _deployDecentAutonomousAdmin( - bytes32 salt, - uint256 _adminHatId - ) internal returns (address deployedAddress) { - bytes memory creationCode = _getCreationCode(_adminHatId); - assembly { - deployedAddress := create2( - 0, - add(creationCode, 0x20), - mload(creationCode), - salt + hatsProtocol.mintHat( + adminHatId, + moduleProxyFactory.deployModule( + decentAutonomousAdminMasterCopy, + abi.encodeWithSignature("setUp()"), + uint256(keccak256(abi.encodePacked(salt, adminHatId))) ) - } - - require(deployedAddress != address(0), "CREATE2: Failed on deploy"); + ); } function _getCreationCode( diff --git a/deploy/core/019_deploy_DecentAutonomousAdmin.ts b/deploy/core/019_deploy_DecentAutonomousAdmin.ts new file mode 100644 index 00000000..f1adb696 --- /dev/null +++ b/deploy/core/019_deploy_DecentAutonomousAdmin.ts @@ -0,0 +1,9 @@ +import { HardhatRuntimeEnvironment } from "hardhat/types"; +import { DeployFunction } from "hardhat-deploy/types"; +import { deployNonUpgradeable } from "../helpers/deployNonUpgradeable"; + +const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { + await deployNonUpgradeable(hre, "DecentAutonomousAdmin"); +}; + +export default func;