You really don't understand what's going on here. Your cofounder is screwing you out of your ownership stake by reincorporating a new company and firing you. There is no difference between the "old business" and the "new business" besides the fact that you are being cut out of your equity. You need to first and foremost get a lawyer. If you ask in this thread, I am 100% sure someone will give you a good referral. Run, don't walk towards getting a competent lawyer on your side.

Second of all, don't say you "invested your time" -- you worked for free. There's a difference. If your cofounder is actually a really close friend, you have very unfortunate taste in friends. After all, it's you who cares about keeping the friendship intact, not them. What kind of a friend has their friend do free work for two years and then unceremoniously cuts them out? You don't have a friend. You have someone who dangled the idea of friendship in front of you to exploit you for your labor.

As far as business partners go, they're no good. Whether they were paying with their own money or not, they failed. The two jobs of the business cofounder are to bring the product to market successfully and get traction, and to raise money. You worked for free and they're not going to even cut you in on the new business, despite the fact that you're the only one who has the full technical history in your head?

I don't see signs that you have, but you should learn a valuable lesson from this. The first is not to work for free, even as a cofounder. The second is to be wary of and generally avoid cofounding with friends because a cofounder relationship is a business relationship first and foremost in a high risk new venture that will likely end in failure. That means you need to be ready for the working relationship to be burned, or you won't be able to make the right decision when things get rough.

This is a sad story as old as time. I myself went through something similar about 6 years ago. It was very challenging and caused me no end of grief. But at the end, I was forced to recognized that I was exploited and that business partnerships are not friendships and vice versa. People go into business to make money, not to ensure everyone that works at the company gets equally compensated. If you see an exception to that at early stage companies, it's great but it is certainly not the rule. Remember that and be very careful.

To end on a good note, I'll leave you with some advice. You've had to learn a lot by taking the risk of trying to start something from scratch, even if it failed. That experience, while very costly, can be quite valuable. Take that experience towards a job at a reasonably stable company that's making money. While you won't get those two years of your life back, you can at least recoup the time you spent on that experience and parlay it into faster and more lucrative growth at a bigger company. Do that for a while and see how things work at a healthy company that's in hypergrowth. Once you see what things should look like, and how they formed, you'll have much more realistic expectations on how to get there should you decide to make try to make this journey again. You'll likely have the executive team from that company, the VCs who invested in it, the money you made working there, the experience you got executing, and of course, a much better network of people to go through the founding journey with. That was my experience.

Best of luck. Remember, you can survive this. And, it can and does get better.