Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# build environment
FROM node:14.5.0-alpine

## ENV variables
ENV PERM=active

WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY scripts/package.json ./
COPY scripts/package-lock.json ./
COPY scripts/docker-updater.js ./updater.js
COPY scripts/docker.env .env


RUN npm ci
RUN npm install [email protected] -g


# Entrypoint
ADD scripts/start.sh /
RUN chmod +x /start.sh
CMD /start.sh
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,45 @@ if you have `jq` installed, you can show the first record, which should contain
```
cleos get table --limit 100 delphioracle eosusd datapoints |jq .rows[0]
```

# Running the updater.js using Docker
## :exclamation: Updater in docker uses EOSJS v2

## ENV Variables

|ENV & ARG |Value |Description |
|--------------------------|-------------------------------|-----------------------------------------------|
|**PRIVATE_KEY** |`5xxxxxxxxxxxx` | The prviate key of your permission |
|**BPNAME** |`sentnlagents` | Your BP account |
|**PERM** |`oracle` | If using Custom permission; defaults to active|
|**API** |`waxapi.sentnl.io` | Wax API endpoint |
|**CHAIN** |`wax` | The EOSIO Chain that hosts the delphioracle |
|**APIPORT** |`443` | The port of API endpoint |

## Build the production container

```
docker build https://github.com/ankh2054/delphioracle.git -t delphioracle
```

## Run the container passing required ENV variables


### The following ENV variables need to be passed:

- **BPNAME** - The name of your bp account
- **PERM** - The permissions to sign the transaction with. Defaults to active.
- **API** - The API endpoint you wish to use.
- **CHAIN** - The EOSIO Chain that hosts the delphioracle. :exclamation: Currently only WAX and EOS is supported.

```Dockerfile:
docker run --name delphioracle.wax \
-d -e "PRIVATE_KEY=xxxxxxxxxxxxx" \
-e "BPNAME=sentnlagents" \
-e "PERM=oracle" \
-e "API=waxapi.sentnl.io" \
-e "APIPORT=4343" \
-e "CHAIN=wax" \
delphioracle
```

91 changes: 91 additions & 0 deletions scripts/docker-updater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// EOSJS version 2 used
const { Api, JsonRpc, RpcError } = require('eosjs');
const fetch = require('node-fetch');
const { TextEncoder, TextDecoder } = require('util');
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig');
const axios = require('axios');
const dotenv = require('dotenv');

dotenv.load();

var chain = process.env.CHAIN;
var cryptocompareKey = process.env.CRYPTOCOMPARE;
priceUrl = `https://min-api.cryptocompare.com/data/pricemulti?fsyms=WAXP,USDC,USDT&tsyms=BTC,USD,ETH,EOS&api_key=${cryptocompareKey}`;
usdpair = "waxpusd";
btcpair = "waxpbtc";
eospair = "waxpeos";
ethpair = "waxpeth";
usdcpair = "usdcusd";
usdtpair = "usdtusd";

const owner = process.env.ORACLE;
const oracleContract = process.env.CONTRACT;
const defaultPrivateKey = process.env.EOS_KEY;
const permission = process.env.ORACLE_PERMISSION;
const httpEndpoint = process.env.EOS_PROTOCOL + "://" + process.env.EOS_HOST + ":" + process.env.EOS_PORT;

console.log(owner,oracleContract,permission)
const rpc = new JsonRpc(httpEndpoint, { fetch });
const signatureProvider = new JsSignatureProvider([defaultPrivateKey]);
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });


const eosmain = async (quotes2) => {
try {
const result = await api.transact({
actions: [{
account: oracleContract,
name: 'write',
authorization: [{
actor: owner,
permission: permission,
}],
data: {
owner: owner,
quotes: quotes2
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.dir(result);
} catch (e) {
console.log('\nCaught exception: ' + e);
if (e instanceof RpcError)
console.log(JSON.stringify(e.json, null, 2));
}
}

async function writequotes() {
try {
const waxpResponse = await axios.get(priceUrl);
const [usdcResponse, usdtResponse] = await Promise.all([
axios.get('https://api.coingecko.com/api/v3/simple/price?ids=usd-coin&vs_currencies=usd'),
axios.get('https://api.coingecko.com/api/v3/simple/price?ids=tether&vs_currencies=usd')
]);

const waxpData = waxpResponse.data;
const usdcPrice = usdcResponse.data['usd-coin'].usd;
const usdtPrice = usdtResponse.data.tether.usd;

const quotes2 = [
{ "value": Math.round(waxpData.WAXP.BTC * 100000000), pair: btcpair },
{ "value": Math.round(waxpData.WAXP.USD * 10000), pair: usdpair },
{ "value": Math.round(waxpData.WAXP.ETH * 100000000), pair: ethpair },
{ "value": Math.round(waxpData.WAXP.EOS * 1000000), pair: eospair },
{ "value": Math.round(usdcPrice * 10000), pair: usdcpair },
{ "value": Math.round(usdtPrice * 10000), pair: usdtpair }
];

console.log(quotes2);
await eosmain(quotes2);
} catch (error) {
console.log('\nCaught exception: ' + error);
if (error instanceof RpcError) {
console.log(JSON.stringify(error.json, null, 2));
}
}
}

writequotes();
11 changes: 11 additions & 0 deletions scripts/docker.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
EOS_PROTOCOL='<replace with api protocol>'
EOS_HOST='<replace with api endpoint>'
EOS_PORT='<replace with api port>'
EOS_KEY='<replace with private key>'
EOS_CHAIN='<replace with chain id>'
ORACLE="bpname"
CONTRACT="delphioracle"
FREQ=15000
ORACLE_PERMISSION="permission"
CHAIN='<replace with chain name>'
CRYPTOCOMPARE='<replace with api key>'
Loading