def initcode(args):
     interface = get_pinned_proxy_interface()
     return build_initcode(
         contract_abi=interface["abi"],
         contract_bytecode=interface["bytecode"],
         constructor_args=args,
     )
Esempio n. 2
0
def test_build_initcode_with_constructor(contract_assets):
    contract_interface = contract_assets["TestContract"]
    initcode = build_initcode(
        contract_bytecode=contract_interface["bytecode"],
        contract_abi=contract_interface["abi"],
        constructor_args=[123456],
    )

    assert is_hex(initcode)
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
Esempio n. 4
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 = send_function_call_transaction(
        function_call,
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )
    increase_transaction_options_nonce(transaction_options)

    deployment_event = factory.events.ProxyDeployment().processReceipt(receipt)
    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
Esempio n. 5
0
def non_payable_contract_inticode(contract_assets):
    interface = contract_assets["Identity"]
    return build_initcode(contract_abi=interface["abi"],
                          contract_bytecode=interface["bytecode"])
Esempio n. 6
0
def test_contract_initcode(contract_assets):

    interface = contract_assets["TestContract"]
    return build_initcode(contract_abi=interface["abi"],
                          contract_bytecode=interface["bytecode"])
Esempio n. 7
0
def test_build_initcode_no_constructor(contract_assets):
    contract_interface = contract_assets["OtherContract"]
    initcode = build_initcode(contract_bytecode=contract_interface["bytecode"])

    assert is_hex(initcode)