fix: provider

This commit is contained in:
Danil Kovtonyuk 2021-10-22 00:45:02 +10:00 committed by 0xZick
parent f8f33e0b39
commit dcf62122de
4 changed files with 23 additions and 11 deletions

@ -8,7 +8,7 @@ export const baseConfig = () => ({
base: {
version,
port: process.env.PORT,
chainId: process.env.CHAIN_ID,
chainId: Number(process.env.CHAIN_ID),
serviceFee: {
transfer: toWei(process.env.TRANSFER_SERVICE_FEE).toString(),
withdrawal: Number(process.env.WITHDRAWAL_SERVICE_FEE),

@ -3,18 +3,22 @@ import { ChainId } from '@/types';
const NETWORKS_INFO: { [chainId in ChainId] } = {
[ChainId.MAINNET]: {
symbol: 'ETH',
gasLimit: BigNumber.from(1500000),
minimumBalance: '0.5',
},
[ChainId.GOERLI]: {
symbol: 'gETH',
gasLimit: BigNumber.from(1500000),
minimumBalance: '0.5',
},
[ChainId.OPTIMISM]: {
symbol: 'ETH',
gasLimit: '',
minimumBalance: '0.5',
},
[ChainId.XDAI]: {
symbol: 'xDAI',
gasLimit: BigNumber.from(2000000),
minimumBalance: '0.5',
},

@ -3,9 +3,9 @@ import { v4 as uuid } from 'uuid';
import { InjectQueue } from '@nestjs/bull';
import { Injectable } from '@nestjs/common';
import { jobStatus } from '@/constants';
import { ProviderService } from '@/services';
import { ConfigService } from '@nestjs/config';
import { jobStatus, NETWORKS_INFO } from '@/constants';
import { Transaction } from '@/types';
@ -25,9 +25,9 @@ class ApiService {
return {
health,
version,
chainId,
serviceFee,
rewardAddress,
chainId: Number(chainId),
};
}
@ -59,11 +59,11 @@ class ApiService {
private async healthCheck(): Promise<Health> {
const status = await this.providerService.checkSenderBalance();
const minimumBalance = this.configService.get('base.minimumBalance');
const { chainId, minimumBalance } = this.configService.get('base');
return {
status,
error: status ? '' : `Not enough balance, less than ${minimumBalance} ETH`,
error: status ? '' : `Not enough balance, less than ${minimumBalance} ${NETWORKS_INFO[chainId].symbol}`,
};
}
}

@ -9,23 +9,31 @@ import { TornadoPool__factory as TornadoPool, OffchainOracle__factory as Offchai
@Injectable()
export class ProviderService {
private readonly chainId: number;
public provider: ethers.providers.JsonRpcProvider;
private readonly providers: Map<ChainId, ethers.providers.StaticJsonRpcProvider> = new Map();
constructor(private configService: ConfigService) {
this.chainId = this.configService.get<number>('base.chainId');
this.provider = new ethers.providers.JsonRpcProvider(RPC_LIST[this.chainId]);
}
getProviderWithSigner() {
return ethers.providers.getDefaultProvider(RPC_LIST[this.chainId]);
get provider() {
return this.getProvider(this.chainId);
}
getProvider(chainId: ChainId) {
if (!this.providers.has(chainId)) {
this.providers.set(chainId, new ethers.providers.StaticJsonRpcProvider(RPC_LIST[chainId], chainId));
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this.providers.get(chainId)!;
}
getTornadoPool() {
return TornadoPool.connect(CONTRACT_NETWORKS[this.chainId], this.getProviderWithSigner());
return TornadoPool.connect(CONTRACT_NETWORKS[this.chainId], this.provider);
}
getOffChainOracle() {
const provider = ethers.providers.getDefaultProvider(RPC_LIST[ChainId.MAINNET]);
const provider = this.getProvider(ChainId.MAINNET);
return OffchainOracle.connect(OFF_CHAIN_ORACLE, provider);
}