Skip to main content

Overview

  • Borrowing fees are charged on both sides of a pair, long and short — they are not directional. Where the pair still uses the open-interest mechanism below, the heavier side pays the rate derived from the imbalance and the lighter side pays the minP floor
  • Per-second borrowing (v2) and per-block borrowing (v1) have independent settings. A non-zero borrowingFees.v2.pairParams[pairIndex].borrowingRatePerSecondP means v2 is accruing; it does not select v2 instead of v1
  • Total borrowing fees include both v1 and v2 accrued fees. A current zero rate does not erase fees accrued before a rate change
  • For v1, where a pair belongs to a group, calculate the pair and group fees for the trade’s side and charge the higher of the two. The pair’s lighter-side minP floor can therefore be exceeded by its group fee
  • V1 uses the trader’s position size (collateral times leverage). V2 applies its rate to the price-adjusted notional described below

Borrowing fee per second (v2)

Read collaterals[i].borrowingFees.v2.pairParams[pairIndex].borrowingRatePerSecondP from trading-variables. It is a percentage per second with 1e10 precision, identical for longs and shorts. The hourly percentage is borrowingRatePerSecondP / 1e10 * 3600, applied to collateral * leverage * currentPrice / openPrice rather than just the opening collateral times leverage. To calculate pending v2 fees for an existing trade, use its accumulator difference. With raw contract units:
accBorrowingFeeP and lastBorrowingUpdateTs come from collaterals[i].borrowingFees.v2.pairData[pairIndex]. The trade’s initialAccBorrowingFeeP comes from getTradeFeesData(trader, index). Both accumulators use 1e20 precision; currentPairPrice and openPrice use 1e10 precision; timestamps are Unix seconds. collateralAmount uses the token’s smallest units, and leverage uses 1e3 precision. Both positionSizeCollateral and the resulting fee use the token’s smallest units. Use integer or arbitrary-precision arithmetic for these raw values. The stored accumulator preserves earlier price-weighted accrual, including accrual before a rate was set to zero. Add the pending v1 fee to this result; do not choose one component based on today’s v2 rate. The contract’s getTradePendingHoldingFeesCollateral(trader, index, currentPairPrice) returns them separately as borrowingFeeCollateral (v2) and borrowingFeeCollateral_old (v1); its totalFeeCollateral also includes funding.

Borrowing fee per block

The formula for borrowing fee per block is:

Example:

Let’s calculate the borrowing fee for ENA/USD pair (pairIndex is 219) against USDC collateral (collateralIndex is 3)

1) Fetching Open Interest and Fees

Access current open interests and fees for given collateral and pair index via trading-variables endpoint described here.

2) Calculating Pair Borrowing Fees

To calculate ENA/USD borrowing fees, we use the following object retrieved from Step 1:
With these values, we can calculate the pair’s borrowing fee (per block):

3) Calculating Group Borrowing Fees

Now we need to do the same for group fee, reading the groupIndex from the same trading-variables response (for this example, groupIndex is 2). The process is the same as for calculating pair fees, using groups values of borrowingFees:
Therefore, the group’s borrowing fee (per block) will be:
In this example, groupFeePairBlockis greater than pairFeePerBlok (1.9431296324610092e-7 > 1.9219146149012726e-7) so groupFeePairBlock is the effective feePerBlock.

4) Estimating Borrowing fee per hour

To estimate the hourly paid fee, we need to multiply the number of blocks per hour feePerBlock.
For this example, on Arbitrum (12000 blocks per hour), the estimated borrowing fee per hour is:
Which corresponds to the Gains UI: