add dodoStarterProxy

This commit is contained in:
owen05
2021-12-02 17:07:35 +08:00
parent 4471274053
commit 343a6d2f11
4 changed files with 97 additions and 13 deletions

View File

@@ -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)) {

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -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);
}
}
}