From ba770876594ec4c192baa66927c6caed08e3ca03 Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Mon, 7 Mar 2022 00:16:22 +0530 Subject: [PATCH 1/8] added connector --- .../mainnet/connectors/lido_stETH/events.sol | 5 +++ .../mainnet/connectors/lido_stETH/helpers.sol | 10 +++++ .../connectors/lido_stETH/interface.sol | 7 +++ .../mainnet/connectors/lido_stETH/main.sol | 43 +++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 contracts/mainnet/connectors/lido_stETH/events.sol create mode 100644 contracts/mainnet/connectors/lido_stETH/helpers.sol create mode 100644 contracts/mainnet/connectors/lido_stETH/interface.sol create mode 100644 contracts/mainnet/connectors/lido_stETH/main.sol diff --git a/contracts/mainnet/connectors/lido_stETH/events.sol b/contracts/mainnet/connectors/lido_stETH/events.sol new file mode 100644 index 00000000..2259e797 --- /dev/null +++ b/contracts/mainnet/connectors/lido_stETH/events.sol @@ -0,0 +1,5 @@ +pragma solidity ^0.7.0; + +contract Events { + event LogDeposit(uint256 Amt, uint256 getId, uint256 setId); +} diff --git a/contracts/mainnet/connectors/lido_stETH/helpers.sol b/contracts/mainnet/connectors/lido_stETH/helpers.sol new file mode 100644 index 00000000..0bb82b04 --- /dev/null +++ b/contracts/mainnet/connectors/lido_stETH/helpers.sol @@ -0,0 +1,10 @@ +pragma solidity ^0.7.0; + +import { TokenInterface } from "../../common/interfaces.sol"; +import { ILido } from "./interface.sol"; + +abstract contract Helpers { + ILido internal constant lidoInterface = + ILido(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84); +} +//0xC7B5aF82B05Eb3b64F12241B04B2cF14469E39F7 diff --git a/contracts/mainnet/connectors/lido_stETH/interface.sol b/contracts/mainnet/connectors/lido_stETH/interface.sol new file mode 100644 index 00000000..97aaca29 --- /dev/null +++ b/contracts/mainnet/connectors/lido_stETH/interface.sol @@ -0,0 +1,7 @@ +pragma solidity ^0.7.0; + +interface ILido { + function submit(address _referral) external payable returns (uint256); + + function balanceOf(address owner) external view returns (uint256); +} diff --git a/contracts/mainnet/connectors/lido_stETH/main.sol b/contracts/mainnet/connectors/lido_stETH/main.sol new file mode 100644 index 00000000..a3e9191c --- /dev/null +++ b/contracts/mainnet/connectors/lido_stETH/main.sol @@ -0,0 +1,43 @@ +pragma solidity ^0.7.0; + +/** + * @title WETH. + * @dev Wrap and Unwrap WETH. + */ + +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 deposit ETH into Lido. + * @notice sends Eth into lido and in return you get equivalent of stEth tokens + * @param amt The amount of ETH to deposit. (For max: `uint256(-1)`) + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of ETH deposited. + */ + function deposit( + uint256 amt, + uint256 getId, + uint256 setId + ) + public + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amt = getUint(getId, amt); + + _amt = _amt == uint256(-1) ? address(this).balance : _amt; + lidoInterface.submit{ value: amt }(address(0)); + setUint(setId, _amt); + + _eventName = "LogDeposit(uint256,uint256,uint256)"; + _eventParam = abi.encode(_amt, getId, setId); + } +} + +contract ConnectV2LidoStEth is Resolver { + string public constant name = "LidoStEth-v1.0"; +} From 9b7fe509734abcd86e874a6c592ced32f0efa5e9 Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Mon, 7 Mar 2022 00:16:32 +0530 Subject: [PATCH 2/8] added test --- test/mainnet/lido_stETH/abi.json | 731 ++++++++++++++++++++++ test/mainnet/lido_stETH/lidoStEth.test.ts | 103 +++ 2 files changed, 834 insertions(+) create mode 100644 test/mainnet/lido_stETH/abi.json create mode 100644 test/mainnet/lido_stETH/lidoStEth.test.ts diff --git a/test/mainnet/lido_stETH/abi.json b/test/mainnet/lido_stETH/abi.json new file mode 100644 index 00000000..0db94406 --- /dev/null +++ b/test/mainnet/lido_stETH/abi.json @@ -0,0 +1,731 @@ +[ + { + "constant": false, + "inputs": [], + "name": "resume", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [{ "name": "", "type": "string" }], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "stop", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "hasInitialized", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_spender", "type": "address" }, + { "name": "_amount", "type": "uint256" } + ], + "name": "approve", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "depositContract", "type": "address" }, + { "name": "_oracle", "type": "address" }, + { "name": "_operators", "type": "address" }, + { "name": "_treasury", "type": "address" }, + { "name": "_insuranceFund", "type": "address" } + ], + "name": "initialize", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getInsuranceFund", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "_ethAmount", "type": "uint256" }], + "name": "getSharesByPooledEth", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_sender", "type": "address" }, + { "name": "_recipient", "type": "address" }, + { "name": "_amount", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getOperators", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "_script", "type": "bytes" }], + "name": "getEVMScriptExecutor", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [{ "name": "", "type": "uint8" }], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getRecoveryVault", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "DEPOSIT_ROLE", + "outputs": [{ "name": "", "type": "bytes32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "DEPOSIT_SIZE", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getTotalPooledEther", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "PAUSE_ROLE", + "outputs": [{ "name": "", "type": "bytes32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_spender", "type": "address" }, + { "name": "_addedValue", "type": "uint256" } + ], + "name": "increaseAllowance", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getTreasury", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "SET_ORACLE", + "outputs": [{ "name": "", "type": "bytes32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "isStopped", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MANAGE_WITHDRAWAL_KEY", + "outputs": [{ "name": "", "type": "bytes32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getBufferedEther", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "SIGNATURE_LENGTH", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getWithdrawalCredentials", + "outputs": [{ "name": "", "type": "bytes32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "_account", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getFeeDistribution", + "outputs": [ + { "name": "treasuryFeeBasisPoints", "type": "uint16" }, + { "name": "insuranceFeeBasisPoints", "type": "uint16" }, + { "name": "operatorsFeeBasisPoints", "type": "uint16" } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "_sharesAmount", "type": "uint256" }], + "name": "getPooledEthByShares", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_oracle", "type": "address" }], + "name": "setOracle", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "token", "type": "address" }], + "name": "allowRecoverability", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "appId", + "outputs": [{ "name": "", "type": "bytes32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getOracle", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getInitializationBlock", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_treasuryFeeBasisPoints", "type": "uint16" }, + { "name": "_insuranceFeeBasisPoints", "type": "uint16" }, + { "name": "_operatorsFeeBasisPoints", "type": "uint16" } + ], + "name": "setFeeDistribution", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_feeBasisPoints", "type": "uint16" }], + "name": "setFee", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_maxDeposits", "type": "uint256" }], + "name": "depositBufferedEther", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [{ "name": "", "type": "string" }], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MANAGE_FEE", + "outputs": [{ "name": "", "type": "bytes32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_token", "type": "address" }], + "name": "transferToVault", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "SET_TREASURY", + "outputs": [{ "name": "", "type": "bytes32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { "name": "_sender", "type": "address" }, + { "name": "_role", "type": "bytes32" }, + { "name": "_params", "type": "uint256[]" } + ], + "name": "canPerform", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_referral", "type": "address" }], + "name": "submit", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": true, + "stateMutability": "payable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "WITHDRAWAL_CREDENTIALS_LENGTH", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_spender", "type": "address" }, + { "name": "_subtractedValue", "type": "uint256" } + ], + "name": "decreaseAllowance", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getEVMScriptRegistry", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "PUBKEY_LENGTH", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_amount", "type": "uint256" }, + { "name": "_pubkeyHash", "type": "bytes32" } + ], + "name": "withdraw", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_recipient", "type": "address" }, + { "name": "_amount", "type": "uint256" } + ], + "name": "transfer", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getDepositContract", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getBeaconStat", + "outputs": [ + { "name": "depositedValidators", "type": "uint256" }, + { "name": "beaconValidators", "type": "uint256" }, + { "name": "beaconBalance", "type": "uint256" } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "BURN_ROLE", + "outputs": [{ "name": "", "type": "bytes32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_insuranceFund", "type": "address" }], + "name": "setInsuranceFund", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getFee", + "outputs": [{ "name": "feeBasisPoints", "type": "uint16" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "SET_INSURANCE_FUND", + "outputs": [{ "name": "", "type": "bytes32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "kernel", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getTotalShares", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { "name": "_owner", "type": "address" }, + { "name": "_spender", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "isPetrified", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_withdrawalCredentials", "type": "bytes32" }], + "name": "setWithdrawalCredentials", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "depositBufferedEther", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_account", "type": "address" }, + { "name": "_sharesAmount", "type": "uint256" } + ], + "name": "burnShares", + "outputs": [{ "name": "newTotalShares", "type": "uint256" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_treasury", "type": "address" }], + "name": "setTreasury", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_beaconValidators", "type": "uint256" }, + { "name": "_beaconBalance", "type": "uint256" } + ], + "name": "pushBeacon", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "_account", "type": "address" }], + "name": "sharesOf", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { "payable": true, "stateMutability": "payable", "type": "fallback" }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "executor", "type": "address" }, + { "indexed": false, "name": "script", "type": "bytes" }, + { "indexed": false, "name": "input", "type": "bytes" }, + { "indexed": false, "name": "returnData", "type": "bytes" } + ], + "name": "ScriptResult", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "vault", "type": "address" }, + { "indexed": true, "name": "token", "type": "address" }, + { "indexed": false, "name": "amount", "type": "uint256" } + ], + "name": "RecoverToVault", + "type": "event" + }, + { "anonymous": false, "inputs": [], "name": "Stopped", "type": "event" }, + { "anonymous": false, "inputs": [], "name": "Resumed", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "from", "type": "address" }, + { "indexed": true, "name": "to", "type": "address" }, + { "indexed": false, "name": "value", "type": "uint256" } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "owner", "type": "address" }, + { "indexed": true, "name": "spender", "type": "address" }, + { "indexed": false, "name": "value", "type": "uint256" } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "name": "feeBasisPoints", "type": "uint16" }], + "name": "FeeSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "name": "treasuryFeeBasisPoints", "type": "uint16" }, + { "indexed": false, "name": "insuranceFeeBasisPoints", "type": "uint16" }, + { "indexed": false, "name": "operatorsFeeBasisPoints", "type": "uint16" } + ], + "name": "FeeDistributionSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "name": "withdrawalCredentials", "type": "bytes32" }], + "name": "WithdrawalCredentialsSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "sender", "type": "address" }, + { "indexed": false, "name": "amount", "type": "uint256" }, + { "indexed": false, "name": "referral", "type": "address" } + ], + "name": "Submitted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "name": "amount", "type": "uint256" }], + "name": "Unbuffered", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "sender", "type": "address" }, + { "indexed": false, "name": "tokenAmount", "type": "uint256" }, + { "indexed": false, "name": "sentFromBuffer", "type": "uint256" }, + { "indexed": true, "name": "pubkeyHash", "type": "bytes32" }, + { "indexed": false, "name": "etherAmount", "type": "uint256" } + ], + "name": "Withdrawal", + "type": "event" + } +] diff --git a/test/mainnet/lido_stETH/lidoStEth.test.ts b/test/mainnet/lido_stETH/lidoStEth.test.ts new file mode 100644 index 00000000..9cd318cd --- /dev/null +++ b/test/mainnet/lido_stETH/lidoStEth.test.ts @@ -0,0 +1,103 @@ +import hre from "hardhat"; +import axios from "axios"; +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 { abis } from "../../../scripts/constant/abis"; +import { ConnectV2LidoStEth__factory } from "../../../typechain"; +import lido_abi from "./abi.json"; +import type { Signer, Contract } from "ethers"; + +describe("LidoStEth", function() { + const connectorName = "LidoStEth-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: ConnectV2LidoStEth__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 stake the eth", async function() { + const _amt = ethers.utils.parseEther("1"); + const stETHToken = await ethers.getContractAt( + lido_abi, + "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84" + ); + const initialstEthBalance = await stETHToken.balanceOf(dsaWallet0.address) + const spells = [ + { + connector: connectorName, + method: "deposit", + args: [_amt,0,0] + }, + ]; + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), await wallet1.getAddress()); + const receipt = await tx.wait(); + + const finalstEthBalance = await stETHToken.balanceOf(dsaWallet0.address) + expect(finalstEthBalance).to.be.gt(initialstEthBalance); + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte( + ethers.utils.parseEther("9") + ); + }); + }); +}); From 0d7080b8b10095d856b294b37b4f357a539c8682 Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Mon, 7 Mar 2022 00:21:01 +0530 Subject: [PATCH 3/8] minor fix --- contracts/mainnet/connectors/lido_stETH/interface.sol | 2 -- contracts/mainnet/connectors/lido_stETH/main.sol | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/contracts/mainnet/connectors/lido_stETH/interface.sol b/contracts/mainnet/connectors/lido_stETH/interface.sol index 97aaca29..e62520ef 100644 --- a/contracts/mainnet/connectors/lido_stETH/interface.sol +++ b/contracts/mainnet/connectors/lido_stETH/interface.sol @@ -2,6 +2,4 @@ pragma solidity ^0.7.0; interface ILido { function submit(address _referral) external payable returns (uint256); - - function balanceOf(address owner) external view returns (uint256); } diff --git a/contracts/mainnet/connectors/lido_stETH/main.sol b/contracts/mainnet/connectors/lido_stETH/main.sol index a3e9191c..84c84f36 100644 --- a/contracts/mainnet/connectors/lido_stETH/main.sol +++ b/contracts/mainnet/connectors/lido_stETH/main.sol @@ -39,5 +39,5 @@ abstract contract Resolver is Events, DSMath, Basic, Helpers { } contract ConnectV2LidoStEth is Resolver { - string public constant name = "LidoStEth-v1.0"; + string public constant name = "LidoStEth-v1"; } From cb89771f7e2b4d81cec5a7b2c050cd4908e6ac0d Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Mon, 7 Mar 2022 00:39:38 +0530 Subject: [PATCH 4/8] added referral parameter in deposit func --- contracts/mainnet/connectors/lido_stETH/events.sol | 7 ++++++- contracts/mainnet/connectors/lido_stETH/main.sol | 8 +++++--- test/mainnet/lido_stETH/lidoStEth.test.ts | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/contracts/mainnet/connectors/lido_stETH/events.sol b/contracts/mainnet/connectors/lido_stETH/events.sol index 2259e797..60ef8ab8 100644 --- a/contracts/mainnet/connectors/lido_stETH/events.sol +++ b/contracts/mainnet/connectors/lido_stETH/events.sol @@ -1,5 +1,10 @@ pragma solidity ^0.7.0; contract Events { - event LogDeposit(uint256 Amt, uint256 getId, uint256 setId); + event LogDeposit( + uint256 Amt, + address referral, + uint256 getId, + uint256 setId + ); } diff --git a/contracts/mainnet/connectors/lido_stETH/main.sol b/contracts/mainnet/connectors/lido_stETH/main.sol index 84c84f36..d833a738 100644 --- a/contracts/mainnet/connectors/lido_stETH/main.sol +++ b/contracts/mainnet/connectors/lido_stETH/main.sol @@ -15,11 +15,13 @@ abstract contract Resolver is Events, DSMath, Basic, Helpers { * @dev deposit ETH into Lido. * @notice sends Eth into lido and in return you get equivalent of stEth tokens * @param amt The amount of ETH to deposit. (For max: `uint256(-1)`) + * @param referral optional referral parameter * @param getId ID to retrieve amt. * @param setId ID stores the amount of ETH deposited. */ function deposit( uint256 amt, + address referral, uint256 getId, uint256 setId ) @@ -30,11 +32,11 @@ abstract contract Resolver is Events, DSMath, Basic, Helpers { uint256 _amt = getUint(getId, amt); _amt = _amt == uint256(-1) ? address(this).balance : _amt; - lidoInterface.submit{ value: amt }(address(0)); + lidoInterface.submit{ value: amt }(referral); setUint(setId, _amt); - _eventName = "LogDeposit(uint256,uint256,uint256)"; - _eventParam = abi.encode(_amt, getId, setId); + _eventName = "LogDeposit(uint256,address,uint256,uint256)"; + _eventParam = abi.encode(_amt, referral, getId, setId); } } diff --git a/test/mainnet/lido_stETH/lidoStEth.test.ts b/test/mainnet/lido_stETH/lidoStEth.test.ts index 9cd318cd..3467a119 100644 --- a/test/mainnet/lido_stETH/lidoStEth.test.ts +++ b/test/mainnet/lido_stETH/lidoStEth.test.ts @@ -85,7 +85,7 @@ describe("LidoStEth", function() { { connector: connectorName, method: "deposit", - args: [_amt,0,0] + args: [_amt,"0x0000000000000000000000000000000000000000",0,0] }, ]; const tx = await dsaWallet0 From 2d308f2e3555a3bb319b31d67d6ba3d84a58e5f4 Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Mon, 7 Mar 2022 01:00:45 +0530 Subject: [PATCH 5/8] removed referral param --- contracts/mainnet/connectors/lido_stETH/events.sol | 7 +------ contracts/mainnet/connectors/lido_stETH/helpers.sol | 2 ++ contracts/mainnet/connectors/lido_stETH/main.sol | 8 +++----- test/mainnet/lido_stETH/lidoStEth.test.ts | 2 +- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/contracts/mainnet/connectors/lido_stETH/events.sol b/contracts/mainnet/connectors/lido_stETH/events.sol index 60ef8ab8..2259e797 100644 --- a/contracts/mainnet/connectors/lido_stETH/events.sol +++ b/contracts/mainnet/connectors/lido_stETH/events.sol @@ -1,10 +1,5 @@ pragma solidity ^0.7.0; contract Events { - event LogDeposit( - uint256 Amt, - address referral, - uint256 getId, - uint256 setId - ); + event LogDeposit(uint256 Amt, uint256 getId, uint256 setId); } diff --git a/contracts/mainnet/connectors/lido_stETH/helpers.sol b/contracts/mainnet/connectors/lido_stETH/helpers.sol index 0bb82b04..84a7d016 100644 --- a/contracts/mainnet/connectors/lido_stETH/helpers.sol +++ b/contracts/mainnet/connectors/lido_stETH/helpers.sol @@ -6,5 +6,7 @@ import { ILido } from "./interface.sol"; abstract contract Helpers { ILido internal constant lidoInterface = ILido(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84); + + address treasury = 0x28849D2b63fA8D361e5fc15cB8aBB13019884d09; // Instadapp's treasury address } //0xC7B5aF82B05Eb3b64F12241B04B2cF14469E39F7 diff --git a/contracts/mainnet/connectors/lido_stETH/main.sol b/contracts/mainnet/connectors/lido_stETH/main.sol index d833a738..e97f0e9f 100644 --- a/contracts/mainnet/connectors/lido_stETH/main.sol +++ b/contracts/mainnet/connectors/lido_stETH/main.sol @@ -15,13 +15,11 @@ abstract contract Resolver is Events, DSMath, Basic, Helpers { * @dev deposit ETH into Lido. * @notice sends Eth into lido and in return you get equivalent of stEth tokens * @param amt The amount of ETH to deposit. (For max: `uint256(-1)`) - * @param referral optional referral parameter * @param getId ID to retrieve amt. * @param setId ID stores the amount of ETH deposited. */ function deposit( uint256 amt, - address referral, uint256 getId, uint256 setId ) @@ -32,11 +30,11 @@ abstract contract Resolver is Events, DSMath, Basic, Helpers { uint256 _amt = getUint(getId, amt); _amt = _amt == uint256(-1) ? address(this).balance : _amt; - lidoInterface.submit{ value: amt }(referral); + lidoInterface.submit{ value: amt }(treasury); setUint(setId, _amt); - _eventName = "LogDeposit(uint256,address,uint256,uint256)"; - _eventParam = abi.encode(_amt, referral, getId, setId); + _eventName = "LogDeposit(uint256,uint256,uint256)"; + _eventParam = abi.encode(_amt, getId, setId); } } diff --git a/test/mainnet/lido_stETH/lidoStEth.test.ts b/test/mainnet/lido_stETH/lidoStEth.test.ts index 3467a119..9cd318cd 100644 --- a/test/mainnet/lido_stETH/lidoStEth.test.ts +++ b/test/mainnet/lido_stETH/lidoStEth.test.ts @@ -85,7 +85,7 @@ describe("LidoStEth", function() { { connector: connectorName, method: "deposit", - args: [_amt,"0x0000000000000000000000000000000000000000",0,0] + args: [_amt,0,0] }, ]; const tx = await dsaWallet0 From f1b4892cb5d3409d513cf171c8e157149ae06020 Mon Sep 17 00:00:00 2001 From: 0xBhavik <62445791+bhavik-m@users.noreply.github.com> Date: Sat, 12 Mar 2022 21:21:43 +0530 Subject: [PATCH 6/8] Update contracts/mainnet/connectors/lido_stETH/helpers.sol Co-authored-by: Thrilok kumar --- contracts/mainnet/connectors/lido_stETH/helpers.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/mainnet/connectors/lido_stETH/helpers.sol b/contracts/mainnet/connectors/lido_stETH/helpers.sol index 84a7d016..9764aaf4 100644 --- a/contracts/mainnet/connectors/lido_stETH/helpers.sol +++ b/contracts/mainnet/connectors/lido_stETH/helpers.sol @@ -9,4 +9,3 @@ abstract contract Helpers { address treasury = 0x28849D2b63fA8D361e5fc15cB8aBB13019884d09; // Instadapp's treasury address } -//0xC7B5aF82B05Eb3b64F12241B04B2cF14469E39F7 From 6ddb5ffa190c51864cfc41b1aeaa4322ee14cce3 Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Sat, 12 Mar 2022 21:24:57 +0530 Subject: [PATCH 7/8] lido-stakeEth --- contracts/mainnet/connectors/lido_stETH/helpers.sol | 1 - contracts/mainnet/connectors/lido_stETH/main.sol | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/contracts/mainnet/connectors/lido_stETH/helpers.sol b/contracts/mainnet/connectors/lido_stETH/helpers.sol index 84a7d016..9764aaf4 100644 --- a/contracts/mainnet/connectors/lido_stETH/helpers.sol +++ b/contracts/mainnet/connectors/lido_stETH/helpers.sol @@ -9,4 +9,3 @@ abstract contract Helpers { address treasury = 0x28849D2b63fA8D361e5fc15cB8aBB13019884d09; // Instadapp's treasury address } -//0xC7B5aF82B05Eb3b64F12241B04B2cF14469E39F7 diff --git a/contracts/mainnet/connectors/lido_stETH/main.sol b/contracts/mainnet/connectors/lido_stETH/main.sol index e97f0e9f..bb8ff9f8 100644 --- a/contracts/mainnet/connectors/lido_stETH/main.sol +++ b/contracts/mainnet/connectors/lido_stETH/main.sol @@ -1,8 +1,8 @@ pragma solidity ^0.7.0; /** - * @title WETH. - * @dev Wrap and Unwrap WETH. + * @title Stake Eth. + * @dev deposit Eth into lido and in return you get equivalent of stEth tokens */ import { DSMath } from "../../common/math.sol"; From 00e6f1677ffde4a7bfe66f39b56792d73819b2aa Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Sat, 12 Mar 2022 23:37:56 +0530 Subject: [PATCH 8/8] updated storage variable to constant --- contracts/mainnet/connectors/lido_stETH/helpers.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/mainnet/connectors/lido_stETH/helpers.sol b/contracts/mainnet/connectors/lido_stETH/helpers.sol index 9764aaf4..a7388947 100644 --- a/contracts/mainnet/connectors/lido_stETH/helpers.sol +++ b/contracts/mainnet/connectors/lido_stETH/helpers.sol @@ -7,5 +7,6 @@ abstract contract Helpers { ILido internal constant lidoInterface = ILido(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84); - address treasury = 0x28849D2b63fA8D361e5fc15cB8aBB13019884d09; // Instadapp's treasury address + address internal constant treasury = + 0x28849D2b63fA8D361e5fc15cB8aBB13019884d09; // Instadapp's treasury address }