mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
code refactor
This commit is contained in:
parent
69eb33d64a
commit
791d04091a
|
@ -77,16 +77,17 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
TokenInterface tokenContract = TokenInterface(token_);
|
TokenInterface tokenContract = TokenInterface(token_);
|
||||||
|
|
||||||
params.from = params.from == address(0) ? address(this) : params.from;
|
params.from = params.from == address(0) ? address(this) : params.from;
|
||||||
uint256 initialBal = CometInterface(params.market).borrowBalanceOf(
|
|
||||||
params.from
|
|
||||||
);
|
|
||||||
|
|
||||||
require(
|
require(
|
||||||
TokenInterface(params.market).balanceOf(params.from) == 0,
|
TokenInterface(params.market).balanceOf(params.from) == 0,
|
||||||
"borrow-disabled-when-supplied-base"
|
"borrow-disabled-when-supplied-base"
|
||||||
);
|
);
|
||||||
|
|
||||||
_withdrawHelper(params.market, token_, params.from, params.to, amt_);
|
uint256 initialBal = CometInterface(params.market).borrowBalanceOf(
|
||||||
|
params.from
|
||||||
|
);
|
||||||
|
|
||||||
|
CometInterface(params.market).withdrawFrom(params.from, params.to, token_, amt_);
|
||||||
|
|
||||||
uint256 finalBal = CometInterface(params.market).borrowBalanceOf(
|
uint256 finalBal = CometInterface(params.market).borrowBalanceOf(
|
||||||
params.from
|
params.from
|
||||||
|
@ -126,24 +127,28 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
params.market,
|
params.market,
|
||||||
token_
|
token_
|
||||||
);
|
);
|
||||||
amt_ = amt_ == uint256(-1) ? initialBal : amt_;
|
|
||||||
|
|
||||||
if (token_ == getBaseToken(params.market)) {
|
if (token_ == getBaseToken(market)) {
|
||||||
uint256 balance = CometInterface(params.market).balanceOf(
|
|
||||||
params.from
|
|
||||||
);
|
|
||||||
//if there are supplies, ensure withdrawn amount is not greater than supplied i.e can't borrow using withdraw.
|
//if there are supplies, ensure withdrawn amount is not greater than supplied i.e can't borrow using withdraw.
|
||||||
if (balance > 0) {
|
if (amt_ == uint256(-1)) {
|
||||||
require(amt_ <= balance, "withdraw-amt-greater-than-supplies");
|
amt_ = initialBal;
|
||||||
|
} else {
|
||||||
|
require(
|
||||||
|
amt_ <= initialBal,
|
||||||
|
"withdraw-amt-greater-than-supplies"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if borrow balance > 0, there are no supplies so no withdraw, borrow instead.
|
//if borrow balance > 0, there are no supplies so no withdraw, borrow instead.
|
||||||
require(
|
require(
|
||||||
CometInterface(params.market).borrowBalanceOf(params.from) == 0,
|
CometInterface(market).borrowBalanceOf(params.from) == 0,
|
||||||
"withdraw-disabled-for-zero-supplies"
|
"withdraw-disabled-for-zero-supplies"
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
amt_ = amt_ == uint256(-1) ? initialBal : amt_;
|
||||||
}
|
}
|
||||||
|
|
||||||
_withdrawHelper(params.market, token_, params.from, params.to, amt_);
|
CometInterface(params.market).withdrawFrom(params.from, params.to, token_, amt_);
|
||||||
|
|
||||||
uint256 finalBal = _getAccountSupplyBalanceOfAsset(
|
uint256 finalBal = _getAccountSupplyBalanceOfAsset(
|
||||||
params.from,
|
params.from,
|
||||||
|
@ -245,12 +250,11 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
? address(this).balance
|
? address(this).balance
|
||||||
: TokenInterface(params.sellToken).balanceOf(address(this));
|
: TokenInterface(params.sellToken).balanceOf(address(this));
|
||||||
}
|
}
|
||||||
|
convertEthToWeth(isEth, TokenInterface(params.sellToken), sellAmt_);
|
||||||
|
|
||||||
isEth = params.buyAsset == ethAddr;
|
isEth = params.buyAsset == ethAddr;
|
||||||
params.buyAsset = isEth ? wethAddr : params.buyAsset;
|
params.buyAsset = isEth ? wethAddr : params.buyAsset;
|
||||||
|
|
||||||
convertEthToWeth(isEth, TokenInterface(params.sellToken), sellAmt_);
|
|
||||||
|
|
||||||
uint256 slippageAmt_ = convert18ToDec(
|
uint256 slippageAmt_ = convert18ToDec(
|
||||||
TokenInterface(params.buyAsset).decimals(),
|
TokenInterface(params.buyAsset).decimals(),
|
||||||
wmul(
|
wmul(
|
||||||
|
@ -261,6 +265,7 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
approve(TokenInterface(params.sellToken), params.market, sellAmt_);
|
approve(TokenInterface(params.sellToken), params.market, sellAmt_);
|
||||||
CometInterface(params.market).buyCollateral(
|
CometInterface(params.market).buyCollateral(
|
||||||
params.buyAsset,
|
params.buyAsset,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user