Skip to content

Commit

Permalink
fix: update dependencies, make Subsystem local
Browse files Browse the repository at this point in the history
  • Loading branch information
dk1a committed Feb 6, 2023
1 parent 26126b7 commit 77beaae
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 124 deletions.
8 changes: 4 additions & 4 deletions contracts/duration/ScopedDurationSubsystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
pragma solidity ^0.8.17;

import { IWorld } from "@latticexyz/solecs/src/interfaces/IWorld.sol";
import { Subsystem } from "@latticexyz/solecs/src/Subsystem.sol";
import { getAddressById } from "@latticexyz/solecs/src/utils.sol";

import { ScopedValue } from "../scoped-value/ScopedValue.sol";
import {
SystemCallbackBareComponent,
SystemCallback,
executeSystemCallback
} from "../mud/SystemCallbackBareComponent.sol";
} from "@latticexyz/std-contracts/src/components/SystemCallbackBareComponent.sol";

import { Subsystem } from "../mud/Subsystem.sol";
import { ScopedValue } from "../scoped-value/ScopedValue.sol";

/// @dev durationEntity = hashed(target, prototype)
function getDurationEntity(uint256 targetEntity, uint256 protoEntity) pure returns (uint256) {
Expand Down
22 changes: 22 additions & 0 deletions contracts/mud/Subsystem.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.0;

import { IWorld } from "@latticexyz/solecs/src/interfaces/IWorld.sol";
import { System } from "@latticexyz/solecs/src/System.sol";

import { OwnableWritable } from "@latticexyz/solecs/src/OwnableWritable.sol";

/**
* Subsystem base contract
*/
abstract contract Subsystem is System, OwnableWritable {
constructor(IWorld _world, address _components) System(_world, _components) {}

/** Subsystems have predefined access control for execute */
function execute(bytes memory args) public override onlyWriter returns (bytes memory) {
return _execute(args);
}

/** Override _execute rather than execute */
function _execute(bytes memory args) internal virtual returns (bytes memory);
}
48 changes: 0 additions & 48 deletions contracts/mud/SystemCallbackBareComponent.sol

This file was deleted.

6 changes: 5 additions & 1 deletion contracts/test/duration/ScopedDurationSubsystem.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import { PRBTest } from "@prb/test/src/PRBTest.sol";
import { World } from "@latticexyz/solecs/src/World.sol";

import { Uint256Component } from "@latticexyz/solecs/src/components/Uint256Component.sol";
import {
SystemCallbackBareComponent,
SystemCallback,
executeSystemCallback
} from "@latticexyz/std-contracts/src/components/SystemCallbackBareComponent.sol";
import { ScopeComponent } from "../../scoped-value/ScopeComponent.sol";
import { ValueComponent } from "../../scoped-value/ValueComponent.sol";
import { SystemCallbackBareComponent, SystemCallback } from "../../mud/SystemCallbackBareComponent.sol";

import { ScopedDurationSubsystem, ScopedDuration } from "../../duration/ScopedDurationSubsystem.sol";
import { SetValueSystem, ID as SetValueSystemID } from "./SetValueSystem.sol";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { BaseTest } from "./BaseTest.sol";
import { SafeBatchTransferFromSystemMock, ID as SafeBatchTransferFromSystemMockID } from "./SafeBatchTransferFromSystemMock.sol";

// errors
import { ERC1155BaseInternal } from "../../../token/ERC1155/logic/ERC1155BaseInternal.sol";
import { IERC1155BaseInternal } from "@solidstate/contracts/token/ERC1155/base/IERC1155BaseInternal.sol";

contract SafeBatchTransferFromSystemTest is BaseTest {
SafeBatchTransferFromSystemMock transferSystem;
Expand Down Expand Up @@ -49,7 +49,7 @@ contract SafeBatchTransferFromSystemTest is BaseTest {
_defaultMintToAlice();

vm.prank(bob);
vm.expectRevert(ERC1155BaseInternal.ERC1155Base__NotOwnerOrApproved.selector);
vm.expectRevert(IERC1155BaseInternal.ERC1155Base__NotOwnerOrApproved.selector);
transferSystem.executeTyped(alice, bob, _asArray(tokenId), _asArray(80), '');
}

Expand All @@ -58,7 +58,7 @@ contract SafeBatchTransferFromSystemTest is BaseTest {
ercSubsystem.executeSafeMintBatch(address(transferSystem), _asArray(tokenId), _asArray(100), '');

vm.prank(bob);
vm.expectRevert(ERC1155BaseInternal.ERC1155Base__NotOwnerOrApproved.selector);
vm.expectRevert(IERC1155BaseInternal.ERC1155Base__NotOwnerOrApproved.selector);
transferSystem.executeTyped(address(transferSystem), bob, _asArray(tokenId), _asArray(80), '');
}
}
6 changes: 3 additions & 3 deletions contracts/test/token/ERC721/SafeTransferSystem.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { BaseTest } from "./BaseTest.sol";
import { SafeTransferSystemMock, ID as SafeTransferSystemMockID } from "./SafeTransferSystemMock.sol";

// errors
import { ERC721BaseInternal } from "../../../token/ERC721/logic/ERC721BaseInternal.sol";
import { IERC721BaseInternal } from "@solidstate/contracts/token/ERC721/base/IERC721BaseInternal.sol";

contract SafeTransferSystemTest is BaseTest {
SafeTransferSystemMock transferSystem;
Expand Down Expand Up @@ -44,7 +44,7 @@ contract SafeTransferSystemTest is BaseTest {
_defaultMintToAlice();

vm.prank(bob);
vm.expectRevert(ERC721BaseInternal.ERC721Base__NotOwnerOrApproved.selector);
vm.expectRevert(IERC721BaseInternal.ERC721Base__NotOwnerOrApproved.selector);
transferSystem.executeTyped(alice, bob, tokenId, '');
}

Expand All @@ -53,7 +53,7 @@ contract SafeTransferSystemTest is BaseTest {
ercSubsystem.executeSafeMint(address(transferSystem), tokenId, '');

vm.prank(bob);
vm.expectRevert(ERC721BaseInternal.ERC721Base__NotOwnerOrApproved.selector);
vm.expectRevert(IERC721BaseInternal.ERC721Base__NotOwnerOrApproved.selector);
transferSystem.executeTyped(address(transferSystem), bob, tokenId, '');
}
}
17 changes: 7 additions & 10 deletions contracts/token/ERC1155/ERC1155BaseSubsystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
pragma solidity ^0.8.17;

// erc165
import { ERC165, IERC165 } from "@solidstate/contracts/introspection/ERC165.sol";
import { ERC165Storage } from "@solidstate/contracts/introspection/ERC165Storage.sol";
import { IERC165 } from "@solidstate/contracts/interfaces/IERC165.sol";
import { ERC165Base } from "@solidstate/contracts/introspection/ERC165/base/ERC165Base.sol";
import { IERC1155 } from "@solidstate/contracts/interfaces/IERC1155.sol";
import { ISystem } from "@latticexyz/solecs/src/interfaces/ISystem.sol";

// ECS
import { IWorld } from "@latticexyz/solecs/src/interfaces/IWorld.sol";
import { Subsystem } from "@latticexyz/solecs/src/Subsystem.sol";
import { Subsystem } from "../../mud/Subsystem.sol";

// ERC1155 logic and data provider
import { ERC1155BaseLogic } from "./logic/ERC1155BaseLogic.sol";
Expand All @@ -35,13 +35,11 @@ import { ERC1155BaseDataComponents } from "./data-providers/ERC1155BaseDataCompo
* TODO metadata, enumerable?
*/
contract ERC1155BaseSubsystem is
ERC165,
ERC165Base,
ERC1155BaseDataComponents,
ERC1155BaseLogic,
Subsystem
{
using ERC165Storage for ERC165Storage.Layout;

error ERC1155BaseSubsystem__InvalidExecuteSelector();

// TODO diamond-compatible version?
Expand All @@ -56,13 +54,12 @@ contract ERC1155BaseSubsystem is
__ERC1155BaseDataComponents_init(_world, balanceComponentId, operatorApprovalComponentId);

// register interfaces
ERC165Storage.Layout storage erc165 = ERC165Storage.layout();
// IERC165
erc165.setSupportedInterface(type(IERC165).interfaceId, true);
_setSupportsInterface(type(IERC165).interfaceId, true);
// IERC1155
erc165.setSupportedInterface(type(IERC1155).interfaceId, true);
_setSupportsInterface(type(IERC1155).interfaceId, true);
// ISystem
erc165.setSupportedInterface(type(ISystem).interfaceId, true);
_setSupportsInterface(type(ISystem).interfaceId, true);
}

/**
Expand Down
16 changes: 2 additions & 14 deletions contracts/token/ERC1155/logic/ERC1155BaseInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity ^0.8.17;
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { Context } from "@openzeppelin/contracts/utils/Context.sol";
import { IERC1155Receiver } from '@solidstate/contracts/interfaces/IERC1155Receiver.sol';
import { IERC1155Internal } from "@solidstate/contracts/interfaces/IERC1155Internal.sol";
import { IERC1155BaseInternal } from "@solidstate/contracts/token/ERC1155/base/IERC1155BaseInternal.sol";

import { ERC1155BaseVData } from "./ERC1155BaseVData.sol";

Expand All @@ -16,21 +16,9 @@ import { ERC1155BaseVData } from "./ERC1155BaseVData.sol";
*/
abstract contract ERC1155BaseInternal is
Context,
IERC1155Internal,
IERC1155BaseInternal,
ERC1155BaseVData
{
error ERC1155Base__ArrayLengthMismatch();
error ERC1155Base__BalanceQueryZeroAddress();
error ERC1155Base__BurnExceedsBalance();
error ERC1155Base__BurnFromZeroAddress();
error ERC1155Base__ERC1155ReceiverRejected();
error ERC1155Base__ERC1155ReceiverNotImplemented();
error ERC1155Base__MintToZeroAddress();
error ERC1155Base__NotOwnerOrApproved();
error ERC1155Base__SelfApproval();
error ERC1155Base__TransferExceedsBalance();
error ERC1155Base__TransferToZeroAddress();

function _balanceOf(address account, uint256 id) internal view virtual returns (uint256) {
if (account == address(0)) revert ERC1155Base__BalanceQueryZeroAddress();
return _get_balance(account, id);
Expand Down
17 changes: 7 additions & 10 deletions contracts/token/ERC721/ERC721BaseSubsystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
pragma solidity ^0.8.17;

// erc165
import { ERC165, IERC165 } from "@solidstate/contracts/introspection/ERC165.sol";
import { ERC165Storage } from "@solidstate/contracts/introspection/ERC165Storage.sol";
import { IERC165 } from "@solidstate/contracts/interfaces/IERC165.sol";
import { ERC165Base } from "@solidstate/contracts/introspection/ERC165/base/ERC165Base.sol";
import { IERC721 } from "@solidstate/contracts/interfaces/IERC721.sol";
import { ISystem } from "@latticexyz/solecs/src/interfaces/ISystem.sol";

// ECS
import { IWorld } from "@latticexyz/solecs/src/interfaces/IWorld.sol";
import { Subsystem } from "@latticexyz/solecs/src/Subsystem.sol";
import { Subsystem } from "../../mud/Subsystem.sol";

// ERC721 logic and data provider
import { ERC721BaseLogic } from "./logic/ERC721BaseLogic.sol";
Expand All @@ -35,13 +35,11 @@ import { ERC721BaseDataComponents } from "./data-providers/ERC721BaseDataCompone
* TODO metadata, enumerable?
*/
contract ERC721BaseSubsystem is
ERC165,
ERC165Base,
ERC721BaseDataComponents,
ERC721BaseLogic,
Subsystem
{
using ERC165Storage for ERC165Storage.Layout;

error ERC721BaseSubsystem__InvalidExecuteSelector();

constructor(
Expand All @@ -56,13 +54,12 @@ contract ERC721BaseSubsystem is
__ERC721BaseDataComponents_init(_world, ownershipComponentId, operatorApprovalComponentId, tokenApprovalComponentId);

// register interfaces
ERC165Storage.Layout storage erc165 = ERC165Storage.layout();
// IERC165
erc165.setSupportedInterface(type(IERC165).interfaceId, true);
_setSupportsInterface(type(IERC165).interfaceId, true);
// IERC721
erc165.setSupportedInterface(type(IERC721).interfaceId, true);
_setSupportsInterface(type(IERC721).interfaceId, true);
// ISystem
erc165.setSupportedInterface(type(ISystem).interfaceId, true);
_setSupportsInterface(type(ISystem).interfaceId, true);
}

/**
Expand Down
15 changes: 2 additions & 13 deletions contracts/token/ERC721/logic/ERC721BaseInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,15 @@ pragma solidity ^0.8.17;
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { Context } from "@openzeppelin/contracts/utils/Context.sol";
import { IERC721Receiver } from '@solidstate/contracts/interfaces/IERC721Receiver.sol';
import { IERC721Internal } from "@solidstate/contracts/interfaces/IERC721Internal.sol";
import { IERC721BaseInternal } from "@solidstate/contracts/token/ERC721/base/IERC721BaseInternal.sol";

import { ERC721BaseVData } from "./ERC721BaseVData.sol";

abstract contract ERC721BaseInternal is
Context,
IERC721Internal,
IERC721BaseInternal,
ERC721BaseVData
{
error ERC721Base__NotOwnerOrApproved();
error ERC721Base__SelfApproval();
error ERC721Base__BalanceQueryZeroAddress();
error ERC721Base__ERC721ReceiverNotImplemented();
error ERC721Base__InvalidOwner();
error ERC721Base__MintToZeroAddress();
error ERC721Base__NonExistentToken();
error ERC721Base__NotTokenOwner();
error ERC721Base__TokenAlreadyMinted();
error ERC721Base__TransferToZeroAddress();

function _balanceOf(address account) internal view virtual returns (uint256) {
if (account == address(0)) revert ERC721Base__BalanceQueryZeroAddress();
return _get_balanceOf(account);
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
"/contracts/**/*.sol"
],
"dependencies": {
"@latticexyz/solecs": "https://gitpkg.now.sh/dk1a/mud/packages/solecs?982747e9d05ebaa05a084d4c2aacfd53aa7b4397",
"@latticexyz/std-contracts": "https://gitpkg.now.sh/dk1a/mud/packages/std-contracts?982747e9d05ebaa05a084d4c2aacfd53aa7b4397",
"@openzeppelin/contracts": "^4.8.0",
"@solidstate/contracts": "^0.0.48",
"@latticexyz/solecs": "^1.34.0",
"@latticexyz/std-contracts": "^1.34.0",
"@openzeppelin/contracts": "^4.8.1",
"@solidstate/contracts": "^0.0.52",
"memmove": "github:dk1a/memmove#ffd71cd77b1708574ef46a667b23ca3a5cc9fa27"
},
"devDependencies": {
Expand Down
30 changes: 16 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -559,13 +559,15 @@
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"

"@latticexyz/solecs@https://gitpkg.now.sh/dk1a/mud/packages/solecs?982747e9d05ebaa05a084d4c2aacfd53aa7b4397":
version "1.32.0"
resolved "https://gitpkg.now.sh/dk1a/mud/packages/solecs?982747e9d05ebaa05a084d4c2aacfd53aa7b4397#298cc4bcd647eef994ce04be2306cba50730ff16"
"@latticexyz/solecs@^1.34.0":
version "1.34.0"
resolved "https://registry.yarnpkg.com/@latticexyz/solecs/-/solecs-1.34.0.tgz#bfbf6ca5b577f5c5f5912a35704d99c1ecc089e9"
integrity sha512-tgUyHJWjs03PeOiqxzc+P98NUv2GcH+Ml87puhb/7RFv8WLrus7QOjkiwUcHHRO6+UZCBwr34ySaCY3AzJ4nUg==

"@latticexyz/std-contracts@https://gitpkg.now.sh/dk1a/mud/packages/std-contracts?982747e9d05ebaa05a084d4c2aacfd53aa7b4397":
version "1.32.0"
resolved "https://gitpkg.now.sh/dk1a/mud/packages/std-contracts?982747e9d05ebaa05a084d4c2aacfd53aa7b4397#c7b389f71a5d9ff6b4e24f6081d2dcd2d03f4ad5"
"@latticexyz/std-contracts@^1.34.0":
version "1.34.0"
resolved "https://registry.yarnpkg.com/@latticexyz/std-contracts/-/std-contracts-1.34.0.tgz#3f2bdae721d7aaa641f94ca83592592ab60055f8"
integrity sha512-eLX6qLQV+wQoJpkcO9OFFYB/uJq1ih+hZ1Ufg1n5NzOGzf3kWqJTwQwtSaYWDwUe9bszw2FtreivyqmwfYwubw==

"@metamask/eth-sig-util@^4.0.0":
version "4.0.1"
Expand Down Expand Up @@ -808,10 +810,10 @@
resolved "https://registry.yarnpkg.com/@nomiclabs/hardhat-ethers/-/hardhat-ethers-2.2.1.tgz#8057b43566a0e41abeb8142064a3c0d3f23dca86"
integrity sha512-RHWYwnxryWR8hzRmU4Jm/q4gzvXpetUOJ4OPlwH2YARcDB+j79+yAYCwO0lN1SUOb4++oOTJEe6AWLEc42LIvg==

"@openzeppelin/contracts@^4.8.0":
version "4.8.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.8.0.tgz#6854c37df205dd2c056bdfa1b853f5d732109109"
integrity sha512-AGuwhRRL+NaKx73WKRNzeCxOCOCxpaqF+kp8TJ89QzAipSwZy/NoflkWaL9bywXFRhIzXt8j38sfF7KBKCPWLw==
"@openzeppelin/contracts@^4.8.1":
version "4.8.1"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.8.1.tgz#709cfc4bbb3ca9f4460d60101f15dac6b7a2d5e4"
integrity sha512-xQ6eUZl+RDyb/FiZe1h+U7qr/f4p/SrTSQcTPH2bjur3C5DbuW/zFgCU/b1P/xcIaEqJep+9ju4xDRi3rmChdQ==

"@prb/test@^0.1.3":
version "0.1.3"
Expand Down Expand Up @@ -908,10 +910,10 @@
"@sentry/types" "5.30.0"
tslib "^1.9.3"

"@solidstate/contracts@^0.0.48":
version "0.0.48"
resolved "https://registry.yarnpkg.com/@solidstate/contracts/-/contracts-0.0.48.tgz#c97eb44cec623a388c67e2b36b404df3d46cf6ed"
integrity sha512-egof846MhC1lo+C8MJPmvte2xOjGEIbHcEB4G2H1ysC51F3xd81WZOTB/w+irylBSBK+HQE2uxhVW8QlUTBcEQ==
"@solidstate/contracts@^0.0.52":
version "0.0.52"
resolved "https://registry.yarnpkg.com/@solidstate/contracts/-/contracts-0.0.52.tgz#cfe7e2ef237421f6e150927d7338c1ef02daa7b8"
integrity sha512-xSBn5oLnfYtgNYrsRq/COlWHt0NxK26PFQ3FvI2DDMAFpZKFsffGLzUl8umezj2gVKpN7EZ+EVLdPKjqx6eUOw==

"@solidstate/library@^0.0.48":
version "0.0.48"
Expand Down

0 comments on commit 77beaae

Please sign in to comment.