Skip to content

Commit

Permalink
feat: use Subsystem for ERC721Base and ERC1155Base
Browse files Browse the repository at this point in the history
  • Loading branch information
dk1a committed Dec 20, 2022
1 parent dcc3ad4 commit 06fc515
Show file tree
Hide file tree
Showing 31 changed files with 228 additions and 386 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# solecslib
ERC1155 and ERC721 Systems that use components to store data
ERC1155 and ERC721 Subsystems that use components to store data

Experimental additions to [@latticexyz/solecs](https://github.com/latticexyz/mud/tree/main/packages/solecs)

See [mud.dev](https://mud.dev/) first for context on solecs and what a System is.
See [mud.dev](https://mud.dev/) first for context on solecs and what a System/Subsystem is.

### Development

Expand Down Expand Up @@ -32,16 +32,16 @@ They have similar contracts with shared suffixes:
- Internal - ERC internals, inherits VData
- Logic - ERC public+internal methods, inherits Internal. This is a full ERC implementation, lacking only a data provider.
- DataComponents - data provider (only simple setters/getters), inherits VData.
- ERC__System - Logic + DataComponents + System + constructor + default execute implementation.
- ERC__Subsystem - Logic + DataComponents + Subsystem + constructor + default execute implementation.

#### ERC1155BaseSystem, ERC721BaseSystem
Full ERC1155/721 and System implementation, with a default execute and sub-executes (mint,burn,transfer all share 1 contract). Its components may be read by anyone without even awareness of ERC1155/721, but writes must always go through ERC__BaseSystem (this is mostly because of events, only 1 contract should emit them).
#### ERC1155BaseSubsystem, ERC721BaseSubsystem
Full ERC1155/721 and Subsystem implementation, with a default execute and sub-executes (mint,burn,transfer all share 1 contract). Its components may be read by anyone without even awareness of ERC1155/721, but writes must always go through ERC__BaseSubsystem (this is mostly because of events, only 1 contract should emit them).

#### Notes on VData and Logic
Data and Logic separation isn't really necessary, but this was an interesting use case for it. For example by having *Logic + DataStorage + constructor* you could get an ordinary ERC1155/721 implementation (where DataStorage implements VData but just uses normal contract storage). And imo keeping components away from Logic makes it easier to compare to @solidstate/contracts (I tried to keep it very similar, and even reuse tests via @solidstate/spec).

#### Forwarder systems, like OperatorApprovalSystem
These exist as an optional addition to ERC__BaseSystem. They are pure-ECS wrappers for transfers and approvals. I'm not sure they're useful.
These exist as an optional addition to ERC__BaseSubsystem. They are pure-ECS wrappers for transfers and approvals. I'm not sure they're useful.

----------

Expand Down
44 changes: 0 additions & 44 deletions contracts/mud/OwnableAndWriteAccess.sol

This file was deleted.

20 changes: 0 additions & 20 deletions contracts/mud/OwnableAndWriteAccessStorage.sol

This file was deleted.

24 changes: 0 additions & 24 deletions contracts/mud/SystemFacet.sol

This file was deleted.

23 changes: 0 additions & 23 deletions contracts/mud/SystemStorage.sol

This file was deleted.

32 changes: 0 additions & 32 deletions contracts/mud/_SystemFacet.sol

This file was deleted.

24 changes: 0 additions & 24 deletions contracts/mud/_SystemStorage.sol

This file was deleted.

17 changes: 8 additions & 9 deletions contracts/test/token/ERC1155/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PRBTest } from "@prb/test/src/PRBTest.sol";
// ECS
import { World } from "@latticexyz/solecs/src/World.sol";
// systems
import { ERC1155BaseSystemMock, ID as ERC1155BaseSystemMockID } from "./ERC1155BaseSystemMock.sol";
import { ERC1155BaseSubsystemMock, ID as ERC1155BaseSubsystemMockID } from "./ERC1155BaseSubsystemMock.sol";

// ERC1155 events
import { IERC1155Internal } from "@solidstate/contracts/interfaces/IERC1155Internal.sol";
Expand All @@ -26,8 +26,8 @@ contract BaseTest is
address notWriter = address(bytes20(keccak256("notWriter")));

World world;
// ERC1155 System
ERC1155BaseSystemMock ercSystem;
// ERC1155 Subsystem
ERC1155BaseSubsystemMock ercSubsystem;

uint256 tokenId = 1337;

Expand All @@ -40,11 +40,10 @@ contract BaseTest is

address components = address(world.components());
// deploy systems
ercSystem = new ERC1155BaseSystemMock(world, components);
// register systems
world.registerSystem(address(ercSystem), ERC1155BaseSystemMockID);
// allows calling ercSystem's execute
ercSystem.authorizeWriter(writer);
ercSubsystem = new ERC1155BaseSubsystemMock(world, components);
world.registerSystem(address(ercSubsystem), ERC1155BaseSubsystemMockID);
// authorize
ercSubsystem.authorizeWriter(writer);

vm.stopPrank();
}
Expand All @@ -53,7 +52,7 @@ contract BaseTest is

function _defaultMintToAlice() internal {
vm.prank(writer);
ercSystem.executeSafeMintBatch(alice, _asArray(tokenId), _asArray(100), '');
ercSubsystem.executeSafeMintBatch(alice, _asArray(tokenId), _asArray(100), '');
}

function _asArray(uint256 number) internal pure returns (uint256[] memory result) {
Expand Down
Loading

0 comments on commit 06fc515

Please sign in to comment.