Fixed Avalanche Aave v2 to v3 connector fix

This commit is contained in:
Thrilok Kumar 2022-03-16 17:15:03 +04:00
parent 8cf500a1fa
commit cc44116a03
2 changed files with 31 additions and 8 deletions

View File

@ -44,7 +44,9 @@ abstract contract Helper is DSMath, Basic {
struct ImportData { struct ImportData {
address[] _supplyTokens; address[] _supplyTokens;
address[] _supplyTokensV3;
address[] _borrowTokens; address[] _borrowTokens;
address[] _borrowTokensV3;
ATokenV2Interface[] aTokens; ATokenV2Interface[] aTokens;
uint256[] supplyAmts; uint256[] supplyAmts;
uint256[] variableBorrowAmts; uint256[] variableBorrowAmts;
@ -65,6 +67,22 @@ abstract contract Helper is DSMath, Basic {
} }
contract _AaveHelper is Helper { contract _AaveHelper is Helper {
/*
** Convert Avalanche Bridge tokens to Offical tokens. Like USDC.e to USDC
*/
function convertABTokens (address _token) internal view returns (address) {
if (_token == 0xc7198437980c041c805A1EDcbA50c1Ce5db95118) {
// USDT.e => USDT
return 0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7
} else if (_token == 0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664) {
// USDC.e => USDC
return 0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e
} else {
return _token
}
}
function getBorrowAmountV2(address _token, address userAccount) function getBorrowAmountV2(address _token, address userAccount)
internal internal
view view
@ -92,6 +110,7 @@ contract _AaveHelper is Helper {
) internal returns (ImportData memory) { ) internal returns (ImportData memory) {
if (inputData.borrowTokens.length > 0) { if (inputData.borrowTokens.length > 0) {
data._borrowTokens = new address[](inputData.borrowTokens.length); data._borrowTokens = new address[](inputData.borrowTokens.length);
data._borrowTokensV3 = new address[](inputData.borrowTokens.length);
data.variableBorrowAmts = new uint256[]( data.variableBorrowAmts = new uint256[](
inputData.borrowTokens.length inputData.borrowTokens.length
); );
@ -115,6 +134,7 @@ contract _AaveHelper is Helper {
? wavaxAddr ? wavaxAddr
: inputData.borrowTokens[i]; : inputData.borrowTokens[i];
data._borrowTokens[i] = _token; data._borrowTokens[i] = _token;
data._borrowTokensV3[i] = convertABTokens(_token);
( (
data.stableBorrowAmts[i], data.stableBorrowAmts[i],
@ -159,6 +179,7 @@ contract _AaveHelper is Helper {
) internal view returns (ImportData memory) { ) internal view returns (ImportData memory) {
data.supplyAmts = new uint256[](inputData.supplyTokens.length); data.supplyAmts = new uint256[](inputData.supplyTokens.length);
data._supplyTokens = new address[](inputData.supplyTokens.length); data._supplyTokens = new address[](inputData.supplyTokens.length);
data._supplyTokensV3 = new address[](inputData.supplyTokens.length);
data.aTokens = new ATokenV2Interface[](inputData.supplyTokens.length); data.aTokens = new ATokenV2Interface[](inputData.supplyTokens.length);
for (uint256 i = 0; i < inputData.supplyTokens.length; i++) { for (uint256 i = 0; i < inputData.supplyTokens.length; i++) {
@ -179,6 +200,8 @@ contract _AaveHelper is Helper {
_token _token
); );
data._supplyTokens[i] = _token; data._supplyTokens[i] = _token;
data._supplyTokensV3[i] = convertABTokens(_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);
} }

View File

@ -71,31 +71,31 @@ contract _AaveV2ToV3MigrationResolver is _AaveHelper {
); );
// deposit tokens in v3 // deposit tokens in v3
_depositTokensV3( _depositTokensV3(
data._supplyTokens.length, data._supplyTokensV3.length,
aaveV3, aaveV3,
data.supplyAmts, data.supplyAmts,
data._supplyTokens data._supplyTokensV3
); );
// borrow assets in aave v3 after migrating position // borrow assets in aave v3 after migrating position
if (data.convertStable) { if (data.convertStable) {
_BorrowVariableV3( _BorrowVariableV3(
data._borrowTokens.length, data._borrowTokensV3.length,
aaveV3, aaveV3,
data._borrowTokens, data._borrowTokensV3,
data.totalBorrowAmtsWithFee data.totalBorrowAmtsWithFee
); );
} else { } else {
_BorrowStableV3( _BorrowStableV3(
data._borrowTokens.length, data._borrowTokensV3.length,
aaveV3, aaveV3,
data._borrowTokens, data._borrowTokensV3,
data.stableBorrowAmtsWithFee data.stableBorrowAmtsWithFee
); );
_BorrowVariableV3( _BorrowVariableV3(
data._borrowTokens.length, data._borrowTokensV3.length,
aaveV3, aaveV3,
data._borrowTokens, data._borrowTokensV3,
data.variableBorrowAmtsWithFee data.variableBorrowAmtsWithFee
); );
} }