2

Am building a cosmos-sdk chain and was wondering what the official support was for coin's decimal precision on a cosmos chain either being minted via a peg or seeded via genesis as the primary staking/demon token.

We would like to support 10**18 as this matches ethereum and just want to get clarity on this. Thanks

utx0_
  • 1,364
  • 14
  • 24
  • Hi, have you checked these links regarding issue fixed? [Increasing decimal precision to 18](https://github.com/cosmos/cosmos-sdk/pull/3315) | [Usage of sdk.Decimals for sdk.Coins](https://github.com/cosmos/cosmos-sdk/issues/3251) and the appropriate type for ]Dec_Coin.go](https://github.com/cosmos/cosmos-sdk/blob/master/types/dec_coin.go) – vinipx Jan 18 '21 at 01:02

2 Answers2

1

Coin.Amount used throughout the SDK is an int. There is a DecCoin, but it doesn't seem to be used that much.

Practically speaking, coins are integer values and the upper limit seems to be 10**76 when added to genesis with appd add-genesis-account. However, after the chain has started, having on balance more than 10**76 works fine.

Denis Fadeev
  • 188
  • 1
  • 1
  • 8
  • 1
    Yeah looks like we have actually found an issue in the sdk staking.go code. Have a look at this: https://github.com/cosmos/cosmos-sdk/issues/8357 – utx0_ Jan 18 '21 at 06:23
  • Yep, seems like the limit specifically on staking is much lower. – Denis Fadeev Jan 18 '21 at 06:39
1

The Bank Module and subsequent Coin type contain metadata capabilities that include decimals as outlined in ADR-024-coin-metadata.

The relevant types are as follows:

message DenomUnit {
  string denom    = 1;
  uint32 exponent = 2;  
  repeated string aliases = 3;
}

message Metadata {
  string description = 1;
  repeated DenomUnit denom_units = 2;
  string base = 3;
  string display = 4;
}

And the example of the $ATOM, which has 6 decimals, is given here:

{
  "description": "The native staking token of the Cosmos Hub.",
  "denom_units": [
    {
      "denom": "uatom",
      "exponent": 0,
      "aliases": [
        "microatom"
      ],
    },
    {
      "denom": "matom",
      "exponent": 3,
      "aliases": [
        "milliatom"
      ]
    },
    {
      "denom": "atom",
      "exponent": 6,
    }
  ],
  "base": "uatom",
  "display": "atom",
}
okwme
  • 740
  • 1
  • 7
  • 19