GNSBorrowingFees

Facet #9: Borrowing Fees and open interests

Methods

getAllBorrowingPairs

function getAllBorrowingPairs(uint8 _collateralIndex) external view returns (struct IBorrowingFees.BorrowingData[], struct IBorrowingFees.OpenInterest[], struct IBorrowingFees.BorrowingPairGroup[][])

Returns all borrowing pairs' borrowing data, oi data, and pair groups data

Parameters

NameTypeDescription

_collateralIndex

uint8

index of the collateral

Returns

getBorrowingGroup

function getBorrowingGroup(uint8 _collateralIndex, uint16 _groupIndex) external view returns (struct IBorrowingFees.BorrowingData)

Returns a borrowing group's data

Parameters

NameTypeDescription

_collateralIndex

uint8

index of the collateral

_groupIndex

uint16

index of the borrowing group

Returns

NameTypeDescription

_0

getBorrowingGroupOi

function getBorrowingGroupOi(uint8 _collateralIndex, uint16 _groupIndex) external view returns (struct IBorrowingFees.OpenInterest)

Returns a borrowing group's oi data

Parameters

NameTypeDescription

_collateralIndex

uint8

index of the collateral

_groupIndex

uint16

index of the borrowing group

Returns

NameTypeDescription

_0

getBorrowingGroupPendingAccFees

function getBorrowingGroupPendingAccFees(uint8 _collateralIndex, uint16 _groupIndex, uint256 _currentBlock) external view returns (uint64 accFeeLong, uint64 accFeeShort, uint64 groupAccFeeDelta)

Returns the pending acc borrowing fees for a borrowing group on both sides

Parameters

NameTypeDescription

_collateralIndex

uint8

index of the collateral

_groupIndex

uint16

index of the borrowing group

_currentBlock

uint256

current block number

Returns

NameTypeDescription

accFeeLong

uint64

new group acc borrowing fee on long side

accFeeShort

uint64

new group acc borrowing fee on short side

groupAccFeeDelta

uint64

group acc borrowing fee delta (for side that changed)

getBorrowingGroups

function getBorrowingGroups(uint8 _collateralIndex, uint16[] _indices) external view returns (struct IBorrowingFees.BorrowingData[], struct IBorrowingFees.OpenInterest[])

Returns borrowing groups' data and oi data

Parameters

NameTypeDescription

_collateralIndex

uint8

index of the collateral

_indices

uint16[]

indices of the groups

Returns

getBorrowingInitialAccFees

function getBorrowingInitialAccFees(uint8 _collateralIndex, address _trader, uint32 _index) external view returns (struct IBorrowingFees.BorrowingInitialAccFees)

Returns borrowing groups' data

Parameters

NameTypeDescription

_collateralIndex

uint8

index of the collateral

_trader

address

address of trader

_index

uint32

index of trade

Returns

getBorrowingPair

function getBorrowingPair(uint8 _collateralIndex, uint16 _pairIndex) external view returns (struct IBorrowingFees.BorrowingData)

Returns a borrowing pair's data

Parameters

NameTypeDescription

_collateralIndex

uint8

index of the collateral

_pairIndex

uint16

index of the pair

Returns

NameTypeDescription

_0

getBorrowingPairGroupIndex

function getBorrowingPairGroupIndex(uint8 _collateralIndex, uint16 _pairIndex) external view returns (uint16 groupIndex)

Returns the borrowing group index for a pair

Parameters

NameTypeDescription

_collateralIndex

uint8

index of the collateral

_pairIndex

uint16

index of the pair

Returns

NameTypeDescription

groupIndex

uint16

borrowing group index

getBorrowingPairGroups

function getBorrowingPairGroups(uint8 _collateralIndex, uint16 _pairIndex) external view returns (struct IBorrowingFees.BorrowingPairGroup[])

Returns a borrowing pair's oi data

Parameters

NameTypeDescription

_collateralIndex

uint8

index of the collateral

_pairIndex

uint16

index of the pair

Returns

NameTypeDescription

_0

