From 44236041fb792fc676481d9d30b5846752ed0491 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Wed, 28 Feb 2024 13:03:06 +0000 Subject: [PATCH] refactor: move table ID and field layout constants into table library (#2327) --- .changeset/few-berries-tickle.md | 21 ++++++++++ e2e/packages/contracts/src/codegen/index.sol | 12 +++--- .../contracts/src/codegen/tables/Multi.sol | 20 +++------ .../contracts/src/codegen/tables/Number.sol | 20 +++------ .../src/codegen/tables/NumberList.sol | 20 +++------ .../contracts/src/codegen/tables/Position.sol | 20 +++------ .../src/codegen/tables/StaticArray.sol | 20 +++------ .../contracts/src/codegen/tables/Vector.sol | 20 +++------ .../src/systems/NumberListSystem.sol | 4 +- .../contracts/script/PostDeploy.s.sol | 4 +- .../packages/contracts/src/codegen/index.sol | 6 +-- .../src/codegen/tables/CounterTable.sol | 20 +++------ .../src/codegen/tables/Inventory.sol | 20 +++------ .../src/codegen/tables/MessageTable.sol | 20 +++------ .../contracts/test/ChatNamespaced.t.sol | 4 +- .../packages/contracts/test/CounterTest.t.sol | 4 +- .../packages/contracts/test/StructTest.t.sol | 2 +- .../packages/contracts/src/codegen/index.sol | 2 +- .../contracts/src/codegen/tables/LastCall.sol | 20 +++------ packages/cli/contracts/src/codegen/index.sol | 12 +++--- .../src/codegen/tables/Dynamics1.sol | 20 +++------ .../src/codegen/tables/Dynamics2.sol | 20 +++------ .../contracts/src/codegen/tables/Offchain.sol | 20 +++------ .../src/codegen/tables/Singleton.sol | 20 +++------ .../contracts/src/codegen/tables/Statics.sol | 20 +++------ .../src/codegen/tables/UserTyped.sol | 20 +++------ .../codegen/render-solidity/common.test.ts | 24 +++++------ .../src/codegen/render-solidity/common.ts | 8 ++-- .../src/codegen/render-solidity/types.ts | 2 - packages/store/src/StoreCore.sol | 33 +++++++-------- packages/store/src/codegen/index.sol | 6 +-- packages/store/src/codegen/tables/Hooks.sol | 13 +----- .../store/src/codegen/tables/ResourceIds.sol | 20 +++------ .../store/src/codegen/tables/StoreHooks.sol | 20 +++------ packages/store/src/codegen/tables/Tables.sol | 20 +++------ packages/store/test/KeyEncoding.t.sol | 8 ++-- packages/store/test/Mixed.t.sol | 8 ++-- packages/store/test/StoreCore.t.sol | 4 +- packages/store/test/Vector2.t.sol | 8 ++-- packages/store/test/codegen/index.sol | 8 ++-- .../store/test/codegen/tables/Callbacks.sol | 20 +++------ .../store/test/codegen/tables/KeyEncoding.sol | 20 +++------ packages/store/test/codegen/tables/Mixed.sol | 20 +++------ .../store/test/codegen/tables/Vector2.sol | 20 +++------ packages/store/ts/codegen/renderTable.ts | 14 ++----- packages/store/ts/codegen/renderTableIndex.ts | 3 +- packages/store/ts/codegen/tableOptions.ts | 1 - packages/world-modules/src/index.sol | 10 ++--- .../erc20-puppet/tables/Allowances.sol | 13 +----- .../erc20-puppet/tables/ERC20Metadata.sol | 13 +----- .../erc20-puppet/tables/ERC20Registry.sol | 13 +----- .../erc20-puppet/tables/TotalSupply.sol | 13 +----- .../erc721-puppet/tables/ERC721Metadata.sol | 13 +----- .../erc721-puppet/tables/ERC721Registry.sol | 13 +----- .../erc721-puppet/tables/OperatorApproval.sol | 13 +----- .../modules/erc721-puppet/tables/Owners.sol | 13 +----- .../erc721-puppet/tables/TokenApproval.sol | 13 +----- .../modules/erc721-puppet/tables/TokenURI.sol | 13 +----- .../modules/keysintable/KeysInTableModule.sol | 18 ++++---- .../keysintable/tables/KeysInTable.sol | 20 +++------ .../keysintable/tables/UsedKeysIndex.sol | 20 +++------ .../keyswithvalue/KeysWithValueModule.sol | 2 +- .../keyswithvalue/tables/KeysWithValue.sol | 13 +----- .../modules/puppet/tables/PuppetRegistry.sol | 13 +----- .../tables/CallboundDelegations.sol | 20 +++------ .../tables/SystemboundDelegations.sol | 20 +++------ .../tables/TimeboundDelegations.sol | 20 +++------ .../src/modules/tokens/tables/Balances.sol | 13 +----- .../uniqueentity/tables/UniqueEntity.sol | 13 +----- .../world-modules/test/SystemSwitch.t.sol | 12 +++--- packages/world/src/codegen/index.sol | 24 +++++------ .../world/src/codegen/tables/Balances.sol | 20 +++------ .../src/codegen/tables/FunctionSelectors.sol | 20 +++------ .../src/codegen/tables/FunctionSignatures.sol | 20 +++------ .../src/codegen/tables/InitModuleAddress.sol | 20 +++------ .../src/codegen/tables/InstalledModules.sol | 20 +++------ .../tables/NamespaceDelegationControl.sol | 20 +++------ .../src/codegen/tables/NamespaceOwner.sol | 20 +++------ .../src/codegen/tables/ResourceAccess.sol | 20 +++------ .../world/src/codegen/tables/SystemHooks.sol | 20 +++------ .../src/codegen/tables/SystemRegistry.sol | 20 +++------ packages/world/src/codegen/tables/Systems.sol | 20 +++------ .../codegen/tables/UserDelegationControl.sol | 20 +++------ .../WorldRegistrationSystem.sol | 4 +- packages/world/test/World.t.sol | 42 +++++++++---------- packages/world/test/WorldDynamicUpdate.t.sol | 4 +- .../test/codegen/tables/AddressArray.sol | 13 +----- packages/world/test/codegen/tables/Bool.sol | 13 +----- .../world/test/codegen/tables/TwoFields.sol | 13 +----- .../packages/contracts/src/codegen/index.sol | 2 +- .../contracts/src/codegen/tables/Counter.sol | 20 +++------ .../packages/contracts/test/CounterTest.t.sol | 2 +- .../packages/contracts/src/codegen/index.sol | 2 +- .../contracts/src/codegen/tables/Counter.sol | 20 +++------ .../packages/contracts/test/CounterTest.t.sol | 2 +- .../packages/contracts/src/codegen/index.sol | 2 +- .../contracts/src/codegen/tables/Tasks.sol | 20 +++------ .../packages/contracts/src/codegen/index.sol | 2 +- .../contracts/src/codegen/tables/Position.sol | 20 +++------ .../packages/contracts/src/codegen/index.sol | 2 +- .../contracts/src/codegen/tables/Counter.sol | 20 +++------ .../packages/contracts/test/CounterTest.t.sol | 2 +- 102 files changed, 427 insertions(+), 1037 deletions(-) create mode 100644 .changeset/few-berries-tickle.md diff --git a/.changeset/few-berries-tickle.md b/.changeset/few-berries-tickle.md new file mode 100644 index 0000000000..dcbf3602a1 --- /dev/null +++ b/.changeset/few-berries-tickle.md @@ -0,0 +1,21 @@ +--- +"create-mud": patch +"@latticexyz/cli": major +"@latticexyz/common": major +"@latticexyz/store": patch +"@latticexyz/world": patch +"@latticexyz/world-modules": patch +--- + +Moved table ID and field layout constants in code-generated table libraries from the file level into the library, for clearer access and cleaner imports. + +```diff +-import { SomeTable, SomeTableTableId } from "./codegen/tables/SomeTable.sol"; ++import { SomeTable } from "./codegen/tables/SomeTable.sol"; + +-console.log(SomeTableTableId); ++console.log(SomeTable._tableId); + +-console.log(SomeTable.getFieldLayout()); ++console.log(SomeTable._fieldLayout); +``` diff --git a/e2e/packages/contracts/src/codegen/index.sol b/e2e/packages/contracts/src/codegen/index.sol index 409d155bf2..8de689e3ae 100644 --- a/e2e/packages/contracts/src/codegen/index.sol +++ b/e2e/packages/contracts/src/codegen/index.sol @@ -3,9 +3,9 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -import { Number, NumberTableId } from "./tables/Number.sol"; -import { Vector, VectorData, VectorTableId } from "./tables/Vector.sol"; -import { NumberList, NumberListTableId } from "./tables/NumberList.sol"; -import { Multi, MultiData, MultiTableId } from "./tables/Multi.sol"; -import { Position, PositionTableId } from "./tables/Position.sol"; -import { StaticArray, StaticArrayTableId } from "./tables/StaticArray.sol"; +import { Number } from "./tables/Number.sol"; +import { Vector, VectorData } from "./tables/Vector.sol"; +import { NumberList } from "./tables/NumberList.sol"; +import { Multi, MultiData } from "./tables/Multi.sol"; +import { Position } from "./tables/Position.sol"; +import { StaticArray } from "./tables/StaticArray.sol"; diff --git a/e2e/packages/contracts/src/codegen/tables/Multi.sol b/e2e/packages/contracts/src/codegen/tables/Multi.sol index 99a5c7d699..50bba4cddf 100644 --- a/e2e/packages/contracts/src/codegen/tables/Multi.sol +++ b/e2e/packages/contracts/src/codegen/tables/Multi.sol @@ -19,27 +19,17 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Multi", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x746200000000000000000000000000004d756c74690000000000000000000000); -ResourceId constant MultiTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0021020020010000000000000000000000000000000000000000000000000000 -); - struct MultiData { int256 num; bool value; } library Multi { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Multi", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x746200000000000000000000000000004d756c74690000000000000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0021020020010000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/e2e/packages/contracts/src/codegen/tables/Number.sol b/e2e/packages/contracts/src/codegen/tables/Number.sol index 39654130c2..c66bfdf66a 100644 --- a/e2e/packages/contracts/src/codegen/tables/Number.sol +++ b/e2e/packages/contracts/src/codegen/tables/Number.sol @@ -19,22 +19,12 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Number", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x746200000000000000000000000000004e756d62657200000000000000000000); -ResourceId constant NumberTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0004010004000000000000000000000000000000000000000000000000000000 -); - library Number { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Number", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x746200000000000000000000000000004e756d62657200000000000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0004010004000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/e2e/packages/contracts/src/codegen/tables/NumberList.sol b/e2e/packages/contracts/src/codegen/tables/NumberList.sol index 426f0600cf..a604f3668a 100644 --- a/e2e/packages/contracts/src/codegen/tables/NumberList.sol +++ b/e2e/packages/contracts/src/codegen/tables/NumberList.sol @@ -19,22 +19,12 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "NumberList", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x746200000000000000000000000000004e756d6265724c697374000000000000); -ResourceId constant NumberListTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0000000100000000000000000000000000000000000000000000000000000000 -); - library NumberList { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "NumberList", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x746200000000000000000000000000004e756d6265724c697374000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/e2e/packages/contracts/src/codegen/tables/Position.sol b/e2e/packages/contracts/src/codegen/tables/Position.sol index 7a724cc2a1..495d92554e 100644 --- a/e2e/packages/contracts/src/codegen/tables/Position.sol +++ b/e2e/packages/contracts/src/codegen/tables/Position.sol @@ -19,22 +19,12 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Position", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000506f736974696f6e0000000000000000); -ResourceId constant PositionTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0014010014000000000000000000000000000000000000000000000000000000 -); - library Position { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Position", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000506f736974696f6e0000000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/e2e/packages/contracts/src/codegen/tables/StaticArray.sol b/e2e/packages/contracts/src/codegen/tables/StaticArray.sol index 95a942ff05..7b89a2b2c9 100644 --- a/e2e/packages/contracts/src/codegen/tables/StaticArray.sol +++ b/e2e/packages/contracts/src/codegen/tables/StaticArray.sol @@ -19,22 +19,12 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "StaticArray", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000053746174696341727261790000000000); -ResourceId constant StaticArrayTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0000000100000000000000000000000000000000000000000000000000000000 -); - library StaticArray { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "StaticArray", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000053746174696341727261790000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/e2e/packages/contracts/src/codegen/tables/Vector.sol b/e2e/packages/contracts/src/codegen/tables/Vector.sol index eb09153136..a077935f6d 100644 --- a/e2e/packages/contracts/src/codegen/tables/Vector.sol +++ b/e2e/packages/contracts/src/codegen/tables/Vector.sol @@ -19,27 +19,17 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Vector", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000566563746f7200000000000000000000); -ResourceId constant VectorTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0008020004040000000000000000000000000000000000000000000000000000 -); - struct VectorData { int32 x; int32 y; } library Vector { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Vector", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000566563746f7200000000000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0008020004040000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/e2e/packages/contracts/src/systems/NumberListSystem.sol b/e2e/packages/contracts/src/systems/NumberListSystem.sol index a36fe62521..aa07345160 100644 --- a/e2e/packages/contracts/src/systems/NumberListSystem.sol +++ b/e2e/packages/contracts/src/systems/NumberListSystem.sol @@ -4,7 +4,7 @@ pragma solidity >=0.8.24; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; import { System } from "@latticexyz/world/src/System.sol"; -import { NumberList, NumberListTableId } from "../codegen/index.sol"; +import { NumberList } from "../codegen/index.sol"; contract NumberListSystem is System { function set(uint32[] memory list) public { @@ -22,7 +22,7 @@ contract NumberListSystem is System { } bytes32[] memory emptyKey; - StoreSwitch.pushToDynamicField(NumberListTableId, emptyKey, 0, EncodeArray.encode(list)); + StoreSwitch.pushToDynamicField(NumberList._tableId, emptyKey, 0, EncodeArray.encode(list)); } function pop() public { diff --git a/examples/minimal/packages/contracts/script/PostDeploy.s.sol b/examples/minimal/packages/contracts/script/PostDeploy.s.sol index 9a760231f0..f39faa8fed 100644 --- a/examples/minimal/packages/contracts/script/PostDeploy.s.sol +++ b/examples/minimal/packages/contracts/script/PostDeploy.s.sol @@ -7,7 +7,7 @@ import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol"; import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol"; -import { MessageTable, MessageTableTableId } from "../src/codegen/index.sol"; +import { MessageTable } from "../src/codegen/index.sol"; import { IWorld } from "../src/codegen/world/IWorld.sol"; import { ChatNamespacedSystem } from "../src/systems/ChatNamespacedSystem.sol"; @@ -36,7 +36,7 @@ contract PostDeploy is Script { IWorld(worldAddress).registerFunctionSelector(systemId, "sendMessage(string)"); // Grant this system access to MessageTable - IWorld(worldAddress).grantAccess(MessageTableTableId, address(chatNamespacedSystem)); + IWorld(worldAddress).grantAccess(MessageTable._tableId, address(chatNamespacedSystem)); // ------------------ EXAMPLES ------------------ diff --git a/examples/minimal/packages/contracts/src/codegen/index.sol b/examples/minimal/packages/contracts/src/codegen/index.sol index ac4baf9ad1..172a4254f3 100644 --- a/examples/minimal/packages/contracts/src/codegen/index.sol +++ b/examples/minimal/packages/contracts/src/codegen/index.sol @@ -3,6 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -import { CounterTable, CounterTableTableId } from "./tables/CounterTable.sol"; -import { MessageTable, MessageTableTableId } from "./tables/MessageTable.sol"; -import { Inventory, InventoryTableId } from "./tables/Inventory.sol"; +import { CounterTable } from "./tables/CounterTable.sol"; +import { MessageTable } from "./tables/MessageTable.sol"; +import { Inventory } from "./tables/Inventory.sol"; diff --git a/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol b/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol index d3e5442de7..9d9c2e92c8 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol @@ -19,22 +19,12 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "CounterTable", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000436f756e7465725461626c6500000000); -ResourceId constant CounterTableTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0004010004000000000000000000000000000000000000000000000000000000 -); - library CounterTable { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "CounterTable", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000436f756e7465725461626c6500000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0004010004000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol b/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol index 1b5c163695..672732416c 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol @@ -19,22 +19,12 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Inventory", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000496e76656e746f727900000000000000); -ResourceId constant InventoryTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0004010004000000000000000000000000000000000000000000000000000000 -); - library Inventory { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Inventory", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000496e76656e746f727900000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0004010004000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol b/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol index aadbffde7c..177257cdb1 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol @@ -19,22 +19,12 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "MessageTable", typeId: RESOURCE_OFFCHAIN_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x6f7400000000000000000000000000004d6573736167655461626c6500000000); -ResourceId constant MessageTableTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0000000100000000000000000000000000000000000000000000000000000000 -); - library MessageTable { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "MessageTable", typeId: RESOURCE_OFFCHAIN_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x6f7400000000000000000000000000004d6573736167655461626c6500000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/examples/minimal/packages/contracts/test/ChatNamespaced.t.sol b/examples/minimal/packages/contracts/test/ChatNamespaced.t.sol index eaecdb806a..85f7adfbbe 100644 --- a/examples/minimal/packages/contracts/test/ChatNamespaced.t.sol +++ b/examples/minimal/packages/contracts/test/ChatNamespaced.t.sol @@ -7,7 +7,7 @@ import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswith import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; import { IWorld } from "../src/codegen/world/IWorld.sol"; -import { MessageTable, MessageTableTableId } from "../src/codegen/index.sol"; +import { MessageTable } from "../src/codegen/index.sol"; import { IChatNamespacedSystem } from "../src/interfaces/IChatNamespacedSystem.sol"; contract ChatNamespacedTest is MudTest { @@ -16,7 +16,7 @@ contract ChatNamespacedTest is MudTest { string memory value = "test"; vm.expectEmit(true, true, true, true); emit StoreCore.Store_SetRecord( - MessageTableTableId, + MessageTable._tableId, keyTuple, new bytes(0), MessageTable.encodeLengths(value), diff --git a/examples/minimal/packages/contracts/test/CounterTest.t.sol b/examples/minimal/packages/contracts/test/CounterTest.t.sol index 81cfc6df7d..1c26465979 100644 --- a/examples/minimal/packages/contracts/test/CounterTest.t.sol +++ b/examples/minimal/packages/contracts/test/CounterTest.t.sol @@ -6,7 +6,7 @@ import { MudTest } from "@latticexyz/world/test/MudTest.t.sol"; import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol"; import { IWorld } from "../src/codegen/world/IWorld.sol"; -import { CounterTable, CounterTableTableId } from "../src/codegen/index.sol"; +import { CounterTable } from "../src/codegen/index.sol"; contract CounterTest is MudTest { function testWorldExists() public { @@ -32,7 +32,7 @@ contract CounterTest is MudTest { // TODO: re-enable the KeysWithValueModule in mud.config.ts once it supports singleton keys // function testKeysWithValue() public { // uint32 counter = CounterTable.get(); - // bytes32[] memory keysWithValue = getKeysWithValue(CounterTableTableId, CounterTable.encode(counter)); + // bytes32[] memory keysWithValue = getKeysWithValue(CounterTable._tableId, CounterTable.encode(counter)); // assertEq(keysWithValue.length, 1); // } } diff --git a/examples/minimal/packages/contracts/test/StructTest.t.sol b/examples/minimal/packages/contracts/test/StructTest.t.sol index a6789628ef..b57273ff28 100644 --- a/examples/minimal/packages/contracts/test/StructTest.t.sol +++ b/examples/minimal/packages/contracts/test/StructTest.t.sol @@ -6,7 +6,7 @@ import { MudTest } from "@latticexyz/world/test/MudTest.t.sol"; import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol"; import { IWorld } from "../src/codegen/world/IWorld.sol"; -import { CounterTable, CounterTableTableId } from "../src/codegen/index.sol"; +import { CounterTable } from "../src/codegen/index.sol"; import { BytesStruct, StringStruct } from "../src/systems/structs.sol"; contract StructTest is MudTest { diff --git a/examples/multiple-accounts/packages/contracts/src/codegen/index.sol b/examples/multiple-accounts/packages/contracts/src/codegen/index.sol index 0746454b44..5813f4d78d 100644 --- a/examples/multiple-accounts/packages/contracts/src/codegen/index.sol +++ b/examples/multiple-accounts/packages/contracts/src/codegen/index.sol @@ -3,4 +3,4 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -import { LastCall, LastCallData, LastCallTableId } from "./tables/LastCall.sol"; +import { LastCall, LastCallData } from "./tables/LastCall.sol"; diff --git a/examples/multiple-accounts/packages/contracts/src/codegen/tables/LastCall.sol b/examples/multiple-accounts/packages/contracts/src/codegen/tables/LastCall.sol index 63fc9b3fb1..748501c126 100644 --- a/examples/multiple-accounts/packages/contracts/src/codegen/tables/LastCall.sol +++ b/examples/multiple-accounts/packages/contracts/src/codegen/tables/LastCall.sol @@ -19,27 +19,17 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "LastCall", name: "LastCall", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x74624c61737443616c6c0000000000004c61737443616c6c0000000000000000); -ResourceId constant LastCallTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0034020020140000000000000000000000000000000000000000000000000000 -); - struct LastCallData { uint256 callTime; address sender; } library LastCall { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "LastCall", name: "LastCall", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x74624c61737443616c6c0000000000004c61737443616c6c0000000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0034020020140000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/cli/contracts/src/codegen/index.sol b/packages/cli/contracts/src/codegen/index.sol index 80f2b14a6f..a785c0c5bd 100644 --- a/packages/cli/contracts/src/codegen/index.sol +++ b/packages/cli/contracts/src/codegen/index.sol @@ -3,9 +3,9 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -import { Statics, StaticsData, StaticsTableId } from "./tables/Statics.sol"; -import { Dynamics1, Dynamics1Data, Dynamics1TableId } from "./tables/Dynamics1.sol"; -import { Dynamics2, Dynamics2Data, Dynamics2TableId } from "./tables/Dynamics2.sol"; -import { Singleton, SingletonTableId } from "./tables/Singleton.sol"; -import { Offchain, OffchainTableId } from "./tables/Offchain.sol"; -import { UserTyped, UserTypedData, UserTypedTableId } from "./tables/UserTyped.sol"; +import { Statics, StaticsData } from "./tables/Statics.sol"; +import { Dynamics1, Dynamics1Data } from "./tables/Dynamics1.sol"; +import { Dynamics2, Dynamics2Data } from "./tables/Dynamics2.sol"; +import { Singleton } from "./tables/Singleton.sol"; +import { Offchain } from "./tables/Offchain.sol"; +import { UserTyped, UserTypedData } from "./tables/UserTyped.sol"; diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol index 7267718a35..cadade4bc2 100644 --- a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol +++ b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol @@ -19,14 +19,6 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Dynamics1", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000044796e616d6963733100000000000000); -ResourceId constant Dynamics1TableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0000000500000000000000000000000000000000000000000000000000000000 -); - struct Dynamics1Data { bytes32[1] staticB32; int32[2] staticI32; @@ -36,13 +28,11 @@ struct Dynamics1Data { } library Dynamics1 { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Dynamics1", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000044796e616d6963733100000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0000000500000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol index 4c877d16a6..56da3c6bce 100644 --- a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol +++ b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol @@ -19,14 +19,6 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Dynamics2", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000044796e616d6963733200000000000000); -ResourceId constant Dynamics2TableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0000000300000000000000000000000000000000000000000000000000000000 -); - struct Dynamics2Data { uint64[] u64; string str; @@ -34,13 +26,11 @@ struct Dynamics2Data { } library Dynamics2 { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Dynamics2", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000044796e616d6963733200000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0000000300000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/cli/contracts/src/codegen/tables/Offchain.sol b/packages/cli/contracts/src/codegen/tables/Offchain.sol index 7d83afabc0..e5588681ec 100644 --- a/packages/cli/contracts/src/codegen/tables/Offchain.sol +++ b/packages/cli/contracts/src/codegen/tables/Offchain.sol @@ -19,22 +19,12 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Offchain", typeId: RESOURCE_OFFCHAIN_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x6f7400000000000000000000000000004f6666636861696e0000000000000000); -ResourceId constant OffchainTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0020010020000000000000000000000000000000000000000000000000000000 -); - library Offchain { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Offchain", typeId: RESOURCE_OFFCHAIN_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x6f7400000000000000000000000000004f6666636861696e0000000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/cli/contracts/src/codegen/tables/Singleton.sol b/packages/cli/contracts/src/codegen/tables/Singleton.sol index af76be1d8a..b515bb78cf 100644 --- a/packages/cli/contracts/src/codegen/tables/Singleton.sol +++ b/packages/cli/contracts/src/codegen/tables/Singleton.sol @@ -19,22 +19,12 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Singleton", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000053696e676c65746f6e00000000000000); -ResourceId constant SingletonTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0020010320000000000000000000000000000000000000000000000000000000 -); - library Singleton { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Singleton", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000053696e676c65746f6e00000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0020010320000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/cli/contracts/src/codegen/tables/Statics.sol b/packages/cli/contracts/src/codegen/tables/Statics.sol index ef1fcffa55..2f7c7c1a39 100644 --- a/packages/cli/contracts/src/codegen/tables/Statics.sol +++ b/packages/cli/contracts/src/codegen/tables/Statics.sol @@ -22,14 +22,6 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types import { Enum2, Enum1 } from "./../common.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Statics", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000053746174696373000000000000000000); -ResourceId constant StaticsTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x004a060020041014010100000000000000000000000000000000000000000000 -); - struct StaticsData { uint256 v1; int32 v2; @@ -40,13 +32,11 @@ struct StaticsData { } library Statics { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Statics", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000053746174696373000000000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x004a060020041014010100000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/cli/contracts/src/codegen/tables/UserTyped.sol b/packages/cli/contracts/src/codegen/tables/UserTyped.sol index ccb63dbdca..fce2236e2b 100644 --- a/packages/cli/contracts/src/codegen/tables/UserTyped.sol +++ b/packages/cli/contracts/src/codegen/tables/UserTyped.sol @@ -23,14 +23,6 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; import { TestTypeAddress, TestTypeInt64, TestTypeLibrary } from "./../../types.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "UserTyped", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000055736572547970656400000000000000); -ResourceId constant UserTypedTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x004d050014080110200000000000000000000000000000000000000000000000 -); - struct UserTypedData { TestTypeAddress v1; TestTypeInt64 v2; @@ -40,13 +32,11 @@ struct UserTypedData { } library UserTyped { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "UserTyped", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000055736572547970656400000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x004d050014080110200000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/common/src/codegen/render-solidity/common.test.ts b/packages/common/src/codegen/render-solidity/common.test.ts index e51e849b4f..c754c07551 100644 --- a/packages/common/src/codegen/render-solidity/common.test.ts +++ b/packages/common/src/codegen/render-solidity/common.test.ts @@ -60,24 +60,20 @@ describe("renderValueTypeToBytes32", () => { describe("renderTableId", () => { it("returns Solidity code to compute table ID", () => { - expect(renderTableId({ namespace: "somewhere", name: "Player", offchainOnly: false, tableIdName: "PlayerTableId" })) - .toMatchInlineSnapshot(` + expect(renderTableId({ namespace: "somewhere", name: "Player", offchainOnly: false })).toMatchInlineSnapshot(` + " + // Hex below is the result of \`WorldResourceIdLib.encode({ namespace: \\"somewhere\\", name: \\"Player\\", typeId: RESOURCE_TABLE });\` + ResourceId constant _tableId = ResourceId.wrap(0x7462736f6d6577686572650000000000506c6179657200000000000000000000); " - // Hex below is the result of \`WorldResourceIdLib.encode({ namespace: \\"somewhere\\", name: \\"Player\\", typeId: RESOURCE_TABLE });\` - ResourceId constant _tableId = ResourceId.wrap(0x7462736f6d6577686572650000000000506c6179657200000000000000000000); - ResourceId constant PlayerTableId = _tableId; - " - `); + `); }); it("returns Solidity code to compute offchain table ID", () => { - expect(renderTableId({ namespace: "somewhere", name: "Player", offchainOnly: true, tableIdName: "PlayerTableId" })) - .toMatchInlineSnapshot(` + expect(renderTableId({ namespace: "somewhere", name: "Player", offchainOnly: true })).toMatchInlineSnapshot(` + " + // Hex below is the result of \`WorldResourceIdLib.encode({ namespace: \\"somewhere\\", name: \\"Player\\", typeId: RESOURCE_OFFCHAIN_TABLE });\` + ResourceId constant _tableId = ResourceId.wrap(0x6f74736f6d6577686572650000000000506c6179657200000000000000000000); " - // Hex below is the result of \`WorldResourceIdLib.encode({ namespace: \\"somewhere\\", name: \\"Player\\", typeId: RESOURCE_OFFCHAIN_TABLE });\` - ResourceId constant _tableId = ResourceId.wrap(0x6f74736f6d6577686572650000000000506c6179657200000000000000000000); - ResourceId constant PlayerTableId = _tableId; - " - `); + `); }); }); diff --git a/packages/common/src/codegen/render-solidity/common.ts b/packages/common/src/codegen/render-solidity/common.ts index ea985a0146..0813f25160 100644 --- a/packages/common/src/codegen/render-solidity/common.ts +++ b/packages/common/src/codegen/render-solidity/common.ts @@ -204,15 +204,14 @@ export function renderWithFieldSuffix( } /** - * Renders `_tableId` variable definition and initialization, and its alias which uses the provided `tableIdName`. - * @param param0 static resource data needed to construct the table id + * Renders `_tableId` definition of the given table. + * @param param0 static resource data needed to construct the table ID */ export function renderTableId({ namespace, name, offchainOnly, - tableIdName, -}: Pick): string { +}: Pick): string { return ` // Hex below is the result of \`WorldResourceIdLib.encode({ namespace: ${JSON.stringify( namespace @@ -222,7 +221,6 @@ export function renderTableId({ namespace, name, })}); - ResourceId constant ${tableIdName} = _tableId; `; } diff --git a/packages/common/src/codegen/render-solidity/types.ts b/packages/common/src/codegen/render-solidity/types.ts index f395edcaae..e61da22518 100644 --- a/packages/common/src/codegen/render-solidity/types.ts +++ b/packages/common/src/codegen/render-solidity/types.ts @@ -12,8 +12,6 @@ export interface RelativeImportDatum { export type ImportDatum = AbsoluteImportDatum | RelativeImportDatum; export interface StaticResourceData { - /** Name of the table id constant to render. */ - tableIdName: string; /** Table namespace string */ namespace: string; /** Table name string */ diff --git a/packages/store/src/StoreCore.sol b/packages/store/src/StoreCore.sol index a7a71dec35..e960b60bea 100644 --- a/packages/store/src/StoreCore.sol +++ b/packages/store/src/StoreCore.sol @@ -9,9 +9,8 @@ import { FieldLayout, FieldLayoutLib } from "./FieldLayout.sol"; import { Schema, SchemaLib } from "./Schema.sol"; import { PackedCounter } from "./PackedCounter.sol"; import { Slice, SliceLib } from "./Slice.sol"; -import { Tables, TablesTableId, ResourceIds, ResourceIdsTableId, StoreHooks, StoreHooksTableId } from "./codegen/index.sol"; -import { _fieldLayout as TablesTableFieldLayout } from "./codegen/tables/Tables.sol"; -import { Store_TableAlreadyExists, Store_TableNotFound, Store_InvalidResourceType, Store_InvalidStaticDataLength, Store_InvalidKeyNamesLength, Store_InvalidSplice, Store_IndexOutOfBounds, Store_InvalidBounds, Store_InvalidValueSchemaStaticLength, Store_InvalidValueSchemaDynamicLength, Store_InvalidFieldNamesLength, Store_InvalidValueSchemaLength } from "./errors.sol"; +import { Tables, ResourceIds, StoreHooks } from "./codegen/index.sol"; +import "./errors.sol"; import { IStoreHook } from "./IStoreHook.sol"; import { StoreSwitch } from "./StoreSwitch.sol"; import { Hook, HookLib } from "./Hook.sol"; @@ -103,30 +102,30 @@ library StoreCore { // Instead, we'll register them manually, writing everything to the `Tables` table first, // then the `ResourceIds` table. The logic here ought to be kept in sync with the internals // of the `registerTable` function below. - if (ResourceIds._getExists(TablesTableId)) { - revert Store_TableAlreadyExists(TablesTableId, string(abi.encodePacked(TablesTableId))); + if (ResourceIds._getExists(Tables._tableId)) { + revert Store_TableAlreadyExists(Tables._tableId, string(abi.encodePacked(Tables._tableId))); } - if (ResourceIds._getExists(ResourceIdsTableId)) { - revert Store_TableAlreadyExists(ResourceIdsTableId, string(abi.encodePacked(ResourceIdsTableId))); + if (ResourceIds._getExists(ResourceIds._tableId)) { + revert Store_TableAlreadyExists(ResourceIds._tableId, string(abi.encodePacked(ResourceIds._tableId))); } Tables._set( - TablesTableId, - Tables.getFieldLayout(), + Tables._tableId, + Tables._fieldLayout, Tables.getKeySchema(), Tables.getValueSchema(), abi.encode(Tables.getKeyNames()), abi.encode(Tables.getFieldNames()) ); Tables._set( - ResourceIdsTableId, - ResourceIds.getFieldLayout(), + ResourceIds._tableId, + ResourceIds._fieldLayout, ResourceIds.getKeySchema(), ResourceIds.getValueSchema(), abi.encode(ResourceIds.getKeyNames()), abi.encode(ResourceIds.getFieldNames()) ); - ResourceIds._setExists(TablesTableId, true); - ResourceIds._setExists(ResourceIdsTableId, true); + ResourceIds._setExists(Tables._tableId, true); + ResourceIds._setExists(ResourceIds._tableId, true); // Now we can register the rest of the core tables as regular tables. StoreHooks.register(); @@ -147,13 +146,13 @@ library StoreCore { // Explicit check for the Tables table to solve the bootstraping issue // of the Tables table not having a field layout before it is registered // since the field layout is stored in the Tables table. - if (ResourceId.unwrap(tableId) == ResourceId.unwrap(TablesTableId)) { - return TablesTableFieldLayout; + if (ResourceId.unwrap(tableId) == ResourceId.unwrap(Tables._tableId)) { + return Tables._fieldLayout; } return FieldLayout.wrap( Storage.loadField({ - storagePointer: StoreCoreInternal._getStaticDataLocation(TablesTableId, ResourceId.unwrap(tableId)), + storagePointer: StoreCoreInternal._getStaticDataLocation(Tables._tableId, ResourceId.unwrap(tableId)), length: 32, offset: 0 }) @@ -297,7 +296,7 @@ library StoreCore { * @param hookAddress The address of the hook to unregister. */ function unregisterStoreHook(ResourceId tableId, IStoreHook hookAddress) internal { - HookLib.filterListByAddress(StoreHooksTableId, tableId, address(hookAddress)); + HookLib.filterListByAddress(StoreHooks._tableId, tableId, address(hookAddress)); } /************************************************************************ diff --git a/packages/store/src/codegen/index.sol b/packages/store/src/codegen/index.sol index e627a7ed26..062209e3db 100644 --- a/packages/store/src/codegen/index.sol +++ b/packages/store/src/codegen/index.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -import { StoreHooks, StoreHooksTableId } from "./tables/StoreHooks.sol"; -import { Tables, TablesData, TablesTableId } from "./tables/Tables.sol"; -import { ResourceIds, ResourceIdsTableId } from "./tables/ResourceIds.sol"; +import { StoreHooks } from "./tables/StoreHooks.sol"; +import { Tables, TablesData } from "./tables/Tables.sol"; +import { ResourceIds } from "./tables/ResourceIds.sol"; import { Hooks } from "./tables/Hooks.sol"; diff --git a/packages/store/src/codegen/tables/Hooks.sol b/packages/store/src/codegen/tables/Hooks.sol index 117ee33579..42497a7eb6 100644 --- a/packages/store/src/codegen/tables/Hooks.sol +++ b/packages/store/src/codegen/tables/Hooks.sol @@ -22,18 +22,9 @@ import { ResourceId } from "../../ResourceId.sol"; // Import user types import { ResourceId } from "./../../ResourceId.sol"; -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0000000100000000000000000000000000000000000000000000000000000000 -); - library Hooks { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/store/src/codegen/tables/ResourceIds.sol b/packages/store/src/codegen/tables/ResourceIds.sol index 555c16cde4..ce694bf31a 100644 --- a/packages/store/src/codegen/tables/ResourceIds.sol +++ b/packages/store/src/codegen/tables/ResourceIds.sol @@ -22,22 +22,12 @@ import { ResourceId } from "../../ResourceId.sol"; // Import user types import { ResourceId } from "./../../ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "store", name: "ResourceIds", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x746273746f72650000000000000000005265736f757263654964730000000000); -ResourceId constant ResourceIdsTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0001010001000000000000000000000000000000000000000000000000000000 -); - library ResourceIds { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "store", name: "ResourceIds", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x746273746f72650000000000000000005265736f757263654964730000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0001010001000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/store/src/codegen/tables/StoreHooks.sol b/packages/store/src/codegen/tables/StoreHooks.sol index 10917219c9..953cd67180 100644 --- a/packages/store/src/codegen/tables/StoreHooks.sol +++ b/packages/store/src/codegen/tables/StoreHooks.sol @@ -22,22 +22,12 @@ import { ResourceId } from "../../ResourceId.sol"; // Import user types import { ResourceId } from "./../../ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "store", name: "StoreHooks", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x746273746f726500000000000000000053746f7265486f6f6b73000000000000); -ResourceId constant StoreHooksTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0000000100000000000000000000000000000000000000000000000000000000 -); - library StoreHooks { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "store", name: "StoreHooks", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x746273746f726500000000000000000053746f7265486f6f6b73000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/store/src/codegen/tables/Tables.sol b/packages/store/src/codegen/tables/Tables.sol index 17e0190294..b4c6d0b86c 100644 --- a/packages/store/src/codegen/tables/Tables.sol +++ b/packages/store/src/codegen/tables/Tables.sol @@ -24,14 +24,6 @@ import { ResourceId } from "./../../ResourceId.sol"; import { FieldLayout } from "./../../FieldLayout.sol"; import { Schema } from "./../../Schema.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "store", name: "Tables", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x746273746f72650000000000000000005461626c657300000000000000000000); -ResourceId constant TablesTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0060030220202000000000000000000000000000000000000000000000000000 -); - struct TablesData { FieldLayout fieldLayout; Schema keySchema; @@ -41,13 +33,11 @@ struct TablesData { } library Tables { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "store", name: "Tables", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x746273746f72650000000000000000005461626c657300000000000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0060030220202000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/store/test/KeyEncoding.t.sol b/packages/store/test/KeyEncoding.t.sol index 0f72fe9e48..2215706233 100644 --- a/packages/store/test/KeyEncoding.t.sol +++ b/packages/store/test/KeyEncoding.t.sol @@ -8,7 +8,7 @@ import { FieldLayout } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; import { StoreMock } from "./StoreMock.sol"; -import { KeyEncoding, KeyEncodingTableId } from "./codegen/index.sol"; +import { KeyEncoding } from "./codegen/index.sol"; import { ExampleEnum } from "./codegen/common.sol"; contract KeyEncodingTest is Test, GasReporter, StoreMock { @@ -17,8 +17,8 @@ contract KeyEncodingTest is Test, GasReporter, StoreMock { KeyEncoding.register(); endGasReport(); - FieldLayout registeredFieldLayout = StoreCore.getFieldLayout(KeyEncodingTableId); - FieldLayout declaredFieldLayout = KeyEncoding.getFieldLayout(); + FieldLayout registeredFieldLayout = StoreCore.getFieldLayout(KeyEncoding._tableId); + FieldLayout declaredFieldLayout = KeyEncoding._fieldLayout; assertEq(keccak256(abi.encode(registeredFieldLayout)), keccak256(abi.encode(declaredFieldLayout))); } @@ -26,7 +26,7 @@ contract KeyEncodingTest is Test, GasReporter, StoreMock { function testRegisterAndGetSchema() public { KeyEncoding.register(); - Schema registeredSchema = StoreCore.getValueSchema(KeyEncodingTableId); + Schema registeredSchema = StoreCore.getValueSchema(KeyEncoding._tableId); Schema declaredSchema = KeyEncoding.getValueSchema(); assertEq(keccak256(abi.encode(registeredSchema)), keccak256(abi.encode(declaredSchema))); diff --git a/packages/store/test/Mixed.t.sol b/packages/store/test/Mixed.t.sol index c060604df5..1318a37082 100644 --- a/packages/store/test/Mixed.t.sol +++ b/packages/store/test/Mixed.t.sol @@ -9,7 +9,7 @@ import { FieldLayout } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; import { PackedCounter } from "../src/PackedCounter.sol"; -import { Mixed, MixedData, MixedTableId } from "./codegen/index.sol"; +import { Mixed, MixedData } from "./codegen/index.sol"; contract MixedTest is Test, GasReporter, StoreMock { MixedData private testMixed; @@ -26,14 +26,14 @@ contract MixedTest is Test, GasReporter, StoreMock { } function testRegisterAndGetFieldLayout() public { - FieldLayout registeredFieldLayout = StoreCore.getFieldLayout(MixedTableId); - FieldLayout declaredFieldLayout = Mixed.getFieldLayout(); + FieldLayout registeredFieldLayout = StoreCore.getFieldLayout(Mixed._tableId); + FieldLayout declaredFieldLayout = Mixed._fieldLayout; assertEq(keccak256(abi.encode(registeredFieldLayout)), keccak256(abi.encode(declaredFieldLayout))); } function testRegisterAndGetSchema() public { - Schema registeredSchema = StoreCore.getValueSchema(MixedTableId); + Schema registeredSchema = StoreCore.getValueSchema(Mixed._tableId); Schema declaredSchema = Mixed.getValueSchema(); assertEq(keccak256(abi.encode(registeredSchema)), keccak256(abi.encode(declaredSchema))); diff --git a/packages/store/test/StoreCore.t.sol b/packages/store/test/StoreCore.t.sol index 2aa63add03..4928b334d3 100644 --- a/packages/store/test/StoreCore.t.sol +++ b/packages/store/test/StoreCore.t.sol @@ -15,7 +15,7 @@ import "../src/errors.sol"; import { IStore } from "../src/IStore.sol"; import { StoreSwitch } from "../src/StoreSwitch.sol"; import { IStoreHook } from "../src/IStoreHook.sol"; -import { Tables, ResourceIds, TablesTableId } from "../src/codegen/index.sol"; +import { Tables, ResourceIds } from "../src/codegen/index.sol"; import { ResourceId, ResourceIdLib } from "../src/ResourceId.sol"; import { RESOURCE_TABLE, RESOURCE_OFFCHAIN_TABLE } from "../src/storeResourceTypes.sol"; import { FieldLayoutEncodeHelper } from "./FieldLayoutEncodeHelper.sol"; @@ -82,7 +82,7 @@ contract StoreCoreTest is Test, StoreMock { keyTuple[0] = ResourceId.unwrap(tableId); vm.expectEmit(true, true, true, true); emit Store_SetRecord( - TablesTableId, + Tables._tableId, keyTuple, Tables.encodeStatic(fieldLayout, keySchema, valueSchema), Tables.encodeLengths(abi.encode(keyNames), abi.encode(fieldNames)), diff --git a/packages/store/test/Vector2.t.sol b/packages/store/test/Vector2.t.sol index c07cb1f0d0..d1b9db9131 100644 --- a/packages/store/test/Vector2.t.sol +++ b/packages/store/test/Vector2.t.sol @@ -8,7 +8,7 @@ import { StoreMock } from "../test/StoreMock.sol"; import { FieldLayout } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; -import { Vector2, Vector2Data, Vector2TableId } from "./codegen/index.sol"; +import { Vector2, Vector2Data } from "./codegen/index.sol"; contract Vector2Test is Test, GasReporter, StoreMock { function testRegisterAndGetFieldLayout() public { @@ -16,8 +16,8 @@ contract Vector2Test is Test, GasReporter, StoreMock { Vector2.register(); endGasReport(); - FieldLayout registeredFieldLayout = StoreCore.getFieldLayout(Vector2TableId); - FieldLayout declaredFieldLayout = Vector2.getFieldLayout(); + FieldLayout registeredFieldLayout = StoreCore.getFieldLayout(Vector2._tableId); + FieldLayout declaredFieldLayout = Vector2._fieldLayout; assertEq(FieldLayout.unwrap(registeredFieldLayout), FieldLayout.unwrap(declaredFieldLayout)); } @@ -25,7 +25,7 @@ contract Vector2Test is Test, GasReporter, StoreMock { function testRegisterAndGetSchema() public { Vector2.register(); - Schema registeredSchema = StoreCore.getValueSchema(Vector2TableId); + Schema registeredSchema = StoreCore.getValueSchema(Vector2._tableId); Schema declaredSchema = Vector2.getValueSchema(); assertEq(Schema.unwrap(registeredSchema), Schema.unwrap(declaredSchema)); diff --git a/packages/store/test/codegen/index.sol b/packages/store/test/codegen/index.sol index a37fcf0edf..77c2b35159 100644 --- a/packages/store/test/codegen/index.sol +++ b/packages/store/test/codegen/index.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -import { Callbacks, CallbacksTableId } from "./tables/Callbacks.sol"; -import { Mixed, MixedData, MixedTableId } from "./tables/Mixed.sol"; -import { Vector2, Vector2Data, Vector2TableId } from "./tables/Vector2.sol"; -import { KeyEncoding, KeyEncodingTableId } from "./tables/KeyEncoding.sol"; +import { Callbacks } from "./tables/Callbacks.sol"; +import { Mixed, MixedData } from "./tables/Mixed.sol"; +import { Vector2, Vector2Data } from "./tables/Vector2.sol"; +import { KeyEncoding } from "./tables/KeyEncoding.sol"; diff --git a/packages/store/test/codegen/tables/Callbacks.sol b/packages/store/test/codegen/tables/Callbacks.sol index b69a323a2c..1fe189f32d 100644 --- a/packages/store/test/codegen/tables/Callbacks.sol +++ b/packages/store/test/codegen/tables/Callbacks.sol @@ -19,22 +19,12 @@ import { Schema, SchemaLib } from "../../../src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "../../../src/PackedCounter.sol"; import { ResourceId } from "../../../src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "store", name: "Callbacks", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x746273746f726500000000000000000043616c6c6261636b7300000000000000); -ResourceId constant CallbacksTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0000000100000000000000000000000000000000000000000000000000000000 -); - library Callbacks { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "store", name: "Callbacks", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x746273746f726500000000000000000043616c6c6261636b7300000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/store/test/codegen/tables/KeyEncoding.sol b/packages/store/test/codegen/tables/KeyEncoding.sol index ecdf0b260b..2ed7bbfcc0 100644 --- a/packages/store/test/codegen/tables/KeyEncoding.sol +++ b/packages/store/test/codegen/tables/KeyEncoding.sol @@ -22,22 +22,12 @@ import { ResourceId } from "../../../src/ResourceId.sol"; // Import user types import { ExampleEnum } from "./../common.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "store", name: "KeyEncoding", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x746273746f72650000000000000000004b6579456e636f64696e670000000000); -ResourceId constant KeyEncodingTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0001010001000000000000000000000000000000000000000000000000000000 -); - library KeyEncoding { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "store", name: "KeyEncoding", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x746273746f72650000000000000000004b6579456e636f64696e670000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0001010001000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/store/test/codegen/tables/Mixed.sol b/packages/store/test/codegen/tables/Mixed.sol index 57a7977e55..62f6a17a5c 100644 --- a/packages/store/test/codegen/tables/Mixed.sol +++ b/packages/store/test/codegen/tables/Mixed.sol @@ -19,14 +19,6 @@ import { Schema, SchemaLib } from "../../../src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "../../../src/PackedCounter.sol"; import { ResourceId } from "../../../src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "store", name: "Mixed", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x746273746f72650000000000000000004d697865640000000000000000000000); -ResourceId constant MixedTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0014020204100000000000000000000000000000000000000000000000000000 -); - struct MixedData { uint32 u32; uint128 u128; @@ -35,13 +27,11 @@ struct MixedData { } library Mixed { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "store", name: "Mixed", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x746273746f72650000000000000000004d697865640000000000000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0014020204100000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/store/test/codegen/tables/Vector2.sol b/packages/store/test/codegen/tables/Vector2.sol index 687db88179..d2e12843ba 100644 --- a/packages/store/test/codegen/tables/Vector2.sol +++ b/packages/store/test/codegen/tables/Vector2.sol @@ -19,27 +19,17 @@ import { Schema, SchemaLib } from "../../../src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "../../../src/PackedCounter.sol"; import { ResourceId } from "../../../src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "store", name: "Vector2", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x746273746f7265000000000000000000566563746f7232000000000000000000); -ResourceId constant Vector2TableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0008020004040000000000000000000000000000000000000000000000000000 -); - struct Vector2Data { uint32 x; uint32 y; } library Vector2 { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "store", name: "Vector2", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x746273746f7265000000000000000000566563746f7232000000000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0008020004040000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/store/ts/codegen/renderTable.ts b/packages/store/ts/codegen/renderTable.ts index 9bcd9fa05b..2228021c26 100644 --- a/packages/store/ts/codegen/renderTable.ts +++ b/packages/store/ts/codegen/renderTable.ts @@ -65,10 +65,6 @@ export function renderTable(options: RenderTableOptions) { : "" } - ${staticResourceData ? renderTableId(staticResourceData) : ""} - - ${renderFieldLayout(fields)} - ${ !structName ? "" @@ -80,13 +76,9 @@ export function renderTable(options: RenderTableOptions) { } library ${libraryName} { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + ${staticResourceData ? renderTableId(staticResourceData) : ""} + + ${renderFieldLayout(fields)} /** * @notice Get the table's key schema. diff --git a/packages/store/ts/codegen/renderTableIndex.ts b/packages/store/ts/codegen/renderTableIndex.ts index 56c8be6376..1bb5a990f5 100644 --- a/packages/store/ts/codegen/renderTableIndex.ts +++ b/packages/store/ts/codegen/renderTableIndex.ts @@ -10,10 +10,9 @@ export function renderTableIndex(options: TableOptions[]) { return ` ${renderedSolidityHeader} - ${renderList(options, ({ outputPath, tableName, renderOptions: { structName, staticResourceData } }) => { + ${renderList(options, ({ outputPath, tableName, renderOptions: { structName } }) => { const imports = [tableName]; if (structName) imports.push(structName); - if (staticResourceData) imports.push(staticResourceData.tableIdName); return `import { ${imports.join(", ")} } from "./${posixPath(outputPath)}";`; })} diff --git a/packages/store/ts/codegen/tableOptions.ts b/packages/store/ts/codegen/tableOptions.ts index ce8425b349..b46b24d3d1 100644 --- a/packages/store/ts/codegen/tableOptions.ts +++ b/packages/store/ts/codegen/tableOptions.ts @@ -84,7 +84,6 @@ export function getTableOptions( const staticResourceData = tableData.tableIdArgument ? undefined : { - tableIdName: tableName + "TableId", namespace: config.namespace, name: tableData.name, offchainOnly: tableData.offchainOnly, diff --git a/packages/world-modules/src/index.sol b/packages/world-modules/src/index.sol index 3602fdb1bd..138d5a9e37 100644 --- a/packages/world-modules/src/index.sol +++ b/packages/world-modules/src/index.sol @@ -4,12 +4,12 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ import { KeysWithValue } from "./modules/keyswithvalue/tables/KeysWithValue.sol"; -import { KeysInTable, KeysInTableData, KeysInTableTableId } from "./modules/keysintable/tables/KeysInTable.sol"; -import { UsedKeysIndex, UsedKeysIndexTableId } from "./modules/keysintable/tables/UsedKeysIndex.sol"; +import { KeysInTable, KeysInTableData } from "./modules/keysintable/tables/KeysInTable.sol"; +import { UsedKeysIndex } from "./modules/keysintable/tables/UsedKeysIndex.sol"; import { UniqueEntity } from "./modules/uniqueentity/tables/UniqueEntity.sol"; -import { CallboundDelegations, CallboundDelegationsTableId } from "./modules/std-delegations/tables/CallboundDelegations.sol"; -import { SystemboundDelegations, SystemboundDelegationsTableId } from "./modules/std-delegations/tables/SystemboundDelegations.sol"; -import { TimeboundDelegations, TimeboundDelegationsTableId } from "./modules/std-delegations/tables/TimeboundDelegations.sol"; +import { CallboundDelegations } from "./modules/std-delegations/tables/CallboundDelegations.sol"; +import { SystemboundDelegations } from "./modules/std-delegations/tables/SystemboundDelegations.sol"; +import { TimeboundDelegations } from "./modules/std-delegations/tables/TimeboundDelegations.sol"; import { PuppetRegistry } from "./modules/puppet/tables/PuppetRegistry.sol"; import { Balances } from "./modules/tokens/tables/Balances.sol"; import { ERC20Metadata, ERC20MetadataData } from "./modules/erc20-puppet/tables/ERC20Metadata.sol"; diff --git a/packages/world-modules/src/modules/erc20-puppet/tables/Allowances.sol b/packages/world-modules/src/modules/erc20-puppet/tables/Allowances.sol index e803d156a2..df8bb8bd19 100644 --- a/packages/world-modules/src/modules/erc20-puppet/tables/Allowances.sol +++ b/packages/world-modules/src/modules/erc20-puppet/tables/Allowances.sol @@ -19,18 +19,9 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0020010020000000000000000000000000000000000000000000000000000000 -); - library Allowances { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/src/modules/erc20-puppet/tables/ERC20Metadata.sol b/packages/world-modules/src/modules/erc20-puppet/tables/ERC20Metadata.sol index 2786f6afcf..45184db902 100644 --- a/packages/world-modules/src/modules/erc20-puppet/tables/ERC20Metadata.sol +++ b/packages/world-modules/src/modules/erc20-puppet/tables/ERC20Metadata.sol @@ -19,10 +19,6 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0001010201000000000000000000000000000000000000000000000000000000 -); - struct ERC20MetadataData { uint8 decimals; string name; @@ -30,13 +26,8 @@ struct ERC20MetadataData { } library ERC20Metadata { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0001010201000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/src/modules/erc20-puppet/tables/ERC20Registry.sol b/packages/world-modules/src/modules/erc20-puppet/tables/ERC20Registry.sol index a257de1880..01e662c28c 100644 --- a/packages/world-modules/src/modules/erc20-puppet/tables/ERC20Registry.sol +++ b/packages/world-modules/src/modules/erc20-puppet/tables/ERC20Registry.sol @@ -22,18 +22,9 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0014010014000000000000000000000000000000000000000000000000000000 -); - library ERC20Registry { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/src/modules/erc20-puppet/tables/TotalSupply.sol b/packages/world-modules/src/modules/erc20-puppet/tables/TotalSupply.sol index eaf6762370..8a35ea2be2 100644 --- a/packages/world-modules/src/modules/erc20-puppet/tables/TotalSupply.sol +++ b/packages/world-modules/src/modules/erc20-puppet/tables/TotalSupply.sol @@ -19,18 +19,9 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0020010020000000000000000000000000000000000000000000000000000000 -); - library TotalSupply { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/src/modules/erc721-puppet/tables/ERC721Metadata.sol b/packages/world-modules/src/modules/erc721-puppet/tables/ERC721Metadata.sol index 42967867a1..5263ea10d9 100644 --- a/packages/world-modules/src/modules/erc721-puppet/tables/ERC721Metadata.sol +++ b/packages/world-modules/src/modules/erc721-puppet/tables/ERC721Metadata.sol @@ -19,10 +19,6 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0000000300000000000000000000000000000000000000000000000000000000 -); - struct ERC721MetadataData { string name; string symbol; @@ -30,13 +26,8 @@ struct ERC721MetadataData { } library ERC721Metadata { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0000000300000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/src/modules/erc721-puppet/tables/ERC721Registry.sol b/packages/world-modules/src/modules/erc721-puppet/tables/ERC721Registry.sol index 9b1b0b7a46..d3e0c82716 100644 --- a/packages/world-modules/src/modules/erc721-puppet/tables/ERC721Registry.sol +++ b/packages/world-modules/src/modules/erc721-puppet/tables/ERC721Registry.sol @@ -22,18 +22,9 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0014010014000000000000000000000000000000000000000000000000000000 -); - library ERC721Registry { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/src/modules/erc721-puppet/tables/OperatorApproval.sol b/packages/world-modules/src/modules/erc721-puppet/tables/OperatorApproval.sol index f8ed7b9a51..7181b3d755 100644 --- a/packages/world-modules/src/modules/erc721-puppet/tables/OperatorApproval.sol +++ b/packages/world-modules/src/modules/erc721-puppet/tables/OperatorApproval.sol @@ -19,18 +19,9 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0001010001000000000000000000000000000000000000000000000000000000 -); - library OperatorApproval { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0001010001000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/src/modules/erc721-puppet/tables/Owners.sol b/packages/world-modules/src/modules/erc721-puppet/tables/Owners.sol index 9fd9b9d7ac..72ca90268d 100644 --- a/packages/world-modules/src/modules/erc721-puppet/tables/Owners.sol +++ b/packages/world-modules/src/modules/erc721-puppet/tables/Owners.sol @@ -19,18 +19,9 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0014010014000000000000000000000000000000000000000000000000000000 -); - library Owners { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/src/modules/erc721-puppet/tables/TokenApproval.sol b/packages/world-modules/src/modules/erc721-puppet/tables/TokenApproval.sol index 81b050e9cd..fcc3b300be 100644 --- a/packages/world-modules/src/modules/erc721-puppet/tables/TokenApproval.sol +++ b/packages/world-modules/src/modules/erc721-puppet/tables/TokenApproval.sol @@ -19,18 +19,9 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0014010014000000000000000000000000000000000000000000000000000000 -); - library TokenApproval { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/src/modules/erc721-puppet/tables/TokenURI.sol b/packages/world-modules/src/modules/erc721-puppet/tables/TokenURI.sol index 6a93a319da..48253f5983 100644 --- a/packages/world-modules/src/modules/erc721-puppet/tables/TokenURI.sol +++ b/packages/world-modules/src/modules/erc721-puppet/tables/TokenURI.sol @@ -19,18 +19,9 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0000000100000000000000000000000000000000000000000000000000000000 -); - library TokenURI { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/src/modules/keysintable/KeysInTableModule.sol b/packages/world-modules/src/modules/keysintable/KeysInTableModule.sol index d81268304b..a54f2f71e4 100644 --- a/packages/world-modules/src/modules/keysintable/KeysInTableModule.sol +++ b/packages/world-modules/src/modules/keysintable/KeysInTableModule.sol @@ -13,8 +13,8 @@ import { ResourceId, WorldResourceIdInstance } from "@latticexyz/world/src/World import { revertWithBytes } from "@latticexyz/world/src/revertWithBytes.sol"; import { KeysInTableHook } from "./KeysInTableHook.sol"; -import { KeysInTable, KeysInTableTableId } from "./tables/KeysInTable.sol"; -import { UsedKeysIndex, UsedKeysIndexTableId } from "./tables/UsedKeysIndex.sol"; +import { KeysInTable } from "./tables/KeysInTable.sol"; +import { UsedKeysIndex } from "./tables/UsedKeysIndex.sol"; /** * This module deploys a hook that is called when a value is set in the `sourceTableId` @@ -47,14 +47,14 @@ contract KeysInTableModule is Module { bool success; bytes memory returnData; - if (!ResourceIds._getExists(KeysInTableTableId)) { + if (!ResourceIds._getExists(KeysInTable._tableId)) { // Register the tables (success, returnData) = address(world).delegatecall( abi.encodeCall( world.registerTable, ( - KeysInTableTableId, - KeysInTable.getFieldLayout(), + KeysInTable._tableId, + KeysInTable._fieldLayout, KeysInTable.getKeySchema(), KeysInTable.getValueSchema(), KeysInTable.getKeyNames(), @@ -68,8 +68,8 @@ contract KeysInTableModule is Module { abi.encodeCall( world.registerTable, ( - UsedKeysIndexTableId, - UsedKeysIndex.getFieldLayout(), + UsedKeysIndex._tableId, + UsedKeysIndex._fieldLayout, UsedKeysIndex.getKeySchema(), UsedKeysIndex.getValueSchema(), UsedKeysIndex.getKeyNames(), @@ -81,12 +81,12 @@ contract KeysInTableModule is Module { // Grant the hook access to the tables (success, returnData) = address(world).delegatecall( - abi.encodeCall(world.grantAccess, (KeysInTableTableId, address(hook))) + abi.encodeCall(world.grantAccess, (KeysInTable._tableId, address(hook))) ); if (!success) revertWithBytes(returnData); (success, returnData) = address(world).delegatecall( - abi.encodeCall(world.grantAccess, (UsedKeysIndexTableId, address(hook))) + abi.encodeCall(world.grantAccess, (UsedKeysIndex._tableId, address(hook))) ); if (!success) revertWithBytes(returnData); } diff --git a/packages/world-modules/src/modules/keysintable/tables/KeysInTable.sol b/packages/world-modules/src/modules/keysintable/tables/KeysInTable.sol index a2352e77ca..ab3e522f2a 100644 --- a/packages/world-modules/src/modules/keysintable/tables/KeysInTable.sol +++ b/packages/world-modules/src/modules/keysintable/tables/KeysInTable.sol @@ -22,14 +22,6 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "KeysInTable", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x746200000000000000000000000000004b657973496e5461626c650000000000); -ResourceId constant KeysInTableTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0000000500000000000000000000000000000000000000000000000000000000 -); - struct KeysInTableData { bytes32[] keys0; bytes32[] keys1; @@ -39,13 +31,11 @@ struct KeysInTableData { } library KeysInTable { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "KeysInTable", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x746200000000000000000000000000004b657973496e5461626c650000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0000000500000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/src/modules/keysintable/tables/UsedKeysIndex.sol b/packages/world-modules/src/modules/keysintable/tables/UsedKeysIndex.sol index 120728ffec..dde9b764fb 100644 --- a/packages/world-modules/src/modules/keysintable/tables/UsedKeysIndex.sol +++ b/packages/world-modules/src/modules/keysintable/tables/UsedKeysIndex.sol @@ -22,22 +22,12 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "UsedKeysIndex", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000557365644b657973496e646578000000); -ResourceId constant UsedKeysIndexTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0006020001050000000000000000000000000000000000000000000000000000 -); - library UsedKeysIndex { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "UsedKeysIndex", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000557365644b657973496e646578000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0006020001050000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/src/modules/keyswithvalue/KeysWithValueModule.sol b/packages/world-modules/src/modules/keyswithvalue/KeysWithValueModule.sol index 3ee92750a0..1bc943518b 100644 --- a/packages/world-modules/src/modules/keyswithvalue/KeysWithValueModule.sol +++ b/packages/world-modules/src/modules/keyswithvalue/KeysWithValueModule.sol @@ -60,7 +60,7 @@ contract KeysWithValueModule is Module { world.registerTable, ( targetTableId, - KeysWithValue.getFieldLayout(), + KeysWithValue._fieldLayout, KeysWithValue.getKeySchema(), KeysWithValue.getValueSchema(), KeysWithValue.getKeyNames(), diff --git a/packages/world-modules/src/modules/keyswithvalue/tables/KeysWithValue.sol b/packages/world-modules/src/modules/keyswithvalue/tables/KeysWithValue.sol index f8ca13729d..65eb8319e3 100644 --- a/packages/world-modules/src/modules/keyswithvalue/tables/KeysWithValue.sol +++ b/packages/world-modules/src/modules/keyswithvalue/tables/KeysWithValue.sol @@ -19,18 +19,9 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0000000100000000000000000000000000000000000000000000000000000000 -); - library KeysWithValue { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/src/modules/puppet/tables/PuppetRegistry.sol b/packages/world-modules/src/modules/puppet/tables/PuppetRegistry.sol index 2cb94c5370..12e9b8d793 100644 --- a/packages/world-modules/src/modules/puppet/tables/PuppetRegistry.sol +++ b/packages/world-modules/src/modules/puppet/tables/PuppetRegistry.sol @@ -22,18 +22,9 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0014010014000000000000000000000000000000000000000000000000000000 -); - library PuppetRegistry { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/src/modules/std-delegations/tables/CallboundDelegations.sol b/packages/world-modules/src/modules/std-delegations/tables/CallboundDelegations.sol index d5423166a2..e5b6aef1eb 100644 --- a/packages/world-modules/src/modules/std-delegations/tables/CallboundDelegations.sol +++ b/packages/world-modules/src/modules/std-delegations/tables/CallboundDelegations.sol @@ -22,22 +22,12 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "CallboundDelegat", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000043616c6c626f756e6444656c65676174); -ResourceId constant CallboundDelegationsTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0020010020000000000000000000000000000000000000000000000000000000 -); - library CallboundDelegations { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "CallboundDelegat", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000043616c6c626f756e6444656c65676174); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/src/modules/std-delegations/tables/SystemboundDelegations.sol b/packages/world-modules/src/modules/std-delegations/tables/SystemboundDelegations.sol index d02c2b5587..977713c06d 100644 --- a/packages/world-modules/src/modules/std-delegations/tables/SystemboundDelegations.sol +++ b/packages/world-modules/src/modules/std-delegations/tables/SystemboundDelegations.sol @@ -22,22 +22,12 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "SystemboundDeleg", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000053797374656d626f756e6444656c6567); -ResourceId constant SystemboundDelegationsTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0020010020000000000000000000000000000000000000000000000000000000 -); - library SystemboundDelegations { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "SystemboundDeleg", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000053797374656d626f756e6444656c6567); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/src/modules/std-delegations/tables/TimeboundDelegations.sol b/packages/world-modules/src/modules/std-delegations/tables/TimeboundDelegations.sol index 481c8157ec..67a47d4a8d 100644 --- a/packages/world-modules/src/modules/std-delegations/tables/TimeboundDelegations.sol +++ b/packages/world-modules/src/modules/std-delegations/tables/TimeboundDelegations.sol @@ -19,22 +19,12 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "TimeboundDelegat", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000054696d65626f756e6444656c65676174); -ResourceId constant TimeboundDelegationsTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0020010020000000000000000000000000000000000000000000000000000000 -); - library TimeboundDelegations { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "TimeboundDelegat", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000054696d65626f756e6444656c65676174); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/src/modules/tokens/tables/Balances.sol b/packages/world-modules/src/modules/tokens/tables/Balances.sol index ef3b7d0ca9..eff7a7188c 100644 --- a/packages/world-modules/src/modules/tokens/tables/Balances.sol +++ b/packages/world-modules/src/modules/tokens/tables/Balances.sol @@ -19,18 +19,9 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0020010020000000000000000000000000000000000000000000000000000000 -); - library Balances { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/src/modules/uniqueentity/tables/UniqueEntity.sol b/packages/world-modules/src/modules/uniqueentity/tables/UniqueEntity.sol index e00eb767a6..0b8d05c2e1 100644 --- a/packages/world-modules/src/modules/uniqueentity/tables/UniqueEntity.sol +++ b/packages/world-modules/src/modules/uniqueentity/tables/UniqueEntity.sol @@ -19,18 +19,9 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0020010020000000000000000000000000000000000000000000000000000000 -); - library UniqueEntity { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world-modules/test/SystemSwitch.t.sol b/packages/world-modules/test/SystemSwitch.t.sol index 723745dd35..b0017408a6 100644 --- a/packages/world-modules/test/SystemSwitch.t.sol +++ b/packages/world-modules/test/SystemSwitch.t.sol @@ -5,7 +5,7 @@ import { Test } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { Store_TableNotFound } from "@latticexyz/store/src/errors.sol"; -import { ResourceIds, ResourceIdsTableId } from "@latticexyz/store/src/codegen/tables/ResourceIds.sol"; +import { ResourceIds } from "@latticexyz/store/src/codegen/tables/ResourceIds.sol"; import { Schema } from "@latticexyz/store/src/Schema.sol"; import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; @@ -28,7 +28,7 @@ contract EchoSystem is System { } function readTable() public view returns (Schema) { - return StoreCore.getKeySchema(ResourceIdsTableId); + return StoreCore.getKeySchema(ResourceIds._tableId); } function echo(string memory message) public pure returns (string memory) { @@ -222,8 +222,8 @@ contract SystemSwitchTest is Test, GasReporter { vm.expectRevert( abi.encodeWithSelector( Store_TableNotFound.selector, - ResourceIdsTableId, - string(abi.encodePacked(ResourceIdsTableId)) + ResourceIds._tableId, + string(abi.encodePacked(ResourceIds._tableId)) ) ); world.call(systemAId, abi.encodeCall(EchoSystem.call, (systemBId, abi.encodeCall(EchoSystem.readTable, ())))); @@ -269,8 +269,8 @@ contract SystemSwitchTest is Test, GasReporter { vm.expectRevert( abi.encodeWithSelector( Store_TableNotFound.selector, - ResourceIdsTableId, - string(abi.encodePacked(ResourceIdsTableId)) + ResourceIds._tableId, + string(abi.encodePacked(ResourceIds._tableId)) ) ); world.call(systemAId, abi.encodeCall(EchoSystem.call, (systemBId, abi.encodeCall(EchoSystem.readTable, ())))); diff --git a/packages/world/src/codegen/index.sol b/packages/world/src/codegen/index.sol index 9adaf020c9..b00d58a490 100644 --- a/packages/world/src/codegen/index.sol +++ b/packages/world/src/codegen/index.sol @@ -3,15 +3,15 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -import { NamespaceOwner, NamespaceOwnerTableId } from "./tables/NamespaceOwner.sol"; -import { ResourceAccess, ResourceAccessTableId } from "./tables/ResourceAccess.sol"; -import { InstalledModules, InstalledModulesTableId } from "./tables/InstalledModules.sol"; -import { UserDelegationControl, UserDelegationControlTableId } from "./tables/UserDelegationControl.sol"; -import { NamespaceDelegationControl, NamespaceDelegationControlTableId } from "./tables/NamespaceDelegationControl.sol"; -import { Balances, BalancesTableId } from "./tables/Balances.sol"; -import { Systems, SystemsTableId } from "./tables/Systems.sol"; -import { SystemRegistry, SystemRegistryTableId } from "./tables/SystemRegistry.sol"; -import { SystemHooks, SystemHooksTableId } from "./tables/SystemHooks.sol"; -import { FunctionSelectors, FunctionSelectorsTableId } from "./tables/FunctionSelectors.sol"; -import { FunctionSignatures, FunctionSignaturesTableId } from "./tables/FunctionSignatures.sol"; -import { InitModuleAddress, InitModuleAddressTableId } from "./tables/InitModuleAddress.sol"; +import { NamespaceOwner } from "./tables/NamespaceOwner.sol"; +import { ResourceAccess } from "./tables/ResourceAccess.sol"; +import { InstalledModules } from "./tables/InstalledModules.sol"; +import { UserDelegationControl } from "./tables/UserDelegationControl.sol"; +import { NamespaceDelegationControl } from "./tables/NamespaceDelegationControl.sol"; +import { Balances } from "./tables/Balances.sol"; +import { Systems } from "./tables/Systems.sol"; +import { SystemRegistry } from "./tables/SystemRegistry.sol"; +import { SystemHooks } from "./tables/SystemHooks.sol"; +import { FunctionSelectors } from "./tables/FunctionSelectors.sol"; +import { FunctionSignatures } from "./tables/FunctionSignatures.sol"; +import { InitModuleAddress } from "./tables/InitModuleAddress.sol"; diff --git a/packages/world/src/codegen/tables/Balances.sol b/packages/world/src/codegen/tables/Balances.sol index 7e478bb7b3..7e4e814dce 100644 --- a/packages/world/src/codegen/tables/Balances.sol +++ b/packages/world/src/codegen/tables/Balances.sol @@ -22,22 +22,12 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "Balances", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c6400000000000000000042616c616e6365730000000000000000); -ResourceId constant BalancesTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0020010020000000000000000000000000000000000000000000000000000000 -); - library Balances { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "Balances", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c6400000000000000000042616c616e6365730000000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world/src/codegen/tables/FunctionSelectors.sol b/packages/world/src/codegen/tables/FunctionSelectors.sol index f45012ae4d..d5ae335e63 100644 --- a/packages/world/src/codegen/tables/FunctionSelectors.sol +++ b/packages/world/src/codegen/tables/FunctionSelectors.sol @@ -22,22 +22,12 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "FunctionSelector", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c6400000000000000000046756e6374696f6e53656c6563746f72); -ResourceId constant FunctionSelectorsTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0024020020040000000000000000000000000000000000000000000000000000 -); - library FunctionSelectors { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "FunctionSelector", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c6400000000000000000046756e6374696f6e53656c6563746f72); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0024020020040000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world/src/codegen/tables/FunctionSignatures.sol b/packages/world/src/codegen/tables/FunctionSignatures.sol index 227f39e97a..12af2ed59c 100644 --- a/packages/world/src/codegen/tables/FunctionSignatures.sol +++ b/packages/world/src/codegen/tables/FunctionSignatures.sol @@ -19,22 +19,12 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "FunctionSignatur", typeId: RESOURCE_OFFCHAIN_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x6f74776f726c6400000000000000000046756e6374696f6e5369676e61747572); -ResourceId constant FunctionSignaturesTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0000000100000000000000000000000000000000000000000000000000000000 -); - library FunctionSignatures { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "FunctionSignatur", typeId: RESOURCE_OFFCHAIN_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x6f74776f726c6400000000000000000046756e6374696f6e5369676e61747572); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world/src/codegen/tables/InitModuleAddress.sol b/packages/world/src/codegen/tables/InitModuleAddress.sol index b179b181c5..74299d3ff5 100644 --- a/packages/world/src/codegen/tables/InitModuleAddress.sol +++ b/packages/world/src/codegen/tables/InitModuleAddress.sol @@ -19,22 +19,12 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "InitModuleAddres", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c64000000000000000000496e69744d6f64756c65416464726573); -ResourceId constant InitModuleAddressTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0014010014000000000000000000000000000000000000000000000000000000 -); - library InitModuleAddress { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "InitModuleAddres", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c64000000000000000000496e69744d6f64756c65416464726573); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world/src/codegen/tables/InstalledModules.sol b/packages/world/src/codegen/tables/InstalledModules.sol index 1961a8c2a6..f4cabc0079 100644 --- a/packages/world/src/codegen/tables/InstalledModules.sol +++ b/packages/world/src/codegen/tables/InstalledModules.sol @@ -19,22 +19,12 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "InstalledModules", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c64000000000000000000496e7374616c6c65644d6f64756c6573); -ResourceId constant InstalledModulesTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0001010001000000000000000000000000000000000000000000000000000000 -); - library InstalledModules { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "InstalledModules", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c64000000000000000000496e7374616c6c65644d6f64756c6573); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0001010001000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world/src/codegen/tables/NamespaceDelegationControl.sol b/packages/world/src/codegen/tables/NamespaceDelegationControl.sol index aebe7d0930..b197ca6d4c 100644 --- a/packages/world/src/codegen/tables/NamespaceDelegationControl.sol +++ b/packages/world/src/codegen/tables/NamespaceDelegationControl.sol @@ -22,22 +22,12 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "NamespaceDelegat", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c640000000000000000004e616d65737061636544656c65676174); -ResourceId constant NamespaceDelegationControlTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0020010020000000000000000000000000000000000000000000000000000000 -); - library NamespaceDelegationControl { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "NamespaceDelegat", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c640000000000000000004e616d65737061636544656c65676174); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world/src/codegen/tables/NamespaceOwner.sol b/packages/world/src/codegen/tables/NamespaceOwner.sol index e5cb0a3b7b..f8baa78f9a 100644 --- a/packages/world/src/codegen/tables/NamespaceOwner.sol +++ b/packages/world/src/codegen/tables/NamespaceOwner.sol @@ -22,22 +22,12 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "NamespaceOwner", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c640000000000000000004e616d6573706163654f776e65720000); -ResourceId constant NamespaceOwnerTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0014010014000000000000000000000000000000000000000000000000000000 -); - library NamespaceOwner { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "NamespaceOwner", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c640000000000000000004e616d6573706163654f776e65720000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world/src/codegen/tables/ResourceAccess.sol b/packages/world/src/codegen/tables/ResourceAccess.sol index 5d5a6a50af..6b4be575da 100644 --- a/packages/world/src/codegen/tables/ResourceAccess.sol +++ b/packages/world/src/codegen/tables/ResourceAccess.sol @@ -22,22 +22,12 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "ResourceAccess", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c640000000000000000005265736f757263654163636573730000); -ResourceId constant ResourceAccessTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0001010001000000000000000000000000000000000000000000000000000000 -); - library ResourceAccess { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "ResourceAccess", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c640000000000000000005265736f757263654163636573730000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0001010001000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world/src/codegen/tables/SystemHooks.sol b/packages/world/src/codegen/tables/SystemHooks.sol index e73edd6d16..1bf20c1005 100644 --- a/packages/world/src/codegen/tables/SystemHooks.sol +++ b/packages/world/src/codegen/tables/SystemHooks.sol @@ -22,22 +22,12 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "SystemHooks", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c6400000000000000000053797374656d486f6f6b730000000000); -ResourceId constant SystemHooksTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0000000100000000000000000000000000000000000000000000000000000000 -); - library SystemHooks { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "SystemHooks", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c6400000000000000000053797374656d486f6f6b730000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world/src/codegen/tables/SystemRegistry.sol b/packages/world/src/codegen/tables/SystemRegistry.sol index 551a22293c..1cc0c06168 100644 --- a/packages/world/src/codegen/tables/SystemRegistry.sol +++ b/packages/world/src/codegen/tables/SystemRegistry.sol @@ -22,22 +22,12 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "SystemRegistry", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c6400000000000000000053797374656d52656769737472790000); -ResourceId constant SystemRegistryTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0020010020000000000000000000000000000000000000000000000000000000 -); - library SystemRegistry { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "SystemRegistry", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c6400000000000000000053797374656d52656769737472790000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world/src/codegen/tables/Systems.sol b/packages/world/src/codegen/tables/Systems.sol index ec75746b38..163cf0911d 100644 --- a/packages/world/src/codegen/tables/Systems.sol +++ b/packages/world/src/codegen/tables/Systems.sol @@ -22,22 +22,12 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "Systems", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c6400000000000000000053797374656d73000000000000000000); -ResourceId constant SystemsTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0015020014010000000000000000000000000000000000000000000000000000 -); - library Systems { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "Systems", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c6400000000000000000053797374656d73000000000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0015020014010000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world/src/codegen/tables/UserDelegationControl.sol b/packages/world/src/codegen/tables/UserDelegationControl.sol index f32fa0ca47..bce3d092ab 100644 --- a/packages/world/src/codegen/tables/UserDelegationControl.sol +++ b/packages/world/src/codegen/tables/UserDelegationControl.sol @@ -22,22 +22,12 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "UserDelegationCo", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c640000000000000000005573657244656c65676174696f6e436f); -ResourceId constant UserDelegationControlTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0020010020000000000000000000000000000000000000000000000000000000 -); - library UserDelegationControl { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "world", name: "UserDelegationCo", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462776f726c640000000000000000005573657244656c65676174696f6e436f); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world/src/modules/init/implementations/WorldRegistrationSystem.sol b/packages/world/src/modules/init/implementations/WorldRegistrationSystem.sol index 5ac6bf1664..d9bc340042 100644 --- a/packages/world/src/modules/init/implementations/WorldRegistrationSystem.sol +++ b/packages/world/src/modules/init/implementations/WorldRegistrationSystem.sol @@ -22,7 +22,7 @@ import { ISystemHook } from "../../../ISystemHook.sol"; import { IWorldErrors } from "../../../IWorldErrors.sol"; import { IDelegationControl } from "../../../IDelegationControl.sol"; -import { SystemHooks, SystemHooksTableId } from "../../../codegen/tables/SystemHooks.sol"; +import { SystemHooks } from "../../../codegen/tables/SystemHooks.sol"; import { SystemRegistry } from "../../../codegen/tables/SystemRegistry.sol"; import { Systems } from "../../../codegen/tables/Systems.sol"; import { FunctionSelectors } from "../../../codegen/tables/FunctionSelectors.sol"; @@ -109,7 +109,7 @@ contract WorldRegistrationSystem is System, IWorldErrors, LimitedCallContext { AccessControl.requireOwner(systemId, _msgSender()); // Remove the hook from the list of hooks for this system in the system hooks table - HookLib.filterListByAddress(SystemHooksTableId, systemId, address(hookAddress)); + HookLib.filterListByAddress(SystemHooks._tableId, systemId, address(hookAddress)); } /** diff --git a/packages/world/test/World.t.sol b/packages/world/test/World.t.sol index 67ba63a591..8ec7dedc5c 100644 --- a/packages/world/test/World.t.sol +++ b/packages/world/test/World.t.sol @@ -15,7 +15,7 @@ import { FieldLayoutEncodeHelper } from "@latticexyz/store/test/FieldLayoutEncod import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter } from "@latticexyz/store/src/PackedCounter.sol"; import { SchemaEncodeHelper } from "@latticexyz/store/test/SchemaEncodeHelper.sol"; -import { Tables, ResourceIds, TablesTableId } from "@latticexyz/store/src/codegen/index.sol"; +import { Tables, ResourceIds } from "@latticexyz/store/src/codegen/index.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; import { ALL, BEFORE_SET_RECORD, AFTER_SET_RECORD, BEFORE_SPLICE_STATIC_DATA, AFTER_SPLICE_STATIC_DATA, BEFORE_SPLICE_DYNAMIC_DATA, AFTER_SPLICE_DYNAMIC_DATA, BEFORE_DELETE_RECORD, AFTER_DELETE_RECORD } from "@latticexyz/store/src/storeHookTypes.sol"; import { RevertSubscriber } from "@latticexyz/store/test/RevertSubscriber.sol"; @@ -32,7 +32,7 @@ import { SystemHook } from "../src/SystemHook.sol"; import { BEFORE_CALL_SYSTEM, AFTER_CALL_SYSTEM } from "../src/systemHookTypes.sol"; import { Module, IModule } from "../src/Module.sol"; -import { NamespaceOwner, NamespaceOwnerTableId } from "../src/codegen/tables/NamespaceOwner.sol"; +import { NamespaceOwner } from "../src/codegen/tables/NamespaceOwner.sol"; import { ResourceAccess } from "../src/codegen/tables/ResourceAccess.sol"; import { AccessManagementSystem } from "../src/modules/init/implementations/AccessManagementSystem.sol"; @@ -259,17 +259,17 @@ contract WorldTest is Test, GasReporter { } // Should have registered the table data table (fka schema table) - assertEq(FieldLayout.unwrap(Tables.getFieldLayout(TablesTableId)), FieldLayout.unwrap(Tables.getFieldLayout())); - assertEq(Tables.getAbiEncodedKeyNames(TablesTableId), abi.encode(Tables.getKeyNames())); - assertEq(Tables.getAbiEncodedFieldNames(TablesTableId), abi.encode(Tables.getFieldNames())); + assertEq(FieldLayout.unwrap(Tables.getFieldLayout(Tables._tableId)), FieldLayout.unwrap(Tables._fieldLayout)); + assertEq(Tables.getAbiEncodedKeyNames(Tables._tableId), abi.encode(Tables.getKeyNames())); + assertEq(Tables.getAbiEncodedFieldNames(Tables._tableId), abi.encode(Tables.getFieldNames())); // Should have registered the namespace owner table assertEq( - FieldLayout.unwrap(Tables.getFieldLayout(NamespaceOwnerTableId)), - FieldLayout.unwrap(NamespaceOwner.getFieldLayout()) + FieldLayout.unwrap(Tables.getFieldLayout(NamespaceOwner._tableId)), + FieldLayout.unwrap(NamespaceOwner._fieldLayout) ); - assertEq(Tables.getAbiEncodedKeyNames(NamespaceOwnerTableId), abi.encode(NamespaceOwner.getKeyNames())); - assertEq(Tables.getAbiEncodedFieldNames(NamespaceOwnerTableId), abi.encode(NamespaceOwner.getFieldNames())); + assertEq(Tables.getAbiEncodedKeyNames(NamespaceOwner._tableId), abi.encode(NamespaceOwner.getKeyNames())); + assertEq(Tables.getAbiEncodedFieldNames(NamespaceOwner._tableId), abi.encode(NamespaceOwner.getFieldNames())); // Expect it to not be possible to initialize the World again vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_AlreadyInitialized.selector)); @@ -595,7 +595,7 @@ contract WorldTest is Test, GasReporter { ResourceId tableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: "", name: "testTable" }); world.registerTable( tableId, - Bool.getFieldLayout(), + Bool._fieldLayout, defaultKeySchema, Bool.getValueSchema(), new string[](1), @@ -704,7 +704,7 @@ contract WorldTest is Test, GasReporter { ResourceId tableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: "namespace", name: "name" }); world.registerTable( tableId, - Bool.getFieldLayout(), + Bool._fieldLayout, defaultKeySchema, Bool.getValueSchema(), new string[](1), @@ -740,7 +740,7 @@ contract WorldTest is Test, GasReporter { ); world.registerTable( systemId, - Bool.getFieldLayout(), + Bool._fieldLayout, defaultKeySchema, Bool.getValueSchema(), new string[](1), @@ -753,7 +753,7 @@ contract WorldTest is Test, GasReporter { ); world.registerTable( tableId, - Bool.getFieldLayout(), + Bool._fieldLayout, defaultKeySchema, Bool.getValueSchema(), new string[](1), @@ -779,7 +779,7 @@ contract WorldTest is Test, GasReporter { // Register a new table world.registerTable( tableId, - TwoFields.getFieldLayout(), + TwoFields._fieldLayout, TwoFields.getKeySchema(), TwoFields.getValueSchema(), new string[](0), @@ -809,7 +809,7 @@ contract WorldTest is Test, GasReporter { bytes14 namespace = "testSetField"; bytes16 name = "testTable"; ResourceId tableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: name }); - FieldLayout fieldLayout = Bool.getFieldLayout(); + FieldLayout fieldLayout = Bool._fieldLayout; Schema valueSchema = Bool.getValueSchema(); world.registerNamespace(tableId.getNamespaceId()); @@ -839,7 +839,7 @@ contract WorldTest is Test, GasReporter { bytes14 namespace = "testPushField"; bytes16 name = "testTable"; ResourceId tableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: name }); - FieldLayout fieldLayout = AddressArray.getFieldLayout(); + FieldLayout fieldLayout = AddressArray._fieldLayout; Schema valueSchema = AddressArray.getValueSchema(); // Register a new table @@ -885,7 +885,7 @@ contract WorldTest is Test, GasReporter { bytes14 namespace = "testDeleteReco"; bytes16 name = "testTable"; ResourceId tableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: name }); - FieldLayout fieldLayout = Bool.getFieldLayout(); + FieldLayout fieldLayout = Bool._fieldLayout; Schema valueSchema = Bool.getValueSchema(); // Register a new table @@ -1268,7 +1268,7 @@ contract WorldTest is Test, GasReporter { } function testRegisterStoreHook() public { - FieldLayout fieldLayout = Bool.getFieldLayout(); + FieldLayout fieldLayout = Bool._fieldLayout; Schema valueSchema = Bool.getValueSchema(); ResourceId tableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: "", name: "testTable" }); @@ -1335,7 +1335,7 @@ contract WorldTest is Test, GasReporter { } function testUnregisterStoreHook() public { - FieldLayout fieldLayout = Bool.getFieldLayout(); + FieldLayout fieldLayout = Bool._fieldLayout; Schema valueSchema = Bool.getValueSchema(); ResourceId tableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: "", name: "testTable" }); @@ -1522,7 +1522,7 @@ contract WorldTest is Test, GasReporter { world.registerNamespace(tableId.getNamespaceId()); world.registerTable( tableId, - Bool.getFieldLayout(), + Bool._fieldLayout, defaultKeySchema, Bool.getValueSchema(), new string[](1), @@ -1551,7 +1551,7 @@ contract WorldTest is Test, GasReporter { world.registerNamespace(tableId.getNamespaceId()); world.registerTable( tableId, - Bool.getFieldLayout(), + Bool._fieldLayout, defaultKeySchema, Bool.getValueSchema(), new string[](1), diff --git a/packages/world/test/WorldDynamicUpdate.t.sol b/packages/world/test/WorldDynamicUpdate.t.sol index 3dff138231..cad453a510 100644 --- a/packages/world/test/WorldDynamicUpdate.t.sol +++ b/packages/world/test/WorldDynamicUpdate.t.sol @@ -53,7 +53,7 @@ contract UpdateInDynamicFieldTest is Test, GasReporter { keyTuple = new bytes32[](1); keyTuple[0] = key; singletonKey = new bytes32[](0); - FieldLayout fieldLayout = AddressArray.getFieldLayout(); + FieldLayout fieldLayout = AddressArray._fieldLayout; Schema valueSchema = AddressArray.getValueSchema(); // Initialize the data in setUp so that slots aren't warm in tests (to test cold update) @@ -83,7 +83,7 @@ contract UpdateInDynamicFieldTest is Test, GasReporter { } function testPopFromDynamicField() public { - FieldLayout fieldLayout = AddressArray.getFieldLayout(); + FieldLayout fieldLayout = AddressArray._fieldLayout; // Expect the data to be written assertEq(AddressArray.get(tableId, key), initData); diff --git a/packages/world/test/codegen/tables/AddressArray.sol b/packages/world/test/codegen/tables/AddressArray.sol index 406f83d870..a0538d08d2 100644 --- a/packages/world/test/codegen/tables/AddressArray.sol +++ b/packages/world/test/codegen/tables/AddressArray.sol @@ -19,18 +19,9 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0000000100000000000000000000000000000000000000000000000000000000 -); - library AddressArray { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world/test/codegen/tables/Bool.sol b/packages/world/test/codegen/tables/Bool.sol index 43d6b8fca3..ed67cfd72f 100644 --- a/packages/world/test/codegen/tables/Bool.sol +++ b/packages/world/test/codegen/tables/Bool.sol @@ -19,18 +19,9 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0001010001000000000000000000000000000000000000000000000000000000 -); - library Bool { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0001010001000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/packages/world/test/codegen/tables/TwoFields.sol b/packages/world/test/codegen/tables/TwoFields.sol index da4b7035a8..dc5939612e 100644 --- a/packages/world/test/codegen/tables/TwoFields.sol +++ b/packages/world/test/codegen/tables/TwoFields.sol @@ -19,23 +19,14 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0002020001010000000000000000000000000000000000000000000000000000 -); - struct TwoFieldsData { bool value1; bool value2; } library TwoFields { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0002020001010000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/templates/phaser/packages/contracts/src/codegen/index.sol b/templates/phaser/packages/contracts/src/codegen/index.sol index 6364dfc884..2c7020d821 100644 --- a/templates/phaser/packages/contracts/src/codegen/index.sol +++ b/templates/phaser/packages/contracts/src/codegen/index.sol @@ -3,4 +3,4 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -import { Counter, CounterTableId } from "./tables/Counter.sol"; +import { Counter } from "./tables/Counter.sol"; diff --git a/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol b/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol index 40a1f45dcf..be0bfa0876 100644 --- a/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol @@ -19,22 +19,12 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Counter", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000436f756e746572000000000000000000); -ResourceId constant CounterTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0004010004000000000000000000000000000000000000000000000000000000 -); - library Counter { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Counter", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000436f756e746572000000000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0004010004000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/templates/phaser/packages/contracts/test/CounterTest.t.sol b/templates/phaser/packages/contracts/test/CounterTest.t.sol index 2c76d7b300..4946ef57ff 100644 --- a/templates/phaser/packages/contracts/test/CounterTest.t.sol +++ b/templates/phaser/packages/contracts/test/CounterTest.t.sol @@ -6,7 +6,7 @@ import { MudTest } from "@latticexyz/world/test/MudTest.t.sol"; import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol"; import { IWorld } from "../src/codegen/world/IWorld.sol"; -import { Counter, CounterTableId } from "../src/codegen/index.sol"; +import { Counter } from "../src/codegen/index.sol"; contract CounterTest is MudTest { function testWorldExists() public { diff --git a/templates/react-ecs/packages/contracts/src/codegen/index.sol b/templates/react-ecs/packages/contracts/src/codegen/index.sol index 6364dfc884..2c7020d821 100644 --- a/templates/react-ecs/packages/contracts/src/codegen/index.sol +++ b/templates/react-ecs/packages/contracts/src/codegen/index.sol @@ -3,4 +3,4 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -import { Counter, CounterTableId } from "./tables/Counter.sol"; +import { Counter } from "./tables/Counter.sol"; diff --git a/templates/react-ecs/packages/contracts/src/codegen/tables/Counter.sol b/templates/react-ecs/packages/contracts/src/codegen/tables/Counter.sol index 40a1f45dcf..be0bfa0876 100644 --- a/templates/react-ecs/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/react-ecs/packages/contracts/src/codegen/tables/Counter.sol @@ -19,22 +19,12 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Counter", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000436f756e746572000000000000000000); -ResourceId constant CounterTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0004010004000000000000000000000000000000000000000000000000000000 -); - library Counter { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Counter", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000436f756e746572000000000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0004010004000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/templates/react-ecs/packages/contracts/test/CounterTest.t.sol b/templates/react-ecs/packages/contracts/test/CounterTest.t.sol index 2c76d7b300..4946ef57ff 100644 --- a/templates/react-ecs/packages/contracts/test/CounterTest.t.sol +++ b/templates/react-ecs/packages/contracts/test/CounterTest.t.sol @@ -6,7 +6,7 @@ import { MudTest } from "@latticexyz/world/test/MudTest.t.sol"; import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol"; import { IWorld } from "../src/codegen/world/IWorld.sol"; -import { Counter, CounterTableId } from "../src/codegen/index.sol"; +import { Counter } from "../src/codegen/index.sol"; contract CounterTest is MudTest { function testWorldExists() public { diff --git a/templates/react/packages/contracts/src/codegen/index.sol b/templates/react/packages/contracts/src/codegen/index.sol index 541ff3b552..6337bbbc62 100644 --- a/templates/react/packages/contracts/src/codegen/index.sol +++ b/templates/react/packages/contracts/src/codegen/index.sol @@ -3,4 +3,4 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -import { Tasks, TasksData, TasksTableId } from "./tables/Tasks.sol"; +import { Tasks, TasksData } from "./tables/Tasks.sol"; diff --git a/templates/react/packages/contracts/src/codegen/tables/Tasks.sol b/templates/react/packages/contracts/src/codegen/tables/Tasks.sol index dd0f1cad01..a12ef6d589 100644 --- a/templates/react/packages/contracts/src/codegen/tables/Tasks.sol +++ b/templates/react/packages/contracts/src/codegen/tables/Tasks.sol @@ -19,14 +19,6 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Tasks", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x746200000000000000000000000000005461736b730000000000000000000000); -ResourceId constant TasksTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0040020120200000000000000000000000000000000000000000000000000000 -); - struct TasksData { uint256 createdAt; uint256 completedAt; @@ -34,13 +26,11 @@ struct TasksData { } library Tasks { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Tasks", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x746200000000000000000000000000005461736b730000000000000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0040020120200000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/templates/threejs/packages/contracts/src/codegen/index.sol b/templates/threejs/packages/contracts/src/codegen/index.sol index 02e9432e11..b72005c189 100644 --- a/templates/threejs/packages/contracts/src/codegen/index.sol +++ b/templates/threejs/packages/contracts/src/codegen/index.sol @@ -3,4 +3,4 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -import { Position, PositionData, PositionTableId } from "./tables/Position.sol"; +import { Position, PositionData } from "./tables/Position.sol"; diff --git a/templates/threejs/packages/contracts/src/codegen/tables/Position.sol b/templates/threejs/packages/contracts/src/codegen/tables/Position.sol index ee7e364497..11222af4d0 100644 --- a/templates/threejs/packages/contracts/src/codegen/tables/Position.sol +++ b/templates/threejs/packages/contracts/src/codegen/tables/Position.sol @@ -19,14 +19,6 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Position", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000506f736974696f6e0000000000000000); -ResourceId constant PositionTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x000c030004040400000000000000000000000000000000000000000000000000 -); - struct PositionData { int32 x; int32 y; @@ -34,13 +26,11 @@ struct PositionData { } library Position { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Position", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000506f736974696f6e0000000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x000c030004040400000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/templates/vanilla/packages/contracts/src/codegen/index.sol b/templates/vanilla/packages/contracts/src/codegen/index.sol index 6364dfc884..2c7020d821 100644 --- a/templates/vanilla/packages/contracts/src/codegen/index.sol +++ b/templates/vanilla/packages/contracts/src/codegen/index.sol @@ -3,4 +3,4 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -import { Counter, CounterTableId } from "./tables/Counter.sol"; +import { Counter } from "./tables/Counter.sol"; diff --git a/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol b/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol index 40a1f45dcf..be0bfa0876 100644 --- a/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol @@ -19,22 +19,12 @@ import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Counter", typeId: RESOURCE_TABLE });` -ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000436f756e746572000000000000000000); -ResourceId constant CounterTableId = _tableId; - -FieldLayout constant _fieldLayout = FieldLayout.wrap( - 0x0004010004000000000000000000000000000000000000000000000000000000 -); - library Counter { - /** - * @notice Get the table values' field layout. - * @return _fieldLayout The field layout for the table. - */ - function getFieldLayout() internal pure returns (FieldLayout) { - return _fieldLayout; - } + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Counter", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000436f756e746572000000000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0004010004000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key schema. diff --git a/templates/vanilla/packages/contracts/test/CounterTest.t.sol b/templates/vanilla/packages/contracts/test/CounterTest.t.sol index 2c76d7b300..4946ef57ff 100644 --- a/templates/vanilla/packages/contracts/test/CounterTest.t.sol +++ b/templates/vanilla/packages/contracts/test/CounterTest.t.sol @@ -6,7 +6,7 @@ import { MudTest } from "@latticexyz/world/test/MudTest.t.sol"; import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol"; import { IWorld } from "../src/codegen/world/IWorld.sol"; -import { Counter, CounterTableId } from "../src/codegen/index.sol"; +import { Counter } from "../src/codegen/index.sol"; contract CounterTest is MudTest { function testWorldExists() public {