From 3042f86e66ed39618bf520b5dbba06bfd23486a4 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Wed, 28 Feb 2024 18:33:09 +0000 Subject: [PATCH] refactor: hardcode key/value schema in table libraries (#2328) Co-authored-by: yonada --- .changeset/tough-pumpkins-reply.md | 16 +++++++ .../contracts/src/codegen/tables/Multi.sol | 40 ++++------------ .../contracts/src/codegen/tables/Number.sol | 36 ++++----------- .../src/codegen/tables/NumberList.sol | 35 ++++---------- .../contracts/src/codegen/tables/Position.sol | 38 ++++----------- .../src/codegen/tables/StaticArray.sol | 35 ++++---------- .../contracts/src/codegen/tables/Vector.sol | 37 ++++----------- .../src/codegen/tables/CounterTable.sol | 37 ++++----------- .../src/codegen/tables/Inventory.sol | 38 ++++----------- .../src/codegen/tables/MessageTable.sol | 35 ++++---------- .../contracts/src/codegen/tables/LastCall.sol | 37 ++++----------- .../src/codegen/tables/Dynamics1.sol | 40 ++++------------ .../src/codegen/tables/Dynamics2.sol | 38 ++++----------- .../contracts/src/codegen/tables/Offchain.sol | 36 ++++----------- .../src/codegen/tables/Singleton.sol | 38 ++++----------- .../contracts/src/codegen/tables/Statics.sol | 46 ++++--------------- .../src/codegen/tables/UserTyped.sol | 44 ++++-------------- packages/store/gas-report.json | 6 +-- packages/store/package.json | 1 + packages/store/src/StoreCore.sol | 8 ++-- packages/store/src/codegen/tables/Hooks.sol | 36 ++++----------- .../store/src/codegen/tables/ResourceIds.sol | 36 ++++----------- .../store/src/codegen/tables/StoreHooks.sol | 36 ++++----------- packages/store/src/codegen/tables/Tables.sol | 40 ++++------------ packages/store/test/Callbacks.t.sol | 15 ++++++ packages/store/test/KeyEncoding.t.sol | 23 +++++++++- packages/store/test/Mixed.t.sol | 21 ++++++++- packages/store/test/Vector2.t.sol | 19 +++++++- .../store/test/codegen/tables/Callbacks.sol | 36 ++++----------- .../store/test/codegen/tables/KeyEncoding.sol | 41 ++++------------- packages/store/test/codegen/tables/Mixed.sol | 39 ++++------------ .../store/test/codegen/tables/Vector2.sol | 37 ++++----------- packages/store/ts/codegen/renderTable.ts | 39 +++++----------- packages/world-modules/gas-report.json | 22 ++++----- .../erc20-puppet/tables/Allowances.sol | 37 ++++----------- .../erc20-puppet/tables/ERC20Metadata.sol | 37 ++++----------- .../erc20-puppet/tables/ERC20Registry.sol | 36 ++++----------- .../erc20-puppet/tables/TotalSupply.sol | 35 ++++---------- .../erc721-puppet/tables/ERC721Metadata.sol | 37 ++++----------- .../erc721-puppet/tables/ERC721Registry.sol | 36 ++++----------- .../erc721-puppet/tables/OperatorApproval.sol | 37 ++++----------- .../modules/erc721-puppet/tables/Owners.sol | 36 ++++----------- .../erc721-puppet/tables/TokenApproval.sol | 36 ++++----------- .../modules/erc721-puppet/tables/TokenURI.sol | 36 ++++----------- .../modules/keysintable/KeysInTableModule.sol | 8 ++-- .../keysintable/tables/KeysInTable.sol | 42 ++++------------- .../keysintable/tables/UsedKeysIndex.sol | 40 ++++------------ .../keyswithvalue/KeysWithValueModule.sol | 4 +- .../keyswithvalue/tables/KeysWithValue.sol | 38 ++++----------- .../modules/puppet/tables/PuppetRegistry.sol | 36 ++++----------- .../tables/CallboundDelegations.sol | 39 ++++------------ .../tables/SystemboundDelegations.sol | 38 ++++----------- .../tables/TimeboundDelegations.sol | 37 ++++----------- .../src/modules/tokens/tables/Balances.sol | 36 ++++----------- .../uniqueentity/tables/UniqueEntity.sol | 37 ++++----------- .../world-modules/test/SystemSwitch.t.sol | 4 +- packages/world/gas-report.json | 6 +-- .../world/src/codegen/tables/Balances.sol | 36 ++++----------- .../src/codegen/tables/FunctionSelectors.sol | 37 ++++----------- .../src/codegen/tables/FunctionSignatures.sol | 36 ++++----------- .../src/codegen/tables/InitModuleAddress.sol | 35 ++++---------- .../src/codegen/tables/InstalledModules.sol | 37 ++++----------- .../tables/NamespaceDelegationControl.sol | 36 ++++----------- .../src/codegen/tables/NamespaceOwner.sol | 36 ++++----------- .../src/codegen/tables/ResourceAccess.sol | 37 ++++----------- .../world/src/codegen/tables/SystemHooks.sol | 36 ++++----------- .../src/codegen/tables/SystemRegistry.sol | 36 ++++----------- packages/world/src/codegen/tables/Systems.sol | 37 ++++----------- .../codegen/tables/UserDelegationControl.sol | 37 ++++----------- packages/world/test/World.t.sol | 26 +++++------ packages/world/test/WorldDynamicUpdate.t.sol | 2 +- .../test/codegen/tables/AddressArray.sol | 36 ++++----------- packages/world/test/codegen/tables/Bool.sol | 35 ++++---------- .../world/test/codegen/tables/TwoFields.sol | 36 ++++----------- pnpm-lock.yaml | 3 ++ .../contracts/src/codegen/tables/Counter.sol | 35 ++++---------- .../contracts/src/codegen/tables/Counter.sol | 35 ++++---------- .../contracts/src/codegen/tables/Tasks.sol | 38 ++++----------- .../contracts/src/codegen/tables/Position.sol | 38 ++++----------- .../contracts/src/codegen/tables/Counter.sol | 35 ++++---------- 80 files changed, 656 insertions(+), 1908 deletions(-) create mode 100644 .changeset/tough-pumpkins-reply.md diff --git a/.changeset/tough-pumpkins-reply.md b/.changeset/tough-pumpkins-reply.md new file mode 100644 index 0000000000..559c3ef6d5 --- /dev/null +++ b/.changeset/tough-pumpkins-reply.md @@ -0,0 +1,16 @@ +--- +"create-mud": patch +"@latticexyz/store": minor +"@latticexyz/world": minor +"@latticexyz/world-modules": minor +--- + +Moved key schema and value schema methods to constants in code-generated table libraries for less bytecode and less gas in register/install methods. + +```diff +-console.log(SomeTable.getKeySchema()); ++console.log(SomeTable._keySchema); + +-console.log(SomeTable.getValueSchema()); ++console.log(SomeTable._valueSchema); +``` diff --git a/e2e/packages/contracts/src/codegen/tables/Multi.sol b/e2e/packages/contracts/src/codegen/tables/Multi.sol index 50bba4cddf..ae9811c45f 100644 --- a/e2e/packages/contracts/src/codegen/tables/Multi.sol +++ b/e2e/packages/contracts/src/codegen/tables/Multi.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -31,31 +28,10 @@ library Multi { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0021020020010000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](4); - _keySchema[0] = SchemaType.UINT32; - _keySchema[1] = SchemaType.BOOL; - _keySchema[2] = SchemaType.UINT256; - _keySchema[3] = SchemaType.INT120; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](2); - _valueSchema[0] = SchemaType.INT256; - _valueSchema[1] = SchemaType.BOOL; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (uint32, bool, uint256, int120) + Schema constant _keySchema = Schema.wrap(0x0034040003601f2e000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (int256, bool) + Schema constant _valueSchema = Schema.wrap(0x002102003f600000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -83,14 +59,14 @@ library Multi { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/e2e/packages/contracts/src/codegen/tables/Number.sol b/e2e/packages/contracts/src/codegen/tables/Number.sol index c66bfdf66a..2c2820a54a 100644 --- a/e2e/packages/contracts/src/codegen/tables/Number.sol +++ b/e2e/packages/contracts/src/codegen/tables/Number.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,27 +23,10 @@ library Number { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0004010004000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.UINT32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.UINT32; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (uint32) + Schema constant _keySchema = Schema.wrap(0x0004010003000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint32) + Schema constant _valueSchema = Schema.wrap(0x0004010003000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -70,14 +50,14 @@ library Number { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/e2e/packages/contracts/src/codegen/tables/NumberList.sol b/e2e/packages/contracts/src/codegen/tables/NumberList.sol index a604f3668a..667191bfa2 100644 --- a/e2e/packages/contracts/src/codegen/tables/NumberList.sol +++ b/e2e/packages/contracts/src/codegen/tables/NumberList.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,26 +23,10 @@ library NumberList { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](0); - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.UINT32_ARRAY; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of () + Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint32[]) + Schema constant _valueSchema = Schema.wrap(0x0000000165000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -68,14 +49,14 @@ library NumberList { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/e2e/packages/contracts/src/codegen/tables/Position.sol b/e2e/packages/contracts/src/codegen/tables/Position.sol index 495d92554e..2cfe47fc5b 100644 --- a/e2e/packages/contracts/src/codegen/tables/Position.sol +++ b/e2e/packages/contracts/src/codegen/tables/Position.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,29 +23,10 @@ library Position { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](3); - _keySchema[0] = SchemaType.BYTES32; - _keySchema[1] = SchemaType.INT32; - _keySchema[2] = SchemaType.INT32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.ADDRESS; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32, int32, int32) + Schema constant _keySchema = Schema.wrap(0x002803005f232300000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (address) + Schema constant _valueSchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -74,14 +52,14 @@ library Position { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/e2e/packages/contracts/src/codegen/tables/StaticArray.sol b/e2e/packages/contracts/src/codegen/tables/StaticArray.sol index 7b89a2b2c9..99d6b62320 100644 --- a/e2e/packages/contracts/src/codegen/tables/StaticArray.sol +++ b/e2e/packages/contracts/src/codegen/tables/StaticArray.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,26 +23,10 @@ library StaticArray { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](0); - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.UINT256_ARRAY; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of () + Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint256[]) + Schema constant _valueSchema = Schema.wrap(0x0000000181000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -68,14 +49,14 @@ library StaticArray { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/e2e/packages/contracts/src/codegen/tables/Vector.sol b/e2e/packages/contracts/src/codegen/tables/Vector.sol index a077935f6d..6d3d109d55 100644 --- a/e2e/packages/contracts/src/codegen/tables/Vector.sol +++ b/e2e/packages/contracts/src/codegen/tables/Vector.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -31,28 +28,10 @@ library Vector { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0008020004040000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.UINT32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](2); - _valueSchema[0] = SchemaType.INT32; - _valueSchema[1] = SchemaType.INT32; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (uint32) + Schema constant _keySchema = Schema.wrap(0x0004010003000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (int32, int32) + Schema constant _valueSchema = Schema.wrap(0x0008020023230000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -77,14 +56,14 @@ library Vector { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol b/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol index 9d9c2e92c8..c9a05bc627 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,26 +23,10 @@ library CounterTable { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0004010004000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](0); - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.UINT32; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of () + Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint32) + Schema constant _valueSchema = Schema.wrap(0x0004010003000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -68,21 +49,21 @@ library CounterTable { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config (using the specified store). */ function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol b/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol index 672732416c..f04fddc6e7 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,29 +23,10 @@ library Inventory { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0004010004000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](3); - _keySchema[0] = SchemaType.ADDRESS; - _keySchema[1] = SchemaType.UINT32; - _keySchema[2] = SchemaType.UINT32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.UINT32; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (address, uint32, uint32) + Schema constant _keySchema = Schema.wrap(0x001c030061030300000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint32) + Schema constant _valueSchema = Schema.wrap(0x0004010003000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -74,14 +52,14 @@ library Inventory { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol b/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol index 177257cdb1..343a9aac91 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,26 +23,10 @@ library MessageTable { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](0); - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.STRING; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of () + Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (string) + Schema constant _valueSchema = Schema.wrap(0x00000001c5000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -68,14 +49,14 @@ library MessageTable { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** 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 748501c126..6ae2f1ad37 100644 --- a/examples/multiple-accounts/packages/contracts/src/codegen/tables/LastCall.sol +++ b/examples/multiple-accounts/packages/contracts/src/codegen/tables/LastCall.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -31,28 +28,10 @@ library LastCall { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0034020020140000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.ADDRESS; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](2); - _valueSchema[0] = SchemaType.UINT256; - _valueSchema[1] = SchemaType.ADDRESS; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (address) + Schema constant _keySchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint256, address) + Schema constant _valueSchema = Schema.wrap(0x003402001f610000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -77,14 +56,14 @@ library LastCall { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol index cadade4bc2..c9f147afdd 100644 --- a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol +++ b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -34,31 +31,10 @@ library Dynamics1 { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000500000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](5); - _valueSchema[0] = SchemaType.BYTES32_ARRAY; - _valueSchema[1] = SchemaType.INT32_ARRAY; - _valueSchema[2] = SchemaType.UINT128_ARRAY; - _valueSchema[3] = SchemaType.ADDRESS_ARRAY; - _valueSchema[4] = SchemaType.BOOL_ARRAY; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bytes32[], int32[], uint128[], address[], bool[]) + Schema constant _valueSchema = Schema.wrap(0x00000005c18571c3c20000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -86,14 +62,14 @@ library Dynamics1 { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol index 56da3c6bce..07bc193055 100644 --- a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol +++ b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -32,29 +29,10 @@ library Dynamics2 { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000300000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](3); - _valueSchema[0] = SchemaType.UINT64_ARRAY; - _valueSchema[1] = SchemaType.STRING; - _valueSchema[2] = SchemaType.BYTES; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint64[], string, bytes) + Schema constant _valueSchema = Schema.wrap(0x0000000369c5c400000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -80,14 +58,14 @@ library Dynamics2 { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/cli/contracts/src/codegen/tables/Offchain.sol b/packages/cli/contracts/src/codegen/tables/Offchain.sol index e5588681ec..16732168f8 100644 --- a/packages/cli/contracts/src/codegen/tables/Offchain.sol +++ b/packages/cli/contracts/src/codegen/tables/Offchain.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,27 +23,10 @@ library Offchain { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.UINT256; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint256) + Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -70,14 +50,14 @@ library Offchain { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/cli/contracts/src/codegen/tables/Singleton.sol b/packages/cli/contracts/src/codegen/tables/Singleton.sol index b515bb78cf..ac7955f7e7 100644 --- a/packages/cli/contracts/src/codegen/tables/Singleton.sol +++ b/packages/cli/contracts/src/codegen/tables/Singleton.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,29 +23,10 @@ library Singleton { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0020010320000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](0); - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](4); - _valueSchema[0] = SchemaType.INT256; - _valueSchema[1] = SchemaType.UINT32_ARRAY; - _valueSchema[2] = SchemaType.UINT32_ARRAY; - _valueSchema[3] = SchemaType.UINT32_ARRAY; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of () + Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (int256, uint32[], uint32[], uint32[]) + Schema constant _valueSchema = Schema.wrap(0x002001033f656565000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -74,14 +52,14 @@ library Singleton { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/cli/contracts/src/codegen/tables/Statics.sol b/packages/cli/contracts/src/codegen/tables/Statics.sol index 2f7c7c1a39..86453360fe 100644 --- a/packages/cli/contracts/src/codegen/tables/Statics.sol +++ b/packages/cli/contracts/src/codegen/tables/Statics.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -38,37 +35,10 @@ library Statics { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x004a060020041014010100000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](6); - _keySchema[0] = SchemaType.UINT256; - _keySchema[1] = SchemaType.INT32; - _keySchema[2] = SchemaType.BYTES16; - _keySchema[3] = SchemaType.ADDRESS; - _keySchema[4] = SchemaType.BOOL; - _keySchema[5] = SchemaType.UINT8; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](6); - _valueSchema[0] = SchemaType.UINT256; - _valueSchema[1] = SchemaType.INT32; - _valueSchema[2] = SchemaType.BYTES16; - _valueSchema[3] = SchemaType.ADDRESS; - _valueSchema[4] = SchemaType.BOOL; - _valueSchema[5] = SchemaType.UINT8; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (uint256, int32, bytes16, address, bool, uint8) + Schema constant _keySchema = Schema.wrap(0x004a06001f234f61600000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint256, int32, bytes16, address, bool, uint8) + Schema constant _valueSchema = Schema.wrap(0x004a06001f234f61600000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -102,14 +72,14 @@ library Statics { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/cli/contracts/src/codegen/tables/UserTyped.sol b/packages/cli/contracts/src/codegen/tables/UserTyped.sol index fce2236e2b..fc3fcf29c8 100644 --- a/packages/cli/contracts/src/codegen/tables/UserTyped.sol +++ b/packages/cli/contracts/src/codegen/tables/UserTyped.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -38,35 +35,10 @@ library UserTyped { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x004d050014080110200000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](5); - _keySchema[0] = SchemaType.ADDRESS; - _keySchema[1] = SchemaType.INT64; - _keySchema[2] = SchemaType.BOOL; - _keySchema[3] = SchemaType.UINT128; - _keySchema[4] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](5); - _valueSchema[0] = SchemaType.ADDRESS; - _valueSchema[1] = SchemaType.INT64; - _valueSchema[2] = SchemaType.BOOL; - _valueSchema[3] = SchemaType.UINT128; - _valueSchema[4] = SchemaType.BYTES32; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (address, int64, bool, uint128, bytes32) + Schema constant _keySchema = Schema.wrap(0x004d05006127600f5f0000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (address, int64, bool, uint128, bytes32) + Schema constant _valueSchema = Schema.wrap(0x004d05006127600f5f0000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -98,14 +70,14 @@ library UserTyped { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/store/gas-report.json b/packages/store/gas-report.json index beec1a3c40..343c6287a0 100644 --- a/packages/store/gas-report.json +++ b/packages/store/gas-report.json @@ -21,7 +21,7 @@ "file": "test/Callbacks.t.sol", "test": "testSetAndGet", "name": "Callbacks: get field (warm)", - "gasUsed": 2615 + "gasUsed": 2616 }, { "file": "test/Callbacks.t.sol", @@ -321,7 +321,7 @@ "file": "test/KeyEncoding.t.sol", "test": "testRegisterAndGetFieldLayout", "name": "register KeyEncoding table", - "gasUsed": 723941 + "gasUsed": 717787 }, { "file": "test/Mixed.t.sol", @@ -1107,7 +1107,7 @@ "file": "test/Vector2.t.sol", "test": "testRegisterAndGetFieldLayout", "name": "register Vector2 field layout", - "gasUsed": 447721 + "gasUsed": 443849 }, { "file": "test/Vector2.t.sol", diff --git a/packages/store/package.json b/packages/store/package.json index cef5a69075..81ee8a66ab 100644 --- a/packages/store/package.json +++ b/packages/store/package.json @@ -53,6 +53,7 @@ "dependencies": { "@latticexyz/common": "workspace:*", "@latticexyz/config": "workspace:*", + "@latticexyz/protocol-parser": "workspace:*", "@latticexyz/schema-type": "workspace:*", "abitype": "1.0.0", "viem": "2.7.12", diff --git a/packages/store/src/StoreCore.sol b/packages/store/src/StoreCore.sol index 1c8be06681..4b49743ba9 100644 --- a/packages/store/src/StoreCore.sol +++ b/packages/store/src/StoreCore.sol @@ -115,16 +115,16 @@ library StoreCore { Tables._set( Tables._tableId, Tables._fieldLayout, - Tables.getKeySchema(), - Tables.getValueSchema(), + Tables._keySchema, + Tables._valueSchema, abi.encode(Tables.getKeyNames()), abi.encode(Tables.getFieldNames()) ); Tables._set( ResourceIds._tableId, ResourceIds._fieldLayout, - ResourceIds.getKeySchema(), - ResourceIds.getValueSchema(), + ResourceIds._keySchema, + ResourceIds._valueSchema, abi.encode(ResourceIds.getKeyNames()), abi.encode(ResourceIds.getFieldNames()) ); diff --git a/packages/store/src/codegen/tables/Hooks.sol b/packages/store/src/codegen/tables/Hooks.sol index 42497a7eb6..0ed6108f1d 100644 --- a/packages/store/src/codegen/tables/Hooks.sol +++ b/packages/store/src/codegen/tables/Hooks.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "../../IStore.sol"; import { StoreSwitch } from "../../StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "../../Bytes.sol"; import { Memory } from "../../Memory.sol"; import { SliceLib } from "../../Slice.sol"; import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "../../FieldLayout.sol"; -import { Schema, SchemaLib } from "../../Schema.sol"; +import { FieldLayout } from "../../FieldLayout.sol"; +import { Schema } from "../../Schema.sol"; import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; import { ResourceId } from "../../ResourceId.sol"; @@ -26,27 +23,10 @@ library Hooks { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.BYTES21_ARRAY; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bytes21[]) + Schema constant _valueSchema = Schema.wrap(0x00000001b6000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -70,14 +50,14 @@ library Hooks { * @notice Register the table with its config. */ function register(ResourceId _tableId) internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register(ResourceId _tableId) internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/store/src/codegen/tables/ResourceIds.sol b/packages/store/src/codegen/tables/ResourceIds.sol index ce694bf31a..7951d5c1e4 100644 --- a/packages/store/src/codegen/tables/ResourceIds.sol +++ b/packages/store/src/codegen/tables/ResourceIds.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "../../IStore.sol"; import { StoreSwitch } from "../../StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "../../Bytes.sol"; import { Memory } from "../../Memory.sol"; import { SliceLib } from "../../Slice.sol"; import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "../../FieldLayout.sol"; -import { Schema, SchemaLib } from "../../Schema.sol"; +import { FieldLayout } from "../../FieldLayout.sol"; +import { Schema } from "../../Schema.sol"; import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; import { ResourceId } from "../../ResourceId.sol"; @@ -29,27 +26,10 @@ library ResourceIds { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0001010001000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.BOOL; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bool) + Schema constant _valueSchema = Schema.wrap(0x0001010060000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -73,14 +53,14 @@ library ResourceIds { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/store/src/codegen/tables/StoreHooks.sol b/packages/store/src/codegen/tables/StoreHooks.sol index 953cd67180..b87dc19fd5 100644 --- a/packages/store/src/codegen/tables/StoreHooks.sol +++ b/packages/store/src/codegen/tables/StoreHooks.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "../../IStore.sol"; import { StoreSwitch } from "../../StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "../../Bytes.sol"; import { Memory } from "../../Memory.sol"; import { SliceLib } from "../../Slice.sol"; import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "../../FieldLayout.sol"; -import { Schema, SchemaLib } from "../../Schema.sol"; +import { FieldLayout } from "../../FieldLayout.sol"; +import { Schema } from "../../Schema.sol"; import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; import { ResourceId } from "../../ResourceId.sol"; @@ -29,27 +26,10 @@ library StoreHooks { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.BYTES21_ARRAY; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bytes21[]) + Schema constant _valueSchema = Schema.wrap(0x00000001b6000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -73,14 +53,14 @@ library StoreHooks { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/store/src/codegen/tables/Tables.sol b/packages/store/src/codegen/tables/Tables.sol index b4c6d0b86c..8197adb4d8 100644 --- a/packages/store/src/codegen/tables/Tables.sol +++ b/packages/store/src/codegen/tables/Tables.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "../../IStore.sol"; import { StoreSwitch } from "../../StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "../../Bytes.sol"; import { Memory } from "../../Memory.sol"; import { SliceLib } from "../../Slice.sol"; import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "../../FieldLayout.sol"; -import { Schema, SchemaLib } from "../../Schema.sol"; +import { FieldLayout } from "../../FieldLayout.sol"; +import { Schema } from "../../Schema.sol"; import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; import { ResourceId } from "../../ResourceId.sol"; @@ -39,31 +36,10 @@ library Tables { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0060030220202000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](5); - _valueSchema[0] = SchemaType.BYTES32; - _valueSchema[1] = SchemaType.BYTES32; - _valueSchema[2] = SchemaType.BYTES32; - _valueSchema[3] = SchemaType.BYTES; - _valueSchema[4] = SchemaType.BYTES; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bytes32, bytes32, bytes32, bytes, bytes) + Schema constant _valueSchema = Schema.wrap(0x006003025f5f5fc4c40000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -91,14 +67,14 @@ library Tables { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/store/test/Callbacks.t.sol b/packages/store/test/Callbacks.t.sol index f9af114b08..108d7d8105 100644 --- a/packages/store/test/Callbacks.t.sol +++ b/packages/store/test/Callbacks.t.sol @@ -5,6 +5,7 @@ import { Test } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { Callbacks } from "./codegen/tables/Callbacks.sol"; import { StoreMock } from "./StoreMock.sol"; +import { Schema, SchemaLib, SchemaType } from "../src/Schema.sol"; contract CallbacksTest is Test, GasReporter, StoreMock { function testSetAndGet() public { @@ -34,4 +35,18 @@ contract CallbacksTest is Test, GasReporter, StoreMock { assertEq(returnedCallbacks.length, 2); assertEq(returnedCallbacks[1], callbacks[0]); } + + function testKeySchemaEncoding() public { + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; + + assertEq(Schema.unwrap(SchemaLib.encode(_keySchema)), Schema.unwrap(Callbacks._keySchema)); + } + + function testValueSchemaEncoding() public { + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.BYTES24_ARRAY; + + assertEq(Schema.unwrap(SchemaLib.encode(_valueSchema)), Schema.unwrap(Callbacks._valueSchema)); + } } diff --git a/packages/store/test/KeyEncoding.t.sol b/packages/store/test/KeyEncoding.t.sol index 2215706233..308bc696b2 100644 --- a/packages/store/test/KeyEncoding.t.sol +++ b/packages/store/test/KeyEncoding.t.sol @@ -5,7 +5,7 @@ import { Test } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { StoreCore } from "../src/StoreCore.sol"; import { FieldLayout } from "../src/FieldLayout.sol"; -import { Schema } from "../src/Schema.sol"; +import { Schema, SchemaLib, SchemaType } from "../src/Schema.sol"; import { StoreMock } from "./StoreMock.sol"; import { KeyEncoding } from "./codegen/index.sol"; @@ -27,7 +27,7 @@ contract KeyEncodingTest is Test, GasReporter, StoreMock { KeyEncoding.register(); Schema registeredSchema = StoreCore.getValueSchema(KeyEncoding._tableId); - Schema declaredSchema = KeyEncoding.getValueSchema(); + Schema declaredSchema = KeyEncoding._valueSchema; assertEq(keccak256(abi.encode(registeredSchema)), keccak256(abi.encode(declaredSchema))); } @@ -87,4 +87,23 @@ contract KeyEncodingTest is Test, GasReporter, StoreMock { assertEq(keyTuple[4], bytes32(abi.encode(true))); assertEq(keyTuple[5], bytes32(abi.encode(ExampleEnum.Third))); } + + function testKeySchemaEncoding() public { + SchemaType[] memory _keySchema = new SchemaType[](6); + _keySchema[0] = SchemaType.UINT256; + _keySchema[1] = SchemaType.INT32; + _keySchema[2] = SchemaType.BYTES16; + _keySchema[3] = SchemaType.ADDRESS; + _keySchema[4] = SchemaType.BOOL; + _keySchema[5] = SchemaType.UINT8; + + assertEq(Schema.unwrap(SchemaLib.encode(_keySchema)), Schema.unwrap(KeyEncoding._keySchema)); + } + + function testValueSchemaEncoding() public { + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.BOOL; + + assertEq(Schema.unwrap(SchemaLib.encode(_valueSchema)), Schema.unwrap(KeyEncoding._valueSchema)); + } } diff --git a/packages/store/test/Mixed.t.sol b/packages/store/test/Mixed.t.sol index 1318a37082..31925d812f 100644 --- a/packages/store/test/Mixed.t.sol +++ b/packages/store/test/Mixed.t.sol @@ -6,7 +6,7 @@ import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { StoreCore } from "../src/StoreCore.sol"; import { StoreMock } from "../test/StoreMock.sol"; import { FieldLayout } from "../src/FieldLayout.sol"; -import { Schema } from "../src/Schema.sol"; +import { Schema, SchemaLib, SchemaType } from "../src/Schema.sol"; import { PackedCounter } from "../src/PackedCounter.sol"; import { Mixed, MixedData } from "./codegen/index.sol"; @@ -34,7 +34,7 @@ contract MixedTest is Test, GasReporter, StoreMock { function testRegisterAndGetSchema() public { Schema registeredSchema = StoreCore.getValueSchema(Mixed._tableId); - Schema declaredSchema = Mixed.getValueSchema(); + Schema declaredSchema = Mixed._valueSchema; assertEq(keccak256(abi.encode(registeredSchema)), keccak256(abi.encode(declaredSchema))); } @@ -130,4 +130,21 @@ contract MixedTest is Test, GasReporter, StoreMock { assertEq(encodedLengths.unwrap(), hex"000000000000000000000000000000000000000b000000000800000000000013"); assertEq(dynamicData, hex"0000000300000004736f6d6520737472696e67"); } + + function testKeySchemaEncoding() public { + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; + + assertEq(Schema.unwrap(SchemaLib.encode(_keySchema)), Schema.unwrap(Mixed._keySchema)); + } + + function testValueSchemaEncoding() public { + SchemaType[] memory _valueSchema = new SchemaType[](4); + _valueSchema[0] = SchemaType.UINT32; + _valueSchema[1] = SchemaType.UINT128; + _valueSchema[2] = SchemaType.UINT32_ARRAY; + _valueSchema[3] = SchemaType.STRING; + + assertEq(Schema.unwrap(SchemaLib.encode(_valueSchema)), Schema.unwrap(Mixed._valueSchema)); + } } diff --git a/packages/store/test/Vector2.t.sol b/packages/store/test/Vector2.t.sol index d1b9db9131..6ad8c1aae6 100644 --- a/packages/store/test/Vector2.t.sol +++ b/packages/store/test/Vector2.t.sol @@ -6,7 +6,7 @@ import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { StoreCore } from "../src/StoreCore.sol"; import { StoreMock } from "../test/StoreMock.sol"; import { FieldLayout } from "../src/FieldLayout.sol"; -import { Schema } from "../src/Schema.sol"; +import { Schema, SchemaLib, SchemaType } from "../src/Schema.sol"; import { Vector2, Vector2Data } from "./codegen/index.sol"; @@ -26,7 +26,7 @@ contract Vector2Test is Test, GasReporter, StoreMock { Vector2.register(); Schema registeredSchema = StoreCore.getValueSchema(Vector2._tableId); - Schema declaredSchema = Vector2.getValueSchema(); + Schema declaredSchema = Vector2._valueSchema; assertEq(Schema.unwrap(registeredSchema), Schema.unwrap(declaredSchema)); } @@ -46,4 +46,19 @@ contract Vector2Test is Test, GasReporter, StoreMock { assertEq(vector.x, 1); assertEq(vector.y, 2); } + + function testKeySchemaEncoding() public { + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; + + assertEq(Schema.unwrap(SchemaLib.encode(_keySchema)), Schema.unwrap(Vector2._keySchema)); + } + + function testValueSchemaEncoding() public { + SchemaType[] memory _valueSchema = new SchemaType[](2); + _valueSchema[0] = SchemaType.UINT32; + _valueSchema[1] = SchemaType.UINT32; + + assertEq(Schema.unwrap(SchemaLib.encode(_valueSchema)), Schema.unwrap(Vector2._valueSchema)); + } } diff --git a/packages/store/test/codegen/tables/Callbacks.sol b/packages/store/test/codegen/tables/Callbacks.sol index 1fe189f32d..e2a5e14f51 100644 --- a/packages/store/test/codegen/tables/Callbacks.sol +++ b/packages/store/test/codegen/tables/Callbacks.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "../../../src/IStore.sol"; import { StoreSwitch } from "../../../src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "../../../src/Bytes.sol"; import { Memory } from "../../../src/Memory.sol"; import { SliceLib } from "../../../src/Slice.sol"; import { EncodeArray } from "../../../src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "../../../src/FieldLayout.sol"; -import { Schema, SchemaLib } from "../../../src/Schema.sol"; +import { FieldLayout } from "../../../src/FieldLayout.sol"; +import { Schema } from "../../../src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "../../../src/PackedCounter.sol"; import { ResourceId } from "../../../src/ResourceId.sol"; @@ -26,27 +23,10 @@ library Callbacks { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.BYTES24_ARRAY; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bytes24[]) + Schema constant _valueSchema = Schema.wrap(0x00000001b9000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -70,14 +50,14 @@ library Callbacks { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/store/test/codegen/tables/KeyEncoding.sol b/packages/store/test/codegen/tables/KeyEncoding.sol index 2ed7bbfcc0..4ee62a2c8f 100644 --- a/packages/store/test/codegen/tables/KeyEncoding.sol +++ b/packages/store/test/codegen/tables/KeyEncoding.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "../../../src/IStore.sol"; import { StoreSwitch } from "../../../src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "../../../src/Bytes.sol"; import { Memory } from "../../../src/Memory.sol"; import { SliceLib } from "../../../src/Slice.sol"; import { EncodeArray } from "../../../src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "../../../src/FieldLayout.sol"; -import { Schema, SchemaLib } from "../../../src/Schema.sol"; +import { FieldLayout } from "../../../src/FieldLayout.sol"; +import { Schema } from "../../../src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "../../../src/PackedCounter.sol"; import { ResourceId } from "../../../src/ResourceId.sol"; @@ -29,32 +26,10 @@ library KeyEncoding { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0001010001000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](6); - _keySchema[0] = SchemaType.UINT256; - _keySchema[1] = SchemaType.INT32; - _keySchema[2] = SchemaType.BYTES16; - _keySchema[3] = SchemaType.ADDRESS; - _keySchema[4] = SchemaType.BOOL; - _keySchema[5] = SchemaType.UINT8; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.BOOL; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (uint256, int32, bytes16, address, bool, uint8) + Schema constant _keySchema = Schema.wrap(0x004a06001f234f61600000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bool) + Schema constant _valueSchema = Schema.wrap(0x0001010060000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -83,14 +58,14 @@ library KeyEncoding { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/store/test/codegen/tables/Mixed.sol b/packages/store/test/codegen/tables/Mixed.sol index 62f6a17a5c..68c8a475ed 100644 --- a/packages/store/test/codegen/tables/Mixed.sol +++ b/packages/store/test/codegen/tables/Mixed.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "../../../src/IStore.sol"; import { StoreSwitch } from "../../../src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "../../../src/Bytes.sol"; import { Memory } from "../../../src/Memory.sol"; import { SliceLib } from "../../../src/Slice.sol"; import { EncodeArray } from "../../../src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "../../../src/FieldLayout.sol"; -import { Schema, SchemaLib } from "../../../src/Schema.sol"; +import { FieldLayout } from "../../../src/FieldLayout.sol"; +import { Schema } from "../../../src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "../../../src/PackedCounter.sol"; import { ResourceId } from "../../../src/ResourceId.sol"; @@ -33,30 +30,10 @@ library Mixed { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0014020204100000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](4); - _valueSchema[0] = SchemaType.UINT32; - _valueSchema[1] = SchemaType.UINT128; - _valueSchema[2] = SchemaType.UINT32_ARRAY; - _valueSchema[3] = SchemaType.STRING; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint32, uint128, uint32[], string) + Schema constant _valueSchema = Schema.wrap(0x00140202030f65c5000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -83,14 +60,14 @@ library Mixed { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/store/test/codegen/tables/Vector2.sol b/packages/store/test/codegen/tables/Vector2.sol index d2e12843ba..d15b8fef52 100644 --- a/packages/store/test/codegen/tables/Vector2.sol +++ b/packages/store/test/codegen/tables/Vector2.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "../../../src/IStore.sol"; import { StoreSwitch } from "../../../src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "../../../src/Bytes.sol"; import { Memory } from "../../../src/Memory.sol"; import { SliceLib } from "../../../src/Slice.sol"; import { EncodeArray } from "../../../src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "../../../src/FieldLayout.sol"; -import { Schema, SchemaLib } from "../../../src/Schema.sol"; +import { FieldLayout } from "../../../src/FieldLayout.sol"; +import { Schema } from "../../../src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "../../../src/PackedCounter.sol"; import { ResourceId } from "../../../src/ResourceId.sol"; @@ -31,28 +28,10 @@ library Vector2 { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0008020004040000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](2); - _valueSchema[0] = SchemaType.UINT32; - _valueSchema[1] = SchemaType.UINT32; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint32, uint32) + Schema constant _valueSchema = Schema.wrap(0x0008020003030000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -77,14 +56,14 @@ library Vector2 { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/store/ts/codegen/renderTable.ts b/packages/store/ts/codegen/renderTable.ts index 2228021c26..e7fba56e6b 100644 --- a/packages/store/ts/codegen/renderTable.ts +++ b/packages/store/ts/codegen/renderTable.ts @@ -14,6 +14,7 @@ import { renderEncodeFieldSingle, renderFieldMethods } from "./field"; import { renderDeleteRecordMethods, renderRecordData, renderRecordMethods } from "./record"; import { renderFieldLayout } from "./renderFieldLayout"; import { RenderTableOptions } from "./types"; +import { KeySchema, ValueSchema, keySchemaToHex, valueSchemaToHex } from "@latticexyz/protocol-parser"; /** * Renders Solidity code for a MUD table library, using the specified options @@ -40,9 +41,6 @@ export function renderTable(options: RenderTableOptions) { return ` ${renderedSolidityHeader} - // Import schema type - import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "${storeImportPath}IStore.sol"; import { StoreSwitch } from "${storeImportPath}StoreSwitch.sol"; @@ -51,8 +49,8 @@ export function renderTable(options: RenderTableOptions) { import { Memory } from "${storeImportPath}Memory.sol"; import { SliceLib } from "${storeImportPath}Slice.sol"; import { EncodeArray } from "${storeImportPath}tightcoder/EncodeArray.sol"; - import { FieldLayout, FieldLayoutLib } from "${storeImportPath}FieldLayout.sol"; - import { Schema, SchemaLib } from "${storeImportPath}Schema.sol"; + import { FieldLayout } from "${storeImportPath}FieldLayout.sol"; + import { Schema } from "${storeImportPath}Schema.sol"; import { PackedCounter, PackedCounterLib } from "${storeImportPath}PackedCounter.sol"; import { ResourceId } from "${storeImportPath}ResourceId.sol"; @@ -80,27 +78,14 @@ export function renderTable(options: RenderTableOptions) { ${renderFieldLayout(fields)} - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](${keyTuple.length}); - ${renderList(keyTuple, ({ enumName }, index) => `_keySchema[${index}] = SchemaType.${enumName};`)} - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](${fields.length}); - ${renderList(fields, ({ enumName }, index) => `_valueSchema[${index}] = SchemaType.${enumName};`)} - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (${keyTuple.map((field) => field.internalTypeId).join(", ")}) + Schema constant _keySchema = Schema.wrap(${keySchemaToHex( + Object.fromEntries(keyTuple.map((field) => [field.name, field.internalTypeId])) as KeySchema + )}); + // Hex-encoded value schema of (${fields.map((field) => field.internalTypeId).join(", ")}) + Schema constant _valueSchema = Schema.wrap(${valueSchemaToHex( + Object.fromEntries(fields.map((field) => [field.name, field.internalTypeId])) as ValueSchema + )}); /** * @notice Get the table's key field names. @@ -127,7 +112,7 @@ export function renderTable(options: RenderTableOptions) { * @notice Register the table with its config${_commentSuffix}. */ function ${_methodNamePrefix}register(${renderArguments([_typedStore, _typedTableId])}) internal { - ${_store}.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + ${_store}.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } ` )} diff --git a/packages/world-modules/gas-report.json b/packages/world-modules/gas-report.json index 766f0c311f..f30428b4ca 100644 --- a/packages/world-modules/gas-report.json +++ b/packages/world-modules/gas-report.json @@ -75,13 +75,13 @@ "file": "test/KeysInTableModule.t.sol", "test": "testInstallComposite", "name": "install keys in table module", - "gasUsed": 1424604 + "gasUsed": 1414379 }, { "file": "test/KeysInTableModule.t.sol", "test": "testInstallGas", "name": "install keys in table module", - "gasUsed": 1424604 + "gasUsed": 1414379 }, { "file": "test/KeysInTableModule.t.sol", @@ -93,13 +93,13 @@ "file": "test/KeysInTableModule.t.sol", "test": "testInstallSingleton", "name": "install keys in table module", - "gasUsed": 1424604 + "gasUsed": 1414379 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookCompositeGas", "name": "install keys in table module", - "gasUsed": 1424604 + "gasUsed": 1414379 }, { "file": "test/KeysInTableModule.t.sol", @@ -117,7 +117,7 @@ "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookGas", "name": "install keys in table module", - "gasUsed": 1424604 + "gasUsed": 1414379 }, { "file": "test/KeysInTableModule.t.sol", @@ -135,7 +135,7 @@ "file": "test/KeysWithValueModule.t.sol", "test": "testGetKeysWithValueGas", "name": "install keys with value module", - "gasUsed": 676690 + "gasUsed": 673326 }, { "file": "test/KeysWithValueModule.t.sol", @@ -153,7 +153,7 @@ "file": "test/KeysWithValueModule.t.sol", "test": "testInstall", "name": "install keys with value module", - "gasUsed": 676690 + "gasUsed": 673326 }, { "file": "test/KeysWithValueModule.t.sol", @@ -165,7 +165,7 @@ "file": "test/KeysWithValueModule.t.sol", "test": "testSetAndDeleteRecordHook", "name": "install keys with value module", - "gasUsed": 676690 + "gasUsed": 673326 }, { "file": "test/KeysWithValueModule.t.sol", @@ -183,7 +183,7 @@ "file": "test/KeysWithValueModule.t.sol", "test": "testSetField", "name": "install keys with value module", - "gasUsed": 676690 + "gasUsed": 673326 }, { "file": "test/KeysWithValueModule.t.sol", @@ -303,7 +303,7 @@ "file": "test/UniqueEntityModule.t.sol", "test": "testInstall", "name": "install unique entity module", - "gasUsed": 691509 + "gasUsed": 688807 }, { "file": "test/UniqueEntityModule.t.sol", @@ -315,7 +315,7 @@ "file": "test/UniqueEntityModule.t.sol", "test": "testInstallRoot", "name": "installRoot unique entity module", - "gasUsed": 661978 + "gasUsed": 659276 }, { "file": "test/UniqueEntityModule.t.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 df8bb8bd19..f8b2fb9b23 100644 --- a/packages/world-modules/src/modules/erc20-puppet/tables/Allowances.sol +++ b/packages/world-modules/src/modules/erc20-puppet/tables/Allowances.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -23,28 +20,10 @@ library Allowances { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](2); - _keySchema[0] = SchemaType.ADDRESS; - _keySchema[1] = SchemaType.ADDRESS; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.UINT256; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (address, address) + Schema constant _keySchema = Schema.wrap(0x0028020061610000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint256) + Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -69,14 +48,14 @@ library Allowances { * @notice Register the table with its config. */ function register(ResourceId _tableId) internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register(ResourceId _tableId) internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** 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 45184db902..830107f1bf 100644 --- a/packages/world-modules/src/modules/erc20-puppet/tables/ERC20Metadata.sol +++ b/packages/world-modules/src/modules/erc20-puppet/tables/ERC20Metadata.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -29,28 +26,10 @@ library ERC20Metadata { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0001010201000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](0); - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](3); - _valueSchema[0] = SchemaType.UINT8; - _valueSchema[1] = SchemaType.STRING; - _valueSchema[2] = SchemaType.STRING; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of () + Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint8, string, string) + Schema constant _valueSchema = Schema.wrap(0x0001010200c5c500000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -75,14 +54,14 @@ library ERC20Metadata { * @notice Register the table with its config. */ function register(ResourceId _tableId) internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register(ResourceId _tableId) internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** 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 01e662c28c..85737c4120 100644 --- a/packages/world-modules/src/modules/erc20-puppet/tables/ERC20Registry.sol +++ b/packages/world-modules/src/modules/erc20-puppet/tables/ERC20Registry.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,27 +23,10 @@ library ERC20Registry { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.ADDRESS; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (address) + Schema constant _valueSchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -70,14 +50,14 @@ library ERC20Registry { * @notice Register the table with its config. */ function register(ResourceId _tableId) internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register(ResourceId _tableId) internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** 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 8a35ea2be2..a633aff8ec 100644 --- a/packages/world-modules/src/modules/erc20-puppet/tables/TotalSupply.sol +++ b/packages/world-modules/src/modules/erc20-puppet/tables/TotalSupply.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -23,26 +20,10 @@ library TotalSupply { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](0); - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.UINT256; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of () + Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint256) + Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -65,14 +46,14 @@ library TotalSupply { * @notice Register the table with its config. */ function register(ResourceId _tableId) internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register(ResourceId _tableId) internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** 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 5263ea10d9..dd43390ec5 100644 --- a/packages/world-modules/src/modules/erc721-puppet/tables/ERC721Metadata.sol +++ b/packages/world-modules/src/modules/erc721-puppet/tables/ERC721Metadata.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -29,28 +26,10 @@ library ERC721Metadata { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000300000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](0); - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](3); - _valueSchema[0] = SchemaType.STRING; - _valueSchema[1] = SchemaType.STRING; - _valueSchema[2] = SchemaType.STRING; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of () + Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (string, string, string) + Schema constant _valueSchema = Schema.wrap(0x00000003c5c5c500000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -75,14 +54,14 @@ library ERC721Metadata { * @notice Register the table with its config. */ function register(ResourceId _tableId) internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register(ResourceId _tableId) internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** 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 d3e0c82716..59b1a502f9 100644 --- a/packages/world-modules/src/modules/erc721-puppet/tables/ERC721Registry.sol +++ b/packages/world-modules/src/modules/erc721-puppet/tables/ERC721Registry.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,27 +23,10 @@ library ERC721Registry { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.ADDRESS; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (address) + Schema constant _valueSchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -70,14 +50,14 @@ library ERC721Registry { * @notice Register the table with its config. */ function register(ResourceId _tableId) internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register(ResourceId _tableId) internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** 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 7181b3d755..561f31d6ca 100644 --- a/packages/world-modules/src/modules/erc721-puppet/tables/OperatorApproval.sol +++ b/packages/world-modules/src/modules/erc721-puppet/tables/OperatorApproval.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -23,28 +20,10 @@ library OperatorApproval { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0001010001000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](2); - _keySchema[0] = SchemaType.ADDRESS; - _keySchema[1] = SchemaType.ADDRESS; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.BOOL; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (address, address) + Schema constant _keySchema = Schema.wrap(0x0028020061610000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bool) + Schema constant _valueSchema = Schema.wrap(0x0001010060000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -69,14 +48,14 @@ library OperatorApproval { * @notice Register the table with its config. */ function register(ResourceId _tableId) internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register(ResourceId _tableId) internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** 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 72ca90268d..abb43fed8c 100644 --- a/packages/world-modules/src/modules/erc721-puppet/tables/Owners.sol +++ b/packages/world-modules/src/modules/erc721-puppet/tables/Owners.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -23,27 +20,10 @@ library Owners { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.UINT256; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.ADDRESS; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (uint256) + Schema constant _keySchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (address) + Schema constant _valueSchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -67,14 +47,14 @@ library Owners { * @notice Register the table with its config. */ function register(ResourceId _tableId) internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register(ResourceId _tableId) internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** 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 fcc3b300be..8427e9e2ba 100644 --- a/packages/world-modules/src/modules/erc721-puppet/tables/TokenApproval.sol +++ b/packages/world-modules/src/modules/erc721-puppet/tables/TokenApproval.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -23,27 +20,10 @@ library TokenApproval { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.UINT256; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.ADDRESS; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (uint256) + Schema constant _keySchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (address) + Schema constant _valueSchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -67,14 +47,14 @@ library TokenApproval { * @notice Register the table with its config. */ function register(ResourceId _tableId) internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register(ResourceId _tableId) internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** 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 48253f5983..def9646cfb 100644 --- a/packages/world-modules/src/modules/erc721-puppet/tables/TokenURI.sol +++ b/packages/world-modules/src/modules/erc721-puppet/tables/TokenURI.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -23,27 +20,10 @@ library TokenURI { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.UINT256; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.STRING; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (uint256) + Schema constant _keySchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (string) + Schema constant _valueSchema = Schema.wrap(0x00000001c5000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -67,14 +47,14 @@ library TokenURI { * @notice Register the table with its config. */ function register(ResourceId _tableId) internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register(ResourceId _tableId) internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world-modules/src/modules/keysintable/KeysInTableModule.sol b/packages/world-modules/src/modules/keysintable/KeysInTableModule.sol index a54f2f71e4..295129885d 100644 --- a/packages/world-modules/src/modules/keysintable/KeysInTableModule.sol +++ b/packages/world-modules/src/modules/keysintable/KeysInTableModule.sol @@ -55,8 +55,8 @@ contract KeysInTableModule is Module { ( KeysInTable._tableId, KeysInTable._fieldLayout, - KeysInTable.getKeySchema(), - KeysInTable.getValueSchema(), + KeysInTable._keySchema, + KeysInTable._valueSchema, KeysInTable.getKeyNames(), KeysInTable.getFieldNames() ) @@ -70,8 +70,8 @@ contract KeysInTableModule is Module { ( UsedKeysIndex._tableId, UsedKeysIndex._fieldLayout, - UsedKeysIndex.getKeySchema(), - UsedKeysIndex.getValueSchema(), + UsedKeysIndex._keySchema, + UsedKeysIndex._valueSchema, UsedKeysIndex.getKeyNames(), UsedKeysIndex.getFieldNames() ) diff --git a/packages/world-modules/src/modules/keysintable/tables/KeysInTable.sol b/packages/world-modules/src/modules/keysintable/tables/KeysInTable.sol index ab3e522f2a..f3cc092eb6 100644 --- a/packages/world-modules/src/modules/keysintable/tables/KeysInTable.sol +++ b/packages/world-modules/src/modules/keysintable/tables/KeysInTable.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -37,31 +34,10 @@ library KeysInTable { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000500000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](5); - _valueSchema[0] = SchemaType.BYTES32_ARRAY; - _valueSchema[1] = SchemaType.BYTES32_ARRAY; - _valueSchema[2] = SchemaType.BYTES32_ARRAY; - _valueSchema[3] = SchemaType.BYTES32_ARRAY; - _valueSchema[4] = SchemaType.BYTES32_ARRAY; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bytes32[], bytes32[], bytes32[], bytes32[], bytes32[]) + Schema constant _valueSchema = Schema.wrap(0x00000005c1c1c1c1c10000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -89,21 +65,21 @@ library KeysInTable { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config (using the specified store). */ function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world-modules/src/modules/keysintable/tables/UsedKeysIndex.sol b/packages/world-modules/src/modules/keysintable/tables/UsedKeysIndex.sol index dde9b764fb..a5e8d55e2f 100644 --- a/packages/world-modules/src/modules/keysintable/tables/UsedKeysIndex.sol +++ b/packages/world-modules/src/modules/keysintable/tables/UsedKeysIndex.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -29,29 +26,10 @@ library UsedKeysIndex { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0006020001050000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](2); - _keySchema[0] = SchemaType.BYTES32; - _keySchema[1] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](2); - _valueSchema[0] = SchemaType.BOOL; - _valueSchema[1] = SchemaType.UINT40; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32, bytes32) + Schema constant _keySchema = Schema.wrap(0x004002005f5f0000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bool, uint40) + Schema constant _valueSchema = Schema.wrap(0x0006020060040000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -77,21 +55,21 @@ library UsedKeysIndex { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config (using the specified store). */ function register(IStore _store) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world-modules/src/modules/keyswithvalue/KeysWithValueModule.sol b/packages/world-modules/src/modules/keyswithvalue/KeysWithValueModule.sol index 1bc943518b..5d35813389 100644 --- a/packages/world-modules/src/modules/keyswithvalue/KeysWithValueModule.sol +++ b/packages/world-modules/src/modules/keyswithvalue/KeysWithValueModule.sol @@ -61,8 +61,8 @@ contract KeysWithValueModule is Module { ( targetTableId, KeysWithValue._fieldLayout, - KeysWithValue.getKeySchema(), - KeysWithValue.getValueSchema(), + KeysWithValue._keySchema, + KeysWithValue._valueSchema, KeysWithValue.getKeyNames(), KeysWithValue.getFieldNames() ) diff --git a/packages/world-modules/src/modules/keyswithvalue/tables/KeysWithValue.sol b/packages/world-modules/src/modules/keyswithvalue/tables/KeysWithValue.sol index 65eb8319e3..d6209086ce 100644 --- a/packages/world-modules/src/modules/keyswithvalue/tables/KeysWithValue.sol +++ b/packages/world-modules/src/modules/keyswithvalue/tables/KeysWithValue.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -23,27 +20,10 @@ library KeysWithValue { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.BYTES32_ARRAY; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bytes32[]) + Schema constant _valueSchema = Schema.wrap(0x00000001c1000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -67,21 +47,21 @@ library KeysWithValue { * @notice Register the table with its config. */ function register(ResourceId _tableId) internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register(ResourceId _tableId) internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config (using the specified store). */ function register(IStore _store, ResourceId _tableId) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world-modules/src/modules/puppet/tables/PuppetRegistry.sol b/packages/world-modules/src/modules/puppet/tables/PuppetRegistry.sol index 12e9b8d793..ef08642e3a 100644 --- a/packages/world-modules/src/modules/puppet/tables/PuppetRegistry.sol +++ b/packages/world-modules/src/modules/puppet/tables/PuppetRegistry.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,27 +23,10 @@ library PuppetRegistry { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.ADDRESS; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (address) + Schema constant _valueSchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -70,14 +50,14 @@ library PuppetRegistry { * @notice Register the table with its config. */ function register(ResourceId _tableId) internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register(ResourceId _tableId) internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** 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 e5b6aef1eb..73f3f5a65b 100644 --- a/packages/world-modules/src/modules/std-delegations/tables/CallboundDelegations.sol +++ b/packages/world-modules/src/modules/std-delegations/tables/CallboundDelegations.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -29,30 +26,10 @@ library CallboundDelegations { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](4); - _keySchema[0] = SchemaType.ADDRESS; - _keySchema[1] = SchemaType.ADDRESS; - _keySchema[2] = SchemaType.BYTES32; - _keySchema[3] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.UINT256; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (address, address, bytes32, bytes32) + Schema constant _keySchema = Schema.wrap(0x0068040061615f5f000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint256) + Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -79,14 +56,14 @@ library CallboundDelegations { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** 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 977713c06d..c0d3d130c3 100644 --- a/packages/world-modules/src/modules/std-delegations/tables/SystemboundDelegations.sol +++ b/packages/world-modules/src/modules/std-delegations/tables/SystemboundDelegations.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -29,29 +26,10 @@ library SystemboundDelegations { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](3); - _keySchema[0] = SchemaType.ADDRESS; - _keySchema[1] = SchemaType.ADDRESS; - _keySchema[2] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.UINT256; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (address, address, bytes32) + Schema constant _keySchema = Schema.wrap(0x0048030061615f00000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint256) + Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -77,14 +55,14 @@ library SystemboundDelegations { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** 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 67a47d4a8d..8cc669aaa6 100644 --- a/packages/world-modules/src/modules/std-delegations/tables/TimeboundDelegations.sol +++ b/packages/world-modules/src/modules/std-delegations/tables/TimeboundDelegations.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,28 +23,10 @@ library TimeboundDelegations { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](2); - _keySchema[0] = SchemaType.ADDRESS; - _keySchema[1] = SchemaType.ADDRESS; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.UINT256; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (address, address) + Schema constant _keySchema = Schema.wrap(0x0028020061610000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint256) + Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -72,14 +51,14 @@ library TimeboundDelegations { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world-modules/src/modules/tokens/tables/Balances.sol b/packages/world-modules/src/modules/tokens/tables/Balances.sol index eff7a7188c..bf4005967f 100644 --- a/packages/world-modules/src/modules/tokens/tables/Balances.sol +++ b/packages/world-modules/src/modules/tokens/tables/Balances.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -23,27 +20,10 @@ library Balances { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.ADDRESS; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.UINT256; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (address) + Schema constant _keySchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint256) + Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -67,14 +47,14 @@ library Balances { * @notice Register the table with its config. */ function register(ResourceId _tableId) internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register(ResourceId _tableId) internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world-modules/src/modules/uniqueentity/tables/UniqueEntity.sol b/packages/world-modules/src/modules/uniqueentity/tables/UniqueEntity.sol index 0b8d05c2e1..9d5a77ff8d 100644 --- a/packages/world-modules/src/modules/uniqueentity/tables/UniqueEntity.sol +++ b/packages/world-modules/src/modules/uniqueentity/tables/UniqueEntity.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -23,26 +20,10 @@ library UniqueEntity { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](0); - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.UINT256; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of () + Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint256) + Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -65,21 +46,21 @@ library UniqueEntity { * @notice Register the table with its config. */ function register(ResourceId _tableId) internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register(ResourceId _tableId) internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config (using the specified store). */ function register(IStore _store, ResourceId _tableId) internal { - _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world-modules/test/SystemSwitch.t.sol b/packages/world-modules/test/SystemSwitch.t.sol index 0371107ce9..6965ab2265 100644 --- a/packages/world-modules/test/SystemSwitch.t.sol +++ b/packages/world-modules/test/SystemSwitch.t.sol @@ -140,7 +140,7 @@ contract SystemSwitchTest is Test, GasReporter { function testCallRootFromRootReadTable() public { vm.prank(caller); bytes memory returnData = _executeFromSystemA(rootSystemBId, abi.encodeCall(EchoSystem.readTable, ())); - assertEq(Schema.unwrap(abi.decode(returnData, (Schema))), Schema.unwrap(ResourceIds.getKeySchema())); + assertEq(Schema.unwrap(abi.decode(returnData, (Schema))), Schema.unwrap(ResourceIds._keySchema)); } // - ROOT FROM NON ROOT ---------------------------------------------------------------------------- // @@ -179,7 +179,7 @@ contract SystemSwitchTest is Test, GasReporter { function testCallRootFromNonRootReadTable() public { vm.prank(caller); bytes memory returnData = _executeFromSystemA(rootSystemBId, abi.encodeCall(EchoSystem.readTable, ())); - assertEq(Schema.unwrap(abi.decode(returnData, (Schema))), Schema.unwrap(ResourceIds.getKeySchema())); + assertEq(Schema.unwrap(abi.decode(returnData, (Schema))), Schema.unwrap(ResourceIds._keySchema)); } // - NON ROOT FROM ROOT ---------------------------------------------------------------------------- // diff --git a/packages/world/gas-report.json b/packages/world/gas-report.json index 82ade812e1..6b913e22c6 100644 --- a/packages/world/gas-report.json +++ b/packages/world/gas-report.json @@ -63,7 +63,7 @@ "file": "test/Factories.t.sol", "test": "testWorldFactoryGas", "name": "deploy world via WorldFactory", - "gasUsed": 12698811 + "gasUsed": 12643627 }, { "file": "test/World.t.sol", @@ -93,7 +93,7 @@ "file": "test/World.t.sol", "test": "testDeleteRecord", "name": "Delete record", - "gasUsed": 8957 + "gasUsed": 8958 }, { "file": "test/World.t.sol", @@ -141,7 +141,7 @@ "file": "test/World.t.sol", "test": "testSetField", "name": "Write data to a table field", - "gasUsed": 36435 + "gasUsed": 36436 }, { "file": "test/World.t.sol", diff --git a/packages/world/src/codegen/tables/Balances.sol b/packages/world/src/codegen/tables/Balances.sol index 7e4e814dce..26291f56b3 100644 --- a/packages/world/src/codegen/tables/Balances.sol +++ b/packages/world/src/codegen/tables/Balances.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -29,27 +26,10 @@ library Balances { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.UINT256; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint256) + Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -73,14 +53,14 @@ library Balances { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world/src/codegen/tables/FunctionSelectors.sol b/packages/world/src/codegen/tables/FunctionSelectors.sol index d5ae335e63..d8e9424bd7 100644 --- a/packages/world/src/codegen/tables/FunctionSelectors.sol +++ b/packages/world/src/codegen/tables/FunctionSelectors.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -29,28 +26,10 @@ library FunctionSelectors { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0024020020040000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES4; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](2); - _valueSchema[0] = SchemaType.BYTES32; - _valueSchema[1] = SchemaType.BYTES4; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes4) + Schema constant _keySchema = Schema.wrap(0x0004010043000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bytes32, bytes4) + Schema constant _valueSchema = Schema.wrap(0x002402005f430000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -75,14 +54,14 @@ library FunctionSelectors { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world/src/codegen/tables/FunctionSignatures.sol b/packages/world/src/codegen/tables/FunctionSignatures.sol index 12af2ed59c..d2a4611869 100644 --- a/packages/world/src/codegen/tables/FunctionSignatures.sol +++ b/packages/world/src/codegen/tables/FunctionSignatures.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,27 +23,10 @@ library FunctionSignatures { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES4; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.STRING; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes4) + Schema constant _keySchema = Schema.wrap(0x0004010043000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (string) + Schema constant _valueSchema = Schema.wrap(0x00000001c5000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -70,14 +50,14 @@ library FunctionSignatures { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world/src/codegen/tables/InitModuleAddress.sol b/packages/world/src/codegen/tables/InitModuleAddress.sol index 74299d3ff5..b79eb9f210 100644 --- a/packages/world/src/codegen/tables/InitModuleAddress.sol +++ b/packages/world/src/codegen/tables/InitModuleAddress.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,26 +23,10 @@ library InitModuleAddress { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](0); - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.ADDRESS; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of () + Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (address) + Schema constant _valueSchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -68,14 +49,14 @@ library InitModuleAddress { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world/src/codegen/tables/InstalledModules.sol b/packages/world/src/codegen/tables/InstalledModules.sol index f4cabc0079..6cf4235993 100644 --- a/packages/world/src/codegen/tables/InstalledModules.sol +++ b/packages/world/src/codegen/tables/InstalledModules.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,28 +23,10 @@ library InstalledModules { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0001010001000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](2); - _keySchema[0] = SchemaType.ADDRESS; - _keySchema[1] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.BOOL; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (address, bytes32) + Schema constant _keySchema = Schema.wrap(0x00340200615f0000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bool) + Schema constant _valueSchema = Schema.wrap(0x0001010060000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -72,14 +51,14 @@ library InstalledModules { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world/src/codegen/tables/NamespaceDelegationControl.sol b/packages/world/src/codegen/tables/NamespaceDelegationControl.sol index b197ca6d4c..308b9ef2eb 100644 --- a/packages/world/src/codegen/tables/NamespaceDelegationControl.sol +++ b/packages/world/src/codegen/tables/NamespaceDelegationControl.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -29,27 +26,10 @@ library NamespaceDelegationControl { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bytes32) + Schema constant _valueSchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -73,14 +53,14 @@ library NamespaceDelegationControl { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world/src/codegen/tables/NamespaceOwner.sol b/packages/world/src/codegen/tables/NamespaceOwner.sol index f8baa78f9a..147d8cd9fc 100644 --- a/packages/world/src/codegen/tables/NamespaceOwner.sol +++ b/packages/world/src/codegen/tables/NamespaceOwner.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -29,27 +26,10 @@ library NamespaceOwner { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.ADDRESS; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (address) + Schema constant _valueSchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -73,14 +53,14 @@ library NamespaceOwner { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world/src/codegen/tables/ResourceAccess.sol b/packages/world/src/codegen/tables/ResourceAccess.sol index 6b4be575da..afe61091c2 100644 --- a/packages/world/src/codegen/tables/ResourceAccess.sol +++ b/packages/world/src/codegen/tables/ResourceAccess.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -29,28 +26,10 @@ library ResourceAccess { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0001010001000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](2); - _keySchema[0] = SchemaType.BYTES32; - _keySchema[1] = SchemaType.ADDRESS; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.BOOL; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32, address) + Schema constant _keySchema = Schema.wrap(0x003402005f610000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bool) + Schema constant _valueSchema = Schema.wrap(0x0001010060000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -75,14 +54,14 @@ library ResourceAccess { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world/src/codegen/tables/SystemHooks.sol b/packages/world/src/codegen/tables/SystemHooks.sol index 1bf20c1005..dc99c8190f 100644 --- a/packages/world/src/codegen/tables/SystemHooks.sol +++ b/packages/world/src/codegen/tables/SystemHooks.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -29,27 +26,10 @@ library SystemHooks { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.BYTES21_ARRAY; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bytes21[]) + Schema constant _valueSchema = Schema.wrap(0x00000001b6000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -73,14 +53,14 @@ library SystemHooks { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world/src/codegen/tables/SystemRegistry.sol b/packages/world/src/codegen/tables/SystemRegistry.sol index 1cc0c06168..c538650d08 100644 --- a/packages/world/src/codegen/tables/SystemRegistry.sol +++ b/packages/world/src/codegen/tables/SystemRegistry.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -29,27 +26,10 @@ library SystemRegistry { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.ADDRESS; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (address) + Schema constant _keySchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bytes32) + Schema constant _valueSchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -73,14 +53,14 @@ library SystemRegistry { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world/src/codegen/tables/Systems.sol b/packages/world/src/codegen/tables/Systems.sol index 163cf0911d..9dc15cfa1a 100644 --- a/packages/world/src/codegen/tables/Systems.sol +++ b/packages/world/src/codegen/tables/Systems.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -29,28 +26,10 @@ library Systems { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0015020014010000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](2); - _valueSchema[0] = SchemaType.ADDRESS; - _valueSchema[1] = SchemaType.BOOL; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (address, bool) + Schema constant _valueSchema = Schema.wrap(0x0015020061600000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -75,14 +54,14 @@ library Systems { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world/src/codegen/tables/UserDelegationControl.sol b/packages/world/src/codegen/tables/UserDelegationControl.sol index bce3d092ab..66064511cc 100644 --- a/packages/world/src/codegen/tables/UserDelegationControl.sol +++ b/packages/world/src/codegen/tables/UserDelegationControl.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -29,28 +26,10 @@ library UserDelegationControl { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](2); - _keySchema[0] = SchemaType.ADDRESS; - _keySchema[1] = SchemaType.ADDRESS; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (address, address) + Schema constant _keySchema = Schema.wrap(0x0028020061610000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bytes32) + Schema constant _valueSchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -75,14 +54,14 @@ library UserDelegationControl { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world/test/World.t.sol b/packages/world/test/World.t.sol index 8f24cffb4d..c1149e28db 100644 --- a/packages/world/test/World.t.sol +++ b/packages/world/test/World.t.sol @@ -597,7 +597,7 @@ contract WorldTest is Test, GasReporter { tableId, Bool._fieldLayout, defaultKeySchema, - Bool.getValueSchema(), + Bool._valueSchema, new string[](1), new string[](1) ); @@ -706,7 +706,7 @@ contract WorldTest is Test, GasReporter { tableId, Bool._fieldLayout, defaultKeySchema, - Bool.getValueSchema(), + Bool._valueSchema, new string[](1), new string[](1) ); @@ -742,7 +742,7 @@ contract WorldTest is Test, GasReporter { systemId, Bool._fieldLayout, defaultKeySchema, - Bool.getValueSchema(), + Bool._valueSchema, new string[](1), new string[](1) ); @@ -755,7 +755,7 @@ contract WorldTest is Test, GasReporter { tableId, Bool._fieldLayout, defaultKeySchema, - Bool.getValueSchema(), + Bool._valueSchema, new string[](1), new string[](1) ); @@ -780,8 +780,8 @@ contract WorldTest is Test, GasReporter { world.registerTable( tableId, TwoFields._fieldLayout, - TwoFields.getKeySchema(), - TwoFields.getValueSchema(), + TwoFields._keySchema, + TwoFields._valueSchema, new string[](0), new string[](2) ); @@ -810,7 +810,7 @@ contract WorldTest is Test, GasReporter { bytes16 name = "testTable"; ResourceId tableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: name }); FieldLayout fieldLayout = Bool._fieldLayout; - Schema valueSchema = Bool.getValueSchema(); + Schema valueSchema = Bool._valueSchema; world.registerNamespace(tableId.getNamespaceId()); // Register a new table @@ -840,7 +840,7 @@ contract WorldTest is Test, GasReporter { bytes16 name = "testTable"; ResourceId tableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: name }); FieldLayout fieldLayout = AddressArray._fieldLayout; - Schema valueSchema = AddressArray.getValueSchema(); + Schema valueSchema = AddressArray._valueSchema; // Register a new table world.registerNamespace(tableId.getNamespaceId()); @@ -886,7 +886,7 @@ contract WorldTest is Test, GasReporter { bytes16 name = "testTable"; ResourceId tableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: name }); FieldLayout fieldLayout = Bool._fieldLayout; - Schema valueSchema = Bool.getValueSchema(); + Schema valueSchema = Bool._valueSchema; // Register a new table world.registerNamespace(tableId.getNamespaceId()); @@ -1269,7 +1269,7 @@ contract WorldTest is Test, GasReporter { function testRegisterStoreHook() public { FieldLayout fieldLayout = Bool._fieldLayout; - Schema valueSchema = Bool.getValueSchema(); + Schema valueSchema = Bool._valueSchema; ResourceId tableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: "", name: "testTable" }); // Register a new table @@ -1336,7 +1336,7 @@ contract WorldTest is Test, GasReporter { function testUnregisterStoreHook() public { FieldLayout fieldLayout = Bool._fieldLayout; - Schema valueSchema = Bool.getValueSchema(); + Schema valueSchema = Bool._valueSchema; ResourceId tableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: "", name: "testTable" }); // Register a new table @@ -1524,7 +1524,7 @@ contract WorldTest is Test, GasReporter { tableId, Bool._fieldLayout, defaultKeySchema, - Bool.getValueSchema(), + Bool._valueSchema, new string[](1), new string[](1) ); @@ -1553,7 +1553,7 @@ contract WorldTest is Test, GasReporter { tableId, Bool._fieldLayout, defaultKeySchema, - Bool.getValueSchema(), + Bool._valueSchema, new string[](1), new string[](1) ); diff --git a/packages/world/test/WorldDynamicUpdate.t.sol b/packages/world/test/WorldDynamicUpdate.t.sol index cad453a510..cead1a8d96 100644 --- a/packages/world/test/WorldDynamicUpdate.t.sol +++ b/packages/world/test/WorldDynamicUpdate.t.sol @@ -54,7 +54,7 @@ contract UpdateInDynamicFieldTest is Test, GasReporter { keyTuple[0] = key; singletonKey = new bytes32[](0); FieldLayout fieldLayout = AddressArray._fieldLayout; - Schema valueSchema = AddressArray.getValueSchema(); + Schema valueSchema = AddressArray._valueSchema; // Initialize the data in setUp so that slots aren't warm in tests (to test cold update) diff --git a/packages/world/test/codegen/tables/AddressArray.sol b/packages/world/test/codegen/tables/AddressArray.sol index a0538d08d2..c34bcb9b8b 100644 --- a/packages/world/test/codegen/tables/AddressArray.sol +++ b/packages/world/test/codegen/tables/AddressArray.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -23,27 +20,10 @@ library AddressArray { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.ADDRESS_ARRAY; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (address[]) + Schema constant _valueSchema = Schema.wrap(0x00000001c3000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -67,14 +47,14 @@ library AddressArray { * @notice Register the table with its config. */ function register(ResourceId _tableId) internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register(ResourceId _tableId) internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world/test/codegen/tables/Bool.sol b/packages/world/test/codegen/tables/Bool.sol index ed67cfd72f..913347c8b6 100644 --- a/packages/world/test/codegen/tables/Bool.sol +++ b/packages/world/test/codegen/tables/Bool.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -23,26 +20,10 @@ library Bool { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0001010001000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](0); - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.BOOL; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of () + Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bool) + Schema constant _valueSchema = Schema.wrap(0x0001010060000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -65,14 +46,14 @@ library Bool { * @notice Register the table with its config. */ function register(ResourceId _tableId) internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register(ResourceId _tableId) internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/packages/world/test/codegen/tables/TwoFields.sol b/packages/world/test/codegen/tables/TwoFields.sol index dc5939612e..23221674fc 100644 --- a/packages/world/test/codegen/tables/TwoFields.sol +++ b/packages/world/test/codegen/tables/TwoFields.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -28,27 +25,10 @@ library TwoFields { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0002020001010000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](0); - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](2); - _valueSchema[0] = SchemaType.BOOL; - _valueSchema[1] = SchemaType.BOOL; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of () + Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bool, bool) + Schema constant _valueSchema = Schema.wrap(0x0002020060600000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -72,14 +52,14 @@ library TwoFields { * @notice Register the table with its config. */ function register(ResourceId _tableId) internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register(ResourceId _tableId) internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ebfc36e2f1..aec60e2104 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -729,6 +729,9 @@ importers: '@latticexyz/config': specifier: workspace:* version: link:../config + '@latticexyz/protocol-parser': + specifier: workspace:* + version: link:../protocol-parser '@latticexyz/schema-type': specifier: workspace:* version: link:../schema-type diff --git a/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol b/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol index be0bfa0876..829e0b68f4 100644 --- a/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,26 +23,10 @@ library Counter { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0004010004000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](0); - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.UINT32; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of () + Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint32) + Schema constant _valueSchema = Schema.wrap(0x0004010003000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -68,14 +49,14 @@ library Counter { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** 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 be0bfa0876..829e0b68f4 100644 --- a/templates/react-ecs/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/react-ecs/packages/contracts/src/codegen/tables/Counter.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,26 +23,10 @@ library Counter { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0004010004000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](0); - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.UINT32; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of () + Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint32) + Schema constant _valueSchema = Schema.wrap(0x0004010003000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -68,14 +49,14 @@ library Counter { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/templates/react/packages/contracts/src/codegen/tables/Tasks.sol b/templates/react/packages/contracts/src/codegen/tables/Tasks.sol index a12ef6d589..9acd84366f 100644 --- a/templates/react/packages/contracts/src/codegen/tables/Tasks.sol +++ b/templates/react/packages/contracts/src/codegen/tables/Tasks.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -32,29 +29,10 @@ library Tasks { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0040020120200000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](3); - _valueSchema[0] = SchemaType.UINT256; - _valueSchema[1] = SchemaType.UINT256; - _valueSchema[2] = SchemaType.STRING; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint256, uint256, string) + Schema constant _valueSchema = Schema.wrap(0x004002011f1fc500000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -80,14 +58,14 @@ library Tasks { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/templates/threejs/packages/contracts/src/codegen/tables/Position.sol b/templates/threejs/packages/contracts/src/codegen/tables/Position.sol index 11222af4d0..cbcd371198 100644 --- a/templates/threejs/packages/contracts/src/codegen/tables/Position.sol +++ b/templates/threejs/packages/contracts/src/codegen/tables/Position.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -32,29 +29,10 @@ library Position { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x000c030004040400000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](1); - _keySchema[0] = SchemaType.BYTES32; - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](3); - _valueSchema[0] = SchemaType.INT32; - _valueSchema[1] = SchemaType.INT32; - _valueSchema[2] = SchemaType.INT32; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (int32, int32, int32) + Schema constant _valueSchema = Schema.wrap(0x000c030023232300000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -80,14 +58,14 @@ library Position { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** diff --git a/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol b/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol index be0bfa0876..829e0b68f4 100644 --- a/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol @@ -3,9 +3,6 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -// Import schema type -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; - // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; @@ -14,8 +11,8 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -26,26 +23,10 @@ library Counter { FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0004010004000000000000000000000000000000000000000000000000000000); - /** - * @notice Get the table's key schema. - * @return _keySchema The key schema for the table. - */ - function getKeySchema() internal pure returns (Schema) { - SchemaType[] memory _keySchema = new SchemaType[](0); - - return SchemaLib.encode(_keySchema); - } - - /** - * @notice Get the table's value schema. - * @return _valueSchema The value schema for the table. - */ - function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _valueSchema = new SchemaType[](1); - _valueSchema[0] = SchemaType.UINT32; - - return SchemaLib.encode(_valueSchema); - } + // Hex-encoded key schema of () + Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint32) + Schema constant _valueSchema = Schema.wrap(0x0004010003000000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. @@ -68,14 +49,14 @@ library Counter { * @notice Register the table with its config. */ function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /**