# Path: deploy/utils.py
# def amount_format(web3, wei):
# def createWallet():
# def check_succesful_tx(web3, txid, timeout=180) -> dict:
#     def __init__(self,
#                  web3,
#                  abi,
#                  address,
#                  event_name,
#                  from_block=0,
#                  to_block='latest',
#                  filters=None,
#                  callback=None):
#     def get_logs(self):
#     def set_log_data(self, log):
#     def watch_logs(self, callback):
#         def log_callback(log):
#     def stop(self):
# def watch_logs(contract, event, callback, params={}):
# def print_logs(contract, event, name=''):
# def returnFundsToOwner(web3, owner, bidder):
# def sendFunds(web3, owner, bidder, max_bid):
# def assignFundsToBidders(web3, owner: str, bidders: list, distribution_limit: int=None):
# def set_connection_pool_size(web3, pool_connections, pool_size):
# def get_expected_tokens(amount, token_multiplier, final_price):
# class LogFilter:
# 
# Path: deploy/simulation.py
# def auction_simulation(web3, token, auction, owner, kwargs):
#     # Start the auction
#     bidder_addresses = fund_bidders(web3, owner, kwargs)
#     if kwargs['start_auction'] is True:
#         start_auction(auction, owner, web3)
# 
#     # deploy bidders
#     # this will return when auction ends
#     if kwargs['deploy_bidders']:
#         assert auction.call().price_start() > 0
#         assert isinstance(auction.call().price_constant(), int)
#         assert isinstance(auction.call().price_exponent(), int)
#         assert token.call().decimals() > 0
#         deploy_bidders(bidder_addresses, web3, auction, kwargs)
#     else:
#         log.info("--deploy-bidders is not set. Skipping bidding part of the simulation.")
# 
#     if kwargs['finalize_auction']:
#         finalize_auction(auction, owner, web3)
# 
#     if kwargs['claim_tokens'] is True:
#         if auction.call().stage() == AUCTION_TOKENS_DISTRIBUTED:
#             log.info('not claiming tokens: auction stage is TokensDistributed already')
#             return
#         assert auction.call().stage() == AUCTION_ENDED
#         bidder_addresses = fund_bidders(web3, owner, kwargs)  # refill bidders again
#         event_lst = [gevent.spawn(claim_tokens, auction, x, web3)
#                      for x in bidder_addresses]
#         gevent.joinall(event_lst)
#         event_lst = [gevent.spawn(get_balance, token, x)
#                      for x in bidder_addresses]
#         gevent.joinall(event_lst)
#         total_balance = sum([ev.value for ev in event_lst])
#         assert auction.call().stage() == AUCTION_TOKENS_DISTRIBUTED
#         return total_balance


from gevent import monkey
from populus import Project
from deploy.utils import (
    passphrase,
    check_succesful_tx,
    set_connection_pool_size,
)
from deploy.simulation import (
    auction_simulation
)
import requests.adapters as adapter
import click
import sys
import logging

    log.info("Web3 provider is %s" % (web3.currentProvider))
    assert owner, "Make sure owner account is created"
    assert wallet_address, "Make sure wallet account is created"
    log.info('owner=%s wallet=%s' % (owner, wallet_address))
    log.info('auction start_price=%d constant=%d exponent=%d' %
             (price_start, price_constant, price_exponent))

    # Load Populus contract proxy classes
    Auction = chain.provider.get_contract_factory('DutchAuction')
    Token = chain.provider.get_contract_factory('RaidenToken')

    # Deploy Auction
    auction_txhash = Auction.deploy(transaction={"from": owner},
                                    args=[wallet_address, whitelister, price_start,
                                          price_constant, price_exponent])
    log.info("Deploying auction, tx hash " + auction_txhash)
    receipt, success = check_succesful_tx(web3, auction_txhash)
    assert success is True
    auction_address = receipt["contractAddress"]
    log.info("Auction contract address " + auction_address)

    # Deploy token
    token_txhash = Token.deploy(transaction={"from": owner}, args=[
        auction_address,
        wallet_address,
        supply
    ])

    log.info("Deploying token, tx hash " + token_txhash)

