diff --git a/.changeset/grumpy-files-heal.md b/.changeset/grumpy-files-heal.md new file mode 100644 index 0000000000..1e72cd4b72 --- /dev/null +++ b/.changeset/grumpy-files-heal.md @@ -0,0 +1,28 @@ +--- +"@latticexyz/cli": major +"@latticexyz/protocol-parser": minor +"@latticexyz/store": major +"@latticexyz/world": major +--- + +- Add `FieldLayout`, which is a `bytes32` user-type similar to `Schema`. + + Both `FieldLayout` and `Schema` have the same kind of data in the first 4 bytes. + + - 2 bytes for total length of all static fields + - 1 byte for number of static size fields + - 1 byte for number of dynamic size fields + + But whereas `Schema` has `SchemaType` enum in each of the other 28 bytes, `FieldLayout` has static byte lengths in each of the other 28 bytes. + +- Replace `Schema valueSchema` with `FieldLayout fieldLayout` in Store and World contracts. + + `FieldLayout` is more gas-efficient because it already has lengths, and `Schema` has types which need to be converted to lengths. + +- Add `getFieldLayout` to `IStore` interface. + + There is no `FieldLayout` for keys, only for values, because key byte lengths aren't usually relevant on-chain. You can still use `getKeySchema` if you need key types. + +- Add `fieldLayoutToHex` utility to `protocol-parser` package. + +- Add `constants.sol` for constants shared between `FieldLayout`, `Schema` and `PackedCounter`. diff --git a/e2e/packages/contracts/src/codegen/tables/Multi.sol b/e2e/packages/contracts/src/codegen/tables/Multi.sol index 4a8dda1a71..873f71588f 100644 --- a/e2e/packages/contracts/src/codegen/tables/Multi.sol +++ b/e2e/packages/contracts/src/codegen/tables/Multi.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -26,6 +27,15 @@ struct MultiData { } library Multi { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](2); + _fieldLayout[0] = 32; + _fieldLayout[1] = 1; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](4); @@ -62,14 +72,21 @@ library Multi { fieldNames[1] = "value"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get num */ @@ -80,7 +97,7 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (int256(uint256(Bytes.slice32(_blob, 0)))); } @@ -92,7 +109,7 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (int256(uint256(Bytes.slice32(_blob, 0)))); } @@ -104,7 +121,7 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((num)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((num)), getFieldLayout()); } /** Set num (using the specified store) */ @@ -115,7 +132,7 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((num)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((num)), getFieldLayout()); } /** Get value */ @@ -126,7 +143,7 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -138,7 +155,7 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -150,7 +167,7 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((value)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((value)), getFieldLayout()); } /** Set value (using the specified store) */ @@ -161,7 +178,7 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((value)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((value)), getFieldLayout()); } /** Get the full data */ @@ -172,7 +189,7 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -184,7 +201,7 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -198,7 +215,7 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - StoreSwitch.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using individual values (using the specified store) */ @@ -211,7 +228,7 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - _store.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + _store.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using the data struct */ @@ -224,19 +241,19 @@ library Multi { set(_store, a, b, c, d, _table.num, _table.value); } - /** Decode the tightly packed blob using this table's schema */ + /** Decode the tightly packed blob using this table's field layout */ function decode(bytes memory _blob) internal pure returns (MultiData memory _table) { _table.num = (int256(uint256(Bytes.slice32(_blob, 0)))); _table.value = (_toBool(uint8(Bytes.slice1(_blob, 32)))); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(int256 num, bool value) internal pure returns (bytes memory) { return abi.encodePacked(num, value); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(uint32 a, bool b, uint256 c, int120 d) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](4); _keyTuple[0] = bytes32(uint256(a)); @@ -255,7 +272,7 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -266,7 +283,7 @@ library Multi { _keyTuple[2] = bytes32(uint256(c)); _keyTuple[3] = bytes32(uint256(int256(d))); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/e2e/packages/contracts/src/codegen/tables/Number.sol b/e2e/packages/contracts/src/codegen/tables/Number.sol index a626749183..40ac16b6df 100644 --- a/e2e/packages/contracts/src/codegen/tables/Number.sol +++ b/e2e/packages/contracts/src/codegen/tables/Number.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,14 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Numbe bytes32 constant NumberTableId = _tableId; library Number { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 4; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -49,14 +58,21 @@ library Number { fieldNames[0] = "value"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get value */ @@ -64,7 +80,7 @@ library Number { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint32(Bytes.slice4(_blob, 0))); } @@ -73,7 +89,7 @@ library Number { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint32(Bytes.slice4(_blob, 0))); } @@ -82,7 +98,7 @@ library Number { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getFieldLayout()); } /** Set value (using the specified store) */ @@ -90,15 +106,15 @@ library Number { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(uint32 value) internal pure returns (bytes memory) { return abi.encodePacked(value); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(uint32 key) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); @@ -111,7 +127,7 @@ library Number { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -119,6 +135,6 @@ library Number { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/e2e/packages/contracts/src/codegen/tables/NumberList.sol b/e2e/packages/contracts/src/codegen/tables/NumberList.sol index dbda775b36..c3bd7fdaa6 100644 --- a/e2e/packages/contracts/src/codegen/tables/NumberList.sol +++ b/e2e/packages/contracts/src/codegen/tables/NumberList.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,13 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Numbe bytes32 constant NumberListTableId = _tableId; library NumberList { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](0); + + return FieldLayoutLib.encode(_fieldLayout, 1); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](0); @@ -47,21 +55,28 @@ library NumberList { fieldNames[0] = "value"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get value */ function get() internal view returns (uint32[] memory value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -69,7 +84,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, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -77,21 +92,21 @@ library NumberList { function set(uint32[] memory value) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getFieldLayout()); } /** Set value (using the specified store) */ function set(IStore _store, uint32[] memory value) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getFieldLayout()); } /** Get the length of value */ function length() internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](0); - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 4; } @@ -101,7 +116,7 @@ library NumberList { function length(IStore _store) internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](0); - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 4; } @@ -119,7 +134,7 @@ library NumberList { _tableId, _keyTuple, 0, - getValueSchema(), + getFieldLayout(), _index * 4, (_index + 1) * 4 ); @@ -135,7 +150,7 @@ library NumberList { bytes32[] memory _keyTuple = new bytes32[](0); unchecked { - bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, getValueSchema(), _index * 4, (_index + 1) * 4); + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, getFieldLayout(), _index * 4, (_index + 1) * 4); return (uint32(Bytes.slice4(_blob, 0))); } } @@ -144,28 +159,28 @@ library NumberList { function push(uint32 _element) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to value (using the specified store) */ function push(IStore _store, uint32 _element) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from value */ function pop() internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.popFromField(_tableId, _keyTuple, 0, 4, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 4, getFieldLayout()); } /** Pop an element from value (using the specified store) */ function pop(IStore _store) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.popFromField(_tableId, _keyTuple, 0, 4, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 0, 4, getFieldLayout()); } /** @@ -176,7 +191,7 @@ library NumberList { bytes32[] memory _keyTuple = new bytes32[](0); unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 4, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 4, abi.encodePacked((_element)), getFieldLayout()); } } @@ -188,11 +203,11 @@ library NumberList { bytes32[] memory _keyTuple = new bytes32[](0); unchecked { - _store.updateInField(_tableId, _keyTuple, 0, _index * 4, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 0, _index * 4, abi.encodePacked((_element)), getFieldLayout()); } } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(uint32[] memory value) internal pure returns (bytes memory) { PackedCounter _encodedLengths; // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits @@ -203,7 +218,7 @@ library NumberList { return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode((value))); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple() internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](0); @@ -214,13 +229,13 @@ library NumberList { function deleteRecord() internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ function deleteRecord(IStore _store) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/e2e/packages/contracts/src/codegen/tables/Vector.sol b/e2e/packages/contracts/src/codegen/tables/Vector.sol index edd2318914..5b95bbaaa5 100644 --- a/e2e/packages/contracts/src/codegen/tables/Vector.sol +++ b/e2e/packages/contracts/src/codegen/tables/Vector.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -26,6 +27,15 @@ struct VectorData { } library Vector { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](2); + _fieldLayout[0] = 4; + _fieldLayout[1] = 4; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -56,14 +66,21 @@ library Vector { fieldNames[1] = "y"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get x */ @@ -71,7 +88,7 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (int32(uint32(Bytes.slice4(_blob, 0)))); } @@ -80,7 +97,7 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (int32(uint32(Bytes.slice4(_blob, 0)))); } @@ -89,7 +106,7 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((x)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((x)), getFieldLayout()); } /** Set x (using the specified store) */ @@ -97,7 +114,7 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((x)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((x)), getFieldLayout()); } /** Get y */ @@ -105,7 +122,7 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (int32(uint32(Bytes.slice4(_blob, 0)))); } @@ -114,7 +131,7 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (int32(uint32(Bytes.slice4(_blob, 0)))); } @@ -123,7 +140,7 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((y)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((y)), getFieldLayout()); } /** Set y (using the specified store) */ @@ -131,7 +148,7 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((y)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((y)), getFieldLayout()); } /** Get the full data */ @@ -139,7 +156,7 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -148,7 +165,7 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -159,7 +176,7 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - StoreSwitch.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using individual values (using the specified store) */ @@ -169,7 +186,7 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - _store.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + _store.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using the data struct */ @@ -182,19 +199,19 @@ library Vector { set(_store, key, _table.x, _table.y); } - /** Decode the tightly packed blob using this table's schema */ + /** Decode the tightly packed blob using this table's field layout */ function decode(bytes memory _blob) internal pure returns (VectorData memory _table) { _table.x = (int32(uint32(Bytes.slice4(_blob, 0)))); _table.y = (int32(uint32(Bytes.slice4(_blob, 4)))); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(int32 x, int32 y) internal pure returns (bytes memory) { return abi.encodePacked(x, y); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(uint32 key) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); @@ -207,7 +224,7 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -215,6 +232,6 @@ library Vector { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(key)); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/e2e/packages/contracts/src/systems/NumberListSystem.sol b/e2e/packages/contracts/src/systems/NumberListSystem.sol index 83446e12fe..cd6d80a58c 100644 --- a/e2e/packages/contracts/src/systems/NumberListSystem.sol +++ b/e2e/packages/contracts/src/systems/NumberListSystem.sol @@ -22,7 +22,7 @@ contract NumberListSystem is System { } bytes32[] memory emptyKey; - StoreSwitch.pushToField(NumberListTableId, emptyKey, 0, EncodeArray.encode(list), NumberList.getValueSchema()); + StoreSwitch.pushToField(NumberListTableId, emptyKey, 0, EncodeArray.encode(list), NumberList.getFieldLayout()); } function pop() public { diff --git a/e2e/packages/contracts/types/ethers-contracts/IWorld.ts b/e2e/packages/contracts/types/ethers-contracts/IWorld.ts new file mode 100644 index 0000000000..59de0823a0 --- /dev/null +++ b/e2e/packages/contracts/types/ethers-contracts/IWorld.ts @@ -0,0 +1,1734 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumber, + BigNumberish, + BytesLike, + CallOverrides, + ContractTransaction, + Overrides, + PayableOverrides, + PopulatedTransaction, + Signer, + utils, +} from "ethers"; +import type { + FunctionFragment, + Result, + EventFragment, +} from "@ethersproject/abi"; +import type { Listener, Provider } from "@ethersproject/providers"; +import type { + TypedEventFilter, + TypedEvent, + TypedListener, + OnEvent, + PromiseOrValue, +} from "./common"; + +export interface IWorldInterface extends utils.Interface { + functions: { + "call(bytes32,bytes)": FunctionFragment; + "callFrom(address,bytes32,bytes)": FunctionFragment; + "deleteRecord(bytes32,bytes32[],bytes32)": FunctionFragment; + "emitEphemeralRecord(bytes32,bytes32[],bytes,bytes32)": FunctionFragment; + "getField(bytes32,bytes32[],uint8,bytes32)": FunctionFragment; + "getFieldLayout(bytes32)": FunctionFragment; + "getFieldLength(bytes32,bytes32[],uint8,bytes32)": FunctionFragment; + "getFieldSlice(bytes32,bytes32[],uint8,bytes32,uint256,uint256)": FunctionFragment; + "getKeySchema(bytes32)": FunctionFragment; + "getRecord(bytes32,bytes32[],bytes32)": FunctionFragment; + "getValueSchema(bytes32)": FunctionFragment; + "grantAccess(bytes32,address)": FunctionFragment; + "installModule(address,bytes)": FunctionFragment; + "installRootModule(address,bytes)": FunctionFragment; + "pop()": FunctionFragment; + "popFromField(bytes32,bytes32[],uint8,uint256,bytes32)": FunctionFragment; + "push(uint32)": FunctionFragment; + "pushRange(uint32,uint32)": FunctionFragment; + "pushToField(bytes32,bytes32[],uint8,bytes,bytes32)": FunctionFragment; + "registerDelegation(address,bytes32,bytes)": FunctionFragment; + "registerFunctionSelector(bytes32,string,string)": FunctionFragment; + "registerNamespace(bytes16)": FunctionFragment; + "registerRootFunctionSelector(bytes32,bytes4,bytes4)": FunctionFragment; + "registerStoreHook(bytes32,address)": FunctionFragment; + "registerSystem(bytes32,address,bool)": FunctionFragment; + "registerSystemHook(bytes32,address)": FunctionFragment; + "registerTable(bytes32,bytes32,bytes32,bytes32,string[],string[])": FunctionFragment; + "revokeAccess(bytes32,address)": FunctionFragment; + "set(uint32[])": FunctionFragment; + "setField(bytes32,bytes32[],uint8,bytes,bytes32)": FunctionFragment; + "setRecord(bytes32,bytes32[],bytes,bytes32)": FunctionFragment; + "stub(uint256)": FunctionFragment; + "transferOwnership(bytes16,address)": FunctionFragment; + "updateInField(bytes32,bytes32[],uint8,uint256,bytes,bytes32)": FunctionFragment; + }; + + getFunction( + nameOrSignatureOrTopic: + | "call" + | "callFrom" + | "deleteRecord" + | "emitEphemeralRecord" + | "getField" + | "getFieldLayout" + | "getFieldLength" + | "getFieldSlice" + | "getKeySchema" + | "getRecord" + | "getValueSchema" + | "grantAccess" + | "installModule" + | "installRootModule" + | "pop" + | "popFromField" + | "push" + | "pushRange" + | "pushToField" + | "registerDelegation" + | "registerFunctionSelector" + | "registerNamespace" + | "registerRootFunctionSelector" + | "registerStoreHook" + | "registerSystem" + | "registerSystemHook" + | "registerTable" + | "revokeAccess" + | "set" + | "setField" + | "setRecord" + | "stub" + | "transferOwnership" + | "updateInField" + ): FunctionFragment; + + encodeFunctionData( + functionFragment: "call", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "callFrom", + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "deleteRecord", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "emitEphemeralRecord", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "getField", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "getFieldLayout", + values: [PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "getFieldLength", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "getFieldSlice", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "getKeySchema", + values: [PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "getRecord", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "getValueSchema", + values: [PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "grantAccess", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "installModule", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "installRootModule", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData(functionFragment: "pop", values?: undefined): string; + encodeFunctionData( + functionFragment: "popFromField", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "push", + values: [PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "pushRange", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "pushToField", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "registerDelegation", + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "registerFunctionSelector", + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "registerNamespace", + values: [PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "registerRootFunctionSelector", + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "registerStoreHook", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "registerSystem", + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "registerSystemHook", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "registerTable", + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue, + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue[] + ] + ): string; + encodeFunctionData( + functionFragment: "revokeAccess", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "set", + values: [PromiseOrValue[]] + ): string; + encodeFunctionData( + functionFragment: "setField", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "setRecord", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "stub", + values: [PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "transferOwnership", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "updateInField", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + + decodeFunctionResult(functionFragment: "call", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "callFrom", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "deleteRecord", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "emitEphemeralRecord", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "getField", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "getFieldLayout", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getFieldLength", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getFieldSlice", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getKeySchema", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "getRecord", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "getValueSchema", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "grantAccess", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "installModule", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "installRootModule", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "pop", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "popFromField", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "push", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "pushRange", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "pushToField", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "registerDelegation", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "registerFunctionSelector", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "registerNamespace", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "registerRootFunctionSelector", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "registerStoreHook", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "registerSystem", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "registerSystemHook", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "registerTable", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "revokeAccess", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "set", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "setField", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "setRecord", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "stub", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "transferOwnership", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "updateInField", + data: BytesLike + ): Result; + + events: { + "HelloWorld()": EventFragment; + "StoreDeleteRecord(bytes32,bytes32[])": EventFragment; + "StoreEphemeralRecord(bytes32,bytes32[],bytes)": EventFragment; + "StoreSetField(bytes32,bytes32[],uint8,bytes)": EventFragment; + "StoreSetRecord(bytes32,bytes32[],bytes)": EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: "HelloWorld"): EventFragment; + getEvent(nameOrSignatureOrTopic: "StoreDeleteRecord"): EventFragment; + getEvent(nameOrSignatureOrTopic: "StoreEphemeralRecord"): EventFragment; + getEvent(nameOrSignatureOrTopic: "StoreSetField"): EventFragment; + getEvent(nameOrSignatureOrTopic: "StoreSetRecord"): EventFragment; +} + +export interface HelloWorldEventObject {} +export type HelloWorldEvent = TypedEvent<[], HelloWorldEventObject>; + +export type HelloWorldEventFilter = TypedEventFilter; + +export interface StoreDeleteRecordEventObject { + table: string; + key: string[]; +} +export type StoreDeleteRecordEvent = TypedEvent< + [string, string[]], + StoreDeleteRecordEventObject +>; + +export type StoreDeleteRecordEventFilter = + TypedEventFilter; + +export interface StoreEphemeralRecordEventObject { + table: string; + key: string[]; + data: string; +} +export type StoreEphemeralRecordEvent = TypedEvent< + [string, string[], string], + StoreEphemeralRecordEventObject +>; + +export type StoreEphemeralRecordEventFilter = + TypedEventFilter; + +export interface StoreSetFieldEventObject { + table: string; + key: string[]; + schemaIndex: number; + data: string; +} +export type StoreSetFieldEvent = TypedEvent< + [string, string[], number, string], + StoreSetFieldEventObject +>; + +export type StoreSetFieldEventFilter = TypedEventFilter; + +export interface StoreSetRecordEventObject { + table: string; + key: string[]; + data: string; +} +export type StoreSetRecordEvent = TypedEvent< + [string, string[], string], + StoreSetRecordEventObject +>; + +export type StoreSetRecordEventFilter = TypedEventFilter; + +export interface IWorld extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: IWorldInterface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>; + + listeners( + eventFilter?: TypedEventFilter + ): Array>; + listeners(eventName?: string): Array; + removeAllListeners( + eventFilter: TypedEventFilter + ): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + call( + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: PayableOverrides & { from?: PromiseOrValue } + ): Promise; + + callFrom( + delegator: PromiseOrValue, + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: PayableOverrides & { from?: PromiseOrValue } + ): Promise; + + deleteRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + emitEphemeralRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + getField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[string] & { data: string }>; + + getFieldLayout( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[string] & { fieldLayout: string }>; + + getFieldLength( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[BigNumber]>; + + getFieldSlice( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + start: PromiseOrValue, + end: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[string] & { data: string }>; + + getKeySchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[string] & { schema: string }>; + + getRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[string] & { data: string }>; + + getValueSchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[string] & { schema: string }>; + + grantAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + installModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + installRootModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pop( + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + popFromField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + byteLengthToPop: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + push( + num: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pushRange( + start: PromiseOrValue, + end: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pushToField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + dataToPush: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerDelegation( + delegatee: PromiseOrValue, + delegationControlId: PromiseOrValue, + initFuncSelectorAndArgs: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerFunctionSelector( + resourceSelector: PromiseOrValue, + systemFunctionName: PromiseOrValue, + systemFunctionArguments: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerNamespace( + namespace: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerRootFunctionSelector( + resourceSelector: PromiseOrValue, + worldFunctionSelector: PromiseOrValue, + systemFunctionSelector: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerStoreHook( + table: PromiseOrValue, + hook: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerSystem( + resourceSelector: PromiseOrValue, + system: PromiseOrValue, + publicAccess: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerSystemHook( + resourceSelector: PromiseOrValue, + hook: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerTable( + table: PromiseOrValue, + fieldLayout: PromiseOrValue, + keySchema: PromiseOrValue, + valueSchema: PromiseOrValue, + keyNames: PromiseOrValue[], + fieldNames: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + revokeAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + set( + list: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + stub( + arg: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[BigNumber]>; + + transferOwnership( + namespace: PromiseOrValue, + newOwner: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + updateInField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + startByteIndex: PromiseOrValue, + dataToSet: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + }; + + call( + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: PayableOverrides & { from?: PromiseOrValue } + ): Promise; + + callFrom( + delegator: PromiseOrValue, + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: PayableOverrides & { from?: PromiseOrValue } + ): Promise; + + deleteRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + emitEphemeralRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + getField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldLayout( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldLength( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldSlice( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + start: PromiseOrValue, + end: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getKeySchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getValueSchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + grantAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + installModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + installRootModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pop( + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + popFromField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + byteLengthToPop: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + push( + num: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pushRange( + start: PromiseOrValue, + end: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pushToField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + dataToPush: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerDelegation( + delegatee: PromiseOrValue, + delegationControlId: PromiseOrValue, + initFuncSelectorAndArgs: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerFunctionSelector( + resourceSelector: PromiseOrValue, + systemFunctionName: PromiseOrValue, + systemFunctionArguments: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerNamespace( + namespace: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerRootFunctionSelector( + resourceSelector: PromiseOrValue, + worldFunctionSelector: PromiseOrValue, + systemFunctionSelector: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerStoreHook( + table: PromiseOrValue, + hook: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerSystem( + resourceSelector: PromiseOrValue, + system: PromiseOrValue, + publicAccess: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerSystemHook( + resourceSelector: PromiseOrValue, + hook: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerTable( + table: PromiseOrValue, + fieldLayout: PromiseOrValue, + keySchema: PromiseOrValue, + valueSchema: PromiseOrValue, + keyNames: PromiseOrValue[], + fieldNames: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + revokeAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + set( + list: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + stub( + arg: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + transferOwnership( + namespace: PromiseOrValue, + newOwner: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + updateInField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + startByteIndex: PromiseOrValue, + dataToSet: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + callStatic: { + call( + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + callFrom( + delegator: PromiseOrValue, + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + deleteRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + emitEphemeralRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldLayout( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldLength( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldSlice( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + start: PromiseOrValue, + end: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getKeySchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getValueSchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + grantAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + installModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + installRootModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + pop(overrides?: CallOverrides): Promise; + + popFromField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + byteLengthToPop: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + push( + num: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + pushRange( + start: PromiseOrValue, + end: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + pushToField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + dataToPush: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + registerDelegation( + delegatee: PromiseOrValue, + delegationControlId: PromiseOrValue, + initFuncSelectorAndArgs: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + registerFunctionSelector( + resourceSelector: PromiseOrValue, + systemFunctionName: PromiseOrValue, + systemFunctionArguments: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + registerNamespace( + namespace: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + registerRootFunctionSelector( + resourceSelector: PromiseOrValue, + worldFunctionSelector: PromiseOrValue, + systemFunctionSelector: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + registerStoreHook( + table: PromiseOrValue, + hook: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + registerSystem( + resourceSelector: PromiseOrValue, + system: PromiseOrValue, + publicAccess: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + registerSystemHook( + resourceSelector: PromiseOrValue, + hook: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + registerTable( + table: PromiseOrValue, + fieldLayout: PromiseOrValue, + keySchema: PromiseOrValue, + valueSchema: PromiseOrValue, + keyNames: PromiseOrValue[], + fieldNames: PromiseOrValue[], + overrides?: CallOverrides + ): Promise; + + revokeAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + set( + list: PromiseOrValue[], + overrides?: CallOverrides + ): Promise; + + setField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + setRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + stub( + arg: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + transferOwnership( + namespace: PromiseOrValue, + newOwner: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + updateInField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + startByteIndex: PromiseOrValue, + dataToSet: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + }; + + filters: { + "HelloWorld()"(): HelloWorldEventFilter; + HelloWorld(): HelloWorldEventFilter; + + "StoreDeleteRecord(bytes32,bytes32[])"( + table?: null, + key?: null + ): StoreDeleteRecordEventFilter; + StoreDeleteRecord(table?: null, key?: null): StoreDeleteRecordEventFilter; + + "StoreEphemeralRecord(bytes32,bytes32[],bytes)"( + table?: null, + key?: null, + data?: null + ): StoreEphemeralRecordEventFilter; + StoreEphemeralRecord( + table?: null, + key?: null, + data?: null + ): StoreEphemeralRecordEventFilter; + + "StoreSetField(bytes32,bytes32[],uint8,bytes)"( + table?: null, + key?: null, + schemaIndex?: null, + data?: null + ): StoreSetFieldEventFilter; + StoreSetField( + table?: null, + key?: null, + schemaIndex?: null, + data?: null + ): StoreSetFieldEventFilter; + + "StoreSetRecord(bytes32,bytes32[],bytes)"( + table?: null, + key?: null, + data?: null + ): StoreSetRecordEventFilter; + StoreSetRecord( + table?: null, + key?: null, + data?: null + ): StoreSetRecordEventFilter; + }; + + estimateGas: { + call( + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: PayableOverrides & { from?: PromiseOrValue } + ): Promise; + + callFrom( + delegator: PromiseOrValue, + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: PayableOverrides & { from?: PromiseOrValue } + ): Promise; + + deleteRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + emitEphemeralRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + getField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldLayout( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldLength( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldSlice( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + start: PromiseOrValue, + end: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getKeySchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getValueSchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + grantAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + installModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + installRootModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pop( + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + popFromField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + byteLengthToPop: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + push( + num: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pushRange( + start: PromiseOrValue, + end: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pushToField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + dataToPush: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerDelegation( + delegatee: PromiseOrValue, + delegationControlId: PromiseOrValue, + initFuncSelectorAndArgs: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerFunctionSelector( + resourceSelector: PromiseOrValue, + systemFunctionName: PromiseOrValue, + systemFunctionArguments: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerNamespace( + namespace: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerRootFunctionSelector( + resourceSelector: PromiseOrValue, + worldFunctionSelector: PromiseOrValue, + systemFunctionSelector: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerStoreHook( + table: PromiseOrValue, + hook: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerSystem( + resourceSelector: PromiseOrValue, + system: PromiseOrValue, + publicAccess: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerSystemHook( + resourceSelector: PromiseOrValue, + hook: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerTable( + table: PromiseOrValue, + fieldLayout: PromiseOrValue, + keySchema: PromiseOrValue, + valueSchema: PromiseOrValue, + keyNames: PromiseOrValue[], + fieldNames: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + revokeAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + set( + list: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + stub( + arg: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + transferOwnership( + namespace: PromiseOrValue, + newOwner: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + updateInField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + startByteIndex: PromiseOrValue, + dataToSet: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + }; + + populateTransaction: { + call( + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: PayableOverrides & { from?: PromiseOrValue } + ): Promise; + + callFrom( + delegator: PromiseOrValue, + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: PayableOverrides & { from?: PromiseOrValue } + ): Promise; + + deleteRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + emitEphemeralRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + getField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldLayout( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldLength( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldSlice( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + start: PromiseOrValue, + end: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getKeySchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getValueSchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + grantAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + installModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + installRootModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pop( + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + popFromField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + byteLengthToPop: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + push( + num: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pushRange( + start: PromiseOrValue, + end: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pushToField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + dataToPush: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerDelegation( + delegatee: PromiseOrValue, + delegationControlId: PromiseOrValue, + initFuncSelectorAndArgs: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerFunctionSelector( + resourceSelector: PromiseOrValue, + systemFunctionName: PromiseOrValue, + systemFunctionArguments: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerNamespace( + namespace: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerRootFunctionSelector( + resourceSelector: PromiseOrValue, + worldFunctionSelector: PromiseOrValue, + systemFunctionSelector: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerStoreHook( + table: PromiseOrValue, + hook: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerSystem( + resourceSelector: PromiseOrValue, + system: PromiseOrValue, + publicAccess: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerSystemHook( + resourceSelector: PromiseOrValue, + hook: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerTable( + table: PromiseOrValue, + fieldLayout: PromiseOrValue, + keySchema: PromiseOrValue, + valueSchema: PromiseOrValue, + keyNames: PromiseOrValue[], + fieldNames: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + revokeAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + set( + list: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + stub( + arg: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + transferOwnership( + namespace: PromiseOrValue, + newOwner: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + updateInField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + startByteIndex: PromiseOrValue, + dataToSet: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + }; +} diff --git a/e2e/packages/contracts/types/ethers-contracts/factories/IWorld__factory.ts b/e2e/packages/contracts/types/ethers-contracts/factories/IWorld__factory.ts new file mode 100644 index 0000000000..82783c0ee0 --- /dev/null +++ b/e2e/packages/contracts/types/ethers-contracts/factories/IWorld__factory.ts @@ -0,0 +1,1218 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from "ethers"; +import type { Provider } from "@ethersproject/providers"; +import type { IWorld, IWorldInterface } from "../IWorld"; + +const _abi = [ + { + inputs: [ + { + internalType: "string", + name: "resource", + type: "string", + }, + { + internalType: "address", + name: "caller", + type: "address", + }, + ], + name: "AccessDenied", + type: "error", + }, + { + inputs: [ + { + internalType: "address", + name: "delegator", + type: "address", + }, + { + internalType: "address", + name: "delegatee", + type: "address", + }, + ], + name: "DelegationNotFound", + type: "error", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "functionSelector", + type: "bytes4", + }, + ], + name: "FunctionSelectorExists", + type: "error", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "functionSelector", + type: "bytes4", + }, + ], + name: "FunctionSelectorNotFound", + type: "error", + }, + { + inputs: [ + { + internalType: "string", + name: "resource", + type: "string", + }, + ], + name: "InvalidSelector", + type: "error", + }, + { + inputs: [ + { + internalType: "string", + name: "module", + type: "string", + }, + ], + name: "ModuleAlreadyInstalled", + type: "error", + }, + { + inputs: [ + { + internalType: "string", + name: "resource", + type: "string", + }, + ], + name: "ResourceExists", + type: "error", + }, + { + inputs: [ + { + internalType: "string", + name: "resource", + type: "string", + }, + ], + name: "ResourceNotFound", + type: "error", + }, + { + inputs: [ + { + internalType: "uint256", + name: "length", + type: "uint256", + }, + { + internalType: "uint256", + name: "received", + type: "uint256", + }, + ], + name: "StoreCore_DataIndexOverflow", + type: "error", + }, + { + inputs: [ + { + internalType: "uint256", + name: "expected", + type: "uint256", + }, + { + internalType: "uint256", + name: "received", + type: "uint256", + }, + ], + name: "StoreCore_InvalidDataLength", + type: "error", + }, + { + inputs: [ + { + internalType: "uint256", + name: "expected", + type: "uint256", + }, + { + internalType: "uint256", + name: "received", + type: "uint256", + }, + ], + name: "StoreCore_InvalidKeyNamesLength", + type: "error", + }, + { + inputs: [ + { + internalType: "uint256", + name: "expected", + type: "uint256", + }, + { + internalType: "uint256", + name: "received", + type: "uint256", + }, + ], + name: "StoreCore_InvalidValueNamesLength", + type: "error", + }, + { + inputs: [ + { + internalType: "uint256", + name: "expected", + type: "uint256", + }, + { + internalType: "uint256", + name: "received", + type: "uint256", + }, + ], + name: "StoreCore_InvalidValueSchemaLength", + type: "error", + }, + { + inputs: [], + name: "StoreCore_NotDynamicField", + type: "error", + }, + { + inputs: [], + name: "StoreCore_NotImplemented", + type: "error", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "tableId", + type: "bytes32", + }, + { + internalType: "string", + name: "tableIdString", + type: "string", + }, + ], + name: "StoreCore_TableAlreadyExists", + type: "error", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "tableId", + type: "bytes32", + }, + { + internalType: "string", + name: "tableIdString", + type: "string", + }, + ], + name: "StoreCore_TableNotFound", + type: "error", + }, + { + inputs: [ + { + internalType: "address", + name: "system", + type: "address", + }, + ], + name: "SystemExists", + type: "error", + }, + { + inputs: [], + name: "TestError1", + type: "error", + }, + { + inputs: [ + { + components: [ + { + internalType: "int32", + name: "x", + type: "int32", + }, + { + internalType: "int32", + name: "y", + type: "int32", + }, + ], + internalType: "struct Position", + name: "position", + type: "tuple", + }, + { + internalType: "uint256", + name: "value", + type: "uint256", + }, + { + internalType: "string", + name: "name", + type: "string", + }, + { + internalType: "bool", + name: "flag", + type: "bool", + }, + ], + name: "TestError2", + type: "error", + }, + { + anonymous: false, + inputs: [], + name: "HelloWorld", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + indexed: false, + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + ], + name: "StoreDeleteRecord", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + indexed: false, + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + indexed: false, + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + name: "StoreEphemeralRecord", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + indexed: false, + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + indexed: false, + internalType: "uint8", + name: "schemaIndex", + type: "uint8", + }, + { + indexed: false, + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + name: "StoreSetField", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + indexed: false, + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + indexed: false, + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + name: "StoreSetRecord", + type: "event", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "resourceSelector", + type: "bytes32", + }, + { + internalType: "bytes", + name: "funcSelectorAndArgs", + type: "bytes", + }, + ], + name: "call", + outputs: [ + { + internalType: "bytes", + name: "", + type: "bytes", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "delegator", + type: "address", + }, + { + internalType: "bytes32", + name: "resourceSelector", + type: "bytes32", + }, + { + internalType: "bytes", + name: "funcSelectorAndArgs", + type: "bytes", + }, + ], + name: "callFrom", + outputs: [ + { + internalType: "bytes", + name: "", + type: "bytes", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "deleteRecord", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "emitEphemeralRecord", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "uint8", + name: "schemaIndex", + type: "uint8", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "getField", + outputs: [ + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + ], + name: "getFieldLayout", + outputs: [ + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "uint8", + name: "schemaIndex", + type: "uint8", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "getFieldLength", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "uint8", + name: "schemaIndex", + type: "uint8", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + { + internalType: "uint256", + name: "start", + type: "uint256", + }, + { + internalType: "uint256", + name: "end", + type: "uint256", + }, + ], + name: "getFieldSlice", + outputs: [ + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + ], + name: "getKeySchema", + outputs: [ + { + internalType: "Schema", + name: "schema", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "getRecord", + outputs: [ + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + ], + name: "getValueSchema", + outputs: [ + { + internalType: "Schema", + name: "schema", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "resourceSelector", + type: "bytes32", + }, + { + internalType: "address", + name: "grantee", + type: "address", + }, + ], + name: "grantAccess", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "contract IModule", + name: "module", + type: "address", + }, + { + internalType: "bytes", + name: "args", + type: "bytes", + }, + ], + name: "installModule", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "contract IModule", + name: "module", + type: "address", + }, + { + internalType: "bytes", + name: "args", + type: "bytes", + }, + ], + name: "installRootModule", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "pop", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "uint8", + name: "schemaIndex", + type: "uint8", + }, + { + internalType: "uint256", + name: "byteLengthToPop", + type: "uint256", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "popFromField", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint32", + name: "num", + type: "uint32", + }, + ], + name: "push", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint32", + name: "start", + type: "uint32", + }, + { + internalType: "uint32", + name: "end", + type: "uint32", + }, + ], + name: "pushRange", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "uint8", + name: "schemaIndex", + type: "uint8", + }, + { + internalType: "bytes", + name: "dataToPush", + type: "bytes", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "pushToField", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "delegatee", + type: "address", + }, + { + internalType: "bytes32", + name: "delegationControlId", + type: "bytes32", + }, + { + internalType: "bytes", + name: "initFuncSelectorAndArgs", + type: "bytes", + }, + ], + name: "registerDelegation", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "resourceSelector", + type: "bytes32", + }, + { + internalType: "string", + name: "systemFunctionName", + type: "string", + }, + { + internalType: "string", + name: "systemFunctionArguments", + type: "string", + }, + ], + name: "registerFunctionSelector", + outputs: [ + { + internalType: "bytes4", + name: "worldFunctionSelector", + type: "bytes4", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes16", + name: "namespace", + type: "bytes16", + }, + ], + name: "registerNamespace", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "resourceSelector", + type: "bytes32", + }, + { + internalType: "bytes4", + name: "worldFunctionSelector", + type: "bytes4", + }, + { + internalType: "bytes4", + name: "systemFunctionSelector", + type: "bytes4", + }, + ], + name: "registerRootFunctionSelector", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "contract IStoreHook", + name: "hook", + type: "address", + }, + ], + name: "registerStoreHook", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "resourceSelector", + type: "bytes32", + }, + { + internalType: "contract WorldContextConsumer", + name: "system", + type: "address", + }, + { + internalType: "bool", + name: "publicAccess", + type: "bool", + }, + ], + name: "registerSystem", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "resourceSelector", + type: "bytes32", + }, + { + internalType: "contract ISystemHook", + name: "hook", + type: "address", + }, + ], + name: "registerSystemHook", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + { + internalType: "Schema", + name: "keySchema", + type: "bytes32", + }, + { + internalType: "Schema", + name: "valueSchema", + type: "bytes32", + }, + { + internalType: "string[]", + name: "keyNames", + type: "string[]", + }, + { + internalType: "string[]", + name: "fieldNames", + type: "string[]", + }, + ], + name: "registerTable", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "resourceSelector", + type: "bytes32", + }, + { + internalType: "address", + name: "grantee", + type: "address", + }, + ], + name: "revokeAccess", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint32[]", + name: "list", + type: "uint32[]", + }, + ], + name: "set", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "uint8", + name: "schemaIndex", + type: "uint8", + }, + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "setField", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "setRecord", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "arg", + type: "uint256", + }, + ], + name: "stub", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "pure", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes16", + name: "namespace", + type: "bytes16", + }, + { + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "transferOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "uint8", + name: "schemaIndex", + type: "uint8", + }, + { + internalType: "uint256", + name: "startByteIndex", + type: "uint256", + }, + { + internalType: "bytes", + name: "dataToSet", + type: "bytes", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "updateInField", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, +] as const; + +export class IWorld__factory { + static readonly abi = _abi; + static createInterface(): IWorldInterface { + return new utils.Interface(_abi) as IWorldInterface; + } + static connect(address: string, signerOrProvider: Signer | Provider): IWorld { + return new Contract(address, _abi, signerOrProvider) as IWorld; + } +} diff --git a/e2e/packages/contracts/worlds.json b/e2e/packages/contracts/worlds.json index caf66719c4..f3c6312fd6 100644 --- a/e2e/packages/contracts/worlds.json +++ b/e2e/packages/contracts/worlds.json @@ -1,5 +1,5 @@ { "31337": { - "address": "0xAA292E8611aDF267e563f334Ee42320aC96D0463" + "address": "0x99dBE4AEa58E518C50a1c04aE9b48C9F6354612f" } } \ No newline at end of file diff --git a/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol b/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol index 647bfc052f..d21d510f08 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,14 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Count bytes32 constant CounterTableTableId = _tableId; library CounterTable { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 4; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](0); @@ -47,21 +56,28 @@ library CounterTable { fieldNames[0] = "value"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get value */ function get() internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint32(Bytes.slice4(_blob, 0))); } @@ -69,7 +85,7 @@ library CounterTable { function get(IStore _store) internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint32(Bytes.slice4(_blob, 0))); } @@ -77,22 +93,22 @@ library CounterTable { function set(uint32 value) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getFieldLayout()); } /** Set value (using the specified store) */ function set(IStore _store, uint32 value) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(uint32 value) internal pure returns (bytes memory) { return abi.encodePacked(value); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple() internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](0); @@ -103,13 +119,13 @@ library CounterTable { function deleteRecord() internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ function deleteRecord(IStore _store) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol b/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol index f3406f9e3c..65a36496d5 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,14 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Inven bytes32 constant InventoryTableId = _tableId; library Inventory { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 4; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](3); @@ -53,14 +62,21 @@ library Inventory { fieldNames[0] = "amount"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get amount */ @@ -70,7 +86,7 @@ library Inventory { _keyTuple[1] = bytes32(uint256(item)); _keyTuple[2] = bytes32(uint256(itemVariant)); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint32(Bytes.slice4(_blob, 0))); } @@ -81,7 +97,7 @@ library Inventory { _keyTuple[1] = bytes32(uint256(item)); _keyTuple[2] = bytes32(uint256(itemVariant)); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint32(Bytes.slice4(_blob, 0))); } @@ -92,7 +108,7 @@ library Inventory { _keyTuple[1] = bytes32(uint256(item)); _keyTuple[2] = bytes32(uint256(itemVariant)); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((amount)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((amount)), getFieldLayout()); } /** Set amount (using the specified store) */ @@ -102,15 +118,15 @@ library Inventory { _keyTuple[1] = bytes32(uint256(item)); _keyTuple[2] = bytes32(uint256(itemVariant)); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((amount)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((amount)), getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(uint32 amount) internal pure returns (bytes memory) { return abi.encodePacked(amount); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(address owner, uint32 item, uint32 itemVariant) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](3); _keyTuple[0] = bytes32(uint256(uint160(owner))); @@ -127,7 +143,7 @@ library Inventory { _keyTuple[1] = bytes32(uint256(item)); _keyTuple[2] = bytes32(uint256(itemVariant)); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -137,6 +153,6 @@ library Inventory { _keyTuple[1] = bytes32(uint256(item)); _keyTuple[2] = bytes32(uint256(itemVariant)); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol b/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol index 928fed1d72..849483b418 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/MessageTable.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,13 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Messa bytes32 constant MessageTableTableId = _tableId; library MessageTable { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](0); + + return FieldLayoutLib.encode(_fieldLayout, 1); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](0); @@ -47,14 +55,21 @@ library MessageTable { fieldNames[0] = "value"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Emit the ephemeral event using individual values */ @@ -63,7 +78,7 @@ library MessageTable { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.emitEphemeralRecord(_tableId, _keyTuple, _data, getValueSchema()); + StoreSwitch.emitEphemeralRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Emit the ephemeral event using individual values (using the specified store) */ @@ -72,10 +87,10 @@ library MessageTable { bytes32[] memory _keyTuple = new bytes32[](0); - _store.emitEphemeralRecord(_tableId, _keyTuple, _data, getValueSchema()); + _store.emitEphemeralRecord(_tableId, _keyTuple, _data, getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(string memory value) internal pure returns (bytes memory) { PackedCounter _encodedLengths; // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits @@ -86,7 +101,7 @@ library MessageTable { return abi.encodePacked(_encodedLengths.unwrap(), bytes((value))); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple() internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](0); diff --git a/examples/minimal/packages/contracts/types/ethers-contracts/IWorld.ts b/examples/minimal/packages/contracts/types/ethers-contracts/IWorld.ts new file mode 100644 index 0000000000..46b302ac0d --- /dev/null +++ b/examples/minimal/packages/contracts/types/ethers-contracts/IWorld.ts @@ -0,0 +1,1846 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumber, + BigNumberish, + BytesLike, + CallOverrides, + ContractTransaction, + Overrides, + PayableOverrides, + PopulatedTransaction, + Signer, + utils, +} from "ethers"; +import type { + FunctionFragment, + Result, + EventFragment, +} from "@ethersproject/abi"; +import type { Listener, Provider } from "@ethersproject/providers"; +import type { + TypedEventFilter, + TypedEvent, + TypedListener, + OnEvent, + PromiseOrValue, +} from "./common"; + +export type BytesStructStruct = { value: PromiseOrValue }; + +export type BytesStructStructOutput = [string] & { value: string }; + +export type StringStructStruct = { value: PromiseOrValue }; + +export type StringStructStructOutput = [string] & { value: string }; + +export interface IWorldInterface extends utils.Interface { + functions: { + "call(bytes32,bytes)": FunctionFragment; + "callFrom(address,bytes32,bytes)": FunctionFragment; + "deleteRecord(bytes32,bytes32[],bytes32)": FunctionFragment; + "dynamicArrayBytesStruct((bytes)[])": FunctionFragment; + "dynamicArrayStringStruct((string)[])": FunctionFragment; + "emitEphemeralRecord(bytes32,bytes32[],bytes,bytes32)": FunctionFragment; + "getField(bytes32,bytes32[],uint8,bytes32)": FunctionFragment; + "getFieldLayout(bytes32)": FunctionFragment; + "getFieldLength(bytes32,bytes32[],uint8,bytes32)": FunctionFragment; + "getFieldSlice(bytes32,bytes32[],uint8,bytes32,uint256,uint256)": FunctionFragment; + "getKeySchema(bytes32)": FunctionFragment; + "getRecord(bytes32,bytes32[],bytes32)": FunctionFragment; + "getValueSchema(bytes32)": FunctionFragment; + "grantAccess(bytes32,address)": FunctionFragment; + "increment()": FunctionFragment; + "installModule(address,bytes)": FunctionFragment; + "installRootModule(address,bytes)": FunctionFragment; + "pickUp(uint32,uint32)": FunctionFragment; + "popFromField(bytes32,bytes32[],uint8,uint256,bytes32)": FunctionFragment; + "pushToField(bytes32,bytes32[],uint8,bytes,bytes32)": FunctionFragment; + "registerDelegation(address,bytes32,bytes)": FunctionFragment; + "registerFunctionSelector(bytes32,string,string)": FunctionFragment; + "registerNamespace(bytes16)": FunctionFragment; + "registerRootFunctionSelector(bytes32,bytes4,bytes4)": FunctionFragment; + "registerStoreHook(bytes32,address)": FunctionFragment; + "registerSystem(bytes32,address,bool)": FunctionFragment; + "registerSystemHook(bytes32,address)": FunctionFragment; + "registerTable(bytes32,bytes32,bytes32,bytes32,string[],string[])": FunctionFragment; + "revokeAccess(bytes32,address)": FunctionFragment; + "sendMessage(string)": FunctionFragment; + "setField(bytes32,bytes32[],uint8,bytes,bytes32)": FunctionFragment; + "setRecord(bytes32,bytes32[],bytes,bytes32)": FunctionFragment; + "staticArrayBytesStruct(tuple[1])": FunctionFragment; + "staticArrayStringStruct(tuple[1])": FunctionFragment; + "transferOwnership(bytes16,address)": FunctionFragment; + "updateInField(bytes32,bytes32[],uint8,uint256,bytes,bytes32)": FunctionFragment; + "willRevert()": FunctionFragment; + }; + + getFunction( + nameOrSignatureOrTopic: + | "call" + | "callFrom" + | "deleteRecord" + | "dynamicArrayBytesStruct" + | "dynamicArrayStringStruct" + | "emitEphemeralRecord" + | "getField" + | "getFieldLayout" + | "getFieldLength" + | "getFieldSlice" + | "getKeySchema" + | "getRecord" + | "getValueSchema" + | "grantAccess" + | "increment" + | "installModule" + | "installRootModule" + | "pickUp" + | "popFromField" + | "pushToField" + | "registerDelegation" + | "registerFunctionSelector" + | "registerNamespace" + | "registerRootFunctionSelector" + | "registerStoreHook" + | "registerSystem" + | "registerSystemHook" + | "registerTable" + | "revokeAccess" + | "sendMessage" + | "setField" + | "setRecord" + | "staticArrayBytesStruct" + | "staticArrayStringStruct" + | "transferOwnership" + | "updateInField" + | "willRevert" + ): FunctionFragment; + + encodeFunctionData( + functionFragment: "call", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "callFrom", + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "deleteRecord", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "dynamicArrayBytesStruct", + values: [BytesStructStruct[]] + ): string; + encodeFunctionData( + functionFragment: "dynamicArrayStringStruct", + values: [StringStructStruct[]] + ): string; + encodeFunctionData( + functionFragment: "emitEphemeralRecord", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "getField", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "getFieldLayout", + values: [PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "getFieldLength", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "getFieldSlice", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "getKeySchema", + values: [PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "getRecord", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "getValueSchema", + values: [PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "grantAccess", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData(functionFragment: "increment", values?: undefined): string; + encodeFunctionData( + functionFragment: "installModule", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "installRootModule", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "pickUp", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "popFromField", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "pushToField", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "registerDelegation", + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "registerFunctionSelector", + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "registerNamespace", + values: [PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "registerRootFunctionSelector", + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "registerStoreHook", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "registerSystem", + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "registerSystemHook", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "registerTable", + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue, + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue[] + ] + ): string; + encodeFunctionData( + functionFragment: "revokeAccess", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "sendMessage", + values: [PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "setField", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "setRecord", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "staticArrayBytesStruct", + values: [[BytesStructStruct]] + ): string; + encodeFunctionData( + functionFragment: "staticArrayStringStruct", + values: [[StringStructStruct]] + ): string; + encodeFunctionData( + functionFragment: "transferOwnership", + values: [PromiseOrValue, PromiseOrValue] + ): string; + encodeFunctionData( + functionFragment: "updateInField", + values: [ + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue, + PromiseOrValue, + PromiseOrValue + ] + ): string; + encodeFunctionData( + functionFragment: "willRevert", + values?: undefined + ): string; + + decodeFunctionResult(functionFragment: "call", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "callFrom", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "deleteRecord", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "dynamicArrayBytesStruct", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "dynamicArrayStringStruct", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "emitEphemeralRecord", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "getField", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "getFieldLayout", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getFieldLength", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getFieldSlice", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getKeySchema", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "getRecord", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "getValueSchema", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "grantAccess", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "increment", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "installModule", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "installRootModule", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "pickUp", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "popFromField", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "pushToField", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "registerDelegation", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "registerFunctionSelector", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "registerNamespace", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "registerRootFunctionSelector", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "registerStoreHook", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "registerSystem", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "registerSystemHook", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "registerTable", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "revokeAccess", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "sendMessage", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "setField", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "setRecord", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "staticArrayBytesStruct", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "staticArrayStringStruct", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "transferOwnership", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "updateInField", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "willRevert", data: BytesLike): Result; + + events: { + "HelloWorld()": EventFragment; + "StoreDeleteRecord(bytes32,bytes32[])": EventFragment; + "StoreEphemeralRecord(bytes32,bytes32[],bytes)": EventFragment; + "StoreSetField(bytes32,bytes32[],uint8,bytes)": EventFragment; + "StoreSetRecord(bytes32,bytes32[],bytes)": EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: "HelloWorld"): EventFragment; + getEvent(nameOrSignatureOrTopic: "StoreDeleteRecord"): EventFragment; + getEvent(nameOrSignatureOrTopic: "StoreEphemeralRecord"): EventFragment; + getEvent(nameOrSignatureOrTopic: "StoreSetField"): EventFragment; + getEvent(nameOrSignatureOrTopic: "StoreSetRecord"): EventFragment; +} + +export interface HelloWorldEventObject {} +export type HelloWorldEvent = TypedEvent<[], HelloWorldEventObject>; + +export type HelloWorldEventFilter = TypedEventFilter; + +export interface StoreDeleteRecordEventObject { + table: string; + key: string[]; +} +export type StoreDeleteRecordEvent = TypedEvent< + [string, string[]], + StoreDeleteRecordEventObject +>; + +export type StoreDeleteRecordEventFilter = + TypedEventFilter; + +export interface StoreEphemeralRecordEventObject { + table: string; + key: string[]; + data: string; +} +export type StoreEphemeralRecordEvent = TypedEvent< + [string, string[], string], + StoreEphemeralRecordEventObject +>; + +export type StoreEphemeralRecordEventFilter = + TypedEventFilter; + +export interface StoreSetFieldEventObject { + table: string; + key: string[]; + schemaIndex: number; + data: string; +} +export type StoreSetFieldEvent = TypedEvent< + [string, string[], number, string], + StoreSetFieldEventObject +>; + +export type StoreSetFieldEventFilter = TypedEventFilter; + +export interface StoreSetRecordEventObject { + table: string; + key: string[]; + data: string; +} +export type StoreSetRecordEvent = TypedEvent< + [string, string[], string], + StoreSetRecordEventObject +>; + +export type StoreSetRecordEventFilter = TypedEventFilter; + +export interface IWorld extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: IWorldInterface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>; + + listeners( + eventFilter?: TypedEventFilter + ): Array>; + listeners(eventName?: string): Array; + removeAllListeners( + eventFilter: TypedEventFilter + ): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + call( + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: PayableOverrides & { from?: PromiseOrValue } + ): Promise; + + callFrom( + delegator: PromiseOrValue, + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: PayableOverrides & { from?: PromiseOrValue } + ): Promise; + + deleteRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + dynamicArrayBytesStruct( + arg0: BytesStructStruct[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + dynamicArrayStringStruct( + arg0: StringStructStruct[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + emitEphemeralRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + getField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[string] & { data: string }>; + + getFieldLayout( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[string] & { fieldLayout: string }>; + + getFieldLength( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[BigNumber]>; + + getFieldSlice( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + start: PromiseOrValue, + end: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[string] & { data: string }>; + + getKeySchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[string] & { schema: string }>; + + getRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[string] & { data: string }>; + + getValueSchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise<[string] & { schema: string }>; + + grantAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + increment( + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + installModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + installRootModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pickUp( + item: PromiseOrValue, + itemVariant: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + popFromField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + byteLengthToPop: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pushToField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + dataToPush: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerDelegation( + delegatee: PromiseOrValue, + delegationControlId: PromiseOrValue, + initFuncSelectorAndArgs: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerFunctionSelector( + resourceSelector: PromiseOrValue, + systemFunctionName: PromiseOrValue, + systemFunctionArguments: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerNamespace( + namespace: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerRootFunctionSelector( + resourceSelector: PromiseOrValue, + worldFunctionSelector: PromiseOrValue, + systemFunctionSelector: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerStoreHook( + table: PromiseOrValue, + hook: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerSystem( + resourceSelector: PromiseOrValue, + system: PromiseOrValue, + publicAccess: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerSystemHook( + resourceSelector: PromiseOrValue, + hook: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerTable( + table: PromiseOrValue, + fieldLayout: PromiseOrValue, + keySchema: PromiseOrValue, + valueSchema: PromiseOrValue, + keyNames: PromiseOrValue[], + fieldNames: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + revokeAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + sendMessage( + message: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + staticArrayBytesStruct( + arg0: [BytesStructStruct], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + staticArrayStringStruct( + arg0: [StringStructStruct], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + transferOwnership( + namespace: PromiseOrValue, + newOwner: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + updateInField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + startByteIndex: PromiseOrValue, + dataToSet: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + willRevert( + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + }; + + call( + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: PayableOverrides & { from?: PromiseOrValue } + ): Promise; + + callFrom( + delegator: PromiseOrValue, + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: PayableOverrides & { from?: PromiseOrValue } + ): Promise; + + deleteRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + dynamicArrayBytesStruct( + arg0: BytesStructStruct[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + dynamicArrayStringStruct( + arg0: StringStructStruct[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + emitEphemeralRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + getField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldLayout( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldLength( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldSlice( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + start: PromiseOrValue, + end: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getKeySchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getValueSchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + grantAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + increment( + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + installModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + installRootModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pickUp( + item: PromiseOrValue, + itemVariant: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + popFromField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + byteLengthToPop: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pushToField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + dataToPush: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerDelegation( + delegatee: PromiseOrValue, + delegationControlId: PromiseOrValue, + initFuncSelectorAndArgs: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerFunctionSelector( + resourceSelector: PromiseOrValue, + systemFunctionName: PromiseOrValue, + systemFunctionArguments: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerNamespace( + namespace: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerRootFunctionSelector( + resourceSelector: PromiseOrValue, + worldFunctionSelector: PromiseOrValue, + systemFunctionSelector: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerStoreHook( + table: PromiseOrValue, + hook: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerSystem( + resourceSelector: PromiseOrValue, + system: PromiseOrValue, + publicAccess: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerSystemHook( + resourceSelector: PromiseOrValue, + hook: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerTable( + table: PromiseOrValue, + fieldLayout: PromiseOrValue, + keySchema: PromiseOrValue, + valueSchema: PromiseOrValue, + keyNames: PromiseOrValue[], + fieldNames: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + revokeAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + sendMessage( + message: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + staticArrayBytesStruct( + arg0: [BytesStructStruct], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + staticArrayStringStruct( + arg0: [StringStructStruct], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + transferOwnership( + namespace: PromiseOrValue, + newOwner: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + updateInField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + startByteIndex: PromiseOrValue, + dataToSet: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + willRevert( + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + callStatic: { + call( + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + callFrom( + delegator: PromiseOrValue, + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + deleteRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + dynamicArrayBytesStruct( + arg0: BytesStructStruct[], + overrides?: CallOverrides + ): Promise; + + dynamicArrayStringStruct( + arg0: StringStructStruct[], + overrides?: CallOverrides + ): Promise; + + emitEphemeralRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldLayout( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldLength( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldSlice( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + start: PromiseOrValue, + end: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getKeySchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getValueSchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + grantAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + increment(overrides?: CallOverrides): Promise; + + installModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + installRootModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + pickUp( + item: PromiseOrValue, + itemVariant: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + popFromField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + byteLengthToPop: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + pushToField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + dataToPush: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + registerDelegation( + delegatee: PromiseOrValue, + delegationControlId: PromiseOrValue, + initFuncSelectorAndArgs: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + registerFunctionSelector( + resourceSelector: PromiseOrValue, + systemFunctionName: PromiseOrValue, + systemFunctionArguments: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + registerNamespace( + namespace: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + registerRootFunctionSelector( + resourceSelector: PromiseOrValue, + worldFunctionSelector: PromiseOrValue, + systemFunctionSelector: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + registerStoreHook( + table: PromiseOrValue, + hook: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + registerSystem( + resourceSelector: PromiseOrValue, + system: PromiseOrValue, + publicAccess: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + registerSystemHook( + resourceSelector: PromiseOrValue, + hook: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + registerTable( + table: PromiseOrValue, + fieldLayout: PromiseOrValue, + keySchema: PromiseOrValue, + valueSchema: PromiseOrValue, + keyNames: PromiseOrValue[], + fieldNames: PromiseOrValue[], + overrides?: CallOverrides + ): Promise; + + revokeAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + sendMessage( + message: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + setField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + setRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + staticArrayBytesStruct( + arg0: [BytesStructStruct], + overrides?: CallOverrides + ): Promise; + + staticArrayStringStruct( + arg0: [StringStructStruct], + overrides?: CallOverrides + ): Promise; + + transferOwnership( + namespace: PromiseOrValue, + newOwner: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + updateInField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + startByteIndex: PromiseOrValue, + dataToSet: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + willRevert(overrides?: CallOverrides): Promise; + }; + + filters: { + "HelloWorld()"(): HelloWorldEventFilter; + HelloWorld(): HelloWorldEventFilter; + + "StoreDeleteRecord(bytes32,bytes32[])"( + table?: null, + key?: null + ): StoreDeleteRecordEventFilter; + StoreDeleteRecord(table?: null, key?: null): StoreDeleteRecordEventFilter; + + "StoreEphemeralRecord(bytes32,bytes32[],bytes)"( + table?: null, + key?: null, + data?: null + ): StoreEphemeralRecordEventFilter; + StoreEphemeralRecord( + table?: null, + key?: null, + data?: null + ): StoreEphemeralRecordEventFilter; + + "StoreSetField(bytes32,bytes32[],uint8,bytes)"( + table?: null, + key?: null, + schemaIndex?: null, + data?: null + ): StoreSetFieldEventFilter; + StoreSetField( + table?: null, + key?: null, + schemaIndex?: null, + data?: null + ): StoreSetFieldEventFilter; + + "StoreSetRecord(bytes32,bytes32[],bytes)"( + table?: null, + key?: null, + data?: null + ): StoreSetRecordEventFilter; + StoreSetRecord( + table?: null, + key?: null, + data?: null + ): StoreSetRecordEventFilter; + }; + + estimateGas: { + call( + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: PayableOverrides & { from?: PromiseOrValue } + ): Promise; + + callFrom( + delegator: PromiseOrValue, + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: PayableOverrides & { from?: PromiseOrValue } + ): Promise; + + deleteRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + dynamicArrayBytesStruct( + arg0: BytesStructStruct[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + dynamicArrayStringStruct( + arg0: StringStructStruct[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + emitEphemeralRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + getField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldLayout( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldLength( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldSlice( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + start: PromiseOrValue, + end: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getKeySchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getValueSchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + grantAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + increment( + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + installModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + installRootModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pickUp( + item: PromiseOrValue, + itemVariant: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + popFromField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + byteLengthToPop: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pushToField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + dataToPush: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerDelegation( + delegatee: PromiseOrValue, + delegationControlId: PromiseOrValue, + initFuncSelectorAndArgs: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerFunctionSelector( + resourceSelector: PromiseOrValue, + systemFunctionName: PromiseOrValue, + systemFunctionArguments: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerNamespace( + namespace: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerRootFunctionSelector( + resourceSelector: PromiseOrValue, + worldFunctionSelector: PromiseOrValue, + systemFunctionSelector: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerStoreHook( + table: PromiseOrValue, + hook: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerSystem( + resourceSelector: PromiseOrValue, + system: PromiseOrValue, + publicAccess: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerSystemHook( + resourceSelector: PromiseOrValue, + hook: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerTable( + table: PromiseOrValue, + fieldLayout: PromiseOrValue, + keySchema: PromiseOrValue, + valueSchema: PromiseOrValue, + keyNames: PromiseOrValue[], + fieldNames: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + revokeAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + sendMessage( + message: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + staticArrayBytesStruct( + arg0: [BytesStructStruct], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + staticArrayStringStruct( + arg0: [StringStructStruct], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + transferOwnership( + namespace: PromiseOrValue, + newOwner: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + updateInField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + startByteIndex: PromiseOrValue, + dataToSet: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + willRevert( + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + }; + + populateTransaction: { + call( + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: PayableOverrides & { from?: PromiseOrValue } + ): Promise; + + callFrom( + delegator: PromiseOrValue, + resourceSelector: PromiseOrValue, + funcSelectorAndArgs: PromiseOrValue, + overrides?: PayableOverrides & { from?: PromiseOrValue } + ): Promise; + + deleteRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + dynamicArrayBytesStruct( + arg0: BytesStructStruct[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + dynamicArrayStringStruct( + arg0: StringStructStruct[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + emitEphemeralRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + getField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldLayout( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldLength( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getFieldSlice( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + fieldLayout: PromiseOrValue, + start: PromiseOrValue, + end: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getKeySchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + fieldLayout: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + getValueSchema( + table: PromiseOrValue, + overrides?: CallOverrides + ): Promise; + + grantAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + increment( + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + installModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + installRootModule( + module: PromiseOrValue, + args: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pickUp( + item: PromiseOrValue, + itemVariant: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + popFromField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + byteLengthToPop: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + pushToField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + dataToPush: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerDelegation( + delegatee: PromiseOrValue, + delegationControlId: PromiseOrValue, + initFuncSelectorAndArgs: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerFunctionSelector( + resourceSelector: PromiseOrValue, + systemFunctionName: PromiseOrValue, + systemFunctionArguments: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerNamespace( + namespace: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerRootFunctionSelector( + resourceSelector: PromiseOrValue, + worldFunctionSelector: PromiseOrValue, + systemFunctionSelector: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerStoreHook( + table: PromiseOrValue, + hook: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerSystem( + resourceSelector: PromiseOrValue, + system: PromiseOrValue, + publicAccess: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerSystemHook( + resourceSelector: PromiseOrValue, + hook: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + registerTable( + table: PromiseOrValue, + fieldLayout: PromiseOrValue, + keySchema: PromiseOrValue, + valueSchema: PromiseOrValue, + keyNames: PromiseOrValue[], + fieldNames: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + revokeAccess( + resourceSelector: PromiseOrValue, + grantee: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + sendMessage( + message: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + setRecord( + table: PromiseOrValue, + key: PromiseOrValue[], + data: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + staticArrayBytesStruct( + arg0: [BytesStructStruct], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + staticArrayStringStruct( + arg0: [StringStructStruct], + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + transferOwnership( + namespace: PromiseOrValue, + newOwner: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + updateInField( + table: PromiseOrValue, + key: PromiseOrValue[], + schemaIndex: PromiseOrValue, + startByteIndex: PromiseOrValue, + dataToSet: PromiseOrValue, + fieldLayout: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + + willRevert( + overrides?: Overrides & { from?: PromiseOrValue } + ): Promise; + }; +} diff --git a/examples/minimal/packages/contracts/types/ethers-contracts/factories/IWorld__factory.ts b/examples/minimal/packages/contracts/types/ethers-contracts/factories/IWorld__factory.ts new file mode 100644 index 0000000000..daaf23a05a --- /dev/null +++ b/examples/minimal/packages/contracts/types/ethers-contracts/factories/IWorld__factory.ts @@ -0,0 +1,1241 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from "ethers"; +import type { Provider } from "@ethersproject/providers"; +import type { IWorld, IWorldInterface } from "../IWorld"; + +const _abi = [ + { + inputs: [ + { + internalType: "string", + name: "resource", + type: "string", + }, + { + internalType: "address", + name: "caller", + type: "address", + }, + ], + name: "AccessDenied", + type: "error", + }, + { + inputs: [ + { + internalType: "address", + name: "delegator", + type: "address", + }, + { + internalType: "address", + name: "delegatee", + type: "address", + }, + ], + name: "DelegationNotFound", + type: "error", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "functionSelector", + type: "bytes4", + }, + ], + name: "FunctionSelectorExists", + type: "error", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "functionSelector", + type: "bytes4", + }, + ], + name: "FunctionSelectorNotFound", + type: "error", + }, + { + inputs: [ + { + internalType: "string", + name: "resource", + type: "string", + }, + ], + name: "InvalidSelector", + type: "error", + }, + { + inputs: [ + { + internalType: "string", + name: "module", + type: "string", + }, + ], + name: "ModuleAlreadyInstalled", + type: "error", + }, + { + inputs: [], + name: "MyCustomError", + type: "error", + }, + { + inputs: [ + { + internalType: "string", + name: "resource", + type: "string", + }, + ], + name: "ResourceExists", + type: "error", + }, + { + inputs: [ + { + internalType: "string", + name: "resource", + type: "string", + }, + ], + name: "ResourceNotFound", + type: "error", + }, + { + inputs: [ + { + internalType: "uint256", + name: "length", + type: "uint256", + }, + { + internalType: "uint256", + name: "received", + type: "uint256", + }, + ], + name: "StoreCore_DataIndexOverflow", + type: "error", + }, + { + inputs: [ + { + internalType: "uint256", + name: "expected", + type: "uint256", + }, + { + internalType: "uint256", + name: "received", + type: "uint256", + }, + ], + name: "StoreCore_InvalidDataLength", + type: "error", + }, + { + inputs: [ + { + internalType: "uint256", + name: "expected", + type: "uint256", + }, + { + internalType: "uint256", + name: "received", + type: "uint256", + }, + ], + name: "StoreCore_InvalidKeyNamesLength", + type: "error", + }, + { + inputs: [ + { + internalType: "uint256", + name: "expected", + type: "uint256", + }, + { + internalType: "uint256", + name: "received", + type: "uint256", + }, + ], + name: "StoreCore_InvalidValueNamesLength", + type: "error", + }, + { + inputs: [ + { + internalType: "uint256", + name: "expected", + type: "uint256", + }, + { + internalType: "uint256", + name: "received", + type: "uint256", + }, + ], + name: "StoreCore_InvalidValueSchemaLength", + type: "error", + }, + { + inputs: [], + name: "StoreCore_NotDynamicField", + type: "error", + }, + { + inputs: [], + name: "StoreCore_NotImplemented", + type: "error", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "tableId", + type: "bytes32", + }, + { + internalType: "string", + name: "tableIdString", + type: "string", + }, + ], + name: "StoreCore_TableAlreadyExists", + type: "error", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "tableId", + type: "bytes32", + }, + { + internalType: "string", + name: "tableIdString", + type: "string", + }, + ], + name: "StoreCore_TableNotFound", + type: "error", + }, + { + inputs: [ + { + internalType: "address", + name: "system", + type: "address", + }, + ], + name: "SystemExists", + type: "error", + }, + { + anonymous: false, + inputs: [], + name: "HelloWorld", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + indexed: false, + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + ], + name: "StoreDeleteRecord", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + indexed: false, + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + indexed: false, + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + name: "StoreEphemeralRecord", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + indexed: false, + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + indexed: false, + internalType: "uint8", + name: "schemaIndex", + type: "uint8", + }, + { + indexed: false, + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + name: "StoreSetField", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + indexed: false, + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + indexed: false, + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + name: "StoreSetRecord", + type: "event", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "resourceSelector", + type: "bytes32", + }, + { + internalType: "bytes", + name: "funcSelectorAndArgs", + type: "bytes", + }, + ], + name: "call", + outputs: [ + { + internalType: "bytes", + name: "", + type: "bytes", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "delegator", + type: "address", + }, + { + internalType: "bytes32", + name: "resourceSelector", + type: "bytes32", + }, + { + internalType: "bytes", + name: "funcSelectorAndArgs", + type: "bytes", + }, + ], + name: "callFrom", + outputs: [ + { + internalType: "bytes", + name: "", + type: "bytes", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "deleteRecord", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + components: [ + { + internalType: "bytes", + name: "value", + type: "bytes", + }, + ], + internalType: "struct BytesStruct[]", + name: "", + type: "tuple[]", + }, + ], + name: "dynamicArrayBytesStruct", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + components: [ + { + internalType: "string", + name: "value", + type: "string", + }, + ], + internalType: "struct StringStruct[]", + name: "", + type: "tuple[]", + }, + ], + name: "dynamicArrayStringStruct", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "emitEphemeralRecord", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "uint8", + name: "schemaIndex", + type: "uint8", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "getField", + outputs: [ + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + ], + name: "getFieldLayout", + outputs: [ + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "uint8", + name: "schemaIndex", + type: "uint8", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "getFieldLength", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "uint8", + name: "schemaIndex", + type: "uint8", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + { + internalType: "uint256", + name: "start", + type: "uint256", + }, + { + internalType: "uint256", + name: "end", + type: "uint256", + }, + ], + name: "getFieldSlice", + outputs: [ + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + ], + name: "getKeySchema", + outputs: [ + { + internalType: "Schema", + name: "schema", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "getRecord", + outputs: [ + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + ], + name: "getValueSchema", + outputs: [ + { + internalType: "Schema", + name: "schema", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "resourceSelector", + type: "bytes32", + }, + { + internalType: "address", + name: "grantee", + type: "address", + }, + ], + name: "grantAccess", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "increment", + outputs: [ + { + internalType: "uint32", + name: "", + type: "uint32", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "contract IModule", + name: "module", + type: "address", + }, + { + internalType: "bytes", + name: "args", + type: "bytes", + }, + ], + name: "installModule", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "contract IModule", + name: "module", + type: "address", + }, + { + internalType: "bytes", + name: "args", + type: "bytes", + }, + ], + name: "installRootModule", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint32", + name: "item", + type: "uint32", + }, + { + internalType: "uint32", + name: "itemVariant", + type: "uint32", + }, + ], + name: "pickUp", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "uint8", + name: "schemaIndex", + type: "uint8", + }, + { + internalType: "uint256", + name: "byteLengthToPop", + type: "uint256", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "popFromField", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "uint8", + name: "schemaIndex", + type: "uint8", + }, + { + internalType: "bytes", + name: "dataToPush", + type: "bytes", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "pushToField", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "delegatee", + type: "address", + }, + { + internalType: "bytes32", + name: "delegationControlId", + type: "bytes32", + }, + { + internalType: "bytes", + name: "initFuncSelectorAndArgs", + type: "bytes", + }, + ], + name: "registerDelegation", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "resourceSelector", + type: "bytes32", + }, + { + internalType: "string", + name: "systemFunctionName", + type: "string", + }, + { + internalType: "string", + name: "systemFunctionArguments", + type: "string", + }, + ], + name: "registerFunctionSelector", + outputs: [ + { + internalType: "bytes4", + name: "worldFunctionSelector", + type: "bytes4", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes16", + name: "namespace", + type: "bytes16", + }, + ], + name: "registerNamespace", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "resourceSelector", + type: "bytes32", + }, + { + internalType: "bytes4", + name: "worldFunctionSelector", + type: "bytes4", + }, + { + internalType: "bytes4", + name: "systemFunctionSelector", + type: "bytes4", + }, + ], + name: "registerRootFunctionSelector", + outputs: [ + { + internalType: "bytes4", + name: "", + type: "bytes4", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "contract IStoreHook", + name: "hook", + type: "address", + }, + ], + name: "registerStoreHook", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "resourceSelector", + type: "bytes32", + }, + { + internalType: "contract WorldContextConsumer", + name: "system", + type: "address", + }, + { + internalType: "bool", + name: "publicAccess", + type: "bool", + }, + ], + name: "registerSystem", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "resourceSelector", + type: "bytes32", + }, + { + internalType: "contract ISystemHook", + name: "hook", + type: "address", + }, + ], + name: "registerSystemHook", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + { + internalType: "Schema", + name: "keySchema", + type: "bytes32", + }, + { + internalType: "Schema", + name: "valueSchema", + type: "bytes32", + }, + { + internalType: "string[]", + name: "keyNames", + type: "string[]", + }, + { + internalType: "string[]", + name: "fieldNames", + type: "string[]", + }, + ], + name: "registerTable", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "resourceSelector", + type: "bytes32", + }, + { + internalType: "address", + name: "grantee", + type: "address", + }, + ], + name: "revokeAccess", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "string", + name: "message", + type: "string", + }, + ], + name: "sendMessage", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "uint8", + name: "schemaIndex", + type: "uint8", + }, + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "setField", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "setRecord", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + components: [ + { + internalType: "bytes", + name: "value", + type: "bytes", + }, + ], + internalType: "struct BytesStruct[1]", + name: "", + type: "tuple[1]", + }, + ], + name: "staticArrayBytesStruct", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + components: [ + { + internalType: "string", + name: "value", + type: "string", + }, + ], + internalType: "struct StringStruct[1]", + name: "", + type: "tuple[1]", + }, + ], + name: "staticArrayStringStruct", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes16", + name: "namespace", + type: "bytes16", + }, + { + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "transferOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "table", + type: "bytes32", + }, + { + internalType: "bytes32[]", + name: "key", + type: "bytes32[]", + }, + { + internalType: "uint8", + name: "schemaIndex", + type: "uint8", + }, + { + internalType: "uint256", + name: "startByteIndex", + type: "uint256", + }, + { + internalType: "bytes", + name: "dataToSet", + type: "bytes", + }, + { + internalType: "FieldLayout", + name: "fieldLayout", + type: "bytes32", + }, + ], + name: "updateInField", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "willRevert", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, +] as const; + +export class IWorld__factory { + static readonly abi = _abi; + static createInterface(): IWorldInterface { + return new utils.Interface(_abi) as IWorldInterface; + } + static connect(address: string, signerOrProvider: Signer | Provider): IWorld { + return new Contract(address, _abi, signerOrProvider) as IWorld; + } +} diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol index 49b381771c..177f030fde 100644 --- a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol +++ b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -29,6 +30,13 @@ struct Dynamics1Data { } library Dynamics1 { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](0); + + return FieldLayoutLib.encode(_fieldLayout, 5); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -65,14 +73,21 @@ library Dynamics1 { fieldNames[4] = "staticBools"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get staticB32 */ @@ -80,7 +95,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return toStaticArray_bytes32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -89,7 +104,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return toStaticArray_bytes32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -103,7 +118,7 @@ library Dynamics1 { _keyTuple, 0, EncodeArray.encode(fromStaticArray_bytes32_1(staticB32)), - getValueSchema() + getFieldLayout() ); } @@ -112,7 +127,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode(fromStaticArray_bytes32_1(staticB32)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode(fromStaticArray_bytes32_1(staticB32)), getFieldLayout()); } /** Get the length of staticB32 */ @@ -120,7 +135,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 32; } @@ -131,7 +146,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 32; } @@ -150,7 +165,7 @@ library Dynamics1 { _tableId, _keyTuple, 0, - getValueSchema(), + getFieldLayout(), _index * 32, (_index + 1) * 32 ); @@ -171,7 +186,7 @@ library Dynamics1 { _tableId, _keyTuple, 0, - getValueSchema(), + getFieldLayout(), _index * 32, (_index + 1) * 32 ); @@ -184,7 +199,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to staticB32 (using the specified store) */ @@ -192,7 +207,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from staticB32 */ @@ -200,7 +215,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.popFromField(_tableId, _keyTuple, 0, 32, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 32, getFieldLayout()); } /** Pop an element from staticB32 (using the specified store) */ @@ -208,7 +223,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.popFromField(_tableId, _keyTuple, 0, 32, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 0, 32, getFieldLayout()); } /** @@ -220,7 +235,7 @@ library Dynamics1 { _keyTuple[0] = key; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), getFieldLayout()); } } @@ -233,7 +248,7 @@ library Dynamics1 { _keyTuple[0] = key; unchecked { - _store.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), getFieldLayout()); } } @@ -242,7 +257,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getFieldLayout()); return toStaticArray_int32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_int32()); } @@ -251,7 +266,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getFieldLayout()); return toStaticArray_int32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_int32()); } @@ -265,7 +280,7 @@ library Dynamics1 { _keyTuple, 1, EncodeArray.encode(fromStaticArray_int32_2(staticI32)), - getValueSchema() + getFieldLayout() ); } @@ -274,7 +289,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 1, EncodeArray.encode(fromStaticArray_int32_2(staticI32)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 1, EncodeArray.encode(fromStaticArray_int32_2(staticI32)), getFieldLayout()); } /** Get the length of staticI32 */ @@ -282,7 +297,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 1, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 1, getFieldLayout()); unchecked { return _byteLength / 4; } @@ -293,7 +308,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 1, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 1, getFieldLayout()); unchecked { return _byteLength / 4; } @@ -312,7 +327,7 @@ library Dynamics1 { _tableId, _keyTuple, 1, - getValueSchema(), + getFieldLayout(), _index * 4, (_index + 1) * 4 ); @@ -329,7 +344,7 @@ library Dynamics1 { _keyTuple[0] = key; unchecked { - bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 1, getValueSchema(), _index * 4, (_index + 1) * 4); + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 1, getFieldLayout(), _index * 4, (_index + 1) * 4); return (int32(uint32(Bytes.slice4(_blob, 0)))); } } @@ -339,7 +354,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.pushToField(_tableId, _keyTuple, 1, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 1, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to staticI32 (using the specified store) */ @@ -347,7 +362,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.pushToField(_tableId, _keyTuple, 1, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 1, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from staticI32 */ @@ -355,7 +370,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.popFromField(_tableId, _keyTuple, 1, 4, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 1, 4, getFieldLayout()); } /** Pop an element from staticI32 (using the specified store) */ @@ -363,7 +378,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.popFromField(_tableId, _keyTuple, 1, 4, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 1, 4, getFieldLayout()); } /** @@ -375,7 +390,7 @@ library Dynamics1 { _keyTuple[0] = key; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 1, _index * 4, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 1, _index * 4, abi.encodePacked((_element)), getFieldLayout()); } } @@ -388,7 +403,7 @@ library Dynamics1 { _keyTuple[0] = key; unchecked { - _store.updateInField(_tableId, _keyTuple, 1, _index * 4, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 1, _index * 4, abi.encodePacked((_element)), getFieldLayout()); } } @@ -397,7 +412,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, getFieldLayout()); return toStaticArray_uint128_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint128()); } @@ -406,7 +421,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, getFieldLayout()); return toStaticArray_uint128_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint128()); } @@ -420,7 +435,7 @@ library Dynamics1 { _keyTuple, 2, EncodeArray.encode(fromStaticArray_uint128_3(staticU128)), - getValueSchema() + getFieldLayout() ); } @@ -434,7 +449,7 @@ library Dynamics1 { _keyTuple, 2, EncodeArray.encode(fromStaticArray_uint128_3(staticU128)), - getValueSchema() + getFieldLayout() ); } @@ -443,7 +458,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 2, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 2, getFieldLayout()); unchecked { return _byteLength / 16; } @@ -454,7 +469,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 2, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 2, getFieldLayout()); unchecked { return _byteLength / 16; } @@ -473,7 +488,7 @@ library Dynamics1 { _tableId, _keyTuple, 2, - getValueSchema(), + getFieldLayout(), _index * 16, (_index + 1) * 16 ); @@ -494,7 +509,7 @@ library Dynamics1 { _tableId, _keyTuple, 2, - getValueSchema(), + getFieldLayout(), _index * 16, (_index + 1) * 16 ); @@ -507,7 +522,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to staticU128 (using the specified store) */ @@ -515,7 +530,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from staticU128 */ @@ -523,7 +538,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.popFromField(_tableId, _keyTuple, 2, 16, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 2, 16, getFieldLayout()); } /** Pop an element from staticU128 (using the specified store) */ @@ -531,7 +546,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.popFromField(_tableId, _keyTuple, 2, 16, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 2, 16, getFieldLayout()); } /** @@ -543,7 +558,7 @@ library Dynamics1 { _keyTuple[0] = key; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 2, _index * 16, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 2, _index * 16, abi.encodePacked((_element)), getFieldLayout()); } } @@ -556,7 +571,7 @@ library Dynamics1 { _keyTuple[0] = key; unchecked { - _store.updateInField(_tableId, _keyTuple, 2, _index * 16, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 2, _index * 16, abi.encodePacked((_element)), getFieldLayout()); } } @@ -565,7 +580,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3, getFieldLayout()); return toStaticArray_address_4(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); } @@ -574,7 +589,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 3, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 3, getFieldLayout()); return toStaticArray_address_4(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); } @@ -588,7 +603,7 @@ library Dynamics1 { _keyTuple, 3, EncodeArray.encode(fromStaticArray_address_4(staticAddrs)), - getValueSchema() + getFieldLayout() ); } @@ -602,7 +617,7 @@ library Dynamics1 { _keyTuple, 3, EncodeArray.encode(fromStaticArray_address_4(staticAddrs)), - getValueSchema() + getFieldLayout() ); } @@ -611,7 +626,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 3, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 3, getFieldLayout()); unchecked { return _byteLength / 20; } @@ -622,7 +637,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 3, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 3, getFieldLayout()); unchecked { return _byteLength / 20; } @@ -641,7 +656,7 @@ library Dynamics1 { _tableId, _keyTuple, 3, - getValueSchema(), + getFieldLayout(), _index * 20, (_index + 1) * 20 ); @@ -662,7 +677,7 @@ library Dynamics1 { _tableId, _keyTuple, 3, - getValueSchema(), + getFieldLayout(), _index * 20, (_index + 1) * 20 ); @@ -675,7 +690,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.pushToField(_tableId, _keyTuple, 3, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 3, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to staticAddrs (using the specified store) */ @@ -683,7 +698,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.pushToField(_tableId, _keyTuple, 3, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 3, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from staticAddrs */ @@ -691,7 +706,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.popFromField(_tableId, _keyTuple, 3, 20, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 3, 20, getFieldLayout()); } /** Pop an element from staticAddrs (using the specified store) */ @@ -699,7 +714,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.popFromField(_tableId, _keyTuple, 3, 20, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 3, 20, getFieldLayout()); } /** @@ -711,7 +726,7 @@ library Dynamics1 { _keyTuple[0] = key; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 3, _index * 20, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 3, _index * 20, abi.encodePacked((_element)), getFieldLayout()); } } @@ -724,7 +739,7 @@ library Dynamics1 { _keyTuple[0] = key; unchecked { - _store.updateInField(_tableId, _keyTuple, 3, _index * 20, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 3, _index * 20, abi.encodePacked((_element)), getFieldLayout()); } } @@ -733,7 +748,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 4, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 4, getFieldLayout()); return toStaticArray_bool_5(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bool()); } @@ -742,7 +757,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 4, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 4, getFieldLayout()); return toStaticArray_bool_5(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bool()); } @@ -756,7 +771,7 @@ library Dynamics1 { _keyTuple, 4, EncodeArray.encode(fromStaticArray_bool_5(staticBools)), - getValueSchema() + getFieldLayout() ); } @@ -765,7 +780,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 4, EncodeArray.encode(fromStaticArray_bool_5(staticBools)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 4, EncodeArray.encode(fromStaticArray_bool_5(staticBools)), getFieldLayout()); } /** Get the length of staticBools */ @@ -773,7 +788,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 4, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 4, getFieldLayout()); unchecked { return _byteLength / 1; } @@ -784,7 +799,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 4, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 4, getFieldLayout()); unchecked { return _byteLength / 1; } @@ -803,7 +818,7 @@ library Dynamics1 { _tableId, _keyTuple, 4, - getValueSchema(), + getFieldLayout(), _index * 1, (_index + 1) * 1 ); @@ -820,7 +835,7 @@ library Dynamics1 { _keyTuple[0] = key; unchecked { - bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 4, getValueSchema(), _index * 1, (_index + 1) * 1); + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 4, getFieldLayout(), _index * 1, (_index + 1) * 1); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } } @@ -830,7 +845,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.pushToField(_tableId, _keyTuple, 4, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 4, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to staticBools (using the specified store) */ @@ -838,7 +853,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.pushToField(_tableId, _keyTuple, 4, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 4, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from staticBools */ @@ -846,7 +861,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.popFromField(_tableId, _keyTuple, 4, 1, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 4, 1, getFieldLayout()); } /** Pop an element from staticBools (using the specified store) */ @@ -854,7 +869,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.popFromField(_tableId, _keyTuple, 4, 1, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 4, 1, getFieldLayout()); } /** @@ -866,7 +881,7 @@ library Dynamics1 { _keyTuple[0] = key; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 4, _index * 1, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 4, _index * 1, abi.encodePacked((_element)), getFieldLayout()); } } @@ -879,7 +894,7 @@ library Dynamics1 { _keyTuple[0] = key; unchecked { - _store.updateInField(_tableId, _keyTuple, 4, _index * 1, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 4, _index * 1, abi.encodePacked((_element)), getFieldLayout()); } } @@ -888,7 +903,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -897,7 +912,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -915,7 +930,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using individual values (using the specified store) */ @@ -933,7 +948,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + _store.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using the data struct */ @@ -947,7 +962,7 @@ library Dynamics1 { } /** - * Decode the tightly packed blob using this table's schema. + * Decode the tightly packed blob using this table's field layout. * Undefined behaviour for invalid blobs. */ function decode(bytes memory _blob) internal pure returns (Dynamics1Data memory _table) { @@ -990,7 +1005,7 @@ library Dynamics1 { } } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode( bytes32[1] memory staticB32, int32[2] memory staticI32, @@ -1021,7 +1036,7 @@ library Dynamics1 { ); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes32 key) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; @@ -1034,7 +1049,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -1042,7 +1057,7 @@ library Dynamics1 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol index 79272c9e40..7b9dfd6f1a 100644 --- a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol +++ b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -27,6 +28,13 @@ struct Dynamics2Data { } library Dynamics2 { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](0); + + return FieldLayoutLib.encode(_fieldLayout, 3); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -59,14 +67,21 @@ library Dynamics2 { fieldNames[2] = "b"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get u64 */ @@ -74,7 +89,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint64()); } @@ -83,7 +98,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint64()); } @@ -92,7 +107,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((u64)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((u64)), getFieldLayout()); } /** Set u64 (using the specified store) */ @@ -100,7 +115,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((u64)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((u64)), getFieldLayout()); } /** Get the length of u64 */ @@ -108,7 +123,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 8; } @@ -119,7 +134,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 8; } @@ -138,7 +153,7 @@ library Dynamics2 { _tableId, _keyTuple, 0, - getValueSchema(), + getFieldLayout(), _index * 8, (_index + 1) * 8 ); @@ -155,7 +170,7 @@ library Dynamics2 { _keyTuple[0] = key; unchecked { - bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, getValueSchema(), _index * 8, (_index + 1) * 8); + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, getFieldLayout(), _index * 8, (_index + 1) * 8); return (uint64(Bytes.slice8(_blob, 0))); } } @@ -165,7 +180,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to u64 (using the specified store) */ @@ -173,7 +188,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from u64 */ @@ -181,7 +196,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.popFromField(_tableId, _keyTuple, 0, 8, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 8, getFieldLayout()); } /** Pop an element from u64 (using the specified store) */ @@ -189,7 +204,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.popFromField(_tableId, _keyTuple, 0, 8, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 0, 8, getFieldLayout()); } /** @@ -201,7 +216,7 @@ library Dynamics2 { _keyTuple[0] = key; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 8, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 8, abi.encodePacked((_element)), getFieldLayout()); } } @@ -214,7 +229,7 @@ library Dynamics2 { _keyTuple[0] = key; unchecked { - _store.updateInField(_tableId, _keyTuple, 0, _index * 8, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 0, _index * 8, abi.encodePacked((_element)), getFieldLayout()); } } @@ -223,7 +238,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (string(_blob)); } @@ -232,7 +247,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (string(_blob)); } @@ -241,7 +256,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setField(_tableId, _keyTuple, 1, bytes((str)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 1, bytes((str)), getFieldLayout()); } /** Set str (using the specified store) */ @@ -249,7 +264,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 1, bytes((str)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 1, bytes((str)), getFieldLayout()); } /** Get the length of str */ @@ -257,7 +272,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 1, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 1, getFieldLayout()); unchecked { return _byteLength / 1; } @@ -268,7 +283,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 1, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 1, getFieldLayout()); unchecked { return _byteLength / 1; } @@ -287,7 +302,7 @@ library Dynamics2 { _tableId, _keyTuple, 1, - getValueSchema(), + getFieldLayout(), _index * 1, (_index + 1) * 1 ); @@ -304,7 +319,7 @@ library Dynamics2 { _keyTuple[0] = key; unchecked { - bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 1, getValueSchema(), _index * 1, (_index + 1) * 1); + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 1, getFieldLayout(), _index * 1, (_index + 1) * 1); return (string(_blob)); } } @@ -314,7 +329,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.pushToField(_tableId, _keyTuple, 1, bytes((_slice)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 1, bytes((_slice)), getFieldLayout()); } /** Push a slice to str (using the specified store) */ @@ -322,7 +337,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.pushToField(_tableId, _keyTuple, 1, bytes((_slice)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 1, bytes((_slice)), getFieldLayout()); } /** Pop a slice from str */ @@ -330,7 +345,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.popFromField(_tableId, _keyTuple, 1, 1, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 1, 1, getFieldLayout()); } /** Pop a slice from str (using the specified store) */ @@ -338,7 +353,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.popFromField(_tableId, _keyTuple, 1, 1, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 1, 1, getFieldLayout()); } /** @@ -350,7 +365,7 @@ library Dynamics2 { _keyTuple[0] = key; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 1, _index * 1, bytes((_slice)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 1, _index * 1, bytes((_slice)), getFieldLayout()); } } @@ -363,7 +378,7 @@ library Dynamics2 { _keyTuple[0] = key; unchecked { - _store.updateInField(_tableId, _keyTuple, 1, _index * 1, bytes((_slice)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 1, _index * 1, bytes((_slice)), getFieldLayout()); } } @@ -372,7 +387,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, getFieldLayout()); return (bytes(_blob)); } @@ -381,7 +396,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, getFieldLayout()); return (bytes(_blob)); } @@ -390,7 +405,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setField(_tableId, _keyTuple, 2, bytes((b)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 2, bytes((b)), getFieldLayout()); } /** Set b (using the specified store) */ @@ -398,7 +413,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 2, bytes((b)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 2, bytes((b)), getFieldLayout()); } /** Get the length of b */ @@ -406,7 +421,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 2, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 2, getFieldLayout()); unchecked { return _byteLength / 1; } @@ -417,7 +432,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 2, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 2, getFieldLayout()); unchecked { return _byteLength / 1; } @@ -436,7 +451,7 @@ library Dynamics2 { _tableId, _keyTuple, 2, - getValueSchema(), + getFieldLayout(), _index * 1, (_index + 1) * 1 ); @@ -453,7 +468,7 @@ library Dynamics2 { _keyTuple[0] = key; unchecked { - bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 2, getValueSchema(), _index * 1, (_index + 1) * 1); + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 2, getFieldLayout(), _index * 1, (_index + 1) * 1); return (bytes(_blob)); } } @@ -463,7 +478,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.pushToField(_tableId, _keyTuple, 2, bytes((_slice)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 2, bytes((_slice)), getFieldLayout()); } /** Push a slice to b (using the specified store) */ @@ -471,7 +486,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.pushToField(_tableId, _keyTuple, 2, bytes((_slice)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 2, bytes((_slice)), getFieldLayout()); } /** Pop a slice from b */ @@ -479,7 +494,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.popFromField(_tableId, _keyTuple, 2, 1, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 2, 1, getFieldLayout()); } /** Pop a slice from b (using the specified store) */ @@ -487,7 +502,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.popFromField(_tableId, _keyTuple, 2, 1, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 2, 1, getFieldLayout()); } /** @@ -499,7 +514,7 @@ library Dynamics2 { _keyTuple[0] = key; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 2, _index * 1, bytes((_slice)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 2, _index * 1, bytes((_slice)), getFieldLayout()); } } @@ -512,7 +527,7 @@ library Dynamics2 { _keyTuple[0] = key; unchecked { - _store.updateInField(_tableId, _keyTuple, 2, _index * 1, bytes((_slice)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 2, _index * 1, bytes((_slice)), getFieldLayout()); } } @@ -521,7 +536,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -530,7 +545,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -541,7 +556,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using individual values (using the specified store) */ @@ -551,7 +566,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + _store.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using the data struct */ @@ -565,7 +580,7 @@ library Dynamics2 { } /** - * Decode the tightly packed blob using this table's schema. + * Decode the tightly packed blob using this table's field layout. * Undefined behaviour for invalid blobs. */ function decode(bytes memory _blob) internal pure returns (Dynamics2Data memory _table) { @@ -596,7 +611,7 @@ library Dynamics2 { } } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(uint64[] memory u64, string memory str, bytes memory b) internal pure returns (bytes memory) { PackedCounter _encodedLengths; // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits @@ -607,7 +622,7 @@ library Dynamics2 { return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode((u64)), bytes((str)), bytes((b))); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes32 key) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; @@ -620,7 +635,7 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -628,6 +643,6 @@ library Dynamics2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/cli/contracts/src/codegen/tables/Ephemeral.sol b/packages/cli/contracts/src/codegen/tables/Ephemeral.sol index 16f69fc94b..61225beb79 100644 --- a/packages/cli/contracts/src/codegen/tables/Ephemeral.sol +++ b/packages/cli/contracts/src/codegen/tables/Ephemeral.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,14 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Ephem bytes32 constant EphemeralTableId = _tableId; library Ephemeral { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 32; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -49,14 +58,21 @@ library Ephemeral { fieldNames[0] = "value"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Emit the ephemeral event using individual values */ @@ -66,7 +82,7 @@ library Ephemeral { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.emitEphemeralRecord(_tableId, _keyTuple, _data, getValueSchema()); + StoreSwitch.emitEphemeralRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Emit the ephemeral event using individual values (using the specified store) */ @@ -76,15 +92,15 @@ library Ephemeral { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.emitEphemeralRecord(_tableId, _keyTuple, _data, getValueSchema()); + _store.emitEphemeralRecord(_tableId, _keyTuple, _data, getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(uint256 value) internal pure returns (bytes memory) { return abi.encodePacked(value); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes32 key) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; diff --git a/packages/cli/contracts/src/codegen/tables/Singleton.sol b/packages/cli/contracts/src/codegen/tables/Singleton.sol index f3632fbf3d..2c8f5b0f95 100644 --- a/packages/cli/contracts/src/codegen/tables/Singleton.sol +++ b/packages/cli/contracts/src/codegen/tables/Singleton.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,14 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Singl bytes32 constant SingletonTableId = _tableId; library Singleton { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 32; + + return FieldLayoutLib.encode(_fieldLayout, 3); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](0); @@ -53,21 +62,28 @@ library Singleton { fieldNames[3] = "v4"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get v1 */ function getV1() internal view returns (int256 v1) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (int256(uint256(Bytes.slice32(_blob, 0)))); } @@ -75,7 +91,7 @@ library Singleton { function getV1(IStore _store) internal view returns (int256 v1) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (int256(uint256(Bytes.slice32(_blob, 0)))); } @@ -83,21 +99,21 @@ library Singleton { function setV1(int256 v1) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((v1)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((v1)), getFieldLayout()); } /** Set v1 (using the specified store) */ function setV1(IStore _store, int256 v1) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((v1)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((v1)), getFieldLayout()); } /** Get v2 */ function getV2() internal view returns (uint32[2] memory v2) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getFieldLayout()); return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -105,7 +121,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, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getFieldLayout()); return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -113,21 +129,21 @@ library Singleton { function setV2(uint32[2] memory v2) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.setField(_tableId, _keyTuple, 1, EncodeArray.encode(fromStaticArray_uint32_2(v2)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 1, EncodeArray.encode(fromStaticArray_uint32_2(v2)), getFieldLayout()); } /** Set v2 (using the specified store) */ function setV2(IStore _store, uint32[2] memory v2) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.setField(_tableId, _keyTuple, 1, EncodeArray.encode(fromStaticArray_uint32_2(v2)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 1, EncodeArray.encode(fromStaticArray_uint32_2(v2)), getFieldLayout()); } /** Get the length of v2 */ function lengthV2() internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](0); - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 1, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 1, getFieldLayout()); unchecked { return _byteLength / 4; } @@ -137,7 +153,7 @@ library Singleton { function lengthV2(IStore _store) internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](0); - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 1, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 1, getFieldLayout()); unchecked { return _byteLength / 4; } @@ -155,7 +171,7 @@ library Singleton { _tableId, _keyTuple, 1, - getValueSchema(), + getFieldLayout(), _index * 4, (_index + 1) * 4 ); @@ -171,7 +187,7 @@ library Singleton { bytes32[] memory _keyTuple = new bytes32[](0); unchecked { - bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 1, getValueSchema(), _index * 4, (_index + 1) * 4); + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 1, getFieldLayout(), _index * 4, (_index + 1) * 4); return (uint32(Bytes.slice4(_blob, 0))); } } @@ -180,28 +196,28 @@ library Singleton { function pushV2(uint32 _element) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.pushToField(_tableId, _keyTuple, 1, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 1, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to v2 (using the specified store) */ function pushV2(IStore _store, uint32 _element) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.pushToField(_tableId, _keyTuple, 1, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 1, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from v2 */ function popV2() internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.popFromField(_tableId, _keyTuple, 1, 4, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 1, 4, getFieldLayout()); } /** Pop an element from v2 (using the specified store) */ function popV2(IStore _store) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.popFromField(_tableId, _keyTuple, 1, 4, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 1, 4, getFieldLayout()); } /** @@ -212,7 +228,7 @@ library Singleton { bytes32[] memory _keyTuple = new bytes32[](0); unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 1, _index * 4, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 1, _index * 4, abi.encodePacked((_element)), getFieldLayout()); } } @@ -224,7 +240,7 @@ library Singleton { bytes32[] memory _keyTuple = new bytes32[](0); unchecked { - _store.updateInField(_tableId, _keyTuple, 1, _index * 4, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 1, _index * 4, abi.encodePacked((_element)), getFieldLayout()); } } @@ -232,7 +248,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, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, getFieldLayout()); return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -240,7 +256,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, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, getFieldLayout()); return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -248,21 +264,21 @@ library Singleton { function setV3(uint32[2] memory v3) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.setField(_tableId, _keyTuple, 2, EncodeArray.encode(fromStaticArray_uint32_2(v3)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 2, EncodeArray.encode(fromStaticArray_uint32_2(v3)), getFieldLayout()); } /** Set v3 (using the specified store) */ function setV3(IStore _store, uint32[2] memory v3) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.setField(_tableId, _keyTuple, 2, EncodeArray.encode(fromStaticArray_uint32_2(v3)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 2, EncodeArray.encode(fromStaticArray_uint32_2(v3)), getFieldLayout()); } /** Get the length of v3 */ function lengthV3() internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](0); - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 2, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 2, getFieldLayout()); unchecked { return _byteLength / 4; } @@ -272,7 +288,7 @@ library Singleton { function lengthV3(IStore _store) internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](0); - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 2, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 2, getFieldLayout()); unchecked { return _byteLength / 4; } @@ -290,7 +306,7 @@ library Singleton { _tableId, _keyTuple, 2, - getValueSchema(), + getFieldLayout(), _index * 4, (_index + 1) * 4 ); @@ -306,7 +322,7 @@ library Singleton { bytes32[] memory _keyTuple = new bytes32[](0); unchecked { - bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 2, getValueSchema(), _index * 4, (_index + 1) * 4); + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 2, getFieldLayout(), _index * 4, (_index + 1) * 4); return (uint32(Bytes.slice4(_blob, 0))); } } @@ -315,28 +331,28 @@ library Singleton { function pushV3(uint32 _element) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to v3 (using the specified store) */ function pushV3(IStore _store, uint32 _element) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from v3 */ function popV3() internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.popFromField(_tableId, _keyTuple, 2, 4, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 2, 4, getFieldLayout()); } /** Pop an element from v3 (using the specified store) */ function popV3(IStore _store) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.popFromField(_tableId, _keyTuple, 2, 4, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 2, 4, getFieldLayout()); } /** @@ -347,7 +363,7 @@ library Singleton { bytes32[] memory _keyTuple = new bytes32[](0); unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 2, _index * 4, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 2, _index * 4, abi.encodePacked((_element)), getFieldLayout()); } } @@ -359,7 +375,7 @@ library Singleton { bytes32[] memory _keyTuple = new bytes32[](0); unchecked { - _store.updateInField(_tableId, _keyTuple, 2, _index * 4, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 2, _index * 4, abi.encodePacked((_element)), getFieldLayout()); } } @@ -367,7 +383,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, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3, getFieldLayout()); return toStaticArray_uint32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -375,7 +391,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, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 3, getFieldLayout()); return toStaticArray_uint32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -383,21 +399,21 @@ library Singleton { function setV4(uint32[1] memory v4) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.setField(_tableId, _keyTuple, 3, EncodeArray.encode(fromStaticArray_uint32_1(v4)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 3, EncodeArray.encode(fromStaticArray_uint32_1(v4)), getFieldLayout()); } /** Set v4 (using the specified store) */ function setV4(IStore _store, uint32[1] memory v4) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.setField(_tableId, _keyTuple, 3, EncodeArray.encode(fromStaticArray_uint32_1(v4)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 3, EncodeArray.encode(fromStaticArray_uint32_1(v4)), getFieldLayout()); } /** Get the length of v4 */ function lengthV4() internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](0); - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 3, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 3, getFieldLayout()); unchecked { return _byteLength / 4; } @@ -407,7 +423,7 @@ library Singleton { function lengthV4(IStore _store) internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](0); - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 3, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 3, getFieldLayout()); unchecked { return _byteLength / 4; } @@ -425,7 +441,7 @@ library Singleton { _tableId, _keyTuple, 3, - getValueSchema(), + getFieldLayout(), _index * 4, (_index + 1) * 4 ); @@ -441,7 +457,7 @@ library Singleton { bytes32[] memory _keyTuple = new bytes32[](0); unchecked { - bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 3, getValueSchema(), _index * 4, (_index + 1) * 4); + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 3, getFieldLayout(), _index * 4, (_index + 1) * 4); return (uint32(Bytes.slice4(_blob, 0))); } } @@ -450,28 +466,28 @@ library Singleton { function pushV4(uint32 _element) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.pushToField(_tableId, _keyTuple, 3, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 3, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to v4 (using the specified store) */ function pushV4(IStore _store, uint32 _element) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.pushToField(_tableId, _keyTuple, 3, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 3, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from v4 */ function popV4() internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.popFromField(_tableId, _keyTuple, 3, 4, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 3, 4, getFieldLayout()); } /** Pop an element from v4 (using the specified store) */ function popV4(IStore _store) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.popFromField(_tableId, _keyTuple, 3, 4, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 3, 4, getFieldLayout()); } /** @@ -482,7 +498,7 @@ library Singleton { bytes32[] memory _keyTuple = new bytes32[](0); unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 3, _index * 4, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 3, _index * 4, abi.encodePacked((_element)), getFieldLayout()); } } @@ -494,7 +510,7 @@ library Singleton { bytes32[] memory _keyTuple = new bytes32[](0); unchecked { - _store.updateInField(_tableId, _keyTuple, 3, _index * 4, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 3, _index * 4, abi.encodePacked((_element)), getFieldLayout()); } } @@ -502,7 +518,7 @@ library Singleton { function get() internal view returns (int256 v1, uint32[2] memory v2, uint32[2] memory v3, uint32[1] memory v4) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -512,7 +528,7 @@ library Singleton { ) internal view returns (int256 v1, uint32[2] memory v2, uint32[2] memory v3, uint32[1] memory v4) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -522,7 +538,7 @@ library Singleton { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using individual values (using the specified store) */ @@ -531,11 +547,11 @@ library Singleton { bytes32[] memory _keyTuple = new bytes32[](0); - _store.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + _store.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** - * Decode the tightly packed blob using this table's schema. + * Decode the tightly packed blob using this table's field layout. * Undefined behaviour for invalid blobs. */ function decode( @@ -570,7 +586,7 @@ library Singleton { } } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode( int256 v1, uint32[2] memory v2, @@ -593,7 +609,7 @@ library Singleton { ); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple() internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](0); @@ -604,14 +620,14 @@ library Singleton { function deleteRecord() internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ function deleteRecord(IStore _store) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/cli/contracts/src/codegen/tables/Statics.sol b/packages/cli/contracts/src/codegen/tables/Statics.sol index c4356780c3..e2af928e82 100644 --- a/packages/cli/contracts/src/codegen/tables/Statics.sol +++ b/packages/cli/contracts/src/codegen/tables/Statics.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -34,6 +35,20 @@ struct StaticsData { } library Statics { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](7); + _fieldLayout[0] = 32; + _fieldLayout[1] = 4; + _fieldLayout[2] = 16; + _fieldLayout[3] = 20; + _fieldLayout[4] = 1; + _fieldLayout[5] = 1; + _fieldLayout[6] = 1; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](7); @@ -86,14 +101,21 @@ library Statics { fieldNames[6] = "v7"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get v1 */ @@ -115,7 +137,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint256(Bytes.slice32(_blob, 0))); } @@ -139,7 +161,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint256(Bytes.slice32(_blob, 0))); } @@ -154,7 +176,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((v1)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((v1)), getFieldLayout()); } /** Set v1 (using the specified store) */ @@ -178,7 +200,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((v1)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((v1)), getFieldLayout()); } /** Get v2 */ @@ -200,7 +222,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (int32(uint32(Bytes.slice4(_blob, 0)))); } @@ -224,7 +246,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (int32(uint32(Bytes.slice4(_blob, 0)))); } @@ -239,7 +261,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((v2)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((v2)), getFieldLayout()); } /** Set v2 (using the specified store) */ @@ -263,7 +285,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((v2)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((v2)), getFieldLayout()); } /** Get v3 */ @@ -285,7 +307,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, getFieldLayout()); return (Bytes.slice16(_blob, 0)); } @@ -309,7 +331,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, getFieldLayout()); return (Bytes.slice16(_blob, 0)); } @@ -324,7 +346,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - StoreSwitch.setField(_tableId, _keyTuple, 2, abi.encodePacked((v3)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 2, abi.encodePacked((v3)), getFieldLayout()); } /** Set v3 (using the specified store) */ @@ -348,7 +370,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - _store.setField(_tableId, _keyTuple, 2, abi.encodePacked((v3)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 2, abi.encodePacked((v3)), getFieldLayout()); } /** Get v4 */ @@ -370,7 +392,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3, getFieldLayout()); return (address(Bytes.slice20(_blob, 0))); } @@ -394,7 +416,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 3, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 3, getFieldLayout()); return (address(Bytes.slice20(_blob, 0))); } @@ -409,7 +431,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - StoreSwitch.setField(_tableId, _keyTuple, 3, abi.encodePacked((v4)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 3, abi.encodePacked((v4)), getFieldLayout()); } /** Set v4 (using the specified store) */ @@ -433,7 +455,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - _store.setField(_tableId, _keyTuple, 3, abi.encodePacked((v4)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 3, abi.encodePacked((v4)), getFieldLayout()); } /** Get v5 */ @@ -455,7 +477,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 4, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 4, getFieldLayout()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -479,7 +501,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 4, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 4, getFieldLayout()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -494,7 +516,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - StoreSwitch.setField(_tableId, _keyTuple, 4, abi.encodePacked((v5)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 4, abi.encodePacked((v5)), getFieldLayout()); } /** Set v5 (using the specified store) */ @@ -518,7 +540,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - _store.setField(_tableId, _keyTuple, 4, abi.encodePacked((v5)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 4, abi.encodePacked((v5)), getFieldLayout()); } /** Get v6 */ @@ -540,7 +562,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 5, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 5, getFieldLayout()); return Enum1(uint8(Bytes.slice1(_blob, 0))); } @@ -564,7 +586,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 5, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 5, getFieldLayout()); return Enum1(uint8(Bytes.slice1(_blob, 0))); } @@ -579,7 +601,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - StoreSwitch.setField(_tableId, _keyTuple, 5, abi.encodePacked(uint8(v6)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 5, abi.encodePacked(uint8(v6)), getFieldLayout()); } /** Set v6 (using the specified store) */ @@ -603,7 +625,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - _store.setField(_tableId, _keyTuple, 5, abi.encodePacked(uint8(v6)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 5, abi.encodePacked(uint8(v6)), getFieldLayout()); } /** Get v7 */ @@ -625,7 +647,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 6, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 6, getFieldLayout()); return Enum2(uint8(Bytes.slice1(_blob, 0))); } @@ -649,7 +671,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 6, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 6, getFieldLayout()); return Enum2(uint8(Bytes.slice1(_blob, 0))); } @@ -664,7 +686,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - StoreSwitch.setField(_tableId, _keyTuple, 6, abi.encodePacked(uint8(v7)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 6, abi.encodePacked(uint8(v7)), getFieldLayout()); } /** Set v7 (using the specified store) */ @@ -688,7 +710,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - _store.setField(_tableId, _keyTuple, 6, abi.encodePacked(uint8(v7)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 6, abi.encodePacked(uint8(v7)), getFieldLayout()); } /** Get the full data */ @@ -710,7 +732,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -734,7 +756,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -766,7 +788,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - StoreSwitch.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using individual values (using the specified store) */ @@ -798,7 +820,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - _store.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + _store.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using the data struct */ @@ -846,7 +868,7 @@ library Statics { ); } - /** Decode the tightly packed blob using this table's schema */ + /** Decode the tightly packed blob using this table's field layout */ function decode(bytes memory _blob) internal pure returns (StaticsData memory _table) { _table.v1 = (uint256(Bytes.slice32(_blob, 0))); @@ -863,7 +885,7 @@ library Statics { _table.v7 = Enum2(uint8(Bytes.slice1(_blob, 74))); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode( uint256 v1, int32 v2, @@ -876,7 +898,7 @@ library Statics { return abi.encodePacked(v1, v2, v3, v4, v5, v6, v7); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple( uint256 k1, int32 k2, @@ -909,7 +931,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -932,7 +954,7 @@ library Statics { _keyTuple[5] = bytes32(uint256(uint8(k6))); _keyTuple[6] = bytes32(uint256(uint8(k7))); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/cli/src/commands/trace.ts b/packages/cli/src/commands/trace.ts index 77dd69e1a2..1246b10e1d 100644 --- a/packages/cli/src/commands/trace.ts +++ b/packages/cli/src/commands/trace.ts @@ -71,13 +71,13 @@ const commandModule: CommandModule = { const namespace = mudConfig.namespace; const names = Object.values(resolvedConfig.systems).map(({ name }) => name); - // Fetch system table schema from chain - const systemTableSchema = await WorldContract.getValueSchema(systemsTableId); + // Fetch system table field layout from chain + const systemTableFieldLayout = await WorldContract.getFieldLayout(systemsTableId); const labels: { name: string; address: string }[] = []; for (const name of names) { const systemSelector = tableIdToHex(namespace, name); // Get the first field of `Systems` table (the table maps system name to its address and other data) - const address = await WorldContract.getField(systemsTableId, [systemSelector], 0, systemTableSchema); + const address = await WorldContract.getField(systemsTableId, [systemSelector], 0, systemTableFieldLayout); labels.push({ name, address }); } diff --git a/packages/cli/src/utils/deploy.ts b/packages/cli/src/utils/deploy.ts index bc5096bed8..76b2df2993 100644 --- a/packages/cli/src/utils/deploy.ts +++ b/packages/cli/src/utils/deploy.ts @@ -7,7 +7,7 @@ import { defaultAbiCoder as abi, Fragment, ParamType } from "ethers/lib/utils.js import { getOutDirectory, getScriptDirectory, cast, forge } from "@latticexyz/common/foundry"; import { resolveWithContext } from "@latticexyz/config"; import { MUDError } from "@latticexyz/common/errors"; -import { encodeSchema } from "@latticexyz/schema-type/deprecated"; +import { encodeSchema, getStaticByteLength } from "@latticexyz/schema-type/deprecated"; import { StoreConfig } from "@latticexyz/store"; import { resolveAbiOrUserType } from "@latticexyz/store/codegen"; import { WorldConfig, resolveWorldConfig } from "@latticexyz/world"; @@ -18,6 +18,7 @@ import KeysWithValueModuleData from "@latticexyz/world/abi/KeysWithValueModule.s import KeysInTableModuleData from "@latticexyz/world/abi/KeysInTableModule.sol/KeysInTableModule.json" assert { type: "json" }; import UniqueEntityModuleData from "@latticexyz/world/abi/UniqueEntityModule.sol/UniqueEntityModule.json" assert { type: "json" }; import { tableIdToHex } from "@latticexyz/common"; +import { fieldLayoutToHex } from "@latticexyz/protocol-parser"; export interface DeployConfig { profile?: string; @@ -158,6 +159,12 @@ export async function deploy( return schemaType; }); + const schemaTypeLengths = schemaTypes.map((schemaType) => getStaticByteLength(schemaType)); + const fieldLayout = { + staticFieldLengths: schemaTypeLengths.filter((schemaTypeLength) => schemaTypeLength > 0), + numDynamicFields: schemaTypeLengths.filter((schemaTypeLength) => schemaTypeLength === 0).length, + }; + const keyTypes = Object.values(keySchema).map((abiOrUserType) => { const { schemaType } = resolveAbiOrUserType(abiOrUserType, mudConfig); return schemaType; @@ -168,6 +175,7 @@ export async function deploy( "registerTable", [ tableIdToHex(namespace, name), + fieldLayoutToHex(fieldLayout), encodeSchema(keyTypes), encodeSchema(schemaTypes), Object.keys(keySchema), diff --git a/packages/protocol-parser/src/common.ts b/packages/protocol-parser/src/common.ts index 9ff1790395..cf205abafd 100644 --- a/packages/protocol-parser/src/common.ts +++ b/packages/protocol-parser/src/common.ts @@ -12,6 +12,11 @@ export type TableSchema = { readonly valueSchema: Schema; }; +export type FieldLayout = { + readonly staticFieldLengths: readonly number[]; + readonly numDynamicFields: number; +}; + export type KeySchema = Record; export type ValueSchema = Record; diff --git a/packages/protocol-parser/src/fieldLayoutToHex.ts b/packages/protocol-parser/src/fieldLayoutToHex.ts new file mode 100644 index 0000000000..25432a52e7 --- /dev/null +++ b/packages/protocol-parser/src/fieldLayoutToHex.ts @@ -0,0 +1,14 @@ +import { Hex } from "viem"; +import { FieldLayout } from "./common"; + +export function fieldLayoutToHex(fieldLayout: FieldLayout): Hex { + const staticDataLength = fieldLayout.staticFieldLengths.reduce((totalLength, length) => totalLength + length, 0); + return `0x${[ + staticDataLength.toString(16).padStart(4, "0"), + fieldLayout.staticFieldLengths.length.toString(16).padStart(2, "0"), + fieldLayout.numDynamicFields.toString(16).padStart(2, "0"), + ...fieldLayout.staticFieldLengths.map((schemaType) => schemaType.toString(16).padStart(2, "0")), + ] + .join("") + .padEnd(64, "0")}`; +} diff --git a/packages/protocol-parser/src/index.ts b/packages/protocol-parser/src/index.ts index c501303621..c614daaf4f 100644 --- a/packages/protocol-parser/src/index.ts +++ b/packages/protocol-parser/src/index.ts @@ -13,6 +13,7 @@ export * from "./encodeKeyTuple"; export * from "./encodeRecord"; export * from "./encodeValue"; export * from "./errors"; +export * from "./fieldLayoutToHex"; export * from "./hexToPackedCounter"; export * from "./hexToSchema"; export * from "./hexToTableSchema"; diff --git a/packages/store-sync/src/blockLogsToStorage.test.ts b/packages/store-sync/src/blockLogsToStorage.test.ts index e4dc6bdfeb..3e256adfb2 100644 --- a/packages/store-sync/src/blockLogsToStorage.test.ts +++ b/packages/store-sync/src/blockLogsToStorage.test.ts @@ -51,34 +51,17 @@ describe("blockLogsToStorage", () => { { address: "0x5fbdb2315678afecb367f032d93f642f64180aa3", topics: ["0x912af873e852235aae78a1d25ae9bb28b616a67c36898c53a14fd8184504ee32"], - data: "0x6d756473746f72650000000000000000736368656d6100000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000496e76656e746f72790000000000000000000000000000000000000000000000000000000000000000000000000000400004010003000000000000000000000000000000000000000000000000000000002001005f000000000000000000000000000000000000000000000000000000", + data: "0x6d756473746f726500000000000000005461626c657300000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000496e76656e746f72790000000000000000000000000000000000000000000000000000000000000000000000000002800004010004000000000000000000000000000000000000000000000000000000001c030061030300000000000000000000000000000000000000000000000000000401000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000001600000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000056f776e657200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046974656d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b6974656d56617269616e740000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006616d6f756e740000000000000000000000000000000000000000000000000000", + blockHash: "0x50b3e15ef79abc7c72126ca5ecbd0cf0773c48ade0528e1e3debaf9bbe3643da", blockNumber: 5448n, - transactionHash: "0x2766c01dd2290a80e2b54c27e95ca303d7d362643a68bd71c7d8fdb620f2a3a6", - transactionIndex: 18, - blockHash: "0xc65212ced76e80c3d59fd210fca434d9ceebfc25b544989d5eaecec3d31f9ac9", - logIndex: 18, + transactionHash: "0xd66a9f982ddb8da9ca15a72c5713c3390fb3a6c2f7fe81a8c9026d0ba8130189", + transactionIndex: 16, + logIndex: 53, removed: false, args: { - table: "0x6d756473746f72650000000000000000736368656d6100000000000000000000", + table: "0x6d756473746f726500000000000000005461626c657300000000000000000000", key: ["0x00000000000000000000000000000000496e76656e746f727900000000000000"], - data: "0x0004010003000000000000000000000000000000000000000000000000000000002001005f000000000000000000000000000000000000000000000000000000", - }, - eventName: "StoreSetRecord", - }, - { - address: "0x5fbdb2315678afecb367f032d93f642f64180aa3", - topics: ["0x912af873e852235aae78a1d25ae9bb28b616a67c36898c53a14fd8184504ee32"], - data: "0x6d756473746f7265000000000000000053746f72654d65746164617461000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000496e76656e746f72790000000000000000000000000000000000000000000000000000000000000000000000000000c900000000000000000000000000000000000000a00000000009000000000000a9496e76656e746f7279000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000576616c75650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - blockNumber: 5448n, - transactionHash: "0x80d6650fdd6656461e6639988d7baa8d6d228297df505d8bbd0a4efc273b382b", - transactionIndex: 44, - blockHash: "0x930656a2399ed2473449118a030cf9a3b3f770db4f74e9b565e2e0035c49bc6e", - logIndex: 44, - removed: false, - args: { - table: "0x6d756473746f7265000000000000000053746f72654d65746164617461000000", - key: ["0x00000000000000000000000000000000496e76656e746f727900000000000000"], - data: "0x00000000000000000000000000000000000000a00000000009000000000000a9496e76656e746f7279000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000576616c7565000000000000000000000000000000000000000000000000000000", + data: "0x0004010004000000000000000000000000000000000000000000000000000000001c030061030300000000000000000000000000000000000000000000000000000401000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000001600000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000056f776e657200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046974656d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b6974656d56617269616e740000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006616d6f756e740000000000000000000000000000000000000000000000000000", }, eventName: "StoreSetRecord", }, diff --git a/packages/store-sync/src/postgres/postgresStorage.test.ts b/packages/store-sync/src/postgres/postgresStorage.test.ts index e3165c7bd7..171823647a 100644 --- a/packages/store-sync/src/postgres/postgresStorage.test.ts +++ b/packages/store-sync/src/postgres/postgresStorage.test.ts @@ -56,7 +56,7 @@ describe("postgresStorage", async () => { { address: "0x5fbdb2315678afecb367f032d93f642f64180aa3", topics: ["0x912af873e852235aae78a1d25ae9bb28b616a67c36898c53a14fd8184504ee32"], - data: "0x6d756473746f726500000000000000005461626c657300000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000496e76656e746f7279000000000000000000000000000000000000000000000000000000000000000000000000000260001c030061030300000000000000000000000000000000000000000000000000000401000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000001600000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000056f776e657200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046974656d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b6974656d56617269616e740000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006616d6f756e740000000000000000000000000000000000000000000000000000", + data: "0x6d756473746f726500000000000000005461626c657300000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000496e76656e746f72790000000000000000000000000000000000000000000000000000000000000000000000000002800004010004000000000000000000000000000000000000000000000000000000001c030061030300000000000000000000000000000000000000000000000000000401000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000001600000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000056f776e657200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046974656d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b6974656d56617269616e740000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006616d6f756e740000000000000000000000000000000000000000000000000000", blockHash: "0x4ad3752c86f900332e0d2d8903480e7206747d233586574d16f006eebdb5138b", blockNumber: 2n, transactionHash: "0xaa54bf18053cce5d4d2906538a60cb1d9958cc3c10c34b5f9fdc92fe6a6abab4", @@ -66,7 +66,7 @@ describe("postgresStorage", async () => { args: { table: "0x6d756473746f726500000000000000005461626c657300000000000000000000", key: ["0x00000000000000000000000000000000496e76656e746f727900000000000000"], - data: "0x001c030061030300000000000000000000000000000000000000000000000000000401000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000001600000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000056f776e657200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046974656d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b6974656d56617269616e740000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006616d6f756e740000000000000000000000000000000000000000000000000000", + data: "0x0004010004000000000000000000000000000000000000000000000000000000001c030061030300000000000000000000000000000000000000000000000000000401000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000001600000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000056f776e657200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046974656d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b6974656d56617269616e740000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006616d6f756e740000000000000000000000000000000000000000000000000000", }, eventName: "StoreSetRecord", }, diff --git a/packages/store-sync/src/sqlite/sqliteStorage.test.ts b/packages/store-sync/src/sqlite/sqliteStorage.test.ts index e21cd954e9..2377d45176 100644 --- a/packages/store-sync/src/sqlite/sqliteStorage.test.ts +++ b/packages/store-sync/src/sqlite/sqliteStorage.test.ts @@ -62,7 +62,7 @@ describe("sqliteStorage", async () => { { address: "0x5fbdb2315678afecb367f032d93f642f64180aa3", topics: ["0x912af873e852235aae78a1d25ae9bb28b616a67c36898c53a14fd8184504ee32"], - data: "0x6d756473746f726500000000000000005461626c657300000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000496e76656e746f7279000000000000000000000000000000000000000000000000000000000000000000000000000260001c030061030300000000000000000000000000000000000000000000000000000401000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000001600000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000056f776e657200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046974656d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b6974656d56617269616e740000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006616d6f756e740000000000000000000000000000000000000000000000000000", + data: "0x6d756473746f726500000000000000005461626c657300000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000496e76656e746f72790000000000000000000000000000000000000000000000000000000000000000000000000002800004010004000000000000000000000000000000000000000000000000000000001c030061030300000000000000000000000000000000000000000000000000000401000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000001600000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000056f776e657200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046974656d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b6974656d56617269616e740000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006616d6f756e740000000000000000000000000000000000000000000000000000", blockHash: "0x4ad3752c86f900332e0d2d8903480e7206747d233586574d16f006eebdb5138b", blockNumber: 2n, transactionHash: "0xaa54bf18053cce5d4d2906538a60cb1d9958cc3c10c34b5f9fdc92fe6a6abab4", @@ -72,7 +72,7 @@ describe("sqliteStorage", async () => { args: { table: "0x6d756473746f726500000000000000005461626c657300000000000000000000", key: ["0x00000000000000000000000000000000496e76656e746f727900000000000000"], - data: "0x001c030061030300000000000000000000000000000000000000000000000000000401000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000001600000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000056f776e657200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046974656d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b6974656d56617269616e740000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006616d6f756e740000000000000000000000000000000000000000000000000000", + data: "0x0004010004000000000000000000000000000000000000000000000000000000001c030061030300000000000000000000000000000000000000000000000000000401000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000001600000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000056f776e657200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046974656d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b6974656d56617269616e740000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006616d6f756e740000000000000000000000000000000000000000000000000000", }, eventName: "StoreSetRecord", }, diff --git a/packages/store/abi/EchoSubscriber.sol/EchoSubscriber.abi.json b/packages/store/abi/EchoSubscriber.sol/EchoSubscriber.abi.json index 33ff18626b..c1e97ac5ac 100644 --- a/packages/store/abi/EchoSubscriber.sol/EchoSubscriber.abi.json +++ b/packages/store/abi/EchoSubscriber.sol/EchoSubscriber.abi.json @@ -25,8 +25,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -58,8 +58,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchem", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -86,8 +86,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -109,8 +109,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -142,8 +142,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -170,8 +170,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/store/abi/EchoSubscriber.sol/EchoSubscriber.abi.json.d.ts b/packages/store/abi/EchoSubscriber.sol/EchoSubscriber.abi.json.d.ts index 9bab444311..c46f9f8fc0 100644 --- a/packages/store/abi/EchoSubscriber.sol/EchoSubscriber.abi.json.d.ts +++ b/packages/store/abi/EchoSubscriber.sol/EchoSubscriber.abi.json.d.ts @@ -25,8 +25,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -58,8 +58,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchem"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -86,8 +86,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -109,8 +109,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -142,8 +142,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -170,8 +170,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/store/abi/FieldLayout.sol/FieldLayoutInstance.abi.json b/packages/store/abi/FieldLayout.sol/FieldLayoutInstance.abi.json new file mode 100644 index 0000000000..0637a088a0 --- /dev/null +++ b/packages/store/abi/FieldLayout.sol/FieldLayoutInstance.abi.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/packages/store/abi/FieldLayout.sol/FieldLayoutLib.abi.json b/packages/store/abi/FieldLayout.sol/FieldLayoutLib.abi.json new file mode 100644 index 0000000000..0718613ae7 --- /dev/null +++ b/packages/store/abi/FieldLayout.sol/FieldLayoutLib.abi.json @@ -0,0 +1,23 @@ +[ + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", + "type": "error" + } +] \ No newline at end of file diff --git a/packages/store/abi/FieldLayout.sol/FieldLayoutLib.abi.json.d.ts b/packages/store/abi/FieldLayout.sol/FieldLayoutLib.abi.json.d.ts new file mode 100644 index 0000000000..46ebe7906c --- /dev/null +++ b/packages/store/abi/FieldLayout.sol/FieldLayoutLib.abi.json.d.ts @@ -0,0 +1,24 @@ +declare const abi: [ + { + inputs: [ + { + internalType: "uint256"; + name: "length"; + type: "uint256"; + } + ]; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; + type: "error"; + } +]; +export default abi; diff --git a/packages/store/abi/FieldLayoutEncodeHelper.sol/FieldLayoutEncodeHelper.abi.json b/packages/store/abi/FieldLayoutEncodeHelper.sol/FieldLayoutEncodeHelper.abi.json new file mode 100644 index 0000000000..0637a088a0 --- /dev/null +++ b/packages/store/abi/FieldLayoutEncodeHelper.sol/FieldLayoutEncodeHelper.abi.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/packages/store/abi/IStore.sol/IStore.abi.json b/packages/store/abi/IStore.sol/IStore.abi.json index 48e69022f3..5f2611915f 100644 --- a/packages/store/abi/IStore.sol/IStore.abi.json +++ b/packages/store/abi/IStore.sol/IStore.abi.json @@ -63,6 +63,22 @@ "name": "StoreCore_InvalidKeyNamesLength", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "expected", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "received", + "type": "uint256" + } + ], + "name": "StoreCore_InvalidValueSchemaLength", + "type": "error" + }, { "inputs": [], "name": "StoreCore_NotDynamicField", @@ -218,8 +234,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -246,8 +262,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -274,8 +290,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -290,6 +306,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "table", + "type": "bytes32" + } + ], + "name": "getFieldLayout", + "outputs": [ + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -308,8 +343,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -342,8 +377,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" }, { @@ -400,8 +435,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -458,8 +493,8 @@ "type": "uint256" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -491,8 +526,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -531,6 +566,11 @@ "name": "table", "type": "bytes32" }, + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + }, { "internalType": "Schema", "name": "keySchema", @@ -580,8 +620,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -608,8 +648,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -664,8 +704,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/store/abi/IStore.sol/IStore.abi.json.d.ts b/packages/store/abi/IStore.sol/IStore.abi.json.d.ts index 9838b2e184..53be52609c 100644 --- a/packages/store/abi/IStore.sol/IStore.abi.json.d.ts +++ b/packages/store/abi/IStore.sol/IStore.abi.json.d.ts @@ -63,6 +63,22 @@ declare const abi: [ name: "StoreCore_InvalidKeyNamesLength"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "expected"; + type: "uint256"; + }, + { + internalType: "uint256"; + name: "received"; + type: "uint256"; + } + ]; + name: "StoreCore_InvalidValueSchemaLength"; + type: "error"; + }, { inputs: []; name: "StoreCore_NotDynamicField"; @@ -218,8 +234,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -246,8 +262,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -274,8 +290,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -290,6 +306,25 @@ declare const abi: [ stateMutability: "view"; type: "function"; }, + { + inputs: [ + { + internalType: "bytes32"; + name: "table"; + type: "bytes32"; + } + ]; + name: "getFieldLayout"; + outputs: [ + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + } + ]; + stateMutability: "view"; + type: "function"; + }, { inputs: [ { @@ -308,8 +343,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -342,8 +377,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; }, { @@ -400,8 +435,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -458,8 +493,8 @@ declare const abi: [ type: "uint256"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -491,8 +526,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -531,6 +566,11 @@ declare const abi: [ name: "table"; type: "bytes32"; }, + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + }, { internalType: "Schema"; name: "keySchema"; @@ -580,8 +620,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -608,8 +648,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -664,8 +704,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/store/abi/IStore.sol/IStoreData.abi.json b/packages/store/abi/IStore.sol/IStoreData.abi.json index f02203d5e9..b2f7b1cfe9 100644 --- a/packages/store/abi/IStore.sol/IStoreData.abi.json +++ b/packages/store/abi/IStore.sol/IStoreData.abi.json @@ -87,8 +87,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -115,8 +115,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -131,6 +131,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "table", + "type": "bytes32" + } + ], + "name": "getFieldLayout", + "outputs": [ + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -149,8 +168,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -183,8 +202,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" }, { @@ -241,8 +260,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -299,8 +318,8 @@ "type": "uint256" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -332,8 +351,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -365,8 +384,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -393,8 +412,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -431,8 +450,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/store/abi/IStore.sol/IStoreData.abi.json.d.ts b/packages/store/abi/IStore.sol/IStoreData.abi.json.d.ts index 069dc301f8..8376850819 100644 --- a/packages/store/abi/IStore.sol/IStoreData.abi.json.d.ts +++ b/packages/store/abi/IStore.sol/IStoreData.abi.json.d.ts @@ -87,8 +87,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -115,8 +115,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -131,6 +131,25 @@ declare const abi: [ stateMutability: "view"; type: "function"; }, + { + inputs: [ + { + internalType: "bytes32"; + name: "table"; + type: "bytes32"; + } + ]; + name: "getFieldLayout"; + outputs: [ + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + } + ]; + stateMutability: "view"; + type: "function"; + }, { inputs: [ { @@ -149,8 +168,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -183,8 +202,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; }, { @@ -241,8 +260,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -299,8 +318,8 @@ declare const abi: [ type: "uint256"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -332,8 +351,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -365,8 +384,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -393,8 +412,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -431,8 +450,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/store/abi/IStore.sol/IStoreEphemeral.abi.json b/packages/store/abi/IStore.sol/IStoreEphemeral.abi.json index c9cbd9770c..da76e6a5c2 100644 --- a/packages/store/abi/IStore.sol/IStoreEphemeral.abi.json +++ b/packages/store/abi/IStore.sol/IStoreEphemeral.abi.json @@ -42,8 +42,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/store/abi/IStore.sol/IStoreEphemeral.abi.json.d.ts b/packages/store/abi/IStore.sol/IStoreEphemeral.abi.json.d.ts index 0ab62ee11e..5b3d199d71 100644 --- a/packages/store/abi/IStore.sol/IStoreEphemeral.abi.json.d.ts +++ b/packages/store/abi/IStore.sol/IStoreEphemeral.abi.json.d.ts @@ -42,8 +42,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/store/abi/IStore.sol/IStoreRead.abi.json b/packages/store/abi/IStore.sol/IStoreRead.abi.json index 0f47144f3d..44bcee43a5 100644 --- a/packages/store/abi/IStore.sol/IStoreRead.abi.json +++ b/packages/store/abi/IStore.sol/IStoreRead.abi.json @@ -17,8 +17,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -33,6 +33,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "table", + "type": "bytes32" + } + ], + "name": "getFieldLayout", + "outputs": [ + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -51,8 +70,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -85,8 +104,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" }, { @@ -143,8 +162,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/store/abi/IStore.sol/IStoreRead.abi.json.d.ts b/packages/store/abi/IStore.sol/IStoreRead.abi.json.d.ts index 1fcf24a77e..14c859cc2e 100644 --- a/packages/store/abi/IStore.sol/IStoreRead.abi.json.d.ts +++ b/packages/store/abi/IStore.sol/IStoreRead.abi.json.d.ts @@ -17,8 +17,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -33,6 +33,25 @@ declare const abi: [ stateMutability: "view"; type: "function"; }, + { + inputs: [ + { + internalType: "bytes32"; + name: "table"; + type: "bytes32"; + } + ]; + name: "getFieldLayout"; + outputs: [ + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + } + ]; + stateMutability: "view"; + type: "function"; + }, { inputs: [ { @@ -51,8 +70,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -85,8 +104,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; }, { @@ -143,8 +162,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/store/abi/IStore.sol/IStoreRegistration.abi.json b/packages/store/abi/IStore.sol/IStoreRegistration.abi.json index 8199933edd..d21d2dd147 100644 --- a/packages/store/abi/IStore.sol/IStoreRegistration.abi.json +++ b/packages/store/abi/IStore.sol/IStoreRegistration.abi.json @@ -29,6 +29,11 @@ "name": "table", "type": "bytes32" }, + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + }, { "internalType": "Schema", "name": "keySchema", diff --git a/packages/store/abi/IStore.sol/IStoreRegistration.abi.json.d.ts b/packages/store/abi/IStore.sol/IStoreRegistration.abi.json.d.ts index 02db08cbf2..790883941d 100644 --- a/packages/store/abi/IStore.sol/IStoreRegistration.abi.json.d.ts +++ b/packages/store/abi/IStore.sol/IStoreRegistration.abi.json.d.ts @@ -29,6 +29,11 @@ declare const abi: [ name: "table"; type: "bytes32"; }, + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + }, { internalType: "Schema"; name: "keySchema"; diff --git a/packages/store/abi/IStore.sol/IStoreWrite.abi.json b/packages/store/abi/IStore.sol/IStoreWrite.abi.json index e5a35719c0..98b9d2126f 100644 --- a/packages/store/abi/IStore.sol/IStoreWrite.abi.json +++ b/packages/store/abi/IStore.sol/IStoreWrite.abi.json @@ -87,8 +87,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -120,8 +120,8 @@ "type": "uint256" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -153,8 +153,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -186,8 +186,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -214,8 +214,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -252,8 +252,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/store/abi/IStore.sol/IStoreWrite.abi.json.d.ts b/packages/store/abi/IStore.sol/IStoreWrite.abi.json.d.ts index 6c043cda2f..5861267f02 100644 --- a/packages/store/abi/IStore.sol/IStoreWrite.abi.json.d.ts +++ b/packages/store/abi/IStore.sol/IStoreWrite.abi.json.d.ts @@ -87,8 +87,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -120,8 +120,8 @@ declare const abi: [ type: "uint256"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -153,8 +153,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -186,8 +186,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -214,8 +214,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -252,8 +252,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/store/abi/IStoreErrors.sol/IStoreErrors.abi.json b/packages/store/abi/IStoreErrors.sol/IStoreErrors.abi.json index cf6d375396..d52ffeba10 100644 --- a/packages/store/abi/IStoreErrors.sol/IStoreErrors.abi.json +++ b/packages/store/abi/IStoreErrors.sol/IStoreErrors.abi.json @@ -63,6 +63,22 @@ "name": "StoreCore_InvalidKeyNamesLength", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "expected", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "received", + "type": "uint256" + } + ], + "name": "StoreCore_InvalidValueSchemaLength", + "type": "error" + }, { "inputs": [], "name": "StoreCore_NotDynamicField", diff --git a/packages/store/abi/IStoreErrors.sol/IStoreErrors.abi.json.d.ts b/packages/store/abi/IStoreErrors.sol/IStoreErrors.abi.json.d.ts index 7e72348020..3618648807 100644 --- a/packages/store/abi/IStoreErrors.sol/IStoreErrors.abi.json.d.ts +++ b/packages/store/abi/IStoreErrors.sol/IStoreErrors.abi.json.d.ts @@ -63,6 +63,22 @@ declare const abi: [ name: "StoreCore_InvalidKeyNamesLength"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "expected"; + type: "uint256"; + }, + { + internalType: "uint256"; + name: "received"; + type: "uint256"; + } + ]; + name: "StoreCore_InvalidValueSchemaLength"; + type: "error"; + }, { inputs: []; name: "StoreCore_NotDynamicField"; diff --git a/packages/store/abi/IStoreHook.sol/IStoreHook.abi.json b/packages/store/abi/IStoreHook.sol/IStoreHook.abi.json index b35f6251af..206689d652 100644 --- a/packages/store/abi/IStoreHook.sol/IStoreHook.abi.json +++ b/packages/store/abi/IStoreHook.sol/IStoreHook.abi.json @@ -12,8 +12,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -45,8 +45,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -73,8 +73,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -96,8 +96,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -129,8 +129,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -157,8 +157,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/store/abi/IStoreHook.sol/IStoreHook.abi.json.d.ts b/packages/store/abi/IStoreHook.sol/IStoreHook.abi.json.d.ts index ae36ae3637..4fafcfbee3 100644 --- a/packages/store/abi/IStoreHook.sol/IStoreHook.abi.json.d.ts +++ b/packages/store/abi/IStoreHook.sol/IStoreHook.abi.json.d.ts @@ -12,8 +12,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -45,8 +45,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -73,8 +73,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -96,8 +96,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -129,8 +129,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -157,8 +157,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/store/abi/MirrorSubscriber.sol/MirrorSubscriber.abi.json b/packages/store/abi/MirrorSubscriber.sol/MirrorSubscriber.abi.json index 5325629c8a..0ac0ded164 100644 --- a/packages/store/abi/MirrorSubscriber.sol/MirrorSubscriber.abi.json +++ b/packages/store/abi/MirrorSubscriber.sol/MirrorSubscriber.abi.json @@ -6,6 +6,11 @@ "name": "table", "type": "bytes32" }, + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + }, { "internalType": "Schema", "name": "keySchema", @@ -38,7 +43,17 @@ "type": "uint256" } ], - "name": "PackedCounter_InvalidLength", + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", "type": "error" }, { @@ -49,12 +64,7 @@ "type": "uint256" } ], - "name": "SchemaLib_InvalidLength", - "type": "error" - }, - { - "inputs": [], - "name": "SchemaLib_StaticTypeAfterDynamicType", + "name": "PackedCounter_InvalidLength", "type": "error" }, { @@ -107,8 +117,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -140,7 +150,7 @@ "type": "bytes" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } @@ -168,8 +178,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -191,8 +201,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -224,8 +234,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -252,8 +262,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/store/abi/MirrorSubscriber.sol/MirrorSubscriber.abi.json.d.ts b/packages/store/abi/MirrorSubscriber.sol/MirrorSubscriber.abi.json.d.ts index 47a8e089b3..cdd3b22d81 100644 --- a/packages/store/abi/MirrorSubscriber.sol/MirrorSubscriber.abi.json.d.ts +++ b/packages/store/abi/MirrorSubscriber.sol/MirrorSubscriber.abi.json.d.ts @@ -6,6 +6,11 @@ declare const abi: [ name: "table"; type: "bytes32"; }, + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + }, { internalType: "Schema"; name: "keySchema"; @@ -38,7 +43,17 @@ declare const abi: [ type: "uint256"; } ]; - name: "PackedCounter_InvalidLength"; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; type: "error"; }, { @@ -49,12 +64,7 @@ declare const abi: [ type: "uint256"; } ]; - name: "SchemaLib_InvalidLength"; - type: "error"; - }, - { - inputs: []; - name: "SchemaLib_StaticTypeAfterDynamicType"; + name: "PackedCounter_InvalidLength"; type: "error"; }, { @@ -107,8 +117,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -140,7 +150,7 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } @@ -168,8 +178,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -191,8 +201,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -224,8 +234,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -252,8 +262,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/store/abi/RevertSubscriber.sol/RevertSubscriber.abi.json b/packages/store/abi/RevertSubscriber.sol/RevertSubscriber.abi.json index 2dcffc5af8..9557def75e 100644 --- a/packages/store/abi/RevertSubscriber.sol/RevertSubscriber.abi.json +++ b/packages/store/abi/RevertSubscriber.sol/RevertSubscriber.abi.json @@ -12,7 +12,7 @@ "type": "bytes32[]" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } @@ -45,7 +45,7 @@ "type": "bytes" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } @@ -73,7 +73,7 @@ "type": "bytes" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } @@ -96,7 +96,7 @@ "type": "bytes32[]" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } @@ -129,7 +129,7 @@ "type": "bytes" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } @@ -157,7 +157,7 @@ "type": "bytes" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } diff --git a/packages/store/abi/RevertSubscriber.sol/RevertSubscriber.abi.json.d.ts b/packages/store/abi/RevertSubscriber.sol/RevertSubscriber.abi.json.d.ts index 589b6d8b05..eab9eda73b 100644 --- a/packages/store/abi/RevertSubscriber.sol/RevertSubscriber.abi.json.d.ts +++ b/packages/store/abi/RevertSubscriber.sol/RevertSubscriber.abi.json.d.ts @@ -12,7 +12,7 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } @@ -45,7 +45,7 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } @@ -73,7 +73,7 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } @@ -96,7 +96,7 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } @@ -129,7 +129,7 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } @@ -157,7 +157,7 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } diff --git a/packages/store/abi/StoreCore.sol/StoreCore.abi.json b/packages/store/abi/StoreCore.sol/StoreCore.abi.json index 72f144fcd2..fb85ad946b 100644 --- a/packages/store/abi/StoreCore.sol/StoreCore.abi.json +++ b/packages/store/abi/StoreCore.sol/StoreCore.abi.json @@ -61,7 +61,7 @@ { "indexed": false, "internalType": "uint8", - "name": "schemaIndex", + "name": "fieldIndex", "type": "uint8" }, { diff --git a/packages/store/abi/StoreCore.sol/StoreCore.abi.json.d.ts b/packages/store/abi/StoreCore.sol/StoreCore.abi.json.d.ts index efd33cd781..60f914b4e1 100644 --- a/packages/store/abi/StoreCore.sol/StoreCore.abi.json.d.ts +++ b/packages/store/abi/StoreCore.sol/StoreCore.abi.json.d.ts @@ -61,7 +61,7 @@ declare const abi: [ { indexed: false; internalType: "uint8"; - name: "schemaIndex"; + name: "fieldIndex"; type: "uint8"; }, { diff --git a/packages/store/abi/StoreHook.sol/StoreHook.abi.json b/packages/store/abi/StoreHook.sol/StoreHook.abi.json index 3d219e7777..84037ddd5e 100644 --- a/packages/store/abi/StoreHook.sol/StoreHook.abi.json +++ b/packages/store/abi/StoreHook.sol/StoreHook.abi.json @@ -12,8 +12,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -45,8 +45,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -73,8 +73,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -96,8 +96,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -129,8 +129,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -157,8 +157,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/store/abi/StoreHook.sol/StoreHook.abi.json.d.ts b/packages/store/abi/StoreHook.sol/StoreHook.abi.json.d.ts index 494a46cc19..96c3279f30 100644 --- a/packages/store/abi/StoreHook.sol/StoreHook.abi.json.d.ts +++ b/packages/store/abi/StoreHook.sol/StoreHook.abi.json.d.ts @@ -12,8 +12,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -45,8 +45,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -73,8 +73,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -96,8 +96,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -129,8 +129,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -157,8 +157,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/store/abi/StoreMock.sol/StoreMock.abi.json b/packages/store/abi/StoreMock.sol/StoreMock.abi.json index 276498c2ca..2bdd2738ee 100644 --- a/packages/store/abi/StoreMock.sol/StoreMock.abi.json +++ b/packages/store/abi/StoreMock.sol/StoreMock.abi.json @@ -1,4 +1,25 @@ [ + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", + "type": "error" + }, { "inputs": [ { @@ -111,6 +132,22 @@ "name": "StoreCore_InvalidKeyNamesLength", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "expected", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "received", + "type": "uint256" + } + ], + "name": "StoreCore_InvalidValueSchemaLength", + "type": "error" + }, { "inputs": [], "name": "StoreCore_NotDynamicField", @@ -266,8 +303,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -294,8 +331,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -322,8 +359,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -338,6 +375,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "table", + "type": "bytes32" + } + ], + "name": "getFieldLayout", + "outputs": [ + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -356,8 +412,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "schema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -390,8 +446,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "schema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" }, { @@ -448,8 +504,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -506,8 +562,8 @@ "type": "uint256" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -539,8 +595,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -579,6 +635,11 @@ "name": "table", "type": "bytes32" }, + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + }, { "internalType": "Schema", "name": "keySchema", @@ -628,8 +689,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -656,8 +717,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -712,8 +773,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/store/abi/StoreMock.sol/StoreMock.abi.json.d.ts b/packages/store/abi/StoreMock.sol/StoreMock.abi.json.d.ts index c04f073704..e9dfdc5fd2 100644 --- a/packages/store/abi/StoreMock.sol/StoreMock.abi.json.d.ts +++ b/packages/store/abi/StoreMock.sol/StoreMock.abi.json.d.ts @@ -1,4 +1,25 @@ declare const abi: [ + { + inputs: [ + { + internalType: "uint256"; + name: "length"; + type: "uint256"; + } + ]; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; + type: "error"; + }, { inputs: [ { @@ -111,6 +132,22 @@ declare const abi: [ name: "StoreCore_InvalidKeyNamesLength"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "expected"; + type: "uint256"; + }, + { + internalType: "uint256"; + name: "received"; + type: "uint256"; + } + ]; + name: "StoreCore_InvalidValueSchemaLength"; + type: "error"; + }, { inputs: []; name: "StoreCore_NotDynamicField"; @@ -266,8 +303,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -294,8 +331,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -322,8 +359,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -338,6 +375,25 @@ declare const abi: [ stateMutability: "view"; type: "function"; }, + { + inputs: [ + { + internalType: "bytes32"; + name: "table"; + type: "bytes32"; + } + ]; + name: "getFieldLayout"; + outputs: [ + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + } + ]; + stateMutability: "view"; + type: "function"; + }, { inputs: [ { @@ -356,8 +412,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "schema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -390,8 +446,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "schema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; }, { @@ -448,8 +504,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -506,8 +562,8 @@ declare const abi: [ type: "uint256"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -539,8 +595,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -579,6 +635,11 @@ declare const abi: [ name: "table"; type: "bytes32"; }, + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + }, { internalType: "Schema"; name: "keySchema"; @@ -628,8 +689,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -656,8 +717,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -712,8 +773,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/store/abi/StoreRead.sol/StoreRead.abi.json b/packages/store/abi/StoreRead.sol/StoreRead.abi.json index 93a0e17cf5..1f8dd917db 100644 --- a/packages/store/abi/StoreRead.sol/StoreRead.abi.json +++ b/packages/store/abi/StoreRead.sol/StoreRead.abi.json @@ -4,6 +4,27 @@ "stateMutability": "nonpayable", "type": "constructor" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", + "type": "error" + }, { "inputs": [ { @@ -89,6 +110,22 @@ "name": "StoreCore_InvalidKeyNamesLength", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "expected", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "received", + "type": "uint256" + } + ], + "name": "StoreCore_InvalidValueSchemaLength", + "type": "error" + }, { "inputs": [], "name": "StoreCore_NotDynamicField", @@ -144,8 +181,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -160,6 +197,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "table", + "type": "bytes32" + } + ], + "name": "getFieldLayout", + "outputs": [ + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -178,8 +234,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "schema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -212,8 +268,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "schema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" }, { @@ -270,8 +326,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/store/abi/StoreRead.sol/StoreRead.abi.json.d.ts b/packages/store/abi/StoreRead.sol/StoreRead.abi.json.d.ts index 13d190bb30..677134cc99 100644 --- a/packages/store/abi/StoreRead.sol/StoreRead.abi.json.d.ts +++ b/packages/store/abi/StoreRead.sol/StoreRead.abi.json.d.ts @@ -4,6 +4,27 @@ declare const abi: [ stateMutability: "nonpayable"; type: "constructor"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "length"; + type: "uint256"; + } + ]; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; + type: "error"; + }, { inputs: [ { @@ -89,6 +110,22 @@ declare const abi: [ name: "StoreCore_InvalidKeyNamesLength"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "expected"; + type: "uint256"; + }, + { + internalType: "uint256"; + name: "received"; + type: "uint256"; + } + ]; + name: "StoreCore_InvalidValueSchemaLength"; + type: "error"; + }, { inputs: []; name: "StoreCore_NotDynamicField"; @@ -144,8 +181,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -160,6 +197,25 @@ declare const abi: [ stateMutability: "view"; type: "function"; }, + { + inputs: [ + { + internalType: "bytes32"; + name: "table"; + type: "bytes32"; + } + ]; + name: "getFieldLayout"; + outputs: [ + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + } + ]; + stateMutability: "view"; + type: "function"; + }, { inputs: [ { @@ -178,8 +234,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "schema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -212,8 +268,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "schema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; }, { @@ -270,8 +326,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/store/abi/StoreReadWithStubs.sol/StoreReadWithStubs.abi.json b/packages/store/abi/StoreReadWithStubs.sol/StoreReadWithStubs.abi.json index 58e66783e2..ff1fab95f9 100644 --- a/packages/store/abi/StoreReadWithStubs.sol/StoreReadWithStubs.abi.json +++ b/packages/store/abi/StoreReadWithStubs.sol/StoreReadWithStubs.abi.json @@ -1,4 +1,25 @@ [ + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", + "type": "error" + }, { "inputs": [ { @@ -100,6 +121,22 @@ "name": "StoreCore_InvalidKeyNamesLength", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "expected", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "received", + "type": "uint256" + } + ], + "name": "StoreCore_InvalidValueSchemaLength", + "type": "error" + }, { "inputs": [], "name": "StoreCore_NotDynamicField", @@ -260,7 +297,7 @@ "type": "bytes32[]" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } @@ -288,7 +325,7 @@ "type": "bytes" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } @@ -316,8 +353,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -332,6 +369,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "table", + "type": "bytes32" + } + ], + "name": "getFieldLayout", + "outputs": [ + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -350,8 +406,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "schema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -384,8 +440,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "schema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" }, { @@ -442,8 +498,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -500,7 +556,7 @@ "type": "uint256" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } @@ -533,7 +589,7 @@ "type": "bytes" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } @@ -573,6 +629,11 @@ "name": "", "type": "bytes32" }, + { + "internalType": "FieldLayout", + "name": "", + "type": "bytes32" + }, { "internalType": "Schema", "name": "", @@ -622,7 +683,7 @@ "type": "bytes" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } @@ -650,7 +711,7 @@ "type": "bytes" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } @@ -706,7 +767,7 @@ "type": "bytes" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } diff --git a/packages/store/abi/StoreReadWithStubs.sol/StoreReadWithStubs.abi.json.d.ts b/packages/store/abi/StoreReadWithStubs.sol/StoreReadWithStubs.abi.json.d.ts index 53d8067ddb..667d11271a 100644 --- a/packages/store/abi/StoreReadWithStubs.sol/StoreReadWithStubs.abi.json.d.ts +++ b/packages/store/abi/StoreReadWithStubs.sol/StoreReadWithStubs.abi.json.d.ts @@ -1,4 +1,25 @@ declare const abi: [ + { + inputs: [ + { + internalType: "uint256"; + name: "length"; + type: "uint256"; + } + ]; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; + type: "error"; + }, { inputs: [ { @@ -100,6 +121,22 @@ declare const abi: [ name: "StoreCore_InvalidKeyNamesLength"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "expected"; + type: "uint256"; + }, + { + internalType: "uint256"; + name: "received"; + type: "uint256"; + } + ]; + name: "StoreCore_InvalidValueSchemaLength"; + type: "error"; + }, { inputs: []; name: "StoreCore_NotDynamicField"; @@ -260,7 +297,7 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } @@ -288,7 +325,7 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } @@ -316,8 +353,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -332,6 +369,25 @@ declare const abi: [ stateMutability: "view"; type: "function"; }, + { + inputs: [ + { + internalType: "bytes32"; + name: "table"; + type: "bytes32"; + } + ]; + name: "getFieldLayout"; + outputs: [ + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + } + ]; + stateMutability: "view"; + type: "function"; + }, { inputs: [ { @@ -350,8 +406,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "schema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -384,8 +440,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "schema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; }, { @@ -442,8 +498,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -500,7 +556,7 @@ declare const abi: [ type: "uint256"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } @@ -533,7 +589,7 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } @@ -573,6 +629,11 @@ declare const abi: [ name: ""; type: "bytes32"; }, + { + internalType: "FieldLayout"; + name: ""; + type: "bytes32"; + }, { internalType: "Schema"; name: ""; @@ -622,7 +683,7 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } @@ -650,7 +711,7 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } @@ -706,7 +767,7 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } diff --git a/packages/store/abi/constants.sol/LayoutOffsets.abi.json b/packages/store/abi/constants.sol/LayoutOffsets.abi.json new file mode 100644 index 0000000000..0637a088a0 --- /dev/null +++ b/packages/store/abi/constants.sol/LayoutOffsets.abi.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/packages/store/gas-report.json b/packages/store/gas-report.json index 6ffd6db563..cf9bba9495 100644 --- a/packages/store/gas-report.json +++ b/packages/store/gas-report.json @@ -59,6 +59,66 @@ "name": "create bytes32 from bytes memory with offset 16", "gasUsed": 36 }, + { + "file": "test/FieldLayout.t.sol", + "test": "testEncodeDecodeFieldLayout", + "name": "initialize field layout array with 5 entries", + "gasUsed": 439 + }, + { + "file": "test/FieldLayout.t.sol", + "test": "testEncodeDecodeFieldLayout", + "name": "encode field layout with 5+1 entries", + "gasUsed": 2378 + }, + { + "file": "test/FieldLayout.t.sol", + "test": "testEncodeDecodeFieldLayout", + "name": "get static byte length at index", + "gasUsed": 19 + }, + { + "file": "test/FieldLayout.t.sol", + "test": "testGetNumDynamicFields", + "name": "get number of dynamic fields from field layout", + "gasUsed": 363 + }, + { + "file": "test/FieldLayout.t.sol", + "test": "testGetNumFields", + "name": "get number of all fields from field layout", + "gasUsed": 34 + }, + { + "file": "test/FieldLayout.t.sol", + "test": "testGetNumStaticFields", + "name": "get number of static fields from field layout", + "gasUsed": 293 + }, + { + "file": "test/FieldLayout.t.sol", + "test": "testGetStaticFieldLayoutLength", + "name": "get static data length from field layout", + "gasUsed": 218 + }, + { + "file": "test/FieldLayout.t.sol", + "test": "testIsEmptyFalse", + "name": "check if field layout is empty (non-empty field layout)", + "gasUsed": 7 + }, + { + "file": "test/FieldLayout.t.sol", + "test": "testIsEmptyTrue", + "name": "check if field layout is empty (empty field layout)", + "gasUsed": 7 + }, + { + "file": "test/FieldLayout.t.sol", + "test": "testValidate", + "name": "validate field layout", + "gasUsed": 3944 + }, { "file": "test/Gas.t.sol", "test": "testCompareAbiEncodeVsCustom", @@ -247,9 +307,9 @@ }, { "file": "test/KeyEncoding.t.sol", - "test": "testRegisterAndGetSchema", - "name": "register KeyEncoding schema", - "gasUsed": 669560 + "test": "testRegisterAndGetFieldLayout", + "name": "register KeyEncoding table", + "gasUsed": 697846 }, { "file": "test/Mixed.t.sol", @@ -259,21 +319,21 @@ }, { "file": "test/Mixed.t.sol", - "test": "testRegisterAndGetSchema", - "name": "register Mixed schema", - "gasUsed": 531268 + "test": "testRegisterAndGetFieldLayout", + "name": "register Mixed table", + "gasUsed": 560027 }, { "file": "test/Mixed.t.sol", "test": "testSetAndGet", "name": "set record in Mixed", - "gasUsed": 107229 + "gasUsed": 108640 }, { "file": "test/Mixed.t.sol", "test": "testSetAndGet", "name": "get record from Mixed", - "gasUsed": 9985 + "gasUsed": 9640 }, { "file": "test/PackedCounter.t.sol", @@ -315,19 +375,19 @@ "file": "test/Schema.t.sol", "test": "testEncodeDecodeSchema", "name": "encode schema with 6 entries", - "gasUsed": 2814 + "gasUsed": 3555 }, { "file": "test/Schema.t.sol", "test": "testEncodeDecodeSchema", "name": "get schema type at index", - "gasUsed": 127 + "gasUsed": 115 }, { "file": "test/Schema.t.sol", "test": "testGetNumDynamicFields", "name": "get number of dynamic fields from schema", - "gasUsed": 68 + "gasUsed": 363 }, { "file": "test/Schema.t.sol", @@ -339,13 +399,13 @@ "file": "test/Schema.t.sol", "test": "testGetNumStaticFields", "name": "get number of static fields from schema", - "gasUsed": 79 + "gasUsed": 293 }, { "file": "test/Schema.t.sol", "test": "testGetStaticSchemaLength", "name": "get static data length from schema", - "gasUsed": 33 + "gasUsed": 218 }, { "file": "test/Schema.t.sol", @@ -363,7 +423,7 @@ "file": "test/Schema.t.sol", "test": "testValidate", "name": "validate schema", - "gasUsed": 11163 + "gasUsed": 11336 }, { "file": "test/Slice.t.sol", @@ -459,211 +519,217 @@ "file": "test/StoreCoreDynamic.t.sol", "test": "testGetFieldSlice", "name": "get field slice (cold, 1 slot)", - "gasUsed": 7990 + "gasUsed": 8425 }, { "file": "test/StoreCoreDynamic.t.sol", "test": "testGetFieldSlice", "name": "get field slice (warm, 1 slot)", - "gasUsed": 2059 + "gasUsed": 2493 }, { "file": "test/StoreCoreDynamic.t.sol", "test": "testGetFieldSlice", "name": "get field slice (semi-cold, 1 slot)", - "gasUsed": 4064 + "gasUsed": 4498 }, { "file": "test/StoreCoreDynamic.t.sol", "test": "testGetFieldSlice", "name": "get field slice (warm, 2 slots)", - "gasUsed": 4290 + "gasUsed": 4725 }, { "file": "test/StoreCoreDynamic.t.sol", "test": "testGetSecondFieldLength", "name": "get field length (cold, 1 slot)", - "gasUsed": 7748 + "gasUsed": 7966 }, { "file": "test/StoreCoreDynamic.t.sol", "test": "testGetSecondFieldLength", "name": "get field length (warm, 1 slot)", - "gasUsed": 1745 + "gasUsed": 1961 }, { "file": "test/StoreCoreDynamic.t.sol", "test": "testGetThirdFieldLength", "name": "get field length (warm due to , 2 slots)", - "gasUsed": 7748 + "gasUsed": 7965 }, { "file": "test/StoreCoreDynamic.t.sol", "test": "testGetThirdFieldLength", "name": "get field length (warm, 2 slots)", - "gasUsed": 1745 + "gasUsed": 1962 }, { "file": "test/StoreCoreDynamic.t.sol", "test": "testPopFromSecondField", "name": "pop from field (cold, 1 slot, 1 uint32 item)", - "gasUsed": 21684 + "gasUsed": 22898 }, { "file": "test/StoreCoreDynamic.t.sol", "test": "testPopFromSecondField", "name": "pop from field (warm, 1 slot, 1 uint32 item)", - "gasUsed": 15714 + "gasUsed": 16928 }, { "file": "test/StoreCoreDynamic.t.sol", "test": "testPopFromThirdField", "name": "pop from field (cold, 2 slots, 10 uint32 items)", - "gasUsed": 23433 + "gasUsed": 24647 }, { "file": "test/StoreCoreDynamic.t.sol", "test": "testPopFromThirdField", "name": "pop from field (warm, 2 slots, 10 uint32 items)", - "gasUsed": 15464 + "gasUsed": 16678 }, { "file": "test/StoreCoreGas.t.sol", "test": "testAccessEmptyData", "name": "access non-existing record", - "gasUsed": 6047 + "gasUsed": 6533 }, { "file": "test/StoreCoreGas.t.sol", "test": "testAccessEmptyData", "name": "access static field of non-existing record", - "gasUsed": 1506 + "gasUsed": 1481 }, { "file": "test/StoreCoreGas.t.sol", "test": "testAccessEmptyData", "name": "access dynamic field of non-existing record", - "gasUsed": 2015 + "gasUsed": 2449 }, { "file": "test/StoreCoreGas.t.sol", "test": "testAccessEmptyData", "name": "access length of dynamic field of non-existing record", - "gasUsed": 1118 + "gasUsed": 1335 }, { "file": "test/StoreCoreGas.t.sol", "test": "testAccessEmptyData", "name": "access slice of dynamic field of non-existing record", - "gasUsed": 1197 + "gasUsed": 1631 }, { "file": "test/StoreCoreGas.t.sol", "test": "testDeleteData", "name": "delete record (complex data, 3 slots)", - "gasUsed": 8421 + "gasUsed": 9470 }, { "file": "test/StoreCoreGas.t.sol", - "test": "testHasSchema", + "test": "testHasFieldLayout", "name": "Check for existence of table (existent)", - "gasUsed": 5525 + "gasUsed": 4465 }, { "file": "test/StoreCoreGas.t.sol", - "test": "testHasSchema", + "test": "testHasFieldLayout", "name": "check for existence of table (non-existent)", - "gasUsed": 7527 + "gasUsed": 6468 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooks", "name": "register subscriber", - "gasUsed": 60584 + "gasUsed": 61935 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooks", "name": "set record on table with subscriber", - "gasUsed": 71005 + "gasUsed": 73748 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooks", "name": "set static field on table with subscriber", - "gasUsed": 24312 + "gasUsed": 25441 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooks", "name": "delete record on table with subscriber", - "gasUsed": 19401 + "gasUsed": 21483 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooksDynamicData", "name": "register subscriber", - "gasUsed": 60584 + "gasUsed": 61935 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooksDynamicData", "name": "set (dynamic) record on table with subscriber", - "gasUsed": 163873 + "gasUsed": 167808 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooksDynamicData", "name": "set (dynamic) field on table with subscriber", - "gasUsed": 26248 + "gasUsed": 28269 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooksDynamicData", "name": "delete (dynamic) record on table with subscriber", - "gasUsed": 20837 + "gasUsed": 22901 }, { "file": "test/StoreCoreGas.t.sol", "test": "testPushToField", "name": "push to field (1 slot, 1 uint32 item)", - "gasUsed": 13346 + "gasUsed": 14558 }, { "file": "test/StoreCoreGas.t.sol", "test": "testPushToField", "name": "push to field (2 slots, 10 uint32 items)", - "gasUsed": 35993 + "gasUsed": 37206 + }, + { + "file": "test/StoreCoreGas.t.sol", + "test": "testRegisterAndGetFieldLayout", + "name": "StoreCore: register table", + "gasUsed": 620356 }, { "file": "test/StoreCoreGas.t.sol", - "test": "testRegisterAndGetSchema", - "name": "StoreCore: register schema", - "gasUsed": 594625 + "test": "testRegisterAndGetFieldLayout", + "name": "StoreCore: get field layout (warm)", + "gasUsed": 4479 }, { "file": "test/StoreCoreGas.t.sol", - "test": "testRegisterAndGetSchema", + "test": "testRegisterAndGetFieldLayout", "name": "StoreCore: get schema (warm)", - "gasUsed": 5539 + "gasUsed": 5033 }, { "file": "test/StoreCoreGas.t.sol", - "test": "testRegisterAndGetSchema", + "test": "testRegisterAndGetFieldLayout", "name": "StoreCore: get key schema (warm)", - "gasUsed": 10518 + "gasUsed": 9281 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetDynamicData", "name": "set complex record with dynamic data (4 slots)", - "gasUsed": 102615 + "gasUsed": 104856 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetDynamicData", "name": "get complex record with dynamic data (4 slots)", - "gasUsed": 4619 + "gasUsed": 5105 }, { "file": "test/StoreCoreGas.t.sol", @@ -699,85 +765,85 @@ "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetField", "name": "set static field (1 slot)", - "gasUsed": 33280 + "gasUsed": 33831 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetField", "name": "get static field (1 slot)", - "gasUsed": 1507 + "gasUsed": 1482 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetField", "name": "set static field (overlap 2 slot)", - "gasUsed": 32157 + "gasUsed": 32479 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetField", "name": "get static field (overlap 2 slot)", - "gasUsed": 2265 + "gasUsed": 2010 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetField", "name": "set dynamic field (1 slot, first dynamic field)", - "gasUsed": 54199 + "gasUsed": 55195 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetField", "name": "get dynamic field (1 slot, first dynamic field)", - "gasUsed": 2193 + "gasUsed": 2627 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetField", "name": "set dynamic field (1 slot, second dynamic field)", - "gasUsed": 32317 + "gasUsed": 33313 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetField", "name": "get dynamic field (1 slot, second dynamic field)", - "gasUsed": 2201 + "gasUsed": 2635 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetStaticData", "name": "set static record (1 slot)", - "gasUsed": 32833 + "gasUsed": 34181 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetStaticData", "name": "get static record (1 slot)", - "gasUsed": 1247 + "gasUsed": 1734 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetStaticDataSpanningWords", "name": "set static record (2 slots)", - "gasUsed": 55336 + "gasUsed": 56684 }, { "file": "test/StoreCoreGas.t.sol", "test": "testSetAndGetStaticDataSpanningWords", "name": "get static record (2 slots)", - "gasUsed": 1436 + "gasUsed": 1922 }, { "file": "test/StoreCoreGas.t.sol", "test": "testUpdateInField", "name": "update in field (1 slot, 1 uint32 item)", - "gasUsed": 13623 + "gasUsed": 14835 }, { "file": "test/StoreCoreGas.t.sol", "test": "testUpdateInField", "name": "push to field (2 slots, 6 uint64 items)", - "gasUsed": 14653 + "gasUsed": 15865 }, { "file": "test/StoreHook.t.sol", @@ -825,121 +891,121 @@ "file": "test/tables/Callbacks.t.sol", "test": "testSetAndGet", "name": "Callbacks: set field", - "gasUsed": 58198 + "gasUsed": 59331 }, { "file": "test/tables/Callbacks.t.sol", "test": "testSetAndGet", "name": "Callbacks: get field (warm)", - "gasUsed": 4579 + "gasUsed": 5160 }, { "file": "test/tables/Callbacks.t.sol", "test": "testSetAndGet", "name": "Callbacks: push 1 element", - "gasUsed": 37650 + "gasUsed": 39000 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testOneSlot", "name": "StoreHooks: set field with one elements (cold)", - "gasUsed": 60196 + "gasUsed": 61323 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: set field (cold)", - "gasUsed": 60196 + "gasUsed": 61323 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: get field (warm)", - "gasUsed": 4573 + "gasUsed": 5136 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: push 1 element (cold)", - "gasUsed": 17731 + "gasUsed": 19075 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: pop 1 element (warm)", - "gasUsed": 14111 + "gasUsed": 15453 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: push 1 element (warm)", - "gasUsed": 15793 + "gasUsed": 17134 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: update 1 element (warm)", - "gasUsed": 36144 + "gasUsed": 37483 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: delete record (warm)", - "gasUsed": 9820 + "gasUsed": 10992 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: set field (warm)", - "gasUsed": 32426 + "gasUsed": 33544 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testThreeSlots", "name": "StoreHooks: set field with three elements (cold)", - "gasUsed": 82884 + "gasUsed": 84011 }, { "file": "test/tables/StoreHooks.t.sol", "test": "testTwoSlots", "name": "StoreHooks: set field with two elements (cold)", - "gasUsed": 82795 + "gasUsed": 83923 }, { "file": "test/tables/StoreHooksColdLoad.t.sol", "test": "testDelete", "name": "StoreHooks: delete record (cold)", - "gasUsed": 18613 + "gasUsed": 19792 }, { "file": "test/tables/StoreHooksColdLoad.t.sol", "test": "testGet", "name": "StoreHooks: get field (cold)", - "gasUsed": 10566 + "gasUsed": 11129 }, { "file": "test/tables/StoreHooksColdLoad.t.sol", "test": "testGetItem", "name": "StoreHooks: get 1 element (cold)", - "gasUsed": 7080 + "gasUsed": 7644 }, { "file": "test/tables/StoreHooksColdLoad.t.sol", "test": "testLength", "name": "StoreHooks: get length (cold)", - "gasUsed": 6780 + "gasUsed": 7127 }, { "file": "test/tables/StoreHooksColdLoad.t.sol", "test": "testPop", "name": "StoreHooks: pop 1 element (cold)", - "gasUsed": 24235 + "gasUsed": 25580 }, { "file": "test/tables/StoreHooksColdLoad.t.sol", "test": "testUpdate", "name": "StoreHooks: update 1 element (cold)", - "gasUsed": 25811 + "gasUsed": 27157 }, { "file": "test/tightcoder/DecodeSlice.t.sol", @@ -991,20 +1057,20 @@ }, { "file": "test/Vector2.t.sol", - "test": "testRegisterAndGetSchema", - "name": "register Vector2 schema", - "gasUsed": 392691 + "test": "testRegisterAndGetFieldLayout", + "name": "register Vector2 field layout", + "gasUsed": 421468 }, { "file": "test/Vector2.t.sol", "test": "testSetAndGet", "name": "set Vector2 record", - "gasUsed": 35081 + "gasUsed": 36809 }, { "file": "test/Vector2.t.sol", "test": "testSetAndGet", "name": "get Vector2 record", - "gasUsed": 3604 + "gasUsed": 4472 } ] diff --git a/packages/store/mud.config.ts b/packages/store/mud.config.ts index 80d775bf29..8a99d085b3 100644 --- a/packages/store/mud.config.ts +++ b/packages/store/mud.config.ts @@ -14,6 +14,7 @@ export default mudConfig({ tableId: "bytes32", }, schema: { + fieldLayout: "bytes32", keySchema: "bytes32", valueSchema: "bytes32", abiEncodedKeyNames: "bytes", diff --git a/packages/store/src/FieldLayout.sol b/packages/store/src/FieldLayout.sol new file mode 100644 index 0000000000..86759aa24c --- /dev/null +++ b/packages/store/src/FieldLayout.sol @@ -0,0 +1,149 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +import { WORD_SIZE, WORD_LAST_INDEX, BYTE_TO_BITS, MAX_TOTAL_FIELDS, MAX_DYNAMIC_FIELDS, LayoutOffsets } from "./constants.sol"; + +// - 2 bytes for total length of all static fields +// - 1 byte for number of static size fields +// - 1 byte for number of dynamic size fields +// - 28 bytes for 28 static field lengths +// (MAX_DYNAMIC_FIELDS allows PackedCounter to pack the dynamic lengths into 1 word) +type FieldLayout is bytes32; + +using FieldLayoutInstance for FieldLayout global; + +/** + * Static functions for FieldLayout + */ +library FieldLayoutLib { + error FieldLayoutLib_InvalidLength(uint256 length); + error FieldLayoutLib_StaticLengthIsZero(); + error FieldLayoutLib_StaticLengthDoesNotFitInAWord(); + + /** + * Encode the given field layout into a single bytes32 + */ + function encode(uint256[] memory _staticFields, uint256 numDynamicFields) internal pure returns (FieldLayout) { + uint256 fieldLayout; + uint256 totalLength; + uint256 totalFields = _staticFields.length + numDynamicFields; + if (totalFields > MAX_TOTAL_FIELDS) revert FieldLayoutLib_InvalidLength(totalFields); + if (numDynamicFields > MAX_DYNAMIC_FIELDS) revert FieldLayoutLib_InvalidLength(numDynamicFields); + + // Compute the total static length and store the field lengths in the encoded fieldLayout + for (uint256 i = 0; i < _staticFields.length; ) { + uint256 staticByteLength = _staticFields[i]; + if (staticByteLength == 0) { + revert FieldLayoutLib_StaticLengthIsZero(); + } else if (staticByteLength > WORD_SIZE) { + revert FieldLayoutLib_StaticLengthDoesNotFitInAWord(); + } + + unchecked { + // (safe because 28 (max _staticFields.length) * 32 (max static length) < 2**16) + totalLength += staticByteLength; + // Sequentially store lengths after the first 4 bytes (which are reserved for total length and field numbers) + // (safe because of the initial _staticFields.length check) + fieldLayout |= uint256(_staticFields[i]) << ((WORD_LAST_INDEX - 4 - i) * BYTE_TO_BITS); + i++; + } + } + + // Store total static length in the first 2 bytes, + // number of static fields in the 3rd byte, + // number of dynamic fields in the 4th byte + // (optimizer can handle this, no need for unchecked or single-line assignment) + fieldLayout |= totalLength << LayoutOffsets.TOTAL_LENGTH; + fieldLayout |= _staticFields.length << LayoutOffsets.NUM_STATIC_FIELDS; + fieldLayout |= numDynamicFields << LayoutOffsets.NUM_DYNAMIC_FIELDS; + + return FieldLayout.wrap(bytes32(fieldLayout)); + } +} + +/** + * Instance functions for FieldLayout + */ +library FieldLayoutInstance { + /** + * Get the static byte length at the given index + */ + function atIndex(FieldLayout fieldLayout, uint256 index) internal pure returns (uint256) { + unchecked { + return uint8(uint256(fieldLayout.unwrap()) >> ((WORD_LAST_INDEX - 4 - index) * BYTE_TO_BITS)); + } + } + + /** + * Get the total static byte length for the given field layout + */ + function staticDataLength(FieldLayout fieldLayout) internal pure returns (uint256) { + return uint256(FieldLayout.unwrap(fieldLayout)) >> LayoutOffsets.TOTAL_LENGTH; + } + + /** + * Get the number of static fields for the field layout + */ + function numStaticFields(FieldLayout fieldLayout) internal pure returns (uint256) { + return uint8(uint256(fieldLayout.unwrap()) >> LayoutOffsets.NUM_STATIC_FIELDS); + } + + /** + * Get the number of dynamic length fields for the field layout + */ + function numDynamicFields(FieldLayout fieldLayout) internal pure returns (uint256) { + return uint8(uint256(fieldLayout.unwrap()) >> LayoutOffsets.NUM_DYNAMIC_FIELDS); + } + + /** + * Get the total number of fields for the field layout + */ + function numFields(FieldLayout fieldLayout) internal pure returns (uint256) { + unchecked { + return + uint8(uint256(fieldLayout.unwrap()) >> LayoutOffsets.NUM_STATIC_FIELDS) + + uint8(uint256(fieldLayout.unwrap()) >> LayoutOffsets.NUM_DYNAMIC_FIELDS); + } + } + + /** + * Check if the field layout is empty + */ + function isEmpty(FieldLayout fieldLayout) internal pure returns (bool) { + return FieldLayout.unwrap(fieldLayout) == bytes32(0); + } + + function validate(FieldLayout fieldLayout, bool allowEmpty) internal pure { + // FieldLayout must not be empty + if (!allowEmpty && fieldLayout.isEmpty()) revert FieldLayoutLib.FieldLayoutLib_InvalidLength(0); + + // FieldLayout must have no more than MAX_DYNAMIC_FIELDS + uint256 _numDynamicFields = fieldLayout.numDynamicFields(); + if (_numDynamicFields > MAX_DYNAMIC_FIELDS) revert FieldLayoutLib.FieldLayoutLib_InvalidLength(_numDynamicFields); + + uint256 _numStaticFields = fieldLayout.numStaticFields(); + // FieldLayout must not have more than MAX_TOTAL_FIELDS in total + uint256 _numTotalFields = _numStaticFields + _numDynamicFields; + if (_numTotalFields > MAX_TOTAL_FIELDS) revert FieldLayoutLib.FieldLayoutLib_InvalidLength(_numTotalFields); + + // Static lengths must be valid + for (uint256 i; i < _numStaticFields; ) { + uint256 staticByteLength = fieldLayout.atIndex(i); + if (staticByteLength == 0) { + revert FieldLayoutLib.FieldLayoutLib_StaticLengthIsZero(); + } else if (staticByteLength > WORD_SIZE) { + revert FieldLayoutLib.FieldLayoutLib_StaticLengthDoesNotFitInAWord(); + } + unchecked { + i++; + } + } + } + + /** + * Unwrap the field layout + */ + function unwrap(FieldLayout fieldLayout) internal pure returns (bytes32) { + return FieldLayout.unwrap(fieldLayout); + } +} diff --git a/packages/store/src/IStore.sol b/packages/store/src/IStore.sol index e75dadd2da..2a939e8529 100644 --- a/packages/store/src/IStore.sol +++ b/packages/store/src/IStore.sol @@ -2,10 +2,13 @@ pragma solidity >=0.8.0; import { IStoreErrors } from "./IStoreErrors.sol"; +import { FieldLayout } from "./FieldLayout.sol"; import { Schema } from "./Schema.sol"; import { IStoreHook } from "./IStoreHook.sol"; interface IStoreRead { + function getFieldLayout(bytes32 table) external view returns (FieldLayout fieldLayout); + function getValueSchema(bytes32 table) external view returns (Schema schema); function getKeySchema(bytes32 table) external view returns (Schema schema); @@ -14,7 +17,7 @@ interface IStoreRead { function getRecord( bytes32 table, bytes32[] calldata key, - Schema valueSchema + FieldLayout fieldLayout ) external view returns (bytes memory data); // Get partial data at schema index @@ -22,7 +25,7 @@ interface IStoreRead { bytes32 table, bytes32[] calldata key, uint8 schemaIndex, - Schema valueSchema + FieldLayout fieldLayout ) external view returns (bytes memory data); // Get field length at schema index @@ -30,7 +33,7 @@ interface IStoreRead { bytes32 table, bytes32[] memory key, uint8 schemaIndex, - Schema valueSchema + FieldLayout fieldLayout ) external view returns (uint256); // Get start:end slice of the field at schema index @@ -38,7 +41,7 @@ interface IStoreRead { bytes32 table, bytes32[] memory key, uint8 schemaIndex, - Schema valueSchema, + FieldLayout fieldLayout, uint256 start, uint256 end ) external view returns (bytes memory data); @@ -50,7 +53,7 @@ interface IStoreWrite { event StoreDeleteRecord(bytes32 table, bytes32[] key); // Set full record (including full dynamic data) - function setRecord(bytes32 table, bytes32[] calldata key, bytes calldata data, Schema valueSchema) external; + function setRecord(bytes32 table, bytes32[] calldata key, bytes calldata data, FieldLayout fieldLayout) external; // Set partial data at schema index function setField( @@ -58,7 +61,7 @@ interface IStoreWrite { bytes32[] calldata key, uint8 schemaIndex, bytes calldata data, - Schema valueSchema + FieldLayout fieldLayout ) external; // Push encoded items to the dynamic field at schema index @@ -67,7 +70,7 @@ interface IStoreWrite { bytes32[] calldata key, uint8 schemaIndex, bytes calldata dataToPush, - Schema valueSchema + FieldLayout fieldLayout ) external; // Pop byte length from the dynamic field at schema index @@ -76,7 +79,7 @@ interface IStoreWrite { bytes32[] calldata key, uint8 schemaIndex, uint256 byteLengthToPop, - Schema valueSchema + FieldLayout fieldLayout ) external; // Change encoded items within the dynamic field at schema index @@ -86,18 +89,23 @@ interface IStoreWrite { uint8 schemaIndex, uint256 startByteIndex, bytes calldata dataToSet, - Schema valueSchema + FieldLayout fieldLayout ) external; // Set full record (including full dynamic data) - function deleteRecord(bytes32 table, bytes32[] memory key, Schema valueSchema) external; + function deleteRecord(bytes32 table, bytes32[] memory key, FieldLayout fieldLayout) external; } interface IStoreEphemeral { event StoreEphemeralRecord(bytes32 table, bytes32[] key, bytes data); // Emit the ephemeral event without modifying storage - function emitEphemeralRecord(bytes32 table, bytes32[] calldata key, bytes calldata data, Schema valueSchema) external; + function emitEphemeralRecord( + bytes32 table, + bytes32[] calldata key, + bytes calldata data, + FieldLayout fieldLayout + ) external; } /** @@ -110,13 +118,14 @@ interface IStoreData is IStoreRead, IStoreWrite { } /** - * The IStoreRegistration interface includes methods for managing table schemas, + * The IStoreRegistration interface includes methods for managing table field layouts, * metadata, and hooks, which are usually called once in the setup phase of an application, * making them less performance critical than the IStoreData methods. */ interface IStoreRegistration { function registerTable( bytes32 table, + FieldLayout fieldLayout, Schema keySchema, Schema valueSchema, string[] calldata keyNames, diff --git a/packages/store/src/IStoreErrors.sol b/packages/store/src/IStoreErrors.sol index 4b74b0e321..8763723b5d 100644 --- a/packages/store/src/IStoreErrors.sol +++ b/packages/store/src/IStoreErrors.sol @@ -11,5 +11,6 @@ interface IStoreErrors { error StoreCore_InvalidDataLength(uint256 expected, uint256 received); error StoreCore_InvalidKeyNamesLength(uint256 expected, uint256 received); error StoreCore_InvalidFieldNamesLength(uint256 expected, uint256 received); + error StoreCore_InvalidValueSchemaLength(uint256 expected, uint256 received); error StoreCore_DataIndexOverflow(uint256 length, uint256 received); } diff --git a/packages/store/src/IStoreHook.sol b/packages/store/src/IStoreHook.sol index f12db1affa..ec967976c5 100644 --- a/packages/store/src/IStoreHook.sol +++ b/packages/store/src/IStoreHook.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.0; -import { Schema } from "./Schema.sol"; +import { FieldLayout } from "./FieldLayout.sol"; import { IERC165, ERC165_INTERFACE_ID } from "./IERC165.sol"; // ERC-165 Interface ID (see https://eips.ethereum.org/EIPS/eip-165) @@ -14,16 +14,16 @@ bytes4 constant STORE_HOOK_INTERFACE_ID = IStoreHook.onBeforeSetRecord.selector ERC165_INTERFACE_ID; interface IStoreHook is IERC165 { - function onBeforeSetRecord(bytes32 table, bytes32[] memory key, bytes memory data, Schema valueSchema) external; + function onBeforeSetRecord(bytes32 table, bytes32[] memory key, bytes memory data, FieldLayout fieldLayout) external; - function onAfterSetRecord(bytes32 table, bytes32[] memory key, bytes memory data, Schema valueSchema) external; + function onAfterSetRecord(bytes32 table, bytes32[] memory key, bytes memory data, FieldLayout fieldLayout) external; function onBeforeSetField( bytes32 table, bytes32[] memory key, uint8 schemaIndex, bytes memory data, - Schema valueSchema + FieldLayout fieldLayout ) external; function onAfterSetField( @@ -31,10 +31,10 @@ interface IStoreHook is IERC165 { bytes32[] memory key, uint8 schemaIndex, bytes memory data, - Schema valueSchema + FieldLayout fieldLayout ) external; - function onBeforeDeleteRecord(bytes32 table, bytes32[] memory key, Schema valueSchema) external; + function onBeforeDeleteRecord(bytes32 table, bytes32[] memory key, FieldLayout fieldLayout) external; - function onAfterDeleteRecord(bytes32 table, bytes32[] memory key, Schema valueSchema) external; + function onAfterDeleteRecord(bytes32 table, bytes32[] memory key, FieldLayout fieldLayout) external; } diff --git a/packages/store/src/PackedCounter.sol b/packages/store/src/PackedCounter.sol index e8f53ec949..32f0aa2a7a 100644 --- a/packages/store/src/PackedCounter.sol +++ b/packages/store/src/PackedCounter.sol @@ -127,7 +127,7 @@ library PackedCounterInstance { } // Set the new accumulated value and value at index - // (7 bytes total length, 5 bytes per dynamic schema) + // (7 bytes total length, 5 bytes per dynamic field) uint256 offset; unchecked { offset = ACC_BITS + VAL_BITS * index; diff --git a/packages/store/src/Schema.sol b/packages/store/src/Schema.sol index d27084af51..0d47200371 100644 --- a/packages/store/src/Schema.sol +++ b/packages/store/src/Schema.sol @@ -2,7 +2,8 @@ pragma solidity >=0.8.0; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; -import { Bytes } from "./Bytes.sol"; + +import { WORD_LAST_INDEX, BYTE_TO_BITS, MAX_TOTAL_FIELDS, MAX_DYNAMIC_FIELDS, LayoutOffsets } from "./constants.sol"; // - 2 bytes static length of the schema // - 1 byte for number of static size fields @@ -19,14 +20,11 @@ library SchemaLib { error SchemaLib_InvalidLength(uint256 length); error SchemaLib_StaticTypeAfterDynamicType(); - // Based on PackedCounter's capacity - uint256 internal constant MAX_DYNAMIC_FIELDS = 5; - /** * Encode the given schema into a single bytes32 */ function encode(SchemaType[] memory _schema) internal pure returns (Schema) { - if (_schema.length > 28) revert SchemaLib_InvalidLength(_schema.length); + if (_schema.length > MAX_TOTAL_FIELDS) revert SchemaLib_InvalidLength(_schema.length); uint256 schema; uint256 totalLength; uint256 dynamicFields; @@ -52,7 +50,7 @@ library SchemaLib { totalLength += staticByteLength; // Sequentially store schema types after the first 4 bytes (which are reserved for length and field numbers) // (safe because of the initial _schema.length check) - schema |= uint256(_schema[i]) << ((31 - 4 - i) * 8); + schema |= uint256(_schema[i]) << ((WORD_LAST_INDEX - 4 - i) * BYTE_TO_BITS); i++; } } @@ -70,9 +68,9 @@ library SchemaLib { // number of static fields in the 3rd byte, // number of dynamic fields in the 4th byte // (optimizer can handle this, no need for unchecked or single-line assignment) - schema |= totalLength << ((32 - 2) * 8); - schema |= staticFields << ((32 - 2 - 1) * 8); - schema |= dynamicFields << ((32 - 2 - 1 - 1) * 8); + schema |= totalLength << LayoutOffsets.TOTAL_LENGTH; + schema |= staticFields << LayoutOffsets.NUM_STATIC_FIELDS; + schema |= dynamicFields << LayoutOffsets.NUM_DYNAMIC_FIELDS; return Schema.wrap(bytes32(schema)); } @@ -86,7 +84,7 @@ library SchemaInstance { * Get the length of the static data for the given schema */ function staticDataLength(Schema schema) internal pure returns (uint256) { - return uint256(Schema.unwrap(schema)) >> ((32 - 2) * 8); + return uint256(Schema.unwrap(schema)) >> LayoutOffsets.TOTAL_LENGTH; } /** @@ -94,22 +92,22 @@ library SchemaInstance { */ function atIndex(Schema schema, uint256 index) internal pure returns (SchemaType) { unchecked { - return SchemaType(uint8(uint256(schema.unwrap()) >> ((31 - 4 - index) * 8))); + return SchemaType(uint8(uint256(schema.unwrap()) >> ((WORD_LAST_INDEX - 4 - index) * 8))); } } /** - * Get the number of dynamic length fields for the given schema + * Get the number of static fields for the given schema */ - function numDynamicFields(Schema schema) internal pure returns (uint256) { - return uint8(uint256(schema.unwrap()) >> ((31 - 3) * 8)); + function numStaticFields(Schema schema) internal pure returns (uint256) { + return uint8(uint256(schema.unwrap()) >> LayoutOffsets.NUM_STATIC_FIELDS); } /** - * Get the number of static fields for the given schema + * Get the number of dynamic length fields for the given schema */ - function numStaticFields(Schema schema) internal pure returns (uint256) { - return uint8(uint256(schema.unwrap()) >> ((31 - 2) * 8)); + function numDynamicFields(Schema schema) internal pure returns (uint256) { + return uint8(uint256(schema.unwrap()) >> LayoutOffsets.NUM_DYNAMIC_FIELDS); } /** @@ -117,7 +115,9 @@ library SchemaInstance { */ function numFields(Schema schema) internal pure returns (uint256) { unchecked { - return uint8(uint256(schema.unwrap()) >> ((31 - 3) * 8)) + uint8(uint256(schema.unwrap()) >> ((31 - 2) * 8)); + return + uint8(uint256(schema.unwrap()) >> LayoutOffsets.NUM_STATIC_FIELDS) + + uint8(uint256(schema.unwrap()) >> LayoutOffsets.NUM_DYNAMIC_FIELDS); } } @@ -134,12 +134,12 @@ library SchemaInstance { // Schema must have no more than MAX_DYNAMIC_FIELDS uint256 _numDynamicFields = schema.numDynamicFields(); - if (_numDynamicFields > SchemaLib.MAX_DYNAMIC_FIELDS) revert SchemaLib.SchemaLib_InvalidLength(_numDynamicFields); + if (_numDynamicFields > MAX_DYNAMIC_FIELDS) revert SchemaLib.SchemaLib_InvalidLength(_numDynamicFields); uint256 _numStaticFields = schema.numStaticFields(); - // Schema must not have more than 28 fields in total + // Schema must not have more than MAX_TOTAL_FIELDS in total uint256 _numTotalFields = _numStaticFields + _numDynamicFields; - if (_numTotalFields > 28) revert SchemaLib.SchemaLib_InvalidLength(_numTotalFields); + if (_numTotalFields > MAX_TOTAL_FIELDS) revert SchemaLib.SchemaLib_InvalidLength(_numTotalFields); // No static field can be after a dynamic field uint256 countStaticFields; diff --git a/packages/store/src/StoreCore.sol b/packages/store/src/StoreCore.sol index 6555c689e9..7c52c5280d 100644 --- a/packages/store/src/StoreCore.sol +++ b/packages/store/src/StoreCore.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.0; -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; import { Bytes } from "./Bytes.sol"; import { Storage } from "./Storage.sol"; import { Memory } from "./Memory.sol"; +import { FieldLayout, FieldLayoutLib } from "./FieldLayout.sol"; import { Schema, SchemaLib } from "./Schema.sol"; import { PackedCounter } from "./PackedCounter.sol"; import { Slice, SliceLib } from "./Slice.sol"; @@ -18,7 +18,7 @@ import { StoreHookLib, StoreHookType } from "./StoreHook.sol"; library StoreCore { // note: the preimage of the tuple of keys used to index is part of the event, so it can be used by indexers event StoreSetRecord(bytes32 table, bytes32[] key, bytes data); - event StoreSetField(bytes32 table, bytes32[] key, uint8 schemaIndex, bytes data); + event StoreSetField(bytes32 table, bytes32[] key, uint8 fieldIndex, bytes data); event StoreDeleteRecord(bytes32 table, bytes32[] key); event StoreEphemeralRecord(bytes32 table, bytes32[] key, bytes data); @@ -44,11 +44,11 @@ library StoreCore { ************************************************************************/ /** - * Get the schema for the given tableId + * Get the field layout for the given tableId */ - function getValueSchema(bytes32 tableId) internal view returns (Schema valueSchema) { - valueSchema = Schema.wrap(Tables.getValueSchema(tableId)); - if (valueSchema.isEmpty()) { + function getFieldLayout(bytes32 tableId) internal view returns (FieldLayout fieldLayout) { + fieldLayout = FieldLayout.wrap(Tables.getFieldLayout(tableId)); + if (fieldLayout.isEmpty()) { revert IStoreErrors.StoreCore_TableNotFound(tableId, string(abi.encodePacked(tableId))); } } @@ -64,45 +64,63 @@ library StoreCore { } } + /** + * Get the schema for the given tableId + */ + function getValueSchema(bytes32 tableId) internal view returns (Schema valueSchema) { + valueSchema = Schema.wrap(Tables.getValueSchema(tableId)); + if (valueSchema.isEmpty()) { + revert IStoreErrors.StoreCore_TableNotFound(tableId, string(abi.encodePacked(tableId))); + } + } + /** * Check if a table with the given tableId exists */ function hasTable(bytes32 tableId) internal view returns (bool) { - return Tables.getValueSchema(tableId) != bytes32(0); + return Tables.getFieldLayout(tableId) != bytes32(0); } /** - * Register a new table with key schema, value schema, key names, and field names + * Register a new table with key field layout, value field layout, key names, and value names */ function registerTable( bytes32 tableId, + FieldLayout fieldLayout, Schema keySchema, Schema valueSchema, string[] memory keyNames, string[] memory fieldNames ) internal { + // Verify the field layout is valid + fieldLayout.validate({ allowEmpty: false }); // Verify the schema is valid keySchema.validate({ allowEmpty: true }); valueSchema.validate({ allowEmpty: false }); - // Verify the number of key names corresponds to the key schema length + // Verify the number of key names matches the number of key schema types if (keyNames.length != keySchema.numFields()) { revert IStoreErrors.StoreCore_InvalidKeyNamesLength(keySchema.numFields(), keyNames.length); } - // Verify the number of field names corresponds to the value schema length - if (fieldNames.length != valueSchema.numFields()) { - revert IStoreErrors.StoreCore_InvalidFieldNamesLength(valueSchema.numFields(), fieldNames.length); + // Verify the number of value names + if (fieldNames.length != fieldLayout.numFields()) { + revert IStoreErrors.StoreCore_InvalidFieldNamesLength(fieldLayout.numFields(), fieldNames.length); + } + // Verify the number of value schema types + if (valueSchema.numFields() != fieldLayout.numFields()) { + revert IStoreErrors.StoreCore_InvalidValueSchemaLength(fieldLayout.numFields(), valueSchema.numFields()); } - // Verify the schema doesn't exist yet + // Verify the field layout doesn't exist yet if (hasTable(tableId)) { revert IStoreErrors.StoreCore_TableAlreadyExists(tableId, string(abi.encodePacked(tableId))); } - // Register the schema + // Register the table metadata Tables.set( tableId, + FieldLayout.unwrap(fieldLayout), Schema.unwrap(keySchema), Schema.unwrap(valueSchema), abi.encode(keyNames), @@ -137,14 +155,14 @@ library StoreCore { ************************************************************************/ /** - * Set full data record for the given tableId and key tuple and schema + * Set full data record for the given tableId and key tuple and field layout */ - function setRecord(bytes32 tableId, bytes32[] memory key, bytes memory data, Schema valueSchema) internal { - // verify the value has the correct length for the tableId (based on the tableId's schema) + function setRecord(bytes32 tableId, bytes32[] memory key, bytes memory data, FieldLayout fieldLayout) internal { + // verify the value has the correct length for the tableId (based on the tableId's field layout) // to prevent invalid data from being stored // Verify static data length + dynamic data length matches the given data - (uint256 staticLength, PackedCounter dynamicLength) = StoreCoreInternal._validateDataLength(valueSchema, data); + (uint256 staticLength, PackedCounter dynamicLength) = StoreCoreInternal._validateDataLength(fieldLayout, data); // Emit event to notify indexers emit StoreSetRecord(tableId, key, data); @@ -154,7 +172,7 @@ library StoreCore { for (uint256 i; i < hooks.length; i++) { Hook hook = Hook.wrap(hooks[i]); if (hook.isEnabled(uint8(StoreHookType.BEFORE_SET_RECORD))) { - IStoreHook(hook.getAddress()).onBeforeSetRecord(tableId, key, data, valueSchema); + IStoreHook(hook.getAddress()).onBeforeSetRecord(tableId, key, data, fieldLayout); } } @@ -170,7 +188,7 @@ library StoreCore { memoryPointer += staticLength + 32; // move the memory pointer to the start of the dynamic data (skip the encoded dynamic length) // Set the dynamic data if there are dynamic fields - if (valueSchema.numDynamicFields() > 0) { + if (fieldLayout.numDynamicFields() > 0) { // Store the dynamic data length at the dynamic data length location uint256 dynamicDataLengthLocation = StoreCoreInternal._getDynamicDataLengthLocation(tableId, key); Storage.store({ storagePointer: dynamicDataLengthLocation, data: dynamicLength.unwrap() }); @@ -178,7 +196,7 @@ library StoreCore { // For every dynamic element, slice off the dynamic data and store it at the dynamic location uint256 dynamicDataLocation; uint256 dynamicDataLength; - for (uint8 i; i < valueSchema.numDynamicFields(); ) { + for (uint8 i; i < fieldLayout.numDynamicFields(); ) { dynamicDataLocation = StoreCoreInternal._getDynamicDataLocation(tableId, key, i); dynamicDataLength = dynamicLength.atIndex(i); Storage.store({ @@ -198,20 +216,20 @@ library StoreCore { for (uint256 i; i < hooks.length; i++) { Hook hook = Hook.wrap(hooks[i]); if (hook.isEnabled(uint8(StoreHookType.AFTER_SET_RECORD))) { - IStoreHook(hook.getAddress()).onAfterSetRecord(tableId, key, data, valueSchema); + IStoreHook(hook.getAddress()).onAfterSetRecord(tableId, key, data, fieldLayout); } } } /** - * Set data for a field in a table with the given tableId, key tuple and value schema + * Set data for a field in a table with the given tableId, key tuple and value field layout */ function setField( bytes32 tableId, bytes32[] memory key, uint8 schemaIndex, bytes memory data, - Schema valueSchema + FieldLayout fieldLayout ) internal { // Emit event to notify indexers emit StoreSetField(tableId, key, schemaIndex, data); @@ -221,29 +239,29 @@ library StoreCore { for (uint256 i; i < hooks.length; i++) { Hook hook = Hook.wrap(hooks[i]); if (hook.isEnabled(uint8(StoreHookType.BEFORE_SET_FIELD))) { - IStoreHook(hook.getAddress()).onBeforeSetField(tableId, key, schemaIndex, data, valueSchema); + IStoreHook(hook.getAddress()).onBeforeSetField(tableId, key, schemaIndex, data, fieldLayout); } } - if (schemaIndex < valueSchema.numStaticFields()) { - StoreCoreInternal._setStaticField(tableId, key, valueSchema, schemaIndex, data); + if (schemaIndex < fieldLayout.numStaticFields()) { + StoreCoreInternal._setStaticField(tableId, key, fieldLayout, schemaIndex, data); } else { - StoreCoreInternal._setDynamicField(tableId, key, valueSchema, schemaIndex, data); + StoreCoreInternal._setDynamicField(tableId, key, fieldLayout, schemaIndex, data); } // Call onAfterSetField hooks (after modifying the state) for (uint256 i; i < hooks.length; i++) { Hook hook = Hook.wrap(hooks[i]); if (hook.isEnabled(uint8(StoreHookType.AFTER_SET_FIELD))) { - IStoreHook(hook.getAddress()).onAfterSetField(tableId, key, schemaIndex, data, valueSchema); + IStoreHook(hook.getAddress()).onAfterSetField(tableId, key, schemaIndex, data, fieldLayout); } } } /** - * Delete a record for the given tableId, key tuple and value schema + * Delete a record for the given tableId, key tuple and value field layout */ - function deleteRecord(bytes32 tableId, bytes32[] memory key, Schema valueSchema) internal { + function deleteRecord(bytes32 tableId, bytes32[] memory key, FieldLayout fieldLayout) internal { // Emit event to notify indexers emit StoreDeleteRecord(tableId, key); @@ -252,16 +270,16 @@ library StoreCore { for (uint256 i; i < hooks.length; i++) { Hook hook = Hook.wrap(hooks[i]); if (hook.isEnabled(uint8(StoreHookType.BEFORE_DELETE_RECORD))) { - IStoreHook(hook.getAddress()).onBeforeDeleteRecord(tableId, key, valueSchema); + IStoreHook(hook.getAddress()).onBeforeDeleteRecord(tableId, key, fieldLayout); } } // Delete static data uint256 staticDataLocation = StoreCoreInternal._getStaticDataLocation(tableId, key); - Storage.store({ storagePointer: staticDataLocation, offset: 0, data: new bytes(valueSchema.staticDataLength()) }); + Storage.store({ storagePointer: staticDataLocation, offset: 0, data: new bytes(fieldLayout.staticDataLength()) }); // If there are dynamic fields, delete the dynamic data length - if (valueSchema.numDynamicFields() > 0) { + if (fieldLayout.numDynamicFields() > 0) { uint256 dynamicDataLengthLocation = StoreCoreInternal._getDynamicDataLengthLocation(tableId, key); Storage.store({ storagePointer: dynamicDataLengthLocation, data: bytes32(0) }); } @@ -270,28 +288,28 @@ library StoreCore { for (uint256 i; i < hooks.length; i++) { Hook hook = Hook.wrap(hooks[i]); if (hook.isEnabled(uint8(StoreHookType.AFTER_DELETE_RECORD))) { - IStoreHook(hook.getAddress()).onAfterDeleteRecord(tableId, key, valueSchema); + IStoreHook(hook.getAddress()).onAfterDeleteRecord(tableId, key, fieldLayout); } } } /** - * Push data to a field in a table with the given tableId, key tuple and value schema + * Push data to a field in a table with the given tableId, key tuple and value field layout */ function pushToField( bytes32 tableId, bytes32[] memory key, uint8 schemaIndex, bytes memory dataToPush, - Schema valueSchema + FieldLayout fieldLayout ) internal { - if (schemaIndex < valueSchema.numStaticFields()) { + if (schemaIndex < fieldLayout.numStaticFields()) { revert IStoreErrors.StoreCore_NotDynamicField(); } // TODO add push-specific event and hook to avoid the storage read? (https://github.com/latticexyz/mud/issues/444) bytes memory fullData = abi.encodePacked( - StoreCoreInternal._getDynamicField(tableId, key, schemaIndex, valueSchema), + StoreCoreInternal._getDynamicField(tableId, key, schemaIndex, fieldLayout), dataToPush ); @@ -303,39 +321,39 @@ library StoreCore { for (uint256 i; i < hooks.length; i++) { Hook hook = Hook.wrap(hooks[i]); if (hook.isEnabled(uint8(StoreHookType.BEFORE_SET_FIELD))) { - IStoreHook(hook.getAddress()).onBeforeSetField(tableId, key, schemaIndex, fullData, valueSchema); + IStoreHook(hook.getAddress()).onBeforeSetField(tableId, key, schemaIndex, fullData, fieldLayout); } } - StoreCoreInternal._pushToDynamicField(tableId, key, valueSchema, schemaIndex, dataToPush); + StoreCoreInternal._pushToDynamicField(tableId, key, fieldLayout, schemaIndex, dataToPush); // Call onAfterSetField hooks (after modifying the state) for (uint256 i; i < hooks.length; i++) { Hook hook = Hook.wrap(hooks[i]); if (hook.isEnabled(uint8(StoreHookType.AFTER_SET_FIELD))) { - IStoreHook(hook.getAddress()).onAfterSetField(tableId, key, schemaIndex, fullData, valueSchema); + IStoreHook(hook.getAddress()).onAfterSetField(tableId, key, schemaIndex, fullData, fieldLayout); } } } /** - * Pop data from a field in a table with the given tableId, key tuple and value schema + * Pop data from a field in a table with the given tableId, key tuple and value field layout */ function popFromField( bytes32 tableId, bytes32[] memory key, uint8 schemaIndex, uint256 byteLengthToPop, - Schema valueSchema + FieldLayout fieldLayout ) internal { - if (schemaIndex < valueSchema.numStaticFields()) { + if (schemaIndex < fieldLayout.numStaticFields()) { revert IStoreErrors.StoreCore_NotDynamicField(); } // TODO add pop-specific event and hook to avoid the storage read? (https://github.com/latticexyz/mud/issues/444) bytes memory fullData; { - bytes memory oldData = StoreCoreInternal._getDynamicField(tableId, key, schemaIndex, valueSchema); + bytes memory oldData = StoreCoreInternal._getDynamicField(tableId, key, schemaIndex, fieldLayout); fullData = SliceLib.getSubslice(oldData, 0, oldData.length - byteLengthToPop).toBytes(); } @@ -347,23 +365,23 @@ library StoreCore { for (uint256 i; i < hooks.length; i++) { Hook hook = Hook.wrap(hooks[i]); if (hook.isEnabled(uint8(StoreHookType.BEFORE_SET_FIELD))) { - IStoreHook(hook.getAddress()).onBeforeSetField(tableId, key, schemaIndex, fullData, valueSchema); + IStoreHook(hook.getAddress()).onBeforeSetField(tableId, key, schemaIndex, fullData, fieldLayout); } } - StoreCoreInternal._popFromDynamicField(tableId, key, valueSchema, schemaIndex, byteLengthToPop); + StoreCoreInternal._popFromDynamicField(tableId, key, fieldLayout, schemaIndex, byteLengthToPop); // Call onAfterSetField hooks (after modifying the state) for (uint256 i; i < hooks.length; i++) { Hook hook = Hook.wrap(hooks[i]); if (hook.isEnabled(uint8(StoreHookType.AFTER_SET_FIELD))) { - IStoreHook(hook.getAddress()).onAfterSetField(tableId, key, schemaIndex, fullData, valueSchema); + IStoreHook(hook.getAddress()).onAfterSetField(tableId, key, schemaIndex, fullData, fieldLayout); } } } /** - * Update data in a field in a table with the given tableId, key tuple and value schema + * Update data in a field in a table with the given tableId, key tuple and value field layout */ function updateInField( bytes32 tableId, @@ -371,9 +389,9 @@ library StoreCore { uint8 schemaIndex, uint256 startByteIndex, bytes memory dataToSet, - Schema valueSchema + FieldLayout fieldLayout ) internal { - if (schemaIndex < valueSchema.numStaticFields()) { + if (schemaIndex < fieldLayout.numStaticFields()) { revert IStoreErrors.StoreCore_NotDynamicField(); } // index must be checked because it could be arbitrarily large @@ -385,7 +403,7 @@ library StoreCore { // TODO add setItem-specific event and hook to avoid the storage read? (https://github.com/latticexyz/mud/issues/444) bytes memory fullData; { - bytes memory oldData = StoreCoreInternal._getDynamicField(tableId, key, schemaIndex, valueSchema); + bytes memory oldData = StoreCoreInternal._getDynamicField(tableId, key, schemaIndex, fieldLayout); fullData = abi.encodePacked( SliceLib.getSubslice(oldData, 0, startByteIndex).toBytes(), dataToSet, @@ -401,17 +419,17 @@ library StoreCore { for (uint256 i; i < hooks.length; i++) { Hook hook = Hook.wrap(hooks[i]); if (hook.isEnabled(uint8(StoreHookType.BEFORE_SET_FIELD))) { - IStoreHook(hook.getAddress()).onBeforeSetField(tableId, key, schemaIndex, fullData, valueSchema); + IStoreHook(hook.getAddress()).onBeforeSetField(tableId, key, schemaIndex, fullData, fieldLayout); } } - StoreCoreInternal._setDynamicFieldItem(tableId, key, valueSchema, schemaIndex, startByteIndex, dataToSet); + StoreCoreInternal._setDynamicFieldItem(tableId, key, fieldLayout, schemaIndex, startByteIndex, dataToSet); // Call onAfterSetField hooks (after modifying the state) for (uint256 i; i < hooks.length; i++) { Hook hook = Hook.wrap(hooks[i]); if (hook.isEnabled(uint8(StoreHookType.AFTER_SET_FIELD))) { - IStoreHook(hook.getAddress()).onAfterSetField(tableId, key, schemaIndex, fullData, valueSchema); + IStoreHook(hook.getAddress()).onAfterSetField(tableId, key, schemaIndex, fullData, fieldLayout); } } } @@ -425,9 +443,14 @@ library StoreCore { /** * Emit the ephemeral event without modifying storage for the full data of the given tableId and key tuple */ - function emitEphemeralRecord(bytes32 tableId, bytes32[] memory key, bytes memory data, Schema valueSchema) internal { + function emitEphemeralRecord( + bytes32 tableId, + bytes32[] memory key, + bytes memory data, + FieldLayout fieldLayout + ) internal { // Verify static data length + dynamic data length matches the given data - StoreCoreInternal._validateDataLength(valueSchema, data); + StoreCoreInternal._validateDataLength(fieldLayout, data); // Emit event to notify indexers emit StoreEphemeralRecord(tableId, key, data); @@ -440,16 +463,20 @@ library StoreCore { ************************************************************************/ /** - * Get full record (all fields, static and dynamic data) for the given tableId and key tuple, with the given value schema + * 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[] memory key, Schema valueSchema) internal view returns (bytes memory) { + function getRecord( + bytes32 tableId, + bytes32[] memory key, + FieldLayout fieldLayout + ) internal view returns (bytes memory) { // Get the static data length - uint256 staticLength = valueSchema.staticDataLength(); + uint256 staticLength = fieldLayout.staticDataLength(); uint256 outputLength = staticLength; // Load the dynamic data length if there are dynamic fields PackedCounter dynamicDataLength; - uint256 numDynamicFields = valueSchema.numDynamicFields(); + uint256 numDynamicFields = fieldLayout.numDynamicFields(); if (numDynamicFields > 0) { dynamicDataLength = StoreCoreInternal._loadEncodedDynamicDataLength(tableId, key); // TODO should total output include dynamic data length even if it's 0? @@ -491,55 +518,54 @@ library StoreCore { } /** - * Get a single field from the given tableId and key tuple, with the given value schema + * Get a single field from the given tableId and key tuple, with the given value field layout */ function getField( bytes32 tableId, bytes32[] memory key, uint8 schemaIndex, - Schema valueSchema + FieldLayout fieldLayout ) internal view returns (bytes memory) { - if (schemaIndex < valueSchema.numStaticFields()) { - return StoreCoreInternal._getStaticField(tableId, key, schemaIndex, valueSchema); + if (schemaIndex < fieldLayout.numStaticFields()) { + return StoreCoreInternal._getStaticField(tableId, key, schemaIndex, fieldLayout); } else { - return StoreCoreInternal._getDynamicField(tableId, key, schemaIndex, valueSchema); + return StoreCoreInternal._getDynamicField(tableId, key, schemaIndex, fieldLayout); } } /** - * Get the byte length of a single field from the given tableId and key tuple, with the given value schema + * 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 key, uint8 schemaIndex, - Schema valueSchema + FieldLayout fieldLayout ) internal view returns (uint256) { - uint8 numStaticFields = uint8(valueSchema.numStaticFields()); + uint8 numStaticFields = uint8(fieldLayout.numStaticFields()); if (schemaIndex < numStaticFields) { - SchemaType schemaType = valueSchema.atIndex(schemaIndex); - return schemaType.getStaticByteLength(); + return fieldLayout.atIndex(schemaIndex); } else { // Get the length and storage location of the dynamic field - uint8 dynamicSchemaIndex = schemaIndex - numStaticFields; - return StoreCoreInternal._loadEncodedDynamicDataLength(tableId, key).atIndex(dynamicSchemaIndex); + uint8 dynamicFieldLayoutIndex = schemaIndex - numStaticFields; + return StoreCoreInternal._loadEncodedDynamicDataLength(tableId, key).atIndex(dynamicFieldLayoutIndex); } } /** - * Get a byte slice (including start, excluding end) of a single dynamic field from the given tableId and key tuple, with the given value schema. + * 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 key, uint8 schemaIndex, - Schema valueSchema, + FieldLayout fieldLayout, uint256 start, uint256 end ) internal view returns (bytes memory) { - uint8 numStaticFields = uint8(valueSchema.numStaticFields()); - if (schemaIndex < valueSchema.numStaticFields()) { + uint8 numStaticFields = uint8(fieldLayout.numStaticFields()); + if (schemaIndex < fieldLayout.numStaticFields()) { revert IStoreErrors.StoreCore_NotDynamicField(); } @@ -563,30 +589,30 @@ library StoreCoreInternal { function _setStaticField( bytes32 tableId, bytes32[] memory key, - Schema valueSchema, + FieldLayout fieldLayout, uint8 schemaIndex, bytes memory data ) internal { // verify the value has the correct length for the field - SchemaType schemaType = valueSchema.atIndex(schemaIndex); - if (schemaType.getStaticByteLength() != data.length) { - revert IStoreErrors.StoreCore_InvalidDataLength(schemaType.getStaticByteLength(), data.length); + uint256 staticByteLength = fieldLayout.atIndex(schemaIndex); + if (staticByteLength != data.length) { + revert IStoreErrors.StoreCore_InvalidDataLength(staticByteLength, data.length); } // Store the provided value in storage uint256 location = _getStaticDataLocation(tableId, key); - uint256 offset = _getStaticDataOffset(valueSchema, schemaIndex); + uint256 offset = _getStaticDataOffset(fieldLayout, schemaIndex); Storage.store({ storagePointer: location, offset: offset, data: data }); } function _setDynamicField( bytes32 tableId, bytes32[] memory key, - Schema valueSchema, + FieldLayout fieldLayout, uint8 schemaIndex, bytes memory data ) internal { - uint8 dynamicSchemaIndex = schemaIndex - uint8(valueSchema.numStaticFields()); + uint8 dynamicSchemaIndex = schemaIndex - uint8(fieldLayout.numStaticFields()); // Update the dynamic data length _setDynamicDataLengthAtIndex(tableId, key, dynamicSchemaIndex, data.length); @@ -599,22 +625,22 @@ library StoreCoreInternal { function _pushToDynamicField( bytes32 tableId, bytes32[] memory key, - Schema valueSchema, + FieldLayout fieldLayout, uint8 schemaIndex, bytes memory dataToPush ) internal { - uint8 dynamicSchemaIndex = schemaIndex - uint8(valueSchema.numStaticFields()); + uint8 dynamicSchemaIndex = schemaIndex - uint8(fieldLayout.numStaticFields()); // Load dynamic data length from storage - uint256 dynamicSchemaLengthSlot = _getDynamicDataLengthLocation(tableId, key); - PackedCounter encodedLengths = PackedCounter.wrap(Storage.load({ storagePointer: dynamicSchemaLengthSlot })); + uint256 dynamicDataLengthSlot = _getDynamicDataLengthLocation(tableId, key); + PackedCounter encodedLengths = PackedCounter.wrap(Storage.load({ storagePointer: dynamicDataLengthSlot })); // Update the encoded length uint256 oldFieldLength = encodedLengths.atIndex(dynamicSchemaIndex); encodedLengths = encodedLengths.setAtIndex(dynamicSchemaIndex, oldFieldLength + dataToPush.length); // Set the new length - Storage.store({ storagePointer: dynamicSchemaLengthSlot, data: encodedLengths.unwrap() }); + Storage.store({ storagePointer: dynamicDataLengthSlot, data: encodedLengths.unwrap() }); // Append `dataToPush` to the end of the data in storage _setPartialDynamicData(tableId, key, dynamicSchemaIndex, oldFieldLength, dataToPush); @@ -623,22 +649,22 @@ library StoreCoreInternal { function _popFromDynamicField( bytes32 tableId, bytes32[] memory key, - Schema valueSchema, + FieldLayout fieldLayout, uint8 schemaIndex, uint256 byteLengthToPop ) internal { - uint8 dynamicSchemaIndex = schemaIndex - uint8(valueSchema.numStaticFields()); + uint8 dynamicSchemaIndex = schemaIndex - uint8(fieldLayout.numStaticFields()); // Load dynamic data length from storage - uint256 dynamicSchemaLengthSlot = _getDynamicDataLengthLocation(tableId, key); - PackedCounter encodedLengths = PackedCounter.wrap(Storage.load({ storagePointer: dynamicSchemaLengthSlot })); + uint256 dynamicDataLengthSlot = _getDynamicDataLengthLocation(tableId, key); + PackedCounter encodedLengths = PackedCounter.wrap(Storage.load({ storagePointer: dynamicDataLengthSlot })); // Update the encoded length uint256 oldFieldLength = encodedLengths.atIndex(dynamicSchemaIndex); encodedLengths = encodedLengths.setAtIndex(dynamicSchemaIndex, oldFieldLength - byteLengthToPop); // Set the new length - Storage.store({ storagePointer: dynamicSchemaLengthSlot, data: encodedLengths.unwrap() }); + Storage.store({ storagePointer: dynamicDataLengthSlot, data: encodedLengths.unwrap() }); // Data can be left unchanged, push/set do not assume storage to be 0s } @@ -647,12 +673,12 @@ library StoreCoreInternal { function _setDynamicFieldItem( bytes32 tableId, bytes32[] memory key, - Schema valueSchema, + FieldLayout fieldLayout, uint8 schemaIndex, uint256 startByteIndex, bytes memory dataToSet ) internal { - uint8 dynamicSchemaIndex = schemaIndex - uint8(valueSchema.numStaticFields()); + uint8 dynamicSchemaIndex = schemaIndex - uint8(fieldLayout.numStaticFields()); // Set `dataToSet` at the given index _setPartialDynamicData(tableId, key, dynamicSchemaIndex, startByteIndex, dataToSet); @@ -676,36 +702,35 @@ library StoreCoreInternal { } /** - * Get a single static field from the given tableId and key tuple, with the given value schema + * Get a single static field from the given tableId and key tuple, with the given value field layout */ function _getStaticField( bytes32 tableId, bytes32[] memory key, uint8 schemaIndex, - Schema valueSchema + FieldLayout fieldLayout ) internal view returns (bytes memory) { // Get the length, storage location and offset of the static field - SchemaType schemaType = valueSchema.atIndex(schemaIndex); - uint256 dataLength = schemaType.getStaticByteLength(); + uint256 staticByteLength = fieldLayout.atIndex(schemaIndex); uint256 location = _getStaticDataLocation(tableId, key); - uint256 offset = _getStaticDataOffset(valueSchema, schemaIndex); + uint256 offset = _getStaticDataOffset(fieldLayout, schemaIndex); // Load the data from storage - return Storage.load({ storagePointer: location, length: dataLength, offset: offset }); + 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 schema + * Get a single dynamic field from the given tableId and key tuple, with the given value field layout */ function _getDynamicField( bytes32 tableId, bytes32[] memory key, uint8 schemaIndex, - Schema valueSchema + FieldLayout fieldLayout ) internal view returns (bytes memory) { // Get the length and storage location of the dynamic field - uint8 dynamicSchemaIndex = schemaIndex - uint8(valueSchema.numStaticFields()); + uint8 dynamicSchemaIndex = schemaIndex - uint8(fieldLayout.numStaticFields()); uint256 location = _getDynamicDataLocation(tableId, key, dynamicSchemaIndex); uint256 dataLength = _loadEncodedDynamicDataLength(tableId, key).atIndex(dynamicSchemaIndex); @@ -723,13 +748,13 @@ library StoreCoreInternal { * Returns the static and dynamic lengths */ function _validateDataLength( - Schema valueSchema, + FieldLayout fieldLayout, bytes memory data ) internal pure returns (uint256 staticLength, PackedCounter dynamicLength) { - staticLength = valueSchema.staticDataLength(); + staticLength = fieldLayout.staticDataLength(); uint256 expectedLength = staticLength; dynamicLength; - if (valueSchema.numDynamicFields() > 0) { + if (fieldLayout.numDynamicFields() > 0) { // Dynamic length is encoded at the start of the dynamic length blob dynamicLength = PackedCounter.wrap(Bytes.slice32(data, staticLength)); expectedLength += 32 + dynamicLength.total(); // encoded length + data @@ -752,12 +777,12 @@ library StoreCoreInternal { } /** - * Get storage offset for the given value schema and (static length) index + * Get storage offset for the given value field layout and (static length) index */ - function _getStaticDataOffset(Schema valueSchema, uint8 schemaIndex) internal pure returns (uint256) { + function _getStaticDataOffset(FieldLayout fieldLayout, uint8 schemaIndex) internal pure returns (uint256) { uint256 offset = 0; for (uint256 i; i < schemaIndex; i++) { - offset += valueSchema.atIndex(i).getStaticByteLength(); + offset += fieldLayout.atIndex(i); } return offset; } @@ -785,16 +810,16 @@ library StoreCoreInternal { } /** - * Get the length of the dynamic data for the given value schema and index + * Get the length of the dynamic data for the given value field layout and index */ function _loadEncodedDynamicDataLength(bytes32 tableId, bytes32[] memory key) internal view returns (PackedCounter) { // Load dynamic data length from storage - uint256 dynamicSchemaLengthSlot = _getDynamicDataLengthLocation(tableId, key); - return PackedCounter.wrap(Storage.load({ storagePointer: dynamicSchemaLengthSlot })); + uint256 dynamicDataLengthSlot = _getDynamicDataLengthLocation(tableId, key); + return PackedCounter.wrap(Storage.load({ storagePointer: dynamicDataLengthSlot })); } /** - * Set the length of the dynamic data (in bytes) for the given value schema and index + * Set the length of the dynamic data (in bytes) for the given value field layout and index */ function _setDynamicDataLengthAtIndex( bytes32 tableId, @@ -803,14 +828,14 @@ library StoreCoreInternal { uint256 newLengthAtIndex ) internal { // Load dynamic data length from storage - uint256 dynamicSchemaLengthSlot = _getDynamicDataLengthLocation(tableId, key); - PackedCounter encodedLengths = PackedCounter.wrap(Storage.load({ storagePointer: dynamicSchemaLengthSlot })); + uint256 dynamicDataLengthSlot = _getDynamicDataLengthLocation(tableId, key); + PackedCounter encodedLengths = PackedCounter.wrap(Storage.load({ storagePointer: dynamicDataLengthSlot })); // Update the encoded lengths encodedLengths = encodedLengths.setAtIndex(dynamicSchemaIndex, newLengthAtIndex); // Set the new lengths - Storage.store({ storagePointer: dynamicSchemaLengthSlot, data: encodedLengths.unwrap() }); + Storage.store({ storagePointer: dynamicDataLengthSlot, data: encodedLengths.unwrap() }); } /** diff --git a/packages/store/src/StoreRead.sol b/packages/store/src/StoreRead.sol index 7c6ffe0a30..83ca38b864 100644 --- a/packages/store/src/StoreRead.sol +++ b/packages/store/src/StoreRead.sol @@ -3,6 +3,7 @@ pragma solidity >=0.8.0; import { IStoreRead } from "./IStore.sol"; import { StoreCore } from "./StoreCore.sol"; +import { FieldLayout } from "./FieldLayout.sol"; import { Schema } from "./Schema.sol"; contract StoreRead is IStoreRead { @@ -10,6 +11,10 @@ contract StoreRead is IStoreRead { StoreCore.initialize(); } + function getFieldLayout(bytes32 table) public view virtual returns (FieldLayout fieldLayout) { + fieldLayout = StoreCore.getFieldLayout(table); + } + function getValueSchema(bytes32 table) public view virtual returns (Schema schema) { schema = StoreCore.getValueSchema(table); } @@ -22,9 +27,9 @@ contract StoreRead is IStoreRead { function getRecord( bytes32 table, bytes32[] calldata key, - Schema valueSchema + FieldLayout fieldLayout ) public view virtual returns (bytes memory data) { - data = StoreCore.getRecord(table, key, valueSchema); + data = StoreCore.getRecord(table, key, fieldLayout); } // Get partial data at schema index @@ -32,28 +37,28 @@ contract StoreRead is IStoreRead { bytes32 table, bytes32[] calldata key, uint8 schemaIndex, - Schema valueSchema + FieldLayout fieldLayout ) public view virtual returns (bytes memory data) { - data = StoreCore.getField(table, key, schemaIndex, valueSchema); + data = StoreCore.getField(table, key, schemaIndex, fieldLayout); } function getFieldLength( bytes32 tableId, bytes32[] memory key, uint8 schemaIndex, - Schema schema + FieldLayout fieldLayout ) public view virtual returns (uint256) { - return StoreCore.getFieldLength(tableId, key, schemaIndex, schema); + return StoreCore.getFieldLength(tableId, key, schemaIndex, fieldLayout); } function getFieldSlice( bytes32 tableId, bytes32[] memory key, uint8 schemaIndex, - Schema schema, + FieldLayout fieldLayout, uint256 start, uint256 end ) public view virtual returns (bytes memory) { - return StoreCore.getFieldSlice(tableId, key, schemaIndex, schema, start, end); + return StoreCore.getFieldSlice(tableId, key, schemaIndex, fieldLayout, start, end); } } diff --git a/packages/store/src/StoreReadWithStubs.sol b/packages/store/src/StoreReadWithStubs.sol index 32a03bbdea..71c55ccfca 100644 --- a/packages/store/src/StoreReadWithStubs.sol +++ b/packages/store/src/StoreReadWithStubs.sol @@ -3,6 +3,7 @@ pragma solidity >=0.8.0; import { IStore, IStoreHook } from "./IStore.sol"; import { StoreCore } from "./StoreCore.sol"; +import { FieldLayout } from "./FieldLayout.sol"; import { Schema } from "./Schema.sol"; import { StoreRead } from "./StoreRead.sol"; @@ -17,42 +18,42 @@ contract StoreReadWithStubs is IStore, StoreRead { /** * Not implemented in StoreReadWithStubs */ - function registerTable(bytes32, Schema, Schema, string[] calldata, string[] calldata) public virtual { + function registerTable(bytes32, FieldLayout, Schema, Schema, string[] calldata, string[] calldata) public virtual { revert StoreReadWithStubs_NotImplemented(); } /** * Not implemented in StoreReadWithStubs */ - function setRecord(bytes32, bytes32[] calldata, bytes calldata, Schema) public virtual { + function setRecord(bytes32, bytes32[] calldata, bytes calldata, FieldLayout) public virtual { revert StoreReadWithStubs_NotImplemented(); } /** * Not implemented in StoreReadWithStubs */ - function setField(bytes32, bytes32[] calldata, uint8, bytes calldata, Schema) public virtual { + function setField(bytes32, bytes32[] calldata, uint8, bytes calldata, FieldLayout) public virtual { revert StoreReadWithStubs_NotImplemented(); } /** * Not implemented in StoreReadWithStubs */ - function pushToField(bytes32, bytes32[] calldata, uint8, bytes calldata, Schema) public virtual { + function pushToField(bytes32, bytes32[] calldata, uint8, bytes calldata, FieldLayout) public virtual { revert StoreReadWithStubs_NotImplemented(); } /** * Not implemented in StoreReadWithStubs */ - function popFromField(bytes32, bytes32[] calldata, uint8, uint256, Schema) public virtual { + function popFromField(bytes32, bytes32[] calldata, uint8, uint256, FieldLayout) public virtual { revert StoreReadWithStubs_NotImplemented(); } /** * Not implemented in StoreReadWithStubs */ - function updateInField(bytes32, bytes32[] calldata, uint8, uint256, bytes calldata, Schema) public virtual { + function updateInField(bytes32, bytes32[] calldata, uint8, uint256, bytes calldata, FieldLayout) public virtual { revert StoreReadWithStubs_NotImplemented(); } @@ -73,14 +74,14 @@ contract StoreReadWithStubs is IStore, StoreRead { /** * Not implemented in StoreReadWithStubs */ - function deleteRecord(bytes32, bytes32[] calldata, Schema) public virtual { + function deleteRecord(bytes32, bytes32[] calldata, FieldLayout) public virtual { revert StoreReadWithStubs_NotImplemented(); } /** * Not implemented in StoreReadWithStubs */ - function emitEphemeralRecord(bytes32, bytes32[] calldata, bytes calldata, Schema) public virtual { + function emitEphemeralRecord(bytes32, bytes32[] calldata, bytes calldata, FieldLayout) public virtual { revert StoreReadWithStubs_NotImplemented(); } } diff --git a/packages/store/src/StoreSwitch.sol b/packages/store/src/StoreSwitch.sol index 28912a08ba..4182568096 100644 --- a/packages/store/src/StoreSwitch.sol +++ b/packages/store/src/StoreSwitch.sol @@ -5,6 +5,7 @@ import { IStore } from "./IStore.sol"; import { IStoreHook } from "./IStoreHook.sol"; import { StoreCore } from "./StoreCore.sol"; import { Schema } from "./Schema.sol"; +import { FieldLayout } from "./FieldLayout.sol"; /** * Call IStore functions on self or msg.sender, depending on whether the call is a delegatecall or regular call. @@ -63,6 +64,15 @@ library StoreSwitch { } } + function getFieldLayout(bytes32 table) internal view returns (FieldLayout fieldLayout) { + address _storeAddress = getStoreAddress(); + if (_storeAddress == address(this)) { + fieldLayout = StoreCore.getFieldLayout(table); + } else { + fieldLayout = IStore(_storeAddress).getFieldLayout(table); + } + } + function getValueSchema(bytes32 table) internal view returns (Schema valueSchema) { address _storeAddress = getStoreAddress(); if (_storeAddress == address(this)) { @@ -83,6 +93,7 @@ library StoreSwitch { function registerTable( bytes32 table, + FieldLayout fieldLayout, Schema keySchema, Schema valueSchema, string[] memory keyNames, @@ -90,18 +101,18 @@ library StoreSwitch { ) internal { address _storeAddress = getStoreAddress(); if (_storeAddress == address(this)) { - StoreCore.registerTable(table, keySchema, valueSchema, keyNames, fieldNames); + StoreCore.registerTable(table, fieldLayout, keySchema, valueSchema, keyNames, fieldNames); } else { - IStore(_storeAddress).registerTable(table, keySchema, valueSchema, keyNames, fieldNames); + IStore(_storeAddress).registerTable(table, fieldLayout, keySchema, valueSchema, keyNames, fieldNames); } } - function setRecord(bytes32 table, bytes32[] memory key, bytes memory data, Schema valueSchema) internal { + function setRecord(bytes32 table, bytes32[] memory key, bytes memory data, FieldLayout fieldLayout) internal { address _storeAddress = getStoreAddress(); if (_storeAddress == address(this)) { - StoreCore.setRecord(table, key, data, valueSchema); + StoreCore.setRecord(table, key, data, fieldLayout); } else { - IStore(_storeAddress).setRecord(table, key, data, valueSchema); + IStore(_storeAddress).setRecord(table, key, data, fieldLayout); } } @@ -110,13 +121,13 @@ library StoreSwitch { bytes32[] memory key, uint8 fieldIndex, bytes memory data, - Schema valueSchema + FieldLayout fieldLayout ) internal { address _storeAddress = getStoreAddress(); if (_storeAddress == address(this)) { - StoreCore.setField(table, key, fieldIndex, data, valueSchema); + StoreCore.setField(table, key, fieldIndex, data, fieldLayout); } else { - IStore(_storeAddress).setField(table, key, fieldIndex, data, valueSchema); + IStore(_storeAddress).setField(table, key, fieldIndex, data, fieldLayout); } } @@ -125,13 +136,13 @@ library StoreSwitch { bytes32[] memory key, uint8 fieldIndex, bytes memory dataToPush, - Schema valueSchema + FieldLayout fieldLayout ) internal { address _storeAddress = getStoreAddress(); if (_storeAddress == address(this)) { - StoreCore.pushToField(table, key, fieldIndex, dataToPush, valueSchema); + StoreCore.pushToField(table, key, fieldIndex, dataToPush, fieldLayout); } else { - IStore(_storeAddress).pushToField(table, key, fieldIndex, dataToPush, valueSchema); + IStore(_storeAddress).pushToField(table, key, fieldIndex, dataToPush, fieldLayout); } } @@ -140,13 +151,13 @@ library StoreSwitch { bytes32[] memory key, uint8 fieldIndex, uint256 byteLengthToPop, - Schema valueSchema + FieldLayout fieldLayout ) internal { address _storeAddress = getStoreAddress(); if (_storeAddress == address(this)) { - StoreCore.popFromField(table, key, fieldIndex, byteLengthToPop, valueSchema); + StoreCore.popFromField(table, key, fieldIndex, byteLengthToPop, fieldLayout); } else { - IStore(_storeAddress).popFromField(table, key, fieldIndex, byteLengthToPop, valueSchema); + IStore(_storeAddress).popFromField(table, key, fieldIndex, byteLengthToPop, fieldLayout); } } @@ -156,40 +167,49 @@ library StoreSwitch { uint8 fieldIndex, uint256 startByteIndex, bytes memory dataToSet, - Schema valueSchema + FieldLayout fieldLayout ) internal { address _storeAddress = getStoreAddress(); if (_storeAddress == address(this)) { - StoreCore.updateInField(table, key, fieldIndex, startByteIndex, dataToSet, valueSchema); + StoreCore.updateInField(table, key, fieldIndex, startByteIndex, dataToSet, fieldLayout); } else { - IStore(_storeAddress).updateInField(table, key, fieldIndex, startByteIndex, dataToSet, valueSchema); + IStore(_storeAddress).updateInField(table, key, fieldIndex, startByteIndex, dataToSet, fieldLayout); } } - function deleteRecord(bytes32 table, bytes32[] memory key, Schema valueSchema) internal { + function deleteRecord(bytes32 table, bytes32[] memory key, FieldLayout fieldLayout) internal { address _storeAddress = getStoreAddress(); if (_storeAddress == address(this)) { - StoreCore.deleteRecord(table, key, valueSchema); + StoreCore.deleteRecord(table, key, fieldLayout); } else { - IStore(_storeAddress).deleteRecord(table, key, valueSchema); + IStore(_storeAddress).deleteRecord(table, key, fieldLayout); } } - function emitEphemeralRecord(bytes32 table, bytes32[] memory key, bytes memory data, Schema valueSchema) internal { + function emitEphemeralRecord( + bytes32 table, + bytes32[] memory key, + bytes memory data, + FieldLayout fieldLayout + ) internal { address _storeAddress = getStoreAddress(); if (_storeAddress == address(this)) { - StoreCore.emitEphemeralRecord(table, key, data, valueSchema); + StoreCore.emitEphemeralRecord(table, key, data, fieldLayout); } else { - IStore(_storeAddress).emitEphemeralRecord(table, key, data, valueSchema); + IStore(_storeAddress).emitEphemeralRecord(table, key, data, fieldLayout); } } - function getRecord(bytes32 table, bytes32[] memory key, Schema valueSchema) internal view returns (bytes memory) { + function getRecord( + bytes32 table, + bytes32[] memory key, + FieldLayout fieldLayout + ) internal view returns (bytes memory) { address _storeAddress = getStoreAddress(); if (_storeAddress == address(this)) { - return StoreCore.getRecord(table, key, valueSchema); + return StoreCore.getRecord(table, key, fieldLayout); } else { - return IStore(_storeAddress).getRecord(table, key, valueSchema); + return IStore(_storeAddress).getRecord(table, key, fieldLayout); } } @@ -197,13 +217,13 @@ library StoreSwitch { bytes32 table, bytes32[] memory key, uint8 fieldIndex, - Schema valueSchema + FieldLayout fieldLayout ) internal view returns (bytes memory) { address _storeAddress = getStoreAddress(); if (_storeAddress == address(this)) { - return StoreCore.getField(table, key, fieldIndex, valueSchema); + return StoreCore.getField(table, key, fieldIndex, fieldLayout); } else { - return IStore(_storeAddress).getField(table, key, fieldIndex, valueSchema); + return IStore(_storeAddress).getField(table, key, fieldIndex, fieldLayout); } } @@ -211,13 +231,13 @@ library StoreSwitch { bytes32 table, bytes32[] memory key, uint8 fieldIndex, - Schema schema + FieldLayout fieldLayout ) internal view returns (uint256) { address _storeAddress = getStoreAddress(); if (_storeAddress == address(this)) { - return StoreCore.getFieldLength(table, key, fieldIndex, schema); + return StoreCore.getFieldLength(table, key, fieldIndex, fieldLayout); } else { - return IStore(_storeAddress).getFieldLength(table, key, fieldIndex, schema); + return IStore(_storeAddress).getFieldLength(table, key, fieldIndex, fieldLayout); } } @@ -225,15 +245,15 @@ library StoreSwitch { bytes32 table, bytes32[] memory key, uint8 fieldIndex, - Schema schema, + FieldLayout fieldLayout, uint256 start, uint256 end ) internal view returns (bytes memory) { address _storeAddress = getStoreAddress(); if (_storeAddress == address(this)) { - return StoreCore.getFieldSlice(table, key, fieldIndex, schema, start, end); + return StoreCore.getFieldSlice(table, key, fieldIndex, fieldLayout, start, end); } else { - return IStore(_storeAddress).getFieldSlice(table, key, fieldIndex, schema, start, end); + return IStore(_storeAddress).getFieldSlice(table, key, fieldIndex, fieldLayout, start, end); } } } diff --git a/packages/store/src/codegen/tables/Callbacks.sol b/packages/store/src/codegen/tables/Callbacks.sol index 812cab754c..f43519c60d 100644 --- a/packages/store/src/codegen/tables/Callbacks.sol +++ b/packages/store/src/codegen/tables/Callbacks.sol @@ -14,6 +14,7 @@ import { Bytes } from "../../Bytes.sol"; import { Memory } from "../../Memory.sol"; import { SliceLib } from "../../Slice.sol"; import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "../../FieldLayout.sol"; import { Schema, SchemaLib } from "../../Schema.sol"; import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; @@ -21,6 +22,13 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16("mudstore"), bytes1 bytes32 constant CallbacksTableId = _tableId; library Callbacks { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](0); + + return FieldLayoutLib.encode(_fieldLayout, 1); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -49,14 +57,21 @@ library Callbacks { fieldNames[0] = "value"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get value */ @@ -64,7 +79,7 @@ library Callbacks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes24()); } @@ -73,7 +88,7 @@ library Callbacks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes24()); } @@ -82,7 +97,7 @@ library Callbacks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getFieldLayout()); } /** Set value (using the specified store) */ @@ -90,7 +105,7 @@ library Callbacks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getFieldLayout()); } /** Get the length of value */ @@ -98,7 +113,7 @@ library Callbacks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 24; } @@ -109,7 +124,7 @@ library Callbacks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 24; } @@ -128,7 +143,7 @@ library Callbacks { _tableId, _keyTuple, 0, - getValueSchema(), + getFieldLayout(), _index * 24, (_index + 1) * 24 ); @@ -149,7 +164,7 @@ library Callbacks { _tableId, _keyTuple, 0, - getValueSchema(), + getFieldLayout(), _index * 24, (_index + 1) * 24 ); @@ -162,7 +177,7 @@ library Callbacks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to value (using the specified store) */ @@ -170,7 +185,7 @@ library Callbacks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from value */ @@ -178,7 +193,7 @@ library Callbacks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.popFromField(_tableId, _keyTuple, 0, 24, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 24, getFieldLayout()); } /** Pop an element from value (using the specified store) */ @@ -186,7 +201,7 @@ library Callbacks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.popFromField(_tableId, _keyTuple, 0, 24, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 0, 24, getFieldLayout()); } /** @@ -198,7 +213,7 @@ library Callbacks { _keyTuple[0] = key; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 24, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 24, abi.encodePacked((_element)), getFieldLayout()); } } @@ -211,11 +226,11 @@ library Callbacks { _keyTuple[0] = key; unchecked { - _store.updateInField(_tableId, _keyTuple, 0, _index * 24, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 0, _index * 24, abi.encodePacked((_element)), getFieldLayout()); } } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(bytes24[] memory value) internal pure returns (bytes memory) { PackedCounter _encodedLengths; // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits @@ -226,7 +241,7 @@ library Callbacks { return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode((value))); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes32 key) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; @@ -239,7 +254,7 @@ library Callbacks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -247,6 +262,6 @@ library Callbacks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/store/src/codegen/tables/Hooks.sol b/packages/store/src/codegen/tables/Hooks.sol index ae4d488386..8fca4a03b7 100644 --- a/packages/store/src/codegen/tables/Hooks.sol +++ b/packages/store/src/codegen/tables/Hooks.sol @@ -14,10 +14,18 @@ import { Bytes } from "../../Bytes.sol"; import { Memory } from "../../Memory.sol"; import { SliceLib } from "../../Slice.sol"; import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "../../FieldLayout.sol"; import { Schema, SchemaLib } from "../../Schema.sol"; import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; library Hooks { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](0); + + return FieldLayoutLib.encode(_fieldLayout, 1); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -46,14 +54,21 @@ library Hooks { fieldNames[0] = "value"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register(bytes32 _tableId) internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store, bytes32 _tableId) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get value */ @@ -61,7 +76,7 @@ library Hooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } @@ -70,7 +85,7 @@ library Hooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } @@ -79,7 +94,7 @@ library Hooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getFieldLayout()); } /** Set value (using the specified store) */ @@ -87,7 +102,7 @@ library Hooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getFieldLayout()); } /** Get the length of value */ @@ -95,7 +110,7 @@ library Hooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 21; } @@ -106,7 +121,7 @@ library Hooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 21; } @@ -125,7 +140,7 @@ library Hooks { _tableId, _keyTuple, 0, - getValueSchema(), + getFieldLayout(), _index * 21, (_index + 1) * 21 ); @@ -146,7 +161,7 @@ library Hooks { _tableId, _keyTuple, 0, - getValueSchema(), + getFieldLayout(), _index * 21, (_index + 1) * 21 ); @@ -159,7 +174,7 @@ library Hooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to value (using the specified store) */ @@ -167,7 +182,7 @@ library Hooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from value */ @@ -175,7 +190,7 @@ library Hooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.popFromField(_tableId, _keyTuple, 0, 21, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 21, getFieldLayout()); } /** Pop an element from value (using the specified store) */ @@ -183,7 +198,7 @@ library Hooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.popFromField(_tableId, _keyTuple, 0, 21, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 0, 21, getFieldLayout()); } /** @@ -195,7 +210,7 @@ library Hooks { _keyTuple[0] = key; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), getFieldLayout()); } } @@ -208,11 +223,11 @@ library Hooks { _keyTuple[0] = key; unchecked { - _store.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), getFieldLayout()); } } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(bytes21[] memory value) internal pure returns (bytes memory) { PackedCounter _encodedLengths; // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits @@ -223,7 +238,7 @@ library Hooks { return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode((value))); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes32 key) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; @@ -236,7 +251,7 @@ library Hooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -244,6 +259,6 @@ library Hooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/store/src/codegen/tables/KeyEncoding.sol b/packages/store/src/codegen/tables/KeyEncoding.sol index a0fb759651..43d4ca2cce 100644 --- a/packages/store/src/codegen/tables/KeyEncoding.sol +++ b/packages/store/src/codegen/tables/KeyEncoding.sol @@ -14,6 +14,7 @@ import { Bytes } from "../../Bytes.sol"; import { Memory } from "../../Memory.sol"; import { SliceLib } from "../../Slice.sol"; import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "../../FieldLayout.sol"; import { Schema, SchemaLib } from "../../Schema.sol"; import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; @@ -24,6 +25,14 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16("mudstore"), bytes1 bytes32 constant KeyEncodingTableId = _tableId; library KeyEncoding { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 1; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](6); @@ -62,14 +71,21 @@ library KeyEncoding { fieldNames[0] = "value"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get value */ @@ -89,7 +105,7 @@ library KeyEncoding { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -111,7 +127,7 @@ library KeyEncoding { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -125,7 +141,7 @@ library KeyEncoding { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getFieldLayout()); } /** Set value (using the specified store) */ @@ -147,15 +163,15 @@ library KeyEncoding { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(bool value) internal pure returns (bytes memory) { return abi.encodePacked(value); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple( uint256 k1, int32 k2, @@ -185,7 +201,7 @@ library KeyEncoding { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -198,7 +214,7 @@ library KeyEncoding { _keyTuple[4] = _boolToBytes32(k5); _keyTuple[5] = bytes32(uint256(uint8(k6))); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/store/src/codegen/tables/Mixed.sol b/packages/store/src/codegen/tables/Mixed.sol index 2f80eb45e2..bba29cecd6 100644 --- a/packages/store/src/codegen/tables/Mixed.sol +++ b/packages/store/src/codegen/tables/Mixed.sol @@ -14,6 +14,7 @@ import { Bytes } from "../../Bytes.sol"; import { Memory } from "../../Memory.sol"; import { SliceLib } from "../../Slice.sol"; import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "../../FieldLayout.sol"; import { Schema, SchemaLib } from "../../Schema.sol"; import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; @@ -28,6 +29,15 @@ struct MixedData { } library Mixed { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](2); + _fieldLayout[0] = 4; + _fieldLayout[1] = 16; + + return FieldLayoutLib.encode(_fieldLayout, 2); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -62,14 +72,21 @@ library Mixed { fieldNames[3] = "s"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get u32 */ @@ -77,7 +94,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint32(Bytes.slice4(_blob, 0))); } @@ -86,7 +103,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint32(Bytes.slice4(_blob, 0))); } @@ -95,7 +112,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((u32)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((u32)), getFieldLayout()); } /** Set u32 (using the specified store) */ @@ -103,7 +120,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((u32)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((u32)), getFieldLayout()); } /** Get u128 */ @@ -111,7 +128,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (uint128(Bytes.slice16(_blob, 0))); } @@ -120,7 +137,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (uint128(Bytes.slice16(_blob, 0))); } @@ -129,7 +146,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((u128)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((u128)), getFieldLayout()); } /** Set u128 (using the specified store) */ @@ -137,7 +154,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((u128)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((u128)), getFieldLayout()); } /** Get a32 */ @@ -145,7 +162,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -154,7 +171,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } @@ -163,7 +180,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setField(_tableId, _keyTuple, 2, EncodeArray.encode((a32)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 2, EncodeArray.encode((a32)), getFieldLayout()); } /** Set a32 (using the specified store) */ @@ -171,7 +188,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 2, EncodeArray.encode((a32)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 2, EncodeArray.encode((a32)), getFieldLayout()); } /** Get the length of a32 */ @@ -179,7 +196,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 2, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 2, getFieldLayout()); unchecked { return _byteLength / 4; } @@ -190,7 +207,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 2, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 2, getFieldLayout()); unchecked { return _byteLength / 4; } @@ -209,7 +226,7 @@ library Mixed { _tableId, _keyTuple, 2, - getValueSchema(), + getFieldLayout(), _index * 4, (_index + 1) * 4 ); @@ -226,7 +243,7 @@ library Mixed { _keyTuple[0] = key; unchecked { - bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 2, getValueSchema(), _index * 4, (_index + 1) * 4); + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 2, getFieldLayout(), _index * 4, (_index + 1) * 4); return (uint32(Bytes.slice4(_blob, 0))); } } @@ -236,7 +253,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to a32 (using the specified store) */ @@ -244,7 +261,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from a32 */ @@ -252,7 +269,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.popFromField(_tableId, _keyTuple, 2, 4, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 2, 4, getFieldLayout()); } /** Pop an element from a32 (using the specified store) */ @@ -260,7 +277,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.popFromField(_tableId, _keyTuple, 2, 4, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 2, 4, getFieldLayout()); } /** @@ -272,7 +289,7 @@ library Mixed { _keyTuple[0] = key; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 2, _index * 4, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 2, _index * 4, abi.encodePacked((_element)), getFieldLayout()); } } @@ -285,7 +302,7 @@ library Mixed { _keyTuple[0] = key; unchecked { - _store.updateInField(_tableId, _keyTuple, 2, _index * 4, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 2, _index * 4, abi.encodePacked((_element)), getFieldLayout()); } } @@ -294,7 +311,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3, getFieldLayout()); return (string(_blob)); } @@ -303,7 +320,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 3, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 3, getFieldLayout()); return (string(_blob)); } @@ -312,7 +329,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setField(_tableId, _keyTuple, 3, bytes((s)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 3, bytes((s)), getFieldLayout()); } /** Set s (using the specified store) */ @@ -320,7 +337,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 3, bytes((s)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 3, bytes((s)), getFieldLayout()); } /** Get the length of s */ @@ -328,7 +345,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 3, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 3, getFieldLayout()); unchecked { return _byteLength / 1; } @@ -339,7 +356,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 3, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 3, getFieldLayout()); unchecked { return _byteLength / 1; } @@ -358,7 +375,7 @@ library Mixed { _tableId, _keyTuple, 3, - getValueSchema(), + getFieldLayout(), _index * 1, (_index + 1) * 1 ); @@ -375,7 +392,7 @@ library Mixed { _keyTuple[0] = key; unchecked { - bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 3, getValueSchema(), _index * 1, (_index + 1) * 1); + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 3, getFieldLayout(), _index * 1, (_index + 1) * 1); return (string(_blob)); } } @@ -385,7 +402,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.pushToField(_tableId, _keyTuple, 3, bytes((_slice)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 3, bytes((_slice)), getFieldLayout()); } /** Push a slice to s (using the specified store) */ @@ -393,7 +410,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.pushToField(_tableId, _keyTuple, 3, bytes((_slice)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 3, bytes((_slice)), getFieldLayout()); } /** Pop a slice from s */ @@ -401,7 +418,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.popFromField(_tableId, _keyTuple, 3, 1, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 3, 1, getFieldLayout()); } /** Pop a slice from s (using the specified store) */ @@ -409,7 +426,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.popFromField(_tableId, _keyTuple, 3, 1, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 3, 1, getFieldLayout()); } /** @@ -421,7 +438,7 @@ library Mixed { _keyTuple[0] = key; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 3, _index * 1, bytes((_slice)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 3, _index * 1, bytes((_slice)), getFieldLayout()); } } @@ -434,7 +451,7 @@ library Mixed { _keyTuple[0] = key; unchecked { - _store.updateInField(_tableId, _keyTuple, 3, _index * 1, bytes((_slice)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 3, _index * 1, bytes((_slice)), getFieldLayout()); } } @@ -443,7 +460,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -452,7 +469,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -463,7 +480,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using individual values (using the specified store) */ @@ -473,7 +490,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + _store.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using the data struct */ @@ -487,7 +504,7 @@ library Mixed { } /** - * Decode the tightly packed blob using this table's schema. + * Decode the tightly packed blob using this table's field layout. * Undefined behaviour for invalid blobs. */ function decode(bytes memory _blob) internal pure returns (MixedData memory _table) { @@ -516,7 +533,7 @@ library Mixed { } } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(uint32 u32, uint128 u128, uint32[] memory a32, string memory s) internal pure returns (bytes memory) { PackedCounter _encodedLengths; // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits @@ -527,7 +544,7 @@ library Mixed { return abi.encodePacked(u32, u128, _encodedLengths.unwrap(), EncodeArray.encode((a32)), bytes((s))); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes32 key) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; @@ -540,7 +557,7 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -548,6 +565,6 @@ library Mixed { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/store/src/codegen/tables/StoreHooks.sol b/packages/store/src/codegen/tables/StoreHooks.sol index 9998edbfd4..2168293bce 100644 --- a/packages/store/src/codegen/tables/StoreHooks.sol +++ b/packages/store/src/codegen/tables/StoreHooks.sol @@ -14,6 +14,7 @@ import { Bytes } from "../../Bytes.sol"; import { Memory } from "../../Memory.sol"; import { SliceLib } from "../../Slice.sol"; import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "../../FieldLayout.sol"; import { Schema, SchemaLib } from "../../Schema.sol"; import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; @@ -21,6 +22,13 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16("mudstore"), bytes1 bytes32 constant StoreHooksTableId = _tableId; library StoreHooks { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](0); + + return FieldLayoutLib.encode(_fieldLayout, 1); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -49,14 +57,21 @@ library StoreHooks { fieldNames[0] = "value"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get value */ @@ -64,7 +79,7 @@ library StoreHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } @@ -73,7 +88,7 @@ library StoreHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } @@ -82,7 +97,7 @@ library StoreHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getFieldLayout()); } /** Set value (using the specified store) */ @@ -90,7 +105,7 @@ library StoreHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getFieldLayout()); } /** Get the length of value */ @@ -98,7 +113,7 @@ library StoreHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 21; } @@ -109,7 +124,7 @@ library StoreHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 21; } @@ -128,7 +143,7 @@ library StoreHooks { _tableId, _keyTuple, 0, - getValueSchema(), + getFieldLayout(), _index * 21, (_index + 1) * 21 ); @@ -149,7 +164,7 @@ library StoreHooks { _tableId, _keyTuple, 0, - getValueSchema(), + getFieldLayout(), _index * 21, (_index + 1) * 21 ); @@ -162,7 +177,7 @@ library StoreHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to value (using the specified store) */ @@ -170,7 +185,7 @@ library StoreHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from value */ @@ -178,7 +193,7 @@ library StoreHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.popFromField(_tableId, _keyTuple, 0, 21, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 21, getFieldLayout()); } /** Pop an element from value (using the specified store) */ @@ -186,7 +201,7 @@ library StoreHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.popFromField(_tableId, _keyTuple, 0, 21, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 0, 21, getFieldLayout()); } /** @@ -198,7 +213,7 @@ library StoreHooks { _keyTuple[0] = key; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), getFieldLayout()); } } @@ -211,11 +226,11 @@ library StoreHooks { _keyTuple[0] = key; unchecked { - _store.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), getFieldLayout()); } } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(bytes21[] memory value) internal pure returns (bytes memory) { PackedCounter _encodedLengths; // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits @@ -226,7 +241,7 @@ library StoreHooks { return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode((value))); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes32 key) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; @@ -239,7 +254,7 @@ library StoreHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -247,6 +262,6 @@ library StoreHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/store/src/codegen/tables/Tables.sol b/packages/store/src/codegen/tables/Tables.sol index b032e66434..535a57a44f 100644 --- a/packages/store/src/codegen/tables/Tables.sol +++ b/packages/store/src/codegen/tables/Tables.sol @@ -14,6 +14,7 @@ import { Bytes } from "../../Bytes.sol"; import { Memory } from "../../Memory.sol"; import { SliceLib } from "../../Slice.sol"; import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "../../FieldLayout.sol"; import { Schema, SchemaLib } from "../../Schema.sol"; import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; @@ -21,6 +22,7 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16("mudstore"), bytes1 bytes32 constant TablesTableId = _tableId; struct TablesData { + bytes32 fieldLayout; bytes32 keySchema; bytes32 valueSchema; bytes abiEncodedKeyNames; @@ -28,6 +30,16 @@ struct TablesData { } library Tables { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](3); + _fieldLayout[0] = 32; + _fieldLayout[1] = 32; + _fieldLayout[2] = 32; + + return FieldLayoutLib.encode(_fieldLayout, 2); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -38,11 +50,12 @@ library Tables { /** Get the table's value schema */ function getValueSchema() internal pure returns (Schema) { - SchemaType[] memory _schema = new SchemaType[](4); + SchemaType[] memory _schema = new SchemaType[](5); _schema[0] = SchemaType.BYTES32; _schema[1] = SchemaType.BYTES32; - _schema[2] = SchemaType.BYTES; + _schema[2] = SchemaType.BYTES32; _schema[3] = SchemaType.BYTES; + _schema[4] = SchemaType.BYTES; return SchemaLib.encode(_schema); } @@ -55,21 +68,63 @@ library Tables { /** Get the table's field names */ function getFieldNames() internal pure returns (string[] memory fieldNames) { - fieldNames = new string[](4); - fieldNames[0] = "keySchema"; - fieldNames[1] = "valueSchema"; - fieldNames[2] = "abiEncodedKeyNames"; - fieldNames[3] = "abiEncodedFieldNames"; + fieldNames = new string[](5); + fieldNames[0] = "fieldLayout"; + fieldNames[1] = "keySchema"; + fieldNames[2] = "valueSchema"; + fieldNames[3] = "abiEncodedKeyNames"; + fieldNames[4] = "abiEncodedFieldNames"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + } + + /** Get fieldLayout */ + function getFieldLayout(bytes32 tableId) internal view returns (bytes32 fieldLayout) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = tableId; + + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); + return (Bytes.slice32(_blob, 0)); + } + + /** Get fieldLayout (using the specified store) */ + function getFieldLayout(IStore _store, bytes32 tableId) internal view returns (bytes32 fieldLayout) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = tableId; + + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); + return (Bytes.slice32(_blob, 0)); + } + + /** Set fieldLayout */ + function setFieldLayout(bytes32 tableId, bytes32 fieldLayout) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = tableId; + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((fieldLayout)), getFieldLayout()); + } + + /** Set fieldLayout (using the specified store) */ + function setFieldLayout(IStore _store, bytes32 tableId, bytes32 fieldLayout) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = tableId; + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((fieldLayout)), getFieldLayout()); } /** Get keySchema */ @@ -77,7 +132,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (Bytes.slice32(_blob, 0)); } @@ -86,7 +141,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (Bytes.slice32(_blob, 0)); } @@ -95,7 +150,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((keySchema)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((keySchema)), getFieldLayout()); } /** Set keySchema (using the specified store) */ @@ -103,7 +158,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((keySchema)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((keySchema)), getFieldLayout()); } /** Get valueSchema */ @@ -111,7 +166,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, getFieldLayout()); return (Bytes.slice32(_blob, 0)); } @@ -120,7 +175,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, getFieldLayout()); return (Bytes.slice32(_blob, 0)); } @@ -129,7 +184,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((valueSchema)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 2, abi.encodePacked((valueSchema)), getFieldLayout()); } /** Set valueSchema (using the specified store) */ @@ -137,7 +192,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((valueSchema)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 2, abi.encodePacked((valueSchema)), getFieldLayout()); } /** Get abiEncodedKeyNames */ @@ -145,7 +200,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3, getFieldLayout()); return (bytes(_blob)); } @@ -157,7 +212,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 3, getFieldLayout()); return (bytes(_blob)); } @@ -166,7 +221,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - StoreSwitch.setField(_tableId, _keyTuple, 2, bytes((abiEncodedKeyNames)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 3, bytes((abiEncodedKeyNames)), getFieldLayout()); } /** Set abiEncodedKeyNames (using the specified store) */ @@ -174,7 +229,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - _store.setField(_tableId, _keyTuple, 2, bytes((abiEncodedKeyNames)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 3, bytes((abiEncodedKeyNames)), getFieldLayout()); } /** Get the length of abiEncodedKeyNames */ @@ -182,7 +237,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 2, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 3, getFieldLayout()); unchecked { return _byteLength / 1; } @@ -193,7 +248,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 2, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 3, getFieldLayout()); unchecked { return _byteLength / 1; } @@ -211,8 +266,8 @@ library Tables { bytes memory _blob = StoreSwitch.getFieldSlice( _tableId, _keyTuple, - 2, - getValueSchema(), + 3, + getFieldLayout(), _index * 1, (_index + 1) * 1 ); @@ -233,7 +288,7 @@ library Tables { _keyTuple[0] = tableId; unchecked { - bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 2, getValueSchema(), _index * 1, (_index + 1) * 1); + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 3, getFieldLayout(), _index * 1, (_index + 1) * 1); return (bytes(_blob)); } } @@ -243,7 +298,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - StoreSwitch.pushToField(_tableId, _keyTuple, 2, bytes((_slice)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 3, bytes((_slice)), getFieldLayout()); } /** Push a slice to abiEncodedKeyNames (using the specified store) */ @@ -251,7 +306,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - _store.pushToField(_tableId, _keyTuple, 2, bytes((_slice)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 3, bytes((_slice)), getFieldLayout()); } /** Pop a slice from abiEncodedKeyNames */ @@ -259,7 +314,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - StoreSwitch.popFromField(_tableId, _keyTuple, 2, 1, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 3, 1, getFieldLayout()); } /** Pop a slice from abiEncodedKeyNames (using the specified store) */ @@ -267,7 +322,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - _store.popFromField(_tableId, _keyTuple, 2, 1, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 3, 1, getFieldLayout()); } /** @@ -279,7 +334,7 @@ library Tables { _keyTuple[0] = tableId; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 2, _index * 1, bytes((_slice)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 3, _index * 1, bytes((_slice)), getFieldLayout()); } } @@ -292,7 +347,7 @@ library Tables { _keyTuple[0] = tableId; unchecked { - _store.updateInField(_tableId, _keyTuple, 2, _index * 1, bytes((_slice)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 3, _index * 1, bytes((_slice)), getFieldLayout()); } } @@ -301,7 +356,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 4, getFieldLayout()); return (bytes(_blob)); } @@ -313,7 +368,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 3, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 4, getFieldLayout()); return (bytes(_blob)); } @@ -322,7 +377,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - StoreSwitch.setField(_tableId, _keyTuple, 3, bytes((abiEncodedFieldNames)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 4, bytes((abiEncodedFieldNames)), getFieldLayout()); } /** Set abiEncodedFieldNames (using the specified store) */ @@ -330,7 +385,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - _store.setField(_tableId, _keyTuple, 3, bytes((abiEncodedFieldNames)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 4, bytes((abiEncodedFieldNames)), getFieldLayout()); } /** Get the length of abiEncodedFieldNames */ @@ -338,7 +393,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 3, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 4, getFieldLayout()); unchecked { return _byteLength / 1; } @@ -349,7 +404,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 3, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 4, getFieldLayout()); unchecked { return _byteLength / 1; } @@ -367,8 +422,8 @@ library Tables { bytes memory _blob = StoreSwitch.getFieldSlice( _tableId, _keyTuple, - 3, - getValueSchema(), + 4, + getFieldLayout(), _index * 1, (_index + 1) * 1 ); @@ -389,7 +444,7 @@ library Tables { _keyTuple[0] = tableId; unchecked { - bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 3, getValueSchema(), _index * 1, (_index + 1) * 1); + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 4, getFieldLayout(), _index * 1, (_index + 1) * 1); return (bytes(_blob)); } } @@ -399,7 +454,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - StoreSwitch.pushToField(_tableId, _keyTuple, 3, bytes((_slice)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 4, bytes((_slice)), getFieldLayout()); } /** Push a slice to abiEncodedFieldNames (using the specified store) */ @@ -407,7 +462,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - _store.pushToField(_tableId, _keyTuple, 3, bytes((_slice)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 4, bytes((_slice)), getFieldLayout()); } /** Pop a slice from abiEncodedFieldNames */ @@ -415,7 +470,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - StoreSwitch.popFromField(_tableId, _keyTuple, 3, 1, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 4, 1, getFieldLayout()); } /** Pop a slice from abiEncodedFieldNames (using the specified store) */ @@ -423,7 +478,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - _store.popFromField(_tableId, _keyTuple, 3, 1, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 4, 1, getFieldLayout()); } /** @@ -435,7 +490,7 @@ library Tables { _keyTuple[0] = tableId; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 3, _index * 1, bytes((_slice)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 4, _index * 1, bytes((_slice)), getFieldLayout()); } } @@ -448,7 +503,7 @@ library Tables { _keyTuple[0] = tableId; unchecked { - _store.updateInField(_tableId, _keyTuple, 3, _index * 1, bytes((_slice)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 4, _index * 1, bytes((_slice)), getFieldLayout()); } } @@ -457,7 +512,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -466,72 +521,91 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } /** Set the full data using individual values */ function set( bytes32 tableId, + bytes32 fieldLayout, bytes32 keySchema, bytes32 valueSchema, bytes memory abiEncodedKeyNames, bytes memory abiEncodedFieldNames ) internal { - bytes memory _data = encode(keySchema, valueSchema, abiEncodedKeyNames, abiEncodedFieldNames); + bytes memory _data = encode(fieldLayout, keySchema, valueSchema, abiEncodedKeyNames, abiEncodedFieldNames); bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - StoreSwitch.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using individual values (using the specified store) */ function set( IStore _store, bytes32 tableId, + bytes32 fieldLayout, bytes32 keySchema, bytes32 valueSchema, bytes memory abiEncodedKeyNames, bytes memory abiEncodedFieldNames ) internal { - bytes memory _data = encode(keySchema, valueSchema, abiEncodedKeyNames, abiEncodedFieldNames); + bytes memory _data = encode(fieldLayout, keySchema, valueSchema, abiEncodedKeyNames, abiEncodedFieldNames); bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - _store.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + _store.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using the data struct */ function set(bytes32 tableId, TablesData memory _table) internal { - set(tableId, _table.keySchema, _table.valueSchema, _table.abiEncodedKeyNames, _table.abiEncodedFieldNames); + set( + tableId, + _table.fieldLayout, + _table.keySchema, + _table.valueSchema, + _table.abiEncodedKeyNames, + _table.abiEncodedFieldNames + ); } /** Set the full data using the data struct (using the specified store) */ function set(IStore _store, bytes32 tableId, TablesData memory _table) internal { - set(_store, tableId, _table.keySchema, _table.valueSchema, _table.abiEncodedKeyNames, _table.abiEncodedFieldNames); + set( + _store, + tableId, + _table.fieldLayout, + _table.keySchema, + _table.valueSchema, + _table.abiEncodedKeyNames, + _table.abiEncodedFieldNames + ); } /** - * Decode the tightly packed blob using this table's schema. + * Decode the tightly packed blob using this table's field layout. * Undefined behaviour for invalid blobs. */ function decode(bytes memory _blob) internal pure returns (TablesData memory _table) { - // 64 is the total byte length of static data - PackedCounter _encodedLengths = PackedCounter.wrap(Bytes.slice32(_blob, 64)); + // 96 is the total byte length of static data + PackedCounter _encodedLengths = PackedCounter.wrap(Bytes.slice32(_blob, 96)); + + _table.fieldLayout = (Bytes.slice32(_blob, 0)); - _table.keySchema = (Bytes.slice32(_blob, 0)); + _table.keySchema = (Bytes.slice32(_blob, 32)); - _table.valueSchema = (Bytes.slice32(_blob, 32)); + _table.valueSchema = (Bytes.slice32(_blob, 64)); // Store trims the blob if dynamic fields are all empty - if (_blob.length > 64) { + if (_blob.length > 96) { // skip static data length + dynamic lengths word - uint256 _start = 96; + uint256 _start = 128; uint256 _end; unchecked { - _end = 96 + _encodedLengths.atIndex(0); + _end = 128 + _encodedLengths.atIndex(0); } _table.abiEncodedKeyNames = (bytes(SliceLib.getSubslice(_blob, _start, _end).toBytes())); @@ -543,8 +617,9 @@ library Tables { } } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode( + bytes32 fieldLayout, bytes32 keySchema, bytes32 valueSchema, bytes memory abiEncodedKeyNames, @@ -558,6 +633,7 @@ library Tables { return abi.encodePacked( + fieldLayout, keySchema, valueSchema, _encodedLengths.unwrap(), @@ -566,7 +642,7 @@ library Tables { ); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes32 tableId) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; @@ -579,7 +655,7 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -587,6 +663,6 @@ library Tables { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = tableId; - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/store/src/codegen/tables/Vector2.sol b/packages/store/src/codegen/tables/Vector2.sol index e46e40fe0c..518695ee86 100644 --- a/packages/store/src/codegen/tables/Vector2.sol +++ b/packages/store/src/codegen/tables/Vector2.sol @@ -14,6 +14,7 @@ import { Bytes } from "../../Bytes.sol"; import { Memory } from "../../Memory.sol"; import { SliceLib } from "../../Slice.sol"; import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "../../FieldLayout.sol"; import { Schema, SchemaLib } from "../../Schema.sol"; import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; @@ -26,6 +27,15 @@ struct Vector2Data { } library Vector2 { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](2); + _fieldLayout[0] = 4; + _fieldLayout[1] = 4; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -56,14 +66,21 @@ library Vector2 { fieldNames[1] = "y"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get x */ @@ -71,7 +88,7 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint32(Bytes.slice4(_blob, 0))); } @@ -80,7 +97,7 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint32(Bytes.slice4(_blob, 0))); } @@ -89,7 +106,7 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((x)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((x)), getFieldLayout()); } /** Set x (using the specified store) */ @@ -97,7 +114,7 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((x)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((x)), getFieldLayout()); } /** Get y */ @@ -105,7 +122,7 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (uint32(Bytes.slice4(_blob, 0))); } @@ -114,7 +131,7 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (uint32(Bytes.slice4(_blob, 0))); } @@ -123,7 +140,7 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((y)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((y)), getFieldLayout()); } /** Set y (using the specified store) */ @@ -131,7 +148,7 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((y)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((y)), getFieldLayout()); } /** Get the full data */ @@ -139,7 +156,7 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -148,7 +165,7 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -159,7 +176,7 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using individual values (using the specified store) */ @@ -169,7 +186,7 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + _store.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using the data struct */ @@ -182,19 +199,19 @@ library Vector2 { set(_store, key, _table.x, _table.y); } - /** Decode the tightly packed blob using this table's schema */ + /** Decode the tightly packed blob using this table's field layout */ function decode(bytes memory _blob) internal pure returns (Vector2Data memory _table) { _table.x = (uint32(Bytes.slice4(_blob, 0))); _table.y = (uint32(Bytes.slice4(_blob, 4))); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(uint32 x, uint32 y) internal pure returns (bytes memory) { return abi.encodePacked(x, y); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes32 key) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; @@ -207,7 +224,7 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -215,6 +232,6 @@ library Vector2 { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/store/src/constants.sol b/packages/store/src/constants.sol new file mode 100644 index 0000000000..a5f580b6ec --- /dev/null +++ b/packages/store/src/constants.sol @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Shared constants */ + +// Total byte length of an EVM word +uint256 constant WORD_SIZE = 32; +// Index of the last byte in an EVM word +uint256 constant WORD_LAST_INDEX = 31; +// Conversion for bit shifting +uint256 constant BYTE_TO_BITS = 8; + +// Schema's capacity +uint256 constant MAX_TOTAL_FIELDS = 28; +// FieldLayout's capacity +uint256 constant MAX_STATIC_FIELDS = 28; +// PackedCounter's capacity +uint256 constant MAX_DYNAMIC_FIELDS = 5; + +// FieldLayout and Schema have the same offsets for metadata +library LayoutOffsets { + uint256 internal constant TOTAL_LENGTH = (WORD_SIZE - 2) * BYTE_TO_BITS; + uint256 internal constant NUM_STATIC_FIELDS = (WORD_SIZE - 2 - 1) * BYTE_TO_BITS; + uint256 internal constant NUM_DYNAMIC_FIELDS = (WORD_SIZE - 2 - 1 - 1) * BYTE_TO_BITS; +} diff --git a/packages/store/src/tightcoder/TightCoder.sol b/packages/store/src/tightcoder/TightCoder.sol index 6274f26f0d..2af4eecc0c 100644 --- a/packages/store/src/tightcoder/TightCoder.sol +++ b/packages/store/src/tightcoder/TightCoder.sol @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.0; -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; import { Slice, SliceLib } from "../Slice.sol"; /** diff --git a/packages/store/test/EchoSubscriber.sol b/packages/store/test/EchoSubscriber.sol index f36dd0ce67..b93fef9aa9 100644 --- a/packages/store/test/EchoSubscriber.sol +++ b/packages/store/test/EchoSubscriber.sol @@ -1,18 +1,18 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.0; +import { FieldLayout } from "../src/FieldLayout.sol"; import { StoreHook } from "../src/StoreHook.sol"; -import { Schema } from "../src/Schema.sol"; contract EchoSubscriber is StoreHook { event HookCalled(bytes); - function onBeforeSetRecord(bytes32 table, bytes32[] memory key, bytes memory data, Schema valueSchema) public { - emit HookCalled(abi.encode(table, key, data, valueSchema)); + function onBeforeSetRecord(bytes32 table, bytes32[] memory key, bytes memory data, FieldLayout fieldLayout) public { + emit HookCalled(abi.encode(table, key, data, fieldLayout)); } - function onAfterSetRecord(bytes32 table, bytes32[] memory key, bytes memory data, Schema valueSchema) public { - emit HookCalled(abi.encode(table, key, data, valueSchema)); + function onAfterSetRecord(bytes32 table, bytes32[] memory key, bytes memory data, FieldLayout fieldLayout) public { + emit HookCalled(abi.encode(table, key, data, fieldLayout)); } function onBeforeSetField( @@ -20,9 +20,9 @@ contract EchoSubscriber is StoreHook { bytes32[] memory key, uint8 schemaIndex, bytes memory data, - Schema valueSchema + FieldLayout fieldLayout ) public { - emit HookCalled(abi.encode(table, key, schemaIndex, data, valueSchema)); + emit HookCalled(abi.encode(table, key, schemaIndex, data, fieldLayout)); } function onAfterSetField( @@ -30,16 +30,16 @@ contract EchoSubscriber is StoreHook { bytes32[] memory key, uint8 schemaIndex, bytes memory data, - Schema valueSchem + FieldLayout fieldLayout ) public { - emit HookCalled(abi.encode(table, key, schemaIndex, data, valueSchem)); + emit HookCalled(abi.encode(table, key, schemaIndex, data, fieldLayout)); } - function onBeforeDeleteRecord(bytes32 table, bytes32[] memory key, Schema valueSchema) public { - emit HookCalled(abi.encode(table, key, valueSchema)); + function onBeforeDeleteRecord(bytes32 table, bytes32[] memory key, FieldLayout fieldLayout) public { + emit HookCalled(abi.encode(table, key, fieldLayout)); } - function onAfterDeleteRecord(bytes32 table, bytes32[] memory key, Schema valueSchema) public { - emit HookCalled(abi.encode(table, key, valueSchema)); + function onAfterDeleteRecord(bytes32 table, bytes32[] memory key, FieldLayout fieldLayout) public { + emit HookCalled(abi.encode(table, key, fieldLayout)); } } diff --git a/packages/store/test/FieldLayout.t.sol b/packages/store/test/FieldLayout.t.sol new file mode 100644 index 0000000000..c8555fb18d --- /dev/null +++ b/packages/store/test/FieldLayout.t.sol @@ -0,0 +1,207 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +import { Test, console } from "forge-std/Test.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; +import { FieldLayout, FieldLayoutLib } from "../src/FieldLayout.sol"; +import { FieldLayoutEncodeHelper } from "./FieldLayoutEncodeHelper.sol"; + +// TODO add tests for all lengths +contract FieldLayoutTest is Test, GasReporter { + function testEncodeDecodeFieldLayout() public { + startGasReport("initialize field layout array with 5 entries"); + uint256[] memory _fieldLayout = new uint256[](5); + _fieldLayout[0] = 1; + _fieldLayout[1] = 2; + _fieldLayout[2] = 4; + _fieldLayout[3] = 16; + _fieldLayout[4] = 32; + endGasReport(); + + startGasReport("encode field layout with 5+1 entries"); + FieldLayout fieldLayout = FieldLayoutLib.encode(_fieldLayout, 1); + endGasReport(); + + startGasReport("get static byte length at index"); + uint256 staticByteLength = fieldLayout.atIndex(0); + endGasReport(); + + assertEq(staticByteLength, 1); + assertEq(fieldLayout.atIndex(1), 2); + assertEq(fieldLayout.atIndex(2), 4); + assertEq(fieldLayout.atIndex(3), 16); + assertEq(fieldLayout.atIndex(4), 32); + assertEq(fieldLayout.atIndex(5), 0); + } + + function testInvalidFieldLayoutStaticTypeIsZero() public { + vm.expectRevert(FieldLayoutLib.FieldLayoutLib_StaticLengthIsZero.selector); + FieldLayoutEncodeHelper.encode(1, 0, 1); + } + + function testInvalidFieldLayoutStaticTypeDoesNotFitInAWord() public { + vm.expectRevert(FieldLayoutLib.FieldLayoutLib_StaticLengthDoesNotFitInAWord.selector); + FieldLayoutEncodeHelper.encode(1, 33, 1); + } + + function testEncodeMaxValidLength() public { + uint256[] memory fieldLayout = new uint256[](23); + fieldLayout[0] = 32; + fieldLayout[1] = 32; + fieldLayout[2] = 32; + fieldLayout[3] = 32; + fieldLayout[4] = 32; + fieldLayout[5] = 32; + fieldLayout[6] = 32; + fieldLayout[7] = 32; + fieldLayout[8] = 32; + fieldLayout[9] = 32; + fieldLayout[10] = 32; + fieldLayout[11] = 32; + fieldLayout[12] = 32; + fieldLayout[13] = 32; + fieldLayout[14] = 32; + fieldLayout[15] = 32; + fieldLayout[16] = 32; + fieldLayout[17] = 32; + fieldLayout[18] = 32; + fieldLayout[19] = 32; + fieldLayout[20] = 32; + fieldLayout[21] = 32; + fieldLayout[22] = 32; + FieldLayout encodedFieldLayout = FieldLayoutLib.encode(fieldLayout, 5); + + assertEq(encodedFieldLayout.numStaticFields() + encodedFieldLayout.numDynamicFields(), 28); + } + + function testFailEncodeTooLong() public pure { + uint256[] memory fieldLayout = new uint256[](17); + fieldLayout[0] = 32; + fieldLayout[1] = 32; + fieldLayout[2] = 32; + fieldLayout[3] = 32; + fieldLayout[4] = 32; + fieldLayout[5] = 32; + fieldLayout[6] = 32; + fieldLayout[7] = 32; + fieldLayout[8] = 32; + fieldLayout[9] = 32; + fieldLayout[10] = 32; + fieldLayout[11] = 32; + fieldLayout[12] = 32; + fieldLayout[13] = 32; + fieldLayout[14] = 32; + fieldLayout[15] = 32; + fieldLayout[16] = 32; + FieldLayoutLib.encode(fieldLayout, 12); + } + + function testEncodeMaxValidDynamic() public { + uint256[] memory fieldLayout = new uint256[](0); + FieldLayout encodedFieldLayout = FieldLayoutLib.encode(fieldLayout, 5); + + assertEq(encodedFieldLayout.numDynamicFields(), 5); + } + + function testFailEncodeTooManyDynamic() public pure { + uint256[] memory fieldLayout = new uint256[](0); + FieldLayoutLib.encode(fieldLayout, 6); + } + + function testGetStaticFieldLayoutLength() public { + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 4, 16, 32, 1); + + startGasReport("get static data length from field layout"); + uint256 length = fieldLayout.staticDataLength(); + endGasReport(); + + assertEq(length, 55); + } + + function testGetNumStaticFields() public { + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 4, 16, 32, 1); + + startGasReport("get number of static fields from field layout"); + uint256 num = fieldLayout.numStaticFields(); + endGasReport(); + + assertEq(num, 5); + } + + function testGetNumDynamicFields() public { + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 4, 16, 32, 1); + + startGasReport("get number of dynamic fields from field layout"); + uint256 num = fieldLayout.numDynamicFields(); + endGasReport(); + + assertEq(num, 1); + } + + function testGetNumFields() public { + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 4, 16, 32, 1); + + startGasReport("get number of all fields from field layout"); + uint256 num = fieldLayout.numFields(); + endGasReport(); + + assertEq(num, 6); + } + + function testValidate() public { + uint256[] memory fieldLayout = new uint256[](23); + fieldLayout[0] = 32; + fieldLayout[1] = 32; + fieldLayout[2] = 32; + fieldLayout[3] = 32; + fieldLayout[4] = 32; + fieldLayout[5] = 32; + fieldLayout[6] = 32; + fieldLayout[7] = 32; + fieldLayout[8] = 32; + fieldLayout[9] = 32; + fieldLayout[10] = 32; + fieldLayout[11] = 32; + fieldLayout[12] = 32; + fieldLayout[13] = 32; + fieldLayout[14] = 32; + fieldLayout[15] = 32; + fieldLayout[16] = 32; + fieldLayout[17] = 32; + fieldLayout[18] = 32; + fieldLayout[19] = 32; + fieldLayout[20] = 32; + fieldLayout[21] = 32; + fieldLayout[22] = 32; + FieldLayout encodedFieldLayout = FieldLayoutLib.encode(fieldLayout, 5); + + startGasReport("validate field layout"); + encodedFieldLayout.validate({ allowEmpty: false }); + endGasReport(); + } + + function testFailValidate() public pure { + FieldLayout.wrap(keccak256("some invalid field layout")).validate({ allowEmpty: false }); + } + + function testIsEmptyTrue() public { + uint256[] memory fieldLayout = new uint256[](0); + FieldLayout encodedFieldLayout = FieldLayoutLib.encode(fieldLayout, 0); + + startGasReport("check if field layout is empty (empty field layout)"); + bool empty = encodedFieldLayout.isEmpty(); + endGasReport(); + + assertTrue(empty); + } + + function testIsEmptyFalse() public { + FieldLayout encodedFieldLayout = FieldLayoutEncodeHelper.encode(32, 0); + + startGasReport("check if field layout is empty (non-empty field layout)"); + bool empty = encodedFieldLayout.isEmpty(); + endGasReport(); + + assertFalse(empty); + } +} diff --git a/packages/store/test/FieldLayoutEncodeHelper.sol b/packages/store/test/FieldLayoutEncodeHelper.sol new file mode 100644 index 0000000000..ded71c228d --- /dev/null +++ b/packages/store/test/FieldLayoutEncodeHelper.sol @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +import { FieldLayout, FieldLayoutLib } from "../src/FieldLayout.sol"; + +/** + * Overrides for encode function to simplify tests + */ +library FieldLayoutEncodeHelper { + function encode(uint256 a, uint256 numDynamicFields) internal pure returns (FieldLayout) { + uint256[] memory fieldLayout = new uint256[](1); + fieldLayout[0] = a; + return FieldLayoutLib.encode(fieldLayout, numDynamicFields); + } + + function encode(uint256 a, uint256 b, uint256 numDynamicFields) internal pure returns (FieldLayout) { + uint256[] memory fieldLayout = new uint256[](2); + fieldLayout[0] = a; + fieldLayout[1] = b; + return FieldLayoutLib.encode(fieldLayout, numDynamicFields); + } + + function encode(uint256 a, uint256 b, uint256 c, uint256 numDynamicFields) internal pure returns (FieldLayout) { + uint256[] memory fieldLayout = new uint256[](3); + fieldLayout[0] = a; + fieldLayout[1] = b; + fieldLayout[2] = c; + return FieldLayoutLib.encode(fieldLayout, numDynamicFields); + } + + function encode( + uint256 a, + uint256 b, + uint256 c, + uint256 d, + uint256 numDynamicFields + ) internal pure returns (FieldLayout) { + uint256[] memory fieldLayout = new uint256[](4); + fieldLayout[0] = a; + fieldLayout[1] = b; + fieldLayout[2] = c; + fieldLayout[3] = d; + return FieldLayoutLib.encode(fieldLayout, numDynamicFields); + } + + function encode( + uint256 a, + uint256 b, + uint256 c, + uint256 d, + uint256 e, + uint256 numDynamicFields + ) internal pure returns (FieldLayout) { + uint256[] memory fieldLayout = new uint256[](5); + fieldLayout[0] = a; + fieldLayout[1] = b; + fieldLayout[2] = c; + fieldLayout[3] = d; + fieldLayout[4] = e; + return FieldLayoutLib.encode(fieldLayout, numDynamicFields); + } + + function encode( + uint256 a, + uint256 b, + uint256 c, + uint256 d, + uint256 e, + uint256 f, + uint256 numDynamicFields + ) internal pure returns (FieldLayout) { + uint256[] memory fieldLayout = new uint256[](6); + fieldLayout[0] = a; + fieldLayout[1] = b; + fieldLayout[2] = c; + fieldLayout[3] = d; + fieldLayout[4] = e; + fieldLayout[5] = f; + return FieldLayoutLib.encode(fieldLayout, numDynamicFields); + } +} diff --git a/packages/store/test/KeyEncoding.t.sol b/packages/store/test/KeyEncoding.t.sol index ff34948b30..a697813d28 100644 --- a/packages/store/test/KeyEncoding.t.sol +++ b/packages/store/test/KeyEncoding.t.sol @@ -7,14 +7,24 @@ import { KeyEncoding, KeyEncodingTableId } from "../src/codegen/Tables.sol"; import { ExampleEnum } from "../src/codegen/Types.sol"; import { StoreCore } from "../src/StoreCore.sol"; import { StoreReadWithStubs } from "../src/StoreReadWithStubs.sol"; +import { FieldLayout } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; contract KeyEncodingTest is Test, GasReporter, StoreReadWithStubs { - function testRegisterAndGetSchema() public { - startGasReport("register KeyEncoding schema"); + function testRegisterAndGetFieldLayout() public { + startGasReport("register KeyEncoding table"); KeyEncoding.register(); endGasReport(); + FieldLayout registeredFieldLayout = StoreCore.getFieldLayout(KeyEncodingTableId); + FieldLayout declaredFieldLayout = KeyEncoding.getFieldLayout(); + + assertEq(keccak256(abi.encode(registeredFieldLayout)), keccak256(abi.encode(declaredFieldLayout))); + } + + function testRegisterAndGetSchema() public { + KeyEncoding.register(); + Schema registeredSchema = StoreCore.getValueSchema(KeyEncodingTableId); Schema declaredSchema = KeyEncoding.getValueSchema(); diff --git a/packages/store/test/MirrorSubscriber.sol b/packages/store/test/MirrorSubscriber.sol index cdb701268a..fe4d1d5c34 100644 --- a/packages/store/test/MirrorSubscriber.sol +++ b/packages/store/test/MirrorSubscriber.sol @@ -4,6 +4,7 @@ pragma solidity >=0.8.0; import { IStore } from "../src/IStore.sol"; import { StoreHook } from "../src/StoreHook.sol"; import { StoreSwitch } from "../src/StoreSwitch.sol"; +import { FieldLayout } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; bytes32 constant indexerTableId = keccak256("indexer.table"); @@ -13,21 +14,22 @@ contract MirrorSubscriber is StoreHook { constructor( bytes32 table, + FieldLayout fieldLayout, Schema keySchema, Schema valueSchema, string[] memory keyNames, string[] memory fieldNames ) { - IStore(msg.sender).registerTable(indexerTableId, keySchema, valueSchema, keyNames, fieldNames); + IStore(msg.sender).registerTable(indexerTableId, fieldLayout, keySchema, valueSchema, keyNames, fieldNames); _table = table; } - function onBeforeSetRecord(bytes32 table, bytes32[] memory key, bytes memory data, Schema valueSchema) public { + function onBeforeSetRecord(bytes32 table, bytes32[] memory key, bytes memory data, FieldLayout fieldLayout) public { if (table != table) revert("invalid table"); - StoreSwitch.setRecord(indexerTableId, key, data, valueSchema); + StoreSwitch.setRecord(indexerTableId, key, data, fieldLayout); } - function onAfterSetRecord(bytes32 table, bytes32[] memory key, bytes memory data, Schema valueSchema) public { + function onAfterSetRecord(bytes32 table, bytes32[] memory key, bytes memory data, FieldLayout fieldLayout) public { // NOOP } @@ -36,22 +38,22 @@ contract MirrorSubscriber is StoreHook { bytes32[] memory key, uint8 schemaIndex, bytes memory data, - Schema valueSchema + FieldLayout fieldLayout ) public { if (table != table) revert("invalid table"); - StoreSwitch.setField(indexerTableId, key, schemaIndex, data, valueSchema); + StoreSwitch.setField(indexerTableId, key, schemaIndex, data, fieldLayout); } - function onAfterSetField(bytes32, bytes32[] memory, uint8, bytes memory, Schema) public { + function onAfterSetField(bytes32, bytes32[] memory, uint8, bytes memory, FieldLayout) public { // NOOP } - function onBeforeDeleteRecord(bytes32 table, bytes32[] memory key, Schema valueSchema) public { + function onBeforeDeleteRecord(bytes32 table, bytes32[] memory key, FieldLayout fieldLayout) public { if (table != table) revert("invalid table"); - StoreSwitch.deleteRecord(indexerTableId, key, valueSchema); + StoreSwitch.deleteRecord(indexerTableId, key, fieldLayout); } - function onAfterDeleteRecord(bytes32 table, bytes32[] memory key, Schema valueSchema) public { + function onAfterDeleteRecord(bytes32 table, bytes32[] memory key, FieldLayout fieldLayout) public { // NOOP } } diff --git a/packages/store/test/Mixed.t.sol b/packages/store/test/Mixed.t.sol index 1170c14a0c..9719998447 100644 --- a/packages/store/test/Mixed.t.sol +++ b/packages/store/test/Mixed.t.sol @@ -3,20 +3,29 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; import { Mixed, MixedData, MixedTableId } from "../src/codegen/Tables.sol"; import { StoreCore } from "../src/StoreCore.sol"; import { StoreReadWithStubs } from "../src/StoreReadWithStubs.sol"; +import { FieldLayout } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; contract MixedTest is Test, GasReporter, StoreReadWithStubs { MixedData private testMixed; - function testRegisterAndGetSchema() public { - startGasReport("register Mixed schema"); + function testRegisterAndGetFieldLayout() public { + startGasReport("register Mixed table"); Mixed.register(); endGasReport(); + FieldLayout registeredFieldLayout = StoreCore.getFieldLayout(MixedTableId); + FieldLayout declaredFieldLayout = Mixed.getFieldLayout(); + + assertEq(keccak256(abi.encode(registeredFieldLayout)), keccak256(abi.encode(declaredFieldLayout))); + } + + function testRegisterAndGetSchema() public { + Mixed.register(); + Schema registeredSchema = StoreCore.getValueSchema(MixedTableId); Schema declaredSchema = Mixed.getValueSchema(); diff --git a/packages/store/test/RevertSubscriber.sol b/packages/store/test/RevertSubscriber.sol index 110207dc88..2d157d9850 100644 --- a/packages/store/test/RevertSubscriber.sol +++ b/packages/store/test/RevertSubscriber.sol @@ -1,31 +1,31 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.0; +import { FieldLayout } from "../src/FieldLayout.sol"; import { StoreHook } from "../src/StoreHook.sol"; -import { Schema } from "../src/Schema.sol"; contract RevertSubscriber is StoreHook { - function onBeforeSetRecord(bytes32, bytes32[] memory, bytes memory, Schema) public pure { + function onBeforeSetRecord(bytes32, bytes32[] memory, bytes memory, FieldLayout) public pure { revert("onBeforeSetRecord"); } - function onAfterSetRecord(bytes32, bytes32[] memory, bytes memory, Schema) public pure { + function onAfterSetRecord(bytes32, bytes32[] memory, bytes memory, FieldLayout) public pure { revert("onAfterSetRecord"); } - function onBeforeSetField(bytes32, bytes32[] memory, uint8, bytes memory, Schema) public pure { + function onBeforeSetField(bytes32, bytes32[] memory, uint8, bytes memory, FieldLayout) public pure { revert("onBeforeSetField"); } - function onAfterSetField(bytes32, bytes32[] memory, uint8, bytes memory, Schema) public pure { + function onAfterSetField(bytes32, bytes32[] memory, uint8, bytes memory, FieldLayout) public pure { revert("onAfterSetField"); } - function onBeforeDeleteRecord(bytes32, bytes32[] memory, Schema) public pure { + function onBeforeDeleteRecord(bytes32, bytes32[] memory, FieldLayout) public pure { revert("onBeforeDeleteRecord"); } - function onAfterDeleteRecord(bytes32, bytes32[] memory, Schema) public pure { + function onAfterDeleteRecord(bytes32, bytes32[] memory, FieldLayout) public pure { revert("onAfterDeleteRecord"); } } diff --git a/packages/store/test/StoreCore.t.sol b/packages/store/test/StoreCore.t.sol index add7fa5f77..c0b9f703be 100644 --- a/packages/store/test/StoreCore.t.sol +++ b/packages/store/test/StoreCore.t.sol @@ -7,6 +7,7 @@ import { StoreCore, StoreCoreInternal } from "../src/StoreCore.sol"; import { Bytes } from "../src/Bytes.sol"; import { SliceLib } from "../src/Slice.sol"; import { EncodeArray } from "../src/tightcoder/EncodeArray.sol"; +import { FieldLayout } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "../src/PackedCounter.sol"; import { StoreReadWithStubs } from "../src/StoreReadWithStubs.sol"; @@ -14,6 +15,7 @@ import { IStoreErrors } from "../src/IStoreErrors.sol"; import { IStore } from "../src/IStore.sol"; import { StoreSwitch } from "../src/StoreSwitch.sol"; import { Tables, TablesTableId } from "../src/codegen/Tables.sol"; +import { FieldLayoutEncodeHelper } from "./FieldLayoutEncodeHelper.sol"; import { StoreHookLib } from "../src/StoreHook.sol"; import { SchemaEncodeHelper } from "./SchemaEncodeHelper.sol"; import { StoreMock } from "./StoreMock.sol"; @@ -35,7 +37,8 @@ contract StoreCoreTest is Test, StoreMock { Schema defaultKeySchema = SchemaEncodeHelper.encode(SchemaType.BYTES32); string[] defaultKeyNames = new string[](1); - function testRegisterAndGetSchema() public { + function testRegisterAndGetFieldLayout() public { + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 1, 2, 0); Schema keySchema = SchemaEncodeHelper.encode(SchemaType.UINT8, SchemaType.UINT16); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT8, @@ -61,15 +64,19 @@ contract StoreCoreTest is Test, StoreMock { emit StoreSetRecord( TablesTableId, key, - Tables.encode(keySchema.unwrap(), valueSchema.unwrap(), abi.encode(keyNames), abi.encode(fieldNames)) + Tables.encode( + fieldLayout.unwrap(), + keySchema.unwrap(), + valueSchema.unwrap(), + abi.encode(keyNames), + abi.encode(fieldNames) + ) ); - IStore(this).registerTable(table, keySchema, valueSchema, keyNames, fieldNames); - - Schema loadedValueSchema = IStore(this).getValueSchema(table); - assertEq(loadedValueSchema.unwrap(), valueSchema.unwrap()); + IStore(this).registerTable(table, fieldLayout, keySchema, valueSchema, keyNames, fieldNames); - Schema loadedKeySchema = IStore(this).getKeySchema(table); - assertEq(loadedKeySchema.unwrap(), keySchema.unwrap()); + assertEq(IStore(this).getFieldLayout(table).unwrap(), fieldLayout.unwrap()); + assertEq(IStore(this).getValueSchema(table).unwrap(), valueSchema.unwrap()); + assertEq(IStore(this).getKeySchema(table).unwrap(), keySchema.unwrap()); bytes memory loadedKeyNames = Tables.getAbiEncodedKeyNames(IStore(this), table); assertEq(loadedKeyNames, abi.encode(keyNames)); @@ -78,21 +85,23 @@ contract StoreCoreTest is Test, StoreMock { assertEq(loadedFieldNames, abi.encode(fieldNames)); } - function testFailRegisterInvalidSchema() public { + function testFailRegisterInvalidFieldLayout() public { string[] memory keyNames = new string[](2); string[] memory fieldNames = new string[](4); IStore(this).registerTable( keccak256("table"), - Schema.wrap(keccak256("random bytes as schema")), + FieldLayout.wrap(keccak256("random bytes as value field layout")), Schema.wrap(keccak256("random bytes as key schema")), + Schema.wrap(keccak256("random bytes as schema")), keyNames, fieldNames ); } - function testHasSchema() public { + function testHasFieldLayoutAndSchema() public { string[] memory keyNames = new string[](1); string[] memory fieldNames = new string[](4); + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 1, 2, 0); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT8, SchemaType.UINT16, @@ -101,14 +110,20 @@ contract StoreCoreTest is Test, StoreMock { ); bytes32 table = keccak256("some.table"); bytes32 table2 = keccak256("other.table"); - IStore(this).registerTable(table, defaultKeySchema, valueSchema, keyNames, fieldNames); + IStore(this).registerTable(table, fieldLayout, defaultKeySchema, valueSchema, keyNames, fieldNames); assertTrue(StoreCore.hasTable(table)); assertFalse(StoreCore.hasTable(table2)); + IStore(this).getFieldLayout(table); IStore(this).getValueSchema(table); IStore(this).getKeySchema(table); + vm.expectRevert( + abi.encodeWithSelector(IStoreErrors.StoreCore_TableNotFound.selector, table2, string(abi.encodePacked(table2))) + ); + IStore(this).getFieldLayout(table2); + vm.expectRevert( abi.encodeWithSelector(IStoreErrors.StoreCore_TableNotFound.selector, table2, string(abi.encodePacked(table2))) ); @@ -122,6 +137,7 @@ contract StoreCoreTest is Test, StoreMock { function testRegisterTableRevertNames() public { bytes32 table = keccak256("some.table"); + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 0); Schema keySchema = SchemaEncodeHelper.encode( SchemaType.UINT8, SchemaType.UINT16, @@ -134,16 +150,17 @@ contract StoreCoreTest is Test, StoreMock { // Register table with invalid key names vm.expectRevert(abi.encodeWithSelector(IStoreErrors.StoreCore_InvalidKeyNamesLength.selector, 4, 1)); - IStore(this).registerTable(table, keySchema, valueSchema, oneName, oneName); + IStore(this).registerTable(table, fieldLayout, keySchema, valueSchema, oneName, oneName); // Register table with invalid value names vm.expectRevert(abi.encodeWithSelector(IStoreErrors.StoreCore_InvalidFieldNamesLength.selector, 1, 4)); - IStore(this).registerTable(table, keySchema, valueSchema, fourNames, fourNames); + IStore(this).registerTable(table, fieldLayout, keySchema, valueSchema, fourNames, fourNames); } function testSetAndGetDynamicDataLength() public { bytes32 table = keccak256("some.table"); + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 4, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT8, SchemaType.UINT16, @@ -152,8 +169,8 @@ contract StoreCoreTest is Test, StoreMock { SchemaType.UINT32_ARRAY ); - // Register schema - IStore(this).registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](5)); + // Register table + IStore(this).registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](5)); // Create some key bytes32[] memory key = new bytes32[](1); @@ -185,7 +202,8 @@ contract StoreCoreTest is Test, StoreMock { } function testSetAndGetStaticData() public { - // Register table's schema + // Register table + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 1, 2, 0); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT8, SchemaType.UINT16, @@ -194,7 +212,7 @@ contract StoreCoreTest is Test, StoreMock { ); bytes32 table = keccak256("some.table"); - IStore(this).registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](4)); + IStore(this).registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](4)); // Set data bytes memory data = abi.encodePacked(bytes1(0x01), bytes2(0x0203), bytes1(0x04), bytes2(0x0506)); @@ -206,16 +224,17 @@ contract StoreCoreTest is Test, StoreMock { vm.expectEmit(true, true, true, true); emit StoreSetRecord(table, key, data); - IStore(this).setRecord(table, key, data, valueSchema); + IStore(this).setRecord(table, key, data, fieldLayout); // Get data - bytes memory loadedData = IStore(this).getRecord(table, key, valueSchema); + bytes memory loadedData = IStore(this).getRecord(table, key, fieldLayout); assertTrue(Bytes.equals(data, loadedData)); } function testFailSetAndGetStaticData() public { - // Register table's schema + // Register table + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 1, 2, 0); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT8, SchemaType.UINT16, @@ -223,7 +242,7 @@ contract StoreCoreTest is Test, StoreMock { SchemaType.UINT16 ); bytes32 table = keccak256("some.table"); - IStore(this).registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](4)); + IStore(this).registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](4)); // Set data bytes memory data = abi.encodePacked(bytes1(0x01), bytes2(0x0203), bytes1(0x04)); @@ -232,14 +251,15 @@ contract StoreCoreTest is Test, StoreMock { key[0] = keccak256("some.key"); // This should fail because the data is not 6 bytes long - IStore(this).setRecord(table, key, data, valueSchema); + IStore(this).setRecord(table, key, data, fieldLayout); } function testSetAndGetStaticDataSpanningWords() public { - // Register table's schema + // Register table + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 32, 0); Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT128, SchemaType.UINT256); bytes32 table = keccak256("some.table"); - IStore(this).registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](2)); + IStore(this).registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](2)); // Set data bytes memory data = abi.encodePacked( @@ -254,10 +274,10 @@ contract StoreCoreTest is Test, StoreMock { vm.expectEmit(true, true, true, true); emit StoreSetRecord(table, key, data); - IStore(this).setRecord(table, key, data, valueSchema); + IStore(this).setRecord(table, key, data, fieldLayout); // Get data - bytes memory loadedData = IStore(this).getRecord(table, key, valueSchema); + bytes memory loadedData = IStore(this).getRecord(table, key, fieldLayout); assertTrue(Bytes.equals(data, loadedData)); } @@ -265,13 +285,14 @@ contract StoreCoreTest is Test, StoreMock { function testSetAndGetDynamicData() public { bytes32 table = keccak256("some.table"); - // Register table's schema + // Register table + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT128, SchemaType.UINT32_ARRAY, SchemaType.UINT32_ARRAY ); - IStore(this).registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](3)); + IStore(this).registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](3)); bytes16 firstDataBytes = bytes16(0x0102030405060708090a0b0c0d0e0f10); @@ -314,10 +335,10 @@ contract StoreCoreTest is Test, StoreMock { emit StoreSetRecord(table, key, data); // Set data - IStore(this).setRecord(table, key, data, valueSchema); + IStore(this).setRecord(table, key, data, fieldLayout); // Get data - bytes memory loadedData = IStore(this).getRecord(table, key, valueSchema); + bytes memory loadedData = IStore(this).getRecord(table, key, fieldLayout); assertEq(loadedData.length, data.length); assertEq(keccak256(loadedData), keccak256(data)); @@ -339,14 +360,15 @@ contract StoreCoreTest is Test, StoreMock { function testSetAndGetField() public { bytes32 table = keccak256("some.table"); - // Register table's schema + // Register table + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 32, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT128, SchemaType.UINT256, SchemaType.UINT32_ARRAY, SchemaType.UINT32_ARRAY ); - IStore(this).registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](4)); + IStore(this).registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](4)); bytes16 firstDataBytes = bytes16(0x0102030405060708090a0b0c0d0e0f10); @@ -361,21 +383,21 @@ contract StoreCoreTest is Test, StoreMock { emit StoreSetField(table, key, 0, firstDataPacked); // Set first field - IStore(this).setField(table, key, 0, firstDataPacked, valueSchema); + IStore(this).setField(table, key, 0, firstDataPacked, fieldLayout); //////////////// // Static data //////////////// // Get first field - bytes memory loadedData = IStore(this).getField(table, key, 0, valueSchema); + bytes memory loadedData = IStore(this).getField(table, key, 0, fieldLayout); // Verify loaded data is correct assertEq(loadedData.length, 16); assertEq(bytes16(loadedData), bytes16(firstDataBytes)); // Verify the second index is not set yet - assertEq(uint256(bytes32(IStore(this).getField(table, key, 1, valueSchema))), 0); + assertEq(uint256(bytes32(IStore(this).getField(table, key, 1, fieldLayout))), 0); // Set second field bytes32 secondDataBytes = keccak256("some data"); @@ -386,24 +408,25 @@ contract StoreCoreTest is Test, StoreMock { vm.expectEmit(true, true, true, true); emit StoreSetField(table, key, 1, secondDataPacked); - IStore(this).setField(table, key, 1, secondDataPacked, valueSchema); + IStore(this).setField(table, key, 1, secondDataPacked, fieldLayout); // Get second field - loadedData = IStore(this).getField(table, key, 1, valueSchema); + loadedData = IStore(this).getField(table, key, 1, fieldLayout); // Verify loaded data is correct assertEq(loadedData.length, 32); assertEq(bytes32(loadedData), secondDataBytes); // Verify the first field didn't change - assertEq(bytes16(IStore(this).getField(table, key, 0, valueSchema)), bytes16(firstDataBytes)); + assertEq(bytes16(IStore(this).getField(table, key, 0, fieldLayout)), bytes16(firstDataBytes)); // Verify the full static data is correct + assertEq(IStore(this).getFieldLayout(table).staticDataLength(), 48); assertEq(IStore(this).getValueSchema(table).staticDataLength(), 48); - assertEq(Bytes.slice16(IStore(this).getRecord(table, key, valueSchema), 0), firstDataBytes); - assertEq(Bytes.slice32(IStore(this).getRecord(table, key, valueSchema), 16), secondDataBytes); + assertEq(Bytes.slice16(IStore(this).getRecord(table, key, fieldLayout), 0), firstDataBytes); + assertEq(Bytes.slice32(IStore(this).getRecord(table, key, fieldLayout), 16), secondDataBytes); assertEq( - keccak256(SliceLib.getSubslice(IStore(this).getRecord(table, key, valueSchema), 0, 48).toBytes()), + keccak256(SliceLib.getSubslice(IStore(this).getRecord(table, key, fieldLayout), 0, 48).toBytes()), keccak256(abi.encodePacked(firstDataBytes, secondDataBytes)) ); @@ -433,10 +456,10 @@ contract StoreCoreTest is Test, StoreMock { emit StoreSetField(table, key, 2, thirdDataBytes); // Set third field - IStore(this).setField(table, key, 2, thirdDataBytes, valueSchema); + IStore(this).setField(table, key, 2, thirdDataBytes, fieldLayout); // Get third field - loadedData = IStore(this).getField(table, key, 2, valueSchema); + loadedData = IStore(this).getField(table, key, 2, fieldLayout); // Verify loaded data is correct assertEq(SliceLib.fromBytes(loadedData).decodeArray_uint32().length, 2); @@ -444,21 +467,21 @@ contract StoreCoreTest is Test, StoreMock { assertEq(keccak256(loadedData), keccak256(thirdDataBytes)); // Verify the fourth field is not set yet - assertEq(IStore(this).getField(table, key, 3, valueSchema).length, 0); + assertEq(IStore(this).getField(table, key, 3, fieldLayout).length, 0); // Verify none of the previous fields were impacted - assertEq(bytes16(IStore(this).getField(table, key, 0, valueSchema)), bytes16(firstDataBytes)); - assertEq(bytes32(IStore(this).getField(table, key, 1, valueSchema)), bytes32(secondDataBytes)); + assertEq(bytes16(IStore(this).getField(table, key, 0, fieldLayout)), bytes16(firstDataBytes)); + assertEq(bytes32(IStore(this).getField(table, key, 1, fieldLayout)), bytes32(secondDataBytes)); // Expect a StoreSetField event to be emitted vm.expectEmit(true, true, true, true); emit StoreSetField(table, key, 3, fourthDataBytes); // Set fourth field - IStore(this).setField(table, key, 3, fourthDataBytes, valueSchema); + IStore(this).setField(table, key, 3, fourthDataBytes, fieldLayout); // Get fourth field - loadedData = IStore(this).getField(table, key, 3, valueSchema); + loadedData = IStore(this).getField(table, key, 3, fieldLayout); // Verify loaded data is correct assertEq(loadedData.length, fourthDataBytes.length); @@ -467,7 +490,7 @@ contract StoreCoreTest is Test, StoreMock { // Verify all fields are correct PackedCounter encodedLengths = PackedCounterLib.pack(uint40(thirdDataBytes.length), uint40(fourthDataBytes.length)); assertEq( - keccak256(IStore(this).getRecord(table, key, valueSchema)), + keccak256(IStore(this).getRecord(table, key, fieldLayout)), keccak256( abi.encodePacked(firstDataBytes, secondDataBytes, encodedLengths.unwrap(), thirdDataBytes, fourthDataBytes) ) @@ -477,13 +500,14 @@ contract StoreCoreTest is Test, StoreMock { function testDeleteData() public { bytes32 table = keccak256("some.table"); - // Register table's schema + // Register table + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT128, SchemaType.UINT32_ARRAY, SchemaType.UINT32_ARRAY ); - IStore(this).registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](3)); + IStore(this).registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](3)); bytes16 firstDataBytes = bytes16(0x0102030405060708090a0b0c0d0e0f10); @@ -522,10 +546,10 @@ contract StoreCoreTest is Test, StoreMock { key[0] = bytes32("some.key"); // Set data - IStore(this).setRecord(table, key, data, valueSchema); + IStore(this).setRecord(table, key, data, fieldLayout); // Get data - bytes memory loadedData = IStore(this).getRecord(table, key, valueSchema); + bytes memory loadedData = IStore(this).getRecord(table, key, fieldLayout); assertEq(loadedData.length, data.length); assertEq(keccak256(loadedData), keccak256(data)); @@ -535,11 +559,11 @@ contract StoreCoreTest is Test, StoreMock { emit StoreDeleteRecord(table, key); // Delete data - IStore(this).deleteRecord(table, key, valueSchema); + IStore(this).deleteRecord(table, key, fieldLayout); // Verify data is deleted - loadedData = IStore(this).getRecord(table, key, valueSchema); - assertEq(keccak256(loadedData), keccak256(new bytes(valueSchema.staticDataLength()))); + loadedData = IStore(this).getRecord(table, key, fieldLayout); + assertEq(keccak256(loadedData), keccak256(new bytes(fieldLayout.staticDataLength()))); } struct TestPushToFieldData { @@ -560,13 +584,21 @@ contract StoreCoreTest is Test, StoreMock { data.table = keccak256("some.table"); - // Register table's schema + // Register table + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(32, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT256, SchemaType.UINT32_ARRAY, SchemaType.UINT32_ARRAY ); - IStore(this).registerTable(data.table, defaultKeySchema, valueSchema, new string[](1), new string[](3)); + IStore(this).registerTable( + data.table, + fieldLayout, + defaultKeySchema, + valueSchema, + new string[](1), + new string[](3) + ); // Create key data.key = new bytes32[](1); @@ -590,10 +622,10 @@ contract StoreCoreTest is Test, StoreMock { } // Set fields - IStore(this).setField(data.table, data.key, 0, abi.encodePacked(data.firstDataBytes), valueSchema); - IStore(this).setField(data.table, data.key, 1, data.secondDataBytes, valueSchema); + IStore(this).setField(data.table, data.key, 0, abi.encodePacked(data.firstDataBytes), fieldLayout); + IStore(this).setField(data.table, data.key, 1, data.secondDataBytes, fieldLayout); // Initialize a field with push - IStore(this).pushToField(data.table, data.key, 2, data.thirdDataBytes, valueSchema); + IStore(this).pushToField(data.table, data.key, 2, data.thirdDataBytes, fieldLayout); // Create data to push { @@ -608,10 +640,10 @@ contract StoreCoreTest is Test, StoreMock { emit StoreSetField(data.table, data.key, 1, data.newSecondDataBytes); // Push to second field - IStore(this).pushToField(data.table, data.key, 1, data.secondDataToPush, valueSchema); + IStore(this).pushToField(data.table, data.key, 1, data.secondDataToPush, fieldLayout); // Get second field - data.loadedData = IStore(this).getField(data.table, data.key, 1, valueSchema); + data.loadedData = IStore(this).getField(data.table, data.key, 1, fieldLayout); // Verify loaded data is correct assertEq(SliceLib.fromBytes(data.loadedData).decodeArray_uint32().length, 2 + 1); @@ -619,8 +651,8 @@ contract StoreCoreTest is Test, StoreMock { assertEq(data.loadedData, data.newSecondDataBytes); // Verify none of the other fields were impacted - assertEq(bytes32(IStore(this).getField(data.table, data.key, 0, valueSchema)), data.firstDataBytes); - assertEq(IStore(this).getField(data.table, data.key, 2, valueSchema), data.thirdDataBytes); + assertEq(bytes32(IStore(this).getField(data.table, data.key, 0, fieldLayout)), data.firstDataBytes); + assertEq(IStore(this).getField(data.table, data.key, 2, fieldLayout), data.thirdDataBytes); // Create data to push { @@ -644,10 +676,10 @@ contract StoreCoreTest is Test, StoreMock { emit StoreSetField(data.table, data.key, 2, data.newThirdDataBytes); // Push to third field - IStore(this).pushToField(data.table, data.key, 2, data.thirdDataToPush, valueSchema); + IStore(this).pushToField(data.table, data.key, 2, data.thirdDataToPush, fieldLayout); // Get third field - data.loadedData = IStore(this).getField(data.table, data.key, 2, valueSchema); + data.loadedData = IStore(this).getField(data.table, data.key, 2, fieldLayout); // Verify loaded data is correct assertEq(SliceLib.fromBytes(data.loadedData).decodeArray_uint32().length, 3 + 10); @@ -655,8 +687,8 @@ contract StoreCoreTest is Test, StoreMock { assertEq(data.loadedData, data.newThirdDataBytes); // Verify none of the other fields were impacted - assertEq(bytes32(IStore(this).getField(data.table, data.key, 0, valueSchema)), data.firstDataBytes); - assertEq(IStore(this).getField(data.table, data.key, 1, valueSchema), data.newSecondDataBytes); + assertEq(bytes32(IStore(this).getField(data.table, data.key, 0, fieldLayout)), data.firstDataBytes); + assertEq(IStore(this).getField(data.table, data.key, 1, fieldLayout), data.newSecondDataBytes); } struct TestUpdateInFieldData { @@ -692,13 +724,21 @@ contract StoreCoreTest is Test, StoreMock { data.table = keccak256("some.table"); - // Register table's schema + // Register table + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(32, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT256, SchemaType.UINT32_ARRAY, SchemaType.UINT64_ARRAY ); - IStore(this).registerTable(data.table, defaultKeySchema, valueSchema, new string[](1), new string[](3)); + IStore(this).registerTable( + data.table, + fieldLayout, + defaultKeySchema, + valueSchema, + new string[](1), + new string[](3) + ); // Create key data.key = new bytes32[](1); @@ -721,9 +761,9 @@ contract StoreCoreTest is Test, StoreMock { data.thirdDataBytes = EncodeArray.encode(data.thirdData); // Set fields - IStore(this).setField(data.table, data.key, 0, abi.encodePacked(data.firstDataBytes), valueSchema); - IStore(this).setField(data.table, data.key, 1, data.secondDataBytes, valueSchema); - IStore(this).setField(data.table, data.key, 2, data.thirdDataBytes, valueSchema); + IStore(this).setField(data.table, data.key, 0, abi.encodePacked(data.firstDataBytes), fieldLayout); + IStore(this).setField(data.table, data.key, 1, data.secondDataBytes, fieldLayout); + IStore(this).setField(data.table, data.key, 2, data.thirdDataBytes, fieldLayout); // Create data to use for the update { @@ -739,10 +779,10 @@ contract StoreCoreTest is Test, StoreMock { emit StoreSetField(data.table, data.key, 1, data.newSecondDataBytes); // Update index 1 in second field (4 = byte length of uint32) - IStore(this).updateInField(data.table, data.key, 1, 4 * 1, data.secondDataForUpdate, valueSchema); + IStore(this).updateInField(data.table, data.key, 1, 4 * 1, data.secondDataForUpdate, fieldLayout); // Get second field - data.loadedData = IStore(this).getField(data.table, data.key, 1, valueSchema); + data.loadedData = IStore(this).getField(data.table, data.key, 1, fieldLayout); // Verify loaded data is correct assertEq(SliceLib.fromBytes(data.loadedData).decodeArray_uint32().length, data.secondData.length); @@ -750,8 +790,8 @@ contract StoreCoreTest is Test, StoreMock { assertEq(data.loadedData, data.newSecondDataBytes); // Verify none of the other fields were impacted - assertEq(bytes32(IStore(this).getField(data.table, data.key, 0, valueSchema)), data.firstDataBytes); - assertEq(IStore(this).getField(data.table, data.key, 2, valueSchema), data.thirdDataBytes); + assertEq(bytes32(IStore(this).getField(data.table, data.key, 0, fieldLayout)), data.firstDataBytes); + assertEq(IStore(this).getField(data.table, data.key, 2, fieldLayout), data.thirdDataBytes); // Create data for update { @@ -777,10 +817,10 @@ contract StoreCoreTest is Test, StoreMock { emit StoreSetField(data.table, data.key, 2, data.newThirdDataBytes); // Update indexes 1,2,3,4 in third field (8 = byte length of uint64) - IStore(this).updateInField(data.table, data.key, 2, 8 * 1, data.thirdDataForUpdate, valueSchema); + IStore(this).updateInField(data.table, data.key, 2, 8 * 1, data.thirdDataForUpdate, fieldLayout); // Get third field - data.loadedData = IStore(this).getField(data.table, data.key, 2, valueSchema); + data.loadedData = IStore(this).getField(data.table, data.key, 2, fieldLayout); // Verify loaded data is correct assertEq(SliceLib.fromBytes(data.loadedData).decodeArray_uint64().length, data.thirdData.length); @@ -788,39 +828,40 @@ contract StoreCoreTest is Test, StoreMock { assertEq(data.loadedData, data.newThirdDataBytes); // Verify none of the other fields were impacted - assertEq(bytes32(IStore(this).getField(data.table, data.key, 0, valueSchema)), data.firstDataBytes); - assertEq(IStore(this).getField(data.table, data.key, 1, valueSchema), data.newSecondDataBytes); + assertEq(bytes32(IStore(this).getField(data.table, data.key, 0, fieldLayout)), data.firstDataBytes); + assertEq(IStore(this).getField(data.table, data.key, 1, fieldLayout), data.newSecondDataBytes); // startByteIndex must not overflow vm.expectRevert( abi.encodeWithSelector(IStoreErrors.StoreCore_DataIndexOverflow.selector, type(uint40).max, type(uint56).max) ); - IStore(this).updateInField(data.table, data.key, 2, type(uint56).max, data.thirdDataForUpdate, valueSchema); + IStore(this).updateInField(data.table, data.key, 2, type(uint56).max, data.thirdDataForUpdate, fieldLayout); } function testAccessEmptyData() public { bytes32 table = keccak256("some.table"); + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(4, 1); Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT32, SchemaType.UINT32_ARRAY); - IStore(this).registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](2)); + IStore(this).registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](2)); // Create key bytes32[] memory key = new bytes32[](1); key[0] = bytes32("some.key"); - bytes memory data1 = IStore(this).getRecord(table, key, valueSchema); - assertEq(data1.length, valueSchema.staticDataLength()); + bytes memory data1 = IStore(this).getRecord(table, key, fieldLayout); + assertEq(data1.length, fieldLayout.staticDataLength()); - bytes memory data2 = IStore(this).getField(table, key, 0, valueSchema); - assertEq(data2.length, valueSchema.staticDataLength()); + bytes memory data2 = IStore(this).getField(table, key, 0, fieldLayout); + assertEq(data2.length, fieldLayout.staticDataLength()); - bytes memory data3 = IStore(this).getField(table, key, 1, valueSchema); + bytes memory data3 = IStore(this).getField(table, key, 1, fieldLayout); assertEq(data3.length, 0); - uint256 data3Length = IStore(this).getFieldLength(table, key, 1, valueSchema); + uint256 data3Length = IStore(this).getFieldLength(table, key, 1, fieldLayout); assertEq(data3Length, 0); - bytes memory data3Slice = IStore(this).getFieldSlice(table, key, 1, valueSchema, 0, 0); + bytes memory data3Slice = IStore(this).getFieldSlice(table, key, 1, fieldLayout, 0, 0); assertEq(data3Slice.length, 0); } @@ -829,13 +870,15 @@ contract StoreCoreTest is Test, StoreMock { bytes32[] memory key = new bytes32[](1); key[0] = keccak256("some key"); - // Register table's schema + // Register table + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 0); Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT128); - IStore(this).registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](1)); + IStore(this).registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](1)); // Create subscriber MirrorSubscriber subscriber = new MirrorSubscriber( table, + fieldLayout, defaultKeySchema, valueSchema, new string[](1), @@ -857,24 +900,24 @@ contract StoreCoreTest is Test, StoreMock { bytes memory data = abi.encodePacked(bytes16(0x0102030405060708090a0b0c0d0e0f10)); - IStore(this).setRecord(table, key, data, valueSchema); + IStore(this).setRecord(table, key, data, fieldLayout); // Get data from indexed table - the indexer should have mirrored the data there - bytes memory indexedData = IStore(this).getRecord(indexerTableId, key, valueSchema); + bytes memory indexedData = IStore(this).getRecord(indexerTableId, key, fieldLayout); assertEq(keccak256(data), keccak256(indexedData)); data = abi.encodePacked(bytes16(0x1112131415161718191a1b1c1d1e1f20)); - IStore(this).setField(table, key, 0, data, valueSchema); + IStore(this).setField(table, key, 0, data, fieldLayout); // Get data from indexed table - the indexer should have mirrored the data there - indexedData = IStore(this).getRecord(indexerTableId, key, valueSchema); + indexedData = IStore(this).getRecord(indexerTableId, key, fieldLayout); assertEq(keccak256(data), keccak256(indexedData)); - IStore(this).deleteRecord(table, key, valueSchema); + IStore(this).deleteRecord(table, key, fieldLayout); // Get data from indexed table - the indexer should have mirrored the data there - indexedData = IStore(this).getRecord(indexerTableId, key, valueSchema); + indexedData = IStore(this).getRecord(indexerTableId, key, fieldLayout); assertEq(keccak256(indexedData), keccak256(abi.encodePacked(bytes16(0)))); } @@ -884,8 +927,9 @@ contract StoreCoreTest is Test, StoreMock { key[0] = keccak256("some key"); // Register table's schema + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 0); Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT128); - IStore(this).registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](1)); + IStore(this).registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](1)); // Create a RevertSubscriber and an EchoSubscriber RevertSubscriber revertSubscriber = new RevertSubscriber(); @@ -922,48 +966,48 @@ contract StoreCoreTest is Test, StoreMock { // Expect a revert when the RevertSubscriber's onBeforeSetRecord hook is called vm.expectRevert(bytes("onBeforeSetRecord")); - IStore(this).setRecord(table, key, data, valueSchema); + IStore(this).setRecord(table, key, data, fieldLayout); // Expect a revert when the RevertSubscriber's onBeforeSetField hook is called vm.expectRevert(bytes("onBeforeSetField")); - IStore(this).setField(table, key, 0, data, valueSchema); + IStore(this).setField(table, key, 0, data, fieldLayout); // Expect a revert when the RevertSubscriber's onBeforeDeleteRecord hook is called vm.expectRevert(bytes("onBeforeDeleteRecord")); - IStore(this).deleteRecord(table, key, valueSchema); + IStore(this).deleteRecord(table, key, fieldLayout); // Unregister the RevertSubscriber IStore(this).unregisterStoreHook(table, revertSubscriber); // Expect a HookCalled event to be emitted when the EchoSubscriber's onBeforeSetRecord hook is called vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(table, key, data, valueSchema)); + emit HookCalled(abi.encode(table, key, data, fieldLayout)); // Expect a HookCalled event to be emitted when the EchoSubscriber's onAfterSetRecord hook is called vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(table, key, data, valueSchema)); + emit HookCalled(abi.encode(table, key, data, fieldLayout)); - IStore(this).setRecord(table, key, data, valueSchema); + IStore(this).setRecord(table, key, data, fieldLayout); // Expect a HookCalled event to be emitted when the EchoSubscriber's onBeforeSetField hook is called vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(table, key, uint8(0), data, valueSchema)); + emit HookCalled(abi.encode(table, key, uint8(0), data, fieldLayout)); // Expect a HookCalled event to be emitted when the EchoSubscriber's onAfterSetField hook is called vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(table, key, uint8(0), data, valueSchema)); + emit HookCalled(abi.encode(table, key, uint8(0), data, fieldLayout)); - IStore(this).setField(table, key, 0, data, valueSchema); + IStore(this).setField(table, key, 0, data, fieldLayout); // Expect a HookCalled event to be emitted when the EchoSubscriber's onBeforeDeleteRecord hook is called vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(table, key, valueSchema)); + emit HookCalled(abi.encode(table, key, fieldLayout)); // Expect a HookCalled event to be emitted when the EchoSubscriber's onAfterDeleteRecord hook is called vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(table, key, valueSchema)); + emit HookCalled(abi.encode(table, key, fieldLayout)); - IStore(this).deleteRecord(table, key, valueSchema); + IStore(this).deleteRecord(table, key, fieldLayout); } function testHooksDynamicData() public { @@ -971,13 +1015,15 @@ contract StoreCoreTest is Test, StoreMock { bytes32[] memory key = new bytes32[](1); key[0] = keccak256("some key"); - // Register table's schema + // Register table + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 1); Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT128, SchemaType.UINT32_ARRAY); - IStore(this).registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](2)); + IStore(this).registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](2)); // Create subscriber MirrorSubscriber subscriber = new MirrorSubscriber( table, + fieldLayout, defaultKeySchema, valueSchema, new string[](1), @@ -1005,10 +1051,10 @@ contract StoreCoreTest is Test, StoreMock { bytes memory staticData = abi.encodePacked(bytes16(0x0102030405060708090a0b0c0d0e0f10)); bytes memory data = abi.encodePacked(staticData, dynamicData); - IStore(this).setRecord(table, key, data, valueSchema); + IStore(this).setRecord(table, key, data, fieldLayout); // Get data from indexed table - the indexer should have mirrored the data there - bytes memory indexedData = IStore(this).getRecord(indexerTableId, key, valueSchema); + bytes memory indexedData = IStore(this).getRecord(indexerTableId, key, fieldLayout); assertEq(keccak256(data), keccak256(indexedData)); // Update dynamic data @@ -1017,16 +1063,16 @@ contract StoreCoreTest is Test, StoreMock { dynamicData = abi.encodePacked(encodedArrayDataLength.unwrap(), arrayDataBytes); data = abi.encodePacked(staticData, dynamicData); - IStore(this).setField(table, key, 1, arrayDataBytes, valueSchema); + IStore(this).setField(table, key, 1, arrayDataBytes, fieldLayout); // Get data from indexed table - the indexer should have mirrored the data there - indexedData = IStore(this).getRecord(indexerTableId, key, valueSchema); + indexedData = IStore(this).getRecord(indexerTableId, key, fieldLayout); assertEq(keccak256(data), keccak256(indexedData)); - IStore(this).deleteRecord(table, key, valueSchema); + IStore(this).deleteRecord(table, key, fieldLayout); // Get data from indexed table - the indexer should have mirrored the data there - indexedData = IStore(this).getRecord(indexerTableId, key, valueSchema); + indexedData = IStore(this).getRecord(indexerTableId, key, fieldLayout); assertEq(keccak256(indexedData), keccak256(abi.encodePacked(bytes16(0)))); } } diff --git a/packages/store/test/StoreCoreDynamic.t.sol b/packages/store/test/StoreCoreDynamic.t.sol index 8f94084138..00de8cd813 100644 --- a/packages/store/test/StoreCoreDynamic.t.sol +++ b/packages/store/test/StoreCoreDynamic.t.sol @@ -7,8 +7,10 @@ import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol" import { StoreCore } from "../src/StoreCore.sol"; import { SliceLib } from "../src/Slice.sol"; import { EncodeArray } from "../src/tightcoder/EncodeArray.sol"; +import { FieldLayout } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; import { StoreReadWithStubs } from "../src/StoreReadWithStubs.sol"; +import { FieldLayoutEncodeHelper } from "./FieldLayoutEncodeHelper.sol"; import { SchemaEncodeHelper } from "./SchemaEncodeHelper.sol"; contract StoreCoreDynamicTest is Test, GasReporter, StoreReadWithStubs { @@ -29,19 +31,20 @@ contract StoreCoreDynamicTest is Test, GasReporter, StoreReadWithStubs { bytes32[] calldata key, uint8 schemaIndex, uint256 byteLengthToPop, - Schema valueSchema + FieldLayout fieldLayout ) public override { - StoreCore.popFromField(table, key, schemaIndex, byteLengthToPop, valueSchema); + StoreCore.popFromField(table, key, schemaIndex, byteLengthToPop, fieldLayout); } function setUp() public { // Register table's schema + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(32, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT256, SchemaType.UINT32_ARRAY, SchemaType.UINT32_ARRAY ); - StoreCore.registerTable(_table, defaultKeySchema, valueSchema, new string[](1), new string[](3)); + StoreCore.registerTable(_table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](3)); // Create key _key = new bytes32[](1); @@ -70,14 +73,14 @@ contract StoreCoreDynamicTest is Test, GasReporter, StoreReadWithStubs { thirdDataBytes = EncodeArray.encode(thirdData); // Set fields - StoreCore.setField(_table, _key, 0, abi.encodePacked(firstDataBytes), valueSchema); - StoreCore.setField(_table, _key, 1, secondDataBytes, valueSchema); + StoreCore.setField(_table, _key, 0, abi.encodePacked(firstDataBytes), fieldLayout); + StoreCore.setField(_table, _key, 1, secondDataBytes, fieldLayout); // Initialize a field with push - StoreCore.pushToField(_table, _key, 2, thirdDataBytes, valueSchema); + StoreCore.pushToField(_table, _key, 2, thirdDataBytes, fieldLayout); } function testPopFromSecondField() public { - Schema valueSchema = StoreCore.getValueSchema(_table); + FieldLayout fieldLayout = StoreCore.getFieldLayout(_table); bytes memory dataBytes = secondDataBytes; // Prepare expected data @@ -93,30 +96,30 @@ contract StoreCoreDynamicTest is Test, GasReporter, StoreReadWithStubs { // Pop from second field startGasReport("pop from field (cold, 1 slot, 1 uint32 item)"); - StoreCore.popFromField(_table, _key, 1, byteLengthToPop, valueSchema); + StoreCore.popFromField(_table, _key, 1, byteLengthToPop, fieldLayout); endGasReport(); // Get second field - bytes memory loadedData = StoreCore.getField(_table, _key, 1, valueSchema); + bytes memory loadedData = StoreCore.getField(_table, _key, 1, fieldLayout); // Verify loaded data is correct assertEq(loadedData, newDataBytes); // Reset the second field and pop again (but warm this time) - StoreCore.setField(_table, _key, 1, dataBytes, valueSchema); + StoreCore.setField(_table, _key, 1, dataBytes, fieldLayout); startGasReport("pop from field (warm, 1 slot, 1 uint32 item)"); - StoreCore.popFromField(_table, _key, 1, byteLengthToPop, valueSchema); + StoreCore.popFromField(_table, _key, 1, byteLengthToPop, fieldLayout); endGasReport(); // Get second field - loadedData = StoreCore.getField(_table, _key, 1, valueSchema); + loadedData = StoreCore.getField(_table, _key, 1, fieldLayout); // Verify loaded data is correct assertEq(loadedData, newDataBytes); // Verify none of the other fields were impacted - assertEq(bytes32(StoreCore.getField(_table, _key, 0, valueSchema)), firstDataBytes); - assertEq(StoreCore.getField(_table, _key, 2, valueSchema), thirdDataBytes); + assertEq(bytes32(StoreCore.getField(_table, _key, 0, fieldLayout)), firstDataBytes); + assertEq(StoreCore.getField(_table, _key, 2, fieldLayout), thirdDataBytes); } function testPopFromThirdField() public { - Schema valueSchema = StoreCore.getValueSchema(_table); + FieldLayout fieldLayout = StoreCore.getFieldLayout(_table); bytes memory dataBytes = thirdDataBytes; // Prepare expected data @@ -132,70 +135,70 @@ contract StoreCoreDynamicTest is Test, GasReporter, StoreReadWithStubs { // Pop from the field startGasReport("pop from field (cold, 2 slots, 10 uint32 items)"); - StoreCore.popFromField(_table, _key, 2, byteLengthToPop, valueSchema); + StoreCore.popFromField(_table, _key, 2, byteLengthToPop, fieldLayout); endGasReport(); // Load and verify the field - bytes memory loadedData = StoreCore.getField(_table, _key, 2, valueSchema); + bytes memory loadedData = StoreCore.getField(_table, _key, 2, fieldLayout); assertEq(loadedData, newDataBytes); // Reset the field and pop again (but warm this time) - StoreCore.setField(_table, _key, 2, dataBytes, valueSchema); + StoreCore.setField(_table, _key, 2, dataBytes, fieldLayout); startGasReport("pop from field (warm, 2 slots, 10 uint32 items)"); - StoreCore.popFromField(_table, _key, 2, byteLengthToPop, valueSchema); + StoreCore.popFromField(_table, _key, 2, byteLengthToPop, fieldLayout); endGasReport(); // Load and verify the field - loadedData = StoreCore.getField(_table, _key, 2, valueSchema); + loadedData = StoreCore.getField(_table, _key, 2, fieldLayout); assertEq(loadedData, newDataBytes); // Verify none of the other fields were impacted - assertEq(bytes32(StoreCore.getField(_table, _key, 0, valueSchema)), firstDataBytes); - assertEq(StoreCore.getField(_table, _key, 1, valueSchema), secondDataBytes); + assertEq(bytes32(StoreCore.getField(_table, _key, 0, fieldLayout)), firstDataBytes); + assertEq(StoreCore.getField(_table, _key, 1, fieldLayout), secondDataBytes); } function testGetSecondFieldLength() public { - Schema valueSchema = StoreCore.getValueSchema(_table); + FieldLayout fieldLayout = StoreCore.getFieldLayout(_table); startGasReport("get field length (cold, 1 slot)"); - uint256 length = StoreCore.getFieldLength(_table, _key, 1, valueSchema); + uint256 length = StoreCore.getFieldLength(_table, _key, 1, fieldLayout); endGasReport(); assertEq(length, secondDataBytes.length); startGasReport("get field length (warm, 1 slot)"); - length = StoreCore.getFieldLength(_table, _key, 1, valueSchema); + length = StoreCore.getFieldLength(_table, _key, 1, fieldLayout); endGasReport(); assertEq(length, secondDataBytes.length); } function testGetThirdFieldLength() public { - Schema valueSchema = StoreCore.getValueSchema(_table); + FieldLayout fieldLayout = StoreCore.getFieldLayout(_table); startGasReport("get field length (warm due to , 2 slots)"); - uint256 length = StoreCore.getFieldLength(_table, _key, 2, valueSchema); + uint256 length = StoreCore.getFieldLength(_table, _key, 2, fieldLayout); endGasReport(); assertEq(length, thirdDataBytes.length); startGasReport("get field length (warm, 2 slots)"); - length = StoreCore.getFieldLength(_table, _key, 2, valueSchema); + length = StoreCore.getFieldLength(_table, _key, 2, fieldLayout); endGasReport(); assertEq(length, thirdDataBytes.length); } function testGetFieldSlice() public { - Schema valueSchema = StoreCore.getValueSchema(_table); + FieldLayout fieldLayout = StoreCore.getFieldLayout(_table); startGasReport("get field slice (cold, 1 slot)"); - bytes memory secondFieldSlice = StoreCore.getFieldSlice(_table, _key, 1, valueSchema, 0, 4); + bytes memory secondFieldSlice = StoreCore.getFieldSlice(_table, _key, 1, fieldLayout, 0, 4); endGasReport(); assertEq(secondFieldSlice, SliceLib.getSubslice(secondDataBytes, 0, 4).toBytes()); startGasReport("get field slice (warm, 1 slot)"); - secondFieldSlice = StoreCore.getFieldSlice(_table, _key, 1, valueSchema, 4, 8); + secondFieldSlice = StoreCore.getFieldSlice(_table, _key, 1, fieldLayout, 4, 8); endGasReport(); assertEq(secondFieldSlice, SliceLib.getSubslice(secondDataBytes, 4, 8).toBytes()); startGasReport("get field slice (semi-cold, 1 slot)"); - bytes memory thirdFieldSlice = StoreCore.getFieldSlice(_table, _key, 2, valueSchema, 4, 32); + bytes memory thirdFieldSlice = StoreCore.getFieldSlice(_table, _key, 2, fieldLayout, 4, 32); endGasReport(); assertEq(thirdFieldSlice, SliceLib.getSubslice(thirdDataBytes, 4, 32).toBytes()); startGasReport("get field slice (warm, 2 slots)"); - thirdFieldSlice = StoreCore.getFieldSlice(_table, _key, 2, valueSchema, 8, 40); + thirdFieldSlice = StoreCore.getFieldSlice(_table, _key, 2, fieldLayout, 8, 40); endGasReport(); assertEq(thirdFieldSlice, SliceLib.getSubslice(thirdDataBytes, 8, 40).toBytes()); } diff --git a/packages/store/test/StoreCoreGas.t.sol b/packages/store/test/StoreCoreGas.t.sol index ace0c8141f..ba47a49fe8 100644 --- a/packages/store/test/StoreCoreGas.t.sol +++ b/packages/store/test/StoreCoreGas.t.sol @@ -8,11 +8,13 @@ import { StoreCore, StoreCoreInternal } from "../src/StoreCore.sol"; import { Bytes } from "../src/Bytes.sol"; import { SliceLib } from "../src/Slice.sol"; import { EncodeArray } from "../src/tightcoder/EncodeArray.sol"; +import { FieldLayout } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "../src/PackedCounter.sol"; import { StoreReadWithStubs } from "../src/StoreReadWithStubs.sol"; import { IStoreErrors } from "../src/IStoreErrors.sol"; import { IStore } from "../src/IStore.sol"; +import { FieldLayoutEncodeHelper } from "./FieldLayoutEncodeHelper.sol"; import { StoreHookLib } from "../src/StoreHook.sol"; import { SchemaEncodeHelper } from "./SchemaEncodeHelper.sol"; import { StoreMock } from "./StoreMock.sol"; @@ -30,7 +32,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { mapping(uint256 => bytes) private testMapping; Schema defaultKeySchema = SchemaEncodeHelper.encode(SchemaType.BYTES32); - function testRegisterAndGetSchema() public { + function testRegisterAndGetFieldLayout() public { + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 1, 2, 0); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT8, SchemaType.UINT16, @@ -49,8 +52,12 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { fieldNames[2] = "value3"; fieldNames[3] = "value4"; - startGasReport("StoreCore: register schema"); - StoreCore.registerTable(table, keySchema, valueSchema, keyNames, fieldNames); + startGasReport("StoreCore: register table"); + StoreCore.registerTable(table, fieldLayout, keySchema, valueSchema, keyNames, fieldNames); + endGasReport(); + + startGasReport("StoreCore: get field layout (warm)"); + StoreCore.getFieldLayout(table); endGasReport(); startGasReport("StoreCore: get schema (warm)"); @@ -62,16 +69,17 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { endGasReport(); } - function testHasSchema() public { + function testHasFieldLayout() public { Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT8, SchemaType.UINT16, SchemaType.UINT8, SchemaType.UINT16 ); + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 1, 2, 0); bytes32 table = keccak256("some.table"); bytes32 table2 = keccak256("other.table"); - StoreCore.registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](4)); + StoreCore.registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](4)); startGasReport("Check for existence of table (existent)"); StoreCore.hasTable(table); @@ -93,8 +101,10 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { SchemaType.UINT32_ARRAY ); + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 4, 2); + // Register schema - StoreCore.registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](5)); + StoreCore.registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](5)); // Create some key bytes32[] memory key = new bytes32[](1); @@ -124,8 +134,9 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { SchemaType.UINT8, SchemaType.UINT16 ); + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 1, 2, 0); bytes32 table = keccak256("some.table"); - StoreCore.registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](4)); + StoreCore.registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](4)); // Set data bytes memory data = abi.encodePacked(bytes1(0x01), bytes2(0x0203), bytes1(0x04), bytes2(0x0506)); @@ -133,20 +144,21 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { key[0] = keccak256("some.key"); startGasReport("set static record (1 slot)"); - StoreCore.setRecord(table, key, data, valueSchema); + StoreCore.setRecord(table, key, data, fieldLayout); endGasReport(); // Get data startGasReport("get static record (1 slot)"); - StoreCore.getRecord(table, key, valueSchema); + StoreCore.getRecord(table, key, fieldLayout); endGasReport(); } function testSetAndGetStaticDataSpanningWords() public { // Register table's schema Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT128, SchemaType.UINT256); + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 32, 0); bytes32 table = keccak256("some.table"); - StoreCore.registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](2)); + StoreCore.registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](2)); // Set data bytes memory data = abi.encodePacked( @@ -158,12 +170,12 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { key[0] = keccak256("some.key"); startGasReport("set static record (2 slots)"); - StoreCore.setRecord(table, key, data, valueSchema); + StoreCore.setRecord(table, key, data, fieldLayout); endGasReport(); // Get data startGasReport("get static record (2 slots)"); - StoreCore.getRecord(table, key, valueSchema); + StoreCore.getRecord(table, key, fieldLayout); endGasReport(); } @@ -171,12 +183,13 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { bytes32 table = keccak256("some.table"); // Register table's schema + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT128, SchemaType.UINT32_ARRAY, SchemaType.UINT32_ARRAY ); - StoreCore.registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](3)); + StoreCore.registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](3)); bytes16 firstDataBytes = bytes16(0x0102030405060708090a0b0c0d0e0f10); @@ -216,12 +229,12 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { // Set data startGasReport("set complex record with dynamic data (4 slots)"); - StoreCore.setRecord(table, key, data, valueSchema); + StoreCore.setRecord(table, key, data, fieldLayout); endGasReport(); // Get data startGasReport("get complex record with dynamic data (4 slots)"); - StoreCore.getRecord(table, key, valueSchema); + StoreCore.getRecord(table, key, fieldLayout); endGasReport(); // Compare gas - setting the data as raw struct @@ -246,13 +259,14 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { bytes32 table = keccak256("some.table"); // Register table's schema + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 32, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT128, SchemaType.UINT256, SchemaType.UINT32_ARRAY, SchemaType.UINT32_ARRAY ); - StoreCore.registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](4)); + StoreCore.registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](4)); bytes16 firstDataBytes = bytes16(0x0102030405060708090a0b0c0d0e0f10); @@ -264,7 +278,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { // Set first field startGasReport("set static field (1 slot)"); - StoreCore.setField(table, key, 0, firstDataPacked, valueSchema); + StoreCore.setField(table, key, 0, firstDataPacked, fieldLayout); endGasReport(); //////////////// @@ -273,7 +287,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { // Get first field startGasReport("get static field (1 slot)"); - StoreCore.getField(table, key, 0, valueSchema); + StoreCore.getField(table, key, 0, fieldLayout); endGasReport(); // Set second field @@ -281,12 +295,12 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { bytes memory secondDataPacked = abi.encodePacked(secondDataBytes); startGasReport("set static field (overlap 2 slot)"); - StoreCore.setField(table, key, 1, secondDataPacked, valueSchema); + StoreCore.setField(table, key, 1, secondDataPacked, fieldLayout); endGasReport(); // Get second field startGasReport("get static field (overlap 2 slot)"); - StoreCore.getField(table, key, 1, valueSchema); + StoreCore.getField(table, key, 1, fieldLayout); endGasReport(); //////////////// @@ -312,22 +326,22 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { // Set third field startGasReport("set dynamic field (1 slot, first dynamic field)"); - StoreCore.setField(table, key, 2, thirdDataBytes, valueSchema); + StoreCore.setField(table, key, 2, thirdDataBytes, fieldLayout); endGasReport(); // Get third field startGasReport("get dynamic field (1 slot, first dynamic field)"); - StoreCore.getField(table, key, 2, valueSchema); + StoreCore.getField(table, key, 2, fieldLayout); endGasReport(); // Set fourth field startGasReport("set dynamic field (1 slot, second dynamic field)"); - StoreCore.setField(table, key, 3, fourthDataBytes, valueSchema); + StoreCore.setField(table, key, 3, fourthDataBytes, fieldLayout); endGasReport(); // Get fourth field startGasReport("get dynamic field (1 slot, second dynamic field)"); - StoreCore.getField(table, key, 3, valueSchema); + StoreCore.getField(table, key, 3, fieldLayout); endGasReport(); } @@ -335,12 +349,13 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { bytes32 table = keccak256("some.table"); // Register table's schema + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT128, SchemaType.UINT32_ARRAY, SchemaType.UINT32_ARRAY ); - StoreCore.registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](3)); + StoreCore.registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](3)); bytes16 firstDataBytes = bytes16(0x0102030405060708090a0b0c0d0e0f10); @@ -379,11 +394,11 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { key[0] = bytes32("some.key"); // Set data - StoreCore.setRecord(table, key, data, valueSchema); + StoreCore.setRecord(table, key, data, fieldLayout); // Delete data startGasReport("delete record (complex data, 3 slots)"); - StoreCore.deleteRecord(table, key, valueSchema); + StoreCore.deleteRecord(table, key, fieldLayout); endGasReport(); } @@ -391,12 +406,13 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { bytes32 table = keccak256("some.table"); // Register table's schema + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(32, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT256, SchemaType.UINT32_ARRAY, SchemaType.UINT32_ARRAY ); - StoreCore.registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](3)); + StoreCore.registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](3)); // Create key bytes32[] memory key = new bytes32[](1); @@ -421,10 +437,10 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { } // Set fields - StoreCore.setField(table, key, 0, abi.encodePacked(firstDataBytes), valueSchema); - StoreCore.setField(table, key, 1, secondDataBytes, valueSchema); + StoreCore.setField(table, key, 0, abi.encodePacked(firstDataBytes), fieldLayout); + StoreCore.setField(table, key, 1, secondDataBytes, fieldLayout); // Initialize a field with push - StoreCore.pushToField(table, key, 2, thirdDataBytes, valueSchema); + StoreCore.pushToField(table, key, 2, thirdDataBytes, fieldLayout); // Create data to push bytes memory secondDataToPush; @@ -436,7 +452,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { // Push to second field startGasReport("push to field (1 slot, 1 uint32 item)"); - StoreCore.pushToField(table, key, 1, secondDataToPush, valueSchema); + StoreCore.pushToField(table, key, 1, secondDataToPush, fieldLayout); endGasReport(); // Create data to push @@ -458,7 +474,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { // Push to third field startGasReport("push to field (2 slots, 10 uint32 items)"); - StoreCore.pushToField(table, key, 2, thirdDataToPush, valueSchema); + StoreCore.pushToField(table, key, 2, thirdDataToPush, fieldLayout); endGasReport(); } @@ -477,12 +493,13 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { bytes32 table = keccak256("some.table"); // Register table's schema + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(32, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT256, SchemaType.UINT32_ARRAY, SchemaType.UINT64_ARRAY ); - StoreCore.registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](3)); + StoreCore.registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](3)); // Create key bytes32[] memory key = new bytes32[](1); @@ -505,9 +522,9 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { data.thirdDataBytes = EncodeArray.encode(thirdData); // Set fields - StoreCore.setField(table, key, 0, abi.encodePacked(data.firstDataBytes), valueSchema); - StoreCore.setField(table, key, 1, data.secondDataBytes, valueSchema); - StoreCore.setField(table, key, 2, data.thirdDataBytes, valueSchema); + StoreCore.setField(table, key, 0, abi.encodePacked(data.firstDataBytes), fieldLayout); + StoreCore.setField(table, key, 1, data.secondDataBytes, fieldLayout); + StoreCore.setField(table, key, 2, data.thirdDataBytes, fieldLayout); // Create data to use for the update { @@ -520,7 +537,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { // Update index 1 in second field (4 = byte length of uint32) startGasReport("update in field (1 slot, 1 uint32 item)"); - StoreCore.updateInField(table, key, 1, 4 * 1, data.secondDataForUpdate, valueSchema); + StoreCore.updateInField(table, key, 1, 4 * 1, data.secondDataForUpdate, fieldLayout); endGasReport(); // Create data for update @@ -544,38 +561,39 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { // Update indexes 1,2,3,4 in third field (8 = byte length of uint64) startGasReport("push to field (2 slots, 6 uint64 items)"); - StoreCore.updateInField(table, key, 2, 8 * 1, data.thirdDataForUpdate, valueSchema); + StoreCore.updateInField(table, key, 2, 8 * 1, data.thirdDataForUpdate, fieldLayout); endGasReport(); } function testAccessEmptyData() public { bytes32 table = keccak256("some.table"); + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(4, 1); Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT32, SchemaType.UINT32_ARRAY); - StoreCore.registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](2)); + StoreCore.registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](2)); // Create key bytes32[] memory key = new bytes32[](1); key[0] = bytes32("some.key"); startGasReport("access non-existing record"); - StoreCore.getRecord(table, key, valueSchema); + StoreCore.getRecord(table, key, fieldLayout); endGasReport(); startGasReport("access static field of non-existing record"); - StoreCore.getField(table, key, 0, valueSchema); + StoreCore.getField(table, key, 0, fieldLayout); endGasReport(); startGasReport("access dynamic field of non-existing record"); - StoreCore.getField(table, key, 1, valueSchema); + StoreCore.getField(table, key, 1, fieldLayout); endGasReport(); startGasReport("access length of dynamic field of non-existing record"); - StoreCore.getFieldLength(table, key, 1, valueSchema); + StoreCore.getFieldLength(table, key, 1, fieldLayout); endGasReport(); startGasReport("access slice of dynamic field of non-existing record"); - StoreCore.getFieldSlice(table, key, 1, valueSchema, 0, 0); + StoreCore.getFieldSlice(table, key, 1, fieldLayout, 0, 0); endGasReport(); } @@ -585,12 +603,14 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { key[0] = keccak256("some key"); // Register table's schema + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 0); Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT128); - StoreCore.registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](1)); + StoreCore.registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](1)); // Create subscriber MirrorSubscriber subscriber = new MirrorSubscriber( table, + fieldLayout, defaultKeySchema, valueSchema, new string[](1), @@ -615,17 +635,17 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { bytes memory data = abi.encodePacked(bytes16(0x0102030405060708090a0b0c0d0e0f10)); startGasReport("set record on table with subscriber"); - StoreCore.setRecord(table, key, data, valueSchema); + StoreCore.setRecord(table, key, data, fieldLayout); endGasReport(); data = abi.encodePacked(bytes16(0x1112131415161718191a1b1c1d1e1f20)); startGasReport("set static field on table with subscriber"); - StoreCore.setField(table, key, 0, data, valueSchema); + StoreCore.setField(table, key, 0, data, fieldLayout); endGasReport(); startGasReport("delete record on table with subscriber"); - StoreCore.deleteRecord(table, key, valueSchema); + StoreCore.deleteRecord(table, key, fieldLayout); endGasReport(); } @@ -635,12 +655,14 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { key[0] = keccak256("some key"); // Register table's schema + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 1); Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT128, SchemaType.UINT32_ARRAY); - StoreCore.registerTable(table, defaultKeySchema, valueSchema, new string[](1), new string[](2)); + StoreCore.registerTable(table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](2)); // Create subscriber MirrorSubscriber subscriber = new MirrorSubscriber( table, + fieldLayout, defaultKeySchema, valueSchema, new string[](1), @@ -671,7 +693,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { bytes memory data = abi.encodePacked(staticData, dynamicData); startGasReport("set (dynamic) record on table with subscriber"); - StoreCore.setRecord(table, key, data, valueSchema); + StoreCore.setRecord(table, key, data, fieldLayout); endGasReport(); // Update dynamic data @@ -681,11 +703,11 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { data = abi.encodePacked(staticData, dynamicData); startGasReport("set (dynamic) field on table with subscriber"); - StoreCore.setField(table, key, 1, arrayDataBytes, valueSchema); + StoreCore.setField(table, key, 1, arrayDataBytes, fieldLayout); endGasReport(); startGasReport("delete (dynamic) record on table with subscriber"); - StoreCore.deleteRecord(table, key, valueSchema); + StoreCore.deleteRecord(table, key, fieldLayout); endGasReport(); } } diff --git a/packages/store/test/StoreHook.t.sol b/packages/store/test/StoreHook.t.sol index fe35a244b2..56950bd351 100644 --- a/packages/store/test/StoreHook.t.sol +++ b/packages/store/test/StoreHook.t.sol @@ -11,7 +11,7 @@ import { Hook } from "../src/Hook.sol"; import { StoreHookType } from "../src/StoreHook.sol"; import { StoreHookLib } from "../src/StoreHook.sol"; import { IStoreHook } from "../src/IStore.sol"; -import { Schema } from "../src/Schema.sol"; +import { FieldLayout } from "../src/FieldLayout.sol"; contract StoreHookTest is Test, GasReporter { event HookCalled(bytes); @@ -22,8 +22,7 @@ contract StoreHookTest is Test, GasReporter { bytes32 private tableId = "table"; bytes32[] private key = new bytes32[](1); bytes private data = "data"; - uint8 private schemaIndex = 1; - Schema private valueSchema = Schema.wrap(0); + FieldLayout private fieldLayout = FieldLayout.wrap(0); function testEncodeBitmap() public { assertEq( @@ -280,10 +279,10 @@ contract StoreHookTest is Test, GasReporter { ); vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(tableId, key, data, valueSchema)); + emit HookCalled(abi.encode(tableId, key, data, fieldLayout)); startGasReport("call an enabled hook"); if (storeHook.isEnabled(uint8(StoreHookType.BEFORE_SET_RECORD))) { - IStoreHook(storeHook.getAddress()).onBeforeSetRecord(tableId, key, data, valueSchema); + IStoreHook(storeHook.getAddress()).onBeforeSetRecord(tableId, key, data, fieldLayout); } endGasReport(); @@ -302,7 +301,7 @@ contract StoreHookTest is Test, GasReporter { // Expect the to not be called - otherwise the test will fail with a revert startGasReport("call a disabled hook"); if (revertHook.isEnabled(uint8(StoreHookType.BEFORE_SET_RECORD))) { - IStoreHook(revertHook.getAddress()).onBeforeSetRecord(tableId, key, data, valueSchema); + IStoreHook(revertHook.getAddress()).onBeforeSetRecord(tableId, key, data, fieldLayout); } endGasReport(); } diff --git a/packages/store/test/StoreMock.sol b/packages/store/test/StoreMock.sol index 3974dc6ed0..c0535f6368 100644 --- a/packages/store/test/StoreMock.sol +++ b/packages/store/test/StoreMock.sol @@ -2,8 +2,9 @@ pragma solidity >=0.8.0; import { IStore, IStoreHook } from "../src/IStore.sol"; -import { StoreCore } from "../src/StoreCore.sol"; import { Schema } from "../src/Schema.sol"; +import { StoreCore } from "../src/StoreCore.sol"; +import { FieldLayout } from "../src/FieldLayout.sol"; import { StoreRead } from "../src/StoreRead.sol"; /** @@ -11,8 +12,8 @@ import { StoreRead } from "../src/StoreRead.sol"; */ contract StoreMock is IStore, StoreRead { // Set full record (including full dynamic data) - function setRecord(bytes32 table, bytes32[] calldata key, bytes calldata data, Schema valueSchema) public { - StoreCore.setRecord(table, key, data, valueSchema); + function setRecord(bytes32 table, bytes32[] calldata key, bytes calldata data, FieldLayout fieldLayout) public { + StoreCore.setRecord(table, key, data, fieldLayout); } // Set partial data at schema index @@ -21,9 +22,9 @@ contract StoreMock is IStore, StoreRead { bytes32[] calldata key, uint8 schemaIndex, bytes calldata data, - Schema valueSchema + FieldLayout fieldLayout ) public { - StoreCore.setField(table, key, schemaIndex, data, valueSchema); + StoreCore.setField(table, key, schemaIndex, data, fieldLayout); } // Push encoded items to the dynamic field at schema index @@ -32,9 +33,9 @@ contract StoreMock is IStore, StoreRead { bytes32[] calldata key, uint8 schemaIndex, bytes calldata dataToPush, - Schema valueSchema + FieldLayout fieldLayout ) public { - StoreCore.pushToField(table, key, schemaIndex, dataToPush, valueSchema); + StoreCore.pushToField(table, key, schemaIndex, dataToPush, fieldLayout); } // Pop byte length from the dynamic field at schema index @@ -43,9 +44,9 @@ contract StoreMock is IStore, StoreRead { bytes32[] calldata key, uint8 schemaIndex, uint256 byteLengthToPop, - Schema valueSchema + FieldLayout fieldLayout ) public { - StoreCore.popFromField(table, key, schemaIndex, byteLengthToPop, valueSchema); + StoreCore.popFromField(table, key, schemaIndex, byteLengthToPop, fieldLayout); } // Change encoded items within the dynamic field at schema index @@ -55,29 +56,35 @@ contract StoreMock is IStore, StoreRead { uint8 schemaIndex, uint256 startByteIndex, bytes calldata dataToSet, - Schema valueSchema + FieldLayout fieldLayout ) public { - StoreCore.updateInField(table, key, schemaIndex, startByteIndex, dataToSet, valueSchema); + StoreCore.updateInField(table, key, schemaIndex, startByteIndex, dataToSet, fieldLayout); } // Set full record (including full dynamic data) - function deleteRecord(bytes32 table, bytes32[] memory key, Schema valueSchema) public { - StoreCore.deleteRecord(table, key, valueSchema); + function deleteRecord(bytes32 table, bytes32[] memory key, FieldLayout fieldLayout) public { + StoreCore.deleteRecord(table, key, fieldLayout); } // Emit the ephemeral event without modifying storage - function emitEphemeralRecord(bytes32 table, bytes32[] calldata key, bytes calldata data, Schema valueSchema) public { - StoreCore.emitEphemeralRecord(table, key, data, valueSchema); + function emitEphemeralRecord( + bytes32 table, + bytes32[] calldata key, + bytes calldata data, + FieldLayout fieldLayout + ) public { + StoreCore.emitEphemeralRecord(table, key, data, fieldLayout); } function registerTable( bytes32 table, + FieldLayout fieldLayout, Schema keySchema, Schema valueSchema, string[] calldata keyNames, string[] calldata fieldNames ) public { - StoreCore.registerTable(table, keySchema, valueSchema, keyNames, fieldNames); + StoreCore.registerTable(table, fieldLayout, keySchema, valueSchema, keyNames, fieldNames); } // Register hook to be called when a record or field is set or deleted diff --git a/packages/store/test/Vector2.t.sol b/packages/store/test/Vector2.t.sol index a10aafcc72..d834b28971 100644 --- a/packages/store/test/Vector2.t.sol +++ b/packages/store/test/Vector2.t.sol @@ -6,14 +6,24 @@ import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { Vector2, Vector2Data, Vector2TableId } from "../src/codegen/Tables.sol"; import { StoreCore } from "../src/StoreCore.sol"; import { StoreReadWithStubs } from "../src/StoreReadWithStubs.sol"; +import { FieldLayout } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; contract Vector2Test is Test, GasReporter, StoreReadWithStubs { - function testRegisterAndGetSchema() public { - startGasReport("register Vector2 schema"); + function testRegisterAndGetFieldLayout() public { + startGasReport("register Vector2 field layout"); Vector2.register(); endGasReport(); + FieldLayout registeredFieldLayout = StoreCore.getFieldLayout(Vector2TableId); + FieldLayout declaredFieldLayout = Vector2.getFieldLayout(); + + assertEq(FieldLayout.unwrap(registeredFieldLayout), FieldLayout.unwrap(declaredFieldLayout)); + } + + function testRegisterAndGetSchema() public { + Vector2.register(); + Schema registeredSchema = StoreCore.getValueSchema(Vector2TableId); Schema declaredSchema = Vector2.getValueSchema(); diff --git a/packages/store/test/tightcoder/TightCoder.t.sol b/packages/store/test/tightcoder/TightCoder.t.sol index 5803407e88..b664f80920 100644 --- a/packages/store/test/tightcoder/TightCoder.t.sol +++ b/packages/store/test/tightcoder/TightCoder.t.sol @@ -3,7 +3,6 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; -import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; import { SliceLib } from "../../src/Slice.sol"; import { EncodeArray } from "../../src/tightcoder/EncodeArray.sol"; diff --git a/packages/store/ts/codegen/ephemeral.ts b/packages/store/ts/codegen/ephemeral.ts index 21759a1c74..d3a0a92458 100644 --- a/packages/store/ts/codegen/ephemeral.ts +++ b/packages/store/ts/codegen/ephemeral.ts @@ -19,7 +19,7 @@ export function renderEphemeralMethods(options: RenderTableOptions) { ${_keyTupleDefinition} - ${_store}.emitEphemeralRecord(_tableId, _keyTuple, _data, getValueSchema()); + ${_store}.emitEphemeralRecord(_tableId, _keyTuple, _data, getFieldLayout()); } ` ); diff --git a/packages/store/ts/codegen/field.ts b/packages/store/ts/codegen/field.ts index 928a68750b..29f74789f0 100644 --- a/packages/store/ts/codegen/field.ts +++ b/packages/store/ts/codegen/field.ts @@ -25,7 +25,7 @@ export function renderFieldMethods(options: RenderTableOptions) { _typedKeyArgs, ])}) internal view returns (${_typedFieldName}) { ${_keyTupleDefinition} - bytes memory _blob = ${_store}.getField(_tableId, _keyTuple, ${schemaIndex}, getValueSchema()); + bytes memory _blob = ${_store}.getField(_tableId, _keyTuple, ${schemaIndex}, getFieldLayout()); return ${renderDecodeFieldSingle(field)}; } ` @@ -42,7 +42,7 @@ export function renderFieldMethods(options: RenderTableOptions) { _typedFieldName, ])}) internal { ${_keyTupleDefinition} - ${_store}.setField(_tableId, _keyTuple, ${schemaIndex}, ${renderEncodeFieldSingle(field)}, getValueSchema()); + ${_store}.setField(_tableId, _keyTuple, ${schemaIndex}, ${renderEncodeFieldSingle(field)}, getFieldLayout()); } ` ); @@ -60,7 +60,7 @@ export function renderFieldMethods(options: RenderTableOptions) { _typedKeyArgs, ])}) internal view returns (uint256) { ${_keyTupleDefinition} - uint256 _byteLength = ${_store}.getFieldLength(_tableId, _keyTuple, ${schemaIndex}, getValueSchema()); + uint256 _byteLength = ${_store}.getFieldLength(_tableId, _keyTuple, ${schemaIndex}, getFieldLayout()); unchecked { return _byteLength / ${portionData.elementLength}; } @@ -87,7 +87,7 @@ export function renderFieldMethods(options: RenderTableOptions) { _tableId, _keyTuple, ${schemaIndex}, - getValueSchema(), + getFieldLayout(), _index * ${portionData.elementLength}, (_index + 1) * ${portionData.elementLength} ); @@ -108,7 +108,7 @@ export function renderFieldMethods(options: RenderTableOptions) { `${portionData.typeWithLocation} ${portionData.name}`, ])}) internal { ${_keyTupleDefinition} - ${_store}.pushToField(_tableId, _keyTuple, ${schemaIndex}, ${portionData.encoded}, getValueSchema()); + ${_store}.pushToField(_tableId, _keyTuple, ${schemaIndex}, ${portionData.encoded}, getFieldLayout()); } ` ); @@ -123,7 +123,7 @@ export function renderFieldMethods(options: RenderTableOptions) { _typedKeyArgs, ])}) internal { ${_keyTupleDefinition} - ${_store}.popFromField(_tableId, _keyTuple, ${schemaIndex}, ${portionData.elementLength}, getValueSchema()); + ${_store}.popFromField(_tableId, _keyTuple, ${schemaIndex}, ${portionData.elementLength}, getFieldLayout()); } ` ); @@ -150,7 +150,7 @@ export function renderFieldMethods(options: RenderTableOptions) { ${schemaIndex}, _index * ${portionData.elementLength}, ${portionData.encoded}, - getValueSchema() + getFieldLayout() ); } } diff --git a/packages/store/ts/codegen/record.ts b/packages/store/ts/codegen/record.ts index d2182eb8f3..7cfccd77f6 100644 --- a/packages/store/ts/codegen/record.ts +++ b/packages/store/ts/codegen/record.ts @@ -22,7 +22,7 @@ export function renderRecordMethods(options: RenderTableOptions) { _typedKeyArgs, ])}) internal view returns (${renderDecodedRecord(options)}) { ${_keyTupleDefinition} - bytes memory _blob = ${_store}.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = ${_store}.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } ` @@ -42,7 +42,7 @@ export function renderRecordMethods(options: RenderTableOptions) { ${_keyTupleDefinition} - ${_store}.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + ${_store}.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } ` ); @@ -95,7 +95,7 @@ function renderDecodeFunction({ structName, fields, staticFields, dynamicFields // decode static (optionally) and dynamic data return ` /** - * Decode the tightly packed blob using this table's schema. + * Decode the tightly packed blob using this table's field layout. * Undefined behaviour for invalid blobs. */ function decode(bytes memory _blob) internal pure returns (${renderedDecodedRecord}) { @@ -142,7 +142,7 @@ function renderDecodeFunction({ structName, fields, staticFields, dynamicFields } else { // decode only static data return ` - /** Decode the tightly packed blob using this table's schema */ + /** Decode the tightly packed blob using this table's field layout */ function decode(bytes memory _blob) internal pure returns (${renderedDecodedRecord}) { ${renderList( staticFields, diff --git a/packages/store/ts/codegen/renderTable.ts b/packages/store/ts/codegen/renderTable.ts index a4df23466a..31187893f5 100644 --- a/packages/store/ts/codegen/renderTable.ts +++ b/packages/store/ts/codegen/renderTable.ts @@ -5,7 +5,6 @@ import { renderedSolidityHeader, renderRelativeImports, renderTableId, - renderValueTypeToBytes32, renderWithStore, renderTypeHelpers, RenderDynamicField, @@ -48,6 +47,7 @@ import { Bytes } from "${storeImportPath}Bytes.sol"; import { Memory } from "${storeImportPath}Memory.sol"; import { SliceLib } from "${storeImportPath}Slice.sol"; import { EncodeArray } from "${storeImportPath}tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "${storeImportPath}FieldLayout.sol"; import { Schema, SchemaLib } from "${storeImportPath}Schema.sol"; import { PackedCounter, PackedCounterLib } from "${storeImportPath}PackedCounter.sol"; @@ -73,6 +73,14 @@ ${ } library ${libraryName} { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](${staticFields.length}); + ${renderList(staticFields, ({ staticByteLength }, index) => `_fieldLayout[${index}] = ${staticByteLength};`)} + + return FieldLayoutLib.encode(_fieldLayout, ${dynamicFields.length}); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](${keyTuple.length}); @@ -104,9 +112,9 @@ library ${libraryName} { ${renderWithStore( storeArgument, (_typedStore, _store, _commentSuffix) => ` - /** Register the table's key schema, value schema, key names and value names${_commentSuffix} */ + /** Register the table with its config${_commentSuffix} */ function register(${renderArguments([_typedStore, _typedTableId])}) internal { - ${_store}.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + ${_store}.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } ` )} @@ -117,7 +125,7 @@ library ${libraryName} { ${withEphemeralMethods ? renderEphemeralMethods(options) : ""} - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(${renderArguments( options.fields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`) )}) internal pure returns (bytes memory) { @@ -130,7 +138,7 @@ library ${libraryName} { ])}); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(${renderArguments([_typedKeyArgs])}) internal pure returns (bytes32[] memory) { ${_keyTupleDefinition} return _keyTuple; @@ -144,7 +152,7 @@ library ${libraryName} { /* Delete all data for given keys${_commentSuffix} */ function deleteRecord(${renderArguments([_typedStore, _typedTableId, _typedKeyArgs])}) internal { ${_keyTupleDefinition} - ${_store}.deleteRecord(_tableId, _keyTuple, getValueSchema()); + ${_store}.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } ` ) diff --git a/packages/world/abi/AccessManagementSystem.sol/AccessManagementSystem.abi.json b/packages/world/abi/AccessManagementSystem.sol/AccessManagementSystem.abi.json index ef43178b6f..1455bc1a9e 100644 --- a/packages/world/abi/AccessManagementSystem.sol/AccessManagementSystem.abi.json +++ b/packages/world/abi/AccessManagementSystem.sol/AccessManagementSystem.abi.json @@ -23,7 +23,17 @@ "type": "uint256" } ], - "name": "PackedCounter_InvalidLength", + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", "type": "error" }, { @@ -34,12 +44,7 @@ "type": "uint256" } ], - "name": "SchemaLib_InvalidLength", - "type": "error" - }, - { - "inputs": [], - "name": "SchemaLib_StaticTypeAfterDynamicType", + "name": "PackedCounter_InvalidLength", "type": "error" }, { diff --git a/packages/world/abi/AccessManagementSystem.sol/AccessManagementSystem.abi.json.d.ts b/packages/world/abi/AccessManagementSystem.sol/AccessManagementSystem.abi.json.d.ts index 7bdaba9c70..8c85f7b821 100644 --- a/packages/world/abi/AccessManagementSystem.sol/AccessManagementSystem.abi.json.d.ts +++ b/packages/world/abi/AccessManagementSystem.sol/AccessManagementSystem.abi.json.d.ts @@ -23,7 +23,17 @@ declare const abi: [ type: "uint256"; } ]; - name: "PackedCounter_InvalidLength"; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; type: "error"; }, { @@ -34,12 +44,7 @@ declare const abi: [ type: "uint256"; } ]; - name: "SchemaLib_InvalidLength"; - type: "error"; - }, - { - inputs: []; - name: "SchemaLib_StaticTypeAfterDynamicType"; + name: "PackedCounter_InvalidLength"; type: "error"; }, { diff --git a/packages/world/abi/BalanceTransferSystem.sol/BalanceTransferSystem.abi.json b/packages/world/abi/BalanceTransferSystem.sol/BalanceTransferSystem.abi.json index a50016d9d9..6053b3e357 100644 --- a/packages/world/abi/BalanceTransferSystem.sol/BalanceTransferSystem.abi.json +++ b/packages/world/abi/BalanceTransferSystem.sol/BalanceTransferSystem.abi.json @@ -31,6 +31,27 @@ "name": "DelegationNotFound", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", + "type": "error" + }, { "inputs": [ { @@ -140,22 +161,6 @@ "name": "ResourceNotFound", "type": "error" }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "length", - "type": "uint256" - } - ], - "name": "SchemaLib_InvalidLength", - "type": "error" - }, - { - "inputs": [], - "name": "SchemaLib_StaticTypeAfterDynamicType", - "type": "error" - }, { "inputs": [ { diff --git a/packages/world/abi/BalanceTransferSystem.sol/BalanceTransferSystem.abi.json.d.ts b/packages/world/abi/BalanceTransferSystem.sol/BalanceTransferSystem.abi.json.d.ts index 7e36d4bc4d..fc9e3b5c12 100644 --- a/packages/world/abi/BalanceTransferSystem.sol/BalanceTransferSystem.abi.json.d.ts +++ b/packages/world/abi/BalanceTransferSystem.sol/BalanceTransferSystem.abi.json.d.ts @@ -31,6 +31,27 @@ declare const abi: [ name: "DelegationNotFound"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "length"; + type: "uint256"; + } + ]; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; + type: "error"; + }, { inputs: [ { @@ -140,22 +161,6 @@ declare const abi: [ name: "ResourceNotFound"; type: "error"; }, - { - inputs: [ - { - internalType: "uint256"; - name: "length"; - type: "uint256"; - } - ]; - name: "SchemaLib_InvalidLength"; - type: "error"; - }, - { - inputs: []; - name: "SchemaLib_StaticTypeAfterDynamicType"; - type: "error"; - }, { inputs: [ { diff --git a/packages/world/abi/CallboundDelegationControl.sol/CallboundDelegationControl.abi.json b/packages/world/abi/CallboundDelegationControl.sol/CallboundDelegationControl.abi.json index 33ca75c04e..559ba3a6a7 100644 --- a/packages/world/abi/CallboundDelegationControl.sol/CallboundDelegationControl.abi.json +++ b/packages/world/abi/CallboundDelegationControl.sol/CallboundDelegationControl.abi.json @@ -7,7 +7,17 @@ "type": "uint256" } ], - "name": "PackedCounter_InvalidLength", + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", "type": "error" }, { @@ -18,12 +28,7 @@ "type": "uint256" } ], - "name": "SchemaLib_InvalidLength", - "type": "error" - }, - { - "inputs": [], - "name": "SchemaLib_StaticTypeAfterDynamicType", + "name": "PackedCounter_InvalidLength", "type": "error" }, { diff --git a/packages/world/abi/CallboundDelegationControl.sol/CallboundDelegationControl.abi.json.d.ts b/packages/world/abi/CallboundDelegationControl.sol/CallboundDelegationControl.abi.json.d.ts index 16df83d0da..7b1c8c0f8f 100644 --- a/packages/world/abi/CallboundDelegationControl.sol/CallboundDelegationControl.abi.json.d.ts +++ b/packages/world/abi/CallboundDelegationControl.sol/CallboundDelegationControl.abi.json.d.ts @@ -7,7 +7,17 @@ declare const abi: [ type: "uint256"; } ]; - name: "PackedCounter_InvalidLength"; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; type: "error"; }, { @@ -18,12 +28,7 @@ declare const abi: [ type: "uint256"; } ]; - name: "SchemaLib_InvalidLength"; - type: "error"; - }, - { - inputs: []; - name: "SchemaLib_StaticTypeAfterDynamicType"; + name: "PackedCounter_InvalidLength"; type: "error"; }, { diff --git a/packages/world/abi/CoreModule.sol/CoreModule.abi.json b/packages/world/abi/CoreModule.sol/CoreModule.abi.json index 8f31605e6b..d802475a33 100644 --- a/packages/world/abi/CoreModule.sol/CoreModule.abi.json +++ b/packages/world/abi/CoreModule.sol/CoreModule.abi.json @@ -1,4 +1,25 @@ [ + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", + "type": "error" + }, { "inputs": [], "name": "NonRootInstallNotSupported", @@ -116,6 +137,22 @@ "name": "StoreCore_InvalidKeyNamesLength", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "expected", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "received", + "type": "uint256" + } + ], + "name": "StoreCore_InvalidValueSchemaLength", + "type": "error" + }, { "inputs": [ { diff --git a/packages/world/abi/CoreModule.sol/CoreModule.abi.json.d.ts b/packages/world/abi/CoreModule.sol/CoreModule.abi.json.d.ts index c5b23d3877..a2531ec4bd 100644 --- a/packages/world/abi/CoreModule.sol/CoreModule.abi.json.d.ts +++ b/packages/world/abi/CoreModule.sol/CoreModule.abi.json.d.ts @@ -1,4 +1,25 @@ declare const abi: [ + { + inputs: [ + { + internalType: "uint256"; + name: "length"; + type: "uint256"; + } + ]; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; + type: "error"; + }, { inputs: []; name: "NonRootInstallNotSupported"; @@ -116,6 +137,22 @@ declare const abi: [ name: "StoreCore_InvalidKeyNamesLength"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "expected"; + type: "uint256"; + }, + { + internalType: "uint256"; + name: "received"; + type: "uint256"; + } + ]; + name: "StoreCore_InvalidValueSchemaLength"; + type: "error"; + }, { inputs: [ { diff --git a/packages/world/abi/CoreSystem.sol/CoreSystem.abi.json b/packages/world/abi/CoreSystem.sol/CoreSystem.abi.json index cce7725a39..3a730bca65 100644 --- a/packages/world/abi/CoreSystem.sol/CoreSystem.abi.json +++ b/packages/world/abi/CoreSystem.sol/CoreSystem.abi.json @@ -31,6 +31,27 @@ "name": "DelegationNotFound", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", + "type": "error" + }, { "inputs": [ { @@ -225,6 +246,22 @@ "name": "StoreCore_InvalidKeyNamesLength", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "expected", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "received", + "type": "uint256" + } + ], + "name": "StoreCore_InvalidValueSchemaLength", + "type": "error" + }, { "inputs": [], "name": "StoreCore_NotDynamicField", @@ -339,8 +376,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -555,6 +592,11 @@ "name": "resourceSelector", "type": "bytes32" }, + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + }, { "internalType": "Schema", "name": "keySchema", diff --git a/packages/world/abi/CoreSystem.sol/CoreSystem.abi.json.d.ts b/packages/world/abi/CoreSystem.sol/CoreSystem.abi.json.d.ts index 3fd08490f2..1991fd11ad 100644 --- a/packages/world/abi/CoreSystem.sol/CoreSystem.abi.json.d.ts +++ b/packages/world/abi/CoreSystem.sol/CoreSystem.abi.json.d.ts @@ -31,6 +31,27 @@ declare const abi: [ name: "DelegationNotFound"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "length"; + type: "uint256"; + } + ]; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; + type: "error"; + }, { inputs: [ { @@ -225,6 +246,22 @@ declare const abi: [ name: "StoreCore_InvalidKeyNamesLength"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "expected"; + type: "uint256"; + }, + { + internalType: "uint256"; + name: "received"; + type: "uint256"; + } + ]; + name: "StoreCore_InvalidValueSchemaLength"; + type: "error"; + }, { inputs: []; name: "StoreCore_NotDynamicField"; @@ -339,8 +376,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -555,6 +592,11 @@ declare const abi: [ name: "resourceSelector"; type: "bytes32"; }, + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + }, { internalType: "Schema"; name: "keySchema"; diff --git a/packages/world/abi/EphemeralRecordSystem.sol/EphemeralRecordSystem.abi.json b/packages/world/abi/EphemeralRecordSystem.sol/EphemeralRecordSystem.abi.json index 9874e18914..a756afe3a6 100644 --- a/packages/world/abi/EphemeralRecordSystem.sol/EphemeralRecordSystem.abi.json +++ b/packages/world/abi/EphemeralRecordSystem.sol/EphemeralRecordSystem.abi.json @@ -23,12 +23,17 @@ "type": "uint256" } ], - "name": "SchemaLib_InvalidLength", + "name": "FieldLayoutLib_InvalidLength", "type": "error" }, { "inputs": [], - "name": "SchemaLib_StaticTypeAfterDynamicType", + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", "type": "error" }, { @@ -129,8 +134,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/EphemeralRecordSystem.sol/EphemeralRecordSystem.abi.json.d.ts b/packages/world/abi/EphemeralRecordSystem.sol/EphemeralRecordSystem.abi.json.d.ts index f074bc64fb..bcee40a567 100644 --- a/packages/world/abi/EphemeralRecordSystem.sol/EphemeralRecordSystem.abi.json.d.ts +++ b/packages/world/abi/EphemeralRecordSystem.sol/EphemeralRecordSystem.abi.json.d.ts @@ -23,12 +23,17 @@ declare const abi: [ type: "uint256"; } ]; - name: "SchemaLib_InvalidLength"; + name: "FieldLayoutLib_InvalidLength"; type: "error"; }, { inputs: []; - name: "SchemaLib_StaticTypeAfterDynamicType"; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; type: "error"; }, { @@ -129,8 +134,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/abi/FieldLayout.sol/FieldLayoutInstance.abi.json b/packages/world/abi/FieldLayout.sol/FieldLayoutInstance.abi.json new file mode 100644 index 0000000000..0637a088a0 --- /dev/null +++ b/packages/world/abi/FieldLayout.sol/FieldLayoutInstance.abi.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/packages/world/abi/FieldLayout.sol/FieldLayoutLib.abi.json b/packages/world/abi/FieldLayout.sol/FieldLayoutLib.abi.json new file mode 100644 index 0000000000..0718613ae7 --- /dev/null +++ b/packages/world/abi/FieldLayout.sol/FieldLayoutLib.abi.json @@ -0,0 +1,23 @@ +[ + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", + "type": "error" + } +] \ No newline at end of file diff --git a/packages/world/abi/FieldLayout.sol/FieldLayoutLib.abi.json.d.ts b/packages/world/abi/FieldLayout.sol/FieldLayoutLib.abi.json.d.ts new file mode 100644 index 0000000000..46ebe7906c --- /dev/null +++ b/packages/world/abi/FieldLayout.sol/FieldLayoutLib.abi.json.d.ts @@ -0,0 +1,24 @@ +declare const abi: [ + { + inputs: [ + { + internalType: "uint256"; + name: "length"; + type: "uint256"; + } + ]; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; + type: "error"; + } +]; +export default abi; diff --git a/packages/world/abi/IBaseWorld.sol/IBaseWorld.abi.json b/packages/world/abi/IBaseWorld.sol/IBaseWorld.abi.json index 1031a22ebf..7cb990eefd 100644 --- a/packages/world/abi/IBaseWorld.sol/IBaseWorld.abi.json +++ b/packages/world/abi/IBaseWorld.sol/IBaseWorld.abi.json @@ -193,6 +193,22 @@ "name": "StoreCore_InvalidKeyNamesLength", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "expected", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "received", + "type": "uint256" + } + ], + "name": "StoreCore_InvalidValueSchemaLength", + "type": "error" + }, { "inputs": [], "name": "StoreCore_NotDynamicField", @@ -418,8 +434,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -446,8 +462,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -474,8 +490,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -490,6 +506,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "table", + "type": "bytes32" + } + ], + "name": "getFieldLayout", + "outputs": [ + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -508,8 +543,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -542,8 +577,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" }, { @@ -600,8 +635,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -712,8 +747,8 @@ "type": "uint256" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -745,8 +780,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -925,6 +960,11 @@ "name": "table", "type": "bytes32" }, + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + }, { "internalType": "Schema", "name": "keySchema", @@ -992,8 +1032,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -1020,8 +1060,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -1158,8 +1198,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/IBaseWorld.sol/IBaseWorld.abi.json.d.ts b/packages/world/abi/IBaseWorld.sol/IBaseWorld.abi.json.d.ts index 4274de6990..a1b710dd0a 100644 --- a/packages/world/abi/IBaseWorld.sol/IBaseWorld.abi.json.d.ts +++ b/packages/world/abi/IBaseWorld.sol/IBaseWorld.abi.json.d.ts @@ -193,6 +193,22 @@ declare const abi: [ name: "StoreCore_InvalidKeyNamesLength"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "expected"; + type: "uint256"; + }, + { + internalType: "uint256"; + name: "received"; + type: "uint256"; + } + ]; + name: "StoreCore_InvalidValueSchemaLength"; + type: "error"; + }, { inputs: []; name: "StoreCore_NotDynamicField"; @@ -418,8 +434,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -446,8 +462,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -474,8 +490,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -490,6 +506,25 @@ declare const abi: [ stateMutability: "view"; type: "function"; }, + { + inputs: [ + { + internalType: "bytes32"; + name: "table"; + type: "bytes32"; + } + ]; + name: "getFieldLayout"; + outputs: [ + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + } + ]; + stateMutability: "view"; + type: "function"; + }, { inputs: [ { @@ -508,8 +543,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -542,8 +577,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; }, { @@ -600,8 +635,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -712,8 +747,8 @@ declare const abi: [ type: "uint256"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -745,8 +780,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -925,6 +960,11 @@ declare const abi: [ name: "table"; type: "bytes32"; }, + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + }, { internalType: "Schema"; name: "keySchema"; @@ -992,8 +1032,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -1020,8 +1060,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -1158,8 +1198,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/abi/IStore.sol/IStore.abi.json b/packages/world/abi/IStore.sol/IStore.abi.json index 48e69022f3..5f2611915f 100644 --- a/packages/world/abi/IStore.sol/IStore.abi.json +++ b/packages/world/abi/IStore.sol/IStore.abi.json @@ -63,6 +63,22 @@ "name": "StoreCore_InvalidKeyNamesLength", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "expected", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "received", + "type": "uint256" + } + ], + "name": "StoreCore_InvalidValueSchemaLength", + "type": "error" + }, { "inputs": [], "name": "StoreCore_NotDynamicField", @@ -218,8 +234,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -246,8 +262,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -274,8 +290,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -290,6 +306,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "table", + "type": "bytes32" + } + ], + "name": "getFieldLayout", + "outputs": [ + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -308,8 +343,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -342,8 +377,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" }, { @@ -400,8 +435,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -458,8 +493,8 @@ "type": "uint256" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -491,8 +526,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -531,6 +566,11 @@ "name": "table", "type": "bytes32" }, + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + }, { "internalType": "Schema", "name": "keySchema", @@ -580,8 +620,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -608,8 +648,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -664,8 +704,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/IStore.sol/IStore.abi.json.d.ts b/packages/world/abi/IStore.sol/IStore.abi.json.d.ts index 9838b2e184..53be52609c 100644 --- a/packages/world/abi/IStore.sol/IStore.abi.json.d.ts +++ b/packages/world/abi/IStore.sol/IStore.abi.json.d.ts @@ -63,6 +63,22 @@ declare const abi: [ name: "StoreCore_InvalidKeyNamesLength"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "expected"; + type: "uint256"; + }, + { + internalType: "uint256"; + name: "received"; + type: "uint256"; + } + ]; + name: "StoreCore_InvalidValueSchemaLength"; + type: "error"; + }, { inputs: []; name: "StoreCore_NotDynamicField"; @@ -218,8 +234,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -246,8 +262,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -274,8 +290,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -290,6 +306,25 @@ declare const abi: [ stateMutability: "view"; type: "function"; }, + { + inputs: [ + { + internalType: "bytes32"; + name: "table"; + type: "bytes32"; + } + ]; + name: "getFieldLayout"; + outputs: [ + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + } + ]; + stateMutability: "view"; + type: "function"; + }, { inputs: [ { @@ -308,8 +343,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -342,8 +377,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; }, { @@ -400,8 +435,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -458,8 +493,8 @@ declare const abi: [ type: "uint256"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -491,8 +526,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -531,6 +566,11 @@ declare const abi: [ name: "table"; type: "bytes32"; }, + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + }, { internalType: "Schema"; name: "keySchema"; @@ -580,8 +620,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -608,8 +648,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -664,8 +704,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/abi/IStore.sol/IStoreData.abi.json b/packages/world/abi/IStore.sol/IStoreData.abi.json index f02203d5e9..b2f7b1cfe9 100644 --- a/packages/world/abi/IStore.sol/IStoreData.abi.json +++ b/packages/world/abi/IStore.sol/IStoreData.abi.json @@ -87,8 +87,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -115,8 +115,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -131,6 +131,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "table", + "type": "bytes32" + } + ], + "name": "getFieldLayout", + "outputs": [ + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -149,8 +168,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -183,8 +202,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" }, { @@ -241,8 +260,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -299,8 +318,8 @@ "type": "uint256" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -332,8 +351,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -365,8 +384,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -393,8 +412,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -431,8 +450,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/IStore.sol/IStoreData.abi.json.d.ts b/packages/world/abi/IStore.sol/IStoreData.abi.json.d.ts index 069dc301f8..8376850819 100644 --- a/packages/world/abi/IStore.sol/IStoreData.abi.json.d.ts +++ b/packages/world/abi/IStore.sol/IStoreData.abi.json.d.ts @@ -87,8 +87,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -115,8 +115,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -131,6 +131,25 @@ declare const abi: [ stateMutability: "view"; type: "function"; }, + { + inputs: [ + { + internalType: "bytes32"; + name: "table"; + type: "bytes32"; + } + ]; + name: "getFieldLayout"; + outputs: [ + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + } + ]; + stateMutability: "view"; + type: "function"; + }, { inputs: [ { @@ -149,8 +168,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -183,8 +202,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; }, { @@ -241,8 +260,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -299,8 +318,8 @@ declare const abi: [ type: "uint256"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -332,8 +351,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -365,8 +384,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -393,8 +412,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -431,8 +450,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/abi/IStore.sol/IStoreEphemeral.abi.json b/packages/world/abi/IStore.sol/IStoreEphemeral.abi.json index c9cbd9770c..da76e6a5c2 100644 --- a/packages/world/abi/IStore.sol/IStoreEphemeral.abi.json +++ b/packages/world/abi/IStore.sol/IStoreEphemeral.abi.json @@ -42,8 +42,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/IStore.sol/IStoreEphemeral.abi.json.d.ts b/packages/world/abi/IStore.sol/IStoreEphemeral.abi.json.d.ts index 0ab62ee11e..5b3d199d71 100644 --- a/packages/world/abi/IStore.sol/IStoreEphemeral.abi.json.d.ts +++ b/packages/world/abi/IStore.sol/IStoreEphemeral.abi.json.d.ts @@ -42,8 +42,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/abi/IStore.sol/IStoreRead.abi.json b/packages/world/abi/IStore.sol/IStoreRead.abi.json index 0f47144f3d..44bcee43a5 100644 --- a/packages/world/abi/IStore.sol/IStoreRead.abi.json +++ b/packages/world/abi/IStore.sol/IStoreRead.abi.json @@ -17,8 +17,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -33,6 +33,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "table", + "type": "bytes32" + } + ], + "name": "getFieldLayout", + "outputs": [ + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -51,8 +70,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -85,8 +104,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" }, { @@ -143,8 +162,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/IStore.sol/IStoreRead.abi.json.d.ts b/packages/world/abi/IStore.sol/IStoreRead.abi.json.d.ts index 1fcf24a77e..14c859cc2e 100644 --- a/packages/world/abi/IStore.sol/IStoreRead.abi.json.d.ts +++ b/packages/world/abi/IStore.sol/IStoreRead.abi.json.d.ts @@ -17,8 +17,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -33,6 +33,25 @@ declare const abi: [ stateMutability: "view"; type: "function"; }, + { + inputs: [ + { + internalType: "bytes32"; + name: "table"; + type: "bytes32"; + } + ]; + name: "getFieldLayout"; + outputs: [ + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + } + ]; + stateMutability: "view"; + type: "function"; + }, { inputs: [ { @@ -51,8 +70,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -85,8 +104,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; }, { @@ -143,8 +162,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/abi/IStore.sol/IStoreRegistration.abi.json b/packages/world/abi/IStore.sol/IStoreRegistration.abi.json index 8199933edd..d21d2dd147 100644 --- a/packages/world/abi/IStore.sol/IStoreRegistration.abi.json +++ b/packages/world/abi/IStore.sol/IStoreRegistration.abi.json @@ -29,6 +29,11 @@ "name": "table", "type": "bytes32" }, + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + }, { "internalType": "Schema", "name": "keySchema", diff --git a/packages/world/abi/IStore.sol/IStoreRegistration.abi.json.d.ts b/packages/world/abi/IStore.sol/IStoreRegistration.abi.json.d.ts index 02db08cbf2..790883941d 100644 --- a/packages/world/abi/IStore.sol/IStoreRegistration.abi.json.d.ts +++ b/packages/world/abi/IStore.sol/IStoreRegistration.abi.json.d.ts @@ -29,6 +29,11 @@ declare const abi: [ name: "table"; type: "bytes32"; }, + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + }, { internalType: "Schema"; name: "keySchema"; diff --git a/packages/world/abi/IStore.sol/IStoreWrite.abi.json b/packages/world/abi/IStore.sol/IStoreWrite.abi.json index e5a35719c0..98b9d2126f 100644 --- a/packages/world/abi/IStore.sol/IStoreWrite.abi.json +++ b/packages/world/abi/IStore.sol/IStoreWrite.abi.json @@ -87,8 +87,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -120,8 +120,8 @@ "type": "uint256" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -153,8 +153,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -186,8 +186,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -214,8 +214,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -252,8 +252,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/IStore.sol/IStoreWrite.abi.json.d.ts b/packages/world/abi/IStore.sol/IStoreWrite.abi.json.d.ts index 6c043cda2f..5861267f02 100644 --- a/packages/world/abi/IStore.sol/IStoreWrite.abi.json.d.ts +++ b/packages/world/abi/IStore.sol/IStoreWrite.abi.json.d.ts @@ -87,8 +87,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -120,8 +120,8 @@ declare const abi: [ type: "uint256"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -153,8 +153,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -186,8 +186,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -214,8 +214,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -252,8 +252,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/abi/IStoreErrors.sol/IStoreErrors.abi.json b/packages/world/abi/IStoreErrors.sol/IStoreErrors.abi.json index cf6d375396..d52ffeba10 100644 --- a/packages/world/abi/IStoreErrors.sol/IStoreErrors.abi.json +++ b/packages/world/abi/IStoreErrors.sol/IStoreErrors.abi.json @@ -63,6 +63,22 @@ "name": "StoreCore_InvalidKeyNamesLength", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "expected", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "received", + "type": "uint256" + } + ], + "name": "StoreCore_InvalidValueSchemaLength", + "type": "error" + }, { "inputs": [], "name": "StoreCore_NotDynamicField", diff --git a/packages/world/abi/IStoreErrors.sol/IStoreErrors.abi.json.d.ts b/packages/world/abi/IStoreErrors.sol/IStoreErrors.abi.json.d.ts index 7e72348020..3618648807 100644 --- a/packages/world/abi/IStoreErrors.sol/IStoreErrors.abi.json.d.ts +++ b/packages/world/abi/IStoreErrors.sol/IStoreErrors.abi.json.d.ts @@ -63,6 +63,22 @@ declare const abi: [ name: "StoreCore_InvalidKeyNamesLength"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "expected"; + type: "uint256"; + }, + { + internalType: "uint256"; + name: "received"; + type: "uint256"; + } + ]; + name: "StoreCore_InvalidValueSchemaLength"; + type: "error"; + }, { inputs: []; name: "StoreCore_NotDynamicField"; diff --git a/packages/world/abi/IStoreHook.sol/IStoreHook.abi.json b/packages/world/abi/IStoreHook.sol/IStoreHook.abi.json index b35f6251af..206689d652 100644 --- a/packages/world/abi/IStoreHook.sol/IStoreHook.abi.json +++ b/packages/world/abi/IStoreHook.sol/IStoreHook.abi.json @@ -12,8 +12,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -45,8 +45,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -73,8 +73,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -96,8 +96,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -129,8 +129,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -157,8 +157,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/IStoreHook.sol/IStoreHook.abi.json.d.ts b/packages/world/abi/IStoreHook.sol/IStoreHook.abi.json.d.ts index ae36ae3637..4fafcfbee3 100644 --- a/packages/world/abi/IStoreHook.sol/IStoreHook.abi.json.d.ts +++ b/packages/world/abi/IStoreHook.sol/IStoreHook.abi.json.d.ts @@ -12,8 +12,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -45,8 +45,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -73,8 +73,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -96,8 +96,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -129,8 +129,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -157,8 +157,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/abi/KeysInTableHook.sol/KeysInTableHook.abi.json b/packages/world/abi/KeysInTableHook.sol/KeysInTableHook.abi.json index eaff373dca..7ab3608f13 100644 --- a/packages/world/abi/KeysInTableHook.sol/KeysInTableHook.abi.json +++ b/packages/world/abi/KeysInTableHook.sol/KeysInTableHook.abi.json @@ -7,7 +7,17 @@ "type": "uint256" } ], - "name": "PackedCounter_InvalidLength", + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", "type": "error" }, { @@ -18,12 +28,7 @@ "type": "uint256" } ], - "name": "SchemaLib_InvalidLength", - "type": "error" - }, - { - "inputs": [], - "name": "SchemaLib_StaticTypeAfterDynamicType", + "name": "PackedCounter_InvalidLength", "type": "error" }, { @@ -97,8 +102,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -130,7 +135,7 @@ "type": "bytes" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } @@ -158,7 +163,7 @@ "type": "bytes" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } @@ -181,7 +186,7 @@ "type": "bytes32[]" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } @@ -214,7 +219,7 @@ "type": "bytes" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } @@ -242,7 +247,7 @@ "type": "bytes" }, { - "internalType": "Schema", + "internalType": "FieldLayout", "name": "", "type": "bytes32" } diff --git a/packages/world/abi/KeysInTableHook.sol/KeysInTableHook.abi.json.d.ts b/packages/world/abi/KeysInTableHook.sol/KeysInTableHook.abi.json.d.ts index b6b7fd772c..6cd20a736e 100644 --- a/packages/world/abi/KeysInTableHook.sol/KeysInTableHook.abi.json.d.ts +++ b/packages/world/abi/KeysInTableHook.sol/KeysInTableHook.abi.json.d.ts @@ -7,7 +7,17 @@ declare const abi: [ type: "uint256"; } ]; - name: "PackedCounter_InvalidLength"; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; type: "error"; }, { @@ -18,12 +28,7 @@ declare const abi: [ type: "uint256"; } ]; - name: "SchemaLib_InvalidLength"; - type: "error"; - }, - { - inputs: []; - name: "SchemaLib_StaticTypeAfterDynamicType"; + name: "PackedCounter_InvalidLength"; type: "error"; }, { @@ -97,8 +102,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -130,7 +135,7 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } @@ -158,7 +163,7 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } @@ -181,7 +186,7 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } @@ -214,7 +219,7 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } @@ -242,7 +247,7 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; + internalType: "FieldLayout"; name: ""; type: "bytes32"; } diff --git a/packages/world/abi/KeysInTableModule.sol/KeysInTableModule.abi.json b/packages/world/abi/KeysInTableModule.sol/KeysInTableModule.abi.json index 1b73bd958f..d4ea3bd83c 100644 --- a/packages/world/abi/KeysInTableModule.sol/KeysInTableModule.abi.json +++ b/packages/world/abi/KeysInTableModule.sol/KeysInTableModule.abi.json @@ -1,4 +1,25 @@ [ + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", + "type": "error" + }, { "inputs": [], "name": "NonRootInstallNotSupported", diff --git a/packages/world/abi/KeysInTableModule.sol/KeysInTableModule.abi.json.d.ts b/packages/world/abi/KeysInTableModule.sol/KeysInTableModule.abi.json.d.ts index 00f96c935d..5d87fcd701 100644 --- a/packages/world/abi/KeysInTableModule.sol/KeysInTableModule.abi.json.d.ts +++ b/packages/world/abi/KeysInTableModule.sol/KeysInTableModule.abi.json.d.ts @@ -1,4 +1,25 @@ declare const abi: [ + { + inputs: [ + { + internalType: "uint256"; + name: "length"; + type: "uint256"; + } + ]; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; + type: "error"; + }, { inputs: []; name: "NonRootInstallNotSupported"; diff --git a/packages/world/abi/KeysWithValueHook.sol/KeysWithValueHook.abi.json b/packages/world/abi/KeysWithValueHook.sol/KeysWithValueHook.abi.json index 873654242c..fc5a01140c 100644 --- a/packages/world/abi/KeysWithValueHook.sol/KeysWithValueHook.abi.json +++ b/packages/world/abi/KeysWithValueHook.sol/KeysWithValueHook.abi.json @@ -7,7 +7,17 @@ "type": "uint256" } ], - "name": "PackedCounter_InvalidLength", + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", "type": "error" }, { @@ -18,12 +28,7 @@ "type": "uint256" } ], - "name": "SchemaLib_InvalidLength", - "type": "error" - }, - { - "inputs": [], - "name": "SchemaLib_StaticTypeAfterDynamicType", + "name": "PackedCounter_InvalidLength", "type": "error" }, { @@ -81,8 +86,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -114,8 +119,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -142,8 +147,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -165,8 +170,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -198,8 +203,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -226,8 +231,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/KeysWithValueHook.sol/KeysWithValueHook.abi.json.d.ts b/packages/world/abi/KeysWithValueHook.sol/KeysWithValueHook.abi.json.d.ts index 77467bcde6..4b64245b48 100644 --- a/packages/world/abi/KeysWithValueHook.sol/KeysWithValueHook.abi.json.d.ts +++ b/packages/world/abi/KeysWithValueHook.sol/KeysWithValueHook.abi.json.d.ts @@ -7,7 +7,17 @@ declare const abi: [ type: "uint256"; } ]; - name: "PackedCounter_InvalidLength"; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; type: "error"; }, { @@ -18,12 +28,7 @@ declare const abi: [ type: "uint256"; } ]; - name: "SchemaLib_InvalidLength"; - type: "error"; - }, - { - inputs: []; - name: "SchemaLib_StaticTypeAfterDynamicType"; + name: "PackedCounter_InvalidLength"; type: "error"; }, { @@ -81,8 +86,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -114,8 +119,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -142,8 +147,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -165,8 +170,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -198,8 +203,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -226,8 +231,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/abi/KeysWithValueModule.sol/KeysWithValueModule.abi.json b/packages/world/abi/KeysWithValueModule.sol/KeysWithValueModule.abi.json index 1b73bd958f..d4ea3bd83c 100644 --- a/packages/world/abi/KeysWithValueModule.sol/KeysWithValueModule.abi.json +++ b/packages/world/abi/KeysWithValueModule.sol/KeysWithValueModule.abi.json @@ -1,4 +1,25 @@ [ + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", + "type": "error" + }, { "inputs": [], "name": "NonRootInstallNotSupported", diff --git a/packages/world/abi/KeysWithValueModule.sol/KeysWithValueModule.abi.json.d.ts b/packages/world/abi/KeysWithValueModule.sol/KeysWithValueModule.abi.json.d.ts index 00f96c935d..5d87fcd701 100644 --- a/packages/world/abi/KeysWithValueModule.sol/KeysWithValueModule.abi.json.d.ts +++ b/packages/world/abi/KeysWithValueModule.sol/KeysWithValueModule.abi.json.d.ts @@ -1,4 +1,25 @@ declare const abi: [ + { + inputs: [ + { + internalType: "uint256"; + name: "length"; + type: "uint256"; + } + ]; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; + type: "error"; + }, { inputs: []; name: "NonRootInstallNotSupported"; diff --git a/packages/world/abi/ModuleInstallationSystem.sol/ModuleInstallationSystem.abi.json b/packages/world/abi/ModuleInstallationSystem.sol/ModuleInstallationSystem.abi.json index 171f1ba0fb..4a76a9b72a 100644 --- a/packages/world/abi/ModuleInstallationSystem.sol/ModuleInstallationSystem.abi.json +++ b/packages/world/abi/ModuleInstallationSystem.sol/ModuleInstallationSystem.abi.json @@ -1,4 +1,25 @@ [ + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", + "type": "error" + }, { "inputs": [ { @@ -15,22 +36,6 @@ "name": "InterfaceNotSupported", "type": "error" }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "length", - "type": "uint256" - } - ], - "name": "SchemaLib_InvalidLength", - "type": "error" - }, - { - "inputs": [], - "name": "SchemaLib_StaticTypeAfterDynamicType", - "type": "error" - }, { "inputs": [ { diff --git a/packages/world/abi/ModuleInstallationSystem.sol/ModuleInstallationSystem.abi.json.d.ts b/packages/world/abi/ModuleInstallationSystem.sol/ModuleInstallationSystem.abi.json.d.ts index 46bcda0db2..7d018a421b 100644 --- a/packages/world/abi/ModuleInstallationSystem.sol/ModuleInstallationSystem.abi.json.d.ts +++ b/packages/world/abi/ModuleInstallationSystem.sol/ModuleInstallationSystem.abi.json.d.ts @@ -1,4 +1,25 @@ declare const abi: [ + { + inputs: [ + { + internalType: "uint256"; + name: "length"; + type: "uint256"; + } + ]; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; + type: "error"; + }, { inputs: [ { @@ -15,22 +36,6 @@ declare const abi: [ name: "InterfaceNotSupported"; type: "error"; }, - { - inputs: [ - { - internalType: "uint256"; - name: "length"; - type: "uint256"; - } - ]; - name: "SchemaLib_InvalidLength"; - type: "error"; - }, - { - inputs: []; - name: "SchemaLib_StaticTypeAfterDynamicType"; - type: "error"; - }, { inputs: [ { diff --git a/packages/world/abi/StandardDelegationsModule.sol/StandardDelegationsModule.abi.json b/packages/world/abi/StandardDelegationsModule.sol/StandardDelegationsModule.abi.json index 0d83727d33..80f6e4867e 100644 --- a/packages/world/abi/StandardDelegationsModule.sol/StandardDelegationsModule.abi.json +++ b/packages/world/abi/StandardDelegationsModule.sol/StandardDelegationsModule.abi.json @@ -1,4 +1,25 @@ [ + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", + "type": "error" + }, { "inputs": [], "name": "NonRootInstallNotSupported", @@ -105,6 +126,22 @@ "name": "StoreCore_InvalidKeyNamesLength", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "expected", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "received", + "type": "uint256" + } + ], + "name": "StoreCore_InvalidValueSchemaLength", + "type": "error" + }, { "inputs": [ { diff --git a/packages/world/abi/StandardDelegationsModule.sol/StandardDelegationsModule.abi.json.d.ts b/packages/world/abi/StandardDelegationsModule.sol/StandardDelegationsModule.abi.json.d.ts index a6067f64e3..760da07043 100644 --- a/packages/world/abi/StandardDelegationsModule.sol/StandardDelegationsModule.abi.json.d.ts +++ b/packages/world/abi/StandardDelegationsModule.sol/StandardDelegationsModule.abi.json.d.ts @@ -1,4 +1,25 @@ declare const abi: [ + { + inputs: [ + { + internalType: "uint256"; + name: "length"; + type: "uint256"; + } + ]; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; + type: "error"; + }, { inputs: []; name: "NonRootInstallNotSupported"; @@ -105,6 +126,22 @@ declare const abi: [ name: "StoreCore_InvalidKeyNamesLength"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "expected"; + type: "uint256"; + }, + { + internalType: "uint256"; + name: "received"; + type: "uint256"; + } + ]; + name: "StoreCore_InvalidValueSchemaLength"; + type: "error"; + }, { inputs: [ { diff --git a/packages/world/abi/StoreCore.sol/StoreCore.abi.json b/packages/world/abi/StoreCore.sol/StoreCore.abi.json index 72f144fcd2..fb85ad946b 100644 --- a/packages/world/abi/StoreCore.sol/StoreCore.abi.json +++ b/packages/world/abi/StoreCore.sol/StoreCore.abi.json @@ -61,7 +61,7 @@ { "indexed": false, "internalType": "uint8", - "name": "schemaIndex", + "name": "fieldIndex", "type": "uint8" }, { diff --git a/packages/world/abi/StoreCore.sol/StoreCore.abi.json.d.ts b/packages/world/abi/StoreCore.sol/StoreCore.abi.json.d.ts index efd33cd781..60f914b4e1 100644 --- a/packages/world/abi/StoreCore.sol/StoreCore.abi.json.d.ts +++ b/packages/world/abi/StoreCore.sol/StoreCore.abi.json.d.ts @@ -61,7 +61,7 @@ declare const abi: [ { indexed: false; internalType: "uint8"; - name: "schemaIndex"; + name: "fieldIndex"; type: "uint8"; }, { diff --git a/packages/world/abi/StoreHook.sol/StoreHook.abi.json b/packages/world/abi/StoreHook.sol/StoreHook.abi.json index 3d219e7777..84037ddd5e 100644 --- a/packages/world/abi/StoreHook.sol/StoreHook.abi.json +++ b/packages/world/abi/StoreHook.sol/StoreHook.abi.json @@ -12,8 +12,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -45,8 +45,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -73,8 +73,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -96,8 +96,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -129,8 +129,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -157,8 +157,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/StoreHook.sol/StoreHook.abi.json.d.ts b/packages/world/abi/StoreHook.sol/StoreHook.abi.json.d.ts index 494a46cc19..96c3279f30 100644 --- a/packages/world/abi/StoreHook.sol/StoreHook.abi.json.d.ts +++ b/packages/world/abi/StoreHook.sol/StoreHook.abi.json.d.ts @@ -12,8 +12,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -45,8 +45,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -73,8 +73,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -96,8 +96,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -129,8 +129,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -157,8 +157,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/abi/StoreRead.sol/StoreRead.abi.json b/packages/world/abi/StoreRead.sol/StoreRead.abi.json index 93a0e17cf5..1f8dd917db 100644 --- a/packages/world/abi/StoreRead.sol/StoreRead.abi.json +++ b/packages/world/abi/StoreRead.sol/StoreRead.abi.json @@ -4,6 +4,27 @@ "stateMutability": "nonpayable", "type": "constructor" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", + "type": "error" + }, { "inputs": [ { @@ -89,6 +110,22 @@ "name": "StoreCore_InvalidKeyNamesLength", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "expected", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "received", + "type": "uint256" + } + ], + "name": "StoreCore_InvalidValueSchemaLength", + "type": "error" + }, { "inputs": [], "name": "StoreCore_NotDynamicField", @@ -144,8 +181,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -160,6 +197,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "table", + "type": "bytes32" + } + ], + "name": "getFieldLayout", + "outputs": [ + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -178,8 +234,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "schema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -212,8 +268,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "schema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" }, { @@ -270,8 +326,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/StoreRead.sol/StoreRead.abi.json.d.ts b/packages/world/abi/StoreRead.sol/StoreRead.abi.json.d.ts index 13d190bb30..677134cc99 100644 --- a/packages/world/abi/StoreRead.sol/StoreRead.abi.json.d.ts +++ b/packages/world/abi/StoreRead.sol/StoreRead.abi.json.d.ts @@ -4,6 +4,27 @@ declare const abi: [ stateMutability: "nonpayable"; type: "constructor"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "length"; + type: "uint256"; + } + ]; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; + type: "error"; + }, { inputs: [ { @@ -89,6 +110,22 @@ declare const abi: [ name: "StoreCore_InvalidKeyNamesLength"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "expected"; + type: "uint256"; + }, + { + internalType: "uint256"; + name: "received"; + type: "uint256"; + } + ]; + name: "StoreCore_InvalidValueSchemaLength"; + type: "error"; + }, { inputs: []; name: "StoreCore_NotDynamicField"; @@ -144,8 +181,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -160,6 +197,25 @@ declare const abi: [ stateMutability: "view"; type: "function"; }, + { + inputs: [ + { + internalType: "bytes32"; + name: "table"; + type: "bytes32"; + } + ]; + name: "getFieldLayout"; + outputs: [ + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + } + ]; + stateMutability: "view"; + type: "function"; + }, { inputs: [ { @@ -178,8 +234,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "schema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -212,8 +268,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "schema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; }, { @@ -270,8 +326,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/abi/StoreRegistrationSystem.sol/StoreRegistrationSystem.abi.json b/packages/world/abi/StoreRegistrationSystem.sol/StoreRegistrationSystem.abi.json index ddb3deb9fe..d521da57d5 100644 --- a/packages/world/abi/StoreRegistrationSystem.sol/StoreRegistrationSystem.abi.json +++ b/packages/world/abi/StoreRegistrationSystem.sol/StoreRegistrationSystem.abi.json @@ -31,6 +31,27 @@ "name": "DelegationNotFound", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", + "type": "error" + }, { "inputs": [ { @@ -225,6 +246,22 @@ "name": "StoreCore_InvalidKeyNamesLength", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "expected", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "received", + "type": "uint256" + } + ], + "name": "StoreCore_InvalidValueSchemaLength", + "type": "error" + }, { "inputs": [], "name": "StoreCore_NotDynamicField", @@ -326,6 +363,11 @@ "name": "resourceSelector", "type": "bytes32" }, + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + }, { "internalType": "Schema", "name": "keySchema", diff --git a/packages/world/abi/StoreRegistrationSystem.sol/StoreRegistrationSystem.abi.json.d.ts b/packages/world/abi/StoreRegistrationSystem.sol/StoreRegistrationSystem.abi.json.d.ts index 02d4278711..bb4ce29c6d 100644 --- a/packages/world/abi/StoreRegistrationSystem.sol/StoreRegistrationSystem.abi.json.d.ts +++ b/packages/world/abi/StoreRegistrationSystem.sol/StoreRegistrationSystem.abi.json.d.ts @@ -31,6 +31,27 @@ declare const abi: [ name: "DelegationNotFound"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "length"; + type: "uint256"; + } + ]; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; + type: "error"; + }, { inputs: [ { @@ -225,6 +246,22 @@ declare const abi: [ name: "StoreCore_InvalidKeyNamesLength"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "expected"; + type: "uint256"; + }, + { + internalType: "uint256"; + name: "received"; + type: "uint256"; + } + ]; + name: "StoreCore_InvalidValueSchemaLength"; + type: "error"; + }, { inputs: []; name: "StoreCore_NotDynamicField"; @@ -326,6 +363,11 @@ declare const abi: [ name: "resourceSelector"; type: "bytes32"; }, + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + }, { internalType: "Schema"; name: "keySchema"; diff --git a/packages/world/abi/TimeboundDelegationControl.sol/TimeboundDelegationControl.abi.json b/packages/world/abi/TimeboundDelegationControl.sol/TimeboundDelegationControl.abi.json index e44457fe5a..599df0ec7d 100644 --- a/packages/world/abi/TimeboundDelegationControl.sol/TimeboundDelegationControl.abi.json +++ b/packages/world/abi/TimeboundDelegationControl.sol/TimeboundDelegationControl.abi.json @@ -7,7 +7,17 @@ "type": "uint256" } ], - "name": "PackedCounter_InvalidLength", + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", "type": "error" }, { @@ -18,12 +28,7 @@ "type": "uint256" } ], - "name": "SchemaLib_InvalidLength", - "type": "error" - }, - { - "inputs": [], - "name": "SchemaLib_StaticTypeAfterDynamicType", + "name": "PackedCounter_InvalidLength", "type": "error" }, { diff --git a/packages/world/abi/TimeboundDelegationControl.sol/TimeboundDelegationControl.abi.json.d.ts b/packages/world/abi/TimeboundDelegationControl.sol/TimeboundDelegationControl.abi.json.d.ts index b7a1195398..0add1bc24a 100644 --- a/packages/world/abi/TimeboundDelegationControl.sol/TimeboundDelegationControl.abi.json.d.ts +++ b/packages/world/abi/TimeboundDelegationControl.sol/TimeboundDelegationControl.abi.json.d.ts @@ -7,7 +7,17 @@ declare const abi: [ type: "uint256"; } ]; - name: "PackedCounter_InvalidLength"; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; type: "error"; }, { @@ -18,12 +28,7 @@ declare const abi: [ type: "uint256"; } ]; - name: "SchemaLib_InvalidLength"; - type: "error"; - }, - { - inputs: []; - name: "SchemaLib_StaticTypeAfterDynamicType"; + name: "PackedCounter_InvalidLength"; type: "error"; }, { diff --git a/packages/world/abi/UniqueEntityModule.sol/UniqueEntityModule.abi.json b/packages/world/abi/UniqueEntityModule.sol/UniqueEntityModule.abi.json index dc2f477d69..2bf1bdd337 100644 --- a/packages/world/abi/UniqueEntityModule.sol/UniqueEntityModule.abi.json +++ b/packages/world/abi/UniqueEntityModule.sol/UniqueEntityModule.abi.json @@ -1,4 +1,25 @@ [ + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", + "type": "error" + }, { "inputs": [], "name": "NonRootInstallNotSupported", diff --git a/packages/world/abi/UniqueEntityModule.sol/UniqueEntityModule.abi.json.d.ts b/packages/world/abi/UniqueEntityModule.sol/UniqueEntityModule.abi.json.d.ts index 8f66fa3fb9..9aaa5f39a8 100644 --- a/packages/world/abi/UniqueEntityModule.sol/UniqueEntityModule.abi.json.d.ts +++ b/packages/world/abi/UniqueEntityModule.sol/UniqueEntityModule.abi.json.d.ts @@ -1,4 +1,25 @@ declare const abi: [ + { + inputs: [ + { + internalType: "uint256"; + name: "length"; + type: "uint256"; + } + ]; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; + type: "error"; + }, { inputs: []; name: "NonRootInstallNotSupported"; diff --git a/packages/world/abi/UniqueEntitySystem.sol/UniqueEntitySystem.abi.json b/packages/world/abi/UniqueEntitySystem.sol/UniqueEntitySystem.abi.json index a93a479904..4958d1179d 100644 --- a/packages/world/abi/UniqueEntitySystem.sol/UniqueEntitySystem.abi.json +++ b/packages/world/abi/UniqueEntitySystem.sol/UniqueEntitySystem.abi.json @@ -7,7 +7,17 @@ "type": "uint256" } ], - "name": "PackedCounter_InvalidLength", + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", "type": "error" }, { @@ -18,12 +28,7 @@ "type": "uint256" } ], - "name": "SchemaLib_InvalidLength", - "type": "error" - }, - { - "inputs": [], - "name": "SchemaLib_StaticTypeAfterDynamicType", + "name": "PackedCounter_InvalidLength", "type": "error" }, { diff --git a/packages/world/abi/UniqueEntitySystem.sol/UniqueEntitySystem.abi.json.d.ts b/packages/world/abi/UniqueEntitySystem.sol/UniqueEntitySystem.abi.json.d.ts index af0dc9f756..5371865452 100644 --- a/packages/world/abi/UniqueEntitySystem.sol/UniqueEntitySystem.abi.json.d.ts +++ b/packages/world/abi/UniqueEntitySystem.sol/UniqueEntitySystem.abi.json.d.ts @@ -7,7 +7,17 @@ declare const abi: [ type: "uint256"; } ]; - name: "PackedCounter_InvalidLength"; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; type: "error"; }, { @@ -18,12 +28,7 @@ declare const abi: [ type: "uint256"; } ]; - name: "SchemaLib_InvalidLength"; - type: "error"; - }, - { - inputs: []; - name: "SchemaLib_StaticTypeAfterDynamicType"; + name: "PackedCounter_InvalidLength"; type: "error"; }, { diff --git a/packages/world/abi/World.sol/World.abi.json b/packages/world/abi/World.sol/World.abi.json index d25fe2f864..e6f9da0703 100644 --- a/packages/world/abi/World.sol/World.abi.json +++ b/packages/world/abi/World.sol/World.abi.json @@ -36,6 +36,27 @@ "name": "DelegationNotFound", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", + "type": "error" + }, { "inputs": [ { @@ -246,6 +267,22 @@ "name": "StoreCore_InvalidKeyNamesLength", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "expected", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "received", + "type": "uint256" + } + ], + "name": "StoreCore_InvalidValueSchemaLength", + "type": "error" + }, { "inputs": [], "name": "StoreCore_NotDynamicField", @@ -445,8 +482,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -473,8 +510,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -489,6 +526,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "table", + "type": "bytes32" + } + ], + "name": "getFieldLayout", + "outputs": [ + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -507,8 +563,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "schema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -541,8 +597,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "schema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" }, { @@ -599,8 +655,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -675,8 +731,8 @@ "type": "uint256" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -708,8 +764,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -741,8 +797,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -769,8 +825,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -807,8 +863,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/World.sol/World.abi.json.d.ts b/packages/world/abi/World.sol/World.abi.json.d.ts index 27b4d3902e..733e1d2b57 100644 --- a/packages/world/abi/World.sol/World.abi.json.d.ts +++ b/packages/world/abi/World.sol/World.abi.json.d.ts @@ -36,6 +36,27 @@ declare const abi: [ name: "DelegationNotFound"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "length"; + type: "uint256"; + } + ]; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; + type: "error"; + }, { inputs: [ { @@ -246,6 +267,22 @@ declare const abi: [ name: "StoreCore_InvalidKeyNamesLength"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "expected"; + type: "uint256"; + }, + { + internalType: "uint256"; + name: "received"; + type: "uint256"; + } + ]; + name: "StoreCore_InvalidValueSchemaLength"; + type: "error"; + }, { inputs: []; name: "StoreCore_NotDynamicField"; @@ -445,8 +482,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -473,8 +510,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -489,6 +526,25 @@ declare const abi: [ stateMutability: "view"; type: "function"; }, + { + inputs: [ + { + internalType: "bytes32"; + name: "table"; + type: "bytes32"; + } + ]; + name: "getFieldLayout"; + outputs: [ + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + } + ]; + stateMutability: "view"; + type: "function"; + }, { inputs: [ { @@ -507,8 +563,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "schema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -541,8 +597,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "schema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; }, { @@ -599,8 +655,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -675,8 +731,8 @@ declare const abi: [ type: "uint256"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -708,8 +764,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -741,8 +797,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -769,8 +825,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -807,8 +863,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/abi/WorldRegistrationSystem.sol/WorldRegistrationSystem.abi.json b/packages/world/abi/WorldRegistrationSystem.sol/WorldRegistrationSystem.abi.json index 7db7f553cb..8a3634a6da 100644 --- a/packages/world/abi/WorldRegistrationSystem.sol/WorldRegistrationSystem.abi.json +++ b/packages/world/abi/WorldRegistrationSystem.sol/WorldRegistrationSystem.abi.json @@ -31,6 +31,27 @@ "name": "DelegationNotFound", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", + "type": "error" + }, { "inputs": [ { @@ -140,22 +161,6 @@ "name": "ResourceNotFound", "type": "error" }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "length", - "type": "uint256" - } - ], - "name": "SchemaLib_InvalidLength", - "type": "error" - }, - { - "inputs": [], - "name": "SchemaLib_StaticTypeAfterDynamicType", - "type": "error" - }, { "inputs": [ { diff --git a/packages/world/abi/WorldRegistrationSystem.sol/WorldRegistrationSystem.abi.json.d.ts b/packages/world/abi/WorldRegistrationSystem.sol/WorldRegistrationSystem.abi.json.d.ts index ebcd66f75e..a6e9822f2f 100644 --- a/packages/world/abi/WorldRegistrationSystem.sol/WorldRegistrationSystem.abi.json.d.ts +++ b/packages/world/abi/WorldRegistrationSystem.sol/WorldRegistrationSystem.abi.json.d.ts @@ -31,6 +31,27 @@ declare const abi: [ name: "DelegationNotFound"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "length"; + type: "uint256"; + } + ]; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; + type: "error"; + }, { inputs: [ { @@ -140,22 +161,6 @@ declare const abi: [ name: "ResourceNotFound"; type: "error"; }, - { - inputs: [ - { - internalType: "uint256"; - name: "length"; - type: "uint256"; - } - ]; - name: "SchemaLib_InvalidLength"; - type: "error"; - }, - { - inputs: []; - name: "SchemaLib_StaticTypeAfterDynamicType"; - type: "error"; - }, { inputs: [ { diff --git a/packages/world/abi/constants.sol/LayoutOffsets.abi.json b/packages/world/abi/constants.sol/LayoutOffsets.abi.json new file mode 100644 index 0000000000..0637a088a0 --- /dev/null +++ b/packages/world/abi/constants.sol/LayoutOffsets.abi.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/packages/world/abi/src/FieldLayout.sol/FieldLayoutInstance.abi.json b/packages/world/abi/src/FieldLayout.sol/FieldLayoutInstance.abi.json new file mode 100644 index 0000000000..0637a088a0 --- /dev/null +++ b/packages/world/abi/src/FieldLayout.sol/FieldLayoutInstance.abi.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/packages/world/abi/src/FieldLayout.sol/FieldLayoutLib.abi.json b/packages/world/abi/src/FieldLayout.sol/FieldLayoutLib.abi.json new file mode 100644 index 0000000000..0718613ae7 --- /dev/null +++ b/packages/world/abi/src/FieldLayout.sol/FieldLayoutLib.abi.json @@ -0,0 +1,23 @@ +[ + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "FieldLayoutLib_InvalidLength", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthDoesNotFitInAWord", + "type": "error" + }, + { + "inputs": [], + "name": "FieldLayoutLib_StaticLengthIsZero", + "type": "error" + } +] \ No newline at end of file diff --git a/packages/world/abi/src/FieldLayout.sol/FieldLayoutLib.abi.json.d.ts b/packages/world/abi/src/FieldLayout.sol/FieldLayoutLib.abi.json.d.ts new file mode 100644 index 0000000000..46ebe7906c --- /dev/null +++ b/packages/world/abi/src/FieldLayout.sol/FieldLayoutLib.abi.json.d.ts @@ -0,0 +1,24 @@ +declare const abi: [ + { + inputs: [ + { + internalType: "uint256"; + name: "length"; + type: "uint256"; + } + ]; + name: "FieldLayoutLib_InvalidLength"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthDoesNotFitInAWord"; + type: "error"; + }, + { + inputs: []; + name: "FieldLayoutLib_StaticLengthIsZero"; + type: "error"; + } +]; +export default abi; diff --git a/packages/world/abi/src/IStore.sol/IStore.abi.json b/packages/world/abi/src/IStore.sol/IStore.abi.json index 48e69022f3..5f2611915f 100644 --- a/packages/world/abi/src/IStore.sol/IStore.abi.json +++ b/packages/world/abi/src/IStore.sol/IStore.abi.json @@ -63,6 +63,22 @@ "name": "StoreCore_InvalidKeyNamesLength", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "expected", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "received", + "type": "uint256" + } + ], + "name": "StoreCore_InvalidValueSchemaLength", + "type": "error" + }, { "inputs": [], "name": "StoreCore_NotDynamicField", @@ -218,8 +234,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -246,8 +262,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -274,8 +290,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -290,6 +306,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "table", + "type": "bytes32" + } + ], + "name": "getFieldLayout", + "outputs": [ + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -308,8 +343,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -342,8 +377,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" }, { @@ -400,8 +435,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -458,8 +493,8 @@ "type": "uint256" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -491,8 +526,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -531,6 +566,11 @@ "name": "table", "type": "bytes32" }, + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + }, { "internalType": "Schema", "name": "keySchema", @@ -580,8 +620,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -608,8 +648,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -664,8 +704,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/src/IStore.sol/IStore.abi.json.d.ts b/packages/world/abi/src/IStore.sol/IStore.abi.json.d.ts index 9838b2e184..53be52609c 100644 --- a/packages/world/abi/src/IStore.sol/IStore.abi.json.d.ts +++ b/packages/world/abi/src/IStore.sol/IStore.abi.json.d.ts @@ -63,6 +63,22 @@ declare const abi: [ name: "StoreCore_InvalidKeyNamesLength"; type: "error"; }, + { + inputs: [ + { + internalType: "uint256"; + name: "expected"; + type: "uint256"; + }, + { + internalType: "uint256"; + name: "received"; + type: "uint256"; + } + ]; + name: "StoreCore_InvalidValueSchemaLength"; + type: "error"; + }, { inputs: []; name: "StoreCore_NotDynamicField"; @@ -218,8 +234,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -246,8 +262,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -274,8 +290,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -290,6 +306,25 @@ declare const abi: [ stateMutability: "view"; type: "function"; }, + { + inputs: [ + { + internalType: "bytes32"; + name: "table"; + type: "bytes32"; + } + ]; + name: "getFieldLayout"; + outputs: [ + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + } + ]; + stateMutability: "view"; + type: "function"; + }, { inputs: [ { @@ -308,8 +343,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -342,8 +377,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; }, { @@ -400,8 +435,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -458,8 +493,8 @@ declare const abi: [ type: "uint256"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -491,8 +526,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -531,6 +566,11 @@ declare const abi: [ name: "table"; type: "bytes32"; }, + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + }, { internalType: "Schema"; name: "keySchema"; @@ -580,8 +620,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -608,8 +648,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -664,8 +704,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/abi/src/IStore.sol/IStoreData.abi.json b/packages/world/abi/src/IStore.sol/IStoreData.abi.json index f02203d5e9..b2f7b1cfe9 100644 --- a/packages/world/abi/src/IStore.sol/IStoreData.abi.json +++ b/packages/world/abi/src/IStore.sol/IStoreData.abi.json @@ -87,8 +87,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -115,8 +115,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -131,6 +131,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "table", + "type": "bytes32" + } + ], + "name": "getFieldLayout", + "outputs": [ + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -149,8 +168,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -183,8 +202,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" }, { @@ -241,8 +260,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -299,8 +318,8 @@ "type": "uint256" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -332,8 +351,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -365,8 +384,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -393,8 +412,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -431,8 +450,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/src/IStore.sol/IStoreData.abi.json.d.ts b/packages/world/abi/src/IStore.sol/IStoreData.abi.json.d.ts index 069dc301f8..8376850819 100644 --- a/packages/world/abi/src/IStore.sol/IStoreData.abi.json.d.ts +++ b/packages/world/abi/src/IStore.sol/IStoreData.abi.json.d.ts @@ -87,8 +87,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -115,8 +115,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -131,6 +131,25 @@ declare const abi: [ stateMutability: "view"; type: "function"; }, + { + inputs: [ + { + internalType: "bytes32"; + name: "table"; + type: "bytes32"; + } + ]; + name: "getFieldLayout"; + outputs: [ + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + } + ]; + stateMutability: "view"; + type: "function"; + }, { inputs: [ { @@ -149,8 +168,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -183,8 +202,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; }, { @@ -241,8 +260,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -299,8 +318,8 @@ declare const abi: [ type: "uint256"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -332,8 +351,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -365,8 +384,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -393,8 +412,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -431,8 +450,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/abi/src/IStore.sol/IStoreEphemeral.abi.json b/packages/world/abi/src/IStore.sol/IStoreEphemeral.abi.json index c9cbd9770c..da76e6a5c2 100644 --- a/packages/world/abi/src/IStore.sol/IStoreEphemeral.abi.json +++ b/packages/world/abi/src/IStore.sol/IStoreEphemeral.abi.json @@ -42,8 +42,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/src/IStore.sol/IStoreEphemeral.abi.json.d.ts b/packages/world/abi/src/IStore.sol/IStoreEphemeral.abi.json.d.ts index 0ab62ee11e..5b3d199d71 100644 --- a/packages/world/abi/src/IStore.sol/IStoreEphemeral.abi.json.d.ts +++ b/packages/world/abi/src/IStore.sol/IStoreEphemeral.abi.json.d.ts @@ -42,8 +42,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/abi/src/IStore.sol/IStoreRead.abi.json b/packages/world/abi/src/IStore.sol/IStoreRead.abi.json index 0f47144f3d..44bcee43a5 100644 --- a/packages/world/abi/src/IStore.sol/IStoreRead.abi.json +++ b/packages/world/abi/src/IStore.sol/IStoreRead.abi.json @@ -17,8 +17,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -33,6 +33,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "table", + "type": "bytes32" + } + ], + "name": "getFieldLayout", + "outputs": [ + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -51,8 +70,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -85,8 +104,8 @@ "type": "uint8" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" }, { @@ -143,8 +162,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/src/IStore.sol/IStoreRead.abi.json.d.ts b/packages/world/abi/src/IStore.sol/IStoreRead.abi.json.d.ts index 1fcf24a77e..14c859cc2e 100644 --- a/packages/world/abi/src/IStore.sol/IStoreRead.abi.json.d.ts +++ b/packages/world/abi/src/IStore.sol/IStoreRead.abi.json.d.ts @@ -17,8 +17,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -33,6 +33,25 @@ declare const abi: [ stateMutability: "view"; type: "function"; }, + { + inputs: [ + { + internalType: "bytes32"; + name: "table"; + type: "bytes32"; + } + ]; + name: "getFieldLayout"; + outputs: [ + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + } + ]; + stateMutability: "view"; + type: "function"; + }, { inputs: [ { @@ -51,8 +70,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -85,8 +104,8 @@ declare const abi: [ type: "uint8"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; }, { @@ -143,8 +162,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/abi/src/IStore.sol/IStoreRegistration.abi.json b/packages/world/abi/src/IStore.sol/IStoreRegistration.abi.json index 8199933edd..d21d2dd147 100644 --- a/packages/world/abi/src/IStore.sol/IStoreRegistration.abi.json +++ b/packages/world/abi/src/IStore.sol/IStoreRegistration.abi.json @@ -29,6 +29,11 @@ "name": "table", "type": "bytes32" }, + { + "internalType": "FieldLayout", + "name": "fieldLayout", + "type": "bytes32" + }, { "internalType": "Schema", "name": "keySchema", diff --git a/packages/world/abi/src/IStore.sol/IStoreRegistration.abi.json.d.ts b/packages/world/abi/src/IStore.sol/IStoreRegistration.abi.json.d.ts index 02db08cbf2..790883941d 100644 --- a/packages/world/abi/src/IStore.sol/IStoreRegistration.abi.json.d.ts +++ b/packages/world/abi/src/IStore.sol/IStoreRegistration.abi.json.d.ts @@ -29,6 +29,11 @@ declare const abi: [ name: "table"; type: "bytes32"; }, + { + internalType: "FieldLayout"; + name: "fieldLayout"; + type: "bytes32"; + }, { internalType: "Schema"; name: "keySchema"; diff --git a/packages/world/abi/src/IStore.sol/IStoreWrite.abi.json b/packages/world/abi/src/IStore.sol/IStoreWrite.abi.json index e5a35719c0..98b9d2126f 100644 --- a/packages/world/abi/src/IStore.sol/IStoreWrite.abi.json +++ b/packages/world/abi/src/IStore.sol/IStoreWrite.abi.json @@ -87,8 +87,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -120,8 +120,8 @@ "type": "uint256" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -153,8 +153,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -186,8 +186,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -214,8 +214,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -252,8 +252,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/src/IStore.sol/IStoreWrite.abi.json.d.ts b/packages/world/abi/src/IStore.sol/IStoreWrite.abi.json.d.ts index 6c043cda2f..5861267f02 100644 --- a/packages/world/abi/src/IStore.sol/IStoreWrite.abi.json.d.ts +++ b/packages/world/abi/src/IStore.sol/IStoreWrite.abi.json.d.ts @@ -87,8 +87,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -120,8 +120,8 @@ declare const abi: [ type: "uint256"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -153,8 +153,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -186,8 +186,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -214,8 +214,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -252,8 +252,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/abi/src/IStoreHook.sol/IStoreHook.abi.json b/packages/world/abi/src/IStoreHook.sol/IStoreHook.abi.json index b35f6251af..206689d652 100644 --- a/packages/world/abi/src/IStoreHook.sol/IStoreHook.abi.json +++ b/packages/world/abi/src/IStoreHook.sol/IStoreHook.abi.json @@ -12,8 +12,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -45,8 +45,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -73,8 +73,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -96,8 +96,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -129,8 +129,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -157,8 +157,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/src/IStoreHook.sol/IStoreHook.abi.json.d.ts b/packages/world/abi/src/IStoreHook.sol/IStoreHook.abi.json.d.ts index ae36ae3637..4fafcfbee3 100644 --- a/packages/world/abi/src/IStoreHook.sol/IStoreHook.abi.json.d.ts +++ b/packages/world/abi/src/IStoreHook.sol/IStoreHook.abi.json.d.ts @@ -12,8 +12,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -45,8 +45,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -73,8 +73,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -96,8 +96,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -129,8 +129,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -157,8 +157,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/abi/src/StoreCore.sol/StoreCore.abi.json b/packages/world/abi/src/StoreCore.sol/StoreCore.abi.json index 72f144fcd2..fb85ad946b 100644 --- a/packages/world/abi/src/StoreCore.sol/StoreCore.abi.json +++ b/packages/world/abi/src/StoreCore.sol/StoreCore.abi.json @@ -61,7 +61,7 @@ { "indexed": false, "internalType": "uint8", - "name": "schemaIndex", + "name": "fieldIndex", "type": "uint8" }, { diff --git a/packages/world/abi/src/StoreCore.sol/StoreCore.abi.json.d.ts b/packages/world/abi/src/StoreCore.sol/StoreCore.abi.json.d.ts index efd33cd781..60f914b4e1 100644 --- a/packages/world/abi/src/StoreCore.sol/StoreCore.abi.json.d.ts +++ b/packages/world/abi/src/StoreCore.sol/StoreCore.abi.json.d.ts @@ -61,7 +61,7 @@ declare const abi: [ { indexed: false; internalType: "uint8"; - name: "schemaIndex"; + name: "fieldIndex"; type: "uint8"; }, { diff --git a/packages/world/abi/src/StoreHook.sol/StoreHook.abi.json b/packages/world/abi/src/StoreHook.sol/StoreHook.abi.json index 3d219e7777..84037ddd5e 100644 --- a/packages/world/abi/src/StoreHook.sol/StoreHook.abi.json +++ b/packages/world/abi/src/StoreHook.sol/StoreHook.abi.json @@ -12,8 +12,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -45,8 +45,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -73,8 +73,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -96,8 +96,8 @@ "type": "bytes32[]" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -129,8 +129,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], @@ -157,8 +157,8 @@ "type": "bytes" }, { - "internalType": "Schema", - "name": "valueSchema", + "internalType": "FieldLayout", + "name": "fieldLayout", "type": "bytes32" } ], diff --git a/packages/world/abi/src/StoreHook.sol/StoreHook.abi.json.d.ts b/packages/world/abi/src/StoreHook.sol/StoreHook.abi.json.d.ts index 494a46cc19..96c3279f30 100644 --- a/packages/world/abi/src/StoreHook.sol/StoreHook.abi.json.d.ts +++ b/packages/world/abi/src/StoreHook.sol/StoreHook.abi.json.d.ts @@ -12,8 +12,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -45,8 +45,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -73,8 +73,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -96,8 +96,8 @@ declare const abi: [ type: "bytes32[]"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -129,8 +129,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; @@ -157,8 +157,8 @@ declare const abi: [ type: "bytes"; }, { - internalType: "Schema"; - name: "valueSchema"; + internalType: "FieldLayout"; + name: "fieldLayout"; type: "bytes32"; } ]; diff --git a/packages/world/gas-report.json b/packages/world/gas-report.json index 11e7d508fa..6ec43db51b 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": 12746 + "gasUsed": 13860 }, { "file": "test/AccessControl.t.sol", "test": "testAccessControl", "name": "AccessControl: hasAccess (warm, namespace only)", - "gasUsed": 3451 + "gasUsed": 4007 }, { "file": "test/AccessControl.t.sol", "test": "testAccessControl", "name": "AccessControl: hasAccess (warm)", - "gasUsed": 6779 + "gasUsed": 7892 }, { "file": "test/AccessControl.t.sol", "test": "testRequireAccess", "name": "AccessControl: requireAccess (cold)", - "gasUsed": 12789 + "gasUsed": 13903 }, { "file": "test/AccessControl.t.sol", "test": "testRequireAccess", "name": "AccessControl: requireAccess (warm)", - "gasUsed": 6795 + "gasUsed": 7909 }, { "file": "test/AccessControl.t.sol", @@ -39,73 +39,73 @@ "file": "test/KeysInTableModule.t.sol", "test": "testInstallComposite", "name": "install keys in table module", - "gasUsed": 1438155 + "gasUsed": 1519694 }, { "file": "test/KeysInTableModule.t.sol", "test": "testInstallGas", "name": "install keys in table module", - "gasUsed": 1438155 + "gasUsed": 1519694 }, { "file": "test/KeysInTableModule.t.sol", "test": "testInstallGas", "name": "set a record on a table with keysInTableModule installed", - "gasUsed": 180111 + "gasUsed": 183330 }, { "file": "test/KeysInTableModule.t.sol", "test": "testInstallSingleton", "name": "install keys in table module", - "gasUsed": 1438155 + "gasUsed": 1519694 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookCompositeGas", "name": "install keys in table module", - "gasUsed": 1438155 + "gasUsed": 1519694 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookCompositeGas", "name": "change a composite record on a table with keysInTableModule installed", - "gasUsed": 26196 + "gasUsed": 28471 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookCompositeGas", "name": "delete a composite record on a table with keysInTableModule installed", - "gasUsed": 251113 + "gasUsed": 251350 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookGas", "name": "install keys in table module", - "gasUsed": 1438155 + "gasUsed": 1519694 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookGas", "name": "change a record on a table with keysInTableModule installed", - "gasUsed": 24916 + "gasUsed": 27194 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookGas", "name": "delete a record on a table with keysInTableModule installed", - "gasUsed": 129402 + "gasUsed": 132776 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testGetKeysWithValueGas", "name": "install keys with value module", - "gasUsed": 681318 + "gasUsed": 728670 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testGetKeysWithValueGas", "name": "Get list of keys with a given value", - "gasUsed": 6909 + "gasUsed": 7486 }, { "file": "test/KeysWithValueModule.t.sol", @@ -117,264 +117,264 @@ "file": "test/KeysWithValueModule.t.sol", "test": "testInstall", "name": "install keys with value module", - "gasUsed": 681318 + "gasUsed": 728670 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testInstall", "name": "set a record on a table with KeysWithValueModule installed", - "gasUsed": 149428 + "gasUsed": 157267 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testSetAndDeleteRecordHook", "name": "install keys with value module", - "gasUsed": 681318 + "gasUsed": 728670 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testSetAndDeleteRecordHook", "name": "change a record on a table with KeysWithValueModule installed", - "gasUsed": 118391 + "gasUsed": 126277 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testSetAndDeleteRecordHook", "name": "delete a record on a table with KeysWithValueModule installed", - "gasUsed": 44004 + "gasUsed": 49021 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testSetField", "name": "install keys with value module", - "gasUsed": 681318 + "gasUsed": 728670 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testSetField", "name": "set a field on a table with KeysWithValueModule installed", - "gasUsed": 156137 + "gasUsed": 163755 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testSetField", "name": "change a field on a table with KeysWithValueModule installed", - "gasUsed": 120895 + "gasUsed": 128514 }, { "file": "test/query.t.sol", "test": "testCombinedHasHasValueNotQuery", "name": "CombinedHasHasValueNotQuery", - "gasUsed": 165699 + "gasUsed": 141202 }, { "file": "test/query.t.sol", "test": "testCombinedHasHasValueQuery", "name": "CombinedHasHasValueQuery", - "gasUsed": 75996 + "gasUsed": 69011 }, { "file": "test/query.t.sol", "test": "testCombinedHasNotQuery", "name": "CombinedHasNotQuery", - "gasUsed": 229855 + "gasUsed": 184270 }, { "file": "test/query.t.sol", "test": "testCombinedHasQuery", "name": "CombinedHasQuery", - "gasUsed": 151588 + "gasUsed": 122090 }, { "file": "test/query.t.sol", "test": "testCombinedHasValueNotQuery", "name": "CombinedHasValueNotQuery", - "gasUsed": 143470 + "gasUsed": 117822 }, { "file": "test/query.t.sol", "test": "testCombinedHasValueQuery", "name": "CombinedHasValueQuery", - "gasUsed": 17949 + "gasUsed": 19120 }, { "file": "test/query.t.sol", "test": "testHasQuery", "name": "HasQuery", - "gasUsed": 34883 + "gasUsed": 27974 }, { "file": "test/query.t.sol", "test": "testHasQuery1000Keys", "name": "HasQuery with 1000 keys", - "gasUsed": 9272645 + "gasUsed": 7068034 }, { "file": "test/query.t.sol", "test": "testHasQuery100Keys", "name": "HasQuery with 100 keys", - "gasUsed": 861378 + "gasUsed": 672254 }, { "file": "test/query.t.sol", "test": "testHasValueQuery", "name": "HasValueQuery", - "gasUsed": 8651 + "gasUsed": 9237 }, { "file": "test/query.t.sol", "test": "testNotValueQuery", "name": "NotValueQuery", - "gasUsed": 69590 + "gasUsed": 62610 }, { "file": "test/StandardDelegationsModule.t.sol", "test": "testCallFromCallboundDelegation", "name": "register a callbound delegation", - "gasUsed": 127108 + "gasUsed": 133339 }, { "file": "test/StandardDelegationsModule.t.sol", "test": "testCallFromCallboundDelegation", "name": "call a system via a callbound delegation", - "gasUsed": 44406 + "gasUsed": 49400 }, { "file": "test/StandardDelegationsModule.t.sol", "test": "testCallFromTimeboundDelegation", "name": "register a timebound delegation", - "gasUsed": 121379 + "gasUsed": 127695 }, { "file": "test/StandardDelegationsModule.t.sol", "test": "testCallFromTimeboundDelegation", "name": "call a system via a timebound delegation", - "gasUsed": 35111 + "gasUsed": 38491 }, { "file": "test/UniqueEntityModule.t.sol", "test": "testInstall", "name": "install unique entity module", - "gasUsed": 731650 + "gasUsed": 788009 }, { "file": "test/UniqueEntityModule.t.sol", "test": "testInstall", "name": "get a unique entity nonce (non-root module)", - "gasUsed": 62871 + "gasUsed": 67487 }, { "file": "test/UniqueEntityModule.t.sol", "test": "testInstallRoot", "name": "installRoot unique entity module", - "gasUsed": 716849 + "gasUsed": 771491 }, { "file": "test/UniqueEntityModule.t.sol", "test": "testInstallRoot", "name": "get a unique entity nonce (root module)", - "gasUsed": 62871 + "gasUsed": 67487 }, { "file": "test/World.t.sol", "test": "testCall", "name": "call a system via the World", - "gasUsed": 17615 + "gasUsed": 19578 }, { "file": "test/World.t.sol", "test": "testCallFromUnlimitedDelegation", "name": "register an unlimited delegation", - "gasUsed": 55635 + "gasUsed": 59058 }, { "file": "test/World.t.sol", "test": "testCallFromUnlimitedDelegation", "name": "call a system via an unlimited delegation", - "gasUsed": 17989 + "gasUsed": 19964 }, { "file": "test/World.t.sol", "test": "testDeleteRecord", "name": "Delete record", - "gasUsed": 12229 + "gasUsed": 13858 }, { "file": "test/World.t.sol", "test": "testPushToField", "name": "Push data to the table", - "gasUsed": 91397 + "gasUsed": 93235 }, { "file": "test/World.t.sol", "test": "testRegisterFallbackSystem", "name": "Register a fallback system", - "gasUsed": 70603 + "gasUsed": 75428 }, { "file": "test/World.t.sol", "test": "testRegisterFallbackSystem", "name": "Register a root fallback system", - "gasUsed": 63918 + "gasUsed": 68677 }, { "file": "test/World.t.sol", "test": "testRegisterFunctionSelector", "name": "Register a function selector", - "gasUsed": 91197 + "gasUsed": 96022 }, { "file": "test/World.t.sol", "test": "testRegisterNamespace", "name": "Register a new namespace", - "gasUsed": 140243 + "gasUsed": 146385 }, { "file": "test/World.t.sol", "test": "testRegisterRootFunctionSelector", "name": "Register a root function selector", - "gasUsed": 85836 + "gasUsed": 90595 }, { "file": "test/World.t.sol", "test": "testRegisterTable", "name": "Register a new table in the namespace", - "gasUsed": 650451 + "gasUsed": 685351 }, { "file": "test/World.t.sol", "test": "testSetField", "name": "Write data to a table field", - "gasUsed": 40722 + "gasUsed": 41938 }, { "file": "test/World.t.sol", "test": "testSetRecord", "name": "Write data to the table", - "gasUsed": 39585 + "gasUsed": 41383 }, { "file": "test/WorldDynamicUpdate.t.sol", "test": "testPopFromField", "name": "pop 1 address (cold)", - "gasUsed": 31097 + "gasUsed": 32936 }, { "file": "test/WorldDynamicUpdate.t.sol", "test": "testPopFromField", "name": "pop 1 address (warm)", - "gasUsed": 17887 + "gasUsed": 19725 }, { "file": "test/WorldDynamicUpdate.t.sol", "test": "testUpdateInField", "name": "updateInField 1 item (cold)", - "gasUsed": 33509 + "gasUsed": 35347 }, { "file": "test/WorldDynamicUpdate.t.sol", "test": "testUpdateInField", "name": "updateInField 1 item (warm)", - "gasUsed": 20713 + "gasUsed": 22552 } ] diff --git a/packages/world/src/World.sol b/packages/world/src/World.sol index 8d5abb4b99..90859ba849 100644 --- a/packages/world/src/World.sol +++ b/packages/world/src/World.sol @@ -5,7 +5,7 @@ import { StoreRead } from "@latticexyz/store/src/StoreRead.sol"; import { IStoreData } from "@latticexyz/store/src/IStore.sol"; import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; import { Bytes } from "@latticexyz/store/src/Bytes.sol"; -import { Schema } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; import { System } from "./System.sol"; import { ResourceSelector } from "./ResourceSelector.sol"; @@ -75,12 +75,17 @@ contract World is StoreRead, IStoreData, IWorldKernel { * Write a record in the table at the given tableId. * Requires the caller to have access to the table's namespace or name (encoded in the tableId). */ - function setRecord(bytes32 tableId, bytes32[] calldata key, bytes calldata data, Schema valueSchema) public virtual { + function setRecord( + bytes32 tableId, + bytes32[] calldata key, + bytes calldata data, + FieldLayout fieldLayout + ) public virtual { // Require access to the namespace or name AccessControl.requireAccess(tableId, msg.sender); // Set the record - StoreCore.setRecord(tableId, key, data, valueSchema); + StoreCore.setRecord(tableId, key, data, fieldLayout); } /** @@ -92,13 +97,13 @@ contract World is StoreRead, IStoreData, IWorldKernel { bytes32[] calldata key, uint8 schemaIndex, bytes calldata data, - Schema valueSchema + FieldLayout fieldLayout ) public virtual { // Require access to namespace or name AccessControl.requireAccess(tableId, msg.sender); // Set the field - StoreCore.setField(tableId, key, schemaIndex, data, valueSchema); + StoreCore.setField(tableId, key, schemaIndex, data, fieldLayout); } /** @@ -110,13 +115,13 @@ contract World is StoreRead, IStoreData, IWorldKernel { bytes32[] calldata key, uint8 schemaIndex, bytes calldata dataToPush, - Schema valueSchema + FieldLayout fieldLayout ) public virtual { // Require access to namespace or name AccessControl.requireAccess(tableId, msg.sender); // Push to the field - StoreCore.pushToField(tableId, key, schemaIndex, dataToPush, valueSchema); + StoreCore.pushToField(tableId, key, schemaIndex, dataToPush, fieldLayout); } /** @@ -128,13 +133,13 @@ contract World is StoreRead, IStoreData, IWorldKernel { bytes32[] calldata key, uint8 schemaIndex, uint256 byteLengthToPop, - Schema valueSchema + FieldLayout fieldLayout ) public virtual { // Require access to namespace or name AccessControl.requireAccess(tableId, msg.sender); // Push to the field - StoreCore.popFromField(tableId, key, schemaIndex, byteLengthToPop, valueSchema); + StoreCore.popFromField(tableId, key, schemaIndex, byteLengthToPop, fieldLayout); } /** @@ -147,25 +152,25 @@ contract World is StoreRead, IStoreData, IWorldKernel { uint8 schemaIndex, uint256 startByteIndex, bytes calldata dataToSet, - Schema valueSchema + FieldLayout fieldLayout ) public virtual { // Require access to namespace or name AccessControl.requireAccess(tableId, msg.sender); // Update data in the field - StoreCore.updateInField(tableId, key, schemaIndex, startByteIndex, dataToSet, valueSchema); + StoreCore.updateInField(tableId, key, schemaIndex, startByteIndex, dataToSet, fieldLayout); } /** * Delete a record in the table at the given tableId. * Requires the caller to have access to the namespace or name. */ - function deleteRecord(bytes32 tableId, bytes32[] calldata key, Schema valueSchema) public virtual { + function deleteRecord(bytes32 tableId, bytes32[] calldata key, FieldLayout fieldLayout) public virtual { // Require access to namespace or name AccessControl.requireAccess(tableId, msg.sender); // Delete the record - StoreCore.deleteRecord(tableId, key, valueSchema); + StoreCore.deleteRecord(tableId, key, fieldLayout); } /************************************************************************ diff --git a/packages/world/src/interfaces/IWorldKernel.sol b/packages/world/src/interfaces/IWorldKernel.sol index 4016a56772..8cf3511269 100644 --- a/packages/world/src/interfaces/IWorldKernel.sol +++ b/packages/world/src/interfaces/IWorldKernel.sol @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.0; -import { Schema } from "@latticexyz/store/src/Schema.sol"; import { IWorldErrors } from "./IWorldErrors.sol"; import { IModule } from "./IModule.sol"; diff --git a/packages/world/src/modules/core/implementations/EphemeralRecordSystem.sol b/packages/world/src/modules/core/implementations/EphemeralRecordSystem.sol index d52278520c..14aa949c04 100644 --- a/packages/world/src/modules/core/implementations/EphemeralRecordSystem.sol +++ b/packages/world/src/modules/core/implementations/EphemeralRecordSystem.sol @@ -2,7 +2,8 @@ pragma solidity >=0.8.0; import { IStoreEphemeral } from "@latticexyz/store/src/IStore.sol"; -import { Schema } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { IModule } from "../../../interfaces/IModule.sol"; import { System } from "../../../System.sol"; import { ResourceSelector } from "../../../ResourceSelector.sol"; import { AccessControl } from "../../../AccessControl.sol"; @@ -19,12 +20,12 @@ contract EphemeralRecordSystem is IStoreEphemeral, System { bytes32 resourceSelector, bytes32[] calldata key, bytes calldata data, - Schema valueSchema + FieldLayout fieldLayout ) public virtual { // Require access to the namespace or name AccessControl.requireAccess(resourceSelector, msg.sender); // Set the record - StoreCore.emitEphemeralRecord(resourceSelector, key, data, valueSchema); + StoreCore.emitEphemeralRecord(resourceSelector, key, data, fieldLayout); } } diff --git a/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol b/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol index a4ac826eaf..6281cab124 100644 --- a/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol +++ b/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol @@ -3,6 +3,7 @@ pragma solidity >=0.8.0; import { IStoreHook, STORE_HOOK_INTERFACE_ID } from "@latticexyz/store/src/IStoreHook.sol"; import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema } from "@latticexyz/store/src/Schema.sol"; import { System } from "../../../System.sol"; @@ -37,6 +38,7 @@ contract StoreRegistrationSystem is System, IWorldErrors { */ function registerTable( bytes32 resourceSelector, + FieldLayout fieldLayout, Schema keySchema, Schema valueSchema, string[] calldata keyNames, @@ -48,7 +50,7 @@ contract StoreRegistrationSystem is System, IWorldErrors { // If the namespace doesn't exist yet, register it bytes16 namespace = resourceSelector.getNamespace(); if (ResourceType.get(namespace) == Resource.NONE) { - // We can't call IBaseWorld(this).registerSchema directly because it would be handled like + // We can't call IBaseWorld(this).registerNamespace directly because it would be handled like // an external call, so msg.sender would be the address of the World contract (address systemAddress, ) = Systems.get(ResourceSelector.from(ROOT_NAMESPACE, CORE_SYSTEM_NAME)); WorldContextProvider.delegatecallWithContextOrRevert({ @@ -71,7 +73,7 @@ contract StoreRegistrationSystem is System, IWorldErrors { ResourceType.set(resourceSelector, Resource.TABLE); // Register the table's schema - StoreCore.registerTable(resourceSelector, keySchema, valueSchema, keyNames, fieldNames); + StoreCore.registerTable(resourceSelector, fieldLayout, keySchema, valueSchema, keyNames, fieldNames); } /** diff --git a/packages/world/src/modules/core/tables/Balances.sol b/packages/world/src/modules/core/tables/Balances.sol index 2242c6a1ad..c1ccd74606 100644 --- a/packages/world/src/modules/core/tables/Balances.sol +++ b/packages/world/src/modules/core/tables/Balances.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,14 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Balan bytes32 constant BalancesTableId = _tableId; library Balances { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 32; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -49,14 +58,21 @@ library Balances { fieldNames[0] = "balance"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get balance */ @@ -64,7 +80,7 @@ library Balances { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint256(Bytes.slice32(_blob, 0))); } @@ -73,7 +89,7 @@ library Balances { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint256(Bytes.slice32(_blob, 0))); } @@ -82,7 +98,7 @@ library Balances { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((balance)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((balance)), getFieldLayout()); } /** Set balance (using the specified store) */ @@ -90,15 +106,15 @@ library Balances { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((balance)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((balance)), getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(uint256 balance) internal pure returns (bytes memory) { return abi.encodePacked(balance); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes16 namespace) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); @@ -111,7 +127,7 @@ library Balances { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -119,6 +135,6 @@ library Balances { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/world/src/modules/core/tables/FunctionSelectors.sol b/packages/world/src/modules/core/tables/FunctionSelectors.sol index 7e87cd6ad0..70b3329a17 100644 --- a/packages/world/src/modules/core/tables/FunctionSelectors.sol +++ b/packages/world/src/modules/core/tables/FunctionSelectors.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,15 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Funct bytes32 constant FunctionSelectorsTableId = _tableId; library FunctionSelectors { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](2); + _fieldLayout[0] = 32; + _fieldLayout[1] = 4; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -51,14 +61,21 @@ library FunctionSelectors { fieldNames[1] = "systemFunctionSelector"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get resourceSelector */ @@ -66,7 +83,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (Bytes.slice32(_blob, 0)); } @@ -78,7 +95,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (Bytes.slice32(_blob, 0)); } @@ -87,7 +104,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((resourceSelector)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((resourceSelector)), getFieldLayout()); } /** Set resourceSelector (using the specified store) */ @@ -95,7 +112,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((resourceSelector)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((resourceSelector)), getFieldLayout()); } /** Get systemFunctionSelector */ @@ -103,7 +120,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (Bytes.slice4(_blob, 0)); } @@ -115,7 +132,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (Bytes.slice4(_blob, 0)); } @@ -124,7 +141,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((systemFunctionSelector)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((systemFunctionSelector)), getFieldLayout()); } /** Set systemFunctionSelector (using the specified store) */ @@ -132,7 +149,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((systemFunctionSelector)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((systemFunctionSelector)), getFieldLayout()); } /** Get the full data */ @@ -142,7 +159,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -154,7 +171,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -165,7 +182,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - StoreSwitch.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using individual values (using the specified store) */ @@ -180,22 +197,22 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - _store.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + _store.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } - /** Decode the tightly packed blob using this table's schema */ + /** Decode the tightly packed blob using this table's field layout */ function decode(bytes memory _blob) internal pure returns (bytes32 resourceSelector, bytes4 systemFunctionSelector) { resourceSelector = (Bytes.slice32(_blob, 0)); systemFunctionSelector = (Bytes.slice4(_blob, 32)); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(bytes32 resourceSelector, bytes4 systemFunctionSelector) internal pure returns (bytes memory) { return abi.encodePacked(resourceSelector, systemFunctionSelector); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes4 functionSelector) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); @@ -208,7 +225,7 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -216,6 +233,6 @@ library FunctionSelectors { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(functionSelector); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/world/src/modules/core/tables/ResourceType.sol b/packages/world/src/modules/core/tables/ResourceType.sol index 74bd1179fd..cf99407ecf 100644 --- a/packages/world/src/modules/core/tables/ResourceType.sol +++ b/packages/world/src/modules/core/tables/ResourceType.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -24,6 +25,14 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Resou bytes32 constant ResourceTypeTableId = _tableId; library ResourceType { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 1; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -52,14 +61,21 @@ library ResourceType { fieldNames[0] = "resourceType"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get resourceType */ @@ -67,7 +83,7 @@ library ResourceType { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return Resource(uint8(Bytes.slice1(_blob, 0))); } @@ -76,7 +92,7 @@ library ResourceType { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return Resource(uint8(Bytes.slice1(_blob, 0))); } @@ -85,7 +101,7 @@ library ResourceType { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(resourceType)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(resourceType)), getFieldLayout()); } /** Set resourceType (using the specified store) */ @@ -93,15 +109,15 @@ library ResourceType { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(resourceType)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(resourceType)), getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(Resource resourceType) internal pure returns (bytes memory) { return abi.encodePacked(resourceType); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes32 resourceSelector) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; @@ -114,7 +130,7 @@ library ResourceType { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -122,6 +138,6 @@ library ResourceType { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/world/src/modules/core/tables/SystemHooks.sol b/packages/world/src/modules/core/tables/SystemHooks.sol index c0699e5a4e..891623d6b4 100644 --- a/packages/world/src/modules/core/tables/SystemHooks.sol +++ b/packages/world/src/modules/core/tables/SystemHooks.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,13 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Syste bytes32 constant SystemHooksTableId = _tableId; library SystemHooks { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](0); + + return FieldLayoutLib.encode(_fieldLayout, 1); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -49,14 +57,21 @@ library SystemHooks { fieldNames[0] = "value"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get value */ @@ -64,7 +79,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } @@ -73,7 +88,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } @@ -82,7 +97,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getFieldLayout()); } /** Set value (using the specified store) */ @@ -90,7 +105,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getFieldLayout()); } /** Get the length of value */ @@ -98,7 +113,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 21; } @@ -109,7 +124,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 21; } @@ -128,7 +143,7 @@ library SystemHooks { _tableId, _keyTuple, 0, - getValueSchema(), + getFieldLayout(), _index * 21, (_index + 1) * 21 ); @@ -149,7 +164,7 @@ library SystemHooks { _tableId, _keyTuple, 0, - getValueSchema(), + getFieldLayout(), _index * 21, (_index + 1) * 21 ); @@ -162,7 +177,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to value (using the specified store) */ @@ -170,7 +185,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from value */ @@ -178,7 +193,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.popFromField(_tableId, _keyTuple, 0, 21, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 21, getFieldLayout()); } /** Pop an element from value (using the specified store) */ @@ -186,7 +201,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.popFromField(_tableId, _keyTuple, 0, 21, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 0, 21, getFieldLayout()); } /** @@ -198,7 +213,7 @@ library SystemHooks { _keyTuple[0] = resourceSelector; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), getFieldLayout()); } } @@ -211,11 +226,11 @@ library SystemHooks { _keyTuple[0] = resourceSelector; unchecked { - _store.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), getFieldLayout()); } } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(bytes21[] memory value) internal pure returns (bytes memory) { PackedCounter _encodedLengths; // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits @@ -226,7 +241,7 @@ library SystemHooks { return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode((value))); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes32 resourceSelector) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; @@ -239,7 +254,7 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -247,6 +262,6 @@ library SystemHooks { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/world/src/modules/core/tables/SystemRegistry.sol b/packages/world/src/modules/core/tables/SystemRegistry.sol index f1923a50af..d560340662 100644 --- a/packages/world/src/modules/core/tables/SystemRegistry.sol +++ b/packages/world/src/modules/core/tables/SystemRegistry.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,14 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Syste bytes32 constant SystemRegistryTableId = _tableId; library SystemRegistry { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 32; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -49,14 +58,21 @@ library SystemRegistry { fieldNames[0] = "resourceSelector"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get resourceSelector */ @@ -64,7 +80,7 @@ library SystemRegistry { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(system))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (Bytes.slice32(_blob, 0)); } @@ -73,7 +89,7 @@ library SystemRegistry { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(system))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (Bytes.slice32(_blob, 0)); } @@ -82,7 +98,7 @@ library SystemRegistry { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(system))); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((resourceSelector)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((resourceSelector)), getFieldLayout()); } /** Set resourceSelector (using the specified store) */ @@ -90,15 +106,15 @@ library SystemRegistry { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(system))); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((resourceSelector)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((resourceSelector)), getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(bytes32 resourceSelector) internal pure returns (bytes memory) { return abi.encodePacked(resourceSelector); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(address system) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(system))); @@ -111,7 +127,7 @@ library SystemRegistry { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(system))); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -119,6 +135,6 @@ library SystemRegistry { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(uint160(system))); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/world/src/modules/core/tables/Systems.sol b/packages/world/src/modules/core/tables/Systems.sol index 9b0c9568e3..1be8fb6223 100644 --- a/packages/world/src/modules/core/tables/Systems.sol +++ b/packages/world/src/modules/core/tables/Systems.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,15 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Syste bytes32 constant SystemsTableId = _tableId; library Systems { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](2); + _fieldLayout[0] = 20; + _fieldLayout[1] = 1; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -51,14 +61,21 @@ library Systems { fieldNames[1] = "publicAccess"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get system */ @@ -66,7 +83,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (address(Bytes.slice20(_blob, 0))); } @@ -75,7 +92,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (address(Bytes.slice20(_blob, 0))); } @@ -84,7 +101,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((system)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((system)), getFieldLayout()); } /** Set system (using the specified store) */ @@ -92,7 +109,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((system)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((system)), getFieldLayout()); } /** Get publicAccess */ @@ -100,7 +117,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -109,7 +126,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -118,7 +135,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((publicAccess)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((publicAccess)), getFieldLayout()); } /** Set publicAccess (using the specified store) */ @@ -126,7 +143,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((publicAccess)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((publicAccess)), getFieldLayout()); } /** Get the full data */ @@ -134,7 +151,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -143,7 +160,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -154,7 +171,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using individual values (using the specified store) */ @@ -164,22 +181,22 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + _store.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } - /** Decode the tightly packed blob using this table's schema */ + /** Decode the tightly packed blob using this table's field layout */ function decode(bytes memory _blob) internal pure returns (address system, bool publicAccess) { system = (address(Bytes.slice20(_blob, 0))); publicAccess = (_toBool(uint8(Bytes.slice1(_blob, 20)))); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(address system, bool publicAccess) internal pure returns (bytes memory) { return abi.encodePacked(system, publicAccess); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes32 resourceSelector) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; @@ -192,7 +209,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -200,7 +217,7 @@ library Systems { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = resourceSelector; - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/world/src/modules/keysintable/KeysInTableHook.sol b/packages/world/src/modules/keysintable/KeysInTableHook.sol index 79593852b2..2e9a449324 100644 --- a/packages/world/src/modules/keysintable/KeysInTableHook.sol +++ b/packages/world/src/modules/keysintable/KeysInTableHook.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.0; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; import { StoreHook } from "@latticexyz/store/src/StoreHook.sol"; -import { Schema } from "@latticexyz/store/src/Schema.sol"; import { KeysInTable } from "./tables/KeysInTable.sol"; import { UsedKeysIndex } from "./tables/UsedKeysIndex.sol"; @@ -40,23 +40,23 @@ contract KeysInTableHook is StoreHook { } } - function onBeforeSetRecord(bytes32 table, bytes32[] memory key, bytes memory, Schema) public { + function onBeforeSetRecord(bytes32 table, bytes32[] memory key, bytes memory, FieldLayout) public { handleSet(table, key); } - function onAfterSetRecord(bytes32 table, bytes32[] memory key, bytes memory, Schema) public { + function onAfterSetRecord(bytes32 table, bytes32[] memory key, bytes memory, FieldLayout) public { // NOOP } - function onBeforeSetField(bytes32 table, bytes32[] memory key, uint8, bytes memory, Schema) public { + function onBeforeSetField(bytes32 table, bytes32[] memory key, uint8, bytes memory, FieldLayout) public { // NOOP } - function onAfterSetField(bytes32 table, bytes32[] memory key, uint8, bytes memory, Schema) public { + function onAfterSetField(bytes32 table, bytes32[] memory key, uint8, bytes memory, FieldLayout) public { handleSet(table, key); } - function onBeforeDeleteRecord(bytes32 tableId, bytes32[] memory key, Schema) public { + function onBeforeDeleteRecord(bytes32 tableId, bytes32[] memory key, FieldLayout) public { bytes32 keysHash = keccak256(abi.encode(key)); (bool has, uint40 index) = UsedKeysIndex.get(tableId, keysHash); @@ -125,7 +125,7 @@ contract KeysInTableHook is StoreHook { } } - function onAfterDeleteRecord(bytes32 table, bytes32[] memory key, Schema valueSchema) public { + function onAfterDeleteRecord(bytes32 table, bytes32[] memory key, FieldLayout fieldLayout) public { // NOOP } } diff --git a/packages/world/src/modules/keysintable/KeysInTableModule.sol b/packages/world/src/modules/keysintable/KeysInTableModule.sol index 5c18691c58..f04834d110 100644 --- a/packages/world/src/modules/keysintable/KeysInTableModule.sol +++ b/packages/world/src/modules/keysintable/KeysInTableModule.sol @@ -54,6 +54,7 @@ contract KeysInTableModule is Module { world.registerTable, ( KeysInTableTableId, + KeysInTable.getFieldLayout(), KeysInTable.getKeySchema(), KeysInTable.getValueSchema(), KeysInTable.getKeyNames(), @@ -68,6 +69,7 @@ contract KeysInTableModule is Module { world.registerTable, ( UsedKeysIndexTableId, + UsedKeysIndex.getFieldLayout(), UsedKeysIndex.getKeySchema(), UsedKeysIndex.getValueSchema(), UsedKeysIndex.getKeyNames(), diff --git a/packages/world/src/modules/keysintable/tables/KeysInTable.sol b/packages/world/src/modules/keysintable/tables/KeysInTable.sol index c0a6832e7e..0840d6c228 100644 --- a/packages/world/src/modules/keysintable/tables/KeysInTable.sol +++ b/packages/world/src/modules/keysintable/tables/KeysInTable.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -29,6 +30,13 @@ struct KeysInTableData { } library KeysInTable { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](0); + + return FieldLayoutLib.encode(_fieldLayout, 5); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -65,14 +73,21 @@ library KeysInTable { fieldNames[4] = "keys4"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get keys0 */ @@ -80,7 +95,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -89,7 +104,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -98,7 +113,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keys0)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keys0)), getFieldLayout()); } /** Set keys0 (using the specified store) */ @@ -106,7 +121,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keys0)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keys0)), getFieldLayout()); } /** Get the length of keys0 */ @@ -114,7 +129,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 32; } @@ -125,7 +140,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 32; } @@ -144,7 +159,7 @@ library KeysInTable { _tableId, _keyTuple, 0, - getValueSchema(), + getFieldLayout(), _index * 32, (_index + 1) * 32 ); @@ -165,7 +180,7 @@ library KeysInTable { _tableId, _keyTuple, 0, - getValueSchema(), + getFieldLayout(), _index * 32, (_index + 1) * 32 ); @@ -178,7 +193,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to keys0 (using the specified store) */ @@ -186,7 +201,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from keys0 */ @@ -194,7 +209,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.popFromField(_tableId, _keyTuple, 0, 32, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 32, getFieldLayout()); } /** Pop an element from keys0 (using the specified store) */ @@ -202,7 +217,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.popFromField(_tableId, _keyTuple, 0, 32, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 0, 32, getFieldLayout()); } /** @@ -214,7 +229,7 @@ library KeysInTable { _keyTuple[0] = sourceTable; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), getFieldLayout()); } } @@ -227,7 +242,7 @@ library KeysInTable { _keyTuple[0] = sourceTable; unchecked { - _store.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), getFieldLayout()); } } @@ -236,7 +251,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -245,7 +260,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -254,7 +269,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.setField(_tableId, _keyTuple, 1, EncodeArray.encode((keys1)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 1, EncodeArray.encode((keys1)), getFieldLayout()); } /** Set keys1 (using the specified store) */ @@ -262,7 +277,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.setField(_tableId, _keyTuple, 1, EncodeArray.encode((keys1)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 1, EncodeArray.encode((keys1)), getFieldLayout()); } /** Get the length of keys1 */ @@ -270,7 +285,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 1, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 1, getFieldLayout()); unchecked { return _byteLength / 32; } @@ -281,7 +296,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 1, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 1, getFieldLayout()); unchecked { return _byteLength / 32; } @@ -300,7 +315,7 @@ library KeysInTable { _tableId, _keyTuple, 1, - getValueSchema(), + getFieldLayout(), _index * 32, (_index + 1) * 32 ); @@ -321,7 +336,7 @@ library KeysInTable { _tableId, _keyTuple, 1, - getValueSchema(), + getFieldLayout(), _index * 32, (_index + 1) * 32 ); @@ -334,7 +349,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.pushToField(_tableId, _keyTuple, 1, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 1, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to keys1 (using the specified store) */ @@ -342,7 +357,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.pushToField(_tableId, _keyTuple, 1, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 1, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from keys1 */ @@ -350,7 +365,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.popFromField(_tableId, _keyTuple, 1, 32, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 1, 32, getFieldLayout()); } /** Pop an element from keys1 (using the specified store) */ @@ -358,7 +373,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.popFromField(_tableId, _keyTuple, 1, 32, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 1, 32, getFieldLayout()); } /** @@ -370,7 +385,7 @@ library KeysInTable { _keyTuple[0] = sourceTable; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 1, _index * 32, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 1, _index * 32, abi.encodePacked((_element)), getFieldLayout()); } } @@ -383,7 +398,7 @@ library KeysInTable { _keyTuple[0] = sourceTable; unchecked { - _store.updateInField(_tableId, _keyTuple, 1, _index * 32, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 1, _index * 32, abi.encodePacked((_element)), getFieldLayout()); } } @@ -392,7 +407,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -401,7 +416,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -410,7 +425,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.setField(_tableId, _keyTuple, 2, EncodeArray.encode((keys2)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 2, EncodeArray.encode((keys2)), getFieldLayout()); } /** Set keys2 (using the specified store) */ @@ -418,7 +433,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.setField(_tableId, _keyTuple, 2, EncodeArray.encode((keys2)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 2, EncodeArray.encode((keys2)), getFieldLayout()); } /** Get the length of keys2 */ @@ -426,7 +441,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 2, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 2, getFieldLayout()); unchecked { return _byteLength / 32; } @@ -437,7 +452,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 2, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 2, getFieldLayout()); unchecked { return _byteLength / 32; } @@ -456,7 +471,7 @@ library KeysInTable { _tableId, _keyTuple, 2, - getValueSchema(), + getFieldLayout(), _index * 32, (_index + 1) * 32 ); @@ -477,7 +492,7 @@ library KeysInTable { _tableId, _keyTuple, 2, - getValueSchema(), + getFieldLayout(), _index * 32, (_index + 1) * 32 ); @@ -490,7 +505,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to keys2 (using the specified store) */ @@ -498,7 +513,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 2, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from keys2 */ @@ -506,7 +521,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.popFromField(_tableId, _keyTuple, 2, 32, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 2, 32, getFieldLayout()); } /** Pop an element from keys2 (using the specified store) */ @@ -514,7 +529,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.popFromField(_tableId, _keyTuple, 2, 32, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 2, 32, getFieldLayout()); } /** @@ -526,7 +541,7 @@ library KeysInTable { _keyTuple[0] = sourceTable; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 2, _index * 32, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 2, _index * 32, abi.encodePacked((_element)), getFieldLayout()); } } @@ -539,7 +554,7 @@ library KeysInTable { _keyTuple[0] = sourceTable; unchecked { - _store.updateInField(_tableId, _keyTuple, 2, _index * 32, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 2, _index * 32, abi.encodePacked((_element)), getFieldLayout()); } } @@ -548,7 +563,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -557,7 +572,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 3, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 3, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -566,7 +581,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.setField(_tableId, _keyTuple, 3, EncodeArray.encode((keys3)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 3, EncodeArray.encode((keys3)), getFieldLayout()); } /** Set keys3 (using the specified store) */ @@ -574,7 +589,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.setField(_tableId, _keyTuple, 3, EncodeArray.encode((keys3)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 3, EncodeArray.encode((keys3)), getFieldLayout()); } /** Get the length of keys3 */ @@ -582,7 +597,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 3, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 3, getFieldLayout()); unchecked { return _byteLength / 32; } @@ -593,7 +608,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 3, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 3, getFieldLayout()); unchecked { return _byteLength / 32; } @@ -612,7 +627,7 @@ library KeysInTable { _tableId, _keyTuple, 3, - getValueSchema(), + getFieldLayout(), _index * 32, (_index + 1) * 32 ); @@ -633,7 +648,7 @@ library KeysInTable { _tableId, _keyTuple, 3, - getValueSchema(), + getFieldLayout(), _index * 32, (_index + 1) * 32 ); @@ -646,7 +661,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.pushToField(_tableId, _keyTuple, 3, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 3, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to keys3 (using the specified store) */ @@ -654,7 +669,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.pushToField(_tableId, _keyTuple, 3, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 3, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from keys3 */ @@ -662,7 +677,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.popFromField(_tableId, _keyTuple, 3, 32, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 3, 32, getFieldLayout()); } /** Pop an element from keys3 (using the specified store) */ @@ -670,7 +685,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.popFromField(_tableId, _keyTuple, 3, 32, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 3, 32, getFieldLayout()); } /** @@ -682,7 +697,7 @@ library KeysInTable { _keyTuple[0] = sourceTable; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 3, _index * 32, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 3, _index * 32, abi.encodePacked((_element)), getFieldLayout()); } } @@ -695,7 +710,7 @@ library KeysInTable { _keyTuple[0] = sourceTable; unchecked { - _store.updateInField(_tableId, _keyTuple, 3, _index * 32, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 3, _index * 32, abi.encodePacked((_element)), getFieldLayout()); } } @@ -704,7 +719,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 4, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 4, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -713,7 +728,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 4, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 4, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -722,7 +737,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.setField(_tableId, _keyTuple, 4, EncodeArray.encode((keys4)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 4, EncodeArray.encode((keys4)), getFieldLayout()); } /** Set keys4 (using the specified store) */ @@ -730,7 +745,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.setField(_tableId, _keyTuple, 4, EncodeArray.encode((keys4)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 4, EncodeArray.encode((keys4)), getFieldLayout()); } /** Get the length of keys4 */ @@ -738,7 +753,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 4, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 4, getFieldLayout()); unchecked { return _byteLength / 32; } @@ -749,7 +764,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 4, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 4, getFieldLayout()); unchecked { return _byteLength / 32; } @@ -768,7 +783,7 @@ library KeysInTable { _tableId, _keyTuple, 4, - getValueSchema(), + getFieldLayout(), _index * 32, (_index + 1) * 32 ); @@ -789,7 +804,7 @@ library KeysInTable { _tableId, _keyTuple, 4, - getValueSchema(), + getFieldLayout(), _index * 32, (_index + 1) * 32 ); @@ -802,7 +817,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.pushToField(_tableId, _keyTuple, 4, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 4, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to keys4 (using the specified store) */ @@ -810,7 +825,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.pushToField(_tableId, _keyTuple, 4, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 4, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from keys4 */ @@ -818,7 +833,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.popFromField(_tableId, _keyTuple, 4, 32, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 4, 32, getFieldLayout()); } /** Pop an element from keys4 (using the specified store) */ @@ -826,7 +841,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.popFromField(_tableId, _keyTuple, 4, 32, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 4, 32, getFieldLayout()); } /** @@ -838,7 +853,7 @@ library KeysInTable { _keyTuple[0] = sourceTable; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 4, _index * 32, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 4, _index * 32, abi.encodePacked((_element)), getFieldLayout()); } } @@ -851,7 +866,7 @@ library KeysInTable { _keyTuple[0] = sourceTable; unchecked { - _store.updateInField(_tableId, _keyTuple, 4, _index * 32, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 4, _index * 32, abi.encodePacked((_element)), getFieldLayout()); } } @@ -860,7 +875,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -869,7 +884,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -887,7 +902,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using individual values (using the specified store) */ @@ -905,7 +920,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + _store.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using the data struct */ @@ -919,7 +934,7 @@ library KeysInTable { } /** - * Decode the tightly packed blob using this table's schema. + * Decode the tightly packed blob using this table's field layout. * Undefined behaviour for invalid blobs. */ function decode(bytes memory _blob) internal pure returns (KeysInTableData memory _table) { @@ -962,7 +977,7 @@ library KeysInTable { } } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode( bytes32[] memory keys0, bytes32[] memory keys1, @@ -993,7 +1008,7 @@ library KeysInTable { ); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes32 sourceTable) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; @@ -1006,7 +1021,7 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -1014,6 +1029,6 @@ library KeysInTable { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = sourceTable; - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/world/src/modules/keysintable/tables/UsedKeysIndex.sol b/packages/world/src/modules/keysintable/tables/UsedKeysIndex.sol index c83423843e..724610a783 100644 --- a/packages/world/src/modules/keysintable/tables/UsedKeysIndex.sol +++ b/packages/world/src/modules/keysintable/tables/UsedKeysIndex.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,15 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("UsedK bytes32 constant UsedKeysIndexTableId = _tableId; library UsedKeysIndex { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](2); + _fieldLayout[0] = 1; + _fieldLayout[1] = 5; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](2); @@ -53,14 +63,21 @@ library UsedKeysIndex { fieldNames[1] = "index"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get has */ @@ -69,7 +86,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -79,7 +96,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -89,7 +106,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((has)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((has)), getFieldLayout()); } /** Set has (using the specified store) */ @@ -98,7 +115,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((has)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((has)), getFieldLayout()); } /** Get index */ @@ -107,7 +124,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (uint40(Bytes.slice5(_blob, 0))); } @@ -117,7 +134,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (uint40(Bytes.slice5(_blob, 0))); } @@ -127,7 +144,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((index)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((index)), getFieldLayout()); } /** Set index (using the specified store) */ @@ -136,7 +153,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((index)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((index)), getFieldLayout()); } /** Get the full data */ @@ -145,7 +162,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -155,7 +172,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -167,7 +184,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - StoreSwitch.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using individual values (using the specified store) */ @@ -178,22 +195,22 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - _store.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + _store.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } - /** Decode the tightly packed blob using this table's schema */ + /** Decode the tightly packed blob using this table's field layout */ function decode(bytes memory _blob) internal pure returns (bool has, uint40 index) { has = (_toBool(uint8(Bytes.slice1(_blob, 0)))); index = (uint40(Bytes.slice5(_blob, 1))); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(bool has, uint40 index) internal pure returns (bytes memory) { return abi.encodePacked(has, index); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes32 sourceTable, bytes32 keysHash) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = sourceTable; @@ -208,7 +225,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -217,7 +234,7 @@ library UsedKeysIndex { _keyTuple[0] = sourceTable; _keyTuple[1] = keysHash; - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/world/src/modules/keyswithvalue/KeysWithValueHook.sol b/packages/world/src/modules/keyswithvalue/KeysWithValueHook.sol index 666b8c3644..63e66ed8d1 100644 --- a/packages/world/src/modules/keyswithvalue/KeysWithValueHook.sol +++ b/packages/world/src/modules/keyswithvalue/KeysWithValueHook.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.0; import { StoreHook } from "@latticexyz/store/src/StoreHook.sol"; import { Bytes } from "@latticexyz/store/src/Bytes.sol"; -import { Schema } from "@latticexyz/store/src/Schema.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { IBaseWorld } from "../../interfaces/IBaseWorld.sol"; @@ -33,12 +33,12 @@ contract KeysWithValueHook is StoreHook { bytes32 sourceTableId, bytes32[] memory key, bytes memory data, - Schema valueSchema + FieldLayout fieldLayout ) public { bytes32 targetTableId = getTargetTableSelector(MODULE_NAMESPACE, sourceTableId); // Get the previous value - bytes32 previousValue = keccak256(_world().getRecord(sourceTableId, key, valueSchema)); + bytes32 previousValue = keccak256(_world().getRecord(sourceTableId, key, fieldLayout)); // Remove the key from the list of keys with the previous value _removeKeyFromList(targetTableId, key[0], previousValue); @@ -47,7 +47,12 @@ contract KeysWithValueHook is StoreHook { KeysWithValue.push(targetTableId, keccak256(data), key[0]); } - function onAfterSetRecord(bytes32 sourceTableId, bytes32[] memory key, bytes memory data, Schema valueSchema) public { + function onAfterSetRecord( + bytes32 sourceTableId, + bytes32[] memory key, + bytes memory data, + FieldLayout fieldLayout + ) public { // NOOP } @@ -56,10 +61,10 @@ contract KeysWithValueHook is StoreHook { bytes32[] memory key, uint8, bytes memory, - Schema valueSchema + FieldLayout fieldLayout ) public { // Remove the key from the list of keys with the previous value - bytes32 previousValue = keccak256(_world().getRecord(sourceTableId, key, valueSchema)); + bytes32 previousValue = keccak256(_world().getRecord(sourceTableId, key, fieldLayout)); bytes32 targetTableId = getTargetTableSelector(MODULE_NAMESPACE, sourceTableId); _removeKeyFromList(targetTableId, key[0], previousValue); } @@ -69,22 +74,22 @@ contract KeysWithValueHook is StoreHook { bytes32[] memory key, uint8, bytes memory, - Schema valueSchema + FieldLayout fieldLayout ) public { // Add the key to the list of keys with the new value - bytes32 newValue = keccak256(_world().getRecord(sourceTableId, key, valueSchema)); + bytes32 newValue = keccak256(_world().getRecord(sourceTableId, key, fieldLayout)); bytes32 targetTableId = getTargetTableSelector(MODULE_NAMESPACE, sourceTableId); KeysWithValue.push(targetTableId, newValue, key[0]); } - function onBeforeDeleteRecord(bytes32 sourceTableId, bytes32[] memory key, Schema valueSchema) public { + function onBeforeDeleteRecord(bytes32 sourceTableId, bytes32[] memory key, FieldLayout fieldLayout) public { // Remove the key from the list of keys with the previous value - bytes32 previousValue = keccak256(_world().getRecord(sourceTableId, key, valueSchema)); + bytes32 previousValue = keccak256(_world().getRecord(sourceTableId, key, fieldLayout)); bytes32 targetTableId = getTargetTableSelector(MODULE_NAMESPACE, sourceTableId); _removeKeyFromList(targetTableId, key[0], previousValue); } - function onAfterDeleteRecord(bytes32 sourceTableId, bytes32[] memory key, Schema valueSchema) public { + function onAfterDeleteRecord(bytes32 sourceTableId, bytes32[] memory key, FieldLayout fieldLayout) public { // NOOP } diff --git a/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol b/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol index 1f85d91d59..7ef033db5b 100644 --- a/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol +++ b/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol @@ -14,10 +14,18 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; library KeysWithValue { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](0); + + return FieldLayoutLib.encode(_fieldLayout, 1); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -46,14 +54,21 @@ library KeysWithValue { fieldNames[0] = "keysWithValue"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register(bytes32 _tableId) internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store, bytes32 _tableId) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get keysWithValue */ @@ -61,7 +76,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -74,7 +89,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } @@ -83,7 +98,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keysWithValue)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keysWithValue)), getFieldLayout()); } /** Set keysWithValue (using the specified store) */ @@ -91,7 +106,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keysWithValue)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keysWithValue)), getFieldLayout()); } /** Get the length of keysWithValue */ @@ -99,7 +114,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 32; } @@ -110,7 +125,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 32; } @@ -129,7 +144,7 @@ library KeysWithValue { _tableId, _keyTuple, 0, - getValueSchema(), + getFieldLayout(), _index * 32, (_index + 1) * 32 ); @@ -150,7 +165,7 @@ library KeysWithValue { _tableId, _keyTuple, 0, - getValueSchema(), + getFieldLayout(), _index * 32, (_index + 1) * 32 ); @@ -163,7 +178,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to keysWithValue (using the specified store) */ @@ -171,7 +186,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from keysWithValue */ @@ -179,7 +194,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - StoreSwitch.popFromField(_tableId, _keyTuple, 0, 32, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 32, getFieldLayout()); } /** Pop an element from keysWithValue (using the specified store) */ @@ -187,7 +202,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - _store.popFromField(_tableId, _keyTuple, 0, 32, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 0, 32, getFieldLayout()); } /** @@ -199,7 +214,7 @@ library KeysWithValue { _keyTuple[0] = valueHash; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), getFieldLayout()); } } @@ -212,11 +227,11 @@ library KeysWithValue { _keyTuple[0] = valueHash; unchecked { - _store.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), getFieldLayout()); } } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(bytes32[] memory keysWithValue) internal pure returns (bytes memory) { PackedCounter _encodedLengths; // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits @@ -227,7 +242,7 @@ library KeysWithValue { return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode((keysWithValue))); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes32 valueHash) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; @@ -240,7 +255,7 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -248,6 +263,6 @@ library KeysWithValue { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = valueHash; - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol b/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol index 2a0282f97d..3f582631db 100644 --- a/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol +++ b/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,14 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Callb bytes32 constant CallboundDelegationsTableId = _tableId; library CallboundDelegations { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 32; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](4); @@ -55,14 +64,21 @@ library CallboundDelegations { fieldNames[0] = "availableCalls"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get availableCalls */ @@ -78,7 +94,7 @@ library CallboundDelegations { _keyTuple[2] = resourceSelector; _keyTuple[3] = funcSelectorAndArgsHash; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint256(Bytes.slice32(_blob, 0))); } @@ -96,7 +112,7 @@ library CallboundDelegations { _keyTuple[2] = resourceSelector; _keyTuple[3] = funcSelectorAndArgsHash; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint256(Bytes.slice32(_blob, 0))); } @@ -114,7 +130,7 @@ library CallboundDelegations { _keyTuple[2] = resourceSelector; _keyTuple[3] = funcSelectorAndArgsHash; - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), getFieldLayout()); } /** Set availableCalls (using the specified store) */ @@ -132,15 +148,15 @@ library CallboundDelegations { _keyTuple[2] = resourceSelector; _keyTuple[3] = funcSelectorAndArgsHash; - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(uint256 availableCalls) internal pure returns (bytes memory) { return abi.encodePacked(availableCalls); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple( address delegator, address delegatee, @@ -169,7 +185,7 @@ library CallboundDelegations { _keyTuple[2] = resourceSelector; _keyTuple[3] = funcSelectorAndArgsHash; - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -186,6 +202,6 @@ library CallboundDelegations { _keyTuple[2] = resourceSelector; _keyTuple[3] = funcSelectorAndArgsHash; - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/world/src/modules/std-delegations/tables/TimeboundDelegations.sol b/packages/world/src/modules/std-delegations/tables/TimeboundDelegations.sol index 57df78c17a..40fd73e643 100644 --- a/packages/world/src/modules/std-delegations/tables/TimeboundDelegations.sol +++ b/packages/world/src/modules/std-delegations/tables/TimeboundDelegations.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,14 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Timeb bytes32 constant TimeboundDelegationsTableId = _tableId; library TimeboundDelegations { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 32; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](2); @@ -51,14 +60,21 @@ library TimeboundDelegations { fieldNames[0] = "maxTimestamp"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get maxTimestamp */ @@ -67,7 +83,7 @@ library TimeboundDelegations { _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint256(Bytes.slice32(_blob, 0))); } @@ -77,7 +93,7 @@ library TimeboundDelegations { _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint256(Bytes.slice32(_blob, 0))); } @@ -87,7 +103,7 @@ library TimeboundDelegations { _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((maxTimestamp)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((maxTimestamp)), getFieldLayout()); } /** Set maxTimestamp (using the specified store) */ @@ -96,15 +112,15 @@ library TimeboundDelegations { _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((maxTimestamp)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((maxTimestamp)), getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(uint256 maxTimestamp) internal pure returns (bytes memory) { return abi.encodePacked(maxTimestamp); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(address delegator, address delegatee) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(uint160(delegator))); @@ -119,7 +135,7 @@ library TimeboundDelegations { _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -128,6 +144,6 @@ library TimeboundDelegations { _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol b/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol index f7c9cc8fae..7adfa3d80d 100644 --- a/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol +++ b/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol @@ -14,10 +14,19 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; library UniqueEntity { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 32; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](0); @@ -44,21 +53,28 @@ library UniqueEntity { fieldNames[0] = "value"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register(bytes32 _tableId) internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store, bytes32 _tableId) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get value */ function get(bytes32 _tableId) internal view returns (uint256 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint256(Bytes.slice32(_blob, 0))); } @@ -66,7 +82,7 @@ library UniqueEntity { 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, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint256(Bytes.slice32(_blob, 0))); } @@ -74,22 +90,22 @@ library UniqueEntity { function set(bytes32 _tableId, uint256 value) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getFieldLayout()); } /** Set value (using the specified store) */ function set(IStore _store, bytes32 _tableId, uint256 value) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(uint256 value) internal pure returns (bytes memory) { return abi.encodePacked(value); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple() internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](0); @@ -100,13 +116,13 @@ library UniqueEntity { function deleteRecord(bytes32 _tableId) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ function deleteRecord(IStore _store, bytes32 _tableId) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/world/src/tables/Delegations.sol b/packages/world/src/tables/Delegations.sol index 85c695f526..bdc5bf5f4f 100644 --- a/packages/world/src/tables/Delegations.sol +++ b/packages/world/src/tables/Delegations.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,14 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Deleg bytes32 constant DelegationsTableId = _tableId; library Delegations { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 32; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](2); @@ -51,14 +60,21 @@ library Delegations { fieldNames[0] = "delegationControlId"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get delegationControlId */ @@ -67,7 +83,7 @@ library Delegations { _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (Bytes.slice32(_blob, 0)); } @@ -81,7 +97,7 @@ library Delegations { _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (Bytes.slice32(_blob, 0)); } @@ -91,7 +107,7 @@ library Delegations { _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((delegationControlId)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((delegationControlId)), getFieldLayout()); } /** Set delegationControlId (using the specified store) */ @@ -100,15 +116,15 @@ library Delegations { _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((delegationControlId)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((delegationControlId)), getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(bytes32 delegationControlId) internal pure returns (bytes memory) { return abi.encodePacked(delegationControlId); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(address delegator, address delegatee) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(uint160(delegator))); @@ -123,7 +139,7 @@ library Delegations { _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -132,6 +148,6 @@ library Delegations { _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/world/src/tables/InstalledModules.sol b/packages/world/src/tables/InstalledModules.sol index 6add672ab5..9a010b508d 100644 --- a/packages/world/src/tables/InstalledModules.sol +++ b/packages/world/src/tables/InstalledModules.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -25,6 +26,14 @@ struct InstalledModulesData { } library InstalledModules { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 20; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](2); @@ -55,14 +64,21 @@ library InstalledModules { fieldNames[0] = "moduleAddress"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get moduleAddress */ @@ -71,7 +87,7 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (address(Bytes.slice20(_blob, 0))); } @@ -85,7 +101,7 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (address(Bytes.slice20(_blob, 0))); } @@ -95,7 +111,7 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((moduleAddress)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((moduleAddress)), getFieldLayout()); } /** Set moduleAddress (using the specified store) */ @@ -104,7 +120,7 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((moduleAddress)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((moduleAddress)), getFieldLayout()); } /** Get the full data */ @@ -113,7 +129,7 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -127,7 +143,7 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -139,7 +155,7 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - StoreSwitch.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using individual values (using the specified store) */ @@ -150,7 +166,7 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - _store.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + _store.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using the data struct */ @@ -163,17 +179,17 @@ library InstalledModules { set(_store, moduleName, argumentsHash, _table.moduleAddress); } - /** Decode the tightly packed blob using this table's schema */ + /** Decode the tightly packed blob using this table's field layout */ function decode(bytes memory _blob) internal pure returns (InstalledModulesData memory _table) { _table.moduleAddress = (address(Bytes.slice20(_blob, 0))); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(address moduleAddress) internal pure returns (bytes memory) { return abi.encodePacked(moduleAddress); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes16 moduleName, bytes32 argumentsHash) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(moduleName); @@ -188,7 +204,7 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -197,6 +213,6 @@ library InstalledModules { _keyTuple[0] = bytes32(moduleName); _keyTuple[1] = argumentsHash; - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/world/src/tables/NamespaceOwner.sol b/packages/world/src/tables/NamespaceOwner.sol index 4685b734fc..3a57ea199a 100644 --- a/packages/world/src/tables/NamespaceOwner.sol +++ b/packages/world/src/tables/NamespaceOwner.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,14 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Names bytes32 constant NamespaceOwnerTableId = _tableId; library NamespaceOwner { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 20; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -49,14 +58,21 @@ library NamespaceOwner { fieldNames[0] = "owner"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get owner */ @@ -64,7 +80,7 @@ library NamespaceOwner { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (address(Bytes.slice20(_blob, 0))); } @@ -73,7 +89,7 @@ library NamespaceOwner { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (address(Bytes.slice20(_blob, 0))); } @@ -82,7 +98,7 @@ library NamespaceOwner { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((owner)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((owner)), getFieldLayout()); } /** Set owner (using the specified store) */ @@ -90,15 +106,15 @@ library NamespaceOwner { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((owner)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((owner)), getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(address owner) internal pure returns (bytes memory) { return abi.encodePacked(owner); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes16 namespace) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); @@ -111,7 +127,7 @@ library NamespaceOwner { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -119,6 +135,6 @@ library NamespaceOwner { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(namespace); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/world/src/tables/ResourceAccess.sol b/packages/world/src/tables/ResourceAccess.sol index 1d2e090231..529c849038 100644 --- a/packages/world/src/tables/ResourceAccess.sol +++ b/packages/world/src/tables/ResourceAccess.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,14 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Resou bytes32 constant ResourceAccessTableId = _tableId; library ResourceAccess { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 1; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](2); @@ -51,14 +60,21 @@ library ResourceAccess { fieldNames[0] = "access"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get access */ @@ -67,7 +83,7 @@ library ResourceAccess { _keyTuple[0] = resourceSelector; _keyTuple[1] = bytes32(uint256(uint160(caller))); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -77,7 +93,7 @@ library ResourceAccess { _keyTuple[0] = resourceSelector; _keyTuple[1] = bytes32(uint256(uint160(caller))); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -87,7 +103,7 @@ library ResourceAccess { _keyTuple[0] = resourceSelector; _keyTuple[1] = bytes32(uint256(uint160(caller))); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((access)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((access)), getFieldLayout()); } /** Set access (using the specified store) */ @@ -96,15 +112,15 @@ library ResourceAccess { _keyTuple[0] = resourceSelector; _keyTuple[1] = bytes32(uint256(uint160(caller))); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((access)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((access)), getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(bool access) internal pure returns (bytes memory) { return abi.encodePacked(access); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes32 resourceSelector, address caller) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = resourceSelector; @@ -119,7 +135,7 @@ library ResourceAccess { _keyTuple[0] = resourceSelector; _keyTuple[1] = bytes32(uint256(uint160(caller))); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -128,7 +144,7 @@ library ResourceAccess { _keyTuple[0] = resourceSelector; _keyTuple[1] = bytes32(uint256(uint160(caller))); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/world/test/KeysInTableModule.t.sol b/packages/world/test/KeysInTableModule.t.sol index 3446b8e238..3bffe5dafd 100644 --- a/packages/world/test/KeysInTableModule.t.sol +++ b/packages/world/test/KeysInTableModule.t.sol @@ -4,6 +4,8 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; +import { FieldLayoutEncodeHelper } from "@latticexyz/store/test/FieldLayoutEncodeHelper.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { SchemaEncodeHelper } from "@latticexyz/store/test/SchemaEncodeHelper.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; @@ -34,6 +36,7 @@ contract KeysInTableModuleTest is Test, GasReporter { bytes32 private key3 = keccak256("test3"); bytes32[] private keyTuple3; + FieldLayout private tableFieldLayout; Schema private tableValueSchema; Schema private tableKeySchema; Schema private singletonKeySchema; @@ -46,12 +49,12 @@ contract KeysInTableModuleTest is Test, GasReporter { uint256 private val2 = 42; function setUp() public { + tableFieldLayout = FieldLayoutEncodeHelper.encode(32, 0); + tableValueSchema = SchemaEncodeHelper.encode(SchemaType.UINT256); tableKeySchema = SchemaEncodeHelper.encode(SchemaType.BYTES32); compositeKeySchema = SchemaEncodeHelper.encode(SchemaType.BYTES32, SchemaType.BYTES32, SchemaType.BYTES32); - - SchemaType[] memory _schema = new SchemaType[](0); - singletonKeySchema = SchemaLib.encode(_schema); + singletonKeySchema = SchemaLib.encode(new SchemaType[](0)); world = IBaseWorld(address(new World())); world.installRootModule(new CoreModule(), new bytes(0)); @@ -65,9 +68,23 @@ contract KeysInTableModuleTest is Test, GasReporter { function _installKeysInTableModule() internal { // Register source table - world.registerTable(tableId, tableKeySchema, tableValueSchema, new string[](1), new string[](1)); - world.registerTable(singletonTableId, singletonKeySchema, tableValueSchema, new string[](0), new string[](1)); - world.registerTable(compositeTableId, compositeKeySchema, tableValueSchema, new string[](3), new string[](1)); + world.registerTable(tableId, tableFieldLayout, tableKeySchema, tableValueSchema, new string[](1), new string[](1)); + world.registerTable( + singletonTableId, + tableFieldLayout, + singletonKeySchema, + tableValueSchema, + new string[](0), + new string[](1) + ); + world.registerTable( + compositeTableId, + tableFieldLayout, + compositeKeySchema, + tableValueSchema, + new string[](3), + new string[](1) + ); // Install the index module // TODO: add support for installing this via installModule @@ -86,7 +103,7 @@ contract KeysInTableModuleTest is Test, GasReporter { bytes32[] memory keyTuple = new bytes32[](0); - world.setRecord(singletonTableId, keyTuple, abi.encodePacked(val1), tableValueSchema); + world.setRecord(singletonTableId, keyTuple, abi.encodePacked(val1), tableFieldLayout); // Get the list of keys in this target table bytes32[][] memory keysInTable = getKeysInTable(world, singletonTableId); @@ -103,7 +120,7 @@ contract KeysInTableModuleTest is Test, GasReporter { keyTuple[1] = "two"; keyTuple[2] = "three"; - world.setRecord(compositeTableId, keyTuple, abi.encodePacked(val1), tableValueSchema); + world.setRecord(compositeTableId, keyTuple, abi.encodePacked(val1), tableFieldLayout); // Get the list of keys in this target table bytes32[][] memory keysInTable = getKeysInTable(world, compositeTableId); @@ -128,7 +145,7 @@ contract KeysInTableModuleTest is Test, GasReporter { _installKeysInTableModule(); // Set a value in the source table startGasReport("set a record on a table with keysInTableModule installed"); - world.setRecord(tableId, keyTuple1, abi.encodePacked(value), tableValueSchema); + world.setRecord(tableId, keyTuple1, abi.encodePacked(value), tableFieldLayout); endGasReport(); // Get the list of keys in this target table @@ -147,7 +164,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Set a value in the source table startGasReport("set a record on a table with keysInTableModule installed (first)"); - world.setRecord(tableId, keyTuple, abi.encodePacked(value1), tableValueSchema); + world.setRecord(tableId, keyTuple, abi.encodePacked(value1), tableFieldLayout); endGasReport(); // Get the list of keys in the first target table @@ -160,7 +177,14 @@ contract KeysInTableModuleTest is Test, GasReporter { // Install the hook on the second table bytes16 sourceFile2 = bytes16("source2"); bytes32 sourceTableId2 = ResourceSelector.from(namespace, sourceFile2); - world.registerTable(sourceTableId2, tableValueSchema, tableKeySchema, new string[](1), new string[](1)); + world.registerTable( + sourceTableId2, + tableFieldLayout, + tableKeySchema, + tableValueSchema, + new string[](1), + new string[](1) + ); world.installRootModule(keysInTableModule, abi.encode(sourceTableId2)); keyTuple = new bytes32[](1); @@ -168,7 +192,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Set a value in the source table startGasReport("set a record on a table with keysInTableModule installed (second)"); - world.setRecord(sourceTableId2, keyTuple, abi.encodePacked(value2), tableValueSchema); + world.setRecord(sourceTableId2, keyTuple, abi.encodePacked(value2), tableFieldLayout); endGasReport(); // Get the list of keys in the second target table @@ -188,7 +212,7 @@ contract KeysInTableModuleTest is Test, GasReporter { _installKeysInTableModule(); // Set a value in the source table - world.setRecord(tableId, keyTuple1, abi.encodePacked(value1), tableValueSchema); + world.setRecord(tableId, keyTuple1, abi.encodePacked(value1), tableFieldLayout); // Get the list of keys in the target table bytes32[][] memory keysInTable = getKeysInTable(world, tableId); @@ -198,7 +222,7 @@ contract KeysInTableModuleTest is Test, GasReporter { assertEq(keysInTable[0][0], key1, "2"); // Set another key with the same value - world.setRecord(tableId, keyTuple2, abi.encodePacked(value1), tableValueSchema); + world.setRecord(tableId, keyTuple2, abi.encodePacked(value1), tableFieldLayout); // Get the list of keys in the target table keysInTable = getKeysInTable(world, tableId); @@ -210,7 +234,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Change the value of the first key startGasReport("change a record on a table with keysInTableModule installed"); - world.setRecord(tableId, keyTuple1, abi.encodePacked(value2), tableValueSchema); + world.setRecord(tableId, keyTuple1, abi.encodePacked(value2), tableFieldLayout); endGasReport(); // Get the list of keys in the target table @@ -223,7 +247,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Delete the first key startGasReport("delete a record on a table with keysInTableModule installed"); - world.deleteRecord(tableId, keyTuple1, tableValueSchema); + world.deleteRecord(tableId, keyTuple1, tableFieldLayout); endGasReport(); // Get the list of keys in the target table @@ -253,7 +277,7 @@ contract KeysInTableModuleTest is Test, GasReporter { keyTupleB[2] = "charlie"; // Set a value in the source table - world.setRecord(compositeTableId, keyTupleA, abi.encodePacked(value1), tableValueSchema); + world.setRecord(compositeTableId, keyTupleA, abi.encodePacked(value1), tableFieldLayout); // Get the list of keys in the target table bytes32[][] memory keysInTable = getKeysInTable(world, compositeTableId); @@ -265,7 +289,7 @@ contract KeysInTableModuleTest is Test, GasReporter { } // Set another key with the same value - world.setRecord(compositeTableId, keyTupleB, abi.encodePacked(value1), tableValueSchema); + world.setRecord(compositeTableId, keyTupleB, abi.encodePacked(value1), tableFieldLayout); // Get the list of keys in the target table keysInTable = getKeysInTable(world, compositeTableId); @@ -281,7 +305,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Change the value of the first key startGasReport("change a composite record on a table with keysInTableModule installed"); - world.setRecord(compositeTableId, keyTupleA, abi.encodePacked(value2), tableValueSchema); + world.setRecord(compositeTableId, keyTupleA, abi.encodePacked(value2), tableFieldLayout); endGasReport(); // Get the list of keys in the target table @@ -298,7 +322,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Delete the first key startGasReport("delete a composite record on a table with keysInTableModule installed"); - world.deleteRecord(compositeTableId, keyTupleA, tableValueSchema); + world.deleteRecord(compositeTableId, keyTupleA, tableFieldLayout); endGasReport(); // Get the list of keys in the target table @@ -316,7 +340,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Set a value in the source table startGasReport("set a field on a table with keysInTableModule installed"); - world.setField(tableId, keyTuple1, 0, abi.encodePacked(value1), tableValueSchema); + world.setField(tableId, keyTuple1, 0, abi.encodePacked(value1), tableFieldLayout); endGasReport(); // Get the list of keys in the target table @@ -328,7 +352,7 @@ contract KeysInTableModuleTest is Test, GasReporter { // Change the value using setField startGasReport("change a field on a table with keysInTableModule installed"); - world.setField(tableId, keyTuple1, 0, abi.encodePacked(value2), tableValueSchema); + world.setField(tableId, keyTuple1, 0, abi.encodePacked(value2), tableFieldLayout); endGasReport(); // Get the list of keys in the target table @@ -343,7 +367,7 @@ contract KeysInTableModuleTest is Test, GasReporter { _installKeysInTableModule(); // Set a value in the source table - world.setRecord(tableId, keyTuple1, abi.encodePacked(value1), tableValueSchema); + world.setRecord(tableId, keyTuple1, abi.encodePacked(value1), tableFieldLayout); startGasReport("Get list of keys in a given table"); bytes32[][] memory keysInTable = getKeysInTable(world, tableId); @@ -354,7 +378,7 @@ contract KeysInTableModuleTest is Test, GasReporter { assertEq(keysInTable[0][0], key1); // Set another key with a different value - world.setRecord(tableId, keyTuple2, abi.encodePacked(value2), tableValueSchema); + world.setRecord(tableId, keyTuple2, abi.encodePacked(value2), tableFieldLayout); // Get the list of keys in the target table keysInTable = getKeysInTable(world, tableId); @@ -369,14 +393,14 @@ contract KeysInTableModuleTest is Test, GasReporter { _installKeysInTableModule(); // Add 3 values - world.setRecord(tableId, keyTuple1, abi.encodePacked(value), tableValueSchema); - world.setRecord(tableId, keyTuple2, abi.encodePacked(value), tableValueSchema); - world.setRecord(tableId, keyTuple3, abi.encodePacked(value), tableValueSchema); + world.setRecord(tableId, keyTuple1, abi.encodePacked(value), tableFieldLayout); + world.setRecord(tableId, keyTuple2, abi.encodePacked(value), tableFieldLayout); + world.setRecord(tableId, keyTuple3, abi.encodePacked(value), tableFieldLayout); // Remove 2, starting from the middle // This tests that KeysInTable correctly tracks swaps indexes - world.deleteRecord(tableId, keyTuple2, tableValueSchema); - world.deleteRecord(tableId, keyTuple3, tableValueSchema); + world.deleteRecord(tableId, keyTuple2, tableFieldLayout); + world.deleteRecord(tableId, keyTuple3, tableFieldLayout); // Get the list of keys in the target table bytes32[][] memory keysInTable = getKeysInTable(world, tableId); diff --git a/packages/world/test/KeysWithValueModule.t.sol b/packages/world/test/KeysWithValueModule.t.sol index 4e27ae8cc7..708c4cd607 100644 --- a/packages/world/test/KeysWithValueModule.t.sol +++ b/packages/world/test/KeysWithValueModule.t.sol @@ -8,6 +8,9 @@ import { Schema } from "@latticexyz/store/src/Schema.sol"; import { SchemaEncodeHelper } from "@latticexyz/store/test/SchemaEncodeHelper.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { FieldLayoutEncodeHelper } from "@latticexyz/store/test/FieldLayoutEncodeHelper.sol"; + import { World } from "../src/World.sol"; import { IBaseWorld } from "../src/interfaces/IBaseWorld.sol"; import { ResourceSelector } from "../src/ResourceSelector.sol"; @@ -32,12 +35,14 @@ contract KeysWithValueModuleTest is Test, GasReporter { bytes32 key2 = keccak256("test2"); bytes32[] keyTuple2; + FieldLayout sourceTableFieldLayout; Schema sourceTableSchema; Schema sourceTableKeySchema; bytes32 sourceTableId; bytes32 targetTableId; function setUp() public { + sourceTableFieldLayout = FieldLayoutEncodeHelper.encode(32, 0); sourceTableSchema = SchemaEncodeHelper.encode(SchemaType.UINT256); sourceTableKeySchema = SchemaEncodeHelper.encode(SchemaType.BYTES32); world = IBaseWorld(address(new World())); @@ -52,7 +57,14 @@ contract KeysWithValueModuleTest is Test, GasReporter { function _installKeysWithValueModule() internal { // Register source table - world.registerTable(sourceTableId, sourceTableSchema, sourceTableKeySchema, new string[](1), new string[](1)); + world.registerTable( + sourceTableId, + sourceTableFieldLayout, + sourceTableKeySchema, + sourceTableSchema, + new string[](1), + new string[](1) + ); // Install the index module // TODO: add support for installing this via installModule @@ -68,7 +80,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { uint256 value = 1; startGasReport("set a record on a table with KeysWithValueModule installed"); - world.setRecord(sourceTableId, keyTuple1, abi.encodePacked(value), sourceTableSchema); + world.setRecord(sourceTableId, keyTuple1, abi.encodePacked(value), sourceTableFieldLayout); endGasReport(); // Get the list of entities with this value from the target table @@ -85,7 +97,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { // Set a value in the source table uint256 value1 = 1; - world.setRecord(sourceTableId, keyTuple1, abi.encodePacked(value1), sourceTableSchema); + world.setRecord(sourceTableId, keyTuple1, abi.encodePacked(value1), sourceTableFieldLayout); // Get the list of entities with value1 from the target table bytes32[] memory keysWithValue = KeysWithValue.get(world, targetTableId, keccak256(abi.encode(value1))); @@ -95,7 +107,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { assertEq(keysWithValue[0], key1, "2"); // Set a another key with the same value - world.setRecord(sourceTableId, keyTuple2, abi.encodePacked(value1), sourceTableSchema); + world.setRecord(sourceTableId, keyTuple2, abi.encodePacked(value1), sourceTableFieldLayout); // Get the list of entities with value2 from the target table keysWithValue = KeysWithValue.get(world, targetTableId, keccak256(abi.encode(value1))); @@ -109,7 +121,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { uint256 value2 = 2; startGasReport("change a record on a table with KeysWithValueModule installed"); - world.setRecord(sourceTableId, keyTuple1, abi.encodePacked(value2), sourceTableSchema); + world.setRecord(sourceTableId, keyTuple1, abi.encodePacked(value2), sourceTableFieldLayout); endGasReport(); // Get the list of entities with value1 from the target table @@ -128,7 +140,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { // Delete the first key startGasReport("delete a record on a table with KeysWithValueModule installed"); - world.deleteRecord(sourceTableId, keyTuple1, sourceTableSchema); + world.deleteRecord(sourceTableId, keyTuple1, sourceTableFieldLayout); endGasReport(); // Get the list of entities with value2 from the target table @@ -145,7 +157,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { uint256 value1 = 1; startGasReport("set a field on a table with KeysWithValueModule installed"); - world.setField(sourceTableId, keyTuple1, 0, abi.encodePacked(value1), sourceTableSchema); + world.setField(sourceTableId, keyTuple1, 0, abi.encodePacked(value1), sourceTableFieldLayout); endGasReport(); // Get the list of entities with value1 from the target table @@ -159,7 +171,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { // Change the value using setField startGasReport("change a field on a table with KeysWithValueModule installed"); - world.setField(sourceTableId, keyTuple1, 0, abi.encodePacked(value2), sourceTableSchema); + world.setField(sourceTableId, keyTuple1, 0, abi.encodePacked(value2), sourceTableFieldLayout); endGasReport(); // Get the list of entities with value1 from the target table @@ -200,7 +212,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { _installKeysWithValueModule(); // Set a value in the source table - world.setRecord(sourceTableId, keyTuple1, abi.encodePacked(value), sourceTableSchema); + world.setRecord(sourceTableId, keyTuple1, abi.encodePacked(value), sourceTableFieldLayout); startGasReport("Get list of keys with a given value"); bytes32[] memory keysWithValue = getKeysWithValue(world, sourceTableId, abi.encode(value)); @@ -211,7 +223,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { assertEq(keysWithValue[0], key1); // Set a another key with the same value - world.setRecord(sourceTableId, keyTuple2, abi.encodePacked(value), sourceTableSchema); + world.setRecord(sourceTableId, keyTuple2, abi.encodePacked(value), sourceTableFieldLayout); // Get the list of keys with value from the target table keysWithValue = getKeysWithValue(world, sourceTableId, abi.encode(value)); diff --git a/packages/world/test/World.t.sol b/packages/world/test/World.t.sol index 0ba525d918..95510ceeb2 100644 --- a/packages/world/test/World.t.sol +++ b/packages/world/test/World.t.sol @@ -9,9 +9,10 @@ import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol" import { IStoreHook, STORE_HOOK_INTERFACE_ID } from "@latticexyz/store/src/IStoreHook.sol"; import { StoreCore, StoreCoreInternal } from "@latticexyz/store/src/StoreCore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; -import { Schema } from "@latticexyz/store/src/Schema.sol"; -import { SchemaEncodeHelper } from "@latticexyz/store/test/SchemaEncodeHelper.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; +import { FieldLayoutEncodeHelper } from "@latticexyz/store/test/FieldLayoutEncodeHelper.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { SchemaEncodeHelper } from "@latticexyz/store/test/SchemaEncodeHelper.sol"; import { Tables, TablesTableId } from "@latticexyz/store/src/codegen/Tables.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; import { StoreHookLib } from "@latticexyz/store/src/StoreHook.sol"; @@ -87,12 +88,12 @@ contract WorldTestSystem is System { function writeData(bytes16 namespace, bytes16 name, bool data) public { bytes32[] memory key = new bytes32[](0); bytes32 tableId = ResourceSelector.from(namespace, name); - Schema valueSchema = StoreSwitch.getValueSchema(tableId); + FieldLayout fieldLayout = StoreSwitch.getFieldLayout(tableId); if (StoreSwitch.getStoreAddress() == address(this)) { - StoreCore.setRecord(tableId, key, abi.encodePacked(data), valueSchema); + StoreCore.setRecord(tableId, key, abi.encodePacked(data), fieldLayout); } else { - IBaseWorld(msg.sender).setRecord(tableId, key, abi.encodePacked(data), valueSchema); + IBaseWorld(msg.sender).setRecord(tableId, key, abi.encodePacked(data), fieldLayout); } } @@ -182,14 +183,12 @@ contract WorldTest is Test, GasReporter { new World(); // Should have registered the table data table (fka schema table) - assertEq(Tables.getKeySchema(world, TablesTableId), Schema.unwrap(Tables.getKeySchema())); - assertEq(Tables.getValueSchema(world, TablesTableId), Schema.unwrap(Tables.getValueSchema())); + assertEq(Tables.getFieldLayout(world, TablesTableId), FieldLayout.unwrap(Tables.getFieldLayout())); assertEq(Tables.getAbiEncodedKeyNames(world, TablesTableId), abi.encode(Tables.getKeyNames())); assertEq(Tables.getAbiEncodedFieldNames(world, TablesTableId), abi.encode(Tables.getFieldNames())); // Should have registered the namespace owner table - assertEq(Tables.getKeySchema(world, NamespaceOwnerTableId), Schema.unwrap(NamespaceOwner.getKeySchema())); - assertEq(Tables.getValueSchema(world, NamespaceOwnerTableId), Schema.unwrap(NamespaceOwner.getValueSchema())); + assertEq(Tables.getFieldLayout(world, NamespaceOwnerTableId), FieldLayout.unwrap(NamespaceOwner.getFieldLayout())); assertEq(Tables.getAbiEncodedKeyNames(world, NamespaceOwnerTableId), abi.encode(NamespaceOwner.getKeyNames())); assertEq(Tables.getAbiEncodedFieldNames(world, NamespaceOwnerTableId), abi.encode(NamespaceOwner.getFieldNames())); } @@ -290,6 +289,7 @@ contract WorldTest is Test, GasReporter { } function testRegisterTable() public { + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 32, 1); Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.BOOL, SchemaType.UINT256, SchemaType.STRING); bytes16 namespace = "testNamespace"; bytes16 tableName = "testTable"; @@ -302,15 +302,14 @@ contract WorldTest is Test, GasReporter { fieldNames[2] = "value3"; startGasReport("Register a new table in the namespace"); - world.registerTable(tableSelector, defaultKeySchema, valueSchema, keyNames, fieldNames); + world.registerTable(tableSelector, fieldLayout, defaultKeySchema, valueSchema, keyNames, fieldNames); endGasReport(); // Expect the namespace to be created and owned by the caller assertEq(NamespaceOwner.get(world, namespace), address(this), "namespace should be created by caller"); // Expect the table to be registered - assertEq(world.getKeySchema(tableSelector).unwrap(), defaultKeySchema.unwrap(), "key schema should be registered"); - assertEq(world.getValueSchema(tableSelector).unwrap(), valueSchema.unwrap(), "value schema should be registered"); + assertEq(world.getFieldLayout(tableSelector).unwrap(), fieldLayout.unwrap(), "value schema should be registered"); bytes memory loadedKeyNames = Tables.getAbiEncodedKeyNames(world, tableSelector); assertEq(loadedKeyNames, abi.encode(keyNames), "key names should be registered"); @@ -320,16 +319,16 @@ contract WorldTest is Test, GasReporter { // Expect an error when registering an existing table vm.expectRevert(abi.encodeWithSelector(IWorldErrors.ResourceExists.selector, tableSelector.toString())); - world.registerTable(tableSelector, defaultKeySchema, valueSchema, keyNames, fieldNames); + world.registerTable(tableSelector, fieldLayout, defaultKeySchema, valueSchema, keyNames, fieldNames); // Expect an error when registering a table in a namespace that is not owned by the caller bytes32 otherTableSelector = ResourceSelector.from(namespace, "otherTable"); _expectAccessDenied(address(0x01), namespace, ""); - world.registerTable(otherTableSelector, defaultKeySchema, valueSchema, keyNames, fieldNames); + world.registerTable(otherTableSelector, fieldLayout, defaultKeySchema, valueSchema, keyNames, fieldNames); // Expect the World to not be allowed to call registerTable via an external call _expectAccessDenied(address(world), namespace, ""); - world.registerTable(otherTableSelector, defaultKeySchema, valueSchema, keyNames, fieldNames); + world.registerTable(otherTableSelector, fieldLayout, defaultKeySchema, valueSchema, keyNames, fieldNames); } function testRegisterSystem() public { @@ -376,7 +375,14 @@ contract WorldTest is Test, GasReporter { // Expect an error when registering a system at an existing resource selector of a different type System newSystem = new System(); bytes32 tableId = ResourceSelector.from("", "testTable"); - world.registerTable(tableId, defaultKeySchema, Bool.getValueSchema(), new string[](1), new string[](1)); + world.registerTable( + tableId, + Bool.getFieldLayout(), + defaultKeySchema, + Bool.getValueSchema(), + new string[](1), + new string[](1) + ); vm.expectRevert(abi.encodeWithSelector(IWorldErrors.ResourceExists.selector, tableId.toString())); world.registerSystem(tableId, newSystem, true); @@ -439,7 +445,14 @@ contract WorldTest is Test, GasReporter { function testDuplicateSelectors() public { // Register a new table bytes32 resourceSelector = ResourceSelector.from("namespace", "name"); - world.registerTable(resourceSelector, defaultKeySchema, Bool.getValueSchema(), new string[](1), new string[](1)); + world.registerTable( + resourceSelector, + Bool.getFieldLayout(), + defaultKeySchema, + Bool.getValueSchema(), + new string[](1), + new string[](1) + ); // Deploy a new system System system = new System(); @@ -454,7 +467,14 @@ contract WorldTest is Test, GasReporter { // Expect an error when trying to register a table at the same selector vm.expectRevert(abi.encodeWithSelector(IWorldErrors.ResourceExists.selector, resourceSelector2.toString())); - world.registerTable(resourceSelector2, defaultKeySchema, Bool.getValueSchema(), new string[](1), new string[](1)); + world.registerTable( + resourceSelector2, + Bool.getFieldLayout(), + defaultKeySchema, + Bool.getValueSchema(), + new string[](1), + new string[](1) + ); } function testGrantAccess() public { @@ -468,7 +488,14 @@ contract WorldTest is Test, GasReporter { function testSetRecord() public { bytes32 tableId = ResourceSelector.from("testSetRecord", "testTable"); // Register a new table - world.registerTable(tableId, defaultKeySchema, Bool.getValueSchema(), new string[](1), new string[](1)); + world.registerTable( + tableId, + Bool.getFieldLayout(), + defaultKeySchema, + Bool.getValueSchema(), + new string[](1), + new string[](1) + ); startGasReport("Write data to the table"); Bool.set(world, tableId, true); @@ -490,45 +517,47 @@ contract WorldTest is Test, GasReporter { bytes16 namespace = "testSetField"; bytes16 name = "testTable"; bytes32 tableId = ResourceSelector.from(namespace, name); + FieldLayout fieldLayout = Bool.getFieldLayout(); Schema valueSchema = Bool.getValueSchema(); // Register a new table - world.registerTable(tableId, defaultKeySchema, valueSchema, new string[](1), new string[](1)); + world.registerTable(tableId, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](1)); startGasReport("Write data to a table field"); - world.setField(tableId, singletonKey, 0, abi.encodePacked(true), valueSchema); + world.setField(tableId, singletonKey, 0, abi.encodePacked(true), fieldLayout); endGasReport(); // Expect the data to be written assertTrue(Bool.get(world, tableId)); // Write data to the table via its tableId - world.setField(tableId, singletonKey, 0, abi.encodePacked(false), valueSchema); + world.setField(tableId, singletonKey, 0, abi.encodePacked(false), fieldLayout); // Expect the data to be written assertFalse(Bool.get(world, tableId)); // Expect an error when trying to write from an address that doesn't have access when calling via the namespace _expectAccessDenied(address(0x01), "testSetField", "testTable"); - world.setField(tableId, singletonKey, 0, abi.encodePacked(true), valueSchema); + world.setField(tableId, singletonKey, 0, abi.encodePacked(true), fieldLayout); // Expect an error when trying to write from an address that doesn't have access when calling via the tableId _expectAccessDenied(address(0x01), "testSetField", "testTable"); - world.setField(tableId, singletonKey, 0, abi.encodePacked(true), valueSchema); + world.setField(tableId, singletonKey, 0, abi.encodePacked(true), fieldLayout); // Expect the World to have access vm.prank(address(world)); - world.setField(tableId, singletonKey, 0, abi.encodePacked(true), valueSchema); + world.setField(tableId, singletonKey, 0, abi.encodePacked(true), fieldLayout); } function testPushToField() public { bytes16 namespace = "testPushToField"; bytes16 name = "testTable"; bytes32 tableId = ResourceSelector.from(namespace, name); + FieldLayout fieldLayout = AddressArray.getFieldLayout(); Schema valueSchema = AddressArray.getValueSchema(); // Register a new table - world.registerTable(tableId, defaultKeySchema, valueSchema, new string[](1), new string[](1)); + world.registerTable(tableId, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](1)); // Create data address[] memory dataToPush = new address[](3); @@ -538,69 +567,70 @@ contract WorldTest is Test, GasReporter { bytes memory encodedData = EncodeArray.encode(dataToPush); startGasReport("Push data to the table"); - world.pushToField(tableId, keyTuple, 0, encodedData, valueSchema); + world.pushToField(tableId, keyTuple, 0, encodedData, fieldLayout); endGasReport(); // Expect the data to be written assertEq(AddressArray.get(world, tableId, key), dataToPush); // Delete the data - world.deleteRecord(tableId, keyTuple, valueSchema); + world.deleteRecord(tableId, keyTuple, fieldLayout); // Push data to the table via direct access - world.pushToField(tableId, keyTuple, 0, encodedData, valueSchema); + world.pushToField(tableId, keyTuple, 0, encodedData, fieldLayout); // Expect the data to be written assertEq(AddressArray.get(world, tableId, key), dataToPush); // Expect an error when trying to write from an address that doesn't have access _expectAccessDenied(address(0x01), namespace, name); - world.pushToField(tableId, keyTuple, 0, encodedData, valueSchema); + world.pushToField(tableId, keyTuple, 0, encodedData, fieldLayout); // Expect the World to have access vm.prank(address(world)); - world.pushToField(tableId, keyTuple, 0, encodedData, valueSchema); + world.pushToField(tableId, keyTuple, 0, encodedData, fieldLayout); } function testDeleteRecord() public { bytes16 namespace = "testDeleteRecord"; bytes16 name = "testTable"; bytes32 tableId = ResourceSelector.from(namespace, name); + FieldLayout fieldLayout = Bool.getFieldLayout(); Schema valueSchema = Bool.getValueSchema(); // Register a new table - world.registerTable(tableId, defaultKeySchema, valueSchema, new string[](1), new string[](1)); + world.registerTable(tableId, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](1)); // Write data to the table via the namespace and expect it to be written - world.setRecord(tableId, singletonKey, abi.encodePacked(true), valueSchema); + world.setRecord(tableId, singletonKey, abi.encodePacked(true), fieldLayout); assertTrue(Bool.get(world, tableId)); startGasReport("Delete record"); - world.deleteRecord(tableId, singletonKey, valueSchema); + world.deleteRecord(tableId, singletonKey, fieldLayout); endGasReport(); // expect it to be deleted assertFalse(Bool.get(world, tableId)); // Write data to the table via the namespace and expect it to be written - world.setRecord(tableId, singletonKey, abi.encodePacked(true), valueSchema); + world.setRecord(tableId, singletonKey, abi.encodePacked(true), fieldLayout); assertTrue(Bool.get(world, tableId)); // Delete the record via the tableId and expect it to be deleted - world.deleteRecord(tableId, singletonKey, valueSchema); + world.deleteRecord(tableId, singletonKey, fieldLayout); assertFalse(Bool.get(world, tableId)); // Write data to the table via the namespace and expect it to be written - world.setRecord(tableId, singletonKey, abi.encodePacked(true), valueSchema); + world.setRecord(tableId, singletonKey, abi.encodePacked(true), fieldLayout); assertTrue(Bool.get(world, tableId)); // Expect an error when trying to delete from an address that doesn't have access _expectAccessDenied(address(0x02), "testDeleteRecord", "testTable"); - world.deleteRecord(tableId, singletonKey, valueSchema); + world.deleteRecord(tableId, singletonKey, fieldLayout); // Expect the World to have access vm.prank(address(world)); - world.deleteRecord(tableId, singletonKey, valueSchema); + world.deleteRecord(tableId, singletonKey, fieldLayout); } function testCall() public { @@ -758,11 +788,12 @@ contract WorldTest is Test, GasReporter { } function testRegisterStoreHook() public { + FieldLayout fieldLayout = Bool.getFieldLayout(); Schema valueSchema = Bool.getValueSchema(); bytes32 tableId = ResourceSelector.from("", "testTable"); // Register a new table - world.registerTable(tableId, defaultKeySchema, valueSchema, new string[](1), new string[](1)); + world.registerTable(tableId, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](1)); // Register a new hook IStoreHook tableHook = new EchoSubscriber(); @@ -784,30 +815,30 @@ contract WorldTest is Test, GasReporter { // Expect the hook to be notified when a record is written (once before and once after the record is written) vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(tableId, singletonKey, value, valueSchema)); + emit HookCalled(abi.encode(tableId, singletonKey, value, fieldLayout)); vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(tableId, singletonKey, value, valueSchema)); + emit HookCalled(abi.encode(tableId, singletonKey, value, fieldLayout)); - world.setRecord(tableId, singletonKey, value, valueSchema); + world.setRecord(tableId, singletonKey, value, fieldLayout); // Expect the hook to be notified when a field is written (once before and once after the field is written) vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(tableId, singletonKey, uint8(0), value, valueSchema)); + emit HookCalled(abi.encode(tableId, singletonKey, uint8(0), value, fieldLayout)); vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(tableId, singletonKey, uint8(0), value, valueSchema)); + emit HookCalled(abi.encode(tableId, singletonKey, uint8(0), value, fieldLayout)); - world.setField(tableId, singletonKey, 0, value, valueSchema); + world.setField(tableId, singletonKey, 0, value, fieldLayout); // Expect the hook to be notified when a record is deleted (once before and once after the field is written) vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(tableId, singletonKey, valueSchema)); + emit HookCalled(abi.encode(tableId, singletonKey, fieldLayout)); vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(tableId, singletonKey, valueSchema)); + emit HookCalled(abi.encode(tableId, singletonKey, fieldLayout)); - world.deleteRecord(tableId, singletonKey, valueSchema); + world.deleteRecord(tableId, singletonKey, fieldLayout); // Expect an error when trying to register an address that doesn't implement the IStoreHook interface vm.expectRevert( @@ -828,11 +859,12 @@ contract WorldTest is Test, GasReporter { } function testUnregisterStoreHook() public { + FieldLayout fieldLayout = Bool.getFieldLayout(); Schema valueSchema = Bool.getValueSchema(); bytes32 tableId = ResourceSelector.from("", "testTable"); // Register a new table - world.registerTable(tableId, defaultKeySchema, valueSchema, new string[](1), new string[](1)); + world.registerTable(tableId, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](1)); // Register a new RevertSubscriber IStoreHook revertSubscriber = new RevertSubscriber(); @@ -868,45 +900,45 @@ contract WorldTest is Test, GasReporter { // Expect a revert when the RevertSubscriber's onBeforeSetRecord hook is called vm.expectRevert(bytes("onBeforeSetRecord")); - world.setRecord(tableId, singletonKey, value, valueSchema); + world.setRecord(tableId, singletonKey, value, fieldLayout); // Expect a revert when the RevertSubscriber's onBeforeSetField hook is called vm.expectRevert(bytes("onBeforeSetField")); - world.setField(tableId, singletonKey, 0, value, valueSchema); + world.setField(tableId, singletonKey, 0, value, fieldLayout); // Expect a revert when the RevertSubscriber's onBeforeDeleteRecord hook is called vm.expectRevert(bytes("onBeforeDeleteRecord")); - world.deleteRecord(tableId, singletonKey, valueSchema); + world.deleteRecord(tableId, singletonKey, fieldLayout); // Unregister the RevertSubscriber world.unregisterStoreHook(tableId, revertSubscriber); // Expect the hook to be notified when a record is written (once before and once after the record is written) vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(tableId, singletonKey, value, valueSchema)); + emit HookCalled(abi.encode(tableId, singletonKey, value, fieldLayout)); vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(tableId, singletonKey, value, valueSchema)); + emit HookCalled(abi.encode(tableId, singletonKey, value, fieldLayout)); - world.setRecord(tableId, singletonKey, value, valueSchema); + world.setRecord(tableId, singletonKey, value, fieldLayout); // Expect the hook to be notified when a field is written (once before and once after the field is written) vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(tableId, singletonKey, uint8(0), value, valueSchema)); + emit HookCalled(abi.encode(tableId, singletonKey, uint8(0), value, fieldLayout)); vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(tableId, singletonKey, uint8(0), value, valueSchema)); + emit HookCalled(abi.encode(tableId, singletonKey, uint8(0), value, fieldLayout)); - world.setField(tableId, singletonKey, 0, value, valueSchema); + world.setField(tableId, singletonKey, 0, value, fieldLayout); // Expect the hook to be notified when a record is deleted (once before and once after the field is written) vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(tableId, singletonKey, valueSchema)); + emit HookCalled(abi.encode(tableId, singletonKey, fieldLayout)); vm.expectEmit(true, true, true, true); - emit HookCalled(abi.encode(tableId, singletonKey, valueSchema)); + emit HookCalled(abi.encode(tableId, singletonKey, fieldLayout)); - world.deleteRecord(tableId, singletonKey, valueSchema); + world.deleteRecord(tableId, singletonKey, fieldLayout); } function testRegisterSystemHook() public { @@ -999,7 +1031,14 @@ contract WorldTest is Test, GasReporter { function testWriteRootSystem() public { bytes32 tableId = ResourceSelector.from("namespace", "testTable"); // Register a new table - world.registerTable(tableId, defaultKeySchema, Bool.getValueSchema(), new string[](1), new string[](1)); + world.registerTable( + tableId, + Bool.getFieldLayout(), + defaultKeySchema, + Bool.getValueSchema(), + new string[](1), + new string[](1) + ); // Register a new system bytes32 rootSystemId = ResourceSelector.from("", "testSystem"); @@ -1019,7 +1058,14 @@ contract WorldTest is Test, GasReporter { function testWriteAutonomousSystem() public { bytes32 tableId = ResourceSelector.from("namespace", "testTable"); // Register a new table - world.registerTable(tableId, defaultKeySchema, Bool.getValueSchema(), new string[](1), new string[](1)); + world.registerTable( + tableId, + Bool.getFieldLayout(), + defaultKeySchema, + Bool.getValueSchema(), + new string[](1), + new string[](1) + ); // Register a new system bytes32 systemId = ResourceSelector.from("namespace", "testSystem"); diff --git a/packages/world/test/WorldDynamicUpdate.t.sol b/packages/world/test/WorldDynamicUpdate.t.sol index 62f9a71016..4d385eb850 100644 --- a/packages/world/test/WorldDynamicUpdate.t.sol +++ b/packages/world/test/WorldDynamicUpdate.t.sol @@ -9,6 +9,8 @@ import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol" import { IStoreHook } from "@latticexyz/store/src/IStore.sol"; import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { FieldLayoutEncodeHelper } from "@latticexyz/store/test/FieldLayoutEncodeHelper.sol"; import { Schema } from "@latticexyz/store/src/Schema.sol"; import { SchemaEncodeHelper } from "@latticexyz/store/test/SchemaEncodeHelper.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; @@ -52,6 +54,7 @@ contract UpdateInFieldTest is Test, GasReporter { keyTuple = new bytes32[](1); keyTuple[0] = key; singletonKey = new bytes32[](0); + FieldLayout fieldLayout = AddressArray.getFieldLayout(); Schema valueSchema = AddressArray.getValueSchema(); // Initialize the data in setUp so that slots aren't warm in tests (to test cold update) @@ -61,7 +64,7 @@ contract UpdateInFieldTest is Test, GasReporter { tableId = ResourceSelector.from(namespace, name); // Register a new table - world.registerTable(tableId, defaultKeySchema, valueSchema, new string[](1), new string[](1)); + world.registerTable(tableId, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](1)); // Create data initData = new address[](3); @@ -70,7 +73,7 @@ contract UpdateInFieldTest is Test, GasReporter { initData[2] = address(bytes20(keccak256("another address"))); encodedData = EncodeArray.encode(initData); - world.setField(tableId, keyTuple, 0, encodedData, valueSchema); + world.setField(tableId, keyTuple, 0, encodedData, fieldLayout); } // Expect an error when trying to write from an address that doesn't have access @@ -80,7 +83,7 @@ contract UpdateInFieldTest is Test, GasReporter { } function testPopFromField() public { - Schema valueSchema = AddressArray.getValueSchema(); + FieldLayout fieldLayout = AddressArray.getFieldLayout(); // Expect the data to be written assertEq(AddressArray.get(world, tableId, key), initData); @@ -89,7 +92,7 @@ contract UpdateInFieldTest is Test, GasReporter { uint256 byteLengthToPop = 20; startGasReport("pop 1 address (cold)"); - world.popFromField(tableId, keyTuple, 0, byteLengthToPop, valueSchema); + world.popFromField(tableId, keyTuple, 0, byteLengthToPop, fieldLayout); endGasReport(); // Expect the data to be updated @@ -103,7 +106,7 @@ contract UpdateInFieldTest is Test, GasReporter { byteLengthToPop = 20; startGasReport("pop 1 address (warm)"); - world.popFromField(tableId, keyTuple, 0, byteLengthToPop, valueSchema); + world.popFromField(tableId, keyTuple, 0, byteLengthToPop, fieldLayout); endGasReport(); // Expect the data to be updated @@ -114,10 +117,10 @@ contract UpdateInFieldTest is Test, GasReporter { } // Reset data - world.setField(tableId, keyTuple, 0, encodedData, valueSchema); + world.setField(tableId, keyTuple, 0, encodedData, fieldLayout); // Pop 2 items via direct access byteLengthToPop = 20 * 2; - world.popFromField(tableId, keyTuple, 0, byteLengthToPop, valueSchema); + world.popFromField(tableId, keyTuple, 0, byteLengthToPop, fieldLayout); // Expect the data to be updated loadedData = AddressArray.get(world, tableId, key); assertEq(loadedData.length, initData.length - 2); @@ -127,19 +130,19 @@ contract UpdateInFieldTest is Test, GasReporter { // Expect an error when trying to write from an address that doesn't have access (via namespace/name) _expectAccessDenied(address(0x01), tableId); - world.popFromField(tableId, keyTuple, 0, 20, valueSchema); + world.popFromField(tableId, keyTuple, 0, 20, fieldLayout); // Expect an error when trying to write from an address that doesn't have access (via tableId) _expectAccessDenied(address(0x01), tableId); - world.popFromField(tableId, keyTuple, 0, 20, valueSchema); + world.popFromField(tableId, keyTuple, 0, 20, fieldLayout); // Expect the World to have access vm.prank(address(world)); - world.popFromField(tableId, keyTuple, 0, 20, valueSchema); + world.popFromField(tableId, keyTuple, 0, 20, fieldLayout); } function testUpdateInField() public { - Schema valueSchema = AddressArray.getValueSchema(); + FieldLayout fieldLayout = AddressArray.getFieldLayout(); // Expect the data to be written assertEq(AddressArray.get(world, tableId, key), initData); @@ -149,11 +152,11 @@ contract UpdateInFieldTest is Test, GasReporter { dataForUpdate[0] = address(bytes20(keccak256("address for update"))); startGasReport("updateInField 1 item (cold)"); - world.updateInField(tableId, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), valueSchema); + world.updateInField(tableId, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), fieldLayout); endGasReport(); startGasReport("updateInField 1 item (warm)"); - world.updateInField(tableId, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), valueSchema); + world.updateInField(tableId, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), fieldLayout); endGasReport(); // Expect the data to be updated @@ -161,7 +164,7 @@ contract UpdateInFieldTest is Test, GasReporter { assertEq(AddressArray.get(world, tableId, key), initData); // Update index 1 via direct access - world.updateInField(tableId, keyTuple, 0, 20 * 1, EncodeArray.encode(dataForUpdate), valueSchema); + world.updateInField(tableId, keyTuple, 0, 20 * 1, EncodeArray.encode(dataForUpdate), fieldLayout); // Expect the data to be updated initData[1] = dataForUpdate[0]; @@ -169,14 +172,14 @@ contract UpdateInFieldTest is Test, GasReporter { // Expect an error when trying to write from an address that doesn't have access (via namespace/name) _expectAccessDenied(address(0x01), tableId); - world.updateInField(tableId, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), valueSchema); + world.updateInField(tableId, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), fieldLayout); // Expect an error when trying to write from an address that doesn't have access (via tableId) _expectAccessDenied(address(0x01), tableId); - world.updateInField(tableId, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), valueSchema); + world.updateInField(tableId, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), fieldLayout); // Expect the World to have access vm.prank(address(world)); - world.updateInField(tableId, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), valueSchema); + world.updateInField(tableId, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), fieldLayout); } } diff --git a/packages/world/test/query.t.sol b/packages/world/test/query.t.sol index 7f061dcd1f..3a013610b9 100644 --- a/packages/world/test/query.t.sol +++ b/packages/world/test/query.t.sol @@ -4,6 +4,8 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { FieldLayoutEncodeHelper } from "@latticexyz/store/test/FieldLayoutEncodeHelper.sol"; import { Schema } from "@latticexyz/store/src/Schema.sol"; import { SchemaEncodeHelper } from "@latticexyz/store/test/SchemaEncodeHelper.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; @@ -29,8 +31,9 @@ contract QueryTest is Test, GasReporter { bytes16 name2 = bytes16("source2"); bytes16 name3 = bytes16("source3"); - Schema tableValueSchema; + FieldLayout tableFieldLayout; Schema tableKeySchema; + Schema tableValueSchema; bytes32 table1 = ResourceSelector.from(namespace, name1); bytes32 table2 = ResourceSelector.from(namespace, name2); bytes32 table3 = ResourceSelector.from(namespace, name3); @@ -44,8 +47,9 @@ contract QueryTest is Test, GasReporter { QueryFragment[] fragmentsHasNot; function setUp() public { - tableValueSchema = SchemaEncodeHelper.encode(SchemaType.UINT256); + tableFieldLayout = FieldLayoutEncodeHelper.encode(32, 0); tableKeySchema = SchemaEncodeHelper.encode(SchemaType.BYTES32); + tableValueSchema = SchemaEncodeHelper.encode(SchemaType.UINT256); world = IBaseWorld(address(new World())); world.installRootModule(new CoreModule(), new bytes(0)); @@ -62,9 +66,9 @@ contract QueryTest is Test, GasReporter { function _installKeysInTableModule() internal { // Register source table - world.registerTable(table1, tableKeySchema, tableValueSchema, new string[](1), new string[](1)); - world.registerTable(table2, tableKeySchema, tableValueSchema, new string[](1), new string[](1)); - world.registerTable(table3, tableKeySchema, tableValueSchema, new string[](1), new string[](1)); + world.registerTable(table1, tableFieldLayout, tableKeySchema, tableValueSchema, new string[](1), new string[](1)); + world.registerTable(table2, tableFieldLayout, tableKeySchema, tableValueSchema, new string[](1), new string[](1)); + world.registerTable(table3, tableFieldLayout, tableKeySchema, tableValueSchema, new string[](1), new string[](1)); // Install the index module // TODO: add support for installing this via installModule @@ -86,9 +90,9 @@ contract QueryTest is Test, GasReporter { function testHasQuery() public { _installKeysInTableModule(); - world.setRecord(table1, key1, abi.encode(1), tableValueSchema); - world.setRecord(table1, key2, abi.encode(1), tableValueSchema); - world.setRecord(table2, key1, abi.encode(0), tableValueSchema); + world.setRecord(table1, key1, abi.encode(1), tableFieldLayout); + world.setRecord(table1, key2, abi.encode(1), tableFieldLayout); + world.setRecord(table2, key1, abi.encode(0), tableFieldLayout); // Query should return all keys in table1 QueryFragment[] memory fragments = new QueryFragment[](1); @@ -107,9 +111,9 @@ contract QueryTest is Test, GasReporter { _installKeysInTableModule(); _installKeysWithValueModule(); - world.setRecord(table1, key1, abi.encode(2), tableValueSchema); - world.setRecord(table1, key2, abi.encode(1), tableValueSchema); - world.setRecord(table1, key3, abi.encode(1), tableValueSchema); + world.setRecord(table1, key1, abi.encode(2), tableFieldLayout); + world.setRecord(table1, key2, abi.encode(1), tableFieldLayout); + world.setRecord(table1, key3, abi.encode(1), tableFieldLayout); // Query should return all keys in table1 with value 1 QueryFragment[] memory fragments = new QueryFragment[](1); fragments[0] = QueryFragment(QueryType.HasValue, table1, abi.encode(1)); @@ -125,12 +129,12 @@ contract QueryTest is Test, GasReporter { function testCombinedHasQuery() public { _installKeysInTableModule(); - world.setRecord(table1, key1, abi.encode(2), tableValueSchema); - world.setRecord(table1, key2, abi.encode(1), tableValueSchema); - world.setRecord(table1, key3, abi.encode(1), tableValueSchema); - world.setRecord(table2, key2, abi.encode(1), tableValueSchema); - world.setRecord(table2, key3, abi.encode(1), tableValueSchema); - world.setRecord(table3, key1, abi.encode(1), tableValueSchema); + world.setRecord(table1, key1, abi.encode(2), tableFieldLayout); + world.setRecord(table1, key2, abi.encode(1), tableFieldLayout); + world.setRecord(table1, key3, abi.encode(1), tableFieldLayout); + world.setRecord(table2, key2, abi.encode(1), tableFieldLayout); + world.setRecord(table2, key3, abi.encode(1), tableFieldLayout); + world.setRecord(table3, key1, abi.encode(1), tableFieldLayout); // Query should return all entities that have table1 and table2 QueryFragment[] memory fragments = new QueryFragment[](2); @@ -149,12 +153,12 @@ contract QueryTest is Test, GasReporter { _installKeysInTableModule(); _installKeysWithValueModule(); - world.setRecord(table1, key1, abi.encode(2), tableValueSchema); - world.setRecord(table1, key2, abi.encode(2), tableValueSchema); - world.setRecord(table1, key3, abi.encode(1), tableValueSchema); - world.setRecord(table2, key2, abi.encode(1), tableValueSchema); - world.setRecord(table2, key3, abi.encode(1), tableValueSchema); - world.setRecord(table3, key1, abi.encode(1), tableValueSchema); + world.setRecord(table1, key1, abi.encode(2), tableFieldLayout); + world.setRecord(table1, key2, abi.encode(2), tableFieldLayout); + world.setRecord(table1, key3, abi.encode(1), tableFieldLayout); + world.setRecord(table2, key2, abi.encode(1), tableFieldLayout); + world.setRecord(table2, key3, abi.encode(1), tableFieldLayout); + world.setRecord(table3, key1, abi.encode(1), tableFieldLayout); // Query should return all entities that have table1 and table2 QueryFragment[] memory fragments = new QueryFragment[](2); @@ -172,13 +176,13 @@ contract QueryTest is Test, GasReporter { _installKeysInTableModule(); _installKeysWithValueModule(); - world.setRecord(table1, key1, abi.encode(1), tableValueSchema); - world.setRecord(table1, key2, abi.encode(1), tableValueSchema); - world.setRecord(table1, key3, abi.encode(1), tableValueSchema); - world.setRecord(table2, key1, abi.encode(1), tableValueSchema); - world.setRecord(table2, key2, abi.encode(2), tableValueSchema); - world.setRecord(table2, key3, abi.encode(2), tableValueSchema); - world.setRecord(table2, key4, abi.encode(2), tableValueSchema); + world.setRecord(table1, key1, abi.encode(1), tableFieldLayout); + world.setRecord(table1, key2, abi.encode(1), tableFieldLayout); + world.setRecord(table1, key3, abi.encode(1), tableFieldLayout); + world.setRecord(table2, key1, abi.encode(1), tableFieldLayout); + world.setRecord(table2, key2, abi.encode(2), tableFieldLayout); + world.setRecord(table2, key3, abi.encode(2), tableFieldLayout); + world.setRecord(table2, key4, abi.encode(2), tableFieldLayout); // Query should return all entities that have table1 and table2 QueryFragment[] memory fragments = new QueryFragment[](2); @@ -196,13 +200,13 @@ contract QueryTest is Test, GasReporter { function testCombinedHasNotQuery() public { _installKeysInTableModule(); - world.setRecord(table1, key1, abi.encode(1), tableValueSchema); - world.setRecord(table1, key2, abi.encode(1), tableValueSchema); - world.setRecord(table1, key3, abi.encode(1), tableValueSchema); - world.setRecord(table2, key1, abi.encode(1), tableValueSchema); - world.setRecord(table2, key2, abi.encode(2), tableValueSchema); - world.setRecord(table2, key3, abi.encode(2), tableValueSchema); - world.setRecord(table2, key4, abi.encode(2), tableValueSchema); + world.setRecord(table1, key1, abi.encode(1), tableFieldLayout); + world.setRecord(table1, key2, abi.encode(1), tableFieldLayout); + world.setRecord(table1, key3, abi.encode(1), tableFieldLayout); + world.setRecord(table2, key1, abi.encode(1), tableFieldLayout); + world.setRecord(table2, key2, abi.encode(2), tableFieldLayout); + world.setRecord(table2, key3, abi.encode(2), tableFieldLayout); + world.setRecord(table2, key4, abi.encode(2), tableFieldLayout); // Query should return all entities that have table1 and table2 QueryFragment[] memory fragments = new QueryFragment[](2); @@ -220,13 +224,13 @@ contract QueryTest is Test, GasReporter { _installKeysInTableModule(); _installKeysWithValueModule(); - world.setRecord(table1, key1, abi.encode(1), tableValueSchema); - world.setRecord(table1, key2, abi.encode(1), tableValueSchema); - world.setRecord(table1, key3, abi.encode(1), tableValueSchema); - world.setRecord(table2, key1, abi.encode(1), tableValueSchema); - world.setRecord(table2, key2, abi.encode(2), tableValueSchema); - world.setRecord(table2, key3, abi.encode(1), tableValueSchema); - world.setRecord(table2, key4, abi.encode(1), tableValueSchema); + world.setRecord(table1, key1, abi.encode(1), tableFieldLayout); + world.setRecord(table1, key2, abi.encode(1), tableFieldLayout); + world.setRecord(table1, key3, abi.encode(1), tableFieldLayout); + world.setRecord(table2, key1, abi.encode(1), tableFieldLayout); + world.setRecord(table2, key2, abi.encode(2), tableFieldLayout); + world.setRecord(table2, key3, abi.encode(1), tableFieldLayout); + world.setRecord(table2, key4, abi.encode(1), tableFieldLayout); // Query should return all entities that have table1 and table2 QueryFragment[] memory fragments = new QueryFragment[](2); @@ -244,16 +248,16 @@ contract QueryTest is Test, GasReporter { _installKeysInTableModule(); _installKeysWithValueModule(); - world.setRecord(table1, key1, abi.encode(1), tableValueSchema); - world.setRecord(table1, key2, abi.encode(1), tableValueSchema); - world.setRecord(table1, key3, abi.encode(1), tableValueSchema); - world.setRecord(table2, key1, abi.encode(1), tableValueSchema); - world.setRecord(table2, key2, abi.encode(2), tableValueSchema); - world.setRecord(table2, key3, abi.encode(1), tableValueSchema); - world.setRecord(table2, key4, abi.encode(1), tableValueSchema); - world.setRecord(table3, key2, abi.encode(1), tableValueSchema); - world.setRecord(table3, key3, abi.encode(1), tableValueSchema); - world.setRecord(table3, key4, abi.encode(1), tableValueSchema); + world.setRecord(table1, key1, abi.encode(1), tableFieldLayout); + world.setRecord(table1, key2, abi.encode(1), tableFieldLayout); + world.setRecord(table1, key3, abi.encode(1), tableFieldLayout); + world.setRecord(table2, key1, abi.encode(1), tableFieldLayout); + world.setRecord(table2, key2, abi.encode(2), tableFieldLayout); + world.setRecord(table2, key3, abi.encode(1), tableFieldLayout); + world.setRecord(table2, key4, abi.encode(1), tableFieldLayout); + world.setRecord(table3, key2, abi.encode(1), tableFieldLayout); + world.setRecord(table3, key3, abi.encode(1), tableFieldLayout); + world.setRecord(table3, key4, abi.encode(1), tableFieldLayout); // Query should return all entities that have table2 and not table1 QueryFragment[] memory fragments = new QueryFragment[](3); @@ -272,9 +276,9 @@ contract QueryTest is Test, GasReporter { _installKeysInTableModule(); _installKeysWithValueModule(); - world.setRecord(table1, key1, abi.encode(4), tableValueSchema); - world.setRecord(table1, key2, abi.encode(5), tableValueSchema); - world.setRecord(table1, key3, abi.encode(6), tableValueSchema); + world.setRecord(table1, key1, abi.encode(4), tableFieldLayout); + world.setRecord(table1, key2, abi.encode(5), tableFieldLayout); + world.setRecord(table1, key3, abi.encode(6), tableFieldLayout); // Query should return all entities with table1 except value 6 QueryFragment[] memory fragments = new QueryFragment[](2); @@ -295,9 +299,9 @@ contract QueryTest is Test, GasReporter { for (uint256 i; i < 100; i++) { bytes32[] memory key = new bytes32[](1); key[0] = bytes32(i); - world.setRecord(table1, key, abi.encode(1), tableValueSchema); + world.setRecord(table1, key, abi.encode(1), tableFieldLayout); } - world.setRecord(table2, key1, abi.encode(0), tableValueSchema); + world.setRecord(table2, key1, abi.encode(0), tableFieldLayout); // Query should return all keys in table1 QueryFragment[] memory fragments = new QueryFragment[](1); @@ -316,9 +320,9 @@ contract QueryTest is Test, GasReporter { for (uint256 i; i < 1000; i++) { bytes32[] memory key = new bytes32[](1); key[0] = bytes32(i); - world.setRecord(table1, key, abi.encode(1), tableValueSchema); + world.setRecord(table1, key, abi.encode(1), tableFieldLayout); } - world.setRecord(table2, key1, abi.encode(0), tableValueSchema); + world.setRecord(table2, key1, abi.encode(0), tableFieldLayout); // Query should return all keys in table1 QueryFragment[] memory fragments = new QueryFragment[](1); diff --git a/packages/world/test/tables/AddressArray.sol b/packages/world/test/tables/AddressArray.sol index e17350eaac..1daf1d0d6c 100644 --- a/packages/world/test/tables/AddressArray.sol +++ b/packages/world/test/tables/AddressArray.sol @@ -14,10 +14,18 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; library AddressArray { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](0); + + return FieldLayoutLib.encode(_fieldLayout, 1); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -46,14 +54,21 @@ library AddressArray { fieldNames[0] = "value"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register(bytes32 _tableId) internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store, bytes32 _tableId) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get value */ @@ -61,7 +76,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); } @@ -70,7 +85,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); } @@ -79,7 +94,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getFieldLayout()); } /** Set value (using the specified store) */ @@ -87,7 +102,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), getFieldLayout()); } /** Get the length of value */ @@ -95,7 +110,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 20; } @@ -106,7 +121,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getValueSchema()); + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getFieldLayout()); unchecked { return _byteLength / 20; } @@ -125,7 +140,7 @@ library AddressArray { _tableId, _keyTuple, 0, - getValueSchema(), + getFieldLayout(), _index * 20, (_index + 1) * 20 ); @@ -146,7 +161,7 @@ library AddressArray { _tableId, _keyTuple, 0, - getValueSchema(), + getFieldLayout(), _index * 20, (_index + 1) * 20 ); @@ -159,7 +174,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Push an element to value (using the specified store) */ @@ -167,7 +182,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getValueSchema()); + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), getFieldLayout()); } /** Pop an element from value */ @@ -175,7 +190,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.popFromField(_tableId, _keyTuple, 0, 20, getValueSchema()); + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 20, getFieldLayout()); } /** Pop an element from value (using the specified store) */ @@ -183,7 +198,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.popFromField(_tableId, _keyTuple, 0, 20, getValueSchema()); + _store.popFromField(_tableId, _keyTuple, 0, 20, getFieldLayout()); } /** @@ -195,7 +210,7 @@ library AddressArray { _keyTuple[0] = key; unchecked { - StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 20, abi.encodePacked((_element)), getValueSchema()); + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 20, abi.encodePacked((_element)), getFieldLayout()); } } @@ -208,11 +223,11 @@ library AddressArray { _keyTuple[0] = key; unchecked { - _store.updateInField(_tableId, _keyTuple, 0, _index * 20, abi.encodePacked((_element)), getValueSchema()); + _store.updateInField(_tableId, _keyTuple, 0, _index * 20, abi.encodePacked((_element)), getFieldLayout()); } } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(address[] memory value) internal pure returns (bytes memory) { PackedCounter _encodedLengths; // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits @@ -223,7 +238,7 @@ library AddressArray { return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode((value))); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes32 key) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; @@ -236,7 +251,7 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -244,6 +259,6 @@ library AddressArray { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/packages/world/test/tables/Bool.sol b/packages/world/test/tables/Bool.sol index 828eb8bb45..73f02fd1af 100644 --- a/packages/world/test/tables/Bool.sol +++ b/packages/world/test/tables/Bool.sol @@ -14,10 +14,19 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; library Bool { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 1; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](0); @@ -44,21 +53,28 @@ library Bool { fieldNames[0] = "value"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register(bytes32 _tableId) internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store, bytes32 _tableId) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get value */ function get(bytes32 _tableId) internal view returns (bool value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -66,7 +82,7 @@ library Bool { 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, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (_toBool(uint8(Bytes.slice1(_blob, 0)))); } @@ -74,22 +90,22 @@ library Bool { function set(bytes32 _tableId, bool value) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getFieldLayout()); } /** Set value (using the specified store) */ function set(IStore _store, bytes32 _tableId, bool value) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(bool value) internal pure returns (bytes memory) { return abi.encodePacked(value); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple() internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](0); @@ -100,14 +116,14 @@ library Bool { function deleteRecord(bytes32 _tableId) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ function deleteRecord(IStore _store, bytes32 _tableId) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol b/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol index 23789be1ec..afb08c8ee5 100644 --- a/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,14 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Count bytes32 constant CounterTableId = _tableId; library Counter { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 4; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](0); @@ -47,21 +56,28 @@ library Counter { fieldNames[0] = "value"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get value */ function get() internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint32(Bytes.slice4(_blob, 0))); } @@ -69,7 +85,7 @@ library Counter { function get(IStore _store) internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint32(Bytes.slice4(_blob, 0))); } @@ -77,22 +93,22 @@ library Counter { function set(uint32 value) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getFieldLayout()); } /** Set value (using the specified store) */ function set(IStore _store, uint32 value) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(uint32 value) internal pure returns (bytes memory) { return abi.encodePacked(value); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple() internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](0); @@ -103,13 +119,13 @@ library Counter { function deleteRecord() internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ function deleteRecord(IStore _store) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/templates/react/packages/contracts/src/codegen/tables/Counter.sol b/templates/react/packages/contracts/src/codegen/tables/Counter.sol index 23789be1ec..afb08c8ee5 100644 --- a/templates/react/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/react/packages/contracts/src/codegen/tables/Counter.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,14 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Count bytes32 constant CounterTableId = _tableId; library Counter { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 4; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](0); @@ -47,21 +56,28 @@ library Counter { fieldNames[0] = "value"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get value */ function get() internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint32(Bytes.slice4(_blob, 0))); } @@ -69,7 +85,7 @@ library Counter { function get(IStore _store) internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint32(Bytes.slice4(_blob, 0))); } @@ -77,22 +93,22 @@ library Counter { function set(uint32 value) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getFieldLayout()); } /** Set value (using the specified store) */ function set(IStore _store, uint32 value) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(uint32 value) internal pure returns (bytes memory) { return abi.encodePacked(value); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple() internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](0); @@ -103,13 +119,13 @@ library Counter { function deleteRecord() internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ function deleteRecord(IStore _store) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/templates/threejs/packages/contracts/src/codegen/tables/Position.sol b/templates/threejs/packages/contracts/src/codegen/tables/Position.sol index b2cc2fb59c..ab4731aba7 100644 --- a/templates/threejs/packages/contracts/src/codegen/tables/Position.sol +++ b/templates/threejs/packages/contracts/src/codegen/tables/Position.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -27,6 +28,16 @@ struct PositionData { } library Position { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](3); + _fieldLayout[0] = 4; + _fieldLayout[1] = 4; + _fieldLayout[2] = 4; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](1); @@ -59,14 +70,21 @@ library Position { fieldNames[2] = "z"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get x */ @@ -74,7 +92,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (int32(uint32(Bytes.slice4(_blob, 0)))); } @@ -83,7 +101,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (int32(uint32(Bytes.slice4(_blob, 0)))); } @@ -92,7 +110,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((x)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((x)), getFieldLayout()); } /** Set x (using the specified store) */ @@ -100,7 +118,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((x)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((x)), getFieldLayout()); } /** Get y */ @@ -108,7 +126,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (int32(uint32(Bytes.slice4(_blob, 0)))); } @@ -117,7 +135,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1, getFieldLayout()); return (int32(uint32(Bytes.slice4(_blob, 0)))); } @@ -126,7 +144,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((y)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((y)), getFieldLayout()); } /** Set y (using the specified store) */ @@ -134,7 +152,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((y)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((y)), getFieldLayout()); } /** Get z */ @@ -142,7 +160,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2, getFieldLayout()); return (int32(uint32(Bytes.slice4(_blob, 0)))); } @@ -151,7 +169,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 2, getFieldLayout()); return (int32(uint32(Bytes.slice4(_blob, 0)))); } @@ -160,7 +178,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setField(_tableId, _keyTuple, 2, abi.encodePacked((z)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 2, abi.encodePacked((z)), getFieldLayout()); } /** Set z (using the specified store) */ @@ -168,7 +186,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setField(_tableId, _keyTuple, 2, abi.encodePacked((z)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 2, abi.encodePacked((z)), getFieldLayout()); } /** Get the full data */ @@ -176,7 +194,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -185,7 +203,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getValueSchema()); + bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getFieldLayout()); return decode(_blob); } @@ -196,7 +214,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + StoreSwitch.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using individual values (using the specified store) */ @@ -206,7 +224,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.setRecord(_tableId, _keyTuple, _data, getValueSchema()); + _store.setRecord(_tableId, _keyTuple, _data, getFieldLayout()); } /** Set the full data using the data struct */ @@ -219,7 +237,7 @@ library Position { set(_store, key, _table.x, _table.y, _table.z); } - /** Decode the tightly packed blob using this table's schema */ + /** Decode the tightly packed blob using this table's field layout */ function decode(bytes memory _blob) internal pure returns (PositionData memory _table) { _table.x = (int32(uint32(Bytes.slice4(_blob, 0)))); @@ -228,12 +246,12 @@ library Position { _table.z = (int32(uint32(Bytes.slice4(_blob, 8)))); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(int32 x, int32 y, int32 z) internal pure returns (bytes memory) { return abi.encodePacked(x, y, z); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple(bytes32 key) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; @@ -246,7 +264,7 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ @@ -254,6 +272,6 @@ library Position { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = key; - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } } diff --git a/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol b/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol index 23789be1ec..afb08c8ee5 100644 --- a/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol @@ -14,6 +14,7 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; @@ -21,6 +22,14 @@ bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Count bytes32 constant CounterTableId = _tableId; library Counter { + /** Get the table values' field layout */ + function getFieldLayout() internal pure returns (FieldLayout) { + uint256[] memory _fieldLayout = new uint256[](1); + _fieldLayout[0] = 4; + + return FieldLayoutLib.encode(_fieldLayout, 0); + } + /** Get the table's key schema */ function getKeySchema() internal pure returns (Schema) { SchemaType[] memory _schema = new SchemaType[](0); @@ -47,21 +56,28 @@ library Counter { fieldNames[0] = "value"; } - /** Register the table's key schema, value schema, key names and value names */ + /** Register the table with its config */ function register() internal { - StoreSwitch.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + StoreSwitch.registerTable( + _tableId, + getFieldLayout(), + getKeySchema(), + getValueSchema(), + getKeyNames(), + getFieldNames() + ); } - /** Register the table's key schema, value schema, key names and value names (using the specified store) */ + /** Register the table with its config (using the specified store) */ function register(IStore _store) internal { - _store.registerTable(_tableId, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); + _store.registerTable(_tableId, getFieldLayout(), getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } /** Get value */ function get() internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint32(Bytes.slice4(_blob, 0))); } @@ -69,7 +85,7 @@ library Counter { function get(IStore _store) internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); - bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getValueSchema()); + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0, getFieldLayout()); return (uint32(Bytes.slice4(_blob, 0))); } @@ -77,22 +93,22 @@ library Counter { function set(uint32 value) internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getValueSchema()); + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getFieldLayout()); } /** Set value (using the specified store) */ function set(IStore _store, uint32 value) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getValueSchema()); + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), getFieldLayout()); } - /** Tightly pack full data using this table's schema */ + /** Tightly pack full data using this table's field layout */ function encode(uint32 value) internal pure returns (bytes memory) { return abi.encodePacked(value); } - /** Encode keys as a bytes32 array using this table's schema */ + /** Encode keys as a bytes32 array using this table's field layout */ function encodeKeyTuple() internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](0); @@ -103,13 +119,13 @@ library Counter { function deleteRecord() internal { bytes32[] memory _keyTuple = new bytes32[](0); - StoreSwitch.deleteRecord(_tableId, _keyTuple, getValueSchema()); + StoreSwitch.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } /* Delete all data for given keys (using the specified store) */ function deleteRecord(IStore _store) internal { bytes32[] memory _keyTuple = new bytes32[](0); - _store.deleteRecord(_tableId, _keyTuple, getValueSchema()); + _store.deleteRecord(_tableId, _keyTuple, getFieldLayout()); } }