Paying social security (housing funds, social security, pension, health insurance) became mandatory for foreign employees in 2021, but in reality, it's not actually enforced, and very few companies do it. We got a pretty good insightful article into that here.
Anyway, if your company does payyours (ask your HR if they pay 社会保险 for you), then you are entitled to receive back a portion of those funds. You won't get all of it, but in many cases, you'll get enough to make it worthwhile.
Here's a guide on how to do that:
(We're new to this, so our guide is built on the information we gathered from the Shanghai Social Security Hotline, just to give you some context.)