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

Inherit asset decimals in ERC4626 #3639

Merged
merged 17 commits into from Aug 26, 2022
Merged

Conversation

Amxx
Copy link
Collaborator

@Amxx Amxx commented Aug 19, 2022

Inherit the decimal value from the asset (if any) while still supporting customization on top of ERC4626

Fixes #3549

PR Checklist

  • Tests
  • Changelog entry

@Amxx Amxx marked this pull request as ready for review August 19, 2022 16:27
@Amxx
Copy link
Collaborator Author

Amxx commented Aug 22, 2022

The current tests already check decimal overriding.

We don't have a test where the fallback is done. Will work on that.

@Amxx
Copy link
Collaborator Author

Amxx commented Aug 23, 2022

Testing should be good now

contracts/token/ERC20/extensions/ERC4626.sol Outdated Show resolved Hide resolved
contracts/mocks/ERC4626Mock.sol Outdated Show resolved Hide resolved
@frangio
Copy link
Contributor

frangio commented Aug 24, 2022

This is an improvement over the status quo because it will work for tokens with no decimals. However, one of the points raised in #3549 was:

Even if both tokens expose decimals the method is for usability, not for onchain calculations.

I find this pretty compelling, but to stop using decimals in the conversion functions would be a breaking change now...

From #3549 (comment):

What are the _initialConvertToXxx for. They make the code more complexe, and I don't see a reason for that.

The reason for those functions was to define conversion without reference to the decimals values.

@Amxx
Copy link
Collaborator Author

Amxx commented Aug 24, 2022

Initial conversion function added. They are tests trough our current test suite (that checks decimals mismatch).

Need a breaking change description

contracts/token/ERC20/extensions/ERC4626.sol Outdated Show resolved Hide resolved
contracts/token/ERC20/extensions/ERC4626.sol Outdated Show resolved Hide resolved
contracts/token/ERC20/extensions/draft-IERC20Permit.sol Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
contracts/token/ERC20/extensions/ERC4626.sol Outdated Show resolved Hide resolved
@Amxx Amxx requested a review from frangio August 25, 2022 14:27
@frangio
Copy link
Contributor

frangio commented Aug 25, 2022

I changed the variable name in the constructor which was assetDecimals, because in the catch branch those are expressly not the asset's decimals. If you agree with this let's merge.

@Amxx Amxx merged commit 141130d into OpenZeppelin:master Aug 26, 2022
@Amxx Amxx deleted the fix/erc4626/decimals branch August 26, 2022 07:53
ronhuafeng added a commit to ronhuafeng/openzeppelin-contracts that referenced this pull request Sep 9, 2022
JulissaDantes pushed a commit to JulissaDantes/openzeppelin-contracts that referenced this pull request Nov 3, 2022
JulissaDantes pushed a commit to JulissaDantes/openzeppelin-contracts that referenced this pull request Nov 4, 2022
@alexflorence
Copy link

alexflorence commented Nov 30, 2022

this breaks upgradability from previous implementations to some extent because the initializer is not called on upgrading and therefore_decimals is never set. so decimals() needs to be overridden with a hardcoded value instead of calling super.decimals()

@frangio
Copy link
Contributor

frangio commented Nov 30, 2022

@alexflorence This is a good point we didn't notice. It's solved by calling the initializer though in a function like this:

function migrateToV48() public reinitializer(2) {
    __ERC4626_init(asset);
}

We should add a note in the changelog for this.

We can consider defaulting to super.decimals if the stored decimals are 0 too.

@alexflorence Let us know your thoughts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reduce reliance on underlying decimals in ERC4626
3 participants