Assessment reports>GTE -- Perp>Threat Model>positionTakeover

Function: positionTakeover(Position storage liquidator, Position memory liquidatee, uint256 price, uint256 leverage)

If the liquidator already holds a position in the same direction as the liquidatee position or has no position, the _takeoverOpen function is executed to increase the liquidator position. If the liquidator holds a position in the opposite direction so the current position is partially or fully closed, a new one may be reopened in the new direction using _takeoverClose.

Branches and code coverage

Intended branches

  • Liquidator has no position.

  • Liquidator and liquidatee are both long.

  • Liquidator and liquidatee are both short.

  • Liquidator is long and liquidatee is short.

  • Liquidator is short and liquidatee is long.

  • oiDelta.long or oiDelta.short are calculated correctly.

  • Liquidator’s position has correct price, margin, openNotional, and amount.

  • collateralDelta is calculated properly.

  • Leverage is used correctly to determine a new margin.

  • Liquidatee PNL is correct for a long position closed at a lower price.

  • Liquidatee PNL is correct for a short position closed at a higher price.

Zellic © 2025Back to top ↑