@latticexyz/world-modules 2.0.12-type-resolutions-effc7ab1 → 2.0.12-type-resolutions-ad8cc987

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/cache/solidity-files-cache.json +1 -1
  2. package/package.json +9 -8
  3. package/src/index.sol +25 -0
  4. package/src/interfaces/IBaseWorld.sol +16 -0
  5. package/src/interfaces/IERC20System.sol +33 -0
  6. package/src/interfaces/IERC721System.sol +43 -0
  7. package/src/interfaces/IPuppetFactorySystem.sol +15 -0
  8. package/src/interfaces/IUniqueEntitySystem.sol +13 -0
  9. package/src/interfaces/IUnstable_CallWithSignatureSystem.sol +20 -0
  10. package/src/modules/callwithsignature/ECDSA.sol +174 -0
  11. package/src/modules/callwithsignature/IERC1271.sol +17 -0
  12. package/src/modules/callwithsignature/IUnstable_CallWithSignatureErrors.sol +9 -0
  13. package/src/modules/callwithsignature/SignatureChecker.sol +50 -0
  14. package/src/modules/callwithsignature/Unstable_CallWithSignatureModule.sol +48 -0
  15. package/src/modules/callwithsignature/Unstable_CallWithSignatureSystem.sol +36 -0
  16. package/src/modules/callwithsignature/constants.sol +10 -0
  17. package/src/modules/callwithsignature/getSignedMessageHash.sol +54 -0
  18. package/src/modules/callwithsignature/tables/CallWithSignatureNonces.sol +199 -0
  19. package/src/modules/callwithsignature/validateCallWithSignature.sol +31 -0
  20. package/src/modules/erc20-puppet/ERC20Module.sol +88 -0
  21. package/src/modules/erc20-puppet/ERC20System.sol +286 -0
  22. package/src/modules/erc20-puppet/IERC20.sol +94 -0
  23. package/src/modules/erc20-puppet/IERC20Errors.sol +49 -0
  24. package/src/modules/erc20-puppet/IERC20Events.sol +18 -0
  25. package/src/modules/erc20-puppet/IERC20Mintable.sol +25 -0
  26. package/src/modules/erc20-puppet/constants.sol +20 -0
  27. package/src/modules/erc20-puppet/registerERC20.sol +35 -0
  28. package/src/modules/erc20-puppet/tables/Allowances.sol +208 -0
  29. package/src/modules/erc20-puppet/tables/ERC20Metadata.sol +604 -0
  30. package/src/modules/erc20-puppet/tables/ERC20Registry.sol +199 -0
  31. package/src/modules/erc20-puppet/tables/TotalSupply.sol +184 -0
  32. package/src/modules/erc20-puppet/utils.sol +30 -0
  33. package/src/modules/erc721-puppet/ERC721Module.sol +95 -0
  34. package/src/modules/erc721-puppet/ERC721System.sol +531 -0
  35. package/src/modules/erc721-puppet/IERC721.sol +120 -0
  36. package/src/modules/erc721-puppet/IERC721Errors.sol +61 -0
  37. package/src/modules/erc721-puppet/IERC721Events.sol +23 -0
  38. package/src/modules/erc721-puppet/IERC721Metadata.sol +27 -0
  39. package/src/modules/erc721-puppet/IERC721Mintable.sol +53 -0
  40. package/src/modules/erc721-puppet/IERC721Receiver.sol +28 -0
  41. package/src/modules/erc721-puppet/constants.sol +23 -0
  42. package/src/modules/erc721-puppet/libraries/LibString.sol +77 -0
  43. package/src/modules/erc721-puppet/registerERC721.sol +37 -0
  44. package/src/modules/erc721-puppet/tables/ERC721Metadata.sol +703 -0
  45. package/src/modules/erc721-puppet/tables/ERC721Registry.sol +199 -0
  46. package/src/modules/erc721-puppet/tables/OperatorApproval.sol +220 -0
  47. package/src/modules/erc721-puppet/tables/Owners.sol +196 -0
  48. package/src/modules/erc721-puppet/tables/TokenApproval.sol +196 -0
  49. package/src/modules/erc721-puppet/tables/TokenURI.sol +450 -0
  50. package/src/modules/erc721-puppet/utils.sol +38 -0
  51. package/src/modules/keysintable/KeysInTableHook.sol +141 -0
  52. package/src/modules/keysintable/KeysInTableModule.sol +110 -0
  53. package/src/modules/keysintable/constants.sol +7 -0
  54. package/src/modules/keysintable/getKeysInTable.sol +81 -0
  55. package/src/modules/keysintable/hasKey.sol +28 -0
  56. package/src/modules/keysintable/query.sol +200 -0
  57. package/src/modules/keysintable/tables/KeysInTable.sol +1638 -0
  58. package/src/modules/keysintable/tables/UsedKeysIndex.sol +414 -0
  59. package/src/modules/keyswithvalue/KeysWithValueHook.sol +158 -0
  60. package/src/modules/keyswithvalue/KeysWithValueModule.sol +103 -0
  61. package/src/modules/keyswithvalue/constants.sol +7 -0
  62. package/src/modules/keyswithvalue/getKeysWithValue.sol +58 -0
  63. package/src/modules/keyswithvalue/getTargetTableId.sol +32 -0
  64. package/src/modules/keyswithvalue/tables/KeysWithValue.sol +668 -0
  65. package/src/modules/puppet/Puppet.sol +80 -0
  66. package/src/modules/puppet/PuppetDelegationControl.sol +17 -0
  67. package/src/modules/puppet/PuppetFactorySystem.sol +25 -0
  68. package/src/modules/puppet/PuppetMaster.sol +19 -0
  69. package/src/modules/puppet/PuppetModule.sol +64 -0
  70. package/src/modules/puppet/constants.sol +23 -0
  71. package/src/modules/puppet/createPuppet.sol +24 -0
  72. package/src/modules/puppet/tables/PuppetRegistry.sol +199 -0
  73. package/src/modules/puppet/utils.sol +10 -0
  74. package/src/modules/std-delegations/CallboundDelegationControl.sol +64 -0
  75. package/src/modules/std-delegations/StandardDelegationsModule.sol +55 -0
  76. package/src/modules/std-delegations/SystemboundDelegationControl.sol +54 -0
  77. package/src/modules/std-delegations/TimeboundDelegationControl.sol +27 -0
  78. package/src/modules/std-delegations/constants.sol +21 -0
  79. package/src/modules/std-delegations/tables/CallboundDelegations.sol +287 -0
  80. package/src/modules/std-delegations/tables/SystemboundDelegations.sol +256 -0
  81. package/src/modules/std-delegations/tables/TimeboundDelegations.sol +211 -0
  82. package/src/modules/tokens/tables/Balances.sol +196 -0
  83. package/src/modules/uniqueentity/UniqueEntityModule.sol +73 -0
  84. package/src/modules/uniqueentity/UniqueEntitySystem.sol +18 -0
  85. package/src/modules/uniqueentity/constants.sol +13 -0
  86. package/src/modules/uniqueentity/getUniqueEntity.sol +26 -0
  87. package/src/modules/uniqueentity/tables/UniqueEntity.sol +238 -0
  88. package/src/modules/utils/ArrayLib.sol +55 -0
  89. package/src/utils/AccessControlLib.sol +55 -0
  90. package/src/utils/SystemSwitch.sol +80 -0
@@ -0,0 +1,58 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.8.24;
3
+
4
+ import { IStore } from "@latticexyz/store/src/IStore.sol";
5
+ import { EncodedLengths } from "@latticexyz/store/src/EncodedLengths.sol";
6
+ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
7
+
8
+ import { MODULE_NAMESPACE } from "./constants.sol";
9
+ import { KeysWithValue } from "./tables/KeysWithValue.sol";
10
+ import { getTargetTableId } from "./getTargetTableId.sol";
11
+
12
+ /**
13
+ * Get a list of keys with the given value.
14
+ *
15
+ * Note: this util can only be called within the context of a Store (e.g. from a System or Module).
16
+ * For usage outside of a Store, use the overload that takes an explicit store argument.
17
+ */
18
+ function getKeysWithValue(
19
+ ResourceId tableId,
20
+ bytes memory staticData,
21
+ EncodedLengths encodedLengths,
22
+ bytes memory dynamicData
23
+ ) view returns (bytes32[] memory keysWithValue) {
24
+ // Get the corresponding reverse mapping table
25
+ ResourceId keysWithValueTableId = getTargetTableId(MODULE_NAMESPACE, tableId);
26
+
27
+ // Get the keys with the given value
28
+ bytes memory value;
29
+ if (dynamicData.length > 0) {
30
+ value = abi.encodePacked(staticData, encodedLengths, dynamicData);
31
+ } else {
32
+ value = staticData;
33
+ }
34
+ keysWithValue = KeysWithValue.get(keysWithValueTableId, keccak256(value));
35
+ }
36
+
37
+ /**
38
+ * Get a list of keys with the given value for the given store.
39
+ */
40
+ function getKeysWithValue(
41
+ IStore store,
42
+ ResourceId tableId,
43
+ bytes memory staticData,
44
+ EncodedLengths encodedLengths,
45
+ bytes memory dynamicData
46
+ ) view returns (bytes32[] memory keysWithValue) {
47
+ // Get the corresponding reverse mapping table
48
+ ResourceId keysWithValueTableId = getTargetTableId(MODULE_NAMESPACE, tableId);
49
+
50
+ // Get the keys with the given value
51
+ bytes memory value;
52
+ if (dynamicData.length > 0) {
53
+ value = abi.encodePacked(staticData, encodedLengths, dynamicData);
54
+ } else {
55
+ value = staticData;
56
+ }
57
+ keysWithValue = KeysWithValue.get(store, keysWithValueTableId, keccak256(value));
58
+ }
@@ -0,0 +1,32 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.8.24;
3
+
4
+ import { TYPE_BITS } from "@latticexyz/store/src/ResourceId.sol";
5
+ import { ResourceId, WorldResourceIdInstance, NAME_BITS } from "@latticexyz/world/src/WorldResourceId.sol";
6
+ import { RESOURCE_TABLE } from "@latticexyz/world/src/worldResourceTypes.sol";
7
+
8
+ uint256 constant MODULE_NAMESPACE_BITS = 7 * 8;
9
+ uint256 constant TABLE_NAMESPACE_BITS = 7 * 8;
10
+ uint256 constant TABLE_NAME_BITS = 16 * 8;
11
+
12
+ /**
13
+ * Get a deterministic selector for the reverse mapping table for the given source table.
14
+ * The selector is constructed as follows:
15
+ * - The first 2 bytes are the resource type
16
+ * - The next 7 bytes are the module namespace
17
+ * - The next 7 bytes are the first 7 bytes of the source table namespace
18
+ * -- This is to avoid collisions between tables with the same name in different namespaces
19
+ * (Note that collisions are still possible if the first 7 bytes of the namespace are the same, in which case installing the module fails)
20
+ * - The last 16 bytes are the source table name
21
+ */
22
+ function getTargetTableId(bytes7 moduleNamespace, ResourceId sourceTableId) pure returns (ResourceId) {
23
+ bytes16 tableName = WorldResourceIdInstance.getName(sourceTableId);
24
+ bytes7 sourceTableNamespace = bytes7(WorldResourceIdInstance.getNamespace(sourceTableId));
25
+ return
26
+ ResourceId.wrap(
27
+ bytes32(RESOURCE_TABLE) |
28
+ (bytes32(moduleNamespace) >> TYPE_BITS) |
29
+ (bytes32(sourceTableNamespace) >> (TYPE_BITS + MODULE_NAMESPACE_BITS)) |
30
+ (bytes32(tableName) >> (TYPE_BITS + MODULE_NAMESPACE_BITS + TABLE_NAMESPACE_BITS))
31
+ );
32
+ }