From 343a6d2f11b311ff0430d84e8e337065ddb91126 Mon Sep 17 00:00:00 2001 From: owen05 Date: Thu, 2 Dec 2021 17:07:35 +0800 Subject: [PATCH] add dodoStarterProxy --- contracts/DODOStarter/impl/FairFunding.sol | 4 +- contracts/DODOStarter/impl/Vesting.sol | 21 +++-- contracts/DODOStarter/intf/IDODOStarter.sol | 4 + .../SmartRoute/proxies/DODOStarterProxy.sol | 81 +++++++++++++++++++ 4 files changed, 97 insertions(+), 13 deletions(-) create mode 100644 contracts/SmartRoute/proxies/DODOStarterProxy.sol diff --git a/contracts/DODOStarter/impl/FairFunding.sol b/contracts/DODOStarter/impl/FairFunding.sol index 377c40b..5ef158c 100644 --- a/contracts/DODOStarter/impl/FairFunding.sol +++ b/contracts/DODOStarter/impl/FairFunding.sol @@ -167,10 +167,10 @@ contract FairFunding is Vesting { // ============ Funding Functions ============ - function depositFunds(address to) external preventReentrant isForceStop { + function depositFunds(address to) external preventReentrant isForceStop returns(uint256 inputFund) { require(isDepositOpen(), "DEPOSIT_NOT_OPEN"); // input fund check - uint256 inputFund = IERC20(_FUNDS_ADDRESS_).balanceOf(address(this)).sub(_FUNDS_RESERVE_); + inputFund = IERC20(_FUNDS_ADDRESS_).balanceOf(address(this)).sub(_FUNDS_RESERVE_); _FUNDS_RESERVE_ = _FUNDS_RESERVE_.add(inputFund); if (_QUOTA_ != address(0)) { diff --git a/contracts/DODOStarter/impl/Vesting.sol b/contracts/DODOStarter/impl/Vesting.sol index 6ea4406..1364a48 100644 --- a/contracts/DODOStarter/impl/Vesting.sol +++ b/contracts/DODOStarter/impl/Vesting.sol @@ -20,17 +20,6 @@ contract Vesting is Storage { using SafeMath for uint256; using SafeERC20 for IERC20; - - function _claimToken(address to, uint256 totalAllocation) internal { - uint256 remainingToken = DecimalMath.mulFloor( - getRemainingRatio(block.timestamp,0), - totalAllocation - ); - uint256 claimableTokenAmount = totalAllocation.sub(remainingToken).sub(_CLAIMED_TOKEN_[msg.sender]); - IERC20(_TOKEN_ADDRESS_).safeTransfer(to,claimableTokenAmount); - _CLAIMED_TOKEN_[msg.sender] = _CLAIMED_TOKEN_[msg.sender].add(claimableTokenAmount); - } - function claimFunds(address to) external preventReentrant onlyOwner { uint256 vestingFunds = _TOTAL_RAISED_FUNDS_.sub(_INITIAL_FUND_LIQUIDITY_); uint256 remainingFund = DecimalMath.mulFloor( @@ -97,4 +86,14 @@ contract Vesting is Storage { IERC20(_FUNDS_ADDRESS_).transfer(_INITIAL_POOL_, _INITIAL_FUND_LIQUIDITY_); (_TOTAL_LP_, , ) = IDVM(_INITIAL_POOL_).buyShares(address(this)); } + + function _claimToken(address to, uint256 totalAllocation) internal { + uint256 remainingToken = DecimalMath.mulFloor( + getRemainingRatio(block.timestamp,0), + totalAllocation + ); + uint256 claimableTokenAmount = totalAllocation.sub(remainingToken).sub(_CLAIMED_TOKEN_[msg.sender]); + IERC20(_TOKEN_ADDRESS_).safeTransfer(to,claimableTokenAmount); + _CLAIMED_TOKEN_[msg.sender] = _CLAIMED_TOKEN_[msg.sender].add(claimableTokenAmount); + } } diff --git a/contracts/DODOStarter/intf/IDODOStarter.sol b/contracts/DODOStarter/intf/IDODOStarter.sol index 58aa3b3..44839a4 100644 --- a/contracts/DODOStarter/intf/IDODOStarter.sol +++ b/contracts/DODOStarter/intf/IDODOStarter.sol @@ -14,4 +14,8 @@ interface IDODOStarter { uint256[] calldata timeLine, uint256[] calldata valueList ) external; + + function _FUNDS_ADDRESS_() external view returns (address); + + function depositFunds(address to) external returns (uint256); } diff --git a/contracts/SmartRoute/proxies/DODOStarterProxy.sol b/contracts/SmartRoute/proxies/DODOStarterProxy.sol new file mode 100644 index 0000000..1722ff0 --- /dev/null +++ b/contracts/SmartRoute/proxies/DODOStarterProxy.sol @@ -0,0 +1,81 @@ +/* + Copyright 2021 DODO ZOO. + SPDX-License-Identifier: Apache-2.0 +*/ + +pragma solidity 0.6.9; + +import {IDODOApproveProxy} from "../DODOApproveProxy.sol"; +import {IERC20} from "../../intf/IERC20.sol"; +import {SafeERC20} from "../../lib/SafeERC20.sol"; +import {IWETH} from "../../intf/IWETH.sol"; +import {SafeMath} from "../../lib/SafeMath.sol"; +import {SafeERC20} from "../../lib/SafeERC20.sol"; +import {ReentrancyGuard} from "../../lib/ReentrancyGuard.sol"; +import {IDODOStarter} from "../../DODOStarter/intf/IDODOStarter.sol"; + +/** + * @title DODOStarterProxy + * @author DODO Breeder + * + * @notice FairFund && InstantFund Proxy + */ +contract DODOStarterProxy is ReentrancyGuard { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + // ============ Storage ============ + + address constant _ETH_ADDRESS_ = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; + address public immutable _WETH_; + address public immutable _DODO_APPROVE_PROXY_; + + // ============ Modifiers ============ + + modifier judgeExpired(uint256 deadLine) { + require(deadLine >= block.timestamp, "DODOStarterProxy: EXPIRED"); + _; + } + + fallback() external payable {} + + receive() external payable {} + + constructor( + address payable weth, + address dodoApproveProxy + ) public { + _WETH_ = weth; + _DODO_APPROVE_PROXY_ = dodoApproveProxy; + } + + //============ Functions (bid) ============ + function bid( + address pool, + uint256 fundAmount, + uint8 flag, // 0 - ERC20, 1 - fundInETH + uint256 deadLine + ) external payable preventReentrant judgeExpired(deadLine) returns(uint256) { + _deposit(msg.sender, pool, IDODOStarter(pool)._FUNDS_ADDRESS_(), fundAmount, flag == 1); + return IDODOStarter(pool).depositFunds(msg.sender); + } + + //====================== internal ======================= + + function _deposit( + address from, + address to, + address token, + uint256 amount, + bool isETH + ) internal { + if (isETH) { + if (amount > 0) { + IWETH(_WETH_).deposit{value: amount}(); + if (to != address(this)) SafeERC20.safeTransfer(IERC20(_WETH_), to, amount); + } + } else { + IDODOApproveProxy(_DODO_APPROVE_PROXY_).claimTokens(token, from, to, amount); + } + } +} \ No newline at end of file