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

DecentHats module #93

Merged
merged 15 commits into from
Jul 6, 2024
Merged

DecentHats module #93

merged 15 commits into from
Jul 6, 2024

Conversation

adamgall
Copy link
Member

@adamgall adamgall commented Jun 26, 2024

Closes #92
Closes #94

See also #91


This PR implements a contract called DecentHats which will be temporarily added as a module to Safes, in order to create and configure a Hats tree for that Safe.

It also includes support for deploying instances of ERC6551 "Smart Accounts" for each new Hat.

In live environments, we'll use the HatsAccount1ofN implementation, which is deployed to various chains at address 0xfEf83A660b7C10a3EdaFdCF62DEee1fD8a875D29.

The ERC6551Registry also has a canonical address on all chains: 0x000000006551c19487814612e58FE06813775758.

Copy link
Contributor

@mudrila mudrila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DAMN
THAT's SICK
Straight to prod! 🚀 :shipit:
Have couple of questions though that are not necessarily needs answering - feel free to resolve those conversations and I'll give my approval


constructor(IHats _hats, address _keyValuePairs) {
bytes32 public constant SALT = bytes32(abi.encode(0xdece974a75));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering where this SALT is coming from? Maybe that's reasonable to add a comment about it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good call. Just made it up. I'm pretty sure it doesn't really matter, is just used in deterministic address generation via the internal create2 call that the registry contract makes.

decenthats in leetspeek

Copy link
Member Author

@adamgall adamgall Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i should probably do something more proper here

Copy link
Member Author

@adamgall adamgall Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, idk if this is proper enough though

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

interface IERC6551Registry {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean we have custom registry deployed? Can't we use one from https://github.com/erc6551/reference

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will not have a custom registry deployed. This Interface is included in our codebase so that I can have proper solidity typing in DecentHats when i call the registry to create new Smart Account instances.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

interface IERC6551Registry {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as above - can't we leverage existing package as a dependency?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a Mock used for Testing

function tokenId() public view returns (uint256) {
bytes memory footer = new bytes(0x20);
assembly {
// copy 0x20 bytes from final word of footer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that's not related to this PR and rather to Hats Protocol implementation of HatsAccount - but why final word of a footer? Just curious

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a new ERC6551 contract is deployed from the Registry, the Registry appends some metadata data to the end of the contract bytecode. That metadata includes the NFT contract address and NFT token ID that this contract belongs to.

So, all we're doing with these functions is exposing those properties.

@adamgall adamgall changed the title Create erc6551 accounts DecentHats module Jul 5, 2024
@adamgall adamgall changed the base branch from create-top-hat to develop July 5, 2024 03:36
@adamgall adamgall merged commit 1719ce7 into develop Jul 6, 2024
1 check passed
@adamgall adamgall deleted the create-erc6551-accounts branch July 6, 2024 04:48
adamgall added a commit that referenced this pull request Jul 6, 2024
* Create DecentHats contract, and some helpers

* Create tests for CreateTopHat

* Add support for creating and minting admin and child hats

* Fix tests

* Add the IERC6551Registry.sol interface

* Add the canonical implementation of ERC6551Registry for mock and test purposes

* Create a mock contract which acts as an implementation of the Hats Account which will be cloned via registry

* Deploy instances of Smart Accounts for the newly created Hats

* Add comment

* Less rigid test

* Update SALT

* Use smaller import

* Update name of KeyValuePair key

* DecentHats is wearer of TopHat until end of transaction

* Update parameter order
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants