GmxV2PositionManager
Inherits: Initializable, IHedgeManager, IOrderCallbackReceiver, IGasFeeCallbackReceiver
Author: Logarithm Labs
GmxV2PositionManager is a dedicated smart contract that interacts with the GMX protocol to maintain and adjust short positions in alignment with the strategy’s delta-neutral requirements. This manager operates as an auxiliary component to the main strategy, ensuring that the hedge remains effective by dynamically adjusting the size of the short position based on market movements.
GmxV2PositionManager is an upgradeable smart contract, deployed through the beacon proxy pattern.
State Variables
MIN_IDLE_COLLATERAL_USD
GmxV2PositionManagerStorageLocation
Functions
_getGmxV2PositionManagerStorage
onlyStrategy
whenNotPending
initialize
adjustPosition
Called to adjust the hedge position based on specified parameters.
Parameters
params
AdjustPositionPayload
keep
Called to maintain or adjust the hedge position as required by strategy logic.
Realizes the claimable funding or increases collateral if there are idle assets
claimFunding
Claims all the claimable funding fees. This is callable by anyone. Collateral funding amount is transferred to this position manager, otherwise transferred to strategy
claimCollateral
Claims all the claimable collateral amount. Note: This amount is stored by account, token, timeKey and therefore the only way to figure it out is to use GMX events.
Parameters
token
address
The token address derived from the gmx event: ClaimableCollateralUpdated
timeKey
uint256
The timeKey value derived from the gmx event: ClaimableCollateralUpdated
afterOrderExecution
afterOrderCancellation
afterOrderFrozen
refundExecutionFee
positionNetBalance
Gets the net collateral balance of the position, including pending adjustments.
Returns
<none>
uint256
The total collateral asset amount in the position.
currentLeverage
Retrieves the current leverage of the position.
Returns
<none>
uint256
The leverage ratio as a uint256.
positionSizeInTokens
Returns the current size of the position in terms of index tokens.
Returns
<none>
uint256
The size of the position in index tokens.
getExecutionFee
Calculates the execution fee that is needed from gmx when increasing and decreasing.
Returns
feeIncrease
uint256
The execution fee for increase
feeDecrease
uint256
The execution fee for decrease
getClaimableFundingAmounts
The current claimable funding amounts that are not accrued
getAccruedClaimableFundingAmounts
The accrued claimable token amounts.
cumulativeFundingAndBorrowingFeesUsd
The total cumulated funding fee and borrowing fee in usd including next fees.
needKeep
Checks whether the keep
function needs to be called to maintain the position.
Checks if the claimable funding amount is over than max share or if idle collateral is bigger than minimum requirement so that the position can be settled to add it to position’s collateral.
Returns
<none>
bool
A boolean indicating if keep
should be executed.
_createOrder
Creates increase/decrease GMX order
_processIncreasePosition
Used in GMX callback functions.
_processDecreasePosition
Used in GMX callback functions.
_recordPositionSize
Stores new size and return delta size in tokens
_processPendingPositionFee
Processes the pending position fees.
_getGmxParams
Derives a set of gmx params that are need to call gmx smart contracts.
_onlyStrategy
_whenNotPending
_isPending
True when a GMX order has been submitted, but not executed.
_validateOrderHandler
Validates if the caller is OrderHandler of gmx
_setPendingOrderKey
config
The address of gmx config smart contract.
collateralToken
Returns the address of the collateral token used in the position.
Returns
<none>
address
The address of the collateral token.
strategy
The address of strategy.
gmxGasStation
The address of the gmx gas station smart contract.
marketToken
The address of gmx market token where position is opened at.
indexToken
Returns the address of the index token used in the position.
Returns
<none>
address
The address of the index token.
longToken
The address of long token of the opened market.
shortToken
The address of short token of the opened market.
isLong
The direction of position.
maxClaimableFundingShare
The max share of claimable funding before it get claimed through keeping.
pendingIncreaseOrderKey
The gmx increase order key that is in pending.
pendingDecreaseOrderKey
The gmx decrease order key that is in pending.
increaseCollateralMinMax
Returns the minimum and maximum collateral limits for increasing the position.
Returns
min
uint256
The minimum allowable collateral increase amount.
max
uint256
The maximum allowable collateral increase amount.
increaseSizeMinMax
Returns the minimum and maximum limits for increasing the position size.
Returns
min
uint256
The minimum allowable increase in position size.
max
uint256
The maximum allowable increase in position size.
decreaseCollateralMinMax
Returns the minimum and maximum collateral limits for decreasing the position.
Returns
min
uint256
The minimum allowable collateral decrease amount.
max
uint256
The maximum allowable collateral decrease amount.
decreaseSizeMinMax
Returns the minimum and maximum limits for decreasing the position size.
Returns
min
uint256
The minimum allowable decrease in position size.
max
uint256
The maximum allowable decrease in position size.
limitDecreaseCollateral
Retrieves the minimum decrease in collateral required for cost-efficient execution.
Helps in optimizing gas usage and cost efficiency.
Returns
<none>
uint256
The minimum decrease collateral amount that qualifies for cost-effective execution.
cumulativePositionFeeUsd
The total cumulated position fee in usd.
cumulativeClaimedFundingUsd
The total claimed funding fee in usd.
Events
FundingClaimed
Emitted when the claimable funding fee gets claimed.
CollateralClaimed
Emitted when the claimable collateral gets claimed.
PositionAdjustmentRequested
Emitted when a position adjustment is requested by strategy.
Structs
InternalCreateOrderParams
Used to create GMX order internally.
GmxV2PositionManagerStorage
Enums
Status
Describes the state of position manager.
Last updated