const { instances, netId } = require('../config') const { poseidon } = require('circomlib') const { toBN, toChecksumAddress } = require('web3-utils') const jobType = Object.freeze({ TORNADO_WITHDRAW: 'TORNADO_WITHDRAW', MINING_REWARD: 'MINING_REWARD', MINING_WITHDRAW: 'MINING_WITHDRAW', }) const sleep = ms => new Promise(res => setTimeout(res, ms)) function getInstance(address) { address = toChecksumAddress(address) const inst = instances[`netId${netId}`] for (const currency of Object.keys(inst)) { for (const amount of Object.keys(inst[currency].instanceAddress)) { if (inst[currency].instanceAddress[amount] === address) { return { currency, amount } } } } return null } const poseidonHash = items => toBN(poseidon(items).toString()) const poseidonHash2 = (a, b) => poseidonHash([a, b]) function setSafeInterval(func, interval) { func() .catch(console.error) .finally(() => { setTimeout(() => setSafeInterval(func, interval), interval) }) } /** * A promise that resolves when the source emits specified event */ function when(source, event) { return new Promise((resolve, reject) => { source .once(event, payload => { resolve(payload) }) .on('error', error => { reject(error) }) }) } module.exports = { getInstance, setSafeInterval, poseidonHash2, sleep, when, jobType, }