Skip to content

Commit 76780c0

Browse files
committed
Minor natspec comments improvements
1 parent 8e4d0c9 commit 76780c0

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

contracts/NormalizedApi3ReaderProxyV1.sol

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "./interfaces/INormalizedApi3ReaderProxyV1.sol";
55

66
/// @title An immutable proxy contract that converts a Chainlink
77
/// AggregatorV2V3Interface feed output to 18 decimals to conform with
8-
/// IApi3ReaderProxy decimal standard
8+
/// IApi3ReaderProxy decimal convention
99
/// @dev This contract implements the AggregatorV2V3Interface to be compatible
1010
/// with Chainlink aggregators. This allows the contract to be used as a drop-in
1111
/// replacement for Chainlink aggregators in existing dApps.
@@ -44,6 +44,15 @@ contract NormalizedApi3ReaderProxyV1 is INormalizedApi3ReaderProxyV1 {
4444

4545
/// @notice Returns the price of the underlying Chainlink feed normalized to
4646
/// 18 decimals.
47+
/// @dev Fetches an `int256` answer from the Chainlink feed and scales it
48+
/// to 18 decimals using pre-calculated factors. The result is cast to
49+
/// `int224` to conform to the `IApi3ReaderProxy` interface.
50+
/// IMPORTANT: If the normalized `int256` value is outside the `int224`
51+
/// range, this cast causes silent truncation and data loss. Deployers
52+
/// must verify that the source feed's characteristics (value magnitude
53+
/// and original decimals) ensure the 18-decimal normalized value fits
54+
/// `int224`. Scaling arithmetic (prior to cast) reverts on `int256`
55+
/// overflow.
4756
/// @return value The normalized signed fixed-point value with 18 decimals
4857
/// @return timestamp The updatedAt timestamp of the feed
4958
function read()

contracts/adapters/ScaledApi3FeedProxyV1.sol

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,14 @@ contract ScaledApi3FeedProxyV1 is IScaledApi3FeedProxyV1 {
133133
/// @notice Reads a value from the underlying `IApi3ReaderProxy` and
134134
/// scales it to `targetDecimals`.
135135
/// @dev Reads an `int224` value (assumed to be 18 decimals) from the
136-
/// underlying `IApi3ReaderProxy` and scales it to `targetDecimals`.
137-
/// The initial `int224` proxy value is widened to `int256` before scaling.
138-
/// The scaling arithmetic (`value * factor` or `value / factor`) is then
139-
/// performed using `int256` types. This allows the scaled result to exceed
140-
/// the `int224` range, provided it fits within `int256`.
141-
/// Arithmetic operations will revert on overflow or underflow
142-
/// (e.g., if `value * scalingFactor` exceeds `type(int256).max`).
136+
/// underlying `IApi3ReaderProxy`. This value is then scaled to
137+
/// `targetDecimals` using pre-calculated factors. The scaling arithmetic
138+
/// (e.g., `proxyValue * scalingFactor`) involves an `int224` (`proxyValue`)
139+
/// and an `int256` (`scalingFactor`). `proxyValue` is implicitly promoted
140+
/// to `int256` for this operation, resulting in an `int256` value.
141+
/// This allows the scaled result to exceed the `int224` range, provided
142+
/// it fits within `int256`. Arithmetic operations will revert on `int256`
143+
/// overflow. The function returns the scaled value as an `int256`.
143144
/// @return value The scaled signed fixed-point value with `targetDecimals`.
144145
/// @return timestamp The timestamp from the underlying proxy.
145146
function _read() internal view returns (int256 value, uint32 timestamp) {

0 commit comments

Comments
 (0)