Skip to content

FeesAccrued Contract Interface

0x0B92C464a41e515559064A737F6A165d43F01d43

FeesAccrued.sol calculates and manages borrowing fees.

getPairBorrowingFee

solidity
function getPairBorrowingFee(
    uint256 pairIndex,
    bool long
)
    public
    view
    returns (uint256 feeP)

Retrieves the borrowing fee percentage for a pair.

Parameters

NameTypeDescription
pairIndexuint256The index of the trading pair.
longboolWhether the position is long or short.

Returns

NameTypeDescription
feePuint256The borrowing fee percentage for the pair.

getTradeBorrowingFee

solidity
function getTradeBorrowingFee(BorrowingFeeInput memory input)
    public
    view
    returns (uint256 fee)

Calculates the borrowing fee for a specific trade.

Parameters

NameTypeDescription
inputBorrowingFeeInputThe input parameters for the trade.

Returns

NameTypeDescription
feeuint256The borrowing fee for the trade (in HONEY).

getTradeLiquidationPrice

solidity
function getTradeLiquidationPrice(LiqPriceInput calldata input)
    external
    view
    returns (uint256)

Calculates the liquidation price for a specific trade.

Parameters

NameTypeDescription
inputLiqPriceInputThe input parameters for the trade.

Returns

TypeDescription
uint256The liquidation price for the trade (in PRECISION).

withinMaxGroupOi

solidity
function withinMaxGroupOi(
    uint256 pairIndex,
    bool long,
    uint256 positionSizeHoney
)
    external
    view
    returns (bool)

Checks if a position size is within the maximum group open interest limit.

Parameters

NameTypeDescription
pairIndexuint256The index of the trading pair.
longboolWhether the position is long or short.
positionSizeHoneyuint256The size of the position (in HONEY).

Returns

TypeDescription
boolTrue if the position size is within the limit, false otherwise.

getGroup

solidity
function getGroup(uint16 groupIndex)
    external
    view
    returns (Group memory)

Retrieves the group information for a specific group index.

Parameters

NameTypeDescription
groupIndexuint16The index of the group.

Returns

TypeDescription
Group memoryThe group information for the specified index.

getPair

solidity
function getPair(uint256 pairIndex)
    external
    view
    returns (Pair memory)

Retrieves the pair information for a specific pair index.

Parameters

NameTypeDescription
pairIndexuint256The index of the trading pair.

Returns

TypeDescription
Pair memoryThe pair information for the specified index.

getAllPairs

solidity
function getAllPairs()
    external
    view
    returns (Pair[] memory)

Retrieves the information for all trading pairs.

Returns

TypeDescription
Pair[] memoryThe array of pair information for all pairs.

getGroups

solidity
function getGroups(uint16[] calldata indices)
    external
    view
    returns (Group[] memory)

Retrieves the group information for the specified indices.

Parameters

NameTypeDescription
indicesuint16[]The array of group indices.

Returns

TypeDescription
Group[] memoryThe array of group information for the specified indices.

getTradeInitialAccFees

solidity
function getTradeInitialAccFees(
    address trader,
    uint256 pairIndex,
    uint256 index
)
    external
    view
    returns (
        InitialAccFees memory feesAccrued,
        IPairInfos.TradeInitialAccFees memory otherFees
    )

Retrieves the initial accumulated fees for a specific trade.

Parameters

NameTypeDescription
traderaddressThe address of the trader.
pairIndexuint256The index of the trading pair.
indexuint256The index of the trade.

Returns

NameTypeDescription
feesAccruedInitialAccFees memoryThe initial accumulated borrowing fees.
otherFeesIPairInfos.TradeInitialAccFees memoryThe initial accumulated fees from PairInfos.

getInitialAccFees

solidity
function getInitialAccFees(
    uint256 offset,
    uint256 count
)
    external
    view
    returns (InitialAccFees[] memory)

Retrieves a range of initial accumulated fees for trades.

Parameters

NameTypeDescription
offsetuint256The starting index of the range.
countuint256The number of items to retrieve.

Returns

TypeDescription
InitialAccFees[] memoryThe array of initial accumulated fees for trades.

getPairPendingAccFees

solidity
function getPairPendingAccFees(
    uint256 pairIndex,
    uint256 currentBlock
)
    public
    view
    returns (
        uint64 accFeeLong,
        uint64 accFeeShort,
        int256 pairAccFeeDelta
    )

