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

Initial ERC1155 implementation with some tests #1803

Merged
merged 19 commits into from
Nov 3, 2019

Conversation

cag
Copy link
Contributor

@cag cag commented Jun 18, 2019

Fixes #1728

Implements ERC-1155.

@nventuro
Copy link
Contributor

Hello @cag, thank you very much for this! Reviewing this PR will probably take a while, since there's quite a bit of code, and we need to figure out a reasonable API to provide.

I noticed the implementation by enjin is licensed under Apache v2, whereas we use MIT. We may want to check with them that it is fine to re-license their work to distribute under OpenZeppelin, though I'm not sure to what extent that applies to something like this, where the specification is quite clear-cut regarding what needs to be done.

@nventuro nventuro requested a review from frangio June 19, 2019 00:37
@stale
Copy link

stale bot commented Jul 4, 2019

Hi all!
This Pull Request has not had any recent activity, is it still relevant? If so, what is blocking it? Is there anything we can do to help move it forward?
Thanks!

@stale stale bot added the stale label Jul 4, 2019
@frangio
Copy link
Contributor

frangio commented Jul 4, 2019

Hey there. It's taking a while for me to get some free time to look at this, but I'll come back to it.

@stale stale bot removed the stale label Jul 4, 2019
@stale
Copy link

stale bot commented Jul 20, 2019

Hi all!
This Pull Request has not had any recent activity, is it still relevant? If so, what is blocking it? Is there anything we can do to help move it forward?
Thanks!

@stale stale bot added stale and removed stale labels Jul 20, 2019
@cag cag marked this pull request as ready for review July 23, 2019 21:53
@cag
Copy link
Contributor Author

cag commented Jul 23, 2019

Okay, the tests should be complete for the basic setup now. Cheers!

@The18thWarrior
Copy link

Any update on this PR? I would like to leverage OpenZepplin in my build, but can't stay on hold indefinitely.

@frangio
Copy link
Contributor

frangio commented Aug 7, 2019

We're in the process of reviewing this. 🙂 Expect a review from @andresbach from the OpenZeppelin team in a few days!

@The18thWarrior
Copy link

The18thWarrior commented Aug 7, 2019 via email

@stale
Copy link

stale bot commented Aug 22, 2019

Hi all!
This Pull Request has not had any recent activity, is it still relevant? If so, what is blocking it? Is there anything we can do to help move it forward?
Thanks!

@stale stale bot added the stale label Aug 22, 2019
@stale
Copy link

stale bot commented Sep 6, 2019

Hi folks!
This Pull Request is being closed as there was no response to the previous prompt. However, please leave a comment whenever you're ready to resume, so it can be reopened.
Thanks again!

@stale stale bot closed this Sep 6, 2019
@andresbach andresbach reopened this Sep 17, 2019
@stale stale bot removed the stale label Sep 17, 2019
Copy link
Member

@andresbach andresbach left a comment

Choose a reason for hiding this comment

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

Hey @cag! So sorry for the delay. I left a few comments on things that @frangio and I agreed should be changed, and also a couple questions of other things we might want to add.

contracts/token/ERC1155/ERC1155.sol Outdated Show resolved Hide resolved
contracts/token/ERC1155/ERC1155.sol Outdated Show resolved Hide resolved
contracts/token/ERC1155/ERC1155.sol Show resolved Hide resolved
contracts/token/ERC1155/ERC1155.sol Show resolved Hide resolved
contracts/token/ERC1155/ERC1155.sol Outdated Show resolved Hide resolved
contracts/token/ERC1155/ERC1155.sol Show resolved Hide resolved
contracts/token/ERC1155/ERC1155.sol Show resolved Hide resolved
contracts/token/ERC1155/ERC1155.sol Show resolved Hide resolved
* See https://eips.ethereum.org/EIPS/eip-1155
* Originally based on code by Enjin: https://github.com/enjin/erc-1155
*/
contract ERC1155 is ERC165, IERC1155
Copy link
Member

Choose a reason for hiding this comment

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

Some of the contracts are missing, such as the one for the metadata and the one for the URI functions. Are those going to be implemented in another stage?

Copy link
Contributor Author

@cag cag Oct 4, 2019

Choose a reason for hiding this comment

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

I did not seek to implement those contracts, since we don't know how these features really should work because we don't use them, and didn't plan on using them. These should be added by somebody with more knowledge/use for those features.

contracts/token/ERC1155/ERC1155.sol Outdated Show resolved Hide resolved
@frangio frangio removed their request for review September 18, 2019 17:25
@stale
Copy link

stale bot commented Oct 3, 2019

Hi all!
This Pull Request has not had any recent activity, is it still relevant? If so, what is blocking it? Is there anything we can do to help move it forward?
Thanks!

@stale stale bot added the stale label Oct 3, 2019
@abcoathup
Copy link
Contributor

I’ve reached out to the authors of ERC1155 as would be great to get their assistance.

