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

Use chainlink oracle #168

Open
werg opened this issue Sep 15, 2021 · 0 comments
Open

Use chainlink oracle #168

werg opened this issue Sep 15, 2021 · 0 comments

Comments

@werg
Copy link
Contributor

werg commented Sep 15, 2021

We want to create a contract satisfying this interface: https://github.com/marginswap/marginswap-core/blob/main/interfaces/IOracle.sol

In order to do so we need:

Call chainlink

write a function using this chainlink library: import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";

Here's a very rough sketch

address oracleAddress = tokenOracles[tokenAddress];
AggregatorV3Interface oracle = AggregatorV3Interface(oracleAddress);
        (
            uint80 roundID,
            int256 tokenPrice,
            uint256 startedAt,
            uint256 timeStamp,
            uint80 answeredInRound
        ) = oracle.latestRoundData();

return inAmount * tokenPrice * PEG_EXPONENT / oracleExponent[tokenADdress] / tokenExponent[tokenAddress];

This function likely would be a view function, so could be used to implement both the required functions of the interface.

Store metadata

We need a way to tell the contract which oracle to ask for each token, this should be a onlyOwnerExec gated function in the contract. It should store things such as the oracleExponent and tokenExponent as well as the address of teh oracle contract. You can find links to oracle contracts here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant