text: from brownie import accounts, config, network
  
  
  def get_account(index=0):
      if index:
          return accounts[index]
      if network.show_active() in ["development", "ganache-local"]:
          return accounts[index]
      return accounts.add(config["wallets"]["from_key"])
  
  
  def encode_function_data(initializer=None, *args):
      """Encodes the function call so we can work with an initializer.
  
      Args:
          initializer ([brownie.network.contract.ContractTx], optional):
          The initializer function we want to call. 
  
          args (Any, optional):
          The arguments to pass to the initializer function
  
      Returns:
          [bytes]: Return the encoded bytes.
      """
      if not len(args):
          args = b""
  
      if initializer:
          return initializer.encode_input(*args)
  
      return b""
  
  
  def upgrade(
      account,
      proxy,
      newimplementation_address,
      proxy_admin_contract=None,
      initializer=None,
      *args
  ):
      transaction = None
      if proxy_admin_contract:
          if initializer:
              encoded_function_call = encode_function_data(initializer, *args)
              transaction = proxy_admin_contract.upgradeAndCall(
                  proxy.address,
                  newimplementation_address,
                  encoded_function_call,
                  {"from": account},
              )
          else:
              transaction = proxy_admin_contract.upgrade(
                  proxy.address, newimplementation_address, {"from": account}
              )
      else:
          if initializer:
              encoded_function_call = encode_function_data(initializer, *args)
              transaction = proxy.upgradeToAndCall(
                  newimplementation_address, encoded_function_call, {"from": account}
              )
          else:
              transaction = proxy.upgradeTo(newimplementation_address, {"from": account})
      return transaction
  