示例#1
0
def unfreeze_and_remove_owner(
    currency_network_address: str,
    jsonrpc: str,
    gas_price: int,
    nonce: int,
    keystore: str,
):
    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)
    nonce = get_nonce(web3=web3, nonce=nonce, private_key=private_key)
    transaction_options = build_transaction_options(
        gas=None, gas_price=gas_price, nonce=nonce
    )

    unfreeze_owned_network(
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
        currency_network_address=currency_network_address,
    )
    increase_transaction_options_nonce(transaction_options)
    remove_owner_of_network(
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
        currency_network_address=currency_network_address,
    )
示例#2
0
def report_via_file(
    keystore: str,
    gas: int,
    gas_price: int,
    nonce: int,
    auto_nonce: bool,
    jsonrpc: str,
    contract_address,
    equivocation_report,
) -> None:

    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)

    nonce = get_nonce(web3=web3,
                      nonce=nonce,
                      auto_nonce=auto_nonce,
                      private_key=private_key)

    transaction_options = build_transaction_options(gas=gas,
                                                    gas_price=gas_price,
                                                    nonce=nonce)

    tx_hash = report_malicious_validator(
        web3,
        transaction_options,
        private_key,
        contract_address,
        equivocation_report["unsigned_block_header_one"],
        equivocation_report["signature_one"],
        equivocation_report["unsigned_block_header_two"],
        equivocation_report["signature_two"],
    )

    click.echo(f"Transaction hash: {tx_hash}")
示例#3
0
def exchange(jsonrpc: str, gas: int, gas_price: int, nonce: int,
             auto_nonce: bool, keystore: str):
    """Deploy an exchange contract and a contract to wrap Ether into an ERC 20
  token.
    """
    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)
    nonce = get_nonce(web3=web3,
                      nonce=nonce,
                      auto_nonce=auto_nonce,
                      private_key=private_key)
    transaction_options = build_transaction_options(gas=gas,
                                                    gas_price=gas_price,
                                                    nonce=nonce)
    exchange_contract = deploy_exchange(
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key)
    exchange_address = exchange_contract.address
    unw_eth_contract = deploy_unw_eth(
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
        exchange_address=exchange_address,
    )
    unw_eth_address = unw_eth_contract.address
    click.echo("Exchange: {}".format(to_checksum_address(exchange_address)))
    click.echo("Unwrapping ether: {}".format(
        to_checksum_address(unw_eth_address)))
示例#4
0
def beacon(
    implementation_address: str,
    owner_address: str,
    jsonrpc: str,
    gas_price: int,
    nonce: int,
    keystore: str,
):
    """Used to deploy an owned beacon pointing to an implementation address"""

    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)
    nonce = get_nonce(web3=web3, nonce=nonce, private_key=private_key)
    transaction_options = build_transaction_options(
        gas=None, gas_price=gas_price, nonce=nonce
    )
    beacon = deploy_beacon(
        web3,
        implementation_address,
        owner_address,
        private_key=private_key,
        transaction_options=transaction_options,
    )
    click.secho(
        f"Beacon successfully deployed at address {beacon.address} with owner {beacon.functions.owner().call()}"
    )
示例#5
0
def migration(
    old_addresses_file_path: str,
    new_addresses_file_path: str,
    jsonrpc: str,
    gas_price: int,
    nonce: int,
    keystore: str,
):
    """Used to migrate old currency networks to new ones
    It will fetch information about users in the old contract and set them in the one
    The address files should contain currency network addresses with
    address matching from one file to the other from top to bottom"""

    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)
    nonce = get_nonce(web3=web3, nonce=nonce, private_key=private_key)
    transaction_options = build_transaction_options(
        gas=None, gas_price=gas_price, nonce=nonce
    )
    migrate_networks(
        web3,
        old_addresses_file_path,
        new_addresses_file_path,
        transaction_options,
        private_key,
    )
示例#6
0
def close(
    auction_address,
    keystore: str,
    jsonrpc: str,
    gas: int,
    gas_price: int,
    nonce: int,
    auto_nonce: bool,
):
    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)
    contracts = get_deployed_auction_contracts(web3, auction_address)

    nonce = get_nonce(web3=web3,
                      nonce=nonce,
                      auto_nonce=auto_nonce,
                      private_key=private_key)

    transaction_options = build_transaction_options(gas=gas,
                                                    gas_price=gas_price,
                                                    nonce=nonce)

    auction_close = contracts.auction.functions.closeAuction()

    send_function_call_transaction(
        auction_close,
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )
示例#7
0
def deploy_foreign(
    keystore: str,
    jsonrpc: str,
    gas: int,
    gas_price: int,
    nonce: int,
    auto_nonce: bool,
    token_address,
) -> None:

    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)

    nonce = get_nonce(
        web3=web3, nonce=nonce, auto_nonce=auto_nonce, private_key=private_key
    )
    transaction_options = build_transaction_options(
        gas=gas, gas_price=gas_price, nonce=nonce
    )

    foreign_bridge_contract = deploy_foreign_bridge_contract(
        token_contract_address=token_address,
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )

    click.echo(f"ForeignBridge address: {foreign_bridge_contract.address}")
    click.echo(f"  deployed at block #{web3.eth.blockNumber}")
