From 28ef1ae2bb6e35ad28b420437175c1caccedab69 Mon Sep 17 00:00:00 2001 From: Richa-iitr Date: Fri, 2 Sep 2022 19:43:42 +0530 Subject: [PATCH] setAmt --- .../connectors/compound/v3/helpers.sol | 61 ++++++------------- 1 file changed, 18 insertions(+), 43 deletions(-) diff --git a/contracts/mainnet/connectors/compound/v3/helpers.sol b/contracts/mainnet/connectors/compound/v3/helpers.sol index bd4d7cfa..ad83fdf8 100644 --- a/contracts/mainnet/connectors/compound/v3/helpers.sol +++ b/contracts/mainnet/connectors/compound/v3/helpers.sol @@ -181,51 +181,26 @@ abstract contract Helpers is DSMath, Basic { bool isEth, ACTION action ) internal returns (uint256) { - if (isEth) { - if (amt == uint256(-1)) { - uint256 allowance_ = TokenInterface(token).allowance( - src, - market - ); - uint256 bal_; - if (action == ACTION.repay) { - bal_ = CometInterface(market).borrowBalanceOf(src); - } else if (action == ACTION.deposit) { - bal_ = src.balance; - } else if (action == ACTION.transfer) { - bal_ = (token == getBaseToken(market)) - ? TokenInterface(market).balanceOf(src) - : CometInterface(market) - .userCollateral(src, token) - .balance; - } - if (action == ACTION.transfer) amt = bal_; - else amt = bal_ < allowance_ ? bal_ : allowance_; - } - if (src == address(this)) - convertEthToWeth(isEth, TokenInterface(token), amt); - } else { - if (amt == uint256(-1)) { - uint256 allowance_ = TokenInterface(token).allowance( - src, - market - ); - uint256 bal_; - if (action == ACTION.repay) { - bal_ = CometInterface(market).borrowBalanceOf(src); - } else if (action == ACTION.deposit) { - bal_ = TokenInterface(token).balanceOf(src); - } else if (action == ACTION.transfer) { - bal_ = (token == getBaseToken(market)) - ? TokenInterface(market).balanceOf(src) - : CometInterface(market) - .userCollateral(src, token) - .balance; - } - if (action == ACTION.transfer) amt = bal_; - else amt = bal_ < allowance_ ? bal_ : allowance_; + if (amt == uint256(-1)) { + uint256 allowance_ = TokenInterface(token).allowance(src, market); + uint256 bal_; + + if (action == ACTION.repay) { + bal_ = CometInterface(market).borrowBalanceOf(src); + } else if (action == ACTION.deposit) { + if (isEth) bal_ = src.balance; + else bal_ = TokenInterface(token).balanceOf(src); + } else if (action == ACTION.transfer) { + bal_ = (token == getBaseToken(market)) + ? TokenInterface(market).balanceOf(src) + : CometInterface(market).userCollateral(src, token).balance; } + if (action == ACTION.transfer) amt = bal_; + else amt = bal_ < allowance_ ? bal_ : allowance_; } + if (src == address(this)) + convertEthToWeth(isEth, TokenInterface(token), amt); + return amt; } }