getPnlPercent
Parameters
| Name | Type | Description |
|---|---|---|
| _openPrice | uint64 | trade open price (1e10 precision) |
| _currentPrice | uint64 | trade current price (1e10 precision) |
| _long | bool | true for long, false for short |
| _leverage | uint24 | trade leverage (1e3 precision) |
getPositionSizeCollateral
Parameters
| Name | Type | Description |
|---|---|---|
| _collateralAmount | uint120 | collateral of trade |
| _leverage | uint24 | leverage of trade (1e3) |
getMarketExecutionPrice
Parameters
| Name | Type | Description |
|---|---|---|
| _price | uint256 | price of the asset (1e10) |
| _spreadP | uint256 | spread percentage (1e10) |
| _long | bool | true if long, false if short |
| _open | bool | |
| _contractsVersion | enum ITradingStorage.ContractsVersion |
convertCollateralToUsd
Parameters
| Name | Type | Description |
|---|---|---|
| _collateralAmount | uint256 | amount of collateral (collateral precision) |
| _collateralPrecisionDelta | uint128 | precision delta of collateral (10^18/10^decimals) |
| _collateralPriceUsd | uint256 | price of collateral in USD (1e8) |
convertCollateralToGns
Parameters
| Name | Type | Description |
|---|---|---|
| _collateralAmount | uint256 | amount of collateral (collateral precision) |
| _collateralPrecisionDelta | uint128 | precision delta of collateral (10^18/10^decimals) |
| _gnsPriceCollateral | uint256 | price of GNS in collateral (1e10) |
getTradeValuePure
Parameters
| Name | Type | Description |
|---|---|---|
| _collateral | uint256 | amount of collateral (collateral precision) |
| _percentProfit | int256 | profit percentage (1e10) |
| _feesCollateral | uint256 | borrowing fee + closing fee in collateral tokens (collateral precision) |
| _collateralPrecisionDelta | uint128 | precision delta of collateral (10^18/10^decimals) |
getLiqPnlThresholdP
Parameters
| Name | Type | Description |
|---|---|---|
| _params | IPairsStorage.GroupLiquidationParams | trade liquidation params |
| _leverage | uint256 | trade leverage (1e3 precision) |
getMinPositionSizeCollateral
Parameters
| Name | Type | Description |
|---|---|---|
| _collateralIndex | uint8 | collateral index |
| _pairIndex | uint256 | pair index |
getPositionSizeCollateralBasis
Parameters
| Name | Type | Description |
|---|---|---|
| _collateralIndex | uint8 | collateral index |
| _pairIndex | uint256 | pair index |
| _positionSizeCollateral | uint256 | trade position size in collateral tokens (collateral precision) |
isWithinExposureLimits
Parameters
| Name | Type | Description |
|---|---|---|
| _collateralIndex | uint8 | index of collateral |
| _pairIndex | uint16 | index of pair |
| _long | bool | true if long, false if short |
| _positionSizeCollateralDelta | uint256 | position size delta in collateral tokens (collateral precision) |
getTradeBorrowingFeeCollateral
Parameters
| Name | Type | Description |
|---|---|---|
| _trade | ITradingStorage.Trade | trade input |
getTradeLiquidationPrice
Parameters
| Name | Type | Description |
|---|---|---|
| _trade | ITradingStorage.Trade | trade input |
| _useBorrowingFees | bool |
getTradeValueCollateral
Parameters
| Name | Type | Description |
|---|---|---|
| _trade | ITradingStorage.Trade | trade data |
| _percentProfit | int256 | profit percentage (1e10) |
| _closingFeesCollateral | uint256 | closing fees in collateral tokens (collateral precision) |
| _collateralPrecisionDelta | uint128 | precision delta of collateral (10^18/10^decimals) |
getTradeOpeningPriceImpact
Parameters
| Name | Type | Description |
|---|---|---|
| _input | ITradingCommonUtils.TradePriceImpactInput | input data |
| _contractsVersion | enum ITradingStorage.ContractsVersion | contracts version |
getTradeClosingPriceImpact
Parameters
| Name | Type | Description |
|---|---|---|
| _input | ITradingCommonUtils.TradePriceImpactInput | input data |
getTradeLiqPnlThresholdP
Parameters
| Name | Type | Description |
|---|---|---|
| _trade | ITradingStorage.Trade | trade struct |
getTotalTradeFeesCollateral
Parameters
| Name | Type | Description |
|---|---|---|
| _collateralIndex | uint8 | collateral index |
| _trader | address | address of trader |
| _pairIndex | uint16 | index of pair |
| _positionSizeCollateral | uint256 | position size in collateral tokens (collateral precision) |
getTradeFeesCollateral
Parameters
| Name | Type | Description |
|---|---|---|
| _collateralIndex | uint8 | collateral index |
| _trader | address | address of trader |
| _pairIndex | uint16 | index of pair |
| _collateralAmount | uint256 | trade collateral amount (collateral precision) |
| _positionSizeCollateral | uint256 | trade position size in collateral tokens (collateral precision) |
| _orderType | enum ITradingStorage.PendingOrderType | corresponding order type |
getMinGovFeeCollateral
revertIfTradeHasPendingMarketOrder
Parameters
| Name | Type | Description |
|---|---|---|
| _user | address | trade user |
| _index | uint32 | trade index |
getGToken
Parameters
| Name | Type | Description |
|---|---|---|
| _collateralIndex | uint8 | collateral index |
transferCollateralFrom
Parameters
| Name | Type | Description |
|---|---|---|
| _collateralIndex | uint8 | index of the collateral |
| _from | address | sending address |
| _amountCollateral | uint256 | amount of collateral to receive (collateral precision) |
transferCollateralTo
Parameters
| Name | Type | Description |
|---|---|---|
| _collateralIndex | uint8 | index of the collateral |
| _to | address | receiving address |
| _amountCollateral | uint256 | amount of collateral to transfer (collateral precision) |
transferGnsTo
Parameters
| Name | Type | Description |
|---|---|---|
| _to | address | receiving address |
| _amountGns | uint256 | amount of GNS to transfer (1e18) |
transferGnsFrom
Parameters
| Name | Type | Description |
|---|---|---|
| _from | address | sending address |
| _amountGns | uint256 | amount of GNS to receive (1e18) |
sendCollateralToVault
Parameters
| Name | Type | Description |
|---|---|---|
| _collateralIndex | uint8 | collateral index |
| _amountCollateral | uint256 | amount of collateral to send to vault (collateral precision) |
| _trader | address | trader address |
handleTradePnl
Parameters
| Name | Type | Description |
|---|---|---|
| _trade | ITradingStorage.Trade | trade struct |
| _collateralSentToTrader | int256 | total amount to send to trader (collateral precision) |
| _availableCollateralInDiamond | int256 | part of _collateralSentToTrader available in diamond balance (collateral precision) |
| _borrowingFeeCollateral | uint256 |
updateFeeTierPoints
Parameters
| Name | Type | Description |
|---|---|---|
| _collateralIndex | uint8 | collateral index |
| _trader | address | address of trader |
| _pairIndex | uint256 | index of pair |
| _positionSizeCollateral | uint256 | position size in collateral tokens (collateral precision) |
distributeVaultFeeCollateral
Parameters
| Name | Type | Description |
|---|---|---|
| _collateralIndex | uint8 | index of collateral |
| _trader | address | address of trader |
| _valueCollateral | uint256 | fee in collateral tokens (collateral precision) |
distributeExactGovFeeCollateral
Parameters
| Name | Type | Description |
|---|---|---|
| _collateralIndex | uint8 | index of collateral |
| _trader | address | address of trader |
| _govFeeCollateral | uint256 | position size in collateral tokens (collateral precision) |
distributeGnsOtcFeeCollateral
Parameters
| Name | Type | Description |
|---|---|---|
| _collateralIndex | uint8 | collateral index |
| _trader | address | trader address |
| _amountCollateral | uint256 | amount of collateral tokens to distribute (collateral precision) |
distributeTriggerFeeGns
Parameters
| Name | Type | Description |
|---|---|---|
| _trader | address | address of trader |
| _collateralIndex | uint8 | index of collateral |
| _triggerFeeCollateral | uint256 | trigger fee in collateral tokens (collateral precision) |
| _gnsPriceCollateral | uint256 | gns/collateral price (1e10 precision) |
| _collateralPrecisionDelta | uint128 | collateral precision delta (10^18/10^decimals) |
processFees
Parameters
| Name | Type | Description |
|---|---|---|
| _trade | ITradingStorage.Trade | trade struct |
| _positionSizeCollateral | uint256 | position size in collateral tokens (collateral precision) |
| _orderType | enum ITradingStorage.PendingOrderType | trade order type |
distributeReferralFeeCollateral
Parameters
| Name | Type | Description |
|---|---|---|
| _collateralIndex | uint8 | collateral index |
| _trader | address | address of trader |
| _positionSizeCollateral | uint256 | position size in collateral tokens (collateral precision) |
| _referralFeeCollateral | uint256 | referral fee in collateral tokens (collateral precision) |
| _gnsPriceCollateral | uint256 | gns/collateral price (1e10 precision) |
updateOi
Parameters
| Name | Type | Description |
|---|---|---|
| _trade | ITradingStorage.Trade | trade struct |
| _positionSizeCollateral | uint256 | position size in collateral tokens (collateral precision) |
| _open | bool | whether it corresponds to a trade opening or closing |
| _isPnlPositive | bool | whether it corresponds to a positive pnl trade (only relevant when _open = false) |
updateOiTrade
Parameters
| Name | Type | Description |
|---|---|---|
| _trade | ITradingStorage.Trade | trade struct |
| _open | bool | whether it corresponds to a trade opening or closing |
| _isPnlPositive | bool | whether it corresponds to a positive pnl trade (only relevant when _open = false) |
handleOiDelta
Parameters
| Name | Type | Description |
|---|---|---|
| _trade | ITradingStorage.Trade | trade struct |
| _newPositionSizeCollateral | uint256 | new position size in collateral tokens (collateral precision) |
| _isPnlPositive | bool | whether it corresponds to a positive pnl trade (only relevant when closing) |
