45b ADA limit - how is it achieved in code?

Just exploring the codebase. It took me a while to find these lines below and I am not even sure if they are the ones that limit the ADA supply.

Can somebody with good understanding of Cardano point me at the direction of where is the limit of 45b of ADA coming from?

And whether or not these line below have anything to do with that?

maxCoinVal :: Word64
maxCoinVal = 45000000000000000

-- | Makes a 'Coin' but is _|_ if that coin exceeds 'maxCoinVal'.
-- You can also use 'checkCoin' to do that check.
mkCoin :: Word64 -> Coin
mkCoin c = either error (const coin) (checkCoin coin)
  where
    coin = (Coin c)
{-# INLINE mkCoin #-}

checkCoin :: MonadError Text m => Coin -> m ()
checkCoin (Coin c)
    | c <= maxCoinVal = pure ()
    | otherwise       = throwError $ "Coin: " <> show c <> " is too large"

-- | Coin formatter which restricts type.

Thank you in advance.

Yes, you have found exactly where that limit is set.

1 Like