@latticexyz/world-module-erc20 2.2.21-041031d271b62a7f41f7c6dc0098c1c0ae222bd5 → 2.2.21-581228bd857077023efdb496a9a44fa62ff89936

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 (68) hide show
  1. package/out/AccessManagementSystem.sol/AccessManagementSystem.json +1 -1
  2. package/out/BalanceTransferSystem.sol/BalanceTransferSystem.json +1 -1
  3. package/out/BatchCallSystem.sol/BatchCallSystem.json +1 -1
  4. package/out/Constants.sol/ERC20TableNames.json +1 -1
  5. package/out/Constants.sol/ModuleConstants.json +1 -1
  6. package/out/Constants.sol/OwnableTableNames.abi.json +1 -0
  7. package/out/Constants.sol/OwnableTableNames.json +1 -0
  8. package/out/Constants.sol/PausableTableNames.json +1 -1
  9. package/out/ERC20BaseTest.t.sol/ERC20BehaviorTest.abi.json +0 -324
  10. package/out/ERC20BaseTest.t.sol/ERC20BehaviorTest.abi.json.d.ts +0 -324
  11. package/out/ERC20BaseTest.t.sol/ERC20BehaviorTest.json +1 -1
  12. package/out/ERC20BaseTest.t.sol/ERC20Test.abi.json +0 -324
  13. package/out/ERC20BaseTest.t.sol/ERC20Test.abi.json.d.ts +0 -324
  14. package/out/ERC20BaseTest.t.sol/ERC20Test.json +1 -1
  15. package/out/ERC20BaseTest.t.sol/MockERC20Base.abi.json +280 -21
  16. package/out/ERC20BaseTest.t.sol/MockERC20Base.abi.json.d.ts +280 -21
  17. package/out/ERC20BaseTest.t.sol/MockERC20Base.json +1 -1
  18. package/out/ERC20BaseTest.t.sol/TestConstants.abi.json +1 -0
  19. package/out/ERC20BaseTest.t.sol/TestConstants.json +1 -0
  20. package/out/ERC20Burnable.sol/ERC20Burnable.abi.json +317 -8
  21. package/out/ERC20Burnable.sol/ERC20Burnable.abi.json.d.ts +317 -8
  22. package/out/ERC20Burnable.sol/ERC20Burnable.json +1 -1
  23. package/out/ERC20Burnable.t.sol/ERC20BurnableTest.abi.json +0 -324
  24. package/out/ERC20Burnable.t.sol/ERC20BurnableTest.abi.json.d.ts +0 -324
  25. package/out/ERC20Burnable.t.sol/ERC20BurnableTest.json +1 -1
  26. package/out/ERC20Burnable.t.sol/MockERC20Burnable.abi.json +279 -25
  27. package/out/ERC20Burnable.t.sol/MockERC20Burnable.abi.json.d.ts +279 -25
  28. package/out/ERC20Burnable.t.sol/MockERC20Burnable.json +1 -1
  29. package/out/ERC20Module.sol/ERC20Module.json +1 -1
  30. package/out/ERC20Module.sol/ERC20RegistryLib.json +1 -0
  31. package/out/ERC20Module.t.sol/ERC20ModuleTest.json +1 -1
  32. package/out/ERC20Module.t.sol/TestConstants.json +1 -1
  33. package/out/ERC20Pausable.sol/ERC20Pausable.abi.json +317 -8
  34. package/out/ERC20Pausable.sol/ERC20Pausable.abi.json.d.ts +317 -8
  35. package/out/ERC20Pausable.sol/ERC20Pausable.json +1 -1
  36. package/out/ERC20Pausable.t.sol/{ERC20PausableTest.abi.json → ERC20PausableBehaviorTest.abi.json} +0 -324
  37. package/out/ERC20Pausable.t.sol/{ERC20PausableTest.abi.json.d.ts → ERC20PausableBehaviorTest.abi.json.d.ts} +0 -324
  38. package/out/ERC20Pausable.t.sol/ERC20PausableBehaviorTest.json +1 -0
  39. package/out/ERC20Pausable.t.sol/MockERC20Pausable.abi.json +279 -25
  40. package/out/ERC20Pausable.t.sol/MockERC20Pausable.abi.json.d.ts +279 -25
  41. package/out/ERC20Pausable.t.sol/MockERC20Pausable.json +1 -1
  42. package/out/ERC20PausableBurnable.sol/ERC20PausableBurnable.abi.json +284 -50
  43. package/out/ERC20PausableBurnable.sol/ERC20PausableBurnable.abi.json.d.ts +284 -50
  44. package/out/ERC20PausableBurnable.sol/ERC20PausableBurnable.json +1 -1
  45. package/out/InitModule.sol/InitModule.json +1 -1
  46. package/out/MUDERC20.sol/MUDERC20.abi.json +317 -8
  47. package/out/MUDERC20.sol/MUDERC20.abi.json.d.ts +317 -8
  48. package/out/MUDERC20.sol/MUDERC20.json +1 -1
  49. package/out/Pausable.sol/Pausable.abi.json +369 -8
  50. package/out/Pausable.sol/Pausable.abi.json.d.ts +369 -8
  51. package/out/Pausable.sol/Pausable.json +1 -1
  52. package/out/RegistrationSystem.sol/RegistrationSystem.json +1 -1
  53. package/out/World.sol/World.json +1 -1
  54. package/out/WorldConsumer.sol/WorldConsumer.abi.json +45 -8
  55. package/out/WorldConsumer.sol/WorldConsumer.abi.json.d.ts +45 -8
  56. package/out/WorldConsumer.sol/WorldConsumer.json +1 -1
  57. package/out/build-info/{5dec426f2d87057b9b49f18296a28057.json → 575e1001b22e51590748b4ce55e7c596.json} +1 -1
  58. package/package.json +8 -8
  59. package/src/examples/ERC20PausableBurnable.sol +8 -21
  60. package/src/experimental/Constants.sol +4 -0
  61. package/src/experimental/ERC20Module.sol +9 -46
  62. package/src/experimental/ERC20Pausable.sol +0 -3
  63. package/src/experimental/MUDERC20.sol +29 -24
  64. package/src/experimental/Pausable.sol +15 -15
  65. package/out/ERC20Module.sol/ERC20ModuleLib.json +0 -1
  66. package/out/ERC20Pausable.t.sol/ERC20PausableTest.json +0 -1
  67. /package/out/ERC20Module.sol/{ERC20ModuleLib.abi.json → ERC20RegistryLib.abi.json} +0 -0
  68. /package/out/ERC20Module.sol/{ERC20ModuleLib.abi.json.d.ts → ERC20RegistryLib.abi.json.d.ts} +0 -0
