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

Create top hat #91

wants to merge 4 commits into from

Conversation

adamgall
Copy link
Member

@adamgall adamgall commented Jun 21, 2024

Closes #92

@adamgall adamgall requested review from mudrila and Da-Colon June 21, 2024 00:07
@adamgall
Copy link
Member Author

Original message posted on June 20 as follows:


The goal of this effort is to allow a single transaction to do two things:

  1. Create a new Top Hat
  2. Allow the Safe to "declare" onchain that "this one and only one Top Hat is mine"

Hats protocol doesn't support "predicting" Top Hat IDs ahead of time, like Safe does with their Safe Proxy contracts. Top Hat IDs are simple auto-incrementing integers.

The concern is that if we try to "predict" the next ID ahead of time in our UI, it's possible that another transaction will be included before ours which creates a new Top Hat, and then all of a sudden the Top Hat we create has an ID that we weren't expecting, and so now the rest of our pre-generated transaction data to "declare" the Top Hat into KeyValuePairs and/or create some actual Hats in that tree, will be referencing a Top Hat that isn't ours.

First thought to overcome that (and confirmed with Hats team) is to make a simple contract that does the Top Hat creation call, gets the ID back, then uses that ID in solidity to do "whatever other onchain things we need to do" with that Top Hat ID.

"Whatever other onchain things we need to do", in our case, includes "declaring the Top Hat ID in KeyValuePairs.

However, KeyValuePairs emits events using msg.sender as the "address" in the "address x is declaring such and such" logs that it emits. As it should!

But that means if we have another address besides the Safe calling KeyValuePairs, that other address shows up as the "from" address in event logs.

So, then I thought, let me delegatecall from the new contract to KeyValuePairs, so that msg.sender inside KeyValuePairs will be the address that called the new contract!

This worked well, EXCEPT for the fact that the log that KeyValuePairs emits isn't emitted from KeyValuePairs any longer! It's emitted "from" the middle contract (CreateTopHatKVPairs) which delegatecalls KeyValuePairs! So that's wild (but expected in retrospect), and doesn't solve our issue because the interface won't see that log as long as it's fetching KeyValuePairs logs from the KeyValuePairs address.

Dead end after dead end. Not sure what the best path forward is.

In this PR are two implementations of the different ways I'm seeing we can approach this problem:

  1. Do the delegatecall to KeyValuePairs anyway, and in the interface we'd need to just look for these ValueUpdated logs on both the KeyValuePairs contract and the new CreateTopHatKVPairs contract.
  2. Don't bother with KeyValuePairs at all, and just emit and look for the log which declares a Top Hat ID from the Safe address in the CreateTopHat contract. The interface would then need to look for logs coming off of this CreateTopHat contract for this data, instead of KeyValuePairs.

@adamgall adamgall marked this pull request as ready for review June 25, 2024 19:03
@adamgall adamgall requested a review from DarksightKellar June 25, 2024 19:03
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.

Overall - looks good

From the code it looks straightforward that Hat will be minted with the details given and image specified, but just to make sure - do you mind adding a test case covering that?

Assuming deployment of the contract will happen after merging this PR - I'm cool if we'll get this test case at that point

@adamgall
Copy link
Member Author

adamgall commented Jun 25, 2024

@mudrila i have more code to push into this branch, to support adding admin hat and child hats in this transaction

Also @mudrila I can't really test that because I'm just mocking out my Hats implementation. I don't do anything with those paramaters in my mock function. I mean I guess I could start creating more structure and state in HatsMock, but idk if that's really the point.

@adamgall
Copy link
Member Author

yo @mudrila actually yeah I can't really think of any other tests to write at the moment. Can you?

@mudrila
Copy link
Contributor

mudrila commented Jun 25, 2024

@mudrila i have more code to push into this branch, to support adding admin hat and child hats in this transaction

Also @mudrila I can't really test that because I'm just mocking out my Hats implementation. I don't do anything with those paramaters in my mock function. I mean I guess I could start creating more structure and state in HatsMock, but idk if that's really the point.

I feel like trying to make HatsMock as close as possible to the original implementation, at least from minting prospective, will be great - to verify that some sort of integration works here. Can't we not hold our custom mock but use factory for deployment like we're doing for Safe? I guess we can't but just to clarify
But otherwise - yeah, I don't see any other reasonable functionality to test.

@adamgall
Copy link
Member Author

Yeah AFAIK there's no quick/easy way to deploy the actual Hats Protocol into our test environment, so that's why I made this MockHats contract.

I think it's not relevant to add anything more to MockHats. DecentHats doesn't care about those properties, it's not our concern. What is our concern is the new topHatId being returned from hats.mintTopHat, cause that needs to get emitted through KeyValuePairs. So Idk, I think what we have tested is fine. Anything else to test will just be testing our ability to implement Hats, but it doesn't seem relevant from the context of what DecentHats cares about.

@adamgall
Copy link
Member Author

Bah there are more tests I can write, i'm just being lazy. let me get to it

@adamgall
Copy link
Member Author

Ok this is ready for review again (I didn't add more tests)

@adamgall adamgall requested a review from mudrila June 26, 2024 21:35
@adamgall adamgall self-assigned this Jun 27, 2024
@adamgall
Copy link
Member Author

adamgall commented Jul 5, 2024

Closing this PR, the other one will just have all of this new code

@adamgall adamgall closed this Jul 5, 2024
@adamgall adamgall mentioned this pull request Jul 5, 2024
@adamgall adamgall deleted the create-top-hat branch July 5, 2024 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[roles-0.1.0] Create Safe Module for creating full Hats tree
2 participants