set relayer mode on init()
This commit is contained in:
parent
6f66b34288
commit
9f17840034
@ -1,13 +1,9 @@
|
|||||||
import { jobType } from './types';
|
import { jobType } from './types';
|
||||||
import tornConfig from 'torn-token';
|
import tornConfig, { availableIds } from 'torn-token';
|
||||||
import { EnsResolver } from './modules';
|
|
||||||
import { getProvider } from './modules/contracts';
|
|
||||||
|
|
||||||
|
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
|
||||||
|
export const netId = <availableIds>Number(process.env.NET_ID || 1);
|
||||||
export const netId = Number(process.env.NET_ID) || 1;
|
|
||||||
export const redisUrl = process.env.REDIS_URL || 'redis://127.0.0.1:6379';
|
export const redisUrl = process.env.REDIS_URL || 'redis://127.0.0.1:6379';
|
||||||
export const httpRpcUrl = process.env.HTTP_RPC_URL;
|
export const httpRpcUrl = process.env.HTTP_RPC_URL;
|
||||||
export const wsRpcUrl = process.env.WS_RPC_URL;
|
export const wsRpcUrl = process.env.WS_RPC_URL;
|
||||||
@ -21,7 +17,7 @@ export const instances = tornConfig.instances;
|
|||||||
export const torn = tornConfig;
|
export const torn = tornConfig;
|
||||||
export const port = process.env.APP_PORT || 8000;
|
export const port = process.env.APP_PORT || 8000;
|
||||||
export const tornadoServiceFee = Number(process.env.REGULAR_TORNADO_WITHDRAW_FEE);
|
export const tornadoServiceFee = Number(process.env.REGULAR_TORNADO_WITHDRAW_FEE);
|
||||||
export const miningServiceFee = Number(process.env.MINING_SERVICE_FEE);
|
// export const miningServiceFee = Number(process.env.MINING_SERVICE_FEE);
|
||||||
export const rewardAccount = process.env.REWARD_ACCOUNT;
|
export const rewardAccount = process.env.REWARD_ACCOUNT;
|
||||||
export const governanceAddress = '0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce';
|
export const governanceAddress = '0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce';
|
||||||
export const tornadoGoerliProxy = '0x454d870a72e29d5E5697f635128D18077BD04C60';
|
export const tornadoGoerliProxy = '0x454d870a72e29d5E5697f635128D18077BD04C60';
|
||||||
@ -33,19 +29,8 @@ export const gasLimits = {
|
|||||||
};
|
};
|
||||||
export const minimumBalance = '1000000000000000000';
|
export const minimumBalance = '1000000000000000000';
|
||||||
export const baseFeeReserve = Number(process.env.BASE_FEE_RESERVE_PERCENTAGE);
|
export const baseFeeReserve = Number(process.env.BASE_FEE_RESERVE_PERCENTAGE);
|
||||||
|
export const tornToken = {
|
||||||
let tornadoProxyAddress: string;
|
tokenAddress: '0x77777FeDdddFfC19Ff86DB637967013e6C6A116C',
|
||||||
let tornadoMiningAddress: string;
|
symbol: 'TORN',
|
||||||
|
decimals: 18,
|
||||||
export const initConfig = async () => {
|
|
||||||
const provider = getProvider();
|
|
||||||
const resolver = new EnsResolver(provider);
|
|
||||||
if (netId === 5) {
|
|
||||||
tornadoProxyAddress = tornadoGoerliProxy;
|
|
||||||
} else {
|
|
||||||
tornadoProxyAddress = await resolver.resolve(torn.tornadoRouter.address);
|
|
||||||
}
|
|
||||||
tornadoMiningAddress = await resolver.resolve(torn.miningV2.address);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export { tornadoProxyAddress, tornadoMiningAddress };
|
|
||||||
|
@ -1,42 +1,85 @@
|
|||||||
import { netId, torn, tornadoGoerliProxy } from '../config';
|
import { instances, netId, torn, tornadoGoerliProxy, tornToken } from '../config';
|
||||||
import { Token } from '../types';
|
import { Token } from '../types';
|
||||||
import { getProvider } from '../modules/contracts';
|
import { getProvider, getTornadoProxyContract, getTornadoProxyLightContract } from '../modules/contracts';
|
||||||
import { EnsResolver } from '../modules';
|
import { EnsResolver } from '../modules';
|
||||||
|
import { ProxyLightABI, TornadoProxyABI } from '../../contracts';
|
||||||
|
import { availableIds, netIds } from '../../../torn-token';
|
||||||
|
import { getAddress } from 'ethers/lib/utils';
|
||||||
|
|
||||||
|
const resolver = new EnsResolver(getProvider());
|
||||||
|
|
||||||
const tornToken = {
|
|
||||||
tokenAddress: '0x77777FeDdddFfC19Ff86DB637967013e6C6A116C',
|
|
||||||
symbol: 'TORN',
|
|
||||||
decimals: 18,
|
|
||||||
};
|
|
||||||
|
|
||||||
export class ConfigService {
|
export class ConfigService {
|
||||||
get proxyAddress(): string {
|
static instance: ConfigService;
|
||||||
if (!this._proxyAddress) {
|
netId: availableIds;
|
||||||
this.init().then(() =>
|
netIdKey: netIds;
|
||||||
this._proxyAddress);
|
tokens: Token[];
|
||||||
|
private _proxyAddress: string;
|
||||||
|
private _proxyContract: TornadoProxyABI | ProxyLightABI;
|
||||||
|
addressMap = new Map<string, InstanceProps>();
|
||||||
|
isLightMode: boolean;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.netId = netId;
|
||||||
|
this.netIdKey = `netId${this.netId}`;
|
||||||
|
this.isLightMode = ![1, 5].includes(netId);
|
||||||
|
|
||||||
|
for (const [currency, { instanceAddress, symbol, decimals }] of Object.entries(instances[this.netIdKey])) {
|
||||||
|
Object.entries(instanceAddress).forEach(([amount, address]) =>
|
||||||
|
this.addressMap.set(getAddress(address), {
|
||||||
|
currency,
|
||||||
|
amount,
|
||||||
|
symbol,
|
||||||
|
decimals,
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get proxyContract(): TornadoProxyABI | ProxyLightABI {
|
||||||
|
return this._proxyContract;
|
||||||
|
}
|
||||||
|
|
||||||
|
get proxyAddress(): string {
|
||||||
return this._proxyAddress;
|
return this._proxyAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
tokens: Token[];
|
async init() {
|
||||||
private _proxyAddress: string;
|
if (this.isLightMode) {
|
||||||
|
this._proxyAddress = await resolver.resolve(torn.tornadoProxyLight.address);
|
||||||
constructor() {
|
this._proxyContract = getTornadoProxyLightContract();
|
||||||
this.tokens = [tornToken, ...Object.values(torn.instances.netId1)].map<Token>(el => ({
|
} else {
|
||||||
address: el.tokenAddress,
|
if (this.netIdKey === 'netId1') {
|
||||||
...el,
|
this._proxyAddress = await resolver.resolve(torn.tornadoRouter.address);
|
||||||
})).filter(e => e.address);
|
} else {
|
||||||
|
this._proxyAddress = tornadoGoerliProxy;
|
||||||
|
}
|
||||||
|
this._proxyContract = getTornadoProxyContract();
|
||||||
|
this.tokens = [tornToken, ...Object.values(torn.instances['netId1'])]
|
||||||
|
.map<Token>(el => ({
|
||||||
|
address: getAddress(el.tokenAddress),
|
||||||
|
...el,
|
||||||
|
})).filter(e => e.address);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
getInstance(address: string) {
|
||||||
const provider = getProvider();
|
return this.addressMap.get(getAddress(address));
|
||||||
const resolver = new EnsResolver(provider);
|
}
|
||||||
if (netId === 5) {
|
|
||||||
this._proxyAddress = tornadoGoerliProxy;
|
public static getServiceInstance(): ConfigService {
|
||||||
} else {
|
if (!ConfigService.instance) {
|
||||||
this._proxyAddress = await resolver.resolve(torn.tornadoRouter.address);
|
ConfigService.instance = new ConfigService();
|
||||||
}
|
}
|
||||||
|
return ConfigService.instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new ConfigService();
|
type InstanceProps = {
|
||||||
|
currency: string,
|
||||||
|
amount: string,
|
||||||
|
symbol: string,
|
||||||
|
decimals: number,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ConfigService.getServiceInstance();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user