update proxy

This commit is contained in:
Danil Kovtonyuk 2021-03-17 22:39:34 +10:00 committed by Alexey Pertsev
parent 80f9d4017f
commit 5d4ae5965c
5 changed files with 773 additions and 52 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "relay", "name": "relay",
"version": "4.0.9", "version": "4.0.10",
"description": "Relayer for Tornado.cash privacy solution. https://tornado.cash", "description": "Relayer for Tornado.cash privacy solution. https://tornado.cash",
"scripts": { "scripts": {
"server": "node src/server.js", "server": "node src/server.js",
@ -29,8 +29,8 @@
"gas-price-oracle": "^0.2.2", "gas-price-oracle": "^0.2.2",
"ioredis": "^4.14.1", "ioredis": "^4.14.1",
"node-fetch": "^2.6.0", "node-fetch": "^2.6.0",
"torn-token": "1.0.3", "torn-token": "1.0.4",
"tornado-cash-anonymity-mining": "^1.0.0", "tornado-anonymity-mining": "^2.1.2",
"tx-manager": "^0.2.9", "tx-manager": "^0.2.9",
"uuid": "^8.3.0", "uuid": "^8.3.0",
"web3": "^1.3.0", "web3": "^1.3.0",

View File

@ -18,11 +18,11 @@ module.exports = {
tornadoServiceFee: Number(process.env.REGULAR_TORNADO_WITHDRAW_FEE), tornadoServiceFee: Number(process.env.REGULAR_TORNADO_WITHDRAW_FEE),
miningServiceFee: Number(process.env.MINING_SERVICE_FEE), miningServiceFee: Number(process.env.MINING_SERVICE_FEE),
rewardAccount: process.env.REWARD_ACCOUNT, rewardAccount: process.env.REWARD_ACCOUNT,
tornadoGoerliProxy: '0x454d870a72e29d5E5697f635128D18077BD04C60',
gasLimits: { gasLimits: {
[jobType.TORNADO_WITHDRAW]: 350000, [jobType.TORNADO_WITHDRAW]: 350000,
[jobType.MINING_REWARD]: 455000, [jobType.MINING_REWARD]: 455000,
[jobType.MINING_WITHDRAW]: 400000, [jobType.MINING_WITHDRAW]: 400000,
}, },
tornadoProxy: '0x454d870a72e29d5E5697f635128D18077BD04C60',
minimumBalance: '1000000000000000000', minimumBalance: '1000000000000000000',
} }

View File

@ -2,10 +2,12 @@ const { instances, netId } = require('./config')
const { poseidon } = require('circomlib') const { poseidon } = require('circomlib')
const { toBN, toChecksumAddress, BN } = require('web3-utils') const { toBN, toChecksumAddress, BN } = require('web3-utils')
const TORN_TOKEN = { const TOKENS = {
torn: {
tokenAddress: '0x77777FeDdddFfC19Ff86DB637967013e6C6A116C', tokenAddress: '0x77777FeDdddFfC19Ff86DB637967013e6C6A116C',
symbol: 'TORN', symbol: 'TORN',
decimals: 18, decimals: 18,
},
} }
const sleep = ms => new Promise(res => setTimeout(res, ms)) const sleep = ms => new Promise(res => setTimeout(res, ms))
@ -52,7 +54,7 @@ function when(source, event) {
function getArgsForOracle() { function getArgsForOracle() {
const tokens = { const tokens = {
...instances.netId1, ...instances.netId1,
torn: TORN_TOKEN, ...TOKENS,
} }
const tokenAddresses = [] const tokenAddresses = []
const oneUintAmount = [] const oneUintAmount = []

View File

@ -1,35 +1,34 @@
const fs = require('fs') const fs = require('fs')
const Web3 = require('web3') const Web3 = require('web3')
const { toBN, toWei, fromWei } = require('web3-utils') const { toBN, toWei, fromWei, toChecksumAddress } = require('web3-utils')
const MerkleTree = require('fixed-merkle-tree') const MerkleTree = require('fixed-merkle-tree')
const Redis = require('ioredis') const Redis = require('ioredis')
const { GasPriceOracle } = require('gas-price-oracle') const { GasPriceOracle } = require('gas-price-oracle')
const { Utils } = require('tornado-cash-anonymity-mining') const { Utils, Controller } = require('tornado-anonymity-mining')
const tornadoProxyABI = require('../abis/tornadoProxyABI.json')
const tornadoABI = require('../abis/tornadoABI.json')
const miningABI = require('../abis/mining.abi.json')
const swapABI = require('../abis/swap.abi.json') const swapABI = require('../abis/swap.abi.json')
const miningABI = require('../abis/mining.abi.json')
const tornadoABI = require('../abis/tornadoABI.json')
const tornadoProxyABI = require('../abis/tornadoProxyABI.json')
const { queue } = require('./queue') const { queue } = require('./queue')
const { poseidonHash2, getInstance, fromDecimals, sleep } = require('./utils') const { poseidonHash2, getInstance, fromDecimals, sleep } = require('./utils')
const { jobType, status } = require('./constants') const { jobType, status } = require('./constants')
const { const {
netId,
torn, torn,
httpRpcUrl, netId,
redisUrl, redisUrl,
privateKey,
gasLimits, gasLimits,
instances, instances,
privateKey,
httpRpcUrl,
oracleRpcUrl, oracleRpcUrl,
tornadoProxy,
tornadoServiceFee,
miningServiceFee, miningServiceFee,
tornadoServiceFee,
tornadoGoerliProxy,
} = require('./config') } = require('./config')
const ENSResolver = require('./resolver') const ENSResolver = require('./resolver')
const resolver = new ENSResolver() const resolver = new ENSResolver()
const { TxManager } = require('tx-manager') const { TxManager } = require('tx-manager')
const { Controller } = require('tornado-cash-anonymity-mining')
let web3 let web3
let currentTx let currentTx
@ -39,7 +38,6 @@ let txManager
let controller let controller
let swap let swap
let minerContract let minerContract
let proxyContract
const redis = new Redis(redisUrl) const redis = new Redis(redisUrl)
const redisSubscribe = new Redis(redisUrl) const redisSubscribe = new Redis(redisUrl)
const gasPriceOracle = new GasPriceOracle({ defaultRpc: oracleRpcUrl }) const gasPriceOracle = new GasPriceOracle({ defaultRpc: oracleRpcUrl })
@ -85,14 +83,6 @@ async function start() {
}) })
swap = new web3.eth.Contract(swapABI, await resolver.resolve(torn.rewardSwap.address)) swap = new web3.eth.Contract(swapABI, await resolver.resolve(torn.rewardSwap.address))
minerContract = new web3.eth.Contract(miningABI, await resolver.resolve(torn.miningV2.address)) minerContract = new web3.eth.Contract(miningABI, await resolver.resolve(torn.miningV2.address))
if (netId === 5) {
proxyContract = new web3.eth.Contract(tornadoProxyABI, tornadoProxy)
} else {
proxyContract = new web3.eth.Contract(
tornadoProxyABI,
await resolver.resolve(torn.tornadoProxy.address),
)
}
redisSubscribe.subscribe('treeUpdate', fetchTree) redisSubscribe.subscribe('treeUpdate', fetchTree)
await fetchTree() await fetchTree()
const provingKeys = { const provingKeys = {
@ -184,16 +174,37 @@ async function checkMiningFee({ args }) {
} }
} }
function getTxObject({ data }) { async function getProxyContract() {
let proxyAddress = await resolver.resolve(torn.tornadoProxy.address)
if (netId === 5) {
proxyAddress = tornadoGoerliProxy
}
const contract = new web3.eth.Contract(tornadoProxyABI, proxyAddress)
return {
contract,
isOldProxy: checkOldProxy(proxyAddress),
}
}
function checkOldProxy(address) {
const OLD_PROXY = '0x905b63Fff465B9fFBF41DeA908CEb12478ec7601'
return toChecksumAddress(address) === OLD_PROXY
}
async function getTxObject({ data }) {
if (data.type === jobType.TORNADO_WITHDRAW) { if (data.type === jobType.TORNADO_WITHDRAW) {
let contract, calldata let { contract, isOldProxy } = await getProxyContract()
if (getInstance(data.contract).currency === 'eth') {
contract = proxyContract let calldata = contract.methods.withdraw(data.contract, data.proof, ...data.args).encodeABI()
calldata = contract.methods.withdraw(data.contract, data.proof, ...data.args).encodeABI()
} else { if (isOldProxy && getInstance(data.contract).currency !== 'eth') {
contract = new web3.eth.Contract(tornadoABI, data.contract) contract = new web3.eth.Contract(tornadoABI, data.contract)
calldata = contract.methods.withdraw(data.proof, ...data.args).encodeABI() calldata = contract.methods.withdraw(data.proof, ...data.args).encodeABI()
} }
return { return {
value: data.args[5], value: data.args[5],
to: contract._address, to: contract._address,
@ -241,7 +252,7 @@ async function processJob(job) {
async function submitTx(job, retry = 0) { async function submitTx(job, retry = 0) {
await checkFee(job) await checkFee(job)
currentTx = await txManager.createTx(getTxObject(job)) currentTx = await txManager.createTx(await getTxObject(job))
if (job.data.type !== jobType.TORNADO_WITHDRAW) { if (job.data.type !== jobType.TORNADO_WITHDRAW) {
await fetchTree() await fetchTree()

740
yarn.lock

File diff suppressed because it is too large Load Diff