mirror of
https://github.com/Instadapp/dsa-polygon-migration.git
synced 2024-07-29 22:27:58 +00:00
Merge branch 'new-tests' of https://github.com/Instadapp/dsa-polygon-migration into new-tests
This commit is contained in:
commit
e33001c82f
|
@ -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) {
|
||||||
|
@ -76,16 +72,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
|
||||||
|
@ -103,10 +89,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,12 +101,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
|
||||||
|
@ -156,12 +132,8 @@ abstract contract Helpers is Stores, DSMath, Variables {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.isFlash) {
|
targets[spellsAmt] = "BASIC-A"; // TODO: right spell?
|
||||||
aave.withdraw(data.token, data.flashAmt, address(this));
|
castData[spellsAmt] = abi.encodeWithSignature("withdraw(address,uint256,address,uint256,uint256)", data.atoken, data.borrowAmt, address(this), 0, 0); // encode the data of atoken withdrawal
|
||||||
}
|
|
||||||
|
|
||||||
targets[spellsAmt - 1] = "BASIC-A"; // TODO: right spell?
|
|
||||||
castData[spellsAmt - 1] = abi.encodeWithSignature("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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,10 @@ contract MigrateResolver is Helpers, Events {
|
||||||
|
|
||||||
function addTokenSupport(address[] memory _tokens) public {
|
function addTokenSupport(address[] memory _tokens) public {
|
||||||
require(msg.sender == instaIndex.master(), "not-master");
|
require(msg.sender == instaIndex.master(), "not-master");
|
||||||
|
for (uint i = 0; i < supportedTokens.length; i++) {
|
||||||
|
delete isSupportedToken[supportedTokens[i]];
|
||||||
|
}
|
||||||
|
delete supportedTokens;
|
||||||
for (uint i = 0; i < _tokens.length; i++) {
|
for (uint i = 0; i < _tokens.length; i++) {
|
||||||
require(!isSupportedToken[_tokens[i]], "already-added");
|
require(!isSupportedToken[_tokens[i]], "already-added");
|
||||||
isSupportedToken[_tokens[i]] = true;
|
isSupportedToken[_tokens[i]] = true;
|
||||||
|
@ -66,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));
|
||||||
}
|
}
|
||||||
|
@ -108,6 +112,8 @@ contract AaveV2Migrator is MigrateResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
function onStateReceive(uint256 stateId, bytes calldata receivedData) external {
|
function onStateReceive(uint256 stateId, bytes calldata receivedData) external {
|
||||||
|
// Add some more require statements. Any kind of hashing for better privacy?
|
||||||
|
require(msg.sender == maticReceiver, "not-receiver-address");
|
||||||
require(stateId > lastStateId, "wrong-data");
|
require(stateId > lastStateId, "wrong-data");
|
||||||
lastStateId = stateId;
|
lastStateId = stateId;
|
||||||
|
|
||||||
|
|
|
@ -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(0xa31442F2607947a88807b2bcD5D4951eEdd4A885)); // TODO: FAKE ADDR, CHANGE THIS
|
TokenMappingInterface tokenMapping = TokenMappingInterface(address(0xa31442F2607947a88807b2bcD5D4951eEdd4A885)); // TODO: FAKE ADDR, CHANGE THIS
|
||||||
|
|
||||||
|
@ -36,6 +32,9 @@ contract Variables {
|
||||||
|
|
||||||
// TODO: Set by construtor?
|
// TODO: Set by construtor?
|
||||||
mapping(address => bool) public isSupportedToken;
|
mapping(address => bool) public isSupportedToken;
|
||||||
address[] public supportedTokens;
|
address[] public supportedTokens; // don't add maticAddr. Only add wmaticAddr?
|
||||||
|
|
||||||
|
// Address which will receive L1 data and post it on L2
|
||||||
|
address public maticReceiver = address(0); // TODO: Change address
|
||||||
|
|
||||||
}
|
}
|
|
@ -20,6 +20,10 @@ contract LiquidityResolver is Helpers, Events {
|
||||||
|
|
||||||
function addTokenSupport(address[] memory _tokens) public {
|
function addTokenSupport(address[] memory _tokens) public {
|
||||||
require(msg.sender == instaIndex.master(), "not-master");
|
require(msg.sender == instaIndex.master(), "not-master");
|
||||||
|
for (uint i = 0; i < supportedTokens.length; i++) {
|
||||||
|
delete isSupportedToken[supportedTokens[i]];
|
||||||
|
}
|
||||||
|
delete supportedTokens;
|
||||||
for (uint i = 0; i < _tokens.length; i++) {
|
for (uint i = 0; i < _tokens.length; i++) {
|
||||||
require(!isSupportedToken[_tokens[i]], "already-added");
|
require(!isSupportedToken[_tokens[i]], "already-added");
|
||||||
isSupportedToken[_tokens[i]] = true;
|
isSupportedToken[_tokens[i]] = true;
|
||||||
|
@ -53,8 +57,7 @@ contract LiquidityResolver is Helpers, Events {
|
||||||
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
|
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
|
||||||
for (uint i = 0; i < supportedTokens.length; i++) {
|
for (uint i = 0; i < supportedTokens.length; i++) {
|
||||||
address _token = supportedTokens[i];
|
address _token = supportedTokens[i];
|
||||||
if (_token == ethAddr) {
|
if (_token == wethAddr) {
|
||||||
_token = wethAddr;
|
|
||||||
if (address(this).balance > 0) {
|
if (address(this).balance > 0) {
|
||||||
TokenInterface(wethAddr).deposit{value: address(this).balance}();
|
TokenInterface(wethAddr).deposit{value: address(this).balance}();
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ contract Variables {
|
||||||
uint public fee = 998000000000000000; // 0.2% (99.8%) on collateral? TODO: Is this right?
|
uint public fee = 998000000000000000; // 0.2% (99.8%) on collateral? TODO: Is this right?
|
||||||
// TODO: Set by construtor?
|
// TODO: Set by construtor?
|
||||||
mapping(address => bool) public isSupportedToken;
|
mapping(address => bool) public isSupportedToken;
|
||||||
address[] public supportedTokens;
|
address[] public supportedTokens; // don't add ethAddr. Only add wethAddr
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Aave Provider
|
* @dev Aave Provider
|
||||||
|
|
Loading…
Reference in New Issue
Block a user