Skip to content

Commit

Permalink
fix(world-modules): register total supply table in erc20 module (#2877)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Ingersoll <[email protected]>
  • Loading branch information
yonadaaa and holic authored May 31, 2024
1 parent 7f07e9d commit 36c8b5b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
38 changes: 38 additions & 0 deletions .changeset/light-tables-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
"@latticexyz/world-modules": patch
---

Fixed `ERC20Module` to register the `TotalSupply` table when creating a new token.

If you've deployed a world with the `ERC20Module`, we recommend patching your world to register this table so that indexers can properly decode its record. You can do so with a simple Forge script:

```solidity
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;
import { Script } from "forge-std/Script.sol";
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
import { TotalSupply } from "@latticexyz/world-modules/src/modules/erc20-puppet/tables/TotalSupply.sol";
import { _totalSupplyTableId } from "@latticexyz/world-modules/src/modules/erc20-puppet/utils.sol";
contract RegisterTotalSupply is Script {
function run(address worldAddress, string memory namespaceString) external {
bytes14 namespace = bytes14(bytes(namespaceString));
StoreSwitch.setStoreAddress(worldAddress);
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);
TotalSupply.register(_totalSupplyTableId(namespace));
vm.stopBroadcast();
}
}
```

Then execute the transactions by running the following [`forge script`](https://book.getfoundry.sh/reference/forge/forge-script?highlight=script#forge-script) command:

```shell
forge script ./script/RegisterTotalSupply.s.sol --sig "run(address,string)" $WORLD_ADDRESS $NAMESPACE_STRING
```
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import { createPuppet } from "../puppet/createPuppet.sol";
import { Balances } from "../tokens/tables/Balances.sol";

import { MODULE_NAMESPACE, MODULE_NAMESPACE_ID, ERC20_REGISTRY_TABLE_ID } from "./constants.sol";
import { _allowancesTableId, _balancesTableId, _metadataTableId, _erc20SystemId } from "./utils.sol";
import { _allowancesTableId, _balancesTableId, _metadataTableId, _totalSupplyTableId, _erc20SystemId } from "./utils.sol";
import { ERC20System } from "./ERC20System.sol";

import { ERC20Registry } from "./tables/ERC20Registry.sol";
import { Allowances } from "./tables/Allowances.sol";
import { TotalSupply } from "./tables/TotalSupply.sol";
import { ERC20Metadata, ERC20MetadataData } from "./tables/ERC20Metadata.sol";

contract ERC20Module is Module {
Expand Down Expand Up @@ -80,6 +81,7 @@ contract ERC20ModuleRegistrationLibrary {
// Register the tables
Allowances.register(_allowancesTableId(namespace));
Balances.register(_balancesTableId(namespace));
TotalSupply.register(_totalSupplyTableId(namespace));
ERC20Metadata.register(_metadataTableId(namespace));

// Register a new ERC20System
Expand Down

0 comments on commit 36c8b5b

Please sign in to comment.