From 1f862ac4bf12678d359249e96aa4953584a7d08d Mon Sep 17 00:00:00 2001 From: Richa-iitr Date: Sun, 2 Oct 2022 02:41:44 +0530 Subject: [PATCH] added contracts --- .../connectors/instaLite_v2/events.sol | 14 ++++ .../connectors/instaLite_v2/interface.sol | 16 ++++ .../mainnet/connectors/instaLite_v2/main.sol | 77 +++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 contracts/mainnet/connectors/instaLite_v2/events.sol create mode 100644 contracts/mainnet/connectors/instaLite_v2/interface.sol create mode 100644 contracts/mainnet/connectors/instaLite_v2/main.sol diff --git a/contracts/mainnet/connectors/instaLite_v2/events.sol b/contracts/mainnet/connectors/instaLite_v2/events.sol new file mode 100644 index 00000000..5234807e --- /dev/null +++ b/contracts/mainnet/connectors/instaLite_v2/events.sol @@ -0,0 +1,14 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Events { + event LogImport( + address flashTkn, + uint256 flashAmt, + uint256 route, + uint256 stEthAmt, + uint256 wethAmt, + uint256[] getIds, + uint256[] setIds + ); +} diff --git a/contracts/mainnet/connectors/instaLite_v2/interface.sol b/contracts/mainnet/connectors/instaLite_v2/interface.sol new file mode 100644 index 00000000..b85bd2c6 --- /dev/null +++ b/contracts/mainnet/connectors/instaLite_v2/interface.sol @@ -0,0 +1,16 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +interface IInstaLite { + function token() external view returns (address); + + function importPosition( + address flashTkn_, + uint256 flashAmt_, + uint256 route_, + uint256 stEthAmt_, + uint256 wethAmt_, + uint256 getId, + uint256 setId + ) external; +} diff --git a/contracts/mainnet/connectors/instaLite_v2/main.sol b/contracts/mainnet/connectors/instaLite_v2/main.sol new file mode 100644 index 00000000..9bebfa55 --- /dev/null +++ b/contracts/mainnet/connectors/instaLite_v2/main.sol @@ -0,0 +1,77 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +/** + * @title InstaLite Connector + * @dev Import Position + */ + +import { TokenInterface } from "../../common/interfaces.sol"; +import { Basic } from "../../common/basic.sol"; +import { Events } from "./events.sol"; +import { IInstaLite } from "./interface.sol"; +import "@openzeppelin/contracts/utils/Address.sol"; + +abstract contract InstaLiteConnector is Events, Basic { + TokenInterface internal constant astethToken = + TokenInterface(0x1982b2F5814301d4e9a8b0201555376e62F82428); + TokenInterface internal constant stethToken = + TokenInterface(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84); + address internal constant ethVaultAddr = + 0xc383a3833A87009fD9597F8184979AF5eDFad019; + + /** + * @dev Supply ETH/ERC20 + * @notice Supply a token into Instalite. + * @param flashTkn_ Address of flash token. + * @param flashAmt_ Flash loan amount. + * @param route_ Flash loan route. + * @param stEthAmt_ Amount of astEthToken to be imported. + * @param wethAmt_ Amount of weth borrows to be imported. + * @param getIds IDs to retrieve amt. + * @param setIds array of IDs to store the amount of tokens deposited. + */ + function importPosition( + address flashTkn_, + uint256 flashAmt_, + uint256 route_, + uint256 stEthAmt_, + uint256 wethAmt_, + uint256[] memory getIds, + uint256[] memory setIds + ) external returns (string memory eventName_, bytes memory eventParam_) { + uint256 stEthAmt_ = getUint(getIds[0], stEthAmt_); + uint256 wethAmt_ = getUint(getIds[1], wethAmt_); + stEthAmt_ = stEthAmt_ == type(uint256).max + ? astethToken.balanceOf(msg.sender) + : stEthAmt_; + + astethToken.approve(ethVaultAddr, stEthAmt_); + + bytes memory callData_ = abi.encodeWithSignature( + "importPosition(address,uint256,uint256,address,uint256,uint256)", + flashTkn_, + flashAmt_, + route_, + address(this), + stEthAmt_, + wethAmt_ + ); + + Address.functionDelegateCall( + address(ethVaultAddr), + callData_, + "import-failed" + ); + + setUint(setIds[0], stEthAmt_); + setUint(setIds[1], wethAmt_); + + eventName_ = "LogImport(address,uint256,uint256,uint256,uint256,uint256[],uint256[])"; + eventParam_ = abi.encode(flashTkn_,flashAmt_,route_,stEthAmt_,wethAmt_,getIds,setIds); + } +} + +contract ConnectV2InstaLiteV2 is InstaLiteConnector { + string public constant name = "InstaLite-v2.0"; +}