bug fixes

This commit is contained in:
pradyuman-verma 2022-06-11 02:22:11 +05:30
parent 37e56f0955
commit de1a1a106e
No known key found for this signature in database
GPG Key ID: E36FD6BC8923221F

View File

@ -12,8 +12,8 @@ import { Events } from "./events.sol";
import { IInstaLite } from "./interface.sol"; 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);
/** /**
* @dev Supply ETH/ERC20 * @dev Supply ETH/ERC20
@ -41,7 +41,9 @@ abstract contract InstaLiteConnector is Events, Basic {
if (isEth) { if (isEth) {
_amt = _amt == uint256(-1) ? address(this).balance : _amt; _amt = _amt == uint256(-1) ? address(this).balance : _amt;
vTokenAmt = IInstaLite(vaultAddr).supplyEth{ value: amt }(address(this)); vTokenAmt = IInstaLite(vaultAddr).supplyEth{ value: amt }(
address(this)
);
} else { } else {
TokenInterface tokenContract = TokenInterface(token); TokenInterface tokenContract = TokenInterface(token);
@ -50,7 +52,11 @@ abstract contract InstaLiteConnector is Events, Basic {
: _amt; : _amt;
approve(tokenContract, vaultAddr, _amt); approve(tokenContract, vaultAddr, _amt);
vTokenAmt = IInstaLite(vaultAddr).supply(token, _amt, address(this)); vTokenAmt = IInstaLite(vaultAddr).supply(
token,
_amt,
address(this)
);
} }
setUint(setIds[0], _amt); setUint(setIds[0], _amt);
@ -87,7 +93,7 @@ abstract contract InstaLiteConnector is Events, Basic {
{ {
uint256 _amt = getUint(getId, amt); uint256 _amt = getUint(getId, amt);
uint256 vTokenAmt = IInstaLite(vaultAddr).withdraw(_amt, address(this)); uint256 vTokenAmt = IInstaLite(vaultAddr).withdraw(_amt, address(this));
setUint(setIds[0], _amt); setUint(setIds[0], _amt);
setUint(setIds[1], vTokenAmt); setUint(setIds[1], vTokenAmt);
@ -116,13 +122,13 @@ abstract contract InstaLiteConnector is Events, Basic {
{ {
uint256 _amt = getUint(getId, amt); uint256 _amt = getUint(getId, amt);
uint initialBal = astethToken.balanceOf(address(this)); uint256 initialBal = astethToken.balanceOf(address(this));
approve(TokenInterface(wethAddr), vaultAddr, _amt); approve(TokenInterface(wethAddr), vaultAddr, _amt);
IInstaLite(vaultAddr).deleverage(_amt); IInstaLite(vaultAddr).deleverage(_amt);
uint finalBal = astethToken.balanceOf(address(this)); uint256 finalBal = astethToken.balanceOf(address(this));
require(amt <= (1e9 + finalBal - initialBal), "lack-of-steth"); require(amt <= (1e9 + finalBal - initialBal), "lack-of-steth");
@ -137,54 +143,65 @@ abstract contract InstaLiteConnector is Events, Basic {
* @notice Deleverage Instalite vault. * @notice Deleverage Instalite vault.
* @param vaultAddr Address of vaultAddress Contract. * @param vaultAddr Address of vaultAddress Contract.
* @param deleverageAmount The amount of the token to deleverage. * @param deleverageAmount The amount of the token to deleverage.
* @param withdrawAmount The amount of the token to deleverage. * @param withdrawAmount The amount of the token to deleverage.
* @param getId ID to retrieve amt. * @param getIds ID to retrieve amt.
* @param setId ID to set amt. * @param setIds ID to set amt.
*/ */
function deleverageAndWithdraw( function deleverageAndWithdraw(
address vaultAddr, address vaultAddr,
uint256 deleverageAmount, uint256 deleverageAmount,
uint256 withdrawAmount, uint256 withdrawAmount,
uint256[] memory getIds, uint256[] memory getIds,
uint256[] memory setIds uint256[] memory setIds
) )
external external
payable payable
returns (string memory _eventName, bytes memory _eventParam) returns (string memory _eventName, bytes memory _eventParam)
{ {
if (getIds.length > 2) { require(getIds.length > 2, "invalid get-ids length");
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 = TokenInterface tokenContract = 0xc383a3833A87009fD9597F8184979AF5eDFad019 ==
0xc383a3833A87009fD9597F8184979AF5eDFad019 == vaultAddr ? vaultAddr
TokenInterface(wethAddr) : ? TokenInterface(wethAddr)
TokenInterface(IInstaLite(vaultAddr).token()); : TokenInterface(IInstaLite(vaultAddr).token());
uint initialBalStETH = astethToken.balanceOf(address(this));
uint initialBalToken = tokenContract.balanceOf(address(this));
approve(TokenInterface(wethAddr), vaultAddr, _amt); uint256 initialBalStETH = astethToken.balanceOf(address(this));
uint256 initialBalToken = tokenContract.balanceOf(address(this));
IInstaLite(vaultAddr).deleverageAndWithdraw(_deleverageAmt, _withdrawAmount, address(this)); approve(TokenInterface(wethAddr), vaultAddr, _deleverageAmt);
uint _stETHAmt = astethToken.balanceOf(address(this)) - initialBalStETH; IInstaLite(vaultAddr).deleverageAndWithdraw(
uint _tokenAmt = tokenContract.balanceOf(address(this)) - initialBalToken; _deleverageAmt,
_withdrawAmount,
address(this)
);
uint256 _stETHAmt = astethToken.balanceOf(address(this)) -
initialBalStETH;
uint256 _tokenAmt = tokenContract.balanceOf(address(this)) -
initialBalToken;
// TODO: add require conditions // TODO: add require conditions
if (setIds.length > 2) { if (setIds.length > 2) {
setUint(setIds[0], _stETHAmt); setUint(setIds[0], _stETHAmt);
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[])";
_eventParam = abi.encode(vaultAddr, _deleverageAmt, _withdrawAmount, _stETHAmt, _tokenAmt, getIds, setIds); _eventParam = abi.encode(
vaultAddr,
_deleverageAmt,
_withdrawAmount,
_stETHAmt,
_tokenAmt,
getIds,
setIds
);
} }
} }
contract ConnectV2InstaLite is InstaLiteConnector { contract ConnectV2InstaLite is InstaLiteConnector {
string public constant name = "InstaLite-v1.1"; string public constant name = "InstaLite-v1.1";
} }