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
account
Control: 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.
subaccount
Control: Full control.
Constraints: A valid subaccount of
account
— must contain active positions, which can be liquidated.Impact: Determines the subaccount that will be liquidated.
leverage
Control: Full control.
Constraints: Must be a valid leverage value.
Impact: new applied leverage.
settlement
Control: Full control.
Constraints: Must be a valid settlement type.
Impact: Decides where the collateral goes.
Branches and code coverage
Intended branches
marginDelta
,gtlRpnl
andliquidateeRpnl
are 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
margin
is less than zero, it returns true, even iftotalPnL
covers the debt.What happens if it reverts, reenters or does other unusual control flow? There are not any problems here.