From a3d788f87e399d3bf9ae7c4bda4d6e1bc13621ec Mon Sep 17 00:00:00 2001 From: owen05 Date: Fri, 18 Feb 2022 21:12:18 +0800 Subject: [PATCH] update starter view --- config/rinkeby-config.js | 7 ++- contracts/DODOFee/UserQuota.sol | 2 +- contracts/DODOFee/UserQuotaFactory.sol | 53 +++++++++++++++++++ contracts/DODOStarter/impl/FairFunding.sol | 24 ++++++++- contracts/DODOStarter/impl/InstantFunding.sol | 11 +++- deploy-starter.txt | 22 ++++++++ migrations/2_deploy_starter.js | 35 ++++++++++++ 7 files changed, 148 insertions(+), 6 deletions(-) create mode 100644 contracts/DODOFee/UserQuotaFactory.sol diff --git a/config/rinkeby-config.js b/config/rinkeby-config.js index 2a45ebb..64f37b7 100644 --- a/config/rinkeby-config.js +++ b/config/rinkeby-config.js @@ -121,8 +121,11 @@ module.exports = { //=================== Starter =================== DODOStarterProxy: "0x451E07405B79eDEEA87ccFa57e1BaF184Bea6773", DODOStarterFactory: "0xa28D60c3eCDc52521c8219bd6a4eba0AA8900F88", - FairFunding: "0x9124B1191DDB6CB1CAF9aA899d5059ea52b5D09B", - InstantFunding: "0x80B21A1A832D3b0016A0d287967CD9Dce0Ade688" + FairFunding: "0x6eB0b12F31Bfe983a099DcBe9D2CC86768Dd2a3a", //0x9124B1191DDB6CB1CAF9aA899d5059ea52b5D09B + InstantFunding: "0xC2ff4432F111723DD28c52C0f7B1Fe9c6201F3ce", //0x80B21A1A832D3b0016A0d287967CD9Dce0Ade688 + + UserQuota: "0xEC548eB229f6C5E1E4d3701F9dD258486E127811", + UserQuotaFactory: "0x44640D5a85653279Bf22A45112d3db1BDf14aEF2" } } \ No newline at end of file diff --git a/contracts/DODOFee/UserQuota.sol b/contracts/DODOFee/UserQuota.sol index 8fb8863..cdc078d 100644 --- a/contracts/DODOFee/UserQuota.sol +++ b/contracts/DODOFee/UserQuota.sol @@ -24,7 +24,7 @@ contract UserQuota is InitializableOwnable, IQuota { for(uint256 i = 0; i< users.length; i++) { require(users[i] != address(0), "USER_INVALID"); userQuota[users[i]] = quotas[i]; - // emit SetQuota(users[i],quotas[i]); + emit SetQuota(users[i],quotas[i]); } } diff --git a/contracts/DODOFee/UserQuotaFactory.sol b/contracts/DODOFee/UserQuotaFactory.sol new file mode 100644 index 0000000..a986a7a --- /dev/null +++ b/contracts/DODOFee/UserQuotaFactory.sol @@ -0,0 +1,53 @@ +/* + + Copyright 2022 DODO ZOO. + SPDX-License-Identifier: Apache-2.0 + +*/ + +pragma solidity 0.6.9; +pragma experimental ABIEncoderV2; + +import {ICloneFactory} from "../lib/CloneFactory.sol"; +import {InitializableOwnable} from "../lib/InitializableOwnable.sol"; + + +interface IQuota { + function initOwner(address newOwner) external; + function getUserQuota(address user) external view returns (int); +} + + +/** + * @title DODO UserQuotaFactory + * @author DODO Breeder + * + */ +contract UserQuotaFactory is InitializableOwnable{ + // ============ Templates ============ + + address public immutable _CLONE_FACTORY_; + address public immutable _USER_QUOTA_TEMPLATE_; + + // ============ Events ============ + + event NewQuota(address quota); + + // ============ Functions ============ + + constructor( + address cloneFactory, + address quotaTemplate + ) public { + _CLONE_FACTORY_ = cloneFactory; + _USER_QUOTA_TEMPLATE_ = quotaTemplate; + } + + function createQuota( + address quotaOwner + ) external onlyOwner returns(address newQuota){ + newQuota = ICloneFactory(_CLONE_FACTORY_).clone(_USER_QUOTA_TEMPLATE_); + IQuota(newQuota).initOwner(quotaOwner); + emit NewQuota(newQuota); + } +} \ No newline at end of file diff --git a/contracts/DODOStarter/impl/FairFunding.sol b/contracts/DODOStarter/impl/FairFunding.sol index fb88836..eba018a 100644 --- a/contracts/DODOStarter/impl/FairFunding.sol +++ b/contracts/DODOStarter/impl/FairFunding.sol @@ -322,7 +322,9 @@ contract FairFunding is Vesting { uint256 userFundAmount, uint256 currentPrice, uint256 soldTokenAmount, + uint256 totalClaimAmount, uint256 claimableTokenAmount, + uint256 claimedTokenAmount, bool isHaveCap, uint256 userQuota, uint256 userCurrentQuota @@ -339,9 +341,29 @@ contract FairFunding is Vesting { getRemainingRatio(block.timestamp,0), totalAllocation ); - claimableTokenAmount = totalAllocation.sub(remainingToken).sub(_CLAIMED_TOKEN_[user]); + claimedTokenAmount = _CLAIMED_TOKEN_[user]; + claimableTokenAmount = totalAllocation.sub(remainingToken).sub(claimedTokenAmount); }else { claimableTokenAmount = 0; + claimedTokenAmount =0; + } + + if(raiseFundAmount == 0) { + totalClaimAmount = 0; + } else { + uint256 usedFundRatio = DecimalMath.divFloor( + DecimalMath.mulFloor(_TOTAL_TOKEN_AMOUNT_, currentPrice), + raiseFundAmount + ); + + if (usedFundRatio > DecimalMath.ONE) { + usedFundRatio = DecimalMath.ONE; + } + + totalClaimAmount = DecimalMath.divFloor( + DecimalMath.mulFloor(userFundAmount, usedFundRatio), + currentPrice + ); } if(_QUOTA_ == address(0)) { diff --git a/contracts/DODOStarter/impl/InstantFunding.sol b/contracts/DODOStarter/impl/InstantFunding.sol index ac734d0..a86eac6 100644 --- a/contracts/DODOStarter/impl/InstantFunding.sol +++ b/contracts/DODOStarter/impl/InstantFunding.sol @@ -245,7 +245,9 @@ contract InstantFunding is Vesting { uint256 userFundAmount, uint256 currentPrice, uint256 soldTokenAmount, + uint256 totalClaimAmount, uint256 claimableTokenAmount, + uint256 claimedTokenAmount, bool isHaveCap, uint256 userQuota, uint256 userCurrentQuota @@ -260,12 +262,17 @@ contract InstantFunding is Vesting { uint256 remainingToken = DecimalMath.mulFloor( getRemainingRatio(block.timestamp,0), totalAllocation - ); - claimableTokenAmount = totalAllocation.sub(remainingToken).sub(_CLAIMED_TOKEN_[user]); + ); + claimedTokenAmount = _CLAIMED_TOKEN_[user]; + claimableTokenAmount = totalAllocation.sub(remainingToken).sub(claimedTokenAmount); }else { claimableTokenAmount = 0; + claimedTokenAmount = 0; } + totalClaimAmount = getUserTokenAllocation(user); + + if(_QUOTA_ == address(0)) { isHaveCap = false; userQuota = uint256(-1); diff --git a/deploy-starter.txt b/deploy-starter.txt index 3359741..8ea3161 100644 --- a/deploy-starter.txt +++ b/deploy-starter.txt @@ -52,3 +52,25 @@ network type: rinkeby Deploy time: 2022/2/15 上午9:12:58 Deploy type: STARTER InstantFundingTemplate: 0x80B21A1A832D3b0016A0d287967CD9Dce0Ade688 +==================================================== +network type: rinkeby +Deploy time: 2022/2/17 上午11:25:15 +Deploy type: QuotaFactory +==================================================== +network type: rinkeby +Deploy time: 2022/2/17 上午11:30:18 +Deploy type: QuotaFactory +UserQuotaAddress: 0xEC548eB229f6C5E1E4d3701F9dD258486E127811 +UserQuotaFactoryAddress: 0x44640D5a85653279Bf22A45112d3db1BDf14aEF2 +Init UserQuotaFactory Tx: 0x8224ab09182dfb31ecfd03bea3fdba5b5aa620c42a3e33c545b3e40975538981 +==================================================== +network type: rinkeby +Deploy time: 2022/2/18 下午1:36:36 +Deploy type: STARTER +FairFundingTemplate: 0x6eB0b12F31Bfe983a099DcBe9D2CC86768Dd2a3a +InstantFundingTemplate: 0x95D6c48375E7A59438EDc37183676A6706c9bB2a +==================================================== +network type: rinkeby +Deploy time: 2022/2/18 下午1:47:09 +Deploy type: STARTER +InstantFundingTemplate: 0xC2ff4432F111723DD28c52C0f7B1Fe9c6201F3ce diff --git a/migrations/2_deploy_starter.js b/migrations/2_deploy_starter.js index b7dc006..311203c 100644 --- a/migrations/2_deploy_starter.js +++ b/migrations/2_deploy_starter.js @@ -4,6 +4,9 @@ const file = fs.createWriteStream("../deploy-starter.txt", { 'flags': 'a' }); let logger = new console.Console(file, file); const { GetConfig } = require("../configAdapter.js") +const UserQuota = artifacts.require("UserQuota"); +const UserQuotaFactory = artifacts.require("UserQuotaFactory"); + const DODOStarterProxy = artifacts.require("DODOStarterProxy"); const DODOStarterFactory = artifacts.require("DODOStarterFactory"); const FairFunding = artifacts.require("FairFunding"); @@ -17,6 +20,7 @@ module.exports = async (deployer, network, accounts) => { let CloneFactoryAddress = CONFIG.CloneFactory; let WETHAddress = CONFIG.WETH; + if (DODOApproveProxyAddress == "" || CloneFactoryAddress == "" || WETHAddress == "") return; let FairFundingTemplate = CONFIG.FairFunding; @@ -24,8 +28,39 @@ module.exports = async (deployer, network, accounts) => { let DODOStarterFactoryAddress = CONFIG.DODOStarterFactory; let DODOStarterProxyAddress = CONFIG.DODOStarterProxy; + let UserQuotaAddress = CONFIG.UserQuota; + let UserQuotaFactoryAddress = CONFIG.UserQuotaFactory; + let multiSigAddress = CONFIG.multiSigAddress; + if (deploySwitch.Quota) { + logger.log("===================================================="); + logger.log("network type: " + network); + logger.log("Deploy time: " + new Date().toLocaleString()); + logger.log("Deploy type: QuotaFactory"); + + if (UserQuotaAddress == "") { + await deployer.deploy(UserQuota); + UserQuotaAddress = UserQuota.address; + logger.log("UserQuotaAddress: ", UserQuotaAddress); + } + + if (UserQuotaFactoryAddress == "") { + await deployer.deploy( + UserQuotaFactory, + CloneFactoryAddress, + UserQuotaAddress + ); + + UserQuotaFactoryAddress = UserQuotaFactory.address; + logger.log("UserQuotaFactoryAddress: ", UserQuotaFactoryAddress); + + const instance = await UserQuotaFactory.at(UserQuotaFactoryAddress); + var tx = await instance.initOwner(multiSigAddress); + logger.log("Init UserQuotaFactory Tx:", tx.tx); + } + } + if (deploySwitch.STARTER) { logger.log("===================================================="); logger.log("network type: " + network);