keefertaylor / TezosKit

TezosKit provides a Swift based toolbox for interacting with the Tezos blockchain
MIT License
67 stars 8 forks source link

FA token support #213

Open simonmcl opened 4 years ago

simonmcl commented 4 years ago

Turns out FA1.2 tokens (and FA2 onwards) do have decimal places even though the specification doesn't require a definition for it. They will follow exactly the same pattern as Tez. They will only be represented by 1 natural number, with a piece of metadata indicating how many decimal places exist. The tokens will have variable decimal places however.

It would be great to have a Tez subclass, or alias that has a configurable decimal place. It should follow all the same logic (e.g. passing in a string will be the rpc representation, passing in a double would be the higher order representation).

Other requirements:

simonmcl commented 4 years ago

Thinking about all this again. Given how tightly integrated the Decimal object is, being able to use currency formatters and all inbuilt iOS functions. It might make more sense to scrap Tez and simply add extensions to Decimal such as

rpcRepresentation(decimalPlaces: Int) -> Decimal {
    return self * pow(10, decimalPlaces)
}

fromRpcRepresentation(rpc: String, decimalPlaces: Int) -> Decimal {
    return Decimal(string: rpc) / pow(10, decimalPlaces)
}

Tez is limited to Int64, so there isn't any advantage to using BigInt there. The only question comes for FA Tokens which are arbitrary length natural numbers. Although I think Decimal may be sufficiently large, for any reasonable usecases