mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
refactor code
This commit is contained in:
parent
99fcc41d0f
commit
f58788da51
|
|
@ -33,3 +33,7 @@ interface AccountInterface {
|
|||
) external payable returns (bytes32[] memory responses);
|
||||
}
|
||||
|
||||
interface ListInterface {
|
||||
function accountID(address) public returns (uint64);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ pragma experimental ABIEncoderV2;
|
|||
|
||||
contract Events {
|
||||
event LogAaveV3Import(
|
||||
bool isDsa,
|
||||
address indexed user,
|
||||
address[] atokens,
|
||||
string[] supplyIds,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ pragma abicoder v2;
|
|||
|
||||
import { DSMath } from "../../../common/math.sol";
|
||||
import { Basic } from "../../../common/basic.sol";
|
||||
import { TokenInterface, AccountInterface } from "../../../common/interfaces.sol";
|
||||
import { TokenInterface, AccountInterface, ListInterface } from "../../../common/interfaces.sol";
|
||||
import { AaveInterface, AavePoolProviderInterface, AaveDataProviderInterface } from "./interface.sol";
|
||||
import "./events.sol";
|
||||
import "./interface.sol";
|
||||
|
|
@ -27,6 +27,12 @@ abstract contract Helper is DSMath, Basic {
|
|||
AaveDataProviderInterface internal constant aaveData =
|
||||
AaveDataProviderInterface(0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654);
|
||||
|
||||
/**
|
||||
* @dev InstaList
|
||||
*/
|
||||
ListInterface internal constant instaList =
|
||||
ListInterface(0x839c2D3aDe63DF5b0b8F3E57D5e145057Ab41556);
|
||||
|
||||
function getIsColl(address token, address user)
|
||||
internal
|
||||
view
|
||||
|
|
@ -230,13 +236,12 @@ contract AaveHelpers is Helper {
|
|||
ATokenInterface[] memory atokenContracts,
|
||||
uint256[] memory amts,
|
||||
address[] memory tokens,
|
||||
address userAccount,
|
||||
bool isDsa
|
||||
address userAccount
|
||||
) internal {
|
||||
for (uint256 i = 0; i < _length; i++) {
|
||||
if (amts[i] > 0) {
|
||||
uint256 _amt = amts[i];
|
||||
if (isDsa) {
|
||||
if (instaList.accountID(userAccount) == 0) {
|
||||
for (uint256 i = 0; i < _length; i++) {
|
||||
if (amts[i] > 0) {
|
||||
uint256 _amt = amts[i];
|
||||
require(
|
||||
atokenContracts[i].transferFrom(
|
||||
userAccount,
|
||||
|
|
@ -245,36 +250,36 @@ contract AaveHelpers is Helper {
|
|||
),
|
||||
"allowance?"
|
||||
);
|
||||
} else {
|
||||
string[] memory _targets = new string[](1);
|
||||
bytes[] memory _data = new bytes[](1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
string[] memory _targets = new string[](_length);
|
||||
bytes[] memory _data = new bytes[](_length);
|
||||
bytes4 basicWithdraw = bytes4(
|
||||
keccak256("withdraw(address,uint256,address,uint256,uint256)")
|
||||
);
|
||||
|
||||
_targets[0] = "BASIC-A";
|
||||
bytes4 basicWithdraw = bytes4(
|
||||
keccak256(
|
||||
"withdraw(address,uint256,address,uint256,uint256)"
|
||||
)
|
||||
);
|
||||
|
||||
_data[0] = abi.encodeWithSelector(
|
||||
for (uint256 i = 0; i < _length; i++) {
|
||||
if (amts[i] > 0) {
|
||||
uint256 _amt = amts[i];
|
||||
address _token = tokens[i];
|
||||
_targets[i] = "BASIC-A";
|
||||
_data[i] = abi.encodeWithSelector(
|
||||
basicWithdraw,
|
||||
tokens[i],
|
||||
_token,
|
||||
_amt,
|
||||
userAccount,
|
||||
0,
|
||||
0
|
||||
);
|
||||
AccountInterface(address(this)).cast(
|
||||
_targets,
|
||||
_data,
|
||||
address(0)
|
||||
);
|
||||
}
|
||||
|
||||
if (!getIsColl(tokens[i], address(this))) {
|
||||
aave.setUserUseReserveAsCollateral(tokens[i], true);
|
||||
}
|
||||
}
|
||||
|
||||
AccountInterface(address(this)).cast(_targets, _data, address(0));
|
||||
}
|
||||
|
||||
if (!getIsColl(tokens[i], address(this))) {
|
||||
aave.setUserUseReserveAsCollateral(tokens[i], true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,18 +6,17 @@ pragma experimental ABIEncoderV2;
|
|||
* @dev Import EOA's / withdraw DSA's aave V3 position to DSA's aave v3 position
|
||||
*/
|
||||
|
||||
import { TokenInterface, AccountInterface } from "../../../common/interfaces.sol";
|
||||
import { TokenInterface, AccountInterface, ListInterface } from "../../../common/interfaces.sol";
|
||||
import { AaveInterface, ATokenInterface } from "./interface.sol";
|
||||
import "./helpers.sol";
|
||||
import "./events.sol";
|
||||
|
||||
contract AaveV3ImportResolver is AaveHelpers {
|
||||
function _importAave(
|
||||
bool isDsa,
|
||||
address userAccount,
|
||||
ImportInputData memory inputData
|
||||
) internal returns (string memory _eventName, bytes memory _eventParam) {
|
||||
if (!isDsa) {
|
||||
if (!ListInterface(0x839c2D3aDe63DF5b0b8F3E57D5e145057Ab41556).accountID(userAccount))
|
||||
require(
|
||||
AccountInterface(address(this)).isAuth(userAccount),
|
||||
"user-account-not-auth"
|
||||
|
|
@ -84,7 +83,6 @@ contract AaveV3ImportResolver is AaveHelpers {
|
|||
|
||||
_eventName = "LogAaveV3Import(address,bool,address[],address[],uint256[],uint256[],uint256[],uint256[])";
|
||||
_eventParam = abi.encode(
|
||||
isDsa,
|
||||
userAccount,
|
||||
inputData.convertStable,
|
||||
inputData.supplyTokens,
|
||||
|
|
@ -186,12 +184,10 @@ contract AaveV3ImportResolver is AaveHelpers {
|
|||
/**
|
||||
* @dev Import aave V3 position .
|
||||
* @notice Import EOA's aave V3 position to DSA's aave v3 position
|
||||
* @param isDsa True if the userAccount is DSA, false for EOA
|
||||
* @param userAccount The address of the EOA from which aave position will be imported or address of the DSA to which the DSA positions will be merged
|
||||
* @param inputData The struct containing all the neccessary input data
|
||||
*/
|
||||
function importAave(
|
||||
bool isDsa,
|
||||
address userAccount,
|
||||
ImportInputData memory inputData
|
||||
)
|
||||
|
|
@ -199,7 +195,7 @@ contract AaveV3ImportResolver is AaveHelpers {
|
|||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
(_eventName, _eventParam) = _importAave(isDsa, userAccount, inputData);
|
||||
(_eventName, _eventParam) = _importAave(userAccount, inputData);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user