dsa-connectors/contracts/mainnet/connectors/instaLite/main.sol

140 lines
3.7 KiB
Solidity
Raw Normal View History

2022-04-01 17:03:30 +00:00
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
/**
* @title InstaLite Connector
2022-04-06 02:32:56 +00:00
* @dev Supply, Withdraw & Deleverage
2022-04-01 17:03:30 +00:00
*/
2022-04-06 02:32:56 +00:00
2022-04-02 18:24:00 +00:00
import { TokenInterface } from "../../common/interfaces.sol";
import { Basic } from "../../common/basic.sol";
2022-04-01 17:03:30 +00:00
import { Events } from "./events.sol";
2022-04-02 18:32:38 +00:00
import { IInstaLite } from "./interface.sol";
2022-04-01 17:03:30 +00:00
2022-04-02 17:11:33 +00:00
abstract contract InstaLiteConnector is Events, Basic {
2022-04-06 02:27:57 +00:00
TokenInterface internal constant astethToken = TokenInterface(0x1982b2F5814301d4e9a8b0201555376e62F82428);
2022-04-01 17:03:30 +00:00
/**
* @dev Supply ETH/ERC20
* @notice Supply a token into Instalite.
2022-04-06 02:27:57 +00:00
* @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)`)
2022-04-01 17:03:30 +00:00
* @param getId ID to retrieve amt.
* @param setIds array of IDs to store the amount of tokens deposited.
2022-04-01 17:03:30 +00:00
*/
function supply(
2022-04-06 02:27:57 +00:00
address vaultAddr,
2022-04-01 17:03:30 +00:00
address token,
uint256 amt,
uint256 getId,
2022-04-02 18:24:00 +00:00
uint256[] memory setIds
2022-04-01 17:03:30 +00:00
)
public
payable
returns (string memory _eventName, bytes memory _eventParam)
{
uint256 _amt = getUint(getId, amt);
bool isEth = token == ethAddr;
2022-04-01 17:50:07 +00:00
uint256 vTokenAmt;
2022-04-02 17:11:33 +00:00
2022-04-01 17:03:30 +00:00
if (isEth) {
_amt = _amt == uint256(-1) ? address(this).balance : _amt;
2022-04-06 02:27:57 +00:00
vTokenAmt = IInstaLite(vaultAddr).supplyEth{ value: amt }(address(this));
2022-04-01 17:03:30 +00:00
} else {
TokenInterface tokenContract = TokenInterface(token);
_amt = _amt == uint256(-1)
? tokenContract.balanceOf(address(this))
: _amt;
2022-04-06 02:27:57 +00:00
approve(tokenContract, vaultAddr, _amt);
vTokenAmt = IInstaLite(vaultAddr).supply(token, _amt, address(this));
2022-04-01 17:03:30 +00:00
}
2022-04-02 18:24:00 +00:00
setUint(setIds[0], _amt);
setUint(setIds[1], vTokenAmt);
2022-04-01 17:03:30 +00:00
2022-04-02 22:01:38 +00:00
_eventName = "LogSupply(address,address,uint256,uint256,uint256,uint256[])";
2022-04-02 18:08:26 +00:00
_eventParam = abi.encode(
2022-04-06 02:27:57 +00:00
vaultAddr,
2022-04-02 18:08:26 +00:00
token,
vTokenAmt,
_amt,
getId,
2022-04-02 18:24:00 +00:00
setIds
2022-04-02 18:08:26 +00:00
);
2022-04-01 17:03:30 +00:00
}
/**
* @dev Withdraw ETH/ERC20
* @notice Withdraw deposited tokens from Instalite.
2022-04-06 02:27:57 +00:00
* @param vaultAddr Address of vaultAddress Contract.
2022-04-01 17:03:30 +00:00
* @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.
2022-04-01 17:03:30 +00:00
*/
function withdraw(
2022-04-06 02:27:57 +00:00
address vaultAddr,
2022-04-01 17:03:30 +00:00
uint256 amt,
uint256 getId,
2022-04-02 18:24:00 +00:00
uint256[] memory setIds
2022-04-01 17:03:30 +00:00
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
uint256 _amt = getUint(getId, amt);
2022-04-06 02:27:57 +00:00
uint256 vTokenAmt = IInstaLite(vaultAddr).withdraw(_amt, address(this));
2022-04-01 17:03:30 +00:00
2022-04-02 18:24:00 +00:00
setUint(setIds[0], _amt);
setUint(setIds[1], vTokenAmt);
2022-04-01 17:03:30 +00:00
2022-04-02 22:01:38 +00:00
_eventName = "LogWithdraw(address,uint256,uint256,uint256,uint256[])";
2022-04-06 02:27:57 +00:00
_eventParam = abi.encode(vaultAddr, _amt, vTokenAmt, getId, setIds);
}
/**
2022-04-06 02:32:56 +00:00
* @dev Deleverage vault. Pays back ETH debt and get stETH collateral. 1:1 swap of ETH to stETH
* @notice Deleverage Instalite vault.
* @param vaultAddr Address of vaultAddress Contract.
* @param amt The amount of the token to deleverage.
2022-04-06 02:27:57 +00:00
* @param getId ID to retrieve amt.
2022-04-06 02:32:56 +00:00
* @param setId ID to set amt.
2022-04-06 02:27:57 +00:00
*/
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 <= (1e9 + finalBal - initialBal), "lack-of-steth");
2022-04-06 02:27:57 +00:00
setUint(setId, _amt);
_eventName = "LogDeleverage(address,uint256,uint256,uint256)";
_eventParam = abi.encode(vaultAddr, _amt, getId, setId);
2022-04-01 17:03:30 +00:00
}
2022-04-06 02:32:56 +00:00
2022-04-01 17:03:30 +00:00
}
2022-04-07 17:17:02 +00:00
contract ConnectV2InstaLite is InstaLiteConnector {
string public constant name = "InstaLite-v1";
2022-04-01 17:03:30 +00:00
}