From 4e5a95cf6f3cba3c7476c0f01aefcd7ce81c530e Mon Sep 17 00:00:00 2001 From: owen05 Date: Tue, 22 Dec 2020 16:42:53 +0800 Subject: [PATCH] cpfactory fix and test --- contracts/Factory/CrowdPoolingFactory.sol | 11 +++++------ test/Proxy/proxy.cp.test.ts | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/contracts/Factory/CrowdPoolingFactory.sol b/contracts/Factory/CrowdPoolingFactory.sol index 4d46e27..4e1fd39 100644 --- a/contracts/Factory/CrowdPoolingFactory.sol +++ b/contracts/Factory/CrowdPoolingFactory.sol @@ -8,14 +8,14 @@ pragma solidity 0.6.9; pragma experimental ABIEncoderV2; -import {Ownable} from "../lib/Ownable.sol"; +import {InitializableOwnable} from "../lib/InitializableOwnable.sol"; import {ICloneFactory} from "../lib/CloneFactory.sol"; import {ICP} from "../CrowdPooling/intf/ICP.sol"; import {SafeMath} from "../lib/SafeMath.sol"; import {IERC20} from "../intf/IERC20.sol"; import {DecimalMath} from "../lib/DecimalMath.sol"; -contract CrowdPoolingFactory is Ownable { +contract CrowdPoolingFactory is InitializableOwnable { using SafeMath for uint256; // ============ Templates ============ @@ -29,8 +29,8 @@ contract CrowdPoolingFactory is Ownable { address public immutable _DEFAULT_PERMISSION_MANAGER_; address public immutable _DEFAULT_GAS_PRICE_SOURCE_; - uint256 public _X_; - uint256 public _Y_; + uint256 public _X_ = 50; //default + uint256 public _Y_ = 0; //default // ============ Registry ============ // base -> quote -> CP address list @@ -51,8 +51,7 @@ contract CrowdPoolingFactory is Ownable { require(valueList[3] == DecimalMath.ONE,"CP_FACTORY : CLIFF_RATE_DECIMAL_MATH_ONE_ONLY"); uint256 baseTokenBalance = IERC20(baseToken).balanceOf(cpAddress); - uint256 decimals = IERC20(baseToken).decimals(); - require(valueList[0].mul(100) <= baseTokenBalance.div(10**decimals).mul(valueList[2]).mul(_X_),"CP_FACTORY : QUOTE_CAPE_INVALID"); + require(valueList[0].mul(100) <= baseTokenBalance.mul(valueList[2]).div(10**18).mul(_X_),"CP_FACTORY : QUOTE_CAPE_INVALID"); require(timeLine[3]>= _Y_,"CP_FACTORY : FREEZE_DURATION_INVALID"); _; } diff --git a/test/Proxy/proxy.cp.test.ts b/test/Proxy/proxy.cp.test.ts index 71a085b..5aefc15 100644 --- a/test/Proxy/proxy.cp.test.ts +++ b/test/Proxy/proxy.cp.test.ts @@ -68,14 +68,14 @@ describe("DODOProxyV2.0", () => { var timeLine = [ Math.floor(new Date().getTime() / 1000) + 10, 60 * 60 * 24, - 60 * 60 * 24, + 0, 60 * 60 * 24 * 30, - 60 * 60 * 24 * 7 + 0 ] var valueList = [ mweiStr("10000"), - decimalStr("0.5"), - decimalStr("10"), + decimalStr("0"), + mweiStr("10"), decimalStr("1") ] cp_DODO_USDT = await initCreateCP(ctx, ctx.DODO.options.address, ctx.USDT.options.address, decimalStr("100000"), timeLine, valueList); @@ -100,18 +100,18 @@ describe("DODOProxyV2.0", () => { it("createCP", async () => { var baseToken = ctx.DODO.options.address; var quoteToken = ctx.USDT.options.address; - var baseAmount = decimalStr("100000"); + var baseAmount = decimalStr("1"); var timeLine = [ Math.floor(new Date().getTime() / 1000) + 10, 60 * 60 * 24, - 60 * 60 * 24, + 0, 60 * 60 * 24 * 30, - 60 * 60 * 24 * 7 + 0 ] var valueList = [ - mweiStr("10000"), - decimalStr("0.5"), - decimalStr("10"), + mweiStr("5"), + decimalStr("0"), + mweiStr("10"), decimalStr("1") ] await logGas(await ctx.DODOProxyV2.methods.createCrowdPooling(