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
7 changes: 4 additions & 3 deletions src/routes/balancer.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ router.post('/sell-price', async (req, res) => {
"quote":"0x....."
"base":"0x....."
"amount":0.1
"swaps": 4 (optional)
"maxSwaps":4
}
*/
const initTime = Date.now()
Expand Down Expand Up @@ -105,6 +105,7 @@ router.post('/buy-price', async (req, res) => {
"quote":"0x....."
"base":"0x....."
"amount":0.1
"maxSwaps":4
}
*/
const initTime = Date.now()
Expand Down Expand Up @@ -163,6 +164,7 @@ router.post('/sell', async (req, res) => {
"amount":0.1
"minPrice":1
"gasPrice":10
"maxSwaps":4
"privateKey":{{privateKey}}
}
*/
Expand Down Expand Up @@ -214,8 +216,6 @@ router.post('/sell', async (req, res) => {
gasPrice,
)

debug(txObj)

// submit response
res.status(200).json({
network: balancer.network,
Expand Down Expand Up @@ -256,6 +256,7 @@ router.post('/buy', async (req, res) => {
"amount":0.1
"maxPrice":1
"gasPrice":10
"maxSwaps":4
"privateKey":{{privateKey}}
}
*/
Expand Down
13 changes: 10 additions & 3 deletions src/services/balancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ const debug = require('debug')('router')

// constants
const MULTI = '0xeefba1e63905ef1d7acba5a8513c70307c1ce441';
const MULTI_KOVAN = ' 0x2cc8688C5f75E365aaEEb4ea8D6a480405A48D2A';
const EXCHANGE_PROXY = '0x3E66B66Fd1d0b02fDa6C811Da9E0547970DB2f21';
const EXCHANGE_PROXY_KOVAN = '0x4e67bf5bD28Dd4b570FBAFe11D0633eCbA2754Ec';
const MAX_UINT = ethers.constants.MaxUint256;
const MAX_SWAPS = 4;
const GAS_BASE = 200000;
const GAS_BASE = 200688;
const GAS_PER_SWAP = 100000;

export default class Balancer {
Expand All @@ -23,9 +24,11 @@ export default class Balancer {
switch (network) {
case 'mainnet':
this.exchangeProxy = EXCHANGE_PROXY;
this.multiCall = MULTI;
break;
case 'kovan':
this.exchangeProxy = EXCHANGE_PROXY_KOVAN;
this.multiCall = MULTI_KOVAN;
break;
default:
throw Error(`Invalid network ${network}`)
Expand All @@ -41,10 +44,12 @@ export default class Balancer {
}
console.log('Pools Retrieved.', this.network);

// Get current on-chain data about the fetched pools
let poolData
if (this.network === 'mainnet') {
poolData = await sor.parsePoolDataOnChain(pools.pools, tokenIn, tokenOut, MULTI, this.provider)
poolData = await sor.parsePoolDataOnChain(pools.pools, tokenIn, tokenOut, this.multiCall, this.provider)
} else {
// Kovan multicall throws an ENS error
poolData = await sor.parsePoolData(pools.pools, tokenIn, tokenOut)
}

Expand Down Expand Up @@ -86,10 +91,12 @@ export default class Balancer {
}
console.log('Pools Retrieved.', this.network);

// Get current on-chain data about the fetched pools
let poolData
if (this.network === 'mainnet') {
poolData = await sor.parsePoolDataOnChain(pools.pools, tokenIn, tokenOut, MULTI, this.provider)
poolData = await sor.parsePoolDataOnChain(pools.pools, tokenIn, tokenOut, this.multiCall, this.provider)
} else {
// Kovan multicall throws an ENS error
poolData = await sor.parsePoolData(pools.pools, tokenIn, tokenOut)
}

Expand Down