mirror of
https://github.com/tornadocash/tornado-relayer.git
synced 2025-08-15 01:25:33 -04:00
dai price
This commit is contained in:
parent
53828dca12
commit
2d2115ab43
5 changed files with 38 additions and 6 deletions
18
utils.js
18
utils.js
|
@ -1,6 +1,7 @@
|
|||
const fetch = require('node-fetch')
|
||||
const { isHexStrict } = require('web3-utils')
|
||||
const { gasOracleUrls } = require('./config')
|
||||
const { isHexStrict, hexToNumberString } = require('web3-utils')
|
||||
const { gasOracleUrls, ethdaiAddress } = require('./config')
|
||||
const oracleABI = require('./abis/ETHDAIOracle.json')
|
||||
|
||||
async function fetchGasPrice({ gasPrices, oracleIndex = 0 }) {
|
||||
oracleIndex = (oracleIndex + 1) % gasOracleUrls.length
|
||||
|
@ -30,6 +31,17 @@ async function fetchGasPrice({ gasPrices, oracleIndex = 0 }) {
|
|||
}
|
||||
}
|
||||
|
||||
async function fetchDAIprice({ ethPriceInDai, web3 }) {
|
||||
try {
|
||||
const ethDaiInstance = web3.eth.Contract(oracleABI, ethdaiAddress)
|
||||
const price = await ethDaiInstance.methods.getMedianPrice().call()
|
||||
ethPriceInDai = hexToNumberString(price)
|
||||
setTimeout(() => fetchDAIprice({ ethPriceInDai, web3 }), 1000 * 30)
|
||||
} catch(e) {
|
||||
setTimeout(() => fetchDAIprice({ ethPriceInDai, web3 }), 1000 * 30)
|
||||
}
|
||||
}
|
||||
|
||||
function isValidProof(proof) {
|
||||
// validator expects `websnarkUtils.toSolidityInput(proof)` output
|
||||
|
||||
|
@ -82,4 +94,4 @@ function sleep(ms) {
|
|||
return new Promise(resolve => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
module.exports = { fetchGasPrice, isValidProof, sleep }
|
||||
module.exports = { fetchGasPrice, isValidProof, sleep, fetchDAIprice }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue