mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Polygon: Code refactoring
This commit is contained in:
parent
22728d776a
commit
d59cd4fc7c
|
@ -1,7 +1,7 @@
|
||||||
pragma solidity ^0.7.0;
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
contract Events {
|
contract Events {
|
||||||
event LogAaveV2ImportToV3(
|
event LogAaveImportV2ToV3(
|
||||||
address indexed user,
|
address indexed user,
|
||||||
bool doImport,
|
bool doImport,
|
||||||
bool convertStable,
|
bool convertStable,
|
||||||
|
|
|
@ -39,7 +39,7 @@ abstract contract Helper is DSMath, Basic {
|
||||||
view
|
view
|
||||||
returns (bool isCol)
|
returns (bool isCol)
|
||||||
{
|
{
|
||||||
(, , , , , , , , isCol) = aaveData.getUserReserveData(token, user);
|
(, , , , , , , , isCol) = aaveV2Data.getUserReserveData(token, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ImportData {
|
struct ImportData {
|
||||||
|
@ -65,7 +65,7 @@ abstract contract Helper is DSMath, Basic {
|
||||||
}
|
}
|
||||||
|
|
||||||
contract _AaveHelper is Helper {
|
contract _AaveHelper is Helper {
|
||||||
function getBorrowAmount(address _token, address userAccount)
|
function getBorrowAmountV2(address _token, address userAccount)
|
||||||
internal
|
internal
|
||||||
view
|
view
|
||||||
returns (uint256 stableBorrow, uint256 variableBorrow)
|
returns (uint256 stableBorrow, uint256 variableBorrow)
|
||||||
|
@ -74,7 +74,7 @@ contract _AaveHelper is Helper {
|
||||||
,
|
,
|
||||||
address stableDebtTokenAddress,
|
address stableDebtTokenAddress,
|
||||||
address variableDebtTokenAddress
|
address variableDebtTokenAddress
|
||||||
) = aaveData.getReserveTokensAddresses(_token);
|
) = aaveV2Data.getReserveTokensAddresses(_token);
|
||||||
|
|
||||||
stableBorrow = ATokenV2Interface(stableDebtTokenAddress).balanceOf(
|
stableBorrow = ATokenV2Interface(stableDebtTokenAddress).balanceOf(
|
||||||
userAccount
|
userAccount
|
||||||
|
@ -84,7 +84,7 @@ contract _AaveHelper is Helper {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBorrowAmounts(
|
function getBorrowAmountsV2(
|
||||||
address userAccount,
|
address userAccount,
|
||||||
AaveV2Interface aaveV2,
|
AaveV2Interface aaveV2,
|
||||||
ImportInputData memory inputData,
|
ImportInputData memory inputData,
|
||||||
|
@ -119,7 +119,7 @@ contract _AaveHelper is Helper {
|
||||||
(
|
(
|
||||||
data.stableBorrowAmts[i],
|
data.stableBorrowAmts[i],
|
||||||
data.variableBorrowAmts[i]
|
data.variableBorrowAmts[i]
|
||||||
) = getBorrowAmount(_token, userAccount);
|
) = getBorrowAmountV2(_token, userAccount);
|
||||||
|
|
||||||
if (data.variableBorrowAmts[i] != 0) {
|
if (data.variableBorrowAmts[i] != 0) {
|
||||||
data.variableBorrowAmtsWithFee[i] = add(
|
data.variableBorrowAmtsWithFee[i] = add(
|
||||||
|
@ -152,7 +152,7 @@ contract _AaveHelper is Helper {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSupplyAmounts(
|
function getSupplyAmountsV2(
|
||||||
address userAccount,
|
address userAccount,
|
||||||
ImportInputData memory inputData,
|
ImportInputData memory inputData,
|
||||||
ImportData memory data
|
ImportData memory data
|
||||||
|
@ -175,7 +175,7 @@ contract _AaveHelper is Helper {
|
||||||
address _token = inputData.supplyTokens[i] == maticAddr
|
address _token = inputData.supplyTokens[i] == maticAddr
|
||||||
? wmaticAddr
|
? wmaticAddr
|
||||||
: inputData.supplyTokens[i];
|
: inputData.supplyTokens[i];
|
||||||
(address _aToken, , ) = aaveData.getReserveTokensAddresses(_token);
|
(address _aToken, , ) = aaveV2Data.getReserveTokensAddresses(_token);
|
||||||
data._supplyTokens[i] = _token;
|
data._supplyTokens[i] = _token;
|
||||||
data.aTokens[i] = ATokenV2Interface(_aToken);
|
data.aTokens[i] = ATokenV2Interface(_aToken);
|
||||||
data.supplyAmts[i] = data.aTokens[i].balanceOf(userAccount);
|
data.supplyAmts[i] = data.aTokens[i].balanceOf(userAccount);
|
||||||
|
@ -184,7 +184,7 @@ contract _AaveHelper is Helper {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _paybackBehalfOne(
|
function _paybackBehalfOneV2(
|
||||||
AaveV2Interface aaveV2,
|
AaveV2Interface aaveV2,
|
||||||
address token,
|
address token,
|
||||||
uint256 amt,
|
uint256 amt,
|
||||||
|
@ -194,7 +194,7 @@ contract _AaveHelper is Helper {
|
||||||
aaveV2.repay(token, amt, rateMode, user);
|
aaveV2.repay(token, amt, rateMode, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _PaybackStable(
|
function _PaybackStableV2(
|
||||||
uint256 _length,
|
uint256 _length,
|
||||||
AaveV2Interface aaveV2,
|
AaveV2Interface aaveV2,
|
||||||
address[] memory tokens,
|
address[] memory tokens,
|
||||||
|
@ -203,12 +203,12 @@ contract _AaveHelper is Helper {
|
||||||
) internal {
|
) internal {
|
||||||
for (uint256 i = 0; i < _length; i++) {
|
for (uint256 i = 0; i < _length; i++) {
|
||||||
if (amts[i] > 0) {
|
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,
|
uint256 _length,
|
||||||
AaveV2Interface aaveV2,
|
AaveV2Interface aaveV2,
|
||||||
address[] memory tokens,
|
address[] memory tokens,
|
||||||
|
@ -217,12 +217,12 @@ contract _AaveHelper is Helper {
|
||||||
) internal {
|
) internal {
|
||||||
for (uint256 i = 0; i < _length; i++) {
|
for (uint256 i = 0; i < _length; i++) {
|
||||||
if (amts[i] > 0) {
|
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,
|
uint256 _length,
|
||||||
AaveV2Interface aaveV2,
|
AaveV2Interface aaveV2,
|
||||||
ATokenV2Interface[] memory atokenContracts,
|
ATokenV2Interface[] memory atokenContracts,
|
||||||
|
@ -264,7 +264,7 @@ contract _AaveHelper is Helper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _depositTokensInV3(
|
function _depositTokensV3(
|
||||||
uint256 _length,
|
uint256 _length,
|
||||||
AaveV3Interface aaveV3,
|
AaveV3Interface aaveV3,
|
||||||
uint256[] memory amts,
|
uint256[] memory amts,
|
||||||
|
@ -289,7 +289,7 @@ contract _AaveHelper is Helper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _BorrowVariable(
|
function _BorrowVariableV3(
|
||||||
uint256 _length,
|
uint256 _length,
|
||||||
AaveV3Interface aaveV3,
|
AaveV3Interface aaveV3,
|
||||||
address[] memory tokens,
|
address[] memory tokens,
|
||||||
|
@ -297,12 +297,12 @@ contract _AaveHelper is Helper {
|
||||||
) internal {
|
) internal {
|
||||||
for (uint256 i = 0; i < _length; i++) {
|
for (uint256 i = 0; i < _length; i++) {
|
||||||
if (amts[i] > 0) {
|
if (amts[i] > 0) {
|
||||||
_borrowOne(aaveV3, tokens[i], amts[i], 2);
|
_borrowOneV3(aaveV3, tokens[i], amts[i], 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _BorrowStable(
|
function _BorrowStableV3(
|
||||||
uint256 _length,
|
uint256 _length,
|
||||||
AaveV3Interface aaveV3,
|
AaveV3Interface aaveV3,
|
||||||
address[] memory tokens,
|
address[] memory tokens,
|
||||||
|
@ -310,12 +310,12 @@ contract _AaveHelper is Helper {
|
||||||
) internal {
|
) internal {
|
||||||
for (uint256 i = 0; i < _length; i++) {
|
for (uint256 i = 0; i < _length; i++) {
|
||||||
if (amts[i] > 0) {
|
if (amts[i] > 0) {
|
||||||
_borrowOne(aaveV3, tokens[i], amts[i], 1);
|
_borrowOneV3(aaveV3, tokens[i], amts[i], 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _borrowOne(
|
function _borrowOneV3(
|
||||||
AaveV3Interface aaveV3,
|
AaveV3Interface aaveV3,
|
||||||
address token,
|
address token,
|
||||||
uint256 amt,
|
uint256 amt,
|
||||||
|
|
|
@ -32,18 +32,18 @@ contract _AaveV2ToV3MigrationResolver is _AaveHelper {
|
||||||
);
|
);
|
||||||
AaveV3Interface aaveV3 = AaveV3Interface(aaveV3Provider.getPool());
|
AaveV3Interface aaveV3 = AaveV3Interface(aaveV3Provider.getPool());
|
||||||
|
|
||||||
data = getBorrowAmounts(userAccount, aaveV2, inputData, data);
|
data = getBorrowAmountsV2(userAccount, aaveV2, inputData, data);
|
||||||
data = getSupplyAmounts(userAccount, inputData, data);
|
data = getSupplyAmountsV2(userAccount, inputData, data);
|
||||||
|
|
||||||
// payback borrowed amount;
|
// payback borrowed amount;
|
||||||
_PaybackStable(
|
_PaybackStableV2(
|
||||||
data._borrowTokens.length,
|
data._borrowTokens.length,
|
||||||
aaveV2,
|
aaveV2,
|
||||||
data._borrowTokens,
|
data._borrowTokens,
|
||||||
data.stableBorrowAmts,
|
data.stableBorrowAmts,
|
||||||
userAccount
|
userAccount
|
||||||
);
|
);
|
||||||
_PaybackVariable(
|
_PaybackVariableV2(
|
||||||
data._borrowTokens.length,
|
data._borrowTokens.length,
|
||||||
aaveV2,
|
aaveV2,
|
||||||
data._borrowTokens,
|
data._borrowTokens,
|
||||||
|
@ -53,7 +53,7 @@ contract _AaveV2ToV3MigrationResolver is _AaveHelper {
|
||||||
|
|
||||||
if (doImport) {
|
if (doImport) {
|
||||||
// transfer atokens to user's DSA address;
|
// transfer atokens to user's DSA address;
|
||||||
_TransferAtokens(
|
_TransferAtokensV2(
|
||||||
data._supplyTokens.length,
|
data._supplyTokens.length,
|
||||||
aaveV2,
|
aaveV2,
|
||||||
data.aTokens,
|
data.aTokens,
|
||||||
|
@ -71,7 +71,7 @@ contract _AaveV2ToV3MigrationResolver is _AaveHelper {
|
||||||
data._supplyTokens
|
data._supplyTokens
|
||||||
);
|
);
|
||||||
// deposit tokens in v3
|
// deposit tokens in v3
|
||||||
_depositTokensInV3(
|
_depositTokensV3(
|
||||||
data._supplyTokens.length,
|
data._supplyTokens.length,
|
||||||
aaveV3,
|
aaveV3,
|
||||||
data.supplyAmts,
|
data.supplyAmts,
|
||||||
|
@ -80,20 +80,20 @@ contract _AaveV2ToV3MigrationResolver is _AaveHelper {
|
||||||
|
|
||||||
// borrow assets in aave v3 after migrating position
|
// borrow assets in aave v3 after migrating position
|
||||||
if (data.convertStable) {
|
if (data.convertStable) {
|
||||||
_BorrowVariable(
|
_BorrowVariableV3(
|
||||||
data._borrowTokens.length,
|
data._borrowTokens.length,
|
||||||
aaveV3,
|
aaveV3,
|
||||||
data._borrowTokens,
|
data._borrowTokens,
|
||||||
data.totalBorrowAmtsWithFee
|
data.totalBorrowAmtsWithFee
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
_BorrowStable(
|
_BorrowStableV3(
|
||||||
data._borrowTokens.length,
|
data._borrowTokens.length,
|
||||||
aaveV3,
|
aaveV3,
|
||||||
data._borrowTokens,
|
data._borrowTokens,
|
||||||
data.stableBorrowAmtsWithFee
|
data.stableBorrowAmtsWithFee
|
||||||
);
|
);
|
||||||
_BorrowVariable(
|
_BorrowVariableV3(
|
||||||
data._borrowTokens.length,
|
data._borrowTokens.length,
|
||||||
aaveV3,
|
aaveV3,
|
||||||
data._borrowTokens,
|
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(
|
_eventParam = abi.encode(
|
||||||
userAccount,
|
userAccount,
|
||||||
doImport,
|
doImport,
|
||||||
|
@ -135,6 +135,6 @@ contract _AaveV2ToV3MigrationResolver is _AaveHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract AaveV2ToV3MigrationResolverPolygon is _AaveV2ToV3MigrationResolver {
|
contract ConnectV2AaveV2ToV3MigrationPolygon is _AaveV2ToV3MigrationResolver {
|
||||||
string public constant name = "Aave-v2-to-v3-import";
|
string public constant name = "Aave-Import-v2-to-v3";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user