> ## Documentation Index
> Fetch the complete documentation index at: https://docs.debridge.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Withdrawing Affiliate Fees

> Withdrawing Cross-Chain Affiliate Fees and Same-Chain Affiliate Fees

# Cross-Chain Affiliate Fees

Affiliate fees can be specified by any integration using the [DLN API](/dln-details/integration-guidelines/order-creation/authentication) or the [deBridge
Widget](/dln-details/widget/deBridge-widget). The fees are free to be distributed to the designated beneficiary once [liquidity is unlocked by a
solver](/dln-details/dln-specifics/order-fulfillment/claiming-order) from a fulfilled order—typically within a few hours after the order execution.

### EVM chains

On EVM chains, affiliate fees are automatically transferred to the specified beneficiary address as part of the transaction in which the solver
unlocks liquidity. No additional action is required.

An additional consideration is that gas costs for **affiliate fee transfers are capped at 2300 gas**. If the `affiliateFeeRecipient` is a contract that
requires more gas to process the transfer, the affiliate fees will not be sent, but the order will still be processed normally. In those cases,
affiliate fees have to be claimed manually by calling `DlnSource.withdrawUnclaimedAffiliateFees(...)`. The caller can be anyone, but the specified
beneficiary must be the `affiliateFeeRecipient` set in the request.

### Solana

On Solana, affiliate fees must be claimed manually by the beneficiary. This is done by invoking the `withdrawAffiliateFee` method of the DLN program. A
complete working example for claiming affiliate fees in bulk is available
[here](https://github.com/debridge-finance/api-integrator-example/blob/master/src/scripts/affiliates/sol-batch-withdraw.ts).

<Accordion title="Simplified Example Snippet">
  ```typescript theme={null}
  import { Solana } from "@debridge-finance/dln-client"
  import { Connection, PublicKey, clusterApiUrl } from "@solana/web3.js";

  function findAssociatedTokenAddress(wallet: PublicKey, tokenMint: PublicKey)
      : [PublicKey, number] {
      return PublicKey.findProgramAddressSync(
          [wallet.toBytes(), 
          new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").toBytes(), 
          tokenMint.toBytes()], 
          new PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL")
      );
  }

  const solanaClient = new Solana.DlnClient(
      // Replace with dedicated RPC for production
      new Connection(clusterApiUrl("mainnet-beta")), 
      new PublicKey("src5qyZHqTqecJV4aY6Cb6zDZLMDzrDKKezs22MPHr4"), 
      new PublicKey("dst5MGcFPoBeREFAA5E3tU5ij8m5uVYwkzkSAbsLbNo"), 
      new PublicKey("DEbrdGj3HsRsAzx6uH4MKyREKxVAfBydijLUF3ygsFfh"), 
      new PublicKey("DeSetTwWhjZq6Pz9Kfdo1KoS5NqtsM6G8ERbX4SSCSft"),
  )

  type Order = {
      orderId: string;
      beneficiary: PublicKey;
      giveToken: PublicKey;
  }

  // Load the order using known data or fetch via transaction hash
  // const order = await solanaClient.getOrderFromTransaction(
  //     { giveChain: ChainId.Solana, txHash: "CREATE_TX_HASH" }
  // );
  const order: Order = { /* order data */ };

  // Build and send the withdraw transaction
  const [associatedTokenAddress] = findAssociatedTokenAddress(
      order.beneficiary, 
      order.giveToken
  );
  const tx = await solanaClient.source.withdrawAffiliateFee(
      order.orderId, 
      order.beneficiary, 
      associatedTokenAddress
  );
  // Send the transaction...
  ```
</Accordion>

# Same-Chain Affiliate Fees

Same-Chain Swaps also support affiliate fees using the same `affiliateFeePercent` and `affiliateFeeRecipient` parameters as cross-chain swaps.

### EVM Chains

Affiliate fees for same-chain swaps on EVM chains are handled automatically during the swap transaction execution. No additional configuration is
required.

### Solana

Earned fees can be claimed via the [Jupiter Referral Dashboard](https://referral.jup.ag/dashboard), as specified in the [affiliate fees
article](/dln-details/affiliates/affiliate-fees#solana).
