updates, fixes & refactoring

This commit is contained in:
Samyak Jain 2021-04-07 20:58:21 +05:30
parent ac0217de32
commit 9779cd4241
3 changed files with 29 additions and 10 deletions

View File

@ -15,6 +15,10 @@ import {
abstract contract Helpers is DSMath {
using SafeERC20 for IERC20;
// This will be used to have debt/collateral ratio always 20% less than liquidation
// TODO: Is this number correct for it?
uint public safeRatioGap = 200000000000000000; // 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)
@ -36,6 +40,11 @@ abstract contract Helpers is DSMath {
return data;
}
function isPositionSafe() internal returns (bool isOk) {
// TODO: Check the final position health
require(isOk, "position-at-risk");
}
function transferAtokens(address dsa, address[] memory supplyTokens, uint[] memory supplyAmts) internal {
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
for (uint i = 0; i < supplyTokens.length; i++) {

View File

@ -11,13 +11,9 @@ import { Helpers } from "./helpers.sol";
contract MigrateResolver is Helpers, Events {
using SafeERC20 for IERC20;
// This will be used to have debt/collateral ratio always 20% less than liquidation
// TODO: Is this number correct for it?
uint public safeRatioGap = 200000000000000000; // 20%? 2e17
// dsa => position
mapping(uint => bytes) public positions;
mapping(address => mapping(address => uint)) deposits;
mapping(address => mapping(address => uint)) public deposits;
// InstaIndex Address.
IndexInterface public constant instaIndex = IndexInterface(0x2971AdFa57b20E5a416aE5a708A8655A9c74f723);
@ -82,8 +78,19 @@ contract MigrateResolver is Helpers, Events {
_amts[i] = _amt;
}
isPositionSafe();
emit LogWithdraw(msg.sender, tokens, _amts);
}
// TODO: Things to factor
// If there is same token supply and borrow, then close the smaller one
// If there is ideal token then payback or deposit according to the position
// Object is the decrease the ratio and pay as less interest
function settle() external {
}
}
contract AaveV2Migrator is MigrateResolver {
@ -105,7 +112,7 @@ contract AaveV2Migrator is MigrateResolver {
// Have to borrow from user's account
borrowAndTransferSpells(dsa, borrowTokens, borrowAmts);
// TODO: Final position should be 20% less than liquidation (use 'safeRatioGap', Also should we check this at start?)
isPositionSafe();
}
// function getPosition(address owner) public view returns (AaveData memory data) {

View File

@ -106,11 +106,14 @@ contract LiquidityResolver is Helpers, Events {
emit LogWithdraw(msg.sender, tokens, _amts);
}
// TODO: payback if debt else deposit
// TODO: if ratio is safe then transfer excess collateral to L2 migration contract
// TODO: Things to factor
// If there is same token supply and borrow, then close the smaller one
// If there is ideal token then payback or deposit according to the position
// Object is the decrease the ratio and pay as less interest
// If ratio is safe then transfer excess collateral to L2 migration contract
// Always, keep 1000 wei WETH ideal for flashloan
function settle(address[] calldata tokens) external {
function settle() external {
}
}