Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create top hat #91

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions contracts/DecentHats.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//SPDX-License-Identifier: MIT
pragma solidity =0.8.19;

import {Enum} from "@gnosis.pm/zodiac/contracts/core/Module.sol";
import {IAvatar} from "@gnosis.pm/zodiac/contracts/interfaces/IAvatar.sol";
import {IHats} from "./interfaces/hats/IHats.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

contract DecentHats {
struct Hat {
address eligibility;
uint32 maxSupply;
address toggle;
string details;
string imageURI;
bool isMutable;
address wearer;
}

IHats public hats;
address public keyValuePairs;

constructor(IHats _hats, address _keyValuePairs) {
hats = _hats;
keyValuePairs = _keyValuePairs;
}

function createAndDeclareTree(
string memory _topHatDetails,
string memory _topHatImageURI,
Hat calldata _adminHat,
Hat[] calldata _hats
) public {
uint256 topHatId = hats.mintTopHat(
msg.sender,
_topHatDetails,
_topHatImageURI
);

string[] memory keys = new string[](1);
keys[0] = "hatsTreeId";

string[] memory values = new string[](1);
values[0] = Strings.toString(topHatId);

IAvatar(msg.sender).execTransactionFromModule(
keyValuePairs,
0,
abi.encodeWithSignature(
"updateValues(string[],string[])",
keys,
values
),
Enum.Operation.Call
);

uint256 adminHatId = hats.createHat(
topHatId,
_adminHat.details,
_adminHat.maxSupply,
_adminHat.eligibility,
_adminHat.toggle,
_adminHat.isMutable,
_adminHat.imageURI
);

if (_adminHat.wearer != address(0)) {
hats.mintHat(adminHatId, _adminHat.wearer);
}

for (uint256 i = 0; i < _hats.length; ) {
Hat memory hat = _hats[i];
uint256 hatId = hats.createHat(
adminHatId,
hat.details,
hat.maxSupply,
hat.eligibility,
hat.toggle,
hat.isMutable,
hat.imageURI
);

if (hat.wearer != address(0)) {
hats.mintHat(hatId, hat.wearer);
}

unchecked {
++i;
}
}
}
}
40 changes: 40 additions & 0 deletions contracts/interfaces/hats/IHats.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: AGPL-3.0
// Copyright (C) 2023 Haberdasher Labs
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

pragma solidity >=0.8.13;

interface IHats {
function mintTopHat(
address _target,
string memory _details,
string memory _imageURI
) external returns (uint256 topHatId);

function createHat(
uint256 _admin,
string calldata _details,
uint32 _maxSupply,
address _eligibility,
address _toggle,
bool _mutable,
string calldata _imageURI
) external returns (uint256 newHatId);

function mintHat(
uint256 _hatId,
address _wearer
) external returns (bool success);
}
34 changes: 34 additions & 0 deletions contracts/mock/MockHats.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;

import {IHats} from "../interfaces/hats/IHats.sol";

contract MockHats is IHats {
uint256 count = 0;

function mintTopHat(
address,
string memory,
string memory
) external returns (uint256 topHatId) {
topHatId = count;
count++;
}

function createHat(
uint256,
string calldata,
uint32,
address,
address,
bool,
string calldata
) external returns (uint256 newHatId) {
newHatId = count;
count++;
}

function mintHat(uint256, address) external pure returns (bool success) {
success = true;
}
}
Loading