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
Name | Type | Description |
---|---|---|
_input | request decrease leverage input |
executeUpdateLeverage
Execute update leverage callback
Parameters
Name | Type | Description |
---|---|---|
_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
Name | Type | Description |
---|---|---|
_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
Name | Type | Description |
---|---|---|
_input | request input struct |
_initiateRequest
Stores pending update leverage order and makes price aggregator request
Parameters
Name | Type | Description |
---|---|---|
_trade | trade struct | |
_newLeverage | uint24 | new leverage (1e3) |
_collateralDelta | uint256 | trade collateral delta (collateral precision) |
_prepareCallbackValues
Calculates values for callback
Parameters
Name | Type | Description |
---|---|---|
_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
Name | Type | Description |
---|---|---|
_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
Name | Type | Description |
---|---|---|
_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