From ccd4b7745c731bff096c7000581583363aaad05d Mon Sep 17 00:00:00 2001 From: Samyak Jain Date: Mon, 17 Jun 2019 22:43:33 +0530 Subject: [PATCH] stack too deep error resolved --- contracts/ProxyLogics/InstaBridge.sol | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/contracts/ProxyLogics/InstaBridge.sol b/contracts/ProxyLogics/InstaBridge.sol index 61497c8..6ce40c2 100644 --- a/contracts/ProxyLogics/InstaBridge.sol +++ b/contracts/ProxyLogics/InstaBridge.sol @@ -200,7 +200,7 @@ contract Helper is DSMath { * @dev get uniswap DAI exchange */ function getBridgeAddress() public pure returns (address bridge) { - // bridge = ; + bridge = 0x9807554C441Bb37F549fc7F77165E5be49e55eD5; } /** @@ -312,6 +312,20 @@ contract CompoundHelper is MakerHelper { isOk = totalBorrow < maxBorrow; } + /** + * @dev get user's token supply and borrow in ETH + */ + function compSupplyBorrow(address cTokenAdd, address user) public returns(uint supplyInEth, uint borrowInEth) { + CTokenInterface cTokenContract = CTokenInterface(cTokenAdd); + uint tokenPriceInEth = CompOracleInterface(getCompOracleAddress()).getUnderlyingPrice(cTokenAdd); + uint cTokenBal = cTokenContract.balanceOf(user); + uint cTokenExchangeRate = cTokenContract.exchangeRateCurrent(); + uint tokenSupply = wmul(cTokenBal, cTokenExchangeRate); + supplyInEth = wmul(tokenSupply, tokenPriceInEth); + uint tokenBorrowed = cTokenContract.borrowBalanceCurrent(user); + borrowInEth = wmul(tokenBorrowed, tokenPriceInEth); + } + /** * @dev get users overall details for Compound */ @@ -320,14 +334,7 @@ contract CompoundHelper is MakerHelper { uint arrLength = bridgeContract.cArrLength(); for (uint i = 0; i < arrLength; i++) { (address cTokenAdd, uint factor) = bridgeContract.cTokenAddr(i); - CTokenInterface cTokenContract = CTokenInterface(cTokenAdd); - uint tokenPriceInEth = CompOracleInterface(getCompOracleAddress()).getUnderlyingPrice(cTokenAdd); - uint cTokenBal = cTokenContract.balanceOf(user); - uint cTokenExchangeRate = cTokenContract.exchangeRateCurrent(); - uint tokenSupply = wmul(cTokenBal, cTokenExchangeRate); - uint supplyInEth = wmul(tokenSupply, tokenPriceInEth); - uint tokenBorrowed = cTokenContract.borrowBalanceCurrent(user); - uint borrowInEth = wmul(tokenBorrowed, tokenPriceInEth); + (uint supplyInEth, uint borrowInEth) = compSupplyBorrow(cTokenAdd, user); totalSupply += supplyInEth; totalBorrow += borrowInEth; maxBorrow += wmul(supplyInEth, factor);