diff --git a/example.env b/example.env index cfae98b..d2601a0 100644 --- a/example.env +++ b/example.env @@ -9,10 +9,8 @@ PORT=8000 SERVICE_FEE=0.05 REWARD_ADDRESS= -# bull settings -REDIS_URL=redis://127.0.0.1:6379 - # tx-manager settings -RPC_URL= CHAIN_ID=1 PRIVATE_KEY= +CONFIRMATIONS=4 +MAX_GAS_PRICE=100 diff --git a/src/config/bull.config.ts b/src/config/bull.config.ts index 32a38f3..98a070a 100644 --- a/src/config/bull.config.ts +++ b/src/config/bull.config.ts @@ -3,7 +3,7 @@ import { registerAs } from '@nestjs/config'; export default registerAs('bull', () => ({ name: 'withdrawal', redis: { - host: 'localhost', + host: process.env.NODE_ENV === 'development' ? 'localhost' : 'redis', port: 6379, }, settings: { diff --git a/src/config/configuration.ts b/src/config/configuration.ts index f3afd8a..12a00b7 100644 --- a/src/config/configuration.ts +++ b/src/config/configuration.ts @@ -1,16 +1,17 @@ import { Wallet } from 'ethers'; +import { NETWORKS_INFO } from '@/constants'; import { version } from '../../package.json'; export const baseConfig = () => ({ base: { version, - gasLimit: 600000, - minimumBalance: 0.5, + port: process.env.PORT, chainId: process.env.CHAIN_ID, serviceFee: process.env.SERVICE_FEE, rewardAddress: process.env.REWARD_ADDRESS, - port: parseInt(process.env.PORT, 10) || 8080, address: new Wallet(process.env.PRIVATE_KEY).address, + gasLimit: NETWORKS_INFO[process.env.CHAIN_ID].gasLimit, + minimumBalance: NETWORKS_INFO[process.env.CHAIN_ID].minimumBalance, }, }); diff --git a/src/config/txManager.config.ts b/src/config/txManager.config.ts index c383496..0f53b32 100644 --- a/src/config/txManager.config.ts +++ b/src/config/txManager.config.ts @@ -1,11 +1,12 @@ import { registerAs } from '@nestjs/config'; +import { RPC_LIST } from '@/constants'; export default registerAs('txManager', () => ({ privateKey: process.env.PRIVATE_KEY, - rpcUrl: process.env.RPC_URL, + rpcUrl: RPC_LIST[process.env.CHAIN_ID], config: { - CONFIRMATIONS: '4', - MAX_GAS_PRICE: '100', THROW_ON_REVERT: false, + CONFIRMATIONS: process.env.CONFIRMATIONS, + MAX_GAS_PRICE: process.env.MAX_GAS_PRICE, }, })); diff --git a/src/constants/variables.ts b/src/constants/variables.ts index dfceb89..034cd97 100644 --- a/src/constants/variables.ts +++ b/src/constants/variables.ts @@ -1,4 +1,20 @@ import { BigNumber } from 'ethers'; +import { ChainId } from '@/types'; + +const NETWORKS_INFO: { [chainId in ChainId] } = { + [ChainId.MAINNET]: { + gasLimit: BigNumber.from(600000), + minimumBalance: 0.5, + }, + [ChainId.GOERLI]: { + gasLimit: BigNumber.from(600000), + minimumBalance: 0.5, + }, + [ChainId.OPTIMISM]: { + gasLimit: '', + minimumBalance: 0.5, + }, +}; const numbers = { ZERO: 0, @@ -10,10 +26,8 @@ const numbers = { }; const BG_ZERO = BigNumber.from(numbers.ZERO); -const FIELD_SIZE = BigNumber.from( - '21888242871839275222246405745257275088548364400416034343698204186575808495617', -); +const FIELD_SIZE = BigNumber.from('21888242871839275222246405745257275088548364400416034343698204186575808495617'); const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; -export { numbers, FIELD_SIZE, BG_ZERO, ZERO_ADDRESS }; +export { numbers, NETWORKS_INFO, FIELD_SIZE, BG_ZERO, ZERO_ADDRESS }; diff --git a/src/modules/queue/withdrawal.processor.ts b/src/modules/queue/withdrawal.processor.ts index 2cf9be1..9db7604 100644 --- a/src/modules/queue/withdrawal.processor.ts +++ b/src/modules/queue/withdrawal.processor.ts @@ -91,7 +91,7 @@ export class WithdrawalProcessor extends BaseProcessor { } async prepareTransaction({ proof, args }) { - const chainId = this.configService.get('base.chainId'); + const { chainId, address } = this.configService.get('base'); const contract = this.providerService.getTornadoPool(); @@ -104,8 +104,8 @@ export class WithdrawalProcessor extends BaseProcessor { if (chainId === ChainId.OPTIMISM) { // @ts-ignore gasLimit = await contract.estimateGas.transaction(proof, ...args, { + from: address, value: BigNumber.from(0)._hex, - from: '0x1a5245ea5210C3B57B7Cfdf965990e63534A7b52', gasPrice: toWei('0.015', 'gwei'), }); }