# Path: deploy/utils.py
# def amount_format(web3, wei):
# def createWallet():
# def check_succesful_tx(web3, txid, timeout=180) -> dict:
#     def __init__(self,
#                  web3,
#                  abi,
#                  address,
#                  event_name,
#                  from_block=0,
#                  to_block='latest',
#                  filters=None,
#                  callback=None):
#     def get_logs(self):
#     def set_log_data(self, log):
#     def watch_logs(self, callback):
#         def log_callback(log):
#     def stop(self):
# def watch_logs(contract, event, callback, params={}):
# def print_logs(contract, event, name=''):
# def returnFundsToOwner(web3, owner, bidder):
# def sendFunds(web3, owner, bidder, max_bid):
# def assignFundsToBidders(web3, owner: str, bidders: list, distribution_limit: int=None):
# def set_connection_pool_size(web3, pool_connections, pool_size):
# def get_expected_tokens(amount, token_multiplier, final_price):
# class LogFilter:
# 
# Path: deploy/simulation.py
# def auction_simulation(web3, token, auction, owner, kwargs):
#     # Start the auction
#     bidder_addresses = fund_bidders(web3, owner, kwargs)
#     if kwargs['start_auction'] is True:
#         start_auction(auction, owner, web3)
# 
#     # deploy bidders
#     # this will return when auction ends
#     if kwargs['deploy_bidders']:
#         assert auction.call().price_start() > 0
#         assert isinstance(auction.call().price_constant(), int)
#         assert isinstance(auction.call().price_exponent(), int)
#         assert token.call().decimals() > 0
#         deploy_bidders(bidder_addresses, web3, auction, kwargs)
#     else:
#         log.info("--deploy-bidders is not set. Skipping bidding part of the simulation.")
# 
#     if kwargs['finalize_auction']:
#         finalize_auction(auction, owner, web3)
# 
#     if kwargs['claim_tokens'] is True:
#         if auction.call().stage() == AUCTION_TOKENS_DISTRIBUTED:
#             log.info('not claiming tokens: auction stage is TokensDistributed already')
#             return
#         assert auction.call().stage() == AUCTION_ENDED
#         bidder_addresses = fund_bidders(web3, owner, kwargs)  # refill bidders again
#         event_lst = [gevent.spawn(claim_tokens, auction, x, web3)
#                      for x in bidder_addresses]
#         gevent.joinall(event_lst)
#         event_lst = [gevent.spawn(get_balance, token, x)
#                      for x in bidder_addresses]
#         gevent.joinall(event_lst)
#         total_balance = sum([ev.value for ev in event_lst])
#         assert auction.call().stage() == AUCTION_TOKENS_DISTRIBUTED
#         return total_balance


# Path: deploy/deploy_testnet.py
from gevent import monkey
from populus import Project
from deploy.utils import (
    passphrase,
    check_succesful_tx,
    set_connection_pool_size,
)
from deploy.simulation import (
    auction_simulation
)
import requests.adapters as adapter
import click
import sys
import logging


    log.info("Web3 provider is %s" % (web3.currentProvider))
    assert owner, "Make sure owner account is created"
    assert wallet_address, "Make sure wallet account is created"
    log.info('owner=%s wallet=%s' % (owner, wallet_address))
    log.info('auction start_price=%d constant=%d exponent=%d' %
             (price_start, price_constant, price_exponent))

    # Load Populus contract proxy classes
    Auction = chain.provider.get_contract_factory('DutchAuction')
    Token = chain.provider.get_contract_factory('RaidenToken')

    # Deploy Auction
    auction_txhash = Auction.deploy(transaction={"from": owner},
                                    args=[wallet_address, whitelister, price_start,
                                          price_constant, price_exponent])
    log.info("Deploying auction, tx hash " + auction_txhash)
    receipt, success = check_succesful_tx(web3, auction_txhash)
    assert success is True
    auction_address = receipt["contractAddress"]
    log.info("Auction contract address " + auction_address)

    # Deploy token
    token_txhash = Token.deploy(transaction={"from": owner}, args=[
        auction_address,
        wallet_address,
        supply
    ])

    log.info("Deploying token, tx hash " + token_txhash)

    receipt, success = check_succesful_tx(web3, token_txhash)