From a46fe53bfbd7991fa504472a272e40a5fa840f46 Mon Sep 17 00:00:00 2001 From: alvrs Date: Mon, 3 Jul 2023 21:11:00 +0100 Subject: [PATCH] add more test data for dynamic tables --- .../src/mud/contractComponents.ts | 155 ++++++++++ e2e/packages/contracts/mud.config.ts | 2 +- e2e/packages/contracts/src/codegen/Tables.sol | 10 + .../contracts/src/codegen/tables/Data.sol | 216 +++++++++++++ .../src/codegen/tables/GameConfig.sol | 243 +++++++++++++++ .../src/codegen/tables/LetterCount.sol | 128 ++++++++ .../src/codegen/tables/MerkleRootConfig.sol | 120 ++++++++ .../contracts/src/codegen/tables/Name.sol | 216 +++++++++++++ .../contracts/src/codegen/tables/Points.sol | 128 ++++++++ .../src/codegen/tables/TileLetter.sol | 136 +++++++++ .../src/codegen/tables/TilePlayer.sol | 136 +++++++++ .../contracts/src/codegen/tables/Treasury.sol | 120 ++++++++ .../src/codegen/tables/VRGDAConfig.sol | 283 ++++++++++++++++++ e2e/packages/contracts/worlds.json | 2 +- .../sync-test/data/readClientStore.ts | 7 + e2e/packages/sync-test/data/testData.ts | 2 +- .../sync-test/data/waitForInitialSync.ts | 2 + e2e/packages/sync-test/modeSync.test.ts | 2 +- e2e/packages/sync-test/rpcSync.test.ts | 2 +- 19 files changed, 1905 insertions(+), 5 deletions(-) create mode 100644 e2e/packages/contracts/src/codegen/tables/Data.sol create mode 100644 e2e/packages/contracts/src/codegen/tables/GameConfig.sol create mode 100644 e2e/packages/contracts/src/codegen/tables/LetterCount.sol create mode 100644 e2e/packages/contracts/src/codegen/tables/MerkleRootConfig.sol create mode 100644 e2e/packages/contracts/src/codegen/tables/Name.sol create mode 100644 e2e/packages/contracts/src/codegen/tables/Points.sol create mode 100644 e2e/packages/contracts/src/codegen/tables/TileLetter.sol create mode 100644 e2e/packages/contracts/src/codegen/tables/TilePlayer.sol create mode 100644 e2e/packages/contracts/src/codegen/tables/Treasury.sol create mode 100644 e2e/packages/contracts/src/codegen/tables/VRGDAConfig.sol diff --git a/e2e/packages/client-vanilla/src/mud/contractComponents.ts b/e2e/packages/client-vanilla/src/mud/contractComponents.ts index 388ac45595..2b1f59149b 100644 --- a/e2e/packages/client-vanilla/src/mud/contractComponents.ts +++ b/e2e/packages/client-vanilla/src/mud/contractComponents.ts @@ -67,5 +67,160 @@ export function defineContractComponents(world: World) { } ); })(), + Name: (() => { + const tableId = new TableId("", "Name"); + return defineComponent( + world, + { + name: RecsType.String, + }, + { + metadata: { + contractId: tableId.toHex(), + tableId: tableId.toString(), + }, + } + ); + })(), + Data: (() => { + const tableId = new TableId("", "Data"); + return defineComponent( + world, + { + value: RecsType.String, + }, + { + metadata: { + contractId: tableId.toHex(), + tableId: tableId.toString(), + }, + } + ); + })(), + GameConfig: (() => { + const tableId = new TableId("", "GameConfig"); + return defineComponent( + world, + { + status: RecsType.Number, + maxWords: RecsType.Number, + wordsPlayed: RecsType.Number, + }, + { + metadata: { + contractId: tableId.toHex(), + tableId: tableId.toString(), + }, + } + ); + })(), + MerkleRootConfig: (() => { + const tableId = new TableId("", "MerkleRootConfig"); + return defineComponent( + world, + { + value: RecsType.String, + }, + { + metadata: { + contractId: tableId.toHex(), + tableId: tableId.toString(), + }, + } + ); + })(), + VRGDAConfig: (() => { + const tableId = new TableId("", "VRGDAConfig"); + return defineComponent( + world, + { + startTime: RecsType.BigInt, + targetPrice: RecsType.BigInt, + priceDecay: RecsType.BigInt, + perDay: RecsType.BigInt, + }, + { + metadata: { + contractId: tableId.toHex(), + tableId: tableId.toString(), + }, + } + ); + })(), + TileLetter: (() => { + const tableId = new TableId("", "TileLetter"); + return defineComponent( + world, + { + value: RecsType.Number, + }, + { + metadata: { + contractId: tableId.toHex(), + tableId: tableId.toString(), + }, + } + ); + })(), + TilePlayer: (() => { + const tableId = new TableId("", "TilePlayer"); + return defineComponent( + world, + { + value: RecsType.String, + }, + { + metadata: { + contractId: tableId.toHex(), + tableId: tableId.toString(), + }, + } + ); + })(), + Treasury: (() => { + const tableId = new TableId("", "Treasury"); + return defineComponent( + world, + { + value: RecsType.BigInt, + }, + { + metadata: { + contractId: tableId.toHex(), + tableId: tableId.toString(), + }, + } + ); + })(), + Points: (() => { + const tableId = new TableId("", "Points"); + return defineComponent( + world, + { + value: RecsType.Number, + }, + { + metadata: { + contractId: tableId.toHex(), + tableId: tableId.toString(), + }, + } + ); + })(), + LetterCount: (() => { + const tableId = new TableId("", "LetterCount"); + return defineComponent( + world, + { + value: RecsType.Number, + }, + { + metadata: { + contractId: tableId.toHex(), + tableId: tableId.toString(), + }, + } + ); + })(), }; } diff --git a/e2e/packages/contracts/mud.config.ts b/e2e/packages/contracts/mud.config.ts index 96e4061d1d..ac62fe7885 100644 --- a/e2e/packages/contracts/mud.config.ts +++ b/e2e/packages/contracts/mud.config.ts @@ -41,7 +41,7 @@ export default mudConfig({ keySchema: { user: "address" }, schema: { name: "string" }, }, - Bytes: { + Data: { keySchema: { key: "bytes32" }, schema: { value: "bytes" }, }, diff --git a/e2e/packages/contracts/src/codegen/Tables.sol b/e2e/packages/contracts/src/codegen/Tables.sol index 98f8d2feb8..a310a47a11 100644 --- a/e2e/packages/contracts/src/codegen/Tables.sol +++ b/e2e/packages/contracts/src/codegen/Tables.sol @@ -7,3 +7,13 @@ import { Number, NumberTableId } from "./tables/Number.sol"; import { Vector, VectorData, VectorTableId } from "./tables/Vector.sol"; import { NumberList, NumberListTableId } from "./tables/NumberList.sol"; import { Multi, MultiData, MultiTableId } from "./tables/Multi.sol"; +import { Name, NameTableId } from "./tables/Name.sol"; +import { Data, DataTableId } from "./tables/Data.sol"; +import { GameConfig, GameConfigData, GameConfigTableId } from "./tables/GameConfig.sol"; +import { MerkleRootConfig, MerkleRootConfigTableId } from "./tables/MerkleRootConfig.sol"; +import { VRGDAConfig, VRGDAConfigData, VRGDAConfigTableId } from "./tables/VRGDAConfig.sol"; +import { TileLetter, TileLetterTableId } from "./tables/TileLetter.sol"; +import { TilePlayer, TilePlayerTableId } from "./tables/TilePlayer.sol"; +import { Treasury, TreasuryTableId } from "./tables/Treasury.sol"; +import { Points, PointsTableId } from "./tables/Points.sol"; +import { LetterCount, LetterCountTableId } from "./tables/LetterCount.sol"; diff --git a/e2e/packages/contracts/src/codegen/tables/Data.sol b/e2e/packages/contracts/src/codegen/tables/Data.sol new file mode 100644 index 0000000000..c10c7e1196 --- /dev/null +++ b/e2e/packages/contracts/src/codegen/tables/Data.sol @@ -0,0 +1,216 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +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 { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Data"))); +bytes32 constant DataTableId = _tableId; + +library Data { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.BYTES; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.BYTES32; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("Data", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(bytes32 key) internal view returns (bytes memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + return (bytes(_blob)); + } + + /** Get value (using the specified store) */ + function get(IStore _store, bytes32 key) internal view returns (bytes memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + return (bytes(_blob)); + } + + /** Set value */ + function set(bytes32 key, bytes memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.setField(_tableId, _keyTuple, 0, bytes((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, bytes32 key, bytes memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + _store.setField(_tableId, _keyTuple, 0, bytes((value))); + } + + /** Get the length of value */ + function length(bytes32 key) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getSchema()); + return _byteLength / 1; + } + + /** Get the length of value (using the specified store) */ + function length(IStore _store, bytes32 key) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getSchema()); + return _byteLength / 1; + } + + /** Get an item of value (unchecked, returns invalid data if index overflows) */ + function getItem(bytes32 key, uint256 _index) internal view returns (bytes memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreSwitch.getFieldSlice(_tableId, _keyTuple, 0, getSchema(), _index * 1, (_index + 1) * 1); + return (bytes(_blob)); + } + + /** Get an item of value (using the specified store) (unchecked, returns invalid data if index overflows) */ + function getItem(IStore _store, bytes32 key, uint256 _index) internal view returns (bytes memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, getSchema(), _index * 1, (_index + 1) * 1); + return (bytes(_blob)); + } + + /** Push a slice to value */ + function push(bytes32 key, bytes memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.pushToField(_tableId, _keyTuple, 0, bytes((_slice))); + } + + /** Push a slice to value (using the specified store) */ + function push(IStore _store, bytes32 key, bytes memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + _store.pushToField(_tableId, _keyTuple, 0, bytes((_slice))); + } + + /** Pop a slice from value */ + function pop(bytes32 key) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 1); + } + + /** Pop a slice from value (using the specified store) */ + function pop(IStore _store, bytes32 key) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + _store.popFromField(_tableId, _keyTuple, 0, 1); + } + + /** Update a slice of value at `_index` */ + function update(bytes32 key, uint256 _index, bytes memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 1, bytes((_slice))); + } + + /** Update a slice of value (using the specified store) at `_index` */ + function update(IStore _store, bytes32 key, uint256 _index, bytes memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + _store.updateInField(_tableId, _keyTuple, 0, _index * 1, bytes((_slice))); + } + + /** Tightly pack full data using this table's schema */ + function encode(bytes memory value) internal view returns (bytes memory) { + uint40[] memory _counters = new uint40[](1); + _counters[0] = uint40(bytes(value).length); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(_encodedLengths.unwrap(), bytes((value))); + } + + /** Encode keys as a bytes32 array using this table's schema */ + function encodeKeyTuple(bytes32 key) internal pure returns (bytes32[] memory _keyTuple) { + _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + } + + /* Delete all data for given keys */ + function deleteRecord(bytes32 key) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, bytes32 key) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + _store.deleteRecord(_tableId, _keyTuple); + } +} diff --git a/e2e/packages/contracts/src/codegen/tables/GameConfig.sol b/e2e/packages/contracts/src/codegen/tables/GameConfig.sol new file mode 100644 index 0000000000..4def3889ce --- /dev/null +++ b/e2e/packages/contracts/src/codegen/tables/GameConfig.sol @@ -0,0 +1,243 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +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 { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("GameConfig"))); +bytes32 constant GameConfigTableId = _tableId; + +struct GameConfigData { + uint8 status; + uint16 maxWords; + uint16 wordsPlayed; +} + +library GameConfig { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](3); + _schema[0] = SchemaType.UINT8; + _schema[1] = SchemaType.UINT16; + _schema[2] = SchemaType.UINT16; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](0); + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](3); + _fieldNames[0] = "status"; + _fieldNames[1] = "maxWords"; + _fieldNames[2] = "wordsPlayed"; + return ("GameConfig", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get status */ + function getStatus() internal view returns (uint8 status) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + return (uint8(Bytes.slice1(_blob, 0))); + } + + /** Get status (using the specified store) */ + function getStatus(IStore _store) internal view returns (uint8 status) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + return (uint8(Bytes.slice1(_blob, 0))); + } + + /** Set status */ + function setStatus(uint8 status) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((status))); + } + + /** Set status (using the specified store) */ + function setStatus(IStore _store, uint8 status) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((status))); + } + + /** Get maxWords */ + function getMaxWords() internal view returns (uint16 maxWords) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1); + return (uint16(Bytes.slice2(_blob, 0))); + } + + /** Get maxWords (using the specified store) */ + function getMaxWords(IStore _store) internal view returns (uint16 maxWords) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1); + return (uint16(Bytes.slice2(_blob, 0))); + } + + /** Set maxWords */ + function setMaxWords(uint16 maxWords) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((maxWords))); + } + + /** Set maxWords (using the specified store) */ + function setMaxWords(IStore _store, uint16 maxWords) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((maxWords))); + } + + /** Get wordsPlayed */ + function getWordsPlayed() internal view returns (uint16 wordsPlayed) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2); + return (uint16(Bytes.slice2(_blob, 0))); + } + + /** Get wordsPlayed (using the specified store) */ + function getWordsPlayed(IStore _store) internal view returns (uint16 wordsPlayed) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = _store.getField(_tableId, _keyTuple, 2); + return (uint16(Bytes.slice2(_blob, 0))); + } + + /** Set wordsPlayed */ + function setWordsPlayed(uint16 wordsPlayed) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.setField(_tableId, _keyTuple, 2, abi.encodePacked((wordsPlayed))); + } + + /** Set wordsPlayed (using the specified store) */ + function setWordsPlayed(IStore _store, uint16 wordsPlayed) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.setField(_tableId, _keyTuple, 2, abi.encodePacked((wordsPlayed))); + } + + /** Get the full data */ + function get() internal view returns (GameConfigData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getSchema()); + return decode(_blob); + } + + /** Get the full data (using the specified store) */ + function get(IStore _store) internal view returns (GameConfigData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getSchema()); + return decode(_blob); + } + + /** Set the full data using individual values */ + function set(uint8 status, uint16 maxWords, uint16 wordsPlayed) internal { + bytes memory _data = encode(status, maxWords, wordsPlayed); + + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.setRecord(_tableId, _keyTuple, _data); + } + + /** Set the full data using individual values (using the specified store) */ + function set(IStore _store, uint8 status, uint16 maxWords, uint16 wordsPlayed) internal { + bytes memory _data = encode(status, maxWords, wordsPlayed); + + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.setRecord(_tableId, _keyTuple, _data); + } + + /** Set the full data using the data struct */ + function set(GameConfigData memory _table) internal { + set(_table.status, _table.maxWords, _table.wordsPlayed); + } + + /** Set the full data using the data struct (using the specified store) */ + function set(IStore _store, GameConfigData memory _table) internal { + set(_store, _table.status, _table.maxWords, _table.wordsPlayed); + } + + /** Decode the tightly packed blob using this table's schema */ + function decode(bytes memory _blob) internal pure returns (GameConfigData memory _table) { + _table.status = (uint8(Bytes.slice1(_blob, 0))); + + _table.maxWords = (uint16(Bytes.slice2(_blob, 1))); + + _table.wordsPlayed = (uint16(Bytes.slice2(_blob, 3))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint8 status, uint16 maxWords, uint16 wordsPlayed) internal view returns (bytes memory) { + return abi.encodePacked(status, maxWords, wordsPlayed); + } + + /** Encode keys as a bytes32 array using this table's schema */ + function encodeKeyTuple() internal pure returns (bytes32[] memory _keyTuple) { + _keyTuple = new bytes32[](0); + } + + /* Delete all data for given keys */ + function deleteRecord() internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /* 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); + } +} diff --git a/e2e/packages/contracts/src/codegen/tables/LetterCount.sol b/e2e/packages/contracts/src/codegen/tables/LetterCount.sol new file mode 100644 index 0000000000..47b7bac6c3 --- /dev/null +++ b/e2e/packages/contracts/src/codegen/tables/LetterCount.sol @@ -0,0 +1,128 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +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 { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("LetterCount"))); +bytes32 constant LetterCountTableId = _tableId; + +library LetterCount { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT32; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT8; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("LetterCount", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint8 letter) internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(letter)); + + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint8 letter) internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(letter)); + + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set value */ + function set(uint8 letter, uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(letter)); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint8 letter, uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(letter)); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint32 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /** Encode keys as a bytes32 array using this table's schema */ + function encodeKeyTuple(uint8 letter) internal pure returns (bytes32[] memory _keyTuple) { + _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(letter)); + } + + /* Delete all data for given keys */ + function deleteRecord(uint8 letter) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(letter)); + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint8 letter) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(letter)); + + _store.deleteRecord(_tableId, _keyTuple); + } +} diff --git a/e2e/packages/contracts/src/codegen/tables/MerkleRootConfig.sol b/e2e/packages/contracts/src/codegen/tables/MerkleRootConfig.sol new file mode 100644 index 0000000000..d6f671b912 --- /dev/null +++ b/e2e/packages/contracts/src/codegen/tables/MerkleRootConfig.sol @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +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 { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("MerkleRootConfig"))); +bytes32 constant MerkleRootConfigTableId = _tableId; + +library MerkleRootConfig { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.BYTES32; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](0); + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("MerkleRootConfig", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get() internal view returns (bytes32 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + return (Bytes.slice32(_blob, 0)); + } + + /** Get value (using the specified store) */ + function get(IStore _store) internal view returns (bytes32 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + return (Bytes.slice32(_blob, 0)); + } + + /** Set value */ + function set(bytes32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, bytes32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(bytes32 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /** Encode keys as a bytes32 array using this table's schema */ + function encodeKeyTuple() internal pure returns (bytes32[] memory _keyTuple) { + _keyTuple = new bytes32[](0); + } + + /* Delete all data for given keys */ + function deleteRecord() internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /* 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); + } +} diff --git a/e2e/packages/contracts/src/codegen/tables/Name.sol b/e2e/packages/contracts/src/codegen/tables/Name.sol new file mode 100644 index 0000000000..8676ccb0a7 --- /dev/null +++ b/e2e/packages/contracts/src/codegen/tables/Name.sol @@ -0,0 +1,216 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +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 { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Name"))); +bytes32 constant NameTableId = _tableId; + +library Name { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.STRING; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.ADDRESS; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "name"; + return ("Name", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get name */ + function get(address user) internal view returns (string memory name) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(user))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + return (string(_blob)); + } + + /** Get name (using the specified store) */ + function get(IStore _store, address user) internal view returns (string memory name) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(user))); + + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + return (string(_blob)); + } + + /** Set name */ + function set(address user, string memory name) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(user))); + + StoreSwitch.setField(_tableId, _keyTuple, 0, bytes((name))); + } + + /** Set name (using the specified store) */ + function set(IStore _store, address user, string memory name) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(user))); + + _store.setField(_tableId, _keyTuple, 0, bytes((name))); + } + + /** Get the length of name */ + function length(address user) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(user))); + + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, getSchema()); + return _byteLength / 1; + } + + /** Get the length of name (using the specified store) */ + function length(IStore _store, address user) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(user))); + + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, getSchema()); + return _byteLength / 1; + } + + /** Get an item of name (unchecked, returns invalid data if index overflows) */ + function getItem(address user, uint256 _index) internal view returns (string memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(user))); + + bytes memory _blob = StoreSwitch.getFieldSlice(_tableId, _keyTuple, 0, getSchema(), _index * 1, (_index + 1) * 1); + return (string(_blob)); + } + + /** Get an item of name (using the specified store) (unchecked, returns invalid data if index overflows) */ + function getItem(IStore _store, address user, uint256 _index) internal view returns (string memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(user))); + + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, getSchema(), _index * 1, (_index + 1) * 1); + return (string(_blob)); + } + + /** Push a slice to name */ + function push(address user, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(user))); + + StoreSwitch.pushToField(_tableId, _keyTuple, 0, bytes((_slice))); + } + + /** Push a slice to name (using the specified store) */ + function push(IStore _store, address user, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(user))); + + _store.pushToField(_tableId, _keyTuple, 0, bytes((_slice))); + } + + /** Pop a slice from name */ + function pop(address user) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(user))); + + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 1); + } + + /** Pop a slice from name (using the specified store) */ + function pop(IStore _store, address user) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(user))); + + _store.popFromField(_tableId, _keyTuple, 0, 1); + } + + /** Update a slice of name at `_index` */ + function update(address user, uint256 _index, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(user))); + + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 1, bytes((_slice))); + } + + /** Update a slice of name (using the specified store) at `_index` */ + function update(IStore _store, address user, uint256 _index, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(user))); + + _store.updateInField(_tableId, _keyTuple, 0, _index * 1, bytes((_slice))); + } + + /** Tightly pack full data using this table's schema */ + function encode(string memory name) internal view returns (bytes memory) { + uint40[] memory _counters = new uint40[](1); + _counters[0] = uint40(bytes(name).length); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(_encodedLengths.unwrap(), bytes((name))); + } + + /** Encode keys as a bytes32 array using this table's schema */ + function encodeKeyTuple(address user) internal pure returns (bytes32[] memory _keyTuple) { + _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(user))); + } + + /* Delete all data for given keys */ + function deleteRecord(address user) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(user))); + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, address user) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(user))); + + _store.deleteRecord(_tableId, _keyTuple); + } +} diff --git a/e2e/packages/contracts/src/codegen/tables/Points.sol b/e2e/packages/contracts/src/codegen/tables/Points.sol new file mode 100644 index 0000000000..4aa68a695e --- /dev/null +++ b/e2e/packages/contracts/src/codegen/tables/Points.sol @@ -0,0 +1,128 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +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 { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Points"))); +bytes32 constant PointsTableId = _tableId; + +library Points { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT32; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.ADDRESS; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("Points", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(address player) internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(player))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, address player) internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(player))); + + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set value */ + function set(address player, uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(player))); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, address player, uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(player))); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint32 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /** Encode keys as a bytes32 array using this table's schema */ + function encodeKeyTuple(address player) internal pure returns (bytes32[] memory _keyTuple) { + _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(player))); + } + + /* Delete all data for given keys */ + function deleteRecord(address player) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(player))); + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, address player) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(player))); + + _store.deleteRecord(_tableId, _keyTuple); + } +} diff --git a/e2e/packages/contracts/src/codegen/tables/TileLetter.sol b/e2e/packages/contracts/src/codegen/tables/TileLetter.sol new file mode 100644 index 0000000000..5ba099d304 --- /dev/null +++ b/e2e/packages/contracts/src/codegen/tables/TileLetter.sol @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +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 { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("TileLetter"))); +bytes32 constant TileLetterTableId = _tableId; + +library TileLetter { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT8; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](2); + _schema[0] = SchemaType.INT32; + _schema[1] = SchemaType.INT32; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("TileLetter", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(int32 x, int32 y) internal view returns (uint8 value) { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(int256(x))); + _keyTuple[1] = bytes32(uint256(int256(y))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + return (uint8(Bytes.slice1(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, int32 x, int32 y) internal view returns (uint8 value) { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(int256(x))); + _keyTuple[1] = bytes32(uint256(int256(y))); + + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + return (uint8(Bytes.slice1(_blob, 0))); + } + + /** Set value */ + function set(int32 x, int32 y, uint8 value) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(int256(x))); + _keyTuple[1] = bytes32(uint256(int256(y))); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, int32 x, int32 y, uint8 value) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(int256(x))); + _keyTuple[1] = bytes32(uint256(int256(y))); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint8 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /** Encode keys as a bytes32 array using this table's schema */ + function encodeKeyTuple(int32 x, int32 y) internal pure returns (bytes32[] memory _keyTuple) { + _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(int256(x))); + _keyTuple[1] = bytes32(uint256(int256(y))); + } + + /* Delete all data for given keys */ + function deleteRecord(int32 x, int32 y) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(int256(x))); + _keyTuple[1] = bytes32(uint256(int256(y))); + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, int32 x, int32 y) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(int256(x))); + _keyTuple[1] = bytes32(uint256(int256(y))); + + _store.deleteRecord(_tableId, _keyTuple); + } +} diff --git a/e2e/packages/contracts/src/codegen/tables/TilePlayer.sol b/e2e/packages/contracts/src/codegen/tables/TilePlayer.sol new file mode 100644 index 0000000000..5b179d8109 --- /dev/null +++ b/e2e/packages/contracts/src/codegen/tables/TilePlayer.sol @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +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 { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("TilePlayer"))); +bytes32 constant TilePlayerTableId = _tableId; + +library TilePlayer { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.ADDRESS; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](2); + _schema[0] = SchemaType.INT32; + _schema[1] = SchemaType.INT32; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("TilePlayer", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(int32 x, int32 y) internal view returns (address value) { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(int256(x))); + _keyTuple[1] = bytes32(uint256(int256(y))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + return (address(Bytes.slice20(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, int32 x, int32 y) internal view returns (address value) { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(int256(x))); + _keyTuple[1] = bytes32(uint256(int256(y))); + + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + return (address(Bytes.slice20(_blob, 0))); + } + + /** Set value */ + function set(int32 x, int32 y, address value) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(int256(x))); + _keyTuple[1] = bytes32(uint256(int256(y))); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, int32 x, int32 y, address value) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(int256(x))); + _keyTuple[1] = bytes32(uint256(int256(y))); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(address value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /** Encode keys as a bytes32 array using this table's schema */ + function encodeKeyTuple(int32 x, int32 y) internal pure returns (bytes32[] memory _keyTuple) { + _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(int256(x))); + _keyTuple[1] = bytes32(uint256(int256(y))); + } + + /* Delete all data for given keys */ + function deleteRecord(int32 x, int32 y) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(int256(x))); + _keyTuple[1] = bytes32(uint256(int256(y))); + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, int32 x, int32 y) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(int256(x))); + _keyTuple[1] = bytes32(uint256(int256(y))); + + _store.deleteRecord(_tableId, _keyTuple); + } +} diff --git a/e2e/packages/contracts/src/codegen/tables/Treasury.sol b/e2e/packages/contracts/src/codegen/tables/Treasury.sol new file mode 100644 index 0000000000..1acf602977 --- /dev/null +++ b/e2e/packages/contracts/src/codegen/tables/Treasury.sol @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +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 { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Treasury"))); +bytes32 constant TreasuryTableId = _tableId; + +library Treasury { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](0); + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("Treasury", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get() internal view returns (uint256 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store) internal view returns (uint256 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set value */ + function set(uint256 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /** Encode keys as a bytes32 array using this table's schema */ + function encodeKeyTuple() internal pure returns (bytes32[] memory _keyTuple) { + _keyTuple = new bytes32[](0); + } + + /* Delete all data for given keys */ + function deleteRecord() internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /* 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); + } +} diff --git a/e2e/packages/contracts/src/codegen/tables/VRGDAConfig.sol b/e2e/packages/contracts/src/codegen/tables/VRGDAConfig.sol new file mode 100644 index 0000000000..81b1f88ee6 --- /dev/null +++ b/e2e/packages/contracts/src/codegen/tables/VRGDAConfig.sol @@ -0,0 +1,283 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +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 { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("VRGDAConfig"))); +bytes32 constant VRGDAConfigTableId = _tableId; + +struct VRGDAConfigData { + uint256 startTime; + int256 targetPrice; + int256 priceDecay; + int256 perDay; +} + +library VRGDAConfig { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](4); + _schema[0] = SchemaType.UINT256; + _schema[1] = SchemaType.INT256; + _schema[2] = SchemaType.INT256; + _schema[3] = SchemaType.INT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](0); + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](4); + _fieldNames[0] = "startTime"; + _fieldNames[1] = "targetPrice"; + _fieldNames[2] = "priceDecay"; + _fieldNames[3] = "perDay"; + return ("VRGDAConfig", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get startTime */ + function getStartTime() internal view returns (uint256 startTime) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get startTime (using the specified store) */ + function getStartTime(IStore _store) internal view returns (uint256 startTime) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set startTime */ + function setStartTime(uint256 startTime) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((startTime))); + } + + /** Set startTime (using the specified store) */ + function setStartTime(IStore _store, uint256 startTime) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((startTime))); + } + + /** Get targetPrice */ + function getTargetPrice() internal view returns (int256 targetPrice) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1); + return (int256(uint256(Bytes.slice32(_blob, 0)))); + } + + /** Get targetPrice (using the specified store) */ + function getTargetPrice(IStore _store) internal view returns (int256 targetPrice) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1); + return (int256(uint256(Bytes.slice32(_blob, 0)))); + } + + /** Set targetPrice */ + function setTargetPrice(int256 targetPrice) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((targetPrice))); + } + + /** Set targetPrice (using the specified store) */ + function setTargetPrice(IStore _store, int256 targetPrice) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((targetPrice))); + } + + /** Get priceDecay */ + function getPriceDecay() internal view returns (int256 priceDecay) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2); + return (int256(uint256(Bytes.slice32(_blob, 0)))); + } + + /** Get priceDecay (using the specified store) */ + function getPriceDecay(IStore _store) internal view returns (int256 priceDecay) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = _store.getField(_tableId, _keyTuple, 2); + return (int256(uint256(Bytes.slice32(_blob, 0)))); + } + + /** Set priceDecay */ + function setPriceDecay(int256 priceDecay) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.setField(_tableId, _keyTuple, 2, abi.encodePacked((priceDecay))); + } + + /** Set priceDecay (using the specified store) */ + function setPriceDecay(IStore _store, int256 priceDecay) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.setField(_tableId, _keyTuple, 2, abi.encodePacked((priceDecay))); + } + + /** Get perDay */ + function getPerDay() internal view returns (int256 perDay) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 3); + return (int256(uint256(Bytes.slice32(_blob, 0)))); + } + + /** Get perDay (using the specified store) */ + function getPerDay(IStore _store) internal view returns (int256 perDay) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = _store.getField(_tableId, _keyTuple, 3); + return (int256(uint256(Bytes.slice32(_blob, 0)))); + } + + /** Set perDay */ + function setPerDay(int256 perDay) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.setField(_tableId, _keyTuple, 3, abi.encodePacked((perDay))); + } + + /** Set perDay (using the specified store) */ + function setPerDay(IStore _store, int256 perDay) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.setField(_tableId, _keyTuple, 3, abi.encodePacked((perDay))); + } + + /** Get the full data */ + function get() internal view returns (VRGDAConfigData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getSchema()); + return decode(_blob); + } + + /** Get the full data (using the specified store) */ + function get(IStore _store) internal view returns (VRGDAConfigData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getSchema()); + return decode(_blob); + } + + /** Set the full data using individual values */ + function set(uint256 startTime, int256 targetPrice, int256 priceDecay, int256 perDay) internal { + bytes memory _data = encode(startTime, targetPrice, priceDecay, perDay); + + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.setRecord(_tableId, _keyTuple, _data); + } + + /** Set the full data using individual values (using the specified store) */ + function set(IStore _store, uint256 startTime, int256 targetPrice, int256 priceDecay, int256 perDay) internal { + bytes memory _data = encode(startTime, targetPrice, priceDecay, perDay); + + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.setRecord(_tableId, _keyTuple, _data); + } + + /** Set the full data using the data struct */ + function set(VRGDAConfigData memory _table) internal { + set(_table.startTime, _table.targetPrice, _table.priceDecay, _table.perDay); + } + + /** Set the full data using the data struct (using the specified store) */ + function set(IStore _store, VRGDAConfigData memory _table) internal { + set(_store, _table.startTime, _table.targetPrice, _table.priceDecay, _table.perDay); + } + + /** Decode the tightly packed blob using this table's schema */ + function decode(bytes memory _blob) internal pure returns (VRGDAConfigData memory _table) { + _table.startTime = (uint256(Bytes.slice32(_blob, 0))); + + _table.targetPrice = (int256(uint256(Bytes.slice32(_blob, 32)))); + + _table.priceDecay = (int256(uint256(Bytes.slice32(_blob, 64)))); + + _table.perDay = (int256(uint256(Bytes.slice32(_blob, 96)))); + } + + /** Tightly pack full data using this table's schema */ + function encode( + uint256 startTime, + int256 targetPrice, + int256 priceDecay, + int256 perDay + ) internal view returns (bytes memory) { + return abi.encodePacked(startTime, targetPrice, priceDecay, perDay); + } + + /** Encode keys as a bytes32 array using this table's schema */ + function encodeKeyTuple() internal pure returns (bytes32[] memory _keyTuple) { + _keyTuple = new bytes32[](0); + } + + /* Delete all data for given keys */ + function deleteRecord() internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /* 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); + } +} diff --git a/e2e/packages/contracts/worlds.json b/e2e/packages/contracts/worlds.json index bd48105fd7..52732caca6 100644 --- a/e2e/packages/contracts/worlds.json +++ b/e2e/packages/contracts/worlds.json @@ -1,5 +1,5 @@ { "31337": { - "address": "0x5FbDB2315678afecb367f032d93F642f64180aa3" + "address": "0xaC9fCBA56E42d5960f813B9D0387F3D3bC003338" } } \ No newline at end of file diff --git a/e2e/packages/sync-test/data/readClientStore.ts b/e2e/packages/sync-test/data/readClientStore.ts index 6f9749d5fe..a1dcbd822e 100644 --- a/e2e/packages/sync-test/data/readClientStore.ts +++ b/e2e/packages/sync-test/data/readClientStore.ts @@ -20,6 +20,10 @@ export async function readClientStore( const _serialize = deserializeFunction(_serializeString); const _deserialize = deserializeFunction(_deserializeString); const value = await window["storeCache"].get(_namespace, _table, _deserialize(_key)); + + // TODO: remove log + console.log("reading value", value, _serialize(value), "for key", _key); + const serializedValue = value ? _serialize(value) : undefined; return serializedValue; @@ -31,5 +35,8 @@ export async function readClientStore( } }, args); + // TODO: remove log + console.log("deserialized", deserialize(serializedValue)); + return serializedValue ? deserialize(serializedValue) : undefined; } diff --git a/e2e/packages/sync-test/data/testData.ts b/e2e/packages/sync-test/data/testData.ts index b6d09a9fce..7788cfcbe9 100644 --- a/e2e/packages/sync-test/data/testData.ts +++ b/e2e/packages/sync-test/data/testData.ts @@ -16,7 +16,7 @@ export const testData1 = { ], NumberList: [{ key: {}, value: { value: [1, 2, 3] } }], Name: [{ key: { user: toHex(1234, { size: 20 }) }, value: { name: "some-name" } }], - Bytes: [{ key: { key: toHex(1234, { size: 32 }) }, value: { value: toHex(1234, { size: 64 }) } }], + Data: [{ key: { key: toHex(1234, { size: 32 }) }, value: { value: toHex(1234, { size: 64 }) } }], // -------------- WORDS3 DATA ---------------- GameConfig: [{ key: {}, value: { status: 1, maxWords: 42, wordsPlayed: 1337 } }], MerkleRootConfig: [{ key: {}, value: { value: toHex(1234, { size: 32 }) } }], diff --git a/e2e/packages/sync-test/data/waitForInitialSync.ts b/e2e/packages/sync-test/data/waitForInitialSync.ts index 00c66a98ec..83359825af 100644 --- a/e2e/packages/sync-test/data/waitForInitialSync.ts +++ b/e2e/packages/sync-test/data/waitForInitialSync.ts @@ -1,7 +1,9 @@ import { SyncState } from "@latticexyz/network"; +import { sleep } from "@latticexyz/utils"; import { Page, expect } from "@playwright/test"; export async function waitForInitialSync(page: Page) { const syncState = page.locator("#sync-state"); await expect(syncState).toHaveText(String(SyncState.LIVE)); + await sleep(10000); } diff --git a/e2e/packages/sync-test/modeSync.test.ts b/e2e/packages/sync-test/modeSync.test.ts index da43ba8a56..6e8c37f426 100644 --- a/e2e/packages/sync-test/modeSync.test.ts +++ b/e2e/packages/sync-test/modeSync.test.ts @@ -24,7 +24,7 @@ import { } from "./data"; import { range } from "@latticexyz/utils"; -describe("Sync from MODE", async () => { +describe.skip("Sync from MODE", async () => { const asyncErrorHandler = createAsyncErrorHandler(); let anvilProcess: ExecaChildProcess; let webserver: ViteDevServer; diff --git a/e2e/packages/sync-test/rpcSync.test.ts b/e2e/packages/sync-test/rpcSync.test.ts index d1023603c7..2187c9adaa 100644 --- a/e2e/packages/sync-test/rpcSync.test.ts +++ b/e2e/packages/sync-test/rpcSync.test.ts @@ -46,7 +46,7 @@ describe("Sync from RPC", async () => { anvilProcess?.kill(); }); - test("should sync test data", async () => { + test.only("should sync test data", async () => { await openClientWithRootAccount(page); await waitForInitialSync(page);