From 99076e966871e59d88ee5d443f3bd3cea8e93c65 Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Tue, 2 Aug 2022 13:08:03 +0300 Subject: [PATCH 1/6] added prettier config, use prettier for each file --- .prettierrc | 24 + .solcover.js | 4 +- contracts/Benefit/Benefit.sol | 7 +- contracts/Benefit/IPozBenefit.sol | 4 +- contracts/Benefit/IStaking.sol | 2 +- contracts/EnvelopToken/Manageable.sol | 44 +- contracts/EnvelopToken/OriginalToken.sol | 23 +- .../HodlersWhitelist/HodlersWhitelist.sol | 16 +- contracts/HodlersWhitelist/Manageable.sol | 16 +- contracts/LockedDeal/LockedControl.sol | 87 +- contracts/LockedDeal/LockedPoolz.sol | 59 +- contracts/LockedDeal/LockedPoolzData.sol | 5 +- contracts/LockedDeal/Manageable.sol | 40 +- contracts/LockedDealV2/LockedControl.sol | 86 +- contracts/LockedDealV2/LockedDealV2.sol | 20 +- contracts/LockedDealV2/LockedManageable.sol | 46 +- contracts/LockedDealV2/LockedPoolz.sol | 9 +- contracts/PoolzBack/Invest.sol | 87 +- contracts/PoolzBack/InvestorData.sol | 1 - contracts/PoolzBack/Manageable.sol | 34 +- contracts/PoolzBack/Pools.sol | 31 +- contracts/PoolzBack/PoolsData.sol | 20 +- contracts/PoolzBack/ThePoolz.sol | 5 +- contracts/PoolzBack/Token.sol | 2 +- contracts/WhiteList/WhiteList.sol | 43 +- contracts/WhiteList/WhiteListHelper.sol | 27 +- test/07_CreatingPool.js | 243 ++-- test/08_Invest.js | 636 ++++++---- test/09_LockedDeal.js | 151 +-- test/10_Benefit.js | 385 +++--- test/11_Hodlers.js | 256 ++-- test/12_Envelop.js | 1116 +++++++---------- test/13_WhiteListConvertor.js | 406 +++--- test/14_FlexStaking.js | 266 ++-- test/15_LockedDealV2.js | 238 ++-- test/helper/index.js | 29 +- 36 files changed, 2331 insertions(+), 2137 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..4e9e06c --- /dev/null +++ b/.prettierrc @@ -0,0 +1,24 @@ +{ + "overrides": [ + { + "files": "*.sol", + "options": { + "tadWidth": 2, + "printWidth": 80, + "singleQuote": false + } + }, + { + "files": "*.js", + "options": { + "printWidth": 120, + "useTabs": false, + "semi": false, + "singleQuote": false, + "trailingComma": "none", + "bracketSpacing": true, + "bracketSameLine": true + } + } + ] +} diff --git a/.solcover.js b/.solcover.js index a907046..afc98fe 100644 --- a/.solcover.js +++ b/.solcover.js @@ -1,3 +1,3 @@ module.exports = { - client: require("ganache-cli") // Will load the outermost ganache-cli in node_modules -}; \ No newline at end of file + client: require("ganache-cli") // Will load the outermost ganache-cli in node_modules +} diff --git a/contracts/Benefit/Benefit.sol b/contracts/Benefit/Benefit.sol index 386a2a9..4c2bed6 100644 --- a/contracts/Benefit/Benefit.sol +++ b/contracts/Benefit/Benefit.sol @@ -79,7 +79,12 @@ contract Benefit is IPOZBenefit, Ownable { return IStaking(_Contract).stakeOf(_Subject); } - function IsPOZHolder(address _Subject) override external view returns (bool) { + function IsPOZHolder(address _Subject) + external + view + override + returns (bool) + { return CalcTotal(_Subject) >= MinHold; } diff --git a/contracts/Benefit/IPozBenefit.sol b/contracts/Benefit/IPozBenefit.sol index 141a034..941d4ba 100644 --- a/contracts/Benefit/IPozBenefit.sol +++ b/contracts/Benefit/IPozBenefit.sol @@ -2,7 +2,7 @@ pragma solidity ^0.6.0; -//True POZ Token will have this, +//True POZ Token will have this, interface IPOZBenefit { - function IsPOZHolder(address _Subject) external view returns(bool); + function IsPOZHolder(address _Subject) external view returns (bool); } diff --git a/contracts/Benefit/IStaking.sol b/contracts/Benefit/IStaking.sol index 7674c8d..2b69af4 100644 --- a/contracts/Benefit/IStaking.sol +++ b/contracts/Benefit/IStaking.sol @@ -4,5 +4,5 @@ pragma solidity ^0.6.0; interface IStaking { - function stakeOf(address account) external view returns (uint256) ; + function stakeOf(address account) external view returns (uint256); } diff --git a/contracts/EnvelopToken/Manageable.sol b/contracts/EnvelopToken/Manageable.sol index ac0b6ca..ab34459 100644 --- a/contracts/EnvelopToken/Manageable.sol +++ b/contracts/EnvelopToken/Manageable.sol @@ -7,9 +7,13 @@ import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "poolz-helper/contracts/GovManager.sol"; import "poolz-helper/contracts/IWhiteList.sol"; -contract Manageable is ERC20Helper, GovManager{ - - event LockingDetails(address TokenAddress, uint256 Amount, uint8 TotalUnlocks, uint256 FinishTime); +contract Manageable is ERC20Helper, GovManager { + event LockingDetails( + address TokenAddress, + uint256 Amount, + uint8 TotalUnlocks, + uint256 FinishTime + ); address public OriginalTokenAddress; address public LockedDealAddress; @@ -21,16 +25,19 @@ contract Manageable is ERC20Helper, GovManager{ struct lockDetails { uint64 unlockTime; - uint ratio; + uint256 ratio; } mapping(uint8 => lockDetails) public LockDetails; uint8 public totalUnlocks; - uint public totalOfRatios; + uint256 public totalOfRatios; modifier tokenReady(bool status) { - require(status ? totalUnlocks != 0 : totalUnlocks == 0, "Unlock Data status error"); + require( + status ? totalUnlocks != 0 : totalUnlocks == 0, + "Unlock Data status error" + ); _; } @@ -41,11 +48,17 @@ contract Manageable is ERC20Helper, GovManager{ uint8[] memory _ratios, uint256 _finishTime ) internal tokenReady(false) { - require(_unlockTimes.length == _ratios.length, "Both arrays should have same length."); - require(_unlockTimes.length > 0, "Array length should be greater than 0"); + require( + _unlockTimes.length == _ratios.length, + "Both arrays should have same length." + ); + require( + _unlockTimes.length > 0, + "Array length should be greater than 0" + ); OriginalTokenAddress = _tokenAddress; TransferInToken(_tokenAddress, msg.sender, _amount); - for(uint8 i=0; i<_unlockTimes.length ; i++){ + for (uint8 i = 0; i < _unlockTimes.length; i++) { LockDetails[i] = lockDetails(_unlockTimes[i], _ratios[i]); totalOfRatios = SafeMath.add(totalOfRatios, _ratios[i]); } @@ -58,15 +71,20 @@ contract Manageable is ERC20Helper, GovManager{ LockedDealAddress = lockedDeal; } - function _SetupWhitelist(address _whitelistAddress, uint256 _whitelistId) internal onlyOwnerOrGov { + function _SetupWhitelist(address _whitelistAddress, uint256 _whitelistId) + internal + onlyOwnerOrGov + { WhitelistAddress = _whitelistAddress; WhitelistId = _whitelistId; } - function registerWhitelist(address _address, uint256 _amount) internal returns(bool) { + function registerWhitelist(address _address, uint256 _amount) + internal + returns (bool) + { if (WhitelistId == 0) return true; //turn-off IWhiteList(WhitelistAddress).Register(_address, WhitelistId, _amount); return true; } - -} \ No newline at end of file +} diff --git a/contracts/EnvelopToken/OriginalToken.sol b/contracts/EnvelopToken/OriginalToken.sol index e8493e4..36264f1 100644 --- a/contracts/EnvelopToken/OriginalToken.sol +++ b/contracts/EnvelopToken/OriginalToken.sol @@ -5,21 +5,22 @@ import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; import "openzeppelin-solidity/contracts/access/Ownable.sol"; /** -* @title TestToken is a basic ERC20 Token -*/ -contract OriginalToken is ERC20, Ownable{ - + * @title TestToken is a basic ERC20 Token + */ +contract OriginalToken is ERC20, Ownable { /** - * @dev assign totalSupply to account creating this contract - */ - - constructor(string memory _TokenName, string memory _TokenSymbol) ERC20(_TokenName, _TokenSymbol) public { + * @dev assign totalSupply to account creating this contract + */ + + constructor(string memory _TokenName, string memory _TokenSymbol) + public + ERC20(_TokenName, _TokenSymbol) + { _setupDecimals(18); _mint(msg.sender, 10000 * 10**18); - } - - function FreeTest () public { + + function FreeTest() public { _mint(msg.sender, 10000 * 10**18); } } diff --git a/contracts/HodlersWhitelist/HodlersWhitelist.sol b/contracts/HodlersWhitelist/HodlersWhitelist.sol index 6cfaabf..3c364d9 100644 --- a/contracts/HodlersWhitelist/HodlersWhitelist.sol +++ b/contracts/HodlersWhitelist/HodlersWhitelist.sol @@ -7,7 +7,7 @@ contract HodlersWhitelist is Manageable { constructor() public { MaxUsersLimit = 600; } - + uint256 public MaxUsersLimit; modifier isBelowUserLimit(uint256 _limit) { @@ -19,8 +19,12 @@ contract HodlersWhitelist is Manageable { MaxUsersLimit = _limit; } - function CreateManualWhiteList(uint256 _ChangeUntil) external onlyOwnerOrGov returns (uint256 Id) { - WhitelistSettings[WhiteListCount] = WhiteListItem( + function CreateManualWhiteList(uint256 _ChangeUntil) + external + onlyOwnerOrGov + returns (uint256 Id) + { + WhitelistSettings[WhiteListCount] = WhiteListItem( msg.sender, _ChangeUntil, false @@ -47,8 +51,8 @@ contract HodlersWhitelist is Manageable { TimeRemaining(_Id) isBelowUserLimit(_Users.length) { - require(_Users.length > 0,"Need something..."); - if(!WhitelistSettings[_Id].isReady){ + require(_Users.length > 0, "Need something..."); + if (!WhitelistSettings[_Id].isReady) { WhitelistSettings[_Id].isReady = true; } for (uint256 index = 0; index < _Users.length; index++) { @@ -67,4 +71,4 @@ contract HodlersWhitelist is Manageable { _RemoveAddress(_Id, _Users[index]); } } -} \ No newline at end of file +} diff --git a/contracts/HodlersWhitelist/Manageable.sol b/contracts/HodlersWhitelist/Manageable.sol index 424200b..076f3d0 100644 --- a/contracts/HodlersWhitelist/Manageable.sol +++ b/contracts/HodlersWhitelist/Manageable.sol @@ -4,7 +4,11 @@ pragma solidity ^0.6.0; import "poolz-helper/contracts/GovManager.sol"; contract Manageable is GovManager { - event NewWhiteList(uint _WhitelistId, address _creator, uint _changeUntil); + event NewWhiteList( + uint256 _WhitelistId, + address _creator, + uint256 _changeUntil + ); modifier OnlyCreator(uint256 _Id) { require( @@ -14,7 +18,7 @@ contract Manageable is GovManager { _; } - modifier TimeRemaining(uint256 _Id){ + modifier TimeRemaining(uint256 _Id) { require( now < WhitelistSettings[_Id].ChangeUntil, "Time for edit is finished" @@ -22,7 +26,7 @@ contract Manageable is GovManager { _; } - modifier ValidateId(uint256 _Id){ + modifier ValidateId(uint256 _Id) { require(_Id < WhiteListCount, "Wrong ID"); _; } @@ -50,11 +54,11 @@ contract Manageable is GovManager { WhitelistDB[_Id][user] = false; } - function isWhiteListReady(uint256 _Id) external view returns(bool){ + function isWhiteListReady(uint256 _Id) external view returns (bool) { return WhitelistSettings[_Id].isReady; } - function IsPOZHolder(address _Sender) external view returns(bool){ + function IsPOZHolder(address _Sender) external view returns (bool) { return WhitelistDB[MainWhitelistId][_Sender]; } -} \ No newline at end of file +} diff --git a/contracts/LockedDeal/LockedControl.sol b/contracts/LockedDeal/LockedControl.sol index c02fe69..366b07b 100644 --- a/contracts/LockedDeal/LockedControl.sol +++ b/contracts/LockedDeal/LockedControl.sol @@ -3,17 +3,18 @@ pragma solidity ^0.6.0; import "./LockedPoolz.sol"; -contract LockedControl is LockedPoolz{ - - function TransferPoolOwnership( - uint256 _PoolId, - address _NewOwner - ) external isPoolValid(_PoolId) isPoolOwner(_PoolId) notZeroAddress(_NewOwner) { +contract LockedControl is LockedPoolz { + function TransferPoolOwnership(uint256 _PoolId, address _NewOwner) + external + isPoolValid(_PoolId) + isPoolOwner(_PoolId) + notZeroAddress(_NewOwner) + { Pool storage pool = AllPoolz[_PoolId]; pool.Owner = _NewOwner; uint256[] storage array = MyPoolz[msg.sender]; - for(uint i=0 ; i uint) Allowance; + mapping(address => uint256) Allowance; } // transfer ownership // allowance @@ -31,52 +41,67 @@ contract LockedPoolz is Manageable { mapping(address => uint256[]) MyPoolz; uint256 internal Index; - modifier isTokenValid(address _Token){ + modifier isTokenValid(address _Token) { require(isTokenWhiteListed(_Token), "Need Valid ERC20 Token"); //check if _Token is ERC20 _; } - modifier isPoolValid(uint256 _PoolId){ + modifier isPoolValid(uint256 _PoolId) { require(_PoolId < Index, "Pool does not exist"); _; } - modifier isPoolOwner(uint256 _PoolId){ - require(AllPoolz[_PoolId].Owner == msg.sender, "You are not Pool Owner"); + modifier isPoolOwner(uint256 _PoolId) { + require( + AllPoolz[_PoolId].Owner == msg.sender, + "You are not Pool Owner" + ); _; } - modifier isAllowed(uint256 _PoolId, uint256 _amount){ - require(_amount <= AllPoolz[_PoolId].Allowance[msg.sender], "Not enough Allowance"); + modifier isAllowed(uint256 _PoolId, uint256 _amount) { + require( + _amount <= AllPoolz[_PoolId].Allowance[msg.sender], + "Not enough Allowance" + ); _; } - modifier isLocked(uint256 _PoolId){ + modifier isLocked(uint256 _PoolId) { require(AllPoolz[_PoolId].UnlockTime > now, "Pool is Unlocked"); _; } - modifier notZeroAddress(address _address){ + modifier notZeroAddress(address _address) { require(_address != address(0x0), "Zero Address is not allowed"); _; } - modifier isGreaterThanZero(uint256 _num){ + modifier isGreaterThanZero(uint256 _num) { require(_num > 0, "Array length should be greater than zero"); _; } - modifier isBelowLimit(uint256 _num){ + modifier isBelowLimit(uint256 _num) { require(_num <= maxTransactionLimit, "Max array length limit exceeded"); _; } - function SplitPool(uint256 _PoolId, uint256 _NewAmount , address _NewOwner) internal returns(uint256) { + function SplitPool( + uint256 _PoolId, + uint256 _NewAmount, + address _NewOwner + ) internal returns (uint256) { Pool storage pool = AllPoolz[_PoolId]; require(pool.Amount >= _NewAmount, "Not Enough Amount Balance"); uint256 poolAmount = SafeMath.sub(pool.Amount, _NewAmount); pool.Amount = poolAmount; - uint256 poolId = CreatePool(pool.Token, pool.UnlockTime, _NewAmount, _NewOwner); + uint256 poolId = CreatePool( + pool.Token, + pool.UnlockTime, + _NewAmount, + _NewOwner + ); return poolId; } @@ -86,7 +111,7 @@ contract LockedPoolz is Manageable { uint64 _FinishTime, //Until what time the pool will work uint256 _StartAmount, //Total amount of the tokens to sell in the pool address _Owner // Who the tokens belong to - ) internal returns(uint256){ + ) internal returns (uint256) { //register the pool AllPoolz[Index] = Pool(_FinishTime, _StartAmount, _Owner, _Token); MyPoolz[_Owner].push(Index); diff --git a/contracts/LockedDeal/LockedPoolzData.sol b/contracts/LockedDeal/LockedPoolzData.sol index 41d2ef6..4c2e006 100644 --- a/contracts/LockedDeal/LockedPoolzData.sol +++ b/contracts/LockedDeal/LockedPoolzData.sol @@ -20,7 +20,10 @@ contract LockedPoolzData is LockedControl { ) { Pool storage pool = AllPoolz[_id]; - require(pool.Owner == msg.sender || pool.Allowance[msg.sender] > 0, "Private Information"); + require( + pool.Owner == msg.sender || pool.Allowance[msg.sender] > 0, + "Private Information" + ); return ( AllPoolz[_id].UnlockTime, AllPoolz[_id].Amount, diff --git a/contracts/LockedDeal/Manageable.sol b/contracts/LockedDeal/Manageable.sol index b45a88a..6f58360 100644 --- a/contracts/LockedDeal/Manageable.sol +++ b/contracts/LockedDeal/Manageable.sol @@ -12,33 +12,40 @@ contract Manageable is ETHHelper, ERC20Helper, PozBenefit { MinDuration = 0; //need to set maxTransactionLimit = 400; } - mapping (address => uint256) FeeMap; + + mapping(address => uint256) FeeMap; //@dev for percent use uint16 uint16 internal Fee; //the fee for the pool uint16 internal MinDuration; //the minimum duration of a pool, in seconds address public WhiteList_Address; bool public isTokenFilterOn; - uint public WhiteListId; + uint256 public WhiteListId; uint256 public maxTransactionLimit; - - function setWhiteListAddress(address _address) external onlyOwner{ + + function setWhiteListAddress(address _address) external onlyOwner { WhiteList_Address = _address; } - function setWhiteListId(uint256 _id) external onlyOwner{ - WhiteListId= _id; + function setWhiteListId(uint256 _id) external onlyOwner { + WhiteListId = _id; } - function swapTokenFilter() external onlyOwner{ + function swapTokenFilter() external onlyOwner { isTokenFilterOn = !isTokenFilterOn; } - function isTokenWhiteListed(address _tokenAddress) public view returns(bool) { - return !isTokenFilterOn || IWhiteList(WhiteList_Address).Check(_tokenAddress, WhiteListId) > 0; + function isTokenWhiteListed(address _tokenAddress) + public + view + returns (bool) + { + return + !isTokenFilterOn || + IWhiteList(WhiteList_Address).Check(_tokenAddress, WhiteListId) > 0; } - function setMaxTransactionLimit(uint256 _newLimit) external onlyOwner{ + function setMaxTransactionLimit(uint256 _newLimit) external onlyOwner { maxTransactionLimit = _newLimit; } @@ -54,9 +61,12 @@ contract Manageable is ETHHelper, ERC20Helper, PozBenefit { return Fee; } - function SetFee(uint16 _fee) public onlyOwner + function SetFee(uint16 _fee) + public + onlyOwner PercentCheckOk(_fee) - LeftIsBigger( _fee, PozFee) { + LeftIsBigger(_fee, PozFee) + { Fee = _fee; } @@ -64,7 +74,7 @@ contract Manageable is ETHHelper, ERC20Helper, PozBenefit { public onlyOwner PercentCheckOk(_fee) - LeftIsBigger( Fee,_fee) + LeftIsBigger(Fee, _fee) { PozFee = _fee; } @@ -73,8 +83,8 @@ contract Manageable is ETHHelper, ERC20Helper, PozBenefit { _to.transfer(address(this).balance); // keeps only fee eth on contract //To Do need to take 16% to burn!!! } - function WithdrawERC20Fee(address _Token, address _to) public onlyOwner { + function WithdrawERC20Fee(address _Token, address _to) public onlyOwner { ERC20(_Token).transfer(_to, FeeMap[_Token]); - FeeMap[_Token] = 0 ; + FeeMap[_Token] = 0; } } diff --git a/contracts/LockedDealV2/LockedControl.sol b/contracts/LockedDealV2/LockedControl.sol index a5497f2..f6fb53f 100644 --- a/contracts/LockedDealV2/LockedControl.sol +++ b/contracts/LockedDealV2/LockedControl.sol @@ -34,7 +34,13 @@ contract LockedControl is LockedPoolz { uint256 _PoolId, uint256 _NewAmount, address _NewOwner - ) external isPoolValid(_PoolId) isPoolOwner(_PoolId) isLocked(_PoolId) returns(uint256) { + ) + external + isPoolValid(_PoolId) + isPoolOwner(_PoolId) + isLocked(_PoolId) + returns (uint256) + { uint256 poolId = SplitPool(_PoolId, _NewAmount, _NewOwner); return poolId; } @@ -43,12 +49,23 @@ contract LockedControl is LockedPoolz { uint256 _PoolId, uint256 _Amount, address _Spender - ) external isPoolValid(_PoolId) isPoolOwner(_PoolId) isLocked(_PoolId) notZeroAddress(_Spender) { + ) + external + isPoolValid(_PoolId) + isPoolOwner(_PoolId) + isLocked(_PoolId) + notZeroAddress(_Spender) + { Allowance[_PoolId][_Spender] = _Amount; emit PoolApproval(_PoolId, _Spender, _Amount); } - function GetPoolAllowance(uint256 _PoolId, address _Address) public view isPoolValid(_PoolId) returns(uint256){ + function GetPoolAllowance(uint256 _PoolId, address _Address) + public + view + isPoolValid(_PoolId) + returns (uint256) + { return Allowance[_PoolId][_Address]; } @@ -56,10 +73,16 @@ contract LockedControl is LockedPoolz { uint256 _PoolId, uint256 _Amount, address _Address - ) external isPoolValid(_PoolId) isAllowed(_PoolId, _Amount) isLocked(_PoolId) returns(uint256) { + ) + external + isPoolValid(_PoolId) + isAllowed(_PoolId, _Amount) + isLocked(_PoolId) + returns (uint256) + { uint256 poolId = SplitPool(_PoolId, _Amount, _Address); uint256 _NewAmount = Allowance[_PoolId][msg.sender] - _Amount; - Allowance[_PoolId][msg.sender] = _NewAmount; + Allowance[_PoolId][msg.sender] = _NewAmount; return poolId; } @@ -69,9 +92,12 @@ contract LockedControl is LockedPoolz { uint256 _FinishTime, //Until what time the pool will end uint256 _StartAmount, //Total amount of the tokens to sell in the pool address _Owner // Who the tokens belong to - ) external payable notZeroAddress(_Owner) returns(uint256) { + ) external payable notZeroAddress(_Owner) returns (uint256) { TransferInToken(_Token, msg.sender, _StartAmount); - if(WhiteList_Address != address(0) && !(isUserWithoutFee(msg.sender) || isTokenWithoutFee(_Token))){ + if ( + WhiteList_Address != address(0) && + !(isUserWithoutFee(msg.sender) || isTokenWithoutFee(_Token)) + ) { PayFee(Fee); } CreatePool(_Token, _StartTime, _FinishTime, _StartAmount, _Owner); @@ -83,7 +109,9 @@ contract LockedControl is LockedPoolz { uint256[] calldata _FinishTime, uint256[] calldata _StartAmount, address[] calldata _Owner - ) external payable + ) + external + payable isGreaterThanZero(_Owner.length) isBelowLimit(_Owner.length) { @@ -91,12 +119,21 @@ contract LockedControl is LockedPoolz { require(_StartTime.length == _FinishTime.length, "Date Array Invalid"); require(_Owner.length == _StartAmount.length, "Amount Array Invalid"); TransferInToken(_Token, msg.sender, Array.getArraySum(_StartAmount)); - if(WhiteList_Address != address(0) && !(isUserWithoutFee(msg.sender) || isTokenWithoutFee(_Token))){ + if ( + WhiteList_Address != address(0) && + !(isUserWithoutFee(msg.sender) || isTokenWithoutFee(_Token)) + ) { PayFee(Fee * _Owner.length); } uint256 firstPoolId = Index; - for(uint i=0 ; i < _Owner.length; i++){ - CreatePool(_Token, _StartTime[i], _FinishTime[i], _StartAmount[i], _Owner[i]); + for (uint256 i = 0; i < _Owner.length; i++) { + CreatePool( + _Token, + _StartTime[i], + _FinishTime[i], + _StartAmount[i], + _Owner[i] + ); } uint256 lastPoolId = Index - 1; emit MassPoolsCreated(firstPoolId, lastPoolId); @@ -109,20 +146,35 @@ contract LockedControl is LockedPoolz { uint256[] calldata _FinishTime, uint256[] calldata _StartAmount, address[] calldata _Owner - ) external payable + ) + external + payable isGreaterThanZero(_StartTime.length) isBelowLimit(_Owner.length * _FinishTime.length) { require(_Owner.length == _StartAmount.length, "Amount Array Invalid"); require(_FinishTime.length == _StartTime.length, "Date Array Invalid"); - TransferInToken(_Token, msg.sender, Array.getArraySum(_StartAmount) * _FinishTime.length); + TransferInToken( + _Token, + msg.sender, + Array.getArraySum(_StartAmount) * _FinishTime.length + ); uint256 firstPoolId = Index; - if(WhiteList_Address != address(0) && !(isUserWithoutFee(msg.sender) || isTokenWithoutFee(_Token))){ + if ( + WhiteList_Address != address(0) && + !(isUserWithoutFee(msg.sender) || isTokenWithoutFee(_Token)) + ) { PayFee(Fee * _Owner.length * _FinishTime.length); } - for(uint i=0 ; i < _FinishTime.length ; i++){ - for(uint j=0 ; j < _Owner.length ; j++){ - CreatePool(_Token, _StartTime[i], _FinishTime[i], _StartAmount[j], _Owner[j]); + for (uint256 i = 0; i < _FinishTime.length; i++) { + for (uint256 j = 0; j < _Owner.length; j++) { + CreatePool( + _Token, + _StartTime[i], + _FinishTime[i], + _StartAmount[j], + _Owner[j] + ); } } uint256 lastPoolId = Index - 1; diff --git a/contracts/LockedDealV2/LockedDealV2.sol b/contracts/LockedDealV2/LockedDealV2.sol index 56c6572..18f303e 100644 --- a/contracts/LockedDealV2/LockedDealV2.sol +++ b/contracts/LockedDealV2/LockedDealV2.sol @@ -4,15 +4,21 @@ pragma solidity ^0.8.0; import "./LockedPoolzData.sol"; contract LockedDealV2 is LockedPoolzData { - function getWithdrawableAmount(uint256 _PoolId) public view isPoolValid(_PoolId) returns(uint256){ + function getWithdrawableAmount(uint256 _PoolId) + public + view + isPoolValid(_PoolId) + returns (uint256) + { Pool storage pool = AllPoolz[_PoolId]; - if(block.timestamp < pool.StartTime) return 0; - if(pool.FinishTime < block.timestamp) return pool.StartAmount - pool.DebitedAmount; + if (block.timestamp < pool.StartTime) return 0; + if (pool.FinishTime < block.timestamp) + return pool.StartAmount - pool.DebitedAmount; uint256 totalPoolDuration = pool.FinishTime - pool.StartTime; uint256 timePassed = block.timestamp - pool.StartTime; uint256 timePassedPermille = timePassed * 1000; uint256 ratioPermille = timePassedPermille / totalPoolDuration; - uint256 debitableAmount = pool.StartAmount * ratioPermille/ 1000; + uint256 debitableAmount = (pool.StartAmount * ratioPermille) / 1000; return debitableAmount - pool.DebitedAmount; } @@ -28,11 +34,7 @@ contract LockedDealV2 is LockedPoolzData { uint256 tokenAmount = getWithdrawableAmount(_PoolId); uint256 tempDebitAmount = tokenAmount + pool.DebitedAmount; pool.DebitedAmount = tempDebitAmount; - TransferToken( - pool.Token, - pool.Owner, - tokenAmount - ); + TransferToken(pool.Token, pool.Owner, tokenAmount); emit TokenWithdrawn(_PoolId, pool.Owner, tokenAmount); return true; } diff --git a/contracts/LockedDealV2/LockedManageable.sol b/contracts/LockedDealV2/LockedManageable.sol index 101e3c7..88fa9ba 100644 --- a/contracts/LockedDealV2/LockedManageable.sol +++ b/contracts/LockedDealV2/LockedManageable.sol @@ -6,7 +6,11 @@ import "poolz-helper-v2/contracts/FeeBaseHelper.sol"; import "./LockedDealEvents.sol"; import "./LockedDealModifiers.sol"; -contract LockedManageable is FeeBaseHelper, LockedDealEvents, LockedDealModifiers { +contract LockedManageable is + FeeBaseHelper, + LockedDealEvents, + LockedDealModifiers +{ constructor() { maxTransactionLimit = 400; isTokenFilterOn = false; // disable token filter whitelist @@ -32,19 +36,45 @@ contract LockedManageable is FeeBaseHelper, LockedDealEvents, LockedDealModifier isTokenFilterOn = !isTokenFilterOn; } - function isTokenWithoutFee(address _tokenAddress) notZeroAddress(WhiteList_Address) public view returns(bool) { - return IWhiteList(WhiteList_Address).Check(_tokenAddress, TokenFeeWhiteListId) > 0; + function isTokenWithoutFee(address _tokenAddress) + public + view + notZeroAddress(WhiteList_Address) + returns (bool) + { + return + IWhiteList(WhiteList_Address).Check( + _tokenAddress, + TokenFeeWhiteListId + ) > 0; } - function isTokenWhiteListed(address _tokenAddress) public view returns(bool) { - return !isTokenFilterOn || IWhiteList(WhiteList_Address).Check(_tokenAddress, TokenFilterWhiteListId) > 0; + function isTokenWhiteListed(address _tokenAddress) + public + view + returns (bool) + { + return + !isTokenFilterOn || + IWhiteList(WhiteList_Address).Check( + _tokenAddress, + TokenFilterWhiteListId + ) > + 0; } - function isUserWithoutFee(address _UserAddress) notZeroAddress(WhiteList_Address) public view returns(bool) { - return IWhiteList(WhiteList_Address).Check(_UserAddress, UserWhiteListId) > 0; + function isUserWithoutFee(address _UserAddress) + public + view + notZeroAddress(WhiteList_Address) + returns (bool) + { + return + IWhiteList(WhiteList_Address).Check(_UserAddress, UserWhiteListId) > + 0; } - function setMaxTransactionLimit(uint256 _newLimit) external onlyOwner{ + function setMaxTransactionLimit(uint256 _newLimit) external onlyOwner { maxTransactionLimit = _newLimit; } } diff --git a/contracts/LockedDealV2/LockedPoolz.sol b/contracts/LockedDealV2/LockedPoolz.sol index 25504d5..47b57c9 100644 --- a/contracts/LockedDealV2/LockedPoolz.sol +++ b/contracts/LockedDealV2/LockedPoolz.sol @@ -46,7 +46,14 @@ contract LockedPoolz is LockedManageable { "StartTime is greater than FinishTime" ); //register the pool - AllPoolz[Index] = Pool(_StartTime, _FinishTime, _StartAmount, 0, _Owner, _Token); + AllPoolz[Index] = Pool( + _StartTime, + _FinishTime, + _StartAmount, + 0, + _Owner, + _Token + ); MyPoolz[_Owner].push(Index); emit NewPoolCreated( Index, diff --git a/contracts/PoolzBack/Invest.sol b/contracts/PoolzBack/Invest.sol index 2adf81c..29d2a42 100644 --- a/contracts/PoolzBack/Invest.sol +++ b/contracts/PoolzBack/Invest.sol @@ -7,14 +7,18 @@ import "poolz-helper/contracts/IPozBenefit.sol"; import "poolz-helper/contracts/ILockedDeal.sol"; contract Invest is PoolsData { - event NewInvestorEvent(uint256 Investor_ID, address Investor_Address, uint256 LockedDeal_ID); + event NewInvestorEvent( + uint256 Investor_ID, + address Investor_Address, + uint256 LockedDeal_ID + ); modifier CheckTime(uint256 _Time) { require(now >= _Time, "Pool not open yet"); _; } - modifier validateSender(){ + modifier validateSender() { require( msg.sender == tx.origin && !isContract(msg.sender), "Some thing wrong with the msgSender" @@ -38,10 +42,10 @@ contract Invest is PoolsData { uint256 InvestTime; //the time that investment made } - function getTotalInvestor() external view returns(uint256){ + function getTotalInvestor() external view returns (uint256) { return TotalInvestors; } - + //@dev Send in wei function InvestETH(uint256 _PoolId) external @@ -50,21 +54,23 @@ contract Invest is PoolsData { whenNotPaused CheckTime(pools[_PoolId].MoreData.StartTime) isPoolId(_PoolId) - validateSender() + validateSender { - require(pools[_PoolId].BaseData.Maincoin == address(0x0), "Pool is only for ETH"); + require( + pools[_PoolId].BaseData.Maincoin == address(0x0), + "Pool is only for ETH" + ); uint256 ThisInvestor = NewInvestor(msg.sender, msg.value, _PoolId); uint256 Tokens = CalcTokens(_PoolId, msg.value, msg.sender); - + TokenAllocate(_PoolId, ThisInvestor, Tokens); - uint256 EthMinusFee = - SafeMath.div( - SafeMath.mul(msg.value, SafeMath.sub(10000, CalcFee(_PoolId))), - 10000 - ); + uint256 EthMinusFee = SafeMath.div( + SafeMath.mul(msg.value, SafeMath.sub(10000, CalcFee(_PoolId))), + 10000 + ); // send money to project owner - the fee stays on contract - TransferETH(payable(pools[_PoolId].BaseData.Creator), EthMinusFee); + TransferETH(payable(pools[_PoolId].BaseData.Creator), EthMinusFee); RegisterInvest(_PoolId, Tokens); } @@ -73,7 +79,7 @@ contract Invest is PoolsData { whenNotPaused CheckTime(pools[_PoolId].MoreData.StartTime) isPoolId(_PoolId) - validateSender() + validateSender { require( pools[_PoolId].BaseData.Maincoin != address(0x0), @@ -85,8 +91,10 @@ contract Invest is PoolsData { TokenAllocate(_PoolId, ThisInvestor, Tokens); - uint256 RegularFeePay = - SafeMath.div(SafeMath.mul(_Amount, CalcFee(_PoolId)), 10000); + uint256 RegularFeePay = SafeMath.div( + SafeMath.mul(_Amount, CalcFee(_PoolId)), + 10000 + ); uint256 RegularPaymentMinusFee = SafeMath.sub(_Amount, RegularFeePay); FeeMap[pools[_PoolId].BaseData.Maincoin] = SafeMath.add( @@ -101,19 +109,39 @@ contract Invest is PoolsData { RegisterInvest(_PoolId, Tokens); } - function TokenAllocate(uint256 _PoolId, uint256 _ThisInvestor, uint256 _Tokens) internal { + function TokenAllocate( + uint256 _PoolId, + uint256 _ThisInvestor, + uint256 _Tokens + ) internal { uint256 lockedDealId; if (isPoolLocked(_PoolId)) { - require(isUsingLockedDeal(), "Cannot invest in TLP without LockedDeal"); - (address tokenAddress,,,,,) = GetPoolBaseData(_PoolId); - (uint64 lockedUntil,,,,,) = GetPoolMoreData(_PoolId); + require( + isUsingLockedDeal(), + "Cannot invest in TLP without LockedDeal" + ); + (address tokenAddress, , , , , ) = GetPoolBaseData(_PoolId); + (uint64 lockedUntil, , , , , ) = GetPoolMoreData(_PoolId); ApproveAllowanceERC20(tokenAddress, LockedDealAddress, _Tokens); - lockedDealId = ILockedDeal(LockedDealAddress).CreateNewPool(tokenAddress, lockedUntil, _Tokens, msg.sender); + lockedDealId = ILockedDeal(LockedDealAddress).CreateNewPool( + tokenAddress, + lockedUntil, + _Tokens, + msg.sender + ); } else { // not locked, will transfer the tokens - TransferToken(pools[_PoolId].BaseData.Token, Investors[_ThisInvestor].InvestorAddress, _Tokens); + TransferToken( + pools[_PoolId].BaseData.Token, + Investors[_ThisInvestor].InvestorAddress, + _Tokens + ); } - emit NewInvestorEvent(_ThisInvestor, Investors[_ThisInvestor].InvestorAddress, lockedDealId); + emit NewInvestorEvent( + _ThisInvestor, + Investors[_ThisInvestor].InvestorAddress, + lockedDealId + ); } function RegisterInvest(uint256 _PoolId, uint256 _Tokens) internal { @@ -153,8 +181,8 @@ contract Invest is PoolsData { result = SafeMath.mul(msgValue, pools[_Pid].BaseData.POZRate); } if (GetPoolStatus(_Pid) == PoolStatus.Open) { - (,,address _mainCoin) = GetPoolExtraData(_Pid); - if(_mainCoin == address(0x0)){ + (, , address _mainCoin) = GetPoolExtraData(_Pid); + if (_mainCoin == address(0x0)) { require( msgValue >= MinETHInvest && msgValue <= MaxETHInvest, "Investment amount not valid" @@ -182,12 +210,15 @@ contract Invest is PoolsData { revert("Wrong pool status to CalcTokens"); } - function VerifyPozHolding(address _Sender) internal view returns(bool){ - if(Benefit_Address == address(0)) return true; + function VerifyPozHolding(address _Sender) internal view returns (bool) { + if (Benefit_Address == address(0)) return true; return IPOZBenefit(Benefit_Address).IsPOZHolder(_Sender); } - function LastRegisterWhitelist(address _Sender,uint256 _Id) internal returns(bool) { + function LastRegisterWhitelist(address _Sender, uint256 _Id) + internal + returns (bool) + { if (_Id == 0) return true; //turn-off IWhiteList(WhiteList_Address).LastRoundRegister(_Sender, _Id); return true; diff --git a/contracts/PoolzBack/InvestorData.sol b/contracts/PoolzBack/InvestorData.sol index c0f2b1c..e5399e8 100644 --- a/contracts/PoolzBack/InvestorData.sol +++ b/contracts/PoolzBack/InvestorData.sol @@ -5,7 +5,6 @@ import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "./Invest.sol"; contract InvestorData is Invest { - //Give all the id's of the investment by sender address function GetMyInvestmentIds() public view returns (uint256[] memory) { return InvestorsMap[msg.sender]; diff --git a/contracts/PoolzBack/Manageable.sol b/contracts/PoolzBack/Manageable.sol index a51587b..be62770 100644 --- a/contracts/PoolzBack/Manageable.sol +++ b/contracts/PoolzBack/Manageable.sol @@ -10,7 +10,7 @@ import "poolz-helper/contracts/IWhiteList.sol"; import "openzeppelin-solidity/contracts/utils/Pausable.sol"; -contract Manageable is ETHHelper, ERC20Helper, PozBenefit, Pausable { +contract Manageable is ETHHelper, ERC20Helper, PozBenefit, Pausable { constructor() public { Fee = 20; // *10000 //MinDuration = 0; //need to set @@ -45,23 +45,31 @@ contract Manageable is ETHHelper, ERC20Helper, PozBenefit, Pausable { IsTokenFilterOn = !IsTokenFilterOn; } - function setTokenWhitelistId(uint256 _whiteListId) external onlyOwnerOrGov{ + function setTokenWhitelistId(uint256 _whiteListId) external onlyOwnerOrGov { TokenWhitelistId = _whiteListId; } - function setMCWhitelistId(uint256 _whiteListId) external onlyOwnerOrGov{ + function setMCWhitelistId(uint256 _whiteListId) external onlyOwnerOrGov { MCWhitelistId = _whiteListId; } function IsValidToken(address _address) public view returns (bool) { - return !IsTokenFilterOn || (IWhiteList(WhiteList_Address).Check(_address, TokenWhitelistId) > 0); + return + !IsTokenFilterOn || + (IWhiteList(WhiteList_Address).Check(_address, TokenWhitelistId) > + 0); } function IsERC20Maincoin(address _address) public view returns (bool) { - return !IsTokenFilterOn || IWhiteList(WhiteList_Address).Check(_address, MCWhitelistId) > 0; + return + !IsTokenFilterOn || + IWhiteList(WhiteList_Address).Check(_address, MCWhitelistId) > 0; } - - function SetWhiteList_Address(address _WhiteList_Address) public onlyOwnerOrGov { + + function SetWhiteList_Address(address _WhiteList_Address) + public + onlyOwnerOrGov + { WhiteList_Address = _WhiteList_Address; } @@ -76,10 +84,11 @@ contract Manageable is ETHHelper, ERC20Helper, PozBenefit, Pausable { MinETHInvest = _MinETHInvest; MaxETHInvest = _MaxETHInvest; } - function SetMinMaxERC20Invest(uint256 _MinERC20Invest, uint256 _MaxERC20Invest) - public - onlyOwnerOrGov - { + + function SetMinMaxERC20Invest( + uint256 _MinERC20Invest, + uint256 _MaxERC20Invest + ) public onlyOwnerOrGov { MinERC20Invest = _MinERC20Invest; MaxERC20Invest = _MaxERC20Invest; } @@ -122,7 +131,7 @@ contract Manageable is ETHHelper, ERC20Helper, PozBenefit, Pausable { UseLockedDealForTlp = !UseLockedDealForTlp; } - function isUsingLockedDeal() public view returns(bool) { + function isUsingLockedDeal() public view returns (bool) { return UseLockedDealForTlp && LockedDealAddress != address(0x0); } @@ -133,5 +142,4 @@ contract Manageable is ETHHelper, ERC20Helper, PozBenefit, Pausable { function unpause() public onlyOwnerOrGov { _unpause(); } - } diff --git a/contracts/PoolzBack/Pools.sol b/contracts/PoolzBack/Pools.sol index 489272b..d23ed97 100644 --- a/contracts/PoolzBack/Pools.sol +++ b/contracts/PoolzBack/Pools.sol @@ -41,7 +41,7 @@ contract Pools is Manageable { bool Is21DecimalRate; //If true, the rate will be rate*10^-21 } - function isPoolLocked(uint256 _id) public view returns(bool){ + function isPoolLocked(uint256 _id) public view returns (bool) { return pools[_id].MoreData.LockedUntil > now; } @@ -64,8 +64,14 @@ contract Pools is Manageable { _MainCoin == address(0x0) || IsERC20Maincoin(_MainCoin), "Main coin not in list" ); - require(_FinishTime < SafeMath.add(MaxDuration, now), "Pool duration can't be that long"); - require(_LockedUntil < SafeMath.add(MaxDuration, now) , "Locked value can't be that long"); + require( + _FinishTime < SafeMath.add(MaxDuration, now), + "Pool duration can't be that long" + ); + require( + _LockedUntil < SafeMath.add(MaxDuration, now), + "Locked value can't be that long" + ); require( _Rate <= _POZRate, "POZ holders need to have better price (or the same)" @@ -77,16 +83,15 @@ contract Pools is Manageable { "Need more then MinDuration" ); // check if the time is OK TransferInToken(_Token, msg.sender, _StartAmount); - uint256 Openforall = - (_WhiteListId == 0) - ? _Now //and this - : SafeMath.add( - SafeMath.div( - SafeMath.mul(SafeMath.sub(_FinishTime, _Now), PozTimer), - 10000 - ), - _Now - ); + uint256 Openforall = (_WhiteListId == 0) + ? _Now //and this + : SafeMath.add( + SafeMath.div( + SafeMath.mul(SafeMath.sub(_FinishTime, _Now), PozTimer), + 10000 + ), + _Now + ); //register the pool pools[poolsCount] = Pool( PoolBaseData( diff --git a/contracts/PoolzBack/PoolsData.sol b/contracts/PoolzBack/PoolsData.sol index 5c0f4de..6d5ed9f 100644 --- a/contracts/PoolzBack/PoolsData.sol +++ b/contracts/PoolzBack/PoolsData.sol @@ -4,7 +4,14 @@ pragma solidity ^0.6.0; import "./Pools.sol"; contract PoolsData is Pools { - enum PoolStatus {Created, Open, PreMade, OutOfstock, Finished, Close} //the status of the pools + enum PoolStatus { + Created, + Open, + PreMade, + OutOfstock, + Finished, + Close + } //the status of the pools modifier isPoolId(uint256 _id) { require(_id < poolsCount, "Invalid Pool ID"); @@ -91,7 +98,11 @@ contract PoolsData is Pools { } //@dev no use of revert to make sure the loop will work - function WithdrawLeftOvers(uint256 _PoolId) public isPoolId(_PoolId) returns (bool) { + function WithdrawLeftOvers(uint256 _PoolId) + public + isPoolId(_PoolId) + returns (bool) + { //pool is finished + got left overs + did not took them if (IsReadyWithdrawLeftOvers(_PoolId)) { pools[_PoolId].MoreData.TookLeftOvers = true; @@ -143,10 +154,7 @@ contract PoolsData is Pools { { return (PoolStatus.Close); } - if ( - now >= pools[_id].BaseData.FinishTime && - !isPoolLocked(_id) - ) { + if (now >= pools[_id].BaseData.FinishTime && !isPoolLocked(_id)) { // After finish time - not locked if (pools[_id].MoreData.TookLeftOvers) return (PoolStatus.Close); return (PoolStatus.Finished); diff --git a/contracts/PoolzBack/ThePoolz.sol b/contracts/PoolzBack/ThePoolz.sol index fde49df..d84edc1 100644 --- a/contracts/PoolzBack/ThePoolz.sol +++ b/contracts/PoolzBack/ThePoolz.sol @@ -4,7 +4,7 @@ pragma solidity ^0.6.0; import "./InvestorData.sol"; contract ThePoolz is InvestorData { - constructor() public { } + constructor() public {} function WithdrawETHFee(address payable _to) public onlyOwner { _to.transfer(address(this).balance); // keeps only fee eth on contract //To Do need to take 16% to burn!!! @@ -15,5 +15,4 @@ contract ThePoolz is InvestorData { FeeMap[_Token] = 0; TransferToken(_Token, _to, temp); } - -} \ No newline at end of file +} diff --git a/contracts/PoolzBack/Token.sol b/contracts/PoolzBack/Token.sol index d488769..e0c2104 100644 --- a/contracts/PoolzBack/Token.sol +++ b/contracts/PoolzBack/Token.sol @@ -1,4 +1,4 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; -import "poolz-helper/contracts/Token.sol"; \ No newline at end of file +import "poolz-helper/contracts/Token.sol"; diff --git a/contracts/WhiteList/WhiteList.sol b/contracts/WhiteList/WhiteList.sol index 932c5ec..d6de7f4 100644 --- a/contracts/WhiteList/WhiteList.sol +++ b/contracts/WhiteList/WhiteList.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import "./WhiteListHelper.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; -contract WhiteList is WhiteListHelper, Ownable{ +contract WhiteList is WhiteListHelper, Ownable { constructor() { WhiteListCount = 1; //0 is off MaxUsersLimit = 500; @@ -21,21 +21,22 @@ contract WhiteList is WhiteListHelper, Ownable{ function setMaxUsersLimit(uint256 _limit) external onlyOwner { MaxUsersLimit = _limit; } - + function WithdrawETHFee(address payable _to) public onlyOwner { - _to.transfer(address(this).balance); + _to.transfer(address(this).balance); } function setWhiteListCost(uint256 _newCost) external onlyOwner { WhiteListCost = _newCost; } - function CreateManualWhiteList( - uint256 _ChangeUntil, - address _Contract - ) public payable returns (uint256 Id) { + function CreateManualWhiteList(uint256 _ChangeUntil, address _Contract) + public + payable + returns (uint256 Id) + { require(msg.value >= WhiteListCost, "ether not enough"); - WhitelistSettings[WhiteListCount] = WhiteListItem( + WhitelistSettings[WhiteListCount] = WhiteListItem( /*_Limit == 0 ? type(uint).max :*/ // _Limit, msg.sender, @@ -67,16 +68,23 @@ contract WhiteList is WhiteListHelper, Ownable{ WhitelistSettings[_Id].Contract = _NewContract; } - function AddAddress(uint256 _Id, address[] calldata _Users, uint256[] calldata _Amount) + function AddAddress( + uint256 _Id, + address[] calldata _Users, + uint256[] calldata _Amount + ) external ValidateId(_Id) OnlyCreator(_Id) TimeRemaining(_Id) isBelowUserLimit(_Users.length) { - require(_Users.length == _Amount.length, "Number of users should be same as the amount length"); - require(_Users.length > 0,"Need something..."); - if(!WhitelistSettings[_Id].isReady){ + require( + _Users.length == _Amount.length, + "Number of users should be same as the amount length" + ); + require(_Users.length > 0, "Need something..."); + if (!WhitelistSettings[_Id].isReady) { WhitelistSettings[_Id].isReady = true; } for (uint256 index = 0; index < _Users.length; index++) { @@ -115,21 +123,18 @@ contract WhiteList is WhiteListHelper, Ownable{ assert(WhitelistDB[_Id][_Subject] == temp); } - function LastRoundRegister( - address _Subject, - uint256 _Id - ) external { + function LastRoundRegister(address _Subject, uint256 _Id) external { if (_Id == 0) return; require( msg.sender == WhitelistSettings[_Id].Contract, "Only the Contract can call this" ); require( - WhitelistDB[_Id][_Subject] != type(uint).max, + WhitelistDB[_Id][_Subject] != type(uint256).max, "Sorry, no alocation for Subject" ); - uint256 temp = type(uint).max; + uint256 temp = type(uint256).max; WhitelistDB[_Id][_Subject] = temp; assert(WhitelistDB[_Id][_Subject] == temp); } -} \ No newline at end of file +} diff --git a/contracts/WhiteList/WhiteListHelper.sol b/contracts/WhiteList/WhiteListHelper.sol index 1545f32..ac9bb83 100644 --- a/contracts/WhiteList/WhiteListHelper.sol +++ b/contracts/WhiteList/WhiteListHelper.sol @@ -1,8 +1,13 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -contract WhiteListHelper{ - event NewWhiteList(uint _WhiteListCount, address _creator, address _contract, uint _changeUntil); +contract WhiteListHelper { + event NewWhiteList( + uint256 _WhiteListCount, + address _creator, + address _contract, + uint256 _changeUntil + ); modifier OnlyCreator(uint256 _Id) { require( @@ -12,7 +17,7 @@ contract WhiteListHelper{ _; } - modifier TimeRemaining(uint256 _Id){ + modifier TimeRemaining(uint256 _Id) { require( block.timestamp < WhitelistSettings[_Id].ChangeUntil, "Time for edit is finished" @@ -20,7 +25,7 @@ contract WhiteListHelper{ _; } - modifier ValidateId(uint256 _Id){ + modifier ValidateId(uint256 _Id) { require(_Id < WhiteListCount, "Wrong ID"); _; } @@ -41,7 +46,11 @@ contract WhiteListHelper{ uint256 public WhiteListCost; uint256 public WhiteListCount; - function _AddAddress(uint256 _Id, address user, uint amount) internal { + function _AddAddress( + uint256 _Id, + address user, + uint256 amount + ) internal { WhitelistDB[_Id][user] = amount; } @@ -49,13 +58,13 @@ contract WhiteListHelper{ WhitelistDB[_Id][user] = 0; } - function isWhiteListReady(uint256 _Id) external view returns(bool){ + function isWhiteListReady(uint256 _Id) external view returns (bool) { return WhitelistSettings[_Id].isReady; } //View function to Check if address is whitelisted - function Check(address _user, uint256 _id) external view returns(uint){ - if (_id == 0) return type(uint).max; + function Check(address _user, uint256 _id) external view returns (uint256) { + if (_id == 0) return type(uint256).max; return WhitelistDB[_id][_user]; } -} \ No newline at end of file +} diff --git a/test/07_CreatingPool.js b/test/07_CreatingPool.js index 058473a..b69f4c6 100644 --- a/test/07_CreatingPool.js +++ b/test/07_CreatingPool.js @@ -1,122 +1,159 @@ const ThePoolz = artifacts.require("ThePoolz") const Token = artifacts.require("Token") -const WhiteList = artifacts.require('WhiteList') -const { assert } = require('chai') -const truffleAssert = require('truffle-assertions') +const WhiteList = artifacts.require("WhiteList") +const { assert } = require("chai") +const truffleAssert = require("truffle-assertions") const constants = require("@openzeppelin/test-helpers/src/constants") var BN = web3.utils.BN -const rate = new BN('1000000000') // with decimal21 (shifter) 1 eth^18 = 1 token^6 -const amount = new BN('3000000') //3 tokens for sale -const invest = web3.utils.toWei('1', 'ether') //1eth +const rate = new BN("1000000000") // with decimal21 (shifter) 1 eth^18 = 1 token^6 +const amount = new BN("3000000") //3 tokens for sale -const { createNewWhiteList } = require('./helper') +const { createNewWhiteList } = require("./helper") -contract('Integration between Poolz-Back and WhiteList for Creating New Pool', accounts => { - let poolzBack, testToken, whiteList, mainCoin, firstAddress = accounts[0] - let tokenWhiteListId, mainCoinWhiteListId +contract("Integration between Poolz-Back and WhiteList for Creating New Pool", (accounts) => { + let poolzBack, + testToken, + whiteList, + mainCoin, + firstAddress = accounts[0] + let tokenWhiteListId, mainCoinWhiteListId - before(async () => { - poolzBack = await ThePoolz.deployed() - whiteList = await WhiteList.deployed() - testToken = await Token.new('TestToken', 'TEST') - mainCoin = await Token.new('TestMainToken', 'TESTM') - }) + before(async () => { + poolzBack = await ThePoolz.deployed() + whiteList = await WhiteList.deployed() + testToken = await Token.new("TestToken", "TEST") + mainCoin = await Token.new("TestMainToken", "TESTM") + }) - describe('WhiteList Setup', () => { - it('Creating new WhiteList for Main Coin', async () => { - const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) - mainCoinWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() - }) + describe("WhiteList Setup", () => { + it("Creating new WhiteList for Main Coin", async () => { + const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) + mainCoinWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() + }) - it('Creating new WhiteList for Token', async () => { - const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) - tokenWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() - }) + it("Creating new WhiteList for Token", async () => { + const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) + tokenWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() + }) - it('should add Main Coin Address to whiteList ID 1', async () => { - const addressArray = [mainCoin.address] - const allowanceArray = [100000000] // random allowance - await whiteList.AddAddress(mainCoinWhiteListId, addressArray, allowanceArray, { from: firstAddress }) - const result = await whiteList.Check(mainCoin.address, mainCoinWhiteListId) - assert.equal(result, 100000000) - }) + it("should add Main Coin Address to whiteList ID 1", async () => { + const addressArray = [mainCoin.address] + const allowanceArray = [100000000] // random allowance + await whiteList.AddAddress(mainCoinWhiteListId, addressArray, allowanceArray, { from: firstAddress }) + const result = await whiteList.Check(mainCoin.address, mainCoinWhiteListId) + assert.equal(result, 100000000) + }) - it('should add Token Address to whiteList ID 2', async () => { - const addressArray = [testToken.address] - const allowanceArray = [100000000] // random allowance - await whiteList.AddAddress(tokenWhiteListId, addressArray, allowanceArray, { from: firstAddress }) - const result = await whiteList.Check(testToken.address, tokenWhiteListId) - assert.equal(result, 100000000) - }) + it("should add Token Address to whiteList ID 2", async () => { + const addressArray = [testToken.address] + const allowanceArray = [100000000] // random allowance + await whiteList.AddAddress(tokenWhiteListId, addressArray, allowanceArray, { from: firstAddress }) + const result = await whiteList.Check(testToken.address, tokenWhiteListId) + assert.equal(result, 100000000) }) + }) - describe('PoolzBack Setup', () => { - it('should set whitelist address', async () => { - await poolzBack.SetWhiteList_Address(whiteList.address, { from: firstAddress }) - const result = await poolzBack.WhiteList_Address() - assert.equal(whiteList.address, result) - }) - it('should set Token WhiteList ID', async () => { - await poolzBack.setTokenWhitelistId(tokenWhiteListId, { from: firstAddress }) - const result = await poolzBack.TokenWhitelistId() - assert.equal(tokenWhiteListId, result) - }) - it('should set Main Coin WhiteList ID', async () => { - await poolzBack.setMCWhitelistId(mainCoinWhiteListId, { from: firstAddress }) - const result = await poolzBack.MCWhitelistId() - assert.equal(mainCoinWhiteListId, result) - }) - it('should set Token Filter to true', async () => { - await poolzBack.SwapTokenFilter({ from: firstAddress }) - const result = await poolzBack.IsTokenFilterOn() - assert.equal(true, result) - }) + describe("PoolzBack Setup", () => { + it("should set whitelist address", async () => { + await poolzBack.SetWhiteList_Address(whiteList.address, { from: firstAddress }) + const result = await poolzBack.WhiteList_Address() + assert.equal(whiteList.address, result) + }) + it("should set Token WhiteList ID", async () => { + await poolzBack.setTokenWhitelistId(tokenWhiteListId, { from: firstAddress }) + const result = await poolzBack.TokenWhitelistId() + assert.equal(tokenWhiteListId, result) }) + it("should set Main Coin WhiteList ID", async () => { + await poolzBack.setMCWhitelistId(mainCoinWhiteListId, { from: firstAddress }) + const result = await poolzBack.MCWhitelistId() + assert.equal(mainCoinWhiteListId, result) + }) + it("should set Token Filter to true", async () => { + await poolzBack.SwapTokenFilter({ from: firstAddress }) + const result = await poolzBack.IsTokenFilterOn() + assert.equal(true, result) + }) + }) - describe('Creating Pool', () => { - it('should create new pool with ETH as Main Coin', async () => { - let poolId - await testToken.approve(poolzBack.address, amount, { from: firstAddress }) - const date = new Date() - date.setDate(date.getDate() + 1) // add a day - const future = Math.floor(date.getTime() / 1000) + 60 - const tx = await poolzBack.CreatePool(testToken.address, future, rate, rate, amount, 0, constants.ZERO_ADDRESS, true, 0, 0, { from: firstAddress }) - poolId = tx.logs[1].args[1].toString() - let newpools = await poolzBack.poolsCount.call() - assert.equal(newpools.toNumber(), 1, "Got 1 pool") - let tokensInContract = await testToken.balanceOf(poolzBack.address) - assert.equal(tokensInContract.toString(), amount.toString(), "Got the tokens") - }) - it('should create new pool with ERC20 Main Coin', async () => { - let poolId - await testToken.approve(poolzBack.address, amount, { from: firstAddress }) - const date = new Date() - date.setDate(date.getDate() + 1) // add a day - const future = Math.floor(date.getTime() / 1000) + 60 - const tx = await poolzBack.CreatePool(testToken.address, future, rate, rate, amount, 0, mainCoin.address, true, 0, 0, { from: firstAddress }) - poolId = tx.logs[1].args[1].toString() - let newpools = await poolzBack.poolsCount.call() - assert.equal(newpools.toNumber(), 2, "Got 1 pool") - const data = await poolzBack.GetPoolExtraData(poolId) - assert.equal(mainCoin.address, data[2], 'Address match') - }) + describe("Creating Pool", () => { + it("should create new pool with ETH as Main Coin", async () => { + let poolId + await testToken.approve(poolzBack.address, amount, { from: firstAddress }) + const date = new Date() + date.setDate(date.getDate() + 1) // add a day + const future = Math.floor(date.getTime() / 1000) + 60 + const tx = await poolzBack.CreatePool( + testToken.address, + future, + rate, + rate, + amount, + 0, + constants.ZERO_ADDRESS, + true, + 0, + 0, + { from: firstAddress } + ) + poolId = tx.logs[1].args[1].toString() + let newpools = await poolzBack.poolsCount.call() + assert.equal(newpools.toNumber(), 1, "Got 1 pool") + let tokensInContract = await testToken.balanceOf(poolzBack.address) + assert.equal(tokensInContract.toString(), amount.toString(), "Got the tokens") }) + it("should create new pool with ERC20 Main Coin", async () => { + let poolId + await testToken.approve(poolzBack.address, amount, { from: firstAddress }) + const date = new Date() + date.setDate(date.getDate() + 1) // add a day + const future = Math.floor(date.getTime() / 1000) + 60 + const tx = await poolzBack.CreatePool( + testToken.address, + future, + rate, + rate, + amount, + 0, + mainCoin.address, + true, + 0, + 0, + { from: firstAddress } + ) + poolId = tx.logs[1].args[1].toString() + let newpools = await poolzBack.poolsCount.call() + assert.equal(newpools.toNumber(), 2, "Got 1 pool") + const data = await poolzBack.GetPoolExtraData(poolId) + assert.equal(mainCoin.address, data[2], "Address match") + }) + }) - describe('Fail to Create Pool', () => { - it('should fail to create pool when token is not WhiteListed', async () => { - const randomAddress = accounts[9] - const date = new Date() - date.setDate(date.getDate() + 1) // add a day - const future = Math.floor(date.getTime() / 1000) + 60 - await truffleAssert.reverts(poolzBack.CreatePool(randomAddress, future, rate, rate, amount, 0, constants.ZERO_ADDRESS, true, 0, 0, { from: firstAddress }), 'Need Valid ERC20 Token') - }) - it('should fail to create pool when main coin is not whitelisted', async () => { - const randomAddress = accounts[9] - const date = new Date() - date.setDate(date.getDate() + 1) // add a day - const future = Math.floor(date.getTime() / 1000) + 60 - await truffleAssert.reverts(poolzBack.CreatePool(testToken.address, future, rate, rate, amount, 0, randomAddress, true, 0, 0, { from: firstAddress }), 'Main coin not in list') - }) + describe("Fail to Create Pool", () => { + it("should fail to create pool when token is not WhiteListed", async () => { + const randomAddress = accounts[9] + const date = new Date() + date.setDate(date.getDate() + 1) // add a day + const future = Math.floor(date.getTime() / 1000) + 60 + await truffleAssert.reverts( + poolzBack.CreatePool(randomAddress, future, rate, rate, amount, 0, constants.ZERO_ADDRESS, true, 0, 0, { + from: firstAddress + }), + "Need Valid ERC20 Token" + ) + }) + it("should fail to create pool when main coin is not whitelisted", async () => { + const randomAddress = accounts[9] + const date = new Date() + date.setDate(date.getDate() + 1) // add a day + const future = Math.floor(date.getTime() / 1000) + 60 + await truffleAssert.reverts( + poolzBack.CreatePool(testToken.address, future, rate, rate, amount, 0, randomAddress, true, 0, 0, { + from: firstAddress + }), + "Main coin not in list" + ) }) -}) \ No newline at end of file + }) +}) diff --git a/test/08_Invest.js b/test/08_Invest.js index adcc9f7..4726658 100644 --- a/test/08_Invest.js +++ b/test/08_Invest.js @@ -1,307 +1,397 @@ const ThePoolz = artifacts.require("ThePoolz") const Token = artifacts.require("Token") -const WhiteList = artifacts.require('WhiteList') +const WhiteList = artifacts.require("WhiteList") const LockedDeal = artifacts.require("LockedDeal") -const { assert, should } = require('chai') -const truffleAssert = require('truffle-assertions') -const timeMachine = require('ganache-time-traveler') -const BigNumber = require('bignumber.js') +const { assert } = require("chai") +const truffleAssert = require("truffle-assertions") +const timeMachine = require("ganache-time-traveler") +const BigNumber = require("bignumber.js") const constants = require("@openzeppelin/test-helpers/src/constants") var BN = web3.utils.BN -const pozRate = new BN('1000000000') // with decimal21 (shifter) 1 eth^18 = 1 token^6 -const publicRate = new BN('500000000') // with decimal21 (shifter) 1 eth^18 = 1 token^6 -const amount = new BN('3000000') //3 tokens for sale +const pozRate = new BN("1000000000") // with decimal21 (shifter) 1 eth^18 = 1 token^6 +const publicRate = new BN("500000000") // with decimal21 (shifter) 1 eth^18 = 1 token^6 +const amount = new BN("3000000") //3 tokens for sale -const { createNewWhiteList } = require('./helper') +const { createNewWhiteList } = require("./helper") -contract('Interation Between PoolzBack and WhiteList for Investing', (accounts) => { - let poolzBack, ethTestToken, ercTestToken, whiteList, lockedDeal, mainCoin, firstAddress = accounts[0] - let tokenWhiteListId, mainCoinWhiteListId - let ethInvestor, ethAllowance, ercInvestor, ercAllowance - let ethPoolId, ercPoolId +contract("Interation Between PoolzBack and WhiteList for Investing", (accounts) => { + let poolzBack, + ethTestToken, + ercTestToken, + whiteList, + lockedDeal, + mainCoin, + firstAddress = accounts[0] + let tokenWhiteListId, mainCoinWhiteListId + let ethInvestor, ethAllowance, ercInvestor, ercAllowance + let ethPoolId, ercPoolId - const ercPozRate = new BN('100') - const ercPublicRate = new BN('50') + const ercPozRate = new BN("100") + const ercPublicRate = new BN("50") - before(async () => { - poolzBack = await ThePoolz.deployed() - whiteList = await WhiteList.deployed() - lockedDeal = await LockedDeal.new() - ethTestToken = await Token.new('TestToken', 'TEST') - ercTestToken = await Token.new('TestToken', 'TEST') - mainCoin = await Token.new('TestMainToken', 'TESTM') - }) - - describe('WhiteList Setup', () => { - it('Creating new WhiteList for Main Coin', async () => { - const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) - mainCoinWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() - }) + before(async () => { + poolzBack = await ThePoolz.deployed() + whiteList = await WhiteList.deployed() + lockedDeal = await LockedDeal.new() + ethTestToken = await Token.new("TestToken", "TEST") + ercTestToken = await Token.new("TestToken", "TEST") + mainCoin = await Token.new("TestMainToken", "TESTM") + }) - it('Creating new WhiteList for Token', async () => { - const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) - tokenWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() - }) + describe("WhiteList Setup", () => { + it("Creating new WhiteList for Main Coin", async () => { + const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) + mainCoinWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() + }) - it('should add Main Coin Address to whiteList ID 1', async () => { - const addressArray = [mainCoin.address] - const allowanceArray = [100000000] // random allowance - await whiteList.AddAddress(mainCoinWhiteListId, addressArray, allowanceArray, { from: firstAddress }) - const result = await whiteList.Check(mainCoin.address, mainCoinWhiteListId) - assert.equal(result, 100000000) - }) + it("Creating new WhiteList for Token", async () => { + const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) + tokenWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() + }) - it('should add ethTestToken and ercTestToken Address to whiteList ID 2', async () => { - const addressArray = [ethTestToken.address, ercTestToken.address] - const allowanceArray = [100000000, 100000000] // random allowance - await whiteList.AddAddress(tokenWhiteListId, addressArray, allowanceArray, { from: firstAddress }) - const result = await whiteList.Check(ethTestToken.address, tokenWhiteListId) - assert.equal(result, 100000000) - }) + it("should add Main Coin Address to whiteList ID 1", async () => { + const addressArray = [mainCoin.address] + const allowanceArray = [100000000] // random allowance + await whiteList.AddAddress(mainCoinWhiteListId, addressArray, allowanceArray, { from: firstAddress }) + const result = await whiteList.Check(mainCoin.address, mainCoinWhiteListId) + assert.equal(result, 100000000) }) - describe('PoolzBack Setup', () => { - it('should set whitelist address', async () => { - await poolzBack.SetWhiteList_Address(whiteList.address, { from: firstAddress }) - const result = await poolzBack.WhiteList_Address() - assert.equal(whiteList.address, result) - }) - it('should set Token WhiteList ID', async () => { - await poolzBack.setTokenWhitelistId(tokenWhiteListId, { from: firstAddress }) - const result = await poolzBack.TokenWhitelistId() - assert.equal(tokenWhiteListId, result) - }) - it('should set Main Coin WhiteList ID', async () => { - await poolzBack.setMCWhitelistId(mainCoinWhiteListId, { from: firstAddress }) - const result = await poolzBack.MCWhitelistId() - assert.equal(mainCoinWhiteListId, result) - }) - it('should set Token Filter to true', async () => { - await poolzBack.SwapTokenFilter({ from: firstAddress }) - const result = await poolzBack.IsTokenFilterOn() - assert.equal(true, result) - }) + it("should add ethTestToken and ercTestToken Address to whiteList ID 2", async () => { + const addressArray = [ethTestToken.address, ercTestToken.address] + const allowanceArray = [100000000, 100000000] // random allowance + await whiteList.AddAddress(tokenWhiteListId, addressArray, allowanceArray, { from: firstAddress }) + const result = await whiteList.Check(ethTestToken.address, tokenWhiteListId) + assert.equal(result, 100000000) }) + }) - describe('Creating Whitelist of Investors and New Pool', () => { - describe('New ETH Pool', () => { - let investorWhiteListId - it('should create new whitelist for investors', async () => { - const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) - investorWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() - }) + describe("PoolzBack Setup", () => { + it("should set whitelist address", async () => { + await poolzBack.SetWhiteList_Address(whiteList.address, { from: firstAddress }) + const result = await poolzBack.WhiteList_Address() + assert.equal(whiteList.address, result) + }) + it("should set Token WhiteList ID", async () => { + await poolzBack.setTokenWhitelistId(tokenWhiteListId, { from: firstAddress }) + const result = await poolzBack.TokenWhitelistId() + assert.equal(tokenWhiteListId, result) + }) + it("should set Main Coin WhiteList ID", async () => { + await poolzBack.setMCWhitelistId(mainCoinWhiteListId, { from: firstAddress }) + const result = await poolzBack.MCWhitelistId() + assert.equal(mainCoinWhiteListId, result) + }) + it("should set Token Filter to true", async () => { + await poolzBack.SwapTokenFilter({ from: firstAddress }) + const result = await poolzBack.IsTokenFilterOn() + assert.equal(true, result) + }) + }) - it('should grant allowances to investers', async () => { - ethInvestor = [accounts[9], accounts[8], accounts[7], accounts[6]] - ethAllowance = [] - ethAllowance.push(web3.utils.toWei('0.4')) - ethAllowance.push(web3.utils.toWei('0.3')) - ethAllowance.push(web3.utils.toWei('0.2')) - ethAllowance.push(web3.utils.toWei('0.1')) - await whiteList.AddAddress(investorWhiteListId, ethInvestor, ethAllowance, { from: firstAddress }) - ethInvestor.forEach(async (value, index) => { - const result = await whiteList.Check(value, investorWhiteListId) - assert.equal(result, ethAllowance[index]) - }) - }) + describe("Creating Whitelist of Investors and New Pool", () => { + describe("New ETH Pool", () => { + let investorWhiteListId + it("should create new whitelist for investors", async () => { + const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) + investorWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() + }) - it('should create new pool with ETH as Main Coin', async () => { - await ethTestToken.approve(poolzBack.address, amount, { from: firstAddress }) - const date = new Date() - date.setDate(date.getDate() + 1) // add a day - const future = Math.floor(date.getTime() / 1000) + 60 - const tx = await poolzBack.CreatePool(ethTestToken.address, future, publicRate, pozRate, amount, 0, constants.ZERO_ADDRESS, true, 0, investorWhiteListId, { from: firstAddress }) - ethPoolId = tx.logs[1].args[1].toString() - let newpools = await poolzBack.poolsCount.call() - assert.equal(newpools.toNumber(), 1, "Got 1 pool") - let tokensInContract = await ethTestToken.balanceOf(poolzBack.address) - assert.equal(tokensInContract.toString(), amount.toString(), "Got the tokens") - const result = await poolzBack.GetPoolExtraData(ethPoolId) - assert.equal(investorWhiteListId, result[1].toString()) - }) + it("should grant allowances to investers", async () => { + ethInvestor = [accounts[9], accounts[8], accounts[7], accounts[6]] + ethAllowance = [] + ethAllowance.push(web3.utils.toWei("0.4")) + ethAllowance.push(web3.utils.toWei("0.3")) + ethAllowance.push(web3.utils.toWei("0.2")) + ethAllowance.push(web3.utils.toWei("0.1")) + await whiteList.AddAddress(investorWhiteListId, ethInvestor, ethAllowance, { from: firstAddress }) + ethInvestor.forEach(async (value, index) => { + const result = await whiteList.Check(value, investorWhiteListId) + assert.equal(result, ethAllowance[index]) }) - describe('New ERC20 Pool', () => { - let investorWhiteListId - it('should create new whitelist for investors', async () => { - const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) - investorWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() - }) + }) - it('should grant allowances to investers', async () => { - ercInvestor = [accounts[9], accounts[8], accounts[7], accounts[6]] - const mainCoinDecimals = await mainCoin.decimals() - ercAllowance = [] - ercAllowance.push(0.4 * 10 ** mainCoinDecimals) - ercAllowance.push(0.3 * 10 ** mainCoinDecimals) - ercAllowance.push(0.2 * 10 ** mainCoinDecimals) - ercAllowance.push(0.1 * 10 ** mainCoinDecimals) - await whiteList.AddAddress(investorWhiteListId, ercInvestor, ercAllowance, { from: firstAddress }) - ercInvestor.forEach(async (value, index) => { - const result = await whiteList.Check(value, investorWhiteListId) - assert.equal(result, ercAllowance[index]) - }) - }) + it("should create new pool with ETH as Main Coin", async () => { + await ethTestToken.approve(poolzBack.address, amount, { from: firstAddress }) + const date = new Date() + date.setDate(date.getDate() + 1) // add a day + const future = Math.floor(date.getTime() / 1000) + 60 + const tx = await poolzBack.CreatePool( + ethTestToken.address, + future, + publicRate, + pozRate, + amount, + 0, + constants.ZERO_ADDRESS, + true, + 0, + investorWhiteListId, + { from: firstAddress } + ) + ethPoolId = tx.logs[1].args[1].toString() + let newpools = await poolzBack.poolsCount.call() + assert.equal(newpools.toNumber(), 1, "Got 1 pool") + let tokensInContract = await ethTestToken.balanceOf(poolzBack.address) + assert.equal(tokensInContract.toString(), amount.toString(), "Got the tokens") + const result = await poolzBack.GetPoolExtraData(ethPoolId) + assert.equal(investorWhiteListId, result[1].toString()) + }) + }) + describe("New ERC20 Pool", () => { + let investorWhiteListId + it("should create new whitelist for investors", async () => { + const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) + investorWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() + }) - it('should create new pool with ERC20 as Main Coin', async () => { - const startAmount = new BN('100000000') // 1000 tokens for sale - await ercTestToken.approve(poolzBack.address, startAmount, { from: firstAddress }) - const date = new Date() - date.setDate(date.getDate() + 1) // add a day - const future = Math.floor(date.getTime() / 1000) + 60 - const mainCoinDecimals = await mainCoin.decimals() - const tokenDecimals = await ercTestToken.decimals() - const d21PozRate = ercPozRate.mul(new BN('10').pow(new BN(21 + tokenDecimals.toNumber() - mainCoinDecimals.toNumber()))) - const d21PublicRate = ercPublicRate.mul(new BN('10').pow(new BN(21 + tokenDecimals.toNumber() - mainCoinDecimals.toNumber()))) - const tx = await poolzBack.CreatePool(ercTestToken.address, future, d21PublicRate, d21PozRate, startAmount, 0, mainCoin.address, true, 0, investorWhiteListId, { from: firstAddress }) - ercPoolId = tx.logs[1].args[1].toString() - let newpools = await poolzBack.poolsCount.call() - assert.equal(newpools.toNumber(), 2, "Got 1 pool") - const result = await poolzBack.GetPoolExtraData(ercPoolId) - assert.equal(investorWhiteListId, result[1].toString()) - }) + it("should grant allowances to investers", async () => { + ercInvestor = [accounts[9], accounts[8], accounts[7], accounts[6]] + const mainCoinDecimals = await mainCoin.decimals() + ercAllowance = [] + ercAllowance.push(0.4 * 10 ** mainCoinDecimals) + ercAllowance.push(0.3 * 10 ** mainCoinDecimals) + ercAllowance.push(0.2 * 10 ** mainCoinDecimals) + ercAllowance.push(0.1 * 10 ** mainCoinDecimals) + await whiteList.AddAddress(investorWhiteListId, ercInvestor, ercAllowance, { from: firstAddress }) + ercInvestor.forEach(async (value, index) => { + const result = await whiteList.Check(value, investorWhiteListId) + assert.equal(result, ercAllowance[index]) }) + }) + + it("should create new pool with ERC20 as Main Coin", async () => { + const startAmount = new BN("100000000") // 1000 tokens for sale + await ercTestToken.approve(poolzBack.address, startAmount, { from: firstAddress }) + const date = new Date() + date.setDate(date.getDate() + 1) // add a day + const future = Math.floor(date.getTime() / 1000) + 60 + const mainCoinDecimals = await mainCoin.decimals() + const tokenDecimals = await ercTestToken.decimals() + const d21PozRate = ercPozRate.mul( + new BN("10").pow(new BN(21 + tokenDecimals.toNumber() - mainCoinDecimals.toNumber())) + ) + const d21PublicRate = ercPublicRate.mul( + new BN("10").pow(new BN(21 + tokenDecimals.toNumber() - mainCoinDecimals.toNumber())) + ) + const tx = await poolzBack.CreatePool( + ercTestToken.address, + future, + d21PublicRate, + d21PozRate, + startAmount, + 0, + mainCoin.address, + true, + 0, + investorWhiteListId, + { from: firstAddress } + ) + ercPoolId = tx.logs[1].args[1].toString() + let newpools = await poolzBack.poolsCount.call() + assert.equal(newpools.toNumber(), 2, "Got 1 pool") + const result = await poolzBack.GetPoolExtraData(ercPoolId) + assert.equal(investorWhiteListId, result[1].toString()) + }) }) + }) - describe('Investing in ETH Pool', () => { - const shouldInvest = async (index) => { - await poolzBack.InvestETH(ethPoolId, { from: ethInvestor[index], value: ethAllowance[index] }) - const bal = await ethTestToken.balanceOf(ethInvestor[index]) - const tokenDecimals = await ethTestToken.decimals() - const realRate = pozRate.div(new BN(10).pow(new BN(21 + tokenDecimals.toNumber() - 18))) // converting decimal21Rate to realRate - const tokens = web3.utils.fromWei(ethAllowance[index]) * realRate - assert.deepEqual(bal, new BN(tokens).mul(new BN(10).pow(tokenDecimals))) - } - it('should invest, for investor 0', async () => { - await shouldInvest(0) - }) - it('should invest, for investor 1', async () => { - await shouldInvest(1) - }) - it('should invest, for investor 2', async () => { - await shouldInvest(2) - }) - it('should invest, for investor 3', async () => { - await shouldInvest(3) - }) - it('should Fail to invest when investor not whitelisted', async () => { - const fakeInvestor = accounts[1] - await truffleAssert.reverts(poolzBack.InvestETH(ethPoolId, { from: fakeInvestor, value: web3.utils.toWei('0.1') }), 'Sorry, no alocation for Subject') - }) + describe("Investing in ETH Pool", () => { + const shouldInvest = async (index) => { + await poolzBack.InvestETH(ethPoolId, { from: ethInvestor[index], value: ethAllowance[index] }) + const bal = await ethTestToken.balanceOf(ethInvestor[index]) + const tokenDecimals = await ethTestToken.decimals() + const realRate = pozRate.div(new BN(10).pow(new BN(21 + tokenDecimals.toNumber() - 18))) // converting decimal21Rate to realRate + const tokens = web3.utils.fromWei(ethAllowance[index]) * realRate + assert.deepEqual(bal, new BN(tokens).mul(new BN(10).pow(tokenDecimals))) + } + it("should invest, for investor 0", async () => { + await shouldInvest(0) + }) + it("should invest, for investor 1", async () => { + await shouldInvest(1) }) + it("should invest, for investor 2", async () => { + await shouldInvest(2) + }) + it("should invest, for investor 3", async () => { + await shouldInvest(3) + }) + it("should Fail to invest when investor not whitelisted", async () => { + const fakeInvestor = accounts[1] + await truffleAssert.reverts( + poolzBack.InvestETH(ethPoolId, { from: fakeInvestor, value: web3.utils.toWei("0.1") }), + "Sorry, no alocation for Subject" + ) + }) + }) - describe('Investing in ERC20 Pool', () => { - const shouldInvest = async (index) => { - await mainCoin.approve(poolzBack.address, ercAllowance[index], { from: ercInvestor[index] }) - await poolzBack.InvestERC20(ercPoolId, ercAllowance[index], { from: ercInvestor[index] }) - const bal = await ercTestToken.balanceOf(ercInvestor[index]) - const tokenDecimals = await ercTestToken.decimals() - const mainCoinDecimals = await mainCoin.decimals() - const tokens = new BigNumber(ercAllowance[index]).div(new BigNumber(10).pow(mainCoinDecimals.toString())).multipliedBy(ercPozRate.toString()) - assert.deepEqual(new BigNumber(bal.toString()), tokens.multipliedBy(new BigNumber(10).pow(tokenDecimals))) - } - const fakeInvestor = accounts[1] - const fakeInvestorAmt = '1000000' - before(async () => { - ercInvestor.forEach(async (value, index) => { - await mainCoin.transfer(value, ercAllowance[index], { from: firstAddress }) - const bal = await mainCoin.balanceOf(value) - assert.equal(bal.toNumber(), ercAllowance[index]) - }) - await mainCoin.transfer(fakeInvestor, fakeInvestorAmt, { from: firstAddress }) - }) - it('should invest, for investor 0', async () => { - await shouldInvest(0) - }) - it('should invest, for investor 1', async () => { - await shouldInvest(1) - }) - it('should invest, for investor 2', async () => { - await shouldInvest(2) - }) - it('should invest, for investor 3', async () => { - await shouldInvest(3) - }) - it('should Fail to invest when investor not whitelisted', async () => { - await mainCoin.approve(poolzBack.address, fakeInvestorAmt, { from: fakeInvestor }) - await truffleAssert.reverts(poolzBack.InvestERC20(ercPoolId, fakeInvestorAmt, { from: fakeInvestor }), 'Sorry, no alocation for Subject') - }) + describe("Investing in ERC20 Pool", () => { + const shouldInvest = async (index) => { + await mainCoin.approve(poolzBack.address, ercAllowance[index], { from: ercInvestor[index] }) + await poolzBack.InvestERC20(ercPoolId, ercAllowance[index], { from: ercInvestor[index] }) + const bal = await ercTestToken.balanceOf(ercInvestor[index]) + const tokenDecimals = await ercTestToken.decimals() + const mainCoinDecimals = await mainCoin.decimals() + const tokens = new BigNumber(ercAllowance[index]) + .div(new BigNumber(10).pow(mainCoinDecimals.toString())) + .multipliedBy(ercPozRate.toString()) + assert.deepEqual(new BigNumber(bal.toString()), tokens.multipliedBy(new BigNumber(10).pow(tokenDecimals))) + } + const fakeInvestor = accounts[1] + const fakeInvestorAmt = "1000000" + before(async () => { + ercInvestor.forEach(async (value, index) => { + await mainCoin.transfer(value, ercAllowance[index], { from: firstAddress }) + const bal = await mainCoin.balanceOf(value) + assert.equal(bal.toNumber(), ercAllowance[index]) + }) + await mainCoin.transfer(fakeInvestor, fakeInvestorAmt, { from: firstAddress }) + }) + it("should invest, for investor 0", async () => { + await shouldInvest(0) + }) + it("should invest, for investor 1", async () => { + await shouldInvest(1) }) + it("should invest, for investor 2", async () => { + await shouldInvest(2) + }) + it("should invest, for investor 3", async () => { + await shouldInvest(3) + }) + it("should Fail to invest when investor not whitelisted", async () => { + await mainCoin.approve(poolzBack.address, fakeInvestorAmt, { from: fakeInvestor }) + await truffleAssert.reverts( + poolzBack.InvestERC20(ercPoolId, fakeInvestorAmt, { from: fakeInvestor }), + "Sorry, no alocation for Subject" + ) + }) + }) - describe('should get info', async () => { - let investorWhiteListId, ercPoolId - it('should get investment ids', async () => { - const res = await poolzBack.GetMyInvestmentIds({ from: ethInvestor[0] }) - assert.equal(2, res.length) - assert.equal([0, 4].toString(), res.toString()) - }) + describe("should get info", async () => { + let investorWhiteListId, ercPoolId + it("should get investment ids", async () => { + const res = await poolzBack.GetMyInvestmentIds({ from: ethInvestor[0] }) + assert.equal(2, res.length) + assert.equal([0, 4].toString(), res.toString()) + }) - it('should return OutOfstock', async () => { - await poolzBack.SwitchLockedDealForTlp(); - await poolzBack.SetLockedDealAddress(lockedDeal.address) - const mainCoinDecimals = await mainCoin.decimals() - const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) - const investorWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() - await ercTestToken.approve(poolzBack.address, 100000, { from: firstAddress }) - const date = new Date() - date.setDate(date.getDate() + 1) // add a day - const future = Math.floor(date.getTime() / 1000) + 60 - const tokenDecimals = await ercTestToken.decimals() - const d21PozRate = ercPozRate.mul(new BN('10').pow(new BN(21 + tokenDecimals.toNumber() - mainCoinDecimals.toNumber()))) - const d21PublicRate = ercPublicRate.mul(new BN('10').pow(new BN(21 + tokenDecimals.toNumber() - mainCoinDecimals.toNumber()))) - const result = await poolzBack.CreatePool(ercTestToken.address, future, d21PublicRate, d21PozRate, 100000, future, mainCoin.address, true, 0, investorWhiteListId, { from: firstAddress }) - ercPoolId = result.logs[1].args[1].toString() - await whiteList.AddAddress(investorWhiteListId, [firstAddress], [1000], { from: firstAddress }) - await mainCoin.approve(poolzBack.address, 1000, { from: firstAddress }) - await poolzBack.InvestERC20(ercPoolId, 1000, { from: firstAddress }) - const res = await poolzBack.GetPoolStatus(ercPoolId) - assert.equal(res.toString(), '3') - }) + it("should return OutOfstock", async () => { + await poolzBack.SwitchLockedDealForTlp() + await poolzBack.SetLockedDealAddress(lockedDeal.address) + const mainCoinDecimals = await mainCoin.decimals() + const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) + const investorWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() + await ercTestToken.approve(poolzBack.address, 100000, { from: firstAddress }) + const date = new Date() + date.setDate(date.getDate() + 1) // add a day + const future = Math.floor(date.getTime() / 1000) + 60 + const tokenDecimals = await ercTestToken.decimals() + const d21PozRate = ercPozRate.mul( + new BN("10").pow(new BN(21 + tokenDecimals.toNumber() - mainCoinDecimals.toNumber())) + ) + const d21PublicRate = ercPublicRate.mul( + new BN("10").pow(new BN(21 + tokenDecimals.toNumber() - mainCoinDecimals.toNumber())) + ) + const result = await poolzBack.CreatePool( + ercTestToken.address, + future, + d21PublicRate, + d21PozRate, + 100000, + future, + mainCoin.address, + true, + 0, + investorWhiteListId, + { from: firstAddress } + ) + ercPoolId = result.logs[1].args[1].toString() + await whiteList.AddAddress(investorWhiteListId, [firstAddress], [1000], { from: firstAddress }) + await mainCoin.approve(poolzBack.address, 1000, { from: firstAddress }) + await poolzBack.InvestERC20(ercPoolId, 1000, { from: firstAddress }) + const res = await poolzBack.GetPoolStatus(ercPoolId) + assert.equal(res.toString(), "3") + }) - it('should return Finished', async () => { - const mainCoinDecimals = await mainCoin.decimals() - const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) - investorWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() - await ercTestToken.approve(poolzBack.address, 100000, { from: firstAddress }) - const date = new Date() - date.setDate(date.getDate() + 1) // add a day - const future = Math.floor(date.getTime() / 1000) + 60 - const tokenDecimals = await ercTestToken.decimals() - const d21PozRate = ercPozRate.mul(new BN('10').pow(new BN(21 + tokenDecimals.toNumber() - mainCoinDecimals.toNumber()))) - const d21PublicRate = ercPublicRate.mul(new BN('10').pow(new BN(21 + tokenDecimals.toNumber() - mainCoinDecimals.toNumber()))) - const result = await poolzBack.CreatePool(ercTestToken.address, future, d21PublicRate, d21PozRate, 100000, future + 100000, mainCoin.address, true, 0, investorWhiteListId, { from: firstAddress }) - ercPoolId = result.logs[1].args[1].toString() - await timeMachine.advanceBlockAndSetTime(future) - const res = await poolzBack.GetPoolStatus(ercPoolId) - assert.equal(res.toString(), '4') - }) + it("should return Finished", async () => { + const mainCoinDecimals = await mainCoin.decimals() + const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) + investorWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() + await ercTestToken.approve(poolzBack.address, 100000, { from: firstAddress }) + const date = new Date() + date.setDate(date.getDate() + 1) // add a day + const future = Math.floor(date.getTime() / 1000) + 60 + const tokenDecimals = await ercTestToken.decimals() + const d21PozRate = ercPozRate.mul( + new BN("10").pow(new BN(21 + tokenDecimals.toNumber() - mainCoinDecimals.toNumber())) + ) + const d21PublicRate = ercPublicRate.mul( + new BN("10").pow(new BN(21 + tokenDecimals.toNumber() - mainCoinDecimals.toNumber())) + ) + const result = await poolzBack.CreatePool( + ercTestToken.address, + future, + d21PublicRate, + d21PozRate, + 100000, + future + 100000, + mainCoin.address, + true, + 0, + investorWhiteListId, + { from: firstAddress } + ) + ercPoolId = result.logs[1].args[1].toString() + await timeMachine.advanceBlockAndSetTime(future) + const res = await poolzBack.GetPoolStatus(ercPoolId) + assert.equal(res.toString(), "4") + }) - it('should return Close', async () => { - const mainCoinDecimals = await mainCoin.decimals() - let tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) - investorWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() - await ercTestToken.approve(poolzBack.address, 100000, { from: firstAddress }) - const date1 = new Date() - date1.setDate(date1.getDate() + 1) // add a day - const future = Math.floor(date1.getTime() / 1000) + 60 - const tokenDecimals = await ercTestToken.decimals() - const d21PozRate = ercPozRate.mul(new BN('10').pow(new BN(21 + tokenDecimals.toNumber() - mainCoinDecimals.toNumber()))) - const d21PublicRate = ercPublicRate.mul(new BN('10').pow(new BN(21 + tokenDecimals.toNumber() - mainCoinDecimals.toNumber()))) - tx = await poolzBack.CreatePool(ercTestToken.address, future, d21PublicRate, d21PozRate, 100000, future + 10000000, mainCoin.address, true, 0, investorWhiteListId, { from: firstAddress }) - ercPoolId = tx.logs[1].args[1].toString() - const date = new Date() - date.setDate(date.getDate() + 1) - const time = Math.floor(date.getTime() / 1000) + 60 + 1000000 - await timeMachine.advanceBlockAndSetTime(time) - await poolzBack.GetPoolExtraData(ercPoolId) - await poolzBack.WithdrawLeftOvers(ercPoolId) - const res = await poolzBack.GetPoolStatus(ercPoolId) - assert.equal(res.toString(), '5') - }) + it("should return Close", async () => { + const mainCoinDecimals = await mainCoin.decimals() + let tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) + investorWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() + await ercTestToken.approve(poolzBack.address, 100000, { from: firstAddress }) + const date1 = new Date() + date1.setDate(date1.getDate() + 1) // add a day + const future = Math.floor(date1.getTime() / 1000) + 60 + const tokenDecimals = await ercTestToken.decimals() + const d21PozRate = ercPozRate.mul( + new BN("10").pow(new BN(21 + tokenDecimals.toNumber() - mainCoinDecimals.toNumber())) + ) + const d21PublicRate = ercPublicRate.mul( + new BN("10").pow(new BN(21 + tokenDecimals.toNumber() - mainCoinDecimals.toNumber())) + ) + tx = await poolzBack.CreatePool( + ercTestToken.address, + future, + d21PublicRate, + d21PozRate, + 100000, + future + 10000000, + mainCoin.address, + true, + 0, + investorWhiteListId, + { from: firstAddress } + ) + ercPoolId = tx.logs[1].args[1].toString() + const date = new Date() + date.setDate(date.getDate() + 1) + const time = Math.floor(date.getTime() / 1000) + 60 + 1000000 + await timeMachine.advanceBlockAndSetTime(time) + await poolzBack.GetPoolExtraData(ercPoolId) + await poolzBack.WithdrawLeftOvers(ercPoolId) + const res = await poolzBack.GetPoolStatus(ercPoolId) + assert.equal(res.toString(), "5") + }) - it('should get total investors', async () => { - const res = await poolzBack.getTotalInvestor(); - assert.equal(9, res.toString()); - }) + it("should get total investors", async () => { + const res = await poolzBack.getTotalInvestor() + assert.equal(9, res.toString()) }) -}) \ No newline at end of file + }) +}) diff --git a/test/09_LockedDeal.js b/test/09_LockedDeal.js index c744895..cf9505a 100644 --- a/test/09_LockedDeal.js +++ b/test/09_LockedDeal.js @@ -1,85 +1,96 @@ const ThePoolz = artifacts.require("ThePoolz") const Token = artifacts.require("Token") const LockedDeal = artifacts.require("LockedDeal") -const { assert } = require('chai') -const truffleAssert = require('truffle-assertions') -const timeMachine = require('ganache-time-traveler') +const { assert } = require("chai") +const timeMachine = require("ganache-time-traveler") const constants = require("@openzeppelin/test-helpers/src/constants") var BN = web3.utils.BN -const pozRate = new BN('1000000000') // with decimal21 (shifter) 1 eth^18 = 1 token^6 -const publicRate = new BN('500000000') // with decimal21 (shifter) 1 eth^18 = 1 token^6 -const amount = new BN('3000000') //3 tokens for sale -const invest = web3.utils.toWei('1', 'ether') //1eth +const pozRate = new BN("1000000000") // with decimal21 (shifter) 1 eth^18 = 1 token^6 +const publicRate = new BN("500000000") // with decimal21 (shifter) 1 eth^18 = 1 token^6 +const amount = new BN("3000000") //3 tokens for sale -const { createNewWhiteList } = require('./helper') +contract("Integration between PoolzBack and LockedDeal", (accounts) => { + let poolzBack, + lockedDeal, + testToken, + firstAddress = accounts[0] + let poolId -contract('Integration between PoolzBack and LockedDeal', accounts => { - let poolzBack, lockedDeal, testToken, whiteList, mainCoin, firstAddress = accounts[0] - let poolId + before(async () => { + poolzBack = await ThePoolz.new() + lockedDeal = await LockedDeal.new() + testToken = await Token.new("TestToken", "TEST") + }) - before(async () => { - poolzBack = await ThePoolz.new() - lockedDeal = await LockedDeal.new() - testToken = await Token.new('TestToken', 'TEST') + describe("PoolzBack Setup", () => { + it("should set LockedDeal address", async () => { + await poolzBack.SetLockedDealAddress(lockedDeal.address, { from: firstAddress }) + const result = await poolzBack.LockedDealAddress() + assert.equal(lockedDeal.address, result) }) - - describe('PoolzBack Setup', () => { - it('should set LockedDeal address', async () => { - await poolzBack.SetLockedDealAddress(lockedDeal.address, { from: firstAddress }) - const result = await poolzBack.LockedDealAddress() - assert.equal(lockedDeal.address, result) - }) - it('should use LockedDeal for creating TLP', async () => { - await poolzBack.SwitchLockedDealForTlp({ from: firstAddress }) - const result = await poolzBack.UseLockedDealForTlp() - assert.isTrue(result) - }) - it('should create a TLP', async () => { - await testToken.approve(poolzBack.address, amount, { from: firstAddress }) - const date = new Date() - date.setDate(date.getDate() + 1) // add a day - const future = Math.floor(date.getTime() / 1000) + 60 - const tx = await poolzBack.CreatePool(testToken.address, future, publicRate, pozRate, amount, future, constants.ZERO_ADDRESS, true, 0, 0, { from: firstAddress }) - poolId = tx.logs[1].args[1].toString() - let newpools = await poolzBack.poolsCount.call() - assert.equal(newpools.toNumber(), 1, "Got 1 pool") - let tokensInContract = await testToken.balanceOf(poolzBack.address) - assert.equal(tokensInContract.toString(), amount.toString(), "Got the tokens") - }) + it("should use LockedDeal for creating TLP", async () => { + await poolzBack.SwitchLockedDealForTlp({ from: firstAddress }) + const result = await poolzBack.UseLockedDealForTlp() + assert.isTrue(result) + }) + it("should create a TLP", async () => { + await testToken.approve(poolzBack.address, amount, { from: firstAddress }) + const date = new Date() + date.setDate(date.getDate() + 1) // add a day + const future = Math.floor(date.getTime() / 1000) + 60 + const tx = await poolzBack.CreatePool( + testToken.address, + future, + publicRate, + pozRate, + amount, + future, + constants.ZERO_ADDRESS, + true, + 0, + 0, + { from: firstAddress } + ) + poolId = tx.logs[1].args[1].toString() + let newpools = await poolzBack.poolsCount.call() + assert.equal(newpools.toNumber(), 1, "Got 1 pool") + let tokensInContract = await testToken.balanceOf(poolzBack.address) + assert.equal(tokensInContract.toString(), amount.toString(), "Got the tokens") }) - describe('Investing', () => { - const investor = accounts[9] - let lockedDealId - it('Investing in Locked Deal', async () => { - const tx = await poolzBack.InvestETH(poolId, { from: investor, value: web3.utils.toWei('0.4') }) - lockedDealId = tx.logs[2].args[2].toString() - const investorId = tx.logs[2].args[0].toString() - const result = await poolzBack.GetInvestmentData(investorId) - assert.equal(investor, result[1].toString()) - }) - it('should withdraw investment at unlock time', async () => { - const date = new Date() - date.setDate(date.getDate() + 1) // add a day - const future = Math.floor(date.getTime() / 1000) + 60 - await timeMachine.advanceBlockAndSetTime(future) - // await timeMachine.advanceTimeAndBlock(); - const tx = await lockedDeal.WithdrawToken(lockedDealId, { from: firstAddress }) - const result = tx.logs[0].args[0].toString() - const bal = await testToken.balanceOf(investor) - const now = Date.now() - await timeMachine.advanceBlockAndSetTime(Math.floor(now / 1000)) - assert.equal(result, bal) - }) + }) + describe("Investing", () => { + const investor = accounts[9] + let lockedDealId + it("Investing in Locked Deal", async () => { + const tx = await poolzBack.InvestETH(poolId, { from: investor, value: web3.utils.toWei("0.4") }) + lockedDealId = tx.logs[2].args[2].toString() + const investorId = tx.logs[2].args[0].toString() + const result = await poolzBack.GetInvestmentData(investorId) + assert.equal(investor, result[1].toString()) }) + it("should withdraw investment at unlock time", async () => { + const date = new Date() + date.setDate(date.getDate() + 1) // add a day + const future = Math.floor(date.getTime() / 1000) + 60 + await timeMachine.advanceBlockAndSetTime(future) + // await timeMachine.advanceTimeAndBlock(); + const tx = await lockedDeal.WithdrawToken(lockedDealId, { from: firstAddress }) + const result = tx.logs[0].args[0].toString() + const bal = await testToken.balanceOf(investor) + const now = Date.now() + await timeMachine.advanceBlockAndSetTime(Math.floor(now / 1000)) + assert.equal(result, bal) + }) + }) - describe('Withdrawing', () => { - it('should withdraw eth fee', async () => { - await lockedDeal.WithdrawETHFee(firstAddress) - }) + describe("Withdrawing", () => { + it("should withdraw eth fee", async () => { + await lockedDeal.WithdrawETHFee(firstAddress) + }) - it('should withdraw ERC20 fee', async () => { - await lockedDeal.WithdrawERC20Fee(testToken.address, firstAddress) - }) + it("should withdraw ERC20 fee", async () => { + await lockedDeal.WithdrawERC20Fee(testToken.address, firstAddress) }) -}) \ No newline at end of file + }) +}) diff --git a/test/10_Benefit.js b/test/10_Benefit.js index bfcc689..9a99888 100644 --- a/test/10_Benefit.js +++ b/test/10_Benefit.js @@ -1,19 +1,19 @@ -const ThePoolz = artifacts.require("ThePoolz"); -const Benefit = artifacts.require("Benefit"); -const Token = artifacts.require("Token"); -const WhiteList = artifacts.require("WhiteList"); -const UniswapV2Pair = artifacts.require("UniswapV2Pair"); -const UniswapV2Factory = artifacts.require("UniswapV2Factory"); -const { assert } = require("chai"); -const truffleAssert = require("truffle-assertions"); -const timeMachine = require("ganache-time-traveler"); -const BN = web3.utils.BN; -const pozRate = new BN("1000000000"); // with decimal21 (shifter) 1 eth^18 = 1 token^6 -const publicRate = new BN("500000000"); // with decimal21 (shifter) 1 eth^18 = 1 token^6 -const amount = new BN("3000000"); //3 tokens for sale -const constants = require("@openzeppelin/test-helpers/src/constants"); -const { createNewWhiteList } = require("./helper"); -const { equal } = require("assert"); +const ThePoolz = artifacts.require("ThePoolz") +const Benefit = artifacts.require("Benefit") +const Token = artifacts.require("Token") +const WhiteList = artifacts.require("WhiteList") +const UniswapV2Pair = artifacts.require("UniswapV2Pair") +const UniswapV2Factory = artifacts.require("UniswapV2Factory") +const { assert } = require("chai") +const truffleAssert = require("truffle-assertions") +const timeMachine = require("ganache-time-traveler") +const BN = web3.utils.BN +const pozRate = new BN("1000000000") // with decimal21 (shifter) 1 eth^18 = 1 token^6 +const publicRate = new BN("500000000") // with decimal21 (shifter) 1 eth^18 = 1 token^6 +const amount = new BN("3000000") //3 tokens for sale +const constants = require("@openzeppelin/test-helpers/src/constants") +const { createNewWhiteList } = require("./helper") +const { equal } = require("assert") contract("Integration between PoolzBack, Uniswap and Benefit", (accounts) => { let poolzBack, @@ -21,56 +21,52 @@ contract("Integration between PoolzBack, Uniswap and Benefit", (accounts) => { pozToken, whiteList, testToken, - firstAddress = accounts[0]; - let poolId, uniswapV2Pair, uniswapV2Factory; + firstAddress = accounts[0] + let poolId, uniswapV2Pair, uniswapV2Factory before(async () => { - poolzBack = await ThePoolz.deployed(); - benefit = await Benefit.deployed(); - whiteList = await WhiteList.deployed(); - pozToken = await Token.new("Poolz", "POZ"); - testToken = await Token.new("TestToken", "TEST"); + poolzBack = await ThePoolz.deployed() + benefit = await Benefit.deployed() + whiteList = await WhiteList.deployed() + pozToken = await Token.new("Poolz", "POZ") + testToken = await Token.new("TestToken", "TEST") //uniswapV2Pair = await UniswapV2Pair.deployed() - uniswapV2Factory = await UniswapV2Factory.deployed(); - }); + uniswapV2Factory = await UniswapV2Factory.deployed() + }) describe("Setting up PoolzBack", () => { - let poolWhiteListId; + let poolWhiteListId it("should set address of Benefit contract", async () => { await poolzBack.SetBenefit_Address(benefit.address, { - from: firstAddress, - }); - const result = await poolzBack.Benefit_Address(); - assert.equal(result, benefit.address); - }); + from: firstAddress + }) + const result = await poolzBack.Benefit_Address() + assert.equal(result, benefit.address) + }) it("should set address of whiteList contract", async () => { await poolzBack.SetWhiteList_Address(whiteList.address, { - from: firstAddress, - }); - const result = await poolzBack.WhiteList_Address(); - assert.equal(whiteList.address, result); - }); + from: firstAddress + }) + const result = await poolzBack.WhiteList_Address() + assert.equal(whiteList.address, result) + }) it("Creating new WhiteList for pool", async () => { - const tx = await createNewWhiteList( - whiteList, - poolzBack.address, - firstAddress - ); - poolWhiteListId = tx.logs[0].args._WhiteListCount.toNumber(); - }); + const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) + poolWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() + }) it("should create new ETH Pool", async () => { await testToken.approve(poolzBack.address, amount, { - from: firstAddress, - }); - const date = new Date(); - date.setDate(date.getDate() + 1); // add a day - const lockedUntil = Math.floor(date.getTime() / 1000) + 60; - date.setDate(date.getDate() + 1); // add a day - const finishTime = Math.floor(date.getTime() / 1000) + 60; + from: firstAddress + }) + const date = new Date() + date.setDate(date.getDate() + 1) // add a day + const lockedUntil = Math.floor(date.getTime() / 1000) + 60 + date.setDate(date.getDate() + 1) // add a day + const finishTime = Math.floor(date.getTime() / 1000) + 60 const tx = await poolzBack.CreatePool( testToken.address, finishTime, @@ -83,222 +79,189 @@ contract("Integration between PoolzBack, Uniswap and Benefit", (accounts) => { 0, poolWhiteListId, { from: firstAddress } - ); - poolId = tx.logs[1].args[1].toString(); - let newpools = await poolzBack.poolsCount.call(); - assert.equal(newpools.toNumber(), 1, "Got 1 pool"); - let tokensInContract = await testToken.balanceOf(poolzBack.address); - assert.equal( - tokensInContract.toString(), - amount.toString(), - "Got the tokens" - ); - }); - }); + ) + poolId = tx.logs[1].args[1].toString() + let newpools = await poolzBack.poolsCount.call() + assert.equal(newpools.toNumber(), 1, "Got 1 pool") + let tokensInContract = await testToken.balanceOf(poolzBack.address) + assert.equal(tokensInContract.toString(), amount.toString(), "Got the tokens") + }) + }) describe("Setting up Benefit Contract", () => { it("Adding POZ token to Benefit contract", async () => { - await benefit.AddNewToken(pozToken.address, { from: firstAddress }); - const count = await benefit.ChecksCount(); - assert.equal(count, 1, "Got 1 Check"); - }); + await benefit.AddNewToken(pozToken.address, { from: firstAddress }) + const count = await benefit.ChecksCount() + assert.equal(count, 1, "Got 1 Check") + }) it("Create liquidity pair", async () => { - const result = await uniswapV2Factory.createPair( - pozToken.address, - testToken.address, - { from: firstAddress } - ); - const pair = await uniswapV2Factory.getPair( - pozToken.address, - testToken.address - ); - uniswapV2Pair = await UniswapV2Pair.at(pair); + const result = await uniswapV2Factory.createPair(pozToken.address, testToken.address, { from: firstAddress }) + const pair = await uniswapV2Factory.getPair(pozToken.address, testToken.address) + uniswapV2Pair = await UniswapV2Pair.at(pair) const [token0, token1] = [ result.logs[result.logs.length - 1].args.token0, - result.logs[result.logs.length - 1].args.token1, - ]; - assert.equal( - token0, - await uniswapV2Pair.token0(), - "check first token address" - ); - assert.equal( - token1, - await uniswapV2Pair.token1(), - "check second token address" - ); - }); + result.logs[result.logs.length - 1].args.token1 + ] + assert.equal(token0, await uniswapV2Pair.token0(), "check first token address") + assert.equal(token1, await uniswapV2Pair.token1(), "check second token address") + }) it("Tracking POZ token in LP", async () => { await benefit.AddNewLpCheck(pozToken.address, uniswapV2Pair.address, { - from: firstAddress, - }); - const count = await benefit.ChecksCount(); - assert.equal(count, 2, "Got 2 Check"); - }); - }); + from: firstAddress + }) + const count = await benefit.ChecksCount() + assert.equal(count, 2, "Got 2 Check") + }) + }) describe("Benefit and LP integration", () => { - const pozHolder = accounts[3]; + const pozHolder = accounts[3] it("add liquidity (low-level)", async () => { - const amount = "15000000"; - await pozToken.transfer(uniswapV2Pair.address, amount); - await testToken.transfer(uniswapV2Pair.address, amount); - await uniswapV2Pair.mint(firstAddress); + const amount = "15000000" + await pozToken.transfer(uniswapV2Pair.address, amount) + await testToken.transfer(uniswapV2Pair.address, amount) + await uniswapV2Pair.mint(firstAddress) - const reserve0 = (await uniswapV2Pair.getReserves())["0"]; - const reserve1 = (await uniswapV2Pair.getReserves())["1"]; - assert.equal(reserve0, amount, "check first token reserve"); - assert.equal(reserve1, amount, "check second token reserve"); - }); + const reserve0 = (await uniswapV2Pair.getReserves())["0"] + const reserve1 = (await uniswapV2Pair.getReserves())["1"] + assert.equal(reserve0, amount, "check first token reserve") + assert.equal(reserve1, amount, "check second token reserve") + }) it("calc tokens without LP", async () => { - const amount = "5000000"; - await pozToken.transfer(pozHolder, amount); - await testToken.transfer(pozHolder, amount); - const result = await benefit.CalcTotal(pozHolder); - assert.equal(result.toString(), amount, "check token amount"); - }); + const amount = "5000000" + await pozToken.transfer(pozHolder, amount) + await testToken.transfer(pozHolder, amount) + const result = await benefit.CalcTotal(pozHolder) + assert.equal(result.toString(), amount, "check token amount") + }) it("calc tokens with LP", async () => { - const amount = (await pozToken.balanceOf(pozHolder)) / 2; + const amount = (await pozToken.balanceOf(pozHolder)) / 2 await pozToken.transfer(uniswapV2Pair.address, amount.toString(), { - from: pozHolder, - }); + from: pozHolder + }) await testToken.transfer(uniswapV2Pair.address, amount.toString(), { - from: pozHolder, - }); - await uniswapV2Pair.mint(pozHolder, { from: pozHolder }); - const balance = await uniswapV2Pair.balanceOf(pozHolder); - assert.equal( - amount, - balance, - "checking how many tokens were added to LP" - ); - const result = await benefit.CalcTotal(pozHolder); - const expectedBalance = (await pozToken.balanceOf(pozHolder)) * 2; - assert.equal( - result.toString(), - expectedBalance.toString(), - "check token amount" - ); - }); + from: pozHolder + }) + await uniswapV2Pair.mint(pozHolder, { from: pozHolder }) + const balance = await uniswapV2Pair.balanceOf(pozHolder) + assert.equal(amount, balance, "checking how many tokens were added to LP") + const result = await benefit.CalcTotal(pozHolder) + const expectedBalance = (await pozToken.balanceOf(pozHolder)) * 2 + assert.equal(result.toString(), expectedBalance.toString(), "check token amount") + }) it("check when remove lp traking", async () => { - await benefit.RemoveLastBalanceCheckData(); - const expected = await pozToken.balanceOf(pozHolder); - const actual = await benefit.CalcTotal(pozHolder); - assert.equal( - expected.toString(), - actual.toString(), - "calc tokens without LP contract" - ); - }); + await benefit.RemoveLastBalanceCheckData() + const expected = await pozToken.balanceOf(pozHolder) + const actual = await benefit.CalcTotal(pozHolder) + assert.equal(expected.toString(), actual.toString(), "calc tokens without LP contract") + }) it("calculation of tokens when change liquidity", async () => { - it('should return whether is POZ holder', async () => { + it("should return whether is POZ holder", async () => { await benefit.IsPOZHolder(accounts[3]) }) await benefit.AddNewLpCheck(pozToken.address, uniswapV2Pair.address, { - from: firstAddress, - }); + from: firstAddress + }) // - const amount = "1000"; + const amount = "1000" await pozToken.transfer(uniswapV2Pair.address, amount, { - from: pozHolder, - }); + from: pozHolder + }) await testToken.transfer(uniswapV2Pair.address, amount, { - from: pozHolder, - }); - await uniswapV2Pair.mint(pozHolder, { from: pozHolder }); - let result = await benefit.CalcTotal(pozHolder); - let expectedBalance = "5000000"; - assert.equal(result.toString(), expectedBalance, "check token amount"); + from: pozHolder + }) + await uniswapV2Pair.mint(pozHolder, { from: pozHolder }) + let result = await benefit.CalcTotal(pozHolder) + let expectedBalance = "5000000" + assert.equal(result.toString(), expectedBalance, "check token amount") // await pozToken.transfer(uniswapV2Pair.address, amount, { - from: pozHolder, - }); + from: pozHolder + }) await testToken.transfer(uniswapV2Pair.address, amount, { - from: pozHolder, - }); - await uniswapV2Pair.mint(pozHolder, { from: pozHolder }); - result = await benefit.CalcTotal(pozHolder); - assert.equal(result.toString(), expectedBalance, "check token amount"); - expectedBalance = "2502000"; - result = await uniswapV2Pair.balanceOf(pozHolder); - assert.equal(expectedBalance, result.toString(), "check lp amount"); + from: pozHolder + }) + await uniswapV2Pair.mint(pozHolder, { from: pozHolder }) + result = await benefit.CalcTotal(pozHolder) + assert.equal(result.toString(), expectedBalance, "check token amount") + expectedBalance = "2502000" + result = await uniswapV2Pair.balanceOf(pozHolder) + assert.equal(expectedBalance, result.toString(), "check lp amount") // - await uniswapV2Pair.skim(pozHolder, { from: pozHolder }); - result = await benefit.CalcTotal(pozHolder); - expectedBalance = "5000000"; - assert.equal(result.toString(), expectedBalance, "check token amount"); - }); - }); + await uniswapV2Pair.skim(pozHolder, { from: pozHolder }) + result = await benefit.CalcTotal(pozHolder) + expectedBalance = "5000000" + assert.equal(result.toString(), expectedBalance, "check token amount") + }) + }) describe("Investing in Pool", () => { - const investor = accounts[9]; + const investor = accounts[9] it("Fail to invest when investor has no POZ", async () => { - const date = new Date(); - date.setDate(date.getDate() + 1); // add a day - const future = Math.floor(date.getTime() / 1000) + 60; - await timeMachine.advanceBlockAndSetTime(future); + const date = new Date() + date.setDate(date.getDate() + 1) // add a day + const future = Math.floor(date.getTime() / 1000) + 60 + await timeMachine.advanceBlockAndSetTime(future) await truffleAssert.reverts( poolzBack.InvestETH(poolId, { from: investor, - value: web3.utils.toWei("0.4"), + value: web3.utils.toWei("0.4") }), "Only POZ holder can invest" - ); - await timeMachine.advanceBlockAndSetTime(Math.floor(Date.now() / 1000)); - }); + ) + await timeMachine.advanceBlockAndSetTime(Math.floor(Date.now() / 1000)) + }) it("sending POZ to investor", async () => { - const amount = "1000000"; - await pozToken.transfer(investor, amount, { from: firstAddress }); - const result = await pozToken.balanceOf(investor); - assert.equal(result.toString(), amount); - }); + const amount = "1000000" + await pozToken.transfer(investor, amount, { from: firstAddress }) + const result = await pozToken.balanceOf(investor) + assert.equal(result.toString(), amount) + }) it("should invest in Pool when it is open for all", async () => { - const date = new Date(); - date.setDate(date.getDate() + 1); // add a day - const future = Math.floor(date.getTime() / 1000) + 60; - await timeMachine.advanceBlockAndSetTime(future); + const date = new Date() + date.setDate(date.getDate() + 1) // add a day + const future = Math.floor(date.getTime() / 1000) + 60 + await timeMachine.advanceBlockAndSetTime(future) await poolzBack.InvestETH(poolId, { from: investor, - value: web3.utils.toWei("0.4"), - }); - const tokenDecimals = await testToken.decimals(); - const realRate = publicRate.div( - new BN(10).pow(new BN(21 + tokenDecimals.toNumber() - 18)) - ); // converting decimal21Rate to realRate - const tokens = 0.4 * realRate.toNumber(); - const bal = await testToken.balanceOf(investor); - assert.deepEqual(bal, new BN(tokens).mul(new BN(10).pow(tokenDecimals))); - await timeMachine.advanceBlockAndSetTime(Math.floor(Date.now() / 1000)); - }); + value: web3.utils.toWei("0.4") + }) + const tokenDecimals = await testToken.decimals() + const realRate = publicRate.div(new BN(10).pow(new BN(21 + tokenDecimals.toNumber() - 18))) // converting decimal21Rate to realRate + const tokens = 0.4 * realRate.toNumber() + const bal = await testToken.balanceOf(investor) + assert.deepEqual(bal, new BN(tokens).mul(new BN(10).pow(tokenDecimals))) + await timeMachine.advanceBlockAndSetTime(Math.floor(Date.now() / 1000)) + }) after(async () => { - await timeMachine.advanceBlockAndSetTime(Math.floor(Date.now() / 1000)); - }); - }); + await timeMachine.advanceBlockAndSetTime(Math.floor(Date.now() / 1000)) + }) + }) describe("Setting up Benefit Contract", () => { - it('should reset a check count', async () => { - const previousCount = await benefit.ChecksCount(); - await benefit.RemoveAll(); - const newCount = await benefit.ChecksCount(); + it("should reset a check count", async () => { + const previousCount = await benefit.ChecksCount() + await benefit.RemoveAll() + const newCount = await benefit.ChecksCount() assert.notEqual(previousCount, newCount) assert.equal(0, newCount) }) - it('should add new staking', async () => { - const previousCount = await benefit.ChecksCount(); - await benefit.AddNewStaking(poolzBack.address); - const newCount = await benefit.ChecksCount(); - equal((previousCount.toNumber()) + 1, newCount); + it("should add new staking", async () => { + const previousCount = await benefit.ChecksCount() + await benefit.AddNewStaking(poolzBack.address) + const newCount = await benefit.ChecksCount() + equal(previousCount.toNumber() + 1, newCount) }) - }); -}); + }) +}) diff --git a/test/11_Hodlers.js b/test/11_Hodlers.js index 6fdb0fa..3fd54c8 100644 --- a/test/11_Hodlers.js +++ b/test/11_Hodlers.js @@ -1,135 +1,153 @@ const ThePoolz = artifacts.require("ThePoolz") const HodlersWhitelist = artifacts.require("HodlersWhitelist") const Token = artifacts.require("Token") -const WhiteList = artifacts.require('WhiteList') -const { assert } = require('chai'); -const truffleAssert = require('truffle-assertions') -const timeMachine = require('ganache-time-traveler') -const BigNumber = require('bignumber.js') +const WhiteList = artifacts.require("WhiteList") +const { assert } = require("chai") +const truffleAssert = require("truffle-assertions") +const timeMachine = require("ganache-time-traveler") +const BigNumber = require("bignumber.js") const constants = require("@openzeppelin/test-helpers/src/constants") const BN = web3.utils.BN -const pozRate = new BN('1000000000') // with decimal21 (shifter) 1 eth^18 = 1 token^6 -const publicRate = new BN('500000000') // with decimal21 (shifter) 1 eth^18 = 1 token^6 -const amount = new BN('3000000') //3 tokens for sale +const pozRate = new BN("1000000000") // with decimal21 (shifter) 1 eth^18 = 1 token^6 +const publicRate = new BN("500000000") // with decimal21 (shifter) 1 eth^18 = 1 token^6 +const amount = new BN("3000000") //3 tokens for sale + +const { createNewWhiteList } = require("./helper") + +contract("Integration between HodlersWhitelist and PoolzBack", (accounts) => { + let poolzBack, + testToken, + whiteList, + firstAddress = accounts[0] + let hodlers = [] + let poolId + + before(async () => { + poolzBack = await ThePoolz.deployed() + hodlersWhitelist = await HodlersWhitelist.deployed() + whiteList = await WhiteList.deployed() + // pozToken = await Token.new('Poolz', 'POZ') + testToken = await Token.new("TestToken", "TEST") + }) + + describe("Setting up PoolzBack", () => { + let poolWhiteListId + + it("should set address of HodlersWhitelist contract", async () => { + await poolzBack.SetBenefit_Address(hodlersWhitelist.address, { from: firstAddress }) + const result = await poolzBack.Benefit_Address() + assert.equal(result, hodlersWhitelist.address) + }) + + it("should set address of whiteList contract", async () => { + await poolzBack.SetWhiteList_Address(whiteList.address, { from: firstAddress }) + const result = await poolzBack.WhiteList_Address() + assert.equal(whiteList.address, result) + }) + + it("Creating new WhiteList for pool", async () => { + const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) + poolWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() + }) + + it("should set POZ Timer to 50%", async () => { + await poolzBack.SetPozTimer(5000, { from: firstAddress }) + const result = await poolzBack.PozTimer() + assert.equal(result.toNumber(), 5000) + }) + + it("should create new ETH Pool", async () => { + await testToken.approve(poolzBack.address, amount, { from: firstAddress }) + const date = new Date() + date.setHours(date.getHours() + 4) // add 4 hours + const finishTime = Math.floor(date.getTime() / 1000) + const tx = await poolzBack.CreatePool( + testToken.address, + finishTime, + publicRate, + pozRate, + amount, + 0, + constants.ZERO_ADDRESS, + true, + 0, + poolWhiteListId, + { from: firstAddress } + ) // dsp pool + poolId = tx.logs[1].args[1].toString() + let newpools = await poolzBack.poolsCount.call() + assert.equal(newpools.toNumber(), 1, "Got 1 pool") + let tokensInContract = await testToken.balanceOf(poolzBack.address) + assert.equal(tokensInContract.toString(), amount.toString(), "Got the tokens") + }) + }) + + describe("Setting up HodlersWhitelist Contract", () => { + let whitelistId + + it("should create new Hodlers Whitelist", async () => { + const now = Date.now() / 1000 // current timestamp in seconds + const timestamp = Number(now.toFixed()) + 3600 // timestamp one hour from now + const result = await hodlersWhitelist.CreateManualWhiteList(timestamp, { from: firstAddress }) + const count = await hodlersWhitelist.WhiteListCount() + const logs = result.logs[0].args + whitelistId = logs._WhitelistId.toString() + assert.equal("0", logs._WhitelistId.toString()) + assert.equal(firstAddress, logs._creator.toString()) + assert.equal(timestamp, logs._changeUntil.toString()) + assert.equal("1", count.toString()) + }) -const { createNewWhiteList } = require('./helper') + it("should set the main hodlers whitelist ID", async () => { + await hodlersWhitelist.SetMainWhitelistId(whitelistId, { from: firstAddress }) + const result = await hodlersWhitelist.MainWhitelistId() + assert.equal(result, whitelistId) + }) -contract('Integration between HodlersWhitelist and PoolzBack', accounts => { - let poolzBack, testToken, whiteList, firstAddress = accounts[0] - let hodlers = [] - let poolId + it("should add addresses to whitelist", async () => { + hodlers = [accounts[1], accounts[2], accounts[3], accounts[4], accounts[5]] + await hodlersWhitelist.AddAddress(whitelistId, hodlers, { from: firstAddress }) + const result1 = await hodlersWhitelist.IsPOZHolder(accounts[1]) + assert.isTrue(result1) + const result2 = await hodlersWhitelist.IsPOZHolder(accounts[2]) + assert.isTrue(result2) + const result3 = await hodlersWhitelist.IsPOZHolder(accounts[3]) + assert.isTrue(result3) + const result4 = await hodlersWhitelist.IsPOZHolder(accounts[4]) + assert.isTrue(result4) + const result5 = await hodlersWhitelist.IsPOZHolder(accounts[5]) + assert.isTrue(result5) + const result6 = await hodlersWhitelist.IsPOZHolder(accounts[6]) + assert.isFalse(result6) + }) + }) - before(async () => { - poolzBack = await ThePoolz.deployed() - hodlersWhitelist = await HodlersWhitelist.deployed() - whiteList = await WhiteList.deployed() - // pozToken = await Token.new('Poolz', 'POZ') - testToken = await Token.new('TestToken', 'TEST') + describe("Investing in Pool", () => { + it("moving time to when pool is open", async () => { + await timeMachine.advanceTimeAndBlock(3600 * 2) + const result = await poolzBack.GetPoolStatus(poolId) + assert.equal(result.toString(), "1") }) - describe('Setting up PoolzBack', () => { - let poolWhiteListId - - it('should set address of HodlersWhitelist contract', async () => { - await poolzBack.SetBenefit_Address(hodlersWhitelist.address, { from: firstAddress }) - const result = await poolzBack.Benefit_Address() - assert.equal(result, hodlersWhitelist.address) - }) - - it('should set address of whiteList contract', async () => { - await poolzBack.SetWhiteList_Address(whiteList.address, { from: firstAddress }) - const result = await poolzBack.WhiteList_Address() - assert.equal(whiteList.address, result) - }) - - it('Creating new WhiteList for pool', async () => { - const tx = await createNewWhiteList(whiteList, poolzBack.address, firstAddress) - poolWhiteListId = tx.logs[0].args._WhiteListCount.toNumber() - }) - - it('should set POZ Timer to 50%', async () => { - await poolzBack.SetPozTimer(5000, { from: firstAddress }) - const result = await poolzBack.PozTimer() - assert.equal(result.toNumber(), 5000) - }) - - it('should create new ETH Pool', async () => { - await testToken.approve(poolzBack.address, amount, { from: firstAddress }) - const date = new Date() - date.setHours(date.getHours() + 4) // add 4 hours - const finishTime = Math.floor(date.getTime() / 1000) - const tx = await poolzBack.CreatePool(testToken.address, finishTime, publicRate, pozRate, amount, 0, constants.ZERO_ADDRESS, true, 0, poolWhiteListId, { from: firstAddress }) // dsp pool - poolId = tx.logs[1].args[1].toString() - let newpools = await poolzBack.poolsCount.call() - assert.equal(newpools.toNumber(), 1, "Got 1 pool") - let tokensInContract = await testToken.balanceOf(poolzBack.address) - assert.equal(tokensInContract.toString(), amount.toString(), "Got the tokens") - }) + it("fail to invest when investor is not hodler", async () => { + await truffleAssert.reverts( + poolzBack.InvestETH(poolId, { from: accounts[9], value: web3.utils.toWei("0.1") }), + "Only POZ holder can invest" + ) }) - describe('Setting up HodlersWhitelist Contract', () => { - let whitelistId - - it('should create new Hodlers Whitelist', async () => { - const now = Date.now() / 1000 // current timestamp in seconds - const timestamp = Number(now.toFixed()) + 3600 // timestamp one hour from now - const result = await hodlersWhitelist.CreateManualWhiteList(timestamp, { from: firstAddress }) - const count = await hodlersWhitelist.WhiteListCount() - const logs = result.logs[0].args - whitelistId = logs._WhitelistId.toString() - assert.equal('0', logs._WhitelistId.toString()) - assert.equal(firstAddress, logs._creator.toString()) - assert.equal(timestamp, logs._changeUntil.toString()) - assert.equal('1', count.toString()) - }) - - it('should set the main hodlers whitelist ID', async () => { - await hodlersWhitelist.SetMainWhitelistId(whitelistId, { from: firstAddress }) - const result = await hodlersWhitelist.MainWhitelistId() - assert.equal(result, whitelistId) - }) - - it('should add addresses to whitelist', async () => { - hodlers = [accounts[1], accounts[2], accounts[3], accounts[4], accounts[5]] - await hodlersWhitelist.AddAddress(whitelistId, hodlers, { from: firstAddress }) - const result1 = await hodlersWhitelist.IsPOZHolder(accounts[1]) - assert.isTrue(result1) - const result2 = await hodlersWhitelist.IsPOZHolder(accounts[2]) - assert.isTrue(result2) - const result3 = await hodlersWhitelist.IsPOZHolder(accounts[3]) - assert.isTrue(result3) - const result4 = await hodlersWhitelist.IsPOZHolder(accounts[4]) - assert.isTrue(result4) - const result5 = await hodlersWhitelist.IsPOZHolder(accounts[5]) - assert.isTrue(result5) - const result6 = await hodlersWhitelist.IsPOZHolder(accounts[6]) - assert.isFalse(result6) - }) + it("Successfully invest when investor is Hodler", async () => { + const result = await poolzBack.InvestETH(poolId, { from: hodlers[0], value: web3.utils.toWei("0.4") }) + const tokenDecimals = await testToken.decimals() + const realRate = publicRate.div(new BN(10).pow(new BN(21 + tokenDecimals.toNumber() - 18))) // converting decimal21Rate to realRate + const tokens = 0.4 * realRate.toNumber() + const bal = await testToken.balanceOf(hodlers[0]) + assert.deepEqual(bal, new BN(tokens).mul(new BN(10).pow(tokenDecimals))) }) - describe('Investing in Pool', () => { - it('moving time to when pool is open', async () => { - await timeMachine.advanceTimeAndBlock(3600 * 2); - const result = await poolzBack.GetPoolStatus(poolId) - assert.equal(result.toString(), '1') - }) - - it('fail to invest when investor is not hodler', async () => { - await truffleAssert.reverts(poolzBack.InvestETH(poolId, { from: accounts[9], value: web3.utils.toWei('0.1') }), 'Only POZ holder can invest') - }) - - it('Successfully invest when investor is Hodler', async () => { - const result = await poolzBack.InvestETH(poolId, { from: hodlers[0], value: web3.utils.toWei('0.4') }) - const tokenDecimals = await testToken.decimals() - const realRate = publicRate.div(new BN(10).pow(new BN(21 + tokenDecimals.toNumber() - 18))) // converting decimal21Rate to realRate - const tokens = 0.4 * realRate.toNumber() - const bal = await testToken.balanceOf(hodlers[0]) - assert.deepEqual(bal, new BN(tokens).mul(new BN(10).pow(tokenDecimals))) - }) - - after(async () => { - await timeMachine.advanceTimeAndBlock(-3600 * 2); - }) + after(async () => { + await timeMachine.advanceTimeAndBlock(-3600 * 2) }) -}) \ No newline at end of file + }) +}) diff --git a/test/12_Envelop.js b/test/12_Envelop.js index df2658e..b5ef1ca 100644 --- a/test/12_Envelop.js +++ b/test/12_Envelop.js @@ -1,670 +1,492 @@ -const Token = artifacts.require("POOLZSYNT"); -const TestToken = artifacts.require("OriginalToken"); -const LockedDeal = artifacts.require("LockedDeal"); -const WhiteList = artifacts.require("WhiteList"); -const UniswapV2Factory = artifacts.require("UniswapV2Factory"); -const UniswapV2Pair = artifacts.require("UniswapV2Pair"); -const { assert } = require("chai"); -const truffleAssert = require("truffle-assertions"); -const BigNumber = require("bignumber.js"); -const timeMachine = require("ganache-time-traveler"); -BigNumber.config({ EXPONENTIAL_AT: 1e9 }); -const { uintMinusOne } = require("./helper/index"); -BigNumber.config({ EXPONENTIAL_AT: 1e9 }); +const Token = artifacts.require("POOLZSYNT") +const TestToken = artifacts.require("OriginalToken") +const LockedDeal = artifacts.require("LockedDeal") +const WhiteList = artifacts.require("WhiteList") +const UniswapV2Factory = artifacts.require("UniswapV2Factory") +const UniswapV2Pair = artifacts.require("UniswapV2Pair") +const { assert } = require("chai") +const truffleAssert = require("truffle-assertions") +const BigNumber = require("bignumber.js") +const timeMachine = require("ganache-time-traveler") +BigNumber.config({ EXPONENTIAL_AT: 1e9 }) +const { uintMinusOne } = require("./helper/index") +BigNumber.config({ EXPONENTIAL_AT: 1e9 }) -contract( - "Integration Between Envelop Token, WhiteList and LockedDeal", - (accounts) => { - let token, - originalToken, - lockedDealContract, - whitelistContract, - firstAddress = accounts[0]; - let uniswapV2Factory, uniswapV2Pair, whitelistId; - let finishTime = parseInt( - new Date().setHours(new Date().getHours() + 1) / 1000 - ); // current time + 1H - // let whitelistId = 1 +contract("Integration Between Envelop Token, WhiteList and LockedDeal", (accounts) => { + let token, + originalToken, + lockedDealContract, + whitelistContract, + firstAddress = accounts[0] + let uniswapV2Factory, uniswapV2Pair, whitelistId + let finishTime = parseInt(new Date().setHours(new Date().getHours() + 1) / 1000) // current time + 1H + // let whitelistId = 1 - const cap = new BigNumber(10000); - const timestamps = []; - const ratios = [1, 1, 1]; - const tokenName = "REAL Synthetic"; - const tokenSymbol = "~REAL Poolz"; - const decimals = "18"; + const cap = new BigNumber(10000) + const timestamps = [] + const ratios = [1, 1, 1] + const tokenName = "REAL Synthetic" + const tokenSymbol = "~REAL Poolz" + const decimals = "18" - before(async () => { - originalToken = await TestToken.new("OrgToken", "ORGT", { - from: firstAddress, - }); - lockedDealContract = await LockedDeal.new(); - uniswapV2Factory = await UniswapV2Factory.deployed(); - whitelistContract = await WhiteList.new(); - const now = new Date(); - timestamps.push((now.setHours(now.getHours() + 2) / 1000).toFixed()); // current time + 2H - timestamps.push((now.setHours(now.getHours() + 1) / 1000).toFixed()); - timestamps.push((now.setHours(now.getHours() + 1) / 1000).toFixed()); - }); + before(async () => { + originalToken = await TestToken.new("OrgToken", "ORGT", { + from: firstAddress + }) + lockedDealContract = await LockedDeal.new() + uniswapV2Factory = await UniswapV2Factory.deployed() + whitelistContract = await WhiteList.new() + const now = new Date() + timestamps.push((now.setHours(now.getHours() + 2) / 1000).toFixed()) // current time + 2H + timestamps.push((now.setHours(now.getHours() + 1) / 1000).toFixed()) + timestamps.push((now.setHours(now.getHours() + 1) / 1000).toFixed()) + }) - describe("setting up Envelop Token", () => { - it("should deploy new envelop token", async () => { - token = await Token.new( - tokenName, - tokenSymbol, - cap.toString(), - decimals, - firstAddress, - lockedDealContract.address, - whitelistContract.address, - { from: firstAddress } - ); - // const tx = await web3.eth.getTransactionReceipt(token.transactionHash) - // console.log(tx) - // tx.logs.forEach(item => { - // const data = web3.eth.abi.decodeParameter('string', item.data) - // console.log(data) - // }) - const name = await token.name(); - const symbol = await token.symbol(); - const firstBalance = await token.balanceOf(firstAddress); - const tokenDecimals = await token.decimals(); - const capp = await token.cap(); - const expectedCapp = cap.multipliedBy(10 ** 18).toString(); - const lockedAddress = await token.LockedDealAddress(); - const whitelistAddress = await token.WhitelistAddress(); - whitelistId = await token.WhitelistId(); - const whitelistCount = await whitelistContract.WhiteListCount(); - const whitelistSettings = await whitelistContract.WhitelistSettings( - whitelistId - ); - assert.equal(tokenName, name, "check name"); - assert.equal(tokenSymbol, symbol, "check symbol"); - assert.equal(tokenDecimals.toString(), decimals, "check decimals"); - assert.equal( - firstBalance.toString(), - cap.multipliedBy(10 ** 18).toString(), - "check first address balance" - ); - assert.equal( - lockedAddress, - lockedDealContract.address, - "check lockedDeal address" - ); - assert.equal( - whitelistAddress, - whitelistContract.address, - "check whitelist address" - ); - assert.equal(capp, expectedCapp, "check capitalization"); - assert.equal(whitelistCount.toString(), "2"); - assert.equal(firstAddress, whitelistSettings.Creator); - assert.equal(uintMinusOne, whitelistSettings.ChangeUntil.toString()); - assert.equal(token.address, whitelistSettings.Contract); - assert.equal(false, whitelistSettings.isReady); - }); - it("should set locking details", async () => { - await originalToken.approve( - token.address, - cap.multipliedBy(10 ** 18).toString(), - { from: firstAddress } - ); - const _cap = await token.cap(); - const tx = await token.SetLockingDetails( - originalToken.address, - timestamps, - ratios, - finishTime, - { from: firstAddress } - ); - const originalAddress = tx.logs[3].args.TokenAddress; - const totalAmount = tx.logs[3].args.Amount; - const totalUnlocks = tx.logs[3].args.TotalUnlocks; - const time = tx.logs[3].args.FinishTime; - const tokenCap = await token.cap(); - assert.equal( - originalToken.address, - originalAddress, - "check token address" - ); - assert.equal( - totalAmount.toString(), - tokenCap.toString(), - "check total amount" - ); - assert.equal(totalUnlocks, timestamps.length, "check total unlocks"); - assert.equal(time, finishTime, "check finish time"); - }); + describe("setting up Envelop Token", () => { + it("should deploy new envelop token", async () => { + token = await Token.new( + tokenName, + tokenSymbol, + cap.toString(), + decimals, + firstAddress, + lockedDealContract.address, + whitelistContract.address, + { from: firstAddress } + ) + // const tx = await web3.eth.getTransactionReceipt(token.transactionHash) + // console.log(tx) + // tx.logs.forEach(item => { + // const data = web3.eth.abi.decodeParameter('string', item.data) + // console.log(data) + // }) + const name = await token.name() + const symbol = await token.symbol() + const firstBalance = await token.balanceOf(firstAddress) + const tokenDecimals = await token.decimals() + const capp = await token.cap() + const expectedCapp = cap.multipliedBy(10 ** 18).toString() + const lockedAddress = await token.LockedDealAddress() + const whitelistAddress = await token.WhitelistAddress() + whitelistId = await token.WhitelistId() + const whitelistCount = await whitelistContract.WhiteListCount() + const whitelistSettings = await whitelistContract.WhitelistSettings(whitelistId) + assert.equal(tokenName, name, "check name") + assert.equal(tokenSymbol, symbol, "check symbol") + assert.equal(tokenDecimals.toString(), decimals, "check decimals") + assert.equal(firstBalance.toString(), cap.multipliedBy(10 ** 18).toString(), "check first address balance") + assert.equal(lockedAddress, lockedDealContract.address, "check lockedDeal address") + assert.equal(whitelistAddress, whitelistContract.address, "check whitelist address") + assert.equal(capp, expectedCapp, "check capitalization") + assert.equal(whitelistCount.toString(), "2") + assert.equal(firstAddress, whitelistSettings.Creator) + assert.equal(uintMinusOne, whitelistSettings.ChangeUntil.toString()) + assert.equal(token.address, whitelistSettings.Contract) + assert.equal(false, whitelistSettings.isReady) + }) + it("should set locking details", async () => { + await originalToken.approve(token.address, cap.multipliedBy(10 ** 18).toString(), { from: firstAddress }) + const _cap = await token.cap() + const tx = await token.SetLockingDetails(originalToken.address, timestamps, ratios, finishTime, { + from: firstAddress + }) + const originalAddress = tx.logs[3].args.TokenAddress + const totalAmount = tx.logs[3].args.Amount + const totalUnlocks = tx.logs[3].args.TotalUnlocks + const time = tx.logs[3].args.FinishTime + const tokenCap = await token.cap() + assert.equal(originalToken.address, originalAddress, "check token address") + assert.equal(totalAmount.toString(), tokenCap.toString(), "check total amount") + assert.equal(totalUnlocks, timestamps.length, "check total unlocks") + assert.equal(time, finishTime, "check finish time") + }) - it("verifying locking details", async () => { - const totalRatios = ratios.reduce((a, b) => a + b, 0); - const orgToken = await token.OriginalTokenAddress(); - const totalUnlocks = await token.totalUnlocks(); - const ratioTotal = await token.totalOfRatios(); - assert.equal(orgToken, originalToken.address); - assert.equal(totalUnlocks, timestamps.length); - assert.equal(ratioTotal, totalRatios); - for (let i = 0; i < totalUnlocks; i++) { - const details = await token.LockDetails(i); - assert.equal(details.unlockTime.toString(), timestamps[i].toString()); - assert.equal(details.ratio.toString(), ratios[i].toString()); - } - }); - }); + it("verifying locking details", async () => { + const totalRatios = ratios.reduce((a, b) => a + b, 0) + const orgToken = await token.OriginalTokenAddress() + const totalUnlocks = await token.totalUnlocks() + const ratioTotal = await token.totalOfRatios() + assert.equal(orgToken, originalToken.address) + assert.equal(totalUnlocks, timestamps.length) + assert.equal(ratioTotal, totalRatios) + for (let i = 0; i < totalUnlocks; i++) { + const details = await token.LockDetails(i) + assert.equal(details.unlockTime.toString(), timestamps[i].toString()) + assert.equal(details.ratio.toString(), ratios[i].toString()) + } + }) + }) - describe("Integration with LP contract", () => { - let testToken; - it("create liquidity pair with synth token", async () => { - testToken = await TestToken.new("TestToken", "TEST", { - from: firstAddress, - }); - await uniswapV2Factory.createPair(token.address, testToken.address, { - from: firstAddress, - }); - const pair = await uniswapV2Factory.getPair( - token.address, - testToken.address - ); - uniswapV2Pair = await UniswapV2Pair.at(pair); - const [token0, token1] = - token.address < testToken.address - ? [token.address, testToken.address] - : [testToken.address, token.address]; - assert.equal( - token0, - await uniswapV2Pair.token0(), - "check first token address" - ); - assert.equal( - token1, - await uniswapV2Pair.token1(), - "check second token address" - ); - }); + describe("Integration with LP contract", () => { + let testToken + it("create liquidity pair with synth token", async () => { + testToken = await TestToken.new("TestToken", "TEST", { + from: firstAddress + }) + await uniswapV2Factory.createPair(token.address, testToken.address, { + from: firstAddress + }) + const pair = await uniswapV2Factory.getPair(token.address, testToken.address) + uniswapV2Pair = await UniswapV2Pair.at(pair) + const [token0, token1] = + token.address < testToken.address ? [token.address, testToken.address] : [testToken.address, token.address] + assert.equal(token0, await uniswapV2Pair.token0(), "check first token address") + assert.equal(token1, await uniswapV2Pair.token1(), "check second token address") + }) - it("add liquidity with synth token", async () => { - const amount = "15000000"; - await token.transfer(uniswapV2Pair.address, amount); - await testToken.transfer(uniswapV2Pair.address, amount); - await uniswapV2Pair.mint(firstAddress); - const reserve0 = (await uniswapV2Pair.getReserves())["0"]; - const reserve1 = (await uniswapV2Pair.getReserves())["1"]; - assert.equal(reserve0, amount, "check first token reserve"); - assert.equal(reserve1, amount, "check second token reserve"); - }); + it("add liquidity with synth token", async () => { + const amount = "15000000" + await token.transfer(uniswapV2Pair.address, amount) + await testToken.transfer(uniswapV2Pair.address, amount) + await uniswapV2Pair.mint(firstAddress) + const reserve0 = (await uniswapV2Pair.getReserves())["0"] + const reserve1 = (await uniswapV2Pair.getReserves())["1"] + assert.equal(reserve0, amount, "check first token reserve") + assert.equal(reserve1, amount, "check second token reserve") + }) - it("should transfer when in whitelist", async () => { - const whitelistAddress = accounts[5]; - let result = await whitelistContract.Check( - whitelistAddress, - whitelistId - ); - assert.equal(result, 0); - await whitelistContract.AddAddress( - whitelistId, - [whitelistAddress], - ["10000000"] - ); - result = await whitelistContract.Check(whitelistAddress, whitelistId); - assert.equal( - result.toString(), - "10000000", - "Check if address is whitelisted" - ); - const transferAmount = "1999980000000"; - const swapAmount = "1000"; - await token.transfer(uniswapV2Pair.address, transferAmount); - await testToken.transfer(uniswapV2Pair.address, transferAmount); - await uniswapV2Pair.swap( - swapAmount, - swapAmount, - whitelistAddress, - "0x", - { from: whitelistAddress } - ); - const balance = await token.balanceOf(whitelistAddress); - assert.equal(balance.toString(), swapAmount, "check whitelist balance"); - }); + it("should transfer when in whitelist", async () => { + const whitelistAddress = accounts[5] + let result = await whitelistContract.Check(whitelistAddress, whitelistId) + assert.equal(result, 0) + await whitelistContract.AddAddress(whitelistId, [whitelistAddress], ["10000000"]) + result = await whitelistContract.Check(whitelistAddress, whitelistId) + assert.equal(result.toString(), "10000000", "Check if address is whitelisted") + const transferAmount = "1999980000000" + const swapAmount = "1000" + await token.transfer(uniswapV2Pair.address, transferAmount) + await testToken.transfer(uniswapV2Pair.address, transferAmount) + await uniswapV2Pair.swap(swapAmount, swapAmount, whitelistAddress, "0x", { from: whitelistAddress }) + const balance = await token.balanceOf(whitelistAddress) + assert.equal(balance.toString(), swapAmount, "check whitelist balance") + }) - it("should revert when not in whitelist", async () => { - const notWhitelistAddress = accounts[6]; - const swapAmount = "1000"; - const result = await whitelistContract.Check( - notWhitelistAddress, - whitelistId - ); - assert.equal(result, 0, "Check if address is whitelisted"); - const transferAmount = "1999980000000"; - await uniswapV2Pair.sync(); - await token.transfer(uniswapV2Pair.address, transferAmount); - await truffleAssert.reverts( - uniswapV2Pair.swap( - swapAmount, - swapAmount, - notWhitelistAddress, - "0x", - { from: notWhitelistAddress } - ), - "UniswapV2: TRANSFER_FAILED" - ); - // check transfer if add notWhitelistAddress to whitelist - await whitelistContract.AddAddress( - whitelistId, - [notWhitelistAddress], - ["10000000"] - ); - await uniswapV2Pair.swap( - swapAmount, - swapAmount, - notWhitelistAddress, - "0x", - { from: notWhitelistAddress } - ); - const balance = await token.balanceOf(notWhitelistAddress); - assert.equal( - balance.toString(), - swapAmount, - "check notWhitelistAddress balance" - ); - }); + it("should revert when not in whitelist", async () => { + const notWhitelistAddress = accounts[6] + const swapAmount = "1000" + const result = await whitelistContract.Check(notWhitelistAddress, whitelistId) + assert.equal(result, 0, "Check if address is whitelisted") + const transferAmount = "1999980000000" + await uniswapV2Pair.sync() + await token.transfer(uniswapV2Pair.address, transferAmount) + await truffleAssert.reverts( + uniswapV2Pair.swap(swapAmount, swapAmount, notWhitelistAddress, "0x", { from: notWhitelistAddress }), + "UniswapV2: TRANSFER_FAILED" + ) + // check transfer if add notWhitelistAddress to whitelist + await whitelistContract.AddAddress(whitelistId, [notWhitelistAddress], ["10000000"]) + await uniswapV2Pair.swap(swapAmount, swapAmount, notWhitelistAddress, "0x", { from: notWhitelistAddress }) + const balance = await token.balanceOf(notWhitelistAddress) + assert.equal(balance.toString(), swapAmount, "check notWhitelistAddress balance") + }) - it("check when the finish time is over", async () => { - // create another synth token with past time configuration - const secondAddress = accounts[1]; - const thirdAddress = accounts[2]; - const amount = 1000; - const time = new Date(); - time.setDate(time.getDate() - 1); - const past = Math.floor(time.getTime() / 1000) + 60; - const testToken2 = await TestToken.new("TEST2", "TEST2", { - from: secondAddress, - }); - const newToken = await Token.new( - tokenName, - tokenSymbol, - cap.toString(), - decimals, - secondAddress, - lockedDealContract.address, - whitelistContract.address, - { from: secondAddress } - ); - await testToken2.approve( - newToken.address, - cap.multipliedBy(10 ** 18).toString(), - { from: secondAddress } - ); - await newToken.SetLockingDetails( - testToken2.address, - timestamps, - ratios, - past, - { from: secondAddress } - ); - // check transfer functionality - await newToken.transfer(thirdAddress, (amount * 2).toString(), { - from: secondAddress, - }); - let thirdBalance = await newToken.balanceOf(thirdAddress); - assert.equal( - thirdBalance.toString(), - (amount * 2).toString(), - "check third address balance" - ); - await newToken.transfer(secondAddress, amount.toString(), { - from: thirdAddress, - }); // no whitelist address - const newTokenID = await newToken.WhitelistId(); - await whitelistContract.AddAddress( - newTokenID, - [thirdAddress], - ["10000000"], - { from: secondAddress } - ); - await newToken.transfer(secondAddress, amount.toString(), { - from: thirdAddress, - }); // whitelist address - thirdBalance = await newToken.balanceOf(thirdAddress); - assert.equal( - "0", - thirdBalance.toString(), - "check third address balance" - ); - }); + it("check when the finish time is over", async () => { + // create another synth token with past time configuration + const secondAddress = accounts[1] + const thirdAddress = accounts[2] + const amount = 1000 + const time = new Date() + time.setDate(time.getDate() - 1) + const past = Math.floor(time.getTime() / 1000) + 60 + const testToken2 = await TestToken.new("TEST2", "TEST2", { + from: secondAddress + }) + const newToken = await Token.new( + tokenName, + tokenSymbol, + cap.toString(), + decimals, + secondAddress, + lockedDealContract.address, + whitelistContract.address, + { from: secondAddress } + ) + await testToken2.approve(newToken.address, cap.multipliedBy(10 ** 18).toString(), { from: secondAddress }) + await newToken.SetLockingDetails(testToken2.address, timestamps, ratios, past, { from: secondAddress }) + // check transfer functionality + await newToken.transfer(thirdAddress, (amount * 2).toString(), { + from: secondAddress + }) + let thirdBalance = await newToken.balanceOf(thirdAddress) + assert.equal(thirdBalance.toString(), (amount * 2).toString(), "check third address balance") + await newToken.transfer(secondAddress, amount.toString(), { + from: thirdAddress + }) // no whitelist address + const newTokenID = await newToken.WhitelistId() + await whitelistContract.AddAddress(newTokenID, [thirdAddress], ["10000000"], { from: secondAddress }) + await newToken.transfer(secondAddress, amount.toString(), { + from: thirdAddress + }) // whitelist address + thirdBalance = await newToken.balanceOf(thirdAddress) + assert.equal("0", thirdBalance.toString(), "check third address balance") + }) - after(async () => { - await uniswapV2Pair.sync(); - await uniswapV2Pair.skim(firstAddress); - }); - }); + after(async () => { + await uniswapV2Pair.sync() + await uniswapV2Pair.skim(firstAddress) + }) + }) - describe("Integration with Locked Deal and Whitelist Contract", () => { - const secondAddress = accounts[1], - thirdAddress = accounts[2], - fourthAddress = accounts[3], - fifthAddress = accounts[4]; - const amount = new BigNumber(10 ** 19); + describe("Integration with Locked Deal and Whitelist Contract", () => { + const secondAddress = accounts[1], + thirdAddress = accounts[2], + fourthAddress = accounts[3], + fifthAddress = accounts[4] + const amount = new BigNumber(10 ** 19) - const runSimulation = (amountToActivate, blockTime) => { - let totalAmount = new BigNumber(0), - creditableAmount = new BigNumber(0); - const unlockTimes = [], - unlockAmounts = []; - for (let i = 0; i < timestamps.length; i++) { - const amount = amountToActivate - .multipliedBy(ratios[i]) - .dividedToIntegerBy(ratios.length); - totalAmount = totalAmount.plus(amount); - if (timestamps[i] <= blockTime) { - creditableAmount = creditableAmount.plus(amount); - } else { - unlockTimes.push(timestamps[i]); - unlockAmounts.push(amount); - } + const runSimulation = (amountToActivate, blockTime) => { + let totalAmount = new BigNumber(0), + creditableAmount = new BigNumber(0) + const unlockTimes = [], + unlockAmounts = [] + for (let i = 0; i < timestamps.length; i++) { + const amount = amountToActivate.multipliedBy(ratios[i]).dividedToIntegerBy(ratios.length) + totalAmount = totalAmount.plus(amount) + if (timestamps[i] <= blockTime) { + creditableAmount = creditableAmount.plus(amount) + } else { + unlockTimes.push(timestamps[i]) + unlockAmounts.push(amount) } - if (totalAmount.isLessThan(amountToActivate)) { - const difference = amountToActivate.minus(totalAmount); - if (unlockAmounts.length) { - unlockAmounts[unlockAmounts.length - 1] = - unlockAmounts[unlockAmounts.length - 1].plus(difference); - } else { - creditableAmount = creditableAmount.plus(difference); - } - totalAmount = totalAmount.plus(difference); + } + if (totalAmount.isLessThan(amountToActivate)) { + const difference = amountToActivate.minus(totalAmount) + if (unlockAmounts.length) { + unlockAmounts[unlockAmounts.length - 1] = unlockAmounts[unlockAmounts.length - 1].plus(difference) + } else { + creditableAmount = creditableAmount.plus(difference) } - // console.log(totalAmount.toString()) - // console.log(creditableAmount.toString()) - // unlockTimes.forEach(item => { - // console.log(item.toString()) - // }) - // unlockAmounts.forEach(item => { - // console.log(item.toString()) - // }) - return { totalAmount, creditableAmount, unlockTimes, unlockAmounts }; - }; + totalAmount = totalAmount.plus(difference) + } + // console.log(totalAmount.toString()) + // console.log(creditableAmount.toString()) + // unlockTimes.forEach(item => { + // console.log(item.toString()) + // }) + // unlockAmounts.forEach(item => { + // console.log(item.toString()) + // }) + return { totalAmount, creditableAmount, unlockTimes, unlockAmounts } + } - const getLockedDealData = async (dealId, ownerAddress) => { - const data = await lockedDealContract.GetPoolData(dealId, { - from: ownerAddress, - }); - return { - unlockTime: data[0], - amount: data[1], - owner: data[2], - tokenAddress: data[3], - }; - }; + const getLockedDealData = async (dealId, ownerAddress) => { + const data = await lockedDealContract.GetPoolData(dealId, { + from: ownerAddress + }) + return { + unlockTime: data[0], + amount: data[1], + owner: data[2], + tokenAddress: data[3] + } + } - before(async () => { - // sending token to 4 addresses - await token.transfer(secondAddress, amount.toString(), { - from: firstAddress, - }); - await token.transfer(thirdAddress, amount.toString(), { - from: firstAddress, - }); - await token.transfer(fourthAddress, amount.toString(), { - from: firstAddress, - }); - await token.transfer(fifthAddress, amount.toString(), { - from: firstAddress, - }); - }); + before(async () => { + // sending token to 4 addresses + await token.transfer(secondAddress, amount.toString(), { + from: firstAddress + }) + await token.transfer(thirdAddress, amount.toString(), { + from: firstAddress + }) + await token.transfer(fourthAddress, amount.toString(), { + from: firstAddress + }) + await token.transfer(fifthAddress, amount.toString(), { + from: firstAddress + }) + }) - after(async () => { - const now = Date.now(); - await timeMachine.advanceBlockAndSetTime(Math.floor(now / 1000)); - }); + after(async () => { + const now = Date.now() + await timeMachine.advanceBlockAndSetTime(Math.floor(now / 1000)) + }) - it("should fail to transfer token before FinishTime to Non Whitelisted Address", async () => { - const tx = token.transfer(thirdAddress, amount.toString(), { - from: secondAddress, - }); - await truffleAssert.reverts(tx, "Sorry, no alocation for Subject"); - }); + it("should fail to transfer token before FinishTime to Non Whitelisted Address", async () => { + const tx = token.transfer(thirdAddress, amount.toString(), { + from: secondAddress + }) + await truffleAssert.reverts(tx, "Sorry, no alocation for Subject") + }) - it("should successfully transfer tokens to whitelisted address before FinishTime", async () => { - await whitelistContract.AddAddress( - whitelistId, - [secondAddress, thirdAddress], - [amount.toString(), amount.toString()] - ); - await token.transfer(thirdAddress, amount.toString(), { - from: secondAddress, - }); - const balance3 = await token.balanceOf(thirdAddress); - assert.equal(balance3.toString(), amount.multipliedBy(2).toString()); - await token.transfer(secondAddress, amount.toString(), { - from: thirdAddress, - }); - const balance2 = await token.balanceOf(secondAddress); - assert.equal(balance2.toString(), amount.toString()); - }); + it("should successfully transfer tokens to whitelisted address before FinishTime", async () => { + await whitelistContract.AddAddress( + whitelistId, + [secondAddress, thirdAddress], + [amount.toString(), amount.toString()] + ) + await token.transfer(thirdAddress, amount.toString(), { + from: secondAddress + }) + const balance3 = await token.balanceOf(thirdAddress) + assert.equal(balance3.toString(), amount.multipliedBy(2).toString()) + await token.transfer(secondAddress, amount.toString(), { + from: thirdAddress + }) + const balance2 = await token.balanceOf(secondAddress) + assert.equal(balance2.toString(), amount.toString()) + }) - it("simulation for no unlock", async () => { - // await timeMachine.advanceBlockAndSetTime(timestamps[1]) - const data = await token.getActivationResult(amount.toString()); - const time = new Date().getTime / 1000; - const now = Math.floor(time); - const sim = runSimulation(amount, now); - assert.equal(data[0].toString(), sim.totalAmount.toString()); - assert.equal(data[1].toString(), sim.creditableAmount.toString()); - data[2].forEach((item, index) => { - assert.equal(item.toString(), sim.unlockTimes[index].toString()); - }); - data[3].forEach((item, index) => { - assert.equal(item.toString(), sim.unlockAmounts[index].toString()); - }); - }); - it("simulation for first unlock", async () => { - await timeMachine.advanceBlockAndSetTime(timestamps[0]); - const data = await token.getActivationResult(amount.toString()); - const sim = runSimulation(amount, timestamps[0]); - assert.equal(data[0].toString(), sim.totalAmount.toString()); - assert.equal(data[1].toString(), sim.creditableAmount.toString()); - data[2].forEach((item, index) => { - if (item.toString() === "0") return; - assert.equal(item.toString(), sim.unlockTimes[index].toString()); - }); - data[3].forEach((item, index) => { - if (item.toString() === "0") return; - assert.equal(item.toString(), sim.unlockAmounts[index].toString()); - }); - }); - it("simulation for second unlock", async () => { - await timeMachine.advanceBlockAndSetTime(timestamps[1]); - const data = await token.getActivationResult(amount.toString()); - const sim = runSimulation(amount, timestamps[1]); - assert.equal(data[0].toString(), sim.totalAmount.toString()); - assert.equal(data[1].toString(), sim.creditableAmount.toString()); - data[2].forEach((item, index) => { - if (item.toString() === "0") return; - assert.equal(item.toString(), sim.unlockTimes[index].toString()); - }); - data[3].forEach((item, index) => { - if (item.toString() === "0") return; - assert.equal(item.toString(), sim.unlockAmounts[index].toString()); - }); - }); - it("simulation for third unlock", async () => { - await timeMachine.advanceBlockAndSetTime(timestamps[2]); - const data = await token.getActivationResult(amount.toString()); - const sim = runSimulation(amount, timestamps[2]); - assert.equal(data[0].toString(), sim.totalAmount.toString()); - assert.equal(data[1].toString(), sim.creditableAmount.toString()); - data[2].forEach((item, index) => { - if (item.toString() === "0") return; - assert.equal(item.toString(), sim.unlockTimes[index].toString()); - }); - data[3].forEach((item, index) => { - if (item.toString() === "0") return; - assert.equal(item.toString(), sim.unlockAmounts[index].toString()); - }); - const now = Date.now(); - await timeMachine.advanceBlockAndSetTime(Math.floor(now / 1000)); - }); + it("simulation for no unlock", async () => { + // await timeMachine.advanceBlockAndSetTime(timestamps[1]) + const data = await token.getActivationResult(amount.toString()) + const time = new Date().getTime / 1000 + const now = Math.floor(time) + const sim = runSimulation(amount, now) + assert.equal(data[0].toString(), sim.totalAmount.toString()) + assert.equal(data[1].toString(), sim.creditableAmount.toString()) + data[2].forEach((item, index) => { + assert.equal(item.toString(), sim.unlockTimes[index].toString()) + }) + data[3].forEach((item, index) => { + assert.equal(item.toString(), sim.unlockAmounts[index].toString()) + }) + }) + it("simulation for first unlock", async () => { + await timeMachine.advanceBlockAndSetTime(timestamps[0]) + const data = await token.getActivationResult(amount.toString()) + const sim = runSimulation(amount, timestamps[0]) + assert.equal(data[0].toString(), sim.totalAmount.toString()) + assert.equal(data[1].toString(), sim.creditableAmount.toString()) + data[2].forEach((item, index) => { + if (item.toString() === "0") return + assert.equal(item.toString(), sim.unlockTimes[index].toString()) + }) + data[3].forEach((item, index) => { + if (item.toString() === "0") return + assert.equal(item.toString(), sim.unlockAmounts[index].toString()) + }) + }) + it("simulation for second unlock", async () => { + await timeMachine.advanceBlockAndSetTime(timestamps[1]) + const data = await token.getActivationResult(amount.toString()) + const sim = runSimulation(amount, timestamps[1]) + assert.equal(data[0].toString(), sim.totalAmount.toString()) + assert.equal(data[1].toString(), sim.creditableAmount.toString()) + data[2].forEach((item, index) => { + if (item.toString() === "0") return + assert.equal(item.toString(), sim.unlockTimes[index].toString()) + }) + data[3].forEach((item, index) => { + if (item.toString() === "0") return + assert.equal(item.toString(), sim.unlockAmounts[index].toString()) + }) + }) + it("simulation for third unlock", async () => { + await timeMachine.advanceBlockAndSetTime(timestamps[2]) + const data = await token.getActivationResult(amount.toString()) + const sim = runSimulation(amount, timestamps[2]) + assert.equal(data[0].toString(), sim.totalAmount.toString()) + assert.equal(data[1].toString(), sim.creditableAmount.toString()) + data[2].forEach((item, index) => { + if (item.toString() === "0") return + assert.equal(item.toString(), sim.unlockTimes[index].toString()) + }) + data[3].forEach((item, index) => { + if (item.toString() === "0") return + assert.equal(item.toString(), sim.unlockAmounts[index].toString()) + }) + const now = Date.now() + await timeMachine.advanceBlockAndSetTime(Math.floor(now / 1000)) + }) - it("activating token before all unlocks", async () => { - const userSyntheticBalance = await token.balanceOf(secondAddress); - const time = new Date().getTime / 1000; - const now = Math.floor(time); - const sim = runSimulation( - new BigNumber(userSyntheticBalance.toString()), - now - ); - const tx = await token.ActivateSynthetic({ from: secondAddress }); - const deals = await lockedDealContract.GetMyPoolsId({ - from: secondAddress, - }); - const userOriginalBalance = await originalToken.balanceOf( - secondAddress - ); - assert.equal( - userOriginalBalance.toString(), - sim.creditableAmount.toString() - ); - assert.equal( - tx.logs[tx.logs.length - 1].args.Amount.toString(), - sim.totalAmount.toString() - ); - const promises = []; - deals.forEach(async (item) => { - promises.push(getLockedDealData(item.toString(), secondAddress)); - }); - const dealData = await Promise.all(promises); - assert.equal(dealData.length, sim.unlockTimes.length); - dealData.forEach((item, index) => { - assert.equal( - item.unlockTime.toString(), - sim.unlockTimes[index].toString() - ); - assert.equal( - item.amount.toString(), - sim.unlockAmounts[index].toString() - ); - assert.equal(item.owner, secondAddress); - assert.equal(item.tokenAddress, originalToken.address); - }); - }); + it("activating token before all unlocks", async () => { + const userSyntheticBalance = await token.balanceOf(secondAddress) + const time = new Date().getTime / 1000 + const now = Math.floor(time) + const sim = runSimulation(new BigNumber(userSyntheticBalance.toString()), now) + const tx = await token.ActivateSynthetic({ from: secondAddress }) + const deals = await lockedDealContract.GetMyPoolsId({ + from: secondAddress + }) + const userOriginalBalance = await originalToken.balanceOf(secondAddress) + assert.equal(userOriginalBalance.toString(), sim.creditableAmount.toString()) + assert.equal(tx.logs[tx.logs.length - 1].args.Amount.toString(), sim.totalAmount.toString()) + const promises = [] + deals.forEach(async (item) => { + promises.push(getLockedDealData(item.toString(), secondAddress)) + }) + const dealData = await Promise.all(promises) + assert.equal(dealData.length, sim.unlockTimes.length) + dealData.forEach((item, index) => { + assert.equal(item.unlockTime.toString(), sim.unlockTimes[index].toString()) + assert.equal(item.amount.toString(), sim.unlockAmounts[index].toString()) + assert.equal(item.owner, secondAddress) + assert.equal(item.tokenAddress, originalToken.address) + }) + }) - it("activating token after first unlock", async () => { - await timeMachine.advanceBlockAndSetTime(timestamps[0]); - const userSyntheticBalance = await token.balanceOf(thirdAddress); - const sim = runSimulation( - new BigNumber(userSyntheticBalance.toString()), - timestamps[0] - ); - const tx = await token.ActivateSynthetic({ from: thirdAddress }); - const deals = await lockedDealContract.GetMyPoolsId({ - from: thirdAddress, - }); - const userOriginalBalance = await originalToken.balanceOf(thirdAddress); - assert.equal( - userOriginalBalance.toString(), - sim.creditableAmount.toString() - ); - assert.equal( - tx.logs[tx.logs.length - 1].args.Amount.toString(), - sim.totalAmount.toString() - ); - const promises = []; - deals.forEach(async (item) => { - promises.push(getLockedDealData(item.toString(), thirdAddress)); - }); - const dealData = await Promise.all(promises); - assert.equal(dealData.length, sim.unlockTimes.length); - dealData.forEach((item, index) => { - assert.equal( - item.unlockTime.toString(), - sim.unlockTimes[index].toString() - ); - assert.equal( - item.amount.toString(), - sim.unlockAmounts[index].toString() - ); - assert.equal(item.owner, thirdAddress); - assert.equal(item.tokenAddress, originalToken.address); - }); - }); - it("activating token after second unlock", async () => { - await timeMachine.advanceBlockAndSetTime(timestamps[1]); - const userSyntheticBalance = await token.balanceOf(fourthAddress); - const sim = runSimulation( - new BigNumber(userSyntheticBalance.toString()), - timestamps[1] - ); - const tx = await token.ActivateSynthetic({ from: fourthAddress }); - const deals = await lockedDealContract.GetMyPoolsId({ - from: fourthAddress, - }); - const userOriginalBalance = await originalToken.balanceOf( - fourthAddress - ); - assert.equal( - userOriginalBalance.toString(), - sim.creditableAmount.toString() - ); - assert.equal( - tx.logs[tx.logs.length - 1].args.Amount.toString(), - sim.totalAmount.toString() - ); - const promises = []; - deals.forEach(async (item) => { - promises.push(getLockedDealData(item.toString(), fourthAddress)); - }); - const dealData = await Promise.all(promises); - assert.equal(dealData.length, sim.unlockTimes.length); - dealData.forEach((item, index) => { - assert.equal( - item.unlockTime.toString(), - sim.unlockTimes[index].toString() - ); - assert.equal( - item.amount.toString(), - sim.unlockAmounts[index].toString() - ); - assert.equal(item.owner, fourthAddress); - assert.equal(item.tokenAddress, originalToken.address); - }); - }); - it("activating token after third unlock", async () => { - await timeMachine.advanceBlockAndSetTime(timestamps[2]); - const userSyntheticBalance = await token.balanceOf(fifthAddress); - const sim = runSimulation( - new BigNumber(userSyntheticBalance.toString()), - timestamps[2] - ); - const tx = await token.ActivateSynthetic({ from: fifthAddress }); - const deals = await lockedDealContract.GetMyPoolsId({ - from: fifthAddress, - }); - const userOriginalBalance = await originalToken.balanceOf(fifthAddress); - assert.equal( - userOriginalBalance.toString(), - sim.creditableAmount.toString() - ); - assert.equal( - tx.logs[tx.logs.length - 1].args.Amount.toString(), - sim.totalAmount.toString() - ); - const promises = []; - deals.forEach(async (item) => { - promises.push(getLockedDealData(item.toString(), fifthAddress)); - }); - const dealData = await Promise.all(promises); - assert.equal(dealData.length, sim.unlockTimes.length); - dealData.forEach((item, index) => { - assert.equal( - item.unlockTime.toString(), - sim.unlockTimes[index].toString() - ); - assert.equal( - item.amount.toString(), - sim.unlockAmounts[index].toString() - ); - assert.equal(item.owner, fifthAddress); - assert.equal(item.tokenAddress, originalToken.address); - }); - }); - }); - } -); + it("activating token after first unlock", async () => { + await timeMachine.advanceBlockAndSetTime(timestamps[0]) + const userSyntheticBalance = await token.balanceOf(thirdAddress) + const sim = runSimulation(new BigNumber(userSyntheticBalance.toString()), timestamps[0]) + const tx = await token.ActivateSynthetic({ from: thirdAddress }) + const deals = await lockedDealContract.GetMyPoolsId({ + from: thirdAddress + }) + const userOriginalBalance = await originalToken.balanceOf(thirdAddress) + assert.equal(userOriginalBalance.toString(), sim.creditableAmount.toString()) + assert.equal(tx.logs[tx.logs.length - 1].args.Amount.toString(), sim.totalAmount.toString()) + const promises = [] + deals.forEach(async (item) => { + promises.push(getLockedDealData(item.toString(), thirdAddress)) + }) + const dealData = await Promise.all(promises) + assert.equal(dealData.length, sim.unlockTimes.length) + dealData.forEach((item, index) => { + assert.equal(item.unlockTime.toString(), sim.unlockTimes[index].toString()) + assert.equal(item.amount.toString(), sim.unlockAmounts[index].toString()) + assert.equal(item.owner, thirdAddress) + assert.equal(item.tokenAddress, originalToken.address) + }) + }) + it("activating token after second unlock", async () => { + await timeMachine.advanceBlockAndSetTime(timestamps[1]) + const userSyntheticBalance = await token.balanceOf(fourthAddress) + const sim = runSimulation(new BigNumber(userSyntheticBalance.toString()), timestamps[1]) + const tx = await token.ActivateSynthetic({ from: fourthAddress }) + const deals = await lockedDealContract.GetMyPoolsId({ + from: fourthAddress + }) + const userOriginalBalance = await originalToken.balanceOf(fourthAddress) + assert.equal(userOriginalBalance.toString(), sim.creditableAmount.toString()) + assert.equal(tx.logs[tx.logs.length - 1].args.Amount.toString(), sim.totalAmount.toString()) + const promises = [] + deals.forEach(async (item) => { + promises.push(getLockedDealData(item.toString(), fourthAddress)) + }) + const dealData = await Promise.all(promises) + assert.equal(dealData.length, sim.unlockTimes.length) + dealData.forEach((item, index) => { + assert.equal(item.unlockTime.toString(), sim.unlockTimes[index].toString()) + assert.equal(item.amount.toString(), sim.unlockAmounts[index].toString()) + assert.equal(item.owner, fourthAddress) + assert.equal(item.tokenAddress, originalToken.address) + }) + }) + it("activating token after third unlock", async () => { + await timeMachine.advanceBlockAndSetTime(timestamps[2]) + const userSyntheticBalance = await token.balanceOf(fifthAddress) + const sim = runSimulation(new BigNumber(userSyntheticBalance.toString()), timestamps[2]) + const tx = await token.ActivateSynthetic({ from: fifthAddress }) + const deals = await lockedDealContract.GetMyPoolsId({ + from: fifthAddress + }) + const userOriginalBalance = await originalToken.balanceOf(fifthAddress) + assert.equal(userOriginalBalance.toString(), sim.creditableAmount.toString()) + assert.equal(tx.logs[tx.logs.length - 1].args.Amount.toString(), sim.totalAmount.toString()) + const promises = [] + deals.forEach(async (item) => { + promises.push(getLockedDealData(item.toString(), fifthAddress)) + }) + const dealData = await Promise.all(promises) + assert.equal(dealData.length, sim.unlockTimes.length) + dealData.forEach((item, index) => { + assert.equal(item.unlockTime.toString(), sim.unlockTimes[index].toString()) + assert.equal(item.amount.toString(), sim.unlockAmounts[index].toString()) + assert.equal(item.owner, fifthAddress) + assert.equal(item.tokenAddress, originalToken.address) + }) + }) + }) +}) diff --git a/test/13_WhiteListConvertor.js b/test/13_WhiteListConvertor.js index 69a6fd1..d0530c1 100644 --- a/test/13_WhiteListConvertor.js +++ b/test/13_WhiteListConvertor.js @@ -1,49 +1,48 @@ -const ThePoolz = artifacts.require("ThePoolz"); -const Token = artifacts.require("Token"); -const WhiteList = artifacts.require("WhiteList"); -const WhiteListConvertor = artifacts.require("WhiteListConvertor"); -const { assert } = require("chai"); -const truffleAssert = require("truffle-assertions"); -const constants = require("@openzeppelin/test-helpers/src/constants"); -const BN = web3.utils.BN; +const ThePoolz = artifacts.require("ThePoolz") +const Token = artifacts.require("Token") +const WhiteList = artifacts.require("WhiteList") +const WhiteListConvertor = artifacts.require("WhiteListConvertor") +const { assert } = require("chai") +const truffleAssert = require("truffle-assertions") +const constants = require("@openzeppelin/test-helpers/src/constants") +const BN = web3.utils.BN contract("Integration Between PoolzBack and WhiteListConvertor", (accounts) => { let poolzBack, testToken, whiteList, - firstAddress = accounts[0]; + firstAddress = accounts[0] let whiteListConvertor, - secondAddress = accounts[1]; - let whiteListId, ethPoolId; + secondAddress = accounts[1] + let whiteListId, ethPoolId before(async () => { - poolzBack = await ThePoolz.deployed(); - whiteList = await WhiteList.deployed(); - whiteListConvertor = await WhiteListConvertor.new(whiteList.address); - testToken = await Token.new("TestToken", "TEST", { from: firstAddress }); - }); + poolzBack = await ThePoolz.deployed() + whiteList = await WhiteList.deployed() + whiteListConvertor = await WhiteListConvertor.new(whiteList.address) + testToken = await Token.new("TestToken", "TEST", { from: firstAddress }) + }) it("should create white list", async () => { - const now = Date.now() / 1000; // current timestamp in seconds - const timestamp = Number(now.toFixed()) + 3600; // timestamp one hour from now - const whiteListCost = web3.utils.toWei("0.01", "ether"); - await whiteList.CreateManualWhiteList( - timestamp, - whiteListConvertor.address, - { from: firstAddress, value: whiteListCost } - ); - whiteListId = ((await whiteList.WhiteListCount()) - 1).toString(); - assert.equal(whiteListId, "1"); - }); + const now = Date.now() / 1000 // current timestamp in seconds + const timestamp = Number(now.toFixed()) + 3600 // timestamp one hour from now + const whiteListCost = web3.utils.toWei("0.01", "ether") + await whiteList.CreateManualWhiteList(timestamp, whiteListConvertor.address, { + from: firstAddress, + value: whiteListCost + }) + whiteListId = ((await whiteList.WhiteListCount()) - 1).toString() + assert.equal(whiteListId, "1") + }) it("should create new pool with ETH as Main Coin", async () => { - const date = new Date(); - date.setDate(date.getDate() + 1); // add a day - const future = Math.floor(date.getTime() / 1000) + 60; - const pozRate = new web3.utils.BN("1000000000"); - const publicRate = new web3.utils.BN("500000000"); - const amount = new BN("100000000"); - await testToken.approve(poolzBack.address, amount, { from: firstAddress }); + const date = new Date() + date.setDate(date.getDate() + 1) // add a day + const future = Math.floor(date.getTime() / 1000) + 60 + const pozRate = new web3.utils.BN("1000000000") + const publicRate = new web3.utils.BN("500000000") + const amount = new BN("100000000") + await testToken.approve(poolzBack.address, amount, { from: firstAddress }) const tx = await poolzBack.CreatePool( testToken.address, future, @@ -56,291 +55,248 @@ contract("Integration Between PoolzBack and WhiteListConvertor", (accounts) => { 0, whiteListId, { from: firstAddress } - ); - ethPoolId = tx.logs[1].args[1].toString(); - const result = await poolzBack.GetPoolExtraData(ethPoolId); - assert.equal(whiteListId, result[1].toString()); - }); + ) + ethPoolId = tx.logs[1].args[1].toString() + const result = await poolzBack.GetPoolExtraData(ethPoolId) + assert.equal(whiteListId, result[1].toString()) + }) it("should add Main Coin Address to Whitelist", async () => { - const addressArray = [testToken.address]; - const amount = "100000000"; - const allowanceArray = [amount]; // random allowance + const addressArray = [testToken.address] + const amount = "100000000" + const allowanceArray = [amount] // random allowance await whiteList.AddAddress(whiteListId, addressArray, allowanceArray, { - from: firstAddress, - }); - const result = await whiteList.Check(testToken.address, whiteListId); - assert.equal(result, amount); - await poolzBack.SetWhiteList_Address(whiteListConvertor.address); - await poolzBack.setMCWhitelistId(whiteListId); - await poolzBack.SwapTokenFilter(); - const data = await poolzBack.IsTokenFilterOn(); - assert.equal(true, data); - }); + from: firstAddress + }) + const result = await whiteList.Check(testToken.address, whiteListId) + assert.equal(result, amount) + await poolzBack.SetWhiteList_Address(whiteListConvertor.address) + await poolzBack.setMCWhitelistId(whiteListId) + await poolzBack.SwapTokenFilter() + const data = await poolzBack.IsTokenFilterOn() + assert.equal(true, data) + }) it("add user to WhiteList", async () => { - const addressArray = [secondAddress]; - const allowanceArray = [web3.utils.toWei("100")]; // 100 ETH - await whiteList.AddAddress(whiteListId, addressArray, allowanceArray); - const result = await whiteList.Check(secondAddress, whiteListId); - assert.equal( - result.toString(), - web3.utils.toWei("100"), - "check value in original white list" - ); - }); + const addressArray = [secondAddress] + const allowanceArray = [web3.utils.toWei("100")] // 100 ETH + await whiteList.AddAddress(whiteListId, addressArray, allowanceArray) + const result = await whiteList.Check(secondAddress, whiteListId) + assert.equal(result.toString(), web3.utils.toWei("100"), "check value in original white list") + }) it("should revert with new price", async () => { - const divide = false; - const price = "10"; - const tx = await whiteListConvertor.SetPrice( - whiteListId, - price, - divide, - poolzBack.address - ); - const currentPrice = tx.logs[0].args.Price.toString(); - const currentOperation = tx.logs[0].args.Operation.toString(); - const currentId = tx.logs[0].args.Id.toString(); - assert.equal(currentId, whiteListId); - assert.equal(currentPrice, price); - assert.equal(currentOperation, divide.toString()); - const result = await whiteListConvertor.Check(secondAddress, whiteListId); - assert.equal( - result.toString(), - web3.utils.toWei("10"), - "check value in convertor white list" - ); + const divide = false + const price = "10" + const tx = await whiteListConvertor.SetPrice(whiteListId, price, divide, poolzBack.address) + const currentPrice = tx.logs[0].args.Price.toString() + const currentOperation = tx.logs[0].args.Operation.toString() + const currentId = tx.logs[0].args.Id.toString() + assert.equal(currentId, whiteListId) + assert.equal(currentPrice, price) + assert.equal(currentOperation, divide.toString()) + const result = await whiteListConvertor.Check(secondAddress, whiteListId) + assert.equal(result.toString(), web3.utils.toWei("10"), "check value in convertor white list") await truffleAssert.reverts( poolzBack.InvestETH(ethPoolId, { from: secondAddress, - value: web3.utils.toWei("50"), + value: web3.utils.toWei("50") }), "Sorry, no alocation for Subject" - ); - }); + ) + }) it("should invest", async () => { await poolzBack.InvestETH(ethPoolId, { from: secondAddress, - value: web3.utils.toWei("5"), - }); - const convertorResult = await whiteListConvertor.Check( - secondAddress, - whiteListId - ); // convertor WhiteList - assert.equal( - convertorResult.toString(), - web3.utils.toWei("5"), - "check value in convertor whitelist" - ); - const originalResult = await whiteList.Check(secondAddress, whiteListId); // original WhiteList - assert.equal( - originalResult.toString(), - web3.utils.toWei("50"), - "check value in original whitelist" - ); - }); + value: web3.utils.toWei("5") + }) + const convertorResult = await whiteListConvertor.Check(secondAddress, whiteListId) // convertor WhiteList + assert.equal(convertorResult.toString(), web3.utils.toWei("5"), "check value in convertor whitelist") + const originalResult = await whiteList.Check(secondAddress, whiteListId) // original WhiteList + assert.equal(originalResult.toString(), web3.utils.toWei("50"), "check value in original whitelist") + }) it("should last round register", async () => { - const contractAddress = accounts[9]; - const now = Date.now() / 1000; // current timestamp in seconds - const timestamp = Number(now.toFixed()) + 3600; // timestamp one hour from now - await whiteList.CreateManualWhiteList( - timestamp, - whiteListConvertor.address, - { from: contractAddress } - ); - const id = ((await whiteList.WhiteListCount()) - 1).toString(); - await whiteListConvertor.SetPrice(id, "10", false, contractAddress); + const contractAddress = accounts[9] + const now = Date.now() / 1000 // current timestamp in seconds + const timestamp = Number(now.toFixed()) + 3600 // timestamp one hour from now + await whiteList.CreateManualWhiteList(timestamp, whiteListConvertor.address, { from: contractAddress }) + const id = ((await whiteList.WhiteListCount()) - 1).toString() + await whiteListConvertor.SetPrice(id, "10", false, contractAddress) await whiteListConvertor.LastRoundRegister(secondAddress, id, { - from: contractAddress, - }); + from: contractAddress + }) - const userLimit = await whiteListConvertor.Check(secondAddress, id); - const MAX_INT = constants.MAX_UINT256 / 10; - assert.equal(userLimit.toString(), MAX_INT); - }); + const userLimit = await whiteListConvertor.Check(secondAddress, id) + const MAX_INT = constants.MAX_UINT256 / 10 + assert.equal(userLimit.toString(), MAX_INT) + }) it("should return nothing, because id is 0", async () => { - await whiteList.LastRoundRegister(secondAddress, 0, { from: accounts[9] }); - await whiteList.Register(secondAddress, 0, 1000, { from: accounts[9] }); - }); + await whiteList.LastRoundRegister(secondAddress, 0, { from: accounts[9] }) + await whiteList.Register(secondAddress, 0, 1000, { from: accounts[9] }) + }) describe("should invoke only by creator", async () => { - let now, timestamp, whiteListCost; + let now, timestamp, whiteListCost before(async () => { - now = Date.now() / 1000; // current timestamp in seconds - timestamp = Number(now.toFixed()) + 3600; // timestamp one hour from now - whiteListCost = web3.utils.toWei("0.01", "ether"); - await whiteList.CreateManualWhiteList( - timestamp, - whiteListConvertor.address, - { from: secondAddress, value: whiteListCost } - ); - whiteListId = ((await whiteList.WhiteListCount()) - 1).toString(); - }); + now = Date.now() / 1000 // current timestamp in seconds + timestamp = Number(now.toFixed()) + 3600 // timestamp one hour from now + whiteListCost = web3.utils.toWei("0.01", "ether") + await whiteList.CreateManualWhiteList(timestamp, whiteListConvertor.address, { + from: secondAddress, + value: whiteListCost + }) + whiteListId = ((await whiteList.WhiteListCount()) - 1).toString() + }) it("Only creator can change creator", async () => { - await truffleAssert.reverts( - whiteList.ChangeCreator(whiteListId, secondAddress), - "Only creator can access" - ); - }); + await truffleAssert.reverts(whiteList.ChangeCreator(whiteListId, secondAddress), "Only creator can access") + }) it("Only creator can change contract", async () => { - await truffleAssert.reverts( - whiteList.ChangeContract(whiteListId, secondAddress), - "Only creator can access" - ); - }); + await truffleAssert.reverts(whiteList.ChangeContract(whiteListId, secondAddress), "Only creator can access") + }) it("Only creator can add address", async () => { - const addressArray = [testToken.address]; - const amount = "100000000"; - const allowanceArray = [amount]; // random allowance + const addressArray = [testToken.address] + const amount = "100000000" + const allowanceArray = [amount] // random allowance await truffleAssert.reverts( whiteList.AddAddress(whiteListId, addressArray, allowanceArray, { - from: firstAddress, + from: firstAddress }), "Only creator can access" - ); - }); + ) + }) it("Only creator can remove address", async () => { - const addressArray = [testToken.address]; + const addressArray = [testToken.address] await truffleAssert.reverts( whiteList.RemoveAddress(whiteListId, addressArray, { - from: firstAddress, + from: firstAddress }), "Only creator can access" - ); - }); + ) + }) it("should set max users limit", async () => { - const previousLimit = await whiteList.MaxUsersLimit(); - await whiteList.setMaxUsersLimit(100); - const newLimit = await whiteList.MaxUsersLimit(); - assert.equal(100, newLimit); - assert.notEqual(previousLimit, newLimit); - }); + const previousLimit = await whiteList.MaxUsersLimit() + await whiteList.setMaxUsersLimit(100) + const newLimit = await whiteList.MaxUsersLimit() + assert.equal(100, newLimit) + assert.notEqual(previousLimit, newLimit) + }) it("should set whitelist cost", async () => { - const previousCost = await whiteList.WhiteListCost(); - await whiteList.setWhiteListCost(1); - const newCost = await whiteList.WhiteListCost(); - assert.equal(1, newCost); - assert.notEqual(previousCost, newCost); - }); + const previousCost = await whiteList.WhiteListCost() + await whiteList.setWhiteListCost(1) + const newCost = await whiteList.WhiteListCost() + assert.equal(1, newCost) + assert.notEqual(previousCost, newCost) + }) it("should change a contract", async () => { - const previousContract = await whiteList.WhitelistSettings(whiteListId); + const previousContract = await whiteList.WhitelistSettings(whiteListId) await whiteList.ChangeContract(whiteListId, secondAddress, { - from: secondAddress, - }); - const newContract = await whiteList.WhitelistSettings(whiteListId); - assert.notEqual(previousContract.Contract, newContract.Contract); - assert.equal(newContract.Contract, secondAddress); - }); + from: secondAddress + }) + const newContract = await whiteList.WhitelistSettings(whiteListId) + assert.notEqual(previousContract.Contract, newContract.Contract) + assert.equal(newContract.Contract, secondAddress) + }) it("should remove a contract", async () => { await whiteList.AddAddress(whiteListId, [firstAddress], ["100000000"], { - from: secondAddress, - }); - const res1 = await whiteList.WhitelistDB(whiteListId, firstAddress); + from: secondAddress + }) + const res1 = await whiteList.WhitelistDB(whiteListId, firstAddress) await whiteList.RemoveAddress(whiteListId, [firstAddress], { - from: secondAddress, - }); - const res = await whiteList.WhitelistDB(whiteListId, firstAddress); - assert.notEqual(res1.toString(), res.toString()); - assert.equal(0, res.toString()); - }); + from: secondAddress + }) + const res = await whiteList.WhitelistDB(whiteListId, firstAddress) + assert.notEqual(res1.toString(), res.toString()) + assert.equal(0, res.toString()) + }) it("should change a creator", async () => { - const previousContract = await whiteList.WhitelistSettings(whiteListId); + const previousContract = await whiteList.WhitelistSettings(whiteListId) await whiteList.ChangeCreator(whiteListId, accounts[5], { - from: secondAddress, - }); - const newContract = await whiteList.WhitelistSettings(whiteListId); - assert.notEqual(previousContract.Creator, newContract.Creator); - assert.equal(newContract.Creator, accounts[5]); - }); + from: secondAddress + }) + const newContract = await whiteList.WhitelistSettings(whiteListId) + assert.notEqual(previousContract.Creator, newContract.Creator) + assert.equal(newContract.Creator, accounts[5]) + }) it("should withdraw eth fee", async () => { - const tx = await whiteList.WithdrawETHFee(firstAddress); - }); + const tx = await whiteList.WithdrawETHFee(firstAddress) + }) it("should return true so whitelist is ready", async () => { - const res = await whiteList.isWhiteListReady(whiteListId); - assert.equal(true, res); - }); + const res = await whiteList.isWhiteListReady(whiteListId) + assert.equal(true, res) + }) - it('should set white list address', async () => { - const previousAddress = await whiteListConvertor.WhiteListAddress(); + it("should set white list address", async () => { + const previousAddress = await whiteListConvertor.WhiteListAddress() await whiteListConvertor.SetWhiteListAddress(accounts[2]) - const newAddress = await whiteListConvertor.WhiteListAddress(); + const newAddress = await whiteListConvertor.WhiteListAddress() assert.notEqual(previousAddress, newAddress) assert.equal(newAddress, accounts[2]) }) - }); + }) describe("should fail", async () => { it("should fail because only contract can call this", async () => { await truffleAssert.reverts( whiteList.LastRoundRegister(secondAddress, 1, { from: accounts[9] }), "Only the Contract can call this" - ); + ) await truffleAssert.reverts( whiteList.Register(secondAddress, 1, 1000, { from: accounts[9] }), "Only the Contract can call this" - ); - }); + ) + }) it("should fail with incorrect number of users", async () => { await truffleAssert.reverts( - whiteList.AddAddress( - whiteListId, - [firstAddress], - ["100000000", "100"], - { from: accounts[5] } - ), + whiteList.AddAddress(whiteListId, [firstAddress], ["100000000", "100"], { from: accounts[5] }), "Number of users should be same as the amount length" - ); - }); + ) + }) it("should fail with need in something", async () => { - await truffleAssert.reverts( - whiteList.AddAddress(whiteListId, [], [], { from: accounts[5] }), - "Need something..." - ); - }); + await truffleAssert.reverts(whiteList.AddAddress(whiteListId, [], [], { from: accounts[5] }), "Need something...") + }) it("should fail with ether not enough", async () => { - const now = Date.now() / 1000; // current timestamp in seconds - const timestamp = Number(now.toFixed()) + 3600; // timestamp one hour from now + const now = Date.now() / 1000 // current timestamp in seconds + const timestamp = Number(now.toFixed()) + 3600 // timestamp one hour from now await truffleAssert.reverts( whiteList.CreateManualWhiteList(timestamp, whiteListConvertor.address, { from: secondAddress, - value: 0, + value: 0 }), "ether not enough" - ); - }); + ) + }) it("should return nothing in check", async () => { - await whiteList.Check(accounts[5], 0); - }); + await whiteList.Check(accounts[5], 0) + }) it("should fail with only creator can access", async () => { await truffleAssert.reverts( whiteList.ChangeCreator(whiteListId, accounts[5], { - from: accounts[7], + from: accounts[7] }), "Only creator can access" - ); - }); - }); -}); + ) + }) + }) +}) diff --git a/test/14_FlexStaking.js b/test/14_FlexStaking.js index 6c650a5..de0447e 100644 --- a/test/14_FlexStaking.js +++ b/test/14_FlexStaking.js @@ -1,17 +1,21 @@ -const FlexStakingUser = artifacts.require("FlexStakingUser"); -const LockedDeal = artifacts.require("LockedDealV2"); -const Token = artifacts.require("ERC20Token"); -const { assert } = require("chai"); -const timeMachine = require("ganache-time-traveler"); -const BigNumber = require("bignumber.js"); -const truffleAssert = require("truffle-assertions"); +const FlexStakingUser = artifacts.require("FlexStakingUser") +const LockedDeal = artifacts.require("LockedDealV2") +const Token = artifacts.require("ERC20Token") +const { assert } = require("chai") +const timeMachine = require("ganache-time-traveler") +const BigNumber = require("bignumber.js") +const truffleAssert = require("truffle-assertions") contract("Flex Staking with LockedDealV2 integration", (accounts) => { - const projectOwner = accounts[0], amount = '1000000000000', APR = '50' // Annual Percentage Rate - const minAmount = '10000000', maxAmount = '1000000000', user = accounts[5] + const projectOwner = accounts[0], + amount = "1000000000000", + APR = "50" // Annual Percentage Rate + const minAmount = "10000000", + maxAmount = "1000000000", + user = accounts[5] const oneMonth = 60 * 60 * 24 * 30 // seconds const twoMonths = 60 * 60 * 24 * 60 - const halfYear = '15768000' + const halfYear = "15768000" const date = new Date() const startTime = Math.floor(date.getTime() / 1000) + 60 let finishTime, poolId, lockId, rwdId, poolId2 @@ -22,121 +26,104 @@ contract("Flex Staking with LockedDealV2 integration", (accounts) => { rwdToken = await Token.new("REWARD", "REWARD") lockToken = await Token.new("LOCK", "LOCK") lockedDeal = await LockedDeal.new() - date.setDate(date.getDate() + 365) // add a year + date.setDate(date.getDate() + 365) // add a year finishTime = Math.floor(date.getTime() / 1000) + 60 await flexStaking.SetLockedDealAddress(lockedDeal.address) }) - it('should create new pool', async () => { + it("should create new pool", async () => { await timeMachine.advanceBlockAndSetTime(Date.now()) await rwdToken.approve(flexStaking.address, amount, { from: projectOwner }) - const tx = await flexStaking.CreateStakingPool(lockToken.address, rwdToken.address, amount, startTime, finishTime, APR, oneMonth, halfYear, minAmount, maxAmount, '0') + const tx = await flexStaking.CreateStakingPool( + lockToken.address, + rwdToken.address, + amount, + startTime, + finishTime, + APR, + oneMonth, + halfYear, + minAmount, + maxAmount, + "0" + ) const pool = tx.logs[tx.logs.length - 1].args - assert.equal(projectOwner, pool.Owner, 'invalid owner') - assert.equal('1', pool.Id, 'invalid pool id') - assert.equal(lockToken.address, pool.LockedToken, 'invalid lock token') - assert.equal(rwdToken.address, pool.RewardToken, 'invalid reward token') - assert.equal(amount, pool.TokensAmount, 'invalid tokens amount') - assert.equal(startTime, pool.StartTime, 'invalid start time') - assert.equal(finishTime, pool.FinishTime, 'invalid finish time') - assert.equal(APR, pool.APR, 'invalid APR') - assert.equal(oneMonth, pool.MinDuration, 'invalid min duration') - assert.equal(halfYear, pool.MaxDuration, 'invalid max duration') - assert.equal(minAmount, pool.MinAmount, 'invalid min amount') - assert.equal(maxAmount, pool.MaxAmount, 'invalid max amount') - assert.equal('0', pool.EarlyWithdraw, 'invalid min early withdraw') + assert.equal(projectOwner, pool.Owner, "invalid owner") + assert.equal("1", pool.Id, "invalid pool id") + assert.equal(lockToken.address, pool.LockedToken, "invalid lock token") + assert.equal(rwdToken.address, pool.RewardToken, "invalid reward token") + assert.equal(amount, pool.TokensAmount, "invalid tokens amount") + assert.equal(startTime, pool.StartTime, "invalid start time") + assert.equal(finishTime, pool.FinishTime, "invalid finish time") + assert.equal(APR, pool.APR, "invalid APR") + assert.equal(oneMonth, pool.MinDuration, "invalid min duration") + assert.equal(halfYear, pool.MaxDuration, "invalid max duration") + assert.equal(minAmount, pool.MinAmount, "invalid min amount") + assert.equal(maxAmount, pool.MaxAmount, "invalid max amount") + assert.equal("0", pool.EarlyWithdraw, "invalid min early withdraw") poolId = pool.Id }) - it('should stake', async () => { + it("should stake", async () => { await timeMachine.advanceBlockAndSetTime(startTime) const amount = minAmount const duration = halfYear await lockToken.transfer(user, amount) await lockToken.approve(flexStaking.address, amount, { from: user }) await flexStaking.Stake(poolId, amount, duration, { from: user }) - rwdId = '0' - lockId = '1' + rwdId = "0" + lockId = "1" }) it("should return reward tokens", async () => { - await timeMachine.advanceBlockAndSetTime(finishTime); - const reward = (minAmount * APR * halfYear) / 365 / 24 / 60 / 60 / 100; - const oldBal = new BigNumber(await rwdToken.balanceOf(user)); - const tx = await lockedDeal.WithdrawToken(rwdId, { from: user }); - const actualRwd = tx.logs[tx.logs.length - 1].args.Amount; - const actualBal = new BigNumber(await rwdToken.balanceOf(user)); - assert.equal( - parseInt(reward).toString(), - actualRwd.toString(), - "invalid reward amount" - ); - assert.equal( - BigNumber.sum(oldBal, reward).toString(), - actualBal.toString(), - "invalid balance" - ); - }); + await timeMachine.advanceBlockAndSetTime(finishTime) + const reward = (minAmount * APR * halfYear) / 365 / 24 / 60 / 60 / 100 + const oldBal = new BigNumber(await rwdToken.balanceOf(user)) + const tx = await lockedDeal.WithdrawToken(rwdId, { from: user }) + const actualRwd = tx.logs[tx.logs.length - 1].args.Amount + const actualBal = new BigNumber(await rwdToken.balanceOf(user)) + assert.equal(parseInt(reward).toString(), actualRwd.toString(), "invalid reward amount") + assert.equal(BigNumber.sum(oldBal, reward).toString(), actualBal.toString(), "invalid balance") + }) it("should return locked tokens", async () => { - await timeMachine.advanceBlockAndSetTime(finishTime); - const locked = minAmount; - const oldBal = new BigNumber(await lockToken.balanceOf(user)); - const tx = await lockedDeal.WithdrawToken(lockId, { from: user }); - const result = tx.logs[tx.logs.length - 1].args.Amount; - const actualBal = new BigNumber(await lockToken.balanceOf(user)); - assert.equal( - parseInt(locked).toString(), - result.toString(), - "invalid locked amount" - ); - assert.equal( - BigNumber.sum(oldBal, result).toString(), - actualBal.toString(), - "invalid balance" - ); - }); + await timeMachine.advanceBlockAndSetTime(finishTime) + const locked = minAmount + const oldBal = new BigNumber(await lockToken.balanceOf(user)) + const tx = await lockedDeal.WithdrawToken(lockId, { from: user }) + const result = tx.logs[tx.logs.length - 1].args.Amount + const actualBal = new BigNumber(await lockToken.balanceOf(user)) + assert.equal(parseInt(locked).toString(), result.toString(), "invalid locked amount") + assert.equal(BigNumber.sum(oldBal, result).toString(), actualBal.toString(), "invalid balance") + }) it("should mass stake", async () => { - const users = [accounts[1], accounts[2], accounts[3], accounts[4]]; - const amounts = [minAmount, minAmount, maxAmount, maxAmount / 10]; - const durations = [oneMonth, twoMonths, halfYear, halfYear]; - for ( - let i = 0, rwdId = 2, lockId = 3; - i < users.length; - i++, rwdId += 2, lockId += 2 - ) { - const reward = - (amounts[i] * APR * durations[i]) / 365 / 24 / 60 / 60 / 100; - await lockToken.transfer(users[i], amounts[i]); + const users = [accounts[1], accounts[2], accounts[3], accounts[4]] + const amounts = [minAmount, minAmount, maxAmount, maxAmount / 10] + const durations = [oneMonth, twoMonths, halfYear, halfYear] + for (let i = 0, rwdId = 2, lockId = 3; i < users.length; i++, rwdId += 2, lockId += 2) { + const reward = (amounts[i] * APR * durations[i]) / 365 / 24 / 60 / 60 / 100 + await lockToken.transfer(users[i], amounts[i]) await lockToken.approve(flexStaking.address, amounts[i], { - from: users[i], - }); - await timeMachine.advanceBlockAndSetTime(startTime); + from: users[i] + }) + await timeMachine.advanceBlockAndSetTime(startTime) await flexStaking.Stake(poolId, amounts[i], durations[i], { - from: users[i], - }); - await timeMachine.advanceBlockAndSetTime(finishTime); - const rwdTx = await lockedDeal.WithdrawToken(rwdId, { from: user }); - const lockTx = await lockedDeal.WithdrawToken(lockId, { from: user }); - const actualRwd = rwdTx.logs[rwdTx.logs.length - 1].args.Amount; - const actualLock = lockTx.logs[lockTx.logs.length - 1].args.Amount; - assert.equal( - parseInt(reward).toString(), - actualRwd.toString(), - "invalid reward amount" - ); - assert.equal( - parseInt(amounts[i]).toString(), - actualLock.toString(), - "invalid locked amount" - ); + from: users[i] + }) + await timeMachine.advanceBlockAndSetTime(finishTime) + const rwdTx = await lockedDeal.WithdrawToken(rwdId, { from: user }) + const lockTx = await lockedDeal.WithdrawToken(lockId, { from: user }) + const actualRwd = rwdTx.logs[rwdTx.logs.length - 1].args.Amount + const actualLock = lockTx.logs[lockTx.logs.length - 1].args.Amount + assert.equal(parseInt(reward).toString(), actualRwd.toString(), "invalid reward amount") + assert.equal(parseInt(amounts[i]).toString(), actualLock.toString(), "invalid locked amount") } - }); + }) it("should revert when pause", async () => { - await rwdToken.approve(flexStaking.address, amount, { from: projectOwner }); - await flexStaking.Pause(); + await rwdToken.approve(flexStaking.address, amount, { from: projectOwner }) + await flexStaking.Pause() await truffleAssert.reverts( flexStaking.CreateStakingPool( lockToken.address, @@ -152,58 +139,59 @@ contract("Flex Staking with LockedDealV2 integration", (accounts) => { "0" ), "Pausable: paused" - ); - await timeMachine.advanceBlockAndSetTime(startTime); - await lockToken.transfer(user, amount); - await lockToken.approve(flexStaking.address, amount, { from: user }); - await truffleAssert.reverts( - flexStaking.Stake(poolId, minAmount, halfYear, { from: user }), - "Pausable: paused" - ); - await flexStaking.Unpause(); - }); + ) + await timeMachine.advanceBlockAndSetTime(startTime) + await lockToken.transfer(user, amount) + await lockToken.approve(flexStaking.address, amount, { from: user }) + await truffleAssert.reverts(flexStaking.Stake(poolId, minAmount, halfYear, { from: user }), "Pausable: paused") + await flexStaking.Unpause() + }) it("should withdraw tokens", async () => { - date.setDate(date.getDate() + 1); - finishTime = Math.floor(date.getTime() / 1000) + 60; - await timeMachine.advanceBlockAndSetTime(finishTime); - const rewardReserve = new BigNumber( - await rwdToken.balanceOf(flexStaking.address) - ); - const ownerBal = new BigNumber(await rwdToken.balanceOf(projectOwner)); - await flexStaking.WithdrawLeftOver(poolId, { from: projectOwner }); - const actualBal = new BigNumber(await rwdToken.balanceOf(projectOwner)); - const actualReserv = new BigNumber( - await rwdToken.balanceOf(flexStaking.address) - ); - assert.equal(actualReserv, "0", "invalid reserve amount"); - assert.equal( - actualBal.toString(), - BigNumber.sum(rewardReserve, ownerBal).toString(), - "invalid owner balance" - ); - }); + date.setDate(date.getDate() + 1) + finishTime = Math.floor(date.getTime() / 1000) + 60 + await timeMachine.advanceBlockAndSetTime(finishTime) + const rewardReserve = new BigNumber(await rwdToken.balanceOf(flexStaking.address)) + const ownerBal = new BigNumber(await rwdToken.balanceOf(projectOwner)) + await flexStaking.WithdrawLeftOver(poolId, { from: projectOwner }) + const actualBal = new BigNumber(await rwdToken.balanceOf(projectOwner)) + const actualReserv = new BigNumber(await rwdToken.balanceOf(flexStaking.address)) + assert.equal(actualReserv, "0", "invalid reserve amount") + assert.equal(actualBal.toString(), BigNumber.sum(rewardReserve, ownerBal).toString(), "invalid owner balance") + }) it("should stake with different tokens", async () => { const date = new Date() const startTime = Math.floor(date.getTime() / 1000) + 60 - date.setDate(date.getDate() + 365) // add a year + date.setDate(date.getDate() + 365) // add a year const finishTime = Math.floor(date.getTime() / 1000) + 60 - await timeMachine.advanceBlockAndSetTime(Date.now()); + await timeMachine.advanceBlockAndSetTime(Date.now()) await lockToken.approve(flexStaking.address, 10000000, { from: projectOwner }) - const tx = await flexStaking.CreateStakingPool(lockToken.address, lockToken.address, 10000000, startTime, finishTime, APR, oneMonth, halfYear, minAmount, maxAmount, '0') + const tx = await flexStaking.CreateStakingPool( + lockToken.address, + lockToken.address, + 10000000, + startTime, + finishTime, + APR, + oneMonth, + halfYear, + minAmount, + maxAmount, + "0" + ) const pool = tx.logs[tx.logs.length - 1].args poolId2 = pool.Id - await timeMachine.advanceBlockAndSetTime(startTime); - const amount = minAmount; - const duration = halfYear; - await lockToken.transfer(user, amount); - await lockToken.approve(flexStaking.address, amount, { from: user }); - await flexStaking.Stake(poolId2, amount, duration, { from: user }); - }); + await timeMachine.advanceBlockAndSetTime(startTime) + const amount = minAmount + const duration = halfYear + await lockToken.transfer(user, amount) + await lockToken.approve(flexStaking.address, amount, { from: user }) + await flexStaking.Stake(poolId2, amount, duration, { from: user }) + }) after(async () => { - await timeMachine.advanceBlockAndSetTime(Math.floor(Date.now() / 1000)); - }); -}); + await timeMachine.advanceBlockAndSetTime(Math.floor(Date.now() / 1000)) + }) +}) diff --git a/test/15_LockedDealV2.js b/test/15_LockedDealV2.js index 3e9f9ea..00e1ba5 100644 --- a/test/15_LockedDealV2.js +++ b/test/15_LockedDealV2.js @@ -1,123 +1,143 @@ const LockedDealV2 = artifacts.require("LockedDealV2") const TestToken = artifacts.require("ERC20Token") const WhiteList = artifacts.require("WhiteList") -const { assert } = require('chai') -const truffleAssert = require('truffle-assertions') +const { assert } = require("chai") +const truffleAssert = require("truffle-assertions") -const { createNewWhiteList } = require('./helper') +const { createNewWhiteList } = require("./helper") -contract("LockedDealV2 with WhiteList integration", accounts => { - let instance, Token - let whiteList - const amount = '100000', fromAddress = accounts[0], owner = accounts[9], allow = 100 +contract("LockedDealV2 with WhiteList integration", (accounts) => { + let instance, Token + let whiteList + const amount = "100000", + fromAddress = accounts[0], + owner = accounts[9], + allow = 100 - before(async () => { - instance = await LockedDealV2.new() - Token = await TestToken.new('TestToken', 'TEST') - whiteList = await WhiteList.new() - await instance.setWhiteListAddress(whiteList.address) - let tx = await createNewWhiteList(whiteList, instance.address, fromAddress) - let Id = tx.logs[0].args._WhiteListCount.toNumber() - await instance.setTokenFeeWhiteListId(Id) - tx = await createNewWhiteList(whiteList, instance.address, fromAddress) - Id = tx.logs[0].args._WhiteListCount.toNumber() - await instance.setUserWhiteListId(Id) - }) + before(async () => { + instance = await LockedDealV2.new() + Token = await TestToken.new("TestToken", "TEST") + whiteList = await WhiteList.new() + await instance.setWhiteListAddress(whiteList.address) + let tx = await createNewWhiteList(whiteList, instance.address, fromAddress) + let Id = tx.logs[0].args._WhiteListCount.toNumber() + await instance.setTokenFeeWhiteListId(Id) + tx = await createNewWhiteList(whiteList, instance.address, fromAddress) + Id = tx.logs[0].args._WhiteListCount.toNumber() + await instance.setUserWhiteListId(Id) + }) - it('should pay fee', async () => { - await instance.SetFeeAmount(amount) - await Token.transfer(owner, allow) - await Token.approve(instance.address, allow, { from: owner }) - const date = new Date() - date.setDate(date.getDate() + 1) - const startTime = Math.floor(date.getTime() / 1000) - const finishTime = startTime + 60 * 60 * 24 * 30 - await truffleAssert.reverts(instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { from: owner, value: '99999' }), "Not Enough Fee Provided") - await instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { from: owner, value: amount }) - const contractBal = await web3.eth.getBalance(instance.address) - assert.equal(contractBal, amount, 'invalid contract balance') - await instance.WithdrawFee(fromAddress) - }) + it("should pay fee", async () => { + await instance.SetFeeAmount(amount) + await Token.transfer(owner, allow) + await Token.approve(instance.address, allow, { from: owner }) + const date = new Date() + date.setDate(date.getDate() + 1) + const startTime = Math.floor(date.getTime() / 1000) + const finishTime = startTime + 60 * 60 * 24 * 30 + await truffleAssert.reverts( + instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { from: owner, value: "99999" }), + "Not Enough Fee Provided" + ) + await instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { from: owner, value: amount }) + const contractBal = await web3.eth.getBalance(instance.address) + assert.equal(contractBal, amount, "invalid contract balance") + await instance.WithdrawFee(fromAddress) + }) - it('should pay fee when create mass pools', async () => { - const numberOfPools = 5 - await Token.approve(instance.address, allow * numberOfPools, { from: fromAddress }) - let date = new Date() - date.setDate(date.getDate() + 1) - let future = Math.floor(date.getTime() / 1000) - const startTimeStamps = [] - startTimeStamps.push(future) - startTimeStamps.push(future - 3600) - startTimeStamps.push(future + 3600) - startTimeStamps.push(future + 7200) - startTimeStamps.push(future - 7200) - future = future + 60 * 60 * 24 * 30 - const finishTimeStamps = [] - finishTimeStamps.push(future) - finishTimeStamps.push(future - 3600) - finishTimeStamps.push(future + 3600) - finishTimeStamps.push(future + 7200) - finishTimeStamps.push(future - 7200) - const startAmounts = [allow, allow, allow, allow, allow] - const owners = [accounts[9], accounts[8], accounts[7], accounts[6], accounts[5]] - await instance.CreateMassPools(Token.address, startTimeStamps, finishTimeStamps, startAmounts, owners, { from: fromAddress, value: amount * numberOfPools }) - const contractBal = await web3.eth.getBalance(instance.address) - assert.equal(contractBal, amount * numberOfPools, 'invalid contract balance') - await instance.WithdrawFee(fromAddress) + it("should pay fee when create mass pools", async () => { + const numberOfPools = 5 + await Token.approve(instance.address, allow * numberOfPools, { from: fromAddress }) + let date = new Date() + date.setDate(date.getDate() + 1) + let future = Math.floor(date.getTime() / 1000) + const startTimeStamps = [] + startTimeStamps.push(future) + startTimeStamps.push(future - 3600) + startTimeStamps.push(future + 3600) + startTimeStamps.push(future + 7200) + startTimeStamps.push(future - 7200) + future = future + 60 * 60 * 24 * 30 + const finishTimeStamps = [] + finishTimeStamps.push(future) + finishTimeStamps.push(future - 3600) + finishTimeStamps.push(future + 3600) + finishTimeStamps.push(future + 7200) + finishTimeStamps.push(future - 7200) + const startAmounts = [allow, allow, allow, allow, allow] + const owners = [accounts[9], accounts[8], accounts[7], accounts[6], accounts[5]] + await instance.CreateMassPools(Token.address, startTimeStamps, finishTimeStamps, startAmounts, owners, { + from: fromAddress, + value: amount * numberOfPools }) + const contractBal = await web3.eth.getBalance(instance.address) + assert.equal(contractBal, amount * numberOfPools, "invalid contract balance") + await instance.WithdrawFee(fromAddress) + }) - it('should pay fee when create pool wrt time', async () => { - const allow = 100 - const numberOfOwners = 3 - const numberOfTimestamps = 6 - await Token.approve(instance.address, allow * numberOfOwners * numberOfTimestamps, { from: fromAddress }) - let date = new Date() - date.setDate(date.getDate() + 1) - let future = Math.floor(date.getTime() / 1000) - const startTimeStamps = [] - for (let i = 1; i <= numberOfTimestamps; i++) { // generating array of length 5 - startTimeStamps.push(future + 3600 * i) - } - future = future + 60 * 60 * 24 * 30 - const finishTimeStamps = [] - for (let i = 1; i <= numberOfTimestamps; i++) { // generating array of length 5 - finishTimeStamps.push(future + 3600 * i) - } - const startAmounts = [allow, allow, allow] - const owners = [accounts[9], accounts[8], accounts[7]] - await instance.CreatePoolsWrtTime(Token.address, startTimeStamps, finishTimeStamps, startAmounts, owners, { from: fromAddress, value: amount * numberOfOwners * numberOfTimestamps }) - const contractBal = await web3.eth.getBalance(instance.address) - assert.equal(contractBal, amount * numberOfOwners * numberOfTimestamps, 'invalid contract balance') - await instance.WithdrawFee(fromAddress) + it("should pay fee when create pool wrt time", async () => { + const allow = 100 + const numberOfOwners = 3 + const numberOfTimestamps = 6 + await Token.approve(instance.address, allow * numberOfOwners * numberOfTimestamps, { from: fromAddress }) + let date = new Date() + date.setDate(date.getDate() + 1) + let future = Math.floor(date.getTime() / 1000) + const startTimeStamps = [] + for (let i = 1; i <= numberOfTimestamps; i++) { + // generating array of length 5 + startTimeStamps.push(future + 3600 * i) + } + future = future + 60 * 60 * 24 * 30 + const finishTimeStamps = [] + for (let i = 1; i <= numberOfTimestamps; i++) { + // generating array of length 5 + finishTimeStamps.push(future + 3600 * i) + } + const startAmounts = [allow, allow, allow] + const owners = [accounts[9], accounts[8], accounts[7]] + await instance.CreatePoolsWrtTime(Token.address, startTimeStamps, finishTimeStamps, startAmounts, owners, { + from: fromAddress, + value: amount * numberOfOwners * numberOfTimestamps }) + const contractBal = await web3.eth.getBalance(instance.address) + assert.equal(contractBal, amount * numberOfOwners * numberOfTimestamps, "invalid contract balance") + await instance.WithdrawFee(fromAddress) + }) - describe('enable white list filter', () => { - it('should revert wrong tokens', async () => { - await instance.swapTokenFilter() - let tx = await createNewWhiteList(whiteList, instance.address, fromAddress) - let Id = tx.logs[0].args._WhiteListCount.toNumber() - await instance.setTokenFilterWhiteListId(Id) - await Token.transfer(owner, allow) - await Token.approve(instance.address, allow, { from: owner }) - const date = new Date() - date.setDate(date.getDate() + 1) - const startTime = Math.floor(date.getTime() / 1000) - const finishTime = startTime + 60 * 60 * 24 * 30 - await truffleAssert.reverts(instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { from: owner, value: amount }), "Need Valid ERC20 Token") - }) + describe("enable white list filter", () => { + it("should revert wrong tokens", async () => { + await instance.swapTokenFilter() + let tx = await createNewWhiteList(whiteList, instance.address, fromAddress) + let Id = tx.logs[0].args._WhiteListCount.toNumber() + await instance.setTokenFilterWhiteListId(Id) + await Token.transfer(owner, allow) + await Token.approve(instance.address, allow, { from: owner }) + const date = new Date() + date.setDate(date.getDate() + 1) + const startTime = Math.floor(date.getTime() / 1000) + const finishTime = startTime + 60 * 60 * 24 * 30 + await truffleAssert.reverts( + instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { from: owner, value: amount }), + "Need Valid ERC20 Token" + ) + }) - it('should accept right token', async () => { - await Token.transfer(owner, allow) - await Token.approve(instance.address, allow, { from: owner }) - const date = new Date() - date.setDate(date.getDate() + 1) - const startTime = Math.floor(date.getTime() / 1000) - const finishTime = startTime + 60 * 60 * 24 * 30 - const address = [Token.address] - const allowance = [1] - const whiteListId = await instance.TokenFilterWhiteListId() - await whiteList.AddAddress(whiteListId, address, allowance) - await instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { from: owner, value: amount }) - }) + it("should accept right token", async () => { + await Token.transfer(owner, allow) + await Token.approve(instance.address, allow, { from: owner }) + const date = new Date() + date.setDate(date.getDate() + 1) + const startTime = Math.floor(date.getTime() / 1000) + const finishTime = startTime + 60 * 60 * 24 * 30 + const address = [Token.address] + const allowance = [1] + const whiteListId = await instance.TokenFilterWhiteListId() + await whiteList.AddAddress(whiteListId, address, allowance) + await instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { + from: owner, + value: amount + }) }) -}) \ No newline at end of file + }) +}) diff --git a/test/helper/index.js b/test/helper/index.js index 05d60b8..4d7b339 100644 --- a/test/helper/index.js +++ b/test/helper/index.js @@ -1,18 +1,21 @@ const createNewWhiteList = async (whiteList, contractAddress, fromAddress) => { - const now = Date.now() / 1000 // current timestamp in seconds - const timestamp = Number(now.toFixed()) + 3600 // timestamp one hour from now - let whiteListCost = web3.utils.toWei('0.01', 'ether') - const result = await whiteList.CreateManualWhiteList(timestamp, contractAddress, { from: fromAddress, value: whiteListCost }) - const logs = result.logs[0].args - assert.equal(logs._creator, fromAddress) - assert.equal(logs._contract, contractAddress) - assert.equal(logs._changeUntil, timestamp) - return result + const now = Date.now() / 1000 // current timestamp in seconds + const timestamp = Number(now.toFixed()) + 3600 // timestamp one hour from now + let whiteListCost = web3.utils.toWei("0.01", "ether") + const result = await whiteList.CreateManualWhiteList(timestamp, contractAddress, { + from: fromAddress, + value: whiteListCost + }) + const logs = result.logs[0].args + assert.equal(logs._creator, fromAddress) + assert.equal(logs._contract, contractAddress) + assert.equal(logs._changeUntil, timestamp) + return result } -const uintMinusOne = '115792089237316195423570985008687907853269984665640564039457584007913129639935' +const uintMinusOne = "115792089237316195423570985008687907853269984665640564039457584007913129639935" module.exports = { - createNewWhiteList, - uintMinusOne -} \ No newline at end of file + createNewWhiteList, + uintMinusOne +} From 99aaae065460fb5e1f4e076a8957223927832a84 Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Tue, 2 Aug 2022 13:49:27 +0300 Subject: [PATCH 2/6] added .prettierignore --- .prettierignore | 10 ++++++++++ .prettierrc | 2 +- .travis.yml | 2 +- codecov.yml | 4 ++-- migrations/10_UniswapV2Factory.js | 4 ++-- migrations/11_FlexStaking.js | 2 +- migrations/12_LockedDealV2.js | 6 +++--- migrations/1_WhitelistConvertor.js | 2 +- migrations/3_WhiteList.js | 6 +++--- migrations/4_LockedDeal.js | 6 +++--- migrations/5_Benefit.js | 2 +- migrations/6_Test_Token.js | 2 +- migrations/7_TestMainToken.js | 2 +- migrations/8_HodlersWhitelist.js | 2 +- migrations/9_UniswapV2Pair.js | 2 +- truffle-config.js | 26 +++++++++++++------------- 16 files changed, 45 insertions(+), 35 deletions(-) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..149cc6e --- /dev/null +++ b/.prettierignore @@ -0,0 +1,10 @@ +build +coverage +README.md +coverage.json +package-lock.json +.vscode-test/ +out/ +dist/ +test-fixtures/ +node_modules/ \ No newline at end of file diff --git a/.prettierrc b/.prettierrc index 4e9e06c..791036c 100644 --- a/.prettierrc +++ b/.prettierrc @@ -3,7 +3,7 @@ { "files": "*.sol", "options": { - "tadWidth": 2, + "tadWidth": 4, "printWidth": 80, "singleQuote": false } diff --git a/.travis.yml b/.travis.yml index 9d9fda3..d8391d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,4 +10,4 @@ install: npm i && npm i -g truffle script: - bash ./bin/build.sh - truffle run coverage --network development -after_script: bash <(curl -s https://codecov.io/bash) \ No newline at end of file +after_script: bash <(curl -s https://codecov.io/bash) diff --git a/codecov.yml b/codecov.yml index 5352954..aa5d55d 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,3 +1,3 @@ ignore: - - "contracts/Uniswap-V2-Core" - - "contracts/Benefit" + - "contracts/Uniswap-V2-Core" + - "contracts/Benefit" diff --git a/migrations/10_UniswapV2Factory.js b/migrations/10_UniswapV2Factory.js index b74ec5c..f29e717 100644 --- a/migrations/10_UniswapV2Factory.js +++ b/migrations/10_UniswapV2Factory.js @@ -2,5 +2,5 @@ const UniswapV2Factory = artifacts.require("UniswapV2Factory") const constants = require("@openzeppelin/test-helpers/src/constants") module.exports = function (deployer) { - deployer.deploy(UniswapV2Factory, constants.ZERO_ADDRESS) -} \ No newline at end of file + deployer.deploy(UniswapV2Factory, constants.ZERO_ADDRESS) +} diff --git a/migrations/11_FlexStaking.js b/migrations/11_FlexStaking.js index 09f1c04..b57cce2 100644 --- a/migrations/11_FlexStaking.js +++ b/migrations/11_FlexStaking.js @@ -2,4 +2,4 @@ const FlexStakingUser = artifacts.require("FlexStakingUser.sol") module.exports = function (deployer) { deployer.deploy(FlexStakingUser) -} \ No newline at end of file +} diff --git a/migrations/12_LockedDealV2.js b/migrations/12_LockedDealV2.js index 6b61816..ec52b0a 100644 --- a/migrations/12_LockedDealV2.js +++ b/migrations/12_LockedDealV2.js @@ -1,5 +1,5 @@ -const LockedDealV2 = artifacts.require("LockedDealV2"); +const LockedDealV2 = artifacts.require("LockedDealV2") module.exports = function (deployer) { - deployer.deploy(LockedDealV2); -}; \ No newline at end of file + deployer.deploy(LockedDealV2) +} diff --git a/migrations/1_WhitelistConvertor.js b/migrations/1_WhitelistConvertor.js index c439895..ebb9f37 100644 --- a/migrations/1_WhitelistConvertor.js +++ b/migrations/1_WhitelistConvertor.js @@ -3,4 +3,4 @@ const constants = require("@openzeppelin/test-helpers/src/constants") module.exports = function (deployer) { deployer.deploy(WhiteListConvertor, constants.ZERO_ADDRESS) -} \ No newline at end of file +} diff --git a/migrations/3_WhiteList.js b/migrations/3_WhiteList.js index d923b41..073d79b 100644 --- a/migrations/3_WhiteList.js +++ b/migrations/3_WhiteList.js @@ -1,5 +1,5 @@ -const WhiteList = artifacts.require("WhiteList"); +const WhiteList = artifacts.require("WhiteList") module.exports = function (deployer) { - deployer.deploy(WhiteList); -}; \ No newline at end of file + deployer.deploy(WhiteList) +} diff --git a/migrations/4_LockedDeal.js b/migrations/4_LockedDeal.js index f066dda..229f82b 100644 --- a/migrations/4_LockedDeal.js +++ b/migrations/4_LockedDeal.js @@ -1,5 +1,5 @@ -const LockedDeal = artifacts.require("LockedDeal"); +const LockedDeal = artifacts.require("LockedDeal") module.exports = function (deployer) { - deployer.deploy(LockedDeal); -}; \ No newline at end of file + deployer.deploy(LockedDeal) +} diff --git a/migrations/5_Benefit.js b/migrations/5_Benefit.js index 1e3a692..0695c24 100644 --- a/migrations/5_Benefit.js +++ b/migrations/5_Benefit.js @@ -2,4 +2,4 @@ const Benefit = artifacts.require("Benefit") module.exports = function (deployer) { deployer.deploy(Benefit) -}; \ No newline at end of file +} diff --git a/migrations/6_Test_Token.js b/migrations/6_Test_Token.js index bf0198d..65b5381 100644 --- a/migrations/6_Test_Token.js +++ b/migrations/6_Test_Token.js @@ -2,7 +2,7 @@ const TestToken = artifacts.require("Token") module.exports = function (deployer) { // if(deployer.network_id === 5777){ - deployer.deploy(TestToken, 'TestToken', 'TEST') + deployer.deploy(TestToken, "TestToken", "TEST") // } // return; } diff --git a/migrations/7_TestMainToken.js b/migrations/7_TestMainToken.js index 2322704..cf78b59 100644 --- a/migrations/7_TestMainToken.js +++ b/migrations/7_TestMainToken.js @@ -2,7 +2,7 @@ const TestMainToken = artifacts.require("Token") module.exports = function (deployer) { // if(deployer.network_id === 5777){ - deployer.deploy(TestMainToken, 'TestMainToken', 'TESTM') + deployer.deploy(TestMainToken, "TestMainToken", "TESTM") // } // return; } diff --git a/migrations/8_HodlersWhitelist.js b/migrations/8_HodlersWhitelist.js index 1f824e0..ee589dc 100644 --- a/migrations/8_HodlersWhitelist.js +++ b/migrations/8_HodlersWhitelist.js @@ -2,4 +2,4 @@ const HodlersWhitelist = artifacts.require("HodlersWhitelist") module.exports = function (deployer) { deployer.deploy(HodlersWhitelist) -} \ No newline at end of file +} diff --git a/migrations/9_UniswapV2Pair.js b/migrations/9_UniswapV2Pair.js index 2d0b14c..26b0513 100644 --- a/migrations/9_UniswapV2Pair.js +++ b/migrations/9_UniswapV2Pair.js @@ -2,4 +2,4 @@ const UniswapV2Pair = artifacts.require("UniswapV2Pair") module.exports = function (deployer) { deployer.deploy(UniswapV2Pair) -} \ No newline at end of file +} diff --git a/truffle-config.js b/truffle-config.js index 2d04143..8f66f8e 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -17,8 +17,8 @@ * phrase from a file you've .gitignored so it doesn't accidentally become public. * */ - require("ts-node").register({ - files: true, +require("ts-node").register({ + files: true }) // const HDWalletProvider = require('@truffle/hdwallet-provider'); // const infuraKey = "fj4jll3k....."; @@ -44,12 +44,12 @@ module.exports = { // options below to some value. // development: { - host: "127.0.0.1", // Localhost (default: none) - port: 8545, // Standard Ethereum port (default: none) - network_id: "*", // Any network (default: none) - gas: 6721975, - disableConfirmationListener: true - }, + host: "127.0.0.1", // Localhost (default: none) + port: 8545, // Standard Ethereum port (default: none) + network_id: "*", // Any network (default: none) + gas: 6721975, + disableConfirmationListener: true + } // Another network with more advanced options... // advanced: { // port: 8777, // Custom port @@ -79,7 +79,7 @@ module.exports = { plugins: ["solidity-coverage", "truffle-plugin-verify"], // Set default mocha options here, use special reporters etc. mocha: { - timeout: 100000 + timeout: 100000 }, // Configure your compilers @@ -87,11 +87,11 @@ module.exports = { solc: { settings: { evmVersion: "istanbul", - optimizer: { enabled: true, runs: 200, details: { yul: true } }, - }, + optimizer: { enabled: true, runs: 200, details: { yul: true } } + }, version: "pragma", docker: false, - parser: "solcjs", + parser: "solcjs" } } -}; +} From 02e9cf457de6a5f91225970db4857db8d947a0e8 Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Tue, 2 Aug 2022 13:50:38 +0300 Subject: [PATCH 3/6] fix tabs --- .prettierrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.prettierrc b/.prettierrc index 791036c..4e9e06c 100644 --- a/.prettierrc +++ b/.prettierrc @@ -3,7 +3,7 @@ { "files": "*.sol", "options": { - "tadWidth": 4, + "tadWidth": 2, "printWidth": 80, "singleQuote": false } From ecd34537c3a9f82daeb92224b0f29e0c737b5b7a Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Tue, 2 Aug 2022 14:31:46 +0300 Subject: [PATCH 4/6] typo fix --- .prettierrc | 3 ++- contracts/FlexStaking/ERC20Token.sol | 2 +- test/10_Benefit.js | 4 +++- test/15_LockedDealV2.js | 5 ++++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.prettierrc b/.prettierrc index 4e9e06c..b980b55 100644 --- a/.prettierrc +++ b/.prettierrc @@ -3,7 +3,7 @@ { "files": "*.sol", "options": { - "tadWidth": 2, + "tabWidth": 4, "printWidth": 80, "singleQuote": false } @@ -13,6 +13,7 @@ "options": { "printWidth": 120, "useTabs": false, + "tabWidth": 2, "semi": false, "singleQuote": false, "trailingComma": "none", diff --git a/contracts/FlexStaking/ERC20Token.sol b/contracts/FlexStaking/ERC20Token.sol index c919adf..fd4a556 100644 --- a/contracts/FlexStaking/ERC20Token.sol +++ b/contracts/FlexStaking/ERC20Token.sol @@ -1,4 +1,4 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "poolz-helper-v2/contracts/token/ERC20Token.sol"; \ No newline at end of file +import "poolz-helper-v2/contracts/token/ERC20Token.sol"; \ No newline at end of file diff --git a/test/10_Benefit.js b/test/10_Benefit.js index 9a99888..fd1a086 100644 --- a/test/10_Benefit.js +++ b/test/10_Benefit.js @@ -96,7 +96,9 @@ contract("Integration between PoolzBack, Uniswap and Benefit", (accounts) => { }) it("Create liquidity pair", async () => { - const result = await uniswapV2Factory.createPair(pozToken.address, testToken.address, { from: firstAddress }) + const result = await uniswapV2Factory.createPair(pozToken.address, testToken.address, { + from: firstAddress + }) const pair = await uniswapV2Factory.getPair(pozToken.address, testToken.address) uniswapV2Pair = await UniswapV2Pair.at(pair) const [token0, token1] = [ diff --git a/test/15_LockedDealV2.js b/test/15_LockedDealV2.js index 00e1ba5..2534d51 100644 --- a/test/15_LockedDealV2.js +++ b/test/15_LockedDealV2.js @@ -118,7 +118,10 @@ contract("LockedDealV2 with WhiteList integration", (accounts) => { const startTime = Math.floor(date.getTime() / 1000) const finishTime = startTime + 60 * 60 * 24 * 30 await truffleAssert.reverts( - instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { from: owner, value: amount }), + instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { + from: owner, + value: amount + }), "Need Valid ERC20 Token" ) }) From 14fafdba2049547c9b554637441825a2990adf80 Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Fri, 5 Aug 2022 15:50:52 +0300 Subject: [PATCH 5/6] added prettier script --- .prettierrc | 7 +- contracts/Benefit/Token.sol | 2 +- contracts/EnvelopToken/Token.sol | 129 +++++++++++++++++--------- contracts/FlexStaking/ERC20Token.sol | 2 +- contracts/LockedDeal/Token.sol | 2 +- contracts/LockedDealV2/ERC20Token.sol | 2 +- package.json | 5 + test/14_FlexStaking.js | 9 -- 8 files changed, 99 insertions(+), 59 deletions(-) diff --git a/.prettierrc b/.prettierrc index b980b55..d892cd4 100644 --- a/.prettierrc +++ b/.prettierrc @@ -3,9 +3,12 @@ { "files": "*.sol", "options": { - "tabWidth": 4, "printWidth": 80, - "singleQuote": false + "tabWidth": 4, + "useTabs": false, + "singleQuote": false, + "bracketSpacing": false, + "explicitTypes": "always" } }, { diff --git a/contracts/Benefit/Token.sol b/contracts/Benefit/Token.sol index d488769..e0c2104 100644 --- a/contracts/Benefit/Token.sol +++ b/contracts/Benefit/Token.sol @@ -1,4 +1,4 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; -import "poolz-helper/contracts/Token.sol"; \ No newline at end of file +import "poolz-helper/contracts/Token.sol"; diff --git a/contracts/EnvelopToken/Token.sol b/contracts/EnvelopToken/Token.sol index 779da75..9aa0541 100644 --- a/contracts/EnvelopToken/Token.sol +++ b/contracts/EnvelopToken/Token.sol @@ -16,37 +16,41 @@ contract POOLZSYNT is ERC20, ERC20Capped, ERC20Burnable, Manageable { constructor( string memory _name, string memory _symbol, - uint _cap, + uint256 _cap, uint8 _decimals, address _owner, address _lockedDealAddress, address _whitelistAddress - ) - public - ERC20(_name, _symbol) - ERC20Capped(_cap * 10**uint(_decimals)) - { + ) public ERC20(_name, _symbol) ERC20Capped(_cap * 10**uint256(_decimals)) { require(_decimals <= 18, "Decimal more than 18"); _setupDecimals(_decimals); _mint(_owner, cap()); _SetLockedDealAddress(_lockedDealAddress); - if(_whitelistAddress != address(0)){ - uint256 whitelistId = IWhiteList(_whitelistAddress).CreateManualWhiteList(uint256(-1), address(this)); - IWhiteList(_whitelistAddress).ChangeCreator(whitelistId, _msgSender()); + if (_whitelistAddress != address(0)) { + uint256 whitelistId = IWhiteList(_whitelistAddress) + .CreateManualWhiteList(uint256(-1), address(this)); + IWhiteList(_whitelistAddress).ChangeCreator( + whitelistId, + _msgSender() + ); _SetupWhitelist(_whitelistAddress, whitelistId); } else { _SetupWhitelist(_whitelistAddress, 0); } } - function _beforeTokenTransfer(address from, address to, uint256 amount) - internal virtual override(ERC20Capped, ERC20) - { - require(FinishTime <= now - || _msgSender() == owner() - || to == address(0) - || registerWhitelist(to, amount), - "Invalid Transfer Time or To Address"); + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) internal virtual override(ERC20Capped, ERC20) { + require( + FinishTime <= now || + _msgSender() == owner() || + to == address(0) || + registerWhitelist(to, amount), + "Invalid Transfer Time or To Address" + ); super._beforeTokenTransfer(from, to, amount); // Call parent hook } @@ -55,47 +59,81 @@ contract POOLZSYNT is ERC20, ERC20Capped, ERC20Burnable, Manageable { uint64[] calldata _unlockTimes, uint8[] calldata _ratios, uint256 _finishTime - ) external onlyOwnerOrGov { - _SetLockingDetails(_tokenAddress, cap(), _unlockTimes, _ratios, _finishTime); + ) external onlyOwnerOrGov { + _SetLockingDetails( + _tokenAddress, + cap(), + _unlockTimes, + _ratios, + _finishTime + ); } function ActivateSynthetic() external { ActivateSynthetic(balanceOf(_msgSender())); } - function ActivateSynthetic(uint _amountToActivate) public tokenReady(true) { - (uint amountToBurn, uint CreditableAmount, uint64[] memory unlockTimes, uint256[] memory unlockAmounts) = getActivationResult(_amountToActivate); + function ActivateSynthetic(uint256 _amountToActivate) + public + tokenReady(true) + { + ( + uint256 amountToBurn, + uint256 CreditableAmount, + uint64[] memory unlockTimes, + uint256[] memory unlockAmounts + ) = getActivationResult(_amountToActivate); TransferToken(OriginalTokenAddress, _msgSender(), CreditableAmount); - if(SafeMath.sub(amountToBurn, CreditableAmount) > 0){ - require(LockedDealAddress != address(0), "Error: LockedDeal Contract Address Missing"); - ApproveAllowanceERC20(OriginalTokenAddress, LockedDealAddress, SafeMath.sub(amountToBurn, CreditableAmount)); - for(uint8 i=0 ; i 0){ - ILockedDeal(LockedDealAddress).CreateNewPool(OriginalTokenAddress, unlockTimes[i], unlockAmounts[i], _msgSender()); + if (SafeMath.sub(amountToBurn, CreditableAmount) > 0) { + require( + LockedDealAddress != address(0), + "Error: LockedDeal Contract Address Missing" + ); + ApproveAllowanceERC20( + OriginalTokenAddress, + LockedDealAddress, + SafeMath.sub(amountToBurn, CreditableAmount) + ); + for (uint8 i = 0; i < unlockTimes.length; i++) { + if (unlockAmounts[i] > 0) { + ILockedDeal(LockedDealAddress).CreateNewPool( + OriginalTokenAddress, + unlockTimes[i], + unlockAmounts[i], + _msgSender() + ); } } } - burn(amountToBurn); // here will be check for balance + burn(amountToBurn); // here will be check for balance emit TokenActivated(_msgSender(), amountToBurn); assert(amountToBurn == _amountToActivate); } - function getActivationResult(uint _amountToActivate) - public view tokenReady(true) returns(uint, uint, uint64[] memory, uint256[] memory) + function getActivationResult(uint256 _amountToActivate) + public + view + tokenReady(true) + returns ( + uint256, + uint256, + uint64[] memory, + uint256[] memory + ) { - uint TotalTokens; - uint CreditableAmount; + uint256 TotalTokens; + uint256 CreditableAmount; uint64[] memory unlockTimes = new uint64[](totalUnlocks); uint256[] memory unlockAmounts = new uint256[](totalUnlocks); uint8 iterator; - for(uint8 i=0 ; i= 0 ; i--){ - if(unlockAmounts[i] > 0){ - unlockAmounts[i] = SafeMath.add(unlockAmounts[i], difference); + for (uint8 i = totalUnlocks - 1; i >= 0; i--) { + if (unlockAmounts[i] > 0) { + unlockAmounts[i] = SafeMath.add( + unlockAmounts[i], + difference + ); break; } } } TotalTokens = _amountToActivate; } - return(TotalTokens, CreditableAmount, unlockTimes, unlockAmounts); + return (TotalTokens, CreditableAmount, unlockTimes, unlockAmounts); } -} \ No newline at end of file +} diff --git a/contracts/FlexStaking/ERC20Token.sol b/contracts/FlexStaking/ERC20Token.sol index fd4a556..a3c0c8f 100644 --- a/contracts/FlexStaking/ERC20Token.sol +++ b/contracts/FlexStaking/ERC20Token.sol @@ -1,4 +1,4 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "poolz-helper-v2/contracts/token/ERC20Token.sol"; \ No newline at end of file +import "poolz-helper-v2/contracts/token/ERC20Token.sol"; diff --git a/contracts/LockedDeal/Token.sol b/contracts/LockedDeal/Token.sol index d488769..e0c2104 100644 --- a/contracts/LockedDeal/Token.sol +++ b/contracts/LockedDeal/Token.sol @@ -1,4 +1,4 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; -import "poolz-helper/contracts/Token.sol"; \ No newline at end of file +import "poolz-helper/contracts/Token.sol"; diff --git a/contracts/LockedDealV2/ERC20Token.sol b/contracts/LockedDealV2/ERC20Token.sol index c919adf..a3c0c8f 100644 --- a/contracts/LockedDealV2/ERC20Token.sol +++ b/contracts/LockedDealV2/ERC20Token.sol @@ -1,4 +1,4 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "poolz-helper-v2/contracts/token/ERC20Token.sol"; \ No newline at end of file +import "poolz-helper-v2/contracts/token/ERC20Token.sol"; diff --git a/package.json b/package.json index b333748..61fadc5 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,7 @@ { + "scripts": { + "prettier": "prettier --write /contracts/**/.sol && prettier --write test/" + }, "dependencies": { "@openzeppelin/contracts": "^4.6.0", "@uniswap/v2-core": "^1.0.1", @@ -30,6 +33,8 @@ "mocha": "^6.2.2", "node-fetch": ">=2.6.1", "openzeppelin-solidity": "^3.4.1", + "prettier": "^2.7.1", + "prettier-plugin-solidity": "^1.0.0-dev.23", "sol-merger": "^3.1.0", "solidity-coverage": "^0.7.21", "truffle-plugin-verify": "^0.5.7", diff --git a/test/14_FlexStaking.js b/test/14_FlexStaking.js index 6f6b394..31ee4c2 100644 --- a/test/14_FlexStaking.js +++ b/test/14_FlexStaking.js @@ -31,13 +31,8 @@ contract("Flex Staking with LockedDealV2 integration", (accounts) => { await flexStaking.SetLockedDealAddress(lockedDeal.address) }) -<<<<<<< prettier it("should create new pool", async () => { - await timeMachine.advanceBlockAndSetTime(Date.now()) -======= - it('should create new pool', async () => { await timeMachine.advanceBlockAndSetTime(Math.floor(Date.now() / 1000)) ->>>>>>> master await rwdToken.approve(flexStaking.address, amount, { from: projectOwner }) const tx = await flexStaking.CreateStakingPool( lockToken.address, @@ -170,11 +165,7 @@ contract("Flex Staking with LockedDealV2 integration", (accounts) => { const startTime = Math.floor(date.getTime() / 1000) + 60 date.setDate(date.getDate() + 365) // add a year const finishTime = Math.floor(date.getTime() / 1000) + 60 -<<<<<<< prettier - await timeMachine.advanceBlockAndSetTime(Date.now()) -======= await timeMachine.advanceBlockAndSetTime(Math.floor(Date.now() / 1000)) ->>>>>>> master await lockToken.approve(flexStaking.address, 10000000, { from: projectOwner }) const tx = await flexStaking.CreateStakingPool( lockToken.address, From 2a9ef18e8514cb8d958db3859f7fe46cd2a3ba8a Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Tue, 8 Nov 2022 14:46:04 +0200 Subject: [PATCH 6/6] fix build --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 8fe75ec..6c8c36e 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "chai-bignumber": "^2.0.2", "coveralls": "^3.1.0", "mocha": "^6.2.2", + "truffle": "5.5.22", "node-fetch": ">=2.6.1", "openzeppelin-solidity": "^3.4.1", "sol-merger": "^3.1.0",