Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into holic/sync-to-zustand
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Nov 2, 2023
2 parents d013a04 + d7325e5 commit 4ff8d2e
Show file tree
Hide file tree
Showing 54 changed files with 7,198 additions and 3 deletions.
21 changes: 21 additions & 0 deletions .changeset/gorgeous-swans-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
"@latticexyz/world-modules": minor
---

Added the `ERC721Module` to `@latticexyz/world-modules`.
This module allows the registration of `ERC721` tokens in an existing World.

Important note: this module has not been audited yet, so any production use is discouraged for now.

````solidity
import { PuppetModule } from "@latticexyz/world-modules/src/modules/puppet/PuppetModule.sol";
import { ERC721MetadataData } from "@latticexyz/world-modules/src/modules/erc721-puppet/tables/ERC721Metadata.sol";
import { IERC721Mintable } from "@latticexyz/world-modules/src/modules/erc721-puppet/IERC721Mintable.sol";
import { registerERC721 } from "@latticexyz/world-modules/src/modules/erc721-puppet/registerERC721.sol";
// The ERC721 module requires the Puppet module to be installed first
world.installModule(new PuppetModule(), new bytes(0));
// After the Puppet module is installed, new ERC721 tokens can be registered
IERC721Mintable token = registerERC721(world, "myERC721", ERC721MetadataData({ name: "Token", symbol: "TKN", baseURI: "" }));```
````
22 changes: 22 additions & 0 deletions .changeset/happy-pants-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
"@latticexyz/world-modules": minor
---

Added the `PuppetModule` to `@latticexyz/world-modules`. The puppet pattern allows an external contract to be registered as an external interface for a MUD system.
This allows standards like `ERC20` (that require a specific interface and events to be emitted by a unique contract) to be implemented inside a MUD World.

The puppet serves as a proxy, forwarding all calls to the implementation system (also called the "puppet master").
The "puppet master" system can emit events from the puppet contract.

```solidity
import { PuppetModule } from "@latticexyz/world-modules/src/modules/puppet/PuppetModule.sol";
import { createPuppet } from "@latticexyz/world-modules/src/modules/puppet/createPuppet.sol";
// Install the puppet module
world.installModule(new PuppetModule(), new bytes(0));
// Register a new puppet for any system
// The system must implement the `CustomInterface`,
// and the caller must own the system's namespace
CustomInterface puppet = CustomInterface(createPuppet(world, <systemId>));
```
20 changes: 20 additions & 0 deletions .changeset/silent-buttons-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
"@latticexyz/world-modules": minor
---

Added the `ERC20Module` to `@latticexyz/world-modules`.
This module allows the registration of `ERC20` tokens in an existing World.

Important note: this module has not been audited yet, so any production use is discouraged for now.

```solidity
import { PuppetModule } from "@latticexyz/world-modules/src/modules/puppet/PuppetModule.sol";
import { IERC20Mintable } from "@latticexyz/world-modules/src/modules/erc20-puppet/IERC20Mintable.sol";
import { registerERC20 } from "@latticexyz/world-modules/src/modules/erc20-puppet/registerERC20.sol";
// The ERC20 module requires the Puppet module to be installed first
world.installModule(new PuppetModule(), new bytes(0));
// After the Puppet module is installed, new ERC20 tokens can be registered
IERC20Mintable token = registerERC20(world, "myERC20", ERC20MetadataData({ decimals: 18, name: "Token", symbol: "TKN" }));
```
30 changes: 30 additions & 0 deletions packages/world-modules/gas-report.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
[
{
"file": "test/ERC20.t.sol",
"test": "testApprove",
"name": "approve",
"gasUsed": 114329
},
{
"file": "test/ERC20.t.sol",
"test": "testBurn",
"name": "burn",
"gasUsed": 75866
},
{
"file": "test/ERC20.t.sol",
"test": "testMint",
"name": "mint",
"gasUsed": 161705
},
{
"file": "test/ERC20.t.sol",
"test": "testTransfer",
"name": "transfer",
"gasUsed": 92948
},
{
"file": "test/ERC20.t.sol",
"test": "testTransferFrom",
"name": "transferFrom",
"gasUsed": 130250
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallComposite",
Expand Down
159 changes: 157 additions & 2 deletions packages/world-modules/mud.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default mudConfig({
tables: {
/************************************************************************
*
* MODULE TABLES
* KEYS WITH VALUE MODULE
*
************************************************************************/
KeysWithValue: {
Expand All @@ -24,6 +24,11 @@ export default mudConfig({
tableIdArgument: true,
storeArgument: true,
},
/************************************************************************
*
* KEYS IN TABLE MODULE
*
************************************************************************/
KeysInTable: {
directory: "modules/keysintable/tables",
keySchema: { sourceTableId: "ResourceId" },
Expand All @@ -46,13 +51,23 @@ export default mudConfig({
dataStruct: false,
storeArgument: true,
},
/************************************************************************
*
* UNIQUE ENTITY MODULE
*
************************************************************************/
UniqueEntity: {
directory: "modules/uniqueentity/tables",
keySchema: {},
valueSchema: "uint256",
tableIdArgument: true,
storeArgument: true,
},
/************************************************************************
*
* STD DELEGATIONS MODULE
*
************************************************************************/
CallboundDelegations: {
directory: "modules/std-delegations/tables",
keySchema: {
Expand All @@ -75,6 +90,146 @@ export default mudConfig({
maxTimestamp: "uint256",
},
},
/************************************************************************
*
* PUPPET MODULE
*
************************************************************************/
PuppetRegistry: {
directory: "modules/puppet/tables",
keySchema: {
systemId: "ResourceId",
},
valueSchema: {
puppet: "address",
},
tableIdArgument: true,
},
/************************************************************************
*
* TOKEN TABLES (SHARED BY ERC20, ERC721)
*
************************************************************************/
Balances: {
directory: "modules/tokens/tables",
keySchema: {
account: "address",
},
valueSchema: {
value: "uint256",
},
tableIdArgument: true,
},
/************************************************************************
*
* ERC20 MODULE
*
************************************************************************/
ERC20Metadata: {
directory: "modules/erc20-puppet/tables",
keySchema: {},
valueSchema: {
decimals: "uint8",
name: "string",
symbol: "string",
},
tableIdArgument: true,
},
Allowances: {
directory: "modules/erc20-puppet/tables",
keySchema: {
account: "address",
spender: "address",
},
valueSchema: {
value: "uint256",
},
tableIdArgument: true,
},
TotalSupply: {
directory: "modules/erc20-puppet/tables",
keySchema: {},
valueSchema: {
totalSupply: "uint256",
},
tableIdArgument: true,
},
ERC20Registry: {
directory: "modules/erc20-puppet/tables",
keySchema: {
namespaceId: "ResourceId",
},
valueSchema: {
erc20Address: "address",
},
tableIdArgument: true,
},
/************************************************************************
*
* ERC721 MODULE
*
************************************************************************/
ERC721Metadata: {
directory: "modules/erc721-puppet/tables",
keySchema: {},
valueSchema: {
name: "string",
symbol: "string",
baseURI: "string",
},
tableIdArgument: true,
},
TokenURI: {
directory: "modules/erc721-puppet/tables",
keySchema: {
tokenId: "uint256",
},
valueSchema: {
tokenURI: "string",
},
tableIdArgument: true,
},
Owners: {
directory: "modules/erc721-puppet/tables",
keySchema: {
tokenId: "uint256",
},
valueSchema: {
owner: "address",
},
tableIdArgument: true,
},
TokenApproval: {
directory: "modules/erc721-puppet/tables",
keySchema: {
tokenId: "uint256",
},
valueSchema: {
account: "address",
},
tableIdArgument: true,
},
OperatorApproval: {
directory: "modules/erc721-puppet/tables",
keySchema: {
owner: "address",
operator: "address",
},
valueSchema: {
approved: "bool",
},
tableIdArgument: true,
},
ERC721Registry: {
directory: "modules/erc721-puppet/tables",
keySchema: {
namespaceId: "ResourceId",
},
valueSchema: {
erc20Address: "address",
},
tableIdArgument: true,
},
},
excludeSystems: ["UniqueEntitySystem"],
excludeSystems: ["UniqueEntitySystem", "PuppetFactorySystem", "ERC20System", "ERC721System"],
});
2 changes: 1 addition & 1 deletion packages/world-modules/remappings.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ds-test/=node_modules/ds-test/src/
forge-std/=node_modules/forge-std/src/
@latticexyz/=node_modules/@latticexyz/
@latticexyz/=node_modules/@latticexyz/
12 changes: 12 additions & 0 deletions packages/world-modules/src/index.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@ import { UsedKeysIndex, UsedKeysIndexTableId } from "./modules/keysintable/table
import { UniqueEntity } from "./modules/uniqueentity/tables/UniqueEntity.sol";
import { CallboundDelegations, CallboundDelegationsTableId } from "./modules/std-delegations/tables/CallboundDelegations.sol";
import { TimeboundDelegations, TimeboundDelegationsTableId } from "./modules/std-delegations/tables/TimeboundDelegations.sol";
import { PuppetRegistry } from "./modules/puppet/tables/PuppetRegistry.sol";
import { Balances } from "./modules/tokens/tables/Balances.sol";
import { ERC20Metadata, ERC20MetadataData } from "./modules/erc20-puppet/tables/ERC20Metadata.sol";
import { Allowances } from "./modules/erc20-puppet/tables/Allowances.sol";
import { TotalSupply } from "./modules/erc20-puppet/tables/TotalSupply.sol";
import { ERC20Registry } from "./modules/erc20-puppet/tables/ERC20Registry.sol";
import { ERC721Metadata, ERC721MetadataData } from "./modules/erc721-puppet/tables/ERC721Metadata.sol";
import { TokenURI } from "./modules/erc721-puppet/tables/TokenURI.sol";
import { Owners } from "./modules/erc721-puppet/tables/Owners.sol";
import { TokenApproval } from "./modules/erc721-puppet/tables/TokenApproval.sol";
import { OperatorApproval } from "./modules/erc721-puppet/tables/OperatorApproval.sol";
import { ERC721Registry } from "./modules/erc721-puppet/tables/ERC721Registry.sol";
32 changes: 32 additions & 0 deletions packages/world-modules/src/interfaces/IERC20System.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.21;

/* Autogenerated file. Do not edit manually. */

/**
* @title IERC20System
* @dev This interface is automatically generated from the corresponding system contract. Do not edit manually.
*/
interface IERC20System {
function name() external view returns (string memory);

function symbol() external view returns (string memory);

function decimals() external view returns (uint8);

function totalSupply() external view returns (uint256);

function balanceOf(address account) external view returns (uint256);

function allowance(address owner, address spender) external view returns (uint256);

function transfer(address to, uint256 value) external returns (bool);

function approve(address spender, uint256 value) external returns (bool);

function transferFrom(address from, address to, uint256 value) external returns (bool);

function mint(address account, uint256 value) external;

function burn(address account, uint256 value) external;
}
14 changes: 14 additions & 0 deletions packages/world-modules/src/interfaces/IPuppetFactorySystem.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.21;

/* Autogenerated file. Do not edit manually. */

import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";

/**
* @title IPuppetFactorySystem
* @dev This interface is automatically generated from the corresponding system contract. Do not edit manually.
*/
interface IPuppetFactorySystem {
function createPuppet(ResourceId systemId) external returns (address puppet);
}
Loading

0 comments on commit 4ff8d2e

Please sign in to comment.