For the complete documentation index, see llms.txt. This page is also available as Markdown.

Charge Fees on your Swaps

Use client fees to monetize your swap flow. Client fees are optional integrator fees set with ClientFeeParams.

The integrator keeps 80% of the client fee. Fynd keeps 20%.

Client fees are separate from Fynd fees, which still apply when no client fee is set.

Fee breakdown with client fees

Quotes with encoding include a fee_breakdown with the exact amounts.

amount_out is the raw pre-fee swap output: what the route produces before router or client fees. It is not what the user receives. The user receives at least fee_breakdown.min_amount_received on-chain.

Fynd mirrors the on-chain FeeCalculator with identical integer arithmetic, then uses the result for minAmountOut in the encoded transaction.

Given amount_out, router_fee_bps (see Fynd Fees), client_fee_bps, and slippage:

1. client_fee        = amount_out * client_fee_bps / 10,000
2. router_share      = amount_out * client_fee_bps * 2,000 / 100,000,000
3. client_portion    = client_fee - router_share
4. router_fee_output = amount_out * router_fee_bps / 10,000
5. router_fee        = router_share + router_fee_output
6. amount_after_fees = amount_out - client_portion - router_fee
7. max_slippage      = amount_after_fees * slippage
8. min_amount_received = amount_after_fees - max_slippage

All response fields use output token units:

Field
Description

router_fee

Fynd fee + 20% of client fee

client_fee

Integrator's 80% share of the client fee

max_slippage

Slippage allowance on the post-fee amount

min_amount_received

On-chain minimum the user receives (minAmountOut in the tx)

Invariant: amount_out = router_fee + client_fee + max_slippage + min_amount_received

Example

Example: 1,000,000 USDC output, 0.1 bps Fynd fee, 50 bps client fee, 1% slippage:

Setting up client fees

  1. Set a fee in basis points (e.g. 50 = 0.5%), a receiver address, and a maxClientContribution.

  2. Have the fee receiver sign an EIP-712 ClientFee message authorizing these parameters.

  3. Attach the signed params to EncodingOptions.clientFeeParams.

  4. The router verifies the signature on-chain and deducts the fee. Fees go to the receiver's vault balance.

Without ClientFeeParams, no client fee is charged. Fynd fees still apply.

maxClientContribution

maxClientContribution caps how much the client can subsidize from their vault balance if slippage pushes the output below minAmountOut. If the shortfall exceeds the cap, the transaction reverts.

Set it to 0 to collect fees without covering slippage losses. This is the common case.

See Tycho encoding docs for vault details.

EIP-712 signing

The fee receiver signs a typed data hash binding the fee params to the swap they were quoted for:

Field
Type
Description

clientFeeBps

uint32

Fee in fee units (100,000,000 = 100%; 1 bps = 10,000)

clientFeeReceiver

address

Address receiving the fee

maxClientContribution

uint256

Maximum subsidy from client vault

deadline

uint256

Signature expiry (Unix timestamp)

amountIn

uint256

Exact input amount from the order

tokenIn

address

Input token

tokenOut

address

Output token

expectedAmountOut

uint256

Quoted output (amount_out of the unsigned quote)

minAmountOut

uint256

fee_breakdown.min_amount_received

receiver

address

Address receiving the swap output

swaps

bytes

Encoded swaps — hashed as fee_breakdown.swaps_hash

The API takes the client fee in basis points and scales it into the router's fee units, so the client library helpers sign the scaled value rather than the raw bps.

EIP-712 domain:

Field
Value

name

TychoRouter

version

1

chainId

Target chain ID

verifyingContract

TychoRouter contract address

Code examples

See the full working example: clients/rust/examples/swap_client_fee.rs

Last updated