@@ -7,43 +7,30 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
7
7
  import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol";
8
8
  import { WorldConsumer } from "@latticexyz/world-consumer/src/experimental/WorldConsumer.sol";
9
9
 
10
- import { Pausable } from "../experimental/Pausable.sol";
11
10
  import { ERC20Pausable } from "../experimental/ERC20Pausable.sol";
12
11
  import { ERC20Burnable } from "../experimental/ERC20Burnable.sol";
13
12
  import { MUDERC20 } from "../experimental/MUDERC20.sol";
14
13
 
15
14
  contract ERC20PausableBurnable is MUDERC20, ERC20Pausable, ERC20Burnable {
16
- error ERC20PausableBurnable_AlreadyInitialized();
17
-
18
- bytes14 private immutable _namespace;
19
-
20
15
  constructor(
21
16
  IBaseWorld world,
22
17
  bytes14 namespace,
23
- ResourceId totalSupplyId,
24
- ResourceId balancesId,
25
- ResourceId allowancesId,
26
- ResourceId metadataId,
27
- ResourceId pausedId
28
- ) WorldConsumer(world) MUDERC20(totalSupplyId, balancesId, allowancesId, metadataId) ERC20Pausable(pausedId) {
29
- // Namespace used for access control
30
- _namespace = namespace;
31
- }
32
-
33
- function initialize(string memory name, string memory symbol) external onlyNamespaceOwner(_namespace) {
34
- _MUDERC20_init(name, symbol);
35
- _Pausable_init();
18
+ string memory name,
19
+ string memory symbol
20
+ ) WorldConsumer(world, namespace, true) MUDERC20(name, symbol) {
21
+ // Transfer namespace ownership to the creator
22
+ world.transferOwnership(namespaceId, _msgSender());
36
23
  }
37
24
 
38
- function mint(address to, uint256 value) public onlyNamespace(_namespace) {
25
+ function mint(address to, uint256 value) public onlyNamespace {
39
26
  _mint(to, value);
40
27
  }
41
28
 
42
- function pause() public onlyNamespace(_namespace) {
29
+ function pause() public onlyNamespace {
43
30
  _pause();
44
31
  }
45
32
 
46
- function unpause() public onlyNamespace(_namespace) {
33
+ function unpause() public onlyNamespace {
47
34
  _unpause();
48
35
  }
49
36
 
@@ -27,6 +27,10 @@ library ERC20TableNames {
27
27
  bytes16 internal constant METADATA = "Metadata";
28
28
  }
29
29
 
30
+ library OwnableTableNames {
31
+ bytes16 internal constant OWNER = "Owner";
32
+ }
33
+
30
34
  library PausableTableNames {
31
35
  bytes16 internal constant PAUSED = "Paused";
32
36
  }
@@ -3,23 +3,16 @@ pragma solidity >=0.8.24;
3
3
 
4
4
  import { ResourceIds } from "@latticexyz/store/src/codegen/tables/ResourceIds.sol";
5
5
  import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
6
- import { RESOURCE_TABLE } from "@latticexyz/store/src/storeResourceTypes.sol";
7
6
 
8
7
  import { Module } from "@latticexyz/world/src/Module.sol";
9
8
  import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol";
10
9
  import { WorldResourceIdLib } from "@latticexyz/world/src/WorldResourceId.sol";
11
10
  import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol";
11
+ import { revertWithBytes } from "@latticexyz/world/src/revertWithBytes.sol";
12
12
 
13
13
  import { ERC20Registry } from "../codegen/tables/ERC20Registry.sol";
14
14
  import { ERC20PausableBurnable } from "../examples/ERC20PausableBurnable.sol";
15
- import { MUDERC20 } from "../experimental/MUDERC20.sol";
16
- import { ModuleConstants, ERC20TableNames, PausableTableNames } from "./Constants.sol";
17
-
18
- import { ERC20Metadata, ERC20MetadataData } from "../codegen/tables/ERC20Metadata.sol";
19
- import { TotalSupply } from "../codegen/tables/TotalSupply.sol";
20
- import { Balances } from "../codegen/tables/Balances.sol";
21
- import { Allowances } from "../codegen/tables/Allowances.sol";
22
- import { Paused } from "../codegen/tables/Paused.sol";
15
+ import { ModuleConstants } from "./Constants.sol";
23
16
 
24
17
  contract ERC20Module is Module {
25
18
  error ERC20Module_InvalidNamespace(bytes14 namespace);
@@ -46,53 +39,23 @@ contract ERC20Module is Module {
46
39
 
47
40
  IBaseWorld world = IBaseWorld(_world());
48
41
 
49
- world.registerNamespace(namespaceId);
50
-
51
- ERC20PausableBurnable token = ERC20ModuleLib.deployAndRegisterTables(world, namespace);
42
+ ERC20PausableBurnable token = new ERC20PausableBurnable(world, namespace, name, symbol);
52
43
 
53
- // Grant access to the token so it can register and write to tables after transferring ownership
44
+ // Grant access to the token so it can write to tables after transferring ownership
54
45
  world.grantAccess(namespaceId, address(token));
55
46
 
56
47
  // Register token as a system so its functions can be called through the world
57
48
  world.registerSystem(systemId, token, true);
58
49
 
59
- // Set metadata and paused state by calling initialize (onlyNamespaceOwner)
60
- world.call(systemId, abi.encodeCall(ERC20PausableBurnable.initialize, (name, symbol)));
61
-
62
- ERC20ModuleLib.registerToken(world, namespaceId, address(token));
63
-
50
+ // The token should have transferred the namespace ownership to this module in its constructor
64
51
  world.transferOwnership(namespaceId, _msgSender());
65
- }
66
- }
67
-
68
- library ERC20ModuleLib {
69
- function deployAndRegisterTables(IBaseWorld world, bytes14 namespace) public returns (ERC20PausableBurnable) {
70
- ResourceId totalSupplyId = WorldResourceIdLib.encode(RESOURCE_TABLE, namespace, ERC20TableNames.TOTAL_SUPPLY);
71
- ResourceId balancesId = WorldResourceIdLib.encode(RESOURCE_TABLE, namespace, ERC20TableNames.BALANCES);
72
- ResourceId allowancesId = WorldResourceIdLib.encode(RESOURCE_TABLE, namespace, ERC20TableNames.ALLOWANCES);
73
- ResourceId metadataId = WorldResourceIdLib.encode(RESOURCE_TABLE, namespace, ERC20TableNames.METADATA);
74
- ResourceId pausedId = WorldResourceIdLib.encode(RESOURCE_TABLE, namespace, PausableTableNames.PAUSED);
75
52
 
76
- // Register each table
77
- TotalSupply.register(totalSupplyId);
78
- Balances.register(balancesId);
79
- Allowances.register(allowancesId);
80
- ERC20Metadata.register(metadataId);
81
- Paused.register(pausedId);
82
-
83
- return
84
- new ERC20PausableBurnable({
85
- world: world,
86
- namespace: namespace,
87
- totalSupplyId: totalSupplyId,
88
- balancesId: balancesId,
89
- allowancesId: allowancesId,
90
- metadataId: metadataId,
91
- pausedId: pausedId
92
- });
53
+ ERC20RegistryLib.register(world, namespaceId, address(token));
93
54
  }
55
+ }
94
56
 
95
- function registerToken(IBaseWorld world, ResourceId namespaceId, address token) public {
57
+ library ERC20RegistryLib {
58
+ function register(IBaseWorld world, ResourceId namespaceId, address token) public {
96
59
  ResourceId erc20RegistryTableId = ModuleConstants.registryTableId();
97
60
  if (!ResourceIds.getExists(erc20RegistryTableId)) {
98
61
  world.registerNamespace(ModuleConstants.namespaceId());
@@ -2,13 +2,10 @@
2
2
  // Adapted from OpenZeppelin's [ERC20Pausable extenstion](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/f989fff93168606c726bc5e831ef50dd6e543f45/contracts/token/ERC20/extensions/ERC20Pausable.sol)
3
3
  pragma solidity >=0.8.24;
4
4
 
5
- import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
6
5
  import { Pausable } from "./Pausable.sol";
7
6
  import { MUDERC20 } from "./MUDERC20.sol";
8
7
 
9
8
  abstract contract ERC20Pausable is MUDERC20, Pausable {
10
- constructor(ResourceId pausedId) Pausable(pausedId) {}
11
-
12
9
  function _update(address from, address to, uint256 value) internal virtual override whenNotPaused {
13
10
  super._update(from, to, value);
14
11
  }
@@ -19,16 +19,25 @@ import { IERC20Errors } from "../interfaces/IERC20Errors.sol";
19
19
  import { ERC20TableNames } from "./Constants.sol";
20
20
 
21
21
  abstract contract MUDERC20 is IERC20, IERC20Metadata, IERC20Errors, WorldConsumer {
22
- ResourceId private immutable _totalSupplyId;
23
- ResourceId private immutable _balancesId;
24
- ResourceId private immutable _allowancesId;
25
- ResourceId private immutable _metadataId;
26
-
27
- constructor(ResourceId totalSupplyId, ResourceId balancesId, ResourceId allowancesId, ResourceId metadataId) {
28
- _totalSupplyId = totalSupplyId;
29
- _balancesId = balancesId;
30
- _allowancesId = allowancesId;
31
- _metadataId = metadataId;
22
+ ResourceId internal immutable totalSupplyId;
23
+ ResourceId internal immutable balancesId;
24
+ ResourceId internal immutable allowancesId;
25
+ ResourceId internal immutable metadataId;
26
+
27
+ constructor(string memory _name, string memory _symbol) {
28
+ // Needs to be inlined in the constructor
29
+ totalSupplyId = WorldResourceIdLib.encode(RESOURCE_TABLE, namespace, ERC20TableNames.TOTAL_SUPPLY);
30
+ balancesId = WorldResourceIdLib.encode(RESOURCE_TABLE, namespace, ERC20TableNames.BALANCES);
31
+ allowancesId = WorldResourceIdLib.encode(RESOURCE_TABLE, namespace, ERC20TableNames.ALLOWANCES);
32
+ metadataId = WorldResourceIdLib.encode(RESOURCE_TABLE, namespace, ERC20TableNames.METADATA);
33
+
34
+ // Register each table
35
+ TotalSupply.register(totalSupplyId);
36
+ Balances.register(balancesId);
37
+ Allowances.register(allowancesId);
38
+ ERC20Metadata.register(metadataId);
39
+
40
+ _setMetadata(_name, _symbol, 18);
32
41
  }
33
42
 
34
43
  /**
@@ -144,10 +153,6 @@ abstract contract MUDERC20 is IERC20, IERC20Metadata, IERC20Errors, WorldConsume
144
153
  return true;
145
154
  }
146
155
 
147
- function _MUDERC20_init(string memory _name, string memory _symbol) internal {
148
- _setMetadata(_name, _symbol, 18);
149
- }
150
-
151
156
  /**
152
157
  * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
153
158
  * Relies on the `_update` mechanism
@@ -279,43 +284,43 @@ abstract contract MUDERC20 is IERC20, IERC20Metadata, IERC20Errors, WorldConsume
279
284
  }
280
285
 
281
286
  function _getName() internal view returns (string memory) {
282
- return ERC20Metadata.getName(_metadataId);
287
+ return ERC20Metadata.getName(metadataId);
283
288
  }
284
289
 
285
290
  function _getSymbol() internal view returns (string memory) {
286
- return ERC20Metadata.getSymbol(_metadataId);
291
+ return ERC20Metadata.getSymbol(metadataId);
287
292
  }
288
293
 
289
294
  function _getDecimals() internal view returns (uint8) {
290
- return ERC20Metadata.getDecimals(_metadataId);
295
+ return ERC20Metadata.getDecimals(metadataId);
291
296
  }
292
297
 
293
298
  function _getTotalSupply() internal view returns (uint256) {
294
- return TotalSupply.get(_totalSupplyId);
299
+ return TotalSupply.get(totalSupplyId);
295
300
  }
296
301
 
297
302
  function _getBalance(address account) internal view returns (uint256) {
298
- return Balances.get(_balancesId, account);
303
+ return Balances.get(balancesId, account);
299
304
  }
300
305
 
301
306
  function _getAllowance(address owner, address spender) internal view returns (uint256) {
302
- return Allowances.get(_allowancesId, owner, spender);
307
+ return Allowances.get(allowancesId, owner, spender);
303
308
  }
304
309
 
305
310
  function _setTotalSupply(uint256 value) internal virtual {
306
- TotalSupply.set(_totalSupplyId, value);
311
+ TotalSupply.set(totalSupplyId, value);
307
312
  }
308
313
 
309
314
  function _setBalance(address account, uint256 value) internal virtual {
310
- Balances.set(_balancesId, account, value);
315
+ Balances.set(balancesId, account, value);
311
316
  }
312
317
 
313
318
  function _setAllowance(address owner, address spender, uint256 value) internal virtual {
314
- Allowances.set(_allowancesId, owner, spender, value);
319
+ Allowances.set(allowancesId, owner, spender, value);
315
320
  }
316
321
 
317
322
  function _setMetadata(string memory _name, string memory _symbol, uint8 _decimals) internal virtual {
318
323
  ERC20MetadataData memory metadata = ERC20MetadataData(_decimals, _name, _symbol);
319
- ERC20Metadata.set(_metadataId, metadata);
324
+ ERC20Metadata.set(metadataId, metadata);
320
325
  }
321
326
  }
@@ -2,11 +2,13 @@
2
2
  // Adapted from OpenZeppelin Contracts [utils/Pausable.sol](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/f989fff93168606c726bc5e831ef50dd6e543f45/contracts/utils/Pausable.sol)
3
3
  pragma solidity >=0.8.24;
4
4
 
5
+ import { RESOURCE_TABLE } from "@latticexyz/store/src/storeResourceTypes.sol";
5
6
  import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
6
7
  import { WorldResourceIdLib } from "@latticexyz/world/src/WorldResourceId.sol";
7
8
  import { WorldConsumer } from "@latticexyz/world-consumer/src/experimental/WorldConsumer.sol";
8
9
 
9
10
  import { Paused as PausedTable } from "../codegen/tables/Paused.sol";
11
+ import { PausableTableNames } from "./Constants.sol";
10
12
 
11
13
  /**
12
14
  * @dev Contract module which allows children to implement an emergency stop
@@ -18,7 +20,7 @@ import { Paused as PausedTable } from "../codegen/tables/Paused.sol";
18
20
  * simply including this module, only once the modifiers are put in place.
19
21
  */
20
22
  abstract contract Pausable is WorldConsumer {
21
- ResourceId private immutable _pausedId;
23
+ ResourceId internal immutable pausedId;
22
24
 
23
25
  /**
24
26
  * @dev Emitted when the pause is triggered by `account`.
@@ -40,6 +42,15 @@ abstract contract Pausable is WorldConsumer {
40
42
  */
41
43
  error ExpectedPause();
42
44
 
45
+ /**
46
+ * @dev Initializes the contract in unpaused state.
47
+ */
48
+ constructor() {
49
+ pausedId = WorldResourceIdLib.encode(RESOURCE_TABLE, namespace, PausableTableNames.PAUSED);
50
+ PausedTable.register(pausedId);
51
+ PausedTable.set(pausedId, false);
52
+ }
53
+
43
54
  /**
44
55
  * @dev Modifier to make a function callable only when the contract is not paused.
45
56
  *
@@ -64,22 +75,11 @@ abstract contract Pausable is WorldConsumer {
64
75
  _;
65
76
  }
66
77
 
67
- constructor(ResourceId pausedId) {
68
- _pausedId = pausedId;
69
- }
70
-
71
- /**
72
- * @dev Initializes the contract in unpaused state.
73
- */
74
- function _Pausable_init() internal {
75
- PausedTable.set(_pausedId, false);
76
- }
77
-
78
78
  /**
79
79
  * @dev Returns true if the contract is paused, and false otherwise.
80
80
  */
81
81
  function paused() public view virtual returns (bool) {
82
- return PausedTable.get(_pausedId);
82
+ return PausedTable.get(pausedId);
83
83
  }
84
84
 
85
85
  /**
@@ -108,7 +108,7 @@ abstract contract Pausable is WorldConsumer {
108
108
  * - The contract must not be paused.
109
109
  */
110
110
  function _pause() internal virtual whenNotPaused {
111
- PausedTable.set(_pausedId, true);
111
+ PausedTable.set(pausedId, true);
112
112
  emit Paused(_msgSender());
113
113
  }
114
114
 
@@ -120,7 +120,7 @@ abstract contract Pausable is WorldConsumer {
120
120
  * - The contract must be paused.
121
121
  */
122
122
  function _unpause() internal virtual whenPaused {
123
- PausedTable.set(_pausedId, false);
123
+ PausedTable.set(pausedId, false);
124
124
  emit Unpaused(_msgSender());
125
125
  }
126
126
  }