示例#8
0
def deploy_home(
    keystore: str,
    gas: int,
    gas_price: int,
    nonce: int,
    auto_nonce: bool,
    jsonrpc: str,
    validator_proxy_address: str,
    validators_required_percent: int,
) -> None:

    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)

    nonce = get_nonce(
        web3=web3, nonce=nonce, auto_nonce=auto_nonce, private_key=private_key
    )
    transaction_options = build_transaction_options(
        gas=gas, gas_price=gas_price, nonce=nonce
    )

    home_bridge_contract = deploy_home_bridge_contract(
        validator_proxy_contract_address=validator_proxy_address,
        validators_required_percent=validators_required_percent,
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )

    click.echo(f"HomeBridge address: {home_bridge_contract.address}")
    click.echo(f"  deployed at block #{web3.eth.blockNumber}")
示例#9
0
def deploy_and_migrate(
    addresses_file_path: str,
    output_file_path: str,
    beacon_address: str,
    owner_address: str,
    jsonrpc: str,
    gas_price: int,
    nonce: int,
    keystore: str,
):
    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)
    nonce = get_nonce(web3=web3, nonce=nonce, private_key=private_key)
    transaction_options = build_transaction_options(
        gas=None, gas_price=gas_price, nonce=nonce
    )

    deploy_and_migrate_networks_from_file(
        web3=web3,
        addresses_file_path=addresses_file_path,
        beacon_address=beacon_address,
        owner_address=owner_address,
        private_key=private_key,
        transaction_options=transaction_options,
        output_file_path=output_file_path,
    )
示例#10
0
def deploy(
    keystore: str,
    jsonrpc: str,
    gas: int,
    gas_price: int,
    nonce: int,
    auto_nonce: bool,
    token_address: str,
    airdrop_file_name: str,
    decay_start_time: int,
    decay_start_date: pendulum.DateTime,
    decay_duration: int,
) -> None:

    if decay_start_date is not None and decay_start_time is not None:
        raise click.BadParameter(
            "Both --decay-start-date and --decay-start-time have been specified"
        )
    if decay_start_date is None and decay_start_time is None:
        raise click.BadParameter(
            "Please specify a decay start date with --decay-start-date or --decay-start-time"
        )

    if decay_start_date is not None:
        decay_start_time = int(decay_start_date.timestamp())

    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)

    nonce = get_nonce(web3=web3,
                      nonce=nonce,
                      auto_nonce=auto_nonce,
                      private_key=private_key)
    transaction_options = build_transaction_options(gas=gas,
                                                    gas_price=gas_price,
                                                    nonce=nonce)

    airdrop_data = load_airdrop_file(airdrop_file_name)
    airdrop_items = to_items(airdrop_data)
    merkle_root = compute_merkle_root(airdrop_items)

    constructor_args = (
        token_address,
        sum_of_airdropped_tokens(airdrop_items),
        merkle_root,
        decay_start_time,
        decay_duration,
    )

    merkle_drop = deploy_merkle_drop(
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
        constructor_args=constructor_args,
    )

    click.echo(f"MerkleDrop address: {merkle_drop.address}")
    click.echo(f"Merkle root: {encode_hex(merkle_root)}")
示例#11
0
def verify_migration(
    old_addresses_file_path: str, new_addresses_file_path: str, jsonrpc: str
):
    """Used to verify migration of old currency networks to new ones
    The address files should contain currency network addresses with
    address matching from one file to the other from top to bottom"""

    web3 = connect_to_json_rpc(jsonrpc)

    verify_networks_migrations(web3, old_addresses_file_path, new_addresses_file_path)
示例#12
0
def check_whitelist(whitelist_file: str, auction_address: str,
                    jsonrpc: str) -> None:
    web3 = connect_to_json_rpc(jsonrpc)
    whitelist = read_addresses_in_csv(whitelist_file)
    contracts = get_deployed_auction_contracts(web3, auction_address)

    number_of_missing_addresses = len(
        missing_whitelisted_addresses(contracts.auction, whitelist))

    if number_of_missing_addresses == 0:
        click.echo(f"All {len(whitelist)} addresses have been whitelisted")
    else:
        click.echo(
            f"{number_of_missing_addresses} of {len(whitelist)} addresses have not been whitelisted yet"
        )
示例#13
0
def check_root(jsonrpc: str, merkle_drop_address: str, airdrop_file_name: str):
    click.echo("Read Merkle root from contract...")
    web3 = connect_to_json_rpc(jsonrpc)
    status = get_merkle_drop_status(web3, merkle_drop_address)
    merkle_root_contract = status["root"].hex()
    click.echo(f"Merkle root at contract: '{merkle_root_contract}'")

    click.echo("Calculate Merkle root by airdrop file...")
    airdrop_data = load_airdrop_file(airdrop_file_name)
    merkle_root_file = compute_merkle_root(to_items(airdrop_data)).hex()
    click.echo(f"Merkle root by airdrop file: '{merkle_root_file}'")

    if merkle_root_contract == merkle_root_file:
        click.secho("Both Merkle roots are equal.", fg="green")
    else:
        click.secho("The Merkle roots differ.", fg="red")
        sys.exit(EXIT_ERROR_CODE)
