Deploying Upgradeable Proxies and Proxy Admin from Factory contract

@frangio Here is my initial attempt. Please let me know if its in the right direction.

It looks too easy to be true. I created two contracts the UpgradeableToken and the Factory contract which deploys the Tokens. I realized I don’t need a ProxyAdmin for UUPS.

One of the doubts I had was which type of “Proxy” should I use for UUPS. I went for ERC1967Proxy not sure if it’s the correct choice.

MyTokenUpgradeable

// SPDX-License-Identifier: MIT

pragma solidity 0.8.4;

import "@openzeppelin/contracts-upgradeable/token/ERC20/presets/ERC20PresetFixedSupplyUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";

contract MyTokenUpgradeable is
    ERC20PresetFixedSupplyUpgradeable,
    UUPSUpgradeable,
    OwnableUpgradeable
{
    function initialize(
        string memory name,
        string memory symbol,
        uint256 initialSupply,
        address owner
    ) public override initializer {
        __ERC20PresetFixedSupply_init(name, symbol, initialSupply, owner);
        __Ownable_init();
        transferOwnership(owner);
    }

    function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
}

MyTokenFactory

// SPDX-License-Identifier: MIT

pragma solidity 0.8.4;

import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import "./MyTokenUpgradeable.sol";

contract MyTokenFactoryUUPS {
    address immutable tokenImplementation;

    event TokenDeployed(address tokenAddress);

    constructor() {
        tokenImplementation = address(new MyTokenUpgradeable());
    }

    function createToken(string calldata name, string calldata symbol, uint256 initialSupply, address owner) external returns (address) {
        ERC1967Proxy proxy = new ERC1967Proxy(
            tokenImplementation,
            abi.encodeWithSelector(MyTokenUpgradeable(address(0)).initialize.selector, name, symbol, initialSupply, owner)
        );
        emit TokenDeployed(address(proxy));
        return address(proxy);
    }
}

One thing I wasn’t sure is if there is a better way to set the new owner for the Token, but seems like I have to do __Ownable_init so I can then transfer it to the provided owner. Any workaround to avoid the 2-step process?

Thank you very much for all your support!

Regards,
Julian