GithubHelp home page GithubHelp logo

kitkatty / historical-price-feed-data Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pappas999/historical-price-feed-data

0.0 0.0 0.0 531 KB

Chainlink Data Feeds Historical Data

License: MIT License

Shell 0.28% JavaScript 53.05% Dockerfile 0.36% Solidity 46.31%

historical-price-feed-data's Introduction

Chainlink Data Feeds Historical Data

A Chainlink external adapter and consuming contract that allows obtaining verifiable historical Chainlink Price Feed data based on a proxy address and a search timestamp. Compatible with Ethereum testnet and mainnet, with all aggregator contract versions (including OCR aggregators)

Please note this is still in development, and should not be used in a production scenario without thorough testing beforehand.

For instructions on running the external adapter, please head to the historical-price-data external adapter README. The consumer contract in this repository needs to connect to an oracle running the external adapter in a job.

Take note, the solution is setup to use Chainlink multi-variable response, but for now uses a single delimited byte32 response until this issue is resolved

Live Deployment

The consumer contract has been deployed for users to interact with on the Kovan testnet at the following address. You can connect your MetaMask wallet and call the getHistoricalPriceData function, passing in a valid Kovan price feed address, and a unix timestamp. A LinkRiver hosted Chainlink node hosting a job and the external adapter will receive the request, and send a response, which can be viewed via the Read Contract tab. Values are as follows:

  • priceAnswer: price at that point in time
  • priceTimestamp: timestamp of the rounds answer
  • answerRound: proxy roundId for the answer. This can be verified by passing it into the existing getHistoricalPrice function

Requirements

Installation

Kovan Ethereum Testnet

Set your KOVAN_RPC_URL environment variable.. You can get one for free at Infura's site. You'll also need to set the variable PRIVATE_KEY which is your private key from your wallet, ie MetaMask. This is needed for deploying contracts to public networks.

Setting Environment Variables

You can set these in your .env file if you're unfamiliar with how setting environment variables work. Check out our .env example. If you wish to use this method to set these variables, update the values in the .env.example file, and then rename it to '.env'

WARNING

Don't commit and push any changes to .env files that may contain sensitive information, such as a private key! If this information reaches a public GitHub repository, someone can use it to check if you have any Mainnet funds in that wallet address, and steal them!

.env example:

KOVAN_RPC_URL='www.infura.io/asdfadsfafdadf'
MNEMONIC='cat dog frog...'
MAINNET_RPC_URL="https://eth-mainnet.alchemyapi.io/v2/your-api-key"
MUMBAI_RPC_URL='https://rpc-mumbai.maticvigil.com'
POLYGON_MAINNET_RPC_URL='https://rpc-mainnet.maticvigil.com'

bash example

export KOVAN_RPC_URL='www.infura.io/asdfadsfafdadf'
export MNEMONIC='cat dog frog...'
export MAINNET_RPC_URL='https://eth-mainnet.alchemyapi.io/v2/your-api-key'
export MUMBAI_RPC_URL='https://rpc-mumbai.maticvigil.com'
export POLYGON_MAINNET_RPC_URL='https://rpc-mainnet.maticvigil.com'

If you plan on deploying to a local Hardhat network that's a fork of the Ethereum mainnet instead of a public test network like Kovan, you'll also need to set your MAINNET_RPC_URL environment variable. and uncomment the forking section in hardhat.config.js. You can get one for free at Alchemy's site..

Then you can install all the dependencies

git clone https://github.com/pappas999/historical-price-feed-data/
cd historical-price-feed-data/contracts

then

npm install

Or

yarn

Deploy

Deployment scripts are in the deploy directory. If no network is specified, it will default to the Kovan network.

npx hardhat deploy

To specifically deploy to testnet:

npx hardhat deploy --network kovan

Run

The deployment output will give you the contract address as it's deployed. You can then use this contract address in conjunction with Hardhat tasks to perform operations on the contract

Historical Price Data

The Historical Price Consumer contract has two tasks, one to request historical price data based on a set of parameters, and one to check to see what the result of the data request is. This contract needs to be funded with link first:

Parameter Description Default Value
contract Address of the deployed consumer contract
proxy Proxy address of price feed Kovan ETH/USD
timestamp unix timestamp that you wish to know the price data for

First you need to fund your contract with link

npx hardhat fund-link --contract insert-contract-address-here --network network

Once it's funded, you can request historical price data by passing in a number of parameters to the request-historical-data task. All parameters are mandatory. The following command makes a request to obtain historical price data at unix timestamp 1625095820 (Wednesday, 30 June 2021 23:30:20) for the ETH/USD proxy contract running on the Kovan network.

npx hardhat request-historical-data --contract insert-contract-address-here --proxy 0x9326BFA02ADD2366b30bacB125260Af641031331 --timestamp 1625095820  --network kovan

Once you have successfully made a request for historical data, you can see the result via the read-data task

npx hardhat read-data --contract insert-contract-address-here --network network

historical-price-feed-data's People

Contributors

pappas999 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.