示例#14
0
def token_contract(premint_token_value):
    web3 = connect_to_json_rpc("test")
    compiled_contracts = load_contracts_json("merkle_drop")

    token_contract: Contract = deploy_compiled_contract(
        abi=compiled_contracts["DroppedToken"]["abi"],
        bytecode=compiled_contracts["DroppedToken"]["bytecode"],
        constructor_args=(
            "Test Token",
            "TT",
            18,
            web3.eth.accounts[0],
            premint_token_value,
        ),
        web3=web3,
    )

    return token_contract
示例#15
0
def identity_proxy_factory(
    jsonrpc: str, gas: int, gas_price: int, nonce: int, keystore: str
):
    """Deploy an identity proxy factory, which can be used to create proxies for identity contracts."""

    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)
    nonce = get_nonce(web3=web3, nonce=nonce, private_key=private_key)
    transaction_options = build_transaction_options(
        gas=gas, gas_price=gas_price, nonce=nonce
    )
    identity_proxy_factory = deploy_identity_proxy_factory(
        web3=web3, transaction_options=transaction_options, private_key=private_key
    )
    click.echo(
        "Identity proxy factory: {}".format(
            to_checksum_address(identity_proxy_factory.address)
        )
    )
示例#16
0
def unfunded_merkle_drop_contract(
    premint_token_value, root_hash_for_tree_data, token_contract
):
    web3 = connect_to_json_rpc("test")
    compiled_contracts = load_contracts_json("merkle_drop")

    merkle_drop_contract: Contract = deploy_compiled_contract(
        abi=compiled_contracts["MerkleDrop"]["abi"],
        bytecode=compiled_contracts["MerkleDrop"]["bytecode"],
        constructor_args=(
            token_contract.address,
            premint_token_value,
            root_hash_for_tree_data,
            pendulum.now().int_timestamp + 10,
            60 * 60 * 24 * 4,
        ),
        web3=web3,
    )

    return merkle_drop_contract
示例#17
0
def identity_implementation(jsonrpc: str, gas: int, gas_price: int, nonce: int,
                            auto_nonce: bool, keystore: str):
    """Deploy an identity contract without initializing it. Can be used as the implementation for deployed
    identity proxies.
    """
    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)
    nonce = get_nonce(web3=web3,
                      nonce=nonce,
                      auto_nonce=auto_nonce,
                      private_key=private_key)
    transaction_options = build_transaction_options(gas=gas,
                                                    gas_price=gas_price,
                                                    nonce=nonce)
    identity_implementation = deploy_identity_implementation(
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key)
    click.echo("Identity implementation: {}".format(
        to_checksum_address(identity_implementation.address)))
示例#18
0
def whitelist(
    whitelist_file: str,
    auction_address: str,
    batch_size: int,
    keystore: str,
    jsonrpc: str,
    gas: int,
    gas_price: int,
    nonce: int,
    auto_nonce: bool,
) -> None:

    web3 = connect_to_json_rpc(jsonrpc)
    whitelist = read_addresses_in_csv(whitelist_file)
    private_key = retrieve_private_key(keystore)

    nonce = get_nonce(web3=web3,
                      nonce=nonce,
                      auto_nonce=auto_nonce,
                      private_key=private_key)

    transaction_options = build_transaction_options(gas=gas,
                                                    gas_price=gas_price,
                                                    nonce=nonce)

    contracts = get_deployed_auction_contracts(web3, auction_address)

    number_of_whitelisted_addresses = whitelist_addresses(
        contracts.auction,
        whitelist,
        batch_size=batch_size,
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )
    click.echo("Number of whitelisted addresses: " +
               str(number_of_whitelisted_addresses))
