From 3e7d83d01b9e027df9ef76068ab2e4ddf5c71d4b Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Thu, 21 Mar 2024 11:21:41 +0000 Subject: [PATCH] refactor: rename PackedCounter to EncodedLengths (#2490) --- .changeset/weak-rules-lick.md | 10 + docs/pages/guides/extending-a-world.mdx | 4 +- docs/pages/store/encoding.mdx | 10 +- docs/pages/store/reference/misc.mdx | 4 +- docs/pages/store/reference/store-core.mdx | 150 ++++++------ docs/pages/store/reference/store-hook.mdx | 76 +++--- docs/pages/store/reference/store.mdx | 44 ++-- docs/pages/store/store-hooks.mdx | 2 +- docs/pages/templates/typescript/contracts.mdx | 6 +- docs/pages/world/reference/world.mdx | 16 +- .../contracts/src/codegen/tables/Multi.sol | 20 +- .../contracts/src/codegen/tables/Number.sol | 6 +- .../src/codegen/tables/NumberList.sol | 10 +- .../contracts/src/codegen/tables/Position.sol | 6 +- .../src/codegen/tables/StaticArray.sol | 10 +- .../contracts/src/codegen/tables/Vector.sol | 20 +- .../src/codegen/tables/CounterTable.sol | 6 +- .../src/codegen/tables/Inventory.sol | 6 +- .../src/codegen/tables/MessageTable.sol | 18 +- .../contracts/src/codegen/tables/LastCall.sol | 20 +- .../src/codegen/tables/Dynamics1.sol | 26 +- .../src/codegen/tables/Dynamics2.sol | 26 +- .../contracts/src/codegen/tables/Offchain.sol | 12 +- .../src/codegen/tables/Singleton.sol | 22 +- .../contracts/src/codegen/tables/Statics.sol | 20 +- .../src/codegen/tables/UserTyped.sol | 20 +- packages/protocol-parser/src/decodeRecord.ts | 4 +- packages/protocol-parser/src/encodeRecord.ts | 4 +- packages/protocol-parser/src/errors.ts | 14 +- .../protocol-parser/src/exports/internal.ts | 2 +- .../src/hexToEncodedLengths.test.ts | 35 +++ ...ackedCounter.ts => hexToEncodedLengths.ts} | 10 +- .../src/hexToPackedCounter.test.ts | 35 --- .../src/typescript/dynamicAbiTypes.ts | 2 +- packages/store/gas-report.json | 60 ++--- packages/store/src/EncodedLengths.sol | 224 ++++++++++++++++++ packages/store/src/FieldLayout.sol | 2 +- ...erErrors.sol => IEncodedLengthsErrors.sol} | 12 +- packages/store/src/IStore.sol | 4 +- packages/store/src/IStoreEvents.sol | 6 +- packages/store/src/IStoreHook.sol | 10 +- packages/store/src/IStoreRead.sol | 6 +- packages/store/src/IStoreWrite.sol | 4 +- packages/store/src/PackedCounter.sol | 224 ------------------ packages/store/src/StoreCore.sol | 26 +- packages/store/src/StoreHook.sol | 10 +- packages/store/src/StoreRead.sol | 6 +- packages/store/src/StoreSwitch.sol | 10 +- packages/store/src/codegen/tables/Hooks.sol | 10 +- .../store/src/codegen/tables/ResourceIds.sol | 6 +- .../store/src/codegen/tables/StoreHooks.sol | 10 +- packages/store/src/codegen/tables/Tables.sol | 26 +- packages/store/src/constants.sol | 2 +- packages/store/test/EchoSubscriber.sol | 10 +- packages/store/test/EncodedLengths.t.sol | 110 +++++++++ packages/store/test/Gas.t.sol | 8 +- packages/store/test/MirrorSubscriber.sol | 6 +- packages/store/test/Mixed.t.sol | 4 +- packages/store/test/PackedCounter.t.sol | 110 --------- packages/store/test/RevertSubscriber.sol | 10 +- packages/store/test/StoreCore.t.sol | 62 ++--- packages/store/test/StoreCoreDynamic.t.sol | 6 +- packages/store/test/StoreCoreGas.t.sol | 22 +- packages/store/test/StoreHook.t.sol | 4 +- packages/store/test/StoreMock.sol | 4 +- .../store/test/codegen/tables/Callbacks.sol | 10 +- .../store/test/codegen/tables/KeyEncoding.sol | 6 +- packages/store/test/codegen/tables/Mixed.sol | 26 +- .../store/test/codegen/tables/Vector2.sol | 20 +- .../test/setDynamicDataLengthAtIndex.sol | 4 +- packages/store/ts/codegen/record.ts | 10 +- packages/store/ts/codegen/renderTable.ts | 8 +- packages/store/ts/constants.ts | 2 +- .../erc20-puppet/tables/Allowances.sol | 6 +- .../erc20-puppet/tables/ERC20Metadata.sol | 26 +- .../erc20-puppet/tables/ERC20Registry.sol | 6 +- .../erc20-puppet/tables/TotalSupply.sol | 6 +- .../erc721-puppet/tables/ERC721Metadata.sol | 26 +- .../erc721-puppet/tables/ERC721Registry.sol | 6 +- .../erc721-puppet/tables/OperatorApproval.sol | 6 +- .../modules/erc721-puppet/tables/Owners.sol | 6 +- .../erc721-puppet/tables/TokenApproval.sol | 6 +- .../modules/erc721-puppet/tables/TokenURI.sol | 10 +- .../modules/keysintable/KeysInTableHook.sol | 6 +- .../src/modules/keysintable/query.sol | 14 +- .../keysintable/tables/KeysInTable.sol | 50 ++-- .../keysintable/tables/UsedKeysIndex.sol | 20 +- .../keyswithvalue/KeysWithValueHook.sol | 10 +- .../keyswithvalue/getKeysWithValue.sol | 6 +- .../keyswithvalue/tables/KeysWithValue.sol | 10 +- .../modules/puppet/tables/PuppetRegistry.sol | 6 +- .../tables/CallboundDelegations.sol | 6 +- .../tables/SystemboundDelegations.sol | 6 +- .../tables/TimeboundDelegations.sol | 6 +- .../src/modules/tokens/tables/Balances.sol | 6 +- .../uniqueentity/tables/UniqueEntity.sol | 6 +- .../test/KeysInTableModule.t.sol | 34 +-- .../test/KeysWithValueModule.t.sol | 18 +- packages/world-modules/test/query.t.sol | 114 ++++----- packages/world/src/World.sol | 4 +- .../world/src/codegen/tables/Balances.sol | 6 +- .../src/codegen/tables/FunctionSelectors.sol | 16 +- .../src/codegen/tables/FunctionSignatures.sol | 18 +- .../src/codegen/tables/InitModuleAddress.sol | 6 +- .../src/codegen/tables/InstalledModules.sol | 6 +- .../tables/NamespaceDelegationControl.sol | 6 +- .../src/codegen/tables/NamespaceOwner.sol | 6 +- .../src/codegen/tables/ResourceAccess.sol | 6 +- .../world/src/codegen/tables/SystemHooks.sol | 10 +- .../src/codegen/tables/SystemRegistry.sol | 6 +- packages/world/src/codegen/tables/Systems.sol | 19 +- .../codegen/tables/UserDelegationControl.sol | 6 +- packages/world/test/World.t.sol | 24 +- .../test/codegen/tables/AddressArray.sol | 10 +- packages/world/test/codegen/tables/Bool.sol | 6 +- .../world/test/codegen/tables/TwoFields.sol | 20 +- .../world/ts/protocol-snapshots/2.0.0.snap | 2 +- scripts/render-api-docs.ts | 2 +- .../contracts/src/codegen/tables/Counter.sol | 6 +- .../contracts/src/codegen/tables/Counter.sol | 6 +- .../contracts/src/codegen/tables/Tasks.sol | 26 +- .../contracts/src/codegen/tables/Position.sol | 20 +- .../contracts/src/codegen/tables/Counter.sol | 6 +- .../src/codegen/tables/Health.sol | 6 +- .../src/codegen/tables/Inventory.sol | 6 +- .../src/codegen/tables/Position.sol | 20 +- .../src/codegen/tables/Score.sol | 6 +- .../src/codegen/tables/Terrain.sol | 6 +- .../src/codegen/tables/Winner.sol | 6 +- 129 files changed, 1261 insertions(+), 1230 deletions(-) create mode 100644 .changeset/weak-rules-lick.md create mode 100644 packages/protocol-parser/src/hexToEncodedLengths.test.ts rename packages/protocol-parser/src/{hexToPackedCounter.ts => hexToEncodedLengths.ts} (78%) delete mode 100644 packages/protocol-parser/src/hexToPackedCounter.test.ts create mode 100644 packages/store/src/EncodedLengths.sol rename packages/store/src/{IPackedCounterErrors.sol => IEncodedLengthsErrors.sol} (55%) delete mode 100644 packages/store/src/PackedCounter.sol create mode 100644 packages/store/test/EncodedLengths.t.sol delete mode 100644 packages/store/test/PackedCounter.t.sol diff --git a/.changeset/weak-rules-lick.md b/.changeset/weak-rules-lick.md new file mode 100644 index 0000000000..337be70298 --- /dev/null +++ b/.changeset/weak-rules-lick.md @@ -0,0 +1,10 @@ +--- +"@latticexyz/cli": patch +"@latticexyz/protocol-parser": patch +"@latticexyz/store": major +"@latticexyz/world-modules": patch +"@latticexyz/world": major +"create-mud": patch +--- + +Renamed `PackedCounter` to `EncodedLengths` for consistency. diff --git a/docs/pages/guides/extending-a-world.mdx b/docs/pages/guides/extending-a-world.mdx index 6369f9ef67..e0d411d86e 100644 --- a/docs/pages/guides/extending-a-world.mdx +++ b/docs/pages/guides/extending-a-world.mdx @@ -464,7 +464,7 @@ The easiest way to create the Solidity code is to use the MUD template: Word 0 shows us that this field's value starts at `0x60`, which is word 3. Because there are no static fields, word 3 is all zeros. - Word 1 is a [`PackedCounter`](https://github.com/latticexyz/mud/blob/main/packages/store/src/PackedCounter.sol) with the lengths of the dynamic fields. + Word 1 is a [`EncodedLengths`](https://github.com/latticexyz/mud/blob/main/packages/store/src/EncodedLengths.sol) with the lengths of the dynamic fields. Here is the interpretation. | Bytes | Value | Meaning | @@ -476,7 +476,7 @@ The easiest way to create the Solidity code is to use the MUD template: | 26-22 | `0000000000` | The length of the (non-existent in `Messages`) fourth dynamic field is zero | | 31-27 | `0000000000` | The length of the (non-existent in `Messages`) fifth dynamic field is zero | - MUD tables can only have up to five dynamic fields because `PackedCounter` needs to fit in a 32 byte word. + MUD tables can only have up to five dynamic fields because `EncodedLengths` needs to fit in a 32 byte word. Word 2 shows us that the field with the dynamic lengths starts at byte 0x80, which is word 4. Word 4 gives us the length of the string. diff --git a/docs/pages/store/encoding.mdx b/docs/pages/store/encoding.mdx index 1f2119621e..c83111cd8a 100644 --- a/docs/pages/store/encoding.mdx +++ b/docs/pages/store/encoding.mdx @@ -275,14 +275,14 @@ Example: encoded static data of a table with a `uint64` and a `uint40` field. ## Dynamic length data -### Encoded lengths (`PackedCounter`) +### Encoded lengths (`EncodedLengths`) Tables can have up to five dynamic length fields, each of which has a maximum size of `2**40` (~1 trillion) bytes. This makes it possible to pack the lengths of all dynamic length fields of a table in a single `bytes32` word, instead of prefixing each dynamic length field with 32 bytes to store its length. -The data structure to store the lengths of all dynamic length fields is called `PackedCounter`. +The data structure to store the lengths of all dynamic length fields is called `EncodedLengths`. -Example: `PackedCounter` with 5 fields. +Example: `EncodedLengths` with 5 fields. ``` 0x 0000000000000F 0000000001 0000000002 0000000003 0000000004 0000000005 @@ -353,7 +353,7 @@ function _getStaticDataLocation(ResourceId tableId, bytes32[] memory keyTuple) i } ``` -The [encoded lengths](#encoded-lengths-packedcounter) of all dynamic length fields is stored in a single storage slot, which is determined by a hash of the table ID and the key tuple. +The [encoded lengths](#encoded-lengths-encodedlengths) of all dynamic length fields is stored in a single storage slot, which is determined by a hash of the table ID and the key tuple. ```solidity function _getDynamicDataLengthLocation(ResourceId tableId, bytes32[] memory keyTuple) internal pure returns (uint256) { @@ -376,7 +376,7 @@ function _getDynamicDataLocation( ## Events -Data emitted as part of events uses the same encoding for [static length data](#static-length-data), [encoded lengths](#encoded-lengths-packedcounter) and [dynamic length data](#dynamic-length-data-encoding) as described above. +Data emitted as part of events uses the same encoding for [static length data](#static-length-data), [encoded lengths](#encoded-lengths-encodedlengths) and [dynamic length data](#dynamic-length-data-encoding) as described above. Unlike the [layout in storage](#storage-layout), where each dynamic length data field is stored in its own storage location, in events all data of dynamic length fields is concatenated to a single `bytes` blob. The encoded lengths emitted as part of the event contain the information required to slice up this concatenated `bytes` blob into the individual fields. diff --git a/docs/pages/store/reference/misc.mdx b/docs/pages/store/reference/misc.mdx index 953870cc1e..4f887c8baa 100644 --- a/docs/pages/store/reference/misc.mdx +++ b/docs/pages/store/reference/misc.mdx @@ -1616,7 +1616,7 @@ From left to right, the bytes are laid out as follows: - 1 byte for number of static size fields - 1 byte for number of dynamic size fields - 28 bytes for 28 static field lengths - (MAX_DYNAMIC_FIELDS allows PackedCounter to pack the dynamic lengths into 1 word)\* + (MAX_DYNAMIC_FIELDS allows EncodedLengths to pack the dynamic lengths into 1 word)\* ```solidity type FieldLayout is bytes32; @@ -2476,7 +2476,7 @@ uint256 constant MAX_STATIC_FIELDS = 28; #### MAX_DYNAMIC_FIELDS -_Represents the maximum number of dynamic fields that can be packed in a PackedCounter._ +_Represents the maximum number of dynamic fields that can be packed in EncodedLengths._ ```solidity uint256 constant MAX_DYNAMIC_FIELDS = 5; diff --git a/docs/pages/store/reference/store-core.mdx b/docs/pages/store/reference/store-core.mdx index e20a9fe22b..ad3e19af03 100644 --- a/docs/pages/store/reference/store-core.mdx +++ b/docs/pages/store/reference/store-core.mdx @@ -186,20 +186,20 @@ function setRecord( ResourceId tableId, bytes32[] memory keyTuple, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData ) internal; ``` **Parameters** -| Name | Type | Description | -| ---------------- | --------------- | ------------------------------------------------------- | -| `tableId` | `ResourceId` | The ID of the table to set the record for. | -| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | -| `staticData` | `bytes` | The static data of the record. | -| `encodedLengths` | `PackedCounter` | The encoded lengths of the dynamic data of the record. | -| `dynamicData` | `bytes` | The dynamic data of the record. | +| Name | Type | Description | +| ---------------- | ---------------- | ------------------------------------------------------- | +| `tableId` | `ResourceId` | The ID of the table to set the record for. | +| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | +| `staticData` | `bytes` | The static data of the record. | +| `encodedLengths` | `EncodedLengths` | The encoded lengths of the dynamic data of the record. | +| `dynamicData` | `bytes` | The dynamic data of the record. | #### setRecord @@ -215,7 +215,7 @@ function setRecord( ResourceId tableId, bytes32[] memory keyTuple, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData, FieldLayout fieldLayout ) internal; @@ -223,14 +223,14 @@ function setRecord( **Parameters** -| Name | Type | Description | -| ---------------- | --------------- | ------------------------------------------------------- | -| `tableId` | `ResourceId` | The ID of the table to set the record for. | -| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | -| `staticData` | `bytes` | The static data of the record. | -| `encodedLengths` | `PackedCounter` | The encoded lengths of the dynamic data of the record. | -| `dynamicData` | `bytes` | The dynamic data of the record. | -| `fieldLayout` | `FieldLayout` | The field layout for the record. | +| Name | Type | Description | +| ---------------- | ---------------- | ------------------------------------------------------- | +| `tableId` | `ResourceId` | The ID of the table to set the record for. | +| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | +| `staticData` | `bytes` | The static data of the record. | +| `encodedLengths` | `EncodedLengths` | The encoded lengths of the dynamic data of the record. | +| `dynamicData` | `bytes` | The dynamic data of the record. | +| `fieldLayout` | `FieldLayout` | The field layout for the record. | #### spliceStaticData @@ -494,7 +494,7 @@ If the field layout is available to the caller, it is recommended to use the oth function getRecord( ResourceId tableId, bytes32[] memory keyTuple -) internal view returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); +) internal view returns (bytes memory staticData, EncodedLengths encodedLengths, bytes memory dynamicData); ``` **Parameters** @@ -506,11 +506,11 @@ function getRecord( **Returns** -| Name | Type | Description | -| ---------------- | --------------- | ------------------------------------------------------ | -| `staticData` | `bytes` | The static data of the record. | -| `encodedLengths` | `PackedCounter` | The encoded lengths of the dynamic data of the record. | -| `dynamicData` | `bytes` | The dynamic data of the record. | +| Name | Type | Description | +| ---------------- | ---------------- | ------------------------------------------------------ | +| `staticData` | `bytes` | The static data of the record. | +| `encodedLengths` | `EncodedLengths` | The encoded lengths of the dynamic data of the record. | +| `dynamicData` | `bytes` | The dynamic data of the record. | #### getRecord @@ -521,7 +521,7 @@ function getRecord( ResourceId tableId, bytes32[] memory keyTuple, FieldLayout fieldLayout -) internal view returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); +) internal view returns (bytes memory staticData, EncodedLengths encodedLengths, bytes memory dynamicData); ``` **Parameters** @@ -534,11 +534,11 @@ function getRecord( **Returns** -| Name | Type | Description | -| ---------------- | --------------- | ------------------------------------------------------ | -| `staticData` | `bytes` | The static data of the record. | -| `encodedLengths` | `PackedCounter` | The encoded lengths of the dynamic data of the record. | -| `dynamicData` | `bytes` | The dynamic data of the record. | +| Name | Type | Description | +| ---------------- | ---------------- | ------------------------------------------------------ | +| `staticData` | `bytes` | The static data of the record. | +| `encodedLengths` | `EncodedLengths` | The encoded lengths of the dynamic data of the record. | +| `dynamicData` | `bytes` | The dynamic data of the record. | #### getField @@ -811,21 +811,21 @@ function _spliceDynamicData( uint40 startWithinField, uint40 deleteCount, bytes memory data, - PackedCounter previousEncodedLengths + EncodedLengths previousEncodedLengths ) internal; ``` **Parameters** -| Name | Type | Description | -| ------------------------ | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `tableId` | `ResourceId` | The ID of the table to splice dynamic data. | -| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | -| `dynamicFieldIndex` | `uint8` | The index of the dynamic field to splice data, relative to the start of the dynamic fields. (Dynamic field index = field index - number of static fields) | -| `startWithinField` | `uint40` | The start index within the field for the splice operation. | -| `deleteCount` | `uint40` | The number of bytes to delete in the splice operation. | -| `data` | `bytes` | The data to insert into the dynamic data of the record at the start byte. | -| `previousEncodedLengths` | `PackedCounter` | The previous encoded lengths of the dynamic data of the record. | +| Name | Type | Description | +| ------------------------ | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `tableId` | `ResourceId` | The ID of the table to splice dynamic data. | +| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | +| `dynamicFieldIndex` | `uint8` | The index of the dynamic field to splice data, relative to the start of the dynamic fields. (Dynamic field index = field index - number of static fields) | +| `startWithinField` | `uint40` | The start index within the field for the splice operation. | +| `deleteCount` | `uint40` | The number of bytes to delete in the splice operation. | +| `data` | `bytes` | The data to insert into the dynamic data of the record at the start byte. | +| `previousEncodedLengths` | `EncodedLengths` | The previous encoded lengths of the dynamic data of the record. | #### \_getStaticData @@ -999,7 +999,7 @@ Load the encoded dynamic data length from storage for the given table ID and key function _loadEncodedDynamicDataLength( ResourceId tableId, bytes32[] memory keyTuple -) internal view returns (PackedCounter); +) internal view returns (EncodedLengths); ``` **Parameters** @@ -1011,9 +1011,9 @@ function _loadEncodedDynamicDataLength( **Returns** -| Name | Type | Description | -| -------- | --------------- | ----------------------------------------------------------------------------------------- | -| `` | `PackedCounter` | The loaded encoded dynamic data length from storage for the given table ID and key tuple. | +| Name | Type | Description | +| -------- | ---------------- | ----------------------------------------------------------------------------------------- | +| `` | `EncodedLengths` | The loaded encoded dynamic data length from storage for the given table ID and key tuple. | ## StoreData @@ -1132,7 +1132,7 @@ Fetches a record from a specified table using a provided key tuple. function getRecord( ResourceId tableId, bytes32[] calldata keyTuple -) public view virtual returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); +) public view virtual returns (bytes memory staticData, EncodedLengths encodedLengths, bytes memory dynamicData); ``` **Parameters** @@ -1144,11 +1144,11 @@ function getRecord( **Returns** -| Name | Type | Description | -| ---------------- | --------------- | -------------------------------- | -| `staticData` | `bytes` | The static data of the record. | -| `encodedLengths` | `PackedCounter` | Encoded lengths of dynamic data. | -| `dynamicData` | `bytes` | The dynamic data of the record. | +| Name | Type | Description | +| ---------------- | ---------------- | -------------------------------- | +| `staticData` | `bytes` | The static data of the record. | +| `encodedLengths` | `EncodedLengths` | Encoded lengths of dynamic data. | +| `dynamicData` | `bytes` | The dynamic data of the record. | #### getRecord @@ -1159,7 +1159,7 @@ function getRecord( ResourceId tableId, bytes32[] calldata keyTuple, FieldLayout fieldLayout -) public view virtual returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); +) public view virtual returns (bytes memory staticData, EncodedLengths encodedLengths, bytes memory dynamicData); ``` **Parameters** @@ -1172,11 +1172,11 @@ function getRecord( **Returns** -| Name | Type | Description | -| ---------------- | --------------- | -------------------------------- | -| `staticData` | `bytes` | The static data of the record. | -| `encodedLengths` | `PackedCounter` | Encoded lengths of dynamic data. | -| `dynamicData` | `bytes` | The dynamic data of the record. | +| Name | Type | Description | +| ---------------- | ---------------- | -------------------------------- | +| `staticData` | `bytes` | The static data of the record. | +| `encodedLengths` | `EncodedLengths` | Encoded lengths of dynamic data. | +| `dynamicData` | `bytes` | The dynamic data of the record. | #### getField @@ -1600,20 +1600,20 @@ function setRecord( ResourceId tableId, bytes32[] memory keyTuple, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData ) internal; ``` **Parameters** -| Name | Type | Description | -| ---------------- | --------------- | --------------------------------- | -| `tableId` | `ResourceId` | The table's ID. | -| `keyTuple` | `bytes32[]` | Array of key values. | -| `staticData` | `bytes` | Fixed-length fields data. | -| `encodedLengths` | `PackedCounter` | Encoded lengths for dynamic data. | -| `dynamicData` | `bytes` | Dynamic-length fields data. | +| Name | Type | Description | +| ---------------- | ---------------- | --------------------------------- | +| `tableId` | `ResourceId` | The table's ID. | +| `keyTuple` | `bytes32[]` | Array of key values. | +| `staticData` | `bytes` | Fixed-length fields data. | +| `encodedLengths` | `EncodedLengths` | Encoded lengths for dynamic data. | +| `dynamicData` | `bytes` | Dynamic-length fields data. | #### spliceStaticData @@ -1812,7 +1812,7 @@ _Retrieves a record from a table._ function getRecord( ResourceId tableId, bytes32[] memory keyTuple -) internal view returns (bytes memory, PackedCounter, bytes memory); +) internal view returns (bytes memory, EncodedLengths, bytes memory); ``` **Parameters** @@ -1824,11 +1824,11 @@ function getRecord( **Returns** -| Name | Type | Description | -| -------- | --------------- | ----------------------------------------------- | -| `` | `bytes` | staticData The static data of the record. | -| `` | `PackedCounter` | encodedLengths Encoded lengths of dynamic data. | -| `` | `bytes` | dynamicData The dynamic data of the record. | +| Name | Type | Description | +| -------- | ---------------- | ----------------------------------------------- | +| `` | `bytes` | staticData The static data of the record. | +| `` | `EncodedLengths` | encodedLengths Encoded lengths of dynamic data. | +| `` | `bytes` | dynamicData The dynamic data of the record. | #### getRecord @@ -1839,7 +1839,7 @@ function getRecord( ResourceId tableId, bytes32[] memory keyTuple, FieldLayout fieldLayout -) internal view returns (bytes memory, PackedCounter, bytes memory); +) internal view returns (bytes memory, EncodedLengths, bytes memory); ``` **Parameters** @@ -1852,11 +1852,11 @@ function getRecord( **Returns** -| Name | Type | Description | -| -------- | --------------- | ----------------------------------------------- | -| `` | `bytes` | staticData The static data of the record. | -| `` | `PackedCounter` | encodedLengths Encoded lengths of dynamic data. | -| `` | `bytes` | dynamicData The dynamic data of the record. | +| Name | Type | Description | +| -------- | ---------------- | ----------------------------------------------- | +| `` | `bytes` | staticData The static data of the record. | +| `` | `EncodedLengths` | encodedLengths Encoded lengths of dynamic data. | +| `` | `bytes` | dynamicData The dynamic data of the record. | #### getField diff --git a/docs/pages/store/reference/store-hook.mdx b/docs/pages/store/reference/store-hook.mdx index ab8b0f4583..28b263b057 100644 --- a/docs/pages/store/reference/store-hook.mdx +++ b/docs/pages/store/reference/store-hook.mdx @@ -19,7 +19,7 @@ function onBeforeSetRecord( ResourceId tableId, bytes32[] memory keyTuple, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData, FieldLayout fieldLayout ) external; @@ -27,14 +27,14 @@ function onBeforeSetRecord( **Parameters** -| Name | Type | Description | -| ---------------- | --------------- | ------------------------------------------------------- | -| `tableId` | `ResourceId` | The ID of the table where the record is to be set. | -| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | -| `staticData` | `bytes` | The static data of the record. | -| `encodedLengths` | `PackedCounter` | The encoded lengths of the dynamic data of the record. | -| `dynamicData` | `bytes` | The dynamic data of the record. | -| `fieldLayout` | `FieldLayout` | The layout of the field, see FieldLayout.sol. | +| Name | Type | Description | +| ---------------- | ---------------- | ------------------------------------------------------- | +| `tableId` | `ResourceId` | The ID of the table where the record is to be set. | +| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | +| `staticData` | `bytes` | The static data of the record. | +| `encodedLengths` | `EncodedLengths` | The encoded lengths of the dynamic data of the record. | +| `dynamicData` | `bytes` | The dynamic data of the record. | +| `fieldLayout` | `FieldLayout` | The layout of the field, see FieldLayout.sol. | #### onAfterSetRecord @@ -45,7 +45,7 @@ function onAfterSetRecord( ResourceId tableId, bytes32[] memory keyTuple, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData, FieldLayout fieldLayout ) external; @@ -53,14 +53,14 @@ function onAfterSetRecord( **Parameters** -| Name | Type | Description | -| ---------------- | --------------- | ------------------------------------------------------- | -| `tableId` | `ResourceId` | The ID of the table where the record was set. | -| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | -| `staticData` | `bytes` | The static data of the record. | -| `encodedLengths` | `PackedCounter` | The encoded lengths of the dynamic data of the record. | -| `dynamicData` | `bytes` | The dynamic data of the record. | -| `fieldLayout` | `FieldLayout` | The layout of the field, see FieldLayout.sol. | +| Name | Type | Description | +| ---------------- | ---------------- | ------------------------------------------------------- | +| `tableId` | `ResourceId` | The ID of the table where the record was set. | +| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | +| `staticData` | `bytes` | The static data of the record. | +| `encodedLengths` | `EncodedLengths` | The encoded lengths of the dynamic data of the record. | +| `dynamicData` | `bytes` | The dynamic data of the record. | +| `fieldLayout` | `FieldLayout` | The layout of the field, see FieldLayout.sol. | #### onBeforeSpliceStaticData @@ -126,22 +126,22 @@ function onBeforeSpliceDynamicData( uint8 dynamicFieldIndex, uint40 startWithinField, uint40 deleteCount, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory data ) external; ``` **Parameters** -| Name | Type | Description | -| ------------------- | --------------- | ------------------------------------------------------------------------------ | -| `tableId` | `ResourceId` | The ID of the table where the data is to be spliced. | -| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | -| `dynamicFieldIndex` | `uint8` | The index of the dynamic field. | -| `startWithinField` | `uint40` | The start byte position within the field for splicing. | -| `deleteCount` | `uint40` | The number of bytes to delete in the dynamic data of the record. | -| `encodedLengths` | `PackedCounter` | The encoded lengths of the dynamic data of the record. | -| `data` | `bytes` | The data to be inserted into the dynamic data of the record at the start byte. | +| Name | Type | Description | +| ------------------- | ---------------- | ------------------------------------------------------------------------------ | +| `tableId` | `ResourceId` | The ID of the table where the data is to be spliced. | +| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | +| `dynamicFieldIndex` | `uint8` | The index of the dynamic field. | +| `startWithinField` | `uint40` | The start byte position within the field for splicing. | +| `deleteCount` | `uint40` | The number of bytes to delete in the dynamic data of the record. | +| `encodedLengths` | `EncodedLengths` | The encoded lengths of the dynamic data of the record. | +| `data` | `bytes` | The data to be inserted into the dynamic data of the record at the start byte. | #### onAfterSpliceDynamicData @@ -157,22 +157,22 @@ function onAfterSpliceDynamicData( uint8 dynamicFieldIndex, uint40 startWithinField, uint40 deleteCount, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory data ) external; ``` **Parameters** -| Name | Type | Description | -| ------------------- | --------------- | ------------------------------------------------------------------------ | -| `tableId` | `ResourceId` | The ID of the table where the data was spliced. | -| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | -| `dynamicFieldIndex` | `uint8` | The index of the dynamic field. | -| `startWithinField` | `uint40` | The start byte position within the field for splicing. | -| `deleteCount` | `uint40` | The number of bytes deleted in the dynamic data of the record. | -| `encodedLengths` | `PackedCounter` | The encoded lengths of the dynamic data of the record. | -| `data` | `bytes` | The data inserted into the dynamic data of the record at the start byte. | +| Name | Type | Description | +| ------------------- | ---------------- | ------------------------------------------------------------------------ | +| `tableId` | `ResourceId` | The ID of the table where the data was spliced. | +| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | +| `dynamicFieldIndex` | `uint8` | The index of the dynamic field. | +| `startWithinField` | `uint40` | The start byte position within the field for splicing. | +| `deleteCount` | `uint40` | The number of bytes deleted in the dynamic data of the record. | +| `encodedLengths` | `EncodedLengths` | The encoded lengths of the dynamic data of the record. | +| `data` | `bytes` | The data inserted into the dynamic data of the record at the start byte. | #### onBeforeDeleteRecord diff --git a/docs/pages/store/reference/store.mdx b/docs/pages/store/reference/store.mdx index ba9b118bcf..adfbec8fe8 100644 --- a/docs/pages/store/reference/store.mdx +++ b/docs/pages/store/reference/store.mdx @@ -5,7 +5,7 @@ [Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/IStore.sol) **Inherits:** -[IStoreData](/store/reference/store#istoredata), [IStoreRegistration](/store/reference/store#istoreregistration), [IStoreErrors](/store/reference/store#istoreerrors), [IFieldLayoutErrors](/src/IFieldLayoutErrors.sol/interface.IFieldLayoutErrors.md), [IPackedCounterErrors](/src/IPackedCounterErrors.sol/interface.IPackedCounterErrors.md), [ISchemaErrors](/src/ISchemaErrors.sol/interface.ISchemaErrors.md), [ISliceErrors](/src/ISliceErrors.sol/interface.ISliceErrors.md) +[IStoreData](/store/reference/store#istoredata), [IStoreRegistration](/store/reference/store#istoreregistration), [IStoreErrors](/store/reference/store#istoreerrors), [IFieldLayoutErrors](/src/IFieldLayoutErrors.sol/interface.IFieldLayoutErrors.md), [IEncodedLengthsErrors](/src/IEncodedLengthsErrors.sol/interface.IEncodedLengthsErrors.md), [ISchemaErrors](/src/ISchemaErrors.sol/interface.ISchemaErrors.md), [ISliceErrors](/src/ISliceErrors.sol/interface.ISliceErrors.md) IStore implements the error interfaces for each library that it uses. @@ -38,20 +38,20 @@ event Store_SetRecord( ResourceId indexed tableId, bytes32[] keyTuple, bytes staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes dynamicData ); ``` **Parameters** -| Name | Type | Description | -| ---------------- | --------------- | ------------------------------------------------------- | -| `tableId` | `ResourceId` | The ID of the table where the record is set. | -| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | -| `staticData` | `bytes` | The static data of the record. | -| `encodedLengths` | `PackedCounter` | The encoded lengths of the dynamic data of the record. | -| `dynamicData` | `bytes` | The dynamic data of the record. | +| Name | Type | Description | +| ---------------- | ---------------- | ------------------------------------------------------- | +| `tableId` | `ResourceId` | The ID of the table where the record is set. | +| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | +| `staticData` | `bytes` | The static data of the record. | +| `encodedLengths` | `EncodedLengths` | The encoded lengths of the dynamic data of the record. | +| `dynamicData` | `bytes` | The dynamic data of the record. | #### Store_SpliceStaticData @@ -84,22 +84,22 @@ event Store_SpliceDynamicData( uint8 dynamicFieldIndex, uint48 start, uint40 deleteCount, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes data ); ``` **Parameters** -| Name | Type | Description | -| ------------------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `tableId` | `ResourceId` | The ID of the table where the data is spliced. | -| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | -| `dynamicFieldIndex` | `uint8` | The index of the dynamic field to splice data, relative to the start of the dynamic fields. (Dynamic field index = field index - number of static fields) | -| `start` | `uint48` | The start position in bytes for the splice operation. | -| `deleteCount` | `uint40` | The number of bytes to delete in the splice operation. | -| `encodedLengths` | `PackedCounter` | The encoded lengths of the dynamic data of the record. | -| `data` | `bytes` | The data to insert into the dynamic data of the record at the start byte. | +| Name | Type | Description | +| ------------------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `tableId` | `ResourceId` | The ID of the table where the data is spliced. | +| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | +| `dynamicFieldIndex` | `uint8` | The index of the dynamic field to splice data, relative to the start of the dynamic fields. (Dynamic field index = field index - number of static fields) | +| `start` | `uint48` | The start position in bytes for the splice operation. | +| `deleteCount` | `uint40` | The number of bytes to delete in the splice operation. | +| `encodedLengths` | `EncodedLengths` | The encoded lengths of the dynamic data of the record. | +| `data` | `bytes` | The data to insert into the dynamic data of the record at the start byte. | #### Store_DeleteRecord @@ -372,7 +372,7 @@ Get full record (all fields, static and dynamic data) for the given tableId and function getRecord( ResourceId tableId, bytes32[] calldata keyTuple -) external view returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); +) external view returns (bytes memory staticData, EncodedLengths encodedLengths, bytes memory dynamicData); ``` #### getRecord @@ -384,7 +384,7 @@ function getRecord( ResourceId tableId, bytes32[] calldata keyTuple, FieldLayout fieldLayout -) external view returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); +) external view returns (bytes memory staticData, EncodedLengths encodedLengths, bytes memory dynamicData); ``` #### getField @@ -508,7 +508,7 @@ function setRecord( ResourceId tableId, bytes32[] calldata keyTuple, bytes calldata staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes calldata dynamicData ) external; ``` diff --git a/docs/pages/store/store-hooks.mdx b/docs/pages/store/store-hooks.mdx index 7cf88acd1a..4ba8bff6b5 100644 --- a/docs/pages/store/store-hooks.mdx +++ b/docs/pages/store/store-hooks.mdx @@ -30,7 +30,7 @@ contract CustomHook is StoreHook { ResourceId tableId, bytes32[] memory keyTuple, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData, FieldLayout ) public override { diff --git a/docs/pages/templates/typescript/contracts.mdx b/docs/pages/templates/typescript/contracts.mdx index 0ae2a2ecff..0b033182cb 100644 --- a/docs/pages/templates/typescript/contracts.mdx +++ b/docs/pages/templates/typescript/contracts.mdx @@ -77,7 +77,7 @@ 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 { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; +import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; import { RESOURCE_TABLE, RESOURCE_OFFCHAIN_TABLE } from "@latticexyz/store/src/storeResourceTypes.sol"; ``` @@ -378,10 +378,10 @@ function encodeStatic(uint32 value) internal pure returns (bytes memory) { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dyanmic (variable length) data, encoded into a sequence of bytes. */ -function encode(uint32 value) internal pure returns (bytes memory, PackedCounter, bytes memory) { +function encode(uint32 value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/docs/pages/world/reference/world.mdx b/docs/pages/world/reference/world.mdx index 2bed5edbe2..9fd7e16b06 100644 --- a/docs/pages/world/reference/world.mdx +++ b/docs/pages/world/reference/world.mdx @@ -99,20 +99,20 @@ function setRecord( ResourceId tableId, bytes32[] calldata keyTuple, bytes calldata staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes calldata dynamicData ) public virtual prohibitDirectCallback; ``` **Parameters** -| Name | Type | Description | -| ---------------- | --------------- | ---------------------------------------------------- | -| `tableId` | `ResourceId` | The unique identifier for the table. | -| `keyTuple` | `bytes32[]` | Array of keys identifying the record. | -| `staticData` | `bytes` | Static data (fixed length fields) of the record. | -| `encodedLengths` | `PackedCounter` | Encoded lengths of data. | -| `dynamicData` | `bytes` | Dynamic data (variable length fields) of the record. | +| Name | Type | Description | +| ---------------- | ---------------- | ---------------------------------------------------- | +| `tableId` | `ResourceId` | The unique identifier for the table. | +| `keyTuple` | `bytes32[]` | Array of keys identifying the record. | +| `staticData` | `bytes` | Static data (fixed length fields) of the record. | +| `encodedLengths` | `EncodedLengths` | Encoded lengths of data. | +| `dynamicData` | `bytes` | Dynamic data (variable length fields) of the record. | #### spliceStaticData diff --git a/e2e/packages/contracts/src/codegen/tables/Multi.sol b/e2e/packages/contracts/src/codegen/tables/Multi.sol index 7c667a8067..8f9ad1e31b 100644 --- a/e2e/packages/contracts/src/codegen/tables/Multi.sol +++ b/e2e/packages/contracts/src/codegen/tables/Multi.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; struct MultiData { @@ -187,7 +187,7 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -205,7 +205,7 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -219,7 +219,7 @@ library Multi { function set(uint32 a, bool b, uint256 c, int120 d, int256 num, bool value) internal { bytes memory _staticData = encodeStatic(num, value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](4); @@ -237,7 +237,7 @@ library Multi { function _set(uint32 a, bool b, uint256 c, int120 d, int256 num, bool value) internal { bytes memory _staticData = encodeStatic(num, value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](4); @@ -255,7 +255,7 @@ library Multi { function set(uint32 a, bool b, uint256 c, int120 d, MultiData memory _table) internal { bytes memory _staticData = encodeStatic(_table.num, _table.value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](4); @@ -273,7 +273,7 @@ library Multi { function _set(uint32 a, bool b, uint256 c, int120 d, MultiData memory _table) internal { bytes memory _staticData = encodeStatic(_table.num, _table.value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](4); @@ -302,7 +302,7 @@ library Multi { */ function decode( bytes memory _staticData, - PackedCounter, + EncodedLengths, bytes memory ) internal pure returns (MultiData memory _table) { (_table.num, _table.value) = decodeStatic(_staticData); @@ -348,10 +348,10 @@ library Multi { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(int256 num, bool value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(int256 num, bool value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(num, value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/e2e/packages/contracts/src/codegen/tables/Number.sol b/e2e/packages/contracts/src/codegen/tables/Number.sol index 2c2820a54a..f76a610081 100644 --- a/e2e/packages/contracts/src/codegen/tables/Number.sol +++ b/e2e/packages/contracts/src/codegen/tables/Number.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library Number { @@ -178,10 +178,10 @@ library Number { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint32 value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint32 value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/e2e/packages/contracts/src/codegen/tables/NumberList.sol b/e2e/packages/contracts/src/codegen/tables/NumberList.sol index 667191bfa2..9a559c959f 100644 --- a/e2e/packages/contracts/src/codegen/tables/NumberList.sol +++ b/e2e/packages/contracts/src/codegen/tables/NumberList.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library NumberList { @@ -377,10 +377,10 @@ library NumberList { * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). */ - function encodeLengths(uint32[] memory value) internal pure returns (PackedCounter _encodedLengths) { + function encodeLengths(uint32[] memory value) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack(value.length * 4); + _encodedLengths = EncodedLengthsLib.pack(value.length * 4); } } @@ -398,9 +398,9 @@ library NumberList { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint32[] memory value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint32[] memory value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(value); + EncodedLengths _encodedLengths = encodeLengths(value); bytes memory _dynamicData = encodeDynamic(value); return (_staticData, _encodedLengths, _dynamicData); diff --git a/e2e/packages/contracts/src/codegen/tables/Position.sol b/e2e/packages/contracts/src/codegen/tables/Position.sol index 2cfe47fc5b..dd80568016 100644 --- a/e2e/packages/contracts/src/codegen/tables/Position.sol +++ b/e2e/packages/contracts/src/codegen/tables/Position.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library Position { @@ -200,10 +200,10 @@ library Position { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(address player) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(address player) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(player); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/e2e/packages/contracts/src/codegen/tables/StaticArray.sol b/e2e/packages/contracts/src/codegen/tables/StaticArray.sol index 5ea56ba031..b9ba6ad861 100644 --- a/e2e/packages/contracts/src/codegen/tables/StaticArray.sol +++ b/e2e/packages/contracts/src/codegen/tables/StaticArray.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library StaticArray { @@ -263,10 +263,10 @@ library StaticArray { * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). */ - function encodeLengths(uint256[3] memory value) internal pure returns (PackedCounter _encodedLengths) { + function encodeLengths(uint256[3] memory value) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack(value.length * 32); + _encodedLengths = EncodedLengthsLib.pack(value.length * 32); } } @@ -284,9 +284,9 @@ library StaticArray { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint256[3] memory value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint256[3] memory value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(value); + EncodedLengths _encodedLengths = encodeLengths(value); bytes memory _dynamicData = encodeDynamic(value); return (_staticData, _encodedLengths, _dynamicData); diff --git a/e2e/packages/contracts/src/codegen/tables/Vector.sol b/e2e/packages/contracts/src/codegen/tables/Vector.sol index 34a65b5399..5c40adcb17 100644 --- a/e2e/packages/contracts/src/codegen/tables/Vector.sol +++ b/e2e/packages/contracts/src/codegen/tables/Vector.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; struct VectorData { @@ -157,7 +157,7 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -172,7 +172,7 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -186,7 +186,7 @@ library Vector { function set(uint32 key, int32 x, int32 y) internal { bytes memory _staticData = encodeStatic(x, y); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -201,7 +201,7 @@ library Vector { function _set(uint32 key, int32 x, int32 y) internal { bytes memory _staticData = encodeStatic(x, y); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -216,7 +216,7 @@ library Vector { function set(uint32 key, VectorData memory _table) internal { bytes memory _staticData = encodeStatic(_table.x, _table.y); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -231,7 +231,7 @@ library Vector { function _set(uint32 key, VectorData memory _table) internal { bytes memory _staticData = encodeStatic(_table.x, _table.y); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -257,7 +257,7 @@ library Vector { */ function decode( bytes memory _staticData, - PackedCounter, + EncodedLengths, bytes memory ) internal pure returns (VectorData memory _table) { (_table.x, _table.y) = decodeStatic(_staticData); @@ -297,10 +297,10 @@ library Vector { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(int32 x, int32 y) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(int32 x, int32 y) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(x, y); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol b/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol index c9a05bc627..7ddeff7860 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library CounterTable { @@ -221,10 +221,10 @@ library CounterTable { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint32 value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint32 value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol b/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol index f04fddc6e7..27c7991f10 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library Inventory { @@ -200,10 +200,10 @@ library Inventory { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint32 amount) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint32 amount) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(amount); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol b/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol index 343a9aac91..b8b96444db 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library MessageTable { @@ -64,7 +64,7 @@ library MessageTable { */ function set(string memory value) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(value); + EncodedLengths _encodedLengths = encodeLengths(value); bytes memory _dynamicData = encodeDynamic(value); bytes32[] memory _keyTuple = new bytes32[](0); @@ -77,7 +77,7 @@ library MessageTable { */ function _set(string memory value) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(value); + EncodedLengths _encodedLengths = encodeLengths(value); bytes memory _dynamicData = encodeDynamic(value); bytes32[] memory _keyTuple = new bytes32[](0); @@ -89,7 +89,7 @@ library MessageTable { * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ function decodeDynamic( - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _blob ) internal pure returns (string memory value) { uint256 _start; @@ -108,7 +108,7 @@ library MessageTable { */ function decode( bytes memory, - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _dynamicData ) internal pure returns (string memory value) { (value) = decodeDynamic(_encodedLengths, _dynamicData); @@ -136,10 +136,10 @@ library MessageTable { * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). */ - function encodeLengths(string memory value) internal pure returns (PackedCounter _encodedLengths) { + function encodeLengths(string memory value) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack(bytes(value).length); + _encodedLengths = EncodedLengthsLib.pack(bytes(value).length); } } @@ -157,9 +157,9 @@ library MessageTable { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(string memory value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(string memory value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(value); + EncodedLengths _encodedLengths = encodeLengths(value); bytes memory _dynamicData = encodeDynamic(value); return (_staticData, _encodedLengths, _dynamicData); 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 a9598707c7..496f947461 100644 --- a/examples/multiple-accounts/packages/contracts/src/codegen/tables/LastCall.sol +++ b/examples/multiple-accounts/packages/contracts/src/codegen/tables/LastCall.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; struct LastCallData { @@ -157,7 +157,7 @@ library LastCall { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(caller))); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -172,7 +172,7 @@ library LastCall { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(caller))); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -186,7 +186,7 @@ library LastCall { function set(address caller, uint256 callTime, address sender) internal { bytes memory _staticData = encodeStatic(callTime, sender); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -201,7 +201,7 @@ library LastCall { function _set(address caller, uint256 callTime, address sender) internal { bytes memory _staticData = encodeStatic(callTime, sender); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -216,7 +216,7 @@ library LastCall { function set(address caller, LastCallData memory _table) internal { bytes memory _staticData = encodeStatic(_table.callTime, _table.sender); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -231,7 +231,7 @@ library LastCall { function _set(address caller, LastCallData memory _table) internal { bytes memory _staticData = encodeStatic(_table.callTime, _table.sender); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -257,7 +257,7 @@ library LastCall { */ function decode( bytes memory _staticData, - PackedCounter, + EncodedLengths, bytes memory ) internal pure returns (LastCallData memory _table) { (_table.callTime, _table.sender) = decodeStatic(_staticData); @@ -297,10 +297,10 @@ library LastCall { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint256 callTime, address sender) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint256 callTime, address sender) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(callTime, sender); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol index 87e79fd2ac..45df0941b4 100644 --- a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol +++ b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; struct Dynamics1Data { @@ -574,7 +574,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -589,7 +589,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -609,7 +609,7 @@ library Dynamics1 { bool[5] memory staticBools ) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(staticB32, staticI32, staticU128, staticAddrs, staticBools); + EncodedLengths _encodedLengths = encodeLengths(staticB32, staticI32, staticU128, staticAddrs, staticBools); bytes memory _dynamicData = encodeDynamic(staticB32, staticI32, staticU128, staticAddrs, staticBools); bytes32[] memory _keyTuple = new bytes32[](1); @@ -630,7 +630,7 @@ library Dynamics1 { bool[5] memory staticBools ) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(staticB32, staticI32, staticU128, staticAddrs, staticBools); + EncodedLengths _encodedLengths = encodeLengths(staticB32, staticI32, staticU128, staticAddrs, staticBools); bytes memory _dynamicData = encodeDynamic(staticB32, staticI32, staticU128, staticAddrs, staticBools); bytes32[] memory _keyTuple = new bytes32[](1); @@ -644,7 +644,7 @@ library Dynamics1 { */ function set(bytes32 key, Dynamics1Data memory _table) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths( + EncodedLengths _encodedLengths = encodeLengths( _table.staticB32, _table.staticI32, _table.staticU128, @@ -670,7 +670,7 @@ library Dynamics1 { */ function _set(bytes32 key, Dynamics1Data memory _table) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths( + EncodedLengths _encodedLengths = encodeLengths( _table.staticB32, _table.staticI32, _table.staticU128, @@ -695,7 +695,7 @@ library Dynamics1 { * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ function decodeDynamic( - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _blob ) internal @@ -748,7 +748,7 @@ library Dynamics1 { */ function decode( bytes memory, - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _dynamicData ) internal pure returns (Dynamics1Data memory _table) { (_table.staticB32, _table.staticI32, _table.staticU128, _table.staticAddrs, _table.staticBools) = decodeDynamic( @@ -787,10 +787,10 @@ library Dynamics1 { uint128[3] memory staticU128, address[4] memory staticAddrs, bool[5] memory staticBools - ) internal pure returns (PackedCounter _encodedLengths) { + ) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack( + _encodedLengths = EncodedLengthsLib.pack( staticB32.length * 32, staticI32.length * 4, staticU128.length * 16, @@ -833,9 +833,9 @@ library Dynamics1 { uint128[3] memory staticU128, address[4] memory staticAddrs, bool[5] memory staticBools - ) internal pure returns (bytes memory, PackedCounter, bytes memory) { + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(staticB32, staticI32, staticU128, staticAddrs, staticBools); + EncodedLengths _encodedLengths = encodeLengths(staticB32, staticI32, staticU128, staticAddrs, staticBools); bytes memory _dynamicData = encodeDynamic(staticB32, staticI32, staticU128, staticAddrs, staticBools); return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol index 07bc193055..e2480a74fe 100644 --- a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol +++ b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; struct Dynamics2Data { @@ -561,7 +561,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -576,7 +576,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -589,7 +589,7 @@ library Dynamics2 { */ function set(bytes32 key, uint64[] memory u64, string memory str, bytes memory b) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(u64, str, b); + EncodedLengths _encodedLengths = encodeLengths(u64, str, b); bytes memory _dynamicData = encodeDynamic(u64, str, b); bytes32[] memory _keyTuple = new bytes32[](1); @@ -603,7 +603,7 @@ library Dynamics2 { */ function _set(bytes32 key, uint64[] memory u64, string memory str, bytes memory b) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(u64, str, b); + EncodedLengths _encodedLengths = encodeLengths(u64, str, b); bytes memory _dynamicData = encodeDynamic(u64, str, b); bytes32[] memory _keyTuple = new bytes32[](1); @@ -617,7 +617,7 @@ library Dynamics2 { */ function set(bytes32 key, Dynamics2Data memory _table) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(_table.u64, _table.str, _table.b); + EncodedLengths _encodedLengths = encodeLengths(_table.u64, _table.str, _table.b); bytes memory _dynamicData = encodeDynamic(_table.u64, _table.str, _table.b); bytes32[] memory _keyTuple = new bytes32[](1); @@ -631,7 +631,7 @@ library Dynamics2 { */ function _set(bytes32 key, Dynamics2Data memory _table) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(_table.u64, _table.str, _table.b); + EncodedLengths _encodedLengths = encodeLengths(_table.u64, _table.str, _table.b); bytes memory _dynamicData = encodeDynamic(_table.u64, _table.str, _table.b); bytes32[] memory _keyTuple = new bytes32[](1); @@ -644,7 +644,7 @@ library Dynamics2 { * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ function decodeDynamic( - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _blob ) internal pure returns (uint64[] memory u64, string memory str, bytes memory b) { uint256 _start; @@ -675,7 +675,7 @@ library Dynamics2 { */ function decode( bytes memory, - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _dynamicData ) internal pure returns (Dynamics2Data memory _table) { (_table.u64, _table.str, _table.b) = decodeDynamic(_encodedLengths, _dynamicData); @@ -709,10 +709,10 @@ library Dynamics2 { uint64[] memory u64, string memory str, bytes memory b - ) internal pure returns (PackedCounter _encodedLengths) { + ) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack(u64.length * 8, bytes(str).length, bytes(b).length); + _encodedLengths = EncodedLengthsLib.pack(u64.length * 8, bytes(str).length, bytes(b).length); } } @@ -734,9 +734,9 @@ library Dynamics2 { uint64[] memory u64, string memory str, bytes memory b - ) internal pure returns (bytes memory, PackedCounter, bytes memory) { + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(u64, str, b); + EncodedLengths _encodedLengths = encodeLengths(u64, str, b); bytes memory _dynamicData = encodeDynamic(u64, str, b); return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/cli/contracts/src/codegen/tables/Offchain.sol b/packages/cli/contracts/src/codegen/tables/Offchain.sol index 3370ff4c7f..cd3f75868e 100644 --- a/packages/cli/contracts/src/codegen/tables/Offchain.sol +++ b/packages/cli/contracts/src/codegen/tables/Offchain.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library Offchain { @@ -86,7 +86,7 @@ library Offchain { function set(bytes32 key, uint256 value) internal { bytes memory _staticData = encodeStatic(value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -101,7 +101,7 @@ library Offchain { function _set(bytes32 key, uint256 value) internal { bytes memory _staticData = encodeStatic(value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -123,7 +123,7 @@ library Offchain { * * */ - function decode(bytes memory _staticData, PackedCounter, bytes memory) internal pure returns (uint256 value) { + function decode(bytes memory _staticData, EncodedLengths, bytes memory) internal pure returns (uint256 value) { (value) = decodeStatic(_staticData); } @@ -161,10 +161,10 @@ library Offchain { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint256 value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint256 value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/cli/contracts/src/codegen/tables/Singleton.sol b/packages/cli/contracts/src/codegen/tables/Singleton.sol index 2c25fd5924..2982b00c4a 100644 --- a/packages/cli/contracts/src/codegen/tables/Singleton.sol +++ b/packages/cli/contracts/src/codegen/tables/Singleton.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library Singleton { @@ -379,7 +379,7 @@ library Singleton { function get() internal view returns (int256 v1, uint32[2] memory v2, uint32[2] memory v3, uint32[1] memory v4) { bytes32[] memory _keyTuple = new bytes32[](0); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -393,7 +393,7 @@ library Singleton { function _get() internal view returns (int256 v1, uint32[2] memory v2, uint32[2] memory v3, uint32[1] memory v4) { bytes32[] memory _keyTuple = new bytes32[](0); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -407,7 +407,7 @@ library Singleton { function set(int256 v1, uint32[2] memory v2, uint32[2] memory v3, uint32[1] memory v4) internal { bytes memory _staticData = encodeStatic(v1); - PackedCounter _encodedLengths = encodeLengths(v2, v3, v4); + EncodedLengths _encodedLengths = encodeLengths(v2, v3, v4); bytes memory _dynamicData = encodeDynamic(v2, v3, v4); bytes32[] memory _keyTuple = new bytes32[](0); @@ -421,7 +421,7 @@ library Singleton { function _set(int256 v1, uint32[2] memory v2, uint32[2] memory v3, uint32[1] memory v4) internal { bytes memory _staticData = encodeStatic(v1); - PackedCounter _encodedLengths = encodeLengths(v2, v3, v4); + EncodedLengths _encodedLengths = encodeLengths(v2, v3, v4); bytes memory _dynamicData = encodeDynamic(v2, v3, v4); bytes32[] memory _keyTuple = new bytes32[](0); @@ -440,7 +440,7 @@ library Singleton { * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ function decodeDynamic( - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _blob ) internal pure returns (uint32[2] memory v2, uint32[2] memory v3, uint32[1] memory v4) { uint256 _start; @@ -471,7 +471,7 @@ library Singleton { */ function decode( bytes memory _staticData, - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _dynamicData ) internal pure returns (int256 v1, uint32[2] memory v2, uint32[2] memory v3, uint32[1] memory v4) { (v1) = decodeStatic(_staticData); @@ -513,10 +513,10 @@ library Singleton { uint32[2] memory v2, uint32[2] memory v3, uint32[1] memory v4 - ) internal pure returns (PackedCounter _encodedLengths) { + ) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack(v2.length * 4, v3.length * 4, v4.length * 4); + _encodedLengths = EncodedLengthsLib.pack(v2.length * 4, v3.length * 4, v4.length * 4); } } @@ -548,10 +548,10 @@ library Singleton { uint32[2] memory v2, uint32[2] memory v3, uint32[1] memory v4 - ) internal pure returns (bytes memory, PackedCounter, bytes memory) { + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(v1); - PackedCounter _encodedLengths = encodeLengths(v2, v3, v4); + EncodedLengths _encodedLengths = encodeLengths(v2, v3, v4); bytes memory _dynamicData = encodeDynamic(v2, v3, v4); return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/cli/contracts/src/codegen/tables/Statics.sol b/packages/cli/contracts/src/codegen/tables/Statics.sol index 6ea710509e..83b959c491 100644 --- a/packages/cli/contracts/src/codegen/tables/Statics.sol +++ b/packages/cli/contracts/src/codegen/tables/Statics.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -473,7 +473,7 @@ library Statics { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -500,7 +500,7 @@ library Statics { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -527,7 +527,7 @@ library Statics { ) internal { bytes memory _staticData = encodeStatic(v1, v2, v3, v4, v5, v6); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](6); @@ -560,7 +560,7 @@ library Statics { ) internal { bytes memory _staticData = encodeStatic(v1, v2, v3, v4, v5, v6); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](6); @@ -580,7 +580,7 @@ library Statics { function set(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, StaticsData memory _table) internal { bytes memory _staticData = encodeStatic(_table.v1, _table.v2, _table.v3, _table.v4, _table.v5, _table.v6); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](6); @@ -600,7 +600,7 @@ library Statics { function _set(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, StaticsData memory _table) internal { bytes memory _staticData = encodeStatic(_table.v1, _table.v2, _table.v3, _table.v4, _table.v5, _table.v6); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](6); @@ -641,7 +641,7 @@ library Statics { */ function decode( bytes memory _staticData, - PackedCounter, + EncodedLengths, bytes memory ) internal pure returns (StaticsData memory _table) { (_table.v1, _table.v2, _table.v3, _table.v4, _table.v5, _table.v6) = decodeStatic(_staticData); @@ -705,10 +705,10 @@ library Statics { address v4, bool v5, Enum1 v6 - ) internal pure returns (bytes memory, PackedCounter, bytes memory) { + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(v1, v2, v3, v4, v5, v6); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/cli/contracts/src/codegen/tables/UserTyped.sol b/packages/cli/contracts/src/codegen/tables/UserTyped.sol index 67434015db..5e05f4d1a9 100644 --- a/packages/cli/contracts/src/codegen/tables/UserTyped.sol +++ b/packages/cli/contracts/src/codegen/tables/UserTyped.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -541,7 +541,7 @@ library UserTyped { _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); _keyTuple[4] = ResourceId.unwrap(k5); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -566,7 +566,7 @@ library UserTyped { _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); _keyTuple[4] = ResourceId.unwrap(k5); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -591,7 +591,7 @@ library UserTyped { ) internal { bytes memory _staticData = encodeStatic(v1, v2, v3, v4, v5); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](5); @@ -621,7 +621,7 @@ library UserTyped { ) internal { bytes memory _staticData = encodeStatic(v1, v2, v3, v4, v5); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](5); @@ -647,7 +647,7 @@ library UserTyped { ) internal { bytes memory _staticData = encodeStatic(_table.v1, _table.v2, _table.v3, _table.v4, _table.v5); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](5); @@ -673,7 +673,7 @@ library UserTyped { ) internal { bytes memory _staticData = encodeStatic(_table.v1, _table.v2, _table.v3, _table.v4, _table.v5); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](5); @@ -721,7 +721,7 @@ library UserTyped { */ function decode( bytes memory _staticData, - PackedCounter, + EncodedLengths, bytes memory ) internal pure returns (UserTypedData memory _table) { (_table.v1, _table.v2, _table.v3, _table.v4, _table.v5) = decodeStatic(_staticData); @@ -793,10 +793,10 @@ library UserTyped { TestTypeLibrary.TestTypeBool v3, TestTypeLibrary.TestTypeUint128 v4, ResourceId v5 - ) internal pure returns (bytes memory, PackedCounter, bytes memory) { + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(v1, v2, v3, v4, v5); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/protocol-parser/src/decodeRecord.ts b/packages/protocol-parser/src/decodeRecord.ts index 07cc48d6d5..c80e9aa762 100644 --- a/packages/protocol-parser/src/decodeRecord.ts +++ b/packages/protocol-parser/src/decodeRecord.ts @@ -8,7 +8,7 @@ import { Hex } from "viem"; import { Schema } from "./common"; import { decodeDynamicField } from "./decodeDynamicField"; import { decodeStaticField } from "./decodeStaticField"; -import { hexToPackedCounter } from "./hexToPackedCounter"; +import { hexToEncodedLengths } from "./hexToEncodedLengths"; import { staticDataLength } from "./staticDataLength"; import { readHex } from "@latticexyz/common"; @@ -39,7 +39,7 @@ export function decodeRecord(valueSchema: Schema, data: Hex): readonly (StaticPr } if (valueSchema.dynamicFields.length > 0) { - const dataLayout = hexToPackedCounter(readHex(data, bytesOffset, bytesOffset + 32)); + const dataLayout = hexToEncodedLengths(readHex(data, bytesOffset, bytesOffset + 32)); bytesOffset += 32; valueSchema.dynamicFields.forEach((fieldType, i) => { diff --git a/packages/protocol-parser/src/encodeRecord.ts b/packages/protocol-parser/src/encodeRecord.ts index 46d2cee65f..ab7568dd7f 100644 --- a/packages/protocol-parser/src/encodeRecord.ts +++ b/packages/protocol-parser/src/encodeRecord.ts @@ -26,9 +26,9 @@ export function encodeRecord( const dynamicData = dynamicDataItems.join(""); - const packedCounter = `${dynamicFieldByteLengths + const encodedLengths = `${dynamicFieldByteLengths .map((length) => encodeField("uint40", length).replace(/^0x/, "")) .join("")}${encodeField("uint56", dynamicTotalByteLength).replace(/^0x/, "")}`.padStart(64, "0"); - return `0x${staticData}${packedCounter}${dynamicData}`; + return `0x${staticData}${encodedLengths}${dynamicData}`; } diff --git a/packages/protocol-parser/src/errors.ts b/packages/protocol-parser/src/errors.ts index a3c10857a5..51ce2d4311 100644 --- a/packages/protocol-parser/src/errors.ts +++ b/packages/protocol-parser/src/errors.ts @@ -16,10 +16,10 @@ export class InvalidHexLengthForSchemaError extends MUDError { } } -export class InvalidHexLengthForPackedCounterError extends MUDError { - override name = "InvalidHexLengthForPackedCounterError"; +export class InvalidHexLengthForEncodedLengthsError extends MUDError { + override name = "InvalidHexLengthForEncodedLengthsError"; constructor(value: Hex) { - super(`Hex value "${value}" has length of ${value.length - 2}, but expected length of 64 for a packed counter.`); + super(`Hex value "${value}" has length of ${value.length - 2}, but expected length of 64 for encoded lengths.`); } } @@ -55,11 +55,11 @@ export class SchemaStaticLengthMismatchError extends MUDError { } } -export class PackedCounterLengthMismatchError extends MUDError { - override name = "PackedCounterLengthMismatchError"; - constructor(packedCounterData: Hex, definedLength: bigint, summedLength: bigint) { +export class EncodedLengthsLengthMismatchError extends MUDError { + override name = "EncodedLengthsLengthMismatchError"; + constructor(encodedLengthsData: Hex, definedLength: bigint, summedLength: bigint) { super( - `PackedCounter "${packedCounterData}" total bytes length (${definedLength}) did not match the summed length of all field byte lengths (${summedLength}).`, + `EncodedLengths "${encodedLengthsData}" total bytes length (${definedLength}) did not match the summed length of all field byte lengths (${summedLength}).`, ); } } diff --git a/packages/protocol-parser/src/exports/internal.ts b/packages/protocol-parser/src/exports/internal.ts index e30be5f5cc..05f692c0ad 100644 --- a/packages/protocol-parser/src/exports/internal.ts +++ b/packages/protocol-parser/src/exports/internal.ts @@ -16,7 +16,7 @@ export * from "../encodeValue"; export * from "../encodeValueArgs"; export * from "../errors"; export * from "../fieldLayoutToHex"; -export * from "../hexToPackedCounter"; +export * from "../hexToEncodedLengths"; export * from "../hexToSchema"; export * from "../hexToTableSchema"; export * from "../keySchemaToHex"; diff --git a/packages/protocol-parser/src/hexToEncodedLengths.test.ts b/packages/protocol-parser/src/hexToEncodedLengths.test.ts new file mode 100644 index 0000000000..3f029c5e17 --- /dev/null +++ b/packages/protocol-parser/src/hexToEncodedLengths.test.ts @@ -0,0 +1,35 @@ +import { describe, expect, it } from "vitest"; +import { hexToEncodedLengths } from "./hexToEncodedLengths"; + +describe("hexToEncodedLengths", () => { + it("decodes hex data to encoded lengths", () => { + expect(hexToEncodedLengths("0x0000000000000000000000000000400000000020000000002000000000000080")) + .toMatchInlineSnapshot(` + { + "fieldByteLengths": [ + 32, + 32, + 64, + 0, + 0, + ], + "totalByteLength": 128n, + } + `); + }); + + it("throws if schema hex data is not bytes32", () => { + expect(() => hexToEncodedLengths("0x01234")).toThrowErrorMatchingInlineSnapshot( + '"Hex value \\"0x01234\\" has length of 5, but expected length of 64 for encoded lengths."', + ); + }); + + it("throws if encoded lengths total byte length doesn't match summed byte length of fields", () => { + expect(() => + hexToEncodedLengths("0x0000000000000000000000000000400000000020000000002000000000000040"), + ).toThrowErrorMatchingInlineSnapshot( + // eslint-disable-next-line max-len + '"EncodedLengths \\"0x0000000000000000000000000000400000000020000000002000000000000040\\" total bytes length (64) did not match the summed length of all field byte lengths (128)."', + ); + }); +}); diff --git a/packages/protocol-parser/src/hexToPackedCounter.ts b/packages/protocol-parser/src/hexToEncodedLengths.ts similarity index 78% rename from packages/protocol-parser/src/hexToPackedCounter.ts rename to packages/protocol-parser/src/hexToEncodedLengths.ts index d29121b7ff..5f4333c397 100644 --- a/packages/protocol-parser/src/hexToPackedCounter.ts +++ b/packages/protocol-parser/src/hexToEncodedLengths.ts @@ -1,22 +1,22 @@ import { Hex } from "viem"; import { decodeStaticField } from "./decodeStaticField"; import { decodeDynamicField } from "./decodeDynamicField"; -import { InvalidHexLengthForPackedCounterError, PackedCounterLengthMismatchError } from "./errors"; +import { InvalidHexLengthForEncodedLengthsError, EncodedLengthsLengthMismatchError } from "./errors"; import { readHex } from "@latticexyz/common"; -// Keep this logic in sync with PackedCounter.sol +// Keep this logic in sync with EncodedLengths.sol // - Last 7 bytes (uint56) are used for the total byte length of the dynamic data // - The next 5 byte (uint40) sections are used for the byte length of each field, indexed from right to left // We use byte lengths rather than item counts so that, on chain, we can slice without having to get the value schema first (and thus the field lengths of each dynamic type) -export function hexToPackedCounter(data: Hex): { +export function hexToEncodedLengths(data: Hex): { totalByteLength: bigint; fieldByteLengths: readonly number[]; } { if (data.length !== 66) { - throw new InvalidHexLengthForPackedCounterError(data); + throw new InvalidHexLengthForEncodedLengthsError(data); } const totalByteLength = decodeStaticField("uint56", readHex(data, 32 - 7, 32)); @@ -27,7 +27,7 @@ export function hexToPackedCounter(data: Hex): { const summedLength = BigInt(fieldByteLengths.reduce((total, length) => total + length, 0)); if (summedLength !== totalByteLength) { - throw new PackedCounterLengthMismatchError(data, totalByteLength, summedLength); + throw new EncodedLengthsLengthMismatchError(data, totalByteLength, summedLength); } return { totalByteLength, fieldByteLengths }; diff --git a/packages/protocol-parser/src/hexToPackedCounter.test.ts b/packages/protocol-parser/src/hexToPackedCounter.test.ts deleted file mode 100644 index 91e6a090e0..0000000000 --- a/packages/protocol-parser/src/hexToPackedCounter.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { hexToPackedCounter } from "./hexToPackedCounter"; - -describe("hexToPackedCounter", () => { - it("decodes hex data to packed counter", () => { - expect(hexToPackedCounter("0x0000000000000000000000000000400000000020000000002000000000000080")) - .toMatchInlineSnapshot(` - { - "fieldByteLengths": [ - 32, - 32, - 64, - 0, - 0, - ], - "totalByteLength": 128n, - } - `); - }); - - it("throws if schema hex data is not bytes32", () => { - expect(() => hexToPackedCounter("0x01234")).toThrowErrorMatchingInlineSnapshot( - '"Hex value \\"0x01234\\" has length of 5, but expected length of 64 for a packed counter."', - ); - }); - - it("throws if packed counter total byte length doesn't match summed byte length of fields", () => { - expect(() => - hexToPackedCounter("0x0000000000000000000000000000400000000020000000002000000000000040"), - ).toThrowErrorMatchingInlineSnapshot( - // eslint-disable-next-line max-len - '"PackedCounter \\"0x0000000000000000000000000000400000000020000000002000000000000040\\" total bytes length (64) did not match the summed length of all field byte lengths (128)."', - ); - }); -}); diff --git a/packages/schema-type/src/typescript/dynamicAbiTypes.ts b/packages/schema-type/src/typescript/dynamicAbiTypes.ts index 271ef47fea..5c54a14fab 100644 --- a/packages/schema-type/src/typescript/dynamicAbiTypes.ts +++ b/packages/schema-type/src/typescript/dynamicAbiTypes.ts @@ -2,7 +2,7 @@ import { Hex } from "viem"; import { DynamicAbiType, dynamicAbiTypes } from "./schemaAbiTypes"; import { LiteralToBroad } from "./utils"; -// Variable-length ABI types, where their lengths are encoded by a PackedCounter within the record +// Variable-length ABI types, where their lengths are encoded by EncodedLengths within the record export type DynamicPrimitiveType = | readonly number[] diff --git a/packages/store/gas-report.json b/packages/store/gas-report.json index 46a02d14ec..e4ba19f8c0 100644 --- a/packages/store/gas-report.json +++ b/packages/store/gas-report.json @@ -35,6 +35,36 @@ "name": "Callbacks: push 1 element", "gasUsed": 32402 }, + { + "file": "test/EncodedLengths.t.sol", + "test": "testAtIndex", + "name": "get value at index of EncodedLengths", + "gasUsed": 24 + }, + { + "file": "test/EncodedLengths.t.sol", + "test": "testGas", + "name": "pack 1 length into EncodedLengths", + "gasUsed": 35 + }, + { + "file": "test/EncodedLengths.t.sol", + "test": "testGas", + "name": "pack 4 lengths into EncodedLengths", + "gasUsed": 169 + }, + { + "file": "test/EncodedLengths.t.sol", + "test": "testGas", + "name": "get total of EncodedLengths", + "gasUsed": 15 + }, + { + "file": "test/EncodedLengths.t.sol", + "test": "testSetAtIndex", + "name": "set value at index of EncodedLengths", + "gasUsed": 283 + }, { "file": "test/FieldLayout.t.sol", "test": "testEncodeDecodeFieldLayout", @@ -383,36 +413,6 @@ "name": "delete record from Mixed (internal, warm)", "gasUsed": 7033 }, - { - "file": "test/PackedCounter.t.sol", - "test": "testAtIndex", - "name": "get value at index of PackedCounter", - "gasUsed": 24 - }, - { - "file": "test/PackedCounter.t.sol", - "test": "testGas", - "name": "pack 1 length into PackedCounter", - "gasUsed": 35 - }, - { - "file": "test/PackedCounter.t.sol", - "test": "testGas", - "name": "pack 4 lengths into PackedCounter", - "gasUsed": 169 - }, - { - "file": "test/PackedCounter.t.sol", - "test": "testGas", - "name": "get total of PackedCounter", - "gasUsed": 15 - }, - { - "file": "test/PackedCounter.t.sol", - "test": "testSetAtIndex", - "name": "set value at index of PackedCounter", - "gasUsed": 283 - }, { "file": "test/ResourceId.t.sol", "test": "testEncode", diff --git a/packages/store/src/EncodedLengths.sol b/packages/store/src/EncodedLengths.sol new file mode 100644 index 0000000000..5a0090ad68 --- /dev/null +++ b/packages/store/src/EncodedLengths.sol @@ -0,0 +1,224 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.24; + +import { BYTE_TO_BITS } from "./constants.sol"; +import { IEncodedLengthsErrors } from "./IEncodedLengthsErrors.sol"; + +/** + * @title EncodedLengths Type Definition + * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz) + * @dev Describes how the encoded lengths is structured. + * - 0x00-0x06 The least significant 7 bytes (uint56) represent the total byte length of dynamic (variable length) data. + * - 0x07-0xB The next five bytes (uint40) represent the length of the first dynamic field. + * - 0x0C-0x10 Followed by the length of the second dynamic field + * - 0x11-0x15 Length of the third dynamic field + * - 0x16-0x1A Length of fourth dynamic field + * - 0x1B-0x1F Length of fifth dynamic field + */ +type EncodedLengths is bytes32; + +using EncodedLengthsInstance for EncodedLengths global; + +// Constants for encoded lengths handling: + +// Number of bits for the 7-byte accumulator +uint256 constant ACC_BITS = 7 * BYTE_TO_BITS; +// Number of bits for the 5-byte sections +uint256 constant VAL_BITS = 5 * BYTE_TO_BITS; +// Maximum value of a 5-byte section +uint256 constant MAX_VAL = type(uint40).max; + +/** + * @title EncodedLengths Library + * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz) + * @notice Static functions for handling EncodedLengths type. + * @dev Provides utility functions to pack values into EncodedLengths. + * The caller must ensure that the value arguments are <= MAX_VAL. + */ +library EncodedLengthsLib { + /** + * @notice Packs a single value into EncodedLengths. + * @dev Encodes the given value 'a' into the structure of EncodedLengths. The encoded lengths's accumulator + * will be set to 'a', and the first value slot of the EncodedLengths will also be set to 'a'. + * @param a The length of the first dynamic field's data. + * @return The resulting EncodedLengths containing the encoded value. + */ + function pack(uint256 a) internal pure returns (EncodedLengths) { + uint256 encodedLengths; + unchecked { + encodedLengths = a; + encodedLengths |= (uint256(a) << (ACC_BITS + VAL_BITS * 0)); + } + return EncodedLengths.wrap(bytes32(encodedLengths)); + } + + /** + * @notice Packs two values into EncodedLengths. + * @dev Encodes the given values 'a'-'b' into the structure of EncodedLengths. + * @param a The length of the first dynamic field's data. + * @param b The length of the second dynamic field's data. + * @return The resulting EncodedLengths containing the encoded values. + */ + function pack(uint256 a, uint256 b) internal pure returns (EncodedLengths) { + uint256 encodedLengths; + unchecked { + encodedLengths = a + b; + encodedLengths |= (uint256(a) << (ACC_BITS + VAL_BITS * 0)); + encodedLengths |= (uint256(b) << (ACC_BITS + VAL_BITS * 1)); + } + return EncodedLengths.wrap(bytes32(encodedLengths)); + } + + /** + * @notice Packs three values into EncodedLengths. + * @dev Encodes the given values 'a'-'c' into the structure of EncodedLengths. + * @param a The length of the first dynamic field's data. + * @param b The length of the second dynamic field's data. + * @param c The length of the third dynamic field's data. + * @return The resulting EncodedLengths containing the encoded values. + */ + function pack(uint256 a, uint256 b, uint256 c) internal pure returns (EncodedLengths) { + uint256 encodedLengths; + unchecked { + encodedLengths = a + b + c; + encodedLengths |= (uint256(a) << (ACC_BITS + VAL_BITS * 0)); + encodedLengths |= (uint256(b) << (ACC_BITS + VAL_BITS * 1)); + encodedLengths |= (uint256(c) << (ACC_BITS + VAL_BITS * 2)); + } + return EncodedLengths.wrap(bytes32(encodedLengths)); + } + + /** + * @notice Packs four values into EncodedLengths. + * @dev Encodes the given values 'a'-'d' into the structure of EncodedLengths. + * @param a The length of the first dynamic field's data. + * @param b The length of the second dynamic field's data. + * @param c The length of the third dynamic field's data. + * @param d The length of the fourth dynamic field's data. + * @return The resulting EncodedLengths containing the encoded values. + */ + function pack(uint256 a, uint256 b, uint256 c, uint256 d) internal pure returns (EncodedLengths) { + uint256 encodedLengths; + unchecked { + encodedLengths = a + b + c + d; + encodedLengths |= (uint256(a) << (ACC_BITS + VAL_BITS * 0)); + encodedLengths |= (uint256(b) << (ACC_BITS + VAL_BITS * 1)); + encodedLengths |= (uint256(c) << (ACC_BITS + VAL_BITS * 2)); + encodedLengths |= (uint256(d) << (ACC_BITS + VAL_BITS * 3)); + } + return EncodedLengths.wrap(bytes32(encodedLengths)); + } + + /** + * @notice Packs five values into EncodedLengths. + * @dev Encodes the given values 'a'-'e' into the structure of EncodedLengths. + * @param a The length of the first dynamic field's data. + * @param b The length of the second dynamic field's data. + * @param c The length of the third dynamic field's data. + * @param d The length of the fourth dynamic field's data. + * @param e The length of the fifth dynamic field's data. + * @return The resulting EncodedLengths containing the encoded values. + */ + function pack(uint256 a, uint256 b, uint256 c, uint256 d, uint256 e) internal pure returns (EncodedLengths) { + uint256 encodedLengths; + unchecked { + encodedLengths = a + b + c + d + e; + encodedLengths |= (uint256(a) << (ACC_BITS + VAL_BITS * 0)); + encodedLengths |= (uint256(b) << (ACC_BITS + VAL_BITS * 1)); + encodedLengths |= (uint256(c) << (ACC_BITS + VAL_BITS * 2)); + encodedLengths |= (uint256(d) << (ACC_BITS + VAL_BITS * 3)); + encodedLengths |= (uint256(e) << (ACC_BITS + VAL_BITS * 4)); + } + return EncodedLengths.wrap(bytes32(encodedLengths)); + } +} + +/** + * @title EncodedLengths Instance Library + * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz) + * @notice Instance functions for handling EncodedLengths. + * @dev Offers decoding, extracting, and setting functionalities for EncodedLengths. + */ +library EncodedLengthsInstance { + /** + * @notice Decode the accumulated counter from EncodedLengths. + * @dev Extracts the right-most 7 bytes of EncodedLengths. + * @param encodedLengths The encoded lengths to decode. + * @return The accumulated value from the EncodedLengths. + */ + function total(EncodedLengths encodedLengths) internal pure returns (uint256) { + return uint56(uint256(EncodedLengths.unwrap(encodedLengths))); + } + + /** + * @notice Decode the dynamic field size at a specific index from EncodedLengths. + * @dev Extracts value right-to-left, with 5 bytes per dynamic field after the right-most 7 bytes. + * @param encodedLengths The encoded lengths to decode. + * @param index The index to retrieve. + * @return The value at the given index from the EncodedLengths. + */ + function atIndex(EncodedLengths encodedLengths, uint8 index) internal pure returns (uint256) { + unchecked { + return uint40(uint256(EncodedLengths.unwrap(encodedLengths) >> (ACC_BITS + VAL_BITS * index))); + } + } + + /** + * @notice Set a counter at a specific index in EncodedLengths. + * @dev Updates a value at a specific index and updates the accumulator field. + * @param encodedLengths The encoded lengths to modify. + * @param index The index to set. + * @param newValueAtIndex The new value to set at the given index. + * @return The modified EncodedLengths. + */ + function setAtIndex( + EncodedLengths encodedLengths, + uint8 index, + uint256 newValueAtIndex + ) internal pure returns (EncodedLengths) { + if (newValueAtIndex > MAX_VAL) { + revert IEncodedLengthsErrors.EncodedLengths_InvalidLength(newValueAtIndex); + } + + uint256 rawEncodedLengths = uint256(EncodedLengths.unwrap(encodedLengths)); + + // Get current lengths (total and at index) + uint256 accumulator = total(encodedLengths); + uint256 currentValueAtIndex = atIndex(encodedLengths, index); + + // Compute the difference and update the total value + unchecked { + if (newValueAtIndex >= currentValueAtIndex) { + accumulator += newValueAtIndex - currentValueAtIndex; + } else { + accumulator -= currentValueAtIndex - newValueAtIndex; + } + } + + // Set the new accumulated value and value at index + // (7 bytes total length, 5 bytes per dynamic field) + uint256 offset; + unchecked { + offset = ACC_BITS + VAL_BITS * index; + } + // Bitmask with 1s at the 5 bytes that form the value slot at the given index + uint256 mask = uint256(type(uint40).max) << offset; + + // First set the last 7 bytes to 0, then set them to the new length + rawEncodedLengths = (rawEncodedLengths & ~uint256(type(uint56).max)) | accumulator; + + // Zero out the value slot at the given index, then set the new value + rawEncodedLengths = (rawEncodedLengths & ~mask) | ((newValueAtIndex << offset) & mask); + + return EncodedLengths.wrap(bytes32(rawEncodedLengths)); + } + + /** + * @notice Unwrap EncodedLengths to its raw bytes32 representation. + * @param encodedLengths The encoded lengths to unwrap. + * @return The raw bytes32 value of the EncodedLengths. + */ + function unwrap(EncodedLengths encodedLengths) internal pure returns (bytes32) { + return EncodedLengths.unwrap(encodedLengths); + } +} diff --git a/packages/store/src/FieldLayout.sol b/packages/store/src/FieldLayout.sol index 1cc3bb5154..ccc146c4b3 100644 --- a/packages/store/src/FieldLayout.sol +++ b/packages/store/src/FieldLayout.sol @@ -13,7 +13,7 @@ import { IFieldLayoutErrors } from "./IFieldLayoutErrors.sol"; * - 1 byte for number of static size fields * - 1 byte for number of dynamic size fields * - 28 bytes for 28 static field lengths - * (MAX_DYNAMIC_FIELDS allows PackedCounter to pack the dynamic lengths into 1 word) + * (MAX_DYNAMIC_FIELDS allows EncodedLengths to pack the dynamic lengths into 1 word) */ type FieldLayout is bytes32; diff --git a/packages/store/src/IPackedCounterErrors.sol b/packages/store/src/IEncodedLengthsErrors.sol similarity index 55% rename from packages/store/src/IPackedCounterErrors.sol rename to packages/store/src/IEncodedLengthsErrors.sol index 3d92566bf5..57ff13ec53 100644 --- a/packages/store/src/IPackedCounterErrors.sol +++ b/packages/store/src/IEncodedLengthsErrors.sol @@ -2,16 +2,16 @@ pragma solidity >=0.8.24; /** - * @title IPackedCounterErrors + * @title IEncodedLengthsErrors * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz) - * @notice This interface includes errors for the PackedCounter library. + * @notice This interface includes errors for the EncodedLengths library. * @dev We bundle these errors in an interface (instead of at the file-level or in their corresponding libraries) so they can be inherited by IStore. * This ensures that all possible errors are included in the IStore ABI for proper decoding in the frontend. */ -interface IPackedCounterErrors { +interface IEncodedLengthsErrors { /** - * @notice Error raised when the provided packed counter has an invalid length. - * @param length The length of the packed coutner. + * @notice Error raised when the provided encoded lengths has an invalid length. + * @param length The length of the encoded lengths. */ - error PackedCounter_InvalidLength(uint256 length); + error EncodedLengths_InvalidLength(uint256 length); } diff --git a/packages/store/src/IStore.sol b/packages/store/src/IStore.sol index 71f7cb673f..86d820e90f 100644 --- a/packages/store/src/IStore.sol +++ b/packages/store/src/IStore.sol @@ -5,7 +5,7 @@ import { IStoreErrors } from "./IStoreErrors.sol"; import { IStoreData } from "./IStoreData.sol"; import { IStoreRegistration } from "./IStoreRegistration.sol"; import { IFieldLayoutErrors } from "./IFieldLayoutErrors.sol"; -import { IPackedCounterErrors } from "./IPackedCounterErrors.sol"; +import { IEncodedLengthsErrors } from "./IEncodedLengthsErrors.sol"; import { ISchemaErrors } from "./ISchemaErrors.sol"; import { ISliceErrors } from "./ISliceErrors.sol"; @@ -19,7 +19,7 @@ interface IStore is IStoreRegistration, IStoreErrors, IFieldLayoutErrors, - IPackedCounterErrors, + IEncodedLengthsErrors, ISchemaErrors, ISliceErrors {} diff --git a/packages/store/src/IStoreEvents.sol b/packages/store/src/IStoreEvents.sol index 489441691b..3f57393809 100644 --- a/packages/store/src/IStoreEvents.sol +++ b/packages/store/src/IStoreEvents.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.24; import { ResourceId } from "./ResourceId.sol"; -import { PackedCounter } from "./PackedCounter.sol"; +import { EncodedLengths } from "./EncodedLengths.sol"; /** * @title IStoreEvents @@ -27,7 +27,7 @@ interface IStoreEvents { ResourceId indexed tableId, bytes32[] keyTuple, bytes staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes dynamicData ); @@ -59,7 +59,7 @@ interface IStoreEvents { uint8 dynamicFieldIndex, uint48 start, uint40 deleteCount, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes data ); diff --git a/packages/store/src/IStoreHook.sol b/packages/store/src/IStoreHook.sol index e6fb034e89..81a6a16193 100644 --- a/packages/store/src/IStoreHook.sol +++ b/packages/store/src/IStoreHook.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.24; import { FieldLayout } from "./FieldLayout.sol"; import { IERC165 } from "./IERC165.sol"; -import { PackedCounter } from "./PackedCounter.sol"; +import { EncodedLengths } from "./EncodedLengths.sol"; import { ResourceId } from "./ResourceId.sol"; /** @@ -27,7 +27,7 @@ interface IStoreHook is IERC165 { ResourceId tableId, bytes32[] memory keyTuple, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData, FieldLayout fieldLayout ) external; @@ -45,7 +45,7 @@ interface IStoreHook is IERC165 { ResourceId tableId, bytes32[] memory keyTuple, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData, FieldLayout fieldLayout ) external; @@ -100,7 +100,7 @@ interface IStoreHook is IERC165 { uint8 dynamicFieldIndex, uint40 startWithinField, uint40 deleteCount, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory data ) external; @@ -122,7 +122,7 @@ interface IStoreHook is IERC165 { uint8 dynamicFieldIndex, uint40 startWithinField, uint40 deleteCount, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory data ) external; diff --git a/packages/store/src/IStoreRead.sol b/packages/store/src/IStoreRead.sol index 0237725efa..b6107c07c1 100644 --- a/packages/store/src/IStoreRead.sol +++ b/packages/store/src/IStoreRead.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.24; -import { PackedCounter } from "./PackedCounter.sol"; +import { EncodedLengths } from "./EncodedLengths.sol"; import { FieldLayout } from "./FieldLayout.sol"; import { Schema } from "./Schema.sol"; import { ResourceId } from "./ResourceId.sol"; @@ -23,7 +23,7 @@ interface IStoreRead { function getRecord( ResourceId tableId, bytes32[] calldata keyTuple - ) external view returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); + ) external view returns (bytes memory staticData, EncodedLengths encodedLengths, bytes memory dynamicData); /** * Get full record (all fields, static and dynamic data) for the given tableId and key tuple, with the given field layout @@ -32,7 +32,7 @@ interface IStoreRead { ResourceId tableId, bytes32[] calldata keyTuple, FieldLayout fieldLayout - ) external view returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); + ) external view returns (bytes memory staticData, EncodedLengths encodedLengths, bytes memory dynamicData); /** * Get a single field from the given tableId and key tuple, loading the field layout from storage diff --git a/packages/store/src/IStoreWrite.sol b/packages/store/src/IStoreWrite.sol index 90139aa6aa..8592d768da 100644 --- a/packages/store/src/IStoreWrite.sol +++ b/packages/store/src/IStoreWrite.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.24; import { IStoreEvents } from "./IStoreEvents.sol"; -import { PackedCounter } from "./PackedCounter.sol"; +import { EncodedLengths } from "./EncodedLengths.sol"; import { FieldLayout } from "./FieldLayout.sol"; import { ResourceId } from "./ResourceId.sol"; @@ -16,7 +16,7 @@ interface IStoreWrite is IStoreEvents { ResourceId tableId, bytes32[] calldata keyTuple, bytes calldata staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes calldata dynamicData ) external; diff --git a/packages/store/src/PackedCounter.sol b/packages/store/src/PackedCounter.sol deleted file mode 100644 index fba2ac07fb..0000000000 --- a/packages/store/src/PackedCounter.sol +++ /dev/null @@ -1,224 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -import { BYTE_TO_BITS } from "./constants.sol"; -import { IPackedCounterErrors } from "./IPackedCounterErrors.sol"; - -/** - * @title PackedCounter Type Definition - * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz) - * @dev Describes how the packed counter is structured. - * - 0x00-0x06 The least significant 7 bytes (uint56) represent the total byte length of dynamic (variable length) data. - * - 0x07-0xB The next five bytes (uint40) represent the length of the first dynamic field. - * - 0x0C-0x10 Followed by the length of the second dynamic field - * - 0x11-0x15 Length of the third dynamic field - * - 0x16-0x1A Length of fourth dynamic field - * - 0x1B-0x1F Length of fifth dynamic field - */ -type PackedCounter is bytes32; - -using PackedCounterInstance for PackedCounter global; - -// Constants for packed counter handling: - -// Number of bits for the 7-byte accumulator -uint256 constant ACC_BITS = 7 * BYTE_TO_BITS; -// Number of bits for the 5-byte sections -uint256 constant VAL_BITS = 5 * BYTE_TO_BITS; -// Maximum value of a 5-byte section -uint256 constant MAX_VAL = type(uint40).max; - -/** - * @title PackedCounter Library - * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz) - * @notice Static functions for handling PackedCounter type. - * @dev Provides utility functions to pack values into a PackedCounter. - * The caller must ensure that the value arguments are <= MAX_VAL. - */ -library PackedCounterLib { - /** - * @notice Packs a single value into a PackedCounter. - * @dev Encodes the given value 'a' into the structure of a PackedCounter. The packed counter's accumulator - * will be set to 'a', and the first value slot of the PackedCounter will also be set to 'a'. - * @param a The length of the first dynamic field's data. - * @return The resulting PackedCounter containing the encoded value. - */ - function pack(uint256 a) internal pure returns (PackedCounter) { - uint256 packedCounter; - unchecked { - packedCounter = a; - packedCounter |= (uint256(a) << (ACC_BITS + VAL_BITS * 0)); - } - return PackedCounter.wrap(bytes32(packedCounter)); - } - - /** - * @notice Packs two values into a PackedCounter. - * @dev Encodes the given values 'a'-'b' into the structure of a PackedCounter. - * @param a The length of the first dynamic field's data. - * @param b The length of the second dynamic field's data. - * @return The resulting PackedCounter containing the encoded values. - */ - function pack(uint256 a, uint256 b) internal pure returns (PackedCounter) { - uint256 packedCounter; - unchecked { - packedCounter = a + b; - packedCounter |= (uint256(a) << (ACC_BITS + VAL_BITS * 0)); - packedCounter |= (uint256(b) << (ACC_BITS + VAL_BITS * 1)); - } - return PackedCounter.wrap(bytes32(packedCounter)); - } - - /** - * @notice Packs three values into a PackedCounter. - * @dev Encodes the given values 'a'-'c' into the structure of a PackedCounter. - * @param a The length of the first dynamic field's data. - * @param b The length of the second dynamic field's data. - * @param c The length of the third dynamic field's data. - * @return The resulting PackedCounter containing the encoded values. - */ - function pack(uint256 a, uint256 b, uint256 c) internal pure returns (PackedCounter) { - uint256 packedCounter; - unchecked { - packedCounter = a + b + c; - packedCounter |= (uint256(a) << (ACC_BITS + VAL_BITS * 0)); - packedCounter |= (uint256(b) << (ACC_BITS + VAL_BITS * 1)); - packedCounter |= (uint256(c) << (ACC_BITS + VAL_BITS * 2)); - } - return PackedCounter.wrap(bytes32(packedCounter)); - } - - /** - * @notice Packs four values into a PackedCounter. - * @dev Encodes the given values 'a'-'d' into the structure of a PackedCounter. - * @param a The length of the first dynamic field's data. - * @param b The length of the second dynamic field's data. - * @param c The length of the third dynamic field's data. - * @param d The length of the fourth dynamic field's data. - * @return The resulting PackedCounter containing the encoded values. - */ - function pack(uint256 a, uint256 b, uint256 c, uint256 d) internal pure returns (PackedCounter) { - uint256 packedCounter; - unchecked { - packedCounter = a + b + c + d; - packedCounter |= (uint256(a) << (ACC_BITS + VAL_BITS * 0)); - packedCounter |= (uint256(b) << (ACC_BITS + VAL_BITS * 1)); - packedCounter |= (uint256(c) << (ACC_BITS + VAL_BITS * 2)); - packedCounter |= (uint256(d) << (ACC_BITS + VAL_BITS * 3)); - } - return PackedCounter.wrap(bytes32(packedCounter)); - } - - /** - * @notice Packs five values into a PackedCounter. - * @dev Encodes the given values 'a'-'e' into the structure of a PackedCounter. - * @param a The length of the first dynamic field's data. - * @param b The length of the second dynamic field's data. - * @param c The length of the third dynamic field's data. - * @param d The length of the fourth dynamic field's data. - * @param e The length of the fifth dynamic field's data. - * @return The resulting PackedCounter containing the encoded values. - */ - function pack(uint256 a, uint256 b, uint256 c, uint256 d, uint256 e) internal pure returns (PackedCounter) { - uint256 packedCounter; - unchecked { - packedCounter = a + b + c + d + e; - packedCounter |= (uint256(a) << (ACC_BITS + VAL_BITS * 0)); - packedCounter |= (uint256(b) << (ACC_BITS + VAL_BITS * 1)); - packedCounter |= (uint256(c) << (ACC_BITS + VAL_BITS * 2)); - packedCounter |= (uint256(d) << (ACC_BITS + VAL_BITS * 3)); - packedCounter |= (uint256(e) << (ACC_BITS + VAL_BITS * 4)); - } - return PackedCounter.wrap(bytes32(packedCounter)); - } -} - -/** - * @title PackedCounter Instance Library - * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz) - * @notice Instance functions for handling a PackedCounter. - * @dev Offers decoding, extracting, and setting functionalities for a PackedCounter. - */ -library PackedCounterInstance { - /** - * @notice Decode the accumulated counter from a PackedCounter. - * @dev Extracts the right-most 7 bytes of a PackedCounter. - * @param packedCounter The packed counter to decode. - * @return The accumulated value from the PackedCounter. - */ - function total(PackedCounter packedCounter) internal pure returns (uint256) { - return uint56(uint256(PackedCounter.unwrap(packedCounter))); - } - - /** - * @notice Decode the dynamic field size at a specific index from a PackedCounter. - * @dev Extracts value right-to-left, with 5 bytes per dynamic field after the right-most 7 bytes. - * @param packedCounter The packed counter to decode. - * @param index The index to retrieve. - * @return The value at the given index from the PackedCounter. - */ - function atIndex(PackedCounter packedCounter, uint8 index) internal pure returns (uint256) { - unchecked { - return uint40(uint256(PackedCounter.unwrap(packedCounter) >> (ACC_BITS + VAL_BITS * index))); - } - } - - /** - * @notice Set a counter at a specific index in a PackedCounter. - * @dev Updates a value at a specific index and updates the accumulator field. - * @param packedCounter The packed counter to modify. - * @param index The index to set. - * @param newValueAtIndex The new value to set at the given index. - * @return The modified PackedCounter. - */ - function setAtIndex( - PackedCounter packedCounter, - uint8 index, - uint256 newValueAtIndex - ) internal pure returns (PackedCounter) { - if (newValueAtIndex > MAX_VAL) { - revert IPackedCounterErrors.PackedCounter_InvalidLength(newValueAtIndex); - } - - uint256 rawPackedCounter = uint256(PackedCounter.unwrap(packedCounter)); - - // Get current lengths (total and at index) - uint256 accumulator = total(packedCounter); - uint256 currentValueAtIndex = atIndex(packedCounter, index); - - // Compute the difference and update the total value - unchecked { - if (newValueAtIndex >= currentValueAtIndex) { - accumulator += newValueAtIndex - currentValueAtIndex; - } else { - accumulator -= currentValueAtIndex - newValueAtIndex; - } - } - - // Set the new accumulated value and value at index - // (7 bytes total length, 5 bytes per dynamic field) - uint256 offset; - unchecked { - offset = ACC_BITS + VAL_BITS * index; - } - // Bitmask with 1s at the 5 bytes that form the value slot at the given index - uint256 mask = uint256(type(uint40).max) << offset; - - // First set the last 7 bytes to 0, then set them to the new length - rawPackedCounter = (rawPackedCounter & ~uint256(type(uint56).max)) | accumulator; - - // Zero out the value slot at the given index, then set the new value - rawPackedCounter = (rawPackedCounter & ~mask) | ((newValueAtIndex << offset) & mask); - - return PackedCounter.wrap(bytes32(rawPackedCounter)); - } - - /** - * @notice Unwrap a PackedCounter to its raw bytes32 representation. - * @param packedCounter The packed counter to unwrap. - * @return The raw bytes32 value of the PackedCounter. - */ - function unwrap(PackedCounter packedCounter) internal pure returns (bytes32) { - return PackedCounter.unwrap(packedCounter); - } -} diff --git a/packages/store/src/StoreCore.sol b/packages/store/src/StoreCore.sol index f8f26a1a6b..ddd38a60b1 100644 --- a/packages/store/src/StoreCore.sol +++ b/packages/store/src/StoreCore.sol @@ -7,7 +7,7 @@ import { Storage } from "./Storage.sol"; import { Memory } from "./Memory.sol"; import { FieldLayout, FieldLayoutLib } from "./FieldLayout.sol"; import { Schema, SchemaLib } from "./Schema.sol"; -import { PackedCounter } from "./PackedCounter.sol"; +import { EncodedLengths } from "./EncodedLengths.sol"; import { Slice, SliceLib } from "./Slice.sol"; import { Tables, ResourceIds, StoreHooks } from "./codegen/index.sol"; import { IStoreErrors } from "./IStoreErrors.sol"; @@ -279,7 +279,7 @@ library StoreCore { ResourceId tableId, bytes32[] memory keyTuple, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData ) internal { setRecord(tableId, keyTuple, staticData, encodedLengths, dynamicData, getFieldLayout(tableId)); @@ -302,7 +302,7 @@ library StoreCore { ResourceId tableId, bytes32[] memory keyTuple, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData, FieldLayout fieldLayout ) internal { @@ -556,7 +556,7 @@ library StoreCore { bytes memory data ) internal { // Load the previous length of the field to set from storage to compute how much data to delete - PackedCounter previousEncodedLengths = StoreCoreInternal._loadEncodedDynamicDataLength(tableId, keyTuple); + EncodedLengths previousEncodedLengths = StoreCoreInternal._loadEncodedDynamicDataLength(tableId, keyTuple); uint40 previousFieldLength = uint40(previousEncodedLengths.atIndex(dynamicFieldIndex)); StoreCoreInternal._spliceDynamicData({ @@ -651,7 +651,7 @@ library StoreCore { bytes memory dataToPush ) internal { // Load the previous length of the field to set from storage to compute where to start to push - PackedCounter previousEncodedLengths = StoreCoreInternal._loadEncodedDynamicDataLength(tableId, keyTuple); + EncodedLengths previousEncodedLengths = StoreCoreInternal._loadEncodedDynamicDataLength(tableId, keyTuple); uint40 previousFieldLength = uint40(previousEncodedLengths.atIndex(dynamicFieldIndex)); // Splice the dynamic data @@ -683,7 +683,7 @@ library StoreCore { uint256 byteLengthToPop ) internal { // Load the previous length of the field to set from storage to compute where to start to push - PackedCounter previousEncodedLengths = StoreCoreInternal._loadEncodedDynamicDataLength(tableId, keyTuple); + EncodedLengths previousEncodedLengths = StoreCoreInternal._loadEncodedDynamicDataLength(tableId, keyTuple); uint40 previousFieldLength = uint40(previousEncodedLengths.atIndex(dynamicFieldIndex)); // Splice the dynamic data @@ -717,7 +717,7 @@ library StoreCore { function getRecord( ResourceId tableId, bytes32[] memory keyTuple - ) internal view returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData) { + ) internal view returns (bytes memory staticData, EncodedLengths encodedLengths, bytes memory dynamicData) { return getRecord(tableId, keyTuple, getFieldLayout(tableId)); } @@ -734,7 +734,7 @@ library StoreCore { ResourceId tableId, bytes32[] memory keyTuple, FieldLayout fieldLayout - ) internal view returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData) { + ) internal view returns (bytes memory staticData, EncodedLengths encodedLengths, bytes memory dynamicData) { // Get the static data length uint256 staticLength = fieldLayout.staticDataLength(); @@ -926,7 +926,7 @@ library StoreCore { // Verify the accessed data is within the bounds of the dynamic field. // This is necessary because we don't delete the dynamic data when a record is deleted, // but only decrease its length. - PackedCounter encodedLengths = StoreCoreInternal._loadEncodedDynamicDataLength(tableId, keyTuple); + EncodedLengths encodedLengths = StoreCoreInternal._loadEncodedDynamicDataLength(tableId, keyTuple); uint256 fieldLength = encodedLengths.atIndex(dynamicFieldIndex); if (start >= fieldLength || end > fieldLength) { revert IStoreErrors.Store_IndexOutOfBounds(fieldLength, start >= fieldLength ? start : end - 1); @@ -983,7 +983,7 @@ library StoreCoreInternal { uint40 startWithinField, uint40 deleteCount, bytes memory data, - PackedCounter previousEncodedLengths + EncodedLengths previousEncodedLengths ) internal { // Splicing dynamic data is not supported for offchain tables, because it // requires reading the previous encoded lengths from storage @@ -1006,7 +1006,7 @@ library StoreCoreInternal { } // Update the encoded length - PackedCounter updatedEncodedLengths = previousEncodedLengths.setAtIndex(dynamicFieldIndex, updatedFieldLength); + EncodedLengths updatedEncodedLengths = previousEncodedLengths.setAtIndex(dynamicFieldIndex, updatedFieldLength); // Call onBeforeSpliceDynamicData hooks (before actually modifying the state, so observers have access to the previous state if needed) bytes21[] memory hooks = StoreHooks._get(tableId); @@ -1212,8 +1212,8 @@ library StoreCoreInternal { function _loadEncodedDynamicDataLength( ResourceId tableId, bytes32[] memory keyTuple - ) internal view returns (PackedCounter) { + ) internal view returns (EncodedLengths) { // Load dynamic data length from storage - return PackedCounter.wrap(Storage.load({ storagePointer: _getDynamicDataLengthLocation(tableId, keyTuple) })); + return EncodedLengths.wrap(Storage.load({ storagePointer: _getDynamicDataLengthLocation(tableId, keyTuple) })); } } diff --git a/packages/store/src/StoreHook.sol b/packages/store/src/StoreHook.sol index 2c8ce50d86..22f499fd86 100644 --- a/packages/store/src/StoreHook.sol +++ b/packages/store/src/StoreHook.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.24; import { IStoreHook } from "./IStoreHook.sol"; import { IERC165 } from "./IERC165.sol"; -import { PackedCounter } from "./PackedCounter.sol"; +import { EncodedLengths } from "./EncodedLengths.sol"; import { FieldLayout } from "./FieldLayout.sol"; import { ResourceId } from "./ResourceId.sol"; @@ -39,7 +39,7 @@ abstract contract StoreHook is IStoreHook { ResourceId tableId, bytes32[] memory keyTuple, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData, FieldLayout fieldLayout ) public virtual { @@ -60,7 +60,7 @@ abstract contract StoreHook is IStoreHook { ResourceId tableId, bytes32[] memory keyTuple, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData, FieldLayout fieldLayout ) public virtual { @@ -126,7 +126,7 @@ abstract contract StoreHook is IStoreHook { uint8 dynamicFieldIndex, uint40 startWithinField, uint40 deleteCount, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory data ) public virtual { revert StoreHook_NotImplemented(); @@ -151,7 +151,7 @@ abstract contract StoreHook is IStoreHook { uint8 dynamicFieldIndex, uint40 startWithinField, uint40 deleteCount, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory data ) public virtual { revert StoreHook_NotImplemented(); diff --git a/packages/store/src/StoreRead.sol b/packages/store/src/StoreRead.sol index 26e3002d20..34cfd0abe9 100644 --- a/packages/store/src/StoreRead.sol +++ b/packages/store/src/StoreRead.sol @@ -5,7 +5,7 @@ import { IStoreRead } from "./IStoreRead.sol"; import { StoreCore } from "./StoreCore.sol"; import { FieldLayout } from "./FieldLayout.sol"; import { Schema } from "./Schema.sol"; -import { PackedCounter } from "./PackedCounter.sol"; +import { EncodedLengths } from "./EncodedLengths.sol"; import { ResourceId } from "./ResourceId.sol"; /** @@ -52,7 +52,7 @@ contract StoreRead is IStoreRead { function getRecord( ResourceId tableId, bytes32[] calldata keyTuple - ) public view virtual returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData) { + ) public view virtual returns (bytes memory staticData, EncodedLengths encodedLengths, bytes memory dynamicData) { return StoreCore.getRecord(tableId, keyTuple); } @@ -69,7 +69,7 @@ contract StoreRead is IStoreRead { ResourceId tableId, bytes32[] calldata keyTuple, FieldLayout fieldLayout - ) public view virtual returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData) { + ) public view virtual returns (bytes memory staticData, EncodedLengths encodedLengths, bytes memory dynamicData) { return StoreCore.getRecord(tableId, keyTuple, fieldLayout); } diff --git a/packages/store/src/StoreSwitch.sol b/packages/store/src/StoreSwitch.sol index 28db67e062..b94d8c088f 100644 --- a/packages/store/src/StoreSwitch.sol +++ b/packages/store/src/StoreSwitch.sol @@ -2,12 +2,12 @@ pragma solidity >=0.8.24; import { IStore } from "./IStore.sol"; -import { PackedCounter } from "../src/PackedCounter.sol"; +import { EncodedLengths } from "../src/EncodedLengths.sol"; import { IStoreHook } from "./IStoreHook.sol"; import { StoreCore } from "./StoreCore.sol"; import { Schema } from "./Schema.sol"; import { FieldLayout } from "./FieldLayout.sol"; -import { PackedCounter } from "./PackedCounter.sol"; +import { EncodedLengths } from "./EncodedLengths.sol"; import { ResourceId } from "./ResourceId.sol"; /** @@ -173,7 +173,7 @@ library StoreSwitch { ResourceId tableId, bytes32[] memory keyTuple, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData ) internal { address _storeAddress = getStoreAddress(); @@ -382,7 +382,7 @@ library StoreSwitch { function getRecord( ResourceId tableId, bytes32[] memory keyTuple - ) internal view returns (bytes memory, PackedCounter, bytes memory) { + ) internal view returns (bytes memory, EncodedLengths, bytes memory) { address _storeAddress = getStoreAddress(); if (_storeAddress == address(this)) { return StoreCore.getRecord(tableId, keyTuple); @@ -404,7 +404,7 @@ library StoreSwitch { ResourceId tableId, bytes32[] memory keyTuple, FieldLayout fieldLayout - ) internal view returns (bytes memory, PackedCounter, bytes memory) { + ) internal view returns (bytes memory, EncodedLengths, bytes memory) { address _storeAddress = getStoreAddress(); if (_storeAddress == address(this)) { return StoreCore.getRecord(tableId, keyTuple, fieldLayout); diff --git a/packages/store/src/codegen/tables/Hooks.sol b/packages/store/src/codegen/tables/Hooks.sol index 0ed6108f1d..e815dd892d 100644 --- a/packages/store/src/codegen/tables/Hooks.sol +++ b/packages/store/src/codegen/tables/Hooks.sol @@ -13,7 +13,7 @@ import { SliceLib } from "../../Slice.sol"; import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; import { FieldLayout } from "../../FieldLayout.sol"; import { Schema } from "../../Schema.sol"; -import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; +import { EncodedLengths, EncodedLengthsLib } from "../../EncodedLengths.sol"; import { ResourceId } from "../../ResourceId.sol"; // Import user types @@ -408,10 +408,10 @@ library Hooks { * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). */ - function encodeLengths(bytes21[] memory hooks) internal pure returns (PackedCounter _encodedLengths) { + function encodeLengths(bytes21[] memory hooks) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack(hooks.length * 21); + _encodedLengths = EncodedLengthsLib.pack(hooks.length * 21); } } @@ -429,9 +429,9 @@ library Hooks { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(bytes21[] memory hooks) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(bytes21[] memory hooks) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(hooks); + EncodedLengths _encodedLengths = encodeLengths(hooks); bytes memory _dynamicData = encodeDynamic(hooks); return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/store/src/codegen/tables/ResourceIds.sol b/packages/store/src/codegen/tables/ResourceIds.sol index 7951d5c1e4..0caf3ecac7 100644 --- a/packages/store/src/codegen/tables/ResourceIds.sol +++ b/packages/store/src/codegen/tables/ResourceIds.sol @@ -13,7 +13,7 @@ import { SliceLib } from "../../Slice.sol"; import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; import { FieldLayout } from "../../FieldLayout.sol"; import { Schema } from "../../Schema.sol"; -import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; +import { EncodedLengths, EncodedLengthsLib } from "../../EncodedLengths.sol"; import { ResourceId } from "../../ResourceId.sol"; // Import user types @@ -181,10 +181,10 @@ library ResourceIds { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(bool exists) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(bool exists) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(exists); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/store/src/codegen/tables/StoreHooks.sol b/packages/store/src/codegen/tables/StoreHooks.sol index b87dc19fd5..c5c474768e 100644 --- a/packages/store/src/codegen/tables/StoreHooks.sol +++ b/packages/store/src/codegen/tables/StoreHooks.sol @@ -13,7 +13,7 @@ import { SliceLib } from "../../Slice.sol"; import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; import { FieldLayout } from "../../FieldLayout.sol"; import { Schema } from "../../Schema.sol"; -import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; +import { EncodedLengths, EncodedLengthsLib } from "../../EncodedLengths.sol"; import { ResourceId } from "../../ResourceId.sol"; // Import user types @@ -411,10 +411,10 @@ library StoreHooks { * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). */ - function encodeLengths(bytes21[] memory hooks) internal pure returns (PackedCounter _encodedLengths) { + function encodeLengths(bytes21[] memory hooks) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack(hooks.length * 21); + _encodedLengths = EncodedLengthsLib.pack(hooks.length * 21); } } @@ -432,9 +432,9 @@ library StoreHooks { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(bytes21[] memory hooks) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(bytes21[] memory hooks) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(hooks); + EncodedLengths _encodedLengths = encodeLengths(hooks); bytes memory _dynamicData = encodeDynamic(hooks); return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/store/src/codegen/tables/Tables.sol b/packages/store/src/codegen/tables/Tables.sol index 4c61517349..d034310006 100644 --- a/packages/store/src/codegen/tables/Tables.sol +++ b/packages/store/src/codegen/tables/Tables.sol @@ -13,7 +13,7 @@ import { SliceLib } from "../../Slice.sol"; import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; import { FieldLayout } from "../../FieldLayout.sol"; import { Schema } from "../../Schema.sol"; -import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; +import { EncodedLengths, EncodedLengthsLib } from "../../EncodedLengths.sol"; import { ResourceId } from "../../ResourceId.sol"; // Import user types @@ -534,7 +534,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = ResourceId.unwrap(tableId); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -549,7 +549,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = ResourceId.unwrap(tableId); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -570,7 +570,7 @@ library Tables { ) internal { bytes memory _staticData = encodeStatic(fieldLayout, keySchema, valueSchema); - PackedCounter _encodedLengths = encodeLengths(abiEncodedKeyNames, abiEncodedFieldNames); + EncodedLengths _encodedLengths = encodeLengths(abiEncodedKeyNames, abiEncodedFieldNames); bytes memory _dynamicData = encodeDynamic(abiEncodedKeyNames, abiEncodedFieldNames); bytes32[] memory _keyTuple = new bytes32[](1); @@ -592,7 +592,7 @@ library Tables { ) internal { bytes memory _staticData = encodeStatic(fieldLayout, keySchema, valueSchema); - PackedCounter _encodedLengths = encodeLengths(abiEncodedKeyNames, abiEncodedFieldNames); + EncodedLengths _encodedLengths = encodeLengths(abiEncodedKeyNames, abiEncodedFieldNames); bytes memory _dynamicData = encodeDynamic(abiEncodedKeyNames, abiEncodedFieldNames); bytes32[] memory _keyTuple = new bytes32[](1); @@ -607,7 +607,7 @@ library Tables { function set(ResourceId tableId, TablesData memory _table) internal { bytes memory _staticData = encodeStatic(_table.fieldLayout, _table.keySchema, _table.valueSchema); - PackedCounter _encodedLengths = encodeLengths(_table.abiEncodedKeyNames, _table.abiEncodedFieldNames); + EncodedLengths _encodedLengths = encodeLengths(_table.abiEncodedKeyNames, _table.abiEncodedFieldNames); bytes memory _dynamicData = encodeDynamic(_table.abiEncodedKeyNames, _table.abiEncodedFieldNames); bytes32[] memory _keyTuple = new bytes32[](1); @@ -622,7 +622,7 @@ library Tables { function _set(ResourceId tableId, TablesData memory _table) internal { bytes memory _staticData = encodeStatic(_table.fieldLayout, _table.keySchema, _table.valueSchema); - PackedCounter _encodedLengths = encodeLengths(_table.abiEncodedKeyNames, _table.abiEncodedFieldNames); + EncodedLengths _encodedLengths = encodeLengths(_table.abiEncodedKeyNames, _table.abiEncodedFieldNames); bytes memory _dynamicData = encodeDynamic(_table.abiEncodedKeyNames, _table.abiEncodedFieldNames); bytes32[] memory _keyTuple = new bytes32[](1); @@ -648,7 +648,7 @@ library Tables { * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ function decodeDynamic( - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _blob ) internal pure returns (bytes memory abiEncodedKeyNames, bytes memory abiEncodedFieldNames) { uint256 _start; @@ -673,7 +673,7 @@ library Tables { */ function decode( bytes memory _staticData, - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _dynamicData ) internal pure returns (TablesData memory _table) { (_table.fieldLayout, _table.keySchema, _table.valueSchema) = decodeStatic(_staticData); @@ -720,10 +720,10 @@ library Tables { function encodeLengths( bytes memory abiEncodedKeyNames, bytes memory abiEncodedFieldNames - ) internal pure returns (PackedCounter _encodedLengths) { + ) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack(bytes(abiEncodedKeyNames).length, bytes(abiEncodedFieldNames).length); + _encodedLengths = EncodedLengthsLib.pack(bytes(abiEncodedKeyNames).length, bytes(abiEncodedFieldNames).length); } } @@ -750,10 +750,10 @@ library Tables { Schema valueSchema, bytes memory abiEncodedKeyNames, bytes memory abiEncodedFieldNames - ) internal pure returns (bytes memory, PackedCounter, bytes memory) { + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(fieldLayout, keySchema, valueSchema); - PackedCounter _encodedLengths = encodeLengths(abiEncodedKeyNames, abiEncodedFieldNames); + EncodedLengths _encodedLengths = encodeLengths(abiEncodedKeyNames, abiEncodedFieldNames); bytes memory _dynamicData = encodeDynamic(abiEncodedKeyNames, abiEncodedFieldNames); return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/store/src/constants.sol b/packages/store/src/constants.sol index 87683f6a26..518dc152e0 100644 --- a/packages/store/src/constants.sol +++ b/packages/store/src/constants.sol @@ -22,7 +22,7 @@ uint256 constant MAX_TOTAL_FIELDS = 28; /// @dev Represents the maximum number of static fields in a FieldLayout. uint256 constant MAX_STATIC_FIELDS = 28; -/// @dev Represents the maximum number of dynamic fields that can be packed in a PackedCounter. +/// @dev Represents the maximum number of dynamic fields that can be packed in EncodedLengths. uint256 constant MAX_DYNAMIC_FIELDS = 5; /** diff --git a/packages/store/test/EchoSubscriber.sol b/packages/store/test/EchoSubscriber.sol index 8199d4eab6..029f9d9ccb 100644 --- a/packages/store/test/EchoSubscriber.sol +++ b/packages/store/test/EchoSubscriber.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.24; -import { PackedCounter } from "../src/PackedCounter.sol"; +import { EncodedLengths } from "../src/EncodedLengths.sol"; import { FieldLayout } from "../src/FieldLayout.sol"; import { StoreHook } from "../src/StoreHook.sol"; import { ResourceId } from "../src/ResourceId.sol"; @@ -13,7 +13,7 @@ contract EchoSubscriber is StoreHook { ResourceId tableId, bytes32[] memory keyTuple, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData, FieldLayout fieldLayout ) public override { @@ -26,7 +26,7 @@ contract EchoSubscriber is StoreHook { ResourceId tableId, bytes32[] memory keyTuple, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData, FieldLayout fieldLayout ) public override { @@ -59,7 +59,7 @@ contract EchoSubscriber is StoreHook { uint8 dynamicFieldIndex, uint40 startWithinField, uint40 deleteCount, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory data ) public override { emit HookCalled( @@ -76,7 +76,7 @@ contract EchoSubscriber is StoreHook { uint8 dynamicFieldIndex, uint40 startWithinField, uint40 deleteCount, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory data ) public override { emit HookCalled( diff --git a/packages/store/test/EncodedLengths.t.sol b/packages/store/test/EncodedLengths.t.sol new file mode 100644 index 0000000000..4cf9681e20 --- /dev/null +++ b/packages/store/test/EncodedLengths.t.sol @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.24; + +import { Test } from "forge-std/Test.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; +import { EncodedLengths, EncodedLengthsLib } from "../src/EncodedLengths.sol"; + +contract EncodedLengthsTest is Test, GasReporter { + function testPack1() public { + EncodedLengths encodedLengths = EncodedLengthsLib.pack(4); + assertEq(encodedLengths.atIndex(0), 4); + + assertEq(encodedLengths.total(), 4); + } + + function testPack2() public { + EncodedLengths encodedLengths = EncodedLengthsLib.pack(4, 8); + assertEq(encodedLengths.atIndex(0), 4); + assertEq(encodedLengths.atIndex(1), 8); + + assertEq(encodedLengths.total(), 12); + } + + function testPack3() public { + EncodedLengths encodedLengths = EncodedLengthsLib.pack(4, 8, 16); + assertEq(encodedLengths.atIndex(0), 4); + assertEq(encodedLengths.atIndex(1), 8); + assertEq(encodedLengths.atIndex(2), 16); + + assertEq(encodedLengths.total(), 28); + } + + function testPack4() public { + EncodedLengths encodedLengths = EncodedLengthsLib.pack(4, 8, 16, 32); + assertEq(encodedLengths.atIndex(0), 4); + assertEq(encodedLengths.atIndex(1), 8); + assertEq(encodedLengths.atIndex(2), 16); + assertEq(encodedLengths.atIndex(3), 32); + + assertEq(encodedLengths.total(), 60); + } + + function testPack5() public { + EncodedLengths encodedLengths = EncodedLengthsLib.pack(4, 8, 16, 32, 64); + assertEq(encodedLengths.atIndex(0), 4); + assertEq(encodedLengths.atIndex(1), 8); + assertEq(encodedLengths.atIndex(2), 16); + assertEq(encodedLengths.atIndex(3), 32); + assertEq(encodedLengths.atIndex(4), 64); + + assertEq(encodedLengths.total(), 124); + } + + function testAtIndex() public returns (uint256 value) { + EncodedLengths encodedLengths = EncodedLengthsLib.pack(1, 2, 3, 4); + + startGasReport("get value at index of EncodedLengths"); + value = encodedLengths.atIndex(3); + endGasReport(); + + assertEq(encodedLengths.atIndex(0), 1); + assertEq(encodedLengths.atIndex(1), 2); + assertEq(encodedLengths.atIndex(2), 3); + assertEq(encodedLengths.atIndex(3), 4); + } + + function testSetAtIndex() public { + EncodedLengths encodedLengths = EncodedLengthsLib.pack(1, 2, 3, 4); + + startGasReport("set value at index of EncodedLengths"); + encodedLengths = encodedLengths.setAtIndex(2, 5); + endGasReport(); + + assertEq(encodedLengths.atIndex(0), 1); + assertEq(encodedLengths.atIndex(1), 2); + assertEq(encodedLengths.atIndex(2), 5); + assertEq(encodedLengths.atIndex(3), 4); + assertEq(encodedLengths.total(), 12); + } + + function testGas() public returns (EncodedLengths encodedLengths, uint256 total) { + bytes32[] memory a1 = new bytes32[](1); + address[] memory a2 = new address[](2); + uint8[] memory a3 = new uint8[](3); + int128[] memory a4 = new int128[](4); + + startGasReport("pack 1 length into EncodedLengths"); + unchecked { + encodedLengths = EncodedLengthsLib.pack(a1.length * 32); + } + endGasReport(); + assertEq(encodedLengths.total(), 1 * 32); + + startGasReport("pack 4 lengths into EncodedLengths"); + unchecked { + encodedLengths = EncodedLengthsLib.pack(a1.length * 32, a2.length * 20, a3.length * 1, a4.length * 16); + } + endGasReport(); + + startGasReport("get total of EncodedLengths"); + total = encodedLengths.total(); + endGasReport(); + assertEq(encodedLengths.total(), 1 * 32 + 2 * 20 + 3 * 1 + 4 * 16); + } + + function testHexEncoding() public { + EncodedLengths encodedLengths = EncodedLengthsLib.pack(160, 544); + assertEq(encodedLengths.unwrap(), hex"000000000000000000000000000000000000022000000000a0000000000002c0"); + } +} diff --git a/packages/store/test/Gas.t.sol b/packages/store/test/Gas.t.sol index 32b4976cb3..9c4e33ce4a 100644 --- a/packages/store/test/Gas.t.sol +++ b/packages/store/test/Gas.t.sol @@ -6,7 +6,7 @@ import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { Bytes } from "../src/Bytes.sol"; import { SliceLib } from "../src/Slice.sol"; import { Storage } from "../src/Storage.sol"; -import { PackedCounter } from "../src/PackedCounter.sol"; +import { EncodedLengths } from "../src/EncodedLengths.sol"; import { Mixed, MixedData } from "./codegen/index.sol"; @@ -44,16 +44,16 @@ contract GasTest is Test, GasReporter { endGasReport(); startGasReport("custom encode (length)"); - PackedCounter packedCounter = Mixed.encodeLengths(mixed.a32, mixed.s); + EncodedLengths encodedLengths = Mixed.encodeLengths(mixed.a32, mixed.s); endGasReport(); - PackedCounter.unwrap(packedCounter); + EncodedLengths.unwrap(encodedLengths); startGasReport("custom encode (dynamic)"); bytes memory customEncodedDynamic = Mixed.encodeDynamic(mixed.a32, mixed.s); endGasReport(); startGasReport("custom encode"); - (bytes memory customEncodedStatic2, PackedCounter customEncodedLengths, bytes memory customEncodedDynamic2) = Mixed + (bytes memory customEncodedStatic2, EncodedLengths customEncodedLengths, bytes memory customEncodedDynamic2) = Mixed .encode(mixed.u32, mixed.u128, mixed.a32, mixed.s); endGasReport(); diff --git a/packages/store/test/MirrorSubscriber.sol b/packages/store/test/MirrorSubscriber.sol index 83f9041197..71716b39a8 100644 --- a/packages/store/test/MirrorSubscriber.sol +++ b/packages/store/test/MirrorSubscriber.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.24; import { IStore } from "../src/IStore.sol"; import { StoreHook } from "../src/StoreHook.sol"; -import { PackedCounter } from "../src/PackedCounter.sol"; +import { EncodedLengths } from "../src/EncodedLengths.sol"; import { StoreSwitch } from "../src/StoreSwitch.sol"; import { FieldLayout } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; @@ -33,7 +33,7 @@ contract MirrorSubscriber is StoreHook { ResourceId tableId, bytes32[] memory keyTuple, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData, FieldLayout ) public override { @@ -57,7 +57,7 @@ contract MirrorSubscriber is StoreHook { uint8 dynamicFieldIndex, uint40 startWithinField, uint40 deleteCount, - PackedCounter, + EncodedLengths, bytes memory data ) public override { if (ResourceId.unwrap(tableId) != _tableId) revert("invalid tableId"); diff --git a/packages/store/test/Mixed.t.sol b/packages/store/test/Mixed.t.sol index 31925d812f..2bde2811c9 100644 --- a/packages/store/test/Mixed.t.sol +++ b/packages/store/test/Mixed.t.sol @@ -7,7 +7,7 @@ import { StoreCore } from "../src/StoreCore.sol"; import { StoreMock } from "../test/StoreMock.sol"; import { FieldLayout } from "../src/FieldLayout.sol"; import { Schema, SchemaLib, SchemaType } from "../src/Schema.sol"; -import { PackedCounter } from "../src/PackedCounter.sol"; +import { EncodedLengths } from "../src/EncodedLengths.sol"; import { Mixed, MixedData } from "./codegen/index.sol"; @@ -125,7 +125,7 @@ contract MixedTest is Test, GasReporter, StoreMock { a32[1] = 4; string memory s = "some string"; - (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData) = Mixed.encode(1, 2, a32, s); + (bytes memory staticData, EncodedLengths encodedLengths, bytes memory dynamicData) = Mixed.encode(1, 2, a32, s); assertEq(staticData, hex"0000000100000000000000000000000000000002"); assertEq(encodedLengths.unwrap(), hex"000000000000000000000000000000000000000b000000000800000000000013"); assertEq(dynamicData, hex"0000000300000004736f6d6520737472696e67"); diff --git a/packages/store/test/PackedCounter.t.sol b/packages/store/test/PackedCounter.t.sol deleted file mode 100644 index 234c9258dc..0000000000 --- a/packages/store/test/PackedCounter.t.sol +++ /dev/null @@ -1,110 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; -import { PackedCounter, PackedCounterLib } from "../src/PackedCounter.sol"; - -contract PackedCounterTest is Test, GasReporter { - function testPack1() public { - PackedCounter packedCounter = PackedCounterLib.pack(4); - assertEq(packedCounter.atIndex(0), 4); - - assertEq(packedCounter.total(), 4); - } - - function testPack2() public { - PackedCounter packedCounter = PackedCounterLib.pack(4, 8); - assertEq(packedCounter.atIndex(0), 4); - assertEq(packedCounter.atIndex(1), 8); - - assertEq(packedCounter.total(), 12); - } - - function testPack3() public { - PackedCounter packedCounter = PackedCounterLib.pack(4, 8, 16); - assertEq(packedCounter.atIndex(0), 4); - assertEq(packedCounter.atIndex(1), 8); - assertEq(packedCounter.atIndex(2), 16); - - assertEq(packedCounter.total(), 28); - } - - function testPack4() public { - PackedCounter packedCounter = PackedCounterLib.pack(4, 8, 16, 32); - assertEq(packedCounter.atIndex(0), 4); - assertEq(packedCounter.atIndex(1), 8); - assertEq(packedCounter.atIndex(2), 16); - assertEq(packedCounter.atIndex(3), 32); - - assertEq(packedCounter.total(), 60); - } - - function testPack5() public { - PackedCounter packedCounter = PackedCounterLib.pack(4, 8, 16, 32, 64); - assertEq(packedCounter.atIndex(0), 4); - assertEq(packedCounter.atIndex(1), 8); - assertEq(packedCounter.atIndex(2), 16); - assertEq(packedCounter.atIndex(3), 32); - assertEq(packedCounter.atIndex(4), 64); - - assertEq(packedCounter.total(), 124); - } - - function testAtIndex() public returns (uint256 value) { - PackedCounter packedCounter = PackedCounterLib.pack(1, 2, 3, 4); - - startGasReport("get value at index of PackedCounter"); - value = packedCounter.atIndex(3); - endGasReport(); - - assertEq(packedCounter.atIndex(0), 1); - assertEq(packedCounter.atIndex(1), 2); - assertEq(packedCounter.atIndex(2), 3); - assertEq(packedCounter.atIndex(3), 4); - } - - function testSetAtIndex() public { - PackedCounter packedCounter = PackedCounterLib.pack(1, 2, 3, 4); - - startGasReport("set value at index of PackedCounter"); - packedCounter = packedCounter.setAtIndex(2, 5); - endGasReport(); - - assertEq(packedCounter.atIndex(0), 1); - assertEq(packedCounter.atIndex(1), 2); - assertEq(packedCounter.atIndex(2), 5); - assertEq(packedCounter.atIndex(3), 4); - assertEq(packedCounter.total(), 12); - } - - function testGas() public returns (PackedCounter packedCounter, uint256 total) { - bytes32[] memory a1 = new bytes32[](1); - address[] memory a2 = new address[](2); - uint8[] memory a3 = new uint8[](3); - int128[] memory a4 = new int128[](4); - - startGasReport("pack 1 length into PackedCounter"); - unchecked { - packedCounter = PackedCounterLib.pack(a1.length * 32); - } - endGasReport(); - assertEq(packedCounter.total(), 1 * 32); - - startGasReport("pack 4 lengths into PackedCounter"); - unchecked { - packedCounter = PackedCounterLib.pack(a1.length * 32, a2.length * 20, a3.length * 1, a4.length * 16); - } - endGasReport(); - - startGasReport("get total of PackedCounter"); - total = packedCounter.total(); - endGasReport(); - assertEq(packedCounter.total(), 1 * 32 + 2 * 20 + 3 * 1 + 4 * 16); - } - - function testHexEncoding() public { - PackedCounter packedCounter = PackedCounterLib.pack(160, 544); - assertEq(packedCounter.unwrap(), hex"000000000000000000000000000000000000022000000000a0000000000002c0"); - } -} diff --git a/packages/store/test/RevertSubscriber.sol b/packages/store/test/RevertSubscriber.sol index 6af33f2e0a..8bb9ab339a 100644 --- a/packages/store/test/RevertSubscriber.sol +++ b/packages/store/test/RevertSubscriber.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.24; import { StoreHook } from "../src/StoreHook.sol"; import { FieldLayout } from "../src/FieldLayout.sol"; -import { PackedCounter } from "../src/PackedCounter.sol"; +import { EncodedLengths } from "../src/EncodedLengths.sol"; import { ResourceId } from "../src/ResourceId.sol"; contract RevertSubscriber is StoreHook { @@ -11,7 +11,7 @@ contract RevertSubscriber is StoreHook { ResourceId, bytes32[] memory, bytes memory, - PackedCounter, + EncodedLengths, bytes memory, FieldLayout ) public pure override { @@ -22,7 +22,7 @@ contract RevertSubscriber is StoreHook { ResourceId, bytes32[] memory, bytes memory, - PackedCounter, + EncodedLengths, bytes memory, FieldLayout ) public pure override { @@ -43,7 +43,7 @@ contract RevertSubscriber is StoreHook { uint8, uint40, uint40, - PackedCounter, + EncodedLengths, bytes memory ) public pure override { revert("onBeforeSpliceDynamicData"); @@ -55,7 +55,7 @@ contract RevertSubscriber is StoreHook { uint8, uint40, uint40, - PackedCounter, + EncodedLengths, bytes memory ) public pure override { revert("onAfterSpliceDynamicData"); diff --git a/packages/store/test/StoreCore.t.sol b/packages/store/test/StoreCore.t.sol index a8bedac245..4d046ef8b9 100644 --- a/packages/store/test/StoreCore.t.sol +++ b/packages/store/test/StoreCore.t.sol @@ -9,7 +9,7 @@ import { SliceLib } from "../src/Slice.sol"; import { EncodeArray } from "../src/tightcoder/EncodeArray.sol"; import { FieldLayout, FieldLayoutLib } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; -import { PackedCounter, PackedCounterLib } from "../src/PackedCounter.sol"; +import { EncodedLengths, EncodedLengthsLib } from "../src/EncodedLengths.sol"; import { StoreMock } from "../test/StoreMock.sol"; import { IStoreErrors } from "../src/IStoreErrors.sol"; import { IStore } from "../src/IStore.sol"; @@ -248,7 +248,7 @@ contract StoreCoreTest is Test, StoreMock { // Set dynamic data length of dynamic index 0 setDynamicDataLengthAtIndex(tableId, keyTuple, 0, 10); - PackedCounter encodedLength = StoreCoreInternal._loadEncodedDynamicDataLength(tableId, keyTuple); + EncodedLengths encodedLength = StoreCoreInternal._loadEncodedDynamicDataLength(tableId, keyTuple); assertEq(encodedLength.atIndex(0), 10); assertEq(encodedLength.atIndex(1), 0); assertEq(encodedLength.total(), 10); @@ -292,12 +292,12 @@ contract StoreCoreTest is Test, StoreMock { // Expect a Store_SetRecord event to be emitted vm.expectEmit(true, true, true, true); - emit Store_SetRecord(tableId, keyTuple, staticData, PackedCounter.wrap(bytes32(0)), new bytes(0)); + emit Store_SetRecord(tableId, keyTuple, staticData, EncodedLengths.wrap(bytes32(0)), new bytes(0)); - IStore(this).setRecord(tableId, keyTuple, staticData, PackedCounter.wrap(bytes32(0)), new bytes(0)); + IStore(this).setRecord(tableId, keyTuple, staticData, EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Get data - (bytes memory loadedStaticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = IStore(this).getRecord( + (bytes memory loadedStaticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = IStore(this).getRecord( tableId, keyTuple, fieldLayout @@ -329,12 +329,12 @@ contract StoreCoreTest is Test, StoreMock { // Expect a Store_SetRecord event to be emitted vm.expectEmit(true, true, true, true); - emit Store_SetRecord(tableId, keyTuple, staticData, PackedCounter.wrap(bytes32(0)), new bytes(0)); + emit Store_SetRecord(tableId, keyTuple, staticData, EncodedLengths.wrap(bytes32(0)), new bytes(0)); - IStore(this).setRecord(tableId, keyTuple, staticData, PackedCounter.wrap(bytes32(0)), new bytes(0)); + IStore(this).setRecord(tableId, keyTuple, staticData, EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Get data - (bytes memory loadedStaticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = IStore(this).getRecord( + (bytes memory loadedStaticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = IStore(this).getRecord( tableId, keyTuple, fieldLayout @@ -378,9 +378,9 @@ contract StoreCoreTest is Test, StoreMock { thirdDataBytes = EncodeArray.encode(thirdData); } - PackedCounter encodedDynamicLength; + EncodedLengths encodedDynamicLength; { - encodedDynamicLength = PackedCounterLib.pack(uint40(secondDataBytes.length), uint40(thirdDataBytes.length)); + encodedDynamicLength = EncodedLengthsLib.pack(uint40(secondDataBytes.length), uint40(thirdDataBytes.length)); } // Concat data @@ -399,7 +399,7 @@ contract StoreCoreTest is Test, StoreMock { IStore(this).setRecord(tableId, keyTuple, staticData, encodedDynamicLength, dynamicData); // Get data - (bytes memory loadedStaticData, PackedCounter loadedEncodedLengths, bytes memory loadedDynamicData) = IStore(this) + (bytes memory loadedStaticData, EncodedLengths loadedEncodedLengths, bytes memory loadedDynamicData) = IStore(this) .getRecord(tableId, keyTuple, fieldLayout); assertEq(loadedStaticData, staticData); @@ -510,7 +510,7 @@ contract StoreCoreTest is Test, StoreMock { ); // Verify the full static data is correct - (bytes memory loadedStaticData, PackedCounter loadedEncodedLengths, bytes memory loadedDynamicData) = IStore(this) + (bytes memory loadedStaticData, EncodedLengths loadedEncodedLengths, bytes memory loadedDynamicData) = IStore(this) .getRecord(_data.tableId, keyTuple, _data.fieldLayout); assertEq(IStore(this).getFieldLayout(_data.tableId).staticDataLength(), 48); assertEq(IStore(this).getValueSchema(_data.tableId).staticDataLength(), 48); @@ -548,7 +548,7 @@ contract StoreCoreTest is Test, StoreMock { 0, 0, 0, - PackedCounterLib.pack(_data.thirdDataBytes.length, 0), + EncodedLengthsLib.pack(_data.thirdDataBytes.length, 0), _data.thirdDataBytes ); @@ -584,7 +584,7 @@ contract StoreCoreTest is Test, StoreMock { 1, uint48(_data.thirdDataBytes.length), 0, - PackedCounterLib.pack(_data.thirdDataBytes.length, _data.fourthDataBytes.length), + EncodedLengthsLib.pack(_data.thirdDataBytes.length, _data.fourthDataBytes.length), _data.fourthDataBytes ); @@ -599,7 +599,7 @@ contract StoreCoreTest is Test, StoreMock { assertEq(keccak256(loadedData), keccak256(_data.fourthDataBytes)); // Verify all fields are correct - PackedCounter encodedLengths = PackedCounterLib.pack( + EncodedLengths encodedLengths = EncodedLengthsLib.pack( uint40(_data.thirdDataBytes.length), uint40(_data.fourthDataBytes.length) ); @@ -630,7 +630,7 @@ contract StoreCoreTest is Test, StoreMock { 1, uint48(_data.thirdDataBytes.length), uint40(_data.fourthDataBytes.length), - PackedCounterLib.pack(_data.thirdDataBytes.length, _data.thirdDataBytes.length), + EncodedLengthsLib.pack(_data.thirdDataBytes.length, _data.thirdDataBytes.length), _data.thirdDataBytes ); @@ -678,9 +678,9 @@ contract StoreCoreTest is Test, StoreMock { thirdDataBytes = EncodeArray.encode(thirdData); } - PackedCounter encodedDynamicLength; + EncodedLengths encodedDynamicLength; { - encodedDynamicLength = PackedCounterLib.pack(uint40(secondDataBytes.length), uint40(thirdDataBytes.length)); + encodedDynamicLength = EncodedLengthsLib.pack(uint40(secondDataBytes.length), uint40(thirdDataBytes.length)); } // Concat data @@ -701,7 +701,7 @@ contract StoreCoreTest is Test, StoreMock { IStore(this).setRecord(tableId, keyTuple, staticData, encodedDynamicLength, dynamicData); // Get data - (bytes memory loadedStaticData, PackedCounter loadedEncodedLengths, bytes memory loadedDynamicData) = IStore(this) + (bytes memory loadedStaticData, EncodedLengths loadedEncodedLengths, bytes memory loadedDynamicData) = IStore(this) .getRecord(tableId, keyTuple, fieldLayout); assertEq(abi.encodePacked(loadedStaticData, loadedEncodedLengths, loadedDynamicData), data); @@ -812,7 +812,7 @@ contract StoreCoreTest is Test, StoreMock { 0, uint48(data.secondDataBytes.length), 0, - PackedCounterLib.pack(data.newSecondDataBytes.length, data.thirdDataBytes.length), + EncodedLengthsLib.pack(data.newSecondDataBytes.length, data.thirdDataBytes.length), data.secondDataToPush ); @@ -856,7 +856,7 @@ contract StoreCoreTest is Test, StoreMock { 1, uint48(data.newSecondDataBytes.length + data.thirdDataBytes.length), 0, - PackedCounterLib.pack(data.newSecondDataBytes.length, data.newThirdDataBytes.length), + EncodedLengthsLib.pack(data.newSecondDataBytes.length, data.newThirdDataBytes.length), data.thirdDataToPush ); @@ -967,7 +967,7 @@ contract StoreCoreTest is Test, StoreMock { 0, 4 * 1, 4 * 1, - PackedCounterLib.pack(data.newSecondDataBytes.length, data.thirdDataBytes.length), + EncodedLengthsLib.pack(data.newSecondDataBytes.length, data.thirdDataBytes.length), data.secondDataForUpdate ); @@ -1020,7 +1020,7 @@ contract StoreCoreTest is Test, StoreMock { 1, uint48(data.newSecondDataBytes.length + 8 * 1), 8 * 4, - PackedCounterLib.pack(data.newSecondDataBytes.length, data.newThirdDataBytes.length), + EncodedLengthsLib.pack(data.newSecondDataBytes.length, data.newThirdDataBytes.length), data.thirdDataForUpdate ); @@ -1118,7 +1118,7 @@ contract StoreCoreTest is Test, StoreMock { bytes memory staticData = abi.encodePacked(bytes16(0x0102030405060708090a0b0c0d0e0f10)); - IStore(this).setRecord(tableId, keyTuple, staticData, PackedCounter.wrap(bytes32(0)), new bytes(0)); + IStore(this).setRecord(tableId, keyTuple, staticData, EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Get data from indexed table - the indexer should have mirrored the data there (bytes memory indexedData, , ) = IStore(this).getRecord(indexerTableId, keyTuple, fieldLayout); @@ -1187,7 +1187,7 @@ contract StoreCoreTest is Test, StoreMock { bytes memory staticData = abi.encodePacked(bytes16(0x0102030405060708090a0b0c0d0e0f10)); bytes memory dynamicData = abi.encodePacked(bytes("some string")); - PackedCounter encodedLengths = PackedCounterLib.pack(dynamicData.length); + EncodedLengths encodedLengths = EncodedLengthsLib.pack(dynamicData.length); // Expect a revert when the RevertSubscriber's onBeforeSetRecord hook is called vm.expectRevert(bytes("onBeforeSetRecord")); @@ -1273,7 +1273,7 @@ contract StoreCoreTest is Test, StoreMock { struct RecordData { bytes staticData; - PackedCounter encodedLengths; + EncodedLengths encodedLengths; bytes dynamicData; } @@ -1305,7 +1305,7 @@ contract StoreCoreTest is Test, StoreMock { bytes memory arrayDataBytes = EncodeArray.encode(arrayData); RecordData memory recordData = RecordData({ staticData: abi.encodePacked(bytes16(0x0102030405060708090a0b0c0d0e0f10)), - encodedLengths: PackedCounterLib.pack(uint40(arrayDataBytes.length)), + encodedLengths: EncodedLengthsLib.pack(uint40(arrayDataBytes.length)), dynamicData: arrayDataBytes }); @@ -1374,9 +1374,9 @@ contract StoreCoreTest is Test, StoreMock { // Expect a Store_SetRecord event to be emitted vm.expectEmit(true, true, true, true); - emit Store_SetRecord(tableId, keyTuple, staticData, PackedCounter.wrap(bytes32(0)), new bytes(0)); + emit Store_SetRecord(tableId, keyTuple, staticData, EncodedLengths.wrap(bytes32(0)), new bytes(0)); - IStore(this).setRecord(tableId, keyTuple, staticData, PackedCounter.wrap(bytes32(0)), new bytes(0)); + IStore(this).setRecord(tableId, keyTuple, staticData, EncodedLengths.wrap(bytes32(0)), new bytes(0)); } function testDeleteDataOffchainTable() public { @@ -1412,9 +1412,9 @@ contract StoreCoreTest is Test, StoreMock { thirdDataBytes = EncodeArray.encode(thirdData); } - PackedCounter encodedDynamicLength; + EncodedLengths encodedDynamicLength; { - encodedDynamicLength = PackedCounterLib.pack(uint40(secondDataBytes.length), uint40(thirdDataBytes.length)); + encodedDynamicLength = EncodedLengthsLib.pack(uint40(secondDataBytes.length), uint40(thirdDataBytes.length)); } // Concat data diff --git a/packages/store/test/StoreCoreDynamic.t.sol b/packages/store/test/StoreCoreDynamic.t.sol index 79080a0b14..4b81edf1e2 100644 --- a/packages/store/test/StoreCoreDynamic.t.sol +++ b/packages/store/test/StoreCoreDynamic.t.sol @@ -7,7 +7,7 @@ import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol" import { StoreCore } from "../src/StoreCore.sol"; import { SliceLib } from "../src/Slice.sol"; import { EncodeArray } from "../src/tightcoder/EncodeArray.sol"; -import { PackedCounterLib } from "../src/PackedCounter.sol"; +import { EncodedLengthsLib } from "../src/EncodedLengths.sol"; import { FieldLayout } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; import { ResourceId, ResourceIdLib } from "../src/ResourceId.sol"; @@ -103,7 +103,7 @@ contract StoreCoreDynamicTest is Test, GasReporter, StoreMock { 0, uint48(secondDataBytes.length - byteLengthToPop), uint40(byteLengthToPop), - PackedCounterLib.pack(newDataBytes.length, thirdDataBytes.length), + EncodedLengthsLib.pack(newDataBytes.length, thirdDataBytes.length), new bytes(0) ); @@ -152,7 +152,7 @@ contract StoreCoreDynamicTest is Test, GasReporter, StoreMock { 1, uint48(secondDataBytes.length + thirdDataBytes.length - byteLengthToPop), uint40(byteLengthToPop), - PackedCounterLib.pack(secondDataBytes.length, newDataBytes.length), + EncodedLengthsLib.pack(secondDataBytes.length, newDataBytes.length), new bytes(0) ); diff --git a/packages/store/test/StoreCoreGas.t.sol b/packages/store/test/StoreCoreGas.t.sol index 8eaaa3a708..b3e4684714 100644 --- a/packages/store/test/StoreCoreGas.t.sol +++ b/packages/store/test/StoreCoreGas.t.sol @@ -10,7 +10,7 @@ import { SliceLib } from "../src/Slice.sol"; import { EncodeArray } from "../src/tightcoder/EncodeArray.sol"; import { FieldLayout } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; -import { PackedCounter, PackedCounterLib } from "../src/PackedCounter.sol"; +import { EncodedLengths, EncodedLengthsLib } from "../src/EncodedLengths.sol"; import { StoreMock } from "../test/StoreMock.sol"; import { IStoreErrors } from "../src/IStoreErrors.sol"; import { IStore } from "../src/IStore.sol"; @@ -170,7 +170,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { keyTuple[0] = keccak256("some.key"); startGasReport("set static record (1 slot)"); - StoreCore.setRecord(tableId, keyTuple, staticData, PackedCounter.wrap(bytes32(0)), dynamicData); + StoreCore.setRecord(tableId, keyTuple, staticData, EncodedLengths.wrap(bytes32(0)), dynamicData); endGasReport(); // Get data @@ -198,7 +198,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { keyTuple[0] = "some key"; startGasReport("set static record (2 slots)"); - StoreCore.setRecord(tableId, keyTuple, staticData, PackedCounter.wrap(bytes32(0)), dynamicData); + StoreCore.setRecord(tableId, keyTuple, staticData, EncodedLengths.wrap(bytes32(0)), dynamicData); endGasReport(); // Get data @@ -238,7 +238,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { thirdDataBytes = EncodeArray.encode(thirdData); } - PackedCounter encodedDynamicLength = PackedCounterLib.pack( + EncodedLengths encodedDynamicLength = EncodedLengthsLib.pack( uint40(secondDataBytes.length), uint40(thirdDataBytes.length) ); @@ -400,7 +400,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { thirdDataBytes = EncodeArray.encode(thirdData); } - PackedCounter encodedDynamicLength = PackedCounterLib.pack( + EncodedLengths encodedDynamicLength = EncodedLengthsLib.pack( uint40(secondDataBytes.length), uint40(thirdDataBytes.length) ); @@ -660,7 +660,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { bytes memory dynamicData = new bytes(0); startGasReport("set record on table with subscriber"); - StoreCore.setRecord(tableId, keyTuple, staticData, PackedCounter.wrap(bytes32(0)), dynamicData); + StoreCore.setRecord(tableId, keyTuple, staticData, EncodedLengths.wrap(bytes32(0)), dynamicData); endGasReport(); staticData = abi.encodePacked(bytes16(0x1112131415161718191a1b1c1d1e1f20)); @@ -702,7 +702,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { uint32[] memory arrayData = new uint32[](1); arrayData[0] = 0x01020304; bytes memory arrayDataBytes = EncodeArray.encode(arrayData); - PackedCounter encodedArrayDataLength = PackedCounterLib.pack(uint40(arrayDataBytes.length)); + EncodedLengths encodedArrayDataLength = EncodedLengthsLib.pack(uint40(arrayDataBytes.length)); bytes memory dynamicData = arrayDataBytes; bytes memory staticData = abi.encodePacked(bytes16(0x0102030405060708090a0b0c0d0e0f10)); bytes memory data = abi.encodePacked(staticData, encodedArrayDataLength, dynamicData); @@ -748,10 +748,10 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { // Expect a Store_SetRecord event to be emitted vm.expectEmit(true, true, true, true); - emit Store_SetRecord(tableId, keyTuple, staticData, PackedCounter.wrap(bytes32(0)), new bytes(0)); + emit Store_SetRecord(tableId, keyTuple, staticData, EncodedLengths.wrap(bytes32(0)), new bytes(0)); startGasReport("StoreCore: set record in offchain table"); - IStore(this).setRecord(tableId, keyTuple, staticData, PackedCounter.wrap(bytes32(0)), new bytes(0)); + IStore(this).setRecord(tableId, keyTuple, staticData, EncodedLengths.wrap(bytes32(0)), new bytes(0)); endGasReport(); } @@ -788,9 +788,9 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { thirdDataBytes = EncodeArray.encode(thirdData); } - PackedCounter encodedDynamicLength; + EncodedLengths encodedDynamicLength; { - encodedDynamicLength = PackedCounterLib.pack(uint40(secondDataBytes.length), uint40(thirdDataBytes.length)); + encodedDynamicLength = EncodedLengthsLib.pack(uint40(secondDataBytes.length), uint40(thirdDataBytes.length)); } // Concat data diff --git a/packages/store/test/StoreHook.t.sol b/packages/store/test/StoreHook.t.sol index 1fcca1d95e..479c45cf52 100644 --- a/packages/store/test/StoreHook.t.sol +++ b/packages/store/test/StoreHook.t.sol @@ -9,7 +9,7 @@ import { RevertSubscriber } from "./RevertSubscriber.sol"; import { Hook, HookLib } from "../src/Hook.sol"; import { IStoreHook } from "../src/IStoreHook.sol"; -import { PackedCounter } from "../src/PackedCounter.sol"; +import { EncodedLengths } from "../src/EncodedLengths.sol"; import { FieldLayout } from "../src/FieldLayout.sol"; import { ResourceId, ResourceIdLib } from "../src/ResourceId.sol"; import { RESOURCE_TABLE } from "../src/storeResourceTypes.sol"; @@ -24,7 +24,7 @@ contract StoreHookTest is Test, GasReporter { ResourceId private tableId; bytes32[] private key = new bytes32[](1); bytes private staticData = abi.encodePacked(bytes32(0)); - PackedCounter private encodedLengths = PackedCounter.wrap(bytes32(0)); + EncodedLengths private encodedLengths = EncodedLengths.wrap(bytes32(0)); bytes private dynamicData = new bytes(0); uint8 private fieldIndex = 1; FieldLayout private fieldLayout = FieldLayout.wrap(0); diff --git a/packages/store/test/StoreMock.sol b/packages/store/test/StoreMock.sol index 78785f559b..0a3ec7c60a 100644 --- a/packages/store/test/StoreMock.sol +++ b/packages/store/test/StoreMock.sol @@ -5,7 +5,7 @@ import { IStore } from "../src/IStore.sol"; import { IStoreHook } from "../src/IStoreHook.sol"; import { StoreSwitch } from "../src/StoreSwitch.sol"; import { StoreData } from "../src/StoreData.sol"; -import { PackedCounter } from "../src/PackedCounter.sol"; +import { EncodedLengths } from "../src/EncodedLengths.sol"; import { StoreCore } from "../src/StoreCore.sol"; import { Schema } from "../src/Schema.sol"; import { FieldLayout } from "../src/FieldLayout.sol"; @@ -27,7 +27,7 @@ contract StoreMock is IStore, StoreData { ResourceId tableId, bytes32[] calldata keyTuple, bytes calldata staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes calldata dynamicData ) public { StoreCore.setRecord(tableId, keyTuple, staticData, encodedLengths, dynamicData); diff --git a/packages/store/test/codegen/tables/Callbacks.sol b/packages/store/test/codegen/tables/Callbacks.sol index e2a5e14f51..07425feccf 100644 --- a/packages/store/test/codegen/tables/Callbacks.sol +++ b/packages/store/test/codegen/tables/Callbacks.sol @@ -13,7 +13,7 @@ import { SliceLib } from "../../../src/Slice.sol"; import { EncodeArray } from "../../../src/tightcoder/EncodeArray.sol"; import { FieldLayout } from "../../../src/FieldLayout.sol"; import { Schema } from "../../../src/Schema.sol"; -import { PackedCounter, PackedCounterLib } from "../../../src/PackedCounter.sol"; +import { EncodedLengths, EncodedLengthsLib } from "../../../src/EncodedLengths.sol"; import { ResourceId } from "../../../src/ResourceId.sol"; library Callbacks { @@ -408,10 +408,10 @@ library Callbacks { * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). */ - function encodeLengths(bytes24[] memory value) internal pure returns (PackedCounter _encodedLengths) { + function encodeLengths(bytes24[] memory value) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack(value.length * 24); + _encodedLengths = EncodedLengthsLib.pack(value.length * 24); } } @@ -429,9 +429,9 @@ library Callbacks { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(bytes24[] memory value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(bytes24[] memory value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(value); + EncodedLengths _encodedLengths = encodeLengths(value); bytes memory _dynamicData = encodeDynamic(value); return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/store/test/codegen/tables/KeyEncoding.sol b/packages/store/test/codegen/tables/KeyEncoding.sol index 4ee62a2c8f..649ad7f52a 100644 --- a/packages/store/test/codegen/tables/KeyEncoding.sol +++ b/packages/store/test/codegen/tables/KeyEncoding.sol @@ -13,7 +13,7 @@ import { SliceLib } from "../../../src/Slice.sol"; import { EncodeArray } from "../../../src/tightcoder/EncodeArray.sol"; import { FieldLayout } from "../../../src/FieldLayout.sol"; import { Schema } from "../../../src/Schema.sol"; -import { PackedCounter, PackedCounterLib } from "../../../src/PackedCounter.sol"; +import { EncodedLengths, EncodedLengthsLib } from "../../../src/EncodedLengths.sol"; import { ResourceId } from "../../../src/ResourceId.sol"; // Import user types @@ -264,10 +264,10 @@ library KeyEncoding { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(bool value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(bool value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/store/test/codegen/tables/Mixed.sol b/packages/store/test/codegen/tables/Mixed.sol index 524f0a3a5a..2d3116a9e4 100644 --- a/packages/store/test/codegen/tables/Mixed.sol +++ b/packages/store/test/codegen/tables/Mixed.sol @@ -13,7 +13,7 @@ import { SliceLib } from "../../../src/Slice.sol"; import { EncodeArray } from "../../../src/tightcoder/EncodeArray.sol"; import { FieldLayout } from "../../../src/FieldLayout.sol"; import { Schema } from "../../../src/Schema.sol"; -import { PackedCounter, PackedCounterLib } from "../../../src/PackedCounter.sol"; +import { EncodedLengths, EncodedLengthsLib } from "../../../src/EncodedLengths.sol"; import { ResourceId } from "../../../src/ResourceId.sol"; struct MixedData { @@ -485,7 +485,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -500,7 +500,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -514,7 +514,7 @@ library Mixed { function set(bytes32 key, uint32 u32, uint128 u128, uint32[] memory a32, string memory s) internal { bytes memory _staticData = encodeStatic(u32, u128); - PackedCounter _encodedLengths = encodeLengths(a32, s); + EncodedLengths _encodedLengths = encodeLengths(a32, s); bytes memory _dynamicData = encodeDynamic(a32, s); bytes32[] memory _keyTuple = new bytes32[](1); @@ -529,7 +529,7 @@ library Mixed { function _set(bytes32 key, uint32 u32, uint128 u128, uint32[] memory a32, string memory s) internal { bytes memory _staticData = encodeStatic(u32, u128); - PackedCounter _encodedLengths = encodeLengths(a32, s); + EncodedLengths _encodedLengths = encodeLengths(a32, s); bytes memory _dynamicData = encodeDynamic(a32, s); bytes32[] memory _keyTuple = new bytes32[](1); @@ -544,7 +544,7 @@ library Mixed { function set(bytes32 key, MixedData memory _table) internal { bytes memory _staticData = encodeStatic(_table.u32, _table.u128); - PackedCounter _encodedLengths = encodeLengths(_table.a32, _table.s); + EncodedLengths _encodedLengths = encodeLengths(_table.a32, _table.s); bytes memory _dynamicData = encodeDynamic(_table.a32, _table.s); bytes32[] memory _keyTuple = new bytes32[](1); @@ -559,7 +559,7 @@ library Mixed { function _set(bytes32 key, MixedData memory _table) internal { bytes memory _staticData = encodeStatic(_table.u32, _table.u128); - PackedCounter _encodedLengths = encodeLengths(_table.a32, _table.s); + EncodedLengths _encodedLengths = encodeLengths(_table.a32, _table.s); bytes memory _dynamicData = encodeDynamic(_table.a32, _table.s); bytes32[] memory _keyTuple = new bytes32[](1); @@ -581,7 +581,7 @@ library Mixed { * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ function decodeDynamic( - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _blob ) internal pure returns (uint32[] memory a32, string memory s) { uint256 _start; @@ -606,7 +606,7 @@ library Mixed { */ function decode( bytes memory _staticData, - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _dynamicData ) internal pure returns (MixedData memory _table) { (_table.u32, _table.u128) = decodeStatic(_staticData); @@ -646,10 +646,10 @@ library Mixed { * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). */ - function encodeLengths(uint32[] memory a32, string memory s) internal pure returns (PackedCounter _encodedLengths) { + function encodeLengths(uint32[] memory a32, string memory s) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack(a32.length * 4, bytes(s).length); + _encodedLengths = EncodedLengthsLib.pack(a32.length * 4, bytes(s).length); } } @@ -672,10 +672,10 @@ library Mixed { uint128 u128, uint32[] memory a32, string memory s - ) internal pure returns (bytes memory, PackedCounter, bytes memory) { + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(u32, u128); - PackedCounter _encodedLengths = encodeLengths(a32, s); + EncodedLengths _encodedLengths = encodeLengths(a32, s); bytes memory _dynamicData = encodeDynamic(a32, s); return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/store/test/codegen/tables/Vector2.sol b/packages/store/test/codegen/tables/Vector2.sol index 4098006708..e52a8a1585 100644 --- a/packages/store/test/codegen/tables/Vector2.sol +++ b/packages/store/test/codegen/tables/Vector2.sol @@ -13,7 +13,7 @@ import { SliceLib } from "../../../src/Slice.sol"; import { EncodeArray } from "../../../src/tightcoder/EncodeArray.sol"; import { FieldLayout } from "../../../src/FieldLayout.sol"; import { Schema } from "../../../src/Schema.sol"; -import { PackedCounter, PackedCounterLib } from "../../../src/PackedCounter.sol"; +import { EncodedLengths, EncodedLengthsLib } from "../../../src/EncodedLengths.sol"; import { ResourceId } from "../../../src/ResourceId.sol"; struct Vector2Data { @@ -157,7 +157,7 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -172,7 +172,7 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -186,7 +186,7 @@ library Vector2 { function set(bytes32 key, uint32 x, uint32 y) internal { bytes memory _staticData = encodeStatic(x, y); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -201,7 +201,7 @@ library Vector2 { function _set(bytes32 key, uint32 x, uint32 y) internal { bytes memory _staticData = encodeStatic(x, y); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -216,7 +216,7 @@ library Vector2 { function set(bytes32 key, Vector2Data memory _table) internal { bytes memory _staticData = encodeStatic(_table.x, _table.y); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -231,7 +231,7 @@ library Vector2 { function _set(bytes32 key, Vector2Data memory _table) internal { bytes memory _staticData = encodeStatic(_table.x, _table.y); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -257,7 +257,7 @@ library Vector2 { */ function decode( bytes memory _staticData, - PackedCounter, + EncodedLengths, bytes memory ) internal pure returns (Vector2Data memory _table) { (_table.x, _table.y) = decodeStatic(_staticData); @@ -297,10 +297,10 @@ library Vector2 { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint32 x, uint32 y) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint32 x, uint32 y) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(x, y); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/store/test/setDynamicDataLengthAtIndex.sol b/packages/store/test/setDynamicDataLengthAtIndex.sol index 3888fe364c..1f1de29fc8 100644 --- a/packages/store/test/setDynamicDataLengthAtIndex.sol +++ b/packages/store/test/setDynamicDataLengthAtIndex.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.24; -import { PackedCounter } from "../src/PackedCounter.sol"; +import { EncodedLengths } from "../src/EncodedLengths.sol"; import { StoreCoreInternal } from "../src/StoreCore.sol"; import { Storage } from "../src/Storage.sol"; import { ResourceId } from "../src/ResourceId.sol"; @@ -17,7 +17,7 @@ function setDynamicDataLengthAtIndex( ) { // Load dynamic data length from storage uint256 dynamicDataLengthSlot = StoreCoreInternal._getDynamicDataLengthLocation(tableId, keyTuple); - PackedCounter encodedLengths = PackedCounter.wrap(Storage.load({ storagePointer: dynamicDataLengthSlot })); + EncodedLengths encodedLengths = EncodedLengths.wrap(Storage.load({ storagePointer: dynamicDataLengthSlot })); // Update the encoded lengths encodedLengths = encodedLengths.setAtIndex(dynamicFieldIndex, newLengthAtIndex); diff --git a/packages/store/ts/codegen/record.ts b/packages/store/ts/codegen/record.ts index bd540d7068..09766b21cc 100644 --- a/packages/store/ts/codegen/record.ts +++ b/packages/store/ts/codegen/record.ts @@ -35,7 +35,7 @@ export function renderRecordMethods(options: RenderTableOptions) { ( bytes memory _staticData, - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _dynamicData ) = ${_store}.getRecord(_tableId, _keyTuple, _fieldLayout); return decode(_staticData, _encodedLengths, _dynamicData); @@ -129,7 +129,7 @@ export function renderRecordData(options: RenderTableOptions, namePrefix = "") { if (options.dynamicFields.length > 0) { result += ` - PackedCounter _encodedLengths = encodeLengths( + EncodedLengths _encodedLengths = encodeLengths( ${renderArguments(options.dynamicFields.map(({ name }) => `${namePrefix}${name}`))} ); bytes memory _dynamicData = encodeDynamic( @@ -138,7 +138,7 @@ export function renderRecordData(options: RenderTableOptions, namePrefix = "") { `; } else { result += ` - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; `; } @@ -219,7 +219,7 @@ function renderDecodeFunctions({ structName, fields, staticFields, dynamicFields /** * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ - function decodeDynamic(PackedCounter _encodedLengths, bytes memory _blob) internal pure returns (${renderArguments( + function decodeDynamic(EncodedLengths _encodedLengths, bytes memory _blob) internal pure returns (${renderArguments( dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`), )}) { ${renderList( @@ -260,7 +260,7 @@ function renderDecodeFunctions({ structName, fields, staticFields, dynamicFields */ function decode( bytes memory ${staticFields.length > 0 ? "_staticData" : ""}, - PackedCounter ${dynamicFields.length > 0 ? "_encodedLengths" : ""}, + EncodedLengths ${dynamicFields.length > 0 ? "_encodedLengths" : ""}, bytes memory ${dynamicFields.length > 0 ? "_dynamicData" : ""} ) internal pure returns (${renderedDecodedRecord}) { `; diff --git a/packages/store/ts/codegen/renderTable.ts b/packages/store/ts/codegen/renderTable.ts index 0aa30588c2..91b7036dd3 100644 --- a/packages/store/ts/codegen/renderTable.ts +++ b/packages/store/ts/codegen/renderTable.ts @@ -51,7 +51,7 @@ export function renderTable(options: RenderTableOptions) { import { EncodeArray } from "${storeImportPath}tightcoder/EncodeArray.sol"; import { FieldLayout } from "${storeImportPath}FieldLayout.sol"; import { Schema } from "${storeImportPath}Schema.sol"; - import { PackedCounter, PackedCounterLib } from "${storeImportPath}PackedCounter.sol"; + import { EncodedLengths, EncodedLengthsLib } from "${storeImportPath}EncodedLengths.sol"; import { ResourceId } from "${storeImportPath}ResourceId.sol"; ${ @@ -137,7 +137,7 @@ export function renderTable(options: RenderTableOptions) { */ function encode(${renderArguments( options.fields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`), - )}) internal pure returns (bytes memory, PackedCounter, bytes memory) { + )}) internal pure returns (bytes memory, EncodedLengths, bytes memory) { ${renderRecordData(options)} return (_staticData, _encodedLengths, _dynamicData); @@ -194,10 +194,10 @@ function renderEncodeLengths(dynamicFields: RenderDynamicField[]) { */ function encodeLengths(${renderArguments( dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`), - )}) internal pure returns (PackedCounter _encodedLengths) { + )}) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack( + _encodedLengths = EncodedLengthsLib.pack( ${renderArguments( dynamicFields.map(({ name, arrayElement }) => { if (arrayElement) { diff --git a/packages/store/ts/constants.ts b/packages/store/ts/constants.ts index 9c93949bf3..5ccd4c7067 100644 --- a/packages/store/ts/constants.ts +++ b/packages/store/ts/constants.ts @@ -12,7 +12,7 @@ export const BYTE_TO_BITS = 8; export const MAX_TOTAL_FIELDS = 28; // FieldLayout's capacity export const MAX_STATIC_FIELDS = 28; -// PackedCounter's capacity +// EncodedLengths's capacity export const MAX_DYNAMIC_FIELDS = 5; // FieldLayout and Schema have the same offsets for metadata 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 f8b2fb9b23..b67787d611 100644 --- a/packages/world-modules/src/modules/erc20-puppet/tables/Allowances.sol +++ b/packages/world-modules/src/modules/erc20-puppet/tables/Allowances.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library Allowances { @@ -186,10 +186,10 @@ library Allowances { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint256 value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint256 value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); 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 e7f034868d..30f9d1eb21 100644 --- a/packages/world-modules/src/modules/erc20-puppet/tables/ERC20Metadata.sol +++ b/packages/world-modules/src/modules/erc20-puppet/tables/ERC20Metadata.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; struct ERC20MetadataData { @@ -404,7 +404,7 @@ library ERC20Metadata { function get(ResourceId _tableId) internal view returns (ERC20MetadataData memory _table) { bytes32[] memory _keyTuple = new bytes32[](0); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -418,7 +418,7 @@ library ERC20Metadata { function _get(ResourceId _tableId) internal view returns (ERC20MetadataData memory _table) { bytes32[] memory _keyTuple = new bytes32[](0); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -432,7 +432,7 @@ library ERC20Metadata { function set(ResourceId _tableId, uint8 decimals, string memory name, string memory symbol) internal { bytes memory _staticData = encodeStatic(decimals); - PackedCounter _encodedLengths = encodeLengths(name, symbol); + EncodedLengths _encodedLengths = encodeLengths(name, symbol); bytes memory _dynamicData = encodeDynamic(name, symbol); bytes32[] memory _keyTuple = new bytes32[](0); @@ -446,7 +446,7 @@ library ERC20Metadata { function _set(ResourceId _tableId, uint8 decimals, string memory name, string memory symbol) internal { bytes memory _staticData = encodeStatic(decimals); - PackedCounter _encodedLengths = encodeLengths(name, symbol); + EncodedLengths _encodedLengths = encodeLengths(name, symbol); bytes memory _dynamicData = encodeDynamic(name, symbol); bytes32[] memory _keyTuple = new bytes32[](0); @@ -460,7 +460,7 @@ library ERC20Metadata { function set(ResourceId _tableId, ERC20MetadataData memory _table) internal { bytes memory _staticData = encodeStatic(_table.decimals); - PackedCounter _encodedLengths = encodeLengths(_table.name, _table.symbol); + EncodedLengths _encodedLengths = encodeLengths(_table.name, _table.symbol); bytes memory _dynamicData = encodeDynamic(_table.name, _table.symbol); bytes32[] memory _keyTuple = new bytes32[](0); @@ -474,7 +474,7 @@ library ERC20Metadata { function _set(ResourceId _tableId, ERC20MetadataData memory _table) internal { bytes memory _staticData = encodeStatic(_table.decimals); - PackedCounter _encodedLengths = encodeLengths(_table.name, _table.symbol); + EncodedLengths _encodedLengths = encodeLengths(_table.name, _table.symbol); bytes memory _dynamicData = encodeDynamic(_table.name, _table.symbol); bytes32[] memory _keyTuple = new bytes32[](0); @@ -493,7 +493,7 @@ library ERC20Metadata { * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ function decodeDynamic( - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _blob ) internal pure returns (string memory name, string memory symbol) { uint256 _start; @@ -518,7 +518,7 @@ library ERC20Metadata { */ function decode( bytes memory _staticData, - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _dynamicData ) internal pure returns (ERC20MetadataData memory _table) { (_table.decimals) = decodeStatic(_staticData); @@ -559,10 +559,10 @@ library ERC20Metadata { function encodeLengths( string memory name, string memory symbol - ) internal pure returns (PackedCounter _encodedLengths) { + ) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack(bytes(name).length, bytes(symbol).length); + _encodedLengths = EncodedLengthsLib.pack(bytes(name).length, bytes(symbol).length); } } @@ -584,10 +584,10 @@ library ERC20Metadata { uint8 decimals, string memory name, string memory symbol - ) internal pure returns (bytes memory, PackedCounter, bytes memory) { + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(decimals); - PackedCounter _encodedLengths = encodeLengths(name, symbol); + EncodedLengths _encodedLengths = encodeLengths(name, symbol); bytes memory _dynamicData = encodeDynamic(name, symbol); return (_staticData, _encodedLengths, _dynamicData); 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 85737c4120..421ebfd51e 100644 --- a/packages/world-modules/src/modules/erc20-puppet/tables/ERC20Registry.sol +++ b/packages/world-modules/src/modules/erc20-puppet/tables/ERC20Registry.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -178,10 +178,10 @@ library ERC20Registry { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(address tokenAddress) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(address tokenAddress) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(tokenAddress); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); 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 a633aff8ec..ee12089747 100644 --- a/packages/world-modules/src/modules/erc20-puppet/tables/TotalSupply.sol +++ b/packages/world-modules/src/modules/erc20-puppet/tables/TotalSupply.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library TotalSupply { @@ -164,10 +164,10 @@ library TotalSupply { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint256 totalSupply) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint256 totalSupply) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(totalSupply); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); 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 dd43390ec5..424f85df33 100644 --- a/packages/world-modules/src/modules/erc721-puppet/tables/ERC721Metadata.sol +++ b/packages/world-modules/src/modules/erc721-puppet/tables/ERC721Metadata.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; struct ERC721MetadataData { @@ -514,7 +514,7 @@ library ERC721Metadata { function get(ResourceId _tableId) internal view returns (ERC721MetadataData memory _table) { bytes32[] memory _keyTuple = new bytes32[](0); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -528,7 +528,7 @@ library ERC721Metadata { function _get(ResourceId _tableId) internal view returns (ERC721MetadataData memory _table) { bytes32[] memory _keyTuple = new bytes32[](0); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -541,7 +541,7 @@ library ERC721Metadata { */ function set(ResourceId _tableId, string memory name, string memory symbol, string memory baseURI) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(name, symbol, baseURI); + EncodedLengths _encodedLengths = encodeLengths(name, symbol, baseURI); bytes memory _dynamicData = encodeDynamic(name, symbol, baseURI); bytes32[] memory _keyTuple = new bytes32[](0); @@ -554,7 +554,7 @@ library ERC721Metadata { */ function _set(ResourceId _tableId, string memory name, string memory symbol, string memory baseURI) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(name, symbol, baseURI); + EncodedLengths _encodedLengths = encodeLengths(name, symbol, baseURI); bytes memory _dynamicData = encodeDynamic(name, symbol, baseURI); bytes32[] memory _keyTuple = new bytes32[](0); @@ -567,7 +567,7 @@ library ERC721Metadata { */ function set(ResourceId _tableId, ERC721MetadataData memory _table) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(_table.name, _table.symbol, _table.baseURI); + EncodedLengths _encodedLengths = encodeLengths(_table.name, _table.symbol, _table.baseURI); bytes memory _dynamicData = encodeDynamic(_table.name, _table.symbol, _table.baseURI); bytes32[] memory _keyTuple = new bytes32[](0); @@ -580,7 +580,7 @@ library ERC721Metadata { */ function _set(ResourceId _tableId, ERC721MetadataData memory _table) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(_table.name, _table.symbol, _table.baseURI); + EncodedLengths _encodedLengths = encodeLengths(_table.name, _table.symbol, _table.baseURI); bytes memory _dynamicData = encodeDynamic(_table.name, _table.symbol, _table.baseURI); bytes32[] memory _keyTuple = new bytes32[](0); @@ -592,7 +592,7 @@ library ERC721Metadata { * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ function decodeDynamic( - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _blob ) internal pure returns (string memory name, string memory symbol, string memory baseURI) { uint256 _start; @@ -623,7 +623,7 @@ library ERC721Metadata { */ function decode( bytes memory, - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _dynamicData ) internal pure returns (ERC721MetadataData memory _table) { (_table.name, _table.symbol, _table.baseURI) = decodeDynamic(_encodedLengths, _dynamicData); @@ -655,10 +655,10 @@ library ERC721Metadata { string memory name, string memory symbol, string memory baseURI - ) internal pure returns (PackedCounter _encodedLengths) { + ) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack(bytes(name).length, bytes(symbol).length, bytes(baseURI).length); + _encodedLengths = EncodedLengthsLib.pack(bytes(name).length, bytes(symbol).length, bytes(baseURI).length); } } @@ -684,9 +684,9 @@ library ERC721Metadata { string memory name, string memory symbol, string memory baseURI - ) internal pure returns (bytes memory, PackedCounter, bytes memory) { + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(name, symbol, baseURI); + EncodedLengths _encodedLengths = encodeLengths(name, symbol, baseURI); bytes memory _dynamicData = encodeDynamic(name, symbol, baseURI); return (_staticData, _encodedLengths, _dynamicData); 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 59b1a502f9..3c58d6d248 100644 --- a/packages/world-modules/src/modules/erc721-puppet/tables/ERC721Registry.sol +++ b/packages/world-modules/src/modules/erc721-puppet/tables/ERC721Registry.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -178,10 +178,10 @@ library ERC721Registry { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(address tokenAddress) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(address tokenAddress) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(tokenAddress); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); 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 561f31d6ca..8a77fc84d8 100644 --- a/packages/world-modules/src/modules/erc721-puppet/tables/OperatorApproval.sol +++ b/packages/world-modules/src/modules/erc721-puppet/tables/OperatorApproval.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library OperatorApproval { @@ -186,10 +186,10 @@ library OperatorApproval { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(bool approved) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(bool approved) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(approved); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); 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 abb43fed8c..ccb9415ae0 100644 --- a/packages/world-modules/src/modules/erc721-puppet/tables/Owners.sol +++ b/packages/world-modules/src/modules/erc721-puppet/tables/Owners.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library Owners { @@ -175,10 +175,10 @@ library Owners { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(address owner) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(address owner) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(owner); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); 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 8427e9e2ba..2d7cdefc14 100644 --- a/packages/world-modules/src/modules/erc721-puppet/tables/TokenApproval.sol +++ b/packages/world-modules/src/modules/erc721-puppet/tables/TokenApproval.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library TokenApproval { @@ -175,10 +175,10 @@ library TokenApproval { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(address account) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(address account) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(account); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); 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 def9646cfb..a02991a257 100644 --- a/packages/world-modules/src/modules/erc721-puppet/tables/TokenURI.sol +++ b/packages/world-modules/src/modules/erc721-puppet/tables/TokenURI.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library TokenURI { @@ -409,10 +409,10 @@ library TokenURI { * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). */ - function encodeLengths(string memory tokenURI) internal pure returns (PackedCounter _encodedLengths) { + function encodeLengths(string memory tokenURI) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack(bytes(tokenURI).length); + _encodedLengths = EncodedLengthsLib.pack(bytes(tokenURI).length); } } @@ -430,9 +430,9 @@ library TokenURI { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(string memory tokenURI) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(string memory tokenURI) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(tokenURI); + EncodedLengths _encodedLengths = encodeLengths(tokenURI); bytes memory _dynamicData = encodeDynamic(tokenURI); return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world-modules/src/modules/keysintable/KeysInTableHook.sol b/packages/world-modules/src/modules/keysintable/KeysInTableHook.sol index 00956d6be0..9b8a4e0709 100644 --- a/packages/world-modules/src/modules/keysintable/KeysInTableHook.sol +++ b/packages/world-modules/src/modules/keysintable/KeysInTableHook.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.24; -import { PackedCounter } from "@latticexyz/store/src/PackedCounter.sol"; +import { EncodedLengths } from "@latticexyz/store/src/EncodedLengths.sol"; import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; import { StoreHook } from "@latticexyz/store/src/StoreHook.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; @@ -46,7 +46,7 @@ contract KeysInTableHook is StoreHook { ResourceId tableId, bytes32[] memory keyTuple, bytes memory, - PackedCounter, + EncodedLengths, bytes memory, FieldLayout ) public override { @@ -68,7 +68,7 @@ contract KeysInTableHook is StoreHook { uint8, uint40, uint40, - PackedCounter, + EncodedLengths, bytes memory ) public override { handleSet(tableId, keyTuple); diff --git a/packages/world-modules/src/modules/keysintable/query.sol b/packages/world-modules/src/modules/keysintable/query.sol index a5c7f9a0be..bb720deab3 100644 --- a/packages/world-modules/src/modules/keysintable/query.sol +++ b/packages/world-modules/src/modules/keysintable/query.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.24; import { IStore } from "@latticexyz/store/src/IStore.sol"; -import { PackedCounter } from "@latticexyz/store/src/PackedCounter.sol"; +import { EncodedLengths } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; import { getKeysInTable } from "./getKeysInTable.sol"; @@ -50,7 +50,7 @@ function passesQueryFragment(bytes32[] memory keyTuple, QueryFragment memory fra return ArrayLib.includes( valuesToTuples( - getKeysWithValue(fragment.tableId, fragment.value, PackedCounter.wrap(bytes32(0)), new bytes(0)) + getKeysWithValue(fragment.tableId, fragment.value, EncodedLengths.wrap(bytes32(0)), new bytes(0)) ), keyTuple ); @@ -66,7 +66,7 @@ function passesQueryFragment(bytes32[] memory keyTuple, QueryFragment memory fra return !ArrayLib.includes( valuesToTuples( - getKeysWithValue(fragment.tableId, fragment.value, PackedCounter.wrap(bytes32(0)), new bytes(0)) + getKeysWithValue(fragment.tableId, fragment.value, EncodedLengths.wrap(bytes32(0)), new bytes(0)) ), keyTuple ); @@ -95,7 +95,7 @@ function passesQueryFragment( return ArrayLib.includes( valuesToTuples( - getKeysWithValue(store, fragment.tableId, fragment.value, PackedCounter.wrap(bytes32(0)), new bytes(0)) + getKeysWithValue(store, fragment.tableId, fragment.value, EncodedLengths.wrap(bytes32(0)), new bytes(0)) ), keyTuple ); @@ -111,7 +111,7 @@ function passesQueryFragment( return !ArrayLib.includes( valuesToTuples( - getKeysWithValue(store, fragment.tableId, fragment.value, PackedCounter.wrap(bytes32(0)), new bytes(0)) + getKeysWithValue(store, fragment.tableId, fragment.value, EncodedLengths.wrap(bytes32(0)), new bytes(0)) ), keyTuple ); @@ -135,7 +135,7 @@ function query(QueryFragment[] memory fragments) view returns (bytes32[][] memor keyTuples = fragments[0].queryType == QueryType.Has ? getKeysInTable(fragments[0].tableId) : valuesToTuples( - getKeysWithValue(fragments[0].tableId, fragments[0].value, PackedCounter.wrap(bytes32(0)), new bytes(0)) + getKeysWithValue(fragments[0].tableId, fragments[0].value, EncodedLengths.wrap(bytes32(0)), new bytes(0)) ); for (uint256 i = 1; i < fragments.length; i++) { @@ -172,7 +172,7 @@ function query(IStore store, QueryFragment[] memory fragments) view returns (byt keyTuples = fragments[0].queryType == QueryType.Has ? getKeysInTable(store, fragments[0].tableId) : valuesToTuples( - getKeysWithValue(store, fragments[0].tableId, fragments[0].value, PackedCounter.wrap(bytes32(0)), new bytes(0)) + getKeysWithValue(store, fragments[0].tableId, fragments[0].value, EncodedLengths.wrap(bytes32(0)), new bytes(0)) ); for (uint256 i = 1; i < fragments.length; i++) { diff --git a/packages/world-modules/src/modules/keysintable/tables/KeysInTable.sol b/packages/world-modules/src/modules/keysintable/tables/KeysInTable.sol index f3cc092eb6..57de2ad033 100644 --- a/packages/world-modules/src/modules/keysintable/tables/KeysInTable.sol +++ b/packages/world-modules/src/modules/keysintable/tables/KeysInTable.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -1304,7 +1304,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = ResourceId.unwrap(sourceTableId); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -1319,7 +1319,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = ResourceId.unwrap(sourceTableId); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -1334,7 +1334,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = ResourceId.unwrap(sourceTableId); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = _store.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = _store.getRecord( _tableId, _keyTuple, _fieldLayout @@ -1354,7 +1354,7 @@ library KeysInTable { bytes32[] memory keys4 ) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(keys0, keys1, keys2, keys3, keys4); + EncodedLengths _encodedLengths = encodeLengths(keys0, keys1, keys2, keys3, keys4); bytes memory _dynamicData = encodeDynamic(keys0, keys1, keys2, keys3, keys4); bytes32[] memory _keyTuple = new bytes32[](1); @@ -1375,7 +1375,7 @@ library KeysInTable { bytes32[] memory keys4 ) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(keys0, keys1, keys2, keys3, keys4); + EncodedLengths _encodedLengths = encodeLengths(keys0, keys1, keys2, keys3, keys4); bytes memory _dynamicData = encodeDynamic(keys0, keys1, keys2, keys3, keys4); bytes32[] memory _keyTuple = new bytes32[](1); @@ -1397,7 +1397,7 @@ library KeysInTable { bytes32[] memory keys4 ) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(keys0, keys1, keys2, keys3, keys4); + EncodedLengths _encodedLengths = encodeLengths(keys0, keys1, keys2, keys3, keys4); bytes memory _dynamicData = encodeDynamic(keys0, keys1, keys2, keys3, keys4); bytes32[] memory _keyTuple = new bytes32[](1); @@ -1411,7 +1411,13 @@ library KeysInTable { */ function set(ResourceId sourceTableId, KeysInTableData memory _table) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(_table.keys0, _table.keys1, _table.keys2, _table.keys3, _table.keys4); + EncodedLengths _encodedLengths = encodeLengths( + _table.keys0, + _table.keys1, + _table.keys2, + _table.keys3, + _table.keys4 + ); bytes memory _dynamicData = encodeDynamic(_table.keys0, _table.keys1, _table.keys2, _table.keys3, _table.keys4); bytes32[] memory _keyTuple = new bytes32[](1); @@ -1425,7 +1431,13 @@ library KeysInTable { */ function _set(ResourceId sourceTableId, KeysInTableData memory _table) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(_table.keys0, _table.keys1, _table.keys2, _table.keys3, _table.keys4); + EncodedLengths _encodedLengths = encodeLengths( + _table.keys0, + _table.keys1, + _table.keys2, + _table.keys3, + _table.keys4 + ); bytes memory _dynamicData = encodeDynamic(_table.keys0, _table.keys1, _table.keys2, _table.keys3, _table.keys4); bytes32[] memory _keyTuple = new bytes32[](1); @@ -1439,7 +1451,13 @@ library KeysInTable { */ function set(IStore _store, ResourceId sourceTableId, KeysInTableData memory _table) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(_table.keys0, _table.keys1, _table.keys2, _table.keys3, _table.keys4); + EncodedLengths _encodedLengths = encodeLengths( + _table.keys0, + _table.keys1, + _table.keys2, + _table.keys3, + _table.keys4 + ); bytes memory _dynamicData = encodeDynamic(_table.keys0, _table.keys1, _table.keys2, _table.keys3, _table.keys4); bytes32[] memory _keyTuple = new bytes32[](1); @@ -1452,7 +1470,7 @@ library KeysInTable { * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ function decodeDynamic( - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _blob ) internal @@ -1505,7 +1523,7 @@ library KeysInTable { */ function decode( bytes memory, - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _dynamicData ) internal pure returns (KeysInTableData memory _table) { (_table.keys0, _table.keys1, _table.keys2, _table.keys3, _table.keys4) = decodeDynamic( @@ -1554,10 +1572,10 @@ library KeysInTable { bytes32[] memory keys2, bytes32[] memory keys3, bytes32[] memory keys4 - ) internal pure returns (PackedCounter _encodedLengths) { + ) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack( + _encodedLengths = EncodedLengthsLib.pack( keys0.length * 32, keys1.length * 32, keys2.length * 32, @@ -1600,9 +1618,9 @@ library KeysInTable { bytes32[] memory keys2, bytes32[] memory keys3, bytes32[] memory keys4 - ) internal pure returns (bytes memory, PackedCounter, bytes memory) { + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(keys0, keys1, keys2, keys3, keys4); + EncodedLengths _encodedLengths = encodeLengths(keys0, keys1, keys2, keys3, keys4); bytes memory _dynamicData = encodeDynamic(keys0, keys1, keys2, keys3, keys4); return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world-modules/src/modules/keysintable/tables/UsedKeysIndex.sol b/packages/world-modules/src/modules/keysintable/tables/UsedKeysIndex.sol index 89444b0a4c..926480b14b 100644 --- a/packages/world-modules/src/modules/keysintable/tables/UsedKeysIndex.sol +++ b/packages/world-modules/src/modules/keysintable/tables/UsedKeysIndex.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -218,7 +218,7 @@ library UsedKeysIndex { _keyTuple[0] = ResourceId.unwrap(sourceTableId); _keyTuple[1] = keysHash; - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -234,7 +234,7 @@ library UsedKeysIndex { _keyTuple[0] = ResourceId.unwrap(sourceTableId); _keyTuple[1] = keysHash; - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -254,7 +254,7 @@ library UsedKeysIndex { _keyTuple[0] = ResourceId.unwrap(sourceTableId); _keyTuple[1] = keysHash; - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = _store.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = _store.getRecord( _tableId, _keyTuple, _fieldLayout @@ -268,7 +268,7 @@ library UsedKeysIndex { function set(ResourceId sourceTableId, bytes32 keysHash, bool has, uint40 index) internal { bytes memory _staticData = encodeStatic(has, index); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](2); @@ -284,7 +284,7 @@ library UsedKeysIndex { function _set(ResourceId sourceTableId, bytes32 keysHash, bool has, uint40 index) internal { bytes memory _staticData = encodeStatic(has, index); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](2); @@ -300,7 +300,7 @@ library UsedKeysIndex { function set(IStore _store, ResourceId sourceTableId, bytes32 keysHash, bool has, uint40 index) internal { bytes memory _staticData = encodeStatic(has, index); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](2); @@ -327,7 +327,7 @@ library UsedKeysIndex { */ function decode( bytes memory _staticData, - PackedCounter, + EncodedLengths, bytes memory ) internal pure returns (bool has, uint40 index) { (has, index) = decodeStatic(_staticData); @@ -380,10 +380,10 @@ library UsedKeysIndex { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(bool has, uint40 index) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(bool has, uint40 index) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(has, index); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world-modules/src/modules/keyswithvalue/KeysWithValueHook.sol b/packages/world-modules/src/modules/keyswithvalue/KeysWithValueHook.sol index acf30a05e1..fa2e1592af 100644 --- a/packages/world-modules/src/modules/keyswithvalue/KeysWithValueHook.sol +++ b/packages/world-modules/src/modules/keyswithvalue/KeysWithValueHook.sol @@ -5,7 +5,7 @@ import { StoreHook } from "@latticexyz/store/src/StoreHook.sol"; import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; -import { PackedCounter } from "@latticexyz/store/src/PackedCounter.sol"; +import { EncodedLengths } from "@latticexyz/store/src/EncodedLengths.sol"; import { Tables } from "@latticexyz/store/src/codegen/tables/Tables.sol"; import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol"; @@ -35,7 +35,7 @@ contract KeysWithValueHook is StoreHook { ResourceId sourceTableId, bytes32[] memory keyTuple, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData, FieldLayout fieldLayout ) public override { @@ -89,7 +89,7 @@ contract KeysWithValueHook is StoreHook { uint8, uint40, uint40, - PackedCounter, + EncodedLengths, bytes memory ) public override { // Remove the key from the list of keys with the previous value @@ -105,7 +105,7 @@ contract KeysWithValueHook is StoreHook { uint8, uint40, uint40, - PackedCounter, + EncodedLengths, bytes memory ) public override { // Add the key to the list of keys with the new value @@ -131,7 +131,7 @@ contract KeysWithValueHook is StoreHook { bytes32[] memory keyTuple, FieldLayout fieldLayout ) internal view returns (bytes32 valueHash) { - (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData) = _world().getRecord( + (bytes memory staticData, EncodedLengths encodedLengths, bytes memory dynamicData) = _world().getRecord( sourceTableId, keyTuple, fieldLayout diff --git a/packages/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol b/packages/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol index d1221942e0..01a58758de 100644 --- a/packages/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol +++ b/packages/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.24; import { IStore } from "@latticexyz/store/src/IStore.sol"; -import { PackedCounter } from "@latticexyz/store/src/PackedCounter.sol"; +import { EncodedLengths } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; import { MODULE_NAMESPACE } from "./constants.sol"; @@ -18,7 +18,7 @@ import { getTargetTableId } from "./getTargetTableId.sol"; function getKeysWithValue( ResourceId tableId, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData ) view returns (bytes32[] memory keysWithValue) { // Get the corresponding reverse mapping table @@ -41,7 +41,7 @@ function getKeysWithValue( IStore store, ResourceId tableId, bytes memory staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes memory dynamicData ) view returns (bytes32[] memory keysWithValue) { // Get the corresponding reverse mapping table diff --git a/packages/world-modules/src/modules/keyswithvalue/tables/KeysWithValue.sol b/packages/world-modules/src/modules/keyswithvalue/tables/KeysWithValue.sol index d6209086ce..1e044c7a04 100644 --- a/packages/world-modules/src/modules/keyswithvalue/tables/KeysWithValue.sol +++ b/packages/world-modules/src/modules/keyswithvalue/tables/KeysWithValue.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library KeysWithValue { @@ -627,10 +627,10 @@ library KeysWithValue { * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). */ - function encodeLengths(bytes32[] memory keysWithValue) internal pure returns (PackedCounter _encodedLengths) { + function encodeLengths(bytes32[] memory keysWithValue) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack(keysWithValue.length * 32); + _encodedLengths = EncodedLengthsLib.pack(keysWithValue.length * 32); } } @@ -648,9 +648,9 @@ library KeysWithValue { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(bytes32[] memory keysWithValue) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(bytes32[] memory keysWithValue) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(keysWithValue); + EncodedLengths _encodedLengths = encodeLengths(keysWithValue); bytes memory _dynamicData = encodeDynamic(keysWithValue); return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world-modules/src/modules/puppet/tables/PuppetRegistry.sol b/packages/world-modules/src/modules/puppet/tables/PuppetRegistry.sol index ef08642e3a..a5beb86c42 100644 --- a/packages/world-modules/src/modules/puppet/tables/PuppetRegistry.sol +++ b/packages/world-modules/src/modules/puppet/tables/PuppetRegistry.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -178,10 +178,10 @@ library PuppetRegistry { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(address puppet) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(address puppet) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(puppet); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); 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 73f3f5a65b..3c6f7e6dbd 100644 --- a/packages/world-modules/src/modules/std-delegations/tables/CallboundDelegations.sol +++ b/packages/world-modules/src/modules/std-delegations/tables/CallboundDelegations.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -258,10 +258,10 @@ library CallboundDelegations { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint256 availableCalls) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint256 availableCalls) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(availableCalls); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); 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 c0d3d130c3..d2ad04d72e 100644 --- a/packages/world-modules/src/modules/std-delegations/tables/SystemboundDelegations.sol +++ b/packages/world-modules/src/modules/std-delegations/tables/SystemboundDelegations.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -229,10 +229,10 @@ library SystemboundDelegations { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint256 availableCalls) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint256 availableCalls) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(availableCalls); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); 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 8cc669aaa6..dcac86e288 100644 --- a/packages/world-modules/src/modules/std-delegations/tables/TimeboundDelegations.sol +++ b/packages/world-modules/src/modules/std-delegations/tables/TimeboundDelegations.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library TimeboundDelegations { @@ -189,10 +189,10 @@ library TimeboundDelegations { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint256 maxTimestamp) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint256 maxTimestamp) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(maxTimestamp); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world-modules/src/modules/tokens/tables/Balances.sol b/packages/world-modules/src/modules/tokens/tables/Balances.sol index bf4005967f..03bf11aba0 100644 --- a/packages/world-modules/src/modules/tokens/tables/Balances.sol +++ b/packages/world-modules/src/modules/tokens/tables/Balances.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library Balances { @@ -175,10 +175,10 @@ library Balances { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint256 value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint256 value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world-modules/src/modules/uniqueentity/tables/UniqueEntity.sol b/packages/world-modules/src/modules/uniqueentity/tables/UniqueEntity.sol index 9d5a77ff8d..3d6ab6eb19 100644 --- a/packages/world-modules/src/modules/uniqueentity/tables/UniqueEntity.sol +++ b/packages/world-modules/src/modules/uniqueentity/tables/UniqueEntity.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library UniqueEntity { @@ -218,10 +218,10 @@ library UniqueEntity { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint256 value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint256 value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world-modules/test/KeysInTableModule.t.sol b/packages/world-modules/test/KeysInTableModule.t.sol index 51c7da710c..56426d2313 100644 --- a/packages/world-modules/test/KeysInTableModule.t.sol +++ b/packages/world-modules/test/KeysInTableModule.t.sol @@ -7,7 +7,7 @@ import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { FieldLayoutEncodeHelper } from "@latticexyz/store/test/FieldLayoutEncodeHelper.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; -import { PackedCounter } from "@latticexyz/store/src/PackedCounter.sol"; +import { EncodedLengths } from "@latticexyz/store/src/EncodedLengths.sol"; import { SchemaEncodeHelper } from "@latticexyz/store/test/SchemaEncodeHelper.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; @@ -109,7 +109,7 @@ contract KeysInTableModuleTest is Test, GasReporter { bytes32[] memory keyTuple = new bytes32[](0); - world.setRecord(singletonTableId, keyTuple, abi.encodePacked(val1), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(singletonTableId, keyTuple, abi.encodePacked(val1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Get the list of keys in this target table bytes32[][] memory keysInTable = getKeysInTable(world, singletonTableId); @@ -126,7 +126,7 @@ contract KeysInTableModuleTest is Test, GasReporter { keyTuple[1] = "two"; keyTuple[2] = "three"; - world.setRecord(compositeTableId, keyTuple, abi.encodePacked(val1), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(compositeTableId, keyTuple, abi.encodePacked(val1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Get the list of keys in this target table bytes32[][] memory keysInTable = getKeysInTable(world, compositeTableId); @@ -151,7 +151,7 @@ contract KeysInTableModuleTest is Test, GasReporter { _installKeysInTableModule(); // Set a value in the source table startGasReport("set a record on a table with keysInTableModule installed"); - world.setRecord(tableId, keyTuple1, abi.encodePacked(value), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(tableId, keyTuple1, abi.encodePacked(value), EncodedLengths.wrap(bytes32(0)), new bytes(0)); endGasReport(); // Get the list of keys in this target table @@ -176,7 +176,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Set a value in the source table startGasReport("set a record on a table with keysInTableModule installed (first)"); - world.setRecord(tableId, keyTuple, abi.encodePacked(value1), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(tableId, keyTuple, abi.encodePacked(value1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); endGasReport(); // Get the list of keys in the first target table @@ -208,7 +208,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Set a value in the source table startGasReport("set a record on a table with keysInTableModule installed (second)"); - world.setRecord(sourceTableId2, keyTuple, abi.encodePacked(value2), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(sourceTableId2, keyTuple, abi.encodePacked(value2), EncodedLengths.wrap(bytes32(0)), new bytes(0)); endGasReport(); // Get the list of keys in the second target table @@ -228,7 +228,7 @@ contract KeysInTableModuleTest is Test, GasReporter { _installKeysInTableModule(); // Set a value in the source table - world.setRecord(tableId, keyTuple1, abi.encodePacked(value1), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(tableId, keyTuple1, abi.encodePacked(value1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Get the list of keys in the target table bytes32[][] memory keysInTable = getKeysInTable(world, tableId); @@ -238,7 +238,7 @@ contract KeysInTableModuleTest is Test, GasReporter { assertEq(keysInTable[0][0], key1, "2"); // Set another key with the same value - world.setRecord(tableId, keyTuple2, abi.encodePacked(value1), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(tableId, keyTuple2, abi.encodePacked(value1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Get the list of keys in the target table keysInTable = getKeysInTable(world, tableId); @@ -250,7 +250,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Change the value of the first key startGasReport("change a record on a table with keysInTableModule installed"); - world.setRecord(tableId, keyTuple1, abi.encodePacked(value2), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(tableId, keyTuple1, abi.encodePacked(value2), EncodedLengths.wrap(bytes32(0)), new bytes(0)); endGasReport(); // Get the list of keys in the target table @@ -297,7 +297,7 @@ contract KeysInTableModuleTest is Test, GasReporter { compositeTableId, keyTupleA, abi.encodePacked(value1), - PackedCounter.wrap(bytes32(0)), + EncodedLengths.wrap(bytes32(0)), new bytes(0) ); @@ -315,7 +315,7 @@ contract KeysInTableModuleTest is Test, GasReporter { compositeTableId, keyTupleB, abi.encodePacked(value1), - PackedCounter.wrap(bytes32(0)), + EncodedLengths.wrap(bytes32(0)), new bytes(0) ); @@ -337,7 +337,7 @@ contract KeysInTableModuleTest is Test, GasReporter { compositeTableId, keyTupleA, abi.encodePacked(value2), - PackedCounter.wrap(bytes32(0)), + EncodedLengths.wrap(bytes32(0)), new bytes(0) ); endGasReport(); @@ -401,7 +401,7 @@ contract KeysInTableModuleTest is Test, GasReporter { _installKeysInTableModule(); // Set a value in the source table - world.setRecord(tableId, keyTuple1, abi.encodePacked(value1), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(tableId, keyTuple1, abi.encodePacked(value1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); startGasReport("Get list of keys in a given table"); bytes32[][] memory keysInTable = getKeysInTable(world, tableId); @@ -412,7 +412,7 @@ contract KeysInTableModuleTest is Test, GasReporter { assertEq(keysInTable[0][0], key1); // Set another key with a different value - world.setRecord(tableId, keyTuple2, abi.encodePacked(value2), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(tableId, keyTuple2, abi.encodePacked(value2), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Get the list of keys in the target table keysInTable = getKeysInTable(world, tableId); @@ -427,9 +427,9 @@ contract KeysInTableModuleTest is Test, GasReporter { _installKeysInTableModule(); // Add 3 values - world.setRecord(tableId, keyTuple1, abi.encodePacked(value), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(tableId, keyTuple2, abi.encodePacked(value), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(tableId, keyTuple3, abi.encodePacked(value), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(tableId, keyTuple1, abi.encodePacked(value), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(tableId, keyTuple2, abi.encodePacked(value), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(tableId, keyTuple3, abi.encodePacked(value), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Remove 2, starting from the middle // This tests that KeysInTable correctly tracks swaps indexes diff --git a/packages/world-modules/test/KeysWithValueModule.t.sol b/packages/world-modules/test/KeysWithValueModule.t.sol index ce4a1ae38e..7cf5f63d93 100644 --- a/packages/world-modules/test/KeysWithValueModule.t.sol +++ b/packages/world-modules/test/KeysWithValueModule.t.sol @@ -8,7 +8,7 @@ import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol" import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { Schema } from "@latticexyz/store/src/Schema.sol"; -import { PackedCounter } from "@latticexyz/store/src/PackedCounter.sol"; +import { EncodedLengths } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; import { SchemaEncodeHelper } from "@latticexyz/store/test/SchemaEncodeHelper.sol"; import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; @@ -93,7 +93,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { uint256 value = 1; startGasReport("set a record on a table with KeysWithValueModule installed"); - world.setRecord(sourceTableId, keyTuple1, abi.encodePacked(value), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(sourceTableId, keyTuple1, abi.encodePacked(value), EncodedLengths.wrap(bytes32(0)), new bytes(0)); endGasReport(); // Get the list of entities with this value from the target table @@ -126,7 +126,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { // Set a value in the source table uint256 value1 = 1; - world.setRecord(sourceTableId, keyTuple1, abi.encodePacked(value1), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(sourceTableId, keyTuple1, abi.encodePacked(value1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Get the list of entities with value1 from the target table bytes32[] memory keysWithValue = KeysWithValue.get(targetTableId, keccak256(abi.encodePacked(value1))); @@ -136,7 +136,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { assertEq(keysWithValue[0], key1, "2"); // Set a another key with the same value - world.setRecord(sourceTableId, keyTuple2, abi.encodePacked(value1), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(sourceTableId, keyTuple2, abi.encodePacked(value1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Get the list of entities with value2 from the target table keysWithValue = KeysWithValue.get(targetTableId, keccak256(abi.encodePacked(value1))); @@ -150,7 +150,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { uint256 value2 = 2; startGasReport("change a record on a table with KeysWithValueModule installed"); - world.setRecord(sourceTableId, keyTuple1, abi.encodePacked(value2), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(sourceTableId, keyTuple1, abi.encodePacked(value2), EncodedLengths.wrap(bytes32(0)), new bytes(0)); endGasReport(); // Get the list of entities with value1 from the target table @@ -252,14 +252,14 @@ contract KeysWithValueModuleTest is Test, GasReporter { _installKeysWithValueModule(); // Set a value in the source table - world.setRecord(sourceTableId, keyTuple1, abi.encodePacked(value), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(sourceTableId, keyTuple1, abi.encodePacked(value), EncodedLengths.wrap(bytes32(0)), new bytes(0)); startGasReport("Get list of keys with a given value"); bytes32[] memory keysWithValue = getKeysWithValue( world, sourceTableId, abi.encodePacked(value), - PackedCounter.wrap(bytes32(0)), + EncodedLengths.wrap(bytes32(0)), new bytes(0) ); endGasReport(); @@ -269,14 +269,14 @@ contract KeysWithValueModuleTest is Test, GasReporter { assertEq(keysWithValue[0], key1); // Set a another key with the same value - world.setRecord(sourceTableId, keyTuple2, abi.encodePacked(value), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(sourceTableId, keyTuple2, abi.encodePacked(value), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Get the list of keys with value from the target table keysWithValue = getKeysWithValue( world, sourceTableId, abi.encodePacked(value), - PackedCounter.wrap(bytes32(0)), + EncodedLengths.wrap(bytes32(0)), new bytes(0) ); diff --git a/packages/world-modules/test/query.t.sol b/packages/world-modules/test/query.t.sol index 5571f10f47..efd1792cd3 100644 --- a/packages/world-modules/test/query.t.sol +++ b/packages/world-modules/test/query.t.sol @@ -8,7 +8,7 @@ import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; import { FieldLayoutEncodeHelper } from "@latticexyz/store/test/FieldLayoutEncodeHelper.sol"; import { Schema } from "@latticexyz/store/src/Schema.sol"; import { SchemaEncodeHelper } from "@latticexyz/store/test/SchemaEncodeHelper.sol"; -import { PackedCounter } from "@latticexyz/store/src/PackedCounter.sol"; +import { EncodedLengths } from "@latticexyz/store/src/EncodedLengths.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; import { World } from "@latticexyz/world/src/World.sol"; @@ -91,9 +91,9 @@ contract QueryTest is Test, GasReporter { function testHasQuery() public { _installKeysInTableModule(); - world.setRecord(table1, key1, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table1, key2, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key1, abi.encode(0), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key1, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key2, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key1, abi.encode(0), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Query should return all keys in table1 QueryFragment[] memory fragments = new QueryFragment[](1); @@ -112,9 +112,9 @@ contract QueryTest is Test, GasReporter { _installKeysInTableModule(); _installKeysWithValueModule(); - world.setRecord(table1, key1, abi.encode(2), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table1, key2, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table1, key3, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key1, abi.encode(2), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key2, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key3, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Query should return all keys in table1 with value 1 QueryFragment[] memory fragments = new QueryFragment[](1); fragments[0] = QueryFragment(QueryType.HasValue, table1, abi.encode(1)); @@ -130,12 +130,12 @@ contract QueryTest is Test, GasReporter { function testCombinedHasQuery() public { _installKeysInTableModule(); - world.setRecord(table1, key1, abi.encode(2), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table1, key2, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table1, key3, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key2, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key3, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table3, key1, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key1, abi.encode(2), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key2, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key3, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key2, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key3, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table3, key1, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Query should return all entities that have table1 and table2 QueryFragment[] memory fragments = new QueryFragment[](2); @@ -154,12 +154,12 @@ contract QueryTest is Test, GasReporter { _installKeysInTableModule(); _installKeysWithValueModule(); - world.setRecord(table1, key1, abi.encode(2), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table1, key2, abi.encode(2), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table1, key3, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key2, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key3, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table3, key1, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key1, abi.encode(2), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key2, abi.encode(2), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key3, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key2, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key3, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table3, key1, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Query should return all entities that have table1 and table2 QueryFragment[] memory fragments = new QueryFragment[](2); @@ -177,13 +177,13 @@ contract QueryTest is Test, GasReporter { _installKeysInTableModule(); _installKeysWithValueModule(); - world.setRecord(table1, key1, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table1, key2, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table1, key3, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key1, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key2, abi.encode(2), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key3, abi.encode(2), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key4, abi.encode(2), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key1, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key2, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key3, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key1, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key2, abi.encode(2), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key3, abi.encode(2), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key4, abi.encode(2), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Query should return all entities that have table1 and table2 QueryFragment[] memory fragments = new QueryFragment[](2); @@ -201,13 +201,13 @@ contract QueryTest is Test, GasReporter { function testCombinedHasNotQuery() public { _installKeysInTableModule(); - world.setRecord(table1, key1, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table1, key2, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table1, key3, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key1, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key2, abi.encode(2), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key3, abi.encode(2), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key4, abi.encode(2), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key1, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key2, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key3, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key1, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key2, abi.encode(2), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key3, abi.encode(2), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key4, abi.encode(2), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Query should return all entities that have table1 and table2 QueryFragment[] memory fragments = new QueryFragment[](2); @@ -225,13 +225,13 @@ contract QueryTest is Test, GasReporter { _installKeysInTableModule(); _installKeysWithValueModule(); - world.setRecord(table1, key1, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table1, key2, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table1, key3, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key1, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key2, abi.encode(2), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key3, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key4, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key1, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key2, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key3, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key1, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key2, abi.encode(2), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key3, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key4, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Query should return all entities that have table1 and table2 QueryFragment[] memory fragments = new QueryFragment[](2); @@ -249,16 +249,16 @@ contract QueryTest is Test, GasReporter { _installKeysInTableModule(); _installKeysWithValueModule(); - world.setRecord(table1, key1, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table1, key2, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table1, key3, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key1, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key2, abi.encode(2), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key3, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table2, key4, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table3, key2, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table3, key3, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table3, key4, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key1, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key2, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key3, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key1, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key2, abi.encode(2), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key3, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key4, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table3, key2, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table3, key3, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table3, key4, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Query should return all entities that have table2 and not table1 QueryFragment[] memory fragments = new QueryFragment[](3); @@ -277,9 +277,9 @@ contract QueryTest is Test, GasReporter { _installKeysInTableModule(); _installKeysWithValueModule(); - world.setRecord(table1, key1, abi.encode(4), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table1, key2, abi.encode(5), PackedCounter.wrap(bytes32(0)), new bytes(0)); - world.setRecord(table1, key3, abi.encode(6), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key1, abi.encode(4), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key2, abi.encode(5), EncodedLengths.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, key3, abi.encode(6), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Query should return all entities with table1 except value 6 QueryFragment[] memory fragments = new QueryFragment[](2); @@ -300,9 +300,9 @@ contract QueryTest is Test, GasReporter { for (uint256 i; i < 100; i++) { bytes32[] memory keyTuple = new bytes32[](1); keyTuple[0] = bytes32(i); - world.setRecord(table1, keyTuple, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, keyTuple, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); } - world.setRecord(table2, key1, abi.encode(0), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key1, abi.encode(0), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Query should return all keys in table1 QueryFragment[] memory fragments = new QueryFragment[](1); @@ -321,9 +321,9 @@ contract QueryTest is Test, GasReporter { for (uint256 i; i < 1000; i++) { bytes32[] memory keyTuple = new bytes32[](1); keyTuple[0] = bytes32(i); - world.setRecord(table1, keyTuple, abi.encode(1), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table1, keyTuple, abi.encode(1), EncodedLengths.wrap(bytes32(0)), new bytes(0)); } - world.setRecord(table2, key1, abi.encode(0), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(table2, key1, abi.encode(0), EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Query should return all keys in table1 QueryFragment[] memory fragments = new QueryFragment[](1); diff --git a/packages/world/src/World.sol b/packages/world/src/World.sol index 7f9508a958..fad51c61dc 100644 --- a/packages/world/src/World.sol +++ b/packages/world/src/World.sol @@ -4,7 +4,7 @@ pragma solidity >=0.8.24; import { StoreData } from "@latticexyz/store/src/StoreData.sol"; import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; import { Bytes } from "@latticexyz/store/src/Bytes.sol"; -import { PackedCounter } from "@latticexyz/store/src/PackedCounter.sol"; +import { EncodedLengths } from "@latticexyz/store/src/EncodedLengths.sol"; import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; import { WORLD_VERSION } from "./version.sol"; @@ -136,7 +136,7 @@ contract World is StoreData, IWorldKernel { ResourceId tableId, bytes32[] calldata keyTuple, bytes calldata staticData, - PackedCounter encodedLengths, + EncodedLengths encodedLengths, bytes calldata dynamicData ) public virtual prohibitDirectCallback { // Require access to the namespace or name diff --git a/packages/world/src/codegen/tables/Balances.sol b/packages/world/src/codegen/tables/Balances.sol index 26291f56b3..f4dca1d9ee 100644 --- a/packages/world/src/codegen/tables/Balances.sol +++ b/packages/world/src/codegen/tables/Balances.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -181,10 +181,10 @@ library Balances { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint256 balance) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint256 balance) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(balance); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world/src/codegen/tables/FunctionSelectors.sol b/packages/world/src/codegen/tables/FunctionSelectors.sol index 6c17846b5b..9f7f1d6e22 100644 --- a/packages/world/src/codegen/tables/FunctionSelectors.sol +++ b/packages/world/src/codegen/tables/FunctionSelectors.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -161,7 +161,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(worldFunctionSelector); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -178,7 +178,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(worldFunctionSelector); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -192,7 +192,7 @@ library FunctionSelectors { function set(bytes4 worldFunctionSelector, ResourceId systemId, bytes4 systemFunctionSelector) internal { bytes memory _staticData = encodeStatic(systemId, systemFunctionSelector); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -207,7 +207,7 @@ library FunctionSelectors { function _set(bytes4 worldFunctionSelector, ResourceId systemId, bytes4 systemFunctionSelector) internal { bytes memory _staticData = encodeStatic(systemId, systemFunctionSelector); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -233,7 +233,7 @@ library FunctionSelectors { */ function decode( bytes memory _staticData, - PackedCounter, + EncodedLengths, bytes memory ) internal pure returns (ResourceId systemId, bytes4 systemFunctionSelector) { (systemId, systemFunctionSelector) = decodeStatic(_staticData); @@ -276,10 +276,10 @@ library FunctionSelectors { function encode( ResourceId systemId, bytes4 systemFunctionSelector - ) internal pure returns (bytes memory, PackedCounter, bytes memory) { + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(systemId, systemFunctionSelector); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world/src/codegen/tables/FunctionSignatures.sol b/packages/world/src/codegen/tables/FunctionSignatures.sol index d2a4611869..cd682b8068 100644 --- a/packages/world/src/codegen/tables/FunctionSignatures.sol +++ b/packages/world/src/codegen/tables/FunctionSignatures.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library FunctionSignatures { @@ -65,7 +65,7 @@ library FunctionSignatures { */ function set(bytes4 functionSelector, string memory functionSignature) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(functionSignature); + EncodedLengths _encodedLengths = encodeLengths(functionSignature); bytes memory _dynamicData = encodeDynamic(functionSignature); bytes32[] memory _keyTuple = new bytes32[](1); @@ -79,7 +79,7 @@ library FunctionSignatures { */ function _set(bytes4 functionSelector, string memory functionSignature) internal { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(functionSignature); + EncodedLengths _encodedLengths = encodeLengths(functionSignature); bytes memory _dynamicData = encodeDynamic(functionSignature); bytes32[] memory _keyTuple = new bytes32[](1); @@ -92,7 +92,7 @@ library FunctionSignatures { * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ function decodeDynamic( - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _blob ) internal pure returns (string memory functionSignature) { uint256 _start; @@ -111,7 +111,7 @@ library FunctionSignatures { */ function decode( bytes memory, - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _dynamicData ) internal pure returns (string memory functionSignature) { (functionSignature) = decodeDynamic(_encodedLengths, _dynamicData); @@ -141,10 +141,10 @@ library FunctionSignatures { * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). */ - function encodeLengths(string memory functionSignature) internal pure returns (PackedCounter _encodedLengths) { + function encodeLengths(string memory functionSignature) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack(bytes(functionSignature).length); + _encodedLengths = EncodedLengthsLib.pack(bytes(functionSignature).length); } } @@ -162,9 +162,9 @@ library FunctionSignatures { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(string memory functionSignature) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(string memory functionSignature) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(functionSignature); + EncodedLengths _encodedLengths = encodeLengths(functionSignature); bytes memory _dynamicData = encodeDynamic(functionSignature); return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world/src/codegen/tables/InitModuleAddress.sol b/packages/world/src/codegen/tables/InitModuleAddress.sol index b79eb9f210..c23a724014 100644 --- a/packages/world/src/codegen/tables/InitModuleAddress.sol +++ b/packages/world/src/codegen/tables/InitModuleAddress.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library InitModuleAddress { @@ -167,10 +167,10 @@ library InitModuleAddress { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(address value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(address value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world/src/codegen/tables/InstalledModules.sol b/packages/world/src/codegen/tables/InstalledModules.sol index 6cf4235993..2b5b3fe56c 100644 --- a/packages/world/src/codegen/tables/InstalledModules.sol +++ b/packages/world/src/codegen/tables/InstalledModules.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library InstalledModules { @@ -189,10 +189,10 @@ library InstalledModules { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(bool isInstalled) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(bool isInstalled) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(isInstalled); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world/src/codegen/tables/NamespaceDelegationControl.sol b/packages/world/src/codegen/tables/NamespaceDelegationControl.sol index 308b9ef2eb..8e22dbe524 100644 --- a/packages/world/src/codegen/tables/NamespaceDelegationControl.sol +++ b/packages/world/src/codegen/tables/NamespaceDelegationControl.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -205,10 +205,10 @@ library NamespaceDelegationControl { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(ResourceId delegationControlId) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(ResourceId delegationControlId) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(delegationControlId); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world/src/codegen/tables/NamespaceOwner.sol b/packages/world/src/codegen/tables/NamespaceOwner.sol index 147d8cd9fc..5eae00e696 100644 --- a/packages/world/src/codegen/tables/NamespaceOwner.sol +++ b/packages/world/src/codegen/tables/NamespaceOwner.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -181,10 +181,10 @@ library NamespaceOwner { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(address owner) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(address owner) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(owner); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world/src/codegen/tables/ResourceAccess.sol b/packages/world/src/codegen/tables/ResourceAccess.sol index afe61091c2..5cb402f696 100644 --- a/packages/world/src/codegen/tables/ResourceAccess.sol +++ b/packages/world/src/codegen/tables/ResourceAccess.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -192,10 +192,10 @@ library ResourceAccess { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(bool access) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(bool access) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(access); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world/src/codegen/tables/SystemHooks.sol b/packages/world/src/codegen/tables/SystemHooks.sol index dc99c8190f..fcd36499e0 100644 --- a/packages/world/src/codegen/tables/SystemHooks.sol +++ b/packages/world/src/codegen/tables/SystemHooks.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -411,10 +411,10 @@ library SystemHooks { * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). */ - function encodeLengths(bytes21[] memory value) internal pure returns (PackedCounter _encodedLengths) { + function encodeLengths(bytes21[] memory value) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack(value.length * 21); + _encodedLengths = EncodedLengthsLib.pack(value.length * 21); } } @@ -432,9 +432,9 @@ library SystemHooks { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(bytes21[] memory value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(bytes21[] memory value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(value); + EncodedLengths _encodedLengths = encodeLengths(value); bytes memory _dynamicData = encodeDynamic(value); return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world/src/codegen/tables/SystemRegistry.sol b/packages/world/src/codegen/tables/SystemRegistry.sol index c538650d08..c31310e2f3 100644 --- a/packages/world/src/codegen/tables/SystemRegistry.sol +++ b/packages/world/src/codegen/tables/SystemRegistry.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -181,10 +181,10 @@ library SystemRegistry { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(ResourceId systemId) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(ResourceId systemId) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(systemId); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world/src/codegen/tables/Systems.sol b/packages/world/src/codegen/tables/Systems.sol index ce6b8ff31c..e0c2f5bb88 100644 --- a/packages/world/src/codegen/tables/Systems.sol +++ b/packages/world/src/codegen/tables/Systems.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -155,7 +155,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = ResourceId.unwrap(systemId); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -170,7 +170,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = ResourceId.unwrap(systemId); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -184,7 +184,7 @@ library Systems { function set(ResourceId systemId, address system, bool publicAccess) internal { bytes memory _staticData = encodeStatic(system, publicAccess); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -199,7 +199,7 @@ library Systems { function _set(ResourceId systemId, address system, bool publicAccess) internal { bytes memory _staticData = encodeStatic(system, publicAccess); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -225,7 +225,7 @@ library Systems { */ function decode( bytes memory _staticData, - PackedCounter, + EncodedLengths, bytes memory ) internal pure returns (address system, bool publicAccess) { (system, publicAccess) = decodeStatic(_staticData); @@ -265,10 +265,13 @@ library Systems { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(address system, bool publicAccess) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode( + address system, + bool publicAccess + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(system, publicAccess); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world/src/codegen/tables/UserDelegationControl.sol b/packages/world/src/codegen/tables/UserDelegationControl.sol index 66064511cc..adb06d1d62 100644 --- a/packages/world/src/codegen/tables/UserDelegationControl.sol +++ b/packages/world/src/codegen/tables/UserDelegationControl.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -222,10 +222,10 @@ library UserDelegationControl { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(ResourceId delegationControlId) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(ResourceId delegationControlId) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(delegationControlId); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world/test/World.t.sol b/packages/world/test/World.t.sol index de3d2d734f..2fc33150bb 100644 --- a/packages/world/test/World.t.sol +++ b/packages/world/test/World.t.sol @@ -13,7 +13,7 @@ import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { FieldLayoutEncodeHelper } from "@latticexyz/store/test/FieldLayoutEncodeHelper.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; -import { PackedCounter } from "@latticexyz/store/src/PackedCounter.sol"; +import { EncodedLengths } from "@latticexyz/store/src/EncodedLengths.sol"; import { SchemaEncodeHelper } from "@latticexyz/store/test/SchemaEncodeHelper.sol"; import { Tables, ResourceIds } from "@latticexyz/store/src/codegen/index.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; @@ -105,13 +105,13 @@ contract WorldTestSystem is System { ResourceId tableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: name }); if (StoreSwitch.getStoreAddress() == address(this)) { - StoreCore.setRecord(tableId, keyTuple, abi.encodePacked(data), PackedCounter.wrap(bytes32(0)), new bytes(0)); + StoreCore.setRecord(tableId, keyTuple, abi.encodePacked(data), EncodedLengths.wrap(bytes32(0)), new bytes(0)); } else { IBaseWorld(msg.sender).setRecord( tableId, keyTuple, abi.encodePacked(data), - PackedCounter.wrap(bytes32(0)), + EncodedLengths.wrap(bytes32(0)), new bytes(0) ); } @@ -893,7 +893,7 @@ contract WorldTest is Test, GasReporter { world.registerTable(tableId, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](1)); // Write data to the table and expect it to be written - world.setRecord(tableId, singletonKey, abi.encodePacked(true), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(tableId, singletonKey, abi.encodePacked(true), EncodedLengths.wrap(bytes32(0)), new bytes(0)); assertTrue(Bool.get(tableId)); startGasReport("Delete record"); @@ -904,7 +904,7 @@ contract WorldTest is Test, GasReporter { assertFalse(Bool.get(tableId)); // Write data to the table and expect it to be written - world.setRecord(tableId, singletonKey, abi.encodePacked(true), PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(tableId, singletonKey, abi.encodePacked(true), EncodedLengths.wrap(bytes32(0)), new bytes(0)); assertTrue(Bool.get(tableId)); assertTrue(Bool.get(tableId)); @@ -1287,7 +1287,7 @@ contract WorldTest is Test, GasReporter { emit HookCalled( abi.encodeCall( IStoreHook.onBeforeSetRecord, - (tableId, singletonKey, staticData, PackedCounter.wrap(bytes32(0)), new bytes(0), fieldLayout) + (tableId, singletonKey, staticData, EncodedLengths.wrap(bytes32(0)), new bytes(0), fieldLayout) ) ); @@ -1295,11 +1295,11 @@ contract WorldTest is Test, GasReporter { emit HookCalled( abi.encodeCall( IStoreHook.onAfterSetRecord, - (tableId, singletonKey, staticData, PackedCounter.wrap(bytes32(0)), new bytes(0), fieldLayout) + (tableId, singletonKey, staticData, EncodedLengths.wrap(bytes32(0)), new bytes(0), fieldLayout) ) ); - world.setRecord(tableId, singletonKey, staticData, PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(tableId, singletonKey, staticData, EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Expect the hook to be notified when a static field is written (once before and once after the field is written) vm.expectEmit(true, true, true, true); @@ -1354,7 +1354,7 @@ contract WorldTest is Test, GasReporter { // Expect a revert when the RevertSubscriber's onBeforeSetRecord hook is called vm.expectRevert(bytes("onBeforeSetRecord")); - world.setRecord(tableId, singletonKey, staticData, PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(tableId, singletonKey, staticData, EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Expect a revert when the RevertSubscriber's onBeforeSpliceStaticData hook is called vm.expectRevert(bytes("onBeforeSpliceStaticData")); @@ -1372,7 +1372,7 @@ contract WorldTest is Test, GasReporter { emit HookCalled( abi.encodeCall( IStoreHook.onBeforeSetRecord, - (tableId, singletonKey, staticData, PackedCounter.wrap(bytes32(0)), new bytes(0), fieldLayout) + (tableId, singletonKey, staticData, EncodedLengths.wrap(bytes32(0)), new bytes(0), fieldLayout) ) ); @@ -1380,11 +1380,11 @@ contract WorldTest is Test, GasReporter { emit HookCalled( abi.encodeCall( IStoreHook.onAfterSetRecord, - (tableId, singletonKey, staticData, PackedCounter.wrap(bytes32(0)), new bytes(0), fieldLayout) + (tableId, singletonKey, staticData, EncodedLengths.wrap(bytes32(0)), new bytes(0), fieldLayout) ) ); - world.setRecord(tableId, singletonKey, staticData, PackedCounter.wrap(bytes32(0)), new bytes(0)); + world.setRecord(tableId, singletonKey, staticData, EncodedLengths.wrap(bytes32(0)), new bytes(0)); // Expect the hook to be notified when a static field is written (once before and once after the field is written) vm.expectEmit(true, true, true, true); diff --git a/packages/world/test/codegen/tables/AddressArray.sol b/packages/world/test/codegen/tables/AddressArray.sol index c34bcb9b8b..d7b59d9308 100644 --- a/packages/world/test/codegen/tables/AddressArray.sol +++ b/packages/world/test/codegen/tables/AddressArray.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library AddressArray { @@ -405,10 +405,10 @@ library AddressArray { * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). */ - function encodeLengths(address[] memory value) internal pure returns (PackedCounter _encodedLengths) { + function encodeLengths(address[] memory value) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack(value.length * 20); + _encodedLengths = EncodedLengthsLib.pack(value.length * 20); } } @@ -426,9 +426,9 @@ library AddressArray { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(address[] memory value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(address[] memory value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData; - PackedCounter _encodedLengths = encodeLengths(value); + EncodedLengths _encodedLengths = encodeLengths(value); bytes memory _dynamicData = encodeDynamic(value); return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world/test/codegen/tables/Bool.sol b/packages/world/test/codegen/tables/Bool.sol index 913347c8b6..bd2db3b773 100644 --- a/packages/world/test/codegen/tables/Bool.sol +++ b/packages/world/test/codegen/tables/Bool.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library Bool { @@ -164,10 +164,10 @@ library Bool { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(bool value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(bool value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world/test/codegen/tables/TwoFields.sol b/packages/world/test/codegen/tables/TwoFields.sol index 045c5dbaa8..e1a9ecb33c 100644 --- a/packages/world/test/codegen/tables/TwoFields.sol +++ b/packages/world/test/codegen/tables/TwoFields.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; struct TwoFieldsData { @@ -144,7 +144,7 @@ library TwoFields { function get(ResourceId _tableId) internal view returns (TwoFieldsData memory _table) { bytes32[] memory _keyTuple = new bytes32[](0); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -158,7 +158,7 @@ library TwoFields { function _get(ResourceId _tableId) internal view returns (TwoFieldsData memory _table) { bytes32[] memory _keyTuple = new bytes32[](0); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -172,7 +172,7 @@ library TwoFields { function set(ResourceId _tableId, bool value1, bool value2) internal { bytes memory _staticData = encodeStatic(value1, value2); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](0); @@ -186,7 +186,7 @@ library TwoFields { function _set(ResourceId _tableId, bool value1, bool value2) internal { bytes memory _staticData = encodeStatic(value1, value2); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](0); @@ -200,7 +200,7 @@ library TwoFields { function set(ResourceId _tableId, TwoFieldsData memory _table) internal { bytes memory _staticData = encodeStatic(_table.value1, _table.value2); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](0); @@ -214,7 +214,7 @@ library TwoFields { function _set(ResourceId _tableId, TwoFieldsData memory _table) internal { bytes memory _staticData = encodeStatic(_table.value1, _table.value2); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](0); @@ -239,7 +239,7 @@ library TwoFields { */ function decode( bytes memory _staticData, - PackedCounter, + EncodedLengths, bytes memory ) internal pure returns (TwoFieldsData memory _table) { (_table.value1, _table.value2) = decodeStatic(_staticData); @@ -277,10 +277,10 @@ library TwoFields { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(bool value1, bool value2) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(bool value1, bool value2) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(value1, value2); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/packages/world/ts/protocol-snapshots/2.0.0.snap b/packages/world/ts/protocol-snapshots/2.0.0.snap index 4ee517930f..c5356865a4 100644 --- a/packages/world/ts/protocol-snapshots/2.0.0.snap +++ b/packages/world/ts/protocol-snapshots/2.0.0.snap @@ -1,10 +1,10 @@ [ "constructor()", + "error EncodedLengths_InvalidLength(uint256 length)", "error Module_AlreadyInstalled()", "error Module_MissingDependency(address dependency)", "error Module_NonRootInstallNotSupported()", "error Module_RootInstallNotSupported()", - "error PackedCounter_InvalidLength(uint256 length)", "error Slice_OutOfBounds(bytes data, uint256 start, uint256 end)", "error Store_IndexOutOfBounds(uint256 length, uint256 accessedIndex)", "error Store_InvalidBounds(uint256 start, uint256 end)", diff --git a/scripts/render-api-docs.ts b/scripts/render-api-docs.ts index f0925af297..aa1e9220cd 100644 --- a/scripts/render-api-docs.ts +++ b/scripts/render-api-docs.ts @@ -76,7 +76,7 @@ const PUBLIC_APIS: PublicApis = { { source: "store/src/Hook.sol" }, { source: "store/src/Memory.sol" }, /* - { source: "store/src/PackedCounter.sol" }, + { source: "store/src/EncodedLengths.sol" }, */ { source: "store/src/ResourceId.sol" }, { source: "store/src/Schema.sol" }, diff --git a/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol b/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol index 829e0b68f4..45558b3f11 100644 --- a/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library Counter { @@ -167,10 +167,10 @@ library Counter { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint32 value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint32 value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); 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 829e0b68f4..45558b3f11 100644 --- a/templates/react-ecs/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/react-ecs/packages/contracts/src/codegen/tables/Counter.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library Counter { @@ -167,10 +167,10 @@ library Counter { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint32 value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint32 value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/templates/react/packages/contracts/src/codegen/tables/Tasks.sol b/templates/react/packages/contracts/src/codegen/tables/Tasks.sol index 454d03032d..6f26bc3cab 100644 --- a/templates/react/packages/contracts/src/codegen/tables/Tasks.sol +++ b/templates/react/packages/contracts/src/codegen/tables/Tasks.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; struct TasksData { @@ -321,7 +321,7 @@ library Tasks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = id; - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -336,7 +336,7 @@ library Tasks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = id; - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -350,7 +350,7 @@ library Tasks { function set(bytes32 id, uint256 createdAt, uint256 completedAt, string memory description) internal { bytes memory _staticData = encodeStatic(createdAt, completedAt); - PackedCounter _encodedLengths = encodeLengths(description); + EncodedLengths _encodedLengths = encodeLengths(description); bytes memory _dynamicData = encodeDynamic(description); bytes32[] memory _keyTuple = new bytes32[](1); @@ -365,7 +365,7 @@ library Tasks { function _set(bytes32 id, uint256 createdAt, uint256 completedAt, string memory description) internal { bytes memory _staticData = encodeStatic(createdAt, completedAt); - PackedCounter _encodedLengths = encodeLengths(description); + EncodedLengths _encodedLengths = encodeLengths(description); bytes memory _dynamicData = encodeDynamic(description); bytes32[] memory _keyTuple = new bytes32[](1); @@ -380,7 +380,7 @@ library Tasks { function set(bytes32 id, TasksData memory _table) internal { bytes memory _staticData = encodeStatic(_table.createdAt, _table.completedAt); - PackedCounter _encodedLengths = encodeLengths(_table.description); + EncodedLengths _encodedLengths = encodeLengths(_table.description); bytes memory _dynamicData = encodeDynamic(_table.description); bytes32[] memory _keyTuple = new bytes32[](1); @@ -395,7 +395,7 @@ library Tasks { function _set(bytes32 id, TasksData memory _table) internal { bytes memory _staticData = encodeStatic(_table.createdAt, _table.completedAt); - PackedCounter _encodedLengths = encodeLengths(_table.description); + EncodedLengths _encodedLengths = encodeLengths(_table.description); bytes memory _dynamicData = encodeDynamic(_table.description); bytes32[] memory _keyTuple = new bytes32[](1); @@ -417,7 +417,7 @@ library Tasks { * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ function decodeDynamic( - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _blob ) internal pure returns (string memory description) { uint256 _start; @@ -436,7 +436,7 @@ library Tasks { */ function decode( bytes memory _staticData, - PackedCounter _encodedLengths, + EncodedLengths _encodedLengths, bytes memory _dynamicData ) internal pure returns (TasksData memory _table) { (_table.createdAt, _table.completedAt) = decodeStatic(_staticData); @@ -476,10 +476,10 @@ library Tasks { * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). */ - function encodeLengths(string memory description) internal pure returns (PackedCounter _encodedLengths) { + function encodeLengths(string memory description) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { - _encodedLengths = PackedCounterLib.pack(bytes(description).length); + _encodedLengths = EncodedLengthsLib.pack(bytes(description).length); } } @@ -501,10 +501,10 @@ library Tasks { uint256 createdAt, uint256 completedAt, string memory description - ) internal pure returns (bytes memory, PackedCounter, bytes memory) { + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(createdAt, completedAt); - PackedCounter _encodedLengths = encodeLengths(description); + EncodedLengths _encodedLengths = encodeLengths(description); bytes memory _dynamicData = encodeDynamic(description); return (_staticData, _encodedLengths, _dynamicData); diff --git a/templates/threejs/packages/contracts/src/codegen/tables/Position.sol b/templates/threejs/packages/contracts/src/codegen/tables/Position.sol index 3a8edfb588..00091e91bc 100644 --- a/templates/threejs/packages/contracts/src/codegen/tables/Position.sol +++ b/templates/threejs/packages/contracts/src/codegen/tables/Position.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; struct PositionData { @@ -201,7 +201,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = id; - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -216,7 +216,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = id; - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -230,7 +230,7 @@ library Position { function set(bytes32 id, int32 x, int32 y, int32 z) internal { bytes memory _staticData = encodeStatic(x, y, z); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -245,7 +245,7 @@ library Position { function _set(bytes32 id, int32 x, int32 y, int32 z) internal { bytes memory _staticData = encodeStatic(x, y, z); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -260,7 +260,7 @@ library Position { function set(bytes32 id, PositionData memory _table) internal { bytes memory _staticData = encodeStatic(_table.x, _table.y, _table.z); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -275,7 +275,7 @@ library Position { function _set(bytes32 id, PositionData memory _table) internal { bytes memory _staticData = encodeStatic(_table.x, _table.y, _table.z); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -303,7 +303,7 @@ library Position { */ function decode( bytes memory _staticData, - PackedCounter, + EncodedLengths, bytes memory ) internal pure returns (PositionData memory _table) { (_table.x, _table.y, _table.z) = decodeStatic(_staticData); @@ -343,10 +343,10 @@ library Position { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(int32 x, int32 y, int32 z) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(int32 x, int32 y, int32 z) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(x, y, z); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol b/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol index 829e0b68f4..45558b3f11 100644 --- a/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library Counter { @@ -167,10 +167,10 @@ library Counter { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint32 value) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint32 value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(value); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/test/mock-game-contracts/src/codegen/tables/Health.sol b/test/mock-game-contracts/src/codegen/tables/Health.sol index f954023e77..d5597a444d 100644 --- a/test/mock-game-contracts/src/codegen/tables/Health.sol +++ b/test/mock-game-contracts/src/codegen/tables/Health.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library Health { @@ -178,10 +178,10 @@ library Health { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint256 health) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint256 health) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(health); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/test/mock-game-contracts/src/codegen/tables/Inventory.sol b/test/mock-game-contracts/src/codegen/tables/Inventory.sol index d2ebb1e7de..d709cc5d42 100644 --- a/test/mock-game-contracts/src/codegen/tables/Inventory.sol +++ b/test/mock-game-contracts/src/codegen/tables/Inventory.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library Inventory { @@ -189,10 +189,10 @@ library Inventory { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint32 amount) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint32 amount) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(amount); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/test/mock-game-contracts/src/codegen/tables/Position.sol b/test/mock-game-contracts/src/codegen/tables/Position.sol index 5f46ffe408..a2cf0dba04 100644 --- a/test/mock-game-contracts/src/codegen/tables/Position.sol +++ b/test/mock-game-contracts/src/codegen/tables/Position.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; struct PositionData { @@ -157,7 +157,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(player))); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout @@ -172,7 +172,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(player))); - (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout @@ -186,7 +186,7 @@ library Position { function set(address player, int32 x, int32 y) internal { bytes memory _staticData = encodeStatic(x, y); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -201,7 +201,7 @@ library Position { function _set(address player, int32 x, int32 y) internal { bytes memory _staticData = encodeStatic(x, y); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -216,7 +216,7 @@ library Position { function set(address player, PositionData memory _table) internal { bytes memory _staticData = encodeStatic(_table.x, _table.y); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -231,7 +231,7 @@ library Position { function _set(address player, PositionData memory _table) internal { bytes memory _staticData = encodeStatic(_table.x, _table.y); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); @@ -257,7 +257,7 @@ library Position { */ function decode( bytes memory _staticData, - PackedCounter, + EncodedLengths, bytes memory ) internal pure returns (PositionData memory _table) { (_table.x, _table.y) = decodeStatic(_staticData); @@ -297,10 +297,10 @@ library Position { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(int32 x, int32 y) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(int32 x, int32 y) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(x, y); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/test/mock-game-contracts/src/codegen/tables/Score.sol b/test/mock-game-contracts/src/codegen/tables/Score.sol index e1b6c84a66..f708322d22 100644 --- a/test/mock-game-contracts/src/codegen/tables/Score.sol +++ b/test/mock-game-contracts/src/codegen/tables/Score.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library Score { @@ -189,10 +189,10 @@ library Score { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(uint256 score) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(uint256 score) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(score); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/test/mock-game-contracts/src/codegen/tables/Terrain.sol b/test/mock-game-contracts/src/codegen/tables/Terrain.sol index d3bf87575f..3476bc100a 100644 --- a/test/mock-game-contracts/src/codegen/tables/Terrain.sol +++ b/test/mock-game-contracts/src/codegen/tables/Terrain.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types @@ -192,10 +192,10 @@ library Terrain { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(TerrainType terrainType) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(TerrainType terrainType) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(terrainType); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); diff --git a/test/mock-game-contracts/src/codegen/tables/Winner.sol b/test/mock-game-contracts/src/codegen/tables/Winner.sol index 61e8222060..411d770c50 100644 --- a/test/mock-game-contracts/src/codegen/tables/Winner.sol +++ b/test/mock-game-contracts/src/codegen/tables/Winner.sol @@ -13,7 +13,7 @@ import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.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 { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; library Winner { @@ -178,10 +178,10 @@ library Winner { * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ - function encode(address player) internal pure returns (bytes memory, PackedCounter, bytes memory) { + function encode(address player) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(player); - PackedCounter _encodedLengths; + EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData);