Skip to content

deckb/delphioracle

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EOS TITAN

https://eostitan.com

DelphiOracle

The DelphiOracle dApp acts as a multi-party source of truth, designed to provide the near-realtime price of the EOS/USD pair to other smart contracts or to external users.

The dApp allows the currently elected block producers and other qualified oracles to push the price of EOS expressed in USD, at a maximum frequency of 1 minute.

When a new datapoint is pushed to the contract, the contract will perform a continuous moving average calculation over the last 21 values pushed.

Consumer contracts or external applications can retrieve the last price and use it for their needs.

As more block producers and oracles will begin pushing the value at a 1 minute interval, confidence and accuracy of the value will increase.

This repository provides the code to the contract, as well as an updating script written in node.js for oracles and block producers to use. Ideally, block producers and oracles would use their own mechanism to retrieve the data, using various sources.

The upating script use cryptocompare.com's api to retrieve the EOS/USD price.

This contract has been deployed to the CryptoKylin testnet, on account delphioracle.

Compile and deploy oracle.cpp

Clone repository

cd delphioracle
cd contract
eosio-cpp oracle.cpp -o oracle.wasm
cleos set code <eoscontract> oracle.wasm
cleos set abi <eoscontract> oracle.abi

Push value to the contract

Qualified oracles and currently elected block producers can call the contract up to once every minute, to provide the current price of the EOS/USD pair.

Note: price must be pushed as integer, using the last 4 digits to represent the value after the decimal separator (10,000th of a dollar precision)

Example: a value for EOS/USD of $5.85 pushed by block producer acryptotitan to delphioracle contract would look like this:

cleos push action delphioracle write '{"owner":"acryptotitan", "value":58500}' -p acryptotitan@active

Set up and run updater.js

Updater.js is a nodejs module meant to retrieve the EOS/USD price using cryptocompare.com's API, and push the result to the DelphiOracle smart contract automatically and continuously.

cd scripts
npm install

Required: Copy sample.env to .env and update values

Example file for CryptoKylin:

EOS_PROTOCOL='http'
EOS_HOST='api.kylin.alohaeos.com'
EOS_PORT='80'
EOS_KEY='5... <replace with private key>'
EOS_CHAIN='5fff1dae8dc8e2fc4d5b23b2c7665c97f9e9d8edf2b6485a86ba311c25639191'
ORACLE="acryptotitan"
CONTRACT="delphioracle"
FREQ=15000
ORACLE_PERMISSION="active"

Run script:

node updater.js

Optional: Create a custom permission for oracle write action. Custom oracle permission can be supplied in the .env file under ORACLE_PERMISSION (defaults to active).

cleos set account permission <eosaccount> <permissionname> <eoskey> <permissionparent>
cleos set action permission <eosaccount> <eoscontract> <action> <permissionname>

Example:

cleos set account permission eostitantest oracle EOS6JhWzHJWystQmEv8VbXTHVagf5LKRVjkowwsdqCNYDFxYZQEJ9 active
cleos set action permission eostitantest delphioracle write oracle

Retrieve the last data point

Note: Use average / 10000 to get the actual value.

cleos get table <eoscontract> <eoscontract> eosusd --limit 1

Sample output:

{
  "rows": [{
      "id": "18446744073709551508",
      "owner": "acryptotitan",
      "value": 56800,
      "accumulator": 1194100,
      "average": 56863,
      "timestamp": "1538937978500000"
    }
  ],
  "more": true
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 87.0%
  • JavaScript 13.0%