From 95e390ddef9c6bc945f31e3cec54d7fcd2bab4e9 Mon Sep 17 00:00:00 2001 From: Chinmay Chougaonkar Date: Mon, 21 Mar 2022 15:50:11 +0530 Subject: [PATCH] changed logic for entering markets --- .../mainnet/connectors/compound-import/helpers.sol | 13 ++++--------- .../mainnet/connectors/compound-import/main.sol | 4 +--- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/contracts/mainnet/connectors/compound-import/helpers.sol b/contracts/mainnet/connectors/compound-import/helpers.sol index 6e906ad7..f1a9fac5 100644 --- a/contracts/mainnet/connectors/compound-import/helpers.sol +++ b/contracts/mainnet/connectors/compound-import/helpers.sol @@ -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); } } diff --git a/contracts/mainnet/connectors/compound-import/main.sol b/contracts/mainnet/connectors/compound-import/main.sol index eda52e75..8ab0ea52 100644 --- a/contracts/mainnet/connectors/compound-import/main.sol +++ b/contracts/mainnet/connectors/compound-import/main.sol @@ -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);