DeDust Hub
Quickstart

Fees

Trading fees are the core revenue mechanism for liquidity providers and the protocol. In DeDust CPMM V2, the fee structure is flexible and consists of several components.

Fee Structure

Every swap incurs a Total Fee. This fee is deducted from the input amount (or output amount, depending on the implementation details, but effectively reduces the trader's output).

The Total Fee is composed of:

  1. Base Fee: The standard trading fee defined by the pool configuration.
  2. Affiliate Fee: An optional extra fee charged by integrators (partners/referrers).

Base Fee Distribution

The Base Fee is further distributed among three stakeholders:

  • Liquidity Providers (LP Fee): Added to the pool reserves, increasing the value of liquidity tokens.
  • Protocol (Protocol Fee): Sent to the protocol treasury.
  • Creator (Creator Fee): Sent to the pool creator (if configured).

The split is determined by the PoolConfig:

  • baseFeeBPS: The total base fee charged to the user.
  • creatorFeeBPS: The portion of the baseFeeBPS that goes to the creator.
  • The remainder is split between LPs and the Protocol according to protocol-wide settings (typically fixed).

Affiliate Fees

Integrators can charge additional fees on top of the Base Fee. These are specified in the SwapPayload via PartnerConfig and ReferrerConfig.

  • Partner Fee: A fee for the UI/Service provider facilitating the swap.
  • Referrer Fee: A fee for the entity that referred the user.

These fees are not added to the pool. Instead, they are sent to dedicated Affiliate Account contracts, where they can be claimed by the respective partners.

Fee Collection Strategy (FeeIn)

The pool can be configured to collect fees in different assets. This is defined by the FeeIn enum in PoolConfig.

ValueNameDescription
0BothFees are collected in the Input Asset. If swapping X → Y, fee is in X. If Y → X, fee is in Y.
1AssetXFees are always collected in Asset X. If swapping Y → X, the fee is taken from the output.
2AssetYFees are always collected in Asset Y. If swapping X → Y, the fee is taken from the output.

Fee Calculation (Math)

The constant product formula is applied after deducting fees.

xy=kx \cdot y = k

When a user swaps amount Δx\Delta x for Δy\Delta y:

  1. Fee Deduction: The pool calculates the fee amount ff from Δx\Delta x. Δxnet=Δxf\Delta x_{net} = \Delta x - f
  2. Swap: The swap is executed using Δxnet\Delta x_{net}. (x+Δxnet)(yΔy)=k(x + \Delta x_{net}) \cdot (y - \Delta y) = k
  3. Output: The user receives Δy\Delta y.

If Affiliate fees are present, they are deducted similarly, effectively reducing the amount participating in the swap or being deducted from the output.

Claiming Fees

  • LP Fees: Automatically compounded into the pool reserves. LPs realize this profit when they withdraw liquidity ( their LP tokens are worth more underlying assets).
  • Creator Fees: Accumulate in the Pool contract. The creator must send a ClaimCreatorFees message to withdraw them.
  • Protocol Fees: Accumulate in the Pool contract. The protocol controller sends a ClaimProtocolFees message.
  • Affiliate Fees: Accumulate in separate Affiliate Account contracts. Partners must interact with those contracts to claim.

Claim Creator Fees Message

struct (0xbe3e3179) ClaimCreatorFees {
    queryId: uint64
    to: address
    excessesTo: address
}

On this page