getBorrowingPairOi

function getBorrowingPairOi(uint8 _collateralIndex, uint16 _pairIndex) external view returns (struct IBorrowingFees.OpenInterest)

Returns a borrowing pair's oi data

Parameters

NameTypeDescription

_collateralIndex

uint8

index of the collateral

_pairIndex

uint16

index of the pair

Returns

NameTypeDescription

_0

IBorrowingFees.OpenInterest

getBorrowingPairPendingAccFees

function getBorrowingPairPendingAccFees(uint8 _collateralIndex, uint16 _pairIndex, uint256 _currentBlock) external view returns (uint64 accFeeLong, uint64 accFeeShort, uint64 pairAccFeeDelta)

Returns the pending acc borrowing fees for a pair on both sides

Parameters

NameTypeDescription

_collateralIndex

uint8

index of the collateral

_pairIndex

uint16

index of the pair

_currentBlock

uint256

current block number

Returns

NameTypeDescription

accFeeLong

uint64

new pair acc borrowing fee on long side

accFeeShort

uint64

new pair acc borrowing fee on short side

pairAccFeeDelta

uint64

pair acc borrowing fee delta (for side that changed)

getPairMaxOi

function getPairMaxOi(uint8 _collateralIndex, uint16 _pairIndex) external view returns (uint256)

Returns the max open interest for a pair

Parameters

NameTypeDescription

_collateralIndex

uint8

index of the collateral

_pairIndex

uint16

index of the pair

Returns

NameTypeDescription

_0

uint256

getPairMaxOiCollateral

function getPairMaxOiCollateral(uint8 _collateralIndex, uint16 _pairIndex) external view returns (uint256)

Returns the max open interest in collateral tokens for a pair

Parameters

NameTypeDescription

_collateralIndex

uint8

index of the collateral

_pairIndex

uint16

index of the pair

Returns

NameTypeDescription

_0

uint256

getPairOiCollateral

function getPairOiCollateral(uint8 _collateralIndex, uint16 _pairIndex, bool _long) external view returns (uint256)

Returns the open interest in collateral tokens for a pair on one side

Parameters

NameTypeDescription

_collateralIndex

uint8

index of the collateral

_pairIndex

uint16

index of the pair

_long

bool

true if long side

Returns

NameTypeDescription

_0

uint256

getPairOisCollateral

function getPairOisCollateral(uint8 _collateralIndex, uint16 _pairIndex) external view returns (uint256 longOi, uint256 shortOi)

Returns the open interests for a pair

Parameters

NameTypeDescription

_collateralIndex

uint8

index of the collateral

_pairIndex

uint16

index of the pair

Returns

NameTypeDescription

longOi

uint256

open interest on long side

shortOi

uint256

open interest on short side

getTradeBorrowingFee

function getTradeBorrowingFee(IBorrowingFees.BorrowingFeeInput _input) external view returns (uint256 feeAmountCollateral)

Parameters

NameTypeDescription

_input

Returns

NameTypeDescription

feeAmountCollateral

uint256

getTradeLiquidationPrice

function getTradeLiquidationPrice(IBorrowingFees.LiqPriceInput _input) external view returns (uint256)

Parameters

NameTypeDescription

_input

Returns

NameTypeDescription

_0

uint256

handleTradeBorrowingCallback

function handleTradeBorrowingCallback(uint8 _collateralIndex, address _trader, uint16 _pairIndex, uint32 _index, uint256 _positionSizeCollateral, bool _open, bool _long) external nonpayable

Callback after a trade is opened/closed to store pending borrowing fees and adjust open interests

Parameters

NameTypeDescription

_collateralIndex

uint8

index of the collateral

_trader

address

address of the trader

_pairIndex

uint16

index of the pair

_index

uint32

index of the trade

_positionSizeCollateral

uint256

position size of the trade in collateral tokens

_open

bool

true if trade has been opened, false if trade has been closed

_long

bool

true if trade is long, false if trade is short

setBorrowingGroupParams

