Skip to main content
External library for helper functions commonly used in many places

getPnlPercent

Returns the current percent profit of a trade (1e10 precision)

Parameters

getPositionSizeCollateral

Returns position size of trade in collateral tokens (avoids overflow from uint120 collateralAmount)

Parameters

getMarketExecutionPrice

Calculates market execution price for a trade (1e10 precision)

Parameters

convertCollateralToUsd

Converts collateral value to USD (1e18 precision)

Parameters

convertCollateralToGns

Converts collateral value to GNS (1e18 precision)

Parameters

getTradeValuePure

Calculates trade value (useful when closing a trade) Important: does not calculate if trade can be liquidated or not, has to be done by calling function

Parameters

getLiqPnlThresholdP

Pure function that returns the liquidation pnl % threshold for a trade (1e10)

Parameters

getMinPositionSizeCollateral

Returns minimum position size in collateral tokens for a pair (collateral precision)

Parameters

getPositionSizeCollateralBasis

Returns position size to use when charging fees

Parameters

isWithinExposureLimits

Checks if total position size is not higher than maximum allowed open interest for a pair

Parameters

getTradeBorrowingFeeCollateral

Convenient wrapper to return trade borrowing fee in collateral tokens (collateral precision)

Parameters

getTradeLiquidationPrice

Convenient wrapper to return trade liquidation price (1e10)

Parameters

getTradeValueCollateral

Returns trade value and borrowing fee in collateral tokens

Parameters

getTradeOpeningPriceImpact

Returns price impact % (1e10), price after spread and impact (1e10)

Parameters

getTradeClosingPriceImpact

Returns price impact % (1e10), price after spread and impact (1e10), and trade value used to know if pnl is positive (collateral precision)

Parameters

getTradeLiqPnlThresholdP

Returns a trade’s liquidation threshold % (1e10)

Parameters

getTotalTradeFeesCollateral

Returns all fees for a trade in collateral tokens

Parameters

getTradeFeesCollateral

Returns all fees for a trade in collateral tokens

Parameters

getMinGovFeeCollateral

revertIfTradeHasPendingMarketOrder

Reverts if user initiated any kind of pending market order on his trade

Parameters

getGToken

Returns gToken contract for a collateral index

Parameters

transferCollateralFrom

Transfers collateral from trader

Parameters

transferCollateralTo

Transfers collateral to trader

Parameters

transferGnsTo

Transfers GNS to address

Parameters

transferGnsFrom

Transfers GNS from address

Parameters

sendCollateralToVault

Sends collateral to gToken vault for negative pnl

Parameters

handleTradePnl

Handles pnl transfers when (fully or partially) closing a trade

Parameters

updateFeeTierPoints

Updates a trader’s fee tiers points based on his trade size

Parameters

distributeVaultFeeCollateral

Distributes fee to gToken vault

Parameters

distributeExactGovFeeCollateral

Distributes gov fees exact amount

Parameters

distributeGnsOtcFeeCollateral

Increases OTC balance to be distributed once OTC is executed

Parameters

distributeTriggerFeeGns

Distributes trigger fee in GNS tokens

Parameters

processFees

Distributes opening fees for trade and returns the trade fees charged in collateral tokens

Parameters

distributeReferralFeeCollateral

Distributes referral rewards and returns the amount charged in collateral tokens

Parameters

updateOi

_Update protocol open interest (any amount) CAREFUL: this will reset the trade’s borrowing fees to 0 when open = true

Parameters

updateOiTrade

_Update protocol open interest (trade position size) CAREFUL: this will reset the trade’s borrowing fees to 0 when open = true

Parameters

handleOiDelta

Handles OI delta for an existing trade (for trade updates)

Parameters

_getMultiCollatDiamond

Returns current address as multi-collateral diamond interface to call other facets functions.