Exemplo n.º 1
0
def deploy_beacon(
    web3,
    implementation_address,
    owner_address,
    *,
    private_key: bytes = None,
    transaction_options: Dict = None,
):
    if transaction_options is None:
        transaction_options = {}
    beacon = deploy(
        "ProxyBeacon",
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
        constructor_args=(implementation_address, ),
    )
    increase_transaction_options_nonce(transaction_options)
    if owner_address != beacon.functions.owner().call():
        transfer_ownership = beacon.functions.transferOwnership(owner_address)
        wait_for_successful_function_call(
            transfer_ownership,
            web3=web3,
            transaction_options=transaction_options,
            private_key=private_key,
        )
    return beacon
Exemplo n.º 2
0
def deploy_unw_eth(
    *,
    web3: Web3,
    transaction_options: Dict = None,
    private_key: bytes = None,
    exchange_address=None,
):
    if transaction_options is None:
        transaction_options = {}

    unw_eth = deploy(
        "UnwEth",
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )

    increase_transaction_options_nonce(transaction_options)

    if exchange_address is not None:
        function_call = unw_eth.functions.addAuthorizedAddress(
            exchange_address)
        wait_for_successful_function_call(
            function_call,
            web3=web3,
            transaction_options=transaction_options,
            private_key=private_key,
        )
        increase_transaction_options_nonce(transaction_options)

    return unw_eth
Exemplo n.º 3
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,
    )
Exemplo n.º 4
0
    def call_contract_function_with_tx(self, function_call):
        tx_hash = send_function_call_transaction(
            function_call,
            web3=self.web3,
            transaction_options=self.transaction_options,
            private_key=self.private_key,
        )
        increase_transaction_options_nonce(self.transaction_options)
        self.tx_queue.add(tx_hash)

        if len(self.tx_queue) >= self.max_tx_queue_size:
            self.wait_for_successfull_txs_in_queue()
Exemplo n.º 5
0
def deploy_proxied_identity(
    web3,
    factory_address,
    implementation_address,
    signature,
    *,
    transaction_options: Dict = None,
    private_key: bytes = None,
):
    if transaction_options is None:
        transaction_options = {}

    owner = recover_proxy_deployment_signature_owner(web3, factory_address,
                                                     implementation_address,
                                                     signature)

    interface = get_pinned_proxy_interface()
    initcode = build_initcode(
        contract_abi=interface["abi"],
        contract_bytecode=interface["bytecode"],
        constructor_args=[owner],
    )

    factory_interface = get_contract_interface("IdentityProxyFactory")
    factory = web3.eth.contract(address=factory_address,
                                abi=factory_interface["abi"])

    function_call = factory.functions.deployProxy(initcode,
                                                  implementation_address,
                                                  signature)
    receipt = wait_for_successful_function_call(
        function_call,
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )
    increase_transaction_options_nonce(transaction_options)

    # We know there are events in the receipt that do not correspond to the factory contract
    # for which web3 will raise a warning. So we use `errors=EventLogErrorFlags.Discard`
    deployment_event = factory.events.ProxyDeployment().processReceipt(
        receipt, errors=EventLogErrorFlags.Discard)
    proxy_address = deployment_event[0]["args"]["proxyAddress"]

    computed_proxy_address = build_create2_address(factory_address, initcode)
    assert (
        computed_proxy_address == proxy_address
    ), "The computed proxy address does not match the deployed address found via events"

    identity_interface = get_contract_interface("Identity")
    proxied_identity = web3.eth.contract(address=proxy_address,
                                         abi=identity_interface["abi"])
    return proxied_identity
Exemplo n.º 6
0
def deploy_identity_implementation(*,
                                   web3: Web3,
                                   transaction_options: Dict = None,
                                   private_key: bytes = None):
    if transaction_options is None:
        transaction_options = {}

    indentity_implementation = deploy(
        "Identity",
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )
    increase_transaction_options_nonce(transaction_options)
    return indentity_implementation
