mirror of
https://github.com/Instadapp/dsa-polygon-migration.git
synced 2024-07-29 22:27:58 +00:00
removed flash loan on L2
This commit is contained in:
parent
e31032a3d3
commit
777a98ef56
|
@ -23,9 +23,7 @@ abstract contract Helpers is Stores, DSMath, Variables {
|
||||||
address atoken;
|
address atoken;
|
||||||
uint atokenBal;
|
uint atokenBal;
|
||||||
uint supplyAmt;
|
uint supplyAmt;
|
||||||
uint flashAmt;
|
|
||||||
uint tokenLiq;
|
uint tokenLiq;
|
||||||
bool isFlash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SpellHelperData {
|
struct SpellHelperData {
|
||||||
|
@ -33,8 +31,6 @@ abstract contract Helpers is Stores, DSMath, Variables {
|
||||||
address atoken;
|
address atoken;
|
||||||
uint tokenLiq;
|
uint tokenLiq;
|
||||||
uint borrowAmt;
|
uint borrowAmt;
|
||||||
uint flashAmt;
|
|
||||||
bool isFlash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function remapTokens(AaveData memory data) internal view returns (AaveData memory) {
|
function remapTokens(AaveData memory data) internal view returns (AaveData memory) {
|
||||||
|
@ -71,16 +67,6 @@ abstract contract Helpers is Stores, DSMath, Variables {
|
||||||
|
|
||||||
if (data.atokenBal < data.supplyAmt) {
|
if (data.atokenBal < data.supplyAmt) {
|
||||||
uint _reqAmt = data.supplyAmt - data.atokenBal;
|
uint _reqAmt = data.supplyAmt - data.atokenBal;
|
||||||
if (data.tokenLiq < _reqAmt) {
|
|
||||||
data.flashAmt = flashAmts[data.token];
|
|
||||||
if (data.flashAmt > 0) {
|
|
||||||
_tokenContract.approve(address(aave), data.flashAmt);
|
|
||||||
aave.deposit(data.token, data.flashAmt, address(this), 3288); // TODO: what is our ID on Polygon?
|
|
||||||
data.tokenLiq += data.flashAmt;
|
|
||||||
data.isFlash = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint num = _reqAmt/data.tokenLiq + 1; // TODO: Is this right
|
uint num = _reqAmt/data.tokenLiq + 1; // TODO: Is this right
|
||||||
uint splitAmt = _reqAmt/num; // TODO: Check decimal
|
uint splitAmt = _reqAmt/num; // TODO: Check decimal
|
||||||
uint finalSplit = _reqAmt - (splitAmt * (num - 1)); // TODO: to resolve upper decimal error
|
uint finalSplit = _reqAmt - (splitAmt * (num - 1)); // TODO: to resolve upper decimal error
|
||||||
|
@ -97,10 +83,6 @@ abstract contract Helpers is Stores, DSMath, Variables {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.isFlash) {
|
|
||||||
aave.withdraw(data.token, data.flashAmt, address(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
_atokenContract.safeTransfer(dsa, data.supplyAmt);
|
_atokenContract.safeTransfer(dsa, data.supplyAmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,12 +95,6 @@ abstract contract Helpers is Stores, DSMath, Variables {
|
||||||
(data.tokenLiq,,,,,,,,,) = aaveData.getReserveData(data.token);
|
(data.tokenLiq,,,,,,,,,) = aaveData.getReserveData(data.token);
|
||||||
data.borrowAmt = borrowAmts[i];
|
data.borrowAmt = borrowAmts[i];
|
||||||
|
|
||||||
if (data.tokenLiq < data.borrowAmt) {
|
|
||||||
data.flashAmt = flashAmts[data.token];
|
|
||||||
aave.deposit(data.token, data.flashAmt, address(this), 3288); // TODO: what is our ID on Polygon?
|
|
||||||
data.isFlash = true;
|
|
||||||
data.tokenLiq += data.flashAmt;
|
|
||||||
}
|
|
||||||
// TODO: Check number of loops needed. Borrow and supply on user's account.
|
// TODO: Check number of loops needed. Borrow and supply on user's account.
|
||||||
uint num = data.borrowAmt/data.tokenLiq + 1; // TODO: Is this right
|
uint num = data.borrowAmt/data.tokenLiq + 1; // TODO: Is this right
|
||||||
uint splitAmt = data.borrowAmt/num; // TODO: Check decimal
|
uint splitAmt = data.borrowAmt/num; // TODO: Check decimal
|
||||||
|
@ -142,10 +118,6 @@ abstract contract Helpers is Stores, DSMath, Variables {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.isFlash) {
|
|
||||||
aave.withdraw(data.token, data.flashAmt, address(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
targets[spellsAmt] = "BASIC-A"; // TODO: right spell?
|
targets[spellsAmt] = "BASIC-A"; // TODO: right spell?
|
||||||
castData[spellsAmt] = abi.encode("withdraw(address,uint256,address,uint256,uint256)", data.atoken, data.borrowAmt, address(this), 0, 0); // encode the data of atoken withdrawal
|
castData[spellsAmt] = abi.encode("withdraw(address,uint256,address,uint256,uint256)", data.atoken, data.borrowAmt, address(this), 0, 0); // encode the data of atoken withdrawal
|
||||||
AccountInterface(dsa).castMigrate(targets, castData, address(this));
|
AccountInterface(dsa).castMigrate(targets, castData, address(this));
|
||||||
|
|
|
@ -70,11 +70,11 @@ contract MigrateResolver is Helpers, Events {
|
||||||
) = aaveData.getUserReserveData(_token, address(this));
|
) = aaveData.getUserReserveData(_token, address(this));
|
||||||
if (supplyBal != 0 && borrowBal != 0) {
|
if (supplyBal != 0 && borrowBal != 0) {
|
||||||
if (supplyBal > borrowBal) {
|
if (supplyBal > borrowBal) {
|
||||||
aave.withdraw(_token, (borrowBal + flashAmts[_token]), address(this)); // TODO: fail because of not enough withdrawing capacity?
|
aave.withdraw(_token, borrowBal, address(this)); // TODO: fail because of not enough withdrawing capacity?
|
||||||
IERC20(_token).approve(address(aave), borrowBal);
|
IERC20(_token).approve(address(aave), borrowBal);
|
||||||
aave.repay(_token, borrowBal, 2, address(this));
|
aave.repay(_token, borrowBal, 2, address(this));
|
||||||
} else {
|
} else {
|
||||||
aave.withdraw(_token, (supplyBal + flashAmts[_token]), address(this)); // TODO: fail because of not enough withdrawing capacity?
|
aave.withdraw(_token, supplyBal, address(this)); // TODO: fail because of not enough withdrawing capacity?
|
||||||
IERC20(_token).approve(address(aave), supplyBal);
|
IERC20(_token).approve(address(aave), supplyBal);
|
||||||
aave.repay(_token, supplyBal, 2, address(this));
|
aave.repay(_token, supplyBal, 2, address(this));
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,6 @@ contract Variables {
|
||||||
// TODO: Is this number correct for it?
|
// TODO: Is this number correct for it?
|
||||||
uint public safeRatioGap = 800000000000000000; // 20%? 2e17
|
uint public safeRatioGap = 800000000000000000; // 20%? 2e17
|
||||||
|
|
||||||
// TODO: Add function for flash deposits and withdraw
|
|
||||||
mapping(address => mapping(address => uint)) flashDeposits; // Flash deposits of particular token
|
|
||||||
mapping(address => uint) flashAmts; // token amount for flashloan usage (these token will always stay raw in this contract)
|
|
||||||
|
|
||||||
// TODO: Replace this
|
// TODO: Replace this
|
||||||
TokenMappingInterface tokenMapping = TokenMappingInterface(address(2));
|
TokenMappingInterface tokenMapping = TokenMappingInterface(address(2));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user