Skip to main content
Use platform fees to monetize DFlow integrations by collecting fees on trades executed through applications. Add platform fees by setting fee parameters on Trade API requests. Users pay platform fees only when a trade completes successfully. Platform fees do not affect quoting, routing, slippage checks, or execution behavior. When a trade completes, the platform fee is transferred to a builder-controlled fee account. From a user’s perspective:
  • Fees apply only on successful trades.
  • Fees change net proceeds, not execution.

Fee Models

Builders choose one of two fee models.

Fixed Platform Fees

Charge a fixed percentage of the trade amount.
  • Fees are specified in basis points (bps).
  • 1 bps = 0.01%.
  • Example: platformFeeBps: 50 means a 0.5% fee.
Builders decide whether the fee is collected from the input token or output token using platformFeeMode.

Dynamic Platform Fees (Prediction Markets)

Builders charge a price-dependent fee on prediction market outcome token trades by setting platformFeeScale. DFlow calculates the fee as:
k *p * (1 -p) * c
Where:
  • k is platformFeeScale with 3 decimals of precision (example: 50 means 0.050).
  • p is the all-in price (includes all fees + filled price).
  • c is the contract size.
Users pay no platform fee when redeeming a winning outcome (p = 1). This means apps do not charge a platform fee for outcome token redemption.

Platform Fee Parameters

Configure platform fees using three parameters.

platformFeeMode

Use platformFeeMode to choose which token users pay the fee in:
  • outputMint (default): fee is collected from the output token.
  • inputMint: fee is collected from the input token.
For imperative trades, they can be paid in either the inputMint or outputMint. For declarative trades, they can currently only be paid in the outputMint. For prediction markets outcome token trades, they can only be paid in the settlementMint.

platformFeeBps

Use platformFeeBps to set a fixed platform fee in basis points.
  • The fee is calculated as a percentage of the trade amount.
  • The fee is collected from the input or output token based on platformFeeMode.

platformFeeScale

Use platformFeeScale only for outcome token trades to enable dynamic fees.
  • The fee scales with price and contract size using the formula above.
  • The fee is zero at redemption for winning outcomes (p = 1).

Fee Accounts

Builders must provide a feeAccount to receive platform fees. Requirements:
  • The fee account must be a valid SPL token account.
  • The fee account must match the token being collected.
    • Input token account when collecting from inputMint
    • Output token account when collecting from outputMint
    • Settlement token account for outcome token trades
  • The fee account must be initialized before execution.
Use referralAccount to auto-create the fee account when it does not exist. DFlow derives the fee account from the referral account using the Referral program. You cannot collect fees in a token that is not part of the trade.

How Platform Fees Affect Trades

Platform fees change net economics, not trade behavior.
  • Routing stays the same.
  • Slippage enforcement stays the same.
  • Execution timing stays the same.
If a trade fails, users pay no platform fee.

When To Use Platform Fees

Use platform fees if you want to:
  • Monetize trading volume.
  • Fund product development.
  • Align incentives with usage.

Code Recipes