Skip to main content

Fees

This page documents fee types, execution fee calculation, and how to retrieve fee parameters from the DataStore.

UI fee

UI fees are charged on top of the base protocol fee. The percentage is based on the uiFeeFactor configured for the uiFeeReceiver address you pass when creating an action. For more information, see Running a frontend.

Configure the UI fee percentage for your address by calling ExchangeRouter.setUiFeeFactor. The uiFeeFactor is a percentage value over 10^30. For example, if the uiFeeFactor is 2 * 10^25, the percentage charged is (2 * 10^25) / (10^30) = 0.00002 = 0.002%. The call reverts with InvalidUiFeeFactor if the value exceeds the maximum.

The maximum uiFeeFactor is capped by dataStore.getUint(Keys.MAX_UI_FEE_FACTOR).

You can pass the uiFeeReceiver value for the following actions:

  • Deposits
  • Withdrawals
  • Swap orders
  • Increase and decrease position orders (Market Increase, Limit Increase, Market Decrease, Limit Decrease, Stop-Loss, Take-Profit)
  • GLV deposits
  • GLV withdrawals
  • Shifts

For deposits, withdrawals, and swaps, the fee is a percentage of the input amount. For increase and decrease position orders, the fee is a percentage of the position size change.

UI fees are credited when deposits, withdrawals, and orders execute. Call ExchangeRouter.claimUiFees to claim accumulated fees at any time. The caller's address (msg.sender) is used as the uiFeeReceiver for the claim.

Execution fee

Creating a deposit, order, withdrawal, shift, GLV deposit, or GLV withdrawal request requires sending an executionFee as the transaction value.

During creation, the contracts verify that the provided executionFee is at least the minimum, calculated as:

tx.gasprice * GasUtils.adjustGasLimitForEstimate(dataStore, estimatedGasLimit, oraclePriceCount)

To calculate the estimatedGasLimit, use the appropriate function:

  • For deposits: GasUtils.estimateExecuteDepositGasLimit
  • For withdrawals: GasUtils.estimateExecuteWithdrawalGasLimit
  • For orders: GasUtils.estimateExecuteOrderGasLimit
  • For shifts: GasUtils.estimateExecuteShiftGasLimit
  • For GLV deposits: GasUtils.estimateExecuteGlvDepositGasLimit
  • For GLV withdrawals: GasUtils.estimateExecuteGlvWithdrawalGasLimit

Because tx.gasprice fluctuates based on network usage, add a buffer to reduce the risk of the creation transaction reverting. If the provided executionFee is below the minimum, the transaction reverts with InsufficientExecutionFee. Upon execution, any excess execution fee is refunded to the request's account address.

Funding

For an overview of how funding fees work, see adaptive funding.

Retrieve funding fee parameters from the DataStore using these keys. All keys are per-market.

KeyDescription
FUNDING_FACTORBase funding factor per second
FUNDING_EXPONENT_FACTORExponent applied to the open interest imbalance ratio
FUNDING_INCREASE_FACTOR_PER_SECONDRate at which the funding factor increases per second
FUNDING_DECREASE_FACTOR_PER_SECONDRate at which the funding factor decreases per second
MIN_FUNDING_FACTOR_PER_SECONDMinimum funding factor per second
MAX_FUNDING_FACTOR_PER_SECONDMaximum funding factor per second
THRESHOLD_FOR_STABLE_FUNDINGImbalance threshold below which funding stays stable
THRESHOLD_FOR_DECREASE_FUNDINGImbalance threshold below which the funding factor decreases

Borrowing

For an overview of how borrow fees work, see borrow fees.

Retrieve borrow fee parameters from the DataStore using these keys. Each market uses one of the two models below.

Kink model

KeyDescription
OPTIMAL_USAGE_FACTORUtilization threshold where the rate slope increases
BASE_BORROWING_FACTORBase rate factor below optimal utilization
ABOVE_OPTIMAL_USAGE_BORROWING_FACTORRate factor applied above optimal utilization

Curve (power) model

KeyDescription
BORROWING_FACTORPer-market borrowing factor for longs and shorts
BORROWING_EXPONENT_FACTORPer-market exponent for longs and shorts
SKIP_BORROWING_FEE_FOR_SMALLER_SIDEIf true, the side with smaller open interest pays zero borrow fees

Position and swap fees

Retrieve position and swap fee parameters from the DataStore using these keys. Fee factors are percentage values over 10^30.

Position fees

KeyDescription
POSITION_FEE_FACTORPercentage fee deducted on position increase and decrease, based on position size change
POSITION_IMPACT_FACTORPrice impact factor for position actions
MAX_POSITION_IMPACT_FACTORCap on negative price impact for positions
MAX_POSITION_IMPACT_FACTOR_FOR_LIQUIDATIONSCap on negative price impact applied during liquidations
POSITION_IMPACT_EXPONENT_FACTORExponent for position price impact calculation
POSITION_IMPACT_POOL_DISTRIBUTION_RATERate at which the position impact pool is distributed to the market pool
PRO_DISCOUNT_FACTORFee discount factor applied to pro-tier traders

Swap fees

KeyDescription
SWAP_FEE_FACTORPercentage fee deducted on swaps, based on swap amount
ATOMIC_SWAP_FEE_FACTORPercentage fee deducted on atomic swaps using on-chain price feeds
SWAP_IMPACT_FACTORPrice impact factor for swaps
SWAP_IMPACT_EXPONENT_FACTORExponent for swap price impact calculation
ATOMIC_SWAP_FEE_TYPEType flag that determines the atomic swap fee behavior

Deposit and withdrawal fees

KeyDescription
DEPOSIT_FEE_FACTORPercentage fee deducted on deposits, based on deposit amount
WITHDRAWAL_FEE_FACTORPercentage fee deducted on withdrawals, based on withdrawal amount
ATOMIC_WITHDRAWAL_FEE_FACTORPercentage fee deducted on atomic withdrawals using on-chain price feeds

Liquidation fees

KeyDescription
LIQUIDATION_FEE_FACTORPercentage fee deducted when a position is liquidated

Fee receiver factors

These parameters control the share of collected fees allocated to the fee receiver. Each is a percentage value over 10^30.

KeyDescription
POSITION_FEE_RECEIVER_FACTORShare of position fees allocated to the fee receiver
SWAP_FEE_RECEIVER_FACTORShare of swap fees allocated to the fee receiver
BORROWING_FEE_RECEIVER_FACTORShare of borrow fees allocated to the fee receiver
LIQUIDATION_FEE_RECEIVER_FACTORShare of liquidation fees allocated to the fee receiver

Relay fees

These parameters control fee calculation for Gelato relay (gasless) transactions.

KeyDescription
GELATO_RELAY_FEE_MULTIPLIER_FACTORMultiplier applied to the relay fee calculation
GELATO_RELAY_FEE_BASE_AMOUNTBase fee amount for relay transactions

Atomic operation parameters

These parameters control behavior for atomic (synchronous) operations that use on-chain price feeds.

KeyDescription
MAX_ATOMIC_ORACLE_PRICE_AGEMaximum acceptable age for oracle prices in atomic operations

Advanced parameters

These parameters control specialized protocol behavior.

KeyDescription
DATA_STREAM_SPREAD_REDUCTION_FACTORFactor applied to reduce the bid-ask spread from data stream oracle prices
GLV_SHIFT_MAX_LOSS_FACTORMaximum acceptable loss factor when executing GLV shifts
BUYBACK_GMX_FACTORFactor controlling GMX token buyback from protocol fees
BUYBACK_MAX_PRICE_IMPACT_FACTORMaximum price impact allowed for buyback operations