Retrieves the pending accumulated fees for a pair.

Parameters

NameTypeDescription
pairIndexuint256The index of the trading pair.
currentBlockuint256The current block number.

Returns

NameTypeDescription
accFeeLonguint64The pending accumulated fee for long positions.
accFeeShortuint64The pending accumulated fee for short positions.
pairAccFeeDeltaint256The change in the pair's accumulated fee.

getPairPendingAccFee

solidity
function getPairPendingAccFee(
    uint256 pairIndex,
    uint256 currentBlock,
    bool long
)
    public
    view
    returns (uint64 accFee)

Retrieves the pending accumulated fee for a pair based on the position type.

Parameters

NameTypeDescription
pairIndexuint256The index of the trading pair.
currentBlockuint256The current block number.
longboolWhether the position is long or short.

Returns

NameTypeDescription
accFeeuint64The pending accumulated fee for the specified position type.

getGroupPendingAccFees

solidity
function getGroupPendingAccFees(
    uint16 groupIndex,
    uint256 currentBlock
)
    public
    view
    returns (
        uint64 accFeeLong,
        uint64 accFeeShort,
        int256 groupAccFeeDelta
    )

Retrieves the pending accumulated fees for a group.

Parameters

NameTypeDescription
groupIndexuint16The index of the group.
currentBlockuint256The current block number.

Returns

NameTypeDescription
accFeeLonguint64The pending accumulated fee for long positions.
accFeeShortuint64The pending accumulated fee for short positions.
groupAccFeeDeltaint256The change in the group's accumulated fee.

getGroupPendingAccFee

solidity
function getGroupPendingAccFee(
    uint16 groupIndex,
    uint256 currentBlock,
    bool long
)
    public
    view
    returns (uint64 accFee)

Retrieves the pending accumulated fee for a group based on the position type.

Parameters

NameTypeDescription
groupIndexuint16The index of the group.
currentBlockuint256The current block number.
longboolWhether the position is long or short.

Returns

NameTypeDescription
accFeeuint64The pending accumulated fee for the specified position type.

getPendingAccFees

solidity
function getPendingAccFees(
    uint64 accFeeLong,
    uint64 accFeeShort,
    uint256 oiLong,
    uint256 oiShort,
    uint32 feePerBlock,
    uint256 currentBlock,
    uint256 accLastUpdatedBlock,
    uint256 vaultMarketCap
)
    public
    pure
    returns (
        uint64 newAccFeeLong,
        uint64 newAccFeeShort,
        int256 delta
    )

Calculates the pending accumulated fees based on various parameters.

Parameters

NameTypeDescription
accFeeLonguint64The current accumulated fee for long positions.
accFeeShortuint64The current accumulated fee for short positions.
oiLonguint256The open interest for long positions.
oiShortuint256The open interest for short positions.
feePerBlockuint32The fee per block.
currentBlockuint256The current block number.
accLastUpdatedBlockuint256The block number of the last fee update.
vaultMarketCapuint256The market cap of the vault.

Returns

NameTypeDescription
newAccFeeLonguint64The new accumulated fee for long positions.
newAccFeeShortuint64The new accumulated fee for short positions.
deltaint256The change in the accumulated fee.

getPairGroupAccFeesDeltasNoTrade

solidity
function getPairGroupAccFeesDeltasNoTrade(
    uint256 i,
    PairGroup[] memory pairGroups,
    uint256 pairIndex,
    bool long,
    uint256 currentBlock
)
    public
    view
    returns (uint64 deltaGroup, uint64 deltaPair)

Retrieves the accumulated fee deltas for a pair group when no trade is active.

Parameters

NameTypeDescription
iuint256The index of the pair group.
pairGroupsPairGroup[] memoryThe array of pair groups.
pairIndexuint256The index of the trading pair.
longboolWhether the position is long or short.
currentBlockuint256The current block number.

Returns

NameTypeDescription
deltaGroupuint64The accumulated fee delta for the group.
deltaPairuint64The accumulated fee delta for the pair.

getPairGroupAccFeesDeltas

solidity
function getPairGroupAccFeesDeltas(
    uint256 i,
    PairGroup[] memory pairGroups,
    InitialAccFees memory initialFees,
    uint256 pairIndex,
    bool long,
    uint256 currentBlock
)
    public
    view
    returns (
        uint64 deltaGroup,
        uint64 deltaPair,
        bool beforeTradeOpen
    )