示例#19
0
def status(auction_address, jsonrpc):

    web3 = connect_to_json_rpc(jsonrpc)

    contracts = get_deployed_auction_contracts(web3, auction_address)

    # constants throughout auction
    duration_in_days = contracts.auction.functions.auctionDurationInDays(
    ).call()
    start_price_in_eth = contracts.auction.functions.startPrice().call(
    ) / ETH_IN_WEI
    minimal_number_of_participants = (
        contracts.auction.functions.minimalNumberOfParticipants().call())
    maximal_number_of_participants = (
        contracts.auction.functions.maximalNumberOfParticipants().call())
    locker_address = contracts.locker.address
    locker_initialized = contracts.locker.functions.initialized().call()
    locker_release_timestamp = contracts.locker.functions.releaseTimestamp(
    ).call()

    locker_address_in_auction_contract = (
        contracts.auction.functions.depositLocker().call())
    auction_address_in_locker_contract = (
        contracts.locker.functions.depositorsProxy().call())
    slasher_address_in_locker_contract = contracts.locker.functions.slasher(
    ).call()
    locker_address_in_slasher_contract = ZERO_ADDRESS
    if contracts.slasher is not None:
        locker_address_in_slasher_contract = (
            contracts.slasher.functions.depositContract().call())

    slasher_address = ZERO_ADDRESS
    slasher_initialized = False
    if contracts.slasher is not None:
        slasher_address = contracts.slasher.address
        slasher_initialized = contracts.slasher.functions.initialized().call()

    # variables
    auction_state_value = contracts.auction.functions.auctionState().call()
    auction_state = AuctionState(auction_state_value)
    start_time = contracts.auction.functions.startTime().call()
    close_time = contracts.auction.functions.closeTime().call()
    last_slot_price = contracts.auction.functions.lowestSlotPrice().call()
    current_price_in_eth = 0
    if auction_state == AuctionState.Started:
        current_price_in_eth = (
            contracts.auction.functions.currentPrice().call() / ETH_IN_WEI)

    click.echo("The auction duration is:                " +
               str(duration_in_days) + " days")
    click.echo("The starting price in eth is:           " +
               str(start_price_in_eth) + " eth")
    click.echo("The minimal number of participants is:  " +
               str(minimal_number_of_participants))
    click.echo("The maximal number of participants is:  " +
               str(maximal_number_of_participants))
    click.echo("The address of the locker contract is:  " +
               str(locker_address))
    click.echo("The locker initialized value is:        " +
               str(locker_initialized))
    if contracts.slasher is not None:
        click.echo("The address of the slasher contract is: " +
                   str(slasher_address))
        click.echo("The slasher initialized value is:       " +
                   str(slasher_initialized))
    else:
        click.secho("The slasher contract cannot be found.", fg="red")

    click.echo(
        "------------------------------------    ------------------------------------------"
    )

    click.echo("The auction state is:                   " +
               str(auction_state_value) + " (" + str(auction_state.name) + ")")
    click.echo("The start time is:                      " +
               format_timestamp(start_time))
    click.echo("The close time is:                      " +
               format_timestamp(close_time))
    if auction_state == auction_state.Started:
        click.echo("The current price is:                   " +
                   str(current_price_in_eth) + " eth")
    click.echo("The last slot price is:                  " +
               str(last_slot_price))
    click.echo("Deposits will be locked until:          " +
               format_timestamp(locker_release_timestamp))

    click.echo(
        "------------------------------------    ------------------------------------------"
    )

    if locker_address_in_auction_contract != locker_address:
        click.secho(
            "The locker address in the auction contract does not match to the locker address",
            fg="red",
        )
    if auction_address_in_locker_contract != auction_address:
        click.secho(
            "The auction address in the locker contract does not match the auction address",
            fg="red",
        )
    if slasher_address_in_locker_contract != slasher_address:
        click.secho(
            "The slasher address in the locker contract does not match the slasher address",
            fg="red",
        )
    if locker_address_in_slasher_contract != locker_address:
        click.secho(
            "The locker address in the slasher contract does not match the slasher address",
            fg="red",
        )
示例#20
0
def deploy(
    start_price: int,
    auction_duration: int,
    minimal_number_of_participants: int,
    maximal_number_of_participants: int,
    release_timestamp: int,
    release_date: pendulum.DateTime,
    keystore: str,
    jsonrpc: str,
    gas: int,
    gas_price: int,
    nonce: int,
    auto_nonce: bool,
) -> None:

    if release_date is not None and release_timestamp is not None:
        raise click.BadParameter(
            f"Both --release-date and --release-timestamp have been specified")
    if release_date is None and release_timestamp is None:
        raise click.BadParameter(
            f"Please specify a release date with --release-date or --release-timestamp"
        )

    if release_date is not None:
        release_timestamp = int(release_date.timestamp())

    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)

    auction_options = AuctionOptions(
        start_price * ETH_IN_WEI,
        auction_duration,
        minimal_number_of_participants,
        maximal_number_of_participants,
        release_timestamp,
    )

    nonce = get_nonce(web3=web3,
                      nonce=nonce,
                      auto_nonce=auto_nonce,
                      private_key=private_key)
    transaction_options = build_transaction_options(gas=gas,
                                                    gas_price=gas_price,
                                                    nonce=nonce)

    contracts = deploy_auction_contracts(
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
        auction_options=auction_options,
    )

    initialize_auction_contracts(
        web3=web3,
        transaction_options=transaction_options,
        contracts=contracts,
        release_timestamp=release_timestamp,
        private_key=private_key,
    )

    click.echo("Auction address: " + contracts.auction.address)
    click.echo("Deposit locker address: " + contracts.locker.address)
    click.echo("Validator slasher address: " + contracts.slasher.address)
示例#21
0
def status(auction_address, jsonrpc):

    web3 = connect_to_json_rpc(jsonrpc)

    contracts = get_deployed_auction_contracts(web3, auction_address)

    # constants throughout auction
    duration_in_days = contracts.auction.functions.auctionDurationInDays(
    ).call()
    start_price_in_biggest_unit = (
        contracts.auction.functions.startPrice().call() / ETH_IN_WEI)
    minimal_number_of_participants = (
        contracts.auction.functions.minimalNumberOfParticipants().call())
    maximal_number_of_participants = (
        contracts.auction.functions.maximalNumberOfParticipants().call())
    bid_token_address = get_bid_token_address(web3, auction_address)
    locker_address = contracts.locker.address
    locker_initialized = contracts.locker.functions.initialized().call()
    locker_release_timestamp = contracts.locker.functions.releaseTimestamp(
    ).call()

    slasher_address = ZERO_ADDRESS
    slasher_initialized = False
    if contracts.slasher is not None:
        slasher_address = contracts.slasher.address
        slasher_initialized = contracts.slasher.functions.initialized().call()

    # variables
    auction_state_value = contracts.auction.functions.auctionState().call()
    auction_state = AuctionState(auction_state_value)
    start_time = contracts.auction.functions.startTime().call()
    close_time = contracts.auction.functions.closeTime().call()
    last_slot_price = contracts.auction.functions.lowestSlotPrice().call()
    current_price_in_eth = 0
    if auction_state == AuctionState.Started:
        current_price_in_eth = (
            contracts.auction.functions.currentPrice().call() / ETH_IN_WEI)

    click.echo("The auction duration is:                " +
               str(duration_in_days) + " days")
    click.echo("The starting price is:                  " +
               str(start_price_in_biggest_unit) + " ETH/TLN")
    click.echo("The minimal number of participants is:  " +
               str(minimal_number_of_participants))
    click.echo("The maximal number of participants is:  " +
               str(maximal_number_of_participants))
    if bid_token_address is not None:
        click.echo("The address of the bid token is:        " +
                   str(bid_token_address))
    click.echo("The address of the locker contract is:  " +
               str(locker_address))
    click.echo("The locker initialized value is:        " +
               str(locker_initialized))
    if contracts.slasher is not None:
        click.echo("The address of the slasher contract is: " +
                   str(slasher_address))
        click.echo("The slasher initialized value is:       " +
                   str(slasher_initialized))
    else:
        click.secho("The slasher contract cannot be found.", fg="red")

    click.echo(
        "------------------------------------    ------------------------------------------"
    )

    click.echo("The auction state is:                   " +
               str(auction_state_value) + " (" + str(auction_state.name) + ")")
    click.echo("The start time is:                      " +
               format_timestamp(start_time))
    click.echo("The close time is:                      " +
               format_timestamp(close_time))
    if auction_state == auction_state.Started:
        click.echo("The current price is:                   " +
                   str(current_price_in_eth) + " ETH/TLN")
    click.echo("The last slot price is:                 " +
               str(last_slot_price))
    click.echo("Deposits will be locked until:          " +
               format_timestamp(locker_release_timestamp))

    click.echo(
        "------------------------------------    ------------------------------------------"
    )

    warning_messages = get_errors_messages_on_contracts_links(contracts)
    if warning_messages:
        click.secho(linesep.join(warning_messages), fg="red")
示例#22
0
def deploy(
    start_price: int,
    auction_duration: int,
    minimal_number_of_participants: int,
    maximal_number_of_participants: int,
    use_token: bool,
    token_address: Optional[str],
    release_timestamp: int,
    release_date: pendulum.DateTime,
    keystore: str,
    jsonrpc: str,
    gas: int,
    gas_price: int,
    nonce: int,
    auto_nonce: bool,
    already_deployed_auction,
    already_deployed_locker,
    already_deployed_slasher,
) -> None:

    if use_token and token_address is None:
        raise click.BadParameter(
            "The flag `use-token` was provided, the token address must also be provided via `token-address`"
        )
    if token_address is not None and not use_token:
        raise click.BadParameter(
            "A token address has been provided, "
            "please use the flag --use-token to confirm you want to deploy a token auction"
        )

    if release_date is not None and release_timestamp is not None:
        raise click.BadParameter(
            "Both --release-date and --release-timestamp have been specified")
    if release_date is None and release_timestamp is None:
        raise click.BadParameter(
            "Please specify a release date with --release-date or --release-timestamp"
        )

    if already_deployed_auction is not None and already_deployed_locker is None:
        raise click.BadOptionUsage(
            "--auction",
            "Cannot resume deployment from already deployed auction without already deployed locker. "
            "Locker address is part of auction's constructor argument.",
        )

    if release_date is not None:
        release_timestamp = int(release_date.timestamp())

    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)

    auction_options = AuctionOptions(
        start_price * ETH_IN_WEI,
        auction_duration,
        minimal_number_of_participants,
        maximal_number_of_participants,
        release_timestamp,
        token_address,
    )

    nonce = get_nonce(web3=web3,
                      nonce=nonce,
                      auto_nonce=auto_nonce,
                      private_key=private_key)
    transaction_options = build_transaction_options(gas=gas,
                                                    gas_price=gas_price,
                                                    nonce=nonce)

    contracts = deploy_auction_contracts(
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
        auction_options=auction_options,
        already_deployed_contracts=DeployedContractsAddresses(
            already_deployed_locker, already_deployed_slasher,
            already_deployed_auction),
    )

    initialize_auction_contracts(
        web3=web3,
        transaction_options=transaction_options,
        contracts=contracts,
        release_timestamp=release_timestamp,
        token_address=token_address,
        private_key=private_key,
    )
    slasher: Contract = contracts.slasher

    click.echo("Auction address: " + contracts.auction.address)
    click.echo("Deposit locker address: " + contracts.locker.address)
    click.echo("Validator slasher address: " + slasher.address)
    warning_messages = get_errors_messages_on_contracts_links(contracts)
    if warning_messages:
        warning_messages.append(
            "Verify what is wrong with `auction-deploy status`.")
        click.secho(linesep.join(warning_messages), fg="red")
