Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #153 from The-Poolz/version-2
Browse files Browse the repository at this point in the history
Version 2
  • Loading branch information
PoolzAdmin authored Feb 18, 2021
2 parents 08005d2 + 057e621 commit a94de56
Show file tree
Hide file tree
Showing 21 changed files with 11,339 additions and 514 deletions.
2 changes: 1 addition & 1 deletion contracts/IWhiteList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.4.24;

//For whitelist,
interface IWhiteList {
function Check(address _Subject, uint256 _Id,uint256 _Amount) external view returns(bool);
function Check(address _Subject, uint256 _Id) external view returns(uint);
function Register(address _Subject,uint256 _Id,uint256 _Amount) external;
function IsNeedRegister(uint256 _Id) external view returns(bool);
}
41 changes: 20 additions & 21 deletions contracts/Invest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ contract Invest is PoolsData {
uint256 Poolid; //the id of the pool, he got the rate info and the token, check if looked pool
address InvestorAddress; //
uint256 MainCoin; //the amount of the main coin invested (eth/dai), calc with rate
bool IsPozInvestor; //If the blance of the address got > MinPoz, can get discout if got early
uint256 TokensOwn; //the amount of Tokens the investor needto get from the contract
uint256 InvestTime; //the time that investment made
}

function getTotalInvestor() external view returns(uint256){
return TotalInvestors;
}


//@dev Send in wei
function InvestETH(uint256 _PoolId)
external
Expand All @@ -51,16 +55,8 @@ contract Invest is PoolsData {
);
uint256 ThisInvestor = NewInvestor(msg.sender, msg.value, _PoolId);
uint256 Tokens = CalcTokens(_PoolId, msg.value, msg.sender);
if (pools[_PoolId].MoreData.IsLocked) {
Investors[ThisInvestor].TokensOwn = SafeMath.add(
Investors[ThisInvestor].TokensOwn,
Tokens
);
}
else {
// not locked, will transfer the toke
TransferToken(pools[_PoolId].BaseData.Token, msg.sender, Tokens);
}

TokenAllocate(_PoolId, ThisInvestor, Tokens);

