Skip to content

DjedAlliance/Oracle-Backend

Repository files navigation

Oracle-Backend

The Oracle-Backend is an off-chain service that handles regularly posting of price feeds to the Oracle smart contract.

Oracle Poster

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

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

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
    }
}

Starting the Oracle Scheduler

The scheduler and related config file is in the root directory.

Configuration

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
}

Account Setup

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-KEY

Installing Dependencies

This will install dependencies required to run this scheduler.

npm install

Starting in Development Mode

This will start the scheduler in development mode

npm run dev

Building for Production

The following command will build the Javascript version for the Typescript code inside build directory.

npm run build

Starting in Production Mode

The following command will start the scheduler from the build directory. This should only be run after successfully building the Javascript build.

npm start

Docker Setup

Follow the below steps to start the Docker container for this oracle.

Build Docker Image

The below command will create a Docker image named oracle-scheduler-image

docker build . -t oracle-scheduler-image

Creating Docker Container

We can create multiple Docker containers from the above image.

docker run --name oracle-scheduler-container --env-file ../.env oracle-scheduler-image

We can supply different .env files for different containers as well using the --env-file flag.

Stopping Docker Container

You can stop the container using the below command.

docker stop oracle-scheduler-container

Restarting Docker Container

You can restart the stopped container as well.

docker restart oracle-scheduler-container

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors