#!/usr/bin/python3
import time
from brownie import (
    DataTypes,
    TransparentUpgradeableProxy,
    ProxyAdmin,
    config,
    network,
    Contract,
)
from scripts.helpful_scripts import get_account, encode_function_data


def main():
    account = get_account()
    print(config["networks"][network.show_active()])
    print(f"Deploying to {network.show_active()}")
    data_types = DataTypes.deploy(
        {"from": account},
        publish_source=config["networks"][network.show_active()]["verify"],
    )
    # Optional, deploy the ProxyAdmin and use that as the admin contract
    proxy_admin = ProxyAdmin.deploy(
        {"from": account},
        publish_source=config["networks"][network.show_active()]["verify"],
    )

    # If we want an intializer function we can add
    # `initializer=box.store, 1`
    # to simulate the initializer being the `store` function
    # with a `newValue` of 1
    # data_types_encoded_initializer_function = encode_function_data(data_types.setDataTypes)
    data_types_encoded_initializer_function = encode_function_data(
        data_types.setDataTypes, 10
    )
    proxy = TransparentUpgradeableProxy.deploy(
        data_types.address,
        proxy_admin.address,
        data_types_encoded_initializer_function,
        # gas limit removed fort an issue not very clear
        # {"from": account, "gas_limit": 100000000000},
        {"from": account},
        publish_source=config["networks"][network.show_active()]["verify"],
    )
    print(f"Proxy deployed to {proxy} ! You can now upgrade it to dataTypesV2!")
    proxy_data_types = Contract.from_abi("DataTypes", proxy.address, DataTypes.abi)

[((15, 14, 15, 27), 'scripts.helpful_scripts.get_account', 'get_account', ({}, {}), '()', False, 'from scripts.helpful_scripts import get_account, encode_function_data\n'), ((33, 46, 35, 5), 'scripts.helpful_scripts.encode_function_data', 'encode_function_data', ({(34, 8, 34, 31): 'data_types.setDataTypes', (34, 33, 34, 35): '10'}, {}), '(data_types.setDataTypes, 10)', False, 'from scripts.helpful_scripts import get_account, encode_function_data\n'), ((46, 23, 46, 83), 'brownie.Contract.from_abi', 'Contract.from_abi', ({(46, 41, 46, 52): '"""DataTypes"""', (46, 54, 46, 67): 'proxy.address', (46, 69, 46, 82): 'DataTypes.abi'}, {}), "('DataTypes', proxy.address, DataTypes.abi)", False, 'from brownie import DataTypes, TransparentUpgradeableProxy, ProxyAdmin, config, network, Contract\n'), ((16, 29, 16, 50), 'brownie.network.show_active', 'network.show_active', ({}, {}), '()', False, 'from brownie import DataTypes, TransparentUpgradeableProxy, ProxyAdmin, config, network, Contract\n'), ((17, 26, 17, 47), 'brownie.network.show_active', 'network.show_active', ({}, {}), '()', False, 'from brownie import DataTypes, TransparentUpgradeableProxy, ProxyAdmin, config, network, Contract\n'), ((20, 42, 20, 63), 'brownie.network.show_active', 'network.show_active', ({}, {}), '()', False, 'from brownie import DataTypes, TransparentUpgradeableProxy, ProxyAdmin, config, network, Contract\n'), ((25, 42, 25, 63), 'brownie.network.show_active', 'network.show_active', ({}, {}), '()', False, 'from brownie import DataTypes, TransparentUpgradeableProxy, ProxyAdmin, config, network, Contract\n'), ((43, 42, 43, 63), 'brownie.network.show_active', 'network.show_active', ({}, {}), '()', False, 'from brownie import DataTypes, TransparentUpgradeableProxy, ProxyAdmin, config, network, Contract\n')]