-
Notifications
You must be signed in to change notification settings - Fork 123
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
[feature]: add a function, rfqmath.FixedPointFromUint64_Decimal_Display
#1385
Comments
Thanks for looking into this. What would have helped me most would be better examples in the price-oracle-example code. So I suggest to keep the code as is but improve the comments. For example:
|
I think your coefficient is going to be 42,000,000,000,000,000 with a scale of 6 and a decimal display of 6. With a decimal display of 6 and $42,000 per BTC, 42,000,000,000 is going to be the "fractional value" defined here: taproot-assets/taprpc/priceoraclerpc/price_oracle.proto Lines 26 to 57 in 3a0556c
|
Gaahh, yes you're right of couse. Thanks for pointing it out. So my suggested comment should be:
|
yes, very confusing, that's why I think we need more than just better documentation to clear some of this stuff up for people! |
The The base value is the amount of assets to 1 BTC. If you didn't have any decimal display at all, then it would be 100k. However if you have a decimal display of 3, then this means 1000 units is actually $1, so it would be 100 million. |
There is a lot of confusion when running a price oracle server on how to properly input the exchange rate. One example of this is here: https://lightningcommunity.slack.com/archives/C03B3556HQ8/p1738866875640909?thread_ts=1738748330.746709&cid=C03B3556HQ8 .
The basic-price-oracle example uses the
rfqmath.FixedPointFromUint64
function, and that is where a lot of the confusions arises.taproot-assets/docs/examples/basic-price-oracle/main.go
Lines 111 to 126 in 28c4ea8
taproot-assets/rfqmath/fixed_point.go
Lines 189 to 199 in 28c4ea8
What is very confusing to new users is the "scale". It is recommended that this be the same as the decimal display that was defined when creating the asset. This leads users to think that the "coefficient" be defined in terms of decimal display asset units and then the exchange rate can be off by an order of magnitude of the decimal display. The "scale" parameter is recommended to be the same as the decimal display in order to reduce arithmetic round off error, but it doesn't really change the exchange rate itself.
I'd recommend a new function be created,
rfqmath.FixedPointFromUint64_Decimal_Display
, where the the exchange rate in terms of decimal display assets can be input, and then the decimal display digits as the second input. Then, convert the exchange rate from decimal display asset units to base asset units and use that as thecoefficient
input torfqmath.FixedPointFromUint64
. Then, also use the decimal display digits as thescale
input torfqmath.FixedPointFromUint64
.See also, the definition of FixedPoint:
taproot-assets/taprpc/priceoraclerpc/price_oracle.proto
Lines 26 to 57 in 3a0556c
The text was updated successfully, but these errors were encountered: