Skip to content

Commit 7d01dae

Browse files
committed
docs: document scale factor
1 parent 0007653 commit 7d01dae

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/ChainlinkOracle.sol

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ contract ChainlinkOracle is IOracle {
4141
BASE_FEED_2 = baseFeed2;
4242
QUOTE_FEED_1 = quoteFeed1;
4343
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)
4458
SCALE_FACTOR = 10
4559
** (
4660
36 + quoteTokenDecimals + quoteFeed1.getDecimals() + quoteFeed2.getDecimals() - baseFeed1.getDecimals()

0 commit comments

Comments
 (0)