mirror of
https://github.com/tornadocash/tornado-relayer
synced 2024-02-02 15:04:06 +01:00
remove multicall
This commit is contained in:
parent
77021a52a9
commit
0dd025bd30
@ -1,22 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"components": [
|
|
||||||
{ "internalType": "address", "name": "to", "type": "address" },
|
|
||||||
{ "internalType": "bytes", "name": "data", "type": "bytes" }
|
|
||||||
],
|
|
||||||
"internalType": "struct MultiCall.Call[]",
|
|
||||||
"name": "calls",
|
|
||||||
"type": "tuple[]"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "multicall",
|
|
||||||
"outputs": [
|
|
||||||
{ "internalType": "bytes[]", "name": "results", "type": "bytes[]" },
|
|
||||||
{ "internalType": "bool[]", "name": "success", "type": "bool[]" }
|
|
||||||
],
|
|
||||||
"stateMutability": "view",
|
|
||||||
"type": "function"
|
|
||||||
}
|
|
||||||
]
|
|
@ -8,8 +8,7 @@ module.exports = {
|
|||||||
httpRpcUrl: process.env.HTTP_RPC_URL,
|
httpRpcUrl: process.env.HTTP_RPC_URL,
|
||||||
wsRpcUrl: process.env.WS_RPC_URL,
|
wsRpcUrl: process.env.WS_RPC_URL,
|
||||||
oracleRpcUrl: process.env.ORACLE_RPC_URL || 'https://mainnet.infura.io/',
|
oracleRpcUrl: process.env.ORACLE_RPC_URL || 'https://mainnet.infura.io/',
|
||||||
offchainOracleAddress: '0x080ab73787a8b13ec7f40bd7d00d6cc07f9b24d0',
|
offchainOracleAddress: '0x080AB73787A8B13EC7F40bd7d00d6CC07F9b24d0',
|
||||||
multiCallAddress: '0xda3c19c6fe954576707fa24695efb830d9cca1ca',
|
|
||||||
aggregatorAddress: process.env.AGGREGATOR,
|
aggregatorAddress: process.env.AGGREGATOR,
|
||||||
minerMerkleTreeHeight: 20,
|
minerMerkleTreeHeight: 20,
|
||||||
privateKey: process.env.PRIVATE_KEY,
|
privateKey: process.env.PRIVATE_KEY,
|
||||||
|
@ -1,48 +1,42 @@
|
|||||||
const Redis = require('ioredis')
|
const Redis = require('ioredis')
|
||||||
const { redisUrl, offchainOracleAddress, multiCallAddress, oracleRpcUrl } = require('./config')
|
const { redisUrl, offchainOracleAddress, oracleRpcUrl } = require('./config')
|
||||||
const { getArgsForOracle, setSafeInterval } = require('./utils')
|
const { getArgsForOracle, setSafeInterval } = require('./utils')
|
||||||
const redis = new Redis(redisUrl)
|
const redis = new Redis(redisUrl)
|
||||||
const Web3 = require('web3')
|
const Web3 = require('web3')
|
||||||
const web3 = new Web3(oracleRpcUrl)
|
const web3 = new Web3(oracleRpcUrl, {
|
||||||
|
timeout: 200000, // ms
|
||||||
|
})
|
||||||
|
|
||||||
const multiCallABI = require('../abis/MultiCall.abi.json')
|
|
||||||
const offchainOracleABI = require('../abis/OffchainOracle.abi.json')
|
const offchainOracleABI = require('../abis/OffchainOracle.abi.json')
|
||||||
|
|
||||||
const offchainOracle = new web3.eth.Contract(offchainOracleABI)
|
const offchainOracle = new web3.eth.Contract(offchainOracleABI, offchainOracleAddress)
|
||||||
const multiCall = new web3.eth.Contract(multiCallABI, multiCallAddress)
|
|
||||||
const { tokenAddresses, oneUintAmount, currencyLookup } = getArgsForOracle()
|
const { tokenAddresses, oneUintAmount, currencyLookup } = getArgsForOracle()
|
||||||
|
|
||||||
const { toBN } = require('web3-utils')
|
const { toBN } = require('web3-utils')
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const callData = tokenAddresses.map(address => ({
|
try {
|
||||||
to: offchainOracleAddress,
|
const ethPrices = {}
|
||||||
data: offchainOracle.methods
|
for (let i = 0; i < tokenAddresses.length; i++) {
|
||||||
.getRate(
|
try {
|
||||||
address,
|
const price = await offchainOracle.methods
|
||||||
'0x0000000000000000000000000000000000000000', // rate to ETH
|
.getRate(tokenAddresses[i], '0x0000000000000000000000000000000000000000')
|
||||||
)
|
.call()
|
||||||
.encodeABI(),
|
const numerator = toBN(oneUintAmount[i])
|
||||||
}))
|
const denominator = toBN(10).pow(toBN(18)) // eth decimals
|
||||||
|
const priceFormatted = toBN(price).mul(numerator).div(denominator)
|
||||||
|
|
||||||
const { results, success } = await multiCall.methods.multicall(callData).call()
|
ethPrices[currencyLookup[tokenAddresses[i]]] = priceFormatted.toString()
|
||||||
|
} catch (e) {
|
||||||
const ethPrices = {}
|
console.error('cant get price of ', tokenAddresses[i])
|
||||||
for (let i = 0; i < results.length; i++) {
|
}
|
||||||
if (!success[i]) {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const decodedRate = web3.eth.abi.decodeParameter('uint256', results[i]).toString()
|
await redis.hmset('prices', ethPrices)
|
||||||
const numerator = toBN(oneUintAmount[i])
|
console.log('Wrote following prices to redis', ethPrices)
|
||||||
const denominator = toBN(10).pow(toBN(18)) // eth decimals
|
} catch (e) {
|
||||||
const price = toBN(decodedRate).mul(numerator).div(denominator)
|
console.error('priceWatcher error', e)
|
||||||
|
|
||||||
ethPrices[currencyLookup[tokenAddresses[i]]] = price.toString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await redis.hmset('prices', ethPrices)
|
|
||||||
console.log('Wrote following prices to redis', ethPrices)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setSafeInterval(main, 30 * 1000)
|
setSafeInterval(main, 30 * 1000)
|
||||||
|
@ -22,13 +22,17 @@ let tree, eventSubscription, blockSubscription
|
|||||||
|
|
||||||
// todo handle the situation when we have two rewards in one block
|
// todo handle the situation when we have two rewards in one block
|
||||||
async function fetchEvents(from = 0, to = 'latest') {
|
async function fetchEvents(from = 0, to = 'latest') {
|
||||||
const events = await contract.getPastEvents('NewAccount', {
|
try {
|
||||||
fromBlock: from,
|
const events = await contract.getPastEvents('NewAccount', {
|
||||||
toBlock: to,
|
fromBlock: from,
|
||||||
})
|
toBlock: to,
|
||||||
return events
|
})
|
||||||
.sort((a, b) => a.returnValues.index - b.returnValues.index)
|
return events
|
||||||
.map(e => toBN(e.returnValues.commitment))
|
.sort((a, b) => a.returnValues.index - b.returnValues.index)
|
||||||
|
.map(e => toBN(e.returnValues.commitment))
|
||||||
|
} catch (e) {
|
||||||
|
console.error('error fetching events', e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processNewEvent(err, event) {
|
async function processNewEvent(err, event) {
|
||||||
@ -95,16 +99,20 @@ async function rebuild() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
console.log('Initializing')
|
try {
|
||||||
const miner = await resolver.resolve(torn.miningV2.address)
|
console.log('Initializing')
|
||||||
contract = new web3.eth.Contract(MinerABI, miner)
|
const miner = await resolver.resolve(torn.miningV2.address)
|
||||||
const block = await web3.eth.getBlockNumber()
|
contract = new web3.eth.Contract(MinerABI, miner)
|
||||||
const events = await fetchEvents(0, block)
|
const block = await web3.eth.getBlockNumber()
|
||||||
tree = new MerkleTree(minerMerkleTreeHeight, events, { hashFunction: poseidonHash2 })
|
const events = await fetchEvents(0, block)
|
||||||
console.log(`Rebuilt tree with ${events.length} elements, root: ${tree.root()}`)
|
tree = new MerkleTree(minerMerkleTreeHeight, events, { hashFunction: poseidonHash2 })
|
||||||
eventSubscription = contract.events.NewAccount({ fromBlock: block + 1 }, processNewEvent)
|
console.log(`Rebuilt tree with ${events.length} elements, root: ${tree.root()}`)
|
||||||
blockSubscription = web3.eth.subscribe('newBlockHeaders', processNewBlock)
|
eventSubscription = contract.events.NewAccount({ fromBlock: block + 1 }, processNewEvent)
|
||||||
await updateRedis()
|
blockSubscription = web3.eth.subscribe('newBlockHeaders', processNewBlock)
|
||||||
|
await updateRedis()
|
||||||
|
} catch (e) {
|
||||||
|
console.error('error on init treeWatcher', e.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init()
|
init()
|
||||||
|
@ -3,7 +3,7 @@ const { poseidon } = require('circomlib')
|
|||||||
const { toBN, toChecksumAddress, BN } = require('web3-utils')
|
const { toBN, toChecksumAddress, BN } = require('web3-utils')
|
||||||
|
|
||||||
const TORN_TOKEN = {
|
const TORN_TOKEN = {
|
||||||
tokenAddress: '0x77777feddddffc19ff86db637967013e6c6a116c',
|
tokenAddress: '0x77777FeDdddFfC19Ff86DB637967013e6C6A116C',
|
||||||
symbol: 'TORN',
|
symbol: 'TORN',
|
||||||
decimals: 18,
|
decimals: 18,
|
||||||
}
|
}
|
||||||
|
@ -74,26 +74,30 @@ async function fetchTree() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
web3 = new Web3(httpRpcUrl)
|
try {
|
||||||
const { CONFIRMATIONS, MAX_GAS_PRICE } = process.env
|
web3 = new Web3(httpRpcUrl)
|
||||||
txManager = new TxManager({
|
const { CONFIRMATIONS, MAX_GAS_PRICE } = process.env
|
||||||
privateKey,
|
txManager = new TxManager({
|
||||||
rpcUrl: httpRpcUrl,
|
privateKey,
|
||||||
config: { CONFIRMATIONS, MAX_GAS_PRICE, THROW_ON_REVERT: false },
|
rpcUrl: httpRpcUrl,
|
||||||
})
|
config: { CONFIRMATIONS, MAX_GAS_PRICE, THROW_ON_REVERT: false },
|
||||||
swap = new web3.eth.Contract(swapABI, await resolver.resolve(torn.rewardSwap.address))
|
})
|
||||||
minerContract = new web3.eth.Contract(miningABI, await resolver.resolve(torn.miningV2.address))
|
swap = new web3.eth.Contract(swapABI, await resolver.resolve(torn.rewardSwap.address))
|
||||||
proxyContract = new web3.eth.Contract(tornadoProxyABI, await resolver.resolve(torn.tornadoProxy.address))
|
minerContract = new web3.eth.Contract(miningABI, await resolver.resolve(torn.miningV2.address))
|
||||||
redisSubscribe.subscribe('treeUpdate', fetchTree)
|
proxyContract = new web3.eth.Contract(tornadoProxyABI, await resolver.resolve(torn.tornadoProxy.address))
|
||||||
await fetchTree()
|
redisSubscribe.subscribe('treeUpdate', fetchTree)
|
||||||
const provingKeys = {
|
await fetchTree()
|
||||||
treeUpdateCircuit: require('../keys/TreeUpdate.json'),
|
const provingKeys = {
|
||||||
treeUpdateProvingKey: fs.readFileSync('./keys/TreeUpdate_proving_key.bin').buffer,
|
treeUpdateCircuit: require('../keys/TreeUpdate.json'),
|
||||||
|
treeUpdateProvingKey: fs.readFileSync('./keys/TreeUpdate_proving_key.bin').buffer,
|
||||||
|
}
|
||||||
|
controller = new Controller({ provingKeys })
|
||||||
|
await controller.init()
|
||||||
|
queue.process(processJob)
|
||||||
|
console.log('Worker started')
|
||||||
|
} catch (e) {
|
||||||
|
console.error('error on start worker', e.message)
|
||||||
}
|
}
|
||||||
controller = new Controller({ provingKeys })
|
|
||||||
await controller.init()
|
|
||||||
queue.process(processJob)
|
|
||||||
console.log('Worker started')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkFee({ data }) {
|
function checkFee({ data }) {
|
||||||
|
Loading…
Reference in New Issue
Block a user