11// SPDX-License-Identifier: MIT
22pragma solidity 0.8.27 ;
33
4- import "@api3/contracts/api3-server-v1/proxies/ interfaces/IApi3ReaderProxyV1 .sol " ;
4+ import "../ interfaces/IApi3ReaderProxyWithDappId .sol " ;
55import "./interfaces/IScaledApi3FeedProxyV1.sol " ;
66
77/// @title An immutable Chainlink AggregatorV2V3Interface feed contract that
8- /// scales the value of an IApi3ReaderProxyV1 data feed to a target number of
9- /// decimals
8+ /// scales the value of an IApi3ReaderProxyWithDappId data feed to a target
9+ /// number of decimals
1010/// @dev This contract reads an `int224` value (assumed to be 18 decimals)
11- /// from the underlying `IApi3ReaderProxyV1` and scales it to `targetDecimals`.
11+ /// from the underlying `IApi3ReaderProxyWithDappId` and scales it to
12+ ///`targetDecimals`.
1213/// The scaling arithmetic uses `int256` for intermediate results, allowing the
1314/// scaled value to exceed `int224` limits if upscaling significantly; it will
1415/// revert on `int256` overflow.
1516/// When downscaling, integer division (`proxyValue / scalingFactor`) is used,
1617/// which truncates and may lead to precision loss. Integrators must carefully
1718/// consider this potential precision loss for their specific use case.
1819contract ScaledApi3FeedProxyV1 is IScaledApi3FeedProxyV1 {
19- /// @notice IApi3ReaderProxyV1 contract address
20+ /// @notice IApi3ReaderProxyWithDappId contract address
2021 address public immutable override proxy;
2122
2223 /// @notice dApp ID of the proxy
2324 uint256 public immutable override dappId;
2425
25- /// @dev Target decimals for the scaled value.
26- uint8 private immutable targetDecimals;
27-
2826 /// @notice Pre-calculated factor for scaling the proxy's 18-decimal value
2927 /// to `targetDecimals`.
30- int256 public immutable scalingFactor;
28+ int256 public immutable override scalingFactor;
3129
3230 /// @notice True if upscaling (multiply by `scalingFactor`), false if
3331 /// downscaling (divide by `scalingFactor`), to scale to `targetDecimals`.
34- bool public immutable isUpscaling;
32+ bool public immutable override isUpscaling;
33+
34+ /// @dev Target decimals for the scaled value.
35+ uint8 private immutable targetDecimals;
3536
36- /// @param proxy_ IApi3ReaderProxyV1 contract address
37- /// @param targetDecimals_ Decimals to scale the IApi3ReaderProxyV1 value
37+ /// @param proxy_ IApi3ReaderProxyWithDappId contract address
38+ /// @param targetDecimals_ Decimals to scale the IApi3ReaderProxyWithDappId
39+ /// value
3840 constructor (address proxy_ , uint8 targetDecimals_ ) {
3941 if (proxy_ == address (0 )) {
4042 revert ZeroProxyAddress ();
@@ -46,7 +48,7 @@ contract ScaledApi3FeedProxyV1 is IScaledApi3FeedProxyV1 {
4648 revert NoScalingNeeded ();
4749 }
4850 proxy = proxy_;
49- dappId = IApi3ReaderProxyV1 (proxy_).dappId ();
51+ dappId = IApi3ReaderProxyWithDappId (proxy_).dappId ();
5052 targetDecimals = targetDecimals_;
5153 uint8 delta = targetDecimals_ > 18
5254 ? targetDecimals_ - 18
@@ -92,7 +94,7 @@ contract ScaledApi3FeedProxyV1 is IScaledApi3FeedProxyV1 {
9294 revert FunctionIsNotSupported ();
9395 }
9496
95- /// @dev Decimals used to scale the IApi3ReaderProxyV1 value
97+ /// @dev Decimals used to scale the IApi3ReaderProxyWithDappId value
9698 function decimals () external view override returns (uint8 ) {
9799 return targetDecimals;
98100 }
@@ -141,17 +143,18 @@ contract ScaledApi3FeedProxyV1 is IScaledApi3FeedProxyV1 {
141143 updatedAt = startedAt;
142144 }
143145
144- /// @notice Reads a value from the underlying `IApi3ReaderProxyV1` and
145- /// scales it to `targetDecimals`.
146+ /// @notice Reads a value from the underlying `IApi3ReaderProxyWithDappId`
147+ /// and scales it to `targetDecimals`.
146148 /// @dev Reads from the underlying proxy and applies scaling to
147149 /// `targetDecimals`. Upscaling uses multiplication; downscaling uses integer
148150 /// division (which truncates). All scaling arithmetic is performed using
149151 /// `int256`.
150152 /// @return value The scaled signed fixed-point value with `targetDecimals`.
151153 /// @return timestamp The timestamp from the underlying proxy.
152154 function _read () internal view returns (int256 value , uint32 timestamp ) {
153- (int224 proxyValue , uint32 proxyTimestamp ) = IApi3ReaderProxyV1 (proxy)
154- .read ();
155+ (int224 proxyValue , uint32 proxyTimestamp ) = IApi3ReaderProxyWithDappId (
156+ proxy
157+ ).read ();
155158
156159 value = isUpscaling
157160 ? proxyValue * scalingFactor
0 commit comments