mirror of
				https://github.com/Instadapp/dsa-connectors.git
				synced 2024-07-29 22:37:00 +00:00 
			
		
		
		
	added deleverage function in lite
This commit is contained in:
		
							parent
							
								
									373dcf59af
								
							
						
					
					
						commit
						b191ac1710
					
				| 
						 | 
				
			
			@ -2,6 +2,7 @@
 | 
			
		|||
pragma solidity ^0.7.0;
 | 
			
		||||
 | 
			
		||||
interface IInstaLite {
 | 
			
		||||
 | 
			
		||||
	function supplyEth(address to_) external payable returns (uint256);
 | 
			
		||||
 | 
			
		||||
	function supply(
 | 
			
		||||
| 
						 | 
				
			
			@ -11,4 +12,7 @@ interface IInstaLite {
 | 
			
		|||
	) external returns (uint256);
 | 
			
		||||
 | 
			
		||||
	function withdraw(uint256 amount_, address to_) external returns (uint256);
 | 
			
		||||
 | 
			
		||||
	function deleverage(uint amt_) external;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,17 +12,20 @@ import { Events } from "./events.sol";
 | 
			
		|||
import { IInstaLite } from "./interface.sol";
 | 
			
		||||
 | 
			
		||||
abstract contract InstaLiteConnector is Events, Basic {
 | 
			
		||||
 | 
			
		||||
	TokenInterface internal constant astethToken = TokenInterface(0x1982b2F5814301d4e9a8b0201555376e62F82428);
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @dev Supply ETH/ERC20
 | 
			
		||||
	 * @notice Supply a token into Instalite.
 | 
			
		||||
	 * @param vaultAddress Address of instaLite Contract.
 | 
			
		||||
	 * @param vaultAddr Address of instaLite Contract.
 | 
			
		||||
	 * @param token The address of the token to be supplied. (For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
 | 
			
		||||
	 * @param amt The amount of token to be supplied. (For max: `uint256(-1)`)
 | 
			
		||||
	 * @param getId ID to retrieve amt.
 | 
			
		||||
	 * @param setIds array of IDs to store the amount of tokens deposited.
 | 
			
		||||
	 */
 | 
			
		||||
	function supply(
 | 
			
		||||
		address vaultAddress,
 | 
			
		||||
		address vaultAddr,
 | 
			
		||||
		address token,
 | 
			
		||||
		uint256 amt,
 | 
			
		||||
		uint256 getId,
 | 
			
		||||
| 
						 | 
				
			
			@ -36,11 +39,9 @@ abstract contract InstaLiteConnector is Events, Basic {
 | 
			
		|||
		bool isEth = token == ethAddr;
 | 
			
		||||
		uint256 vTokenAmt;
 | 
			
		||||
 | 
			
		||||
		IInstaLite instaLite = IInstaLite(vaultAddress);
 | 
			
		||||
 | 
			
		||||
		if (isEth) {
 | 
			
		||||
			_amt = _amt == uint256(-1) ? address(this).balance : _amt;
 | 
			
		||||
			vTokenAmt = instaLite.supplyEth{ value: amt }(address(this));
 | 
			
		||||
			vTokenAmt = IInstaLite(vaultAddr).supplyEth{ value: amt }(address(this));
 | 
			
		||||
		} else {
 | 
			
		||||
			TokenInterface tokenContract = TokenInterface(token);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -48,8 +49,8 @@ abstract contract InstaLiteConnector is Events, Basic {
 | 
			
		|||
				? tokenContract.balanceOf(address(this))
 | 
			
		||||
				: _amt;
 | 
			
		||||
 | 
			
		||||
			approve(tokenContract, vaultAddress, _amt);
 | 
			
		||||
			vTokenAmt = instaLite.supply(token, _amt, address(this));
 | 
			
		||||
			approve(tokenContract, vaultAddr, _amt);
 | 
			
		||||
			vTokenAmt = IInstaLite(vaultAddr).supply(token, _amt, address(this));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		setUint(setIds[0], _amt);
 | 
			
		||||
| 
						 | 
				
			
			@ -57,7 +58,7 @@ abstract contract InstaLiteConnector is Events, Basic {
 | 
			
		|||
 | 
			
		||||
		_eventName = "LogSupply(address,address,uint256,uint256,uint256,uint256[])";
 | 
			
		||||
		_eventParam = abi.encode(
 | 
			
		||||
			vaultAddress,
 | 
			
		||||
			vaultAddr,
 | 
			
		||||
			token,
 | 
			
		||||
			vTokenAmt,
 | 
			
		||||
			_amt,
 | 
			
		||||
| 
						 | 
				
			
			@ -69,13 +70,13 @@ abstract contract InstaLiteConnector is Events, Basic {
 | 
			
		|||
	/**
 | 
			
		||||
	 * @dev Withdraw ETH/ERC20
 | 
			
		||||
	 * @notice Withdraw deposited tokens from Instalite.
 | 
			
		||||
	 * @param vaultAddress Address of vaultAddress Contract.
 | 
			
		||||
	 * @param vaultAddr Address of vaultAddress Contract.
 | 
			
		||||
	 * @param amt The amount of the token to withdraw.
 | 
			
		||||
	 * @param getId ID to retrieve amt.
 | 
			
		||||
	 * @param setIds array of IDs to stores the amount of tokens withdrawn.
 | 
			
		||||
	 */
 | 
			
		||||
	function withdraw(
 | 
			
		||||
		address vaultAddress,
 | 
			
		||||
		address vaultAddr,
 | 
			
		||||
		uint256 amt,
 | 
			
		||||
		uint256 getId,
 | 
			
		||||
		uint256[] memory setIds
 | 
			
		||||
| 
						 | 
				
			
			@ -86,15 +87,49 @@ abstract contract InstaLiteConnector is Events, Basic {
 | 
			
		|||
	{
 | 
			
		||||
		uint256 _amt = getUint(getId, amt);
 | 
			
		||||
 | 
			
		||||
		IInstaLite instaLite = IInstaLite(vaultAddress);
 | 
			
		||||
 | 
			
		||||
		uint256 vTokenAmt = instaLite.withdraw(_amt, address(this));
 | 
			
		||||
		uint256 vTokenAmt =  IInstaLite(vaultAddr).withdraw(_amt, address(this));
 | 
			
		||||
 | 
			
		||||
		setUint(setIds[0], _amt);
 | 
			
		||||
		setUint(setIds[1], vTokenAmt);
 | 
			
		||||
 | 
			
		||||
		_eventName = "LogWithdraw(address,uint256,uint256,uint256,uint256[])";
 | 
			
		||||
		_eventParam = abi.encode(vaultAddress, _amt, vTokenAmt, getId, setIds);
 | 
			
		||||
		_eventParam = abi.encode(vaultAddr, _amt, vTokenAmt, getId, setIds);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @dev Withdraw ETH/ERC20
 | 
			
		||||
	 * @notice Withdraw deposited tokens from Instalite.
 | 
			
		||||
	 * @param vaultAddr The amount of the token to withdraw.
 | 
			
		||||
	 * @param amt The amount of the token to withdraw.
 | 
			
		||||
	 * @param getId ID to retrieve amt.
 | 
			
		||||
	 * @param setId ID to retrieve amt.
 | 
			
		||||
	 */
 | 
			
		||||
	function deleverage(
 | 
			
		||||
		address vaultAddr,
 | 
			
		||||
		uint256 amt,
 | 
			
		||||
		uint256 getId,
 | 
			
		||||
		uint256 setId
 | 
			
		||||
	)
 | 
			
		||||
		external
 | 
			
		||||
		payable
 | 
			
		||||
		returns (string memory _eventName, bytes memory _eventParam)
 | 
			
		||||
	{
 | 
			
		||||
		uint256 _amt = getUint(getId, amt);
 | 
			
		||||
 | 
			
		||||
		uint initialBal = astethToken.balanceOf(address(this));
 | 
			
		||||
 | 
			
		||||
		approve(TokenInterface(wethAddr), vaultAddr, _amt);
 | 
			
		||||
 | 
			
		||||
		IInstaLite(vaultAddr).deleverage(_amt);
 | 
			
		||||
 | 
			
		||||
		uint finalBal = astethToken.balanceOf(address(this));
 | 
			
		||||
 | 
			
		||||
		require(amt <= (finalBal - initialBal), "lack-of-steth");
 | 
			
		||||
 | 
			
		||||
		setUint(setId, _amt);
 | 
			
		||||
 | 
			
		||||
		_eventName = "LogDeleverage(address,uint256,uint256,uint256)";
 | 
			
		||||
		_eventParam = abi.encode(vaultAddr, _amt, getId, setId);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user