mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Merge pull request #229 from Instadapp/lite-deleverageAndWithdraw
Added lite deleverageAndWithdraw function
This commit is contained in:
commit
c25928b5aa
contracts/mainnet/connectors/instaLite
|
@ -24,4 +24,14 @@ contract Events {
|
|||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogDeleverageAndWithdraw(
|
||||
address vaultAddr,
|
||||
uint256 deleverageAmt,
|
||||
uint256 withdrawAmount,
|
||||
uint256 stETHAmt,
|
||||
uint256 tokenAmt,
|
||||
uint256[] getIds,
|
||||
uint256[] setIds
|
||||
);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
interface IInstaLite {
|
||||
|
||||
function supplyEth(address to_) external payable returns (uint256);
|
||||
|
||||
function supply(
|
||||
|
@ -13,6 +12,13 @@ interface IInstaLite {
|
|||
|
||||
function withdraw(uint256 amount_, address to_) external returns (uint256);
|
||||
|
||||
function deleverage(uint amt_) external;
|
||||
function deleverage(uint256 amt_) external;
|
||||
|
||||
function deleverageAndWithdraw(
|
||||
uint256 deleverageAmt_,
|
||||
uint256 withdrawAmount_,
|
||||
address to_
|
||||
) external;
|
||||
|
||||
function token() external view returns (address);
|
||||
}
|
||||
|
|
|
@ -12,8 +12,12 @@ import { Events } from "./events.sol";
|
|||
import { IInstaLite } from "./interface.sol";
|
||||
|
||||
abstract contract InstaLiteConnector is Events, Basic {
|
||||
|
||||
TokenInterface internal constant astethToken = TokenInterface(0x1982b2F5814301d4e9a8b0201555376e62F82428);
|
||||
TokenInterface internal constant astethToken =
|
||||
TokenInterface(0x1982b2F5814301d4e9a8b0201555376e62F82428);
|
||||
TokenInterface internal constant stethToken =
|
||||
TokenInterface(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
|
||||
address internal constant ethVaultAddr =
|
||||
0xc383a3833A87009fD9597F8184979AF5eDFad019;
|
||||
|
||||
/**
|
||||
* @dev Supply ETH/ERC20
|
||||
|
@ -41,7 +45,9 @@ abstract contract InstaLiteConnector is Events, Basic {
|
|||
|
||||
if (isEth) {
|
||||
_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 {
|
||||
TokenInterface tokenContract = TokenInterface(token);
|
||||
|
||||
|
@ -50,11 +56,17 @@ abstract contract InstaLiteConnector is Events, Basic {
|
|||
: _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[1], vTokenAmt);
|
||||
if (setIds.length >= 2) {
|
||||
setUint(setIds[0], _amt);
|
||||
setUint(setIds[1], vTokenAmt);
|
||||
}
|
||||
|
||||
_eventName = "LogSupply(address,address,uint256,uint256,uint256,uint256[])";
|
||||
_eventParam = abi.encode(
|
||||
|
@ -87,10 +99,12 @@ abstract contract InstaLiteConnector is Events, Basic {
|
|||
{
|
||||
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[1], vTokenAmt);
|
||||
if (setIds.length >= 2) {
|
||||
setUint(setIds[0], _amt);
|
||||
setUint(setIds[1], vTokenAmt);
|
||||
}
|
||||
|
||||
_eventName = "LogWithdraw(address,uint256,uint256,uint256,uint256[])";
|
||||
_eventParam = abi.encode(vaultAddr, _amt, vTokenAmt, getId, setIds);
|
||||
|
@ -116,13 +130,13 @@ abstract contract InstaLiteConnector is Events, Basic {
|
|||
{
|
||||
uint256 _amt = getUint(getId, amt);
|
||||
|
||||
uint initialBal = astethToken.balanceOf(address(this));
|
||||
uint256 initialBal = astethToken.balanceOf(address(this));
|
||||
|
||||
approve(TokenInterface(wethAddr), vaultAddr, _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");
|
||||
|
||||
|
@ -132,8 +146,103 @@ abstract contract InstaLiteConnector is Events, Basic {
|
|||
_eventParam = abi.encode(vaultAddr, _amt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Deleverage and Withdraw vault. Pays back weth debt and gets steth collateral (aSteth).
|
||||
* @notice Deleverage Instalite vault.
|
||||
* @param vaultAddr Address of vaultAddress Contract.
|
||||
* @param deleverageAmt The amount of the weth to deleverage.
|
||||
* @param withdrawAmt The amount of the token to withdraw.
|
||||
* @param getIds IDs to retrieve amts.
|
||||
* @param setIds IDs to set amts.
|
||||
*/
|
||||
function deleverageAndWithdraw(
|
||||
address vaultAddr,
|
||||
uint256 deleverageAmt,
|
||||
uint256 withdrawAmt,
|
||||
uint256[] memory getIds,
|
||||
uint256[] memory setIds
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
if (getIds.length >= 2) {
|
||||
deleverageAmt = getUint(getIds[0], deleverageAmt);
|
||||
withdrawAmt = getUint(getIds[1], withdrawAmt);
|
||||
}
|
||||
|
||||
uint256 _astethAmt;
|
||||
uint256 _ethAmt;
|
||||
uint256 _stethAmt;
|
||||
uint256 _tokenAmt;
|
||||
|
||||
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(
|
||||
deleverageAmt,
|
||||
withdrawAmt,
|
||||
address(this)
|
||||
);
|
||||
|
||||
_astethAmt =
|
||||
astethToken.balanceOf(address(this)) -
|
||||
initialBalAsteth;
|
||||
_ethAmt = address(this).balance - initialBalEth;
|
||||
_stethAmt = stethToken.balanceOf(address(this)) - initialBalSteth;
|
||||
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,
|
||||
withdrawAmt,
|
||||
address(this)
|
||||
);
|
||||
|
||||
_astethAmt =
|
||||
astethToken.balanceOf(address(this)) -
|
||||
initialBalAsteth;
|
||||
_tokenAmt =
|
||||
tokenContract.balanceOf(address(this)) -
|
||||
initialBalToken;
|
||||
require(deleverageAmt <= (1e9 + _astethAmt), "lack-of-steth");
|
||||
|
||||
if (setIds.length >= 2) {
|
||||
setUint(setIds[0], _astethAmt);
|
||||
setUint(setIds[1], _tokenAmt);
|
||||
}
|
||||
}
|
||||
|
||||
_eventName = "LogDeleverageAndWithdraw(address,uint256,uint256,uint256,uint256,uint256,uint256,uint256[],uint256[])";
|
||||
_eventParam = abi.encode(
|
||||
vaultAddr,
|
||||
deleverageAmt,
|
||||
withdrawAmt,
|
||||
_astethAmt,
|
||||
_ethAmt,
|
||||
_stethAmt,
|
||||
_tokenAmt,
|
||||
getIds,
|
||||
setIds
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2InstaLite is InstaLiteConnector {
|
||||
string public constant name = "InstaLite-v1";
|
||||
string public constant name = "InstaLite-v1.1";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user