The Trading API supports an on-chain, atomic custom-fee (also called Add Fee / referral fee / revenue share) feature: a configurable percentage of each swap is deducted on-chain and sent to a wallet address you designate, while the remainder follows the normal DEX route. This is useful for integrators who want to collect a platform fee or share revenue with affiliates.
All deductions happen atomically inside the swap transaction â the fee and the swap either succeed together or fail together. No off-chain settlement is required.
Supported Endpoints & Chains
The feature is available on every swap-building endpoint, across EVM chains and Solana:
| Endpoint | Method | Fee parameters |
|---|---|---|
/api/v1/dex/aggregator/quote | GET | feePercent + feeSource |
/api/v1/dex/aggregator/swap | GET | feePercent + one referrer address |
/api/v1/dex/aggregator/quote-and-swap | GET | feePercent + one referrer address |
/api/v1/dex/aggregator/swap-instruction | GET | feePercent + one referrer address (Solana only) |
| Chain | feePercent range | Referrer address format |
|---|---|---|
| BNB Smart Chain, Ethereum, Arbitrum One, Base, Polygon, Optimism, Linea, Blast, Avalanche C-Chain, Scroll, Mode, Metis Andromeda, Sonic, Katana, Plasma, Monad, Robinhood | (0, 5] â greater than 0, up to 5% inclusive | 0x + 40 hex chars |
| Tron | (0, 5] â greater than 0, up to 5% inclusive | Base58 (T + 33 chars) |
| Solana | (0, 10] â greater than 0, up to 10% inclusive | Base58 pubkey |
feePercent is a decimal string with at most 2 decimal places (e.g. "1.5" = 1.5%). Values
with more than 2 decimals are rejected with INVALID_FEE_PERCENT (40466).
Fee Directions
Two deduction directions are supported. On /quote the direction is chosen via feeSource; on the
swap-building endpoints it is implied by which referrer address you pass.
| Direction | /quote | Swap endpoints | Effect |
|---|---|---|---|
FROM_TOKEN | feeSource=FROM_TOKEN | fromTokenReferrerWalletAddress | Fee is deducted from the sell token; the net amount is sent to the DEX. The user still receives the full DEX output. |
TO_TOKEN | feeSource=TO_TOKEN | toTokenReferrerWalletAddress | The full input is swapped; the fee is deducted from the buy-token output. The user receives the DEX output minus the fee. |
Fund flow
Code
Parameter Pairing
Each endpoint accepts a specific combination â parameters must be all present or all absent for a given fee direction:
| Endpoint | Fee parameters | Rule |
|---|---|---|
/quote | feePercent + feeSource | Both present or both absent. |
/swap, /quote-and-swap, /swap-instruction | feePercent + exactly one of fromTokenReferrerWalletAddress / toTokenReferrerWalletAddress | The two referrer addresses are mutually exclusive â supplying both returns CONFLICT_REFERRER_PARAMS (40468). |
If you omit all fee parameters, the swap executes as a regular fee-less swap.
Limits & Validation
| Rule | Detail | Error on violation |
|---|---|---|
feePercent range (EVM) | (0, 5] â > 0, ⤠5, max 2 decimals | 40466 INVALID_FEE_PERCENT |
feePercent range (Solana) | (0, 10] â > 0, ⤠10, max 2 decimals | 40466 INVALID_FEE_PERCENT |
| Referrer address format | EVM: 0x + 40 hex chars; Solana: Base58 pubkey | 40467 INVALID_REFERRER_ADDRESS |
| Both referrer addresses | Mutually exclusive â pick exactly one | 40468 CONFLICT_REFERRER_PARAMS |
| Solana referrer not activated | Referrer wallet has no SOL balance (ATA cannot be created) | 40469 REFERRER_NOT_ACTIVATED |
| Tax token on same side (Solana) | The token on the fee side is a tax token (buyTax > 0 or sellTax > 0) | 40470 TAX_TOKEN_FEE_CONFLICT |
four.meme tokens | Fee parameters are not supported when either side of the pair is a four.meme token | â |
| RFQ routes (equity / RWA tokens) | Fee parameters are ignored; the order executes as a standard fee-less RFQ order | â |
Solana referrer activation: before using a referrer address on Solana, fund it with a small amount of SOL so the on-chain fee token account (ATA) can be created. An empty referrer wallet is rejected with
40469.
Quote â Swap Consistency
When using the two-step flow (/quote â /swap), the fee direction (implied by which referrer
address you pass to /swap) and the feePercent value must match the ones locked in the
/quote cache for that quoteId. A mismatch returns SWAP_QUOTE_MISMATCH (40462).
The one-step /quote-and-swap Flash API has no prior quote, so the fee is fully determined by
the single request â no consistency check applies.
Response Echo
When the fee is enabled, the /quote, /swap, /quote-and-swap, and /swap-instruction responses
include three fields under each route / routerResult. All three are null when the fee is not
enabled.
| Field | Type | Description |
|---|---|---|
feeAmount | string (integer, smallest unit) | Fee deducted for this swap. FROM_TOKEN = originalFromCoinAmount à feePercent/100 (HALF_UP); TO_TOKEN = originalToCoinAmount à feePercent/100 (HALF_DOWN). |
feeToken | string (contract address) | Token in which the fee is denominated. FROM_TOKEN = sell-token address; TO_TOKEN = buy-token address. |
actualSwapAmount | string (integer, smallest unit) | Amount that actually participates in the DEX swap. FROM_TOKEN = fromTokenAmount â feeAmount (net); TO_TOKEN = original input amount (fee taken from the output side). |
Error Codes
| Code | Message | Affected endpoints |
|---|---|---|
40462 | SWAP_QUOTE_MISMATCH â fee direction / feePercent on /swap differs from the cached /quote | /swap |
40466 | Invalid feePercent. EVM chains allow (0, 5], Solana allows (0, 10] | /quote, /swap, /quote-and-swap, /swap-instruction |
40467 | Invalid referrer address â format does not match the selected chain | /swap, /quote-and-swap, /swap-instruction |
40468 | fromTokenReferrerWalletAddress and toTokenReferrerWalletAddress are mutually exclusive | /swap, /quote-and-swap, /swap-instruction |
40469 | Referrer wallet address is not activated on Solana â fund it with SOL first | /swap, /quote-and-swap, /swap-instruction (Solana only) |
40470 | Tax token cannot configure referral fee on the same side â use the opposite direction or remove the fee | /quote, /swap, /quote-and-swap, /swap-instruction (Solana only) |
Sample Calls (Python)
Both examples use a 1.5% fee deducted from the sell token (FROM_TOKEN direction).
Two-step: /quote then /swap
Code
One-step: /quote-and-swap
Code