Skip to content

Commit

Permalink
Make it possible to have whitelisted participants to enter the ICO be…
Browse files Browse the repository at this point in the history
…fore the official starting date.
  • Loading branch information
miohtama committed May 15, 2017
1 parent f375d74 commit b6a2f6d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
26 changes: 25 additions & 1 deletion contracts/Crowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ contract Crowdsale is Haltable {
/** How much tokens this crowdsale has credited for each investor address */
mapping (address => uint256) public tokenAmountOf;

/** Addresses that are allowed to invest even before ICO offical opens. For testing, for ICO partners, etc. */
mapping (address => bool) public earlyParticipantWhitelist;

/** This is for manul testing for the interaction from owner wallet. You can set it to any value and inspect this in blockchain explorer to see that crowdsale interaction works. */
uint public ownerTestValue;

Expand All @@ -104,6 +107,9 @@ contract Crowdsale is Haltable {
// The rules were changed what kind of investments we accept
event InvestmentPolicyChanged(bool requireCustomerId, bool requiredSignedAddress, address signerAddress);

// Address early participation whitelist status changed
event Whitelisted(address addr, bool status);

function Crowdsale(address _token, PricingStrategy _pricingStrategy, address _multisigWallet, uint _start, uint _end, uint _minimumFundingGoal) {

owner = msg.sender;
Expand Down Expand Up @@ -155,7 +161,15 @@ contract Crowdsale is Haltable {
* @param customerId (optional) UUID v4 to track the successful payments on the server side
*
*/
function investInternal(address receiver, uint128 customerId) inState(State.Funding) stopInEmergency private {
function investInternal(address receiver, uint128 customerId) stopInEmergency private {

// Are we whitelisted for early deposit
if(!earlyParticipantWhitelist[receiver]) {
if(getState() != State.Funding) {
// Retail participants can only come in when the crowdsale is running
throw;
}
}

uint weiAmount = msg.value;
uint tokenAmount = pricingStrategy.calculatePrice(weiAmount, weiRaised, tokensSold, msg.sender, token.decimals());
Expand Down Expand Up @@ -300,6 +314,16 @@ contract Crowdsale is Haltable {
InvestmentPolicyChanged(requireCustomerId, requiredSignedAddress, signerAddress);
}

/**
* Allow addresses to do early participation.
*
*/
function setEarlyParicipantWhitelist(address addr, bool status) onlyOwner {
earlyParticipantWhitelist[addr] = status;
Whitelisted(addr, status);
}


/**
* Allow to (re)set pricing strategy.
*
Expand Down
2 changes: 1 addition & 1 deletion ico/cmd/distributetokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ico.utils import check_succesful_tx
from ico.utils import check_multiple_succesful_txs
from ico.etherscan import verify_contract
from ico.etherscan import get_etherscan_link%cpas
from ico.etherscan import get_etherscan_link
from ico.utils import get_constructor_arguments


Expand Down
14 changes: 13 additions & 1 deletion ico/tests/contracts/test_uncapped_flatprice.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_initialized(ico: Contract, uncapped_token: Contract, team_multisig, pre
assert ico.call().minimumFundingGoal() == preico_funding_goal


def test_buy_early(chain: TestRPCChain, ico: Contract, customer: str, preico_starts_at):
def test_buy_early(chain: TestRPCChain, ico: Contract, customer: str, preico_starts_at, uncapped_token):
"""Cannot buy too early."""

time_travel(chain, preico_starts_at - 1)
Expand All @@ -44,6 +44,18 @@ def test_buy_early(chain: TestRPCChain, ico: Contract, customer: str, preico_sta
ico.transact({"from": customer, "value": to_wei(1, "ether")}).buy()



def test_buy_early_whitelisted(chain: TestRPCChain, ico: Contract, customer: str, preico_starts_at, team_multisig, uncapped_token):
"""Whitelisted participants can buy earliy."""

time_travel(chain, preico_starts_at - 1)
assert ico.call().getState() == CrowdsaleState.PreFunding
ico.transact({"from": team_multisig}).setEarlyParicipantWhitelist(customer, True)
ico.transact({"from": customer, "value": to_wei(1, "ether")}).buy()
assert uncapped_token.call().balanceOf(customer) > 0



def test_buy_one_investor(chain: TestRPCChain, web3: Web3, ico: Contract, uncapped_token: Contract, customer: str, preico_token_price, preico_starts_at, team_multisig):
"""Can buy when crowdsale is running."""

Expand Down

0 comments on commit b6a2f6d

Please sign in to comment.