-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Assumed decimals must be 18 #2613
Comments
Hi @vittominacori, Thanks for the feedback, it is really appreciated. We can override The project owner will review your feedback as soon as they can. Please wait until we have discussed this idea before writing any code or submitting a Pull Request, so we can go through the design beforehand. We don’t want you to waste your time! |
Yes I know that we can override but it is introducing lot of stuff. If I would like to set decimals in construction basically I should replicate the old _setupDecimals behavior. Also if you override this method, any other derived contract must override too in order to avoid |
Hi @vittominacori, your feedback is appreciated. I'll reply to each of your points separately.
What we're assuming is that 18 decimals is the most common value. We're not ignoring that someone might want to change the decimals value, but the way to do this is now to override the function.
Around 20k gas cheaper (22k with Berlin hardfork changes). This is around 1% of deployment cost. It also reduces bytecode size and overall deployment cost, but I don't have the exact numbers on this.
Because there is no standard value for
Can you give an example about this? What I can think of is that if you define a contract |
Hello thanks for your reply. Yes, I mean that having that contract abstract contract ERC20WithDecimals is ERC20 {
uint8 immutable private _decimals;
constructor (uint8 decimals_) {
_decimals = decimals_;
}
function decimals() public view virtual override returns (uint8) {
return _decimals;
}
} and the derived one contract DerivedERC20 is ERC20, ERC20WithDecimals {
constructor (
string memory name_,
string memory symbol_,
uint8 decimals_
)
ERC20(name_, symbol_)
ERC20WithDecimals(decimals_)
{}
} we will have the following error
|
In this particular case, you can make the following change to get rid of that error: -contract DerivedERC20 is ERC20, ERC20WithDecimals {
+contract DerivedERC20 is ERC20WithDecimals { This fix might not work with more complex inheritance lists. |
Yes it was an example taken from your reply :) It doesn't solve if I have something like this. contract DerivedERC20 is ERC20Burnable, ERC20WithDecimals {
constructor (
string memory name_,
string memory symbol_,
uint8 decimals_
)
ERC20(name_, symbol_)
ERC20WithDecimals(decimals_)
{}
} |
I'm going to close this, as it was a design decision we made based on the fact that the vast majority of ERC20 tokens have 18 decimals. We recognize that there is now more friction to define a different decimals number, but it is definitely still possible to do so. |
You are assuming here that decimals must be 18.
Also if this is true for most of the token and I always use 18, there are lot of tokens using 2, 6, 8 or other numbers.
How much is token deployment cheaper having decimals not stored? And is it so important to reduce gas in reading slot on a view method like
decimals()
?At this point, why we are not reducing gas on
name
andsymbol
the same way we are doing fordecimals
?I think a library should be more extensible and not take decisions on business logic.
In v4.0.0 there is the try to "save" some point of gas by introducing complexity for end users or breaking some first days logic (like the impossibility to check cap during construction #2580).
The text was updated successfully, but these errors were encountered: