The three structures people actually use here are different animals and they fail differently.
You lend. You hold a note secured by the property, he owns it, he refinances and pays you off. Your upside is capped at the interest rate, your downside is that a shortfall at refi is his problem to solve, not yours, and you have foreclosure as the remedy if he can't. Cleanest documentation, least upside.
You co-own through an entity. Both names on the operating agreement, the entity borrows, and most lenders on a small commercial or DSCR-style loan will want personal guarantees from anyone over a certain ownership percentage, commonly 20% or 25%. That means your passive intent doesn't keep you off the guarantee. Ask any prospective lender for their guarantee threshold in writing before you paper the entity, because restructuring ownership after the fact to dodge a guarantee is the kind of thing that gets a loan pulled.
You fund as preferred equity. You get paid back first out of refi proceeds, he gets his sweat equity position only after your 180k is returned, and the operating agreement says exactly that in the distribution waterfall.
On the 20k shortfall, that's a drafting decision, not a market fact. The agreement can say it stays as your outstanding capital balance accruing a preferred return until a later refi or sale clears it, or it can say he contributes cash to make you whole, or it can say you both take the haircut pro rata. Decide which before you fund. A lawyer in your state should draft it, and if you're taking money from anyone beyond this one friend there are securities questions that need a licensed opinion.
The thing that breaks these deals more often than the shortfall is scope creep on the rehab. Your 180k number needs a change-order clause saying who approves overruns and whose capital funds them.