@stale stale bot removed the stale label Oct 4, 2019
@thecryptofruit
Copy link

SafeMath.sub with custom error message is not yet released AFAIK, not in 2.3 at least.

@nventuro nventuro added contracts Smart contract code. feature New contracts, functions, or helpers. labels Oct 18, 2019
@nventuro nventuro self-assigned this Oct 18, 2019
@stale
Copy link

stale bot commented Nov 2, 2019

Hi all!
This Pull Request has not had any recent activity, is it still relevant? If so, what is blocking it? Is there anything we can do to help move it forward?
Thanks!

@stale stale bot added the stale label Nov 2, 2019
@frangio
Copy link
Contributor

frangio commented Nov 3, 2019

Hi everyone. We haven't had the time to do a second review of the code in this PR, which is something we have to do for such a big feature before releasing it.

However, we don't want to delay merging this PR any longer so we're merging it into a feature branch. If you're interested in getting this feature released as soon as possible, please help us by reviewing the code and posting your results in an issue or in the forum. We will also be doing our own review and may create an issue with a list of things that need work, where help will also be appreciated.

Sorry for taking so long with this and thank you for the great work @cag!

@stale stale bot removed the stale label Nov 3, 2019
@frangio frangio changed the base branch from master to feature-erc1155 November 3, 2019 01:20
@frangio frangio merged commit 20642cc into OpenZeppelin:feature-erc1155 Nov 3, 2019
@coinfork
Copy link

Hello @cag, thank you very much for this! Reviewing this PR will probably take a while, since there's quite a bit of code, and we need to figure out a reasonable API to provide.

I noticed the implementation by enjin is licensed under Apache v2, whereas we use MIT. We may want to check with them that it is fine to re-license their work to distribute under OpenZeppelin, though I'm not sure to what extent that applies to something like this, where the specification is quite clear-cut regarding what needs to be done.

We're completely fine with re-licensing your implementation with the MIT license.

@KaiRo-at
Copy link
Contributor

I'm trying to use the contracts for a project right now, and I just realized that - compared to other OpenZeppelin token implementations - there is no internal _transferFrom() function (or similar) in those, which makes it harder for us to override something so we can intercept a transfer and e.g. maintain a "totalSupply"-like counter when something is transferred to/from 0x0, or put some restrictions on transfers via custom logic or similar side-effects - and the external public unctions do not allow overrides that call the inherited code via super.safeTransferFrom(), for example.
This is one case where an implementation in OpenZeppelin probably requires some additional work than just a (reference) implementation, so people can inherit from this code and flexibly extend it.

@frangio
Copy link
Contributor

frangio commented Nov 19, 2019

@KaiRo-at Agree! Would you like to open a PR making the functions public?

@KaiRo-at
Copy link
Contributor

I think it would be even better to abstract the actual transfer into an internal function like e.g. ERC20 and ERC721 OpenZeppelin implementations do. They also have the beauty of having a single internal function for all variants of transfers, which is harder here as single and batch emit different events, so I'm not 100% sure yet how to do this in the best way.

@frangio frangio mentioned this pull request Nov 19, 2019
@frangio
Copy link
Contributor

frangio commented Nov 19, 2019

@KaiRo-at Let's continue this discussion in #2003.

@frangio frangio mentioned this pull request Dec 2, 2019
6 tasks
@KaiRo-at
Copy link
Contributor

KaiRo-at commented Dec 13, 2019

Another thing I just noticed is that this PR contains a URI() event in the interface, but nothing using it or anything else related to URIs, so either the event should be removed or the implementation using it some way. Though actually, this may be a bug in the ERC itself, as that even should belong to the "interface ERC1155Metadata_URI" definition in there, I guess... See ethereum/EIPs#1155 (comment)

@frangio
Copy link
Contributor

frangio commented Dec 13, 2019

Thank you @KaiRo-at. Please move all related discussion to #2014. 🙂

KaiRo-at pushed a commit to KaiRo-at/openzeppelin-contracts that referenced this pull request Mar 16, 2020
* Initial ERC1155 implementation with some tests

* Remove mocked isERC1155TokenReceiver

* Revert reason edit nit

* Remove parameters associated with isERC1155TokenReceiver call

* Add tests for approvals and single transfers

* Add tests for transferring to contracts

* Add tests for batch transfers

* Make expectEvent.inTransaction tests async

* Renamed "owner" to "account" and "holder"

* Document unspecified balanceOfBatch reversion on zero behavior

* Ensure accounts can't set their own operator status

* Specify descriptive messages for underflow errors

* Bring SafeMath.add calls in line with OZ style

* Explicitly prevent _burn on the zero account

* Implement batch minting/burning

* Refactored operator approval check into isApprovedForAll calls

* Renamed ERC1155TokenReceiver to ERC1155Receiver

* Added ERC1155Holder

