diff --git a/example.env b/example.env index 7810ef5..e70172d 100644 --- a/example.env +++ b/example.env @@ -11,6 +11,10 @@ REDIS_URL=redis://redis/0 # REDIS_URL=localhost 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= diff --git a/src/config/configuration.ts b/src/config/configuration.ts index 123aec1..cbd88cb 100644 --- a/src/config/configuration.ts +++ b/src/config/configuration.ts @@ -1,6 +1,9 @@ import { Wallet } from 'ethers'; + +import { ChainId } from '@/types'; + import { toWei } from '@/utilities'; -import { NETWORKS_INFO } from '@/constants'; +import { NETWORKS_INFO, RPC_LIST } from '@/constants'; import { version } from '../../package.json'; @@ -13,6 +16,8 @@ export const baseConfig = () => ({ transfer: toWei(process.env.TRANSFER_SERVICE_FEE).toString(), 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, address: new Wallet(process.env.PRIVATE_KEY).address, gasLimit: NETWORKS_INFO[process.env.CHAIN_ID].gasLimit, diff --git a/src/config/txManager.config.ts b/src/config/txManager.config.ts index 45db7b3..f37a8ae 100644 --- a/src/config/txManager.config.ts +++ b/src/config/txManager.config.ts @@ -3,7 +3,7 @@ import { RPC_LIST } from '@/constants'; export default registerAs('txManager', () => ({ privateKey: process.env.PRIVATE_KEY, - rpcUrl: RPC_LIST[process.env.CHAIN_ID], + rpcUrl: process.env.RPC_URL || RPC_LIST[process.env.CHAIN_ID], config: { THROW_ON_REVERT: false, CONFIRMATIONS: process.env.CONFIRMATIONS, diff --git a/src/constants/contracts.ts b/src/constants/contracts.ts index 05e6a19..ea1d5b9 100644 --- a/src/constants/contracts.ts +++ b/src/constants/contracts.ts @@ -6,9 +6,7 @@ export const CONTRACT_NETWORKS: { [chainId in ChainId]: string } = { }; export const RPC_LIST: { [chainId in ChainId]: string } = { - [ChainId.MAINNET]: 'https://mainnet.infura.io/v3/eb6a84e726614079948e0b1efce5baa5', - [ChainId.GOERLI]: 'https://eth-goerli.alchemyapi.io/v2/hlSj0EqPUuLGyyTExs6UqFKnXDrc_eOh', - [ChainId.OPTIMISM]: 'https://optimism-kovan.infura.io/v3/8f786b96d16046b78e0287fa61c6fcf8', + [ChainId.MAINNET]: 'https://api.mycryptoapi.com/eth', [ChainId.XDAI]: 'https://rpc.xdaichain.com/tornado', }; diff --git a/src/constants/variables.ts b/src/constants/variables.ts index b7322f4..b9d263b 100644 --- a/src/constants/variables.ts +++ b/src/constants/variables.ts @@ -2,21 +2,6 @@ import { BigNumber } from 'ethers'; 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), diff --git a/src/modules/queue/transaction.processor.ts b/src/modules/queue/transaction.processor.ts index 1b1efce..f4375ba 100644 --- a/src/modules/queue/transaction.processor.ts +++ b/src/modules/queue/transaction.processor.ts @@ -7,8 +7,8 @@ import { ConfigService } from '@nestjs/config'; import { InjectQueue, Process, Processor, OnQueueActive, OnQueueCompleted, OnQueueFailed } from '@nestjs/bull'; import { Transaction } from '@/types'; +import { CONTRACT_ERRORS, jobStatus } from '@/constants'; import { getToIntegerMultiplier, toWei } from '@/utilities'; -import { numbers, CONTRACT_ERRORS, jobStatus } from '@/constants'; import { GasPriceService, ProviderService, OffchainPriceService } from '@/services'; import txMangerConfig from '@/config/txManager.config'; diff --git a/src/services/gas-price.service.ts b/src/services/gas-price.service.ts index a72d47c..a7aa397 100644 --- a/src/services/gas-price.service.ts +++ b/src/services/gas-price.service.ts @@ -5,7 +5,6 @@ import { BigNumber } from 'ethers'; import { GasPriceOracle } from 'gas-price-oracle'; import { toWei } from '@/utilities'; -import { RPC_LIST } from '@/constants'; const bump = (gas: BigNumber, percent: number) => gas.mul(percent).div(100).toHexString(); const gweiToWei = (value: number) => toWei(String(value), 'gwei'); @@ -20,15 +19,17 @@ const percentBump = { @Injectable() export class GasPriceService { private readonly chainId: number; + private readonly rpcUrl: string; constructor(private configService: ConfigService) { this.chainId = this.configService.get('base.chainId'); + this.rpcUrl = this.configService.get('base.rpcUrl'); } async getGasPrice() { const instance = new GasPriceOracle({ chainId: this.chainId, - defaultRpc: RPC_LIST[this.chainId], + defaultRpc: this.rpcUrl, }); const result = await instance.gasPrices(); diff --git a/src/services/offchain-price.service.ts b/src/services/offchain-price.service.ts index 53ac76c..44554bc 100644 --- a/src/services/offchain-price.service.ts +++ b/src/services/offchain-price.service.ts @@ -11,9 +11,11 @@ import { toWei } from '@/utilities'; @Injectable() export class OffchainPriceService { private readonly chainId: number; + private readonly rpcUrl: string; constructor(private configService: ConfigService, private providerService: ProviderService) { this.chainId = ChainId.MAINNET; + this.rpcUrl = this.configService.get('base.oracleRpcUrl'); } async getDaiEthPrice() { diff --git a/src/services/provider.service.ts b/src/services/provider.service.ts index acabb77..f074db7 100644 --- a/src/services/provider.service.ts +++ b/src/services/provider.service.ts @@ -3,25 +3,27 @@ import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; 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'; @Injectable() export class ProviderService { private readonly chainId: number; + private readonly rpcUrl: string; private readonly providers: Map = new Map(); constructor(private configService: ConfigService) { this.chainId = this.configService.get('base.chainId'); + this.rpcUrl = this.configService.get('base.rpcUrl'); } 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)) { - 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 @@ -33,7 +35,8 @@ export class ProviderService { } 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); } diff --git a/src/types/index.ts b/src/types/index.ts index ccb5070..cba2d55 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -2,14 +2,10 @@ import { BigNumberish } from 'ethers'; import { BytesLike } from '@ethersproject/bytes'; const MAINNET_CHAIN_ID = 1; -const GOERLI_CHAIN_ID = 5; -const OPTIMISM_CHAIN_ID = 69; const XDAI_CHAIN_ID = 100; export enum ChainId { MAINNET = MAINNET_CHAIN_ID, - GOERLI = GOERLI_CHAIN_ID, - OPTIMISM = OPTIMISM_CHAIN_ID, XDAI = XDAI_CHAIN_ID, }