Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates based on v0.2 #11

Merged
merged 5 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ yarn compile
## Deploy

```shell
# aggregator example
# feed example
npx hardhat deploy --network baobab --deploy-scripts deploy/DataFeedConsumer
```

Expand Down
14 changes: 6 additions & 8 deletions contracts/DataFeedConsumer.sol
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
nick-bisonai marked this conversation as resolved.
Show resolved Hide resolved

import {IAggregator} from "@bisonai/orakl-contracts/src/v0.1/interfaces/IAggregator.sol";
import {IFeedProxy} from "./interfaces/IFeedProxy.sol";


contract DataFeedConsumer {
IAggregator internal dataFeed;
IFeedProxy internal feedProxy;
int256 public answer;
uint80 public roundId;

constructor(address aggregatorProxy) {
dataFeed = IAggregator(aggregatorProxy);
constructor(address _feedProxy) {
feedProxy = IFeedProxy(_feedProxy);
}

function getLatestData() public {
(
uint80 roundId_,
int256 answer_
, /* uint startedAt */
, /* uint updatedAt */
, /* uint80 answeredInRound */
) = dataFeed.latestRoundData();
) = feedProxy.latestRoundData();

answer = answer_;
roundId = roundId_;
}

function decimals() public view returns (uint8) {
return dataFeed.decimals();
return feedProxy.decimals();
}
}
9 changes: 4 additions & 5 deletions contracts/DataFeedRouterConsumer.sol
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import {IAggregatorRouter} from "@bisonai/orakl-contracts/src/v0.1/interfaces/IAggregatorRouter.sol";
import {IFeedRouter} from "./interfaces/IFeedRouter.sol";

