mirror of
https://github.com/tornadocash/tornado-pool-relayer
synced 2024-02-02 15:04:09 +01:00
fix: provider
This commit is contained in:
parent
f8f33e0b39
commit
dcf62122de
@ -8,7 +8,7 @@ export const baseConfig = () => ({
|
|||||||
base: {
|
base: {
|
||||||
version,
|
version,
|
||||||
port: process.env.PORT,
|
port: process.env.PORT,
|
||||||
chainId: process.env.CHAIN_ID,
|
chainId: Number(process.env.CHAIN_ID),
|
||||||
serviceFee: {
|
serviceFee: {
|
||||||
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),
|
||||||
|
@ -3,18 +3,22 @@ import { ChainId } from '@/types';
|
|||||||
|
|
||||||
const NETWORKS_INFO: { [chainId in ChainId] } = {
|
const NETWORKS_INFO: { [chainId in ChainId] } = {
|
||||||
[ChainId.MAINNET]: {
|
[ChainId.MAINNET]: {
|
||||||
|
symbol: 'ETH',
|
||||||
gasLimit: BigNumber.from(1500000),
|
gasLimit: BigNumber.from(1500000),
|
||||||
minimumBalance: '0.5',
|
minimumBalance: '0.5',
|
||||||
},
|
},
|
||||||
[ChainId.GOERLI]: {
|
[ChainId.GOERLI]: {
|
||||||
|
symbol: 'gETH',
|
||||||
gasLimit: BigNumber.from(1500000),
|
gasLimit: BigNumber.from(1500000),
|
||||||
minimumBalance: '0.5',
|
minimumBalance: '0.5',
|
||||||
},
|
},
|
||||||
[ChainId.OPTIMISM]: {
|
[ChainId.OPTIMISM]: {
|
||||||
|
symbol: 'ETH',
|
||||||
gasLimit: '',
|
gasLimit: '',
|
||||||
minimumBalance: '0.5',
|
minimumBalance: '0.5',
|
||||||
},
|
},
|
||||||
[ChainId.XDAI]: {
|
[ChainId.XDAI]: {
|
||||||
|
symbol: 'xDAI',
|
||||||
gasLimit: BigNumber.from(2000000),
|
gasLimit: BigNumber.from(2000000),
|
||||||
minimumBalance: '0.5',
|
minimumBalance: '0.5',
|
||||||
},
|
},
|
||||||
|
@ -3,9 +3,9 @@ import { v4 as uuid } from 'uuid';
|
|||||||
import { InjectQueue } from '@nestjs/bull';
|
import { InjectQueue } from '@nestjs/bull';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
import { jobStatus } from '@/constants';
|
|
||||||
import { ProviderService } from '@/services';
|
import { ProviderService } from '@/services';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
import { jobStatus, NETWORKS_INFO } from '@/constants';
|
||||||
|
|
||||||
import { Transaction } from '@/types';
|
import { Transaction } from '@/types';
|
||||||
|
|
||||||
@ -25,9 +25,9 @@ class ApiService {
|
|||||||
return {
|
return {
|
||||||
health,
|
health,
|
||||||
version,
|
version,
|
||||||
|
chainId,
|
||||||
serviceFee,
|
serviceFee,
|
||||||
rewardAddress,
|
rewardAddress,
|
||||||
chainId: Number(chainId),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,11 +59,11 @@ class ApiService {
|
|||||||
private async healthCheck(): Promise<Health> {
|
private async healthCheck(): Promise<Health> {
|
||||||
const status = await this.providerService.checkSenderBalance();
|
const status = await this.providerService.checkSenderBalance();
|
||||||
|
|
||||||
const minimumBalance = this.configService.get('base.minimumBalance');
|
const { chainId, minimumBalance } = this.configService.get('base');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status,
|
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()
|
@Injectable()
|
||||||
export class ProviderService {
|
export class ProviderService {
|
||||||
private readonly chainId: number;
|
private readonly chainId: number;
|
||||||
public provider: ethers.providers.JsonRpcProvider;
|
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.provider = new ethers.providers.JsonRpcProvider(RPC_LIST[this.chainId]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getProviderWithSigner() {
|
get provider() {
|
||||||
return ethers.providers.getDefaultProvider(RPC_LIST[this.chainId]);
|
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() {
|
getTornadoPool() {
|
||||||
return TornadoPool.connect(CONTRACT_NETWORKS[this.chainId], this.getProviderWithSigner());
|
return TornadoPool.connect(CONTRACT_NETWORKS[this.chainId], this.provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
getOffChainOracle() {
|
getOffChainOracle() {
|
||||||
const provider = ethers.providers.getDefaultProvider(RPC_LIST[ChainId.MAINNET]);
|
const provider = this.getProvider(ChainId.MAINNET);
|
||||||
return OffchainOracle.connect(OFF_CHAIN_ORACLE, provider);
|
return OffchainOracle.connect(OFF_CHAIN_ORACLE, provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user