Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FA token support #213

Open
simonmcl opened this issue Jun 10, 2020 · 1 comment
Open

FA token support #213

simonmcl opened this issue Jun 10, 2020 · 1 comment

Comments

@simonmcl
Copy link
Collaborator

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:

  • Being able to multiply Tez and NativeToken if they are separate objects) by a double or Decimal. Giving the ability to be able to display the local currency value of the token without having to cast to other objects.

  • Being able to add Tez and NativeToken together (if they are separate objects). To have the ability to multiply all of the Tez and Tokens by their local currency amount, and then add all of them together to get a wallet/account total. Again without having to cast to intermediate objects. Leading rounding/truncation issues.

@simonmcl
Copy link
Collaborator Author

simonmcl commented Jul 2, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant