Skip to content

Commit

Permalink
Create DecentHats contract, and some helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgall committed Jun 25, 2024
1 parent c8349fa commit 3d4f280
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
36 changes: 36 additions & 0 deletions contracts/DecentHats.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//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 {
IHats public hats;
address public keyValuePairs;

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

function createAndDeclareTree(string memory _details, string memory _imageURI) public returns (bool success) {
uint256 topHatId = hats.mintTopHat(msg.sender, _details, _imageURI);

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

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

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

return success;
}
}
23 changes: 23 additions & 0 deletions contracts/interfaces/hats/IHats.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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);
}
13 changes: 13 additions & 0 deletions contracts/mock/MockHats.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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++;
}
}

0 comments on commit 3d4f280

Please sign in to comment.