From 1f862ac4bf12678d359249e96aa4953584a7d08d Mon Sep 17 00:00:00 2001 From: Richa-iitr Date: Sun, 2 Oct 2022 02:41:44 +0530 Subject: [PATCH 1/7] 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"; +} From 72f989c9dae8aa01473b28222e8e278f180d07c0 Mon Sep 17 00:00:00 2001 From: Richa-iitr Date: Sun, 2 Oct 2022 03:27:58 +0530 Subject: [PATCH 2/7] rename contract --- contracts/mainnet/connectors/instaLite_v2/main.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/mainnet/connectors/instaLite_v2/main.sol b/contracts/mainnet/connectors/instaLite_v2/main.sol index 9bebfa55..1e0ab47c 100644 --- a/contracts/mainnet/connectors/instaLite_v2/main.sol +++ b/contracts/mainnet/connectors/instaLite_v2/main.sol @@ -72,6 +72,6 @@ abstract contract InstaLiteConnector is Events, Basic { } } -contract ConnectV2InstaLiteV2 is InstaLiteConnector { - string public constant name = "InstaLite-v2.0"; +contract ConnectV2InstaLiteImport is InstaLiteConnector { + string public constant name = "InstaLite-Import-v1.0"; } From 2ee63f3058bd079c9eeb9ec7e0be7c280e8930c7 Mon Sep 17 00:00:00 2001 From: Richa-iitr Date: Sun, 2 Oct 2022 03:50:17 +0530 Subject: [PATCH 3/7] updated ieth call --- .../connectors/instaLite_v2/interface.sol | 7 ++--- .../mainnet/connectors/instaLite_v2/main.sol | 28 +++++++++---------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/contracts/mainnet/connectors/instaLite_v2/interface.sol b/contracts/mainnet/connectors/instaLite_v2/interface.sol index b85bd2c6..078847c6 100644 --- a/contracts/mainnet/connectors/instaLite_v2/interface.sol +++ b/contracts/mainnet/connectors/instaLite_v2/interface.sol @@ -2,15 +2,12 @@ pragma solidity ^0.7.0; interface IInstaLite { - function token() external view returns (address); - function importPosition( address flashTkn_, uint256 flashAmt_, uint256 route_, + address to_, uint256 stEthAmt_, - uint256 wethAmt_, - uint256 getId, - uint256 setId + uint256 wethAmt_ ) external; } diff --git a/contracts/mainnet/connectors/instaLite_v2/main.sol b/contracts/mainnet/connectors/instaLite_v2/main.sol index 1e0ab47c..110f80da 100644 --- a/contracts/mainnet/connectors/instaLite_v2/main.sol +++ b/contracts/mainnet/connectors/instaLite_v2/main.sol @@ -10,15 +10,14 @@ 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; + IInstaLite internal constant iEth = + IInstaLite(0xc383a3833A87009fD9597F8184979AF5eDFad019); /** * @dev Supply ETH/ERC20 @@ -27,7 +26,7 @@ abstract contract InstaLiteConnector is Events, Basic { * @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 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. */ @@ -46,10 +45,9 @@ abstract contract InstaLiteConnector is Events, Basic { ? astethToken.balanceOf(msg.sender) : stEthAmt_; - astethToken.approve(ethVaultAddr, stEthAmt_); + astethToken.approve(address(iEth), stEthAmt_); - bytes memory callData_ = abi.encodeWithSignature( - "importPosition(address,uint256,uint256,address,uint256,uint256)", + iEth.importPosition( flashTkn_, flashAmt_, route_, @@ -58,17 +56,19 @@ abstract contract InstaLiteConnector is Events, Basic { 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); + eventParam_ = abi.encode( + flashTkn_, + flashAmt_, + route_, + stEthAmt_, + wethAmt_, + getIds, + setIds + ); } } From b479b164ddead324d370ac57bb696f1d98573c7e Mon Sep 17 00:00:00 2001 From: Richa-iitr Date: Sun, 2 Oct 2022 10:13:11 +0530 Subject: [PATCH 4/7] changes --- .../{instaLite_v2 => instaLite_import}/events.sol | 2 +- .../{instaLite_v2 => instaLite_import}/interface.sol | 2 ++ .../{instaLite_v2 => instaLite_import}/main.sol | 11 +++++------ 3 files changed, 8 insertions(+), 7 deletions(-) rename contracts/mainnet/connectors/{instaLite_v2 => instaLite_import}/events.sol (91%) rename contracts/mainnet/connectors/{instaLite_v2 => instaLite_import}/interface.sol (74%) rename contracts/mainnet/connectors/{instaLite_v2 => instaLite_import}/main.sol (90%) diff --git a/contracts/mainnet/connectors/instaLite_v2/events.sol b/contracts/mainnet/connectors/instaLite_import/events.sol similarity index 91% rename from contracts/mainnet/connectors/instaLite_v2/events.sol rename to contracts/mainnet/connectors/instaLite_import/events.sol index 5234807e..7cbc2510 100644 --- a/contracts/mainnet/connectors/instaLite_v2/events.sol +++ b/contracts/mainnet/connectors/instaLite_import/events.sol @@ -9,6 +9,6 @@ contract Events { uint256 stEthAmt, uint256 wethAmt, uint256[] getIds, - uint256[] setIds + uint256 setId ); } diff --git a/contracts/mainnet/connectors/instaLite_v2/interface.sol b/contracts/mainnet/connectors/instaLite_import/interface.sol similarity index 74% rename from contracts/mainnet/connectors/instaLite_v2/interface.sol rename to contracts/mainnet/connectors/instaLite_import/interface.sol index 078847c6..a206432e 100644 --- a/contracts/mainnet/connectors/instaLite_v2/interface.sol +++ b/contracts/mainnet/connectors/instaLite_import/interface.sol @@ -2,6 +2,8 @@ pragma solidity ^0.7.0; interface IInstaLite { + function balanceOf(address account) external view virtual returns (uint256); + function importPosition( address flashTkn_, uint256 flashAmt_, diff --git a/contracts/mainnet/connectors/instaLite_v2/main.sol b/contracts/mainnet/connectors/instaLite_import/main.sol similarity index 90% rename from contracts/mainnet/connectors/instaLite_v2/main.sol rename to contracts/mainnet/connectors/instaLite_import/main.sol index 110f80da..49a9028a 100644 --- a/contracts/mainnet/connectors/instaLite_v2/main.sol +++ b/contracts/mainnet/connectors/instaLite_import/main.sol @@ -28,7 +28,7 @@ abstract contract InstaLiteConnector is Events, Basic { * @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. + * @param setId ID to store balanceOf of iEth. */ function importPosition( address flashTkn_, @@ -37,7 +37,7 @@ abstract contract InstaLiteConnector is Events, Basic { uint256 stEthAmt_, uint256 wethAmt_, uint256[] memory getIds, - uint256[] memory setIds + uint256 setId ) external returns (string memory eventName_, bytes memory eventParam_) { uint256 stEthAmt_ = getUint(getIds[0], stEthAmt_); uint256 wethAmt_ = getUint(getIds[1], wethAmt_); @@ -56,10 +56,9 @@ abstract contract InstaLiteConnector is Events, Basic { wethAmt_ ); - setUint(setIds[0], stEthAmt_); - setUint(setIds[1], wethAmt_); + setUint(setId, iEth.balanceOf(address(this))); - eventName_ = "LogImport(address,uint256,uint256,uint256,uint256,uint256[],uint256[])"; + eventName_ = "LogImport(address,uint256,uint256,uint256,uint256,uint256[],uint256)"; eventParam_ = abi.encode( flashTkn_, flashAmt_, @@ -67,7 +66,7 @@ abstract contract InstaLiteConnector is Events, Basic { stEthAmt_, wethAmt_, getIds, - setIds + setId ); } } From 61d39702738b5a2bbd54e821adc2e8fcadee2970 Mon Sep 17 00:00:00 2001 From: Richa-iitr Date: Sun, 2 Oct 2022 20:25:58 +0530 Subject: [PATCH 5/7] updated setId --- contracts/mainnet/connectors/instaLite_import/events.sol | 1 + contracts/mainnet/connectors/instaLite_import/main.sol | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/instaLite_import/events.sol b/contracts/mainnet/connectors/instaLite_import/events.sol index 7cbc2510..0dacbeb5 100644 --- a/contracts/mainnet/connectors/instaLite_import/events.sol +++ b/contracts/mainnet/connectors/instaLite_import/events.sol @@ -8,6 +8,7 @@ contract Events { uint256 route, uint256 stEthAmt, uint256 wethAmt, + uint256 iEthAmount, uint256[] getIds, uint256 setId ); diff --git a/contracts/mainnet/connectors/instaLite_import/main.sol b/contracts/mainnet/connectors/instaLite_import/main.sol index 49a9028a..e2c956fb 100644 --- a/contracts/mainnet/connectors/instaLite_import/main.sol +++ b/contracts/mainnet/connectors/instaLite_import/main.sol @@ -46,6 +46,7 @@ abstract contract InstaLiteConnector is Events, Basic { : stEthAmt_; astethToken.approve(address(iEth), stEthAmt_); + uint256 initialBal = iEth.balanceOf(address(this)); iEth.importPosition( flashTkn_, @@ -56,7 +57,10 @@ abstract contract InstaLiteConnector is Events, Basic { wethAmt_ ); - setUint(setId, iEth.balanceOf(address(this))); + uint256 finalBalance = iEth.balanceOf(address(this)); + uint256 iEthAmt_ = finalBalance - initialBal; + + setUint(setId, iEthAmt_); eventName_ = "LogImport(address,uint256,uint256,uint256,uint256,uint256[],uint256)"; eventParam_ = abi.encode( @@ -65,6 +69,7 @@ abstract contract InstaLiteConnector is Events, Basic { route_, stEthAmt_, wethAmt_, + iEthAmt_, getIds, setId ); From b83981d2d3850f5c558ebc90ce66fcca7ac4de21 Mon Sep 17 00:00:00 2001 From: Richa-iitr Date: Sun, 2 Oct 2022 20:29:01 +0530 Subject: [PATCH 6/7] minor change --- contracts/mainnet/connectors/instaLite_import/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/instaLite_import/main.sol b/contracts/mainnet/connectors/instaLite_import/main.sol index e2c956fb..c18c0f3e 100644 --- a/contracts/mainnet/connectors/instaLite_import/main.sol +++ b/contracts/mainnet/connectors/instaLite_import/main.sol @@ -62,7 +62,7 @@ abstract contract InstaLiteConnector is Events, Basic { setUint(setId, iEthAmt_); - eventName_ = "LogImport(address,uint256,uint256,uint256,uint256,uint256[],uint256)"; + eventName_ = "LogImport(address,uint256,uint256,uint256,uint256,uint256,uint256[],uint256)"; eventParam_ = abi.encode( flashTkn_, flashAmt_, From 2ec88215beabd4980ddd7ab5f60044773fd35fd5 Mon Sep 17 00:00:00 2001 From: Richa-iitr Date: Sun, 2 Oct 2022 22:36:45 +0530 Subject: [PATCH 7/7] updated approve to iEthDSA --- contracts/mainnet/connectors/instaLite_import/main.sol | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/instaLite_import/main.sol b/contracts/mainnet/connectors/instaLite_import/main.sol index c18c0f3e..8b7b6528 100644 --- a/contracts/mainnet/connectors/instaLite_import/main.sol +++ b/contracts/mainnet/connectors/instaLite_import/main.sol @@ -19,6 +19,9 @@ abstract contract InstaLiteConnector is Events, Basic { IInstaLite internal constant iEth = IInstaLite(0xc383a3833A87009fD9597F8184979AF5eDFad019); + address internal constant iEthDSA = + 0x94269A09c5Fcbd5e88F9DF13741997bc11735a9c; + /** * @dev Supply ETH/ERC20 * @notice Supply a token into Instalite. @@ -45,7 +48,7 @@ abstract contract InstaLiteConnector is Events, Basic { ? astethToken.balanceOf(msg.sender) : stEthAmt_; - astethToken.approve(address(iEth), stEthAmt_); + astethToken.approve(iEthDSA, stEthAmt_); uint256 initialBal = iEth.balanceOf(address(this)); iEth.importPosition(