input-output-hk / marlowe-ts-sdk

Marlowe TypeScript SDK
https://marlowe.iohk.io/
Apache License 2.0
21 stars 10 forks source link

Helper function to parseADA to Lovelace #163

Open nhenin opened 5 months ago

nhenin commented 5 months ago

Discussed in https://github.com/input-output-hk/marlowe-ts-sdk/discussions/143

Originally posted by **nstanford5** December 21, 2023 Most DApps will present users with the ability to input token amounts to a UI component. Users typically think in terms of ADA amounts, but we need to send Lovelace amounts to the blockchain. Should the SDK include a simple helper function to `parseADA` to Lovelace? Something like.. `const parseADA = (num: number) => { return num * 1000000; };` On the other side of that, when querying the blockchain for amounts -- it will return Lovelace that needs to be formatted to ADA to present to users. Should we also include a `formatLovelace` function?
hrajchert commented 5 months ago

As I responded in the discussion, I believe this should be part of a bigger thing that we can call TemplateParameters/ContractScheme/etc that is similar to the Marlowe Extended feature.

This could allow us to define a DSL for contract parameters with assertions (amount > x, deadline 1 > deadline 2, etc), with a human description (that can help us with Marlowe to english explainer) and with a proper serialization mechanism so we can simplify this type of code.

The proposed function parseADA is misleading as it is not parsing anything, it could be called lovelaceToAda, but multiplying a number for 1 Million is trivial and does not belong in the SDK IMO.