Skip to main content
Facet #9: Borrowing Fees and open interests

constructor

constructor() public

setBorrowingPairParams

function setBorrowingPairParams(uint8 _collateralIndex, uint16 _pairIndex, struct IBorrowingFees.BorrowingPairParams _value) external
Updates borrowing pair params of a pair

Parameters

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

setBorrowingPairParamsArray

function setBorrowingPairParamsArray(uint8 _collateralIndex, uint16[] _indices, struct IBorrowingFees.BorrowingPairParams[] _values) external
Updates borrowing pair params of multiple pairs

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_indicesuint16[]indices of the pairs
_valuesIBorrowingFees.BorrowingPairParams[]new values

setBorrowingGroupParams

function setBorrowingGroupParams(uint8 _collateralIndex, uint16 _groupIndex, struct IBorrowingFees.BorrowingGroupParams _value) external
Updates borrowing group params of a group

Parameters

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

setBorrowingGroupParamsArray

function setBorrowingGroupParamsArray(uint8 _collateralIndex, uint16[] _indices, struct IBorrowingFees.BorrowingGroupParams[] _values) external
Updates borrowing group params of multiple groups

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_indicesuint16[]indices of the groups
_valuesIBorrowingFees.BorrowingGroupParams[]new values

handleTradeBorrowingCallback

function handleTradeBorrowingCallback(uint8 _collateralIndex, address _trader, uint16 _pairIndex, uint32 _index, uint256 _positionSizeCollateral, bool _open, bool _long) external virtual
Callback after a trade is opened/closed to store pending borrowing fees and adjust open interests

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_traderaddressaddress of the trader
_pairIndexuint16index of the pair
_indexuint32index of the trade
_positionSizeCollateraluint256position size of the trade in collateral tokens
_openbooltrue if trade has been opened, false if trade has been closed
_longbooltrue if trade is long, false if trade is short

resetTradeBorrowingFees

function resetTradeBorrowingFees(uint8 _collateralIndex, address _trader, uint16 _pairIndex, uint32 _index, bool _long) external virtual
Resets a trade borrowing fee to 0 (useful when new trade opened or when partial trade executed)

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_traderaddressaddress of the trader
_pairIndexuint16index of the pair
_indexuint32index of the trade
_longbooltrue if trade is long, false if trade is short

getBorrowingPairPendingAccFees

function getBorrowingPairPendingAccFees(uint8 _collateralIndex, uint16 _pairIndex, uint256 _currentBlock) public view returns (uint64 accFeeLong, uint64 accFeeShort, uint64 pairAccFeeDelta)
Returns the pending acc borrowing fees for a pair on both sides

Parameters

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

Return Values

NameTypeDescription
accFeeLonguint64new pair acc borrowing fee on long side
accFeeShortuint64new pair acc borrowing fee on short side
pairAccFeeDeltauint64pair acc borrowing fee delta (for side that changed)

getBorrowingGroupPendingAccFees

function getBorrowingGroupPendingAccFees(uint8 _collateralIndex, uint16 _groupIndex, uint256 _currentBlock) public view returns (uint64 accFeeLong, uint64 accFeeShort, uint64 groupAccFeeDelta)
Returns the pending acc borrowing fees for a borrowing group on both sides

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
accFeeShortuint64new group acc borrowing fee on short side
groupAccFeeDeltauint64group acc borrowing fee delta (for side that changed)

getTradeBorrowingFee

function getTradeBorrowingFee(struct IBorrowingFees.BorrowingFeeInput _input) public view returns (uint256 feeAmountCollateral)
Returns the borrowing fee for a trade

Parameters

NameTypeDescription
_inputIBorrowingFees.BorrowingFeeInputinput data (collateralIndex, trader, pairIndex, index, long, collateral, leverage)

Return Values

NameTypeDescription
feeAmountCollateraluint256borrowing fee (collateral precision)

getTradeLiquidationPrice

function getTradeLiquidationPrice(struct IBorrowingFees.LiqPriceInput _input) external view returns (uint256)
Returns the liquidation price for a trade

Parameters

NameTypeDescription
_inputIBorrowingFees.LiqPriceInputinput data (collateralIndex, trader, pairIndex, index, openPrice, long, collateral, leverage)

getPairOisCollateral

function getPairOisCollateral(uint8 _collateralIndex, uint16 _pairIndex) public view returns (uint256 longOi, uint256 shortOi)
Returns the open interests for a pair

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_pairIndexuint16index of the pair

Return Values

NameTypeDescription
longOiuint256open interest on long side
shortOiuint256open interest on short side

getBorrowingPairGroupIndex

function getBorrowingPairGroupIndex(uint8 _collateralIndex, uint16 _pairIndex) public view returns (uint16 groupIndex)
Returns the borrowing group index for a pair

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_pairIndexuint16index of the pair

Return Values

NameTypeDescription
groupIndexuint16borrowing group index

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
_collateralIndexuint8index of the collateral
_pairIndexuint16index of the pair
_longbooltrue if long side

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
_collateralIndexuint8index of the collateral
_pairIndexuint16index of the pair
_longbooltrue if long side
_positionSizeCollateraluint256position size of the trade in collateral tokens

getBorrowingGroup

function getBorrowingGroup(uint8 _collateralIndex, uint16 _groupIndex) external view returns (struct IBorrowingFees.BorrowingData)
Returns a borrowing group’s data

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_groupIndexuint16index of the borrowing group

getBorrowingGroupOi

function getBorrowingGroupOi(uint8 _collateralIndex, uint16 _groupIndex) external view returns (struct IBorrowingFees.OpenInterest)
Returns a borrowing group’s oi data

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_groupIndexuint16index of the borrowing group

getBorrowingPair

function getBorrowingPair(uint8 _collateralIndex, uint16 _pairIndex) external view returns (struct IBorrowingFees.BorrowingData)
Returns a borrowing pair’s data

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_pairIndexuint16index of the pair

getBorrowingPairOi

function getBorrowingPairOi(uint8 _collateralIndex, uint16 _pairIndex) external view returns (struct IBorrowingFees.OpenInterest)
Returns a borrowing pair’s oi data

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_pairIndexuint16index of the pair

getBorrowingPairGroups

function getBorrowingPairGroups(uint8 _collateralIndex, uint16 _pairIndex) external view returns (struct IBorrowingFees.BorrowingPairGroup[])
Returns a borrowing pair’s oi data

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_pairIndexuint16index of the pair

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
_collateralIndexuint8index of the collateral

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
_collateralIndexuint8index of the collateral
_indicesuint16[]indices of the groups

getBorrowingInitialAccFees

function getBorrowingInitialAccFees(uint8 _collateralIndex, address _trader, uint32 _index) external view returns (struct IBorrowingFees.BorrowingInitialAccFees)
Returns borrowing groups’ data

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_traderaddressaddress of trader
_indexuint32index of trade

getPairMaxOi

function getPairMaxOi(uint8 _collateralIndex, uint16 _pairIndex) external view returns (uint256)
Returns the max open interest for a pair

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_pairIndexuint16index of the pair

getPairMaxOiCollateral

function getPairMaxOiCollateral(uint8 _collateralIndex, uint16 _pairIndex) external view returns (uint256)
Returns the max open interest in collateral tokens for a pair

Parameters

NameTypeDescription
_collateralIndexuint8index of the collateral
_pairIndexuint16index of the pair