Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(world): identify modules by addresses instead of names [L-08] #2168

Merged
merged 7 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 44 additions & 44 deletions packages/world-modules/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,139 +3,139 @@
"file": "test/ERC20.t.sol",
"test": "testApprove",
"name": "approve",
"gasUsed": 114348
"gasUsed": 114354
},
{
"file": "test/ERC20.t.sol",
"test": "testBurn",
"name": "burn",
"gasUsed": 75910
"gasUsed": 75922
},
{
"file": "test/ERC20.t.sol",
"test": "testMint",
"name": "mint",
"gasUsed": 161749
"gasUsed": 161761
},
{
"file": "test/ERC20.t.sol",
"test": "testTransfer",
"name": "transfer",
"gasUsed": 92995
"gasUsed": 93007
},
{
"file": "test/ERC20.t.sol",
"test": "testTransferFrom",
"name": "transferFrom",
"gasUsed": 130331
"gasUsed": 130349
},
{
"file": "test/ERC721.t.sol",
"test": "testApproveAllGas",
"name": "setApprovalForAll",
"gasUsed": 113972
"gasUsed": 113978
},
{
"file": "test/ERC721.t.sol",
"test": "testApproveGas",
"name": "approve",
"gasUsed": 87981
"gasUsed": 87987
},
{
"file": "test/ERC721.t.sol",
"test": "testBurnGas",
"name": "burn",
"gasUsed": 101910
"gasUsed": 101928
},
{
"file": "test/ERC721.t.sol",
"test": "testMintGas",
"name": "mint",
"gasUsed": 169480
"gasUsed": 169492
},
{
"file": "test/ERC721.t.sol",
"test": "testSafeMintToEOAGas",
"name": "safeMint",
"gasUsed": 169751
"gasUsed": 169763
},
{
"file": "test/ERC721.t.sol",
"test": "testSafeTransferFromToEOAGas",
"name": "safeTransferFrom",
"gasUsed": 143744
"gasUsed": 143768
},
{
"file": "test/ERC721.t.sol",
"test": "testTransferFromGas",
"name": "transferFrom",
"gasUsed": 136901
"gasUsed": 136925
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallComposite",
"name": "install keys in table module",
"gasUsed": 1439079
"gasUsed": 1438518
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallGas",
"name": "install keys in table module",
"gasUsed": 1439079
"gasUsed": 1438518
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallGas",
"name": "set a record on a table with keysInTableModule installed",
"gasUsed": 158830
"gasUsed": 158860
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallSingleton",
"name": "install keys in table module",
"gasUsed": 1439079
"gasUsed": 1438518
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookCompositeGas",
"name": "install keys in table module",
"gasUsed": 1439079
"gasUsed": 1438518
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookCompositeGas",
"name": "change a composite record on a table with keysInTableModule installed",
"gasUsed": 22483
"gasUsed": 22489
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookCompositeGas",
"name": "delete a composite record on a table with keysInTableModule installed",
"gasUsed": 155938
"gasUsed": 156040
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookGas",
"name": "install keys in table module",
"gasUsed": 1439079
"gasUsed": 1438518
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookGas",
"name": "change a record on a table with keysInTableModule installed",
"gasUsed": 21205
"gasUsed": 21211
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookGas",
"name": "delete a record on a table with keysInTableModule installed",
"gasUsed": 85160
"gasUsed": 85214
},
{
"file": "test/KeysWithValueModule.t.sol",
"test": "testGetKeysWithValueGas",
"name": "install keys with value module",
"gasUsed": 684459
"gasUsed": 683905
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -153,79 +153,79 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testInstall",
"name": "install keys with value module",
"gasUsed": 684459
"gasUsed": 683905
},
{
"file": "test/KeysWithValueModule.t.sol",
"test": "testInstall",
"name": "set a record on a table with KeysWithValueModule installed",
"gasUsed": 135410
"gasUsed": 135440
},
{
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetAndDeleteRecordHook",
"name": "install keys with value module",
"gasUsed": 684459
"gasUsed": 683905
},
{
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetAndDeleteRecordHook",
"name": "change a record on a table with KeysWithValueModule installed",
"gasUsed": 103813
"gasUsed": 103843
},
{
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetAndDeleteRecordHook",
"name": "delete a record on a table with KeysWithValueModule installed",
"gasUsed": 36468
"gasUsed": 36486
},
{
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetField",
"name": "install keys with value module",
"gasUsed": 684459
"gasUsed": 683905
},
{
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetField",
"name": "set a field on a table with KeysWithValueModule installed",
"gasUsed": 146645
"gasUsed": 146675
},
{
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetField",
"name": "change a field on a table with KeysWithValueModule installed",
"gasUsed": 111404
"gasUsed": 111434
},
{
"file": "test/query.t.sol",
"test": "testCombinedHasHasValueNotQuery",
"name": "CombinedHasHasValueNotQuery",
"gasUsed": 104500
"gasUsed": 104518
},
{
"file": "test/query.t.sol",
"test": "testCombinedHasHasValueQuery",
"name": "CombinedHasHasValueQuery",
"gasUsed": 53210
"gasUsed": 53216
},
{
"file": "test/query.t.sol",
"test": "testCombinedHasNotQuery",
"name": "CombinedHasNotQuery",
"gasUsed": 130734
"gasUsed": 130764
},
{
"file": "test/query.t.sol",
"test": "testCombinedHasQuery",
"name": "CombinedHasQuery",
"gasUsed": 84137
"gasUsed": 84161
},
{
"file": "test/query.t.sol",
"test": "testCombinedHasValueNotQuery",
"name": "CombinedHasValueNotQuery",
"gasUsed": 84673
"gasUsed": 84691
},
{
"file": "test/query.t.sol",
Expand All @@ -237,19 +237,19 @@
"file": "test/query.t.sol",
"test": "testHasQuery",
"name": "HasQuery",
"gasUsed": 18802
"gasUsed": 18808
},
{
"file": "test/query.t.sol",
"test": "testHasQuery1000Keys",
"name": "HasQuery with 1000 keys",
"gasUsed": 5764585
"gasUsed": 5764591
},
{
"file": "test/query.t.sol",
"test": "testHasQuery100Keys",
"name": "HasQuery with 100 keys",
"gasUsed": 537538
"gasUsed": 537544
},
{
"file": "test/query.t.sol",
Expand All @@ -261,7 +261,7 @@
"file": "test/query.t.sol",
"test": "testNotValueQuery",
"name": "NotValueQuery",
"gasUsed": 46806
"gasUsed": 46812
},
{
"file": "test/StandardDelegationsModule.t.sol",
Expand Down Expand Up @@ -303,24 +303,24 @@
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstall",
"name": "install unique entity module",
"gasUsed": 704219
"gasUsed": 703658
},
{
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstall",
"name": "get a unique entity nonce (non-root module)",
"gasUsed": 50365
"gasUsed": 50371
},
{
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstallRoot",
"name": "installRoot unique entity module",
"gasUsed": 673145
"gasUsed": 672531
},
{
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstallRoot",
"name": "get a unique entity nonce (root module)",
"gasUsed": 50368
"gasUsed": 50374
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import { revertWithBytes } from "@latticexyz/world/src/revertWithBytes.sol";

import { Puppet } from "../puppet/Puppet.sol";
import { createPuppet } from "../puppet/createPuppet.sol";
import { MODULE_NAME as PUPPET_MODULE_NAME } from "../puppet/constants.sol";
import { Balances } from "../tokens/tables/Balances.sol";

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

Expand All @@ -25,21 +24,22 @@ contract ERC20Module is Module {
error ERC20Module_InvalidNamespace(bytes14 namespace);

address immutable registrationLibrary = address(new ERC20ModuleRegistrationLibrary());
address immutable puppetModule;

function getName() public pure override returns (bytes16) {
return MODULE_NAME;
constructor(address _puppetModule) {
puppetModule = _puppetModule;
}

function _requireDependencies() internal view {
// Require PuppetModule to be installed
if (!isInstalled(PUPPET_MODULE_NAME, new bytes(0))) {
revert Module_MissingDependency(string(bytes.concat(PUPPET_MODULE_NAME)));
if (!isInstalled(puppetModule, new bytes(0))) {
revert Module_MissingDependency(puppetModule);
}
}

function install(bytes memory args) public {
// Require the module to not be installed with these args yet
requireNotInstalled(MODULE_NAME, args);
requireNotInstalled(__self, args);

// Extract args
(bytes14 namespace, ERC20MetadataData memory metadata) = abi.decode(args, (bytes14, ERC20MetadataData));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
import { RESOURCE_TABLE } from "@latticexyz/store/src/storeResourceTypes.sol";
import { RESOURCE_SYSTEM, RESOURCE_NAMESPACE } from "@latticexyz/world/src/worldResourceTypes.sol";

bytes16 constant MODULE_NAME = "erc20-puppet";
bytes14 constant MODULE_NAMESPACE = "erc20-puppet";
ResourceId constant MODULE_NAMESPACE_ID = ResourceId.wrap(
bytes32(abi.encodePacked(RESOURCE_NAMESPACE, MODULE_NAMESPACE))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ import { ERC20Registry } from "./tables/ERC20Registry.sol";
*/
function registerERC20(
IBaseWorld world,
address puppetModule,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel like this additional params is making it pretty impractical to use since it's currently not easy to find the address of the puppet module. Why don't we add an overload for this function that doesn't require the puppetModule address and instead calls this overload with the CREATE2 default address of the puppet module? That way it's not a breaking change for consumers (on CREATE2 compatible chains) but still allows customisation if necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The puppet module is part of the deployment pipeline right now, so doesn't use Create2. For example Sky Strife manually deploys the puppet: https://github.com/latticexyz/skystrife-public/blob/main/packages/contracts/script/PostDeploy.s.sol#L111-L119

bytes14 namespace,
ERC20MetadataData memory metadata
) returns (IERC20Mintable token) {
// Get the ERC20 module
ERC20Module erc20Module = ERC20Module(NamespaceOwner.get(MODULE_NAMESPACE_ID));
if (address(erc20Module) == address(0)) {
erc20Module = new ERC20Module();
erc20Module = new ERC20Module(puppetModule);
}

// Install the ERC20 module with the provided args
Expand Down
Loading
Loading