Retrieves the accumulated fee deltas for a pair group.

Parameters

NameTypeDescription
iuint256The index of the pair group.
pairGroupsPairGroup[] memoryThe array of pair groups.
initialFeesInitialAccFees memoryThe initial accumulated fees.
pairIndexuint256The index of the trading pair.
longboolWhether the position is long or short.
currentBlockuint256The current block number.

Returns

NameTypeDescription
deltaGroupuint64The accumulated fee delta for the group.
deltaPairuint64The accumulated fee delta for the pair.
beforeTradeOpenboolWhether the pair group is before the trade opening.

getPairOpenInterestHoney

solidity
function getPairOpenInterestHoney(uint256 pairIndex)
    public
    view
    returns (uint256, uint256, uint256)

Retrieves the open interest in HONEY for a pair.

Parameters

NameTypeDescription
pairIndexuint256The index of the trading pair.

Returns

TypeDescription
uint256The open interest for long positions.
uint256The open interest for short positions.
uint256The maximum open interest.

getPairGroupIndex

solidity
function getPairGroupIndex(uint256 pairIndex)
    public
    view
    returns (uint16 groupIndex)

Retrieves the group index for a pair.

Parameters

NameTypeDescription
pairIndexuint256The index of the trading pair.

Returns

NameTypeDescription
groupIndexuint16The index of the group the pair belongs to.

getPendingAccBlockWeightedMarketCap

solidity
function getPendingAccBlockWeightedMarketCap(uint256 currentBlock)
    public
    view
    returns (uint256)

Retrieves the pending accumulated block-weighted market cap.

Parameters

NameTypeDescription
currentBlockuint256The current block number.

Returns

TypeDescription
uint256The pending accumulated block-weighted market cap.

getGroupWeightedVaultMarketCapSinceLastUpdate

solidity
function getGroupWeightedVaultMarketCapSinceLastUpdate(
    uint16 groupIndex,
    uint256 currentBlock
)
    public
    view
    returns (uint256)

Retrieves the group's weighted vault market cap since the last update.

Parameters

NameTypeDescription
groupIndexuint16The index of the group.
currentBlockuint256The current block number.

Returns

TypeDescription
uint256The group's weighted vault market cap since the last update.

getPairWeightedVaultMarketCapSinceLastUpdate

solidity
function getPairWeightedVaultMarketCapSinceLastUpdate(
    uint256 pairIndex,
    uint256 currentBlock
)
    public
    view
    returns (uint256)

Retrieves the pair's weighted vault market cap since the last update.

Parameters

NameTypeDescription
pairIndexuint256The index of the trading pair.
currentBlockuint256The current block number.

Returns

TypeDescription
uint256The pair's weighted vault market cap since the last update.

getWeightedVaultMarketCap

solidity
function getWeightedVaultMarketCap(
    uint256 accBlockWeightedMarketCap,
    uint256 lastAccBlockWeightedMarketCap,
    uint256 blockDelta
)
    public
    pure
    returns (uint256)

Calculates the weighted vault market cap based on various parameters.

Parameters

NameTypeDescription
accBlockWeightedMarketCapuint256The accumulated block-weighted market cap.
lastAccBlockWeightedMarketCapuint256The last accumulated block-weighted market cap.
blockDeltauint256The difference in block numbers.

Returns

TypeDescription
uint256The calculated weighted vault market cap.

getPairsCurrentAPR

solidity
function getPairsCurrentAPR(uint256[] calldata indices)
    external
    view
    returns (uint64[] memory borrowAPRLong, uint64[] memory borrowAPRShort)

Retrieves the current annual percentage rate (APR) for the specified pairs.

Parameters

NameTypeDescription
indicesuint256[]The array of pair indices.

Returns

NameTypeDescription
borrowAPRLonguint64[]The current APR for long positions of each pair.
borrowAPRShortuint64[]The current APR for short positions of each pair.

getGroupsCurrentAPR

solidity
function getGroupsCurrentAPR(uint16[] calldata indices)
    external
    view
    returns (uint64[] memory borrowAPRLong, uint64[] memory borrowAPRShort)

Retrieves the current annual percentage rate (APR) for the specified groups.

Parameters

NameTypeDescription
indicesuint16[]The array of group indices.

Returns

