File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,20 @@ contract ChainlinkOracle is IOracle {
41
41
BASE_FEED_2 = baseFeed2;
42
42
QUOTE_FEED_1 = quoteFeed1;
43
43
QUOTE_FEED_2 = quoteFeed2;
44
+ // Let pB1 and pB2 be the base prices, and pQ1 and pQ2 the quote prices (price of 1e(decimals) asset), in a
45
+ // common quote currency.
46
+ // Chainlink feeds return pB1*b1FeedPrecision, pB2*b2FeedPrecision, pQ1*q1FeedPrecision and pQ2*q2FeedPrecision.
47
+ // `price()` should return 1e36 * (pB1/1e(b1Decimals) * pB2/1e(b2Decimals)) / (pQ1/1e(q1Decimals) *
48
+ // pQ2/1e(q2Decimals)).
49
+ // Yet `price()` returns (pB1*1e(b1FeedPrecision) * pB2*1e(b2FeedPrecision) * SCALE_FACTOR) /
50
+ // (pQ1*1e(q1FeedPrecision) * pQ2*1e(q2FeedPrecision))
51
+ // So 1e36 * (pB1/1e(b1Decimals) * pB2/1e(b2Decimals)) / (pQ1/1e(q1Decimals) * pQ2/1e(q2Decimals)) =
52
+ // (pB1*1e(b1FeedPrecision) * pB2*1e(b2FeedPrecision) * SCALE_FACTOR) / (pQ1*1e(q1FeedPrecision) *
53
+ // pQ2*1e(q2FeedPrecision))
54
+ // So SCALE_FACTOR = 1e36 / 1e(b1Decimals) / 1e(b2Decimals) * 1e(q1Decimals) * 1e(q2Decimals) *
55
+ // 1e(q1FeedPrecision) * 1e(q2FeedPrecision) / 1e(b1FeedPrecision) / 1e(b2FeedPrecision)
56
+ // = 1e(36 + q1Decimals + q2Decimals + q1FeedPrecision + q2FeedPrecision - b1Decimals -
57
+ // b2Decimals - b1FeedPrecision - b2FeedPrecision)
44
58
SCALE_FACTOR = 10
45
59
** (
46
60
36 + quoteTokenDecimals + quoteFeed1.getDecimals () + quoteFeed2.getDecimals () - baseFeed1.getDecimals ()
You can’t perform that action at this time.
0 commit comments