From e5fc46a089fa9d763933dc0e4cca3191fd194dad Mon Sep 17 00:00:00 2001 From: Burak Benligiray Date: Wed, 14 Aug 2024 18:39:51 +0300 Subject: [PATCH] Finalize DapiProxyWithOevV2 --- .../Api3ServerV1OevExtension.sol | 7 ++-- .../interfaces/IApi3ServerV1OevExtension.sol | 3 +- .../proxies/DapiProxyWithOevV2.sol | 32 +++++++++---------- .../interfaces/IDapiProxyWithOevV2.sol | 10 ++++++ 4 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 contracts/api3-server-v1/proxies/interfaces/IDapiProxyWithOevV2.sol diff --git a/contracts/api3-server-v1/Api3ServerV1OevExtension.sol b/contracts/api3-server-v1/Api3ServerV1OevExtension.sol index 8f18ce1..44c3dc5 100644 --- a/contracts/api3-server-v1/Api3ServerV1OevExtension.sol +++ b/contracts/api3-server-v1/Api3ServerV1OevExtension.sol @@ -188,10 +188,13 @@ contract Api3ServerV1OevExtension is return Address.functionCall(target, data); } - function dataFeeds( + function oevDataFeed( + uint256 dappId, bytes32 dataFeedId ) external view override returns (int224 value, uint32 timestamp) { - DataFeed storage dataFeed = _dataFeeds[dataFeedId]; + DataFeed storage dataFeed = _dataFeeds[ + keccak256(abi.encodePacked(dappId, dataFeedId)) + ]; (value, timestamp) = (dataFeed.value, dataFeed.timestamp); } diff --git a/contracts/api3-server-v1/interfaces/IApi3ServerV1OevExtension.sol b/contracts/api3-server-v1/interfaces/IApi3ServerV1OevExtension.sol index 1b5f85f..b9f850c 100644 --- a/contracts/api3-server-v1/interfaces/IApi3ServerV1OevExtension.sol +++ b/contracts/api3-server-v1/interfaces/IApi3ServerV1OevExtension.sol @@ -61,7 +61,8 @@ interface IApi3ServerV1OevExtension is bytes calldata data ) external returns (bytes memory); - function dataFeeds( + function oevDataFeed( + uint256 dappId, bytes32 dataFeedId ) external view returns (int224 value, uint32 timestamp); diff --git a/contracts/api3-server-v1/proxies/DapiProxyWithOevV2.sol b/contracts/api3-server-v1/proxies/DapiProxyWithOevV2.sol index 8521176..04b21a3 100644 --- a/contracts/api3-server-v1/proxies/DapiProxyWithOevV2.sol +++ b/contracts/api3-server-v1/proxies/DapiProxyWithOevV2.sol @@ -1,30 +1,30 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "./interfaces/IDapiProxy.sol"; +import "./interfaces/IDapiProxyWithOevV2.sol"; import "../interfaces/IApi3ServerV1.sol"; -import "../Api3ServerV1OevExtension.sol"; +import "../interfaces/IApi3ServerV1OevExtension.sol"; // This contract will be upgradeable whose proxy is deployed by a factory -contract DapiProxyWithOevV2 is IDapiProxy { +contract DapiProxyWithOevV2 is IDapiProxyWithOevV2 { address public override api3ServerV1; bytes32 public override dapiNameHash; - address public api3ServerV1OevExtension; + address public override api3ServerV1OevExtension; - uint256 public dappId; + uint256 public override dappId; constructor( - address api3ServerV1_, - bytes32 dapiNameHash_, - address api3ServerV1OevExtension_, - uint256 dappId_ + address _api3ServerV1, + bytes32 _dapiNameHash, + address _api3ServerV1OevExtension, + uint256 _dappId ) { - api3ServerV1 = api3ServerV1_; - dapiNameHash = dapiNameHash_; - api3ServerV1OevExtension = api3ServerV1OevExtension_; - dappId = dappId_; + api3ServerV1 = _api3ServerV1; + dapiNameHash = _dapiNameHash; + api3ServerV1OevExtension = _api3ServerV1OevExtension; + dappId = _dappId; } function read() @@ -34,7 +34,6 @@ contract DapiProxyWithOevV2 is IDapiProxy { override returns (int224 value, uint32 timestamp) { - // Adapted from _readDataFeedWithDapiNameHashAsOevProxy() of OevDapiServer bytes32 dataFeedId = IApi3ServerV1(api3ServerV1) .dapiNameHashToDataFeedId(dapiNameHash); require(dataFeedId != bytes32(0), "dAPI name not set"); @@ -44,8 +43,9 @@ contract DapiProxyWithOevV2 is IDapiProxy { ( int224 oevDapiValue, uint32 oevDapiTimestamp - ) = Api3ServerV1OevExtension(api3ServerV1OevExtension).dataFeeds( - keccak256(abi.encodePacked(dappId, dataFeedId)) + ) = IApi3ServerV1OevExtension(api3ServerV1OevExtension).oevDataFeed( + dappId, + dataFeedId ); if (oevDapiTimestamp > baseDapiTimestamp) { (value, timestamp) = (oevDapiValue, oevDapiTimestamp); diff --git a/contracts/api3-server-v1/proxies/interfaces/IDapiProxyWithOevV2.sol b/contracts/api3-server-v1/proxies/interfaces/IDapiProxyWithOevV2.sol new file mode 100644 index 0000000..9ab3f37 --- /dev/null +++ b/contracts/api3-server-v1/proxies/interfaces/IDapiProxyWithOevV2.sol @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import "./IDapiProxy.sol"; + +interface IDapiProxyWithOevV2 is IDapiProxy { + function api3ServerV1OevExtension() external view returns (address); + + function dappId() external view returns (uint256); +}