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

Virtual balanceOf in ERC20 #2400

Closed
ebulku opened this issue Nov 3, 2020 · 5 comments
Closed

Virtual balanceOf in ERC20 #2400

ebulku opened this issue Nov 3, 2020 · 5 comments

Comments

@ebulku
Copy link

ebulku commented Nov 3, 2020

🧐 Motivation
I want to use my own logic behind the balanceOf() function for ERC20.

📝 Details
Is there any known issue if I change the balaceOf() in virtual in ERC20.sol

@frangio
Copy link
Contributor

frangio commented Nov 3, 2020

It depends on what you want to override it with. There are potential issues integrating with other contracts when balanceOf returns a dynamic value. I'm not sure if this has been explained anywhere. I couldn't find a link to provide, sorry!

@frangio
Copy link
Contributor

frangio commented Nov 3, 2020

For the general issue of having virtual view functions see #2154.

Closing this issue but let's continue the discussion if you want.

@frangio frangio closed this as completed Nov 3, 2020
@ebulku
Copy link
Author

ebulku commented Nov 4, 2020

@frangio There are cases when the balance is changing over time, and to save costs for transactions you can implement the changed balance dynamically. This usually occurs in DeFi when users are getting interests, or there may be cases when the token holders are awarded extra tokens.

I have seen this implementation in aave: https://github.com/aave/aave-protocol/blob/f7ef52000af2964046857da7e5fe01894a51f2ab/contracts/tokenization/AToken.sol#L338

But they are using an older version of OpenZeppelin to override the balanceOf

@ebulku
Copy link
Author

ebulku commented Nov 17, 2020

@frangio what do you think about this?

@frangio
Copy link
Contributor

frangio commented Nov 18, 2020

@ebulku We're going to add virtual view functions in the next release (see #2154 (comment)). Whether balanceOf will be one of these virtual view functions I'm still not sure. I will try to make it so but there are some caveats (see #2154 (comment)). I've included your request for ERC20.balanceOf in the list of requested virtual functions.

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

No branches or pull requests

2 participants