Skip to main content
GNSBorrowingFees facet internal library

setBorrowingPairParams

function setBorrowingPairParams(uint8 _collateralIndex, uint16 _pairIndex, struct IBorrowingFees.BorrowingPairParams _value) internal
Check IBorrowingFeesUtils interface for documentation

setBorrowingPairParamsArray

function setBorrowingPairParamsArray(uint8 _collateralIndex, uint16[] _indices, struct IBorrowingFees.BorrowingPairParams[] _values) internal
Check IBorrowingFeesUtils interface for documentation

setBorrowingGroupParams

function setBorrowingGroupParams(uint8 _collateralIndex, uint16 _groupIndex, struct IBorrowingFees.BorrowingGroupParams _value) internal
Check IBorrowingFeesUtils interface for documentation

setBorrowingGroupParamsArray

function setBorrowingGroupParamsArray(uint8 _collateralIndex, uint16[] _indices, struct IBorrowingFees.BorrowingGroupParams[] _values) internal
Check IBorrowingFeesUtils interface for documentation

handleTradeBorrowingCallback

function handleTradeBorrowingCallback(uint8 _collateralIndex, address _trader, uint16 _pairIndex, uint32 _index, uint256 _positionSizeCollateral, bool _open, bool _long) internal
Check IBorrowingFeesUtils interface for documentation

resetTradeBorrowingFees

function resetTradeBorrowingFees(uint8 _collateralIndex, address _trader, uint16 _pairIndex, uint32 _index, bool _long) internal
Check IBorrowingFeesUtils interface for documentation

getBorrowingPairPendingAccFees

function getBorrowingPairPendingAccFees(uint8 _collateralIndex, uint16 _pairIndex, uint256 _currentBlock) internal view returns (uint64 accFeeLong, uint64 accFeeShort, uint64 pairAccFeeDelta)
Check IBorrowingFeesUtils interface for documentation

getBorrowingGroupPendingAccFees

function getBorrowingGroupPendingAccFees(uint8 _collateralIndex, uint16 _groupIndex, uint256 _currentBlock) internal view returns (uint64 accFeeLong, uint64 accFeeShort, uint64 groupAccFeeDelta)
Check IBorrowingFeesUtils interface for documentation

getTradeBorrowingFee

function getTradeBorrowingFee(struct IBorrowingFees.BorrowingFeeInput _input) internal view returns (uint256 feeAmountCollateral)
Check IBorrowingFeesUtils interface for documentation

getTradeLiquidationPrice

function getTradeLiquidationPrice(struct IBorrowingFees.LiqPriceInput _input) internal view returns (uint256)
Check IBorrowingFeesUtils interface for documentation

getPairOisCollateral

function getPairOisCollateral(uint8 _collateralIndex, uint16 _pairIndex) internal view returns (uint256 longOiCollateral, uint256 shortOiCollateral)
Check IBorrowingFeesUtils interface for documentation

getBorrowingPairGroupIndex

function getBorrowingPairGroupIndex(uint8 _collateralIndex, uint16 _pairIndex) internal view returns (uint16 groupIndex)
Check IBorrowingFeesUtils interface for documentation

getPairOiCollateral

function getPairOiCollateral(uint8 _collateralIndex, uint16 _pairIndex, bool _long) internal view returns (uint256)
Check IBorrowingFeesUtils interface for documentation

withinMaxBorrowingGroupOi

function withinMaxBorrowingGroupOi(uint8 _collateralIndex, uint16 _pairIndex, bool _long, uint256 _positionSizeCollateral) internal view returns (bool)
Check IBorrowingFeesUtils interface for documentation

getBorrowingGroup

function getBorrowingGroup(uint8 _collateralIndex, uint16 _groupIndex) internal view returns (struct IBorrowingFees.BorrowingData)
Check IBorrowingFeesUtils interface for documentation

getBorrowingGroupOi

function getBorrowingGroupOi(uint8 _collateralIndex, uint16 _groupIndex) internal view returns (struct IBorrowingFees.OpenInterest)
Check IBorrowingFeesUtils interface for documentation

getBorrowingPair

function getBorrowingPair(uint8 _collateralIndex, uint16 _pairIndex) internal view returns (struct IBorrowingFees.BorrowingData)
Check IBorrowingFeesUtils interface for documentation

getBorrowingPairOi

function getBorrowingPairOi(uint8 _collateralIndex, uint16 _pairIndex) internal view returns (struct IBorrowingFees.OpenInterest)
Check IBorrowingFeesUtils interface for documentation

getBorrowingPairGroups

