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

feat(world-consumer): convert store-consumer package into world-consumer #3584

Merged
merged 19 commits into from
Feb 7, 2025

Conversation

vdrg
Copy link
Contributor

@vdrg vdrg commented Feb 6, 2025

Simplifies the existing store-consumer package to just support consuming from a World. Updates the world-module-erc20 contracts to inherit from the new WorldConsumer contract.

Copy link

changeset-bot bot commented Feb 6, 2025

🦋 Changeset detected

Latest commit: d4b8b11

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
@latticexyz/world-module-erc20 Patch
@latticexyz/world-consumer Patch
@latticexyz/abi-ts Patch
@latticexyz/block-logs-stream Patch
@latticexyz/cli Patch
@latticexyz/common Patch
@latticexyz/config Patch
create-mud Patch
@latticexyz/dev-tools Patch
@latticexyz/entrykit Patch
@latticexyz/explorer Patch
@latticexyz/faucet Patch
@latticexyz/gas-report Patch
@latticexyz/paymaster Patch
@latticexyz/protocol-parser Patch
@latticexyz/react Patch
@latticexyz/recs Patch
@latticexyz/schema-type Patch
solhint-config-mud Patch
solhint-plugin-mud Patch
@latticexyz/stash Patch
@latticexyz/store-indexer Patch
@latticexyz/store-sync Patch
@latticexyz/store Patch
@latticexyz/utils Patch
vite-plugin-mud Patch
@latticexyz/world-module-callwithsignature Patch
@latticexyz/world-module-metadata Patch
@latticexyz/world-modules Patch
@latticexyz/world Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

---

Renamed `store-consumer` package to `world-consumer`. The `world-consumer` package now only includes a single `WorldConsumer` contract that always attaches to a World.
The `world-module-erc20` package was updated to reflect this refactor.
Copy link
Member

Choose a reason for hiding this comment

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

I'd prob move this to its own changeset like

Migrated from store-consumer to world-consumer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

error WorldConsumer_NamespaceDoesNotExists(bytes14 namespace);
error WorldConsumer_CallerHasNoNamespaceAccess(bytes14 namespace, address caller);
error WorldConsumer_CallerIsNotWorld(address caller);
error WorldConsumer_ValueNotAllowed();
Copy link
Member

@frolic frolic Feb 6, 2025

Choose a reason for hiding this comment

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

I wonder if its worth adding a worldAddress to each? might make it easier to see what world is trying to be called if you end up configuring or calling this wrong

I also wonder about bytes14 namespace vs ResourceId namespaceId since the latter is generally what we pass around inside world

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah let me check other errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mm so we have:

  error World_AccessDenied(string resource, address caller);
  error World_InvalidNamespace(bytes14 namespace);

As the current error is just referring to a namespace, I feel it might be more consistent to keep it as just bytes14 but not sure.

Adding the world address makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added it as a IBaseWorld world

Copy link
Member

@frolic frolic Feb 6, 2025

Choose a reason for hiding this comment

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

I think we can keep it address world to simplify if you wanted to avoid casting everywhere

I also wonder if we should use _world() and WorldContext._world()

function _world() internal view returns (address) {
return StoreSwitch.getStoreAddress();
}

Instead of reimplementing + renaming as getWorld()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah good point! will do, this was from before using world context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, ended up using _world() directly for most things so turned the events args to address worldAddress.

alvrs
alvrs previously approved these changes Feb 7, 2025
import { System } from "@latticexyz/world/src/System.sol";

abstract contract WorldConsumer is System {
bytes14 public immutable namespace;
Copy link
Member

@frolic frolic Feb 7, 2025

Choose a reason for hiding this comment

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

not blocking, but do we need this anymore if we can now do namespaceId.getNamespace()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well if we are doing the immutable stuff for efficiency, we might as well keep the namespace and use it directly

Copy link
Member

@frolic frolic Feb 7, 2025

Choose a reason for hiding this comment

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

oh does immutable not have the same read gas cost? I assumed if we used both of these variables in one call, we'd have 2x storage look ups

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah immutable actually works similar to constants, the data gets added to the bytecode so you are not reading from storage. That reminds me that immutable vars shouldn't be readable from within the constructor, so not sure why the tests are passing 🤔

Copy link
Member

Choose a reason for hiding this comment

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

image

TIL how immutable works

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah since solidity 0.8.21 they can be read in the constructor, all good

@vdrg vdrg merged commit b774ab2 into main Feb 7, 2025
16 checks passed
@vdrg vdrg deleted the vdrg/world-consumer branch February 7, 2025 16:59
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.

3 participants