Skip to content

FeesMarkets Contract Interface

0xd8c63AA3B1dCBA8a8781bf9C4E3F8F06305a459d

FeesMarkets.sol calculates and manages fees related to trading pairs.

Functions

getTradePriceImpact

solidity
function getTradePriceImpact(
    int64 openPrice,
    uint256 pairIndex,
    bool long,
    uint256 tradeOpenInterest
) external view returns (int64 priceImpactP, int64 priceAfterImpact)

Calculates the price impact of a trade.

Parameters

NameTypeDescription
openPriceint64The opening price of the trade.
pairIndexuint256The index of the pair.
longboolWhether the trade is a long position.
tradeOpenInterestuint256The open interest of the trade.

Returns

NameTypeDescription
priceImpactPint64The price impact percentage.
priceAfterImpactint64The price after applying the impact.

getTradePriceImpactPure

solidity
function getTradePriceImpactPure(
    int64 openPrice,
    bool long,
    uint256 startOpenInterest,
    uint256 tradeOpenInterest,
    uint256 onePercentDepth
) public pure returns (int64 priceImpactP, int64 priceAfterImpact)

Calculates the price impact of a trade using pure function.

Parameters

NameTypeDescription
openPriceint64The opening price of the trade.
longboolWhether the trade is a long position.
startOpenInterestuint256The starting open interest.
tradeOpenInterestuint256The open interest of the trade.
onePercentDepthuint256The one percent depth.

Returns

NameTypeDescription
priceImpactPint64The price impact percentage.
priceAfterImpactint64The price after applying the impact.

getTradeRolloverFee

solidity
function getTradeRolloverFee(
    uint256 pairIndex,
    uint256 tradeIndex,
    uint256 collateral
) public view returns (uint256)

Calculates the rollover fee for a trade.

Parameters

NameTypeDescription
pairIndexuint256The index of the pair.
tradeIndexuint256The index of the trade.
collateraluint256The collateral amount of the trade.

Returns

TypeDescription
uint256The rollover fee for the trade.

getPendingAccRolloverFees

solidity
function getPendingAccRolloverFees(uint256 pairIndex) public view returns (uint256)

Retrieves the pending accumulated rollover fees for a specific pair.

Parameters

NameTypeDescription
pairIndexuint256The index of the pair.

Returns

TypeDescription
uint256The pending accumulated rollover fees.

getTradeFundingFee

solidity
function getTradeFundingFee(
    uint256 pairIndex,
    uint256 tradeIndex,
    bool long,
    uint256 collateral,
    uint256 leverage
) public view returns (int256)

Calculates the funding fee for a trade.

Parameters

NameTypeDescription
pairIndexuint256The index of the pair.
tradeIndexuint256The index of the trade.
longboolWhether the trade is a long position.
collateraluint256The collateral amount of the trade.
leverageuint256The leverage of the trade.

Returns

TypeDescription
int256The funding fee for the trade. Positive value indicates a fee, negative value indicates a reward.

getTradeLiquidationPrice

solidity
function getTradeLiquidationPrice(
    uint256 pairIndex,
    uint256 index,
    int64 openPrice,
    bool long,
    uint256 collateral,
    uint256 leverage
) external view returns (int64)

Calculates the liquidation price for a trade.

Parameters

NameTypeDescription
pairIndexuint256The index of the pair.
indexuint256The index of the trade.
openPriceint64The opening price of the trade.
longboolWhether the trade is a long position.
collateraluint256The collateral amount of the trade.
leverageuint256The leverage of the trade.

Returns

TypeDescription
int64The liquidation price for the trade.

getTradeValuePure

solidity
function getTradeValuePure(
    uint256 collateral,
    int256 percentProfit,
    uint256 rolloverFee,
    int256 fundingFee,
    uint256 closingFee
) public pure returns (uint256)

Calculates the trade value after applying PnL and fees.

Parameters

NameTypeDescription
collateraluint256The collateral amount of the trade (1e18 HONEY).
percentProfitint256The percentage profit of the trade.
rolloverFeeuint256The rollover fee of the trade (1e18 HONEY).
fundingFeeint256The funding fee of the trade (1e18 HONEY).
closingFeeuint256The closing fee of the trade.

Returns

NameTypeDescription
valueuint256The trade value after applying PnL and fees.

getPair

solidity
function getPair(uint256 pairIndex) external view returns (
    PairParams memory,
    PairRolloverFees memory,
    PairFundingFees memory
)

Retrieves the parameters and fees for a specific pair.

Parameters

NameTypeDescription
pairIndexuint256The index of the pair.

Returns

NameTypeDescription
-PairParamsThe parameters of the pair.
-PairRolloverFeesThe rollover fees of the pair.
-PairFundingFeesThe funding fees of the pair.

getAllPairs

solidity
function getAllPairs() external view returns (
    PairParams[] memory,
    PairRolloverFees[] memory,
    PairFundingFees[] memory
)

