Skip to content
This repository was archived by the owner on Feb 25, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/routes/balancer.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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({
Expand Down Expand Up @@ -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
Expand All @@ -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({
Expand Down
30 changes: 29 additions & 1 deletion src/routes/eth.route.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
12 changes: 4 additions & 8 deletions src/routes/uniswap.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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({
Expand Down Expand Up @@ -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,
Expand All @@ -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({
Expand Down
6 changes: 2 additions & 4 deletions src/services/balancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -161,7 +160,6 @@ export default class Balancer {
}
)
debug(`Tx Hash: ${tx.hash}`)
const txObj = await tx.wait()
return txObj
return tx
}
}
6 changes: 2 additions & 4 deletions src/services/uniswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -110,7 +109,6 @@ export default class Uniswap {
)

debug(`Tx Hash: ${tx.hash}`);
const txObj = await tx.wait()
return txObj
return tx
}
}