function setBorrowingGroupParams(uint8 _collateralIndex, uint16 _groupIndex, IBorrowingFees.BorrowingGroupParams _value) external nonpayable

Parameters

NameTypeDescription

_collateralIndex

uint8

_groupIndex

uint16

_value

setBorrowingGroupParamsArray

function setBorrowingGroupParamsArray(uint8 _collateralIndex, uint16[] _indices, IBorrowingFees.BorrowingGroupParams[] _values) external nonpayable

Parameters

NameTypeDescription

_collateralIndex

uint8

_indices

uint16[]

_values

setBorrowingPairParams

function setBorrowingPairParams(uint8 _collateralIndex, uint16 _pairIndex, IBorrowingFees.BorrowingPairParams _value) external nonpayable

Parameters

NameTypeDescription

_collateralIndex

uint8

_pairIndex

uint16

_value

setBorrowingPairParamsArray

function setBorrowingPairParamsArray(uint8 _collateralIndex, uint16[] _indices, IBorrowingFees.BorrowingPairParams[] _values) external nonpayable

Parameters

NameTypeDescription

_collateralIndex

uint8

_indices

uint16[]

_values

withinMaxBorrowingGroupOi

function withinMaxBorrowingGroupOi(uint8 _collateralIndex, uint16 _pairIndex, bool _long, uint256 _positionSizeCollateral) external view returns (bool)

Returns whether a trade is within the max group borrowing open interest

Parameters

NameTypeDescription

_collateralIndex

uint8

index of the collateral

_pairIndex

uint16

index of the pair

_long

bool

true if long side

_positionSizeCollateral

uint256

position size of the trade in collateral tokens

Returns

NameTypeDescription

_0

bool

Events

BorrowingGroupAccFeesUpdated

event BorrowingGroupAccFeesUpdated(uint8 indexed collateralIndex, uint16 indexed groupIndex, uint256 currentBlock, uint64 accFeeLong, uint64 accFeeShort)

Emitted when a group's borrowing acc fees are updated

Parameters

NameTypeDescription

collateralIndex indexed

uint8

groupIndex indexed

uint16

index of the borrowing group

currentBlock

uint256

current block number

accFeeLong

uint64

new group acc borrowing fee on long side

accFeeShort

uint64

new group acc borrowing fee on short side

BorrowingGroupOiUpdated

event BorrowingGroupOiUpdated(uint8 indexed collateralIndex, uint16 indexed groupIndex, bool long, bool increase, uint72 delta, uint72 newOiLong, uint72 newOiShort)

Emitted when a borrowing group's open interests are updated

Parameters

NameTypeDescription

collateralIndex indexed

uint8

groupIndex indexed

uint16

index of the borrowing group

long

bool

true if long side

increase

bool

true if open interest is increased, false if decreased

delta

uint72

change in open interest in collateral tokens (1e10 precision)

newOiLong

uint72

new open interest on long side

newOiShort

uint72

new open interest on short side

BorrowingGroupUpdated

event BorrowingGroupUpdated(uint8 indexed collateralIndex, uint16 indexed groupIndex, uint32 feePerBlock, uint72 maxOi, uint48 feeExponent)

Emitted when a group's borrowing params is updated

Parameters

NameTypeDescription

collateralIndex indexed

uint8

groupIndex indexed

uint16

index of the group

feePerBlock

uint32

new fee per block

maxOi

uint72

new max open interest

feeExponent

uint48

new fee exponent

BorrowingInitialAccFeesStored

event BorrowingInitialAccFeesStored(uint8 indexed collateralIndex, address indexed trader, uint16 indexed pairIndex, uint32 index, uint64 initialPairAccFee, uint64 initialGroupAccFee)

Emitted when a trade's initial acc borrowing fees are stored

Parameters

NameTypeDescription

collateralIndex indexed

uint8

trader indexed

address

address of the trader

pairIndex indexed

uint16

index of the pair

index

uint32

index of the trade

initialPairAccFee

uint64

initial pair acc fee (for the side of the trade)

initialGroupAccFee

