mirror of
https://github.com/Instadapp/dsa-polygon-migration.git
synced 2024-07-29 22:27:58 +00:00
removed deposit & withdraw function
This commit is contained in:
parent
93786f4c8f
commit
818fcfeb13
|
@ -43,92 +43,6 @@ contract MigrateResolver is Helpers, Events {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: change deposit to single token at once as msg.value == amt[i] can lead to double ETH deposit
|
||||
function deposit(address[] calldata tokens, uint[] calldata amts) external payable {
|
||||
uint _length = tokens.length;
|
||||
require(_length == amts.length, "invalid-length");
|
||||
|
||||
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
|
||||
|
||||
uint[] memory _amts = new uint[](_length);
|
||||
|
||||
for (uint256 i = 0; i < _length; i++) {
|
||||
require(isSupportedToken[tokens[i]], "token-not-enabled");
|
||||
uint _amt;
|
||||
bool isMatic = tokens[i] == maticAddr;
|
||||
address _token = isMatic ? wmaticAddr : tokens[i];
|
||||
|
||||
IERC20 tokenContract = IERC20(_token);
|
||||
|
||||
if (isMatic) {
|
||||
require(msg.value == amts[i]);
|
||||
TokenInterface(_token).deposit{value: msg.value}();
|
||||
_amt = msg.value;
|
||||
} else {
|
||||
_amt = amts[i] == uint(-1) ? tokenContract.balanceOf(msg.sender) : amts[i];
|
||||
tokenContract.safeTransferFrom(msg.sender, address(this), _amt);
|
||||
}
|
||||
|
||||
tokenContract.safeApprove(address(aave),_amt);
|
||||
aave.deposit(_token, _amt, address(this), 3288);
|
||||
|
||||
_amts[i] = _amt;
|
||||
|
||||
deposits[msg.sender][_token] += _amt;
|
||||
}
|
||||
|
||||
emit LogDeposit(msg.sender, tokens, _amts);
|
||||
}
|
||||
|
||||
// TODO: change withdraw to single token at once as msg.value == amt[i] can lead to double ETH deposit
|
||||
function withdraw(address[] calldata tokens, uint[] calldata amts) external {
|
||||
uint _length = tokens.length;
|
||||
require(_length == amts.length, "invalid-length");
|
||||
|
||||
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
|
||||
|
||||
uint[] memory _amts = new uint[](_length);
|
||||
|
||||
for (uint256 i = 0; i < _length; i++) {
|
||||
require(isSupportedToken[tokens[i]], "token-not-enabled");
|
||||
uint _amt = amts[i];
|
||||
bool isMatic = tokens[i] == maticAddr;
|
||||
address _token = isMatic ? wmaticAddr : tokens[i];
|
||||
uint maxAmt = deposits[msg.sender][_token];
|
||||
|
||||
if (_amt > maxAmt) {
|
||||
_amt = maxAmt;
|
||||
}
|
||||
|
||||
deposits[msg.sender][_token] = sub(maxAmt, _amt);
|
||||
|
||||
if (isMatic) {
|
||||
TokenInterface _tokenContract = TokenInterface(wmaticAddr);
|
||||
uint _maticBal = address(this).balance;
|
||||
uint _tknBal = _tokenContract.balanceOf(address(this));
|
||||
if ((_maticBal + _tknBal) < _amt) {
|
||||
aave.withdraw(wmaticAddr, sub(_amt, (_tknBal + _maticBal)), address(this));
|
||||
}
|
||||
_tokenContract.withdraw((sub(_amt, _maticBal)));
|
||||
msg.sender.call{value: _amt}("");
|
||||
_amts[i] = _amt;
|
||||
} else {
|
||||
IERC20 _tokenContract = IERC20(_token);
|
||||
uint _tknBal = _tokenContract.balanceOf(address(this));
|
||||
if (_tknBal < _amt) {
|
||||
aave.withdraw(_token, sub(_amt, _tknBal), address(this));
|
||||
}
|
||||
_tokenContract.safeTransfer(msg.sender, _amt);
|
||||
}
|
||||
|
||||
_amts[i] = _amt;
|
||||
}
|
||||
|
||||
isPositionSafe();
|
||||
|
||||
emit LogWithdraw(msg.sender, tokens, _amts);
|
||||
}
|
||||
|
||||
function settle() external {
|
||||
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
|
||||
for (uint i = 0; i < supportedTokens.length; i++) {
|
||||
|
|
|
@ -30,7 +30,6 @@ contract Variables {
|
|||
|
||||
// dsa => position
|
||||
mapping(uint => bytes) public positions;
|
||||
mapping(address => mapping(address => uint)) public deposits;
|
||||
|
||||
// InstaIndex Address.
|
||||
IndexInterface public constant instaIndex = IndexInterface(0xA9B99766E6C676Cf1975c0D3166F96C0848fF5ad);
|
||||
|
|
|
@ -37,13 +37,9 @@ contract Events {
|
|||
);
|
||||
|
||||
event LogAddSupportedTokens(
|
||||
uint256[] tokens
|
||||
address[] tokens
|
||||
);
|
||||
|
||||
event LogAddTokensSupport(address[] _tokens);
|
||||
|
||||
event variablesUpdate(uint _safeRatioGap, uint _fee, bool _depositEnable);
|
||||
|
||||
event settle(address[] tokens, uint[] amts);
|
||||
event LogVariablesUpdate(uint _safeRatioGap, uint _fee);
|
||||
|
||||
}
|
|
@ -11,12 +11,11 @@ import { Events } from "./events.sol";
|
|||
contract LiquidityResolver is Helpers, Events {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
function updateVariables(uint _safeRatioGap, uint _fee, bool _depositEnable) public {
|
||||
function updateVariables(uint _safeRatioGap, uint _fee) public {
|
||||
require(msg.sender == instaIndex.master(), "not-master");
|
||||
safeRatioGap = _safeRatioGap;
|
||||
fee = _fee;
|
||||
isDepositsEnabled = _depositEnable;
|
||||
emit variablesUpdate(safeRatioGap, fee, isDepositsEnabled);
|
||||
emit LogVariablesUpdate(safeRatioGap, fee);
|
||||
}
|
||||
|
||||
function addTokenSupport(address[] memory _tokens) public {
|
||||
|
@ -45,97 +44,6 @@ contract LiquidityResolver is Helpers, Events {
|
|||
}
|
||||
}
|
||||
|
||||
function deposit(address[] calldata tokens, uint[] calldata amts) external payable {
|
||||
require(isDepositsEnabled, "deposit-not-enable");
|
||||
uint _length = tokens.length;
|
||||
require(_length == amts.length, "invalid-length");
|
||||
|
||||
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
|
||||
|
||||
uint[] memory _amts = new uint[](_length);
|
||||
|
||||
for (uint256 i = 0; i < _length; i++) {
|
||||
require(isSupportedToken[tokens[i]], "token-not-enabled");
|
||||
uint _amt;
|
||||
bool isEth = tokens[i] == ethAddr;
|
||||
address _token = isEth ? wethAddr : tokens[i];
|
||||
|
||||
IERC20 tokenContract = IERC20(_token);
|
||||
|
||||
if (isEth) {
|
||||
require(msg.value == amts[i]);
|
||||
TokenInterface(wethAddr).deposit{value: msg.value}();
|
||||
_amt = msg.value;
|
||||
} else {
|
||||
_amt = amts[i] == uint(-1) ? tokenContract.balanceOf(msg.sender) : amts[i];
|
||||
tokenContract.safeTransferFrom(msg.sender, address(this), _amt);
|
||||
}
|
||||
|
||||
tokenContract.safeApprove(address(aave),_amt);
|
||||
aave.deposit(_token, _amt, address(this), 3288);
|
||||
|
||||
_amts[i] = _amt;
|
||||
|
||||
deposits[msg.sender][_token] += _amt;
|
||||
}
|
||||
|
||||
emit LogDeposit(msg.sender, tokens, _amts);
|
||||
}
|
||||
|
||||
function withdraw(address[] calldata tokens, uint[] calldata amts) external {
|
||||
require(isDepositsEnabled, "withdraw-not-enable");
|
||||
uint _length = tokens.length;
|
||||
require(_length == amts.length, "invalid-length");
|
||||
|
||||
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
|
||||
|
||||
uint[] memory _amts = new uint[](_length);
|
||||
|
||||
for (uint256 i = 0; i < _length; i++) {
|
||||
require(isSupportedToken[tokens[i]], "token-not-enabled");
|
||||
uint _amt = amts[i];
|
||||
bool isEth = tokens[i] == ethAddr;
|
||||
address _token = isEth ? wethAddr : tokens[i];
|
||||
uint maxAmt = deposits[msg.sender][_token];
|
||||
|
||||
if (_amt > maxAmt) {
|
||||
_amt = maxAmt;
|
||||
}
|
||||
|
||||
deposits[msg.sender][_token] = sub(maxAmt, _amt);
|
||||
|
||||
if (isEth) {
|
||||
TokenInterface _tokenContract = TokenInterface(wethAddr);
|
||||
uint _ethBal = address(this).balance;
|
||||
uint _tknBal = _tokenContract.balanceOf(address(this));
|
||||
if (_ethBal > _amt) {
|
||||
msg.sender.call{value: _amt}("");
|
||||
_amts[i] = _amt;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((_ethBal + _tknBal) < _amt) {
|
||||
aave.withdraw(wethAddr, sub(_amt, (_tknBal + _ethBal)), address(this));
|
||||
}
|
||||
_tokenContract.withdraw((sub(_amt, _ethBal)));
|
||||
msg.sender.call{value: _amt}("");
|
||||
} else {
|
||||
IERC20 _tokenContract = IERC20(_token);
|
||||
uint _tknBal = _tokenContract.balanceOf(address(this));
|
||||
if (_tknBal < _amt) {
|
||||
aave.withdraw(_token, sub(_amt, _tknBal), address(this));
|
||||
}
|
||||
_tokenContract.safeTransfer(msg.sender, _amt);
|
||||
}
|
||||
|
||||
_amts[i] = _amt;
|
||||
}
|
||||
|
||||
isPositionSafe();
|
||||
|
||||
emit LogWithdraw(msg.sender, tokens, _amts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param _tokens - array of tokens to transfer to L2 receiver's contract
|
||||
* @param _amts - array of token amounts to transfer to L2 receiver's contract
|
||||
|
|
|
@ -71,8 +71,6 @@ contract Variables {
|
|||
*/
|
||||
StateSenderInterface constant internal stateSender = StateSenderInterface(0x28e4F3a7f651294B9564800b2D01f35189A5bFbE);
|
||||
|
||||
mapping(address => mapping(address => uint)) public deposits;
|
||||
bool public isDepositsEnabled;
|
||||
|
||||
// InstaIndex Address.
|
||||
IndexInterface public constant instaIndex = IndexInterface(0x2971AdFa57b20E5a416aE5a708A8655A9c74f723);
|
||||
|
|
Loading…
Reference in New Issue
Block a user