* Fix lint issues
KaiRo-at pushed a commit to KaiRo-at/openzeppelin-contracts that referenced this pull request Mar 16, 2020
* Initial ERC1155 implementation with some tests

* Remove mocked isERC1155TokenReceiver

* Revert reason edit nit

* Remove parameters associated with isERC1155TokenReceiver call

* Add tests for approvals and single transfers

* Add tests for transferring to contracts

* Add tests for batch transfers

* Make expectEvent.inTransaction tests async

* Renamed "owner" to "account" and "holder"

* Document unspecified balanceOfBatch reversion on zero behavior

* Ensure accounts can't set their own operator status

* Specify descriptive messages for underflow errors

* Bring SafeMath.add calls in line with OZ style

* Explicitly prevent _burn on the zero account

* Implement batch minting/burning

* Refactored operator approval check into isApprovedForAll calls

* Renamed ERC1155TokenReceiver to ERC1155Receiver

* Added ERC1155Holder

* Fix lint issues
nventuro added a commit that referenced this pull request May 8, 2020
* Initial ERC1155 implementation with some tests (#1803)

* Initial ERC1155 implementation with some tests

* Remove mocked isERC1155TokenReceiver

* Revert reason edit nit

* Remove parameters associated with isERC1155TokenReceiver call

* Add tests for approvals and single transfers

* Add tests for transferring to contracts

* Add tests for batch transfers

* Make expectEvent.inTransaction tests async

* Renamed "owner" to "account" and "holder"

* Document unspecified balanceOfBatch reversion on zero behavior

* Ensure accounts can't set their own operator status

* Specify descriptive messages for underflow errors

* Bring SafeMath.add calls in line with OZ style

* Explicitly prevent _burn on the zero account

* Implement batch minting/burning

* Refactored operator approval check into isApprovedForAll calls

* Renamed ERC1155TokenReceiver to ERC1155Receiver

* Added ERC1155Holder

* Fix lint issues

* Migrate tests to @openzeppelin/test-environment

* Port ERC 1155 branch to Solidity 0.6 (and current master) (#2130)

* port ERC1155 to Solidity 0.6

* make ERC1155 constructor more similar to ERC721 one

* also migrate mock contracts to Solidity 0.6

* mark all non-view functions as virtual

Co-authored-by: Alan Lu <[email protected]>
Co-authored-by: Nicolás Venturo <[email protected]>
Co-authored-by: Robert Kaiser <[email protected]>
nventuro added a commit that referenced this pull request Jun 3, 2020
…2029)

* Initial ERC1155 implementation with some tests (#1803)

* Initial ERC1155 implementation with some tests

* Remove mocked isERC1155TokenReceiver

* Revert reason edit nit

* Remove parameters associated with isERC1155TokenReceiver call

* Add tests for approvals and single transfers

* Add tests for transferring to contracts

* Add tests for batch transfers

* Make expectEvent.inTransaction tests async

* Renamed "owner" to "account" and "holder"

* Document unspecified balanceOfBatch reversion on zero behavior

* Ensure accounts can't set their own operator status

* Specify descriptive messages for underflow errors

* Bring SafeMath.add calls in line with OZ style

* Explicitly prevent _burn on the zero account

* Implement batch minting/burning

* Refactored operator approval check into isApprovedForAll calls

* Renamed ERC1155TokenReceiver to ERC1155Receiver

* Added ERC1155Holder

* Fix lint issues

* Migrate tests to @openzeppelin/test-environment

* port ERC1155 to Solidity 0.6

* make ERC1155 constructor more similar to ERC721 one

* also migrate mock contracts to Solidity 0.6

* mark all non-view functions as virtual

* add simple catch-all implementation for the metadata URI interface

* include an internal function to set the URI so users can implement functionality to switch URIs

* add tests for ERC1155 metadata URI

* fix nits, mostly pointed out by linter

* convert ERC1155 metadata URI work to Solidity 0.6

* mark all non-view functions as virtual

* Port ERC 1155 branch to Solidity 0.6 (and current master) (#2130)

* port ERC1155 to Solidity 0.6

* make ERC1155 constructor more similar to ERC721 one

* also migrate mock contracts to Solidity 0.6

* mark all non-view functions as virtual

* Update contracts/token/ERC1155/IERC1155MetadataURI.sol

Starting on Solidity v0.6.2, interfaces can now inherit. \o/

Co-authored-by: Nicolás Venturo <[email protected]>

* Fix compile errors

* Remove URI event

* Merge MetadataCatchAll into ERC1155

* Improve documentation.

* Simplify tests

* Move tests into ERC1155 tests

* Update documentation

* Bump minimum compiler version for inteface inheritance

* Fix holder tests

* Improve setUri docs

* Fix docs generation

Co-authored-by: Alan Lu <[email protected]>
Co-authored-by: Nicolás Venturo <[email protected]>
Co-authored-by: Francisco Giordano <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contracts Smart contract code. feature New contracts, functions, or helpers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants