mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
update v2->v3 import avax
This commit is contained in:
parent
31a497e21b
commit
270a3f79b9
|
@ -1,8 +1,9 @@
|
||||||
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 convertStable,
|
bool convertStable,
|
||||||
address[] supplyTokens,
|
address[] supplyTokens,
|
||||||
address[] borrowTokens,
|
address[] borrowTokens,
|
||||||
|
|
|
@ -17,7 +17,7 @@ abstract contract Helper is DSMath, Basic {
|
||||||
*/
|
*/
|
||||||
AaveV2LendingPoolProviderInterface internal constant aaveV2Provider =
|
AaveV2LendingPoolProviderInterface internal constant aaveV2Provider =
|
||||||
AaveV2LendingPoolProviderInterface(
|
AaveV2LendingPoolProviderInterface(
|
||||||
0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5 // v2 address TODO: need to update this
|
0xb6A86025F0FE1862B372cb0ca18CE3EDe02A318f // v2 address: LendingPoolAddressProvider avax
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,21 +25,21 @@ abstract contract Helper is DSMath, Basic {
|
||||||
*/
|
*/
|
||||||
AaveV3PoolProviderInterface internal constant aaveV3Provider =
|
AaveV3PoolProviderInterface internal constant aaveV3Provider =
|
||||||
AaveV3PoolProviderInterface(
|
AaveV3PoolProviderInterface(
|
||||||
0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5 // v2 address TODO: need to update this
|
0x7013523049CeC8b06F594edb8c5fb7F232c0Df7C // v3 - PoolAddressesProvider Avalanche
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Aave Protocol Data Provider
|
* @dev Aave Protocol Data Provider
|
||||||
*/
|
*/
|
||||||
AaveV2DataProviderInterface internal constant aaveData =
|
AaveV2DataProviderInterface internal constant aaveV2Data =
|
||||||
AaveV2DataProviderInterface(0x057835Ad21a177dbdd3090bB1CAE03EaCF78Fc6d); // TODO: need to update this
|
AaveV2DataProviderInterface(0x65285E9dfab318f57051ab2b139ccCf232945451); // aave v2 - avax
|
||||||
|
|
||||||
function getIsColl(address token, address user)
|
function getIsColl(address token, address user)
|
||||||
internal
|
internal
|
||||||
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,9 @@ contract _AaveHelper is Helper {
|
||||||
address _token = inputData.supplyTokens[i] == avaxAddr
|
address _token = inputData.supplyTokens[i] == avaxAddr
|
||||||
? wavaxAddr
|
? wavaxAddr
|
||||||
: 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 +186,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 +196,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 +205,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 +219,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 +266,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 +291,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 +299,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 +312,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,
|
||||||
|
|
|
@ -7,15 +7,18 @@ import "./helpers.sol";
|
||||||
import "./events.sol";
|
import "./events.sol";
|
||||||
|
|
||||||
contract _AaveV2ToV3MigrationResolver is _AaveHelper {
|
contract _AaveV2ToV3MigrationResolver is _AaveHelper {
|
||||||
function _importAave(address userAccount, ImportInputData memory inputData)
|
function _importAave(
|
||||||
internal
|
address userAccount,
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
ImportInputData memory inputData,
|
||||||
{
|
bool doImport
|
||||||
require(
|
) internal returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
AccountInterface(address(this)).isAuth(userAccount),
|
if (doImport) {
|
||||||
"user-account-not-auth"
|
// check only when we are importing from user's address
|
||||||
);
|
require(
|
||||||
|
AccountInterface(address(this)).isAuth(userAccount),
|
||||||
|
"user-account-not-auth"
|
||||||
|
);
|
||||||
|
}
|
||||||
require(inputData.supplyTokens.length > 0, "0-length-not-allowed");
|
require(inputData.supplyTokens.length > 0, "0-length-not-allowed");
|
||||||
|
|
||||||
ImportData memory data;
|
ImportData memory data;
|
||||||
|
@ -25,18 +28,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,
|
||||||
|
@ -44,16 +47,17 @@ contract _AaveV2ToV3MigrationResolver is _AaveHelper {
|
||||||
userAccount
|
userAccount
|
||||||
);
|
);
|
||||||
|
|
||||||
// transfer atokens to this address;
|
if (doImport) {
|
||||||
_TransferAtokens(
|
// transfer atokens to this address;
|
||||||
data._supplyTokens.length,
|
_TransferAtokensV2(
|
||||||
aaveV2,
|
data._supplyTokens.length,
|
||||||
data.aTokens,
|
aaveV2,
|
||||||
data.supplyAmts,
|
data.aTokens,
|
||||||
data._supplyTokens,
|
data.supplyAmts,
|
||||||
userAccount
|
data._supplyTokens,
|
||||||
);
|
userAccount
|
||||||
|
);
|
||||||
|
}
|
||||||
// withdraw v2 supplied tokens
|
// withdraw v2 supplied tokens
|
||||||
_WithdrawTokensFromV2(
|
_WithdrawTokensFromV2(
|
||||||
data._supplyTokens.length,
|
data._supplyTokens.length,
|
||||||
|
@ -62,7 +66,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,
|
||||||
|
@ -71,20 +75,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,
|
||||||
|
@ -92,9 +96,10 @@ contract _AaveV2ToV3MigrationResolver is _AaveHelper {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_eventName = "LogAaveV2ImportToV3(address,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,
|
||||||
inputData.convertStable,
|
inputData.convertStable,
|
||||||
inputData.supplyTokens,
|
inputData.supplyTokens,
|
||||||
inputData.borrowTokens,
|
inputData.borrowTokens,
|
||||||
|
@ -113,7 +118,7 @@ contract _AaveV2ToV3MigrationResolver is _AaveHelper {
|
||||||
payable
|
payable
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
{
|
{
|
||||||
(_eventName, _eventParam) = _importAave(userAccount, inputData);
|
(_eventName, _eventParam) = _importAave(userAccount, inputData, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
function migrateAaveV2ToV3(ImportInputData memory inputData)
|
function migrateAaveV2ToV3(ImportInputData memory inputData)
|
||||||
|
@ -121,10 +126,10 @@ contract _AaveV2ToV3MigrationResolver is _AaveHelper {
|
||||||
payable
|
payable
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
{
|
{
|
||||||
(_eventName, _eventParam) = _importAave(msg.sender, inputData);
|
(_eventName, _eventParam) = _importAave(msg.sender, inputData, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract AaveV2ToV3MigrationResolverAvalanche is _AaveV2ToV3MigrationResolver {
|
contract ConnectV2AaveV2ToV3MigrationPolygon is _AaveV2ToV3MigrationResolver {
|
||||||
string public constant name = "Aave-v2-to-v3-import";
|
string public constant name = "Aave-Import-v2-to-v3";
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,7 @@ contract _AaveV2ToV3MigrationResolver is _AaveHelper {
|
||||||
address userAccount,
|
address userAccount,
|
||||||
ImportInputData memory inputData,
|
ImportInputData memory inputData,
|
||||||
bool doImport
|
bool doImport
|
||||||
)
|
) internal returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
internal
|
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
|
||||||
{
|
|
||||||
if (doImport) {
|
if (doImport) {
|
||||||
// check only when we are importing from user's address
|
// check only when we are importing from user's address
|
||||||
require(
|
require(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user