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
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (result.error) {
const env = process.env.NODE_ENV
const port = process.env.PORT
const certPassphrase = process.env.CERT_PASSPHRASE
const balancerNetwork = process.env.BALANCER_NETWORK
const ethereumChain = process.env.ETHEREUM_CHAIN
let certPath = process.env.CERT_PATH

if ((typeof certPath === 'undefined' && certPath == null) || certPath === '') {
Expand Down Expand Up @@ -79,4 +79,4 @@ server.listen(port)
server.on('error', onError)
server.on('listening', onListening)

console.log('server: gateway-api | port:', port, '| balancer-network:', balancerNetwork);
console.log('server: gateway-api | port:', port, '| ethereum-chain:', ethereumChain);
2 changes: 1 addition & 1 deletion src/routes/balancer.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ router.post('/sell', async (req, res) => {
amount,
)

const price = expectedOut / amount
const price = expectedOut / amount
debug(`Price: ${price.toString()}`)
if (!maxPrice || price >= maxPrice) {
// pass swaps to exchange-proxy to complete trade
Expand Down
43 changes: 17 additions & 26 deletions src/routes/eth.route.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import BigNumber from 'bignumber.js';
import { ethers } from 'ethers';
import express from 'express';

import { getParamData, latency, reportConnectionError, statusMessages } from '../services/utils';
import Ethereum from '../services/eth';
import Balancer from '../services/balancer';

const router = express.Router()
const eth = new Ethereum(process.env.BALANCER_NETWORK)
const balancer = new Balancer(process.env.BALANCER_NETWORK)
const seperator = ','
const eth = new Ethereum(process.env.ETHEREUM_CHAIN)
const separator = ','
const spenders = { balancer: process.env.EXCHANGE_PROXY,
uniswap: process.env.UNISWAP_ROUTER }

const debug = require('debug')('router')

Expand Down Expand Up @@ -38,7 +37,7 @@ router.post('/balances', async (req, res) => {
}
let tokenAddressList
if (paramData.tokenAddressList) {
tokenAddressList = paramData.tokenAddressList.split(seperator)
tokenAddressList = paramData.tokenAddressList.split(separator)
}
debug(tokenAddressList)

Expand Down Expand Up @@ -72,11 +71,13 @@ router.post('/allowances', async (req, res) => {
x-www-form-urlencoded: {
privateKey:{{privateKey}}
tokenAddressList:{{tokenAddressList}}
connector:{{connector_name}}
}
*/
const initTime = Date.now()
const paramData = getParamData(req.body)
const privateKey = paramData.privateKey
const spender = spenders[paramData.connector]
let wallet
try {
wallet = new ethers.Wallet(privateKey, eth.provider)
Expand All @@ -89,12 +90,10 @@ router.post('/allowances', async (req, res) => {
})
return
}
const spender = balancer.exchangeProxy
let tokenAddressList
if (paramData.tokenAddressList) {
tokenAddressList = paramData.tokenAddressList.split(seperator)
tokenAddressList = paramData.tokenAddressList.split(separator)
}
debug(tokenAddressList)

const approvals = {}
try {
Expand Down Expand Up @@ -125,15 +124,17 @@ router.post('/approve', async (req, res) => {
/*
POST: /approve
x-www-form-urlencoded: {
tokenAddress:"0x....."
privateKey:{{privateKey}}
tokenAddress:"0x....."
decimals: {{token_decimals}}
connector:{{connector_name}}
amount:{{amount}}
}
*/
const initTime = Date.now()
// params: privateKey (required), tokenAddress (required), amount (optional), gasPrice (required)
const paramData = getParamData(req.body)
const privateKey = paramData.privateKey
const spender = spenders[paramData.connector]
let wallet
try {
wallet = new ethers.Wallet(privateKey, eth.provider)
Expand All @@ -147,10 +148,11 @@ router.post('/approve', async (req, res) => {
return
}
const tokenAddress = paramData.tokenAddress
const spender = balancer.exchangeProxy
let amount
paramData.amount ? amount = ethers.utils.parseEther(paramData.amount)
: amount = ethers.utils.parseEther('1000000000') // approve for 1 billion units if no amount specified
let amount, decimals
paramData.decimals ? decimals = paramData.decimals
: decimals = 18
paramData.amount ? amount = ethers.utils.parseUnits(paramData.amount, decimals)
: amount = ethers.utils.parseUnits('1000000000', decimals) // approve for 1 billion units if no amount specified
let gasPrice
if (paramData.gasPrice) {
gasPrice = parseFloat(paramData.gasPrice)
Expand Down Expand Up @@ -191,7 +193,6 @@ router.post('/get-weth', async (req, res) => {
}
*/
const initTime = Date.now()
// params: primaryKey (required), amount (required), gasPrice (optional)
const paramData = getParamData(req.body)
const privateKey = paramData.privateKey
let wallet
Expand Down Expand Up @@ -232,16 +233,6 @@ router.post('/get-weth', async (req, res) => {
message: err
})
}

// When Balancer gives us the faucet ABI, we can use this faucet to get all Kovan tokens
// const contract = new ethers.Contract(abi.KovanFaucetAddress, abi.KovanFaucetAbi, provider)
// contract.drip(wallet.address, tokenAddress).then((response) => {
// res.status(200).json({
// network: network,
// timestamp: initTime,
// result: response
// })
// })
})

module.exports = router;