diff --git a/identity-service/src/relay/ethTxRelay.js b/identity-service/src/relay/ethTxRelay.js index 5691a026f07..7b99b5432f4 100644 --- a/identity-service/src/relay/ethTxRelay.js +++ b/identity-service/src/relay/ethTxRelay.js @@ -8,7 +8,6 @@ const { Lock } = require('../redis') const ENVIRONMENT = config.get('environment') const DEFAULT_GAS_LIMIT = config.get('defaultGasLimit') -const GANACHE_GAS_PRICE = config.get('ganacheGasPrice') // L1 relayer wallets const ethRelayerWallets = config.get('ethRelayerWallets') // { publicKey, privateKey } @@ -70,12 +69,6 @@ const sendEthTransaction = async (req, txProps, reqBodySHA) => { req.logger.info( `L1 txRelay - selected relayerPublicWallet=${selectedEthRelayerWallet.publicKey}` ) - const ethGasPriceInfo = await getProdGasInfo(req.app.get('redis'), req.logger) - - // Select the 'fast' gas price - let ethRelayGasPrice = ethGasPriceInfo[config.get('ethRelayerProdGasTier')] - ethRelayGasPrice = - ethRelayGasPrice * parseFloat(config.get('ethGasMultiplier')) let resp try { @@ -88,7 +81,6 @@ const sendEthTransaction = async (req, txProps, reqBodySHA) => { '0x00', ethWeb3, req.logger, - ethRelayGasPrice, gasLimit, encodedABI ) @@ -129,7 +121,6 @@ const createAndSendEthTransaction = async ( value, web3, logger, - gasPrice, gasLimit = null, data = null ) => { @@ -144,7 +135,6 @@ const createAndSendEthTransaction = async ( const nonce = await web3.eth.getTransactionCount(address) let txParams = { nonce: web3.utils.toHex(nonce), - gasPrice, gasLimit: gasLimit ? web3.utils.numberToHex(gasLimit) : DEFAULT_GAS_LIMIT, to: receiverAddress, value: web3.utils.toHex(value) @@ -157,69 +147,13 @@ const createAndSendEthTransaction = async ( tx.sign(privateKeyBuffer) const signedTx = '0x' + tx.serialize().toString('hex') logger.info( - `L1 txRelay - sending a transaction for sender ${ - sender.publicKey - } to ${receiverAddress}, gasPrice ${parseInt( - gasPrice, - 16 - )}, gasLimit ${DEFAULT_GAS_LIMIT}, nonce ${nonce}` + `L1 txRelay - sending a transaction for sender ${sender.publicKey} to ${receiverAddress}, gasLimit ${DEFAULT_GAS_LIMIT}, nonce ${nonce}` ) const receipt = await web3.eth.sendSignedTransaction(signedTx) return { txHash: receipt.transactionHash, txParams } } -// Query mainnet ethereum gas prices -/* - Sample call:https://data-api.defipulse.com/api/v1/egs/api/ethgasAPI.json?api-key=some_key -*/ -const getProdGasInfo = async (redis, logger) => { - if (ENVIRONMENT === 'development') { - return { - fastGweiHex: GANACHE_GAS_PRICE, - averageGweiHex: GANACHE_GAS_PRICE, - fastestGweiHex: GANACHE_GAS_PRICE - } - } - const prodGasPriceKey = 'eth-gas-prod-price-info' - let gasInfo = await redis.get(prodGasPriceKey) - if (!gasInfo) { - logger.info(`Redis cache miss, querying remote`) - let prodGasInfo - const defiPulseKey = config.get('defiPulseApiKey') - if (defiPulseKey !== '') { - logger.info(`L1 txRelay querying ethGas with apiKey`) - prodGasInfo = await axios({ - method: 'get', - url: `https://data-api.defipulse.com/api/v1/egs/api/ethgasAPI.json?api-key=${defiPulseKey}` - }) - } else { - prodGasInfo = await axios({ - method: 'get', - url: 'https://ethgasstation.info/api/ethgasAPI.json' - }) - } - const { fast, fastest, safeLow, average } = prodGasInfo.data - gasInfo = { fast, fastest, safeLow, average } - // Convert returned values into gwei to be used during relay and cache - // Must divide by 10 to get gwei price (Math.pow(10, 9) -> Math.pow(10, 8)) - // https://docs.ethgasstation.info/gas-price - gasInfo.fastGwei = parseInt(gasInfo.fast) * Math.pow(10, 8) - gasInfo.fastestGwei = parseInt(gasInfo.fastest) * Math.pow(10, 8) - gasInfo.averageGwei = parseInt(gasInfo.average) * Math.pow(10, 8) - gasInfo.fastGweiHex = ethWeb3.utils.numberToHex(gasInfo.fastGwei) - gasInfo.fastestGweiHex = ethWeb3.utils.numberToHex(gasInfo.fastestGwei) - gasInfo.averageGweiHex = ethWeb3.utils.numberToHex(gasInfo.averageGwei) - gasInfo.cachedResponse = false - redis.set(prodGasPriceKey, JSON.stringify(gasInfo), 'EX', 30) - logger.info(`L1 txRelay - Updated gasInfo: ${JSON.stringify(gasInfo)}`) - } else { - gasInfo = JSON.parse(gasInfo) - gasInfo.cachedResponse = true - } - return gasInfo -} - /** * Fund L1 wallets as necessary to facilitate multiple relayers */ @@ -271,6 +205,5 @@ module.exports = { sendEthTransaction, queryEthRelayerWallet, getEthRelayerFunds, - getProdGasInfo, generateETHWalletLockKey } diff --git a/identity-service/src/routes/ethRelay.js b/identity-service/src/routes/ethRelay.js index 6e4e2469e93..6385cda0258 100644 --- a/identity-service/src/routes/ethRelay.js +++ b/identity-service/src/routes/ethRelay.js @@ -63,16 +63,4 @@ module.exports = function (app) { return successResponse({ selectedEthWallet }) }) ) - - // Serves latest state of production gas tracking on identity service - app.get( - '/eth_gas_price', - handleResponse(async (req, res, next) => { - const gasInfo = await ethTxRelay.getProdGasInfo( - req.app.get('redis'), - req.logger - ) - return successResponse(gasInfo) - }) - ) } diff --git a/packages/libs/initScripts/manageProdRelayerWallets.js b/packages/libs/initScripts/manageProdRelayerWallets.js index 958ec479940..01ca6e275ae 100644 --- a/packages/libs/initScripts/manageProdRelayerWallets.js +++ b/packages/libs/initScripts/manageProdRelayerWallets.js @@ -98,16 +98,7 @@ const loadProdRelayerWallets = async () => { return { funder, relayerWallets } } -const getGasPrice = async () => { - const { data } = await axios({ - url: 'https://identityservice.staging.audius.co/eth_gas_price', - method: 'get', - timeout: 3000 - }) - return data -} - -const createAndSendTransaction = async (sender, receiverAddress, value, web3, gasPrice) => { +const createAndSendTransaction = async (sender, receiverAddress, value, web3) => { const privateKeyBuffer = Buffer.from(sender.privateKey, 'hex') const walletAddress = EthereumWallet.fromPrivateKey(privateKeyBuffer) const address = walletAddress.getAddressString() @@ -123,7 +114,6 @@ const createAndSendTransaction = async (sender, receiverAddress, value, web3, ga console.log(`Sending tx from ${sender.publicKey} to ${receiverAddress} with nonce=${nonce}, gasPrice=${gasPrice}, gasLimit=${gasLimit}`) const txParams = { nonce: web3.utils.toHex(nonce), - gasPrice: gasPrice, gasLimit: gasLimit, to: receiverAddress, value: web3.utils.toHex(value) @@ -143,9 +133,6 @@ const fundEthRelayerIfEmpty = async () => { const relayerWallets = walletInfo.relayerWallets - let gasInfo - let gasPrice - for (let i = 0; i < relayerWallets.length; i++) { const relayerPublicKey = relayerWallets[i].publicKey let balance = await ethWeb3.eth.getBalance(relayerPublicKey) @@ -154,14 +141,11 @@ const fundEthRelayerIfEmpty = async () => { if (!validBalance) { const missingBalance = minimumBalance - balance console.log(`${i + 1} - Funding ${relayerPublicKey} with ${missingBalance}, currently ${balance}/${minimumBalance}`) - gasInfo = await getGasPrice() - gasPrice = gasInfo.fastestGweiHex await createAndSendTransaction( walletInfo.funder, // Always send from the designated FUNDER relayerPublicKey, // Public key of receiving account missingBalance, // Min - ethWeb3, - gasPrice + ethWeb3 ) console.log(`${i + 1} - Finished Funding ${relayerPublicKey} with ${minimumBalance}`) balance = await ethWeb3.eth.getBalance(relayerPublicKey)