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

Add ERC20 compatibility to ERC777. #1735

Merged
merged 17 commits into from
May 8, 2019
Merged

Conversation

nventuro
Copy link
Contributor

Fixes #1731.

Our ERC20 implementation has internal functions for _mint, _transfer, _burn and _approve, but I did not include any of these here to keep the API small for now. Note that we do have a _mint function, but it performs ERC777 minting (i.e. it requires a recipient contract to implement the token recipient interface).

Should we also add the functions to increase and decrease allowance?

@nventuro nventuro added feature New contracts, functions, or helpers. contracts Smart contract code. labels Apr 30, 2019
@nventuro nventuro added this to the v2.3 milestone Apr 30, 2019
@nventuro nventuro marked this pull request as ready for review April 30, 2019 22:18
@nventuro nventuro requested a review from frangio April 30, 2019 22:18
@catageek
Copy link
Contributor

catageek commented May 5, 2019

Hi, I made a quick review of the contract, see my comments above. What do you think about implementing ERC20 compatibility as a switchable feature ? What if someone does not want ERC20 compatibility ?

@nventuro
Copy link
Contributor Author

nventuro commented May 6, 2019

Thank you @frangio and @catageek for the review!

What do you think about implementing ERC20 compatibility as a switchable feature ? What if someone does not want ERC20 compatibility?

We thought about this and decided it'd be best to have support by default (which has the nice side effect of greatly simplifying the implementation). I'm not sure why someone would not want to have ERC20 support, but we can add a contract that removes it by having all of the ERC20 functions (transfer, approve, etc.) revert when called.


@frangio I'm considering getting rid of the granularity bit and hardcoding it to 1, which will both make the code simpler and cheaper by removing unnecessary requires, but also simplify the constructor. As of now, creating an ERC777 requires understanding what granularity is.

The spec says:

Most of the tokens SHOULD be fully partition-able. I.e., this function SHOULD return 1 unless there is a good reason for not allowing any fraction of the token.

WDYT?

@nventuro
Copy link
Contributor Author

nventuro commented May 6, 2019

Hm, coverage decreased due to a require in approve that is correct, but can never be triggered by the contract as-is. approve used to be internal in ERC20, and was therefore more testeable. @frangio what do?

contracts/drafts/ERC777/ERC777.sol Outdated Show resolved Hide resolved
test/drafts/ERC777/ERC777.test.js Outdated Show resolved Hide resolved
test/drafts/ERC777/ERC777.test.js Outdated Show resolved Hide resolved
@frangio
Copy link
Contributor

frangio commented May 6, 2019

What do you think about implementing ERC20 compatibility as a switchable feature?

I'm considering getting rid of the granularity bit and hardcoding it to 1

In both of these cases I think for now we should target only the most common use cases. This means ERC20 support built-in, and granularity hardcoded to 1. However, I'd like to understand what a future API would look like if we ever decide to: 1) implement support for opting out of ERC20 compatibility, and 2) opting in to a different granularity.

@frangio
Copy link
Contributor

frangio commented May 6, 2019

Should we also add the functions to increase and decrease allowance?

I think so, yes. Why not?

@frangio
Copy link
Contributor

frangio commented May 6, 2019

@nventuro and I looked into the potential future API for opting out of ERC20 support and in to granularity.

We saw that we can put the ERC777 implementation alone in its own contract and, as long as we provide an internal _transfer function that does not call the recipient hook, it's possible to implement ERC20 compatibility on top of it with inheritance.

The same for granularity because it's just adding a couple require checks on internal functions.

@nventuro
Copy link
Contributor Author

nventuro commented May 7, 2019

I've commented out the offending require statement, that should be it for this PR. I'll remove the granularity in a separate one, to make reverting that change easier once (if) we add opt-in support for it.

@frangio
Copy link
Contributor

frangio commented May 8, 2019

Just a thought... what do you think about adding a pending test (i.e. empty it) for the approve check that's missing coverage?

@nventuro
Copy link
Contributor Author

nventuro commented May 8, 2019

Not sure what you mean, calling a public function on the mock that calls the non-existent internal function? What would be the point?

frangio
frangio previously approved these changes May 8, 2019
Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

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

LGTM!

contracts/drafts/ERC777/ERC777.sol Outdated Show resolved Hide resolved
contracts/drafts/ERC777/ERC777.sol Outdated Show resolved Hide resolved
Co-Authored-By: nventuro <nicolas.venturo@gmail.com>
Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you @nventuro and @catageek!

@nventuro nventuro merged commit aa4c9fe into OpenZeppelin:master May 8, 2019
@nventuro nventuro deleted the erc777-erc20 branch May 8, 2019 16:13
nventuro added a commit that referenced this pull request May 8, 2019
* Add ERC20 compatibility.

* Reusing ERC20 tests for ERC777.

* Improve documentation.

* Add changelog entry.

* Improved ERC20 behavior tests.

* Add revert reasons to ERC777.

* ERC20 methods allow sending tokens to contracts with no interface.

* Register ERC20 interface.

* Add comment about avoidLockingTokens.

* Improve revert reason string.

* Make ERC777 implement IERC20.

* Fix test revert string.

* Remove unnecesary require.

* Add private _transfer.

* Update contracts/drafts/ERC777/ERC777.sol

Co-Authored-By: nventuro <nicolas.venturo@gmail.com>

* Update private helper names.

(cherry picked from commit aa4c9fe)
@frantino199

This comment was marked as spam.

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.

Add backwards compatilibty with ERC20 for ERC777
4 participants