@latticexyz/world-modules 2.0.12-main-ecc8f658 → 2.0.12-type-resolutions-effc7ab1

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 (91) hide show
  1. package/cache/solidity-files-cache.json +1 -0
  2. package/dist/mud.config.d.ts +0 -2
  3. package/package.json +9 -9
  4. package/src/index.sol +0 -25
  5. package/src/interfaces/IBaseWorld.sol +0 -16
  6. package/src/interfaces/IERC20System.sol +0 -33
  7. package/src/interfaces/IERC721System.sol +0 -43
  8. package/src/interfaces/IPuppetFactorySystem.sol +0 -15
  9. package/src/interfaces/IUniqueEntitySystem.sol +0 -13
  10. package/src/interfaces/IUnstable_CallWithSignatureSystem.sol +0 -20
  11. package/src/modules/callwithsignature/ECDSA.sol +0 -174
  12. package/src/modules/callwithsignature/IERC1271.sol +0 -17
  13. package/src/modules/callwithsignature/IUnstable_CallWithSignatureErrors.sol +0 -9
  14. package/src/modules/callwithsignature/SignatureChecker.sol +0 -50
  15. package/src/modules/callwithsignature/Unstable_CallWithSignatureModule.sol +0 -48
  16. package/src/modules/callwithsignature/Unstable_CallWithSignatureSystem.sol +0 -36
  17. package/src/modules/callwithsignature/constants.sol +0 -10
  18. package/src/modules/callwithsignature/getSignedMessageHash.sol +0 -54
  19. package/src/modules/callwithsignature/tables/CallWithSignatureNonces.sol +0 -199
  20. package/src/modules/callwithsignature/validateCallWithSignature.sol +0 -31
  21. package/src/modules/erc20-puppet/ERC20Module.sol +0 -88
  22. package/src/modules/erc20-puppet/ERC20System.sol +0 -286
  23. package/src/modules/erc20-puppet/IERC20.sol +0 -94
  24. package/src/modules/erc20-puppet/IERC20Errors.sol +0 -49
  25. package/src/modules/erc20-puppet/IERC20Events.sol +0 -18
  26. package/src/modules/erc20-puppet/IERC20Mintable.sol +0 -25
  27. package/src/modules/erc20-puppet/constants.sol +0 -20
  28. package/src/modules/erc20-puppet/registerERC20.sol +0 -35
  29. package/src/modules/erc20-puppet/tables/Allowances.sol +0 -208
  30. package/src/modules/erc20-puppet/tables/ERC20Metadata.sol +0 -604
  31. package/src/modules/erc20-puppet/tables/ERC20Registry.sol +0 -199
  32. package/src/modules/erc20-puppet/tables/TotalSupply.sol +0 -184
  33. package/src/modules/erc20-puppet/utils.sol +0 -30
  34. package/src/modules/erc721-puppet/ERC721Module.sol +0 -95
  35. package/src/modules/erc721-puppet/ERC721System.sol +0 -531
  36. package/src/modules/erc721-puppet/IERC721.sol +0 -120
  37. package/src/modules/erc721-puppet/IERC721Errors.sol +0 -61
  38. package/src/modules/erc721-puppet/IERC721Events.sol +0 -23
  39. package/src/modules/erc721-puppet/IERC721Metadata.sol +0 -27
  40. package/src/modules/erc721-puppet/IERC721Mintable.sol +0 -53
  41. package/src/modules/erc721-puppet/IERC721Receiver.sol +0 -28
  42. package/src/modules/erc721-puppet/constants.sol +0 -23
  43. package/src/modules/erc721-puppet/libraries/LibString.sol +0 -77
  44. package/src/modules/erc721-puppet/registerERC721.sol +0 -37
  45. package/src/modules/erc721-puppet/tables/ERC721Metadata.sol +0 -703
  46. package/src/modules/erc721-puppet/tables/ERC721Registry.sol +0 -199
  47. package/src/modules/erc721-puppet/tables/OperatorApproval.sol +0 -220
  48. package/src/modules/erc721-puppet/tables/Owners.sol +0 -196
  49. package/src/modules/erc721-puppet/tables/TokenApproval.sol +0 -196
  50. package/src/modules/erc721-puppet/tables/TokenURI.sol +0 -450
  51. package/src/modules/erc721-puppet/utils.sol +0 -38
  52. package/src/modules/keysintable/KeysInTableHook.sol +0 -141
  53. package/src/modules/keysintable/KeysInTableModule.sol +0 -110
  54. package/src/modules/keysintable/constants.sol +0 -7
  55. package/src/modules/keysintable/getKeysInTable.sol +0 -81
  56. package/src/modules/keysintable/hasKey.sol +0 -28
  57. package/src/modules/keysintable/query.sol +0 -200
  58. package/src/modules/keysintable/tables/KeysInTable.sol +0 -1638
  59. package/src/modules/keysintable/tables/UsedKeysIndex.sol +0 -414
  60. package/src/modules/keyswithvalue/KeysWithValueHook.sol +0 -158
  61. package/src/modules/keyswithvalue/KeysWithValueModule.sol +0 -103
  62. package/src/modules/keyswithvalue/constants.sol +0 -7
  63. package/src/modules/keyswithvalue/getKeysWithValue.sol +0 -58
  64. package/src/modules/keyswithvalue/getTargetTableId.sol +0 -32
  65. package/src/modules/keyswithvalue/tables/KeysWithValue.sol +0 -668
  66. package/src/modules/puppet/Puppet.sol +0 -80
  67. package/src/modules/puppet/PuppetDelegationControl.sol +0 -17
  68. package/src/modules/puppet/PuppetFactorySystem.sol +0 -25
  69. package/src/modules/puppet/PuppetMaster.sol +0 -19
  70. package/src/modules/puppet/PuppetModule.sol +0 -64
  71. package/src/modules/puppet/constants.sol +0 -23
  72. package/src/modules/puppet/createPuppet.sol +0 -24
  73. package/src/modules/puppet/tables/PuppetRegistry.sol +0 -199
  74. package/src/modules/puppet/utils.sol +0 -10
  75. package/src/modules/std-delegations/CallboundDelegationControl.sol +0 -64
  76. package/src/modules/std-delegations/StandardDelegationsModule.sol +0 -55
  77. package/src/modules/std-delegations/SystemboundDelegationControl.sol +0 -54
  78. package/src/modules/std-delegations/TimeboundDelegationControl.sol +0 -27
  79. package/src/modules/std-delegations/constants.sol +0 -21
  80. package/src/modules/std-delegations/tables/CallboundDelegations.sol +0 -287
  81. package/src/modules/std-delegations/tables/SystemboundDelegations.sol +0 -256
  82. package/src/modules/std-delegations/tables/TimeboundDelegations.sol +0 -211
  83. package/src/modules/tokens/tables/Balances.sol +0 -196
  84. package/src/modules/uniqueentity/UniqueEntityModule.sol +0 -73
  85. package/src/modules/uniqueentity/UniqueEntitySystem.sol +0 -18
  86. package/src/modules/uniqueentity/constants.sol +0 -13
  87. package/src/modules/uniqueentity/getUniqueEntity.sol +0 -26
  88. package/src/modules/uniqueentity/tables/UniqueEntity.sol +0 -238
  89. package/src/modules/utils/ArrayLib.sol +0 -55
  90. package/src/utils/AccessControlLib.sol +0 -55
  91. package/src/utils/SystemSwitch.sol +0 -80
