Ejemplo n.º 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,
    )
Ejemplo n.º 2
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,
    )
Ejemplo n.º 3
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,
    )
Ejemplo n.º 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()}"
    )
Ejemplo n.º 5
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)))
Ejemplo n.º 6
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)
        )
    )
Ejemplo n.º 7
0
def identity_implementation(
    jsonrpc: str, gas: int, gas_price: int, nonce: int, 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, 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)
        )
    )
Ejemplo n.º 8
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),
        )
    )
Ejemplo n.º 9
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)
            )
        )
Ejemplo n.º 10
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,
    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(
            "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_network(
        web3,
        network_settings,
        exchange_address=exchange_contract,
        currency_network_contract_name=currency_network_contract_name,
        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),
        )
    )