3

adaOf encodes Lovelace/Ada ratio in phantom type Micro

adaOf :: Micro -> Ada
type Micro = Fixed E6
newtype Fixed (a :: k) = MkFixed Integer

Question: Being that the ratio is already encoded in the type, can I somehow get it, such that I can have a function that takes actual Ada token quantity -- not Lovelace quantity -- and gives back Ada, without hardcoding?

f :: Integer -> Ada
f adaQty = Lovelace (1_000_000 * n) -- don't really want to do this

I actually found the constant in the plutus repo:

lovelacePerAda = Constant 1000000
1
  • That constant you found probably isn't the one to use, since it's in the Marlowe libraries. Why are you interested in denominating in major units in your Plutus code? I could see the need in your UI. Aug 18 at 21:49
3

Use adaOf

In a GHCi session with plutus-ledger-api in scope:

> import Plutus.V1.Ledger.Ada
> adaOf 1
Lovelace {getLovelace = 1000000}
1
  • Great! So that constant I found in Marlowe appears to be a mistake, because it is introducing a second source-of-truth.
    – Kwaggy
    Aug 22 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.