mirror of
https://github.com/tornadocash/tornado-relayer
synced 2024-02-02 15:04:06 +01:00
cleanup and formatting code
This commit is contained in:
parent
591c2d94f3
commit
d32ff07fa8
@ -1,6 +1,5 @@
|
||||
NET_ID=1
|
||||
HTTP_RPC_URL=https://mainnet.infura.io
|
||||
WS_RPC_URL=wss://mainnet.infura.io/ws/v3/
|
||||
# ORACLE_RPC_URL should always point to the mainnet
|
||||
ORACLE_RPC_URL=https://mainnet.infura.io
|
||||
REDIS_URL=redis://127.0.0.1:6379
|
||||
@ -14,8 +13,7 @@ APP_PORT=8000
|
||||
PRIVATE_KEY=
|
||||
# 0.05 means 0.05%
|
||||
REGULAR_TORNADO_WITHDRAW_FEE=0.05
|
||||
MINING_SERVICE_FEE=0.05
|
||||
REWARD_ACCOUNT=
|
||||
REWARD_ACCOUNT=0x...
|
||||
CONFIRMATIONS=4
|
||||
|
||||
# in GWEI
|
||||
|
@ -8,8 +8,9 @@ export const priceWorker = async () => {
|
||||
const healthService = getHealthService();
|
||||
|
||||
const price = new PriceQueueHelper();
|
||||
console.log(price.queue.name, 'worker started');
|
||||
|
||||
price.scheduler.on('stalled', (jobId, prev) => console.log({ jobId, prev }));
|
||||
console.log('price worker', price.queue.name);
|
||||
price.worker.on('active', () => console.log('worker active'));
|
||||
price.worker.on('completed', async (job, result) => {
|
||||
console.log(`Job ${job.name} completed with result: `, result);
|
||||
@ -22,6 +23,7 @@ export const relayerWorker = async () => {
|
||||
const relayer = new RelayerQueueHelper();
|
||||
const healthService = getHealthService();
|
||||
console.log(relayer.queue.name, 'worker started');
|
||||
|
||||
relayer.worker.on('completed', (job, result) => {
|
||||
console.log(`Job ${job.id} completed with result: `, result);
|
||||
});
|
||||
@ -33,7 +35,6 @@ export const relayerWorker = async () => {
|
||||
};
|
||||
|
||||
export const healthWorker = async () => {
|
||||
console.log('health worker starting');
|
||||
await configService.init();
|
||||
const health = new HealthQueueHelper();
|
||||
console.log(health.queue.name, 'worker started');
|
||||
|
@ -12,7 +12,7 @@ import {
|
||||
tornadoGoerliProxy,
|
||||
tornToken,
|
||||
} from '../config';
|
||||
import { Token } from '../types';
|
||||
import { ChainIds, Token } from '../types';
|
||||
import { getProvider, getTornadoProxyContract, getTornadoProxyLightContract, getTornTokenContract } from '../modules/contracts';
|
||||
import { resolve } from '../modules';
|
||||
import { ERC20Abi, ProxyLightABI, TornadoProxyABI } from '../contracts';
|
||||
@ -56,7 +56,7 @@ export class ConfigService {
|
||||
constructor(private store: RedisStore) {
|
||||
this.netIdKey = `netId${this.netId}`;
|
||||
this.queueName = `relayer_${this.netId}`;
|
||||
this.isLightMode = ![1, 5].includes(netId);
|
||||
this.isLightMode = ![ChainIds.ethereum, ChainIds.goerli].includes(netId);
|
||||
this.host = host;
|
||||
this.instances = instances[this.netIdKey];
|
||||
this.provider = getProvider(false);
|
||||
@ -85,7 +85,6 @@ export class ConfigService {
|
||||
|
||||
private _fillInstanceMap() {
|
||||
if (!this.instances) throw new Error('config mismatch, check your environment variables');
|
||||
// TODO
|
||||
for (const [currency, { instanceAddress, symbol, decimals }] of Object.entries(this.instances)) {
|
||||
for (const [amount, address] of Object.entries(instanceAddress)) {
|
||||
if (address)
|
||||
@ -123,23 +122,23 @@ export class ConfigService {
|
||||
} else {
|
||||
this._proxyAddress = tornadoGoerliProxy;
|
||||
this.nativeCurrency = 'eth';
|
||||
if (this.netId === 1) {
|
||||
if (this.netId === ChainIds.ethereum) {
|
||||
this._proxyAddress = await resolve(torn.tornadoRouter.address);
|
||||
}
|
||||
this._proxyContract = getTornadoProxyContract(this._proxyAddress);
|
||||
this.tokens = [tornToken, ...Object.values(torn.instances['netId1'])]
|
||||
.map<Token>(
|
||||
(el) =>
|
||||
el.tokenAddress && {
|
||||
address: getAddress(el.tokenAddress),
|
||||
decimals: el.decimals,
|
||||
symbol: el.symbol,
|
||||
},
|
||||
)
|
||||
.filter(Boolean);
|
||||
}
|
||||
// TODO get instances from registry
|
||||
|
||||
this.tokens = [tornToken, ...Object.values(torn.instances['netId1'])]
|
||||
.map<Token>(
|
||||
(el) =>
|
||||
el.tokenAddress && {
|
||||
address: getAddress(el.tokenAddress),
|
||||
decimals: el.decimals,
|
||||
symbol: el.symbol,
|
||||
},
|
||||
)
|
||||
.filter(Boolean);
|
||||
console.log(
|
||||
'Configuration completed\n',
|
||||
`-- netId: ${this.netId}\n`,
|
||||
@ -156,9 +155,9 @@ export class ConfigService {
|
||||
async clearRedisState() {
|
||||
const queueKeys = (await this.store.client.keys('bull:*')).filter((s) => s.indexOf('relayer') === -1);
|
||||
const errorKeys = await this.store.client.keys('errors:*');
|
||||
// const alertKeys = await this.store.client.keys('alerts:*');
|
||||
const keys = [...queueKeys, ...errorKeys];
|
||||
if (keys.length) await this.store.client.del([...queueKeys, ...errorKeys]);
|
||||
const alertKeys = await this.store.client.keys('alerts:*');
|
||||
const keys = [...queueKeys, ...errorKeys, ...alertKeys];
|
||||
if (keys.length) await this.store.client.del(keys);
|
||||
}
|
||||
|
||||
getInstance(address: string) {
|
||||
|
@ -80,10 +80,10 @@ export class HealthService {
|
||||
}
|
||||
|
||||
async saveError(e, jobId?: string) {
|
||||
await this.store.client.zadd('errors:code', 'INCR', 1, e?.code || 'RUNTIME_ERROR');
|
||||
await this.store.client.zadd('errors:code', 'INCR', 1, e.code || 'RUNTIME_ERROR');
|
||||
await this.store.client.zadd('errors:log', 'INCR', 1, e.message);
|
||||
|
||||
if (e?.code === 'REVERTED' || e?.code === 'SEND_ERROR') {
|
||||
if (e.code === 'REVERTED' || e.code === 'SEND_ERROR') {
|
||||
const jobUrl = `${this.config.host}/v1/jobs/${jobId}`;
|
||||
await this.pushAlert({
|
||||
message: `${e.message} \n ${jobUrl}`,
|
||||
|
@ -38,15 +38,6 @@ export class JobService {
|
||||
return await this.relayer.queue.getJobCountByTypes('active', 'waiting', 'delayed');
|
||||
}
|
||||
|
||||
private async _clearSchedulerJobs() {
|
||||
try {
|
||||
const jobs = await Promise.all([this.price.queue.getJobs(), this.health.queue.getJobs()]);
|
||||
await Promise.all(jobs.flat().map((job) => job?.remove()));
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
async setupRepeatableJobs() {
|
||||
if (!this.config.isLightMode) {
|
||||
await this.price.addRepeatable(this.config.tokens);
|
||||
|
@ -51,15 +51,15 @@ export class PriceService {
|
||||
}
|
||||
|
||||
async getPrice(currency: string) {
|
||||
return await this.store.client.hget('prices', currency);
|
||||
return this.store.client.hget('prices', currency);
|
||||
}
|
||||
|
||||
async getPrices() {
|
||||
return await this.store.client.hgetall('prices');
|
||||
return this.store.client.hgetall('prices');
|
||||
}
|
||||
|
||||
async savePrices(prices: Record<string, string>) {
|
||||
return await this.store.client.hset('prices', prices);
|
||||
return this.store.client.hset('prices', prices);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,7 @@ export class TxService {
|
||||
provider: this.provider,
|
||||
});
|
||||
this.oracle = new GasPriceOracle(gasPriceOracleConfig);
|
||||
|
||||
switch (netId) {
|
||||
case ChainIds.ethereum:
|
||||
case ChainIds.goerli:
|
||||
|
Loading…
Reference in New Issue
Block a user