UpdateLeverageLifecycles
This is an external library for leverage update lifecycles Used by GNSTrading and GNSTradingCallbacks facets
requestUpdateLeverage
Initiate update leverage order, done in 2 steps because need to cancel if liquidation price reached
Parameters
_input
request decrease leverage input
executeUpdateLeverage
Execute update leverage callback
Parameters
_order
pending order struct
_answer
price aggregator request answer
_getMultiCollatDiamond
Returns current address as multi-collateral diamond interface to call other facets functions.
_getNewCollateralAmount
Returns new trade collateral amount based on new leverage (collateral precision)
Parameters
_existingCollateralAmount
uint256
existing trade collateral amount (collateral precision)
_existingLeverage
uint256
existing trade leverage (1e3)
_newLeverage
uint256
new trade leverage (1e3)
_validateRequest
Fetches trade, does validation for update leverage request, and returns useful data
Parameters
_input
request input struct
_initiateRequest
Stores pending update leverage order and makes price aggregator request
Parameters
_trade
trade struct
_newLeverage
uint24
new leverage (1e3)
_collateralDelta
uint256
trade collateral delta (collateral precision)
_prepareCallbackValues
Calculates values for callback
Parameters
_existingTrade
existing trade struct
_pendingTrade
pending trade struct
_isIncrease
bool
true if increase leverage, false if decrease leverage
_validateCallback
Validates callback, and returns corresponding cancel reason
Parameters
_existingTrade
existing trade struct
_values
pre-calculated useful values
_answer
price aggregator answer
_handleCallback
Handles trade update, removes gov fee OI, and transfers collateral delta (for both successful and failed requests)
Parameters
_trade
trade struct
_pendingTrade
pending trade struct
_values
pre-calculated useful values
_cancelReason
enum ITradingCallbacks.CancelReason
cancel reason
_isIncrease
bool
true if increase leverage, false if decrease leverage
Last updated