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 internal overrideable _flashFee in ERC20FlashMint #3551

Merged
merged 14 commits into from Jul 22, 2022
Merged

Add internal overrideable _flashFee in ERC20FlashMint #3551

merged 14 commits into from Jul 22, 2022

Conversation

nirban256
Copy link
Contributor

@nirban256 nirban256 commented Jul 15, 2022

Fixes #3331

added internal _flashFee function

added the function so that instead of flashFee function the _flashFee function can be overridden inside the ERC20FlashMint contract

PR Checklist

  • Tests
  • Documentation

@Amxx
Copy link
Collaborator

Amxx commented Jul 15, 2022

Hello @nirban256

I'm really puzzeled by this design.

    function flashFee(address token, uint256 amount) public view virtual override returns (uint256) {
        require(token == address(this), "ERC20FlashMint: wrong token");
        // silence warning about unused variable without the addition of bytecode.
        amount;
        return 0;
    }
    function _flashFee(address token, uint256 amount) internal view virtual returns (uint256) {
        uint256 fee = flashFee(token, amount);
        return fee;
    }

What are dev supposed to override? If you override the public one, you risk losing the require. If you override the internal, you risk having an inconsistency between the public value and the value used.

@Amxx
Copy link
Collaborator

Amxx commented Jul 15, 2022

Maybe what we want is

    function flashFee(address token, uint256 amount) public view virtual override returns (uint256) {
        require(token == address(this), "ERC20FlashMint: wrong token");
        return _flashFee(token, amount);
    }
    function _flashFee(address token, uint256 amount) internal view virtual returns (uint256) {
        // silence warning about unused variable without the addition of bytecode.
        token;
        amount;
        return 0;
    }

@nirban256
Copy link
Contributor Author

Ok I will change this to this new implementation shortly

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.

Please update ERC20FlashMintMock to override _flashFee instead of flashFee like it does currently.

CHANGELOG.md Outdated Show resolved Hide resolved
@frangio
Copy link
Contributor

frangio commented Jul 19, 2022

My previous comment hasn't been addressed yet:

Please update ERC20FlashMintMock to override _flashFee instead of flashFee like it does currently.

It refers to the mock contract used for testing.

@nirban256
Copy link
Contributor Author

Sir I have pushed a commit, let me know what are the changes required.

@frangio frangio changed the title added internal _flashFee without validation to ERC20FlashMint Add internal overrideable _flashFee in ERC20FlashMint Jul 21, 2022
frangio
frangio previously approved these changes Jul 21, 2022
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.

Thanks!

@frangio frangio enabled auto-merge (squash) July 21, 2022 16:03
@nirban256
Copy link
Contributor Author

do I need to do anything more in order to complete this pull request? @frangio

@frangio frangio disabled auto-merge July 22, 2022 17:43
@frangio frangio merged commit d1b1e17 into OpenZeppelin:master Jul 22, 2022
@nirban256 nirban256 deleted the fix/internal-flashFee-#3331 branch July 22, 2022 17:48
ronhuafeng added a commit to ronhuafeng/openzeppelin-contracts that referenced this pull request Sep 9, 2022
)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: Francisco <frangio.1@gmail.com>
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.

Add internal _flashFee without validation to ERC20FlashMint
3 participants