Skip to content

Commit

Permalink
use ModuleProxyFactory to deploy AutoAdmin
Browse files Browse the repository at this point in the history
  • Loading branch information
Da-Colon committed Oct 9, 2024
1 parent 1bafbf8 commit bf80360
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 32 deletions.
8 changes: 2 additions & 6 deletions contracts/DecentAutonomousAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,11 +21,9 @@ contract DecentAutonomousAdmin {
}

// //////////////////////////////////////////////////////////////
// Constructor
// initializer
// //////////////////////////////////////////////////////////////
constructor(uint256 _adminHatId) {
adminHatId = _adminHatId;
}
function setUp() public {}

// //////////////////////////////////////////////////////////////
// Public Functions
Expand Down
51 changes: 25 additions & 26 deletions contracts/DecentHats_0_2_0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
);

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions deploy/core/019_deploy_DecentAutonomousAdmin.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit bf80360

Please sign in to comment.