-
Notifications
You must be signed in to change notification settings - Fork 174
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
refactor(solecs): use @solidstate Ownable, add OwnableWritable, fix some import formatting #265
Conversation
cc @Kooshaba, this touches on some of your multiple system contract ideas i think, |
Also, let's split up the Ownable refactor and the Subsystem changes into two separate PRs |
72c9383
to
97405f7
Compare
Removed Subsystem from this PR, will elaborate on it in its own PR. Diamond storage: benefits:
implications:
The first benefit applies even more so to the other state vars, especially in System: world, components. But that's for another PR (the 2 drafts I made) |
Oh also removed the tests, they'll be together with Subsystem since they use it, unless it's rejected changing them back and forth seems unnecessary. |
97405f7
to
3c7a7f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking really good, thank you! Just had one minor comment and one question, and need to test locally.
if (!writeAccess(msg.sender)) { | ||
revert OwnableWritable__NotWriter(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious about your preference of revert
over require
- could you elaborate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's more about my preference of custom errors over error strings. Custom errors just don't support require, unfortunately.
I took the specific semantics (Contract__ErrorName) from solidstate.
- Unlike strings, custom errors are guaranteed to be devoid of typos, since you can define them in one place, and use (via imports or inheritance) everywhere
- They allow args (like events), which is the most convenient way to do dynamic errors imo
- They aren't strings, so they should be more gas-efficient
- I just don't like the hardcoded nature of error-strings (this is similar to the 1st point, but about personal preference rather than some objective benefit)
imo it'd be great if mud started leaning towards these event-like errors. But if you ultimately prefer require, I can keep that in mind for future PRs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seconding request for use of Custom Errors moving forward!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for elaborating, I agree custom errors are a better approach!
3c7a7f8
to
861ee0f
Compare
Seems like @solidstate/contracts removed |
Updated it. I actually prefer the lack of setOwner |
30bd3c4
to
43d075d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! We should make sure to mention the requirement to install @solidstate/contracts
in consuming packages in the merge commit. Technically a breaking change, but not worth waiting for this change until the next breaking version imo.
contract Ownable is SolidStateOwnable { | ||
constructor() { | ||
// Initialize owner (SolidState has no constructors) | ||
OwnableStorage.layout().owner = msg.sender; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooc why set this manually like this rather than calling _setOwner(msg.sender)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it's set in just 1 place and having an explicit method for it seemed unnecessary.
The method also emits an event.
Which is important, because after checking EIP-173, the event should be emitted on creation too.
Since it's merged I'll make a fix PR to use _setOwner, @holic thanks for noticing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it's set in just 1 place and having an explicit method for it seemed unnecessary.
By that I mean, _setOwner didn't exist in the previous version (I made the PR 2 months ago and recently updated solidstate), and when updating I didn't think to check for a method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this comment is about another setOwner
which was removed, it didn't emit an event
…ome import formatting (latticexyz#265) * refactor(solecs): use @SolidState Ownable, add OwnableWritable, fix some import formatting (latticexyz#265) * build(solecs): add peerDependencies to package.json breaking: - consumers need to install `@solidstate/contracts` as a new peerDependency of `solecs`. - internal `_owner` field was removed from `Component`. (Use `owner()` instead.) Co-authored-by: alvrs <alvarius@lattice.xyz>
Closes #245
Edit: removed paragraph about subsystems since they're moved to #268