BorrowingFeesUtils
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
_collateralIndex
uint8
index of the collateral
_pairIndex
uint16
index of the pair
_currentBlock
uint256
current block number
_long
bool
true if long side
Return Values
accFee
uint64
new 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
_collateralIndex
uint8
index of the collateral
_groupIndex
uint16
index of the borrowing group
_currentBlock
uint256
current block number
_long
bool
true if long side
Return Values
accFee
uint64
new 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
_input
input data (last acc fees, OIs, fee per block, current block, etc.)
Return Values
newAccFeeLong
uint64
new acc borrowing fee on long side
newAccFeeShort
uint64
new acc borrowing fee on short side
delta
uint64
delta 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
_openPrice
uint256
trade open price (1e10 precision)
_long
bool
true if long, false if short
_collateral
uint256
trade collateral (collateral precision)
_leverage
uint256
trade leverage (1e3 precision)
_feesCollateral
uint256
closing fees + borrowing fees amount (collateral precision)
_collateralPrecisionDelta
uint256
collateral precision delta (10^18/10^decimals)
_contractsVersion
enum ITradingStorage.ContractsVersion
contracts version of the trade
_pairSpreadP
uint256
pair spread percentage (1e10)
_setBorrowingPairParams
function _setBorrowingPairParams(uint8 _collateralIndex, uint16 _pairIndex, struct IBorrowingFees.BorrowingPairParams _value) internal
Function to set borrowing pair params
Parameters
_collateralIndex
uint8
index of the collateral
_pairIndex
uint16
index of the pair
_setBorrowingGroupParams
function _setBorrowingGroupParams(uint8 _collateralIndex, uint16 _groupIndex, struct IBorrowingFees.BorrowingGroupParams _value) internal
Function to set borrowing group params
Parameters
_collateralIndex
uint8
index of the collateral
_groupIndex
uint16
index of the borrowing group
_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
_long
bool
true if long, false if short
_increase
bool
true if increase, false if decrease
_amountCollateral
uint256
amount of collateral to increase/decrease (collateral precision)
_collateralPrecision
uint128
collateral precision (10^decimals)
Return Values
newOiLong
uint72
new long open interest (1e10)
newOiShort
uint72
new short open interest (1e10)
delta
uint72
difference 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
_collateralIndex
uint8
index of the collateral
_pairIndex
uint16
index of the borrowing group
_long
bool
true if long, false if short
_increase
bool
true if increase, false if decrease
_amountCollateral
uint256
amount 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
_collateralIndex
uint8
index of the collateral
_groupIndex
uint16
index of the borrowing group
_long
bool
true if long, false if short
_increase
bool
true if increase, false if decrease
_amountCollateral
uint256
amount 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
_collateralIndex
uint8
index of the collateral
_i
uint256
index of the borrowing pair group
_pairIndex
uint16
index of the pair
_long
bool
true if long, false if short
_currentBlock
uint256
current block number
Return Values
deltaGroup
uint64
difference between new and current group acc borrowing fee
deltaPair
uint64
difference between new and current pair acc borrowing fee
beforeTradeOpen
bool
true 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
_collateralIndex
uint8
index of the collateral
_pairIndex
uint16
index of the pair
_currentBlock
uint256
current block number
Return Values
accFeeLong
uint64
new pair acc borrowing fee on long side (1e10 precision)
accFeeShort
uint64
new 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
_collateralIndex
uint8
index of the collateral
_groupIndex
uint16
index of the borrowing group
_currentBlock
uint256
current block number
Return Values
accFeeLong
uint64
new group acc borrowing fee on long side (1e10 precision)
accFeeShort
uint64
new group acc borrowing fee on short side (1e10 precision)
Last updated
Was this helpful?