Update logic

This commit is contained in:
Mubaris NK 2021-01-07 18:58:37 +05:30
parent fce46257cc
commit e0ee6b8752
No known key found for this signature in database
GPG Key ID: 1F132294E8700320

View File

@ -560,6 +560,7 @@ contract CompoundHelpers is Helpers {
} }
function _compBorrowOne(uint fee, address token, uint amt) internal { function _compBorrowOne(uint fee, address token, uint amt) internal {
if (amt > 0) {
address cToken = InstaMapping(getMappingAddr()).cTokenMapping(token); address cToken = InstaMapping(getMappingAddr()).cTokenMapping(token);
uint feeAmt = wmul(amt, fee); uint feeAmt = wmul(amt, fee);
uint _amt = add(amt, feeAmt); uint _amt = add(amt, feeAmt);
@ -571,6 +572,7 @@ contract CompoundHelpers is Helpers {
TokenInterface(token).transfer(feeCollector, feeAmt); TokenInterface(token).transfer(feeCollector, feeAmt);
} }
} }
}
function _compBorrow( function _compBorrow(
uint length, uint length,
@ -579,13 +581,12 @@ contract CompoundHelpers is Helpers {
uint[] memory amts uint[] memory amts
) internal { ) internal {
for (uint i = 0; i < length; i++) { for (uint i = 0; i < length; i++) {
if (amts[i] > 0) {
_compBorrowOne(fee, tokens[i], amts[i]); _compBorrowOne(fee, tokens[i], amts[i]);
} }
} }
}
function _compDepositOne(uint fee, address token, uint amt) internal { function _compDepositOne(uint fee, address token, uint amt) internal {
if (amt > 0) {
address cToken = InstaMapping(getMappingAddr()).cTokenMapping(token); address cToken = InstaMapping(getMappingAddr()).cTokenMapping(token);
uint feeAmt = wmul(amt, fee); uint feeAmt = wmul(amt, fee);
@ -601,6 +602,7 @@ contract CompoundHelpers is Helpers {
feeCollector.transfer(feeAmt); feeCollector.transfer(feeAmt);
} }
} }
}
function _compDeposit( function _compDeposit(
uint length, uint length,
@ -609,13 +611,12 @@ contract CompoundHelpers is Helpers {
uint[] memory amts uint[] memory amts
) internal { ) internal {
for (uint i = 0; i < length; i++) { for (uint i = 0; i < length; i++) {
if (amts[i] > 0) {
_compDepositOne(fee, tokens[i], amts[i]); _compDepositOne(fee, tokens[i], amts[i]);
} }
} }
}
function _compWithdrawOne(address token, uint amt) internal { function _compWithdrawOne(address token, uint amt) internal {
if (amt > 0) {
address cToken = InstaMapping(getMappingAddr()).cTokenMapping(token); address cToken = InstaMapping(getMappingAddr()).cTokenMapping(token);
CTokenInterface cTokenContract = CTokenInterface(cToken); CTokenInterface cTokenContract = CTokenInterface(cToken);
if (amt == uint(-1)) { if (amt == uint(-1)) {
@ -623,6 +624,7 @@ contract CompoundHelpers is Helpers {
} }
require(cTokenContract.redeemUnderlying(amt) == 0, "withdraw-failed"); require(cTokenContract.redeemUnderlying(amt) == 0, "withdraw-failed");
} }
}
function _compWithdraw( function _compWithdraw(
uint length, uint length,
@ -630,13 +632,12 @@ contract CompoundHelpers is Helpers {
uint[] memory amts uint[] memory amts
) internal { ) internal {
for (uint i = 0; i < length; i++) { for (uint i = 0; i < length; i++) {
if (amts[i] > 0) {
_compWithdrawOne(tokens[i], amts[i]); _compWithdrawOne(tokens[i], amts[i]);
} }
} }
}
function _compPaybackOne(address token, uint amt) internal { function _compPaybackOne(address token, uint amt) internal {
if (amt > 0) {
address cToken = InstaMapping(getMappingAddr()).cTokenMapping(token); address cToken = InstaMapping(getMappingAddr()).cTokenMapping(token);
CTokenInterface cTokenContract = CTokenInterface(cToken); CTokenInterface cTokenContract = CTokenInterface(cToken);
@ -651,6 +652,7 @@ contract CompoundHelpers is Helpers {
CETHInterface(cToken).repayBorrow.value(amt)(); CETHInterface(cToken).repayBorrow.value(amt)();
} }
} }
}
function _compPayback( function _compPayback(
uint length, uint length,
@ -658,11 +660,9 @@ contract CompoundHelpers is Helpers {
uint[] memory amts uint[] memory amts
) internal { ) internal {
for (uint i = 0; i < length; i++) { for (uint i = 0; i < length; i++) {
if (amts[i] > 0) {
_compPaybackOne(tokens[i], amts[i]); _compPaybackOne(tokens[i], amts[i]);
} }
} }
}
} }
contract AaveV1Helpers is CompoundHelpers { contract AaveV1Helpers is CompoundHelpers {
@ -674,6 +674,7 @@ contract AaveV1Helpers is CompoundHelpers {
uint amt, uint amt,
uint rateMode uint rateMode
) internal { ) internal {
if (amt > 0) {
uint feeAmt = wmul(amt, fee); uint feeAmt = wmul(amt, fee);
uint _amt = add(amt, feeAmt); uint _amt = add(amt, feeAmt);
@ -684,6 +685,7 @@ contract AaveV1Helpers is CompoundHelpers {
TokenInterface(token).transfer(feeCollector, feeAmt); TokenInterface(token).transfer(feeCollector, feeAmt);
} }
} }
}
function _aaveV1Borrow( function _aaveV1Borrow(
AaveV1Interface aave, AaveV1Interface aave,
@ -694,11 +696,9 @@ contract AaveV1Helpers is CompoundHelpers {
uint[] memory rateModes uint[] memory rateModes
) internal { ) internal {
for (uint i = 0; i < length; i++) { for (uint i = 0; i < length; i++) {
if (amts[i] > 0) {
_aaveV1BorrowOne(aave, fee, tokens[i], amts[i], rateModes[i]); _aaveV1BorrowOne(aave, fee, tokens[i], amts[i], rateModes[i]);
} }
} }
}
function _aaveV1DepositOne( function _aaveV1DepositOne(
AaveV1Interface aave, AaveV1Interface aave,
@ -706,6 +706,7 @@ contract AaveV1Helpers is CompoundHelpers {
address token, address token,
uint amt uint amt
) internal { ) internal {
if (amt > 0) {
uint ethAmt; uint ethAmt;
uint feeAmt = wmul(amt, fee); uint feeAmt = wmul(amt, fee);
uint _amt = sub(amt, feeAmt); uint _amt = sub(amt, feeAmt);
@ -725,6 +726,7 @@ contract AaveV1Helpers is CompoundHelpers {
if (!getIsColl(aave, token)) if (!getIsColl(aave, token))
aave.setUserUseReserveAsCollateral(token, true); aave.setUserUseReserveAsCollateral(token, true);
} }
}
function _aaveV1Deposit( function _aaveV1Deposit(
AaveV1Interface aave, AaveV1Interface aave,
@ -734,20 +736,20 @@ contract AaveV1Helpers is CompoundHelpers {
uint[] memory amts uint[] memory amts
) internal { ) internal {
for (uint i = 0; i < length; i++) { for (uint i = 0; i < length; i++) {
if (amts[i] > 0) {
_aaveV1DepositOne(aave, fee, tokens[i], amts[i]); _aaveV1DepositOne(aave, fee, tokens[i], amts[i]);
} }
} }
}
function _aaveV1WithdrawOne( function _aaveV1WithdrawOne(
AaveV1CoreInterface aaveCore, AaveV1CoreInterface aaveCore,
address token, address token,
uint amt uint amt
) internal { ) internal {
if (amt > 0) {
ATokenV1Interface atoken = ATokenV1Interface(aaveCore.getReserveATokenAddress(token)); ATokenV1Interface atoken = ATokenV1Interface(aaveCore.getReserveATokenAddress(token));
atoken.redeem(amt); atoken.redeem(amt);
} }
}
function _aaveV1Withdraw( function _aaveV1Withdraw(
AaveV1CoreInterface aaveCore, AaveV1CoreInterface aaveCore,
@ -756,17 +758,16 @@ contract AaveV1Helpers is CompoundHelpers {
uint[] memory amts uint[] memory amts
) internal { ) internal {
for (uint i = 0; i < length; i++) { for (uint i = 0; i < length; i++) {
if (amts[i] > 0) {
_aaveV1WithdrawOne(aaveCore, tokens[i], amts[i]); _aaveV1WithdrawOne(aaveCore, tokens[i], amts[i]);
} }
} }
}
function _aaveV1PaybackOne( function _aaveV1PaybackOne(
AaveV1Interface aave, AaveV1Interface aave,
address token, address token,
uint amt uint amt
) internal { ) internal {
if (amt > 0) {
uint ethAmt; uint ethAmt;
bool isEth = token == getEthAddr(); bool isEth = token == getEthAddr();
if (isEth) { if (isEth) {
@ -778,6 +779,7 @@ contract AaveV1Helpers is CompoundHelpers {
aave.repay.value(ethAmt)(token, amt, payable(address(this))); aave.repay.value(ethAmt)(token, amt, payable(address(this)));
} }
}
function _aaveV1Payback( function _aaveV1Payback(
AaveV1Interface aave, AaveV1Interface aave,
@ -786,11 +788,9 @@ contract AaveV1Helpers is CompoundHelpers {
uint[] memory amts uint[] memory amts
) internal { ) internal {
for (uint i = 0; i < length; i++) { for (uint i = 0; i < length; i++) {
if (amts[i] > 0) {
_aaveV1PaybackOne(aave, tokens[i], amts[i]); _aaveV1PaybackOne(aave, tokens[i], amts[i]);
} }
} }
}
} }
contract AaveV2Helpers is AaveV1Helpers { contract AaveV2Helpers is AaveV1Helpers {
@ -802,6 +802,7 @@ contract AaveV2Helpers is AaveV1Helpers {
uint amt, uint amt,
uint rateMode uint rateMode
) internal { ) internal {
if (amt > 0) {
uint feeAmt = wmul(amt, fee); uint feeAmt = wmul(amt, fee);
uint _amt = add(amt, feeAmt); uint _amt = add(amt, feeAmt);
@ -817,6 +818,7 @@ contract AaveV2Helpers is AaveV1Helpers {
TokenInterface(_token).transfer(feeCollector, feeAmt); TokenInterface(_token).transfer(feeCollector, feeAmt);
} }
} }
}
function _aaveV2Borrow( function _aaveV2Borrow(
AaveV2Interface aave, AaveV2Interface aave,
@ -827,11 +829,9 @@ contract AaveV2Helpers is AaveV1Helpers {
uint[] memory rateModes uint[] memory rateModes
) internal { ) internal {
for (uint i = 0; i < length; i++) { for (uint i = 0; i < length; i++) {
if (amts[i] > 0) {
_aaveV2BorrowOne(aave, fee, tokens[i], amts[i], rateModes[i]); _aaveV2BorrowOne(aave, fee, tokens[i], amts[i], rateModes[i]);
} }
} }
}
function _aaveV2DepositOne( function _aaveV2DepositOne(
AaveV2Interface aave, AaveV2Interface aave,
@ -840,6 +840,7 @@ contract AaveV2Helpers is AaveV1Helpers {
address token, address token,
uint amt uint amt
) internal { ) internal {
if (amt > 0) {
uint feeAmt = wmul(amt, fee); uint feeAmt = wmul(amt, fee);
uint _amt = sub(amt, feeAmt); uint _amt = sub(amt, feeAmt);
@ -863,6 +864,7 @@ contract AaveV2Helpers is AaveV1Helpers {
aave.setUserUseReserveAsCollateral(_token, true); aave.setUserUseReserveAsCollateral(_token, true);
} }
} }
}
function _aaveV2Deposit( function _aaveV2Deposit(
AaveV2Interface aave, AaveV2Interface aave,
@ -873,11 +875,9 @@ contract AaveV2Helpers is AaveV1Helpers {
uint[] memory amts uint[] memory amts
) internal { ) internal {
for (uint i = 0; i < length; i++) { for (uint i = 0; i < length; i++) {
if (amts[i] > 0) {
_aaveV2DepositOne(aave, aaveData, fee, tokens[i], amts[i]); _aaveV2DepositOne(aave, aaveData, fee, tokens[i], amts[i]);
} }
} }
}
function _aaveV2WithdrawOne( function _aaveV2WithdrawOne(
AaveV2Interface aave, AaveV2Interface aave,
@ -885,6 +885,7 @@ contract AaveV2Helpers is AaveV1Helpers {
address token, address token,
uint amt uint amt
) internal { ) internal {
if (amt > 0) {
bool isEth = token == getEthAddr(); bool isEth = token == getEthAddr();
address _token = isEth ? getWethAddr() : token; address _token = isEth ? getWethAddr() : token;
TokenInterface tokenContract = TokenInterface(_token); TokenInterface tokenContract = TokenInterface(_token);
@ -895,6 +896,7 @@ contract AaveV2Helpers is AaveV1Helpers {
convertWethToEth(isEth, tokenContract, _amt); convertWethToEth(isEth, tokenContract, _amt);
} }
}
function _aaveV2Withdraw( function _aaveV2Withdraw(
AaveV2Interface aave, AaveV2Interface aave,
@ -904,11 +906,9 @@ contract AaveV2Helpers is AaveV1Helpers {
uint[] memory amts uint[] memory amts
) internal { ) internal {
for (uint i = 0; i < length; i++) { for (uint i = 0; i < length; i++) {
if (amts[i] > 0) {
_aaveV2WithdrawOne(aave, aaveData, tokens[i], amts[i]); _aaveV2WithdrawOne(aave, aaveData, tokens[i], amts[i]);
} }
} }
}
function _aaveV2PaybackOne( function _aaveV2PaybackOne(
AaveV2Interface aave, AaveV2Interface aave,
@ -917,6 +917,7 @@ contract AaveV2Helpers is AaveV1Helpers {
uint amt, uint amt,
uint rateMode uint rateMode
) internal { ) internal {
if (amt > 0) {
bool isEth = token == getEthAddr(); bool isEth = token == getEthAddr();
address _token = isEth ? getWethAddr() : token; address _token = isEth ? getWethAddr() : token;
TokenInterface tokenContract = TokenInterface(_token); TokenInterface tokenContract = TokenInterface(_token);
@ -927,6 +928,7 @@ contract AaveV2Helpers is AaveV1Helpers {
aave.repay(_token, _amt, rateMode, address(this)); aave.repay(_token, _amt, rateMode, address(this));
} }
}
function _aaveV2Payback( function _aaveV2Payback(
AaveV2Interface aave, AaveV2Interface aave,
@ -937,11 +939,9 @@ contract AaveV2Helpers is AaveV1Helpers {
uint[] memory rateModes uint[] memory rateModes
) internal { ) internal {
for (uint i = 0; i < length; i++) { for (uint i = 0; i < length; i++) {
if (amts[i] > 0) {
_aaveV2PaybackOne(aave, aaveData, tokens[i], amts[i], rateModes[i]); _aaveV2PaybackOne(aave, aaveData, tokens[i], amts[i], rateModes[i]);
} }
} }
}
} }
contract MakerHelpers is AaveV2Helpers { contract MakerHelpers is AaveV2Helpers {
@ -1019,8 +1019,8 @@ contract MakerHelpers is AaveV2Helpers {
VatLike(managerContract.vat()).frob( VatLike(managerContract.vat()).frob(
ilk, ilk,
urn, urn,
_this, address(this),
_this, address(this),
intAmt, intAmt,
0 0
); );