From 7ac94a3db34764c8652697eb8bc249767426d535 Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Fri, 1 Apr 2022 22:33:30 +0530 Subject: [PATCH 01/19] added connector --- .../mainnet/connectors/instaLite/events.sol | 13 +++ .../mainnet/connectors/instaLite/helpers.sol | 11 +++ .../connectors/instaLite/interface.sol | 14 +++ .../mainnet/connectors/instaLite/main.sol | 90 +++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 contracts/mainnet/connectors/instaLite/events.sol create mode 100644 contracts/mainnet/connectors/instaLite/helpers.sol create mode 100644 contracts/mainnet/connectors/instaLite/interface.sol create mode 100644 contracts/mainnet/connectors/instaLite/main.sol diff --git a/contracts/mainnet/connectors/instaLite/events.sol b/contracts/mainnet/connectors/instaLite/events.sol new file mode 100644 index 00000000..5794d77b --- /dev/null +++ b/contracts/mainnet/connectors/instaLite/events.sol @@ -0,0 +1,13 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Events { + event LogSupply( + address token, + uint256 amt, + address to, + uint256 getId, + uint256 setId + ); + event LogWithdraw(uint256 amt, address to, uint256 getId, uint256 setId); +} diff --git a/contracts/mainnet/connectors/instaLite/helpers.sol b/contracts/mainnet/connectors/instaLite/helpers.sol new file mode 100644 index 00000000..5c0aec28 --- /dev/null +++ b/contracts/mainnet/connectors/instaLite/helpers.sol @@ -0,0 +1,11 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +import { DSMath } from "../../common/math.sol"; +import { Basic } from "../../common/basic.sol"; +import { instaLiteInterface } from "./interface.sol"; + +abstract contract Helpers is DSMath, Basic { + instaLiteInterface internal constant instaLite = + instaLiteInterface(0xc383a3833A87009fD9597F8184979AF5eDFad019); +} diff --git a/contracts/mainnet/connectors/instaLite/interface.sol b/contracts/mainnet/connectors/instaLite/interface.sol new file mode 100644 index 00000000..1024fee0 --- /dev/null +++ b/contracts/mainnet/connectors/instaLite/interface.sol @@ -0,0 +1,14 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +interface instaLiteInterface { + function supplyEth(address to_) external payable returns (uint256); + + function supply( + address token_, + uint256 amount_, + address to_ + ) external returns (uint256); + + function withdraw(uint256 amount_, address to_) external returns (uint256); +} diff --git a/contracts/mainnet/connectors/instaLite/main.sol b/contracts/mainnet/connectors/instaLite/main.sol new file mode 100644 index 00000000..73e4f3f0 --- /dev/null +++ b/contracts/mainnet/connectors/instaLite/main.sol @@ -0,0 +1,90 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +/** + * @title InstaLite Connector + * @dev + + */ +import { TokenInterface } from "../../common/interfaces.sol"; +import { DSMath } from "../../common/math.sol"; +import { Basic } from "../../common/basic.sol"; +import { Events } from "./events.sol"; +import { Helpers } from "./helpers.sol"; + +abstract contract Resolver is Events, DSMath, Basic, Helpers { + /** + * @dev Supply + * @notice Supply eth/weth/stEth tokens into instalite. + * @param token The address of token to be supplied. + * @param amt The amount of token to be supplied. + * @param to The address of the account on behalf of you want to supplied. + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of token deposited. + */ + function supply( + address token, + uint256 amt, + address to, + uint256 getId, + uint256 setId + ) + public + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amt = getUint(getId, amt); + bool isEth = token == ethAddr; + + if (isEth) { + _amt = _amt == uint256(-1) ? address(this).balance : _amt; + uint256 vTokenAmt = instaLite.supplyEth{ value: amt }(to); + } else { + TokenInterface tokenContract = TokenInterface(token); + + _amt = _amt == uint256(-1) + ? tokenContract.balanceOf(address(this)) + : _amt; + + approve(tokenContract, address(instaLite), _amt); + uint256 vTokenAmt = instaLite.supply(token, _amt, to); + } + + setUint(setId, _amt); + + _eventName = "LogSupply(address,uint256,address,uint256,uint256)"; + _eventParam = abi.encode(token, _amt, to, getId, setId); + } + + /** + * @dev Withdraw + * @notice Withdraw eth/stEth tokens from instalite contract. + * @param amt The amount of the token to withdraw. + * @param to The address of the account on behalf of you want to withdraw. + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of token withdrawn. + */ + function withdraw( + uint256 amt, + address to, + uint256 getId, + uint256 setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amt = getUint(getId, amt); + + instaLite.withdraw(_amt, to); + + setUint(setId, _amt); + + _eventName = "LogWithdraw(uint256,address,uint256,uint256)"; + _eventParam = abi.encode(_amt, to, getId, setId); + } +} + +contract ConnectV2InstaLite is Resolver { + string public constant name = "instaLite-v1"; +} From f55e0abeb112734a62d1e8c6fdcbaea3bac13a8e Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Fri, 1 Apr 2022 22:33:40 +0530 Subject: [PATCH 02/19] added test --- test/mainnet/instaLite/instaLite.test.ts | 101 +++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 test/mainnet/instaLite/instaLite.test.ts diff --git a/test/mainnet/instaLite/instaLite.test.ts b/test/mainnet/instaLite/instaLite.test.ts new file mode 100644 index 00000000..7cae412c --- /dev/null +++ b/test/mainnet/instaLite/instaLite.test.ts @@ -0,0 +1,101 @@ +import hre from "hardhat"; +import { expect } from "chai"; +const { ethers } = hre; //check +import { BigNumber } from "bignumber.js"; +import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector"; +import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"; +import { encodeSpells } from "../../../scripts/tests/encodeSpells"; +import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"; +import { addresses } from "../../../scripts/tests/mainnet/addresses"; +import { addLiquidity } from "../../../scripts/tests/addLiquidity"; +import { abis } from "../../../scripts/constant/abis"; +import { ConnectV2InstaLite__factory } from "../../../typechain"; +// import lido_abi from "./abi.json"; +import type { Signer, Contract } from "ethers"; +import { parseEther } from "ethers/lib/utils"; + +describe("instaLite", function () { + const connectorName = "instaLite-test"; + + let dsaWallet0: Contract; + let wallet0: Signer, wallet1: Signer; + let masterSigner: Signer; + let instaConnectorsV2: Contract; + let connector: Contract; + + before(async () => { + // await hre.network.provider.request({ + // method: "hardhat_reset", + // params: [ + // { + // forking: { + // // @ts-ignore + // jsonRpcUrl: hre.config.networks.hardhat.forking.url, + // blockNumber: 14334859 + // }, + // }, + // ], + // }); + [wallet0, wallet1] = await ethers.getSigners(); + masterSigner = await getMasterSigner(); + instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2); + connector = await deployAndEnableConnector({ + connectorName, + contractArtifact: ConnectV2InstaLite__factory, + signer: masterSigner, + connectors: instaConnectorsV2 + }); + console.log("Connector address", connector.address); + }); + + it("Should have contracts deployed.", async function () { + expect(!!instaConnectorsV2.address).to.be.true; + expect(!!connector.address).to.be.true; + expect(!!(await masterSigner.getAddress())).to.be.true; + }); + + describe("DSA wallet setup", function () { + it("Should build DSA v2", async function () { + dsaWallet0 = await buildDSAv2(await wallet0.getAddress()); + expect(!!dsaWallet0.address).to.be.true; + }); + + it("Deposit ETH into DSA wallet", async function () { + await wallet0.sendTransaction({ + to: dsaWallet0.address, + value: ethers.utils.parseEther("10") + }); + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10")); + }); + }); + + describe("Main", function () { + it("should deposit the eth", async function () { + const _amt = ethers.utils.parseEther("5"); + const ethAddr = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"; + const spells = [ + { + connector: connectorName, + method: "supply", + args: [ethAddr, _amt, dsaWallet0.address, 0, 0] + } + ]; + const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet1.getAddress()); + const receipt = await tx.wait(); + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.eq(parseEther("5")); + }); + + it("should withdraw", async function () { + const _amt = ethers.utils.parseEther("1"); + const spells = [ + { + connector: connectorName, + method: "withdraw", + args: [_amt, dsaWallet0.address, 0, 0] + } + ]; + const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet1.getAddress()); + const receipt = await tx.wait(); + }); + }); +}); From 10c1872885293b25729537b4eba940f054f531ac Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Fri, 1 Apr 2022 23:20:07 +0530 Subject: [PATCH 03/19] restructured files --- .../instaLite/{ => vault1}/events.sol | 9 +++++++- .../instaLite/{ => vault1}/helpers.sol | 1 - .../instaLite/{ => vault1}/interface.sol | 0 .../instaLite/{ => vault1}/main.sol | 22 +++++++++---------- 4 files changed, 19 insertions(+), 13 deletions(-) rename contracts/mainnet/connectors/instaLite/{ => vault1}/events.sol (58%) rename contracts/mainnet/connectors/instaLite/{ => vault1}/helpers.sol (87%) rename contracts/mainnet/connectors/instaLite/{ => vault1}/interface.sol (100%) rename contracts/mainnet/connectors/instaLite/{ => vault1}/main.sol (75%) diff --git a/contracts/mainnet/connectors/instaLite/events.sol b/contracts/mainnet/connectors/instaLite/vault1/events.sol similarity index 58% rename from contracts/mainnet/connectors/instaLite/events.sol rename to contracts/mainnet/connectors/instaLite/vault1/events.sol index 5794d77b..e0e79105 100644 --- a/contracts/mainnet/connectors/instaLite/events.sol +++ b/contracts/mainnet/connectors/instaLite/vault1/events.sol @@ -4,10 +4,17 @@ pragma solidity ^0.7.0; contract Events { event LogSupply( address token, + uint256 vTokenAmt, uint256 amt, address to, uint256 getId, uint256 setId ); - event LogWithdraw(uint256 amt, address to, uint256 getId, uint256 setId); + event LogWithdraw( + uint256 amt, + uint256 vTokenAmt, + address to, + uint256 getId, + uint256 setId + ); } diff --git a/contracts/mainnet/connectors/instaLite/helpers.sol b/contracts/mainnet/connectors/instaLite/vault1/helpers.sol similarity index 87% rename from contracts/mainnet/connectors/instaLite/helpers.sol rename to contracts/mainnet/connectors/instaLite/vault1/helpers.sol index 5c0aec28..758093f9 100644 --- a/contracts/mainnet/connectors/instaLite/helpers.sol +++ b/contracts/mainnet/connectors/instaLite/vault1/helpers.sol @@ -1,7 +1,6 @@ //SPDX-License-Identifier: MIT pragma solidity ^0.7.0; -import { DSMath } from "../../common/math.sol"; import { Basic } from "../../common/basic.sol"; import { instaLiteInterface } from "./interface.sol"; diff --git a/contracts/mainnet/connectors/instaLite/interface.sol b/contracts/mainnet/connectors/instaLite/vault1/interface.sol similarity index 100% rename from contracts/mainnet/connectors/instaLite/interface.sol rename to contracts/mainnet/connectors/instaLite/vault1/interface.sol diff --git a/contracts/mainnet/connectors/instaLite/main.sol b/contracts/mainnet/connectors/instaLite/vault1/main.sol similarity index 75% rename from contracts/mainnet/connectors/instaLite/main.sol rename to contracts/mainnet/connectors/instaLite/vault1/main.sol index 73e4f3f0..ca5828f1 100644 --- a/contracts/mainnet/connectors/instaLite/main.sol +++ b/contracts/mainnet/connectors/instaLite/vault1/main.sol @@ -3,7 +3,7 @@ pragma solidity ^0.7.0; /** * @title InstaLite Connector - * @dev + * @dev Supply and Withdraw */ import { TokenInterface } from "../../common/interfaces.sol"; @@ -12,7 +12,7 @@ import { Basic } from "../../common/basic.sol"; import { Events } from "./events.sol"; import { Helpers } from "./helpers.sol"; -abstract contract Resolver is Events, DSMath, Basic, Helpers { +abstract contract InstaLiteConnector is Events, Basic, Helpers { /** * @dev Supply * @notice Supply eth/weth/stEth tokens into instalite. @@ -35,10 +35,10 @@ abstract contract Resolver is Events, DSMath, Basic, Helpers { { uint256 _amt = getUint(getId, amt); bool isEth = token == ethAddr; - + uint256 vTokenAmt; if (isEth) { _amt = _amt == uint256(-1) ? address(this).balance : _amt; - uint256 vTokenAmt = instaLite.supplyEth{ value: amt }(to); + vTokenAmt = instaLite.supplyEth{ value: amt }(to); } else { TokenInterface tokenContract = TokenInterface(token); @@ -47,13 +47,13 @@ abstract contract Resolver is Events, DSMath, Basic, Helpers { : _amt; approve(tokenContract, address(instaLite), _amt); - uint256 vTokenAmt = instaLite.supply(token, _amt, to); + vTokenAmt = instaLite.supply(token, _amt, to); } setUint(setId, _amt); - _eventName = "LogSupply(address,uint256,address,uint256,uint256)"; - _eventParam = abi.encode(token, _amt, to, getId, setId); + _eventName = "LogSupply(address,uint256,uint256,address,uint256,uint256)"; + _eventParam = abi.encode(token, vTokenAmt, _amt, to, getId, setId); } /** @@ -76,15 +76,15 @@ abstract contract Resolver is Events, DSMath, Basic, Helpers { { uint256 _amt = getUint(getId, amt); - instaLite.withdraw(_amt, to); + unit256 vTokenAmt = instaLite.withdraw(_amt, to); setUint(setId, _amt); - _eventName = "LogWithdraw(uint256,address,uint256,uint256)"; - _eventParam = abi.encode(_amt, to, getId, setId); + _eventName = "LogWithdraw(uint256,uint256,address,uint256,uint256)"; + _eventParam = abi.encode(_amt, vTokenAmt, to, getId, setId); } } -contract ConnectV2InstaLite is Resolver { +contract ConnectV2InstaLiteVault1 is Resolver { string public constant name = "instaLite-v1"; } From dfb2c8132d80c3d311d6187fb3b86e7e521e8841 Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Sat, 2 Apr 2022 22:41:33 +0530 Subject: [PATCH 04/19] passed vault addr in params --- .../connectors/instaLite/vault1/helpers.sol | 10 ----- .../connectors/instaLite/vault1/main.sol | 37 ++++++++++++------- test/mainnet/instaLite/instaLite.test.ts | 8 ++-- 3 files changed, 28 insertions(+), 27 deletions(-) delete mode 100644 contracts/mainnet/connectors/instaLite/vault1/helpers.sol diff --git a/contracts/mainnet/connectors/instaLite/vault1/helpers.sol b/contracts/mainnet/connectors/instaLite/vault1/helpers.sol deleted file mode 100644 index 758093f9..00000000 --- a/contracts/mainnet/connectors/instaLite/vault1/helpers.sol +++ /dev/null @@ -1,10 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity ^0.7.0; - -import { Basic } from "../../common/basic.sol"; -import { instaLiteInterface } from "./interface.sol"; - -abstract contract Helpers is DSMath, Basic { - instaLiteInterface internal constant instaLite = - instaLiteInterface(0xc383a3833A87009fD9597F8184979AF5eDFad019); -} diff --git a/contracts/mainnet/connectors/instaLite/vault1/main.sol b/contracts/mainnet/connectors/instaLite/vault1/main.sol index ca5828f1..27d16958 100644 --- a/contracts/mainnet/connectors/instaLite/vault1/main.sol +++ b/contracts/mainnet/connectors/instaLite/vault1/main.sol @@ -6,19 +6,20 @@ pragma solidity ^0.7.0; * @dev Supply and Withdraw */ -import { TokenInterface } from "../../common/interfaces.sol"; -import { DSMath } from "../../common/math.sol"; -import { Basic } from "../../common/basic.sol"; +import { TokenInterface } from "../../../common/interfaces.sol"; +import { DSMath } from "../../../common/math.sol"; +import { Basic } from "../../../common/basic.sol"; import { Events } from "./events.sol"; -import { Helpers } from "./helpers.sol"; +import { instaLiteInterface } from "./interface.sol"; -abstract contract InstaLiteConnector is Events, Basic, Helpers { +abstract contract InstaLiteConnector is Events, Basic { /** * @dev Supply * @notice Supply eth/weth/stEth tokens into instalite. * @param token The address of token to be supplied. * @param amt The amount of token to be supplied. * @param to The address of the account on behalf of you want to supplied. + * @param instaLite Address of instaLite Contract. * @param getId ID to retrieve amt. * @param setId ID stores the amount of token deposited. */ @@ -26,8 +27,9 @@ abstract contract InstaLiteConnector is Events, Basic, Helpers { address token, uint256 amt, address to, + address instaLite, uint256 getId, - uint256 setId + uint256[] memory setId ) public payable @@ -36,9 +38,12 @@ abstract contract InstaLiteConnector is Events, Basic, Helpers { uint256 _amt = getUint(getId, amt); bool isEth = token == ethAddr; uint256 vTokenAmt; + + instaLiteInterface instaLiteInstance = instaLiteInterface(instaLite); + if (isEth) { _amt = _amt == uint256(-1) ? address(this).balance : _amt; - vTokenAmt = instaLite.supplyEth{ value: amt }(to); + vTokenAmt = instaLiteInstance.supplyEth{ value: amt }(to); } else { TokenInterface tokenContract = TokenInterface(token); @@ -47,10 +52,11 @@ abstract contract InstaLiteConnector is Events, Basic, Helpers { : _amt; approve(tokenContract, address(instaLite), _amt); - vTokenAmt = instaLite.supply(token, _amt, to); + vTokenAmt = instaLiteInstance.supply(token, _amt, to); } - setUint(setId, _amt); + setUint(setId[0], _amt); + setUint(setId[1], vTokenAmt); _eventName = "LogSupply(address,uint256,uint256,address,uint256,uint256)"; _eventParam = abi.encode(token, vTokenAmt, _amt, to, getId, setId); @@ -61,14 +67,16 @@ abstract contract InstaLiteConnector is Events, Basic, Helpers { * @notice Withdraw eth/stEth tokens from instalite contract. * @param amt The amount of the token to withdraw. * @param to The address of the account on behalf of you want to withdraw. + * @param instaLite Address of instaLite Contract. * @param getId ID to retrieve amt. * @param setId ID stores the amount of token withdrawn. */ function withdraw( uint256 amt, address to, + address instaLite, uint256 getId, - uint256 setId + uint256[] memory setId ) external payable @@ -76,15 +84,18 @@ abstract contract InstaLiteConnector is Events, Basic, Helpers { { uint256 _amt = getUint(getId, amt); - unit256 vTokenAmt = instaLite.withdraw(_amt, to); + instaLiteInterface instaLiteInstance = instaLiteInterface(instaLite); - setUint(setId, _amt); + uint256 vTokenAmt = instaLiteInstance.withdraw(_amt, to); + + setUint(setId[0], _amt); + setUint(setId[1], vTokenAmt); _eventName = "LogWithdraw(uint256,uint256,address,uint256,uint256)"; _eventParam = abi.encode(_amt, vTokenAmt, to, getId, setId); } } -contract ConnectV2InstaLiteVault1 is Resolver { +contract ConnectV2InstaLiteVault1 is InstaLiteConnector { string public constant name = "instaLite-v1"; } diff --git a/test/mainnet/instaLite/instaLite.test.ts b/test/mainnet/instaLite/instaLite.test.ts index 7cae412c..524dabea 100644 --- a/test/mainnet/instaLite/instaLite.test.ts +++ b/test/mainnet/instaLite/instaLite.test.ts @@ -9,7 +9,7 @@ import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"; import { addresses } from "../../../scripts/tests/mainnet/addresses"; import { addLiquidity } from "../../../scripts/tests/addLiquidity"; import { abis } from "../../../scripts/constant/abis"; -import { ConnectV2InstaLite__factory } from "../../../typechain"; +import { ConnectV2InstaLiteVault1__factory } from "../../../typechain"; // import lido_abi from "./abi.json"; import type { Signer, Contract } from "ethers"; import { parseEther } from "ethers/lib/utils"; @@ -41,7 +41,7 @@ describe("instaLite", function () { instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2); connector = await deployAndEnableConnector({ connectorName, - contractArtifact: ConnectV2InstaLite__factory, + contractArtifact: ConnectV2InstaLiteVault1__factory, signer: masterSigner, connectors: instaConnectorsV2 }); @@ -77,7 +77,7 @@ describe("instaLite", function () { { connector: connectorName, method: "supply", - args: [ethAddr, _amt, dsaWallet0.address, 0, 0] + args: [ethAddr, _amt, dsaWallet0.address, "0xc383a3833a87009fd9597f8184979af5edfad019", 0, [0, 0]] } ]; const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet1.getAddress()); @@ -91,7 +91,7 @@ describe("instaLite", function () { { connector: connectorName, method: "withdraw", - args: [_amt, dsaWallet0.address, 0, 0] + args: [_amt, dsaWallet0.address, "0xc383a3833a87009fd9597f8184979af5edfad019", 0, [0, 0]] } ]; const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet1.getAddress()); From 8c668e6e2be93ef418eae3104cb4ee4c39f762b6 Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Sat, 2 Apr 2022 23:38:26 +0530 Subject: [PATCH 05/19] added instalite contract address on instalite --- .../mainnet/connectors/instaLite/vault1/main.sol | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/contracts/mainnet/connectors/instaLite/vault1/main.sol b/contracts/mainnet/connectors/instaLite/vault1/main.sol index 27d16958..5bce5327 100644 --- a/contracts/mainnet/connectors/instaLite/vault1/main.sol +++ b/contracts/mainnet/connectors/instaLite/vault1/main.sol @@ -58,8 +58,16 @@ abstract contract InstaLiteConnector is Events, Basic { setUint(setId[0], _amt); setUint(setId[1], vTokenAmt); - _eventName = "LogSupply(address,uint256,uint256,address,uint256,uint256)"; - _eventParam = abi.encode(token, vTokenAmt, _amt, to, getId, setId); + _eventName = "LogSupply(address,uint256,uint256,address,address,uint256,uint256[])"; + _eventParam = abi.encode( + token, + vTokenAmt, + _amt, + to, + instaLite, + getId, + setId + ); } /** @@ -91,8 +99,8 @@ abstract contract InstaLiteConnector is Events, Basic { setUint(setId[0], _amt); setUint(setId[1], vTokenAmt); - _eventName = "LogWithdraw(uint256,uint256,address,uint256,uint256)"; - _eventParam = abi.encode(_amt, vTokenAmt, to, getId, setId); + _eventName = "LogWithdraw(uint256,uint256,address,address,uint256,uint256[])"; + _eventParam = abi.encode(_amt, vTokenAmt, to, instaLite, getId, setId); } } From 931cd418443d38c3fca062027f0bc652ea4c50de Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Sat, 2 Apr 2022 23:38:26 +0530 Subject: [PATCH 06/19] New message --- .../mainnet/connectors/instaLite/vault1/main.sol | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/contracts/mainnet/connectors/instaLite/vault1/main.sol b/contracts/mainnet/connectors/instaLite/vault1/main.sol index 27d16958..5bce5327 100644 --- a/contracts/mainnet/connectors/instaLite/vault1/main.sol +++ b/contracts/mainnet/connectors/instaLite/vault1/main.sol @@ -58,8 +58,16 @@ abstract contract InstaLiteConnector is Events, Basic { setUint(setId[0], _amt); setUint(setId[1], vTokenAmt); - _eventName = "LogSupply(address,uint256,uint256,address,uint256,uint256)"; - _eventParam = abi.encode(token, vTokenAmt, _amt, to, getId, setId); + _eventName = "LogSupply(address,uint256,uint256,address,address,uint256,uint256[])"; + _eventParam = abi.encode( + token, + vTokenAmt, + _amt, + to, + instaLite, + getId, + setId + ); } /** @@ -91,8 +99,8 @@ abstract contract InstaLiteConnector is Events, Basic { setUint(setId[0], _amt); setUint(setId[1], vTokenAmt); - _eventName = "LogWithdraw(uint256,uint256,address,uint256,uint256)"; - _eventParam = abi.encode(_amt, vTokenAmt, to, getId, setId); + _eventName = "LogWithdraw(uint256,uint256,address,address,uint256,uint256[])"; + _eventParam = abi.encode(_amt, vTokenAmt, to, instaLite, getId, setId); } } From 00561c0d83a07cfcea2073a2f02c7baa43f59838 Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Sat, 2 Apr 2022 23:54:00 +0530 Subject: [PATCH 07/19] minor fix --- .../instaLite/{vault1 => }/events.sol | 6 ++- .../instaLite/{vault1 => }/interface.sol | 0 .../instaLite/{vault1 => }/main.sol | 53 +++++++++++-------- 3 files changed, 34 insertions(+), 25 deletions(-) rename contracts/mainnet/connectors/instaLite/{vault1 => }/events.sol (76%) rename contracts/mainnet/connectors/instaLite/{vault1 => }/interface.sol (100%) rename contracts/mainnet/connectors/instaLite/{vault1 => }/main.sol (64%) diff --git a/contracts/mainnet/connectors/instaLite/vault1/events.sol b/contracts/mainnet/connectors/instaLite/events.sol similarity index 76% rename from contracts/mainnet/connectors/instaLite/vault1/events.sol rename to contracts/mainnet/connectors/instaLite/events.sol index e0e79105..e83bafdb 100644 --- a/contracts/mainnet/connectors/instaLite/vault1/events.sol +++ b/contracts/mainnet/connectors/instaLite/events.sol @@ -3,18 +3,20 @@ pragma solidity ^0.7.0; contract Events { event LogSupply( + address vaultAddress, address token, uint256 vTokenAmt, uint256 amt, address to, uint256 getId, - uint256 setId + uint256[] setIds ); event LogWithdraw( + address vaultAddress, uint256 amt, uint256 vTokenAmt, address to, uint256 getId, - uint256 setId + uint256[] setIds ); } diff --git a/contracts/mainnet/connectors/instaLite/vault1/interface.sol b/contracts/mainnet/connectors/instaLite/interface.sol similarity index 100% rename from contracts/mainnet/connectors/instaLite/vault1/interface.sol rename to contracts/mainnet/connectors/instaLite/interface.sol diff --git a/contracts/mainnet/connectors/instaLite/vault1/main.sol b/contracts/mainnet/connectors/instaLite/main.sol similarity index 64% rename from contracts/mainnet/connectors/instaLite/vault1/main.sol rename to contracts/mainnet/connectors/instaLite/main.sol index 5bce5327..d68de918 100644 --- a/contracts/mainnet/connectors/instaLite/vault1/main.sol +++ b/contracts/mainnet/connectors/instaLite/main.sol @@ -6,9 +6,9 @@ pragma solidity ^0.7.0; * @dev Supply and Withdraw */ -import { TokenInterface } from "../../../common/interfaces.sol"; -import { DSMath } from "../../../common/math.sol"; -import { Basic } from "../../../common/basic.sol"; +import { TokenInterface } from "../../common/interfaces.sol"; +import { DSMath } from "../../common/math.sol"; +import { Basic } from "../../common/basic.sol"; import { Events } from "./events.sol"; import { instaLiteInterface } from "./interface.sol"; @@ -16,20 +16,20 @@ abstract contract InstaLiteConnector is Events, Basic { /** * @dev Supply * @notice Supply eth/weth/stEth tokens into instalite. + * @param vaultAddress Address of instaLite Contract. * @param token The address of token to be supplied. * @param amt The amount of token to be supplied. * @param to The address of the account on behalf of you want to supplied. - * @param instaLite Address of instaLite Contract. * @param getId ID to retrieve amt. - * @param setId ID stores the amount of token deposited. + * @param setIds ID stores the amount of token deposited. */ function supply( + address vaultAddress, address token, uint256 amt, address to, - address instaLite, uint256 getId, - uint256[] memory setId + uint256[] memory setIds ) public payable @@ -39,7 +39,7 @@ abstract contract InstaLiteConnector is Events, Basic { bool isEth = token == ethAddr; uint256 vTokenAmt; - instaLiteInterface instaLiteInstance = instaLiteInterface(instaLite); + instaLiteInterface instaLiteInstance = instaLiteInterface(vaultAddress); if (isEth) { _amt = _amt == uint256(-1) ? address(this).balance : _amt; @@ -51,40 +51,40 @@ abstract contract InstaLiteConnector is Events, Basic { ? tokenContract.balanceOf(address(this)) : _amt; - approve(tokenContract, address(instaLite), _amt); + approve(tokenContract, vaultAddress, _amt); vTokenAmt = instaLiteInstance.supply(token, _amt, to); } - setUint(setId[0], _amt); - setUint(setId[1], vTokenAmt); + setUint(setIds[0], _amt); + setUint(setIds[1], vTokenAmt); - _eventName = "LogSupply(address,uint256,uint256,address,address,uint256,uint256[])"; + _eventName = "LogSupply(address,address,uint256,uint256,address,uint256,uint256[])"; _eventParam = abi.encode( + vaultAddress, token, vTokenAmt, _amt, to, - instaLite, getId, - setId + setIds ); } /** * @dev Withdraw * @notice Withdraw eth/stEth tokens from instalite contract. + * @param vaultAddress Address of vaultAddress Contract. * @param amt The amount of the token to withdraw. * @param to The address of the account on behalf of you want to withdraw. - * @param instaLite Address of instaLite Contract. * @param getId ID to retrieve amt. - * @param setId ID stores the amount of token withdrawn. + * @param setIds ID stores the amount of token withdrawn. */ function withdraw( + address vaultAddress, uint256 amt, address to, - address instaLite, uint256 getId, - uint256[] memory setId + uint256[] memory setIds ) external payable @@ -92,15 +92,22 @@ abstract contract InstaLiteConnector is Events, Basic { { uint256 _amt = getUint(getId, amt); - instaLiteInterface instaLiteInstance = instaLiteInterface(instaLite); + instaLiteInterface instaLiteInstance = instaLiteInterface(vaultAddress); uint256 vTokenAmt = instaLiteInstance.withdraw(_amt, to); - setUint(setId[0], _amt); - setUint(setId[1], vTokenAmt); + setUint(setIds[0], _amt); + setUint(setIds[1], vTokenAmt); - _eventName = "LogWithdraw(uint256,uint256,address,address,uint256,uint256[])"; - _eventParam = abi.encode(_amt, vTokenAmt, to, instaLite, getId, setId); + _eventName = "LogWithdraw(address,uint256,uint256,address,uint256,uint256[])"; + _eventParam = abi.encode( + vaultAddress, + _amt, + vTokenAmt, + to, + getId, + setIds + ); } } From 04930d454929bb667065ae9fce019afcddee6857 Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Sat, 2 Apr 2022 23:57:09 +0530 Subject: [PATCH 08/19] minor fix --- contracts/mainnet/connectors/instaLite/main.sol | 5 ----- 1 file changed, 5 deletions(-) diff --git a/contracts/mainnet/connectors/instaLite/main.sol b/contracts/mainnet/connectors/instaLite/main.sol index d91c8418..d68de918 100644 --- a/contracts/mainnet/connectors/instaLite/main.sol +++ b/contracts/mainnet/connectors/instaLite/main.sol @@ -99,7 +99,6 @@ abstract contract InstaLiteConnector is Events, Basic { setUint(setIds[0], _amt); setUint(setIds[1], vTokenAmt); -<<<<<<< HEAD:contracts/mainnet/connectors/instaLite/main.sol _eventName = "LogWithdraw(address,uint256,uint256,address,uint256,uint256[])"; _eventParam = abi.encode( vaultAddress, @@ -109,10 +108,6 @@ abstract contract InstaLiteConnector is Events, Basic { getId, setIds ); -======= - _eventName = "LogWithdraw(uint256,uint256,address,address,uint256,uint256[])"; - _eventParam = abi.encode(_amt, vTokenAmt, to, instaLite, getId, setId); ->>>>>>> 8c668e6e2be93ef418eae3104cb4ee4c39f762b6:contracts/mainnet/connectors/instaLite/vault1/main.sol } } From 1241e35690812193514bd8f6e1fa28e89ae77cc0 Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Sat, 2 Apr 2022 23:59:04 +0530 Subject: [PATCH 09/19] removed dsmath import --- contracts/mainnet/connectors/instaLite/main.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/mainnet/connectors/instaLite/main.sol b/contracts/mainnet/connectors/instaLite/main.sol index d68de918..5003950d 100644 --- a/contracts/mainnet/connectors/instaLite/main.sol +++ b/contracts/mainnet/connectors/instaLite/main.sol @@ -7,7 +7,6 @@ pragma solidity ^0.7.0; */ import { TokenInterface } from "../../common/interfaces.sol"; -import { DSMath } from "../../common/math.sol"; import { Basic } from "../../common/basic.sol"; import { Events } from "./events.sol"; import { instaLiteInterface } from "./interface.sol"; From bf55464ce06d16b680c81c4fbf6eee4b175f13fe Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Sun, 3 Apr 2022 00:02:38 +0530 Subject: [PATCH 10/19] formatted code --- contracts/mainnet/connectors/instaLite/interface.sol | 2 +- contracts/mainnet/connectors/instaLite/main.sol | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/contracts/mainnet/connectors/instaLite/interface.sol b/contracts/mainnet/connectors/instaLite/interface.sol index 1024fee0..8f50de96 100644 --- a/contracts/mainnet/connectors/instaLite/interface.sol +++ b/contracts/mainnet/connectors/instaLite/interface.sol @@ -1,7 +1,7 @@ //SPDX-License-Identifier: MIT pragma solidity ^0.7.0; -interface instaLiteInterface { +interface IInstaLite { function supplyEth(address to_) external payable returns (uint256); function supply( diff --git a/contracts/mainnet/connectors/instaLite/main.sol b/contracts/mainnet/connectors/instaLite/main.sol index 5003950d..3092e1f7 100644 --- a/contracts/mainnet/connectors/instaLite/main.sol +++ b/contracts/mainnet/connectors/instaLite/main.sol @@ -9,7 +9,7 @@ pragma solidity ^0.7.0; import { TokenInterface } from "../../common/interfaces.sol"; import { Basic } from "../../common/basic.sol"; import { Events } from "./events.sol"; -import { instaLiteInterface } from "./interface.sol"; +import { IInstaLite } from "./interface.sol"; abstract contract InstaLiteConnector is Events, Basic { /** @@ -38,11 +38,11 @@ abstract contract InstaLiteConnector is Events, Basic { bool isEth = token == ethAddr; uint256 vTokenAmt; - instaLiteInterface instaLiteInstance = instaLiteInterface(vaultAddress); + IInstaLite instaLite = IInstaLite(vaultAddress); if (isEth) { _amt = _amt == uint256(-1) ? address(this).balance : _amt; - vTokenAmt = instaLiteInstance.supplyEth{ value: amt }(to); + vTokenAmt = instaLite.supplyEth{ value: amt }(to); } else { TokenInterface tokenContract = TokenInterface(token); @@ -51,7 +51,7 @@ abstract contract InstaLiteConnector is Events, Basic { : _amt; approve(tokenContract, vaultAddress, _amt); - vTokenAmt = instaLiteInstance.supply(token, _amt, to); + vTokenAmt = instaLite.supply(token, _amt, to); } setUint(setIds[0], _amt); @@ -91,9 +91,9 @@ abstract contract InstaLiteConnector is Events, Basic { { uint256 _amt = getUint(getId, amt); - instaLiteInterface instaLiteInstance = instaLiteInterface(vaultAddress); + IInstaLite instaLite = IInstaLite(vaultAddress); - uint256 vTokenAmt = instaLiteInstance.withdraw(_amt, to); + uint256 vTokenAmt = instaLite.withdraw(_amt, to); setUint(setIds[0], _amt); setUint(setIds[1], vTokenAmt); From 34802d0dc77aa9204a76a0bf44a0a49bfa52808b Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Sun, 3 Apr 2022 03:31:38 +0530 Subject: [PATCH 11/19] removed to param --- .../mainnet/connectors/instaLite/events.sol | 2 -- .../mainnet/connectors/instaLite/main.sol | 24 +++++-------------- test/mainnet/instaLite/instaLite.test.ts | 4 ++-- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/contracts/mainnet/connectors/instaLite/events.sol b/contracts/mainnet/connectors/instaLite/events.sol index e83bafdb..12553d7a 100644 --- a/contracts/mainnet/connectors/instaLite/events.sol +++ b/contracts/mainnet/connectors/instaLite/events.sol @@ -7,7 +7,6 @@ contract Events { address token, uint256 vTokenAmt, uint256 amt, - address to, uint256 getId, uint256[] setIds ); @@ -15,7 +14,6 @@ contract Events { address vaultAddress, uint256 amt, uint256 vTokenAmt, - address to, uint256 getId, uint256[] setIds ); diff --git a/contracts/mainnet/connectors/instaLite/main.sol b/contracts/mainnet/connectors/instaLite/main.sol index 3092e1f7..a876c3be 100644 --- a/contracts/mainnet/connectors/instaLite/main.sol +++ b/contracts/mainnet/connectors/instaLite/main.sol @@ -18,7 +18,6 @@ abstract contract InstaLiteConnector is Events, Basic { * @param vaultAddress Address of instaLite Contract. * @param token The address of token to be supplied. * @param amt The amount of token to be supplied. - * @param to The address of the account on behalf of you want to supplied. * @param getId ID to retrieve amt. * @param setIds ID stores the amount of token deposited. */ @@ -26,7 +25,6 @@ abstract contract InstaLiteConnector is Events, Basic { address vaultAddress, address token, uint256 amt, - address to, uint256 getId, uint256[] memory setIds ) @@ -42,7 +40,7 @@ abstract contract InstaLiteConnector is Events, Basic { if (isEth) { _amt = _amt == uint256(-1) ? address(this).balance : _amt; - vTokenAmt = instaLite.supplyEth{ value: amt }(to); + vTokenAmt = instaLite.supplyEth{ value: amt }(address(this)); } else { TokenInterface tokenContract = TokenInterface(token); @@ -51,19 +49,18 @@ abstract contract InstaLiteConnector is Events, Basic { : _amt; approve(tokenContract, vaultAddress, _amt); - vTokenAmt = instaLite.supply(token, _amt, to); + vTokenAmt = instaLite.supply(token, _amt, address(this)); } setUint(setIds[0], _amt); setUint(setIds[1], vTokenAmt); - _eventName = "LogSupply(address,address,uint256,uint256,address,uint256,uint256[])"; + _eventName = "LogSupply(address,address,uint256,uint256,uint256,uint256[])"; _eventParam = abi.encode( vaultAddress, token, vTokenAmt, _amt, - to, getId, setIds ); @@ -74,14 +71,12 @@ abstract contract InstaLiteConnector is Events, Basic { * @notice Withdraw eth/stEth tokens from instalite contract. * @param vaultAddress Address of vaultAddress Contract. * @param amt The amount of the token to withdraw. - * @param to The address of the account on behalf of you want to withdraw. * @param getId ID to retrieve amt. * @param setIds ID stores the amount of token withdrawn. */ function withdraw( address vaultAddress, uint256 amt, - address to, uint256 getId, uint256[] memory setIds ) @@ -93,20 +88,13 @@ abstract contract InstaLiteConnector is Events, Basic { IInstaLite instaLite = IInstaLite(vaultAddress); - uint256 vTokenAmt = instaLite.withdraw(_amt, to); + uint256 vTokenAmt = instaLite.withdraw(_amt, address(this)); setUint(setIds[0], _amt); setUint(setIds[1], vTokenAmt); - _eventName = "LogWithdraw(address,uint256,uint256,address,uint256,uint256[])"; - _eventParam = abi.encode( - vaultAddress, - _amt, - vTokenAmt, - to, - getId, - setIds - ); + _eventName = "LogWithdraw(address,uint256,uint256,uint256,uint256[])"; + _eventParam = abi.encode(vaultAddress, _amt, vTokenAmt, getId, setIds); } } diff --git a/test/mainnet/instaLite/instaLite.test.ts b/test/mainnet/instaLite/instaLite.test.ts index 524dabea..a08847e3 100644 --- a/test/mainnet/instaLite/instaLite.test.ts +++ b/test/mainnet/instaLite/instaLite.test.ts @@ -77,7 +77,7 @@ describe("instaLite", function () { { connector: connectorName, method: "supply", - args: [ethAddr, _amt, dsaWallet0.address, "0xc383a3833a87009fd9597f8184979af5edfad019", 0, [0, 0]] + args: ["0xc383a3833a87009fd9597f8184979af5edfad019", ethAddr, _amt, 0, [0, 0]] } ]; const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet1.getAddress()); @@ -91,7 +91,7 @@ describe("instaLite", function () { { connector: connectorName, method: "withdraw", - args: [_amt, dsaWallet0.address, "0xc383a3833a87009fd9597f8184979af5edfad019", 0, [0, 0]] + args: ["0xc383a3833a87009fd9597f8184979af5edfad019", _amt, 0, [0, 0]] } ]; const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), await wallet1.getAddress()); From 3f9ca9c8904946bda7071c62b20762594bc2aaa5 Mon Sep 17 00:00:00 2001 From: Thrilok kumar Date: Sun, 3 Apr 2022 03:50:21 +0530 Subject: [PATCH 12/19] Update contracts/mainnet/connectors/instaLite/main.sol --- contracts/mainnet/connectors/instaLite/main.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/mainnet/connectors/instaLite/main.sol b/contracts/mainnet/connectors/instaLite/main.sol index a876c3be..8d73ef91 100644 --- a/contracts/mainnet/connectors/instaLite/main.sol +++ b/contracts/mainnet/connectors/instaLite/main.sol @@ -67,12 +67,12 @@ abstract contract InstaLiteConnector is Events, Basic { } /** - * @dev Withdraw - * @notice Withdraw eth/stEth tokens from instalite contract. + * @dev Withdraw ETH/ERC20 + * @notice Withdraw deposited tokens from Instalite. * @param vaultAddress Address of vaultAddress Contract. * @param amt The amount of the token to withdraw. * @param getId ID to retrieve amt. - * @param setIds ID stores the amount of token withdrawn. + * @param setIds array of IDs to stores the amount of tokens withdrawn. */ function withdraw( address vaultAddress, From 2bca7d70b09f78aeee00b189791a3402cd4af077 Mon Sep 17 00:00:00 2001 From: Thrilok kumar Date: Sun, 3 Apr 2022 03:50:29 +0530 Subject: [PATCH 13/19] Update contracts/mainnet/connectors/instaLite/main.sol --- contracts/mainnet/connectors/instaLite/main.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/mainnet/connectors/instaLite/main.sol b/contracts/mainnet/connectors/instaLite/main.sol index 8d73ef91..d102b68b 100644 --- a/contracts/mainnet/connectors/instaLite/main.sol +++ b/contracts/mainnet/connectors/instaLite/main.sol @@ -13,11 +13,11 @@ import { IInstaLite } from "./interface.sol"; abstract contract InstaLiteConnector is Events, Basic { /** - * @dev Supply - * @notice Supply eth/weth/stEth tokens into instalite. + * @dev Supply ETH/ERC20 + * @notice Supply a token into Instalite. * @param vaultAddress Address of instaLite Contract. - * @param token The address of token to be supplied. - * @param amt The amount of token to be supplied. + * @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 ID stores the amount of token deposited. */ From eb96ae86863f2ca367dffa02e4d236a303eda834 Mon Sep 17 00:00:00 2001 From: Thrilok kumar Date: Sun, 3 Apr 2022 03:50:41 +0530 Subject: [PATCH 14/19] Update contracts/mainnet/connectors/instaLite/main.sol --- contracts/mainnet/connectors/instaLite/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/instaLite/main.sol b/contracts/mainnet/connectors/instaLite/main.sol index d102b68b..16e802af 100644 --- a/contracts/mainnet/connectors/instaLite/main.sol +++ b/contracts/mainnet/connectors/instaLite/main.sol @@ -19,7 +19,7 @@ abstract contract InstaLiteConnector is Events, Basic { * @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 ID stores the amount of token deposited. + * @param setIds array of IDs to store the amount of tokens deposited. */ function supply( address vaultAddress, From 373dcf59afa24626dfb6835acba25a02f2365e0d Mon Sep 17 00:00:00 2001 From: Thrilok kumar Date: Sun, 3 Apr 2022 03:50:49 +0530 Subject: [PATCH 15/19] Update contracts/mainnet/connectors/instaLite/main.sol --- contracts/mainnet/connectors/instaLite/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/instaLite/main.sol b/contracts/mainnet/connectors/instaLite/main.sol index 16e802af..65680916 100644 --- a/contracts/mainnet/connectors/instaLite/main.sol +++ b/contracts/mainnet/connectors/instaLite/main.sol @@ -99,5 +99,5 @@ abstract contract InstaLiteConnector is Events, Basic { } contract ConnectV2InstaLiteVault1 is InstaLiteConnector { - string public constant name = "instaLite-v1"; + string public constant name = "InstaLite-v1"; } From b191ac171057ea5c69bbf7048954030be17b9fed Mon Sep 17 00:00:00 2001 From: Samyak Jain <34437877+KaymasJain@users.noreply.github.com> Date: Wed, 6 Apr 2022 06:27:57 +0400 Subject: [PATCH 16/19] added deleverage function in lite --- .../connectors/instaLite/interface.sol | 4 ++ .../mainnet/connectors/instaLite/main.sol | 63 ++++++++++++++----- 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/contracts/mainnet/connectors/instaLite/interface.sol b/contracts/mainnet/connectors/instaLite/interface.sol index 8f50de96..ae20fed4 100644 --- a/contracts/mainnet/connectors/instaLite/interface.sol +++ b/contracts/mainnet/connectors/instaLite/interface.sol @@ -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; + } diff --git a/contracts/mainnet/connectors/instaLite/main.sol b/contracts/mainnet/connectors/instaLite/main.sol index 65680916..24045709 100644 --- a/contracts/mainnet/connectors/instaLite/main.sol +++ b/contracts/mainnet/connectors/instaLite/main.sol @@ -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); } } From 73a76c34675e95a8b2bcf5e3629c4081f0a91f61 Mon Sep 17 00:00:00 2001 From: Samyak Jain <34437877+KaymasJain@users.noreply.github.com> Date: Wed, 6 Apr 2022 06:32:56 +0400 Subject: [PATCH 17/19] minor text update --- contracts/mainnet/connectors/instaLite/main.sol | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/contracts/mainnet/connectors/instaLite/main.sol b/contracts/mainnet/connectors/instaLite/main.sol index 24045709..539cbbb7 100644 --- a/contracts/mainnet/connectors/instaLite/main.sol +++ b/contracts/mainnet/connectors/instaLite/main.sol @@ -3,9 +3,9 @@ pragma solidity ^0.7.0; /** * @title InstaLite Connector - * @dev Supply and Withdraw - + * @dev Supply, Withdraw & Deleverage */ + import { TokenInterface } from "../../common/interfaces.sol"; import { Basic } from "../../common/basic.sol"; import { Events } from "./events.sol"; @@ -97,12 +97,12 @@ abstract contract InstaLiteConnector is Events, Basic { } /** - * @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. + * @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. * @param getId ID to retrieve amt. - * @param setId ID to retrieve amt. + * @param setId ID to set amt. */ function deleverage( address vaultAddr, @@ -131,6 +131,7 @@ abstract contract InstaLiteConnector is Events, Basic { _eventName = "LogDeleverage(address,uint256,uint256,uint256)"; _eventParam = abi.encode(vaultAddr, _amt, getId, setId); } + } contract ConnectV2InstaLiteVault1 is InstaLiteConnector { From dafa5e771bd51e6caafbd5a6d11903bf17485a6c Mon Sep 17 00:00:00 2001 From: Vaibhav Khanna Date: Thu, 7 Apr 2022 11:05:05 +0530 Subject: [PATCH 18/19] minor fix --- contracts/mainnet/connectors/instaLite/events.sol | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/contracts/mainnet/connectors/instaLite/events.sol b/contracts/mainnet/connectors/instaLite/events.sol index 12553d7a..6b1e2827 100644 --- a/contracts/mainnet/connectors/instaLite/events.sol +++ b/contracts/mainnet/connectors/instaLite/events.sol @@ -3,7 +3,7 @@ pragma solidity ^0.7.0; contract Events { event LogSupply( - address vaultAddress, + address vaultAddr, address token, uint256 vTokenAmt, uint256 amt, @@ -11,10 +11,17 @@ contract Events { uint256[] setIds ); event LogWithdraw( - address vaultAddress, + address vaultAddr, uint256 amt, uint256 vTokenAmt, uint256 getId, uint256[] setIds ); + + event LogDeleverage( + address vaultAddr, + uint256 amt, + uint256 getId, + uint256 setId + ); } From 3cf25980c71b82f6b92f9e87fe7f5f35f07468df Mon Sep 17 00:00:00 2001 From: Vaibhav Khanna Date: Thu, 7 Apr 2022 22:47:02 +0530 Subject: [PATCH 19/19] fixed name --- contracts/mainnet/connectors/instaLite/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/instaLite/main.sol b/contracts/mainnet/connectors/instaLite/main.sol index 539cbbb7..d366cd69 100644 --- a/contracts/mainnet/connectors/instaLite/main.sol +++ b/contracts/mainnet/connectors/instaLite/main.sol @@ -134,6 +134,6 @@ abstract contract InstaLiteConnector is Events, Basic { } -contract ConnectV2InstaLiteVault1 is InstaLiteConnector { +contract ConnectV2InstaLite is InstaLiteConnector { string public constant name = "InstaLite-v1"; }