@@ -1,199 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity >=0.8.24;
3
-
4
- /* Autogenerated file. Do not edit manually. */
5
-
6
- // Import store internals
7
- import { IStore } from "@latticexyz/store/src/IStore.sol";
8
- import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
9
- import { StoreCore } from "@latticexyz/store/src/StoreCore.sol";
10
- import { Bytes } from "@latticexyz/store/src/Bytes.sol";
11
- import { Memory } from "@latticexyz/store/src/Memory.sol";
12
- import { SliceLib } from "@latticexyz/store/src/Slice.sol";
13
- import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol";
14
- import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol";
15
- import { Schema } from "@latticexyz/store/src/Schema.sol";
16
- import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol";
17
- import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
18
-
19
- library CallWithSignatureNonces {
20
- // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "CallWithSignatur", typeId: RESOURCE_TABLE });`
21
- ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000043616c6c576974685369676e61747572);
22
-
23
- FieldLayout constant _fieldLayout =
24
- FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000);
25
-
26
- // Hex-encoded key schema of (address)
27
- Schema constant _keySchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000);
28
- // Hex-encoded value schema of (uint256)
29
- Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000);
30
-
31
- /**
32
- * @notice Get the table's key field names.
33
- * @return keyNames An array of strings with the names of key fields.
34
- */
35
- function getKeyNames() internal pure returns (string[] memory keyNames) {
36
- keyNames = new string[](1);
37
- keyNames[0] = "signer";
38
- }
39
-
40
- /**
41
- * @notice Get the table's value field names.
42
- * @return fieldNames An array of strings with the names of value fields.
43
- */
44
- function getFieldNames() internal pure returns (string[] memory fieldNames) {
45
- fieldNames = new string[](1);
46
- fieldNames[0] = "nonce";
47
- }
48
-
49
- /**
50
- * @notice Register the table with its config.
51
- */
52
- function register() internal {
53
- StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
54
- }
55
-
56
- /**
57
- * @notice Register the table with its config.
58
- */
59
- function _register() internal {
60
- StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
61
- }
62
-
63
- /**
64
- * @notice Get nonce.
65
- */
66
- function getNonce(address signer) internal view returns (uint256 nonce) {
67
- bytes32[] memory _keyTuple = new bytes32[](1);
68
- _keyTuple[0] = bytes32(uint256(uint160(signer)));
69
-
70
- bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
71
- return (uint256(bytes32(_blob)));
72
- }
73
-
74
- /**
75
- * @notice Get nonce.
76
- */
77
- function _getNonce(address signer) internal view returns (uint256 nonce) {
78
- bytes32[] memory _keyTuple = new bytes32[](1);
79
- _keyTuple[0] = bytes32(uint256(uint160(signer)));
80
-
81
- bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
82
- return (uint256(bytes32(_blob)));
83
- }
84
-
85
- /**
86
- * @notice Get nonce.
87
- */
88
- function get(address signer) internal view returns (uint256 nonce) {
89
- bytes32[] memory _keyTuple = new bytes32[](1);
90
- _keyTuple[0] = bytes32(uint256(uint160(signer)));
91
-
92
- bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
93
- return (uint256(bytes32(_blob)));
94
- }
95
-
96
- /**
97
- * @notice Get nonce.
98
- */
99
- function _get(address signer) internal view returns (uint256 nonce) {
100
- bytes32[] memory _keyTuple = new bytes32[](1);
101
- _keyTuple[0] = bytes32(uint256(uint160(signer)));
102
-
103
- bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
104
- return (uint256(bytes32(_blob)));
105
- }
106
-
107
- /**
108
- * @notice Set nonce.
109
- */
110
- function setNonce(address signer, uint256 nonce) internal {
111
- bytes32[] memory _keyTuple = new bytes32[](1);
112
- _keyTuple[0] = bytes32(uint256(uint160(signer)));
113
-
114
- StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((nonce)), _fieldLayout);
115
- }
116
-
117
- /**
118
- * @notice Set nonce.
119
- */
120
- function _setNonce(address signer, uint256 nonce) internal {
121
- bytes32[] memory _keyTuple = new bytes32[](1);
122
- _keyTuple[0] = bytes32(uint256(uint160(signer)));
123
-
124
- StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((nonce)), _fieldLayout);
125
- }
126
-
127
- /**
128
- * @notice Set nonce.
129
- */
130
- function set(address signer, uint256 nonce) internal {
131
- bytes32[] memory _keyTuple = new bytes32[](1);
132
- _keyTuple[0] = bytes32(uint256(uint160(signer)));
133
-
134
- StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((nonce)), _fieldLayout);
135
- }
136
-
137
- /**
138
- * @notice Set nonce.
139
- */
140
- function _set(address signer, uint256 nonce) internal {
141
- bytes32[] memory _keyTuple = new bytes32[](1);
142
- _keyTuple[0] = bytes32(uint256(uint160(signer)));
143
-
144
- StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((nonce)), _fieldLayout);
145
- }
146
-
147
- /**
148
- * @notice Delete all data for given keys.
149
- */
150
- function deleteRecord(address signer) internal {
151
- bytes32[] memory _keyTuple = new bytes32[](1);
152
- _keyTuple[0] = bytes32(uint256(uint160(signer)));
153
-
154
- StoreSwitch.deleteRecord(_tableId, _keyTuple);
155
- }
156
-
157
- /**
158
- * @notice Delete all data for given keys.
159
- */
160
- function _deleteRecord(address signer) internal {
161
- bytes32[] memory _keyTuple = new bytes32[](1);
162
- _keyTuple[0] = bytes32(uint256(uint160(signer)));
163
-
164
- StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
165
- }
166
-
167
- /**
168
- * @notice Tightly pack static (fixed length) data using this table's schema.
169
- * @return The static data, encoded into a sequence of bytes.
170
- */
171
- function encodeStatic(uint256 nonce) internal pure returns (bytes memory) {
172
- return abi.encodePacked(nonce);
173
- }
174
-
175
- /**
176
- * @notice Encode all of a record's fields.
177
- * @return The static (fixed length) data, encoded into a sequence of bytes.
178
- * @return The lengths of the dynamic fields (packed into a single bytes32 value).
179
- * @return The dynamic (variable length) data, encoded into a sequence of bytes.
180
- */
181
- function encode(uint256 nonce) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
182
- bytes memory _staticData = encodeStatic(nonce);
183
-
184
- EncodedLengths _encodedLengths;
185
- bytes memory _dynamicData;
186
-
187
- return (_staticData, _encodedLengths, _dynamicData);
188
- }
189
-
190
- /**
191
- * @notice Encode keys as a bytes32 array using this table's field layout.
192
- */
193
- function encodeKeyTuple(address signer) internal pure returns (bytes32[] memory) {
194
- bytes32[] memory _keyTuple = new bytes32[](1);
195
- _keyTuple[0] = bytes32(uint256(uint160(signer)));
196
-
197
- return _keyTuple;
198
- }
199
- }
@@ -1,31 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity >=0.8.24;
3
- import { ResourceId } from "@latticexyz/world/src/WorldResourceId.sol";
4
- import { WorldContextConsumerLib } from "@latticexyz/world/src/WorldContext.sol";
5
- import { CallWithSignatureNonces } from "./tables/CallWithSignatureNonces.sol";
6
- import { getSignedMessageHash } from "./getSignedMessageHash.sol";
7
- import { ECDSA } from "./ECDSA.sol";
8
- import { IUnstable_CallWithSignatureErrors } from "./IUnstable_CallWithSignatureErrors.sol";
9
- import { SignatureChecker } from "./SignatureChecker.sol";
10
-
11
- /**
12
- * @notice Verifies the given system call corresponds to the given signature.
13
- * @param signer The address on whose behalf the system is called.
14
- * @param systemId The ID of the system to be called.
15
- * @param callData The ABI data for the system call.
16
- * @param signature The EIP712 signature.
17
- * @dev Reverts with InvalidSignature(recoveredSigner) if the signature is invalid.
18
- */
19
- function validateCallWithSignature(
20
- address signer,
21
- ResourceId systemId,
22
- bytes memory callData,
23
- bytes memory signature
24
- ) view {
25
- uint256 nonce = CallWithSignatureNonces._get(signer);
26
- bytes32 hash = getSignedMessageHash(signer, systemId, callData, nonce, WorldContextConsumerLib._world());
27
-
28
- if (!SignatureChecker.isValidSignatureNow(signer, hash, signature)) {
29
- revert IUnstable_CallWithSignatureErrors.InvalidSignature();
30
- }
31
- }
@@ -1,88 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity >=0.8.24;
3
-
4
- import { ResourceIds } from "@latticexyz/store/src/codegen/tables/ResourceIds.sol";
5
- import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
6
- import { Module } from "@latticexyz/world/src/Module.sol";
7
- import { WorldResourceIdLib } from "@latticexyz/world/src/WorldResourceId.sol";
8
- import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol";
9
- import { revertWithBytes } from "@latticexyz/world/src/revertWithBytes.sol";
10
-
11
- import { Puppet } from "../puppet/Puppet.sol";
12
- import { createPuppet } from "../puppet/createPuppet.sol";
13
- import { Balances } from "../tokens/tables/Balances.sol";
14
-
15
- import { MODULE_NAMESPACE, MODULE_NAMESPACE_ID, ERC20_REGISTRY_TABLE_ID } from "./constants.sol";
16
- import { _allowancesTableId, _balancesTableId, _metadataTableId, _erc20SystemId } from "./utils.sol";
17
- import { ERC20System } from "./ERC20System.sol";
18
-
19
- import { ERC20Registry } from "./tables/ERC20Registry.sol";
20
- import { Allowances } from "./tables/Allowances.sol";
21
- import { ERC20Metadata, ERC20MetadataData } from "./tables/ERC20Metadata.sol";
22
-
23
- contract ERC20Module is Module {
24
- error ERC20Module_InvalidNamespace(bytes14 namespace);
25
-
26
- address immutable registrationLibrary = address(new ERC20ModuleRegistrationLibrary());
27
-
28
- function install(bytes memory encodedArgs) public {
29
- // Require the module to not be installed with these args yet
30
- requireNotInstalled(__self, encodedArgs);
31
-
32
- // Decode args
33
- (bytes14 namespace, ERC20MetadataData memory metadata) = abi.decode(encodedArgs, (bytes14, ERC20MetadataData));
34
-
35
- // Require the namespace to not be the module's namespace
36
- if (namespace == MODULE_NAMESPACE) {
37
- revert ERC20Module_InvalidNamespace(namespace);
38
- }
39
-
40
- // Register the ERC20 tables and system
41
- IBaseWorld world = IBaseWorld(_world());
42
- (bool success, bytes memory returnData) = registrationLibrary.delegatecall(
43
- abi.encodeCall(ERC20ModuleRegistrationLibrary.register, (world, namespace))
44
- );
45
- if (!success) revertWithBytes(returnData);
46
-
47
- // Initialize the Metadata
48
- ERC20Metadata.set(_metadataTableId(namespace), metadata);
49
-
50
- // Deploy and register the ERC20 puppet.
51
- ResourceId erc20SystemId = _erc20SystemId(namespace);
52
- address puppet = createPuppet(world, erc20SystemId);
53
-
54
- // Transfer ownership of the namespace to the caller
55
- ResourceId namespaceId = WorldResourceIdLib.encodeNamespace(namespace);
56
- world.transferOwnership(namespaceId, _msgSender());
57
-
58
- // Register the ERC20 in the ERC20Registry
59
- if (!ResourceIds.getExists(ERC20_REGISTRY_TABLE_ID)) {
60
- world.registerNamespace(MODULE_NAMESPACE_ID);
61
- ERC20Registry.register(ERC20_REGISTRY_TABLE_ID);
62
- }
63
- ERC20Registry.set(ERC20_REGISTRY_TABLE_ID, namespaceId, puppet);
64
- }
65
-
66
- function installRoot(bytes memory) public pure {
67
- revert Module_RootInstallNotSupported();
68
- }
69
- }
70
-
71
- contract ERC20ModuleRegistrationLibrary {
72
- /**
73
- * Register systems and tables for a new ERC20 token in a given namespace
74
- */
75
- function register(IBaseWorld world, bytes14 namespace) public {
76
- // Register the namespace if it doesn't exist yet
77
- ResourceId tokenNamespace = WorldResourceIdLib.encodeNamespace(namespace);
78
- world.registerNamespace(tokenNamespace);
79
-
80
- // Register the tables
81
- Allowances.register(_allowancesTableId(namespace));
82
- Balances.register(_balancesTableId(namespace));
83
- ERC20Metadata.register(_metadataTableId(namespace));
84
-
85
- // Register a new ERC20System
86
- world.registerSystem(_erc20SystemId(namespace), new ERC20System(), true);
87
- }
88
- }
@@ -1,286 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity >=0.8.24;
3
-
4
- import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
5
- import { System } from "@latticexyz/world/src/System.sol";
6
- import { WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol";
7
- import { NamespaceOwner } from "@latticexyz/world/src/codegen/tables/NamespaceOwner.sol";
8
- import { SystemRegistry } from "@latticexyz/world/src/codegen/tables/SystemRegistry.sol";
9
-
10
- import { AccessControlLib } from "../../utils/AccessControlLib.sol";
11
- import { PuppetMaster } from "../puppet/PuppetMaster.sol";
12
- import { toTopic } from "../puppet/utils.sol";
13
- import { Balances } from "../tokens/tables/Balances.sol";
14
-
15
- import { IERC20Mintable } from "./IERC20Mintable.sol";
16
-
17
- import { Allowances } from "./tables/Allowances.sol";
18
- import { TotalSupply } from "./tables/TotalSupply.sol";
19
- import { ERC20Metadata } from "./tables/ERC20Metadata.sol";
20
-
21
- import { _allowancesTableId, _balancesTableId, _totalSupplyTableId, _metadataTableId } from "./utils.sol";
22
-
23
- contract ERC20System is System, IERC20Mintable, PuppetMaster {
24
- using WorldResourceIdInstance for ResourceId;
25
-
26
- /**
27
- * @dev Returns the name of the token.
28
- */
29
- function name() public view virtual returns (string memory) {
30
- return ERC20Metadata.getName(_metadataTableId(_namespace()));
31
- }
32
-
33
- /**
34
- * @dev Returns the symbol of the token, usually a shorter version of the
35
- * name.
36
- */
37
- function symbol() public view virtual returns (string memory) {
38
- return ERC20Metadata.getSymbol(_metadataTableId(_namespace()));
39
- }
40
-
41
- /**
42
- * @dev Returns the number of decimals used to get its user representation.
43
- * For example, if `decimals` equals `2`, a balance of `505` tokens should
44
- * be displayed to a user as `5.05` (`505 / 10 ** 2`).
45
- *
46
- * Tokens usually opt for a value of 18, imitating the relationship between
47
- * Ether and Wei. This is the default value returned by this function, unless
48
- * it's overridden.
49
- *
50
- * NOTE: This information is only used for _display_ purposes: it in
51
- * no way affects any of the arithmetic of the contract, including
52
- * {IERC20-balanceOf} and {IERC20-transfer}.
53
- */
54
- function decimals() public view virtual returns (uint8) {
55
- return ERC20Metadata.getDecimals(_metadataTableId(_namespace()));
56
- }
57
-
58
- /**
59
- * @dev Returns the value of tokens in existence.
60
- */
61
- function totalSupply() external view returns (uint256) {
62
- return TotalSupply.get(_totalSupplyTableId(_namespace()));
63
- }
64
-
65
- /**
66
- * @dev Returns the value of tokens owned by `account`.
67
- */
68
- function balanceOf(address account) external view returns (uint256) {
69
- return Balances.get(_balancesTableId(_namespace()), account);
70
- }
71
-
72
- /**
73
- * @dev Returns the remaining number of tokens that `spender` will be
74
- * allowed to spend on behalf of `owner` through {transferFrom}. This is
75
- * zero by default.
76
- *
77
- * This value changes when {approve} or {transferFrom} are called.
78
- */
79
- function allowance(address owner, address spender) external view returns (uint256) {
80
- return Allowances.get(_allowancesTableId(_namespace()), owner, spender);
81
- }
82
-
83
- /**
84
- * @dev See {IERC20-transfer}.
85
- *
86
- * Requirements:
87
- *
88
- * - `to` cannot be the zero address.
89
- * - the caller must have a balance of at least `value`.
90
- */
91
- function transfer(address to, uint256 value) public virtual returns (bool) {
92
- address owner = _msgSender();
93
- _transfer(owner, to, value);
94
-
95
- return true;
96
- }
97
-
98
- /**
99
- * @dev See {IERC20-approve}.
100
- *
101
- * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
102
- * `transferFrom`. This is semantically equivalent to an infinite approval.
103
- *
104
- * Requirements:
105
- *
106
- * - `spender` cannot be the zero address.
107
- */
108
- function approve(address spender, uint256 value) public virtual returns (bool) {
109
- address owner = _msgSender();
110
- _approve(owner, spender, value);
111
-
112
- return true;
113
- }
114
-
115
- /**
116
- * @dev See {IERC20-transferFrom}.
117
- *
118
- * Emits an {Approval} event indicating the updated allowance. This is not
119
- * required by the EIP. See the note at the beginning of {ERC20}.
120
- *
121
- * NOTE: Does not update the allowance if the current allowance
122
- * is the maximum `uint256`.
123
- *
124
- * Requirements:
125
- *
126
- * - `from` and `to` cannot be the zero address.
127
- * - `from` must have a balance of at least `value`.
128
- * - the caller must have allowance for ``from``'s tokens of at least
129
- * `value`.
130
- */
131
- function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
132
- address spender = _msgSender();
133
- _spendAllowance(from, spender, value);
134
- _transfer(from, to, value);
135
-
136
- return true;
137
- }
138
-
139
- /**
140
- * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
141
- * Relies on the `_update` mechanism
142
- *
143
- * Emits a {Transfer} event with `from` set to the zero address.
144
- */
145
- function mint(address account, uint256 value) public {
146
- // Require the caller to own the namespace
147
- _requireOwner();
148
-
149
- if (account == address(0)) {
150
- revert ERC20InvalidReceiver(address(0));
151
- }
152
-
153
- _update(address(0), account, value);
154
- }
155
-
156
- /**
157
- * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
158
- * Relies on the `_update` mechanism.
159
- *
160
- * Emits a {Transfer} event with `to` set to the zero address.
161
- *
162
- * NOTE: This function is not virtual, {_update} should be overridden instead
163
- */
164
- function burn(address account, uint256 value) public {
165
- // Require the caller to own the namespace
166
- _requireOwner();
167
-
168
- if (account == address(0)) {
169
- revert ERC20InvalidSender(address(0));
170
- }
171
-
172
- _update(account, address(0), value);
173
- }
174
-
175
- /**
176
- * @dev Moves a `value` amount of tokens from `from` to `to`.
177
- *
178
- * This internal function is equivalent to {transfer}, and can be used to
179
- * e.g. implement automatic token fees, slashing mechanisms, etc.
180
- *
181
- * Emits a {Transfer} event.
182
- *
183
- * NOTE: This function is not virtual, {_update} should be overridden instead.
184
- */
185
- function _transfer(address from, address to, uint256 value) internal {
186
- if (from == address(0)) {
187
- revert ERC20InvalidSender(address(0));
188
- }
189
- if (to == address(0)) {
190
- revert ERC20InvalidReceiver(address(0));
191
- }
192
- _update(from, to, value);
193
- }
194
-
195
- /**
196
- * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
197
- * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
198
- * this function.
199
- *
200
- * Emits a {Transfer} event.
201
- */
202
- function _update(address from, address to, uint256 value) internal virtual {
203
- bytes14 namespace = _namespace();
204
- ResourceId totalSupplyTableId = _totalSupplyTableId(namespace);
205
- ResourceId balanceTableId = _balancesTableId(namespace);
206
-
207
- if (from == address(0)) {
208
- // Overflow check required: The rest of the code assumes that totalSupply never overflows
209
- TotalSupply.set(totalSupplyTableId, TotalSupply.get(totalSupplyTableId) + value);
210
- } else {
211
- uint256 fromBalance = Balances.get(balanceTableId, from);
212
- if (fromBalance < value) {
213
- revert ERC20InsufficientBalance(from, fromBalance, value);
214
- }
215
- unchecked {
216
- // Overflow not possible: value <= fromBalance <= totalSupply.
217
- Balances.set(balanceTableId, from, fromBalance - value);
218
- }
219
- }
220
-
221
- if (to == address(0)) {
222
- unchecked {
223
- // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
224
- TotalSupply.set(totalSupplyTableId, TotalSupply.get(totalSupplyTableId) - value);
225
- }
226
- } else {
227
- unchecked {
228
- // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
229
- Balances.set(balanceTableId, to, Balances.get(balanceTableId, to) + value);
230
- }
231
- }
232
-
233
- // Emit Transfer event on puppet
234
- puppet().log(Transfer.selector, toTopic(from), toTopic(to), abi.encode(value));
235
- }
236
-
237
- /**
238
- * @dev Sets `value` as the allowance of `spender` over the `owner`s tokens.
239
- *
240
- * Requirements:
241
- *
242
- * - `owner` cannot be the zero address.
243
- * - `spender` cannot be the zero address.
244
- */
245
- function _approve(address owner, address spender, uint256 value) internal virtual {
246
- if (owner == address(0)) {
247
- revert ERC20InvalidApprover(address(0));
248
- }
249
- if (spender == address(0)) {
250
- revert ERC20InvalidSpender(address(0));
251
- }
252
- Allowances.set(_allowancesTableId(_namespace()), owner, spender, value);
253
-
254
- // Emit Approval event on puppet
255
- puppet().log(Approval.selector, toTopic(owner), toTopic(spender), abi.encode(value));
256
- }
257
-
258
- /**
259
- * @dev Updates `owner` s allowance for `spender` based on spent `value`.
260
- *
261
- * Does not update the allowance value in case of infinite allowance.
262
- * Revert if not enough allowance is available.
263
- *
264
- * Does not emit an {Approval} event.
265
- */
266
- function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
267
- uint256 currentAllowance = Allowances.get(_allowancesTableId(_namespace()), owner, spender);
268
- if (currentAllowance != type(uint256).max) {
269
- if (currentAllowance < value) {
270
- revert ERC20InsufficientAllowance(spender, currentAllowance, value);
271
- }
272
- unchecked {
273
- _approve(owner, spender, currentAllowance - value);
274
- }
275
- }
276
- }
277
-
278
- function _namespace() internal view returns (bytes14 namespace) {
279
- ResourceId systemId = SystemRegistry.get(address(this));
280
- return systemId.getNamespace();
281
- }
282
-
283
- function _requireOwner() internal view {
284
- AccessControlLib.requireOwner(SystemRegistry.get(address(this)), _msgSender());
285
- }
286
- }
@@ -1,94 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
3
-
4
- pragma solidity >=0.8.24;
5
-
6
- import { IERC20Events } from "./IERC20Events.sol";
7
- import { IERC20Errors } from "./IERC20Errors.sol";
8
-
9
- /**
10
- * @dev Interface of the ERC20 standard as defined in the EIP.
11
- */
12
- interface IERC20 is IERC20Events, IERC20Errors {
13
- /**
14
- * @dev Returns the name of the token.
15
- */
16
- function name() external view returns (string memory);
17
-
18
- /**
19
- * @dev Returns the symbol of the token, usually a shorter version of the
20
- * name.
21
- */
22
- function symbol() external view returns (string memory);
23
-
24
- /**
25
- * @dev Returns the number of decimals used to get its user representation.
26
- * For example, if `decimals` equals `2`, a balance of `505` tokens should
27
- * be displayed to a user as `5.05` (`505 / 10 ** 2`).
28
- *
29
- * Tokens usually opt for a value of 18, imitating the relationship between
30
- * Ether and Wei. This is the default value returned by this function, unless
31
- * it's overridden.
32
- *
33
- * NOTE: This information is only used for _display_ purposes: it in
34
- * no way affects any of the arithmetic of the contract, including
35
- * {IERC20-balanceOf} and {IERC20-transfer}.
36
- */
37
- function decimals() external view returns (uint8);
38
-
39
- /**
40
- * @dev Returns the value of tokens in existence.
41
- */
42
- function totalSupply() external view returns (uint256);
43
-
44
- /**
45
- * @dev Returns the value of tokens owned by `account`.
46
- */
47
- function balanceOf(address account) external view returns (uint256);
48
-
49
- /**
50
- * @dev Moves a `value` amount of tokens from the caller's account to `to`.
51
- *
52
- * Returns a boolean value indicating whether the operation succeeded.
53
- *
54
- * Emits a {Transfer} event.
55
- */
56
- function transfer(address to, uint256 value) external returns (bool);
57
-
58
- /**
59
- * @dev Returns the remaining number of tokens that `spender` will be
60
- * allowed to spend on behalf of `owner` through {transferFrom}. This is
61
- * zero by default.
62
- *
63
- * This value changes when {approve} or {transferFrom} are called.
64
- */
65
- function allowance(address owner, address spender) external view returns (uint256);
66
-
67
- /**
68
- * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
69
- * caller's tokens.
70
- *
71
- * Returns a boolean value indicating whether the operation succeeded.
72
- *
73
- * IMPORTANT: Beware that changing an allowance with this method brings the risk
74
- * that someone may use both the old and the new allowance by unfortunate
75
- * transaction ordering. One possible solution to mitigate this race
76
- * condition is to first reduce the spender's allowance to 0 and set the
77
- * desired value afterwards:
78
- * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
79
- *
80
- * Emits an {Approval} event.
81
- */
82
- function approve(address spender, uint256 value) external returns (bool);
83
-
84
- /**
85
- * @dev Moves a `value` amount of tokens from `from` to `to` using the
86
- * allowance mechanism. `value` is then deducted from the caller's
87
- * allowance.
88
- *
89
- * Returns a boolean value indicating whether the operation succeeded.
90
- *
91
- * Emits a {Transfer} event.
92
- */
93
- function transferFrom(address from, address to, uint256 value) external returns (bool);
94
- }