NameTypeDescription
borrowAPRLonguint64[]The current APR for long positions of each group.
borrowAPRShortuint64[]The current APR for short positions of each group.

getTradesLiquidationPrices

solidity
function getTradesLiquidationPrices(uint256[] calldata tradeIndices)
    external
    view
    returns (int64[] memory liqPrices, uint256[] memory borrowFees)

Retrieves the liquidation prices and borrowing fees for the specified trade indices.

Parameters

NameTypeDescription
tradeIndicesuint256[]The array of trade indices.

Returns

NameTypeDescription
liqPricesint64[]The liquidation prices for each trade.
borrowFeesuint256[]The borrowing fees for each trade.

getPairsOpenInterest

solidity
function getPairsOpenInterest(uint256[] calldata indices)
    external
    view
    returns (uint256[] memory longOIs, uint256[] memory shortOIs, uint256[] memory maxOIs)

Retrieves the current open interest for the specified pairs.

Parameters

NameTypeDescription
indicesuint256[]The array of pair indices.

Returns

NameTypeDescription
longOIsuint256[]The open interest for long positions of each pair.
shortOIsuint256[]The open interest for short positions of each pair.
maxOIsuint256[]The maximum open interest allowed for each pair.

getAllPairs

solidity
function getAllPairs() external view returns (Pair[] memory p)

Retrieves all pairs.

Returns

NameTypeDescription
pPair[]The array of all pairs.

getTradeInitialAccFees

solidity
function getTradeInitialAccFees(uint256 tradeIndex)
    external
    view
    returns (InitialAccFees memory feesAccrued, IFeesMarkets.TradeInitialAccFees memory otherFees)

Retrieves the initial accumulated fees for a specific trade.

Parameters

NameTypeDescription
tradeIndexuint256The index of the trade.

Returns

NameTypeDescription
feesAccruedInitialAccFeesThe initial accumulated fees from FeesAccrued.
otherFeesIFeesMarkets.TradeInitialAccFeesThe initial accumulated fees from FeesMarkets.

Structs

solidity
struct PairGroup {
    uint16 groupIndex;
    uint48 block;
    uint64 initialAccFeeLong; // 1e10 (%)
    uint64 initialAccFeeShort; // 1e10 (%)
    uint64 prevGroupAccFeeLong; // 1e10 (%)
    uint64 prevGroupAccFeeShort; // 1e10 (%)
    uint64 pairAccFeeLong; // 1e10 (%)
    uint64 pairAccFeeShort; // 1e10 (%)
    uint64 _placeholder; // might be useful later
}

struct Pair {
    PairGroup[] groups;
    uint32 feePerBlock; // 1e10 (%)
    uint64 accFeeLong; // 1e10 (%)
    uint64 accFeeShort; // 1e10 (%)
    uint48 accLastUpdatedBlock;
    uint48 _placeholder; // might be useful later
    uint256 lastAccBlockWeightedMarketCap; // 1e40
}

struct Group {
    uint112 oiLong; // 1e10
    uint112 oiShort; // 1e10
    uint32 feePerBlock; // 1e10 (%)
    uint64 accFeeLong; // 1e10 (%)
    uint64 accFeeShort; // 1e10 (%)
    uint48 accLastUpdatedBlock;
    uint80 maxOi; // 1e10
    uint256 lastAccBlockWeightedMarketCap; // 1e40
}

struct InitialAccFees {
    bytes32 tradeKey; // tradeKeyFor: (address trader, uint256 pairIndex, uint256 index)
    uint64 accPairFee; // 1e10 (%)
    uint64 accGroupFee; // 1e10 (%)
    uint48 block;
    uint80 _placeholder; // might be useful later
}

struct PairParams {
    uint16 groupIndex;
    uint32 feePerBlock; // 1e10 (%)
}

struct GroupParams {
    uint32 feePerBlock; // 1e10 (%)
    uint80 maxOi; // 1e10
}

struct BorrowingFeeInput {
    address trader;
    uint256 pairIndex;
    uint256 index;
    bool long;
    uint256 collateral; // 1e18 (HONEY)
    uint256 leverage;
}

struct LiqPriceInput {
    address trader;
    uint256 pairIndex;
    uint256 index;
    uint256 openPrice; // 1e10
    bool long;
    uint256 collateral; // 1e18 (HONEY)
    uint256 leverage;
}