uint256 EthMinusFee =
SafeMath.div(
Expand Down Expand Up @@ -91,15 +87,7 @@ contract Invest is PoolsData {
uint256 ThisInvestor = NewInvestor(msg.sender, _Amount, _PoolId);
uint256 Tokens = CalcTokens(_PoolId, _Amount, msg.sender);

if (pools[_PoolId].MoreData.IsLocked) {
Investors[ThisInvestor].TokensOwn = SafeMath.add(
Investors[ThisInvestor].TokensOwn,
Tokens
);
} else {
// not locked, will transfer the tokens
TransferToken(pools[_PoolId].BaseData.Token, msg.sender, Tokens);
}
TokenAllocate(_PoolId, ThisInvestor, Tokens);

uint256 RegularFeePay =
SafeMath.div(SafeMath.mul(_Amount, CalcFee(_PoolId)), 10000);
Expand All @@ -117,6 +105,18 @@ contract Invest is PoolsData {
RegisterInvest(_PoolId, Tokens);
}

function TokenAllocate(uint256 _PoolId, uint256 _ThisInvestor, uint256 _Tokens) internal {
if (isPoolLocked(_PoolId)) {
Investors[_ThisInvestor].TokensOwn = SafeMath.add(
Investors[_ThisInvestor].TokensOwn,
_Tokens
);
} else {
// not locked, will transfer the tokens
TransferToken(pools[_PoolId].BaseData.Token, Investors[_ThisInvestor].InvestorAddress, _Tokens);
}
}

function RegisterInvest(uint256 _PoolId, uint256 _Tokens) internal {
require(
_Tokens <= pools[_PoolId].MoreData.Lefttokens,
Expand All @@ -139,7 +139,6 @@ contract Invest is PoolsData {
_Pid,
_Sender,
_Amount,
IsPOZInvestor(_Sender),
0,
block.timestamp
);
Expand Down
2 changes: 0 additions & 2 deletions contracts/InvestorData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ contract InvestorData is Invest {
uint256,
address,
uint256,
bool,
uint256,
uint256
)
Expand All @@ -56,7 +55,6 @@ contract InvestorData is Invest {
Investors[_id].Poolid,
Investors[_id].InvestorAddress,
Investors[_id].MainCoin,
Investors[_id].IsPozInvestor,
Investors[_id].TokensOwn,
Investors[_id].InvestTime
);
Expand Down
17 changes: 6 additions & 11 deletions contracts/MainCoinManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,19 @@
pragma solidity ^0.4.24;

import "./Manageable.sol";
import "./IWhiteList.sol";

contract MainCoinManager is Manageable {
event MainCoinAdded (address Token);
event MainCoinRemoved (address Token);

mapping(address => bool) public ERC20MainCoins; //when approve new erc20 main coin - it will list here
uint256 public MCWhitelistId;

function AddERC20Maincoin(address _token) public onlyOwner {
emit MainCoinAdded(_token);
ERC20MainCoins[_token] = true;
}

function RemoveERC20Maincoin(address _token) public onlyOwner {
emit MainCoinRemoved(_token);
ERC20MainCoins[_token] = false;
}
function setMCWhitelistId(uint256 _whiteListId) external onlyOwnerOrGov{
MCWhitelistId = _whiteListId;
}

function IsERC20Maincoin(address _token) public view returns (bool) {
return ERC20MainCoins[_token];
return IWhiteList(WhitelistContract).Check(_token, MCWhitelistId) > 0;
}
}
29 changes: 8 additions & 21 deletions contracts/Manageable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,34 @@ contract Manageable is ETHHelper {
uint256 public MinETHInvest;
uint256 public MaxETHInvest;
address public WhiteList_Address; //The address of the Whitelist contract
bool public MustPozBenefit;

function SwitchMustPozBenefit() public onlyOwner {
MustPozBenefit = !MustPozBenefit;
}

function SetWhiteList_Address(address _WhiteList_Address) public onlyOwner {

function SetWhiteList_Address(address _WhiteList_Address) public onlyOwnerOrGov {
WhiteList_Address = _WhiteList_Address;
}

function SetMinMaxETHInvest(uint256 _MinETHInvest, uint256 _MaxETHInvest)
public
onlyOwner
onlyOwnerOrGov
{
MinETHInvest = _MinETHInvest;
MaxETHInvest = _MaxETHInvest;
}

function SetMinMaxDuration(uint256 _minDuration, uint256 _maxDuration)
public
onlyOwner
onlyOwnerOrGov
{
MinDuration = _minDuration;
MaxDuration = _maxDuration;
}

function SetPoolPrice(uint256 _PoolPrice) public onlyOwner {
function SetPoolPrice(uint256 _PoolPrice) public onlyOwnerOrGov {
PoolPrice = _PoolPrice;
}

function SetFee(uint256 _fee)
public
onlyOwner
onlyOwnerOrGov
PercentCheckOk(_fee)
LeftIsBigger(_fee, PozFee)
{
Expand All @@ -65,20 +60,12 @@ contract Manageable is ETHHelper {

function SetPOZFee(uint256 _fee)
public
onlyOwner
onlyOwnerOrGov
PercentCheckOk(_fee)
LeftIsBigger(Fee, _fee)
{
PozFee = _fee;
}

function WithdrawETHFee(address _to) public onlyOwner {
_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 {
uint256 temp = FeeMap[_Token];
FeeMap[_Token] = 0;
TransferToken(_Token, _to, temp);
}

}
35 changes: 27 additions & 8 deletions contracts/Pools.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,42 @@ contract Pools is MainCoinManager {
uint256 StartAmount; //The total amount of the tokens for sale
}
struct PoolMoreData {
bool IsLocked; // true - the investors getting the tokens after the FinishTime. false - intant deal
uint64 LockedUntil; // true - the investors getting the tokens after the FinishTime. false - intant deal
uint256 Lefttokens; // the ammount of tokens left for sale
uint256 StartTime; // the time the pool open //TODO Maybe Delete this?
uint256 OpenForAll; // The Time that all investors can invest
uint256 UnlockedTokens; //for locked pools
uint256 WhiteListId; // 0 is turn off, the Id of the whitelist from the contract.
bool TookLeftOvers; //The Creator took the left overs after the pool finished
bool Is21DecimalRate; //If true, the rate will be rate*10^-21
uint256 WhiteListId; // 0 is turn off, the Id of the whitelist from the contract.
}

//create a new pool
function getPoolsMoreData(uint256 _Id) external view returns(uint64, uint256, uint256, uint256, uint256, bool, bool, uint256){
PoolMoreData storage moreData = pools[_Id].MoreData;
return(
moreData.LockedUntil,
moreData.Lefttokens,
moreData.StartTime,
moreData.OpenForAll,
moreData.UnlockedTokens,
moreData.TookLeftOvers,
moreData.Is21DecimalRate,
moreData.WhiteListId
);
}

function isPoolLocked(uint256 _id) public view returns(bool){
return pools[_id].MoreData.LockedUntil > now;
}

//create a new pool
function CreatePool(
address _Token, //token to sell address
uint256 _FinishTime, //Until what time the pool will work
uint256 _Rate, //the rate of the trade
uint256 _POZRate, //the rate for POZ Holders, how much each token = main coin
uint256 _StartAmount, //Total amount of the tokens to sell in the pool
bool _IsLocked, //False = DSP or True = TLP, [TODO: make timestamp]
uint64 _LockedUntil, //False = DSP or True = TLP
address _MainCoin, // address(0x0) = ETH, address of main token
bool _Is21Decimal, //focus the for smaller tokens.
uint256 _Now, //Start Time - can be 0 to not change current flow
Expand All @@ -60,7 +78,8 @@ contract Pools is MainCoinManager {
_MainCoin == address(0x0) || IsERC20Maincoin(_MainCoin),
"Main coin not in list"
);
require(_FinishTime - now < MaxDuration, "Can't be that long pool");
require(_FinishTime < MaxDuration + now, "Pool duration can't be that long");
require(_LockedUntil < MaxDuration + now , "Locked value can't be that long");
require(
_Rate <= _POZRate,
"POZ holders need to have better price (or the same)"
Expand Down Expand Up @@ -94,14 +113,14 @@ contract Pools is MainCoinManager {
_StartAmount
),
PoolMoreData(
_IsLocked,
_LockedUntil,
_StartAmount,
_Now,
Openforall,
0,
_WhiteListId,
false,
_Is21Decimal,
_WhiteListId
_Is21Decimal
)
);
poolsMap[msg.sender].push(poolsCount);
Expand Down
10 changes: 5 additions & 5 deletions contracts/PoolsData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ contract PoolsData is Pools {
view
PoolId(_Id)
returns (
bool,
uint64,
uint256,
uint256,
uint256,
Expand All @@ -52,7 +52,7 @@ contract PoolsData is Pools {
)
{
return (
pools[_Id].MoreData.IsLocked,
pools[_Id].MoreData.LockedUntil,
pools[_Id].MoreData.Lefttokens,
pools[_Id].MoreData.StartTime,
pools[_Id].MoreData.OpenForAll,
Expand Down Expand Up @@ -129,21 +129,21 @@ contract PoolsData is Pools {
}
if (
pools[_id].MoreData.Lefttokens == 0 &&
pools[_id].MoreData.IsLocked &&
isPoolLocked(_id) &&
now < pools[_id].BaseData.FinishTime
) //no tokens on locked pool, got time
{
return (PoolStatus.OutOfstock);
}
if (
pools[_id].MoreData.Lefttokens == 0 && !pools[_id].MoreData.IsLocked
pools[_id].MoreData.Lefttokens == 0 && !isPoolLocked(_id)
) //no tokens on direct pool
{
return (PoolStatus.Close);
}
if (
now >= pools[_id].BaseData.FinishTime &&
!pools[_id].MoreData.IsLocked
!isPoolLocked(_id)
) {
// After finish time - not locked
if (pools[_id].MoreData.TookLeftOvers) return (PoolStatus.Close);
Expand Down
37 changes: 4 additions & 33 deletions contracts/PozBenefit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ contract PozBenefit is ERC20Helper {
constructor() public {
PozFee = 15; // *10000
PozTimer = 1000; // *10000
MinPoz = 80; // ^Token.decimals

// POZ_Address = address(0x0);
// POZBenefit_Address = address(0x0);
}

uint256 public PozFee; // the fee for the first part of the pool
uint256 public PozTimer; //the timer for the first part fo the pool
uint256 public MinPoz; //minimum ammount ofpoz to be part of the discount
address public POZ_Address; //The address of the POZ Token
address public POZBenefit_Address; //the address for implementation of IPozBenefit - to get POZ benefit status from other contracts


modifier PercentCheckOk(uint256 _percent) {
if (_percent < 10000) _;
else revert("Not in range");
Expand All @@ -31,37 +28,11 @@ contract PozBenefit is ERC20Helper {

function SetPozTimer(uint256 _pozTimer)
public
onlyOwner
onlyOwnerOrGov
PercentCheckOk(_pozTimer)
{
PozTimer = _pozTimer;
}

function SetMinPoz(uint256 _MinPoz) public onlyOwner {
MinPoz = _MinPoz;
}

function SetPOZBenefit_Address(address _POZBenefit_Address)
public
onlyOwner
{
POZBenefit_Address = _POZBenefit_Address;
}

function SetPozAdress(address _POZ_Address) public onlyOwner {
POZ_Address = _POZ_Address;
}

function AmIPOZInvestor() public view returns (bool) {
return IsPOZInvestor(msg.sender);
}

//@dev Taken from interface, To join the POZ Benefit club
function IsPOZInvestor(address _investor) internal view returns (bool) {
if (POZ_Address == address(0x0) && POZBenefit_Address == address(0x0)) return true; //false; // for testing stage, until got the address
return ((POZ_Address != address(0x0) &&
CheckBalance(POZ_Address, _investor) >= MinPoz) ||
(POZBenefit_Address != address(0x0) &&
IPOZBenefit(POZBenefit_Address).IsPOZHolder(_investor)));
}

}
Loading

0 comments on commit a94de56

Please sign in to comment.