The Oracle-Backend is an off-chain service that handles regularly posting of price feeds to the Oracle smart contract.
Poster is a class we can instantiate to fetch price data from multiple sources and post it to the Oracle smart contract on the specified EVM chain.
class Poster {
async Fetch();
async Post(price?: string);
}Scheduler is used for regularly posting price data using the Poster class. It uses a configuration file for instantiating the Poster class.
const poster = new Poster(process.env.PK!, {
RPC: config.RPC,
CONTRACTADDRESS: config.ADDRESS
});FetchPrice contains a set of utility functions for fetching and processing prices from implemented data sources.
const PriceFetchImplementation: any = {
"coingecko": async () => {
const response = await axios.get('https://api.coingecko.com/api/v3/simple/price?ids=cardano&vs_currencies=usd')
return response.data.cardano.usd
},
"redstone": async () => {
const response = await axios.get('https://api.redstone.finance/prices?symbol=ADA&provider=redstone&limit=1')
return response.data[0].value
}
}The scheduler and related config file is in the root directory.
You first need to set up the config file with your deployed Oracle contract address and the RPC URL for the EVM chain on which this Oracle contract is deployed.
{
"RPC": "https://rpc-devnet-cardano-evm.c1.milkomeda.com",
"ADDRESS": "0x2635098CB39A17B1a2777F12B92F8E34C12927F6",
"SCHEDULE": 5000,
"THRESHOLD": 0.01
}You need an account with some funds in it. This account will be issuing transaction to post price data on the Oracle contract. This account must be the owner for the deployed contract.
Add your account's private key inside .env in the root directory (without double quotes).
PK=OWNER-PRIVATE-KEYThis will install dependencies required to run this scheduler.
npm installThis will start the scheduler in development mode
npm run devThe following command will build the Javascript version for the Typescript code inside build directory.
npm run buildThe following command will start the scheduler from the build directory. This should only be run after successfully building the Javascript build.
npm startFollow the below steps to start the Docker container for this oracle.
The below command will create a Docker image named oracle-scheduler-image
docker build . -t oracle-scheduler-imageWe can create multiple Docker containers from the above image.
docker run --name oracle-scheduler-container --env-file ../.env oracle-scheduler-imageWe can supply different .env files for different containers as well using the --env-file flag.
You can stop the container using the below command.
docker stop oracle-scheduler-containerYou can restart the stopped container as well.
docker restart oracle-scheduler-container