mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
code refactor
This commit is contained in:
parent
e1737f533f
commit
8a6c936edb
|
|
@ -256,32 +256,44 @@ contract AaveHelpers is Helper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
string[] memory _targets = new string[](_length);
|
uint256 _len = 0;
|
||||||
bytes[] memory _data = new bytes[](_length);
|
uint256 _cntr = 0;
|
||||||
|
for (uint256 i = 0; i < _length; i++) {
|
||||||
|
if (amts[i] > 0) {
|
||||||
|
_len++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
string[] memory _targets = new string[](_len);
|
||||||
|
bytes[] memory _data = new bytes[](_len);
|
||||||
|
address[] memory _tokens = new address[](_len);
|
||||||
bytes4 basicWithdraw = bytes4(
|
bytes4 basicWithdraw = bytes4(
|
||||||
keccak256("withdraw(address,uint256,address,uint256,uint256)")
|
keccak256("withdraw(address,uint256,address,uint256,uint256)")
|
||||||
);
|
);
|
||||||
|
|
||||||
for (uint256 i = 0; i < _length; i++) {
|
for (uint256 i = 0; i < _length; i++) {
|
||||||
_targets[i] = "BASIC-A";
|
|
||||||
if (amts[i] > 0) {
|
if (amts[i] > 0) {
|
||||||
uint256 _amt = amts[i];
|
uint256 _amt = amts[i];
|
||||||
address _token = tokens[i];
|
address _token = tokens[i];
|
||||||
_data[i] = abi.encodeWithSelector(
|
_targets[_cntr] = "BASIC-A";
|
||||||
|
_data[_cntr] = abi.encodeWithSelector(
|
||||||
basicWithdraw,
|
basicWithdraw,
|
||||||
_token,
|
tokens[i],
|
||||||
_amt,
|
_amt,
|
||||||
address(this),
|
address(this),
|
||||||
0,
|
0,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
if (!getIsColl(_token, address(this))) {
|
_tokens[_cntr] = _token;
|
||||||
aave.setUserUseReserveAsCollateral(_token, true);
|
_cntr++;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountInterface(userAccount).cast(_targets, _data, address(0));
|
AccountInterface(userAccount).cast(_targets, _data, address(0));
|
||||||
|
for (uint256 i = 0; i < _len; i++) {
|
||||||
|
if (!getIsColl(_tokens[i], address(this))) {
|
||||||
|
aave.setUserUseReserveAsCollateral(_tokens[i], true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -294,6 +306,7 @@ contract AaveHelpers is Helper {
|
||||||
bool[] memory colEnable,
|
bool[] memory colEnable,
|
||||||
address userAccount
|
address userAccount
|
||||||
) internal {
|
) internal {
|
||||||
|
if (instaList.accountID(userAccount) == 0) {
|
||||||
for (uint256 i = 0; i < _length; i++) {
|
for (uint256 i = 0; i < _length; i++) {
|
||||||
if (amts[i] > 0) {
|
if (amts[i] > 0) {
|
||||||
uint256 _amt = amts[i];
|
uint256 _amt = amts[i];
|
||||||
|
|
@ -307,7 +320,53 @@ contract AaveHelpers is Helper {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!getIsColl(tokens[i], address(this))) {
|
if (!getIsColl(tokens[i], address(this))) {
|
||||||
aave.setUserUseReserveAsCollateral(tokens[i], colEnable[i]);
|
aave.setUserUseReserveAsCollateral(
|
||||||
|
tokens[i],
|
||||||
|
colEnable[i]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
uint256 _len = 0;
|
||||||
|
uint256 _cntr = 0;
|
||||||
|
for (uint256 i = 0; i < _length; i++) {
|
||||||
|
if (amts[i] > 0) {
|
||||||
|
_len++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
string[] memory _targets = new string[](_len);
|
||||||
|
bytes[] memory _data = new bytes[](_len);
|
||||||
|
address[] memory _tokens = new address[](_len);
|
||||||
|
bytes4 basicWithdraw = bytes4(
|
||||||
|
keccak256("withdraw(address,uint256,address,uint256,uint256)")
|
||||||
|
);
|
||||||
|
|
||||||
|
for (uint256 i = 0; i < _length; i++) {
|
||||||
|
if (amts[i] > 0) {
|
||||||
|
uint256 _amt = amts[i];
|
||||||
|
address _token = tokens[i];
|
||||||
|
_targets[_cntr] = "BASIC-A";
|
||||||
|
_data[_cntr] = abi.encodeWithSelector(
|
||||||
|
basicWithdraw,
|
||||||
|
tokens[i],
|
||||||
|
_amt,
|
||||||
|
address(this),
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
_tokens[_cntr] = _token;
|
||||||
|
_cntr++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AccountInterface(userAccount).cast(_targets, _data, address(0));
|
||||||
|
for (uint256 i = 0; i < _len; i++) {
|
||||||
|
if (!getIsColl(_tokens[i], address(this))) {
|
||||||
|
aave.setUserUseReserveAsCollateral(
|
||||||
|
_tokens[i],
|
||||||
|
colEnable[i]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,7 @@ contract AaveV3ImportResolver is AaveHelpers {
|
||||||
internal
|
internal
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
{
|
{
|
||||||
if (
|
if (instaList.accountID(userAccount) == 0) {
|
||||||
ListInterface(0x839c2D3aDe63DF5b0b8F3E57D5e145057Ab41556).accountID(
|
|
||||||
userAccount
|
|
||||||
) == 0
|
|
||||||
) {
|
|
||||||
require(
|
require(
|
||||||
AccountInterface(address(this)).isAuth(userAccount),
|
AccountInterface(address(this)).isAuth(userAccount),
|
||||||
"user-account-not-auth"
|
"user-account-not-auth"
|
||||||
|
|
|
||||||
|
|
@ -221,6 +221,7 @@ describe("Import Aave v3 Position", function () {
|
||||||
let dsaWallet1: any;
|
let dsaWallet1: any;
|
||||||
let dsaWallet2: any;
|
let dsaWallet2: any;
|
||||||
let walletB: any;
|
let walletB: any;
|
||||||
|
let walletBsigner: any;
|
||||||
let masterSigner: Signer;
|
let masterSigner: Signer;
|
||||||
let instaConnectorsV2: Contract;
|
let instaConnectorsV2: Contract;
|
||||||
let connector: any;
|
let connector: any;
|
||||||
|
|
@ -325,6 +326,13 @@ describe("Import Aave v3 Position", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should create DSA Aave v3 position of DAI(collateral) and USDC(debt)", async () => {
|
it("Should create DSA Aave v3 position of DAI(collateral) and USDC(debt)", async () => {
|
||||||
|
await hre.network.provider.request({
|
||||||
|
method: "hardhat_impersonateAccount",
|
||||||
|
params: [walletB.address]
|
||||||
|
});
|
||||||
|
|
||||||
|
walletBsigner = await ethers.getSigner(walletB.address);
|
||||||
|
|
||||||
await token.connect(signer).transfer(dsaWallet2.address, ethers.utils.parseEther("10"));
|
await token.connect(signer).transfer(dsaWallet2.address, ethers.utils.parseEther("10"));
|
||||||
console.log(await token.connect(signer).balanceOf(dsaWallet2.address));
|
console.log(await token.connect(signer).balanceOf(dsaWallet2.address));
|
||||||
console.log(dsaWallet1.address);
|
console.log(dsaWallet1.address);
|
||||||
|
|
@ -343,7 +351,7 @@ describe("Import Aave v3 Position", function () {
|
||||||
args: [USDC, parseUnits("3", 6), 2, 0, 0]
|
args: [USDC, parseUnits("3", 6), 2, 0, 0]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
const tx = await dsaWallet2.connect(walletB).cast(...encodeSpells(spells), walletB.address);
|
const tx = await dsaWallet2.connect(walletBsigner).cast(...encodeSpells(spells), walletB.address);
|
||||||
const receipt = await tx.wait();
|
const receipt = await tx.wait();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -351,6 +359,7 @@ describe("Import Aave v3 Position", function () {
|
||||||
expect(await aDai.connect(wallet0).balanceOf(dsaWallet2.address)).to.be.gte(
|
expect(await aDai.connect(wallet0).balanceOf(dsaWallet2.address)).to.be.gte(
|
||||||
new BigNumber(10).multipliedBy(1e18).toString()
|
new BigNumber(10).multipliedBy(1e18).toString()
|
||||||
);
|
);
|
||||||
|
console.log((await aDai.connect(wallet0).balanceOf(dsaWallet2.address)).toString());
|
||||||
|
|
||||||
expect(await usdcToken.connect(wallet0).balanceOf(dsaWallet2.address)).to.be.gte(
|
expect(await usdcToken.connect(wallet0).balanceOf(dsaWallet2.address)).to.be.gte(
|
||||||
new BigNumber(3).multipliedBy(1e6).toString()
|
new BigNumber(3).multipliedBy(1e6).toString()
|
||||||
|
|
@ -395,7 +404,7 @@ describe("Import Aave v3 Position", function () {
|
||||||
|
|
||||||
it("Should check DSA-1 AAVE position", async () => {
|
it("Should check DSA-1 AAVE position", async () => {
|
||||||
expect(await aDai.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte(
|
expect(await aDai.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.gte(
|
||||||
new BigNumber(8).multipliedBy(1e18).toString()
|
new BigNumber(10).multipliedBy(1e18).toString()
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -413,7 +422,7 @@ describe("Import Aave v3 Position", function () {
|
||||||
{
|
{
|
||||||
connector: "AAVE-V3-IMPORT-X",
|
connector: "AAVE-V3-IMPORT-X",
|
||||||
method: "importAave",
|
method: "importAave",
|
||||||
args: [dsaWallet2.address, [[DAI], [USDC], false, [amountB.toFixed(0)]]]
|
args: [dsaWallet2.address, [[DAI], [USDC], false, [amountB.toFixed(0)]]] //dsaWallet2 --> DSA_A DSA with aave position
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
connector: "INSTAPOOL-C",
|
connector: "INSTAPOOL-C",
|
||||||
|
|
@ -429,6 +438,7 @@ describe("Import Aave v3 Position", function () {
|
||||||
args: [USDC, amount0.toString(), 5, encodeFlashcastData(flashSpells), "0x"]
|
args: [USDC, amount0.toString(), 5, encodeFlashcastData(flashSpells), "0x"]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
//merge to dsaWallet1
|
||||||
const tx = await dsaWallet1.connect(wallet0).cast(...encodeSpells(spells), wallet.address);
|
const tx = await dsaWallet1.connect(wallet0).cast(...encodeSpells(spells), wallet.address);
|
||||||
const receipt = await tx.wait();
|
const receipt = await tx.wait();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user