function getBorrowingPairGroups(uint8 _collateralIndex, uint16 _pairIndex) internal view returns (struct IBorrowingFees.BorrowingPairGroup[])
Check IBorrowingFeesUtils interface for documentation

getAllBorrowingPairs

function getAllBorrowingPairs(uint8 _collateralIndex) internal view returns (struct IBorrowingFees.BorrowingData[], struct IBorrowingFees.OpenInterest[], struct IBorrowingFees.BorrowingPairGroup[][])
Check IBorrowingFeesUtils interface for documentation

getBorrowingGroups

function getBorrowingGroups(uint8 _collateralIndex, uint16[] _indices) internal view returns (struct IBorrowingFees.BorrowingData[], struct IBorrowingFees.OpenInterest[])
Check IBorrowingFeesUtils interface for documentation

getBorrowingInitialAccFees

function getBorrowingInitialAccFees(uint8 _collateralIndex, address _trader, uint32 _index) internal view returns (struct IBorrowingFees.BorrowingInitialAccFees)
Check IBorrowingFeesUtils interface for documentation

getPairMaxOi

function getPairMaxOi(uint8 _collateralIndex, uint16 _pairIndex) internal view returns (uint256)
Check IBorrowingFeesUtils interface for documentation

getPairMaxOiCollateral

function getPairMaxOiCollateral(uint8 _collateralIndex, uint16 _pairIndex) internal view returns (uint256)
Check IBorrowingFeesUtils interface for documentation

_getSlot

function _getSlot() internal pure returns (uint256)
Returns storage slot to use when fetching storage relevant to library

_getStorage

function _getStorage() internal pure returns (struct IBorrowingFees.BorrowingFeesStorage s)
Returns storage pointer for storage struct in diamond contract, at defined slot

_getMultiCollatDiamond

function _getMultiCollatDiamond() internal view returns (contract IGNSMultiCollatDiamond)
Returns current address as multi-collateral diamond interface to call other facets functions.

validCollateralIndex

modifier validCollateralIndex(uint8 _collateralIndex)
Reverts if collateral index is not valid

_getBorrowingPairPendingAccFee

function _getBorrowingPairPendingAccFee(uint8 _collateralIndex, uint16 _pairIndex, uint256 _currentBlock, bool _long) internal view returns (uint64 accFee)
Returns pending acc borrowing fee for a pair on one side only

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_pairIndexuint16index of the pair
_currentBlockuint256current block number
_longbooltrue if long side

Return Values

NameTypeDescription
accFeeuint64new pair acc borrowing fee

_getBorrowingGroupPendingAccFee

function _getBorrowingGroupPendingAccFee(uint8 _collateralIndex, uint16 _groupIndex, uint256 _currentBlock, bool _long) internal view returns (uint64 accFee)
Returns pending acc borrowing fee for a borrowing group on one side only

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_groupIndexuint16index of the borrowing group
_currentBlockuint256current block number
_longbooltrue if long side

Return Values

NameTypeDescription
accFeeuint64new group acc borrowing fee

_getBorrowingPendingAccFees

function _getBorrowingPendingAccFees(struct IBorrowingFees.PendingBorrowingAccFeesInput _input) internal pure returns (uint64 newAccFeeLong, uint64 newAccFeeShort, uint64 delta)
Pure function that returns the new acc borrowing fees and delta between two blocks (for pairs and groups)

Parameters

NameTypeDescription
_inputIBorrowingFees.PendingBorrowingAccFeesInputinput data (last acc fees, OIs, fee per block, current block, etc.)

Return Values

NameTypeDescription
newAccFeeLonguint64new acc borrowing fee on long side
newAccFeeShortuint64new acc borrowing fee on short side
deltauint64delta with current acc borrowing fee (for side that changed)

_getTradeLiquidationPrice

function _getTradeLiquidationPrice(uint256 _openPrice, bool _long, uint256 _collateral, uint256 _leverage, uint256 _feesCollateral, uint256 _collateralPrecisionDelta, struct IPairsStorage.GroupLiquidationParams _liquidationParams, enum ITradingStorage.ContractsVersion _contractsVersion, uint256 _pairSpreadP) internal pure returns (uint256)
Pure function that returns the liquidation price for a trade (1e10 precision)

Parameters

NameTypeDescription
_openPriceuint256trade open price (1e10 precision)
_longbooltrue if long, false if short
_collateraluint256trade collateral (collateral precision)
_leverageuint256trade leverage (1e3 precision)
_feesCollateraluint256closing fees + borrowing fees amount (collateral precision)
_collateralPrecisionDeltauint256collateral precision delta (10^18/10^decimals)
_liquidationParamsIPairsStorage.GroupLiquidationParamsliquidation parameters for the trade
_contractsVersionenum ITradingStorage.ContractsVersioncontracts version of the trade
_pairSpreadPuint256pair spread percentage (1e10)

