From d8402407d38975c176561c37ff009a5caacc7740 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Sun, 14 Apr 2024 14:34:26 +0100 Subject: [PATCH] build: disable DTS in dev --- package.json | 2 +- packages/abi-ts/tsup.config.ts | 2 +- packages/block-logs-stream/tsup.config.ts | 2 +- .../src/codegen/tables/Dynamics1.sol | 1140 ----------------- .../src/codegen/tables/Dynamics2.sol | 754 ----------- .../contracts/src/codegen/tables/Offchain.sol | 182 --- .../src/codegen/tables/Singleton.sol | 694 ---------- .../contracts/src/codegen/tables/Statics.sol | 760 ----------- .../src/codegen/tables/UserTyped.sol | 846 ------------ packages/cli/tsup.config.ts | 2 +- packages/common/tsup.config.ts | 2 +- packages/config/tsup.config.ts | 2 +- packages/dev-tools/tsup.config.ts | 2 +- packages/faucet/tsup.config.ts | 2 +- packages/gas-report/tsup.config.ts | 2 +- packages/protocol-parser/tsup.config.ts | 2 +- packages/query/tsup.config.ts | 2 +- packages/react/tsup.config.ts | 2 +- packages/recs/tsup.config.ts | 2 +- packages/schema-type/tsup.config.ts | 2 +- packages/services/tsup.config.ts | 2 +- packages/solhint-config-mud/tsup.config.ts | 2 +- packages/solhint-plugin-mud/tsup.config.ts | 2 +- packages/store-indexer/tsup.config.ts | 2 +- packages/store-sync/tsup.config.ts | 2 +- packages/store/tsup.config.ts | 2 +- packages/utils/tsup.config.ts | 2 +- packages/world-modules/tsup.config.ts | 2 +- packages/world/tsup.config.ts | 2 +- 29 files changed, 23 insertions(+), 4399 deletions(-) delete mode 100644 packages/cli/contracts/src/codegen/tables/Dynamics1.sol delete mode 100644 packages/cli/contracts/src/codegen/tables/Dynamics2.sol delete mode 100644 packages/cli/contracts/src/codegen/tables/Offchain.sol delete mode 100644 packages/cli/contracts/src/codegen/tables/Singleton.sol delete mode 100644 packages/cli/contracts/src/codegen/tables/Statics.sol delete mode 100644 packages/cli/contracts/src/codegen/tables/UserTyped.sol diff --git a/package.json b/package.json index 5a5ffda9d4..bb068ea10a 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "build": "turbo run build", "changelog:generate": "bun scripts/changelog.ts", "clean": "turbo run clean", - "dev": "turbo run dev --concurrency 100", + "dev": "TSUP_SKIP_DTS=true turbo run dev --concurrency 100", "dist-tag-rm": "pnpm recursive exec -- sh -c 'npm dist-tag rm $(cat package.json | jq -r \".name\") $TAG || true'", "docs:generate:api": "bun scripts/render-api-docs.ts", "foundryup": "curl -L https://foundry.paradigm.xyz | bash && bash ~/.foundry/bin/foundryup", diff --git a/packages/abi-ts/tsup.config.ts b/packages/abi-ts/tsup.config.ts index 783fa85248..17e4b13a46 100644 --- a/packages/abi-ts/tsup.config.ts +++ b/packages/abi-ts/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["src/index.ts", "src/abi-ts.ts"], target: "esnext", format: ["esm"], - dts: true, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/block-logs-stream/tsup.config.ts b/packages/block-logs-stream/tsup.config.ts index 52bdfceee6..86fe9a5339 100644 --- a/packages/block-logs-stream/tsup.config.ts +++ b/packages/block-logs-stream/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["src/index.ts"], target: "esnext", format: ["esm"], - dts: true, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol b/packages/cli/contracts/src/codegen/tables/Dynamics1.sol deleted file mode 100644 index 96f8d3469e..0000000000 --- a/packages/cli/contracts/src/codegen/tables/Dynamics1.sol +++ /dev/null @@ -1,1140 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -/* Autogenerated file. Do not edit manually. */ - -// 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 { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema } from "@latticexyz/store/src/Schema.sol"; -import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; -import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; - -struct Dynamics1Data { - bytes32[1] staticB32; - int32[2] staticI32; - uint128[3] staticU128; - address[4] staticAddrs; - bool[5] staticBools; -} - -library Dynamics1 { - // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Dynamics1", typeId: RESOURCE_TABLE });` - ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000044796e616d6963733100000000000000); - - FieldLayout constant _fieldLayout = - FieldLayout.wrap(0x0000000500000000000000000000000000000000000000000000000000000000); - - // Hex-encoded key schema of (bytes32) - Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); - // Hex-encoded value schema of (bytes32[], int32[], uint128[], address[], bool[]) - Schema constant _valueSchema = Schema.wrap(0x00000005c18571c3c20000000000000000000000000000000000000000000000); - - /** - * @notice Get the table's key field names. - * @return keyNames An array of strings with the names of key fields. - */ - function getKeyNames() internal pure returns (string[] memory keyNames) { - keyNames = new string[](1); - keyNames[0] = "key"; - } - - /** - * @notice Get the table's value field names. - * @return fieldNames An array of strings with the names of value fields. - */ - function getFieldNames() internal pure returns (string[] memory fieldNames) { - fieldNames = new string[](5); - fieldNames[0] = "staticB32"; - fieldNames[1] = "staticI32"; - fieldNames[2] = "staticU128"; - fieldNames[3] = "staticAddrs"; - fieldNames[4] = "staticBools"; - } - - /** - * @notice Register the table with its config. - */ - function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); - } - - /** - * @notice Register the table with its config. - */ - function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); - } - - /** - * @notice Get staticB32. - */ - function getStaticB32(bytes32 key) internal view returns (bytes32[1] memory staticB32) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); - return toStaticArray_bytes32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); - } - - /** - * @notice Get staticB32. - */ - function _getStaticB32(bytes32 key) internal view returns (bytes32[1] memory staticB32) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0); - return toStaticArray_bytes32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); - } - - /** - * @notice Set staticB32. - */ - function setStaticB32(bytes32 key, bytes32[1] memory staticB32) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode(fromStaticArray_bytes32_1(staticB32))); - } - - /** - * @notice Set staticB32. - */ - function _setStaticB32(bytes32 key, bytes32[1] memory staticB32) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode(fromStaticArray_bytes32_1(staticB32))); - } - - // The length of staticB32 - uint256 constant lengthStaticB32 = 1; - - /** - * @notice Get an item of staticB32. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemStaticB32(bytes32 key, uint256 _index) internal view returns (bytes32) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 0); - uint256 dynamicLength = _byteLength / 32; - uint256 staticLength = 1; - - if (_index < staticLength && _index >= dynamicLength) { - return (bytes32(new bytes(0))); - } - - unchecked { - bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 32, (_index + 1) * 32); - return (bytes32(_blob)); - } - } - - /** - * @notice Get an item of staticB32. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function _getItemStaticB32(bytes32 key, uint256 _index) internal view returns (bytes32) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 0); - uint256 dynamicLength = _byteLength / 32; - uint256 staticLength = 1; - - if (_index < staticLength && _index >= dynamicLength) { - return (bytes32(new bytes(0))); - } - - unchecked { - bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 32, (_index + 1) * 32); - return (bytes32(_blob)); - } - } - - /** - * @notice Update an element of staticB32 at `_index`. - */ - function updateStaticB32(bytes32 key, uint256 _index, bytes32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 32), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Update an element of staticB32 at `_index`. - */ - function _updateStaticB32(bytes32 key, uint256 _index, bytes32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - StoreCore.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 32), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Get staticI32. - */ - function getStaticI32(bytes32 key) internal view returns (int32[2] memory staticI32) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 1); - return toStaticArray_int32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_int32()); - } - - /** - * @notice Get staticI32. - */ - function _getStaticI32(bytes32 key) internal view returns (int32[2] memory staticI32) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 1); - return toStaticArray_int32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_int32()); - } - - /** - * @notice Set staticI32. - */ - function setStaticI32(bytes32 key, int32[2] memory staticI32) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.setDynamicField(_tableId, _keyTuple, 1, EncodeArray.encode(fromStaticArray_int32_2(staticI32))); - } - - /** - * @notice Set staticI32. - */ - function _setStaticI32(bytes32 key, int32[2] memory staticI32) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.setDynamicField(_tableId, _keyTuple, 1, EncodeArray.encode(fromStaticArray_int32_2(staticI32))); - } - - // The length of staticI32 - uint256 constant lengthStaticI32 = 2; - - /** - * @notice Get an item of staticI32. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemStaticI32(bytes32 key, uint256 _index) internal view returns (int32) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 1); - uint256 dynamicLength = _byteLength / 4; - uint256 staticLength = 2; - - if (_index < staticLength && _index >= dynamicLength) { - return (int32(uint32(bytes4(new bytes(0))))); - } - - unchecked { - bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 4, (_index + 1) * 4); - return (int32(uint32(bytes4(_blob)))); - } - } - - /** - * @notice Get an item of staticI32. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function _getItemStaticI32(bytes32 key, uint256 _index) internal view returns (int32) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 1); - uint256 dynamicLength = _byteLength / 4; - uint256 staticLength = 2; - - if (_index < staticLength && _index >= dynamicLength) { - return (int32(uint32(bytes4(new bytes(0))))); - } - - unchecked { - bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 4, (_index + 1) * 4); - return (int32(uint32(bytes4(_blob)))); - } - } - - /** - * @notice Update an element of staticI32 at `_index`. - */ - function updateStaticI32(bytes32 key, uint256 _index, int32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 4), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Update an element of staticI32 at `_index`. - */ - function _updateStaticI32(bytes32 key, uint256 _index, int32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - StoreCore.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 4), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Get staticU128. - */ - function getStaticU128(bytes32 key) internal view returns (uint128[3] memory staticU128) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 2); - return toStaticArray_uint128_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint128()); - } - - /** - * @notice Get staticU128. - */ - function _getStaticU128(bytes32 key) internal view returns (uint128[3] memory staticU128) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 2); - return toStaticArray_uint128_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint128()); - } - - /** - * @notice Set staticU128. - */ - function setStaticU128(bytes32 key, uint128[3] memory staticU128) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.setDynamicField(_tableId, _keyTuple, 2, EncodeArray.encode(fromStaticArray_uint128_3(staticU128))); - } - - /** - * @notice Set staticU128. - */ - function _setStaticU128(bytes32 key, uint128[3] memory staticU128) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.setDynamicField(_tableId, _keyTuple, 2, EncodeArray.encode(fromStaticArray_uint128_3(staticU128))); - } - - // The length of staticU128 - uint256 constant lengthStaticU128 = 3; - - /** - * @notice Get an item of staticU128. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemStaticU128(bytes32 key, uint256 _index) internal view returns (uint128) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 2); - uint256 dynamicLength = _byteLength / 16; - uint256 staticLength = 3; - - if (_index < staticLength && _index >= dynamicLength) { - return (uint128(bytes16(new bytes(0)))); - } - - unchecked { - bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 2, _index * 16, (_index + 1) * 16); - return (uint128(bytes16(_blob))); - } - } - - /** - * @notice Get an item of staticU128. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function _getItemStaticU128(bytes32 key, uint256 _index) internal view returns (uint128) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 2); - uint256 dynamicLength = _byteLength / 16; - uint256 staticLength = 3; - - if (_index < staticLength && _index >= dynamicLength) { - return (uint128(bytes16(new bytes(0)))); - } - - unchecked { - bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 2, _index * 16, (_index + 1) * 16); - return (uint128(bytes16(_blob))); - } - } - - /** - * @notice Update an element of staticU128 at `_index`. - */ - function updateStaticU128(bytes32 key, uint256 _index, uint128 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 2, uint40(_index * 16), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Update an element of staticU128 at `_index`. - */ - function _updateStaticU128(bytes32 key, uint256 _index, uint128 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - StoreCore.spliceDynamicData(_tableId, _keyTuple, 2, uint40(_index * 16), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Get staticAddrs. - */ - function getStaticAddrs(bytes32 key) internal view returns (address[4] memory staticAddrs) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 3); - return toStaticArray_address_4(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); - } - - /** - * @notice Get staticAddrs. - */ - function _getStaticAddrs(bytes32 key) internal view returns (address[4] memory staticAddrs) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 3); - return toStaticArray_address_4(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); - } - - /** - * @notice Set staticAddrs. - */ - function setStaticAddrs(bytes32 key, address[4] memory staticAddrs) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.setDynamicField(_tableId, _keyTuple, 3, EncodeArray.encode(fromStaticArray_address_4(staticAddrs))); - } - - /** - * @notice Set staticAddrs. - */ - function _setStaticAddrs(bytes32 key, address[4] memory staticAddrs) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.setDynamicField(_tableId, _keyTuple, 3, EncodeArray.encode(fromStaticArray_address_4(staticAddrs))); - } - - // The length of staticAddrs - uint256 constant lengthStaticAddrs = 4; - - /** - * @notice Get an item of staticAddrs. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemStaticAddrs(bytes32 key, uint256 _index) internal view returns (address) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 3); - uint256 dynamicLength = _byteLength / 20; - uint256 staticLength = 4; - - if (_index < staticLength && _index >= dynamicLength) { - return (address(bytes20(new bytes(0)))); - } - - unchecked { - bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 3, _index * 20, (_index + 1) * 20); - return (address(bytes20(_blob))); - } - } - - /** - * @notice Get an item of staticAddrs. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function _getItemStaticAddrs(bytes32 key, uint256 _index) internal view returns (address) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 3); - uint256 dynamicLength = _byteLength / 20; - uint256 staticLength = 4; - - if (_index < staticLength && _index >= dynamicLength) { - return (address(bytes20(new bytes(0)))); - } - - unchecked { - bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 3, _index * 20, (_index + 1) * 20); - return (address(bytes20(_blob))); - } - } - - /** - * @notice Update an element of staticAddrs at `_index`. - */ - function updateStaticAddrs(bytes32 key, uint256 _index, address _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 3, uint40(_index * 20), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Update an element of staticAddrs at `_index`. - */ - function _updateStaticAddrs(bytes32 key, uint256 _index, address _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - StoreCore.spliceDynamicData(_tableId, _keyTuple, 3, uint40(_index * 20), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Get staticBools. - */ - function getStaticBools(bytes32 key) internal view returns (bool[5] memory staticBools) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 4); - return toStaticArray_bool_5(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bool()); - } - - /** - * @notice Get staticBools. - */ - function _getStaticBools(bytes32 key) internal view returns (bool[5] memory staticBools) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 4); - return toStaticArray_bool_5(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bool()); - } - - /** - * @notice Set staticBools. - */ - function setStaticBools(bytes32 key, bool[5] memory staticBools) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.setDynamicField(_tableId, _keyTuple, 4, EncodeArray.encode(fromStaticArray_bool_5(staticBools))); - } - - /** - * @notice Set staticBools. - */ - function _setStaticBools(bytes32 key, bool[5] memory staticBools) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.setDynamicField(_tableId, _keyTuple, 4, EncodeArray.encode(fromStaticArray_bool_5(staticBools))); - } - - // The length of staticBools - uint256 constant lengthStaticBools = 5; - - /** - * @notice Get an item of staticBools. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemStaticBools(bytes32 key, uint256 _index) internal view returns (bool) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 4); - uint256 dynamicLength = _byteLength / 1; - uint256 staticLength = 5; - - if (_index < staticLength && _index >= dynamicLength) { - return (_toBool(uint8(bytes1(new bytes(0))))); - } - - unchecked { - bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 4, _index * 1, (_index + 1) * 1); - return (_toBool(uint8(bytes1(_blob)))); - } - } - - /** - * @notice Get an item of staticBools. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function _getItemStaticBools(bytes32 key, uint256 _index) internal view returns (bool) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 4); - uint256 dynamicLength = _byteLength / 1; - uint256 staticLength = 5; - - if (_index < staticLength && _index >= dynamicLength) { - return (_toBool(uint8(bytes1(new bytes(0))))); - } - - unchecked { - bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 4, _index * 1, (_index + 1) * 1); - return (_toBool(uint8(bytes1(_blob)))); - } - } - - /** - * @notice Update an element of staticBools at `_index`. - */ - function updateStaticBools(bytes32 key, uint256 _index, bool _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 4, uint40(_index * 1), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Update an element of staticBools at `_index`. - */ - function _updateStaticBools(bytes32 key, uint256 _index, bool _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - StoreCore.spliceDynamicData(_tableId, _keyTuple, 4, uint40(_index * 1), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Get the full data. - */ - function get(bytes32 key) internal view returns (Dynamics1Data memory _table) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Get the full data. - */ - function _get(bytes32 key) internal view returns (Dynamics1Data memory _table) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Set the full data using individual values. - */ - function set( - bytes32 key, - bytes32[1] memory staticB32, - int32[2] memory staticI32, - uint128[3] memory staticU128, - address[4] memory staticAddrs, - bool[5] memory staticBools - ) internal { - bytes memory _staticData; - EncodedLengths _encodedLengths = encodeLengths(staticB32, staticI32, staticU128, staticAddrs, staticBools); - bytes memory _dynamicData = encodeDynamic(staticB32, staticI32, staticU128, staticAddrs, staticBools); - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Set the full data using individual values. - */ - function _set( - bytes32 key, - bytes32[1] memory staticB32, - int32[2] memory staticI32, - uint128[3] memory staticU128, - address[4] memory staticAddrs, - bool[5] memory staticBools - ) internal { - bytes memory _staticData; - EncodedLengths _encodedLengths = encodeLengths(staticB32, staticI32, staticU128, staticAddrs, staticBools); - bytes memory _dynamicData = encodeDynamic(staticB32, staticI32, staticU128, staticAddrs, staticBools); - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); - } - - /** - * @notice Set the full data using the data struct. - */ - function set(bytes32 key, Dynamics1Data memory _table) internal { - bytes memory _staticData; - EncodedLengths _encodedLengths = encodeLengths( - _table.staticB32, - _table.staticI32, - _table.staticU128, - _table.staticAddrs, - _table.staticBools - ); - bytes memory _dynamicData = encodeDynamic( - _table.staticB32, - _table.staticI32, - _table.staticU128, - _table.staticAddrs, - _table.staticBools - ); - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Set the full data using the data struct. - */ - function _set(bytes32 key, Dynamics1Data memory _table) internal { - bytes memory _staticData; - EncodedLengths _encodedLengths = encodeLengths( - _table.staticB32, - _table.staticI32, - _table.staticU128, - _table.staticAddrs, - _table.staticBools - ); - bytes memory _dynamicData = encodeDynamic( - _table.staticB32, - _table.staticI32, - _table.staticU128, - _table.staticAddrs, - _table.staticBools - ); - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); - } - - /** - * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. - */ - function decodeDynamic( - EncodedLengths _encodedLengths, - bytes memory _blob - ) - internal - pure - returns ( - bytes32[1] memory staticB32, - int32[2] memory staticI32, - uint128[3] memory staticU128, - address[4] memory staticAddrs, - bool[5] memory staticBools - ) - { - uint256 _start; - uint256 _end; - unchecked { - _end = _encodedLengths.atIndex(0); - } - staticB32 = toStaticArray_bytes32_1(SliceLib.getSubslice(_blob, _start, _end).decodeArray_bytes32()); - - _start = _end; - unchecked { - _end += _encodedLengths.atIndex(1); - } - staticI32 = toStaticArray_int32_2(SliceLib.getSubslice(_blob, _start, _end).decodeArray_int32()); - - _start = _end; - unchecked { - _end += _encodedLengths.atIndex(2); - } - staticU128 = toStaticArray_uint128_3(SliceLib.getSubslice(_blob, _start, _end).decodeArray_uint128()); - - _start = _end; - unchecked { - _end += _encodedLengths.atIndex(3); - } - staticAddrs = toStaticArray_address_4(SliceLib.getSubslice(_blob, _start, _end).decodeArray_address()); - - _start = _end; - unchecked { - _end += _encodedLengths.atIndex(4); - } - staticBools = toStaticArray_bool_5(SliceLib.getSubslice(_blob, _start, _end).decodeArray_bool()); - } - - /** - * @notice Decode the tightly packed blobs using this table's field layout. - * - * @param _encodedLengths Encoded lengths of dynamic fields. - * @param _dynamicData Tightly packed dynamic fields. - */ - function decode( - bytes memory, - EncodedLengths _encodedLengths, - bytes memory _dynamicData - ) internal pure returns (Dynamics1Data memory _table) { - (_table.staticB32, _table.staticI32, _table.staticU128, _table.staticAddrs, _table.staticBools) = decodeDynamic( - _encodedLengths, - _dynamicData - ); - } - - /** - * @notice Delete all data for given keys. - */ - function deleteRecord(bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.deleteRecord(_tableId, _keyTuple); - } - - /** - * @notice Delete all data for given keys. - */ - function _deleteRecord(bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); - } - - /** - * @notice Tightly pack dynamic data lengths using this table's schema. - * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). - */ - function encodeLengths( - bytes32[1] memory staticB32, - int32[2] memory staticI32, - uint128[3] memory staticU128, - address[4] memory staticAddrs, - bool[5] memory staticBools - ) internal pure returns (EncodedLengths _encodedLengths) { - // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits - unchecked { - _encodedLengths = EncodedLengthsLib.pack( - staticB32.length * 32, - staticI32.length * 4, - staticU128.length * 16, - staticAddrs.length * 20, - staticBools.length * 1 - ); - } - } - - /** - * @notice Tightly pack dynamic (variable length) data using this table's schema. - * @return The dynamic data, encoded into a sequence of bytes. - */ - function encodeDynamic( - bytes32[1] memory staticB32, - int32[2] memory staticI32, - uint128[3] memory staticU128, - address[4] memory staticAddrs, - bool[5] memory staticBools - ) internal pure returns (bytes memory) { - return - abi.encodePacked( - EncodeArray.encode(fromStaticArray_bytes32_1(staticB32)), - EncodeArray.encode(fromStaticArray_int32_2(staticI32)), - EncodeArray.encode(fromStaticArray_uint128_3(staticU128)), - EncodeArray.encode(fromStaticArray_address_4(staticAddrs)), - EncodeArray.encode(fromStaticArray_bool_5(staticBools)) - ); - } - - /** - * @notice Encode all of a record's fields. - * @return The static (fixed length) data, encoded into a sequence of bytes. - * @return The lengths of the dynamic fields (packed into a single bytes32 value). - * @return The dynamic (variable length) data, encoded into a sequence of bytes. - */ - function encode( - bytes32[1] memory staticB32, - int32[2] memory staticI32, - uint128[3] memory staticU128, - address[4] memory staticAddrs, - bool[5] memory staticBools - ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { - bytes memory _staticData; - EncodedLengths _encodedLengths = encodeLengths(staticB32, staticI32, staticU128, staticAddrs, staticBools); - bytes memory _dynamicData = encodeDynamic(staticB32, staticI32, staticU128, staticAddrs, staticBools); - - return (_staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice 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; - - return _keyTuple; - } -} - -/** - * @notice Cast a dynamic array to a static array. - * @dev In memory static arrays are just dynamic arrays without the 32 length bytes, - * so this function moves the pointer to the first element of the dynamic array. - * If the length of the dynamic array is smaller than the static length, - * the function returns an uninitialized array to avoid memory corruption. - * @param _value The dynamic array to cast. - * @return _result The static array. - */ -function toStaticArray_bytes32_1(bytes32[] memory _value) pure returns (bytes32[1] memory _result) { - if (_value.length < 1) { - // return an uninitialized array if the length is smaller than the fixed length to avoid memory corruption - return _result; - } else { - // in memory static arrays are just dynamic arrays without the 32 length bytes - // (without the length check this could lead to memory corruption) - assembly { - _result := add(_value, 0x20) - } - } -} - -/** - * @notice Cast a dynamic array to a static array. - * @dev In memory static arrays are just dynamic arrays without the 32 length bytes, - * so this function moves the pointer to the first element of the dynamic array. - * If the length of the dynamic array is smaller than the static length, - * the function returns an uninitialized array to avoid memory corruption. - * @param _value The dynamic array to cast. - * @return _result The static array. - */ -function toStaticArray_int32_2(int32[] memory _value) pure returns (int32[2] memory _result) { - if (_value.length < 2) { - // return an uninitialized array if the length is smaller than the fixed length to avoid memory corruption - return _result; - } else { - // in memory static arrays are just dynamic arrays without the 32 length bytes - // (without the length check this could lead to memory corruption) - assembly { - _result := add(_value, 0x20) - } - } -} - -/** - * @notice Cast a dynamic array to a static array. - * @dev In memory static arrays are just dynamic arrays without the 32 length bytes, - * so this function moves the pointer to the first element of the dynamic array. - * If the length of the dynamic array is smaller than the static length, - * the function returns an uninitialized array to avoid memory corruption. - * @param _value The dynamic array to cast. - * @return _result The static array. - */ -function toStaticArray_uint128_3(uint128[] memory _value) pure returns (uint128[3] memory _result) { - if (_value.length < 3) { - // return an uninitialized array if the length is smaller than the fixed length to avoid memory corruption - return _result; - } else { - // in memory static arrays are just dynamic arrays without the 32 length bytes - // (without the length check this could lead to memory corruption) - assembly { - _result := add(_value, 0x20) - } - } -} - -/** - * @notice Cast a dynamic array to a static array. - * @dev In memory static arrays are just dynamic arrays without the 32 length bytes, - * so this function moves the pointer to the first element of the dynamic array. - * If the length of the dynamic array is smaller than the static length, - * the function returns an uninitialized array to avoid memory corruption. - * @param _value The dynamic array to cast. - * @return _result The static array. - */ -function toStaticArray_address_4(address[] memory _value) pure returns (address[4] memory _result) { - if (_value.length < 4) { - // return an uninitialized array if the length is smaller than the fixed length to avoid memory corruption - return _result; - } else { - // in memory static arrays are just dynamic arrays without the 32 length bytes - // (without the length check this could lead to memory corruption) - assembly { - _result := add(_value, 0x20) - } - } -} - -/** - * @notice Cast a dynamic array to a static array. - * @dev In memory static arrays are just dynamic arrays without the 32 length bytes, - * so this function moves the pointer to the first element of the dynamic array. - * If the length of the dynamic array is smaller than the static length, - * the function returns an uninitialized array to avoid memory corruption. - * @param _value The dynamic array to cast. - * @return _result The static array. - */ -function toStaticArray_bool_5(bool[] memory _value) pure returns (bool[5] memory _result) { - if (_value.length < 5) { - // return an uninitialized array if the length is smaller than the fixed length to avoid memory corruption - return _result; - } else { - // in memory static arrays are just dynamic arrays without the 32 length bytes - // (without the length check this could lead to memory corruption) - assembly { - _result := add(_value, 0x20) - } - } -} - -/** - * @notice Copy a static array to a dynamic array. - * @dev Static arrays don't have a length prefix, so this function copies the memory from the static array to a new dynamic array. - * @param _value The static array to copy. - * @return _result The dynamic array. - */ -function fromStaticArray_bytes32_1(bytes32[1] memory _value) pure returns (bytes32[] memory _result) { - _result = new bytes32[](1); - uint256 fromPointer; - uint256 toPointer; - assembly { - fromPointer := _value - toPointer := add(_result, 0x20) - } - Memory.copy(fromPointer, toPointer, 32); -} - -/** - * @notice Copy a static array to a dynamic array. - * @dev Static arrays don't have a length prefix, so this function copies the memory from the static array to a new dynamic array. - * @param _value The static array to copy. - * @return _result The dynamic array. - */ -function fromStaticArray_int32_2(int32[2] memory _value) pure returns (int32[] memory _result) { - _result = new int32[](2); - uint256 fromPointer; - uint256 toPointer; - assembly { - fromPointer := _value - toPointer := add(_result, 0x20) - } - Memory.copy(fromPointer, toPointer, 64); -} - -/** - * @notice Copy a static array to a dynamic array. - * @dev Static arrays don't have a length prefix, so this function copies the memory from the static array to a new dynamic array. - * @param _value The static array to copy. - * @return _result The dynamic array. - */ -function fromStaticArray_uint128_3(uint128[3] memory _value) pure returns (uint128[] memory _result) { - _result = new uint128[](3); - uint256 fromPointer; - uint256 toPointer; - assembly { - fromPointer := _value - toPointer := add(_result, 0x20) - } - Memory.copy(fromPointer, toPointer, 96); -} - -/** - * @notice Copy a static array to a dynamic array. - * @dev Static arrays don't have a length prefix, so this function copies the memory from the static array to a new dynamic array. - * @param _value The static array to copy. - * @return _result The dynamic array. - */ -function fromStaticArray_address_4(address[4] memory _value) pure returns (address[] memory _result) { - _result = new address[](4); - uint256 fromPointer; - uint256 toPointer; - assembly { - fromPointer := _value - toPointer := add(_result, 0x20) - } - Memory.copy(fromPointer, toPointer, 128); -} - -/** - * @notice Copy a static array to a dynamic array. - * @dev Static arrays don't have a length prefix, so this function copies the memory from the static array to a new dynamic array. - * @param _value The static array to copy. - * @return _result The dynamic array. - */ -function fromStaticArray_bool_5(bool[5] memory _value) pure returns (bool[] memory _result) { - _result = new bool[](5); - uint256 fromPointer; - uint256 toPointer; - assembly { - fromPointer := _value - toPointer := add(_result, 0x20) - } - Memory.copy(fromPointer, toPointer, 160); -} - -/** - * @notice Cast a value to a bool. - * @dev Boolean values are encoded as uint8 (1 = true, 0 = false), but Solidity doesn't allow casting between uint8 and bool. - * @param value The uint8 value to convert. - * @return result The boolean value. - */ -function _toBool(uint8 value) pure returns (bool result) { - assembly { - result := value - } -} diff --git a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol b/packages/cli/contracts/src/codegen/tables/Dynamics2.sol deleted file mode 100644 index e2480a74fe..0000000000 --- a/packages/cli/contracts/src/codegen/tables/Dynamics2.sol +++ /dev/null @@ -1,754 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -/* Autogenerated file. Do not edit manually. */ - -// 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 { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema } from "@latticexyz/store/src/Schema.sol"; -import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; -import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; - -struct Dynamics2Data { - uint64[] u64; - string str; - bytes b; -} - -library Dynamics2 { - // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Dynamics2", typeId: RESOURCE_TABLE });` - ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000044796e616d6963733200000000000000); - - FieldLayout constant _fieldLayout = - FieldLayout.wrap(0x0000000300000000000000000000000000000000000000000000000000000000); - - // Hex-encoded key schema of (bytes32) - Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); - // Hex-encoded value schema of (uint64[], string, bytes) - Schema constant _valueSchema = Schema.wrap(0x0000000369c5c400000000000000000000000000000000000000000000000000); - - /** - * @notice Get the table's key field names. - * @return keyNames An array of strings with the names of key fields. - */ - function getKeyNames() internal pure returns (string[] memory keyNames) { - keyNames = new string[](1); - keyNames[0] = "key"; - } - - /** - * @notice Get the table's value field names. - * @return fieldNames An array of strings with the names of value fields. - */ - function getFieldNames() internal pure returns (string[] memory fieldNames) { - fieldNames = new string[](3); - fieldNames[0] = "u64"; - fieldNames[1] = "str"; - fieldNames[2] = "b"; - } - - /** - * @notice Register the table with its config. - */ - function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); - } - - /** - * @notice Register the table with its config. - */ - function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); - } - - /** - * @notice Get u64. - */ - function getU64(bytes32 key) internal view returns (uint64[] memory u64) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); - return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint64()); - } - - /** - * @notice Get u64. - */ - function _getU64(bytes32 key) internal view returns (uint64[] memory u64) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0); - return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint64()); - } - - /** - * @notice Set u64. - */ - function setU64(bytes32 key, uint64[] memory u64) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((u64))); - } - - /** - * @notice Set u64. - */ - function _setU64(bytes32 key, uint64[] memory u64) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((u64))); - } - - /** - * @notice Get the length of u64. - */ - function lengthU64(bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 8; - } - } - - /** - * @notice Get the length of u64. - */ - function _lengthU64(bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 0); - unchecked { - return _byteLength / 8; - } - } - - /** - * @notice Get an item of u64. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemU64(bytes32 key, uint256 _index) internal view returns (uint64) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 8, (_index + 1) * 8); - return (uint64(bytes8(_blob))); - } - } - - /** - * @notice Get an item of u64. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function _getItemU64(bytes32 key, uint256 _index) internal view returns (uint64) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 8, (_index + 1) * 8); - return (uint64(bytes8(_blob))); - } - } - - /** - * @notice Push an element to u64. - */ - function pushU64(bytes32 key, uint64 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); - } - - /** - * @notice Push an element to u64. - */ - function _pushU64(bytes32 key, uint64 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); - } - - /** - * @notice Pop an element from u64. - */ - function popU64(bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.popFromDynamicField(_tableId, _keyTuple, 0, 8); - } - - /** - * @notice Pop an element from u64. - */ - function _popU64(bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 8); - } - - /** - * @notice Update an element of u64 at `_index`. - */ - function updateU64(bytes32 key, uint256 _index, uint64 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 8), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Update an element of u64 at `_index`. - */ - function _updateU64(bytes32 key, uint256 _index, uint64 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - StoreCore.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 8), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Get str. - */ - function getStr(bytes32 key) internal view returns (string memory str) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 1); - return (string(_blob)); - } - - /** - * @notice Get str. - */ - function _getStr(bytes32 key) internal view returns (string memory str) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 1); - return (string(_blob)); - } - - /** - * @notice Set str. - */ - function setStr(bytes32 key, string memory str) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.setDynamicField(_tableId, _keyTuple, 1, bytes((str))); - } - - /** - * @notice Set str. - */ - function _setStr(bytes32 key, string memory str) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.setDynamicField(_tableId, _keyTuple, 1, bytes((str))); - } - - /** - * @notice Get the length of str. - */ - function lengthStr(bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 1); - unchecked { - return _byteLength / 1; - } - } - - /** - * @notice Get the length of str. - */ - function _lengthStr(bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 1); - unchecked { - return _byteLength / 1; - } - } - - /** - * @notice Get an item of str. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemStr(bytes32 key, uint256 _index) internal view returns (string memory) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 1, (_index + 1) * 1); - return (string(_blob)); - } - } - - /** - * @notice Get an item of str. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function _getItemStr(bytes32 key, uint256 _index) internal view returns (string memory) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 1, (_index + 1) * 1); - return (string(_blob)); - } - } - - /** - * @notice Push a slice to str. - */ - function pushStr(bytes32 key, string memory _slice) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.pushToDynamicField(_tableId, _keyTuple, 1, bytes((_slice))); - } - - /** - * @notice Push a slice to str. - */ - function _pushStr(bytes32 key, string memory _slice) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.pushToDynamicField(_tableId, _keyTuple, 1, bytes((_slice))); - } - - /** - * @notice Pop a slice from str. - */ - function popStr(bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.popFromDynamicField(_tableId, _keyTuple, 1, 1); - } - - /** - * @notice Pop a slice from str. - */ - function _popStr(bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.popFromDynamicField(_tableId, _keyTuple, 1, 1); - } - - /** - * @notice Update a slice of str at `_index`. - */ - function updateStr(bytes32 key, uint256 _index, string memory _slice) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = bytes((_slice)); - StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 1), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Update a slice of str at `_index`. - */ - function _updateStr(bytes32 key, uint256 _index, string memory _slice) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = bytes((_slice)); - StoreCore.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 1), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Get b. - */ - function getB(bytes32 key) internal view returns (bytes memory b) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 2); - return (bytes(_blob)); - } - - /** - * @notice Get b. - */ - function _getB(bytes32 key) internal view returns (bytes memory b) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 2); - return (bytes(_blob)); - } - - /** - * @notice Set b. - */ - function setB(bytes32 key, bytes memory b) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.setDynamicField(_tableId, _keyTuple, 2, bytes((b))); - } - - /** - * @notice Set b. - */ - function _setB(bytes32 key, bytes memory b) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.setDynamicField(_tableId, _keyTuple, 2, bytes((b))); - } - - /** - * @notice Get the length of b. - */ - function lengthB(bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 2); - unchecked { - return _byteLength / 1; - } - } - - /** - * @notice Get the length of b. - */ - function _lengthB(bytes32 key) internal view returns (uint256) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 2); - unchecked { - return _byteLength / 1; - } - } - - /** - * @notice Get an item of b. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemB(bytes32 key, uint256 _index) internal view returns (bytes memory) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 2, _index * 1, (_index + 1) * 1); - return (bytes(_blob)); - } - } - - /** - * @notice Get an item of b. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function _getItemB(bytes32 key, uint256 _index) internal view returns (bytes memory) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 2, _index * 1, (_index + 1) * 1); - return (bytes(_blob)); - } - } - - /** - * @notice Push a slice to b. - */ - function pushB(bytes32 key, bytes memory _slice) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.pushToDynamicField(_tableId, _keyTuple, 2, bytes((_slice))); - } - - /** - * @notice Push a slice to b. - */ - function _pushB(bytes32 key, bytes memory _slice) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.pushToDynamicField(_tableId, _keyTuple, 2, bytes((_slice))); - } - - /** - * @notice Pop a slice from b. - */ - function popB(bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.popFromDynamicField(_tableId, _keyTuple, 2, 1); - } - - /** - * @notice Pop a slice from b. - */ - function _popB(bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.popFromDynamicField(_tableId, _keyTuple, 2, 1); - } - - /** - * @notice Update a slice of b at `_index`. - */ - function updateB(bytes32 key, uint256 _index, bytes memory _slice) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = bytes((_slice)); - StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 2, uint40(_index * 1), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Update a slice of b at `_index`. - */ - function _updateB(bytes32 key, uint256 _index, bytes memory _slice) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - unchecked { - bytes memory _encoded = bytes((_slice)); - StoreCore.spliceDynamicData(_tableId, _keyTuple, 2, uint40(_index * 1), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Get the full data. - */ - function get(bytes32 key) internal view returns (Dynamics2Data memory _table) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Get the full data. - */ - function _get(bytes32 key) internal view returns (Dynamics2Data memory _table) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Set the full data using individual values. - */ - function set(bytes32 key, uint64[] memory u64, string memory str, bytes memory b) internal { - bytes memory _staticData; - EncodedLengths _encodedLengths = encodeLengths(u64, str, b); - bytes memory _dynamicData = encodeDynamic(u64, str, b); - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Set the full data using individual values. - */ - function _set(bytes32 key, uint64[] memory u64, string memory str, bytes memory b) internal { - bytes memory _staticData; - EncodedLengths _encodedLengths = encodeLengths(u64, str, b); - bytes memory _dynamicData = encodeDynamic(u64, str, b); - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); - } - - /** - * @notice Set the full data using the data struct. - */ - function set(bytes32 key, Dynamics2Data memory _table) internal { - bytes memory _staticData; - EncodedLengths _encodedLengths = encodeLengths(_table.u64, _table.str, _table.b); - bytes memory _dynamicData = encodeDynamic(_table.u64, _table.str, _table.b); - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Set the full data using the data struct. - */ - function _set(bytes32 key, Dynamics2Data memory _table) internal { - bytes memory _staticData; - EncodedLengths _encodedLengths = encodeLengths(_table.u64, _table.str, _table.b); - bytes memory _dynamicData = encodeDynamic(_table.u64, _table.str, _table.b); - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); - } - - /** - * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. - */ - function decodeDynamic( - EncodedLengths _encodedLengths, - bytes memory _blob - ) internal pure returns (uint64[] memory u64, string memory str, bytes memory b) { - uint256 _start; - uint256 _end; - unchecked { - _end = _encodedLengths.atIndex(0); - } - u64 = (SliceLib.getSubslice(_blob, _start, _end).decodeArray_uint64()); - - _start = _end; - unchecked { - _end += _encodedLengths.atIndex(1); - } - str = (string(SliceLib.getSubslice(_blob, _start, _end).toBytes())); - - _start = _end; - unchecked { - _end += _encodedLengths.atIndex(2); - } - b = (bytes(SliceLib.getSubslice(_blob, _start, _end).toBytes())); - } - - /** - * @notice Decode the tightly packed blobs using this table's field layout. - * - * @param _encodedLengths Encoded lengths of dynamic fields. - * @param _dynamicData Tightly packed dynamic fields. - */ - function decode( - bytes memory, - EncodedLengths _encodedLengths, - bytes memory _dynamicData - ) internal pure returns (Dynamics2Data memory _table) { - (_table.u64, _table.str, _table.b) = decodeDynamic(_encodedLengths, _dynamicData); - } - - /** - * @notice Delete all data for given keys. - */ - function deleteRecord(bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.deleteRecord(_tableId, _keyTuple); - } - - /** - * @notice Delete all data for given keys. - */ - function _deleteRecord(bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); - } - - /** - * @notice Tightly pack dynamic data lengths using this table's schema. - * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). - */ - function encodeLengths( - uint64[] memory u64, - string memory str, - bytes memory b - ) internal pure returns (EncodedLengths _encodedLengths) { - // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits - unchecked { - _encodedLengths = EncodedLengthsLib.pack(u64.length * 8, bytes(str).length, bytes(b).length); - } - } - - /** - * @notice Tightly pack dynamic (variable length) data using this table's schema. - * @return The dynamic data, encoded into a sequence of bytes. - */ - function encodeDynamic(uint64[] memory u64, string memory str, bytes memory b) internal pure returns (bytes memory) { - return abi.encodePacked(EncodeArray.encode((u64)), bytes((str)), bytes((b))); - } - - /** - * @notice Encode all of a record's fields. - * @return The static (fixed length) data, encoded into a sequence of bytes. - * @return The lengths of the dynamic fields (packed into a single bytes32 value). - * @return The dynamic (variable length) data, encoded into a sequence of bytes. - */ - function encode( - uint64[] memory u64, - string memory str, - bytes memory b - ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { - bytes memory _staticData; - EncodedLengths _encodedLengths = encodeLengths(u64, str, b); - bytes memory _dynamicData = encodeDynamic(u64, str, b); - - return (_staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice 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; - - return _keyTuple; - } -} diff --git a/packages/cli/contracts/src/codegen/tables/Offchain.sol b/packages/cli/contracts/src/codegen/tables/Offchain.sol deleted file mode 100644 index cd3f75868e..0000000000 --- a/packages/cli/contracts/src/codegen/tables/Offchain.sol +++ /dev/null @@ -1,182 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -/* Autogenerated file. Do not edit manually. */ - -// 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 { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema } from "@latticexyz/store/src/Schema.sol"; -import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; -import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; - -library Offchain { - // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Offchain", typeId: RESOURCE_OFFCHAIN_TABLE });` - ResourceId constant _tableId = ResourceId.wrap(0x6f7400000000000000000000000000004f6666636861696e0000000000000000); - - FieldLayout constant _fieldLayout = - FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); - - // Hex-encoded key schema of (bytes32) - Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); - // Hex-encoded value schema of (uint256) - Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000); - - /** - * @notice Get the table's key field names. - * @return keyNames An array of strings with the names of key fields. - */ - function getKeyNames() internal pure returns (string[] memory keyNames) { - keyNames = new string[](1); - keyNames[0] = "key"; - } - - /** - * @notice Get the table's value field names. - * @return fieldNames An array of strings with the names of value fields. - */ - function getFieldNames() internal pure returns (string[] memory fieldNames) { - fieldNames = new string[](1); - fieldNames[0] = "value"; - } - - /** - * @notice Register the table with its config. - */ - function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); - } - - /** - * @notice Register the table with its config. - */ - function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); - } - - /** - * @notice Set value. - */ - function setValue(bytes32 key, uint256 value) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); - } - - /** - * @notice Set value. - */ - function _setValue(bytes32 key, uint256 value) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); - } - - /** - * @notice Set the full data using individual values. - */ - function set(bytes32 key, uint256 value) internal { - bytes memory _staticData = encodeStatic(value); - - EncodedLengths _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Set the full data using individual values. - */ - function _set(bytes32 key, uint256 value) internal { - bytes memory _staticData = encodeStatic(value); - - EncodedLengths _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); - } - - /** - * @notice Decode the tightly packed blob of static data using this table's field layout. - */ - function decodeStatic(bytes memory _blob) internal pure returns (uint256 value) { - value = (uint256(Bytes.getBytes32(_blob, 0))); - } - - /** - * @notice Decode the tightly packed blobs using this table's field layout. - * @param _staticData Tightly packed static fields. - * - * - */ - function decode(bytes memory _staticData, EncodedLengths, bytes memory) internal pure returns (uint256 value) { - (value) = decodeStatic(_staticData); - } - - /** - * @notice Delete all data for given keys. - */ - function deleteRecord(bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreSwitch.deleteRecord(_tableId, _keyTuple); - } - - /** - * @notice Delete all data for given keys. - */ - function _deleteRecord(bytes32 key) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = key; - - StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); - } - - /** - * @notice Tightly pack static (fixed length) data using this table's schema. - * @return The static data, encoded into a sequence of bytes. - */ - function encodeStatic(uint256 value) internal pure returns (bytes memory) { - return abi.encodePacked(value); - } - - /** - * @notice Encode all of a record's fields. - * @return The static (fixed length) data, encoded into a sequence of bytes. - * @return The lengths of the dynamic fields (packed into a single bytes32 value). - * @return The dynamic (variable length) data, encoded into a sequence of bytes. - */ - function encode(uint256 value) internal pure returns (bytes memory, EncodedLengths, bytes memory) { - bytes memory _staticData = encodeStatic(value); - - EncodedLengths _encodedLengths; - bytes memory _dynamicData; - - return (_staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice 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; - - return _keyTuple; - } -} diff --git a/packages/cli/contracts/src/codegen/tables/Singleton.sol b/packages/cli/contracts/src/codegen/tables/Singleton.sol deleted file mode 100644 index 20d508cdf6..0000000000 --- a/packages/cli/contracts/src/codegen/tables/Singleton.sol +++ /dev/null @@ -1,694 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -/* Autogenerated file. Do not edit manually. */ - -// 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 { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema } from "@latticexyz/store/src/Schema.sol"; -import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; -import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; - -library Singleton { - // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Singleton", typeId: RESOURCE_TABLE });` - ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000053696e676c65746f6e00000000000000); - - FieldLayout constant _fieldLayout = - FieldLayout.wrap(0x0020010320000000000000000000000000000000000000000000000000000000); - - // Hex-encoded key schema of () - Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000); - // Hex-encoded value schema of (int256, uint32[], uint32[], uint32[]) - Schema constant _valueSchema = Schema.wrap(0x002001033f656565000000000000000000000000000000000000000000000000); - - /** - * @notice Get the table's key field names. - * @return keyNames An array of strings with the names of key fields. - */ - function getKeyNames() internal pure returns (string[] memory keyNames) { - keyNames = new string[](0); - } - - /** - * @notice Get the table's value field names. - * @return fieldNames An array of strings with the names of value fields. - */ - function getFieldNames() internal pure returns (string[] memory fieldNames) { - fieldNames = new string[](4); - fieldNames[0] = "v1"; - fieldNames[1] = "v2"; - fieldNames[2] = "v3"; - fieldNames[3] = "v4"; - } - - /** - * @notice Register the table with its config. - */ - function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); - } - - /** - * @notice Register the table with its config. - */ - function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); - } - - /** - * @notice Get v1. - */ - function getV1() internal view returns (int256 v1) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (int256(uint256(bytes32(_blob)))); - } - - /** - * @notice Get v1. - */ - function _getV1() internal view returns (int256 v1) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (int256(uint256(bytes32(_blob)))); - } - - /** - * @notice Set v1. - */ - function setV1(int256 v1) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((v1)), _fieldLayout); - } - - /** - * @notice Set v1. - */ - function _setV1(int256 v1) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((v1)), _fieldLayout); - } - - /** - * @notice Get v2. - */ - function getV2() internal view returns (uint32[2] memory v2) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); - return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); - } - - /** - * @notice Get v2. - */ - function _getV2() internal view returns (uint32[2] memory v2) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0); - return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); - } - - /** - * @notice Set v2. - */ - function setV2(uint32[2] memory v2) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - StoreSwitch.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode(fromStaticArray_uint32_2(v2))); - } - - /** - * @notice Set v2. - */ - function _setV2(uint32[2] memory v2) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode(fromStaticArray_uint32_2(v2))); - } - - // The length of v2 - uint256 constant lengthV2 = 2; - - /** - * @notice Get an item of v2. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemV2(uint256 _index) internal view returns (uint32) { - bytes32[] memory _keyTuple = new bytes32[](0); - - uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 0); - uint256 dynamicLength = _byteLength / 4; - uint256 staticLength = 2; - - if (_index < staticLength && _index >= dynamicLength) { - return (uint32(bytes4(new bytes(0)))); - } - - unchecked { - bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 4, (_index + 1) * 4); - return (uint32(bytes4(_blob))); - } - } - - /** - * @notice Get an item of v2. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function _getItemV2(uint256 _index) internal view returns (uint32) { - bytes32[] memory _keyTuple = new bytes32[](0); - - uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 0); - uint256 dynamicLength = _byteLength / 4; - uint256 staticLength = 2; - - if (_index < staticLength && _index >= dynamicLength) { - return (uint32(bytes4(new bytes(0)))); - } - - unchecked { - bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 4, (_index + 1) * 4); - return (uint32(bytes4(_blob))); - } - } - - /** - * @notice Update an element of v2 at `_index`. - */ - function updateV2(uint256 _index, uint32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 4), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Update an element of v2 at `_index`. - */ - function _updateV2(uint256 _index, uint32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - StoreCore.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 4), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Get v3. - */ - function getV3() internal view returns (uint32[2] memory v3) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 1); - return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); - } - - /** - * @notice Get v3. - */ - function _getV3() internal view returns (uint32[2] memory v3) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 1); - return toStaticArray_uint32_2(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); - } - - /** - * @notice Set v3. - */ - function setV3(uint32[2] memory v3) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - StoreSwitch.setDynamicField(_tableId, _keyTuple, 1, EncodeArray.encode(fromStaticArray_uint32_2(v3))); - } - - /** - * @notice Set v3. - */ - function _setV3(uint32[2] memory v3) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - StoreCore.setDynamicField(_tableId, _keyTuple, 1, EncodeArray.encode(fromStaticArray_uint32_2(v3))); - } - - // The length of v3 - uint256 constant lengthV3 = 2; - - /** - * @notice Get an item of v3. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemV3(uint256 _index) internal view returns (uint32) { - bytes32[] memory _keyTuple = new bytes32[](0); - - uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 1); - uint256 dynamicLength = _byteLength / 4; - uint256 staticLength = 2; - - if (_index < staticLength && _index >= dynamicLength) { - return (uint32(bytes4(new bytes(0)))); - } - - unchecked { - bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 4, (_index + 1) * 4); - return (uint32(bytes4(_blob))); - } - } - - /** - * @notice Get an item of v3. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function _getItemV3(uint256 _index) internal view returns (uint32) { - bytes32[] memory _keyTuple = new bytes32[](0); - - uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 1); - uint256 dynamicLength = _byteLength / 4; - uint256 staticLength = 2; - - if (_index < staticLength && _index >= dynamicLength) { - return (uint32(bytes4(new bytes(0)))); - } - - unchecked { - bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 4, (_index + 1) * 4); - return (uint32(bytes4(_blob))); - } - } - - /** - * @notice Update an element of v3 at `_index`. - */ - function updateV3(uint256 _index, uint32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 4), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Update an element of v3 at `_index`. - */ - function _updateV3(uint256 _index, uint32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - StoreCore.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 4), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Get v4. - */ - function getV4() internal view returns (uint32[1] memory v4) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 2); - return toStaticArray_uint32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); - } - - /** - * @notice Get v4. - */ - function _getV4() internal view returns (uint32[1] memory v4) { - bytes32[] memory _keyTuple = new bytes32[](0); - - bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 2); - return toStaticArray_uint32_1(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); - } - - /** - * @notice Set v4. - */ - function setV4(uint32[1] memory v4) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - StoreSwitch.setDynamicField(_tableId, _keyTuple, 2, EncodeArray.encode(fromStaticArray_uint32_1(v4))); - } - - /** - * @notice Set v4. - */ - function _setV4(uint32[1] memory v4) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - StoreCore.setDynamicField(_tableId, _keyTuple, 2, EncodeArray.encode(fromStaticArray_uint32_1(v4))); - } - - // The length of v4 - uint256 constant lengthV4 = 1; - - /** - * @notice Get an item of v4. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function getItemV4(uint256 _index) internal view returns (uint32) { - bytes32[] memory _keyTuple = new bytes32[](0); - - uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 2); - uint256 dynamicLength = _byteLength / 4; - uint256 staticLength = 1; - - if (_index < staticLength && _index >= dynamicLength) { - return (uint32(bytes4(new bytes(0)))); - } - - unchecked { - bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 2, _index * 4, (_index + 1) * 4); - return (uint32(bytes4(_blob))); - } - } - - /** - * @notice Get an item of v4. - * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. - */ - function _getItemV4(uint256 _index) internal view returns (uint32) { - bytes32[] memory _keyTuple = new bytes32[](0); - - uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 2); - uint256 dynamicLength = _byteLength / 4; - uint256 staticLength = 1; - - if (_index < staticLength && _index >= dynamicLength) { - return (uint32(bytes4(new bytes(0)))); - } - - unchecked { - bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 2, _index * 4, (_index + 1) * 4); - return (uint32(bytes4(_blob))); - } - } - - /** - * @notice Update an element of v4 at `_index`. - */ - function updateV4(uint256 _index, uint32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 2, uint40(_index * 4), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Update an element of v4 at `_index`. - */ - function _updateV4(uint256 _index, uint32 _element) internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - unchecked { - bytes memory _encoded = abi.encodePacked((_element)); - StoreCore.spliceDynamicData(_tableId, _keyTuple, 2, uint40(_index * 4), uint40(_encoded.length), _encoded); - } - } - - /** - * @notice Get the full data. - */ - function get() internal view returns (int256 v1, uint32[2] memory v2, uint32[2] memory v3, uint32[1] memory v4) { - bytes32[] memory _keyTuple = new bytes32[](0); - - (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Get the full data. - */ - function _get() internal view returns (int256 v1, uint32[2] memory v2, uint32[2] memory v3, uint32[1] memory v4) { - bytes32[] memory _keyTuple = new bytes32[](0); - - (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Set the full data using individual values. - */ - function set(int256 v1, uint32[2] memory v2, uint32[2] memory v3, uint32[1] memory v4) internal { - bytes memory _staticData = encodeStatic(v1); - - EncodedLengths _encodedLengths = encodeLengths(v2, v3, v4); - bytes memory _dynamicData = encodeDynamic(v2, v3, v4); - - bytes32[] memory _keyTuple = new bytes32[](0); - - StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Set the full data using individual values. - */ - function _set(int256 v1, uint32[2] memory v2, uint32[2] memory v3, uint32[1] memory v4) internal { - bytes memory _staticData = encodeStatic(v1); - - EncodedLengths _encodedLengths = encodeLengths(v2, v3, v4); - bytes memory _dynamicData = encodeDynamic(v2, v3, v4); - - bytes32[] memory _keyTuple = new bytes32[](0); - - StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); - } - - /** - * @notice Decode the tightly packed blob of static data using this table's field layout. - */ - function decodeStatic(bytes memory _blob) internal pure returns (int256 v1) { - v1 = (int256(uint256(Bytes.getBytes32(_blob, 0)))); - } - - /** - * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. - */ - function decodeDynamic( - EncodedLengths _encodedLengths, - bytes memory _blob - ) internal pure returns (uint32[2] memory v2, uint32[2] memory v3, uint32[1] memory v4) { - uint256 _start; - uint256 _end; - unchecked { - _end = _encodedLengths.atIndex(0); - } - v2 = toStaticArray_uint32_2(SliceLib.getSubslice(_blob, _start, _end).decodeArray_uint32()); - - _start = _end; - unchecked { - _end += _encodedLengths.atIndex(1); - } - v3 = toStaticArray_uint32_2(SliceLib.getSubslice(_blob, _start, _end).decodeArray_uint32()); - - _start = _end; - unchecked { - _end += _encodedLengths.atIndex(2); - } - v4 = toStaticArray_uint32_1(SliceLib.getSubslice(_blob, _start, _end).decodeArray_uint32()); - } - - /** - * @notice Decode the tightly packed blobs using this table's field layout. - * @param _staticData Tightly packed static fields. - * @param _encodedLengths Encoded lengths of dynamic fields. - * @param _dynamicData Tightly packed dynamic fields. - */ - function decode( - bytes memory _staticData, - EncodedLengths _encodedLengths, - bytes memory _dynamicData - ) internal pure returns (int256 v1, uint32[2] memory v2, uint32[2] memory v3, uint32[1] memory v4) { - (v1) = decodeStatic(_staticData); - - (v2, v3, v4) = decodeDynamic(_encodedLengths, _dynamicData); - } - - /** - * @notice Delete all data for given keys. - */ - function deleteRecord() internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - StoreSwitch.deleteRecord(_tableId, _keyTuple); - } - - /** - * @notice Delete all data for given keys. - */ - function _deleteRecord() internal { - bytes32[] memory _keyTuple = new bytes32[](0); - - StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); - } - - /** - * @notice Tightly pack static (fixed length) data using this table's schema. - * @return The static data, encoded into a sequence of bytes. - */ - function encodeStatic(int256 v1) internal pure returns (bytes memory) { - return abi.encodePacked(v1); - } - - /** - * @notice Tightly pack dynamic data lengths using this table's schema. - * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). - */ - function encodeLengths( - uint32[2] memory v2, - uint32[2] memory v3, - uint32[1] memory v4 - ) internal pure returns (EncodedLengths _encodedLengths) { - // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits - unchecked { - _encodedLengths = EncodedLengthsLib.pack(v2.length * 4, v3.length * 4, v4.length * 4); - } - } - - /** - * @notice Tightly pack dynamic (variable length) data using this table's schema. - * @return The dynamic data, encoded into a sequence of bytes. - */ - function encodeDynamic( - uint32[2] memory v2, - uint32[2] memory v3, - uint32[1] memory v4 - ) internal pure returns (bytes memory) { - return - abi.encodePacked( - EncodeArray.encode(fromStaticArray_uint32_2(v2)), - EncodeArray.encode(fromStaticArray_uint32_2(v3)), - EncodeArray.encode(fromStaticArray_uint32_1(v4)) - ); - } - - /** - * @notice Encode all of a record's fields. - * @return The static (fixed length) data, encoded into a sequence of bytes. - * @return The lengths of the dynamic fields (packed into a single bytes32 value). - * @return The dynamic (variable length) data, encoded into a sequence of bytes. - */ - function encode( - int256 v1, - uint32[2] memory v2, - uint32[2] memory v3, - uint32[1] memory v4 - ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { - bytes memory _staticData = encodeStatic(v1); - - EncodedLengths _encodedLengths = encodeLengths(v2, v3, v4); - bytes memory _dynamicData = encodeDynamic(v2, v3, v4); - - return (_staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice 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); - - return _keyTuple; - } -} - -/** - * @notice Cast a dynamic array to a static array. - * @dev In memory static arrays are just dynamic arrays without the 32 length bytes, - * so this function moves the pointer to the first element of the dynamic array. - * If the length of the dynamic array is smaller than the static length, - * the function returns an uninitialized array to avoid memory corruption. - * @param _value The dynamic array to cast. - * @return _result The static array. - */ -function toStaticArray_uint32_2(uint32[] memory _value) pure returns (uint32[2] memory _result) { - if (_value.length < 2) { - // return an uninitialized array if the length is smaller than the fixed length to avoid memory corruption - return _result; - } else { - // in memory static arrays are just dynamic arrays without the 32 length bytes - // (without the length check this could lead to memory corruption) - assembly { - _result := add(_value, 0x20) - } - } -} - -/** - * @notice Cast a dynamic array to a static array. - * @dev In memory static arrays are just dynamic arrays without the 32 length bytes, - * so this function moves the pointer to the first element of the dynamic array. - * If the length of the dynamic array is smaller than the static length, - * the function returns an uninitialized array to avoid memory corruption. - * @param _value The dynamic array to cast. - * @return _result The static array. - */ -function toStaticArray_uint32_1(uint32[] memory _value) pure returns (uint32[1] memory _result) { - if (_value.length < 1) { - // return an uninitialized array if the length is smaller than the fixed length to avoid memory corruption - return _result; - } else { - // in memory static arrays are just dynamic arrays without the 32 length bytes - // (without the length check this could lead to memory corruption) - assembly { - _result := add(_value, 0x20) - } - } -} - -/** - * @notice Copy a static array to a dynamic array. - * @dev Static arrays don't have a length prefix, so this function copies the memory from the static array to a new dynamic array. - * @param _value The static array to copy. - * @return _result The dynamic array. - */ -function fromStaticArray_uint32_2(uint32[2] memory _value) pure returns (uint32[] memory _result) { - _result = new uint32[](2); - uint256 fromPointer; - uint256 toPointer; - assembly { - fromPointer := _value - toPointer := add(_result, 0x20) - } - Memory.copy(fromPointer, toPointer, 64); -} - -/** - * @notice Copy a static array to a dynamic array. - * @dev Static arrays don't have a length prefix, so this function copies the memory from the static array to a new dynamic array. - * @param _value The static array to copy. - * @return _result The dynamic array. - */ -function fromStaticArray_uint32_1(uint32[1] memory _value) pure returns (uint32[] memory _result) { - _result = new uint32[](1); - uint256 fromPointer; - uint256 toPointer; - assembly { - fromPointer := _value - toPointer := add(_result, 0x20) - } - Memory.copy(fromPointer, toPointer, 32); -} diff --git a/packages/cli/contracts/src/codegen/tables/Statics.sol b/packages/cli/contracts/src/codegen/tables/Statics.sol deleted file mode 100644 index 83b959c491..0000000000 --- a/packages/cli/contracts/src/codegen/tables/Statics.sol +++ /dev/null @@ -1,760 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -/* Autogenerated file. Do not edit manually. */ - -// 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 { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema } from "@latticexyz/store/src/Schema.sol"; -import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; -import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; - -// Import user types -import { Enum2, Enum1 } from "./../common.sol"; - -struct StaticsData { - uint256 v1; - int32 v2; - bytes16 v3; - address v4; - bool v5; - Enum1 v6; -} - -library Statics { - // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Statics", typeId: RESOURCE_TABLE });` - ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000053746174696373000000000000000000); - - FieldLayout constant _fieldLayout = - FieldLayout.wrap(0x004a060020041014010100000000000000000000000000000000000000000000); - - // Hex-encoded key schema of (uint256, int32, bytes16, address, bool, uint8) - Schema constant _keySchema = Schema.wrap(0x004a06001f234f61600000000000000000000000000000000000000000000000); - // Hex-encoded value schema of (uint256, int32, bytes16, address, bool, uint8) - Schema constant _valueSchema = Schema.wrap(0x004a06001f234f61600000000000000000000000000000000000000000000000); - - /** - * @notice Get the table's key field names. - * @return keyNames An array of strings with the names of key fields. - */ - function getKeyNames() internal pure returns (string[] memory keyNames) { - keyNames = new string[](6); - keyNames[0] = "k1"; - keyNames[1] = "k2"; - keyNames[2] = "k3"; - keyNames[3] = "k4"; - keyNames[4] = "k5"; - keyNames[5] = "k6"; - } - - /** - * @notice Get the table's value field names. - * @return fieldNames An array of strings with the names of value fields. - */ - function getFieldNames() internal pure returns (string[] memory fieldNames) { - fieldNames = new string[](6); - fieldNames[0] = "v1"; - fieldNames[1] = "v2"; - fieldNames[2] = "v3"; - fieldNames[3] = "v4"; - fieldNames[4] = "v5"; - fieldNames[5] = "v6"; - } - - /** - * @notice Register the table with its config. - */ - function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); - } - - /** - * @notice Register the table with its config. - */ - function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); - } - - /** - * @notice Get v1. - */ - function getV1(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6) internal view returns (uint256 v1) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(bytes32(_blob))); - } - - /** - * @notice Get v1. - */ - function _getV1(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6) internal view returns (uint256 v1) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(bytes32(_blob))); - } - - /** - * @notice Set v1. - */ - function setV1(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, uint256 v1) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((v1)), _fieldLayout); - } - - /** - * @notice Set v1. - */ - function _setV1(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, uint256 v1) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((v1)), _fieldLayout); - } - - /** - * @notice Get v2. - */ - function getV2(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6) internal view returns (int32 v2) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); - return (int32(uint32(bytes4(_blob)))); - } - - /** - * @notice Get v2. - */ - function _getV2(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6) internal view returns (int32 v2) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); - return (int32(uint32(bytes4(_blob)))); - } - - /** - * @notice Set v2. - */ - function setV2(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, int32 v2) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - StoreSwitch.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((v2)), _fieldLayout); - } - - /** - * @notice Set v2. - */ - function _setV2(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, int32 v2) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((v2)), _fieldLayout); - } - - /** - * @notice Get v3. - */ - function getV3(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6) internal view returns (bytes16 v3) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); - return (bytes16(_blob)); - } - - /** - * @notice Get v3. - */ - function _getV3(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6) internal view returns (bytes16 v3) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); - return (bytes16(_blob)); - } - - /** - * @notice Set v3. - */ - function setV3(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, bytes16 v3) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - StoreSwitch.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((v3)), _fieldLayout); - } - - /** - * @notice Set v3. - */ - function _setV3(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, bytes16 v3) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - StoreCore.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((v3)), _fieldLayout); - } - - /** - * @notice Get v4. - */ - function getV4(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6) internal view returns (address v4) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 3, _fieldLayout); - return (address(bytes20(_blob))); - } - - /** - * @notice Get v4. - */ - function _getV4(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6) internal view returns (address v4) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 3, _fieldLayout); - return (address(bytes20(_blob))); - } - - /** - * @notice Set v4. - */ - function setV4(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, address v4) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - StoreSwitch.setStaticField(_tableId, _keyTuple, 3, abi.encodePacked((v4)), _fieldLayout); - } - - /** - * @notice Set v4. - */ - function _setV4(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, address v4) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - StoreCore.setStaticField(_tableId, _keyTuple, 3, abi.encodePacked((v4)), _fieldLayout); - } - - /** - * @notice Get v5. - */ - function getV5(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6) internal view returns (bool v5) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 4, _fieldLayout); - return (_toBool(uint8(bytes1(_blob)))); - } - - /** - * @notice Get v5. - */ - function _getV5(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6) internal view returns (bool v5) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 4, _fieldLayout); - return (_toBool(uint8(bytes1(_blob)))); - } - - /** - * @notice Set v5. - */ - function setV5(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, bool v5) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - StoreSwitch.setStaticField(_tableId, _keyTuple, 4, abi.encodePacked((v5)), _fieldLayout); - } - - /** - * @notice Set v5. - */ - function _setV5(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, bool v5) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - StoreCore.setStaticField(_tableId, _keyTuple, 4, abi.encodePacked((v5)), _fieldLayout); - } - - /** - * @notice Get v6. - */ - function getV6(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6) internal view returns (Enum1 v6) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 5, _fieldLayout); - return Enum1(uint8(bytes1(_blob))); - } - - /** - * @notice Get v6. - */ - function _getV6(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6) internal view returns (Enum1 v6) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 5, _fieldLayout); - return Enum1(uint8(bytes1(_blob))); - } - - /** - * @notice Set v6. - */ - function setV6(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, Enum1 v6) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - StoreSwitch.setStaticField(_tableId, _keyTuple, 5, abi.encodePacked(uint8(v6)), _fieldLayout); - } - - /** - * @notice Set v6. - */ - function _setV6(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, Enum1 v6) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - StoreCore.setStaticField(_tableId, _keyTuple, 5, abi.encodePacked(uint8(v6)), _fieldLayout); - } - - /** - * @notice Get the full data. - */ - function get( - uint256 k1, - int32 k2, - bytes16 k3, - address k4, - bool k5, - Enum2 k6 - ) internal view returns (StaticsData memory _table) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Get the full data. - */ - function _get( - uint256 k1, - int32 k2, - bytes16 k3, - address k4, - bool k5, - Enum2 k6 - ) internal view returns (StaticsData memory _table) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Set the full data using individual values. - */ - function set( - uint256 k1, - int32 k2, - bytes16 k3, - address k4, - bool k5, - Enum2 k6, - uint256 v1, - int32 v2, - bytes16 v3, - address v4, - bool v5, - Enum1 v6 - ) internal { - bytes memory _staticData = encodeStatic(v1, v2, v3, v4, v5, v6); - - EncodedLengths _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Set the full data using individual values. - */ - function _set( - uint256 k1, - int32 k2, - bytes16 k3, - address k4, - bool k5, - Enum2 k6, - uint256 v1, - int32 v2, - bytes16 v3, - address v4, - bool v5, - Enum1 v6 - ) internal { - bytes memory _staticData = encodeStatic(v1, v2, v3, v4, v5, v6); - - EncodedLengths _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); - } - - /** - * @notice Set the full data using the data struct. - */ - function set(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, StaticsData memory _table) internal { - bytes memory _staticData = encodeStatic(_table.v1, _table.v2, _table.v3, _table.v4, _table.v5, _table.v6); - - EncodedLengths _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Set the full data using the data struct. - */ - function _set(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6, StaticsData memory _table) internal { - bytes memory _staticData = encodeStatic(_table.v1, _table.v2, _table.v3, _table.v4, _table.v5, _table.v6); - - EncodedLengths _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); - } - - /** - * @notice Decode the tightly packed blob of static data using this table's field layout. - */ - function decodeStatic( - bytes memory _blob - ) internal pure returns (uint256 v1, int32 v2, bytes16 v3, address v4, bool v5, Enum1 v6) { - v1 = (uint256(Bytes.getBytes32(_blob, 0))); - - v2 = (int32(uint32(Bytes.getBytes4(_blob, 32)))); - - v3 = (Bytes.getBytes16(_blob, 36)); - - v4 = (address(Bytes.getBytes20(_blob, 52))); - - v5 = (_toBool(uint8(Bytes.getBytes1(_blob, 72)))); - - v6 = Enum1(uint8(Bytes.getBytes1(_blob, 73))); - } - - /** - * @notice Decode the tightly packed blobs using this table's field layout. - * @param _staticData Tightly packed static fields. - * - * - */ - function decode( - bytes memory _staticData, - EncodedLengths, - bytes memory - ) internal pure returns (StaticsData memory _table) { - (_table.v1, _table.v2, _table.v3, _table.v4, _table.v5, _table.v6) = decodeStatic(_staticData); - } - - /** - * @notice Delete all data for given keys. - */ - function deleteRecord(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - StoreSwitch.deleteRecord(_tableId, _keyTuple); - } - - /** - * @notice Delete all data for given keys. - */ - function _deleteRecord(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, Enum2 k6) internal { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); - } - - /** - * @notice Tightly pack static (fixed length) data using this table's schema. - * @return The static data, encoded into a sequence of bytes. - */ - function encodeStatic( - uint256 v1, - int32 v2, - bytes16 v3, - address v4, - bool v5, - Enum1 v6 - ) internal pure returns (bytes memory) { - return abi.encodePacked(v1, v2, v3, v4, v5, v6); - } - - /** - * @notice Encode all of a record's fields. - * @return The static (fixed length) data, encoded into a sequence of bytes. - * @return The lengths of the dynamic fields (packed into a single bytes32 value). - * @return The dynamic (variable length) data, encoded into a sequence of bytes. - */ - function encode( - uint256 v1, - int32 v2, - bytes16 v3, - address v4, - bool v5, - Enum1 v6 - ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { - bytes memory _staticData = encodeStatic(v1, v2, v3, v4, v5, v6); - - EncodedLengths _encodedLengths; - bytes memory _dynamicData; - - return (_staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Encode keys as a bytes32 array using this table's field layout. - */ - function encodeKeyTuple( - uint256 k1, - int32 k2, - bytes16 k3, - address k4, - bool k5, - Enum2 k6 - ) internal pure returns (bytes32[] memory) { - bytes32[] memory _keyTuple = new bytes32[](6); - _keyTuple[0] = bytes32(uint256(k1)); - _keyTuple[1] = bytes32(uint256(int256(k2))); - _keyTuple[2] = bytes32(k3); - _keyTuple[3] = bytes32(uint256(uint160(k4))); - _keyTuple[4] = _boolToBytes32(k5); - _keyTuple[5] = bytes32(uint256(uint8(k6))); - - return _keyTuple; - } -} - -/** - * @notice Cast a value to a bool. - * @dev Boolean values are encoded as uint8 (1 = true, 0 = false), but Solidity doesn't allow casting between uint8 and bool. - * @param value The uint8 value to convert. - * @return result The boolean value. - */ -function _toBool(uint8 value) pure returns (bool result) { - assembly { - result := value - } -} - -/** - * @notice Cast a bool to a bytes32. - * @dev The boolean value is casted to a bytes32 value with 0 or 1 at the least significant bit. - */ -function _boolToBytes32(bool value) pure returns (bytes32 result) { - assembly { - result := value - } -} diff --git a/packages/cli/contracts/src/codegen/tables/UserTyped.sol b/packages/cli/contracts/src/codegen/tables/UserTyped.sol deleted file mode 100644 index 5e05f4d1a9..0000000000 --- a/packages/cli/contracts/src/codegen/tables/UserTyped.sol +++ /dev/null @@ -1,846 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -/* Autogenerated file. Do not edit manually. */ - -// 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 { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema } from "@latticexyz/store/src/Schema.sol"; -import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; -import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; - -// Import user types -import { TestTypeAddress, TestTypeInt64, TestTypeLibrary } from "./../../types.sol"; -import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; - -struct UserTypedData { - TestTypeAddress v1; - TestTypeInt64 v2; - TestTypeLibrary.TestTypeBool v3; - TestTypeLibrary.TestTypeUint128 v4; - ResourceId v5; -} - -library UserTyped { - // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "UserTyped", typeId: RESOURCE_TABLE });` - ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000055736572547970656400000000000000); - - FieldLayout constant _fieldLayout = - FieldLayout.wrap(0x004d050014080110200000000000000000000000000000000000000000000000); - - // Hex-encoded key schema of (address, int64, bool, uint128, bytes32) - Schema constant _keySchema = Schema.wrap(0x004d05006127600f5f0000000000000000000000000000000000000000000000); - // Hex-encoded value schema of (address, int64, bool, uint128, bytes32) - Schema constant _valueSchema = Schema.wrap(0x004d05006127600f5f0000000000000000000000000000000000000000000000); - - /** - * @notice Get the table's key field names. - * @return keyNames An array of strings with the names of key fields. - */ - function getKeyNames() internal pure returns (string[] memory keyNames) { - keyNames = new string[](5); - keyNames[0] = "k1"; - keyNames[1] = "k2"; - keyNames[2] = "k3"; - keyNames[3] = "k4"; - keyNames[4] = "k5"; - } - - /** - * @notice Get the table's value field names. - * @return fieldNames An array of strings with the names of value fields. - */ - function getFieldNames() internal pure returns (string[] memory fieldNames) { - fieldNames = new string[](5); - fieldNames[0] = "v1"; - fieldNames[1] = "v2"; - fieldNames[2] = "v3"; - fieldNames[3] = "v4"; - fieldNames[4] = "v5"; - } - - /** - * @notice Register the table with its config. - */ - function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); - } - - /** - * @notice Register the table with its config. - */ - function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); - } - - /** - * @notice Get v1. - */ - function getV1( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal view returns (TestTypeAddress v1) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return TestTypeAddress.wrap(address(bytes20(_blob))); - } - - /** - * @notice Get v1. - */ - function _getV1( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal view returns (TestTypeAddress v1) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return TestTypeAddress.wrap(address(bytes20(_blob))); - } - - /** - * @notice Set v1. - */ - function setV1( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - TestTypeAddress v1 - ) internal { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(TestTypeAddress.unwrap(v1)), _fieldLayout); - } - - /** - * @notice Set v1. - */ - function _setV1( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - TestTypeAddress v1 - ) internal { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(TestTypeAddress.unwrap(v1)), _fieldLayout); - } - - /** - * @notice Get v2. - */ - function getV2( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal view returns (TestTypeInt64 v2) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); - return TestTypeInt64.wrap(int64(uint64(bytes8(_blob)))); - } - - /** - * @notice Get v2. - */ - function _getV2( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal view returns (TestTypeInt64 v2) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); - return TestTypeInt64.wrap(int64(uint64(bytes8(_blob)))); - } - - /** - * @notice Set v2. - */ - function setV2( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - TestTypeInt64 v2 - ) internal { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - StoreSwitch.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked(TestTypeInt64.unwrap(v2)), _fieldLayout); - } - - /** - * @notice Set v2. - */ - function _setV2( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - TestTypeInt64 v2 - ) internal { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked(TestTypeInt64.unwrap(v2)), _fieldLayout); - } - - /** - * @notice Get v3. - */ - function getV3( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal view returns (TestTypeLibrary.TestTypeBool v3) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); - return TestTypeLibrary.TestTypeBool.wrap(_toBool(uint8(bytes1(_blob)))); - } - - /** - * @notice Get v3. - */ - function _getV3( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal view returns (TestTypeLibrary.TestTypeBool v3) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); - return TestTypeLibrary.TestTypeBool.wrap(_toBool(uint8(bytes1(_blob)))); - } - - /** - * @notice Set v3. - */ - function setV3( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - TestTypeLibrary.TestTypeBool v3 - ) internal { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - StoreSwitch.setStaticField( - _tableId, - _keyTuple, - 2, - abi.encodePacked(TestTypeLibrary.TestTypeBool.unwrap(v3)), - _fieldLayout - ); - } - - /** - * @notice Set v3. - */ - function _setV3( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - TestTypeLibrary.TestTypeBool v3 - ) internal { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - StoreCore.setStaticField( - _tableId, - _keyTuple, - 2, - abi.encodePacked(TestTypeLibrary.TestTypeBool.unwrap(v3)), - _fieldLayout - ); - } - - /** - * @notice Get v4. - */ - function getV4( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal view returns (TestTypeLibrary.TestTypeUint128 v4) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 3, _fieldLayout); - return TestTypeLibrary.TestTypeUint128.wrap(uint128(bytes16(_blob))); - } - - /** - * @notice Get v4. - */ - function _getV4( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal view returns (TestTypeLibrary.TestTypeUint128 v4) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 3, _fieldLayout); - return TestTypeLibrary.TestTypeUint128.wrap(uint128(bytes16(_blob))); - } - - /** - * @notice Set v4. - */ - function setV4( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - TestTypeLibrary.TestTypeUint128 v4 - ) internal { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - StoreSwitch.setStaticField( - _tableId, - _keyTuple, - 3, - abi.encodePacked(TestTypeLibrary.TestTypeUint128.unwrap(v4)), - _fieldLayout - ); - } - - /** - * @notice Set v4. - */ - function _setV4( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - TestTypeLibrary.TestTypeUint128 v4 - ) internal { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - StoreCore.setStaticField( - _tableId, - _keyTuple, - 3, - abi.encodePacked(TestTypeLibrary.TestTypeUint128.unwrap(v4)), - _fieldLayout - ); - } - - /** - * @notice Get v5. - */ - function getV5( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal view returns (ResourceId v5) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 4, _fieldLayout); - return ResourceId.wrap(bytes32(_blob)); - } - - /** - * @notice Get v5. - */ - function _getV5( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal view returns (ResourceId v5) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 4, _fieldLayout); - return ResourceId.wrap(bytes32(_blob)); - } - - /** - * @notice Set v5. - */ - function setV5( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - ResourceId v5 - ) internal { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - StoreSwitch.setStaticField(_tableId, _keyTuple, 4, abi.encodePacked(ResourceId.unwrap(v5)), _fieldLayout); - } - - /** - * @notice Set v5. - */ - function _setV5( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - ResourceId v5 - ) internal { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - StoreCore.setStaticField(_tableId, _keyTuple, 4, abi.encodePacked(ResourceId.unwrap(v5)), _fieldLayout); - } - - /** - * @notice Get the full data. - */ - function get( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal view returns (UserTypedData memory _table) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Get the full data. - */ - function _get( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal view returns (UserTypedData memory _table) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( - _tableId, - _keyTuple, - _fieldLayout - ); - return decode(_staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Set the full data using individual values. - */ - function set( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - TestTypeAddress v1, - TestTypeInt64 v2, - TestTypeLibrary.TestTypeBool v3, - TestTypeLibrary.TestTypeUint128 v4, - ResourceId v5 - ) internal { - bytes memory _staticData = encodeStatic(v1, v2, v3, v4, v5); - - EncodedLengths _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Set the full data using individual values. - */ - function _set( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - TestTypeAddress v1, - TestTypeInt64 v2, - TestTypeLibrary.TestTypeBool v3, - TestTypeLibrary.TestTypeUint128 v4, - ResourceId v5 - ) internal { - bytes memory _staticData = encodeStatic(v1, v2, v3, v4, v5); - - EncodedLengths _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); - } - - /** - * @notice Set the full data using the data struct. - */ - function set( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - UserTypedData memory _table - ) internal { - bytes memory _staticData = encodeStatic(_table.v1, _table.v2, _table.v3, _table.v4, _table.v5); - - EncodedLengths _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Set the full data using the data struct. - */ - function _set( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5, - UserTypedData memory _table - ) internal { - bytes memory _staticData = encodeStatic(_table.v1, _table.v2, _table.v3, _table.v4, _table.v5); - - EncodedLengths _encodedLengths; - bytes memory _dynamicData; - - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); - } - - /** - * @notice Decode the tightly packed blob of static data using this table's field layout. - */ - function decodeStatic( - bytes memory _blob - ) - internal - pure - returns ( - TestTypeAddress v1, - TestTypeInt64 v2, - TestTypeLibrary.TestTypeBool v3, - TestTypeLibrary.TestTypeUint128 v4, - ResourceId v5 - ) - { - v1 = TestTypeAddress.wrap(address(Bytes.getBytes20(_blob, 0))); - - v2 = TestTypeInt64.wrap(int64(uint64(Bytes.getBytes8(_blob, 20)))); - - v3 = TestTypeLibrary.TestTypeBool.wrap(_toBool(uint8(Bytes.getBytes1(_blob, 28)))); - - v4 = TestTypeLibrary.TestTypeUint128.wrap(uint128(Bytes.getBytes16(_blob, 29))); - - v5 = ResourceId.wrap(Bytes.getBytes32(_blob, 45)); - } - - /** - * @notice Decode the tightly packed blobs using this table's field layout. - * @param _staticData Tightly packed static fields. - * - * - */ - function decode( - bytes memory _staticData, - EncodedLengths, - bytes memory - ) internal pure returns (UserTypedData memory _table) { - (_table.v1, _table.v2, _table.v3, _table.v4, _table.v5) = decodeStatic(_staticData); - } - - /** - * @notice Delete all data for given keys. - */ - function deleteRecord( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - StoreSwitch.deleteRecord(_tableId, _keyTuple); - } - - /** - * @notice Delete all data for given keys. - */ - function _deleteRecord( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); - } - - /** - * @notice Tightly pack static (fixed length) data using this table's schema. - * @return The static data, encoded into a sequence of bytes. - */ - function encodeStatic( - TestTypeAddress v1, - TestTypeInt64 v2, - TestTypeLibrary.TestTypeBool v3, - TestTypeLibrary.TestTypeUint128 v4, - ResourceId v5 - ) internal pure returns (bytes memory) { - return abi.encodePacked(v1, v2, v3, v4, v5); - } - - /** - * @notice Encode all of a record's fields. - * @return The static (fixed length) data, encoded into a sequence of bytes. - * @return The lengths of the dynamic fields (packed into a single bytes32 value). - * @return The dynamic (variable length) data, encoded into a sequence of bytes. - */ - function encode( - TestTypeAddress v1, - TestTypeInt64 v2, - TestTypeLibrary.TestTypeBool v3, - TestTypeLibrary.TestTypeUint128 v4, - ResourceId v5 - ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { - bytes memory _staticData = encodeStatic(v1, v2, v3, v4, v5); - - EncodedLengths _encodedLengths; - bytes memory _dynamicData; - - return (_staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Encode keys as a bytes32 array using this table's field layout. - */ - function encodeKeyTuple( - TestTypeAddress k1, - TestTypeInt64 k2, - TestTypeLibrary.TestTypeBool k3, - TestTypeLibrary.TestTypeUint128 k4, - ResourceId k5 - ) internal pure returns (bytes32[] memory) { - bytes32[] memory _keyTuple = new bytes32[](5); - _keyTuple[0] = bytes32(uint256(uint160(TestTypeAddress.unwrap(k1)))); - _keyTuple[1] = bytes32(uint256(int256(TestTypeInt64.unwrap(k2)))); - _keyTuple[2] = _boolToBytes32(TestTypeLibrary.TestTypeBool.unwrap(k3)); - _keyTuple[3] = bytes32(uint256(TestTypeLibrary.TestTypeUint128.unwrap(k4))); - _keyTuple[4] = ResourceId.unwrap(k5); - - return _keyTuple; - } -} - -/** - * @notice Cast a value to a bool. - * @dev Boolean values are encoded as uint8 (1 = true, 0 = false), but Solidity doesn't allow casting between uint8 and bool. - * @param value The uint8 value to convert. - * @return result The boolean value. - */ -function _toBool(uint8 value) pure returns (bool result) { - assembly { - result := value - } -} - -/** - * @notice Cast a bool to a bytes32. - * @dev The boolean value is casted to a bytes32 value with 0 or 1 at the least significant bit. - */ -function _boolToBytes32(bool value) pure returns (bytes32 result) { - assembly { - result := value - } -} diff --git a/packages/cli/tsup.config.ts b/packages/cli/tsup.config.ts index cc3e3ca7de..1034d999ad 100644 --- a/packages/cli/tsup.config.ts +++ b/packages/cli/tsup.config.ts @@ -21,7 +21,7 @@ export default defineConfig({ entry: ["src/index.ts", "src/mud.ts"], target: "esnext", format: ["esm"], - dts: false, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/common/tsup.config.ts b/packages/common/tsup.config.ts index 0a6d6d0491..3abf76ff17 100644 --- a/packages/common/tsup.config.ts +++ b/packages/common/tsup.config.ts @@ -13,7 +13,7 @@ export default defineConfig({ }, target: "esnext", format: ["esm"], - dts: true, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/config/tsup.config.ts b/packages/config/tsup.config.ts index b758b036c8..8204f00f19 100644 --- a/packages/config/tsup.config.ts +++ b/packages/config/tsup.config.ts @@ -10,7 +10,7 @@ export default defineConfig({ }, target: "esnext", format: ["esm"], - dts: true, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/dev-tools/tsup.config.ts b/packages/dev-tools/tsup.config.ts index 7189afad8e..315c0c9fb7 100644 --- a/packages/dev-tools/tsup.config.ts +++ b/packages/dev-tools/tsup.config.ts @@ -16,7 +16,7 @@ export default defineConfig({ entry: ["src/index.ts"], target: "esnext", format: ["esm"], - dts: true, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/faucet/tsup.config.ts b/packages/faucet/tsup.config.ts index cadbc2f970..9fd1990d5f 100644 --- a/packages/faucet/tsup.config.ts +++ b/packages/faucet/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["src/index.ts", "bin/faucet-server.ts"], target: "esnext", format: ["esm"], - dts: true, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/gas-report/tsup.config.ts b/packages/gas-report/tsup.config.ts index 289314bad7..9249f040b1 100644 --- a/packages/gas-report/tsup.config.ts +++ b/packages/gas-report/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["ts/index.ts", "ts/gas-report.ts"], target: "esnext", format: ["esm"], - dts: true, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/protocol-parser/tsup.config.ts b/packages/protocol-parser/tsup.config.ts index bb7fe3066b..709f21cd88 100644 --- a/packages/protocol-parser/tsup.config.ts +++ b/packages/protocol-parser/tsup.config.ts @@ -7,7 +7,7 @@ export default defineConfig({ }, target: "esnext", format: ["esm"], - dts: true, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/query/tsup.config.ts b/packages/query/tsup.config.ts index bb7fe3066b..709f21cd88 100644 --- a/packages/query/tsup.config.ts +++ b/packages/query/tsup.config.ts @@ -7,7 +7,7 @@ export default defineConfig({ }, target: "esnext", format: ["esm"], - dts: true, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/react/tsup.config.ts b/packages/react/tsup.config.ts index 52bdfceee6..86fe9a5339 100644 --- a/packages/react/tsup.config.ts +++ b/packages/react/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["src/index.ts"], target: "esnext", format: ["esm"], - dts: true, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/recs/tsup.config.ts b/packages/recs/tsup.config.ts index faf54cff78..7bd5468d6d 100644 --- a/packages/recs/tsup.config.ts +++ b/packages/recs/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["src/index.ts", "src/deprecated/index.ts"], target: "esnext", format: ["esm"], - dts: true, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/schema-type/tsup.config.ts b/packages/schema-type/tsup.config.ts index 757d933b24..785c99b7cc 100644 --- a/packages/schema-type/tsup.config.ts +++ b/packages/schema-type/tsup.config.ts @@ -9,7 +9,7 @@ export default defineConfig({ outDir: "dist", target: "esnext", format: ["esm"], - dts: true, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/services/tsup.config.ts b/packages/services/tsup.config.ts index ed5646e5d5..92aa8b823d 100644 --- a/packages/services/tsup.config.ts +++ b/packages/services/tsup.config.ts @@ -6,7 +6,7 @@ export default defineConfig({ }, target: "esnext", format: ["esm"], - dts: true, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, }); diff --git a/packages/solhint-config-mud/tsup.config.ts b/packages/solhint-config-mud/tsup.config.ts index 7bb3556dd8..35ed4525fe 100644 --- a/packages/solhint-config-mud/tsup.config.ts +++ b/packages/solhint-config-mud/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["src/index.ts"], target: "esnext", format: ["cjs"], - dts: false, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/solhint-plugin-mud/tsup.config.ts b/packages/solhint-plugin-mud/tsup.config.ts index 7bb3556dd8..35ed4525fe 100644 --- a/packages/solhint-plugin-mud/tsup.config.ts +++ b/packages/solhint-plugin-mud/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["src/index.ts"], target: "esnext", format: ["cjs"], - dts: false, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/store-indexer/tsup.config.ts b/packages/store-indexer/tsup.config.ts index 7ae6c030dd..9b3595745c 100644 --- a/packages/store-indexer/tsup.config.ts +++ b/packages/store-indexer/tsup.config.ts @@ -10,7 +10,7 @@ export default defineConfig({ ], target: "esnext", format: ["esm"], - dts: false, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/store-sync/tsup.config.ts b/packages/store-sync/tsup.config.ts index a6442c1a4a..d8f6860bea 100644 --- a/packages/store-sync/tsup.config.ts +++ b/packages/store-sync/tsup.config.ts @@ -13,7 +13,7 @@ export default defineConfig({ ], target: "esnext", format: ["esm"], - dts: true, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/store/tsup.config.ts b/packages/store/tsup.config.ts index 3a4b84cdac..569cd72017 100644 --- a/packages/store/tsup.config.ts +++ b/packages/store/tsup.config.ts @@ -12,7 +12,7 @@ export default defineConfig({ }, target: "esnext", format: ["esm"], - dts: true, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/utils/tsup.config.ts b/packages/utils/tsup.config.ts index 52bdfceee6..86fe9a5339 100644 --- a/packages/utils/tsup.config.ts +++ b/packages/utils/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["src/index.ts"], target: "esnext", format: ["esm"], - dts: true, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/world-modules/tsup.config.ts b/packages/world-modules/tsup.config.ts index 997df67bba..a89281f3d6 100644 --- a/packages/world-modules/tsup.config.ts +++ b/packages/world-modules/tsup.config.ts @@ -6,7 +6,7 @@ export default defineConfig({ }, target: "esnext", format: ["esm"], - dts: true, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true, diff --git a/packages/world/tsup.config.ts b/packages/world/tsup.config.ts index cb091b605f..8ea323c621 100644 --- a/packages/world/tsup.config.ts +++ b/packages/world/tsup.config.ts @@ -11,7 +11,7 @@ export default defineConfig({ }, target: "esnext", format: ["esm"], - dts: true, + dts: !process.env.TSUP_SKIP_DTS, sourcemap: true, clean: true, minify: true,