Libraries
TradingCommonUtils
External library for helper functions commonly used in many places
Returns the current percent profit of a trade (1e10 precision)
Returns position size of trade in collateral tokens (avoids overflow from uint120 collateralAmount)
Calculates market execution price for a trade (1e10 precision)
Converts collateral value to USD (1e18 precision)
Converts collateral value to GNS (1e18 precision)
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
Pure function that returns the liquidation pnl % threshold for a trade (1e10)
Returns minimum position size in collateral tokens for a pair (collateral precision)
Returns position size to use when charging fees
Checks if total position size is not higher than maximum allowed open interest for a pair
Convenient wrapper to return trade borrowing fee in collateral tokens (collateral precision)
Convenient wrapper to return trade liquidation price (1e10)
Returns trade value and borrowing fee in collateral tokens
Returns price impact % (1e10), price after spread and impact (1e10)
Returns price impact % (1e10), price after spread and impact (1e10), and trade value used to know if pnl is positive (collateral precision)
Returns a trade’s liquidation threshold % (1e10)
Returns all fees for a trade in collateral tokens
Returns all fees for a trade in collateral tokens
Reverts if user initiated any kind of pending market order on his trade
Returns gToken contract for a collateral index
Transfers collateral from trader
Transfers collateral to trader
Transfers GNS to address
Transfers GNS from address
Sends collateral to gToken vault for negative pnl
Handles pnl transfers when (fully or partially) closing a trade
Updates a trader’s fee tiers points based on his trade size
Distributes fee to gToken vault
Distributes gov fees exact amount
Increases OTC balance to be distributed once OTC is executed
Distributes trigger fee in GNS tokens
Distributes opening fees for trade and returns the trade fees charged in collateral tokens
Distributes referral rewards and returns the amount charged in collateral tokens
_Update protocol open interest (any amount) CAREFUL: this will reset the trade’s borrowing fees to 0 when open = true
_Update protocol open interest (trade position size) CAREFUL: this will reset the trade’s borrowing fees to 0 when open = true
Handles OI delta for an existing trade (for trade updates)
Returns current address as multi-collateral diamond interface to call other facets functions.
