From 83a34cd632637a1e8677b65bc8ae564d0ddd81e0 Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Sat, 2 Oct 2021 21:37:42 +0530 Subject: [PATCH 01/16] Added Fantom connectors --- contracts/fantom/common/basic.sol | 54 ++++++++++++ contracts/fantom/common/interfaces.sol | 22 +++++ contracts/fantom/common/math.sol | 50 +++++++++++ contracts/fantom/common/stores.sol | 37 +++++++++ .../fantom/connectors/authority/events.sol | 6 ++ .../fantom/connectors/authority/helpers.sol | 15 ++++ .../fantom/connectors/authority/interface.sol | 13 +++ .../fantom/connectors/authority/main.sol | 45 ++++++++++ contracts/fantom/connectors/basic/events.sol | 6 ++ contracts/fantom/connectors/basic/main.sol | 82 +++++++++++++++++++ contracts/fantom/connectors/wftm/events.sol | 6 ++ contracts/fantom/connectors/wftm/helpers.sol | 8 ++ contracts/fantom/connectors/wftm/main.sol | 65 +++++++++++++++ hardhat.config.js | 7 ++ scripts/deploy.js | 26 +++--- scripts/deployConnector.js | 15 ++-- 16 files changed, 437 insertions(+), 20 deletions(-) create mode 100644 contracts/fantom/common/basic.sol create mode 100644 contracts/fantom/common/interfaces.sol create mode 100644 contracts/fantom/common/math.sol create mode 100644 contracts/fantom/common/stores.sol create mode 100644 contracts/fantom/connectors/authority/events.sol create mode 100644 contracts/fantom/connectors/authority/helpers.sol create mode 100644 contracts/fantom/connectors/authority/interface.sol create mode 100644 contracts/fantom/connectors/authority/main.sol create mode 100644 contracts/fantom/connectors/basic/events.sol create mode 100644 contracts/fantom/connectors/basic/main.sol create mode 100644 contracts/fantom/connectors/wftm/events.sol create mode 100644 contracts/fantom/connectors/wftm/helpers.sol create mode 100644 contracts/fantom/connectors/wftm/main.sol diff --git a/contracts/fantom/common/basic.sol b/contracts/fantom/common/basic.sol new file mode 100644 index 00000000..007e3e1c --- /dev/null +++ b/contracts/fantom/common/basic.sol @@ -0,0 +1,54 @@ +pragma solidity ^0.7.0; + +import { TokenInterface } from "./interfaces.sol"; +import { Stores } from "./stores.sol"; +import { DSMath } from "./math.sol"; + +abstract contract Basic is DSMath, Stores { + + function convert18ToDec(uint _dec, uint256 _amt) internal pure returns (uint256 amt) { + amt = (_amt / 10 ** (18 - _dec)); + } + + function convertTo18(uint _dec, uint256 _amt) internal pure returns (uint256 amt) { + amt = mul(_amt, 10 ** (18 - _dec)); + } + + function getTokenBal(TokenInterface token) internal view returns(uint _amt) { + _amt = address(token) == ftmAddr ? address(this).balance : token.balanceOf(address(this)); + } + + function getTokensDec(TokenInterface buyAddr, TokenInterface sellAddr) internal view returns(uint buyDec, uint sellDec) { + buyDec = address(buyAddr) == ftmAddr ? 18 : buyAddr.decimals(); + sellDec = address(sellAddr) == ftmAddr ? 18 : sellAddr.decimals(); + } + + function encodeEvent(string memory eventName, bytes memory eventParam) internal pure returns (bytes memory) { + return abi.encode(eventName, eventParam); + } + + function approve(TokenInterface token, address spender, uint256 amount) internal { + try token.approve(spender, amount) { + + } catch { + token.approve(spender, 0); + token.approve(spender, amount); + } + } + + function changeftmAddress(address buy, address sell) internal pure returns(TokenInterface _buy, TokenInterface _sell){ + _buy = buy == ftmAddr ? TokenInterface(wftmAddr) : TokenInterface(buy); + _sell = sell == ftmAddr ? TokenInterface(wftmAddr) : TokenInterface(sell); + } + + function convertEthToWeth(bool isEth, TokenInterface token, uint amount) internal { + if(isEth) token.deposit{value: amount}(); + } + + function convertWethToEth(bool isEth, TokenInterface token, uint amount) internal { + if(isEth) { + approve(token, address(token), amount); + token.withdraw(amount); + } + } +} \ No newline at end of file diff --git a/contracts/fantom/common/interfaces.sol b/contracts/fantom/common/interfaces.sol new file mode 100644 index 00000000..ea9c362d --- /dev/null +++ b/contracts/fantom/common/interfaces.sol @@ -0,0 +1,22 @@ +pragma solidity ^0.7.0; + +interface TokenInterface { + function approve(address, uint256) external; + function transfer(address, uint) external; + function transferFrom(address, address, uint) external; + function deposit() external payable; + function withdraw(uint) external; + function balanceOf(address) external view returns (uint); + function decimals() external view returns (uint); +} + +interface MemoryInterface { + function getUint(uint id) external returns (uint num); + function setUint(uint id, uint val) external; +} + +interface AccountInterface { + function enable(address) external; + function disable(address) external; + function isAuth(address) external view returns (bool); +} diff --git a/contracts/fantom/common/math.sol b/contracts/fantom/common/math.sol new file mode 100644 index 00000000..f6e2e6cd --- /dev/null +++ b/contracts/fantom/common/math.sol @@ -0,0 +1,50 @@ +pragma solidity ^0.7.0; + +import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; + +contract DSMath { + uint constant WAD = 10 ** 18; + uint constant RAY = 10 ** 27; + + function add(uint x, uint y) internal pure returns (uint z) { + z = SafeMath.add(x, y); + } + + function sub(uint x, uint y) internal virtual pure returns (uint z) { + z = SafeMath.sub(x, y); + } + + function mul(uint x, uint y) internal pure returns (uint z) { + z = SafeMath.mul(x, y); + } + + function div(uint x, uint y) internal pure returns (uint z) { + z = SafeMath.div(x, y); + } + + function wmul(uint x, uint y) internal pure returns (uint z) { + z = SafeMath.add(SafeMath.mul(x, y), WAD / 2) / WAD; + } + + function wdiv(uint x, uint y) internal pure returns (uint z) { + z = SafeMath.add(SafeMath.mul(x, WAD), y / 2) / y; + } + + function rdiv(uint x, uint y) internal pure returns (uint z) { + z = SafeMath.add(SafeMath.mul(x, RAY), y / 2) / y; + } + + function rmul(uint x, uint y) internal pure returns (uint z) { + z = SafeMath.add(SafeMath.mul(x, y), RAY / 2) / RAY; + } + + function toInt(uint x) internal pure returns (int y) { + y = int(x); + require(y >= 0, "int-overflow"); + } + + function toRad(uint wad) internal pure returns (uint rad) { + rad = mul(wad, 10 ** 27); + } + +} diff --git a/contracts/fantom/common/stores.sol b/contracts/fantom/common/stores.sol new file mode 100644 index 00000000..ab93ef75 --- /dev/null +++ b/contracts/fantom/common/stores.sol @@ -0,0 +1,37 @@ +pragma solidity ^0.7.0; + +import { MemoryInterface } from "./interfaces.sol"; + + +abstract contract Stores { + + /** + * @dev Return FTM address + */ + address constant internal ftmAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; + + /** + * @dev Return Wrapped FTM address + */ + address constant internal wftmAddr = 0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83; + + /** + * @dev Return memory variable address + */ + MemoryInterface constant internal instaMemory = MemoryInterface(0x56439117379A53bE3CC2C55217251e2481B7a1C8); + + /** + * @dev Get Uint value from InstaMemory Contract. + */ + function getUint(uint getId, uint val) internal returns (uint returnVal) { + returnVal = getId == 0 ? val : instaMemory.getUint(getId); + } + + /** + * @dev Set Uint value in InstaMemory Contract. + */ + function setUint(uint setId, uint val) virtual internal { + if (setId != 0) instaMemory.setUint(setId, val); + } + +} diff --git a/contracts/fantom/connectors/authority/events.sol b/contracts/fantom/connectors/authority/events.sol new file mode 100644 index 00000000..1ad38da7 --- /dev/null +++ b/contracts/fantom/connectors/authority/events.sol @@ -0,0 +1,6 @@ +pragma solidity ^0.7.0; + +contract Events { + event LogAddAuth(address indexed _msgSender, address indexed _authority); + event LogRemoveAuth(address indexed _msgSender, address indexed _authority); +} \ No newline at end of file diff --git a/contracts/fantom/connectors/authority/helpers.sol b/contracts/fantom/connectors/authority/helpers.sol new file mode 100644 index 00000000..e1f8abef --- /dev/null +++ b/contracts/fantom/connectors/authority/helpers.sol @@ -0,0 +1,15 @@ +pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; + +import { DSMath } from "../../common/math.sol"; +import { Basic } from "../../common/basic.sol"; +import { ListInterface } from "./interface.sol"; + +abstract contract Helpers is DSMath, Basic { + ListInterface internal constant listContract = ListInterface(0x3565F6057b7fFE36984779A507fC87b31EFb0f09); + + function checkAuthCount() internal view returns (uint count) { + uint64 accountId = listContract.accountID(address(this)); + count = listContract.accountLink(accountId).count; + } +} diff --git a/contracts/fantom/connectors/authority/interface.sol b/contracts/fantom/connectors/authority/interface.sol new file mode 100644 index 00000000..5b7fde6d --- /dev/null +++ b/contracts/fantom/connectors/authority/interface.sol @@ -0,0 +1,13 @@ +pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; + +interface ListInterface { + struct AccountLink { + address first; + address last; + uint64 count; + } + + function accountID(address) external view returns (uint64); + function accountLink(uint64) external view returns (AccountLink memory); +} \ No newline at end of file diff --git a/contracts/fantom/connectors/authority/main.sol b/contracts/fantom/connectors/authority/main.sol new file mode 100644 index 00000000..c7dbaf0c --- /dev/null +++ b/contracts/fantom/connectors/authority/main.sol @@ -0,0 +1,45 @@ +pragma solidity ^0.7.0; + +/** + * @title Authority. + * @dev Manage Authorities to DSA. + */ + +import { AccountInterface } from "../../common/interfaces.sol"; +import { Helpers } from "./helpers.sol"; +import { Events } from "./events.sol"; + +abstract contract AuthorityResolver is Events, Helpers { + /** + * @dev Add New authority + * @notice Add an address as account authority + * @param authority The authority Address. + */ + function add( + address authority + ) external payable returns (string memory _eventName, bytes memory _eventParam) { + AccountInterface(address(this)).enable(authority); + + _eventName = "LogAddAuth(address,address)"; + _eventParam = abi.encode(msg.sender, authority); + } + + /** + * @dev Remove authority + * @notice Remove an address as account authority + * @param authority The authority Address. + */ + function remove( + address authority + ) external payable returns (string memory _eventName, bytes memory _eventParam) { + require(checkAuthCount() > 1, "Removing-all-authorities"); + AccountInterface(address(this)).disable(authority); + + _eventName = "LogRemoveAuth(address,address)"; + _eventParam = abi.encode(msg.sender, authority); + } +} + +contract ConnectV2AuthFantom is AuthorityResolver { + string public constant name = "Auth-v1"; +} diff --git a/contracts/fantom/connectors/basic/events.sol b/contracts/fantom/connectors/basic/events.sol new file mode 100644 index 00000000..b68f3801 --- /dev/null +++ b/contracts/fantom/connectors/basic/events.sol @@ -0,0 +1,6 @@ +pragma solidity ^0.7.0; + +contract Events { + event LogDeposit(address indexed erc20, uint256 tokenAmt, uint256 getId, uint256 setId); + event LogWithdraw(address indexed erc20, uint256 tokenAmt, address indexed to, uint256 getId, uint256 setId); +} diff --git a/contracts/fantom/connectors/basic/main.sol b/contracts/fantom/connectors/basic/main.sol new file mode 100644 index 00000000..e894d9ce --- /dev/null +++ b/contracts/fantom/connectors/basic/main.sol @@ -0,0 +1,82 @@ +pragma solidity ^0.7.0; + + +/** + * @title Basic. + * @dev Deposit & Withdraw from DSA. + */ + +import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; + +import { DSMath } from "../../common/math.sol"; +import { Basic } from "../../common/basic.sol"; +import { Events } from "./events.sol"; + +abstract contract BasicResolver is Events, DSMath, Basic { + using SafeERC20 for IERC20; + + /** + * @dev Deposit Assets To Smart Account. + * @notice Deposit a token to DSA + * @param token The address of the token to deposit. (For MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param amt The amount of tokens to deposit. (For max: `uint256(-1)` (Not valid for MATIC)) + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of tokens deposited. + */ + function deposit( + address token, + uint256 amt, + uint256 getId, + uint256 setId + ) public payable returns (string memory _eventName, bytes memory _eventParam) { + uint _amt = getUint(getId, amt); + if (token != ftmAddr) { + IERC20 tokenContract = IERC20(token); + _amt = _amt == uint(-1) ? tokenContract.balanceOf(msg.sender) : _amt; + tokenContract.safeTransferFrom(msg.sender, address(this), _amt); + } else { + require(msg.value == _amt || _amt == uint(-1), "invalid-ether-amount"); + _amt = msg.value; + } + setUint(setId, _amt); + + _eventName = "LogDeposit(address,uint256,uint256,uint256)"; + _eventParam = abi.encode(token, _amt, getId, setId); + } + + /** + * @dev Withdraw Assets from Smart Account + * @notice Withdraw a token from DSA + * @param token The address of the token to withdraw. (For MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param amt The amount of tokens to withdraw. (For max: `uint256(-1)`) + * @param to The address to receive the token upon withdrawal + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of tokens withdrawn. + */ + function withdraw( + address token, + uint amt, + address payable to, + uint getId, + uint setId + ) public payable returns (string memory _eventName, bytes memory _eventParam) { + uint _amt = getUint(getId, amt); + if (token == ftmAddr) { + _amt = _amt == uint(-1) ? address(this).balance : _amt; + to.call{value: _amt}(""); + } else { + IERC20 tokenContract = IERC20(token); + _amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt; + tokenContract.safeTransfer(to, _amt); + } + setUint(setId, _amt); + + _eventName = "LogWithdraw(address,uint256,address,uint256,uint256)"; + _eventParam = abi.encode(token, _amt, to, getId, setId); + } +} + +contract ConnectV2BasicFantom is BasicResolver { + string constant public name = "Basic-v1"; +} diff --git a/contracts/fantom/connectors/wftm/events.sol b/contracts/fantom/connectors/wftm/events.sol new file mode 100644 index 00000000..f8ec366a --- /dev/null +++ b/contracts/fantom/connectors/wftm/events.sol @@ -0,0 +1,6 @@ +pragma solidity ^0.7.0; + +contract Events { + event LogDeposit(uint256 tokenAmt, uint256 getId, uint256 setId); + event LogWithdraw(uint256 tokenAmt, uint256 getId, uint256 setId); +} diff --git a/contracts/fantom/connectors/wftm/helpers.sol b/contracts/fantom/connectors/wftm/helpers.sol new file mode 100644 index 00000000..1366ca65 --- /dev/null +++ b/contracts/fantom/connectors/wftm/helpers.sol @@ -0,0 +1,8 @@ +pragma solidity ^0.7.0; + +import { TokenInterface } from "../../common/interfaces.sol"; + + +abstract contract Helpers { + TokenInterface constant internal wftmContract = TokenInterface(0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83); +} diff --git a/contracts/fantom/connectors/wftm/main.sol b/contracts/fantom/connectors/wftm/main.sol new file mode 100644 index 00000000..0bc273dc --- /dev/null +++ b/contracts/fantom/connectors/wftm/main.sol @@ -0,0 +1,65 @@ +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 WETH. + * @notice Wrap ETH into WETH + * @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) { + uint _amt = getUint(getId, amt); + + _amt = _amt == uint(-1) ? address(this).balance : _amt; + wftmContract.deposit{value: _amt}(); + + setUint(setId, _amt); + + _eventName = "LogDeposit(uint256,uint256,uint256)"; + _eventParam = abi.encode(_amt, getId, setId); + } + + /** + * @dev Withdraw ETH from WETH from Smart Account + * @notice Unwrap ETH from WETH + * @param amt The amount of weth to withdraw. (For max: `uint256(-1)`) + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of ETH withdrawn. + */ + function withdraw( + uint amt, + uint getId, + uint setId + ) public payable returns (string memory _eventName, bytes memory _eventParam) { + uint _amt = getUint(getId, amt); + + _amt = _amt == uint(-1) ? wftmContract.balanceOf(address(this)) : _amt; + approve(wftmContract, wftmAddr, _amt); + wftmContract.withdraw(_amt); + + setUint(setId, _amt); + + _eventName = "LogWithdraw(uint256,uint256,uint256)"; + _eventParam = abi.encode(_amt, getId, setId); + } +} + +contract ConnectV2WETHArbitrum is Resolver { + string constant public name = "WETH-v1.0"; +} diff --git a/hardhat.config.js b/hardhat.config.js index e4a64184..802d359a 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -74,6 +74,13 @@ module.exports = { timeout: 150000, gasPrice: parseInt(utils.parseUnits("2", "gwei")), }, + fantom: { + chainId: 250, + url: `https://rpc.ftm.tools/`, + accounts: [`0x${PRIVATE_KEY}`], + timeout: 150000, + gasPrice: parseInt(utils.parseUnits("250", "gwei")) + } }, etherscan: { apiKey: process.env.ETHERSCAN_API_KEY, diff --git a/scripts/deploy.js b/scripts/deploy.js index 26f65d8e..19d244b8 100644 --- a/scripts/deploy.js +++ b/scripts/deploy.js @@ -8,19 +8,19 @@ async function main() { const wallet = accounts[0] const connectMapping = { - '1INCH-A': 'ConnectV2OneInch', - '1INCH-B': 'ConnectV2OneProto', - 'AAVE-V1-A': 'ConnectV2AaveV1', - 'AAVE-V2-A': 'ConnectV2AaveV2', - 'AUTHORITY-A': 'ConnectV2Auth', - 'BASIC-A': 'ConnectV2Basic', - 'COMP-A': 'ConnectV2COMP', - 'COMPOUND-A': 'ConnectV2Compound', - 'DYDX-A': 'ConnectV2Dydx', - 'FEE-A': 'ConnectV2Fee', - 'GELATO-A': 'ConnectV2Gelato', - 'MAKERDAO-A': 'ConnectV2Maker', - 'UNISWAP-A': 'ConnectV2UniswapV2' + // '1INCH-A': 'ConnectV2OneInch', + // '1INCH-B': 'ConnectV2OneProto', + // 'AAVE-V1-A': 'ConnectV2AaveV1', + // 'AAVE-V2-A': 'ConnectV2AaveV2', + 'AUTHORITY-A': 'ConnectV2AuthFantom', + 'BASIC-A': 'ConnectV2BasicFantom', + // 'COMP-A': 'ConnectV2COMP', + // 'COMPOUND-A': 'ConnectV2Compound', + // 'DYDX-A': 'ConnectV2Dydx', + // 'FEE-A': 'ConnectV2Fee', + // 'GELATO-A': 'ConnectV2Gelato', + // 'MAKERDAO-A': 'ConnectV2Maker', + // 'UNISWAP-A': 'ConnectV2UniswapV2' } const addressMapping = {} diff --git a/scripts/deployConnector.js b/scripts/deployConnector.js index f0ae463d..013c372b 100644 --- a/scripts/deployConnector.js +++ b/scripts/deployConnector.js @@ -2,20 +2,21 @@ const hre = require("hardhat"); const { ethers } = hre; module.exports = async (connectorName) => { - const Connector = await ethers.getContractFactory(connectorName); - const connector = await Connector.deploy(); - await connector.deployed(); + // const Connector = await ethers.getContractFactory(connectorName); + // const connector = await Connector.deploy(); + // await connector.deployed(); - console.log(`${connectorName} Deployed: ${connector.address}`); + // console.log(`${connectorName} Deployed: ${connector.address}`); try { await hre.run("verify:verify", { - address: connector.address, - constructorArguments: [] + address: "0x9926955e0dd681dc303370c52f4ad0a4dd061687", + constructorArguments: [], + contract: "contracts/fantom/connectors/basic/main.sol:ConnectV2BasicFantom" } ) } catch (error) { - console.log(`Failed to verify: ${connectorName}@${connector.address}`) + // console.log(`Failed to verify: ${connectorName}@${connector.address}`) console.log(error) console.log() } From 4af34209c9f56b104cc1e9a7697b634a724b1cfa Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Sat, 2 Oct 2021 21:38:27 +0530 Subject: [PATCH 02/16] deployed auth and basic connectors --- docs/connectors.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/connectors.json b/docs/connectors.json index 4cdfad3a..79d871d3 100644 --- a/docs/connectors.json +++ b/docs/connectors.json @@ -47,6 +47,10 @@ "UNISWAP-V3-A": "0x3254Ce8f5b1c82431B8f21Df01918342215825C2", "1INCH-A": "0xA4BF319968986D2352FA1c550D781bBFCCE3FcaB", "WETH-A": "0x6C7256cf7C003dD85683339F75DdE9971f98f2FD" + }, + "fantom" : { + "AUTHORITY-A": "0x6CE3e607C808b4f4C26B7F6aDAeB619e49CAbb25", + "BASIC-A": "0x9926955e0dd681dc303370c52f4ad0a4dd061687" } }, "mappings": { From 5a0188544ec12008de760b2206247e64da1c4b35 Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Fri, 11 Feb 2022 00:08:52 +0530 Subject: [PATCH 03/16] Added BasicB and BasicC --- .gitignore | 1 + .../connectors/basic-ERC1155/events.sol | 20 ++++ .../fantom/connectors/basic-ERC1155/main.sol | 93 +++++++++++++++++++ .../fantom/connectors/basic-ERC721/events.sol | 18 ++++ .../fantom/connectors/basic-ERC721/main.sol | 76 +++++++++++++++ 5 files changed, 208 insertions(+) create mode 100644 contracts/fantom/connectors/basic-ERC1155/events.sol create mode 100644 contracts/fantom/connectors/basic-ERC1155/main.sol create mode 100644 contracts/fantom/connectors/basic-ERC721/events.sol create mode 100644 contracts/fantom/connectors/basic-ERC721/main.sol diff --git a/.gitignore b/.gitignore index 26988819..14dce074 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,4 @@ build/contracts # buidler artifacts cache +typechain diff --git a/contracts/fantom/connectors/basic-ERC1155/events.sol b/contracts/fantom/connectors/basic-ERC1155/events.sol new file mode 100644 index 00000000..2ef9f79a --- /dev/null +++ b/contracts/fantom/connectors/basic-ERC1155/events.sol @@ -0,0 +1,20 @@ +pragma solidity ^0.7.0; + +contract Events { + event LogDepositERC1155( + address indexed erc1155, + address from, + uint256 tokenId, + uint256 amount, + uint256 getId, + uint256 setId + ); + event LogWithdrawERC1155( + address indexed erc1155, + uint256 tokenId, + address indexed to, + uint256 amount, + uint256 getId, + uint256 setId + ); +} diff --git a/contracts/fantom/connectors/basic-ERC1155/main.sol b/contracts/fantom/connectors/basic-ERC1155/main.sol new file mode 100644 index 00000000..30a9902e --- /dev/null +++ b/contracts/fantom/connectors/basic-ERC1155/main.sol @@ -0,0 +1,93 @@ +pragma solidity ^0.7.0; + +/** + * @title Basic. + * @dev Deposit & Withdraw from ERC1155 DSA. + */ +import {IERC1155} from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol"; + +import {DSMath} from "../../common/math.sol"; +import {Basic} from "../../common/basic.sol"; +import {Events} from "./events.sol"; + +abstract contract BasicResolver is Events, DSMath, Basic { + /** + * @dev Deposit Assets To Smart Account. + * @notice Deposit a ERC1155 token to DSA + * @param token Address of token. + * @param tokenId ID of token. + * @param amount Amount to deposit. + * @param getId ID to retrieve amount. + * @param setId ID stores the amount. + */ + function depositERC1155( + address token, + uint256 tokenId, + uint256 amount, + uint256 getId, + uint256 setId + ) + public + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amount = getUint(getId, amount); + + IERC1155 tokenContract = IERC1155(token); + tokenContract.safeTransferFrom( + msg.sender, + address(this), + tokenId, + _amount, + "" + ); + + setUint(setId, _amount); + + _eventName = "LogDepositERC1155(address,address,uint256,uint256,uint256,uint256)"; + _eventParam = abi.encode( + token, + msg.sender, + tokenId, + _amount, + getId, + setId + ); + } + + /** + * @dev Withdraw Assets To Smart Account. + * @notice Withdraw a ERC1155 token from DSA + * @param token Address of the token. + * @param tokenId ID of token. + * @param to The address to receive the token upon withdrawal + * @param amount Amount to withdraw. + * @param getId ID to retrieve amount. + * @param setId ID stores the amount. + */ + function withdrawERC1155( + address token, + uint256 tokenId, + address payable to, + uint256 amount, + uint256 getId, + uint256 setId + ) + public + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amount = getUint(getId, amount); + IERC1155 tokenContract = IERC1155(token); + tokenContract.safeTransferFrom(address(this), to, tokenId, _amount, ""); + + setUint(setId, _amount); + + _eventName = "LogWithdrawERC1155(address,uint256,address,uint256,uint256,uint256)"; + _eventParam = abi.encode(token, tokenId, to, _amount, getId, setId); + } +} + +contract ConnectV2BasicERC1155Fantom is BasicResolver { + string public constant name = "BASIC-ERC1155-v1.0"; +} diff --git a/contracts/fantom/connectors/basic-ERC721/events.sol b/contracts/fantom/connectors/basic-ERC721/events.sol new file mode 100644 index 00000000..7b367145 --- /dev/null +++ b/contracts/fantom/connectors/basic-ERC721/events.sol @@ -0,0 +1,18 @@ +pragma solidity ^0.7.0; + +contract Events { + event LogDepositERC721( + address indexed erc721, + address from, + uint256 tokenId, + uint256 getId, + uint256 setId + ); + event LogWithdrawERC721( + address indexed erc721, + uint256 tokenId, + address indexed to, + uint256 getId, + uint256 setId + ); +} diff --git a/contracts/fantom/connectors/basic-ERC721/main.sol b/contracts/fantom/connectors/basic-ERC721/main.sol new file mode 100644 index 00000000..410c6342 --- /dev/null +++ b/contracts/fantom/connectors/basic-ERC721/main.sol @@ -0,0 +1,76 @@ +pragma solidity ^0.7.0; + +/** + * @title Basic. + * @dev Deposit & Withdraw ERC721 from DSA. + */ +import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; + +import {DSMath} from "../../common/math.sol"; +import {Basic} from "../../common/basic.sol"; +import {Events} from "./events.sol"; + +abstract contract BasicResolver is Events, DSMath, Basic { + /** + * @dev Deposit Assets To Smart Account. + * @notice Deposit a ERC721 token to DSA + * @param token Address of token. + * @param tokenId ID of token. + * @param getId ID to retrieve tokenId. + * @param setId ID stores the tokenId. + */ + function depositERC721( + address token, + uint256 tokenId, + uint256 getId, + uint256 setId + ) + public + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _tokenId = getUint(getId, tokenId); + + IERC721 tokenContract = IERC721(token); + tokenContract.safeTransferFrom(msg.sender, address(this), _tokenId); + + setUint(setId, _tokenId); + + _eventName = "LogDepositERC721(address,address,uint256,uint256,uint256)"; + _eventParam = abi.encode(token, msg.sender, _tokenId, getId, setId); + } + + /** + * @dev Withdraw Assets To Smart Account. + * @notice Withdraw a ERC721 token from DSA + * @param token Address of the token. + * @param tokenId ID of token. + * @param to The address to receive the token upon withdrawal + * @param getId ID to retrieve tokenId. + * @param setId ID stores the tokenId. + */ + function withdrawERC721( + address token, + uint256 tokenId, + address payable to, + uint256 getId, + uint256 setId + ) + public + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _tokenId = getUint(getId, tokenId); + IERC721 tokenContract = IERC721(token); + tokenContract.safeTransferFrom(address(this), to, _tokenId); + + setUint(setId, _tokenId); + + _eventName = "LogWithdrawERC721(address,uint256,address,uint256,uint256)"; + _eventParam = abi.encode(token, _tokenId, to, getId, setId); + } +} + +contract ConnectV2BasicERC721 is BasicResolver { + string public constant name = "BASIC-ERC721-v1.0"; +} From d8605357a90bbe73be0c037c74dbd72462d90f54 Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Fri, 11 Feb 2022 00:18:57 +0530 Subject: [PATCH 04/16] minor change --- contracts/fantom/connectors/basic-ERC721/main.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/fantom/connectors/basic-ERC721/main.sol b/contracts/fantom/connectors/basic-ERC721/main.sol index 410c6342..681a42bb 100644 --- a/contracts/fantom/connectors/basic-ERC721/main.sol +++ b/contracts/fantom/connectors/basic-ERC721/main.sol @@ -71,6 +71,6 @@ abstract contract BasicResolver is Events, DSMath, Basic { } } -contract ConnectV2BasicERC721 is BasicResolver { +contract ConnectV2BasicERC721Fantom is BasicResolver { string public constant name = "BASIC-ERC721-v1.0"; } From 49c80cf9869992ecce2c7c8da92f2daf8a1205a7 Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Sun, 13 Feb 2022 21:52:03 +0530 Subject: [PATCH 05/16] deploy basic-b and basic-c connectors --- docs/connectors.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/connectors.json b/docs/connectors.json index 79d871d3..c8ecef06 100644 --- a/docs/connectors.json +++ b/docs/connectors.json @@ -50,7 +50,9 @@ }, "fantom" : { "AUTHORITY-A": "0x6CE3e607C808b4f4C26B7F6aDAeB619e49CAbb25", - "BASIC-A": "0x9926955e0dd681dc303370c52f4ad0a4dd061687" + "BASIC-A": "0x9926955e0dd681dc303370c52f4ad0a4dd061687", + "BASIC-B": "0x8dA60dee0815a08d16C066b07814b10722fA9306", + "BASIC-C": "0x2EadEecf1aB9283a9F76D219CF17eeD4932B8811" } }, "mappings": { From eaa49c0c69b13a739dcb8d613f1664605eed5f85 Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Mon, 14 Feb 2022 08:28:00 +0530 Subject: [PATCH 06/16] converted js files to ts --- hardhat.config.js | 95 -------------------------------------- hardhat.config.ts | 8 +++- scripts/deploy.js | 38 --------------- scripts/deployConnector.js | 25 ---------- 4 files changed, 7 insertions(+), 159 deletions(-) delete mode 100644 hardhat.config.js delete mode 100644 scripts/deploy.js delete mode 100644 scripts/deployConnector.js diff --git a/hardhat.config.js b/hardhat.config.js deleted file mode 100644 index 802d359a..00000000 --- a/hardhat.config.js +++ /dev/null @@ -1,95 +0,0 @@ -require("@nomiclabs/hardhat-waffle"); -require("@nomiclabs/hardhat-ethers"); -require("@tenderly/hardhat-tenderly"); -require("@nomiclabs/hardhat-etherscan"); -require("@nomiclabs/hardhat-web3"); -require("hardhat-deploy"); -require("hardhat-deploy-ethers"); -require("dotenv").config(); - -const { utils } = require("ethers"); - -const PRIVATE_KEY = process.env.PRIVATE_KEY; -const ALCHEMY_ID = process.env.ALCHEMY_ID; - -if (!process.env.ALCHEMY_ID) { - throw new Error("ENV Variable ALCHEMY_ID not set!"); -} - -/** - * @type import('hardhat/config').HardhatUserConfig - */ -module.exports = { - solidity: { - compilers: [ - { - version: "0.7.6", - settings: { - optimizer: { - enabled: false, - runs: 200, - }, - }, - }, - { - version: "0.6.0", - }, - { - version: "0.6.2", - }, - { - version: "0.6.5", - }, - ], - }, - networks: { - kovan: { - url: `https://eth-kovan.alchemyapi.io/v2/${ALCHEMY_ID}`, - accounts: [`0x${PRIVATE_KEY}`], - }, - mainnet: { - url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_ID}`, - accounts: [`0x${PRIVATE_KEY}`], - timeout: 150000, - gasPrice: parseInt(utils.parseUnits("30", "gwei")), - }, - hardhat: { - forking: { - url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_ID}`, - blockNumber: 12796965, - }, - blockGasLimit: 12000000, - gasPrice: parseInt(utils.parseUnits("300", "gwei")) - }, - matic: { - url: "https://rpc-mainnet.maticvigil.com/", - accounts: [`0x${PRIVATE_KEY}`], - timeout: 150000, - gasPrice: parseInt(utils.parseUnits("1", "gwei")), - }, - arbitrum: { - chainId: 42161, - url: `https://arb-mainnet.g.alchemy.com/v2/${ALCHEMY_ID}`, - accounts: [`0x${PRIVATE_KEY}`], - timeout: 150000, - gasPrice: parseInt(utils.parseUnits("2", "gwei")), - }, - fantom: { - chainId: 250, - url: `https://rpc.ftm.tools/`, - accounts: [`0x${PRIVATE_KEY}`], - timeout: 150000, - gasPrice: parseInt(utils.parseUnits("250", "gwei")) - } - }, - etherscan: { - apiKey: process.env.ETHERSCAN_API_KEY, - }, - tenderly: { - project: process.env.TENDERLY_PROJECT, - username: process.env.TENDERLY_USERNAME, - }, - mocha: { - timeout: 100 * 1000, - }, -}; \ No newline at end of file diff --git a/hardhat.config.ts b/hardhat.config.ts index d3bd78b9..014cdaa9 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -23,7 +23,8 @@ const chainIds = { avalanche: 43114, polygon: 137, arbitrum: 42161, - optimism: 10 + optimism: 10, + fantom:250 }; const alchemyApiKey = process.env.ALCHEMY_API_KEY; @@ -36,6 +37,7 @@ const ETHERSCAN_API = process.env.ETHERSCAN_API_KEY; const POLYGONSCAN_API = process.env.POLYGON_API_KEY; const ARBISCAN_API = process.env.ARBISCAN_API_KEY; const SNOWTRACE_API = process.env.SNOWTRACE_API_KEY; +const FANTOMSCAN_API = process.env.FANTOM_API_KEY; const mnemonic = process.env.MNEMONIC ?? "test test test test test test test test test test test junk"; @@ -64,6 +66,8 @@ function getNetworkUrl(networkType: string) { return `https://arb-mainnet.g.alchemy.com/v2/${alchemyApiKey}`; else if (networkType === "optimism") return `https://opt-mainnet.g.alchemy.com/v2/${alchemyApiKey}`; + else if(networkType === "fantom") + return `https://rpc.ftm.tools/` else return `https://eth-mainnet.alchemyapi.io/v2/${alchemyApiKey}`; } @@ -71,6 +75,7 @@ function getScanApiKey(networkType: string) { if (networkType === "avalanche") return SNOWTRACE_API; else if (networkType === "polygon") return POLYGONSCAN_API; else if (networkType === "arbitrum") return ARBISCAN_API; + else if(networkType === "fantom") return FANTOMSCAN_API; else return ETHERSCAN_API; } @@ -115,6 +120,7 @@ const config: HardhatUserConfig = { avalanche: createConfig("avalanche"), arbitrum: createConfig("arbitrum"), optimism: createConfig("optimism"), + fantom: createConfig("fantom"), }, paths: { artifacts: "./artifacts", diff --git a/scripts/deploy.js b/scripts/deploy.js deleted file mode 100644 index 19d244b8..00000000 --- a/scripts/deploy.js +++ /dev/null @@ -1,38 +0,0 @@ -const hre = require("hardhat"); -const { ethers } = hre; - -const deployConnector = require("./deployConnector"); - -async function main() { - const accounts = await hre.ethers.getSigners() - const wallet = accounts[0] - - const connectMapping = { - // '1INCH-A': 'ConnectV2OneInch', - // '1INCH-B': 'ConnectV2OneProto', - // 'AAVE-V1-A': 'ConnectV2AaveV1', - // 'AAVE-V2-A': 'ConnectV2AaveV2', - 'AUTHORITY-A': 'ConnectV2AuthFantom', - 'BASIC-A': 'ConnectV2BasicFantom', - // 'COMP-A': 'ConnectV2COMP', - // 'COMPOUND-A': 'ConnectV2Compound', - // 'DYDX-A': 'ConnectV2Dydx', - // 'FEE-A': 'ConnectV2Fee', - // 'GELATO-A': 'ConnectV2Gelato', - // 'MAKERDAO-A': 'ConnectV2Maker', - // 'UNISWAP-A': 'ConnectV2UniswapV2' - } - - const addressMapping = {} - - for (const key in connectMapping) { - addressMapping[key] = await deployConnector(connectMapping[key]) - } -} - -main() - .then(() => process.exit(0)) - .catch(error => { - console.error(error); - process.exit(1); - }); diff --git a/scripts/deployConnector.js b/scripts/deployConnector.js deleted file mode 100644 index 013c372b..00000000 --- a/scripts/deployConnector.js +++ /dev/null @@ -1,25 +0,0 @@ -const hre = require("hardhat"); -const { ethers } = hre; - -module.exports = async (connectorName) => { - // const Connector = await ethers.getContractFactory(connectorName); - // const connector = await Connector.deploy(); - // await connector.deployed(); - - // console.log(`${connectorName} Deployed: ${connector.address}`); - - try { - await hre.run("verify:verify", { - address: "0x9926955e0dd681dc303370c52f4ad0a4dd061687", - constructorArguments: [], - contract: "contracts/fantom/connectors/basic/main.sol:ConnectV2BasicFantom" - } - ) - } catch (error) { - // console.log(`Failed to verify: ${connectorName}@${connector.address}`) - console.log(error) - console.log() - } - - return connector.address -} \ No newline at end of file From 0a6c140d9492ccaf2725c27a4462f3461c8b4b83 Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Tue, 15 Feb 2022 22:12:44 +0530 Subject: [PATCH 07/16] minor fixes --- contracts/fantom/connectors/wftm/main.sol | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/contracts/fantom/connectors/wftm/main.sol b/contracts/fantom/connectors/wftm/main.sol index 0bc273dc..45373dad 100644 --- a/contracts/fantom/connectors/wftm/main.sol +++ b/contracts/fantom/connectors/wftm/main.sol @@ -1,8 +1,8 @@ pragma solidity ^0.7.0; /** - * @title WETH. - * @dev Wrap and Unwrap WETH. + * @title WFTM. + * @dev Wrap and Unwrap WFTM. */ import { DSMath } from "../../common/math.sol"; @@ -13,11 +13,11 @@ import { Helpers } from "./helpers.sol"; abstract contract Resolver is Events, DSMath, Basic, Helpers { /** - * @dev Deposit ETH into WETH. - * @notice Wrap ETH into WETH - * @param amt The amount of ETH to deposit. (For max: `uint256(-1)`) + * @dev Deposit FTM into WFTM. + * @notice Wrap FTM into WFTM + * @param amt The amount of FTM to deposit. (For max: `uint256(-1)`) * @param getId ID to retrieve amt. - * @param setId ID stores the amount of ETH deposited. + * @param setId ID stores the amount of FTM deposited. */ function deposit( uint256 amt, @@ -36,11 +36,11 @@ abstract contract Resolver is Events, DSMath, Basic, Helpers { } /** - * @dev Withdraw ETH from WETH from Smart Account - * @notice Unwrap ETH from WETH - * @param amt The amount of weth to withdraw. (For max: `uint256(-1)`) + * @dev Withdraw FTM from WFTM from Smart Account + * @notice Unwrap FTM from WFTM + * @param amt The amount of wFTM to withdraw. (For max: `uint256(-1)`) * @param getId ID to retrieve amt. - * @param setId ID stores the amount of ETH withdrawn. + * @param setId ID stores the amount of FTM withdrawn. */ function withdraw( uint amt, @@ -60,6 +60,6 @@ abstract contract Resolver is Events, DSMath, Basic, Helpers { } } -contract ConnectV2WETHArbitrum is Resolver { - string constant public name = "WETH-v1.0"; +contract ConnectV2WFTMFantom is Resolver { + string constant public name = "WFTM-v1.0"; } From 8aac74a788760f3209f1da525eb4f44fb4b2f3ca Mon Sep 17 00:00:00 2001 From: 0xBhavik <62445791+bhavik-m@users.noreply.github.com> Date: Wed, 16 Feb 2022 21:21:06 +0530 Subject: [PATCH 08/16] Update .gitignore --- .gitignore | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index edf87049..2aed425f 100644 --- a/.gitignore +++ b/.gitignore @@ -63,8 +63,5 @@ build/contracts # buidler artifacts cache -<<<<<<< HEAD typechain -======= -typechain ->>>>>>> 64d52604ec3f9c9172250d8ab60275599074af87 + From ba770876594ec4c192baa66927c6caed08e3ca03 Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Mon, 7 Mar 2022 00:16:22 +0530 Subject: [PATCH 09/16] 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 10/16] 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 11/16] 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 12/16] 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 13/16] 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 14/16] 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 15/16] 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 16/16] 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 }