Exemplo n.º 7
0
def deploy_exchange(*,
                    web3: Web3,
                    transaction_options: Dict = None,
                    private_key: bytes = None):
    if transaction_options is None:
        transaction_options = {}

    exchange = deploy(
        "Exchange",
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )
    increase_transaction_options_nonce(transaction_options)
    return exchange
Exemplo n.º 8
0
def deploy_identity(web3,
                    owner_address,
                    chain_id=None,
                    transaction_options: Dict = None):
    if transaction_options is None:
        transaction_options = {}
    identity = deploy("Identity",
                      web3=web3,
                      transaction_options=transaction_options)
    increase_transaction_options_nonce(transaction_options)
    if chain_id is None:
        chain_id = get_chain_id(web3)
    function_call = identity.functions.init(owner_address, chain_id)
    wait_for_successful_function_call(function_call,
                                      web3=web3,
                                      transaction_options=transaction_options)
    increase_transaction_options_nonce(transaction_options)

    return identity
Exemplo n.º 9
0
def deploy_network(
    web3,
    network_settings: NetworkSettings,
    exchange_address=None,
    currency_network_contract_name=None,
    transaction_options: Dict = None,
    private_key=None,
    authorized_addresses=None,
):
    if transaction_options is None:
        transaction_options = {}
    if authorized_addresses is None:
        authorized_addresses = []

    # CurrencyNetwork is the standard contract to deploy, If we're running
    # tests or trying to export data for testing the python implementation of
    # private functions, we may want deploy the TestCurrencyNetwork contract
    # instead.
    if currency_network_contract_name is None:
        currency_network_contract_name = "CurrencyNetwork"

    currency_network = deploy(
        currency_network_contract_name,
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )
    increase_transaction_options_nonce(transaction_options)

    init_currency_network(
        web3=web3,
        network_settings=network_settings,
        currency_network=currency_network,
        exchange_address=exchange_address,
        authorized_addresses=authorized_addresses,
        transaction_options=transaction_options,
        private_key=private_key,
    )
    increase_transaction_options_nonce(transaction_options)

    return currency_network
Exemplo n.º 10
0
def deploy_identity_proxy_factory(
    *,
    chain_id=None,
    web3: Web3,
    transaction_options: Dict = None,
    private_key: bytes = None,
):
    if transaction_options is None:
        transaction_options = {}

    if chain_id is None:
        chain_id = get_chain_id(web3)

    identity_proxy_factory = deploy(
        "IdentityProxyFactory",
        constructor_args=(chain_id, ),
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )
    increase_transaction_options_nonce(transaction_options)
    return identity_proxy_factory
Exemplo n.º 11
0
def deploy_currency_network_proxy(
    *,
    web3,
    network_settings: NetworkSettings,
    exchange_address=None,
    authorized_addresses=None,
    beacon_address,
    owner_address,
    private_key: bytes = None,
    transaction_options: Dict = None,
):
    verify_owner_not_deployer(web3, owner_address, private_key)

    if transaction_options is None:
        transaction_options = {}

    proxy = deploy(
        "AdministrativeProxy",
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
        constructor_args=(beacon_address, ""),
    )
    increase_transaction_options_nonce(transaction_options)

    change_owner = proxy.functions.changeAdmin(owner_address)
    wait_for_successful_function_call(
        change_owner,
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )
    increase_transaction_options_nonce(transaction_options)
    assert proxy.functions.admin().call({"from":
                                         owner_address}) == owner_address

    interface = get_contract_interface("CurrencyNetwork")
    proxied_currency_network = web3.eth.contract(
        abi=interface["abi"],
        address=proxy.address,
        bytecode=interface["bytecode"])

    init_currency_network(
        web3=web3,
        network_settings=network_settings,
        currency_network=proxied_currency_network,
        exchange_address=exchange_address,
        authorized_addresses=authorized_addresses,
        transaction_options=transaction_options,
        private_key=private_key,
    )
    increase_transaction_options_nonce(transaction_options)

    return proxied_currency_network