fix: env rpc

This commit is contained in:
Danil Kovtonyuk 2021-12-10 00:58:05 +10:00
parent c95249ca4c
commit 709f9d3944
10 changed files with 26 additions and 32 deletions

@ -11,6 +11,10 @@ REDIS_URL=redis://redis/0
# REDIS_URL=localhost # REDIS_URL=localhost
CHAIN_ID=100 CHAIN_ID=100
# RPC_URL=https://rpc.xdaichain.com/tornado
# ORACLE_RPC_URL should always point to the mainnet
# ORACLE_RPC_URL=https://mainnet.infura.io
REWARD_ADDRESS= REWARD_ADDRESS=

@ -1,6 +1,9 @@
import { Wallet } from 'ethers'; import { Wallet } from 'ethers';
import { ChainId } from '@/types';
import { toWei } from '@/utilities'; import { toWei } from '@/utilities';
import { NETWORKS_INFO } from '@/constants'; import { NETWORKS_INFO, RPC_LIST } from '@/constants';
import { version } from '../../package.json'; import { version } from '../../package.json';
@ -13,6 +16,8 @@ export const baseConfig = () => ({
transfer: toWei(process.env.TRANSFER_SERVICE_FEE).toString(), transfer: toWei(process.env.TRANSFER_SERVICE_FEE).toString(),
withdrawal: Number(process.env.WITHDRAWAL_SERVICE_FEE), withdrawal: Number(process.env.WITHDRAWAL_SERVICE_FEE),
}, },
rpcUrl: process.env.RPC_URL || RPC_LIST[process.env.CHAIN_ID],
oracleRpcUrl: process.env.ORACLE_RPC_URL || RPC_LIST[ChainId.MAINNET],
rewardAddress: process.env.REWARD_ADDRESS, rewardAddress: process.env.REWARD_ADDRESS,
address: new Wallet(process.env.PRIVATE_KEY).address, address: new Wallet(process.env.PRIVATE_KEY).address,
gasLimit: NETWORKS_INFO[process.env.CHAIN_ID].gasLimit, gasLimit: NETWORKS_INFO[process.env.CHAIN_ID].gasLimit,

