diff --git a/src/routes/balancer.route.js b/src/routes/balancer.route.js index cd213e8..65dcef2 100644 --- a/src/routes/balancer.route.js +++ b/src/routes/balancer.route.js @@ -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() @@ -105,6 +105,7 @@ router.post('/buy-price', async (req, res) => { "quote":"0x....." "base":"0x....." "amount":0.1 + "maxSwaps":4 } */ const initTime = Date.now() @@ -163,6 +164,7 @@ router.post('/sell', async (req, res) => { "amount":0.1 "minPrice":1 "gasPrice":10 + "maxSwaps":4 "privateKey":{{privateKey}} } */ @@ -214,8 +216,6 @@ router.post('/sell', async (req, res) => { gasPrice, ) - debug(txObj) - // submit response res.status(200).json({ network: balancer.network, @@ -256,6 +256,7 @@ router.post('/buy', async (req, res) => { "amount":0.1 "maxPrice":1 "gasPrice":10 + "maxSwaps":4 "privateKey":{{privateKey}} } */ diff --git a/src/services/balancer.js b/src/services/balancer.js index 9aa3593..cee470b 100644 --- a/src/services/balancer.js +++ b/src/services/balancer.js @@ -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 { @@ -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}`) @@ -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) } @@ -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) }