Skip to content

Commit 9cc4ffe

Browse files
committed
Makes scalingFactor and isUpscaling public state vars
1 parent 76780c0 commit 9cc4ffe

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

contracts/NormalizedApi3ReaderProxyV1.sol

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ contract NormalizedApi3ReaderProxyV1 is INormalizedApi3ReaderProxyV1 {
1515
/// @notice Chainlink AggregatorV2V3Interface contract address
1616
address public immutable override feed;
1717

18-
/// @dev Pre-calculated factor for scaling to 18 decimals.
19-
int256 private immutable scalingFactor;
18+
/// @notice Pre-calculated factor for scaling the feed's value to 18
19+
/// decimals.
20+
int256 public immutable scalingFactor;
2021

21-
/// @dev True for upscaling (multiply by scalingFactor), else downscaling
22-
/// (divide by scalingFactor).
23-
bool private immutable isUpscaling;
22+
/// @notice True if upscaling (multiply by `scalingFactor`), false if
23+
/// downscaling (divide by `scalingFactor`), to normalize to 18 decimals.
24+
bool public immutable isUpscaling;
2425

2526
/// @param feed_ The address of the Chainlink AggregatorV2V3Interface feed
2627
constructor(address feed_) {

contracts/adapters/ScaledApi3FeedProxyV1.sol

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ contract ScaledApi3FeedProxyV1 is IScaledApi3FeedProxyV1 {
1616
/// @dev Target decimals for the scaled value.
1717
uint8 private immutable targetDecimals;
1818

19-
/// @dev Pre-calculated factor for scaling from 18 decimals.
20-
int256 private immutable scalingFactor;
19+
/// @notice Pre-calculated factor for scaling the proxy's 18-decimal value
20+
/// to `targetDecimals`.
21+
int256 public immutable scalingFactor;
2122

22-
/// @dev True for upscaling (multiply by scalingFactor), else downscaling
23-
/// (divide by scalingFactor).
24-
bool private immutable isUpscaling;
23+
/// @notice True if upscaling (multiply by `scalingFactor`), false if
24+
/// downscaling (divide by `scalingFactor`), to scale to `targetDecimals`.
25+
bool public immutable isUpscaling;
2526

2627
/// @param proxy_ IApi3ReaderProxy contract address
2728
/// @param targetDecimals_ Decimals used to scale the IApi3ReaderProxy value

contracts/adapters/interfaces/IScaledApi3FeedProxyV1.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ interface IScaledApi3FeedProxyV1 is AggregatorV2V3Interface {
1313
error FunctionIsNotSupported();
1414

1515
function proxy() external view returns (address proxy);
16+
17+
function scalingFactor() external view returns (int256);
18+
19+
function isUpscaling() external view returns (bool);
1620
}

contracts/interfaces/INormalizedApi3ReaderProxyV1.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ interface INormalizedApi3ReaderProxyV1 is
1717
error FunctionIsNotSupported();
1818

1919
function feed() external view returns (address feed);
20+
21+
function scalingFactor() external view returns (int256);
22+
23+
function isUpscaling() external view returns (bool);
2024
}

test/NormalizedApi3ReaderProxyV1.sol.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ describe('NormalizedApi3ReaderProxyV1', function () {
1111
return { ...acc, [roleName]: accounts[index] };
1212
}, {});
1313

14-
const decimals = 20;
15-
const answer = ethers.parseUnits('1824.97', decimals);
14+
const decimals = 8;
15+
const answer = ethers.parseUnits('0.25', decimals);
1616
const timestamp = await helpers.time.latest();
1717

1818
const mockAggregatorV2V3Factory = await ethers.getContractFactory('MockAggregatorV2V3', roles.deployer);
@@ -46,6 +46,8 @@ describe('NormalizedApi3ReaderProxyV1', function () {
4646
it('constructs', async function () {
4747
const { feed, normalizedApi3ReaderProxyV1 } = await helpers.loadFixture(deploy);
4848
expect(await normalizedApi3ReaderProxyV1.feed()).to.equal(await feed.getAddress());
49+
expect(await normalizedApi3ReaderProxyV1.isUpscaling()).to.equal(true); // 8 < 18 is true
50+
expect(await normalizedApi3ReaderProxyV1.scalingFactor()).to.equal(10_000_000_000n); // 10**(18-8)
4951
});
5052
});
5153
context('feed has 18 decimals', function () {

test/adapters/ScaledApi3FeedProxyV1.sol.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ describe('ScaledApi3FeedProxyV1', function () {
9292
it('constructs', async function () {
9393
const { api3ReaderProxyV1, scaledApi3FeedProxyV1 } = await helpers.loadFixture(deploy);
9494
expect(await scaledApi3FeedProxyV1.proxy()).to.equal(await api3ReaderProxyV1.getAddress());
95+
expect(await scaledApi3FeedProxyV1.isUpscaling()).to.equal(false); // targetDecimals (8) > 18 is false
96+
expect(await scaledApi3FeedProxyV1.scalingFactor()).to.equal(10_000_000_000n); // 10**(18-8)
9597
});
9698
});
9799
context('targetDecimals is 18', function () {

0 commit comments

Comments
 (0)