tornado-relayer/src/priceWatcher.js

20 lines
616 B
JavaScript
Raw Normal View History

const { setSafeInterval, RelayerError, logRelayerError } = require('./utils')
const { redis } = require('./modules/redis')
const { TokenPriceOracle } = require('@tornado/tornado-oracles')
const { oracleRpcUrl } = require('./config')
2020-10-05 17:22:52 +03:00
const priceOracle = new TokenPriceOracle(oracleRpcUrl)
2020-10-05 17:22:52 +03:00
async function main() {
2021-03-02 07:38:16 +03:00
try {
const ethPrices = await priceOracle.fetchPrices()
2021-03-02 07:38:16 +03:00
await redis.hmset('prices', ethPrices)
console.log('Wrote following prices to redis', ethPrices)
} catch (e) {
2022-04-20 08:41:59 +03:00
await logRelayerError(redis, e)
2021-03-02 07:38:16 +03:00
console.error('priceWatcher error', e)
2021-02-26 12:52:15 +03:00
}
2020-10-05 17:22:52 +03:00
}
setSafeInterval(main, 30 * 1000)