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

Check IBorrowingFeesUtils interface for documentation

resetTradeBorrowingFees

Check IBorrowingFeesUtils interface for documentation

getBorrowingPairPendingAccFees

Check IBorrowingFeesUtils interface for documentation

getBorrowingGroupPendingAccFees

Check IBorrowingFeesUtils interface for documentation

getTradeBorrowingFee

Check IBorrowingFeesUtils interface for documentation

getTradeLiquidationPrice

Check IBorrowingFeesUtils interface for documentation

getPairOisCollateral

Check IBorrowingFeesUtils interface for documentation

getBorrowingPairGroupIndex

Check IBorrowingFeesUtils interface for documentation

getPairOiCollateral

Check IBorrowingFeesUtils interface for documentation

withinMaxBorrowingGroupOi

Check IBorrowingFeesUtils interface for documentation

getBorrowingGroup

Check IBorrowingFeesUtils interface for documentation

getBorrowingGroupOi

Check IBorrowingFeesUtils interface for documentation

getBorrowingPair

Check IBorrowingFeesUtils interface for documentation

getBorrowingPairOi

Check IBorrowingFeesUtils interface for documentation

getBorrowingPairGroups

Check IBorrowingFeesUtils interface for documentation

getAllBorrowingPairs

Check IBorrowingFeesUtils interface for documentation

getBorrowingGroups

Check IBorrowingFeesUtils interface for documentation

getBorrowingInitialAccFees

Check IBorrowingFeesUtils interface for documentation

getPairMaxOi

Check IBorrowingFeesUtils interface for documentation

getPairMaxOiCollateral

Check IBorrowingFeesUtils interface for documentation

_getSlot

Returns storage slot to use when fetching storage relevant to library

_getStorage

Returns storage pointer for storage struct in diamond contract, at defined slot

_getMultiCollatDiamond

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

validCollateralIndex

Reverts if collateral index is not valid

_getBorrowingPairPendingAccFee

Returns pending acc borrowing fee for a pair on one side only

Parameters

Name
Type
Description

_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

Name
Type
Description

accFee

uint64

new pair acc borrowing fee

_getBorrowingGroupPendingAccFee

Returns pending acc borrowing fee for a borrowing group on one side only

Parameters

Name
Type
Description

_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

Name
Type
Description

accFee

uint64

new group acc borrowing fee

_getBorrowingPendingAccFees

Pure function that returns the new acc borrowing fees and delta between two blocks (for pairs and groups)

Parameters

Name
Type
Description

_input

input data (last acc fees, OIs, fee per block, current block, etc.)

Return Values

Name
Type
Description

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

Pure function that returns the liquidation price for a trade (1e10 precision)

Parameters

Name
Type
Description

_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)

_liquidationParams

liquidation parameters for the trade

_contractsVersion

enum ITradingStorage.ContractsVersion

contracts version of the trade

_pairSpreadP

uint256

pair spread percentage (1e10)

_setBorrowingPairParams

Function to set borrowing pair params

Parameters

Name
Type
Description

_collateralIndex

uint8

index of the collateral

_pairIndex

uint16

index of the pair

_setBorrowingGroupParams

Function to set borrowing group params

Parameters

Name
Type
Description

_collateralIndex

uint8

index of the collateral

_groupIndex

uint16

index of the borrowing group

_updateOi

Function to update a borrowing pair/group open interest

Parameters

Name
Type
Description

_oiStorage

open interest storage reference

_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

Name
Type
Description

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 to update a borrowing group's open interest

Parameters

Name
Type
Description

_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 to update a borrowing group's open interest

Parameters

Name
Type
Description

_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

_Calculates the borrowing group and pair acc fees deltas for a trade between pair group at index i and next one

Parameters

Name
Type
Description

_collateralIndex

uint8

index of the collateral

_i

uint256

index of the borrowing pair group

_pairGroups

all pair's historical borrowing groups

_initialFees

trade initial borrowing fees

_pairIndex

uint16

index of the pair

_long

bool

true if long, false if short

_currentBlock

uint256

current block number

Return Values

Name
Type
Description

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

Parameters

Name
Type
Description

_collateralIndex

uint8

index of the collateral

_pairIndex

uint16

index of the pair

_currentBlock

uint256

current block number

Return Values

Name
Type
Description

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

Parameters

Name
Type
Description

_collateralIndex

uint8

index of the collateral

_groupIndex

uint16

index of the borrowing group

_currentBlock

uint256

current block number

Return Values

Name
Type
Description

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?