solana-program-library
solana-program-library copied to clipboard
token-cli: Minting more than `u64::MAX` tokens leads to confusing behavior
Here are devnet transactions:
$ spl-token create-token --decimals 18
Creating token BZk67G7gcKquWXAgoTDoKqe78xwkSQiF4thsqYkHshJd
Signature: XioHUWB36xfCT97iPsQhugHnN39obq4UxPp9m7d5oc7fYfmcoa4DGs7wvbFsw1zijkXcr6LkHZ7yQLHr1befSVi
$ spl-token mint BZk67G7gcKquWXAgoTDoKqe78xwkSQiF4thsqYkHshJd 1000
Minting 1000 tokens
$ spl-token supply BZk67G7gcKquWXAgoTDoKqe78xwkSQiF4thsqYkHshJd
18.446744073709551615
Similar commands work fine with other tokens that have less decimal digits.
Can we make the token amount a u128 in the program? Why is it currently a u64?
Is there a reason the token program allows creating Mint accounts with 18 decimals? The supply being an u64 does not leave too much room for practical application of such a token.
I am trying to ming token with decimal 18 and total supply 100,000,000,000. command is not working correctly. There is a same issue!
I am trying to ming token with decimal 18 and total supply 100,000,000,000. command is not working correctly. There is a same issue!
As mentioned above, the token supply is implemented as a u64. It can represent at most 18,446,744,073,709,551,615 base units, so if you want 100B total supply, the largest decimals you can use is 8
Seems like as a start, the CLI could error by default if you're trying to mint more than the max supply, with some sort of yolo flag to get rid of the check if someone wants to overmint. And at least print a correct message.
Made a pull request to fix this issue: https://github.com/solana-labs/solana-program-library/pull/3275
Does this issue still need to be worked on?
My understanding is that specifying --decimals x means that the base unit of the token is $\mathbf{10^{-x}}$, which means 1 token is made up of $\mathbf{10^{x}}$ base units. Let $\mathbf{T}$ denote the max tokens that can be minted. We get $\mathbf{2^{64} - 1 = T \times 10^{x}}$, which gives us $\mathbf{T = \frac{2^{64} - 1}{10^{x} } }$. Is my understanding correct?
The command with decimals is working well on current version!
The confusing behavior is still there unfortunately. You can "over-mint" tokens with the "mint" command, try running the commands in the first post and you'll see that you only get 18.44... tokens even though you ask to mint 1000