示例#23
0
def test(
    jsonrpc: str,
    file: str,
    gas: int,
    gas_price: int,
    nonce: int,
    auto_nonce: bool,
    keystore: str,
    currency_network_contract_name: str,
):
    """Deploy three test currency network contracts connected to an exchange contract and an unwrapping ether contract.
    Also deploys an identity proxy factory and a identity implementation contract.
    This can be used for testing"""

    expiration_time = 4_102_444_800  # 01/01/2100

    network_settings = [
        {
            "name": "Cash",
            "symbol": "CASH",
            "decimals": 4,
            "fee_divisor": 1000,
            "default_interest_rate": 0,
            "custom_interests": True,
            "expiration_time": expiration_time,
        },
        {
            "name": "Work Hours",
            "symbol": "HOU",
            "decimals": 4,
            "fee_divisor": 0,
            "default_interest_rate": 1000,
            "custom_interests": False,
            "expiration_time": expiration_time,
        },
        {
            "name": "Beers",
            "symbol": "BEER",
            "decimals": 0,
            "fee_divisor": 0,
            "custom_interests": False,
            "expiration_time": expiration_time,
        },
    ]

    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)
    nonce = get_nonce(web3=web3,
                      nonce=nonce,
                      auto_nonce=auto_nonce,
                      private_key=private_key)
    transaction_options = build_transaction_options(gas=gas,
                                                    gas_price=gas_price,
                                                    nonce=nonce)
    networks, exchange, unw_eth = deploy_networks(
        web3,
        network_settings,
        currency_network_contract_name=currency_network_contract_name,
    )
    identity_implementation = deploy_identity_implementation(
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key)
    identity_proxy_factory = deploy_identity_proxy_factory(
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key)
    addresses = dict()
    network_addresses = [network.address for network in networks]
    exchange_address = exchange.address
    unw_eth_address = unw_eth.address
    addresses["networks"] = network_addresses
    addresses["exchange"] = exchange_address
    addresses["unwEth"] = unw_eth_address
    addresses["identityImplementation"] = identity_implementation.address
    addresses["identityProxyFactory"] = identity_proxy_factory.address

    if file:
        with open(file, "w") as outfile:
            json.dump(addresses, outfile)

    click.echo("Exchange: {}".format(to_checksum_address(exchange_address)))
    click.echo("Unwrapping ether: {}".format(
        to_checksum_address(unw_eth_address)))
    click.echo("Identity proxy factory: {}".format(
        to_checksum_address(identity_proxy_factory.address)))
    click.echo("Identity implementation: {}".format(
        to_checksum_address(identity_implementation.address)))
    for settings, address in zip(network_settings, network_addresses):
        click.echo("CurrencyNetwork({settings}) at {address}".format(
            settings=settings, address=to_checksum_address(address)))
示例#24
0
def test(
    jsonrpc: str,
    file: str,
    gas: int,
    gas_price: int,
    nonce: int,
    keystore: str,
    currency_network_contract_name: str,
):
    """Deploy three test currency network contracts connected to an exchange contract and an unwrapping ether contract.
    Also deploys an identity proxy factory and an identity implementation contract.
    This can be used for testing"""

    expiration_time = 4_102_444_800  # 01/01/2100

    network_settings = [
        NetworkSettings(
            name="Euro",
            symbol="EUR",
            decimals=4,
            fee_divisor=1000,
            default_interest_rate=0,
            custom_interests=True,
            expiration_time=expiration_time,
            prevent_mediator_interests=False,
        ),
        NetworkSettings(
            name="Hours",
            symbol="HOURS",
            decimals=4,
            fee_divisor=0,
            default_interest_rate=1000,
            custom_interests=False,
            expiration_time=expiration_time,
            prevent_mediator_interests=False,
        ),
        NetworkSettings(
            name="Beer",
            symbol="BEER",
            decimals=0,
            fee_divisor=0,
            default_interest_rate=0,
            custom_interests=False,
            expiration_time=expiration_time,
            prevent_mediator_interests=False,
        ),
    ]

    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)
    nonce = get_nonce(web3=web3, nonce=nonce, private_key=private_key)
    transaction_options = build_transaction_options(
        gas=gas, gas_price=gas_price, nonce=nonce
    )
    networks, exchange, unw_eth = deploy_networks(
        web3,
        network_settings,
        currency_network_contract_name=currency_network_contract_name,
        transaction_options=transaction_options,
    )
    identity_implementation = deploy_identity_implementation(
        web3=web3, transaction_options=transaction_options, private_key=private_key
    )
    second_identity_implementation = deploy_identity_implementation(
        web3=web3, transaction_options=transaction_options, private_key=private_key
    )
    identity_proxy_factory = deploy_identity_proxy_factory(
        web3=web3, transaction_options=transaction_options, private_key=private_key
    )
    addresses = dict()
    network_addresses = [network.address for network in networks]
    exchange_address = exchange.address
    unw_eth_address = unw_eth.address
    addresses["networks"] = network_addresses
    addresses["exchange"] = exchange_address
    addresses["unwEth"] = unw_eth_address
    # TODO: remove address["identityImplementation"], left for backward compatibility
    addresses["identityImplementation"] = identity_implementation.address
    addresses["identityProxyFactory"] = identity_proxy_factory.address
    addresses["identityImplementations"] = [
        identity_implementation.address,
        second_identity_implementation.address,
    ]

    if file:
        with open(file, "w") as outfile:
            json.dump(addresses, outfile)

    click.echo("Exchange: {}".format(to_checksum_address(exchange_address)))
    click.echo("Unwrapping ether: {}".format(to_checksum_address(unw_eth_address)))
    click.echo(
        "Identity proxy factory: {}".format(
            to_checksum_address(identity_proxy_factory.address)
        )
    )
    click.echo(
        "Identity implementations: {} and {}".format(
            to_checksum_address(identity_implementation.address),
            to_checksum_address(second_identity_implementation.address),
        )
    )
    for settings, address in zip(network_settings, network_addresses):
        click.echo(
            "CurrencyNetwork({settings}) at {address}".format(
                settings=settings, address=to_checksum_address(address)
            )
        )
