contract StakingFactoryV2 is Ownable {
    // info about rewards for a particular staking token
    struct StakingInfo {
        address stakingTokenContract;
        uint256 duration;
        uint256 baseApy;
    }

    // the staking tokens for which the contract has been deployed
    StakingInfo[] public stakingTokens;

    constructor() Ownable() {}

    ///// permissioned functions

    // deploy a staking contract for the staking token, and store the reward duration
    function deploy(
        address stakingToken,
        uint256 duration,
        uint256 baseApy
    ) public onlyOwner {
        require(duration > 0, 'duration=0');
        address deployedContract = address(new StakingTokenV2(stakingToken, duration, baseApy, address(this)));
        stakingTokens.push(StakingInfo(deployedContract, duration, baseApy));
    }

    function emergencyWithdraw(address _token) external onlyOwner {
        for (uint256 index = 0; index < stakingTokens.length; index++) {
            StakingInfo memory info = stakingTokens[index];
            IStakingToken(info.stakingTokenContract).emergencyWithdraw(_token);
        }
        IERC20(_token).transfer(msg.sender, IERC20(_token).balanceOf(address(this)));
    }
}
// import 'C:\Projects\VRM.FarmingStaking.Contracts\node_modules\@openzeppelin\contracts\token\ERC20\IERC20.sol';
// import 'C:\Projects\VRM.FarmingStaking.Contracts\node_modules\@openzeppelin\contracts\access\Ownable.sol';
// import 'contracts\StakingTokenV2.sol';
function deploy(
    address stakingToken,
    uint256 duration,
    uint256 baseApy
) public onlyOwner {
    require(duration > 0, 'duration=0');
    address deployedContract = address(new StakingTokenV2(stakingToken, duration, baseApy, address(this)));
    stakingTokens.push(StakingInfo(deployedContract, duration, baseApy));
}

// deploy a staking contract for the staking token, and store the reward duration