Skip to content

refactor(erc1155): modular facet architecture with exportSelectors#286

Merged
maxnorm merged 6 commits intoPerfect-Abstractions:mainfrom
aapsi:refactor/erc1155
Mar 7, 2026
Merged

refactor(erc1155): modular facet architecture with exportSelectors#286
maxnorm merged 6 commits intoPerfect-Abstractions:mainfrom
aapsi:refactor/erc1155

Conversation

@aapsi
Copy link
Contributor

@aapsi aapsi commented Mar 6, 2026

Summary

Refactors the ERC1155 implementation to match the modular facet pattern established by ERC20
and ERC721. Splits the monolithic ERC1155Facet.sol into focused facets and modules per
concern, and adds exportSelectors() to each facet as a selector discovery mechanism per
EIP-8153.

Changes Made

  • Deleted pre-refactor root-level files: ERC1155Facet.sol, ERC1155DataFacet.sol,
    ERC1155Mod.sol
  • Added Approve/ERC1155ApproveFacet.sol — external setApprovalForAll
  • Added Approve/ERC1155ApproveMod.sol — internal free function for approval logic
  • Added Burn/ERC1155BurnFacet.sol — external burnERC1155 and burnERC1155Batch with
    owner/operator authorization
  • Added Burn/ERC1155BurnMod.sol — internal free functions for burn logic
  • Added Data/ERC1155DataFacet.sol — external read-only functions: balanceOf,
    balanceOfBatch, isApprovedForAll
  • Added Metadata/ERC1155MetadataFacet.sol — external uri with per-token and base URI
    support
  • Added Metadata/ERC1155MetadataMod.sol — internal free functions: setURI, setBaseURI,
    setTokenURI
  • Added Mint/ERC1155MintMod.sol — internal free functions: mintERC1155,
    mintERC1155Batch with ERC1155Receiver validation
  • Added Transfer/ERC1155TransferFacet.sol — external safeTransferFrom and
    safeBatchTransferFrom with ERC1155Receiver validation
  • Added Transfer/ERC1155TransferMod.sol — internal free functions for transfer logic
  • Added exportSelectors() to all 5 facets (Approve, Burn, Data, Metadata, Transfer)
  • Function naming follows token-prefixed convention: mintERC1155, burnERC1155, etc.
    (consistent with mintERC20, burnERC721)
  • Two diamond storage slots: keccak256("erc1155") for core token data,
    keccak256("erc1155.metadata") for metadata
  • ERC-6093 compliant error names throughout
  • ERC-8042 compliant storage struct annotations

Checklist

Before submitting this PR, please ensure:

  • Code follows the Solidity feature ban - No inheritance, constructors, modifiers,
    public/private variables, external library functions, using for directives, or
    selfdestruct

  • Code follows Design Principles - Readable, uses diamond storage, favors composition
    over inheritance

  • Code matches the codebase style - Consistent formatting, documentation, and
    patterns (e.g. ERC20Facet.sol)

  • Code is formatted with forge fmt

  • Existing tests pass - Run tests to be sure existing tests pass.

  • All tests pass - Run forge test and ensure everything works

  • Documentation updated - If applicable, update relevant documentation

Make sure to follow the
contributing guidelines.

Additional Notes

Existing test files still reference the deleted pre-refactor files and will need to be
updated.

agent-cli and others added 4 commits March 6, 2026 07:32
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
@netlify
Copy link

netlify bot commented Mar 6, 2026

👷 Deploy request for compose-diamonds pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit e649e9e

@aapsi aapsi marked this pull request as draft March 6, 2026 09:20
@maxnorm maxnorm linked an issue Mar 6, 2026 that may be closed by this pull request

/**
* @notice Burns a single token type from an address.
* @dev Decreases the balance and emits a TransferSingle event.
Copy link
Collaborator

Choose a reason for hiding this comment

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

For extra safety, do you think it's worth adding a @dev notice on the fact that the module doesn't check for approval like the functions in the facet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, added a @dev notice on both burn and burnBatch
clarifying that the module skips approval checks — callers should
use the facet if approval enforcement is needed.

Copy link
Collaborator

@maxnorm maxnorm Mar 7, 2026

Choose a reason for hiding this comment

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

I'm not sure about "Use the facet for approval-checked burns.". More like "Ensure proper ownership or approval validation before calling this function."

The use of module is to extend default behavior inside your own facet, so use facet isn't suited. What do you think?

After that, i think it's ready to merge

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh right!! my bad

@maxnorm maxnorm marked this pull request as ready for review March 7, 2026 19:00
@maxnorm
Copy link
Collaborator

maxnorm commented Mar 7, 2026

Thanks for the great work as always!

@maxnorm maxnorm merged commit 83d238e into Perfect-Abstractions:main Mar 7, 2026
1 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Refactor ERC1155

2 participants