@ -3,7 +3,7 @@ import { RPC_LIST } from '@/constants';
export default registerAs('txManager', () => ({ export default registerAs('txManager', () => ({
privateKey: process.env.PRIVATE_KEY, privateKey: process.env.PRIVATE_KEY,
rpcUrl: RPC_LIST[process.env.CHAIN_ID], rpcUrl: process.env.RPC_URL || RPC_LIST[process.env.CHAIN_ID],
config: { config: {
THROW_ON_REVERT: false, THROW_ON_REVERT: false,
CONFIRMATIONS: process.env.CONFIRMATIONS, CONFIRMATIONS: process.env.CONFIRMATIONS,

@ -6,9 +6,7 @@ export const CONTRACT_NETWORKS: { [chainId in ChainId]: string } = {
}; };
export const RPC_LIST: { [chainId in ChainId]: string } = { export const RPC_LIST: { [chainId in ChainId]: string } = {
[ChainId.MAINNET]: 'https://mainnet.infura.io/v3/eb6a84e726614079948e0b1efce5baa5', [ChainId.MAINNET]: 'https://api.mycryptoapi.com/eth',
[ChainId.GOERLI]: 'https://eth-goerli.alchemyapi.io/v2/hlSj0EqPUuLGyyTExs6UqFKnXDrc_eOh',
[ChainId.OPTIMISM]: 'https://optimism-kovan.infura.io/v3/8f786b96d16046b78e0287fa61c6fcf8',
[ChainId.XDAI]: 'https://rpc.xdaichain.com/tornado', [ChainId.XDAI]: 'https://rpc.xdaichain.com/tornado',
}; };

@ -2,21 +2,6 @@ import { BigNumber } from 'ethers';
import { ChainId } from '@/types'; import { ChainId } from '@/types';
const NETWORKS_INFO: { [chainId in ChainId] } = { 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]: { [ChainId.XDAI]: {
symbol: 'xDAI', symbol: 'xDAI',
gasLimit: BigNumber.from(2000000), gasLimit: BigNumber.from(2000000),

@ -7,8 +7,8 @@ import { ConfigService } from '@nestjs/config';
import { InjectQueue, Process, Processor, OnQueueActive, OnQueueCompleted, OnQueueFailed } from '@nestjs/bull'; import { InjectQueue, Process, Processor, OnQueueActive, OnQueueCompleted, OnQueueFailed } from '@nestjs/bull';
import { Transaction } from '@/types'; import { Transaction } from '@/types';
import { CONTRACT_ERRORS, jobStatus } from '@/constants';
import { getToIntegerMultiplier, toWei } from '@/utilities'; import { getToIntegerMultiplier, toWei } from '@/utilities';
import { numbers, CONTRACT_ERRORS, jobStatus } from '@/constants';
import { GasPriceService, ProviderService, OffchainPriceService } from '@/services'; import { GasPriceService, ProviderService, OffchainPriceService } from '@/services';
import txMangerConfig from '@/config/txManager.config'; import txMangerConfig from '@/config/txManager.config';

@ -5,7 +5,6 @@ import { BigNumber } from 'ethers';
import { GasPriceOracle } from 'gas-price-oracle'; import { GasPriceOracle } from 'gas-price-oracle';
import { toWei } from '@/utilities'; import { toWei } from '@/utilities';
import { RPC_LIST } from '@/constants';
const bump = (gas: BigNumber, percent: number) => gas.mul(percent).div(100).toHexString(); const bump = (gas: BigNumber, percent: number) => gas.mul(percent).div(100).toHexString();
const gweiToWei = (value: number) => toWei(String(value), 'gwei'); const gweiToWei = (value: number) => toWei(String(value), 'gwei');
@ -20,15 +19,17 @@ const percentBump = {
@Injectable() @Injectable()
export class GasPriceService { export class GasPriceService {
private readonly chainId: number; private readonly chainId: number;
private readonly rpcUrl: string;
constructor(private configService: ConfigService) { constructor(private configService: ConfigService) {
this.chainId = this.configService.get<number>('base.chainId'); this.chainId = this.configService.get<number>('base.chainId');
this.rpcUrl = this.configService.get('base.rpcUrl');
} }
async getGasPrice() { async getGasPrice() {
const instance = new GasPriceOracle({ const instance = new GasPriceOracle({
chainId: this.chainId, chainId: this.chainId,
defaultRpc: RPC_LIST[this.chainId], defaultRpc: this.rpcUrl,
}); });
const result = await instance.gasPrices(); const result = await instance.gasPrices();

@ -11,9 +11,11 @@ import { toWei } from '@/utilities';
@Injectable() @Injectable()
export class OffchainPriceService { export class OffchainPriceService {
private readonly chainId: number; private readonly chainId: number;
private readonly rpcUrl: string;
constructor(private configService: ConfigService, private providerService: ProviderService) { constructor(private configService: ConfigService, private providerService: ProviderService) {
this.chainId = ChainId.MAINNET; this.chainId = ChainId.MAINNET;
this.rpcUrl = this.configService.get('base.oracleRpcUrl');
} }
async getDaiEthPrice() { async getDaiEthPrice() {

@ -3,25 +3,27 @@ import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config'; import { ConfigService } from '@nestjs/config';
import { ChainId } from '@/types'; import { ChainId } from '@/types';
import { CONTRACT_NETWORKS, OFF_CHAIN_ORACLE, RPC_LIST } from '@/constants'; import { CONTRACT_NETWORKS, OFF_CHAIN_ORACLE } from '@/constants';
import { TornadoPool__factory as TornadoPool, OffchainOracle__factory as OffchainOracle } from '@/artifacts'; import { TornadoPool__factory as TornadoPool, OffchainOracle__factory as OffchainOracle } from '@/artifacts';
@Injectable() @Injectable()
export class ProviderService { export class ProviderService {
private readonly chainId: number; private readonly chainId: number;
private readonly rpcUrl: string;
private readonly providers: Map<ChainId, ethers.providers.StaticJsonRpcProvider> = new Map(); private readonly providers: Map<ChainId, ethers.providers.StaticJsonRpcProvider> = new Map();
constructor(private configService: ConfigService) { constructor(private configService: ConfigService) {
this.chainId = this.configService.get<number>('base.chainId'); this.chainId = this.configService.get<number>('base.chainId');
this.rpcUrl = this.configService.get('base.rpcUrl');
} }
get provider() { get provider() {
return this.getProvider(this.chainId); return this.getProvider(this.chainId, this.rpcUrl);
} }
getProvider(chainId: ChainId) { getProvider(chainId: ChainId, rpcUrl: string) {
if (!this.providers.has(chainId)) { if (!this.providers.has(chainId)) {
this.providers.set(chainId, new ethers.providers.StaticJsonRpcProvider(RPC_LIST[chainId], chainId)); this.providers.set(chainId, new ethers.providers.StaticJsonRpcProvider(rpcUrl, chainId));
} }
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@ -33,7 +35,8 @@ export class ProviderService {
} }
getOffChainOracle() { getOffChainOracle() {
const provider = this.getProvider(ChainId.MAINNET); const oracleRpcUrl = this.configService.get('base.oracleRpcUrl');
const provider = this.getProvider(ChainId.MAINNET, oracleRpcUrl);
return OffchainOracle.connect(OFF_CHAIN_ORACLE, provider); return OffchainOracle.connect(OFF_CHAIN_ORACLE, provider);
} }

@ -2,14 +2,10 @@ import { BigNumberish } from 'ethers';
import { BytesLike } from '@ethersproject/bytes'; import { BytesLike } from '@ethersproject/bytes';
const MAINNET_CHAIN_ID = 1; const MAINNET_CHAIN_ID = 1;
const GOERLI_CHAIN_ID = 5;
const OPTIMISM_CHAIN_ID = 69;
const XDAI_CHAIN_ID = 100; const XDAI_CHAIN_ID = 100;
export enum ChainId { export enum ChainId {
MAINNET = MAINNET_CHAIN_ID, MAINNET = MAINNET_CHAIN_ID,
GOERLI = GOERLI_CHAIN_ID,
OPTIMISM = OPTIMISM_CHAIN_ID,
XDAI = XDAI_CHAIN_ID, XDAI = XDAI_CHAIN_ID,
} }