From 3d952f1906e7e824c345b0174026574e1aab7394 Mon Sep 17 00:00:00 2001 From: Danil Kovtonyuk Date: Tue, 23 Nov 2021 00:50:29 +1000 Subject: [PATCH] feat: add Arbitrum --- package.json | 2 +- src/config.js | 1 + src/constants.js | 23 +++++++++++++++++++++++ src/worker.js | 12 +++++++++--- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index bb0de96..bf3913a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "relay", - "version": "5.0.0-beta.6", + "version": "5.0.0-beta.7", "description": "Relayer for Tornado.cash privacy solution. https://tornado.cash", "scripts": { "server": "node src/server.js", diff --git a/src/config.js b/src/config.js index c0721a2..f5caf7d 100644 --- a/src/config.js +++ b/src/config.js @@ -19,6 +19,7 @@ module.exports = { gasPrices, gasLimits: { [jobType.TORNADO_WITHDRAW]: 390000, + [jobType.ARB_TORNADO_WITHDRAW]: 1900000, }, proxyLight, nativeCurrency, diff --git a/src/constants.js b/src/constants.js index 14b6e12..c93ce1a 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,5 +1,6 @@ const jobType = Object.freeze({ TORNADO_WITHDRAW: 'TORNADO_WITHDRAW', + ARB_TORNADO_WITHDRAW: 'ARB_TORNADO_WITHDRAW', }) const status = Object.freeze({ @@ -79,6 +80,28 @@ const networkConfig = { }, proxyLight: '0x0D5550d52428E7e3175bfc9550207e4ad3859b17', }, + netId42161: { + gasPrices: { + instant: 4, + fast: 3, + standard: 2.52, + low: 2.29, + }, + nativeCurrency: 'eth', + instances: { + eth: { + instanceAddress: { + 0.1: '0x84443CFd09A48AF6eF360C6976C5392aC5023a1F', + 1: '0xd47438C816c9E7f2E2888E060936a499Af9582b3', + 10: '0x330bdFADE01eE9bF63C209Ee33102DD334618e0a', + 100: '0x1E34A77868E19A6647b1f2F47B51ed72dEDE95DD', + }, + symbol: 'ETH', + decimals: 18, + }, + }, + proxyLight: '0x0D5550d52428E7e3175bfc9550207e4ad3859b17', + }, netId43114: { gasPrices: { instant: 225, diff --git a/src/worker.js b/src/worker.js index efe93d7..86f134a 100644 --- a/src/worker.js +++ b/src/worker.js @@ -50,7 +50,7 @@ function start() { } async function getGasPrices() { - const networksWithOracle = [56, 100, 137, 43114] + const networksWithOracle = [56, 100, 137, 43114, 42161] if (networksWithOracle.includes(netId)) { return await gasPriceOracle.gasPrices() } @@ -58,6 +58,12 @@ async function getGasPrices() { return gasPrices } +function getGasLimit() { + const action = Number(netId) === 42161 ? jobType.ARB_TORNADO_WITHDRAW : jobType.TORNADO_WITHDRAW + + return gasLimits[action] +} + async function checkTornadoFee({ args, contract }) { const { currency, amount } = getInstance(contract) const { decimals } = instances[currency] @@ -65,7 +71,7 @@ async function checkTornadoFee({ args, contract }) { const { fast } = await getGasPrices() - const expense = toBN(toWei(fast.toString(), 'gwei')).mul(toBN(gasLimits[jobType.TORNADO_WITHDRAW])) + const expense = toBN(toWei(fast.toString(), 'gwei')).mul(toBN(getGasLimit())) const feePercent = toBN(fromDecimals(amount, decimals)) .mul(toBN(parseInt(tornadoServiceFee * 1e10))) .div(toBN(1e10 * 100)) @@ -93,7 +99,7 @@ async function getTxObject({ data }) { value: data.args[5], to: contract._address, data: calldata, - gasLimit: gasLimits[jobType.TORNADO_WITHDRAW], + gasLimit: getGasLimit(), gasPrice: toHex(toWei(fast.toString(), 'gwei')), } }