<!-- canonical: https://0xsimao.com/findings/nftperp-i-realized-returned-trader-merge -->

# Realized pnl not returned to trader on _mergeDecrease()

Crit/High · Three Sigma · NFT perpetuals · 2nd January, 2024

Finding 3S-NFTPerp-H01 of the Nftperp Exchange security review.

- Report: /reports/nftperp-i
- Source: https://cdn.sanity.io/files/qoqld077/production/c19530de75e234ad15694b4563edb1fc9d2a3fd8.pdf

---

### Description

On the merge of a liquidator position following a liquidation, the [realizedPnl](https://github.com/nftperp/NFTPerp-V2-Contracts/blob/1c16f2010a851ac23aec73822d55388901bbe5e7/src/clearinghouse-libs/PositionMerger.sol#L516) from the
previous position is not added to the marginToRemove() variable, but it is [removed](https://github.com/nftperp/NFTPerp-V2-Contracts/blob/1c16f2010a851ac23aec73822d55388901bbe5e7/src/clearinghouse-libs/PositionMerger.sol#L526-L530) from the
openNotional, leading to loss of yield for the liquidator.

### Recommendation

Add the = symbol to the operation marginToRemove += params.rpnl;.

### Status

Addressed in the AMMRouter
