The transaction fees are fully paid to the platform, but the platform will use a portion of the fees to pay market makers.
The perpetual contract funding rate is entirely given to the counterparty.
The main part of the margin (principal), which is the loss incurred before liquidation, is earned by the counterparty.
The additional losses incurred during liquidation go to the platform. If this is a spike market, then this part is indeed earned by the platform. However, if it's a one-sided market, this money may actually have been lost by the platform, and the platform could lose even more, which then benefits the counterparty. However, now almost all platforms have an ADL mechanism, so the platform will forcibly close the counterparty's position to avoid significant losses.
The exchange will not actively participate as the counterparty. The dealer is always the market maker, not the platform's reserve.