def participate_early(chain, web3: Web3, presale_address: str, crowdsale_address: str, deploy_address: str, start=0, end=32, timeout=300) -> int: """Move funds over early. .. note :: Crowdsale contract checks the participate whitelist by invest address, not by msg.sender. This process will open the presale investors an ability to participate to the crowdsale early, bypassing the retail investor start time. However they could also top up their existing preico accounts, so this is largerly no issue. :param start: Move only n investors (for testing purposes) :param end: Move only n investors (for testing purposes) """ updated = 0 PresaleFundCollector = get_contract_by_name(chain, "PresaleFundCollector") presale = PresaleFundCollector(address=presale_address) Crowdsale = PresaleFundCollector = get_contract_by_name(chain, "Crowdsale") crowdsale = Crowdsale(address=crowdsale_address) # Make sure presale is correctly set txid = presale.transact({"from": deploy_address}).setCrowdsale(crowdsale.address) logger.info("Setting presale crowdsale address to %s on txid", crowdsale.address, txid) check_succesful_tx(web3, txid, timeout=timeout) # Double check presale has a presale price set MilestonePricing = get_contract_by_name(chain, "MilestonePricing") pricing_strategy = MilestonePricing(address=crowdsale.call().pricingStrategy()) if not pricing_strategy.call().preicoAddresses(presale.address): raise RuntimeError("Was not listed as presale address for pricing: {}".format(presale.address)) for i in range(start, min(end, presale.call().investorCount())): investor = presale.call().investors(i) if presale.call().balances(investor) > 0: print("Whitelisting for {} to crowdsale {}".format(investor, crowdsale.address)) txid = crowdsale.transact({"from": deploy_address}).setEarlyParicipantWhitelist(investor, True) print("Broadcasting whitelist transaction {}".format(txid)) check_succesful_tx(web3, txid, timeout=timeout) funds = from_wei(presale.call().balances(investor), "ether") print("Moving funds {} ETH for investor {} to presale {}".format(funds, investor, presale.address)) txid = presale.transact({"from": deploy_address}).participateCrowdsaleInvestor(investor) print("Broadcasting transaction {}".format(txid)) check_succesful_tx(web3, txid, timeout=timeout) updated += 1 else: print("Investor already handled: {}".format(investor)) return updated
def deploy_crowdsale(project: Project, chain, source_definitions: dict, deploy_address) -> Tuple[dict, dict, dict]: """Deploy multiple contracts from crowdsale definitions. :param chain: Populus chain object :param data: One of mainnet/ropsten parsed data definitions in a YAML file :return: Tuple (expaneded definitions, statistics, contract object map). The expanded definitions are run-time data that has everything expanded out and actual contract addresses """ statistics = Counter() # This will contain our output and parsed values runtime_data = copy.deepcopy(source_definitions) # Contract handles for post-actions contracts = {} # Store the address we used for the deployment runtime_data["deploy_address"] = deploy_address chain_name = runtime_data["chain"] verify_on_etherscan = asbool(runtime_data["verify_on_etherscan"]) browser_driver = runtime_data.get("browser_driver", "chrome") need_unlock = runtime_data.get("unlock_deploy_address", True) for name, contract_def in runtime_data["contracts"].items(): contract_name = contract_def["contract_name"] # First expand out all variables address = contract_def.get("address") if address: print("Already deployed contract,", name, address) Contract = get_contract_by_name(chain, contract_name) contracts[name] = Contract(address=address) statistics["already_deployed"] += 1 continue # Expand Jinja templated variables for this contract context = get_jinja_context(runtime_data) try: expanded_contract_def = interpolate_data(contract_def, context) except jinja2.exceptions.TemplateError as e: raise RuntimeError( "Could not expand data for section {}".format(name)) from e # Store expanded data for output runtime_data["contracts"][name] = expanded_contract_def contracts[name] = deploy_contract(project, chain, deploy_address, expanded_contract_def, chain_name, need_unlock=need_unlock) statistics["deployed"] += 1 # Perform manual verification of the deployed contract if verify_on_etherscan: fname = runtime_data["contracts"][name]["contract_file"] src = verify_contract( project=project, chain_name=chain_name, address=runtime_data["contracts"][name]["address"], contract_name=contract_name, contract_filename=fname, constructor_args=runtime_data["contracts"][name] ["constructor_args"], libraries=runtime_data["contracts"][name]["libraries"], browser_driver=browser_driver) runtime_data["contracts"][name][ "etherscan_link"] = get_etherscan_link( chain_name, runtime_data["contracts"][name]["address"]) # Write out our expanded contract expanded_path = os.path.join(os.getcwd(), "build", "expanded", fname) with open(expanded_path, "wt") as out: out.write(src) return runtime_data, statistics, contracts
def deploy_crowdsale(project: Project, chain, yaml_filename: str, source_definitions: dict, deploy_address) -> Tuple[dict, dict, dict]: """Deploy multiple contracts from crowdsale definitions. :param chain: Populus chain object :param data: One of mainnet/ropsten parsed data definitions in a YAML file :return: Tuple (expaneded definitions, statistics, contract object map). The expanded definitions are run-time data that has everything expanded out and actual contract addresses """ statistics = Counter() # This will contain our output and parsed values runtime_data = copy.deepcopy(source_definitions) # Contract handles for post-actions contracts = {} # Store the address we used for the deployment runtime_data["deploy_address"] = deploy_address chain_name = runtime_data["chain"] verify_on_etherscan = asbool(runtime_data["verify_on_etherscan"]) browser_driver = runtime_data.get("browser_driver", "chrome") solc = runtime_data["solc"] need_unlock = runtime_data.get("unlock_deploy_address", True) for name, contract_def in runtime_data["contracts"].items(): contract_name = contract_def["contract_name"] # First expand out all variables address = contract_def.get("address") if address: print("Already deployed contract,", name, address) Contract = get_contract_by_name(chain, contract_name) contracts[name] = Contract(address=address) statistics["already_deployed"] += 1 continue # Expand Jinja templated variables for this contract context = get_jinja_context(runtime_data) try: expanded_contract_def = interpolate_data(contract_def, context) except jinja2.exceptions.TemplateError as e: raise RuntimeError("Could not expand data for section {}".format(name)) from e # Store expanded data for output runtime_data["contracts"][name] = expanded_contract_def contracts[name] = deploy_contract(project, chain, deploy_address, expanded_contract_def, chain_name, need_unlock=need_unlock) statistics["deployed"] += 1 # Perform manual verification of the deployed contract if verify_on_etherscan: fname = runtime_data["contracts"][name]["contract_file"] src = verify_contract( project=project, chain_name=chain_name, address=runtime_data["contracts"][name]["address"], contract_name=contract_name, contract_filename=fname, constructor_args=runtime_data["contracts"][name]["constructor_args"], libraries=runtime_data["contracts"][name]["libraries"], browser_driver=browser_driver, compiler=solc["version"], optimization=asbool(solc["optimizations"]["optimizer"]), optimizer_runs=int(solc["optimizations"]["runs"]) ) runtime_data["contracts"][name]["etherscan_link"] = get_etherscan_link(chain_name, runtime_data["contracts"][name]["address"]) # Write out our expanded contract expanded_path = os.path.join(os.getcwd(), "build", "expanded", fname) with open(expanded_path, "wt") as out: out.write(src) # Write the ongoing output, so we can use it e.g. to debug EtherScan verification write_deployment_report(yaml_filename, runtime_data, partial=True) return runtime_data, statistics, contracts
from ico.utils import check_succesful_tx from ico.utils import get_contract_by_name import populus from populus.utils.cli import request_account_unlock from populus.utils.accounts import is_account_locked p = populus.Project() account = "0x3e3c4504a59d1f35dedc9b079dbbd51275ee1a6b" # Our controller account on Kovan with p.get_chain("kovan") as chain: web3 = chain.web3 Contract = get_contract_by_name(chain, "Crowdsale") contract = Contract(address="0x3bfb37fde9bf11923de51d50e58c67a6675040c2") if is_account_locked(web3, account): request_account_unlock(chain, account, None) txid = contract.transact({ "from": account }).setEarlyParicipantWhitelist( "0x2BB6a9aC8ff0bF09aAC94F08bACe57f41E9bC312", True) print("TXID is", txid) check_succesful_tx(web3, txid) print("OK")