Function: backstopLiquidate(address account, uint256 subaccount, uint256 leverage, Settlement settlement)
The positionTakeover function allows a liquidator to take over the entire position of the liquidatee that has become liquidatable.
Inputs
accountControl: Full control.
Constraints: A valid address that own a position in the specified subaccount. The account must be eligible for liquidation.
Impact: Identifies which user’s subaccount will be liquidated.
subaccountControl: Full control.
Constraints: A valid subaccount of
account— must contain active positions, which can be liquidated.Impact: Determines the subaccount that will be liquidated.
leverageControl: Full control.
Constraints: Must be a valid leverage value.
Impact: new applied leverage.
settlementControl: Full control.
Constraints: Must be a valid settlement type.
Impact: Decides where the collateral goes.
Branches and code coverage
Intended branches
marginDelta,gtlRpnlandliquidateeRpnlare calculated correctly.
Negative behavior
Reverts if position is not liquidatable.
Reverts if position amount is zero.
Invalid leverage.
Caller is not a GTLOperator.
Function call analysis
self.isLiquidatable({account: account, subaccount: subaccount, margin: self.collateralManager.getMarginAccountBalance(account, subaccount).toInt256() - liquidateeFundingPayment})What is controllable?
account,subaccount, andsettlement.If the return value is controllable, how is it used and how can it go wrong? If
marginis less than zero, it returns true, even iftotalPnLcovers the debt.What happens if it reverts, reenters or does other unusual control flow? There are not any problems here.