From 55ab88a60adb3ad72ebafef4d50513eb71e3c314 Mon Sep 17 00:00:00 2001 From: alvarius Date: Sat, 16 Sep 2023 22:35:08 +0100 Subject: [PATCH] feat(store): expose `getStaticField` and `getDynamicField` on `IStore` and use it in codegen tables (#1521) --- .changeset/sour-cycles-warn.md | 34 +++++ .../contracts/src/codegen/tables/Multi.sol | 16 +-- .../contracts/src/codegen/tables/Number.sol | 8 +- .../src/codegen/tables/NumberList.sol | 8 +- .../contracts/src/codegen/tables/Vector.sol | 16 +-- .../src/codegen/tables/CounterTable.sol | 8 +- .../src/codegen/tables/Inventory.sol | 8 +- .../src/codegen/tables/Dynamics1.sol | 40 +++--- .../src/codegen/tables/Dynamics2.sol | 16 +-- .../src/codegen/tables/Singleton.sol | 32 ++--- .../contracts/src/codegen/tables/Statics.sol | 48 +++---- packages/store/gas-report.json | 134 +++++++++--------- packages/store/src/IStore.sol | 39 ++++- packages/store/src/StoreCore.sol | 84 +++++++---- packages/store/src/StoreRead.sol | 19 ++- packages/store/src/StoreSwitch.sol | 27 ++++ .../store/src/codegen/tables/Callbacks.sol | 8 +- packages/store/src/codegen/tables/Hooks.sol | 8 +- .../store/src/codegen/tables/KeyEncoding.sol | 8 +- packages/store/src/codegen/tables/Mixed.sol | 28 ++-- .../store/src/codegen/tables/StoreHooks.sol | 8 +- packages/store/src/codegen/tables/Tables.sol | 32 ++--- packages/store/src/codegen/tables/Vector2.sol | 16 +-- packages/store/ts/codegen/field.ts | 35 ++++- packages/world/gas-report.json | 122 ++++++++-------- .../src/modules/core/tables/Balances.sol | 8 +- .../modules/core/tables/FunctionSelectors.sol | 16 +-- .../src/modules/core/tables/ResourceType.sol | 8 +- .../src/modules/core/tables/SystemHooks.sol | 8 +- .../modules/core/tables/SystemRegistry.sol | 8 +- .../world/src/modules/core/tables/Systems.sol | 16 +-- .../keysintable/tables/KeysInTable.sol | 40 +++--- .../keysintable/tables/UsedKeysIndex.sol | 16 +-- .../keyswithvalue/tables/KeysWithValue.sol | 8 +- .../tables/CallboundDelegations.sol | 8 +- .../tables/TimeboundDelegations.sol | 8 +- .../uniqueentity/tables/UniqueEntity.sol | 8 +- packages/world/src/tables/Delegations.sol | 8 +- .../world/src/tables/InstalledModules.sol | 8 +- packages/world/src/tables/NamespaceOwner.sol | 8 +- packages/world/src/tables/ResourceAccess.sol | 8 +- packages/world/test/tables/AddressArray.sol | 8 +- packages/world/test/tables/Bool.sol | 8 +- .../contracts/src/codegen/tables/Counter.sol | 8 +- .../contracts/src/codegen/tables/Counter.sol | 8 +- .../contracts/src/codegen/tables/Position.sol | 24 ++-- .../contracts/src/codegen/tables/Counter.sol | 8 +- 47 files changed, 601 insertions(+), 449 deletions(-) create mode 100644 .changeset/sour-cycles-warn.md diff --git a/.changeset/sour-cycles-warn.md b/.changeset/sour-cycles-warn.md new file mode 100644 index 0000000000..1a79d508c5 --- /dev/null +++ b/.changeset/sour-cycles-warn.md @@ -0,0 +1,34 @@ +--- +"@latticexyz/cli": patch +"@latticexyz/store": minor +"@latticexyz/world": patch +--- + +`StoreCore` and `IStore` now expose specific functions for `getStaticField` and `getDynamicField` in addition to the general `getField`. +Using the specific functions reduces gas overhead because more optimized logic can be executed. + +```solidity +interface IStore { + /** + * Get a single static field from the given tableId and key tuple, with the given value field layout. + * Note: the field value is left-aligned in the returned bytes32, the rest of the word is not zeroed out. + * Consumers are expected to truncate the returned value as needed. + */ + function getStaticField( + bytes32 tableId, + bytes32[] calldata keyTuple, + uint8 fieldIndex, + FieldLayout fieldLayout + ) external view returns (bytes32); + + /** + * Get a single dynamic field from the given tableId and key tuple at the given dynamic field index. + * (Dynamic field index = field index - number of static fields) + */ + function getDynamicField( + bytes32 tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex + ) external view returns (bytes memory); +} +``` diff --git a/e2e/packages/contracts/src/codegen/tables/Multi.sol b/e2e/packages/contracts/src/codegen/tables/Multi.sol index 2f25c111dd..8b97411563 100644 --- a/e2e/packages/contracts/src/codegen/tables/Multi.sol +++ b/e2e/packages/contracts/src/codegen/tables/Multi.sol @@ -90,8 +90,8 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (int256(uint256(Bytes.slice32(_blob, 0)))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (int256(uint256(bytes32(_blob)))); } /** Get num (using the specified store) */ @@ -102,8 +102,8 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (int256(uint256(Bytes.slice32(_blob, 0)))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (int256(uint256(bytes32(_blob)))); } /** Set num */ @@ -136,8 +136,8 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); } /** Get value (using the specified store) */ @@ -148,8 +148,8 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); } /** Set value */ diff --git a/e2e/packages/contracts/src/codegen/tables/Number.sol b/e2e/packages/contracts/src/codegen/tables/Number.sol index 07eeb5619e..f5c62ae689 100644 --- a/e2e/packages/contracts/src/codegen/tables/Number.sol +++ b/e2e/packages/contracts/src/codegen/tables/Number.sol @@ -74,8 +74,8 @@ library Number { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(Bytes.slice4(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); } /** Get value (using the specified store) */ @@ -83,8 +83,8 @@ library Number { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(Bytes.slice4(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); } /** Set value */ diff --git a/e2e/packages/contracts/src/codegen/tables/NumberList.sol b/e2e/packages/contracts/src/codegen/tables/NumberList.sol index 0f26dba1a2..8f203ff4d0 100644 --- a/e2e/packages/contracts/src/codegen/tables/NumberList.sol +++ b/e2e/packages/contracts/src/codegen/tables/NumberList.sol @@ -71,7 +71,7 @@ library NumberList { function get() internal view returns (uint32[] memory value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -79,7 +79,7 @@ library NumberList { function get(IStore _store) internal view returns (uint32[] memory value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -133,7 +133,7 @@ library NumberList { _index * 4, (_index + 1) * 4 ); - return (uint32(Bytes.slice4(_blob, 0))); + return (uint32(bytes4(_blob))); } } @@ -146,7 +146,7 @@ library NumberList { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, _fieldLayout, _index * 4, (_index + 1) * 4); - return (uint32(Bytes.slice4(_blob, 0))); + return (uint32(bytes4(_blob))); } } diff --git a/e2e/packages/contracts/src/codegen/tables/Vector.sol b/e2e/packages/contracts/src/codegen/tables/Vector.sol index a7870c1a6c..a872229034 100644 --- a/e2e/packages/contracts/src/codegen/tables/Vector.sol +++ b/e2e/packages/contracts/src/codegen/tables/Vector.sol @@ -81,8 +81,8 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (int32(uint32(Bytes.slice4(_blob, 0)))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (int32(uint32(bytes4(_blob)))); } /** Get x (using the specified store) */ @@ -90,8 +90,8 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (int32(uint32(Bytes.slice4(_blob, 0)))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (int32(uint32(bytes4(_blob)))); } /** Set x */ @@ -115,8 +115,8 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (int32(uint32(Bytes.slice4(_blob, 0)))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (int32(uint32(bytes4(_blob)))); } /** Get y (using the specified store) */ @@ -124,8 +124,8 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (int32(uint32(Bytes.slice4(_blob, 0)))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (int32(uint32(bytes4(_blob)))); } /** Set y */ diff --git a/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol b/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol index 04bf83b923..ec404deade 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol @@ -71,16 +71,16 @@ library CounterTable { function get() internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(Bytes.slice4(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); } /** Get value (using the specified store) */ function get(IStore _store) internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(Bytes.slice4(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); } /** Set value */ diff --git a/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol b/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol index 2fe128efd0..40b4913ac1 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol @@ -80,8 +80,8 @@ library Inventory { _keyTuple[1] = bytes32(uint256(item)); _keyTuple[2] = bytes32(uint256(itemVariant)); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(Bytes.slice4(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); } /** Get amount (using the specified store) */ @@ -91,8 +91,8 @@ library Inventory { _keyTuple[1] = bytes32(uint256(item)); _keyTuple[2] = bytes32(uint256(itemVariant)); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(Bytes.slice4(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); } /** Set amount */ diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol index 9d96284463..b4b6f609cb 100644 --- a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol +++ b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol @@ -90,7 +90,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); return toStaticArray_bytes32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -99,7 +99,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); return toStaticArray_bytes32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -164,7 +164,7 @@ library Dynamics1 { _index * 32, (_index + 1) * 32 ); - return (Bytes.slice32(_blob, 0)); + return (bytes32(_blob)); } } @@ -178,7 +178,7 @@ library Dynamics1 { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, _fieldLayout, _index * 32, (_index + 1) * 32); - return (Bytes.slice32(_blob, 0)); + return (bytes32(_blob)); } } @@ -245,7 +245,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 1); return toStaticArray_int32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_int32()); } @@ -254,7 +254,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 1); return toStaticArray_int32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_int32()); } @@ -313,7 +313,7 @@ library Dynamics1 { _index * 4, (_index + 1) * 4 ); - return (int32(uint32(Bytes.slice4(_blob, 0)))); + return (int32(uint32(bytes4(_blob)))); } } @@ -327,7 +327,7 @@ library Dynamics1 { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 1, _fieldLayout, _index * 4, (_index + 1) * 4); - return (int32(uint32(Bytes.slice4(_blob, 0)))); + return (int32(uint32(bytes4(_blob)))); } } @@ -394,7 +394,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 2); return toStaticArray_uint128_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint128()); } @@ -403,7 +403,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 2); return toStaticArray_uint128_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint128()); } @@ -468,7 +468,7 @@ library Dynamics1 { _index * 16, (_index + 1) * 16 ); - return (uint128(Bytes.slice16(_blob, 0))); + return (uint128(bytes16(_blob))); } } @@ -482,7 +482,7 @@ library Dynamics1 { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 2, _fieldLayout, _index * 16, (_index + 1) * 16); - return (uint128(Bytes.slice16(_blob, 0))); + return (uint128(bytes16(_blob))); } } @@ -549,7 +549,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 3); return toStaticArray_address_4(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); } @@ -558,7 +558,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 3, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 3); return toStaticArray_address_4(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); } @@ -623,7 +623,7 @@ library Dynamics1 { _index * 20, (_index + 1) * 20 ); - return (address(Bytes.slice20(_blob, 0))); + return (address(bytes20(_blob))); } } @@ -637,7 +637,7 @@ library Dynamics1 { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 3, _fieldLayout, _index * 20, (_index + 1) * 20); - return (address(Bytes.slice20(_blob, 0))); + return (address(bytes20(_blob))); } } @@ -704,7 +704,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 4, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 4); return toStaticArray_bool_5(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bool()); } @@ -713,7 +713,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 4, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 4); return toStaticArray_bool_5(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bool()); } @@ -772,7 +772,7 @@ library Dynamics1 { _index * 1, (_index + 1) * 1 ); - return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + return (_toBool(uint8(bytes1(_blob)))); } } @@ -786,7 +786,7 @@ library Dynamics1 { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 4, _fieldLayout, _index * 1, (_index + 1) * 1); - return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + return (_toBool(uint8(bytes1(_blob)))); } } diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol index 2317c58515..59d39a2106 100644 --- a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol +++ b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol @@ -84,7 +84,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint64()); } @@ -93,7 +93,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint64()); } @@ -152,7 +152,7 @@ library Dynamics2 { _index * 8, (_index + 1) * 8 ); - return (uint64(Bytes.slice8(_blob, 0))); + return (uint64(bytes8(_blob))); } } @@ -166,7 +166,7 @@ library Dynamics2 { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, _fieldLayout, _index * 8, (_index + 1) * 8); - return (uint64(Bytes.slice8(_blob, 0))); + return (uint64(bytes8(_blob))); } } @@ -233,7 +233,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 1); return (string(_blob)); } @@ -242,7 +242,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 1); return (string(_blob)); } @@ -382,7 +382,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 2); return (bytes(_blob)); } @@ -391,7 +391,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 2); return (bytes(_blob)); } diff --git a/packages/cli/contracts/src/codegen/tables/Singleton.sol b/packages/cli/contracts/src/codegen/tables/Singleton.sol index d331c6eda3..90e1319b41 100644 --- a/packages/cli/contracts/src/codegen/tables/Singleton.sol +++ b/packages/cli/contracts/src/codegen/tables/Singleton.sol @@ -77,16 +77,16 @@ library Singleton { function getV1() internal view returns (int256 v1) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (int256(uint256(Bytes.slice32(_blob, 0)))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (int256(uint256(bytes32(_blob)))); } /** Get v1 (using the specified store) */ function getV1(IStore _store) internal view returns (int256 v1) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (int256(uint256(Bytes.slice32(_blob, 0)))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (int256(uint256(bytes32(_blob)))); } /** Set v1 */ @@ -107,7 +107,7 @@ library Singleton { function getV2() internal view returns (uint32[2] memory v2) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -115,7 +115,7 @@ library Singleton { function getV2(IStore _store) internal view returns (uint32[2] memory v2) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -169,7 +169,7 @@ library Singleton { _index * 4, (_index + 1) * 4 ); - return (uint32(Bytes.slice4(_blob, 0))); + return (uint32(bytes4(_blob))); } } @@ -182,7 +182,7 @@ library Singleton { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 1, _fieldLayout, _index * 4, (_index + 1) * 4); - return (uint32(Bytes.slice4(_blob, 0))); + return (uint32(bytes4(_blob))); } } @@ -242,7 +242,7 @@ library Singleton { function getV3() internal view returns (uint32[2] memory v3) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 1); return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -250,7 +250,7 @@ library Singleton { function getV3(IStore _store) internal view returns (uint32[2] memory v3) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 1); return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -304,7 +304,7 @@ library Singleton { _index * 4, (_index + 1) * 4 ); - return (uint32(Bytes.slice4(_blob, 0))); + return (uint32(bytes4(_blob))); } } @@ -317,7 +317,7 @@ library Singleton { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 2, _fieldLayout, _index * 4, (_index + 1) * 4); - return (uint32(Bytes.slice4(_blob, 0))); + return (uint32(bytes4(_blob))); } } @@ -377,7 +377,7 @@ library Singleton { function getV4() internal view returns (uint32[1] memory v4) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 2); return toStaticArray_uint32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -385,7 +385,7 @@ library Singleton { function getV4(IStore _store) internal view returns (uint32[1] memory v4) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 3, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 2); return toStaticArray_uint32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -439,7 +439,7 @@ library Singleton { _index * 4, (_index + 1) * 4 ); - return (uint32(Bytes.slice4(_blob, 0))); + return (uint32(bytes4(_blob))); } } @@ -452,7 +452,7 @@ library Singleton { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 3, _fieldLayout, _index * 4, (_index + 1) * 4); - return (uint32(Bytes.slice4(_blob, 0))); + return (uint32(bytes4(_blob))); } } diff --git a/packages/cli/contracts/src/codegen/tables/Statics.sol b/packages/cli/contracts/src/codegen/tables/Statics.sol index 14e42c5370..0f0376d429 100644 --- a/packages/cli/contracts/src/codegen/tables/Statics.sol +++ b/packages/cli/contracts/src/codegen/tables/Statics.sol @@ -111,8 +111,8 @@ library Statics { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(Bytes.slice32(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); } /** Get v1 (using the specified store) */ @@ -133,8 +133,8 @@ library Statics { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(Bytes.slice32(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); } /** Set v1 */ @@ -173,8 +173,8 @@ library Statics { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (int32(uint32(Bytes.slice4(_blob, 0)))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (int32(uint32(bytes4(_blob)))); } /** Get v2 (using the specified store) */ @@ -195,8 +195,8 @@ library Statics { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (int32(uint32(Bytes.slice4(_blob, 0)))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (int32(uint32(bytes4(_blob)))); } /** Set v2 */ @@ -235,8 +235,8 @@ library Statics { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, _fieldLayout); - return (Bytes.slice16(_blob, 0)); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); + return (bytes16(_blob)); } /** Get v3 (using the specified store) */ @@ -257,8 +257,8 @@ library Statics { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, _fieldLayout); - return (Bytes.slice16(_blob, 0)); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); + return (bytes16(_blob)); } /** Set v3 */ @@ -297,8 +297,8 @@ library Statics { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3, _fieldLayout); - return (address(Bytes.slice20(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 3, _fieldLayout); + return (address(bytes20(_blob))); } /** Get v4 (using the specified store) */ @@ -319,8 +319,8 @@ library Statics { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 3, _fieldLayout); - return (address(Bytes.slice20(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 3, _fieldLayout); + return (address(bytes20(_blob))); } /** Set v4 */ @@ -359,8 +359,8 @@ library Statics { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 4, _fieldLayout); - return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 4, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); } /** Get v5 (using the specified store) */ @@ -381,8 +381,8 @@ library Statics { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 4, _fieldLayout); - return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 4, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); } /** Set v5 */ @@ -421,8 +421,8 @@ library Statics { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 5, _fieldLayout); - return Enum1(uint8(Bytes.slice1(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 5, _fieldLayout); + return Enum1(uint8(bytes1(_blob))); } /** Get v6 (using the specified store) */ @@ -443,8 +443,8 @@ library Statics { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 5, _fieldLayout); - return Enum1(uint8(Bytes.slice1(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 5, _fieldLayout); + return Enum1(uint8(bytes1(_blob))); } /** Set v6 */ diff --git a/packages/store/gas-report.json b/packages/store/gas-report.json index 7ac2f7e9e6..c1ac85ebb5 100644 --- a/packages/store/gas-report.json +++ b/packages/store/gas-report.json @@ -351,7 +351,7 @@ "file": "test/KeyEncoding.t.sol", "test": "testRegisterAndGetFieldLayout", "name": "register KeyEncoding table", - "gasUsed": 690015 + "gasUsed": 688555 }, { "file": "test/Mixed.t.sol", @@ -363,13 +363,13 @@ "file": "test/Mixed.t.sol", "test": "testRegisterAndGetFieldLayout", "name": "register Mixed table", - "gasUsed": 551833 + "gasUsed": 550389 }, { "file": "test/Mixed.t.sol", "test": "testSetAndGet", "name": "set record in Mixed", - "gasUsed": 104922 + "gasUsed": 104102 }, { "file": "test/Mixed.t.sol", @@ -561,13 +561,13 @@ "file": "test/StoreCoreDynamic.t.sol", "test": "testGetFieldSlice", "name": "get field slice (cold, 1 slot)", - "gasUsed": 8281 + "gasUsed": 8282 }, { "file": "test/StoreCoreDynamic.t.sol", "test": "testGetFieldSlice", "name": "get field slice (warm, 1 slot)", - "gasUsed": 2349 + "gasUsed": 2350 }, { "file": "test/StoreCoreDynamic.t.sol", @@ -579,13 +579,13 @@ "file": "test/StoreCoreDynamic.t.sol", "test": "testGetFieldSlice", "name": "get field slice (warm, 2 slots)", - "gasUsed": 4580 + "gasUsed": 4579 }, { "file": "test/StoreCoreDynamic.t.sol", "test": "testGetSecondFieldLength", "name": "get field length (cold, 1 slot)", - "gasUsed": 7756 + "gasUsed": 7757 }, { "file": "test/StoreCoreDynamic.t.sol", @@ -609,49 +609,49 @@ "file": "test/StoreCoreDynamic.t.sol", "test": "testPopFromSecondField", "name": "pop from field (cold, 1 slot, 1 uint32 item)", - "gasUsed": 21297 + "gasUsed": 20433 }, { "file": "test/StoreCoreDynamic.t.sol", "test": "testPopFromSecondField", "name": "pop from field (warm, 1 slot, 1 uint32 item)", - "gasUsed": 15309 + "gasUsed": 14445 }, { "file": "test/StoreCoreDynamic.t.sol", "test": "testPopFromThirdField", "name": "pop from field (cold, 2 slots, 10 uint32 items)", - "gasUsed": 23493 + "gasUsed": 22629 }, { "file": "test/StoreCoreDynamic.t.sol", "test": "testPopFromThirdField", "name": "pop from field (warm, 2 slots, 10 uint32 items)", - "gasUsed": 15505 + "gasUsed": 14641 }, { "file": "test/StoreCoreGas.t.sol", "test": "testAccessEmptyData", "name": "access non-existing record", - "gasUsed": 6197 + "gasUsed": 6198 }, { "file": "test/StoreCoreGas.t.sol", "test": "testAccessEmptyData", "name": "access static field of non-existing record", - "gasUsed": 1357 + "gasUsed": 1318 }, { "file": "test/StoreCoreGas.t.sol", "test": "testAccessEmptyData", "name": "access dynamic field of non-existing record", - "gasUsed": 2090 + "gasUsed": 2045 }, { "file": "test/StoreCoreGas.t.sol", "test": "testAccessEmptyData", "name": "access length of dynamic field of non-existing record", - "gasUsed": 1120 + "gasUsed": 1121 }, { "file": "test/StoreCoreGas.t.sol", @@ -663,109 +663,109 @@ "file": "test/StoreCoreGas.t.sol", "test": "testDeleteData", "name": "delete record (complex data, 3 slots)", - "gasUsed": 7702 + "gasUsed": 6882 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHasFieldLayout", "name": "Check for existence of table (existent)", - "gasUsed": 2178 + "gasUsed": 1555 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHasFieldLayout", "name": "check for existence of table (non-existent)", - "gasUsed": 4180 + "gasUsed": 3556 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooks", "name": "register subscriber", - "gasUsed": 59474 + "gasUsed": 58604 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooks", "name": "set record on table with subscriber", - "gasUsed": 73142 + "gasUsed": 71502 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooks", "name": "set static field on table with subscriber", - "gasUsed": 22908 + "gasUsed": 21245 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooks", "name": "delete record on table with subscriber", - "gasUsed": 18460 + "gasUsed": 16797 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooksDynamicData", "name": "register subscriber", - "gasUsed": 59474 + "gasUsed": 58604 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooksDynamicData", "name": "set (dynamic) record on table with subscriber", - "gasUsed": 166238 + "gasUsed": 164598 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooksDynamicData", "name": "set (dynamic) field on table with subscriber", - "gasUsed": 26108 + "gasUsed": 24445 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooksDynamicData", "name": "delete (dynamic) record on table with subscriber", - "gasUsed": 19445 + "gasUsed": 17782 }, { "file": "test/StoreCoreGas.t.sol", "test": "testPushToField", "name": "push to field (1 slot, 1 uint32 item)", - "gasUsed": 13053 + "gasUsed": 12189 }, { "file": "test/StoreCoreGas.t.sol", "test": "testPushToField", "name": "push to field (2 slots, 10 uint32 items)", - "gasUsed": 35807 + "gasUsed": 34943 }, { "file": "test/StoreCoreGas.t.sol", "test": "testRegisterAndGetFieldLayout", "name": "StoreCore: register table", - "gasUsed": 613985 + "gasUsed": 612540 }, { "file": "test/StoreCoreGas.t.sol", "test": "testRegisterAndGetFieldLayout", "name": "StoreCore: get field layout (warm)", - "gasUsed": 2191 + "gasUsed": 1567 }, { "file": "test/StoreCoreGas.t.sol", "test": "testRegisterAndGetFieldLayout", "name": "StoreCore: get value schema (warm)", - "gasUsed": 2744 + "gasUsed": 2077 }, { "file": "test/StoreCoreGas.t.sol", "test": "testRegisterAndGetFieldLayout", "name": "StoreCore: get key schema (warm)", - "gasUsed": 4699 + "gasUsed": 3406 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetDynamicData", "name": "set complex record with dynamic data (4 slots)", - "gasUsed": 102843 + "gasUsed": 102022 }, { "file": "test/StoreCoreGas.t.sol", @@ -801,61 +801,61 @@ "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetDynamicDataLength", "name": "reduce dynamic length of dynamic index 0", - "gasUsed": 961 + "gasUsed": 960 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetField", "name": "set static field (1 slot)", - "gasUsed": 32564 + "gasUsed": 31744 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetField", "name": "get static field (1 slot)", - "gasUsed": 1357 + "gasUsed": 1318 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetField", "name": "set static field (overlap 2 slot)", - "gasUsed": 31204 + "gasUsed": 30384 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetField", "name": "get static field (overlap 2 slot)", - "gasUsed": 1883 + "gasUsed": 1844 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetField", "name": "set dynamic field (1 slot, first dynamic field)", - "gasUsed": 54090 + "gasUsed": 53269 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetField", "name": "get dynamic field (1 slot, first dynamic field)", - "gasUsed": 2258 + "gasUsed": 2214 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetField", "name": "set dynamic field (1 slot, second dynamic field)", - "gasUsed": 32317 + "gasUsed": 31496 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetField", "name": "get dynamic field (1 slot, second dynamic field)", - "gasUsed": 2260 + "gasUsed": 2216 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetStaticData", "name": "set static record (1 slot)", - "gasUsed": 33148 + "gasUsed": 32328 }, { "file": "test/StoreCoreGas.t.sol", @@ -867,7 +867,7 @@ "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetStaticDataSpanningWords", "name": "set static record (2 slots)", - "gasUsed": 55652 + "gasUsed": 54832 }, { "file": "test/StoreCoreGas.t.sol", @@ -879,13 +879,13 @@ "file": "test/StoreCoreGas.t.sol", "test": "testUpdateInField", "name": "update in field (1 slot, 1 uint32 item)", - "gasUsed": 14090 + "gasUsed": 13227 }, { "file": "test/StoreCoreGas.t.sol", "test": "testUpdateInField", "name": "push to field (2 slots, 6 uint64 items)", - "gasUsed": 14894 + "gasUsed": 14029 }, { "file": "test/StoreHook.t.sol", @@ -933,103 +933,103 @@ "file": "test/tables/Callbacks.t.sol", "test": "testSetAndGet", "name": "Callbacks: set field", - "gasUsed": 57164 + "gasUsed": 56344 }, { "file": "test/tables/Callbacks.t.sol", "test": "testSetAndGet", "name": "Callbacks: get field (warm)", - "gasUsed": 3732 + "gasUsed": 2912 }, { "file": "test/tables/Callbacks.t.sol", "test": "testSetAndGet", "name": "Callbacks: push 1 element", - "gasUsed": 36119 + "gasUsed": 35254 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testOneSlot", "name": "StoreHooks: set field with one elements (cold)", - "gasUsed": 59162 + "gasUsed": 58342 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: set field (cold)", - "gasUsed": 59162 + "gasUsed": 58342 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: get field (warm)", - "gasUsed": 3716 + "gasUsed": 2896 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: push 1 element (cold)", - "gasUsed": 16205 + "gasUsed": 15341 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: pop 1 element (warm)", - "gasUsed": 12760 + "gasUsed": 11896 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: push 1 element (warm)", - "gasUsed": 14231 + "gasUsed": 13367 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: update 1 element (warm)", - "gasUsed": 35329 + "gasUsed": 34465 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: delete record (warm)", - "gasUsed": 8113 + "gasUsed": 7293 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: set field (warm)", - "gasUsed": 31324 + "gasUsed": 30504 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testThreeSlots", "name": "StoreHooks: set field with three elements (cold)", - "gasUsed": 81853 + "gasUsed": 81033 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testTwoSlots", "name": "StoreHooks: set field with two elements (cold)", - "gasUsed": 81764 + "gasUsed": 80944 }, { "file": "test/tables/StoreHooksColdLoad.t.sol", "test": "testDelete", "name": "StoreHooks: delete record (cold)", - "gasUsed": 16978 + "gasUsed": 16158 }, { "file": "test/tables/StoreHooksColdLoad.t.sol", "test": "testGet", "name": "StoreHooks: get field (cold)", - "gasUsed": 9713 + "gasUsed": 8893 }, { "file": "test/tables/StoreHooksColdLoad.t.sol", "test": "testGetItem", "name": "StoreHooks: get 1 element (cold)", - "gasUsed": 6440 + "gasUsed": 6521 }, { "file": "test/tables/StoreHooksColdLoad.t.sol", @@ -1041,13 +1041,13 @@ "file": "test/tables/StoreHooksColdLoad.t.sol", "test": "testPop", "name": "StoreHooks: pop 1 element (cold)", - "gasUsed": 23246 + "gasUsed": 22382 }, { "file": "test/tables/StoreHooksColdLoad.t.sol", "test": "testUpdate", "name": "StoreHooks: update 1 element (cold)", - "gasUsed": 25382 + "gasUsed": 24518 }, { "file": "test/tightcoder/DecodeSlice.t.sol", @@ -1101,13 +1101,13 @@ "file": "test/Vector2.t.sol", "test": "testRegisterAndGetFieldLayout", "name": "register Vector2 field layout", - "gasUsed": 413256 + "gasUsed": 411812 }, { "file": "test/Vector2.t.sol", "test": "testSetAndGet", "name": "set Vector2 record", - "gasUsed": 34051 + "gasUsed": 33231 }, { "file": "test/Vector2.t.sol", diff --git a/packages/store/src/IStore.sol b/packages/store/src/IStore.sol index 95bf0e301f..052195b0bc 100644 --- a/packages/store/src/IStore.sol +++ b/packages/store/src/IStore.sol @@ -14,14 +14,18 @@ interface IStoreRead { function getKeySchema(bytes32 tableId) external view returns (Schema keySchema); - // Get full record (including full array) + /** + * Get full record (all fields, static and dynamic data) for the given tableId and key tuple, with the given value field layout + */ function getRecord( bytes32 tableId, bytes32[] calldata keyTuple, FieldLayout fieldLayout ) external view returns (bytes memory data); - // Get partial data at schema index + /** + * Get a single field from the given tableId and key tuple, with the given value field layout + */ function getField( bytes32 tableId, bytes32[] calldata keyTuple, @@ -29,7 +33,31 @@ interface IStoreRead { FieldLayout fieldLayout ) external view returns (bytes memory data); - // Get field length at schema index + /** + * Get a single static field from the given tableId and key tuple, with the given value field layout. + * Note: the field value is left-aligned in the returned bytes32, the rest of the word is not zeroed out. + * Consumers are expected to truncate the returned value as needed. + */ + function getStaticField( + bytes32 tableId, + bytes32[] calldata keyTuple, + uint8 fieldIndex, + FieldLayout fieldLayout + ) external view returns (bytes32); + + /** + * Get a single dynamic field from the given tableId and key tuple at the given dynamic field index. + * (Dynamic field index = field index - number of static fields) + */ + function getDynamicField( + bytes32 tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex + ) external view returns (bytes memory); + + /** + * Get the byte length of a single field from the given tableId and key tuple, with the given value field layout + */ function getFieldLength( bytes32 tableId, bytes32[] memory keyTuple, @@ -37,7 +65,10 @@ interface IStoreRead { FieldLayout fieldLayout ) external view returns (uint256); - // Get start:end slice of the field at schema index + /** + * Get a byte slice (including start, excluding end) of a single dynamic field from the given tableId and key tuple, with the given value field layout. + * The slice is unchecked and will return invalid data if `start`:`end` overflow. + */ function getFieldSlice( bytes32 tableId, bytes32[] memory keyTuple, diff --git a/packages/store/src/StoreCore.sol b/packages/store/src/StoreCore.sol index f752e7e7c9..684c834c42 100644 --- a/packages/store/src/StoreCore.sol +++ b/packages/store/src/StoreCore.sol @@ -358,7 +358,7 @@ library StoreCore { // TODO add push-specific hook to avoid the storage read? (https://github.com/latticexyz/mud/issues/444) bytes memory fullData = abi.encodePacked( - StoreCoreInternal._getDynamicField(tableId, keyTuple, fieldIndex, fieldLayout), + getDynamicField(tableId, keyTuple, fieldIndex - uint8(fieldLayout.numStaticFields())), dataToPush ); @@ -399,7 +399,7 @@ library StoreCore { // TODO add pop-specific hook to avoid the storage read? (https://github.com/latticexyz/mud/issues/444) bytes memory fullData; { - bytes memory oldData = StoreCoreInternal._getDynamicField(tableId, keyTuple, fieldIndex, fieldLayout); + bytes memory oldData = getDynamicField(tableId, keyTuple, fieldIndex - uint8(fieldLayout.numStaticFields())); fullData = SliceLib.getSubslice(oldData, 0, oldData.length - byteLengthToPop).toBytes(); } @@ -447,7 +447,7 @@ library StoreCore { // TODO add setItem-specific hook to avoid the storage read? (https://github.com/latticexyz/mud/issues/444) bytes memory fullData; { - bytes memory oldData = StoreCoreInternal._getDynamicField(tableId, keyTuple, fieldIndex, fieldLayout); + bytes memory oldData = getDynamicField(tableId, keyTuple, fieldIndex - uint8(fieldLayout.numStaticFields())); fullData = abi.encodePacked( SliceLib.getSubslice(oldData, 0, startByteIndex).toBytes(), dataToSet, @@ -572,12 +572,51 @@ library StoreCore { FieldLayout fieldLayout ) internal view returns (bytes memory) { if (fieldIndex < fieldLayout.numStaticFields()) { - return StoreCoreInternal._getStaticField(tableId, keyTuple, fieldIndex, fieldLayout); + return StoreCoreInternal._getStaticFieldBytes(tableId, keyTuple, fieldIndex, fieldLayout); } else { - return StoreCoreInternal._getDynamicField(tableId, keyTuple, fieldIndex, fieldLayout); + return getDynamicField(tableId, keyTuple, fieldIndex - uint8(fieldLayout.numStaticFields())); } } + /** + * Get a single static field from the given tableId and key tuple, with the given value field layout. + * Note: the field value is left-aligned in the returned bytes32, the rest of the word is not zeroed out. + * Consumers are expected to truncate the returned value as needed. + */ + function getStaticField( + bytes32 tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + FieldLayout fieldLayout + ) internal view returns (bytes32) { + // Get the length, storage location and offset of the static field + // and load the data from storage + return + Storage.loadField({ + storagePointer: StoreCoreInternal._getStaticDataLocation(tableId, keyTuple), + length: fieldLayout.atIndex(fieldIndex), + offset: StoreCoreInternal._getStaticDataOffset(fieldLayout, fieldIndex) + }); + } + + /** + * Get a single dynamic field from the given tableId and key tuple, with the given value field layout + */ + function getDynamicField( + bytes32 tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex + ) internal view returns (bytes memory) { + // Get the storage location of the dynamic field + // and load the data from storage + return + Storage.load({ + storagePointer: StoreCoreInternal._getDynamicDataLocation(tableId, keyTuple, dynamicFieldIndex), + length: StoreCoreInternal._loadEncodedDynamicDataLength(tableId, keyTuple).atIndex(dynamicFieldIndex), + offset: 0 + }); + } + /** * Get the byte length of a single field from the given tableId and key tuple, with the given value field layout */ @@ -848,38 +887,23 @@ library StoreCoreInternal { } /** - * Get a single static field from the given tableId and key tuple, with the given value field layout + * Get a single static field from the given tableId and key tuple, with the given value field layout. + * Returns dynamic bytes memory in the size of the field. */ - function _getStaticField( + function _getStaticFieldBytes( bytes32 tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout ) internal view returns (bytes memory) { // Get the length, storage location and offset of the static field - uint256 staticByteLength = fieldLayout.atIndex(fieldIndex); - uint256 location = _getStaticDataLocation(tableId, keyTuple); - uint256 offset = _getStaticDataOffset(fieldLayout, fieldIndex); - - // Load the data from storage - return Storage.load({ storagePointer: location, length: staticByteLength, offset: offset }); - } - - /** - * Get a single dynamic field from the given tableId and key tuple, with the given value field layout - */ - function _getDynamicField( - bytes32 tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex, - FieldLayout fieldLayout - ) internal view returns (bytes memory) { - // Get the length and storage location of the dynamic field - uint8 dynamicSchemaIndex = fieldIndex - uint8(fieldLayout.numStaticFields()); - uint256 location = _getDynamicDataLocation(tableId, keyTuple, dynamicSchemaIndex); - uint256 dataLength = _loadEncodedDynamicDataLength(tableId, keyTuple).atIndex(dynamicSchemaIndex); - - return Storage.load({ storagePointer: location, length: dataLength, offset: 0 }); + // and load the data from storage + return + Storage.load({ + storagePointer: StoreCoreInternal._getStaticDataLocation(tableId, keyTuple), + length: fieldLayout.atIndex(fieldIndex), + offset: StoreCoreInternal._getStaticDataOffset(fieldLayout, fieldIndex) + }); } /************************************************************************ diff --git a/packages/store/src/StoreRead.sol b/packages/store/src/StoreRead.sol index 92125f5bd0..3017f1510f 100644 --- a/packages/store/src/StoreRead.sol +++ b/packages/store/src/StoreRead.sol @@ -19,7 +19,6 @@ contract StoreRead is IStoreRead { keySchema = StoreCore.getKeySchema(tableId); } - // Get full record (static and dynamic data) function getRecord( bytes32 tableId, bytes32[] calldata keyTuple, @@ -28,7 +27,6 @@ contract StoreRead is IStoreRead { data = StoreCore.getRecord(tableId, keyTuple, fieldLayout); } - // Get partial data at schema index function getField( bytes32 tableId, bytes32[] calldata keyTuple, @@ -38,6 +36,23 @@ contract StoreRead is IStoreRead { data = StoreCore.getField(tableId, keyTuple, fieldIndex, fieldLayout); } + function getStaticField( + bytes32 tableId, + bytes32[] calldata keyTuple, + uint8 fieldIndex, + FieldLayout fieldLayout + ) public view virtual returns (bytes32 data) { + data = StoreCore.getStaticField(tableId, keyTuple, fieldIndex, fieldLayout); + } + + function getDynamicField( + bytes32 tableId, + bytes32[] calldata keyTuple, + uint8 dynamicFieldIndex + ) public view virtual returns (bytes memory data) { + data = StoreCore.getDynamicField(tableId, keyTuple, dynamicFieldIndex); + } + function getFieldLength( bytes32 tableId, bytes32[] memory keyTuple, diff --git a/packages/store/src/StoreSwitch.sol b/packages/store/src/StoreSwitch.sol index ed3e243b0e..412d34bc5b 100644 --- a/packages/store/src/StoreSwitch.sol +++ b/packages/store/src/StoreSwitch.sol @@ -244,6 +244,33 @@ library StoreSwitch { } } + function getStaticField( + bytes32 tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + FieldLayout fieldLayout + ) internal view returns (bytes32) { + address _storeAddress = getStoreAddress(); + if (_storeAddress == address(this)) { + return StoreCore.getStaticField(tableId, keyTuple, fieldIndex, fieldLayout); + } else { + return IStore(_storeAddress).getStaticField(tableId, keyTuple, fieldIndex, fieldLayout); + } + } + + function getDynamicField( + bytes32 tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex + ) internal view returns (bytes memory) { + address _storeAddress = getStoreAddress(); + if (_storeAddress == address(this)) { + return StoreCore.getDynamicField(tableId, keyTuple, dynamicFieldIndex); + } else { + return IStore(_storeAddress).getDynamicField(tableId, keyTuple, dynamicFieldIndex); + } + } + function getFieldLength( bytes32 tableId, bytes32[] memory keyTuple, diff --git a/packages/store/src/codegen/tables/Callbacks.sol b/packages/store/src/codegen/tables/Callbacks.sol index 8d9b02a251..cbe5d850c5 100644 --- a/packages/store/src/codegen/tables/Callbacks.sol +++ b/packages/store/src/codegen/tables/Callbacks.sol @@ -74,7 +74,7 @@ library Callbacks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes24()); } @@ -83,7 +83,7 @@ library Callbacks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes24()); } @@ -142,7 +142,7 @@ library Callbacks { _index * 24, (_index + 1) * 24 ); - return (Bytes.slice24(_blob, 0)); + return (bytes24(_blob)); } } @@ -156,7 +156,7 @@ library Callbacks { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, _fieldLayout, _index * 24, (_index + 1) * 24); - return (Bytes.slice24(_blob, 0)); + return (bytes24(_blob)); } } diff --git a/packages/store/src/codegen/tables/Hooks.sol b/packages/store/src/codegen/tables/Hooks.sol index 3332c321e4..d01e5b05e0 100644 --- a/packages/store/src/codegen/tables/Hooks.sol +++ b/packages/store/src/codegen/tables/Hooks.sol @@ -71,7 +71,7 @@ library Hooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } @@ -80,7 +80,7 @@ library Hooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } @@ -139,7 +139,7 @@ library Hooks { _index * 21, (_index + 1) * 21 ); - return (Bytes.slice21(_blob, 0)); + return (bytes21(_blob)); } } @@ -153,7 +153,7 @@ library Hooks { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, _fieldLayout, _index * 21, (_index + 1) * 21); - return (Bytes.slice21(_blob, 0)); + return (bytes21(_blob)); } } diff --git a/packages/store/src/codegen/tables/KeyEncoding.sol b/packages/store/src/codegen/tables/KeyEncoding.sol index b23620d632..78d705bf2d 100644 --- a/packages/store/src/codegen/tables/KeyEncoding.sol +++ b/packages/store/src/codegen/tables/KeyEncoding.sol @@ -99,8 +99,8 @@ library KeyEncoding { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); } /** Get value (using the specified store) */ @@ -121,8 +121,8 @@ library KeyEncoding { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); } /** Set value */ diff --git a/packages/store/src/codegen/tables/Mixed.sol b/packages/store/src/codegen/tables/Mixed.sol index d6060d0c95..13f6d12dfd 100644 --- a/packages/store/src/codegen/tables/Mixed.sol +++ b/packages/store/src/codegen/tables/Mixed.sol @@ -87,8 +87,8 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(Bytes.slice4(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); } /** Get u32 (using the specified store) */ @@ -96,8 +96,8 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(Bytes.slice4(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); } /** Set u32 */ @@ -121,8 +121,8 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (uint128(Bytes.slice16(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (uint128(bytes16(_blob))); } /** Get u128 (using the specified store) */ @@ -130,8 +130,8 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (uint128(Bytes.slice16(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (uint128(bytes16(_blob))); } /** Set u128 */ @@ -155,7 +155,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -164,7 +164,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -223,7 +223,7 @@ library Mixed { _index * 4, (_index + 1) * 4 ); - return (uint32(Bytes.slice4(_blob, 0))); + return (uint32(bytes4(_blob))); } } @@ -237,7 +237,7 @@ library Mixed { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 2, _fieldLayout, _index * 4, (_index + 1) * 4); - return (uint32(Bytes.slice4(_blob, 0))); + return (uint32(bytes4(_blob))); } } @@ -304,7 +304,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 1); return (string(_blob)); } @@ -313,7 +313,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 3, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 1); return (string(_blob)); } diff --git a/packages/store/src/codegen/tables/StoreHooks.sol b/packages/store/src/codegen/tables/StoreHooks.sol index e997c1a4f9..a2632c0b20 100644 --- a/packages/store/src/codegen/tables/StoreHooks.sol +++ b/packages/store/src/codegen/tables/StoreHooks.sol @@ -74,7 +74,7 @@ library StoreHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } @@ -83,7 +83,7 @@ library StoreHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } @@ -142,7 +142,7 @@ library StoreHooks { _index * 21, (_index + 1) * 21 ); - return (Bytes.slice21(_blob, 0)); + return (bytes21(_blob)); } } @@ -156,7 +156,7 @@ library StoreHooks { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, _fieldLayout, _index * 21, (_index + 1) * 21); - return (Bytes.slice21(_blob, 0)); + return (bytes21(_blob)); } } diff --git a/packages/store/src/codegen/tables/Tables.sol b/packages/store/src/codegen/tables/Tables.sol index b3e553b585..6204d3de73 100644 --- a/packages/store/src/codegen/tables/Tables.sol +++ b/packages/store/src/codegen/tables/Tables.sol @@ -90,8 +90,8 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (Bytes.slice32(_blob, 0)); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); } /** Get fieldLayout (using the specified store) */ @@ -99,8 +99,8 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (Bytes.slice32(_blob, 0)); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); } /** Set fieldLayout */ @@ -124,8 +124,8 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (Bytes.slice32(_blob, 0)); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (bytes32(_blob)); } /** Get keySchema (using the specified store) */ @@ -133,8 +133,8 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (Bytes.slice32(_blob, 0)); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (bytes32(_blob)); } /** Set keySchema */ @@ -158,8 +158,8 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, _fieldLayout); - return (Bytes.slice32(_blob, 0)); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); + return (bytes32(_blob)); } /** Get valueSchema (using the specified store) */ @@ -167,8 +167,8 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, _fieldLayout); - return (Bytes.slice32(_blob, 0)); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); + return (bytes32(_blob)); } /** Set valueSchema */ @@ -192,7 +192,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); return (bytes(_blob)); } @@ -204,7 +204,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 3, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); return (bytes(_blob)); } @@ -348,7 +348,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 4, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 1); return (bytes(_blob)); } @@ -360,7 +360,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 4, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 1); return (bytes(_blob)); } diff --git a/packages/store/src/codegen/tables/Vector2.sol b/packages/store/src/codegen/tables/Vector2.sol index 9c1f7cbea1..d7694660eb 100644 --- a/packages/store/src/codegen/tables/Vector2.sol +++ b/packages/store/src/codegen/tables/Vector2.sol @@ -81,8 +81,8 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(Bytes.slice4(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); } /** Get x (using the specified store) */ @@ -90,8 +90,8 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(Bytes.slice4(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); } /** Set x */ @@ -115,8 +115,8 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (uint32(Bytes.slice4(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (uint32(bytes4(_blob))); } /** Get y (using the specified store) */ @@ -124,8 +124,8 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (uint32(Bytes.slice4(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (uint32(bytes4(_blob))); } /** Set y */ diff --git a/packages/store/ts/codegen/field.ts b/packages/store/ts/codegen/field.ts index 5d1c3bdf81..e63ad43f2d 100644 --- a/packages/store/ts/codegen/field.ts +++ b/packages/store/ts/codegen/field.ts @@ -13,6 +13,8 @@ export function renderFieldMethods(options: RenderTableOptions) { let result = ""; for (const [schemaIndex, field] of options.fields.entries()) { + // For dynamic fields, compute the field index relative to the end of the static fields + const _typedFieldName = `${field.typeWithLocation} ${field.name}`; result += renderWithStore( @@ -25,7 +27,20 @@ export function renderFieldMethods(options: RenderTableOptions) { _typedKeyArgs, ])}) internal view returns (${_typedFieldName}) { ${_keyTupleDefinition} - bytes memory _blob = ${_store}.getField(_tableId, _keyTuple, ${schemaIndex}, _fieldLayout); + ${ + field.isDynamic + ? `bytes memory _blob = ${_store}.getDynamicField( + _tableId, + _keyTuple, + ${schemaIndex - options.staticFields.length} + );` + : `bytes32 _blob = ${_store}.getStaticField( + _tableId, + _keyTuple, + ${schemaIndex}, + _fieldLayout + );` + } return ${renderDecodeFieldSingle(field)}; } ` @@ -174,20 +189,26 @@ export function renderEncodeFieldSingle(field: RenderField) { } export function renderDecodeValueType(field: RenderType, offset: number) { - const { staticByteLength, internalTypeId } = field; + const { staticByteLength } = field; const innerSlice = `Bytes.slice${staticByteLength}(_blob, ${offset})`; + + return renderCastStaticBytesToType(field, innerSlice); +} + +function renderCastStaticBytesToType(field: RenderType, staticBytes: string) { + const { staticByteLength, internalTypeId } = field; const bits = staticByteLength * 8; let result; if (internalTypeId.match(/^uint\d{1,3}$/) || internalTypeId === "address") { - result = `${internalTypeId}(${innerSlice})`; + result = `${internalTypeId}(${staticBytes})`; } else if (internalTypeId.match(/^int\d{1,3}$/)) { - result = `${internalTypeId}(uint${bits}(${innerSlice}))`; + result = `${internalTypeId}(uint${bits}(${staticBytes}))`; } else if (internalTypeId.match(/^bytes\d{1,2}$/)) { - result = innerSlice; + result = staticBytes; } else if (internalTypeId === "bool") { - result = `_toBool(uint8(${innerSlice}))`; + result = `_toBool(uint8(${staticBytes}))`; } else { throw new Error(`Unknown value type id ${internalTypeId}`); } @@ -233,6 +254,6 @@ function renderDecodeFieldSingle(field: RenderField) { // bytes/string return `${field.typeWrap}(${field.internalTypeId}(_blob))`; } else { - return renderDecodeValueType(field, 0); + return renderCastStaticBytesToType(field, `bytes${field.staticByteLength}(_blob)`); } } diff --git a/packages/world/gas-report.json b/packages/world/gas-report.json index 7775787446..1568db80f3 100644 --- a/packages/world/gas-report.json +++ b/packages/world/gas-report.json @@ -3,31 +3,31 @@ "file": "test/AccessControl.t.sol", "test": "testAccessControl", "name": "AccessControl: hasAccess (cold)", - "gasUsed": 10667 + "gasUsed": 9514 }, { "file": "test/AccessControl.t.sol", "test": "testAccessControl", "name": "AccessControl: hasAccess (warm, namespace only)", - "gasUsed": 2408 + "gasUsed": 1829 }, { "file": "test/AccessControl.t.sol", "test": "testAccessControl", "name": "AccessControl: hasAccess (warm)", - "gasUsed": 4689 + "gasUsed": 3534 }, { "file": "test/AccessControl.t.sol", "test": "testRequireAccess", "name": "AccessControl: requireAccess (cold)", - "gasUsed": 10709 + "gasUsed": 9556 }, { "file": "test/AccessControl.t.sol", "test": "testRequireAccess", "name": "AccessControl: requireAccess (warm)", - "gasUsed": 4713 + "gasUsed": 3559 }, { "file": "test/AccessControl.t.sol", @@ -39,73 +39,73 @@ "file": "test/KeysInTableModule.t.sol", "test": "testInstallComposite", "name": "install keys in table module", - "gasUsed": 1443420 + "gasUsed": 1425069 }, { "file": "test/KeysInTableModule.t.sol", "test": "testInstallGas", "name": "install keys in table module", - "gasUsed": 1443420 + "gasUsed": 1425069 }, { "file": "test/KeysInTableModule.t.sol", "test": "testInstallGas", "name": "set a record on a table with keysInTableModule installed", - "gasUsed": 167906 + "gasUsed": 161043 }, { "file": "test/KeysInTableModule.t.sol", "test": "testInstallSingleton", "name": "install keys in table module", - "gasUsed": 1443420 + "gasUsed": 1425069 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookCompositeGas", "name": "install keys in table module", - "gasUsed": 1443420 + "gasUsed": 1425069 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookCompositeGas", "name": "change a composite record on a table with keysInTableModule installed", - "gasUsed": 25326 + "gasUsed": 22513 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookCompositeGas", "name": "delete a composite record on a table with keysInTableModule installed", - "gasUsed": 195723 + "gasUsed": 178377 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookGas", "name": "install keys in table module", - "gasUsed": 1443420 + "gasUsed": 1425069 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookGas", "name": "change a record on a table with keysInTableModule installed", - "gasUsed": 24049 + "gasUsed": 21235 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookGas", "name": "delete a record on a table with keysInTableModule installed", - "gasUsed": 101263 + "gasUsed": 91846 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testGetKeysWithValueGas", "name": "install keys with value module", - "gasUsed": 674478 + "gasUsed": 661189 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testGetKeysWithValueGas", "name": "Get list of keys with a given value", - "gasUsed": 6170 + "gasUsed": 5351 }, { "file": "test/KeysWithValueModule.t.sol", @@ -117,264 +117,264 @@ "file": "test/KeysWithValueModule.t.sol", "test": "testInstall", "name": "install keys with value module", - "gasUsed": 674478 + "gasUsed": 661189 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testInstall", "name": "set a record on a table with KeysWithValueModule installed", - "gasUsed": 142864 + "gasUsed": 136579 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testSetAndDeleteRecordHook", "name": "install keys with value module", - "gasUsed": 674478 + "gasUsed": 661189 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testSetAndDeleteRecordHook", "name": "change a record on a table with KeysWithValueModule installed", - "gasUsed": 112442 + "gasUsed": 106157 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testSetAndDeleteRecordHook", "name": "delete a record on a table with KeysWithValueModule installed", - "gasUsed": 38443 + "gasUsed": 34216 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testSetField", "name": "install keys with value module", - "gasUsed": 674478 + "gasUsed": 661189 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testSetField", "name": "set a field on a table with KeysWithValueModule installed", - "gasUsed": 147478 + "gasUsed": 141193 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testSetField", "name": "change a field on a table with KeysWithValueModule installed", - "gasUsed": 112237 + "gasUsed": 105952 }, { "file": "test/query.t.sol", "test": "testCombinedHasHasValueNotQuery", "name": "CombinedHasHasValueNotQuery", - "gasUsed": 109103 + "gasUsed": 103370 }, { "file": "test/query.t.sol", "test": "testCombinedHasHasValueQuery", "name": "CombinedHasHasValueQuery", - "gasUsed": 55818 + "gasUsed": 52259 }, { "file": "test/query.t.sol", "test": "testCombinedHasNotQuery", "name": "CombinedHasNotQuery", - "gasUsed": 135801 + "gasUsed": 130426 }, { "file": "test/query.t.sol", "test": "testCombinedHasQuery", "name": "CombinedHasQuery", - "gasUsed": 87885 + "gasUsed": 83357 }, { "file": "test/query.t.sol", "test": "testCombinedHasValueNotQuery", "name": "CombinedHasValueNotQuery", - "gasUsed": 88206 + "gasUsed": 84121 }, { "file": "test/query.t.sol", "test": "testCombinedHasValueQuery", "name": "CombinedHasValueQuery", - "gasUsed": 16614 + "gasUsed": 14966 }, { "file": "test/query.t.sol", "test": "testHasQuery", "name": "HasQuery", - "gasUsed": 19725 + "gasUsed": 18578 }, { "file": "test/query.t.sol", "test": "testHasQuery1000Keys", "name": "HasQuery with 1000 keys", - "gasUsed": 5843418 + "gasUsed": 5902151 }, { "file": "test/query.t.sol", "test": "testHasQuery100Keys", "name": "HasQuery with 100 keys", - "gasUsed": 546112 + "gasUsed": 550845 }, { "file": "test/query.t.sol", "test": "testHasValueQuery", "name": "HasValueQuery", - "gasUsed": 7978 + "gasUsed": 7154 }, { "file": "test/query.t.sol", "test": "testNotValueQuery", "name": "NotValueQuery", - "gasUsed": 49414 + "gasUsed": 45855 }, { "file": "test/StandardDelegationsModule.t.sol", "test": "testCallFromCallboundDelegation", "name": "register a callbound delegation", - "gasUsed": 118637 + "gasUsed": 116017 }, { "file": "test/StandardDelegationsModule.t.sol", "test": "testCallFromCallboundDelegation", "name": "call a system via a callbound delegation", - "gasUsed": 37881 + "gasUsed": 35016 }, { "file": "test/StandardDelegationsModule.t.sol", "test": "testCallFromTimeboundDelegation", "name": "register a timebound delegation", - "gasUsed": 112991 + "gasUsed": 110371 }, { "file": "test/StandardDelegationsModule.t.sol", "test": "testCallFromTimeboundDelegation", "name": "call a system via a timebound delegation", - "gasUsed": 29993 + "gasUsed": 27946 }, { "file": "test/UniqueEntityModule.t.sol", "test": "testInstall", "name": "install unique entity module", - "gasUsed": 712299 + "gasUsed": 693352 }, { "file": "test/UniqueEntityModule.t.sol", "test": "testInstall", "name": "get a unique entity nonce (non-root module)", - "gasUsed": 56214 + "gasUsed": 52577 }, { "file": "test/UniqueEntityModule.t.sol", "test": "testInstallRoot", "name": "installRoot unique entity module", - "gasUsed": 699545 + "gasUsed": 680858 }, { "file": "test/UniqueEntityModule.t.sol", "test": "testInstallRoot", "name": "get a unique entity nonce (root module)", - "gasUsed": 56214 + "gasUsed": 52577 }, { "file": "test/World.t.sol", "test": "testCall", "name": "call a system via the World", - "gasUsed": 14602 + "gasUsed": 13196 }, { "file": "test/World.t.sol", "test": "testCallFromUnlimitedDelegation", "name": "register an unlimited delegation", - "gasUsed": 50997 + "gasUsed": 49345 }, { "file": "test/World.t.sol", "test": "testCallFromUnlimitedDelegation", "name": "call a system via an unlimited delegation", - "gasUsed": 15010 + "gasUsed": 13590 }, { "file": "test/World.t.sol", "test": "testDeleteRecord", "name": "Delete record", - "gasUsed": 10744 + "gasUsed": 9343 }, { "file": "test/World.t.sol", "test": "testPushToField", "name": "Push data to the table", - "gasUsed": 90191 + "gasUsed": 88725 }, { "file": "test/World.t.sol", "test": "testRegisterFallbackSystem", "name": "Register a fallback system", - "gasUsed": 63739 + "gasUsed": 60882 }, { "file": "test/World.t.sol", "test": "testRegisterFallbackSystem", "name": "Register a root fallback system", - "gasUsed": 56989 + "gasUsed": 54136 }, { "file": "test/World.t.sol", "test": "testRegisterFunctionSelector", "name": "Register a function selector", - "gasUsed": 84333 + "gasUsed": 81476 }, { "file": "test/World.t.sol", "test": "testRegisterNamespace", "name": "Register a new namespace", - "gasUsed": 131214 + "gasUsed": 127343 }, { "file": "test/World.t.sol", "test": "testRegisterRootFunctionSelector", "name": "Register a root function selector", - "gasUsed": 78907 + "gasUsed": 76054 }, { "file": "test/World.t.sol", "test": "testRegisterTable", "name": "Register a new table in the namespace", - "gasUsed": 655916 + "gasUsed": 648531 }, { "file": "test/World.t.sol", "test": "testSetField", "name": "Write data to a table field", - "gasUsed": 39031 + "gasUsed": 37631 }, { "file": "test/World.t.sol", "test": "testSetRecord", "name": "Write data to the table", - "gasUsed": 37025 + "gasUsed": 35625 }, { "file": "test/WorldDynamicUpdate.t.sol", "test": "testPopFromField", "name": "pop 1 address (cold)", - "gasUsed": 29349 + "gasUsed": 27929 }, { "file": "test/WorldDynamicUpdate.t.sol", "test": "testPopFromField", "name": "pop 1 address (warm)", - "gasUsed": 16462 + "gasUsed": 15042 }, { "file": "test/WorldDynamicUpdate.t.sol", "test": "testUpdateInField", "name": "updateInField 1 item (cold)", - "gasUsed": 32728 + "gasUsed": 31284 }, { "file": "test/WorldDynamicUpdate.t.sol", "test": "testUpdateInField", "name": "updateInField 1 item (warm)", - "gasUsed": 19933 + "gasUsed": 18489 } ] diff --git a/packages/world/src/modules/core/tables/Balances.sol b/packages/world/src/modules/core/tables/Balances.sol index ac0cada199..280b77ae71 100644 --- a/packages/world/src/modules/core/tables/Balances.sol +++ b/packages/world/src/modules/core/tables/Balances.sol @@ -74,8 +74,8 @@ library Balances { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(Bytes.slice32(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); } /** Get balance (using the specified store) */ @@ -83,8 +83,8 @@ library Balances { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(Bytes.slice32(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); } /** Set balance */ diff --git a/packages/world/src/modules/core/tables/FunctionSelectors.sol b/packages/world/src/modules/core/tables/FunctionSelectors.sol index f679ed4e18..28ee846849 100644 --- a/packages/world/src/modules/core/tables/FunctionSelectors.sol +++ b/packages/world/src/modules/core/tables/FunctionSelectors.sol @@ -76,8 +76,8 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (Bytes.slice32(_blob, 0)); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); } /** Get resourceSelector (using the specified store) */ @@ -88,8 +88,8 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (Bytes.slice32(_blob, 0)); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); } /** Set resourceSelector */ @@ -113,8 +113,8 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (Bytes.slice4(_blob, 0)); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (bytes4(_blob)); } /** Get systemFunctionSelector (using the specified store) */ @@ -125,8 +125,8 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (Bytes.slice4(_blob, 0)); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (bytes4(_blob)); } /** Set systemFunctionSelector */ diff --git a/packages/world/src/modules/core/tables/ResourceType.sol b/packages/world/src/modules/core/tables/ResourceType.sol index 1d56109aa6..4dd272567b 100644 --- a/packages/world/src/modules/core/tables/ResourceType.sol +++ b/packages/world/src/modules/core/tables/ResourceType.sol @@ -77,8 +77,8 @@ library ResourceType { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return Resource(uint8(Bytes.slice1(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return Resource(uint8(bytes1(_blob))); } /** Get resourceType (using the specified store) */ @@ -86,8 +86,8 @@ library ResourceType { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return Resource(uint8(Bytes.slice1(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return Resource(uint8(bytes1(_blob))); } /** Set resourceType */ diff --git a/packages/world/src/modules/core/tables/SystemHooks.sol b/packages/world/src/modules/core/tables/SystemHooks.sol index 8ea6e2b31b..1314088f74 100644 --- a/packages/world/src/modules/core/tables/SystemHooks.sol +++ b/packages/world/src/modules/core/tables/SystemHooks.sol @@ -74,7 +74,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } @@ -83,7 +83,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } @@ -142,7 +142,7 @@ library SystemHooks { _index * 21, (_index + 1) * 21 ); - return (Bytes.slice21(_blob, 0)); + return (bytes21(_blob)); } } @@ -156,7 +156,7 @@ library SystemHooks { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, _fieldLayout, _index * 21, (_index + 1) * 21); - return (Bytes.slice21(_blob, 0)); + return (bytes21(_blob)); } } diff --git a/packages/world/src/modules/core/tables/SystemRegistry.sol b/packages/world/src/modules/core/tables/SystemRegistry.sol index 4a83e64bec..e27e2fdd95 100644 --- a/packages/world/src/modules/core/tables/SystemRegistry.sol +++ b/packages/world/src/modules/core/tables/SystemRegistry.sol @@ -74,8 +74,8 @@ library SystemRegistry { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(system))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (Bytes.slice32(_blob, 0)); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); } /** Get resourceSelector (using the specified store) */ @@ -83,8 +83,8 @@ library SystemRegistry { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(system))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (Bytes.slice32(_blob, 0)); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); } /** Set resourceSelector */ diff --git a/packages/world/src/modules/core/tables/Systems.sol b/packages/world/src/modules/core/tables/Systems.sol index 1316f4331a..edffc1d222 100644 --- a/packages/world/src/modules/core/tables/Systems.sol +++ b/packages/world/src/modules/core/tables/Systems.sol @@ -76,8 +76,8 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (address(Bytes.slice20(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (address(bytes20(_blob))); } /** Get system (using the specified store) */ @@ -85,8 +85,8 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (address(Bytes.slice20(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (address(bytes20(_blob))); } /** Set system */ @@ -110,8 +110,8 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); } /** Get publicAccess (using the specified store) */ @@ -119,8 +119,8 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); } /** Set publicAccess */ diff --git a/packages/world/src/modules/keysintable/tables/KeysInTable.sol b/packages/world/src/modules/keysintable/tables/KeysInTable.sol index 589642c66c..c18a7915d5 100644 --- a/packages/world/src/modules/keysintable/tables/KeysInTable.sol +++ b/packages/world/src/modules/keysintable/tables/KeysInTable.sol @@ -90,7 +90,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -99,7 +99,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -158,7 +158,7 @@ library KeysInTable { _index * 32, (_index + 1) * 32 ); - return (Bytes.slice32(_blob, 0)); + return (bytes32(_blob)); } } @@ -172,7 +172,7 @@ library KeysInTable { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, _fieldLayout, _index * 32, (_index + 1) * 32); - return (Bytes.slice32(_blob, 0)); + return (bytes32(_blob)); } } @@ -239,7 +239,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 1); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -248,7 +248,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 1); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -307,7 +307,7 @@ library KeysInTable { _index * 32, (_index + 1) * 32 ); - return (Bytes.slice32(_blob, 0)); + return (bytes32(_blob)); } } @@ -321,7 +321,7 @@ library KeysInTable { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 1, _fieldLayout, _index * 32, (_index + 1) * 32); - return (Bytes.slice32(_blob, 0)); + return (bytes32(_blob)); } } @@ -388,7 +388,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 2); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -397,7 +397,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 2); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -456,7 +456,7 @@ library KeysInTable { _index * 32, (_index + 1) * 32 ); - return (Bytes.slice32(_blob, 0)); + return (bytes32(_blob)); } } @@ -470,7 +470,7 @@ library KeysInTable { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 2, _fieldLayout, _index * 32, (_index + 1) * 32); - return (Bytes.slice32(_blob, 0)); + return (bytes32(_blob)); } } @@ -537,7 +537,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 3); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -546,7 +546,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 3, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 3); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -605,7 +605,7 @@ library KeysInTable { _index * 32, (_index + 1) * 32 ); - return (Bytes.slice32(_blob, 0)); + return (bytes32(_blob)); } } @@ -619,7 +619,7 @@ library KeysInTable { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 3, _fieldLayout, _index * 32, (_index + 1) * 32); - return (Bytes.slice32(_blob, 0)); + return (bytes32(_blob)); } } @@ -686,7 +686,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 4, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 4); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -695,7 +695,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 4, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 4); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -754,7 +754,7 @@ library KeysInTable { _index * 32, (_index + 1) * 32 ); - return (Bytes.slice32(_blob, 0)); + return (bytes32(_blob)); } } @@ -768,7 +768,7 @@ library KeysInTable { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 4, _fieldLayout, _index * 32, (_index + 1) * 32); - return (Bytes.slice32(_blob, 0)); + return (bytes32(_blob)); } } diff --git a/packages/world/src/modules/keysintable/tables/UsedKeysIndex.sol b/packages/world/src/modules/keysintable/tables/UsedKeysIndex.sol index a0ebf6dea2..a0ab8dc9fd 100644 --- a/packages/world/src/modules/keysintable/tables/UsedKeysIndex.sol +++ b/packages/world/src/modules/keysintable/tables/UsedKeysIndex.sol @@ -79,8 +79,8 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); } /** Get has (using the specified store) */ @@ -89,8 +89,8 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); } /** Set has */ @@ -117,8 +117,8 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (uint40(Bytes.slice5(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (uint40(bytes5(_blob))); } /** Get index (using the specified store) */ @@ -127,8 +127,8 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (uint40(Bytes.slice5(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (uint40(bytes5(_blob))); } /** Set index */ diff --git a/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol b/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol index 47b0af5076..9255f04f3f 100644 --- a/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol +++ b/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol @@ -71,7 +71,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -84,7 +84,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -143,7 +143,7 @@ library KeysWithValue { _index * 32, (_index + 1) * 32 ); - return (Bytes.slice32(_blob, 0)); + return (bytes32(_blob)); } } @@ -157,7 +157,7 @@ library KeysWithValue { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, _fieldLayout, _index * 32, (_index + 1) * 32); - return (Bytes.slice32(_blob, 0)); + return (bytes32(_blob)); } } diff --git a/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol b/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol index 0cb37a05be..54d2f15682 100644 --- a/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol +++ b/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol @@ -88,8 +88,8 @@ library CallboundDelegations { _keyTuple[2] = resourceSelector; _keyTuple[3] = funcSelectorAndArgsHash; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(Bytes.slice32(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); } /** Get availableCalls (using the specified store) */ @@ -106,8 +106,8 @@ library CallboundDelegations { _keyTuple[2] = resourceSelector; _keyTuple[3] = funcSelectorAndArgsHash; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(Bytes.slice32(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); } /** Set availableCalls */ diff --git a/packages/world/src/modules/std-delegations/tables/TimeboundDelegations.sol b/packages/world/src/modules/std-delegations/tables/TimeboundDelegations.sol index 4fc2762cee..f751ad7f14 100644 --- a/packages/world/src/modules/std-delegations/tables/TimeboundDelegations.sol +++ b/packages/world/src/modules/std-delegations/tables/TimeboundDelegations.sol @@ -77,8 +77,8 @@ library TimeboundDelegations { _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(Bytes.slice32(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); } /** Get maxTimestamp (using the specified store) */ @@ -87,8 +87,8 @@ library TimeboundDelegations { _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(Bytes.slice32(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); } /** Set maxTimestamp */ diff --git a/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol b/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol index a3e4568034..a47b78e150 100644 --- a/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol +++ b/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol @@ -68,16 +68,16 @@ library UniqueEntity { function get(bytes32 _tableId) internal view returns (uint256 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(Bytes.slice32(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); } /** Get value (using the specified store) */ function get(IStore _store, bytes32 _tableId) internal view returns (uint256 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(Bytes.slice32(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); } /** Set value */ diff --git a/packages/world/src/tables/Delegations.sol b/packages/world/src/tables/Delegations.sol index 5bdb511112..2e0378a220 100644 --- a/packages/world/src/tables/Delegations.sol +++ b/packages/world/src/tables/Delegations.sol @@ -77,8 +77,8 @@ library Delegations { _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (Bytes.slice32(_blob, 0)); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); } /** Get delegationControlId (using the specified store) */ @@ -91,8 +91,8 @@ library Delegations { _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (Bytes.slice32(_blob, 0)); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); } /** Set delegationControlId */ diff --git a/packages/world/src/tables/InstalledModules.sol b/packages/world/src/tables/InstalledModules.sol index 637770c6b9..b89b19bb88 100644 --- a/packages/world/src/tables/InstalledModules.sol +++ b/packages/world/src/tables/InstalledModules.sol @@ -77,8 +77,8 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (address(Bytes.slice20(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (address(bytes20(_blob))); } /** Get moduleAddress (using the specified store) */ @@ -87,8 +87,8 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (address(Bytes.slice20(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (address(bytes20(_blob))); } /** Set moduleAddress */ diff --git a/packages/world/src/tables/NamespaceOwner.sol b/packages/world/src/tables/NamespaceOwner.sol index d290e3fcab..10f34300f2 100644 --- a/packages/world/src/tables/NamespaceOwner.sol +++ b/packages/world/src/tables/NamespaceOwner.sol @@ -74,8 +74,8 @@ library NamespaceOwner { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (address(Bytes.slice20(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (address(bytes20(_blob))); } /** Get owner (using the specified store) */ @@ -83,8 +83,8 @@ library NamespaceOwner { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (address(Bytes.slice20(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (address(bytes20(_blob))); } /** Set owner */ diff --git a/packages/world/src/tables/ResourceAccess.sol b/packages/world/src/tables/ResourceAccess.sol index 1e6b75690b..56ce7e7616 100644 --- a/packages/world/src/tables/ResourceAccess.sol +++ b/packages/world/src/tables/ResourceAccess.sol @@ -77,8 +77,8 @@ library ResourceAccess { _keyTuple[0] = resourceSelector; _keyTuple[1] = bytes32(uint256(uint160(caller))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); } /** Get access (using the specified store) */ @@ -87,8 +87,8 @@ library ResourceAccess { _keyTuple[0] = resourceSelector; _keyTuple[1] = bytes32(uint256(uint160(caller))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); } /** Set access */ diff --git a/packages/world/test/tables/AddressArray.sol b/packages/world/test/tables/AddressArray.sol index 8064fad34e..32a0e2131e 100644 --- a/packages/world/test/tables/AddressArray.sol +++ b/packages/world/test/tables/AddressArray.sol @@ -71,7 +71,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); } @@ -80,7 +80,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); } @@ -139,7 +139,7 @@ library AddressArray { _index * 20, (_index + 1) * 20 ); - return (address(Bytes.slice20(_blob, 0))); + return (address(bytes20(_blob))); } } @@ -153,7 +153,7 @@ library AddressArray { unchecked { bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, _fieldLayout, _index * 20, (_index + 1) * 20); - return (address(Bytes.slice20(_blob, 0))); + return (address(bytes20(_blob))); } } diff --git a/packages/world/test/tables/Bool.sol b/packages/world/test/tables/Bool.sol index 001f076745..87b9f6e209 100644 --- a/packages/world/test/tables/Bool.sol +++ b/packages/world/test/tables/Bool.sol @@ -68,16 +68,16 @@ library Bool { function get(bytes32 _tableId) internal view returns (bool value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); } /** Get value (using the specified store) */ function get(IStore _store, bytes32 _tableId) internal view returns (bool value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); } /** Set value */ diff --git a/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol b/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol index 5422d16dad..77ca8cd102 100644 --- a/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol @@ -71,16 +71,16 @@ library Counter { function get() internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(Bytes.slice4(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); } /** Get value (using the specified store) */ function get(IStore _store) internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(Bytes.slice4(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); } /** Set value */ diff --git a/templates/react/packages/contracts/src/codegen/tables/Counter.sol b/templates/react/packages/contracts/src/codegen/tables/Counter.sol index 5422d16dad..77ca8cd102 100644 --- a/templates/react/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/react/packages/contracts/src/codegen/tables/Counter.sol @@ -71,16 +71,16 @@ library Counter { function get() internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(Bytes.slice4(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); } /** Get value (using the specified store) */ function get(IStore _store) internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(Bytes.slice4(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); } /** Set value */ diff --git a/templates/threejs/packages/contracts/src/codegen/tables/Position.sol b/templates/threejs/packages/contracts/src/codegen/tables/Position.sol index 624887fbb2..f757dc4c9f 100644 --- a/templates/threejs/packages/contracts/src/codegen/tables/Position.sol +++ b/templates/threejs/packages/contracts/src/codegen/tables/Position.sol @@ -84,8 +84,8 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (int32(uint32(Bytes.slice4(_blob, 0)))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (int32(uint32(bytes4(_blob)))); } /** Get x (using the specified store) */ @@ -93,8 +93,8 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (int32(uint32(Bytes.slice4(_blob, 0)))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (int32(uint32(bytes4(_blob)))); } /** Set x */ @@ -118,8 +118,8 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (int32(uint32(Bytes.slice4(_blob, 0)))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (int32(uint32(bytes4(_blob)))); } /** Get y (using the specified store) */ @@ -127,8 +127,8 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, _fieldLayout); - return (int32(uint32(Bytes.slice4(_blob, 0)))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (int32(uint32(bytes4(_blob)))); } /** Set y */ @@ -152,8 +152,8 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, _fieldLayout); - return (int32(uint32(Bytes.slice4(_blob, 0)))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); + return (int32(uint32(bytes4(_blob)))); } /** Get z (using the specified store) */ @@ -161,8 +161,8 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, _fieldLayout); - return (int32(uint32(Bytes.slice4(_blob, 0)))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); + return (int32(uint32(bytes4(_blob)))); } /** Set z */ diff --git a/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol b/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol index 5422d16dad..77ca8cd102 100644 --- a/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol @@ -71,16 +71,16 @@ library Counter { function get() internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(Bytes.slice4(_blob, 0))); + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); } /** Get value (using the specified store) */ function get(IStore _store) internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint32(Bytes.slice4(_blob, 0))); + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); } /** Set value */