mirror of
https://github.com/tornadocash/tornado-relayer.git
synced 2025-08-07 05:42:19 -04:00
use ens
This commit is contained in:
parent
d22837d2bf
commit
cab8a2b8db
9 changed files with 390 additions and 33 deletions
|
@ -1,6 +1,7 @@
|
|||
require('dotenv').config()
|
||||
|
||||
const jobType = require('./jobTypes')
|
||||
const tornConfig = require('torn-token')
|
||||
|
||||
module.exports = {
|
||||
netId: Number(process.env.NET_ID) || 42,
|
||||
|
@ -9,12 +10,11 @@ module.exports = {
|
|||
wsRpcUrl: process.env.WS_RPC_URL,
|
||||
oracleRpcUrl: process.env.ORACLE_RPC_URL || 'https://mainnet.infura.io/',
|
||||
oracleAddress: '0xA2b8E7ee7c8a18ea561A5CF7C9C365592026E374',
|
||||
minerAddress: '0x3E0a9C6Cf76136862De28ce25a56cDBF38EF9D37', // each network has its own instance
|
||||
tornadoProxyAddress: '0x98529F6FaE5AdaFfa0AaDA37d9017AF9a4281E13', // each network has its own instance
|
||||
swapAddress: '0x1E73e0a484a595B692f3d212642AE4B3BF30E7e3',
|
||||
aggregatorAddress: '0x748F37B04eAB454Ad8cF4F5d6814984448c79B35',
|
||||
minerMerkleTreeHeight: 20,
|
||||
privateKey: process.env.PRIVATE_KEY,
|
||||
instances: require('torn-token').instances,
|
||||
instances: tornConfig.instances,
|
||||
torn: tornConfig,
|
||||
port: process.env.APP_PORT || 8000,
|
||||
tornadoServiceFee: Number(process.env.REGULAR_TORNADO_WITHDRAW_FEE),
|
||||
miningServiceFee: Number(process.env.MINING_SERVICE_FEE),
|
||||
|
|
30
src/resolver.js
Normal file
30
src/resolver.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
const { httpRpcUrl, aggregatorAddress } = require('./config')
|
||||
const Web3 = require('web3')
|
||||
const web3 = new Web3(httpRpcUrl)
|
||||
const aggregator = new web3.eth.Contract(require('../abis/Aggregator.abi.json'), aggregatorAddress)
|
||||
const ens = require('eth-ens-namehash')
|
||||
|
||||
class ENSResolver {
|
||||
constructor() {
|
||||
this.addresses = {}
|
||||
}
|
||||
|
||||
async resolve(domains) {
|
||||
if (!Array.isArray(domains)) {
|
||||
domains = [domains]
|
||||
}
|
||||
|
||||
const unresolved = domains.filter(d => !this.addresses[d])
|
||||
if (unresolved.length) {
|
||||
const resolved = await aggregator.methods.bulkResolve(unresolved.map(ens.hash)).call()
|
||||
for (let i = 0; i < resolved.length; i++) {
|
||||
this.addresses[domains[i]] = resolved[i]
|
||||
}
|
||||
}
|
||||
|
||||
const addresses = domains.map(domain => this.addresses[domain])
|
||||
return addresses.length === 1 ? addresses[0] : addresses
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ENSResolver
|
|
@ -1,12 +1,15 @@
|
|||
const MerkleTree = require('fixed-merkle-tree')
|
||||
const { redisUrl, wsRpcUrl, minerMerkleTreeHeight, minerAddress } = require('./config')
|
||||
const { redisUrl, wsRpcUrl, minerMerkleTreeHeight, torn } = require('./config')
|
||||
const { poseidonHash2 } = require('./utils')
|
||||
const { toBN } = require('web3-utils')
|
||||
const Redis = require('ioredis')
|
||||
const redis = new Redis(redisUrl)
|
||||
const ENSResolver = require('./resolver')
|
||||
const resolver = new ENSResolver()
|
||||
const Web3 = require('web3')
|
||||
const web3 = new Web3(wsRpcUrl)
|
||||
const contract = new web3.eth.Contract(require('../abis/mining.abi.json'), minerAddress)
|
||||
const MinerABI = require('../abis/mining.abi.json')
|
||||
let contract
|
||||
|
||||
let tree, eventSubscription, blockSubscription
|
||||
|
||||
|
@ -86,6 +89,7 @@ async function rebuild() {
|
|||
|
||||
async function init() {
|
||||
console.log('Initializing')
|
||||
contract = new web3.eth.Contract(MinerABI, await resolver.resolve(torn.miningV2.address))
|
||||
const block = await web3.eth.getBlockNumber()
|
||||
const events = await fetchEvents(0, block)
|
||||
tree = new MerkleTree(minerMerkleTreeHeight, events, { hashFunction: poseidonHash2 })
|
||||
|
|
|
@ -14,17 +14,17 @@ const { poseidonHash2, getInstance, fromDecimals } = require('./utils')
|
|||
const jobType = require('./jobTypes')
|
||||
const {
|
||||
netId,
|
||||
torn,
|
||||
httpRpcUrl,
|
||||
redisUrl,
|
||||
privateKey,
|
||||
swapAddress,
|
||||
minerAddress,
|
||||
tornadoProxyAddress,
|
||||
gasLimits,
|
||||
instances,
|
||||
tornadoServiceFee,
|
||||
miningServiceFee,
|
||||
} = require('./config')
|
||||
const ENSResolver = require('./resolver')
|
||||
const resolver = new ENSResolver()
|
||||
const { TxManager } = require('tx-manager')
|
||||
const { Controller } = require('tornado-cash-anonymity-mining')
|
||||
|
||||
|
@ -63,6 +63,7 @@ async function fetchTree() {
|
|||
|
||||
const update = await controller.treeUpdate(args.account.outputCommitment, tree)
|
||||
|
||||
const minerAddress = await resolver.resolve(torn.miningV2.address)
|
||||
const instance = new web3.eth.Contract(miningABI, minerAddress)
|
||||
const data =
|
||||
currentJob.data.type === 'MINING_REWARD'
|
||||
|
@ -79,7 +80,7 @@ async function fetchTree() {
|
|||
async function start() {
|
||||
web3 = new Web3(httpRpcUrl)
|
||||
txManager = new TxManager({ privateKey, rpcUrl: httpRpcUrl, config: { CONFIRMATIONS: 6 } })
|
||||
swap = new web3.eth.Contract(swapABI, swapAddress)
|
||||
swap = new web3.eth.Contract(swapABI, resolver.resolve(torn.rewardSwap.address))
|
||||
redisSubscribe.subscribe('treeUpdate', fetchTree)
|
||||
await fetchTree()
|
||||
const provingKeys = {
|
||||
|
@ -168,16 +169,18 @@ async function checkMiningFee({ args }) {
|
|||
}
|
||||
}
|
||||
|
||||
function getTxObject({ data }) {
|
||||
async function getTxObject({ data }) {
|
||||
if (data.type === jobType.TORNADO_WITHDRAW) {
|
||||
const tornadoProxyAddress = await resolver.resolve(torn.tornadoProxy.address)
|
||||
const contract = new web3.eth.Contract(tornadoProxyABI, tornadoProxyAddress)
|
||||
const calldata = contract.methods.withdraw(data.contract, data.proof, ...data.args).encodeABI()
|
||||
return {
|
||||
value: data.args[5],
|
||||
to: tornadoProxyAddress,
|
||||
data: calldata
|
||||
data: calldata,
|
||||
}
|
||||
} else {
|
||||
const minerAddress = await resolver.resolve(torn.miningV2.address)
|
||||
const contract = new web3.eth.Contract(miningABI, minerAddress)
|
||||
const method = data.type === jobType.MINING_REWARD ? 'reward' : 'withdraw'
|
||||
const calldata = contract.methods[method](data.proof, data.args).encodeABI()
|
||||
|
@ -197,7 +200,7 @@ async function process(job) {
|
|||
await updateStatus(status.ACCEPTED)
|
||||
console.log(`Start processing a new ${job.data.type} job #${job.id}`)
|
||||
await checkFee(job)
|
||||
currentTx = await txManager.createTx(getTxObject(job))
|
||||
currentTx = await txManager.createTx(await getTxObject(job))
|
||||
|
||||
if (job.data.type !== jobType.TORNADO_WITHDRAW) {
|
||||
await fetchTree()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue