diff --git a/src/routes/balancer.route.js b/src/routes/balancer.route.js index f5bb4eb..d38dbdf 100644 --- a/src/routes/balancer.route.js +++ b/src/routes/balancer.route.js @@ -197,7 +197,7 @@ router.post('/sell', async (req, res) => { debug(`Price: ${price.toString()}`) if (!maxPrice || price >= maxPrice) { // pass swaps to exchange-proxy to complete trade - const txObj = await balancer.swapExactIn( + const tx = await balancer.swapExactIn( wallet, swaps, baseTokenAddress, // tokenIn is base asset @@ -217,9 +217,7 @@ router.post('/sell', async (req, res) => { amount: parseFloat(paramData.amount), expectedOut: expectedOut / denomMultiplier, price: price, - gasUsed: parseInt(txObj.gasUsed), - txHash: txObj.transactionHash, - status: txObj.status, + txHash: tx.hash, }) } else { res.status(200).json({ @@ -286,7 +284,7 @@ router.post('/buy', async (req, res) => { debug(`Price: ${price.toString()}`) if (!maxPrice || price <= maxPrice) { // pass swaps to exchange-proxy to complete trade - const txObj = await balancer.swapExactOut( + const tx = await balancer.swapExactOut( wallet, swaps, quoteTokenAddress, // tokenIn is quote asset @@ -305,9 +303,7 @@ router.post('/buy', async (req, res) => { amount: parseFloat(paramData.amount), expectedIn: expectedIn / denomMultiplier, price: price, - gasUsed: parseInt(txObj.gasUsed), - txHash: txObj.transactionHash, - status: txObj.status, + txHash: tx.hash, }) } else { res.status(200).json({ diff --git a/src/routes/eth.route.js b/src/routes/eth.route.js index 77619ef..d55f916 100644 --- a/src/routes/eth.route.js +++ b/src/routes/eth.route.js @@ -1,4 +1,4 @@ -import { ethers } from 'ethers'; +import { ethers, BigNumber } from 'ethers'; import express from 'express'; import { getParamData, latency, reportConnectionError, statusMessages } from '../services/utils'; @@ -237,4 +237,32 @@ router.post('/get-weth', async (req, res) => { } }) +router.post('/get-receipt', async (req, res) => { + const initTime = Date.now() + const paramData = getParamData(req.body) + const txHash = paramData.txHash + const txReceipt = await eth.provider.getTransactionReceipt(txHash) + debug('Tx Receipt:') + debug(txReceipt) + + const receipt = {} + const confirmed = txReceipt && txReceipt.blockNumber ? true : false + if (confirmed) { + receipt.gasUsed = BigNumber.from(txReceipt.gasUsed).toNumber() + receipt.blockNumber = txReceipt.blockNumber + receipt.confirmations = txReceipt.confirmations + receipt.status = txReceipt.status + } + + res.status(500).json({ + network: eth.network, + timestamp: initTime, + latency: latency(initTime, Date.now()), + txHash: txHash, + confirmed: confirmed, + receipt: receipt, + }) + return txReceipt +}) + module.exports = router; diff --git a/src/routes/uniswap.route.js b/src/routes/uniswap.route.js index 129d97d..d58b6b6 100644 --- a/src/routes/uniswap.route.js +++ b/src/routes/uniswap.route.js @@ -184,7 +184,7 @@ router.post('/sell', async (req, res) => { debug(`Price: ${price.toString()}`) if (!maxPrice || price >= maxPrice) { // pass swaps to exchange-proxy to complete trade - const txObj = await uniswap.swapExactIn( + const tx = await uniswap.swapExactIn( wallet, trade, baseTokenAddress, @@ -201,9 +201,7 @@ router.post('/sell', async (req, res) => { amount: amount, expectedOut: expectedOut.toSignificant(8), price: price, - gasUsed: parseInt(txObj.gasUsed), - txHash: txObj.transactionHash, - status: txObj.status, + txHash: tx.hash, }) } else { res.status(200).json({ @@ -264,7 +262,7 @@ router.post('/buy', async (req, res) => { debug(`Price: ${price.toString()}`) if (!maxPrice || price <= maxPrice) { // pass swaps to exchange-proxy to complete trade - const txObj = await uniswap.swapExactOut( + const tx = await uniswap.swapExactOut( wallet, trade, baseTokenAddress, @@ -281,9 +279,7 @@ router.post('/buy', async (req, res) => { amount: amount, expectedIn: expectedIn.toSignificant(8), price: price, - gasUsed: parseInt(txObj.gasUsed), - txHash: txObj.transactionHash, - status: txObj.status, + txHash: tx.hash, }) } else { res.status(200).json({ diff --git a/src/services/balancer.js b/src/services/balancer.js index cee470b..eca16fd 100644 --- a/src/services/balancer.js +++ b/src/services/balancer.js @@ -143,8 +143,7 @@ export default class Balancer { } ) debug(`Tx Hash: ${tx.hash}`); - const txObj = await tx.wait() - return txObj + return tx } async swapExactOut (wallet, swaps, tokenIn, tokenOut, expectedIn, gasPrice) { @@ -161,7 +160,6 @@ export default class Balancer { } ) debug(`Tx Hash: ${tx.hash}`) - const txObj = await tx.wait() - return txObj + return tx } } diff --git a/src/services/uniswap.js b/src/services/uniswap.js index 2216074..a4bbab3 100644 --- a/src/services/uniswap.js +++ b/src/services/uniswap.js @@ -85,8 +85,7 @@ export default class Uniswap { ) debug(`Tx Hash: ${tx.hash}`); - const txObj = await tx.wait() - return txObj + return tx } async swapExactOut (wallet, trade, tokenAddress, gasPrice) { @@ -110,7 +109,6 @@ export default class Uniswap { ) debug(`Tx Hash: ${tx.hash}`); - const txObj = await tx.wait() - return txObj + return tx } }