2020-10-05 17:22:52 +03:00
|
|
|
const Redis = require('ioredis')
|
2021-02-09 20:14:37 +03:00
|
|
|
const { redisUrl, oracleAddress, oracleRpcUrl } = require('./config')
|
2020-10-05 17:22:52 +03:00
|
|
|
const { getArgsForOracle, setSafeInterval } = require('./utils')
|
|
|
|
const redis = new Redis(redisUrl)
|
|
|
|
const Web3 = require('web3')
|
|
|
|
const web3 = new Web3(oracleRpcUrl)
|
|
|
|
|
|
|
|
const priceOracleABI = require('../abis/PriceOracle.abi.json')
|
|
|
|
const oracle = new web3.eth.Contract(priceOracleABI, oracleAddress)
|
|
|
|
const { tokenAddresses, oneUintAmount, currencyLookup } = getArgsForOracle()
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const prices = await oracle.methods.getPricesInETH(tokenAddresses, oneUintAmount).call()
|
|
|
|
const ethPrices = prices.reduce((acc, price, i) => {
|
|
|
|
acc[currencyLookup[tokenAddresses[i]]] = price
|
|
|
|
return acc
|
|
|
|
}, {})
|
|
|
|
await redis.hmset('prices', ethPrices)
|
|
|
|
console.log('Wrote following prices to redis', ethPrices)
|
|
|
|
}
|
|
|
|
|
|
|
|
setSafeInterval(main, 30 * 1000)
|