_setBorrowingPairParams

function _setBorrowingPairParams(uint8 _collateralIndex, uint16 _pairIndex, struct IBorrowingFees.BorrowingPairParams _value) internal
Function to set borrowing pair params

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_pairIndexuint16index of the pair
_valueIBorrowingFees.BorrowingPairParamsnew pair params

_setBorrowingGroupParams

function _setBorrowingGroupParams(uint8 _collateralIndex, uint16 _groupIndex, struct IBorrowingFees.BorrowingGroupParams _value) internal
Function to set borrowing group params

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_groupIndexuint16index of the borrowing group
_valueIBorrowingFees.BorrowingGroupParamsnew group params

_updateOi

function _updateOi(struct IBorrowingFees.OpenInterest _oiStorage, bool _long, bool _increase, uint256 _amountCollateral, uint128 _collateralPrecision) internal returns (uint72 newOiLong, uint72 newOiShort, uint72 delta)
Function to update a borrowing pair/group open interest

Parameters

NameTypeDescription
_oiStorageIBorrowingFees.OpenInterestopen interest storage reference
_longbooltrue if long, false if short
_increasebooltrue if increase, false if decrease
_amountCollateraluint256amount of collateral to increase/decrease (collateral precision)
_collateralPrecisionuint128collateral precision (10^decimals)

Return Values

NameTypeDescription
newOiLonguint72new long open interest (1e10)
newOiShortuint72new short open interest (1e10)
deltauint72difference between new and current open interest (1e10)

_updatePairOi

function _updatePairOi(uint8 _collateralIndex, uint16 _pairIndex, bool _long, bool _increase, uint256 _amountCollateral) internal
Function to update a borrowing group’s open interest

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_pairIndexuint16index of the borrowing group
_longbooltrue if long, false if short
_increasebooltrue if increase, false if decrease
_amountCollateraluint256amount of collateral to increase/decrease (collateral precision)

_updateGroupOi

function _updateGroupOi(uint8 _collateralIndex, uint16 _groupIndex, bool _long, bool _increase, uint256 _amountCollateral) internal
Function to update a borrowing group’s open interest

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_groupIndexuint16index of the borrowing group
_longbooltrue if long, false if short
_increasebooltrue if increase, false if decrease
_amountCollateraluint256amount of collateral to increase/decrease (collateral precision)

_getBorrowingPairGroupAccFeesDeltas

function _getBorrowingPairGroupAccFeesDeltas(uint8 _collateralIndex, uint256 _i, struct IBorrowingFees.BorrowingPairGroup[] _pairGroups, struct IBorrowingFees.BorrowingInitialAccFees _initialFees, uint16 _pairIndex, bool _long, uint256 _currentBlock) internal view returns (uint64 deltaGroup, uint64 deltaPair, bool beforeTradeOpen)
_Calculates the borrowing group and pair acc fees deltas for a trade between pair group at index i and next one

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_iuint256index of the borrowing pair group
_pairGroupsIBorrowingFees.BorrowingPairGroup[]all pair’s historical borrowing groups
_initialFeesIBorrowingFees.BorrowingInitialAccFeestrade initial borrowing fees
_pairIndexuint16index of the pair
_longbooltrue if long, false if short
_currentBlockuint256current block number

Return Values

NameTypeDescription
deltaGroupuint64difference between new and current group acc borrowing fee
deltaPairuint64difference between new and current pair acc borrowing fee
beforeTradeOpenbooltrue if pair group was set before trade was opened

_setPairPendingAccFees

function _setPairPendingAccFees(uint8 _collateralIndex, uint16 _pairIndex, uint256 _currentBlock) internal returns (uint64 accFeeLong, uint64 accFeeShort)

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_pairIndexuint16index of the pair
_currentBlockuint256current block number

Return Values

NameTypeDescription
accFeeLonguint64new pair acc borrowing fee on long side (1e10 precision)
accFeeShortuint64new pair acc borrowing fee on short side (1e10 precision)

_setGroupPendingAccFees

function _setGroupPendingAccFees(uint8 _collateralIndex, uint16 _groupIndex, uint256 _currentBlock) internal returns (uint64 accFeeLong, uint64 accFeeShort)

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_groupIndexuint16index of the borrowing group
_currentBlockuint256current block number

Return Values

NameTypeDescription
accFeeLonguint64new group acc borrowing fee on long side (1e10 precision)
accFeeShortuint64new group acc borrowing fee on short side (1e10 precision)