示例#25
0
def currency_network_proxy(
    name: str,
    symbol: str,
    decimals: int,
    jsonrpc: str,
    fee_rate: float,
    default_interest_rate: float,
    custom_interests: bool,
    prevent_mediator_interests: bool,
    expiration_time: int,
    expiration_date: pendulum.DateTime,
    beacon_address: str,
    owner_address: str,
    gas: int,
    gas_price: int,
    nonce: int,
    keystore: str,
):
    """Deploy an AdministrativeProxy contract eventually pointing towards a currency network contract
    with custom network settings and proxy owner.
    If the currency network contract is of type AdministrativeProxy,
    one may need to unfreeze it and remove the owner to use it."""
    if custom_interests and default_interest_rate != 0.0:
        raise click.BadParameter(
            "Custom interests can only be set without a"
            " default interest rate, but was {}%.".format(default_interest_rate)
        )

    if prevent_mediator_interests and not custom_interests:
        raise click.BadParameter(
            "Prevent mediator interests is not necessary if custom interests are disabled."
        )

    if expiration_date is not None and expiration_time is not None:
        raise click.BadParameter(
            "Both --expiration-date and --expiration-times have been specified."
        )

    if expiration_date is None and expiration_time is None:
        expiration_time = 0

    if expiration_date is not None:
        expiration_time = int(expiration_date.timestamp())

    fee_divisor = 1 / fee_rate * 100 if fee_rate != 0 else 0
    if int(fee_divisor) != fee_divisor:
        raise click.BadParameter("This fee rate is not usable")
    fee_divisor = int(fee_divisor)

    default_interest_rate = default_interest_rate * 100
    if int(default_interest_rate) != default_interest_rate:
        raise click.BadParameter("This default interest rate is not usable")
    default_interest_rate = int(default_interest_rate)

    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)
    nonce = get_nonce(web3=web3, nonce=nonce, private_key=private_key)
    transaction_options = build_transaction_options(
        gas=gas, gas_price=gas_price, nonce=nonce
    )

    network_settings = NetworkSettings(
        name=name,
        symbol=symbol,
        decimals=decimals,
        fee_divisor=fee_divisor,
        default_interest_rate=default_interest_rate,
        custom_interests=custom_interests,
        prevent_mediator_interests=prevent_mediator_interests,
        expiration_time=expiration_time,
    )

    contract = deploy_currency_network_proxy(
        web3=web3,
        network_settings=network_settings,
        beacon_address=beacon_address,
        owner_address=owner_address,
        private_key=private_key,
        transaction_options=transaction_options,
    )

    click.echo(
        "CurrencyNetwork(name={name}, symbol={symbol}, "
        "decimals={decimals}, fee_divisor={fee_divisor}, "
        "default_interest_rate={default_interest_rate}, "
        "custom_interests={custom_interests}, "
        "prevent_mediator_interests={prevent_mediator_interests}): {address}".format(
            name=name,
            symbol=symbol,
            decimals=decimals,
            fee_divisor=fee_divisor,
            default_interest_rate=default_interest_rate,
            custom_interests=custom_interests,
            prevent_mediator_interests=prevent_mediator_interests,
            address=to_checksum_address(contract.address),
        )
    )
示例#26
0
def currencynetwork(
    name: str,
    symbol: str,
    decimals: int,
    jsonrpc: str,
    fee_rate: float,
    default_interest_rate: float,
    custom_interests: bool,
    prevent_mediator_interests: bool,
    exchange_contract: str,
    currency_network_contract_name: str,
    expiration_time: int,
    expiration_date: pendulum.DateTime,
    gas: int,
    gas_price: int,
    nonce: int,
    auto_nonce: bool,
    keystore: str,
):
    """Deploy a currency network contract with custom settings and optionally connect it to an exchange contract"""
    if exchange_contract is not None and not is_checksum_address(
            exchange_contract):
        raise click.BadParameter(
            "{} is not a valid address.".format(exchange_contract))

    if custom_interests and default_interest_rate != 0.0:
        raise click.BadParameter("Custom interests can only be set without a"
                                 " default interest rate, but was {}%.".format(
                                     default_interest_rate))

    if prevent_mediator_interests and not custom_interests:
        raise click.BadParameter(
            "Prevent mediator interests is not necessary if custom interests are disabled."
        )

    if expiration_date is not None and expiration_time is not None:
        raise click.BadParameter(
            f"Both --expiration-date and --expiration-times have been specified."
        )

    if expiration_date is None and expiration_time is None:
        expiration_time = 0

    if expiration_date is not None:
        expiration_time = int(expiration_date.timestamp())

    fee_divisor = 1 / fee_rate * 100 if fee_rate != 0 else 0
    if int(fee_divisor) != fee_divisor:
        raise click.BadParameter("This fee rate is not usable")
    fee_divisor = int(fee_divisor)

    default_interest_rate = default_interest_rate * 100
    if int(default_interest_rate) != default_interest_rate:
        raise click.BadParameter("This default interest rate is not usable")
    default_interest_rate = int(default_interest_rate)

    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)
    nonce = get_nonce(web3=web3,
                      nonce=nonce,
                      auto_nonce=auto_nonce,
                      private_key=private_key)
    transaction_options = build_transaction_options(gas=gas,
                                                    gas_price=gas_price,
                                                    nonce=nonce)

    contract = deploy_network(
        web3,
        name,
        symbol,
        decimals,
        fee_divisor=fee_divisor,
        default_interest_rate=default_interest_rate,
        custom_interests=custom_interests,
        prevent_mediator_interests=prevent_mediator_interests,
        exchange_address=exchange_contract,
        currency_network_contract_name=currency_network_contract_name,
        expiration_time=expiration_time,
        transaction_options=transaction_options,
        private_key=private_key,
    )

    click.echo("CurrencyNetwork(name={name}, symbol={symbol}, "
               "decimals={decimals}, fee_divisor={fee_divisor}, "
               "default_interest_rate={default_interest_rate}, "
               "custom_interests={custom_interests}, "
               "prevent_mediator_interests={prevent_mediator_interests}, "
               "exchange_address={exchange_address}): {address}".format(
                   name=name,
                   symbol=symbol,
                   decimals=decimals,
                   fee_divisor=fee_divisor,
                   default_interest_rate=default_interest_rate,
                   custom_interests=custom_interests,
                   prevent_mediator_interests=prevent_mediator_interests,
                   exchange_address=exchange_contract,
                   address=to_checksum_address(contract.address),
               ))
示例#27
0
def status(jsonrpc: str, merkle_drop_address: str):
    web3 = connect_to_json_rpc(jsonrpc)

    exit_code = EXIT_OK_CODE
    status_dict = get_merkle_drop_status(web3, merkle_drop_address)

    click.echo(f"Token Address:             {status_dict['token_address']}")
    click.echo(
        f"Token Name:                {status_dict['token_name']} ({status_dict['token_symbol']})"
    )
    click.echo(
        f"Token Balance:             {status_dict['token_balance'] / 10**status_dict['token_decimals']}"
    )

    click.echo("")

    click.echo(f"Merkle Drop Address:       {status_dict['address']}")
    click.echo(f"Merkle Root:               {status_dict['root'].hex()}")

    click.echo("")

    click.echo(
        f"Initial Balance:           {status_dict['initial_balance'] / 10**status_dict['token_decimals']}"
    )
    click.echo(
        f"Remaining Value:           {status_dict['remaining_value'] / 10**status_dict['token_decimals']}"
    )
    click.echo(
        f"Spent tokens:              {status_dict['spent_tokens'] / 10**status_dict['token_decimals']}"
    )
    click.echo(
        f"Decayed Remaining Value:   {status_dict['decayed_remaining_value'] / 10**status_dict['token_decimals']}"
    )

    if status_dict["token_balance"] < status_dict["decayed_remaining_value"]:
        click.secho("Token Balance is lower than Decayed Remaining Value.",
                    fg="red")
        exit_code = EXIT_ERROR_CODE

    click.echo("")

    click.echo(
        f"Decay Start Time:          {pendulum.from_timestamp(status_dict['decay_start_time'])}"
        f" ({pendulum.from_timestamp(status_dict['decay_start_time']).diff_for_humans()})"
    )
    click.echo(
        f"Decay Duration in Seconds: {status_dict['decay_duration_in_seconds']}"
        f" ({pendulum.now().add(seconds=status_dict['decay_duration_in_seconds']).diff_for_humans(absolute=True)})"
    )

    end_timestamp = pendulum.from_timestamp(
        status_dict["decay_start_time"] +
        status_dict["decay_duration_in_seconds"])
    click.echo(f"Decay End Time:            "
               f"{end_timestamp}"
               f" ({end_timestamp.diff_for_humans()})")

    remaining_seconds = (status_dict["decay_start_time"] +
                         status_dict["decay_duration_in_seconds"]
                         ) - pendulum.now().int_timestamp
    click.echo(
        f"Remaining Time in Seconds: "
        f"{remaining_seconds}"
        f" ({pendulum.now().add(seconds=remaining_seconds).diff_for_humans(absolute=True)})"
    )

    sys.exit(exit_code)