Skip to content

Commit

Permalink
Finalize DapiProxyWithOevV2
Browse files Browse the repository at this point in the history
  • Loading branch information
bbenligiray committed Aug 14, 2024
1 parent c772ed2 commit e5fc46a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
7 changes: 5 additions & 2 deletions contracts/api3-server-v1/Api3ServerV1OevExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
32 changes: 16 additions & 16 deletions contracts/api3-server-v1/proxies/DapiProxyWithOevV2.sol
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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");
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit e5fc46a

Please sign in to comment.