mirror of
https://github.com/Instadapp/dsa-polygon-migration.git
synced 2024-07-29 22:27:58 +00:00
flies refactoring
This commit is contained in:
parent
2213f12058
commit
ee2d8acbd8
|
@ -113,7 +113,7 @@ contract MigrateResolver is Helpers, Events {
|
||||||
// Keep flashAmt tokens as ideal
|
// Keep flashAmt tokens as ideal
|
||||||
// Object is the decrease the ratio and pay as less interest
|
// Object is the decrease the ratio and pay as less interest
|
||||||
function settle() external {
|
function settle() external {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
10
contracts/senders2/aave-v2-connector/events.sol
Normal file
10
contracts/senders2/aave-v2-connector/events.sol
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
contract Events {
|
||||||
|
event LogAaveV2Migrate(
|
||||||
|
address indexed user,
|
||||||
|
address indexed targetDsa,
|
||||||
|
address[] supplyTokens,
|
||||||
|
address[] borrowTokens
|
||||||
|
);
|
||||||
|
}
|
15
contracts/senders2/aave-v2-connector/helpers.sol
Normal file
15
contracts/senders2/aave-v2-connector/helpers.sol
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
import { DSMath } from "../../common/math.sol";
|
||||||
|
import { Stores } from "../../common/stores-mainnet.sol";
|
||||||
|
import { AaveLendingPoolProviderInterface, AaveDataProviderInterface, AaveMigratorInterface } from "./interfaces.sol";
|
||||||
|
|
||||||
|
abstract contract Helpers is DSMath, Stores {
|
||||||
|
|
||||||
|
AaveMigratorInterface constant internal migrator = AaveMigratorInterface(address(2)); // Replace this (Migrator contract)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Aave Data Provider
|
||||||
|
*/
|
||||||
|
AaveDataProviderInterface constant internal aaveData = AaveDataProviderInterface(0x057835Ad21a177dbdd3090bB1CAE03EaCF78Fc6d);
|
||||||
|
}
|
87
contracts/senders2/aave-v2-connector/interfaces.sol
Normal file
87
contracts/senders2/aave-v2-connector/interfaces.sol
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
interface AaveInterface {
|
||||||
|
function deposit(address _asset, uint256 _amount, address _onBehalfOf, uint16 _referralCode) external;
|
||||||
|
function withdraw(address _asset, uint256 _amount, address _to) external;
|
||||||
|
function borrow(
|
||||||
|
address _asset,
|
||||||
|
uint256 _amount,
|
||||||
|
uint256 _interestRateMode,
|
||||||
|
uint16 _referralCode,
|
||||||
|
address _onBehalfOf
|
||||||
|
) external;
|
||||||
|
function repay(address _asset, uint256 _amount, uint256 _rateMode, address _onBehalfOf) external;
|
||||||
|
function setUserUseReserveAsCollateral(address _asset, bool _useAsCollateral) external;
|
||||||
|
function getUserAccountData(address user) external view returns (
|
||||||
|
uint256 totalCollateralETH,
|
||||||
|
uint256 totalDebtETH,
|
||||||
|
uint256 availableBorrowsETH,
|
||||||
|
uint256 currentLiquidationThreshold,
|
||||||
|
uint256 ltv,
|
||||||
|
uint256 healthFactor
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AaveLendingPoolProviderInterface {
|
||||||
|
function getLendingPool() external view returns (address);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aave Protocol Data Provider
|
||||||
|
interface AaveDataProviderInterface {
|
||||||
|
function getReserveTokensAddresses(address _asset) external view returns (
|
||||||
|
address aTokenAddress,
|
||||||
|
address stableDebtTokenAddress,
|
||||||
|
address variableDebtTokenAddress
|
||||||
|
);
|
||||||
|
function getUserReserveData(address _asset, address _user) external view returns (
|
||||||
|
uint256 currentATokenBalance,
|
||||||
|
uint256 currentStableDebt,
|
||||||
|
uint256 currentVariableDebt,
|
||||||
|
uint256 principalStableDebt,
|
||||||
|
uint256 scaledVariableDebt,
|
||||||
|
uint256 stableBorrowRate,
|
||||||
|
uint256 liquidityRate,
|
||||||
|
uint40 stableRateLastUpdated,
|
||||||
|
bool usageAsCollateralEnabled
|
||||||
|
);
|
||||||
|
function getReserveConfigurationData(address asset) external view returns (
|
||||||
|
uint256 decimals,
|
||||||
|
uint256 ltv,
|
||||||
|
uint256 liquidationThreshold,
|
||||||
|
uint256 liquidationBonus,
|
||||||
|
uint256 reserveFactor,
|
||||||
|
bool usageAsCollateralEnabled,
|
||||||
|
bool borrowingEnabled,
|
||||||
|
bool stableBorrowRateEnabled,
|
||||||
|
bool isActive,
|
||||||
|
bool isFrozen
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AaveAddressProviderRegistryInterface {
|
||||||
|
function getAddressesProvidersList() external view returns (address[] memory);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ATokenInterface {
|
||||||
|
function scaledBalanceOf(address _user) external view returns (uint256);
|
||||||
|
function isTransferAllowed(address _user, uint256 _amount) external view returns (bool);
|
||||||
|
function balanceOf(address _user) external view returns(uint256);
|
||||||
|
function transferFrom(address, address, uint) external returns (bool);
|
||||||
|
function approve(address, uint256) external;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AaveMigratorInterface {
|
||||||
|
function migrate(address, address, address[] calldata, address[] calldata) external;
|
||||||
|
function migrate(address, AaveData memory) external;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AaveData {
|
||||||
|
bool isFinal;
|
||||||
|
address targetDsa;
|
||||||
|
uint[] supplyAmts;
|
||||||
|
uint[] variableBorrowAmts;
|
||||||
|
uint[] stableBorrowAmts;
|
||||||
|
address[] supplyTokens;
|
||||||
|
address[] borrowTokens;
|
||||||
|
}
|
72
contracts/senders2/aave-v2-connector/main.sol
Normal file
72
contracts/senders2/aave-v2-connector/main.sol
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
import { TokenInterface, AccountInterface } from "../../common/interfaces.sol";
|
||||||
|
import { AaveInterface, ATokenInterface, AaveData } from "./interfaces.sol";
|
||||||
|
import { Helpers } from "./helpers.sol";
|
||||||
|
import { Events } from "./events.sol";
|
||||||
|
|
||||||
|
contract AaveMigrateResolver is Helpers, Events {
|
||||||
|
|
||||||
|
// function migrate(
|
||||||
|
// address targetDsa,
|
||||||
|
// address[] calldata supplyTokens,
|
||||||
|
// address[] calldata borrowTokens
|
||||||
|
// ) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
|
// require(supplyTokens.length > 0, "0-length-not-allowed");
|
||||||
|
// require(targetDsa != address(0), "invalid-address");
|
||||||
|
|
||||||
|
// for (uint i = 0; i < supplyTokens.length; i++) {
|
||||||
|
// address _token = supplyTokens[i] == ethAddr ? wethAddr : supplyTokens[i];
|
||||||
|
// (address _aToken, ,) = aaveData.getReserveTokensAddresses(_token);
|
||||||
|
// ATokenInterface _aTokenContract = ATokenInterface(_aToken);
|
||||||
|
// _aTokenContract.approve(address(migrator), _aTokenContract.balanceOf(address(this)));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// migrator.migrate(msg.sender, targetDsa, supplyTokens, borrowTokens);
|
||||||
|
|
||||||
|
// _eventName = "LogAaveV2Migrate(address,address,address[],address[])";
|
||||||
|
// _eventParam = abi.encode(msg.sender, targetDsa, supplyTokens, borrowTokens);
|
||||||
|
// }
|
||||||
|
|
||||||
|
function migrate(
|
||||||
|
AaveData calldata _data
|
||||||
|
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
|
require(_data.supplyTokens.length > 0, "0-length-not-allowed");
|
||||||
|
require(_data.supplyTokens.length == _data.supplyAmts.length, "invalid-length");
|
||||||
|
require(_data.targetDsa != address(0), "invalid-address");
|
||||||
|
require(!_data.isFinal, "wrong-data");
|
||||||
|
|
||||||
|
AaveData memory data;
|
||||||
|
|
||||||
|
data.borrowTokens = _data.borrowTokens;
|
||||||
|
data.isFinal = _data.isFinal;
|
||||||
|
data.stableBorrowAmts = _data.stableBorrowAmts;
|
||||||
|
data.supplyAmts = _data.supplyAmts;
|
||||||
|
data.supplyTokens = _data.supplyTokens;
|
||||||
|
data.targetDsa = _data.targetDsa;
|
||||||
|
data.variableBorrowAmts = _data.variableBorrowAmts;
|
||||||
|
|
||||||
|
for (uint i = 0; i < data.supplyTokens.length; i++) {
|
||||||
|
address _token = data.supplyTokens[i] == ethAddr ? wethAddr : data.supplyTokens[i];
|
||||||
|
data.supplyTokens[i] = _token;
|
||||||
|
(address _aToken, ,) = aaveData.getReserveTokensAddresses(_token);
|
||||||
|
ATokenInterface _aTokenContract = ATokenInterface(_aToken);
|
||||||
|
|
||||||
|
if (data.supplyAmts[i] == uint(-1)) {
|
||||||
|
data.supplyAmts[i] = _aTokenContract.balanceOf(address(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
_aTokenContract.approve(address(migrator), data.supplyAmts[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
migrator.migrate(msg.sender, data);
|
||||||
|
|
||||||
|
_eventName = "LogAaveV2Migrate(address,address,address[],address[])";
|
||||||
|
_eventParam = abi.encode(msg.sender, data.targetDsa, data.supplyTokens, data.borrowTokens);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract AaveV2Migrator is AaveMigrateResolver {
|
||||||
|
string constant public name = "AaveV2PolygonMigrator-v1";
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user