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

Make TokenSDK support high-precision assets #211

Open
dazraf opened this issue Sep 2, 2020 · 4 comments
Open

Make TokenSDK support high-precision assets #211

dazraf opened this issue Sep 2, 2020 · 4 comments

Comments

@dazraf
Copy link

dazraf commented Sep 2, 2020

As the the worlds of traditional and crypto assets gradually converge, we need to be prepared for firms (and notably large institutional firms) looking to trade a variety of asset classes including those that require high-precision amounts. These classically include BTC, Ripple, ETH and also the vast majority of Ethereum tokens. TokenSDK, being steeped in the Corda Amount, uses Longs to represent amounts (using a divisor) which are insufficient to represent the aforementioned asset types. This request is for TokenSDK to formally support BigDecimal amounts.

@dave-hudson
Copy link

Do you have some examples of asset classes where 63 bits of precision aren't sufficient? It would be great to ground this in some concrete problems.

Arbitrary precision maths is intellectually more satisfying (I wrote a C++ library to do just this a few years ago) but is not without its own set of quirks, especially around conversions to other types.

@dazraf
Copy link
Author

dazraf commented Sep 4, 2020

Thanks @dave-hudson.
Yes, Corda's 63 bit longs mean that the largest absolute value that we can represent is 9,223,372,036,854,775,807.
19 significant figures.

Corda then applies a factor to adjust the value for the number of decimal places.
So e.g. the largest USD value that can be represented in Corda is 92,233,720,368,547,758.07.
This is conveniently well within the range of ~80 trillion USD in circulation.👍

Let's now consider ETH (and the bulk of Ethereum based tokens). These have 256 bits of precision.
Here's an example transaction:
https://www.blockchain.com/eth/tx/0xa907c2ac4a318728ca78042d237a09eaa556631f4b66e11de52d60e5535ba977

It's for 42.186822807956594688 ETH (roughly 16,065.59 USD)
Removing the decimal place, we have: 42186822807956594688. 20 significant figures. This exceeds the precision of Corda Amount.

I've discussed this matter with our trader clients. The suggestion of rounding all transactions so that they fit within the 63bit (19 sf) range was met with a non-satisfactory response. Every penny/cent/wei counts.

I recognise the complexities of engineering for high-precision assets - you can see my implementation in the Cordite project. There we represented amounts as BigDecimal in code and DECIMAL in the database. We can discuss the limits of DECIMAL - for practical concerns, it is sufficient to store very large ETH transactions.

Hope this helps give some context.

@roastario
Copy link
Contributor

roastario commented Apr 6, 2021

@dazraf thanks for this - I will take a look at it.

The complexity comes from maintaining compatibility with existing tokens out there.

@dazraf
Copy link
Author

dazraf commented Jun 3, 2021

Thanks @roastario. Yes, compatibility is tricky. Perhaps we can do a f2f chat about it. Happy to be of help.

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

3 participants