Description
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 the coefficient
input to rfqmath.FixedPointFromUint64
. Then, also use the decimal display digits as the scale
input to rfqmath.FixedPointFromUint64
.
See also, the definition of FixedPoint:
taproot-assets/taprpc/priceoraclerpc/price_oracle.proto
Lines 26 to 57 in 3a0556c
Metadata
Assignees
Labels
Type
Projects
Status
π New
Activity