diff --git a/src/oracle/OracleProvider.sol b/src/oracle/OracleProvider.sol index b346f69..5616238 100644 --- a/src/oracle/OracleProvider.sol +++ b/src/oracle/OracleProvider.sol @@ -7,6 +7,13 @@ enum OracleProviders { CHAINLINK } +// Fiat currencies follow https://en.wikipedia.org/wiki/ISO_4217 +// struct PairQuote { +// USD: address(840), +// GBP: address(826), +// EUR: address(978) +// } + library OracleProvider { /** * @dev Returns the name of the specified oracle provider. diff --git a/src/oracle/examples/OracleMockExample.sol b/src/oracle/examples/OracleMockExample.sol new file mode 100644 index 0000000..59a0125 --- /dev/null +++ b/src/oracle/examples/OracleMockExample.sol @@ -0,0 +1,19 @@ +pragma solidity ^0.8.0; + +import "../OracleMock.sol"; +import "../../tokens/Tokens.sol"; + +import "forge-std/console.sol"; + +contract OracleMockExample is OracleMock,Tokens { + OracleProviders internal _op; + + function initiateAttack(OracleProviders op) external { + _op = op; + if (op == OracleProviders.CHAINLINK) { + console.log("CHAINLNK"); + } + mockOracleData(op,bytes("xx")); + } + +} \ No newline at end of file diff --git a/src/oracle/lib/ChainlinkOracle.sol b/src/oracle/lib/ChainlinkOracle.sol index ba98159..20850c6 100644 --- a/src/oracle/lib/ChainlinkOracle.sol +++ b/src/oracle/lib/ChainlinkOracle.sol @@ -2,6 +2,7 @@ pragma solidity ^0.8.0; import "../../tokens/Tokens.sol"; + /** * ChainlinkOracle is a library used to facilitate interactions with Chainlink Oracles. * This includes functions to mock oracle data for testing and to retrieve context information @@ -9,7 +10,7 @@ import "../../tokens/Tokens.sol"; */ library ChainlinkOracle { struct Context { - EACAggregatorProxy aggregator; + FeedRegistryInterface registry; } /** @@ -20,6 +21,24 @@ library ChainlinkOracle { function mockOracleData(bytes memory data) internal { Context memory context = context(); + console.log("HEREEE"); + console.log(address(context.registry)); + + EACAggregatorProxy feed = context.registry.getFeed(0x514910771AF9Ca656af840dff83E8264EcF986CA,0x0000000000000000000000000000000000000348); + console.log(address(feed)); + + feed.decimals(); + + //vm.roll(100); + + //vm.prank(context.registry); + feed.latestAnswer(); + //feed.description(); + + + //console.log(feed.description()); + // feed.latestRoundData(); + // It's likely we can generalize this function to take a token pair to mock the returned price of, but we should provide a generic // function which can be used to mock any oracle data, not just price data. This way the Oracle specific library can have their own // wrapper function which serializes/deserializes the generic mock oracle data into the appropriate parameters. @@ -34,16 +53,16 @@ library ChainlinkOracle { * @return Context The context information for the current blockchain. */ function context() internal view returns (Context memory) { - EACAggregatorProxy aggregator; + FeedRegistryInterface registry; if (block.chainid == 1) { // Ethereum mainnet - aggregator = EACAggregatorProxy(0x72AFAECF99C9d9C8215fF44C77B94B99C28741e8); + registry = FeedRegistryInterface(0x47Fb2585D2C56Fe188D0E6ec628a38b74fCeeeDf); } else { revert("ChainlinkOracle: Chain not supported"); } - return Context(aggregator); + return Context(registry); } // /** @@ -74,6 +93,32 @@ library ChainlinkOracle { // } } +interface FeedRegistryInterface { + function latestRoundData( + address base, + address quote + ) + external + view + returns ( + uint80 roundId, + int256 answer, + uint256 startedAt, + uint256 updatedAt, + uint80 answeredInRound + ); + + function getFeed( + address base, + address quote + ) + external + view + returns ( + EACAggregatorProxy aggregator + ); +} + interface EACAggregatorProxy { event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 updatedAt); event NewRound(uint256 indexed roundId, address indexed startedBy, uint256 startedAt); diff --git a/test/examples/OracleMockExample.sol b/test/examples/OracleMockExample.sol new file mode 100644 index 0000000..2773616 --- /dev/null +++ b/test/examples/OracleMockExample.sol @@ -0,0 +1,22 @@ +pragma solidity ^0.8.13; + +import "forge-std/Test.sol"; +import "../../src/oracle/examples/OracleMockExample.sol"; + +contract OracleMockExampleTest is Test { + uint256 mainnetFork; + + OracleMockExample public oracleMockExample; + + function setUp() public { + mainnetFork = vm.createFork("eth"); + vm.selectFork(mainnetFork); + + oracleMockExample = new OracleMockExample(); + } + + function testMe() public { + console.log("XXX"); + oracleMockExample.initiateAttack(OracleProviders.CHAINLINK); + } +} \ No newline at end of file