You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Updates `WithWorld` to be a `System`, so that functions in child contracts that use the `onlyWorld` or `onlyNamespace` modifiers must be called through the world in order to safely support calls from systems.
Copy file name to clipboardExpand all lines: docs/pages/world/modules/erc20.mdx
+17-8Lines changed: 17 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,11 +12,13 @@ This module is unaudited and may change in the future.
12
12
The [`erc20` module](https://github.com/latticexyz/mud/tree/main/packages/world-module-erc20/) lets you create [ERC-20](https://ethereum.org/en/developers/docs/standards/tokens/erc-20/) tokens as part of a MUD `World`.
13
13
The advantage of doing this, rather than creating a separate [ERC-20 contract](https://github.com/OpenZeppelin/openzeppelin-contracts/tree/master/contracts/token/ERC20) and merely controlling it from MUD, is that all the information is in MUD tables and is immediately available in the client.
14
14
15
+
The token contract can be seen as a hybrid system contract which contains functions directly callable from outside the world (ERC20 functions like `transfer`, `balanceOf`, etc), and restricted functions that must be called as a system function through the World (`mint`, `pause`, etc).
16
+
15
17
The ERC20Module receives the namespace, name and symbol of the token as parameters, and deploys the new token. Currently it installs a [default ERC20](https://github.com/latticexyz/mud/tree/main/packages/world-module-erc20/src/examples/ERC20WithWorld.sol) with the following features:
16
18
17
19
- ERC20Burnable: Allows users to burn their tokens (or the ones approved to them) using the `burn` and `burnFrom` function.
18
-
- ERC20Pausable: Supports pausing and unpausing token operations. This is combined with the `pause` and `unpause` public functions that can be called by addresses with access to the token's namespace.
19
-
- Minting: Addresses with namespace access can call the `mint` function to mint tokens to any address.
20
+
- ERC20Pausable: Supports pausing and unpausing token operations. This is combined with the `pause` and `unpause` public functions that can be called by addresses and systems with access to the token's namespace. Must be done through a World call.
21
+
- Minting: Addresses and Systems with namespace access can call the `mint` function to mint tokens to any address. This must be done through a World call.
This is the process to get the address of our token contract.
151
+
This is the process to get the address of our token contract and the system id of the token.
145
152
First, we get the [`resourceId` values](/world/resource-ids) for the `erc20-module__ERC20Registry` table and the namespace we are interested in (each namespace can only have one ERC-20 token).
146
-
Then we use that table to get the token address.
153
+
Then we use that table to get the token address. Finally, we obtain the token system id from the `SystemRegistry` table.
147
154
148
155
```solidity
149
156
// Use the token
@@ -153,13 +160,15 @@ Then we use that table to get the token address.
153
160
Cast the token address to an `ERC20` contract so we can call its methods.
154
161
155
162
```solidity
163
+
// Mint some tokens
164
+
// We must call the token system (instead of calling mint directly)
Note that only the owner of the name space is authorized to mint tokens.
171
+
Note that the mint function must be called through the world as a system function, as it is restricted to entities with access to the token's namespace.
0 commit comments