mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
bug fixes
This commit is contained in:
parent
f4314f5589
commit
64569a7185
|
@ -2,7 +2,6 @@
|
||||||
pragma solidity ^0.7.0;
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
interface IInstaLite {
|
interface IInstaLite {
|
||||||
|
|
||||||
function supplyEth(address to_) external payable returns (uint256);
|
function supplyEth(address to_) external payable returns (uint256);
|
||||||
|
|
||||||
function supply(
|
function supply(
|
||||||
|
@ -13,12 +12,13 @@ interface IInstaLite {
|
||||||
|
|
||||||
function withdraw(uint256 amount_, address to_) external returns (uint256);
|
function withdraw(uint256 amount_, address to_) external returns (uint256);
|
||||||
|
|
||||||
function deleverage(uint amt_) external;
|
function deleverage(uint256 amt_) external;
|
||||||
|
|
||||||
function deleverageAndWithdraw(
|
function deleverageAndWithdraw(
|
||||||
uint256 deleverageAmt_,
|
uint256 deleverageAmt_,
|
||||||
uint256 withdrawAmount_,
|
uint256 withdrawAmount_,
|
||||||
address to_
|
address to_
|
||||||
) external;
|
) external;
|
||||||
function token() external returns(address);
|
|
||||||
|
|
||||||
|
function token() external returns (address);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,10 @@ import { IInstaLite } from "./interface.sol";
|
||||||
abstract contract InstaLiteConnector is Events, Basic {
|
abstract contract InstaLiteConnector is Events, Basic {
|
||||||
TokenInterface internal constant astethToken =
|
TokenInterface internal constant astethToken =
|
||||||
TokenInterface(0x1982b2F5814301d4e9a8b0201555376e62F82428);
|
TokenInterface(0x1982b2F5814301d4e9a8b0201555376e62F82428);
|
||||||
|
TokenInterface internal constant stethToken =
|
||||||
|
TokenInterface(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
|
||||||
|
address internal constant ethVaultAddr =
|
||||||
|
0xc383a3833a87009fd9597f8184979af5edfad019;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Supply ETH/ERC20
|
* @dev Supply ETH/ERC20
|
||||||
|
@ -59,8 +63,10 @@ abstract contract InstaLiteConnector is Events, Basic {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (setIds.length >= 2) {
|
||||||
setUint(setIds[0], _amt);
|
setUint(setIds[0], _amt);
|
||||||
setUint(setIds[1], vTokenAmt);
|
setUint(setIds[1], vTokenAmt);
|
||||||
|
}
|
||||||
|
|
||||||
_eventName = "LogSupply(address,address,uint256,uint256,uint256,uint256[])";
|
_eventName = "LogSupply(address,address,uint256,uint256,uint256,uint256[])";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
|
@ -95,8 +101,10 @@ abstract contract InstaLiteConnector is Events, Basic {
|
||||||
|
|
||||||
uint256 vTokenAmt = IInstaLite(vaultAddr).withdraw(_amt, address(this));
|
uint256 vTokenAmt = IInstaLite(vaultAddr).withdraw(_amt, address(this));
|
||||||
|
|
||||||
|
if (setIds.length >= 2) {
|
||||||
setUint(setIds[0], _amt);
|
setUint(setIds[0], _amt);
|
||||||
setUint(setIds[1], vTokenAmt);
|
setUint(setIds[1], vTokenAmt);
|
||||||
|
}
|
||||||
|
|
||||||
_eventName = "LogWithdraw(address,uint256,uint256,uint256,uint256[])";
|
_eventName = "LogWithdraw(address,uint256,uint256,uint256,uint256[])";
|
||||||
_eventParam = abi.encode(vaultAddr, _amt, vTokenAmt, getId, setIds);
|
_eventParam = abi.encode(vaultAddr, _amt, vTokenAmt, getId, setIds);
|
||||||
|
@ -162,15 +170,16 @@ abstract contract InstaLiteConnector is Events, Basic {
|
||||||
uint256 _deleverageAmt = getUint(getIds[0], deleverageAmount);
|
uint256 _deleverageAmt = getUint(getIds[0], deleverageAmount);
|
||||||
uint256 _withdrawAmount = getUint(getIds[1], withdrawAmount);
|
uint256 _withdrawAmount = getUint(getIds[1], withdrawAmount);
|
||||||
|
|
||||||
TokenInterface tokenContract = 0xc383a3833A87009fD9597F8184979AF5eDFad019 ==
|
uint256 _astethAmt;
|
||||||
vaultAddr
|
uint256 _ethAmt;
|
||||||
? TokenInterface(wethAddr)
|
uint256 _stethAmt;
|
||||||
: TokenInterface(IInstaLite(vaultAddr).token());
|
uint256 _tokenAmt;
|
||||||
|
|
||||||
uint256 initialBalStETH = astethToken.balanceOf(address(this));
|
|
||||||
uint256 initialBalToken = tokenContract.balanceOf(address(this));
|
|
||||||
|
|
||||||
approve(TokenInterface(wethAddr), vaultAddr, _deleverageAmt);
|
approve(TokenInterface(wethAddr), vaultAddr, _deleverageAmt);
|
||||||
|
if (vaultAddr == ethVaultAddr) {
|
||||||
|
uint256 initialBalAsteth = astethToken.balanceOf(address(this));
|
||||||
|
uint256 initialBalEth = address(this).balance;
|
||||||
|
uint256 initialBalSteth = stethToken.balanceOf(address(this));
|
||||||
|
|
||||||
IInstaLite(vaultAddr).deleverageAndWithdraw(
|
IInstaLite(vaultAddr).deleverageAndWithdraw(
|
||||||
_deleverageAmt,
|
_deleverageAmt,
|
||||||
|
@ -178,24 +187,52 @@ abstract contract InstaLiteConnector is Events, Basic {
|
||||||
address(this)
|
address(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
uint256 _stETHAmt = astethToken.balanceOf(address(this)) -
|
_astethAmt = astethToken.balanceOf(address(this)) -
|
||||||
initialBalStETH;
|
initialBalStETH;
|
||||||
uint256 _tokenAmt = tokenContract.balanceOf(address(this)) -
|
_ethAmt = address(this).balance - initialBalEth;
|
||||||
initialBalToken;
|
_stethAmt = stethToken.balanceOf(address(this));
|
||||||
|
require(_deleverageAmt <= (1e9 + _astethAmt), "lack-of-steth");
|
||||||
|
|
||||||
|
if (setIds.length >= 3) {
|
||||||
|
setUint(setIds[0], _astethAmt);
|
||||||
|
setUint(setIds[1], _ethAmt);
|
||||||
|
setUint(setIds[2], _stethAmt);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
TokenInterface tokenContract = TokenInterface(
|
||||||
|
IInstaLite(vaultAddr).token()
|
||||||
|
);
|
||||||
|
|
||||||
|
uint256 initialBalAsteth = astethToken.balanceOf(address(this));
|
||||||
|
uint256 initialBalToken = tokenContract.balanceOf(address(this));
|
||||||
|
|
||||||
|
IInstaLite(vaultAddr).deleverageAndWithdraw(
|
||||||
|
_deleverageAmt,
|
||||||
|
_withdrawAmount,
|
||||||
|
address(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
_astethAmt = astethToken.balanceOf(address(this)) -
|
||||||
|
initialBalAsteth;
|
||||||
|
_tokenAmt = tokenContract.balanceOf(address(this)) -
|
||||||
|
initialBalToken;
|
||||||
|
require(_deleverageAmt <= (1e9 + _astethAmt), "lack-of-steth");
|
||||||
|
|
||||||
// TODO: add require conditions
|
|
||||||
if (setIds.length >= 2) {
|
if (setIds.length >= 2) {
|
||||||
setUint(setIds[0], _stETHAmt);
|
setUint(setIds[0], _astethAmt);
|
||||||
setUint(setIds[1], _tokenAmt);
|
setUint(setIds[1], _tokenAmt);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_eventName = "LogDeleverageAndWithdraw(address,uint256,uint256,uint256,uint256,uint256[],uint256[])";
|
_eventName = "LogDeleverageAndWithdraw(address,uint256,uint256,uint256,uint256,uint256,uint256,uint256[],uint256[])";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
vaultAddr,
|
vaultAddr,
|
||||||
_deleverageAmt,
|
_deleverageAmt,
|
||||||
_withdrawAmount,
|
_withdrawAmount,
|
||||||
_stETHAmt,
|
_astethAmt;
|
||||||
_tokenAmt,
|
_ethAmt;
|
||||||
|
_stethAmt;
|
||||||
|
_tokenAmt;
|
||||||
getIds,
|
getIds,
|
||||||
setIds
|
setIds
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user