contract DataFeedRouterConsumer {
IAggregatorRouter internal router;
IFeedRouter internal router;
int256 public answer;
uint80 public roundId;

constructor(address aggregatorRouter) {
router = IAggregatorRouter(aggregatorRouter);
router = IFeedRouter(aggregatorRouter);
}


function getLatestData(string calldata pair) public {
(
uint80 roundId_,
int256 answer_
, /* uint startedAt */
, /* uint updatedAt */
, /* uint80 answeredInRound */

) = router.latestRoundData(pair);

answer = answer_;
Expand Down
66 changes: 66 additions & 0 deletions contracts/interfaces/IFeed.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IFeed {
/**
* @notice Get decimals of the feed.
* @return decimals The decimals of the feed.
*/
function decimals() external view returns (uint8);

/**
* @notice Get description of the feed.
* @return description The description of the feed.
*/
function description() external view returns (string memory);

/**
* @notice Get version and type of the feed.
* @return typeAndVersion The type and version of the feed.
*/
function typeAndVersion() external view returns (string memory);

/**
* @notice Get latest round data of the feed.
* @dev This function internally calls getRoundData with the
* latest round ID. If no rounds have been submitted, this function
* reverts with NoDataPresent error.
* @return id The round ID.
* @return answer The oracle answer.
* @return updatedAt Timestamp of the last update.
*/
function latestRoundData() external view returns (uint64 id, int256 answer, uint256 updatedAt);

/**
* @notice Get timestamp of the latest round update
* @dev If no updates have been made, this function returns 0.
* @return The timestamp of the latest round update
*/
function latestRoundUpdatedAt() external view returns (uint256);

/**
* @notice Get the time-weighted average price (TWAP) of the feed
* over a given interval.
* @dev If the latest update time is older than the given tolerance,
* this function reverts with AnswerAboveTolerange error. If the number of
* data points is less than the given minimum count, this function reverts
* with InsufficientData error.
* @param interval The time interval in seconds
* @param latestUpdatedAtTolerance The tolerance for the latest update time
* @param minCount The minimum number of data points
* @return The TWAP
*/
function twap(uint256 interval, uint256 latestUpdatedAtTolerance, int256 minCount) external view returns (int256);

/**
* @notice Get round data given a round ID.
* @dev If the given roundId is higher than the latest round ID or
* feed has not been updated yet, this function reverts with
* NoDataPresent error.
* @param roundId The round ID.
* @return id The round ID.
* @return answer The oracle answer.
* @return updatedAt Timestamp of the last update.
*/
function getRoundData(uint64 roundId) external view returns (uint64 id, int256 answer, uint256 updatedAt);
}
58 changes: 58 additions & 0 deletions contracts/interfaces/IFeedProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {IFeed} from "./IFeed.sol";

interface IFeedProxy is IFeed {
/**
* @notice Get round data from the proposed feed given a round ID.
* @dev If there is no proposed feed, this function reverts with
* NoProposedFeed error. If the given roundId is higher than the
* latest round ID or feed has not been updated yet, this function
* reverts with NoDataPresent error.
* @param roundId The round ID.
* @return id The round ID.
* @return answer The oracle answer.
* @return updatedAt Timestamp of the last update.
*/
function getRoundDataFromProposedFeed(uint64 roundId)
external
view
returns (uint64 id, int256 answer, uint256 updatedAt);

/**
* @notice Get the latest round data from the proposed feed.
* @dev If there is no proposed feed, this function reverts with
* NoProposedFeed error. If no rounds have been submitted, this function
* reverts with NoDataPresent error.
* @return id The round ID.
* @return answer The oracle answer.
* @return updatedAt Timestamp of the last update.
*/
function latestRoundDataFromProposedFeed() external view returns (uint64 id, int256 answer, uint256 updatedAt);

/**
* @notice Get address of the feed.
* @return The address of the feed.
*/
function getFeed() external view returns (address);

/**
* @notice Get address of the proposed feed.
* @return The address of the proposed feed.
*/
function getProposedFeed() external view returns (address);

/**
* @notice Get the time-weighted average price (TWAP) of the
* proposed feed over a given interval.
* @param interval The time interval in seconds
* @param latestUpdatedAtTolerance The tolerance for the latest update time
* @param minCount The minimum number of data points
* @return The TWAP
*/
function twapFromProposedFeed(uint256 interval, uint256 latestUpdatedAtTolerance, int256 minCount)
external
view
returns (int256);
}
149 changes: 149 additions & 0 deletions contracts/interfaces/IFeedRouter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IFeedRouter {
/**
* @notice Get the address of the feed proxy given a feed name.
* @param feedName The feed name.
* @return The address of the feed proxy.
*/
function feedToProxies(string calldata feedName) external view returns (address);

/**
* @notice Update the feed proxy addresses in bulk.
* @dev This function is restricted to the owner. Internally, this
* function uses `updateProxy` to update the proxy addresses.
* @param feedNames The feed names.
* @param proxyAddresses The addresses of the feed proxies.
*/
function updateProxyBulk(string[] calldata feedNames, address[] calldata proxyAddresses) external;

/**
* @notice Remove the feed proxy addresses in bulk.
* @dev This function is restricted to the owner. Internally, this
* function uses `removeProxy` to remove the proxy addresses.
* @param feedNames The feed names.
*/
function removeProxyBulk(string[] calldata feedNames) external;

/**
* @notice Get the round data given a a feedd name and round ID.
* @param feedName The feed name.
* @param roundId The round ID.
* @return id The round ID.
* @return answer The oracle answer.
* @return updatedAt Timestamp of the last update.
*/
function getRoundData(string calldata feedName, uint64 roundId)
external
view
returns (uint64 id, int256 answer, uint256 updatedAt);

/**
* @notice Get the latest round data of the feed given a feed name.
* @param feedName The feed name.
* @return id The round ID.
* @return answer The oracle answer.
* @return updatedAt Timestamp of the last update.
*/
function latestRoundData(string calldata feedName)
external
view
returns (uint64 id, int256 answer, uint256 updatedAt);

/**
* @notice Get the time-weighted average price (TWAP) of the feed
* over a given interval.
* @param feedName The feed name.
* @param interval The time interval in seconds
* @param latestUpdatedAtTolerance The tolerance for the latest update time
* @param minCount The minimum number of data points
* @return The TWAP
*/
function twap(string calldata feedName, uint256 interval, uint256 latestUpdatedAtTolerance, int256 minCount)
external
view
returns (int256);

/**
* @notice Get the time-weighted average price (TWAP) of the
* proposed feed over a given interval.
* @param feedName The feed name.
* @param interval The time interval in seconds
* @param latestUpdatedAtTolerance The tolerance for the latest update time
* @param minCount The minimum number of data points
* @return The TWAP
*/
function twapFromProposedFeed(
string calldata feedName,
uint256 interval,
uint256 latestUpdatedAtTolerance,
int256 minCount
) external view returns (int256);

/**
* @notice Get round data from the proposed feed given a feed name and round ID.
* @param feedName The feed name.
* @param roundId The round ID.
* @return id The round ID.
* @return answer The oracle answer.
* @return updatedAt Timestamp of the last update.
*/
function getRoundDataFromProposedFeed(string calldata feedName, uint64 roundId)
external
view
returns (uint64 id, int256 answer, uint256 updatedAt);

/**
* @notice Get the latest round data from the proposed feed given a feed name.
* @param feedName The feed name.
* @return id The round ID.
* @return answer The oracle answer.
* @return updatedAt Timestamp of the last update.
*/
function latestRoundDataFromProposedFeed(string calldata feedName)
external
view
returns (uint64 id, int256 answer, uint256 updatedAt);

/**
* @notice Get address of the feed given a feed name.
* @param feedName The feed name.
* @return The address of the feed.
*/
function feed(string calldata feedName) external view returns (address);

/**
* @notice Return the address of the proposed feed given a feed name.
* @param feedName The feed name.
* @return The address of the proposed feed.
*/
function proposedFeed(string calldata feedName) external view returns (address);

/**
* @notice Get decimals of the feed given a feed name.
* @param feedName The feed name.
* @return decimals The decimals of the feed.
*/
function decimals(string calldata feedName) external view returns (uint8);

/**
* @notice Get version and type of the feed given a feed name.
* @param feedName The feed name.
* @return typeAndVersion The type and version of the feed.
*/
function typeAndVersion(string calldata feedName) external view returns (string memory);

/**
* @notice Get description of the feed given a feed name.
* @param feedName The feed name.
* @return description The description of the feed.
*/
function description(string calldata feedName) external view returns (string memory);

/**
* @notice Get supported feed names.
* @return The feed names.
*/
function getFeedNames() external view returns (string[] memory);
}
4 changes: 2 additions & 2 deletions deploy/DataFeedConsumer/DataFeedConsumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DeployFunction } from 'hardhat-deploy/types'
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts, network } = hre
const { deploy } = deployments
const { deployer, aggregatorProxy: aggregatorProxyAddress } = await getNamedAccounts()
const { deployer, feedProxy: feedProxyAddress } = await getNamedAccounts()

console.log('0-DataFeedConsumer.ts')

Expand All @@ -14,7 +14,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}

await deploy('DataFeedConsumer', {
args: [aggregatorProxyAddress],
args: [feedProxyAddress],
from: deployer,
log: true
})
Expand Down
4 changes: 2 additions & 2 deletions deploy/DataFeedRouterConsumer/DataFeedRouterConsumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DeployFunction } from 'hardhat-deploy/types'
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts, network } = hre
const { deploy } = deployments
const { deployer, aggregatorRouter: aggregatorRouterAddress } = await getNamedAccounts()
const { deployer, feedRouter: feedRouterAddress } = await getNamedAccounts()

console.log('1-DataFeedRouterConsumer.ts')

Expand All @@ -14,7 +14,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}

await deploy('DataFeedRouterConsumer', {
args: [aggregatorRouterAddress],
args: [feedRouterAddress],
from: deployer,
log: true
})
Expand Down
Loading
Loading