changed logic for entering markets

This commit is contained in:
Chinmay Chougaonkar 2022-03-21 15:50:11 +05:30
parent b14f886365
commit 95e390ddef
2 changed files with 5 additions and 12 deletions

View File

@ -42,18 +42,13 @@ abstract contract Helpers is DSMath, Basic {
/**
* @dev enter compound market
* @param _userAccount address of the EOA's account to get the user's entered markets
*/
function enterMarket(address cToken) internal {
address[] memory markets = troller.getAssetsIn(address(this));
bool isEntered = false;
function _enterMarkets(address _userAccount) internal {
address[] memory markets = troller.getAssetsIn(_userAccount);
for (uint i = 0; i < markets.length; i++) {
if (markets[i] == cToken) {
isEntered = true;
}
}
if (!isEntered) {
address[] memory toEnter = new address[](1);
toEnter[0] = cToken;
toEnter[0] = markets[i];
troller.enterMarkets(toEnter);
}
}

View File

@ -35,9 +35,7 @@ contract CompoundImportResolver is CompoundHelper {
data = getBorrowAmounts(_importInputData, data);
data = getSupplyAmounts(_importInputData, data);
for(uint i = 0; i < data.cTokens.length; i++){
enterMarket(data.cTokens[i]);
}
_enterMarkets(_importInputData.userAccount);
// pay back user's debt using flash loan funds
_repayUserDebt(_importInputData.userAccount, data.borrowCtokens, data.borrowAmts);