Retrieves the parameters and fees for all pairs.

Returns

NameTypeDescription
-PairParams[]The array of parameters for all pairs.
-PairRolloverFees[]The array of rollover fees for all pairs.
-PairFundingFees[]The array of funding fees for all pairs.

getOnePercentDepthAbove

solidity
function getOnePercentDepthAbove(uint256 pairIndex) external view returns (uint256)

Retrieves the one percent depth above the price for a specific pair.

Parameters

NameTypeDescription
pairIndexuint256The index of the pair.

Returns

TypeDescription
uint256The one percent depth above the price.

getOnePercentDepthBelow

solidity
function getOnePercentDepthBelow(uint256 pairIndex) external view returns (uint256)

Retrieves the one percent depth below the price for a specific pair.

Parameters

NameTypeDescription
pairIndexuint256The index of the pair.

Returns

TypeDescription
uint256The one percent depth below the price.

getRolloverFeePerBlockP

solidity
function getRolloverFeePerBlockP(uint256 pairIndex) external view returns (uint256)

Retrieves the rollover fee per block for a specific pair.

Parameters

NameTypeDescription
pairIndexuint256The index of the pair.

Returns

TypeDescription
uint256The rollover fee per block.

getFundingFeePerBlockP

solidity
function getFundingFeePerBlockP(uint256 pairIndex) external view returns (uint256)

Retrieves the funding fee per block for a specific pair.

Parameters

NameTypeDescription
pairIndexuint256The index of the pair.

Returns

TypeDescription
uint256The funding fee per block.

getAccRolloverFees

solidity
function getAccRolloverFees(uint256 pairIndex) external view returns (uint256)

Retrieves the accumulated rollover fees for a specific pair.

Parameters

NameTypeDescription
pairIndexuint256The index of the pair.

Returns

TypeDescription
uint256The accumulated rollover fees.

getAccRolloverFeesUpdateBlock

solidity
function getAccRolloverFeesUpdateBlock(uint256 pairIndex) external view returns (uint256)

Retrieves the last update block for the accumulated rollover fees of a specific pair.

Parameters

NameTypeDescription
pairIndexuint256The index of the pair.

Returns

TypeDescription
uint256The last update block for the accumulated rollover fees.

getAccFundingFeesLong

solidity
function getAccFundingFeesLong(uint256 pairIndex) external view returns (int256)

Retrieves the accumulated funding fees for long positions of a specific pair.

Parameters

NameTypeDescription
pairIndexuint256The index of the pair.

Returns

TypeDescription
int256The accumulated funding fees for long positions.

getAccFundingFeesShort

solidity
function getAccFundingFeesShort(uint256 pairIndex) external view returns (int256)

Retrieves the accumulated funding fees for short positions of a specific pair.

Parameters

NameTypeDescription
pairIndexuint256The index of the pair.

Returns

TypeDescription
int256The accumulated funding fees for short positions.

getAccFundingFeesUpdateBlock

solidity
function getAccFundingFeesUpdateBlock(uint256 pairIndex) external view returns (uint256)

Retrieves the last update block for the accumulated funding fees of a specific pair.

Parameters

NameTypeDescription
pairIndexuint256The index of the pair.

Returns

TypeDescription
uint256The last update block for the accumulated funding fees.

tradeInitialAccFees

solidity
function tradeInitialAccFees(uint256 tradeIndex) external view returns (TradeInitialAccFees memory)

Retrieves the initial accumulated fees for a specific trade.

Parameters

NameTypeDescription
tradeIndexuint256The index of the trade.

Returns

TypeDescription
TradeInitialAccFeesThe initial accumulated fees for the trade.

getTradeInitialAccFees

solidity
function getTradeInitialAccFees(
    uint256 offset,
    uint256 count
) external view returns (TradeInitialAccFees[] 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
TradeInitialAccFees[]The array of initial accumulated fees for trades.

Structs

solidity
struct TradeInitialAccFees {
    bytes32 tradeKey; // tradeKeyFor: (address trader, uint256 pairIndex, uint256 index)
    uint256 rollover; // 1e18 (HONEY)
    int256 funding; // 1e18 (HONEY)
    bool openedAfterUpdate;
}

struct PairParams {
    uint256 onePercentDepthAbove; // HONEY
    uint256 onePercentDepthBelow; // HONEY
    uint256 rolloverFeePerBlockP; // PRECISION (%) // rolling over when
        // position open (flat fee)
    uint256 fundingFeePerBlockP; // PRECISION (%) // funding fee per block
        // (received/provided for long/short)
}

struct PairFundingFees {
    int256 accPerOiLong; // 1e18 (HONEY) // accrued funding fee per oi long
    int256 accPerOiShort; // 1e18 (HONEY) // accrued funding fee per oi
        // short
    uint256 lastUpdateBlock;
}

// accrued per collateral
struct PairRolloverFees {
    uint256 accPerCollateral; // 1e18 (HONEY)
    uint256 lastUpdateBlock;
}