dsa-connectors/contracts/mainnet/connectors/aave/v3-import/main.sol

109 lines
2.6 KiB
Solidity
Raw Normal View History

2022-02-26 20:44:41 +00:00
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import { TokenInterface, AccountInterface } from "../../../common/interfaces.sol";
import { AaveInterface, ATokenInterface } from "./interface.sol";
import "./helpers.sol";
import "./events.sol";
2022-02-26 20:44:41 +00:00
contract AaveV3ImportResolver is AaveHelpers {
function _importAave(address userAccount, ImportInputData memory inputData)
2022-02-26 20:44:41 +00:00
internal
returns (string memory _eventName, bytes memory _eventParam)
2022-02-26 20:44:41 +00:00
{
require(
AccountInterface(address(this)).isAuth(userAccount),
"user-account-not-auth"
2022-02-26 20:44:41 +00:00
);
require(inputData.supplyTokens.length > 0, "0-length-not-allowed");
2022-02-26 20:44:41 +00:00
ImportData memory data;
2022-02-26 20:44:41 +00:00
AaveInterface aave = AaveInterface(aaveProvider.getPool());
2022-02-26 20:44:41 +00:00
data = getBorrowAmounts(userAccount, aave, inputData, data);
data = getSupplyAmounts(userAccount, inputData, data);
2022-02-26 20:44:41 +00:00
// payback borrowed amount;
2022-02-26 20:44:41 +00:00
_PaybackStable(
2022-02-26 20:58:09 +00:00
data._borrowTokens.length,
2022-02-26 20:44:41 +00:00
aave,
2022-02-26 20:58:09 +00:00
data._borrowTokens,
data.stableBorrowAmts,
userAccount
2022-02-26 20:44:41 +00:00
);
_PaybackVariable(
2022-02-26 20:58:09 +00:00
data._borrowTokens.length,
2022-02-26 20:44:41 +00:00
aave,
2022-02-26 20:58:09 +00:00
data._borrowTokens,
data.variableBorrowAmts,
userAccount
2022-02-26 20:44:41 +00:00
);
// transfer atokens to this address;
2022-02-26 20:44:41 +00:00
_TransferAtokens(
2022-02-26 20:58:09 +00:00
data._supplyTokens.length,
2022-02-26 20:44:41 +00:00
aave,
2022-02-26 20:58:09 +00:00
data.aTokens,
data.supplyAmts,
data._supplyTokens,
userAccount
2022-02-26 20:44:41 +00:00
);
// borrow assets after migrating position
2022-02-26 20:58:09 +00:00
if (data.convertStable) {
2022-02-26 20:44:41 +00:00
_BorrowVariable(
2022-02-26 20:58:09 +00:00
data._borrowTokens.length,
2022-02-26 20:44:41 +00:00
aave,
2022-02-26 20:58:09 +00:00
data._borrowTokens,
data.totalBorrowAmtsWithFee
2022-02-26 20:44:41 +00:00
);
} else {
_BorrowStable(
2022-02-26 20:58:09 +00:00
data._borrowTokens.length,
2022-02-26 20:44:41 +00:00
aave,
2022-02-26 20:58:09 +00:00
data._borrowTokens,
data.stableBorrowAmtsWithFee
2022-02-26 20:44:41 +00:00
);
_BorrowVariable(
2022-02-26 20:58:09 +00:00
data._borrowTokens.length,
2022-02-26 20:44:41 +00:00
aave,
2022-02-26 20:58:09 +00:00
data._borrowTokens,
data.variableBorrowAmtsWithFee
2022-02-26 20:44:41 +00:00
);
}
_eventName = "LogAaveV2Import(address,bool,address[],address[],uint256[],uint256[],uint256[])";
_eventParam = abi.encode(
userAccount,
inputData.convertStable,
inputData.supplyTokens,
inputData.borrowTokens,
data.supplyAmts,
data.stableBorrowAmts,
data.variableBorrowAmts
);
}
function importAave(address userAccount, ImportInputData memory inputData)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
(_eventName, _eventParam) = _importAave(userAccount, inputData);
}
function migrateAave(ImportInputData memory inputData)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
(_eventName, _eventParam) = _importAave(msg.sender, inputData);
}
}
contract ConnectV2AaveV3Import is AaveV3ImportResolver {
string public constant name = "Aave-v3-Import-v2";
}