- Implementation of a centralised Oracle which uses a VWAP (volume weighted average price) over a predefined period.
- Motivation for implimenting this is to minimise the risk of liquidations due to short-lived fluctuations in price.
- For more in depth information about the architecture see the
/docs
folder.
Read more about the blockservice here : https://github.com/Lamden/lamden_block_service
The blockservice is a lightweight application, it will need a 2 core machine, with at least 25gb space. As the Lamden blockchain grows it will be necessary to upgrade the disk space.
- Mongo DB (latest)
- Nodejs and NPM
- PM2 - https://pm2.keymetrics.io/docs/usage/quick-start/
- Clone https://github.com/cloakdkiller/lamden_block_service.git to your host machine.
- From project root
touch ecosystem.config.js
- nano
ecosystem.config.js
- paste the below code and press
ctrl-x
to exit & confirm you want to save.
module.exports = {
"apps" : [{
"name" : "block_service",
"script" : "npm run start",
"env": {
"NETWORK": "mainnet",
"BLOCKSERVICE_HOST": "0.0.0.0",
}}
]
}
I recommend you only allow connections from the machine which will be running the oracle process on ports 3535 & 3536
- Ensure mongo is running.
sudo systemctl start mongod.service
- From project root
pm2 start ecosystem.config.js
pm2 save
to set pm2 to run on system start.
The oracle is a lightweight application, it will need a 2 core machine, with at least 25gb space. This app does have a local DB which is it uses to store some state, as time goes on this may need to be upgraded.
- Nodejs and NPM
- PM2 - https://pm2.keymetrics.io/docs/usage/quick-start/
- Clone this repository to your host machine.
Open ecosystem.config.js
, edit required fields.
variable | explanation |
---|---|
block_service_urls | comma dilineated list of IP addresses e.g 0.0.0.0,78.4.2.3 |
check_eth_price_frequency | how often the ETH price is synced to the local DB |
etherscan_api_key | get one here |
network | mainnet or testnet |
operator_sk | the SK which will be writing the value to the blockchain |
operator_vk | VK of above. |
amm_contract | the rocketswap contract, don't change this |
oracle_contract | contract to call set_price on |
vwap_period_seconds | How many seconds the VWAP is calculated over, default is 86400 (1 day) |
vwap_submission_frequency | How often the VWAP is calculated and submitted to the blockchain in milliseconds |
sync_trades_from_bs_frequency | how often the API will sync new trades from the block-service, in milliseconds. default 10,000 |
submit_vwap_to_blockchain | true or false . determines whether the application should submit values to the blockchain. |
It's recommended that you block all incoming connections, except for SSH connections from whitelisted IP addresses, and port 3000, again whitelisted IP's only. Your cloud provider should provide an interface for this.
If you wish to provide a data visualisation in the rubix application, a sensible approach might be to :
- create a data-vis microservice on a seperate machine (perhaps the rubix UI server),
- microservice would forward api calls to the oracle process
- microservice IP would be whitelisted by the oracle firewall.
if the UI is experiencing significant load, a seperate instance of the oracle process could be created, with blockchain submission functionality disabled.
- From the project root directory
pm2 start ecosystem.config.js
- Configure this service to run at system startup
pm2 save
There is a basic REST API, which allows querying values in the local DB. For convenience there is a swagger dashboard available at <server_ip>:3000/api, once the application is running.
This api could form the basis for basic data visualisations.