From f58788da51f316f8b3aa8118b6963539efe8635b Mon Sep 17 00:00:00 2001 From: Richa-iitr Date: Sun, 29 May 2022 12:11:26 +0530 Subject: [PATCH] refactor code --- contracts/polygon/common/interfaces.sol | 4 ++ .../connectors/aave/v3-import/events.sol | 1 - .../connectors/aave/v3-import/helpers.sol | 61 ++++++++++--------- .../connectors/aave/v3-import/main.sol | 10 +-- 4 files changed, 40 insertions(+), 36 deletions(-) diff --git a/contracts/polygon/common/interfaces.sol b/contracts/polygon/common/interfaces.sol index b502c277..fed5b4ee 100644 --- a/contracts/polygon/common/interfaces.sol +++ b/contracts/polygon/common/interfaces.sol @@ -33,3 +33,7 @@ interface AccountInterface { ) external payable returns (bytes32[] memory responses); } +interface ListInterface { + function accountID(address) public returns (uint64); +} + diff --git a/contracts/polygon/connectors/aave/v3-import/events.sol b/contracts/polygon/connectors/aave/v3-import/events.sol index 80d131ee..6317bdba 100644 --- a/contracts/polygon/connectors/aave/v3-import/events.sol +++ b/contracts/polygon/connectors/aave/v3-import/events.sol @@ -4,7 +4,6 @@ pragma experimental ABIEncoderV2; contract Events { event LogAaveV3Import( - bool isDsa, address indexed user, address[] atokens, string[] supplyIds, diff --git a/contracts/polygon/connectors/aave/v3-import/helpers.sol b/contracts/polygon/connectors/aave/v3-import/helpers.sol index b6c5299b..86a7890b 100644 --- a/contracts/polygon/connectors/aave/v3-import/helpers.sol +++ b/contracts/polygon/connectors/aave/v3-import/helpers.sol @@ -4,7 +4,7 @@ pragma abicoder v2; import { DSMath } from "../../../common/math.sol"; import { Basic } from "../../../common/basic.sol"; -import { TokenInterface, AccountInterface } from "../../../common/interfaces.sol"; +import { TokenInterface, AccountInterface, ListInterface } from "../../../common/interfaces.sol"; import { AaveInterface, AavePoolProviderInterface, AaveDataProviderInterface } from "./interface.sol"; import "./events.sol"; import "./interface.sol"; @@ -27,6 +27,12 @@ abstract contract Helper is DSMath, Basic { AaveDataProviderInterface internal constant aaveData = AaveDataProviderInterface(0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654); + /** + * @dev InstaList + */ + ListInterface internal constant instaList = + ListInterface(0x839c2D3aDe63DF5b0b8F3E57D5e145057Ab41556); + function getIsColl(address token, address user) internal view @@ -230,13 +236,12 @@ contract AaveHelpers is Helper { ATokenInterface[] memory atokenContracts, uint256[] memory amts, address[] memory tokens, - address userAccount, - bool isDsa + address userAccount ) internal { - for (uint256 i = 0; i < _length; i++) { - if (amts[i] > 0) { - uint256 _amt = amts[i]; - if (isDsa) { + if (instaList.accountID(userAccount) == 0) { + for (uint256 i = 0; i < _length; i++) { + if (amts[i] > 0) { + uint256 _amt = amts[i]; require( atokenContracts[i].transferFrom( userAccount, @@ -245,36 +250,36 @@ contract AaveHelpers is Helper { ), "allowance?" ); - } else { - string[] memory _targets = new string[](1); - bytes[] memory _data = new bytes[](1); + } + } + } else { + string[] memory _targets = new string[](_length); + bytes[] memory _data = new bytes[](_length); + bytes4 basicWithdraw = bytes4( + keccak256("withdraw(address,uint256,address,uint256,uint256)") + ); - _targets[0] = "BASIC-A"; - bytes4 basicWithdraw = bytes4( - keccak256( - "withdraw(address,uint256,address,uint256,uint256)" - ) - ); - - _data[0] = abi.encodeWithSelector( + for (uint256 i = 0; i < _length; i++) { + if (amts[i] > 0) { + uint256 _amt = amts[i]; + address _token = tokens[i]; + _targets[i] = "BASIC-A"; + _data[i] = abi.encodeWithSelector( basicWithdraw, - tokens[i], + _token, _amt, userAccount, 0, 0 ); - AccountInterface(address(this)).cast( - _targets, - _data, - address(0) - ); - } - - if (!getIsColl(tokens[i], address(this))) { - aave.setUserUseReserveAsCollateral(tokens[i], true); } } + + AccountInterface(address(this)).cast(_targets, _data, address(0)); + } + + if (!getIsColl(tokens[i], address(this))) { + aave.setUserUseReserveAsCollateral(tokens[i], true); } } diff --git a/contracts/polygon/connectors/aave/v3-import/main.sol b/contracts/polygon/connectors/aave/v3-import/main.sol index 0274d7b8..7be74082 100644 --- a/contracts/polygon/connectors/aave/v3-import/main.sol +++ b/contracts/polygon/connectors/aave/v3-import/main.sol @@ -6,18 +6,17 @@ pragma experimental ABIEncoderV2; * @dev Import EOA's / withdraw DSA's aave V3 position to DSA's aave v3 position */ -import { TokenInterface, AccountInterface } from "../../../common/interfaces.sol"; +import { TokenInterface, AccountInterface, ListInterface } from "../../../common/interfaces.sol"; import { AaveInterface, ATokenInterface } from "./interface.sol"; import "./helpers.sol"; import "./events.sol"; contract AaveV3ImportResolver is AaveHelpers { function _importAave( - bool isDsa, address userAccount, ImportInputData memory inputData ) internal returns (string memory _eventName, bytes memory _eventParam) { - if (!isDsa) { + if (!ListInterface(0x839c2D3aDe63DF5b0b8F3E57D5e145057Ab41556).accountID(userAccount)) require( AccountInterface(address(this)).isAuth(userAccount), "user-account-not-auth" @@ -84,7 +83,6 @@ contract AaveV3ImportResolver is AaveHelpers { _eventName = "LogAaveV3Import(address,bool,address[],address[],uint256[],uint256[],uint256[],uint256[])"; _eventParam = abi.encode( - isDsa, userAccount, inputData.convertStable, inputData.supplyTokens, @@ -186,12 +184,10 @@ contract AaveV3ImportResolver is AaveHelpers { /** * @dev Import aave V3 position . * @notice Import EOA's aave V3 position to DSA's aave v3 position - * @param isDsa True if the userAccount is DSA, false for EOA * @param userAccount The address of the EOA from which aave position will be imported or address of the DSA to which the DSA positions will be merged * @param inputData The struct containing all the neccessary input data */ function importAave( - bool isDsa, address userAccount, ImportInputData memory inputData ) @@ -199,7 +195,7 @@ contract AaveV3ImportResolver is AaveHelpers { payable returns (string memory _eventName, bytes memory _eventParam) { - (_eventName, _eventParam) = _importAave(isDsa, userAccount, inputData); + (_eventName, _eventParam) = _importAave(userAccount, inputData); } /**