From d59cd4fc7c79d8543ec4467b7e5cebcb16ec9676 Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Wed, 9 Mar 2022 00:24:59 +0400 Subject: [PATCH] Polygon: Code refactoring --- .../aave/v2-to-v3-import/events.sol | 2 +- .../aave/v2-to-v3-import/helpers.sol | 38 +++++++++---------- .../connectors/aave/v2-to-v3-import/main.sol | 24 ++++++------ 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/contracts/polygon/connectors/aave/v2-to-v3-import/events.sol b/contracts/polygon/connectors/aave/v2-to-v3-import/events.sol index 0d1ed7ae..84bb146f 100644 --- a/contracts/polygon/connectors/aave/v2-to-v3-import/events.sol +++ b/contracts/polygon/connectors/aave/v2-to-v3-import/events.sol @@ -1,7 +1,7 @@ pragma solidity ^0.7.0; contract Events { - event LogAaveV2ImportToV3( + event LogAaveImportV2ToV3( address indexed user, bool doImport, bool convertStable, diff --git a/contracts/polygon/connectors/aave/v2-to-v3-import/helpers.sol b/contracts/polygon/connectors/aave/v2-to-v3-import/helpers.sol index c05dc259..9b397e8c 100644 --- a/contracts/polygon/connectors/aave/v2-to-v3-import/helpers.sol +++ b/contracts/polygon/connectors/aave/v2-to-v3-import/helpers.sol @@ -39,7 +39,7 @@ abstract contract Helper is DSMath, Basic { view returns (bool isCol) { - (, , , , , , , , isCol) = aaveData.getUserReserveData(token, user); + (, , , , , , , , isCol) = aaveV2Data.getUserReserveData(token, user); } struct ImportData { @@ -65,7 +65,7 @@ abstract contract Helper is DSMath, Basic { } contract _AaveHelper is Helper { - function getBorrowAmount(address _token, address userAccount) + function getBorrowAmountV2(address _token, address userAccount) internal view returns (uint256 stableBorrow, uint256 variableBorrow) @@ -74,7 +74,7 @@ contract _AaveHelper is Helper { , address stableDebtTokenAddress, address variableDebtTokenAddress - ) = aaveData.getReserveTokensAddresses(_token); + ) = aaveV2Data.getReserveTokensAddresses(_token); stableBorrow = ATokenV2Interface(stableDebtTokenAddress).balanceOf( userAccount @@ -84,7 +84,7 @@ contract _AaveHelper is Helper { ); } - function getBorrowAmounts( + function getBorrowAmountsV2( address userAccount, AaveV2Interface aaveV2, ImportInputData memory inputData, @@ -119,7 +119,7 @@ contract _AaveHelper is Helper { ( data.stableBorrowAmts[i], data.variableBorrowAmts[i] - ) = getBorrowAmount(_token, userAccount); + ) = getBorrowAmountV2(_token, userAccount); if (data.variableBorrowAmts[i] != 0) { data.variableBorrowAmtsWithFee[i] = add( @@ -152,7 +152,7 @@ contract _AaveHelper is Helper { return data; } - function getSupplyAmounts( + function getSupplyAmountsV2( address userAccount, ImportInputData memory inputData, ImportData memory data @@ -175,7 +175,7 @@ contract _AaveHelper is Helper { address _token = inputData.supplyTokens[i] == maticAddr ? wmaticAddr : inputData.supplyTokens[i]; - (address _aToken, , ) = aaveData.getReserveTokensAddresses(_token); + (address _aToken, , ) = aaveV2Data.getReserveTokensAddresses(_token); data._supplyTokens[i] = _token; data.aTokens[i] = ATokenV2Interface(_aToken); data.supplyAmts[i] = data.aTokens[i].balanceOf(userAccount); @@ -184,7 +184,7 @@ contract _AaveHelper is Helper { return data; } - function _paybackBehalfOne( + function _paybackBehalfOneV2( AaveV2Interface aaveV2, address token, uint256 amt, @@ -194,7 +194,7 @@ contract _AaveHelper is Helper { aaveV2.repay(token, amt, rateMode, user); } - function _PaybackStable( + function _PaybackStableV2( uint256 _length, AaveV2Interface aaveV2, address[] memory tokens, @@ -203,12 +203,12 @@ contract _AaveHelper is Helper { ) internal { for (uint256 i = 0; i < _length; i++) { if (amts[i] > 0) { - _paybackBehalfOne(aaveV2, tokens[i], amts[i], 1, user); + _paybackBehalfOneV2(aaveV2, tokens[i], amts[i], 1, user); } } } - function _PaybackVariable( + function _PaybackVariableV2( uint256 _length, AaveV2Interface aaveV2, address[] memory tokens, @@ -217,12 +217,12 @@ contract _AaveHelper is Helper { ) internal { for (uint256 i = 0; i < _length; i++) { if (amts[i] > 0) { - _paybackBehalfOne(aaveV2, tokens[i], amts[i], 2, user); + _paybackBehalfOneV2(aaveV2, tokens[i], amts[i], 2, user); } } } - function _TransferAtokens( + function _TransferAtokensV2( uint256 _length, AaveV2Interface aaveV2, ATokenV2Interface[] memory atokenContracts, @@ -264,7 +264,7 @@ contract _AaveHelper is Helper { } } - function _depositTokensInV3( + function _depositTokensV3( uint256 _length, AaveV3Interface aaveV3, uint256[] memory amts, @@ -289,7 +289,7 @@ contract _AaveHelper is Helper { } } - function _BorrowVariable( + function _BorrowVariableV3( uint256 _length, AaveV3Interface aaveV3, address[] memory tokens, @@ -297,12 +297,12 @@ contract _AaveHelper is Helper { ) internal { for (uint256 i = 0; i < _length; i++) { if (amts[i] > 0) { - _borrowOne(aaveV3, tokens[i], amts[i], 2); + _borrowOneV3(aaveV3, tokens[i], amts[i], 2); } } } - function _BorrowStable( + function _BorrowStableV3( uint256 _length, AaveV3Interface aaveV3, address[] memory tokens, @@ -310,12 +310,12 @@ contract _AaveHelper is Helper { ) internal { for (uint256 i = 0; i < _length; i++) { if (amts[i] > 0) { - _borrowOne(aaveV3, tokens[i], amts[i], 1); + _borrowOneV3(aaveV3, tokens[i], amts[i], 1); } } } - function _borrowOne( + function _borrowOneV3( AaveV3Interface aaveV3, address token, uint256 amt, diff --git a/contracts/polygon/connectors/aave/v2-to-v3-import/main.sol b/contracts/polygon/connectors/aave/v2-to-v3-import/main.sol index 34001a15..9cb1683c 100644 --- a/contracts/polygon/connectors/aave/v2-to-v3-import/main.sol +++ b/contracts/polygon/connectors/aave/v2-to-v3-import/main.sol @@ -32,18 +32,18 @@ contract _AaveV2ToV3MigrationResolver is _AaveHelper { ); AaveV3Interface aaveV3 = AaveV3Interface(aaveV3Provider.getPool()); - data = getBorrowAmounts(userAccount, aaveV2, inputData, data); - data = getSupplyAmounts(userAccount, inputData, data); + data = getBorrowAmountsV2(userAccount, aaveV2, inputData, data); + data = getSupplyAmountsV2(userAccount, inputData, data); // payback borrowed amount; - _PaybackStable( + _PaybackStableV2( data._borrowTokens.length, aaveV2, data._borrowTokens, data.stableBorrowAmts, userAccount ); - _PaybackVariable( + _PaybackVariableV2( data._borrowTokens.length, aaveV2, data._borrowTokens, @@ -53,7 +53,7 @@ contract _AaveV2ToV3MigrationResolver is _AaveHelper { if (doImport) { // transfer atokens to user's DSA address; - _TransferAtokens( + _TransferAtokensV2( data._supplyTokens.length, aaveV2, data.aTokens, @@ -71,7 +71,7 @@ contract _AaveV2ToV3MigrationResolver is _AaveHelper { data._supplyTokens ); // deposit tokens in v3 - _depositTokensInV3( + _depositTokensV3( data._supplyTokens.length, aaveV3, data.supplyAmts, @@ -80,20 +80,20 @@ contract _AaveV2ToV3MigrationResolver is _AaveHelper { // borrow assets in aave v3 after migrating position if (data.convertStable) { - _BorrowVariable( + _BorrowVariableV3( data._borrowTokens.length, aaveV3, data._borrowTokens, data.totalBorrowAmtsWithFee ); } else { - _BorrowStable( + _BorrowStableV3( data._borrowTokens.length, aaveV3, data._borrowTokens, data.stableBorrowAmtsWithFee ); - _BorrowVariable( + _BorrowVariableV3( data._borrowTokens.length, aaveV3, data._borrowTokens, @@ -101,7 +101,7 @@ contract _AaveV2ToV3MigrationResolver is _AaveHelper { ); } - _eventName = "LogAaveV2ImportToV3(address,bool,bool,address[],address[],uint256[],uint256[],uint256[],uint256[])"; + _eventName = "LogAaveImportV2ToV3(address,bool,bool,address[],address[],uint256[],uint256[],uint256[],uint256[])"; _eventParam = abi.encode( userAccount, doImport, @@ -135,6 +135,6 @@ contract _AaveV2ToV3MigrationResolver is _AaveHelper { } } -contract AaveV2ToV3MigrationResolverPolygon is _AaveV2ToV3MigrationResolver { - string public constant name = "Aave-v2-to-v3-import"; +contract ConnectV2AaveV2ToV3MigrationPolygon is _AaveV2ToV3MigrationResolver { + string public constant name = "Aave-Import-v2-to-v3"; }