-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Migrate Contracts to Solidity v0.6 #2080
Conversation
* Initial migration, missing GSN, 721, 777 and Crowdsales. * Add _beforeTokenOperation and _afterTokenOperation. * Add documentation for hooks. * Add hooks doc * Add missing drafts * Add back ERC721 with hooks * Bring back ERC777 * Notes on hooks * Bring back GSN * Make functions virtual * Make GSN overrides explicit * Fix ERC20Pausable tests * Remove virtual from some view functions * Update linter
We won't have a test coverage report until sc-forks/solidity-coverage#464 is fixed, sadly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nventuro quite a large PR! Looks good (as good as an inspection over 201 changed files can go in a single sitting), but I have a comment about the beforeApproval
hooks.
Right now, they are being called in two very different scenarios: 1) when the owner of the asset manually sets an approval, and 2) when it is decremented due to an action (such as a transferFrom
). And it is not possible to determine, from within the hook, which case it is.
I checked the uses of beforeApproval
within the library, and found only pausable
. For this, only the first usage of the hook is actually needed, since the second one is covered by the beforeTransfer
hook which also checks for the paused state. Thinking a bit more, if one wanted to implement a pause all approvals behaviour, then it would make sense to only pause 1), and not 2) - which is not possible to do today.
So, the conclusion of this rambling is: shouldn't we rename beforeApproval
to beforeSetApproval
, and only call it in the methods where approval is actually changed?
Thanks for the review! You raise an interesting point, we should definitely be clear about what hooks mean. Keep in mind Contracts features internal functions like The current hook behavior is quite generic and allows to react to all changes to the allowance, which is IMO a more powerful primitive: if what you want is to prevent users from calling approve, then the natural place to do it is at the |
if what you want is to prevent users from calling approve, then the
natural place to do it is at the approve external function.
What do you think about removing the `beforeApprove` hooks then, and
implement pausable like this?
…On Fri, Feb 7, 2020 at 5:34 PM Nicolás Venturo ***@***.***> wrote:
Thanks for the review! You raise an interesting point, we should
definitely be clear about what hooks mean.
Keep in mind Contracts features internal functions like _approve, which
can be called arbitrarily by the contract (imagine some sort of signup
during which a contract gives itself infinite allowance over the user's
tokens). This means approve and transferFrom are *not* the only possible
triggers for allowance changes.
The current hook behavior is quite generic and allows to react to *all
changes to the allowance*, which is IMO a more powerful primitive: if
what you want is to prevent users from calling approve, then the natural
place to do it is at the approve external function.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#2080?email_source=notifications&email_token=AADI4JG4GMRXR5IFTPZBC3LRBXAWTA5CNFSM4KRCDBV2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELEQGIY#issuecomment-583598883>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADI4JGKUN74CXPSD2M5AYLRBXAWTANCNFSM4KRCDBVQ>
.
|
I'm actually considering removing That leaves the question of which hooks we should provide. |
We should be clear the batteries-included contracts are not meant as examples only. They are meant to be used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this work!
Keep in mind all methods are still virtual. We are not sacrificing flexibility, the user can still implement this - only that they will have to explicitly choose which |
Hm, you're right, users can always do e.g. function _approve(...) override {
_beforeApproval();
super._approve();
_afterApproval();
} It wouldn't quite be the same since not all scenarios may be covered (e.g. |
I think I'm with @spalladino on this one. I think we may want to review whether it's a good idea that |
Thanks for the reviews! I've updated the token contracts to remove the allowance and operator hooks, removing also the associated functions from the We'll want to think some more about the conditions that can trigger a hook, and which ones we want to provide initially. |
Thanks @frangio and @spalladino for the reviews! |
@nventuro similar to having ERC20's |
@alexanderatallah Did you mean virtual (as opposed to non-virtual)? |
Closes #2028
This a continuation of #2063, now bringing the
dev-v3.0
branch intomaster
, and the foundation of the v3.0 release. This merge, with perhaps some light edits, should become the v3.0-alpha release.For more information about the v3.0 release, head to our roadmap.
This PR is quite massive, with a lot of noise. Below is a summary of the included changes:
virtual
_before
hooks were added to ERC20, ERC721 and ERC777 to better support custom extensions, and to prevent users from having to manually override too many functions on diamond inheritance patternsRoles
library). Contracts with access control baked-in were either removed (ERC20Mintable), or reduced to internal functions (Pausable
)A couple undesirable side-effects product of the migration are:
balanceOf
andallowance
arevirtual
despite beingview
. This is required forGSNRecipientERC20Fee
companion token contractI'd tackle these in separate PRs (if at all).
Note that these are not all the changes we want to include in v3.0. We're redesigning our Access Control solution and plan to have it implemented for the final release, and will also make some small changes such as removal of deprecated functions.