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

feat(world-modules): add ERC721 module #1844

Merged
merged 27 commits into from
Nov 1, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
make it compile
alvrs committed Nov 1, 2023
commit 00bc3627a72df1bce5dc4ef2e5f9aeeb2d7e88b9
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import { ERC20Module } from "./ERC20Module.sol";
import { MODULE_NAMESPACE_ID, ERC20_REGISTRY_TABLE_ID } from "./constants.sol";
import { IERC20Mintable } from "./IERC20Mintable.sol";

import { MetadataData } from "./tables/Metadata.sol";
import { ERC20MetadataData } from "./tables/ERC20Metadata.sol";
import { ERC20Registry } from "./tables/ERC20Registry.sol";

/**
@@ -19,7 +19,7 @@ import { ERC20Registry } from "./tables/ERC20Registry.sol";
function registerERC20(
IBaseWorld world,
bytes14 namespace,
MetadataData memory metadata
ERC20MetadataData memory metadata
) returns (IERC20Mintable token) {
// Get the ERC20 module
ERC20Module erc20Module = ERC20Module(NamespaceOwner.get(MODULE_NAMESPACE_ID));
Original file line number Diff line number Diff line change
@@ -177,7 +177,7 @@ contract ERC721System is IERC721Mintable, System, PuppetMaster {
}

/**
* @dev Same as {xref-ERC721-safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* @dev Same as {xref-ERC721-safeMint-address-uint256-}[`safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function safeMint(address to, uint256 tokenId, bytes memory data) public virtual {
Original file line number Diff line number Diff line change
@@ -20,6 +20,25 @@ interface IERC721Mintable is IERC721 {
*/
function mint(address to, uint256 tokenId) external;

/**
* @dev Mints `tokenId`, transfers it to `to` and checks for `to` acceptance.
*
* Requirements:
*
* - caller must own the namespace
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeMint(address to, uint256 tokenId) external;

/**
* @dev Same as {xref-ERC721-safeMint-address-uint256-}[`safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function safeMint(address to, uint256 tokenId, bytes memory data) external;

/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
Original file line number Diff line number Diff line change
@@ -7,31 +7,31 @@ import { WorldResourceIdLib } from "@latticexyz/world/src/WorldResourceId.sol";

import { SystemSwitch } from "../../utils/SystemSwitch.sol";

import { ERC20Module } from "./ERC20Module.sol";
import { MODULE_NAMESPACE_ID, ERC20_REGISTRY_TABLE_ID } from "./constants.sol";
import { IERC20Mintable } from "./IERC20Mintable.sol";
import { ERC721Module } from "./ERC721Module.sol";
import { MODULE_NAMESPACE_ID, ERC721_REGISTRY_TABLE_ID } from "./constants.sol";
import { IERC721Mintable } from "./IERC721Mintable.sol";

import { MetadataData } from "./tables/Metadata.sol";
import { ERC20Registry } from "./tables/ERC20Registry.sol";
import { ERC721MetadataData } from "./tables/ERC721Metadata.sol";
import { ERC721Registry } from "./tables/ERC721Registry.sol";

/**
* @notice Register a new ERC20 token with the given metadata in a given namespace
* @notice Register a new ERC721 token with the given metadata in a given namespace
* @dev This function must be called within a Store context (i.e. using StoreSwitch.setStoreAddress())
*/
function registerERC20(
function registerERC721(
IBaseWorld world,
bytes14 namespace,
MetadataData 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();
ERC721MetadataData memory metadata
) returns (IERC721Mintable token) {
// Get the ERC721 module
ERC721Module erc721Module = ERC721Module(NamespaceOwner.get(MODULE_NAMESPACE_ID));
if (address(erc721Module) == address(0)) {
erc721Module = new ERC721Module();
}

// Install the ERC20 module with the provided args
world.installModule(erc20Module, abi.encode(namespace, metadata));
// Install the ERC721 module with the provided args
world.installModule(erc721Module, abi.encode(namespace, metadata));

// Return the newly created ERC20 token
token = IERC20Mintable(ERC20Registry.get(ERC20_REGISTRY_TABLE_ID, WorldResourceIdLib.encodeNamespace(namespace)));
// Return the newly created ERC721 token
token = IERC721Mintable(ERC721Registry.get(ERC721_REGISTRY_TABLE_ID, WorldResourceIdLib.encodeNamespace(namespace)));
}
4 changes: 2 additions & 2 deletions packages/world-modules/test/ERC721.t.sol
Original file line number Diff line number Diff line change
@@ -119,7 +119,7 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {
token.mint(owner, id);

assertEq(token.balanceOf(owner), 1);
assertEq(_ownerOf(id), owner);
assertEq(token.ownerOf(id), owner);
}

function testMintRevertAccessDenied(uint256 id, address owner) public {
@@ -145,7 +145,7 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {
token.ownerOf(id);
}

function testBurnRevertAccessDenined() public {
function testBurnRevertAccessDenined(uint256 id, address owner) public {
vm.assume(owner != address(0));

vm.prank(tokenOwner);