uint64

initial group acc fee (for the side of the trade)

BorrowingPairAccFeesUpdated

event BorrowingPairAccFeesUpdated(uint8 indexed collateralIndex, uint16 indexed pairIndex, uint256 currentBlock, uint64 accFeeLong, uint64 accFeeShort)

Emitted when a pair's borrowing acc fees are updated

Parameters

NameTypeDescription

collateralIndex indexed

uint8

pairIndex indexed

uint16

index of the pair

currentBlock

uint256

current block number

accFeeLong

uint64

new pair acc borrowing fee on long side

accFeeShort

uint64

new pair acc borrowing fee on short side

BorrowingPairGroupUpdated

event BorrowingPairGroupUpdated(uint8 indexed collateralIndex, uint16 indexed pairIndex, uint16 prevGroupIndex, uint16 newGroupIndex)

Emitted when a pair's borrowing group has been updated

Parameters

NameTypeDescription

collateralIndex indexed

uint8

pairIndex indexed

uint16

index of the pair

prevGroupIndex

uint16

previous borrowing group index

newGroupIndex

uint16

new borrowing group index

BorrowingPairOiUpdated

event BorrowingPairOiUpdated(uint8 indexed collateralIndex, uint16 indexed pairIndex, bool long, bool increase, uint72 delta, uint72 newOiLong, uint72 newOiShort)

Emitted when a borrowing pair's open interests are updated

Parameters

NameTypeDescription

collateralIndex indexed

uint8

pairIndex indexed

uint16

index of the pair

long

bool

true if long side

increase

bool

true if open interest is increased, false if decreased

delta

uint72

change in open interest in collateral tokens (1e10 precision)

newOiLong

uint72

new open interest on long side

newOiShort

uint72

new open interest on short side

BorrowingPairParamsUpdated

event BorrowingPairParamsUpdated(uint8 indexed collateralIndex, uint16 indexed pairIndex, uint16 indexed groupIndex, uint32 feePerBlock, uint48 feeExponent, uint72 maxOi)

Emitted when a pair's borrowing params is updated

Parameters

NameTypeDescription

collateralIndex indexed

uint8

pairIndex indexed

uint16

index of the pair

groupIndex indexed

uint16

index of its new group

feePerBlock

uint32

new fee per block

feeExponent

uint48

new fee exponent

maxOi

uint72

new max open interest

TradeBorrowingCallbackHandled

event TradeBorrowingCallbackHandled(uint8 indexed collateralIndex, address indexed trader, uint16 indexed pairIndex, uint32 index, bool open, bool long, uint256 positionSizeCollateral)

Emitted when a trade is executed and borrowing callback is handled

Parameters

NameTypeDescription

collateralIndex indexed

uint8

trader indexed

address

address of the trader

pairIndex indexed

uint16

index of the pair

index

uint32

index of the trade

open

bool

true if trade has been opened, false if trade has been closed

long

bool

true if trade is long, false if trade is short

positionSizeCollateral

uint256

position size of the trade in collateral tokens

Errors

AboveMax

error AboveMax()

AlreadyExists

error AlreadyExists()

BelowMin

error BelowMin()

BlockOrder

error BlockOrder()

BorrowingWrongExponent

error BorrowingWrongExponent()

BorrowingZeroGroup

error BorrowingZeroGroup()

DoesntExist

error DoesntExist()

InitError

error InitError()

InvalidAddresses

error InvalidAddresses()

InvalidCollateralIndex

error InvalidCollateralIndex()

InvalidInputLength

error InvalidInputLength()

NotAllowed

error NotAllowed()

NotAuthorized

error NotAuthorized()

Overflow

error Overflow()

Paused

error Paused()

WrongAccess

error WrongAccess()

WrongIndex

error WrongIndex()

WrongLength

error WrongLength()

WrongOrder

error WrongOrder()

WrongParams

error WrongParams()

WrongTradeType

error WrongTradeType()

ZeroAddress

error ZeroAddress()

ZeroValue

error ZeroValue()

Last updated