From 205a60f9d712d5259b109b239c16f0adedf4ece9 Mon Sep 17 00:00:00 2001 From: Samyak Jain <34437877+KaymasJain@users.noreply.github.com> Date: Sat, 12 Sep 2020 23:29:12 +1000 Subject: [PATCH] basic logic done --- contracts/logics/settle/eth/basic.sol | 45 ++++++++++++++++++++----- contracts/logics/settle/eth/maxComp.sol | 7 ++-- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/contracts/logics/settle/eth/basic.sol b/contracts/logics/settle/eth/basic.sol index e7987b8..bac5305 100644 --- a/contracts/logics/settle/eth/basic.sol +++ b/contracts/logics/settle/eth/basic.sol @@ -1,24 +1,53 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.6.8; +pragma experimental ABIEncoderV2; + +import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { DSMath } from "../../../libs/safeMath.sol"; +interface DSAInterface { + function cast(address[] calldata _targets, bytes[] calldata _data, address _origin) external payable; +} + contract LogicOne { - address poolToken; + using SafeERC20 for IERC20; - function deploy(address _dsa, uint amt) public { + /** + * @dev Return ethereum address + */ + function getEthAddr() internal pure returns (address) { + return 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; // ETH Address + } + + function deploy(address _dsa, address _token, uint amt) public { // check if DSA is authorised - // transfer assets to DSA + if (_token == getEthAddr()) { + uint _bal = address(this).balance; + amt = amt > _bal ? _bal : amt; + payable(_dsa).transfer(amt); + } else { + IERC20 token = IERC20(_token); + uint _bal = token.balanceOf(address(this)); + amt = amt > _bal ? _bal : amt; + token.safeTransfer(_dsa, amt); + } } - function redeem(address _dsa, uint amt) public { - // withdraw assets from DSA + // withdraw assets from DSA + function redeem(address _dsa, address _token, uint amt) public { + uint _bal = IERC20(_token).balanceOf(_dsa); + amt = amt > _bal ? _bal : amt; + address[] memory _targets = new address[](1); + _targets[0] = address(0); // Check9898 - address of basic connector + bytes[] memory _data = new bytes[](1); + _data[0] = abi.encodeWithSignature("withdraw(address,uint256,address,uint256,uint256)", _token, amt, address(this), uint(0), uint(0)); + DSAInterface(_dsa).cast(_targets, _data, address(0)); // Check9898 - address of origin } - constructor (address ethPool) public { - poolToken = address(ethPool); - } + constructor () public {} receive() external payable {} diff --git a/contracts/logics/settle/eth/maxComp.sol b/contracts/logics/settle/eth/maxComp.sol index 116331b..b858ce4 100644 --- a/contracts/logics/settle/eth/maxComp.sol +++ b/contracts/logics/settle/eth/maxComp.sol @@ -12,12 +12,13 @@ contract LogicOne { function maxComp(address _dsa, address[] calldata _targets, bytes[] calldata _data) public { // check if DSA is authorised for interaction - address compoundConnector = address(0); - address instaPoolConnector = address(0); + // Also think on dydx flash loan connector + address compoundConnector = address(0); // Check9898 - address of compound connector + address instaPoolConnector = address(0); // Check9898 - address of instaPool connector for (uint i = 0; i < _targets.length; i++) { require(_targets[i] == compoundConnector || _targets[i] == instaPoolConnector, "connector-not-authorised"); } - DSAInterface(_dsa).cast(_targets, _data, address(0)); + DSAInterface(_dsa).cast(_targets, _data, address(0)); // Check9898 - address of basic connector // check if status is safe and only have assets in the specific tokens }