Skip to content

Commit d6abe74

Browse files
committed
Adds IApi3ReaderProxyWithDappId interface
1 parent f4364a6 commit d6abe74

9 files changed

+76
-69
lines changed

contracts/InverseApi3ReaderProxyV1.sol

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity 0.8.27;
33

4-
import "@api3/contracts/api3-server-v1/proxies/interfaces/IApi3ReaderProxyV1.sol";
4+
import "./interfaces/IApi3ReaderProxyWithDappId.sol";
55
import "./interfaces/IInverseApi3ReaderProxyV1.sol";
66

77
/// @title An immutable proxy contract that inverts the value returned by an
8-
/// IApi3ReaderProxyV1 data feed
8+
/// IApi3ReaderProxyWithDappId data feed
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.
1212
/// Refer to https://github.com/api3dao/migrate-from-chainlink-to-api3 for more
1313
/// information about the Chainlink interface implementation.
1414
contract InverseApi3ReaderProxyV1 is IInverseApi3ReaderProxyV1 {
15-
/// @notice IApi3ReaderProxyV1 contract address
15+
/// @notice IApi3ReaderProxyWithDappId contract address
1616
address public immutable override proxy;
1717

1818
/// @notice dApp ID of the proxy
1919
uint256 public immutable override dappId;
2020

21-
/// @param proxy_ IApi3ReaderProxyV1 contract address
21+
/// @param proxy_ IApi3ReaderProxyWithDappId contract address
2222
constructor(address proxy_) {
2323
if (proxy_ == address(0)) {
2424
revert ZeroProxyAddress();
2525
}
2626
proxy = proxy_;
27-
dappId = IApi3ReaderProxyV1(proxy_).dappId();
27+
dappId = IApi3ReaderProxyWithDappId(proxy_).dappId();
2828
}
2929

30-
/// @notice Returns the inverted value of the underlying IApi3ReaderProxyV1
30+
/// @notice Returns the inverted value of the underlying
31+
/// IApi3ReaderProxyWithDappId
3132
/// @dev Calculates `int224(1e36) / baseValue`. The operation will revert if
3233
/// `baseValue` is zero. If `baseValue` is non-zero but its absolute value is
3334
/// greater than `1e36`, the result of the integer division will be `0`.
@@ -39,8 +40,9 @@ contract InverseApi3ReaderProxyV1 is IInverseApi3ReaderProxyV1 {
3940
override
4041
returns (int224 value, uint32 timestamp)
4142
{
42-
(int224 baseValue, uint32 baseTimestamp) = IApi3ReaderProxyV1(proxy)
43-
.read();
43+
(int224 baseValue, uint32 baseTimestamp) = IApi3ReaderProxyWithDappId(
44+
proxy
45+
).read();
4446

4547
if (baseValue == 0) {
4648
revert DivisionByZero();
@@ -99,7 +101,7 @@ contract InverseApi3ReaderProxyV1 is IInverseApi3ReaderProxyV1 {
99101
}
100102

101103
/// @dev A unique version is chosen to easily check if an unverified
102-
/// contract that acts as a Chainlink feed is a InverseApi3ReaderProxyV1
104+
/// contract that acts as a Chainlink feed is an InverseApi3ReaderProxyV1
103105
function version() external pure override returns (uint256) {
104106
return 4915;
105107
}

contracts/PriceCappedApi3ReaderProxyV1.sol

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity 0.8.27;
33

4-
import "@api3/contracts/api3-server-v1/proxies/interfaces/IApi3ReaderProxyV1.sol";
4+
import "./interfaces/IApi3ReaderProxyWithDappId.sol";
55
import "./interfaces/IPriceCappedApi3ReaderProxyV1.sol";
66

77
/**
@@ -21,7 +21,7 @@ import "./interfaces/IPriceCappedApi3ReaderProxyV1.sol";
2121
* floored at 0 if `lowerBound_` is 0.
2222
*/
2323
contract PriceCappedApi3ReaderProxyV1 is IPriceCappedApi3ReaderProxyV1 {
24-
/// @notice IApi3ReaderProxyV1 contract address
24+
/// @notice IApi3ReaderProxyWithDappId contract address
2525
address public immutable override proxy;
2626

2727
/// @notice dApp ID of the proxy
@@ -33,7 +33,7 @@ contract PriceCappedApi3ReaderProxyV1 is IPriceCappedApi3ReaderProxyV1 {
3333
/// @notice The maximum price (inclusive) that this proxy will report.
3434
int224 public immutable override upperBound;
3535

36-
/// @param proxy_ IApi3ReaderProxyV1 contract address
36+
/// @param proxy_ IApi3ReaderProxyWithDappId contract address
3737
/// @param lowerBound_ The minimum price (inclusive) this proxy will report
3838
/// @param upperBound_ The maximum price (inclusive) this proxy will report
3939
constructor(address proxy_, int224 lowerBound_, int224 upperBound_) {
@@ -47,13 +47,13 @@ contract PriceCappedApi3ReaderProxyV1 is IPriceCappedApi3ReaderProxyV1 {
4747
revert UpperBoundMustBeGreaterOrEqualToLowerBound();
4848
}
4949
proxy = proxy_;
50-
dappId = IApi3ReaderProxyV1(proxy_).dappId();
50+
dappId = IApi3ReaderProxyWithDappId(proxy_).dappId();
5151
lowerBound = lowerBound_;
5252
upperBound = upperBound_;
5353
}
5454

5555
/// @notice Reads the current value and timestamp from the underlying
56-
/// `IApi3ReaderProxyV1` and applies the price bounds.
56+
/// `IApi3ReaderProxyWithDappId` and applies the price bounds.
5757
/// @dev If the `baseValue` from the underlying proxy is less than
5858
/// `lowerBound`, then `lowerBound` is returned as the `value`. If
5959
/// `baseValue` is greater than `upperBound`, then `upperBound` is returned.
@@ -67,8 +67,9 @@ contract PriceCappedApi3ReaderProxyV1 is IPriceCappedApi3ReaderProxyV1 {
6767
override
6868
returns (int224 value, uint32 timestamp)
6969
{
70-
(int224 baseValue, uint32 baseTimestamp) = IApi3ReaderProxyV1(proxy)
71-
.read();
70+
(int224 baseValue, uint32 baseTimestamp) = IApi3ReaderProxyWithDappId(
71+
proxy
72+
).read();
7273

7374
timestamp = baseTimestamp;
7475

@@ -86,7 +87,7 @@ contract PriceCappedApi3ReaderProxyV1 is IPriceCappedApi3ReaderProxyV1 {
8687
/// @return True if the base value is less than `lowerBound` or greater
8788
/// than `upperBound`, false otherwise.
8889
function isCapped() external view returns (bool) {
89-
(int224 baseValue, ) = IApi3ReaderProxyV1(proxy).read();
90+
(int224 baseValue, ) = IApi3ReaderProxyWithDappId(proxy).read();
9091
return baseValue < lowerBound || baseValue > upperBound;
9192
}
9293

contracts/ProductApi3ReaderProxyV1.sol

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity 0.8.27;
33

4-
import "@api3/contracts/api3-server-v1/proxies/interfaces/IApi3ReaderProxyV1.sol";
4+
import "./interfaces/IApi3ReaderProxyWithDappId.sol";
55
import "./interfaces/IProductApi3ReaderProxyV1.sol";
66

77
/// @title An immutable proxy contract that is used to read a composition of two
8-
/// IApi3ReaderProxyV1 data feeds by multiplying their values
8+
/// IApi3ReaderProxyWithDappId data feeds by multiplying their values
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.
1212
/// Refer to https://github.com/api3dao/migrate-from-chainlink-to-api3 for more
1313
/// information about the Chainlink interface implementation.
1414
contract ProductApi3ReaderProxyV1 is IProductApi3ReaderProxyV1 {
15-
/// @notice First IApi3ReaderProxyV1 contract address
15+
/// @notice First IApi3ReaderProxyWithDappId contract address
1616
address public immutable override proxy1;
1717

18-
/// @notice Second IApi3ReaderProxyV1 contract address
18+
/// @notice Second IApi3ReaderProxyWithDappId contract address
1919
address public immutable override proxy2;
2020

2121
/// @notice The dApp ID of the two proxies
2222
uint256 public immutable override dappId;
2323

24-
/// @param proxy1_ First IApi3ReaderProxyV1 contract address
25-
/// @param proxy2_ Second IApi3ReaderProxyV1 contract address
24+
/// @param proxy1_ First IApi3ReaderProxyWithDappId contract address
25+
/// @param proxy2_ Second IApi3ReaderProxyWithDappId contract address
2626
constructor(address proxy1_, address proxy2_) {
2727
if (proxy1_ == address(0) || proxy2_ == address(0)) {
2828
revert ZeroProxyAddress();
2929
}
3030
if (proxy1_ == proxy2_) {
3131
revert SameProxyAddress();
3232
}
33-
uint256 dappId1 = IApi3ReaderProxyV1(proxy1_).dappId();
34-
uint256 dappId2 = IApi3ReaderProxyV1(proxy2_).dappId();
33+
uint256 dappId1 = IApi3ReaderProxyWithDappId(proxy1_).dappId();
34+
uint256 dappId2 = IApi3ReaderProxyWithDappId(proxy2_).dappId();
3535
if (dappId1 != dappId2) {
3636
revert DappIdMismatch();
3737
}
@@ -41,7 +41,8 @@ contract ProductApi3ReaderProxyV1 is IProductApi3ReaderProxyV1 {
4141
}
4242

4343
/// @notice Returns the current value and timestamp of the rate composition
44-
/// between two IApi3ReaderProxyV1 proxies by multiplying their values
44+
/// between two IApi3ReaderProxyWithDappId proxies by multiplying their
45+
/// values
4546
/// @dev Calculates product as `(int256(value1) * int256(value2)) / 1e18`.
4647
/// The initial multiplication `int256(value1) * int256(value2)` may revert
4748
/// on `int256` overflow. The final `int256` result of the full expression
@@ -58,8 +59,8 @@ contract ProductApi3ReaderProxyV1 is IProductApi3ReaderProxyV1 {
5859
override
5960
returns (int224 value, uint32 timestamp)
6061
{
61-
(int224 value1, ) = IApi3ReaderProxyV1(proxy1).read();
62-
(int224 value2, ) = IApi3ReaderProxyV1(proxy2).read();
62+
(int224 value1, ) = IApi3ReaderProxyWithDappId(proxy1).read();
63+
(int224 value2, ) = IApi3ReaderProxyWithDappId(proxy2).read();
6364

6465
value = int224((int256(value1) * int256(value2)) / 1e18);
6566
timestamp = uint32(block.timestamp);

contracts/adapters/ScaledApi3FeedProxyV1.sol

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity 0.8.27;
33

4-
import "@api3/contracts/api3-server-v1/proxies/interfaces/IApi3ReaderProxyV1.sol";
4+
import "../interfaces/IApi3ReaderProxyWithDappId.sol";
55
import "./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.
1819
contract 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
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.27;
3+
4+
import "@api3/contracts/interfaces/IApi3ReaderProxy.sol";
5+
6+
interface IApi3ReaderProxyWithDappId is IApi3ReaderProxy {
7+
function dappId() external view returns (uint256);
8+
}
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.4;
33

4-
import "@api3/contracts/interfaces/IApi3ReaderProxy.sol";
54
import "../vendor/@chainlink/[email protected]/src/v0.8/shared/interfaces/AggregatorV2V3Interface.sol";
5+
import "./IApi3ReaderProxyWithDappId.sol";
66

77
interface IInverseApi3ReaderProxyV1 is
8-
IApi3ReaderProxy,
8+
IApi3ReaderProxyWithDappId,
99
AggregatorV2V3Interface
1010
{
1111
error ZeroProxyAddress();
@@ -14,7 +14,5 @@ interface IInverseApi3ReaderProxyV1 is
1414

1515
error FunctionIsNotSupported();
1616

17-
function proxy() external view returns (address proxy);
18-
19-
function dappId() external view returns (uint256);
17+
function proxy() external view returns (address);
2018
}

contracts/interfaces/INormalizedApi3ReaderProxyV1.sol

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.4;
33

4-
import "@api3/contracts/interfaces/IApi3ReaderProxy.sol";
54
import "../vendor/@chainlink/[email protected]/src/v0.8/shared/interfaces/AggregatorV2V3Interface.sol";
5+
import "./IApi3ReaderProxyWithDappId.sol";
66

77
interface INormalizedApi3ReaderProxyV1 is
8-
IApi3ReaderProxy,
8+
IApi3ReaderProxyWithDappId,
99
AggregatorV2V3Interface
1010
{
1111
error ZeroProxyAddress();
@@ -16,9 +16,7 @@ interface INormalizedApi3ReaderProxyV1 is
1616

1717
error FunctionIsNotSupported();
1818

19-
function feed() external view returns (address feed);
20-
21-
function dappId() external view returns (uint256);
19+
function feed() external view returns (address);
2220

2321
function scalingFactor() external view returns (int256);
2422

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.4;
33

4-
import "@api3/contracts/interfaces/IApi3ReaderProxy.sol";
54
import "../vendor/@chainlink/[email protected]/src/v0.8/shared/interfaces/AggregatorV2V3Interface.sol";
5+
import "./IApi3ReaderProxyWithDappId.sol";
66

77
interface IPriceCappedApi3ReaderProxyV1 is
8-
IApi3ReaderProxy,
8+
IApi3ReaderProxyWithDappId,
99
AggregatorV2V3Interface
1010
{
1111
error ZeroProxyAddress();
@@ -16,13 +16,11 @@ interface IPriceCappedApi3ReaderProxyV1 is
1616

1717
error FunctionIsNotSupported();
1818

19-
function proxy() external view returns (address proxy);
19+
function proxy() external view returns (address);
2020

21-
function dappId() external view returns (uint256);
21+
function lowerBound() external view returns (int224);
2222

23-
function lowerBound() external view returns (int224 lowerBound);
24-
25-
function upperBound() external view returns (int224 upperBound);
23+
function upperBound() external view returns (int224);
2624

2725
function isCapped() external view returns (bool);
2826
}

0 commit comments

Comments
 (0)