This commit is contained in:
Thrilok kumar 2022-09-03 01:20:02 +05:30
parent 791d04091a
commit 611ff8a3e7
2 changed files with 18 additions and 54 deletions

View File

@ -28,8 +28,7 @@ abstract contract Helpers is DSMath, Basic {
enum Action {
REPAY,
DEPOSIT,
TRANSFER
DEPOSIT
}
function getBaseToken(address market)
@ -52,11 +51,7 @@ abstract contract Helpers is DSMath, Basic {
address to,
uint256 amt
) internal {
if (from == address(this)) {
CometInterface(market).withdrawTo(to, token, amt);
} else {
CometInterface(market).withdrawFrom(from, to, token, amt);
}
CometInterface(market).withdrawFrom(from, to, token, amt);
}
function _borrow(BorrowWithdrawParams memory params)
@ -173,11 +168,7 @@ abstract contract Helpers is DSMath, Basic {
address to,
uint256 amt
) internal {
if (from == address(0)) {
CometInterface(market).transferAsset(to, token, amt);
} else {
CometInterface(market).transferAssetFrom(from, to, token, amt);
}
CometInterface(market).transferAssetFrom(from, to, token, amt);
}
function _getAccountSupplyBalanceOfAsset(
@ -213,13 +204,9 @@ abstract contract Helpers is DSMath, Basic {
} 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_;
}
amt = bal_ < allowance_ ? bal_ : allowance_;
}
if (src == address(this))
convertEthToWeth(isEth, TokenInterface(token), amt);

View File

@ -287,7 +287,7 @@ abstract contract CompoundV3Resolver is Events, Helpers {
BorrowWithdrawParams({
market: market,
token: token,
from: address(0),
from: address(this),
to: to,
amt: amt,
getId: getId,
@ -407,12 +407,10 @@ abstract contract CompoundV3Resolver is Events, Helpers {
TokenInterface tokenContract = TokenInterface(token_);
if (token_ == getBaseToken(market)) {
require(
CometInterface(market).balanceOf(address(this)) == 0,
"borrow-disabled-when-supplied-base"
);
}
require(
CometInterface(market).balanceOf(address(this)) == 0,
"borrow-disabled-when-supplied-base"
);
uint256 initialBal = CometInterface(market).borrowBalanceOf(
address(this)
@ -464,7 +462,7 @@ abstract contract CompoundV3Resolver is Events, Helpers {
BorrowWithdrawParams({
market: market,
token: token,
from: address(0),
from: address(this),
to: to,
amt: amt,
getId: getId,
@ -804,23 +802,11 @@ abstract contract CompoundV3Resolver is Events, Helpers {
"invalid market/token/to address"
);
bool isEth = token == ethAddr;
address token_ = isEth ? wethAddr : token;
TokenInterface tokenContract = TokenInterface(token_);
address token_ = token == ethAddr ? wethAddr : token;
convertEthToWeth(isEth, tokenContract, amt_);
amt_ = amt_ == uint256(-1) ? _getAccountSupplyBalanceOfAsset(address(this)) : amt_;
amt_ = amt_ == uint256(-1)
? (
(token_ == getBaseToken(market))
? TokenInterface(market).balanceOf(address(this))
: CometInterface(market)
.userCollateral(address(this), token_)
.balance
)
: amt_;
_transfer(market, token_, address(0), dest, amt_);
CometInterface(market).transferAssetFrom(address(this), dest, token_, amt);
setUint(setId, amt_);
@ -858,20 +844,11 @@ abstract contract CompoundV3Resolver is Events, Helpers {
"invalid market/token/to address"
);
bool isEth = token == ethAddr;
address token_ = isEth ? wethAddr : token;
TokenInterface tokenContract = TokenInterface(token_);
address token_ = token == ethAddr ? wethAddr : token;
amt_ = _calculateFromAmount(
market,
token_,
src,
amt_,
isEth,
Action.TRANSFER
);
amt_ = amt_ == uint256(-1) ? _getAccountSupplyBalanceOfAsset(src) : amt_;
_transfer(market, token_, src, dest, amt_);
CometInterface(market).transferAssetFrom(src, dest, token_, amt_);
setUint(setId, amt_);