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:
- Base Fee: The standard trading fee defined by the pool configuration.
- 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 thebaseFeeBPSthat 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.
| Value | Name | Description |
|---|---|---|
0 | Both | Fees are collected in the Input Asset. If swapping X → Y, fee is in X. If Y → X, fee is in Y. |
1 | AssetX | Fees are always collected in Asset X. If swapping Y → X, the fee is taken from the output. |
2 | AssetY | Fees 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.
When a user swaps amount for :
- Fee Deduction: The pool calculates the fee amount from .
- Swap: The swap is executed using .
- Output: The user receives .
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
Poolcontract. The creator must send aClaimCreatorFeesmessage to withdraw them. - Protocol Fees: Accumulate in the
Poolcontract. The protocol controller sends aClaimProtocolFeesmessage. - 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
}