Fallback gas prices for light mode

This commit is contained in:
smart_ex 2022-05-26 15:43:07 +10:00
parent 1a375d1cd9
commit fecac18687
4 changed files with 85 additions and 8 deletions

@ -31,3 +31,60 @@ export const tornToken = {
symbol: 'TORN', symbol: 'TORN',
decimals: 18, decimals: 18,
}; };
export const networkConfig = {
netId56: {
gasPrices: {
instant: 5,
fast: 5,
standard: 5,
low: 5,
},
nativeCurrency: 'bnb',
},
netId10: {
gasPrices: {
instant: 0.001,
fast: 0.001,
standard: 0.001,
low: 0.001,
},
nativeCurrency: 'eth',
},
netId100: {
gasPrices: {
instant: 6,
fast: 5,
standard: 4,
low: 1,
},
nativeCurrency: 'xdai',
},
netId137: {
gasPrices: {
instant: 100,
fast: 75,
standard: 50,
low: 30,
},
nativeCurrency: 'matic',
},
netId42161: {
gasPrices: {
instant: 4,
fast: 3,
standard: 2.52,
low: 2.29,
},
nativeCurrency: 'eth',
},
netId43114: {
gasPrices: {
instant: 225,
fast: 35,
standard: 25,
low: 25,
},
nativeCurrency: 'avax',
},
};

@ -12,12 +12,10 @@ export const relayerProcessor: RelayerProcessor = async (job) => {
const withdrawalData = job.data; const withdrawalData = job.data;
await txService.checkTornadoFee(withdrawalData); await txService.checkTornadoFee(withdrawalData);
const txData = await txService.prepareTxData(withdrawalData); const txData = await txService.prepareTxData(withdrawalData);
const receipt = await txService.sendTx(txData); return await txService.sendTx(txData);
return receipt;
} catch (e) { } catch (e) {
console.log(e); console.log(e);
await job.update({ ...job.data, status: JobStatus.FAILED }); await job.update({ ...job.data, status: JobStatus.FAILED });
throw new Error(e.message); throw new Error(e.message);
} }
}; };

@ -1,4 +1,14 @@
import { instances, minimumBalance, netId, privateKey, rpcUrl, torn, tornadoGoerliProxy, tornToken } from '../config'; import {
instances,
minimumBalance,
netId,
networkConfig,
privateKey,
rpcUrl,
torn,
tornadoGoerliProxy,
tornToken,
} from '../config';
import { Token } from '../types'; import { Token } from '../types';
import { getProvider, getTornadoProxyContract, getTornadoProxyLightContract } from '../modules/contracts'; import { getProvider, getTornadoProxyContract, getTornadoProxyLightContract } from '../modules/contracts';
import { resolve } from '../modules'; import { resolve } from '../modules';
@ -7,6 +17,7 @@ import { availableIds, netIds, NetInstances } from '../../../torn-token';
import { getAddress } from 'ethers/lib/utils'; import { getAddress } from 'ethers/lib/utils';
import { providers, Wallet } from 'ethers'; import { providers, Wallet } from 'ethers';
import { container, singleton } from 'tsyringe'; import { container, singleton } from 'tsyringe';
import { GasPrice } from 'gas-price-oracle/lib/types';
type relayerQueueName = `relayer_${availableIds}` type relayerQueueName = `relayer_${availableIds}`
@ -26,6 +37,9 @@ export class ConfigService {
public readonly privateKey = privateKey; public readonly privateKey = privateKey;
public readonly rpcUrl = rpcUrl; public readonly rpcUrl = rpcUrl;
isInit: boolean; isInit: boolean;
nativeCurrency: string;
fallbackGasPrices: GasPrice;
constructor() { constructor() {
this.netIdKey = `netId${this.netId}`; this.netIdKey = `netId${this.netId}`;
@ -74,6 +88,9 @@ export class ConfigService {
if (this.isLightMode) { if (this.isLightMode) {
this._proxyAddress = await resolve(torn.tornadoProxyLight.address); this._proxyAddress = await resolve(torn.tornadoProxyLight.address);
this._proxyContract = getTornadoProxyLightContract(this._proxyAddress); this._proxyContract = getTornadoProxyLightContract(this._proxyAddress);
const { gasPrices, nativeCurrency } = networkConfig[this.netIdKey];
this.nativeCurrency = nativeCurrency;
this.fallbackGasPrices = gasPrices;
} else { } else {
this._proxyAddress = tornadoGoerliProxy; this._proxyAddress = tornadoGoerliProxy;
if (this.netId === 1) { if (this.netId === 1) {
@ -92,6 +109,7 @@ export class ConfigService {
console.log( console.log(
`Configuration completed\n-- netId: ${this.netId}\n-- rpcUrl: ${this.rpcUrl}`); `Configuration completed\n-- netId: ${this.netId}\n-- rpcUrl: ${this.rpcUrl}`);
this.isInit = true; this.isInit = true;
console.log(this);
} catch (e) { } catch (e) {
console.error(`${this.constructor.name} Error:`, e.message); console.error(`${this.constructor.name} Error:`, e.message);
} }

@ -42,7 +42,11 @@ export class TxService {
this.txManager = new TxManager({ privateKey, rpcUrl, config: { THROW_ON_REVERT: true } }); this.txManager = new TxManager({ privateKey, rpcUrl, config: { THROW_ON_REVERT: true } });
this.tornadoProxy = this.config.proxyContract; this.tornadoProxy = this.config.proxyContract;
this.provider = this.tornadoProxy.provider; this.provider = this.tornadoProxy.provider;
this.oracle = new GasPriceOracle({ defaultRpc: rpcUrl, chainId: netId }); this.oracle = new GasPriceOracle({
defaultRpc: rpcUrl,
chainId: netId,
defaultFallbackGasPrices: this.config?.fallbackGasPrices,
});
} }
async updateJobData(data: Partial<RelayerJobData>) { async updateJobData(data: Partial<RelayerJobData>) {
@ -57,15 +61,15 @@ export class TxService {
const receipt = await currentTx.send() const receipt = await currentTx.send()
.on('transactionHash', async txHash => { .on('transactionHash', async txHash => {
console.log({ txHash }); console.log('Transaction sent, txHash: ', txHash);
await this.updateJobData({ txHash, status: JobStatus.SENT }); await this.updateJobData({ txHash, status: JobStatus.SENT });
}) })
.on('mined', async receipt => { .on('mined', async receipt => {
console.log('Mined in block', receipt.blockNumber); console.log('Transaction mined in block', receipt.blockNumber);
await this.updateJobData({ status: JobStatus.MINED }); await this.updateJobData({ status: JobStatus.MINED });
}) })
.on('confirmations', async confirmations => { .on('confirmations', async confirmations => {
console.log({ confirmations }); console.log('Transaction confirmations: ', confirmations);
await this.updateJobData({ confirmations }); await this.updateJobData({ confirmations });
}); });
if (receipt.status === 1) { if (receipt.status === 1) {