Skip to main content

Charging Fees with Bungee

Bungee allows integrators to charge fees on swaps and transfers, providing a revenue stream for your application. This guide explains how to implement fee charging in both Bungee Auto and Bungee Manual integrations. If you plan to implement fee charging, please request a dedicated API key first.

Fee Mechanics

When integrating Bungee, you can specify two key parameters to collect fees:
  • feeTakerAddress: The address that will receive the collected fees
  • feeBps: The percentage of the transfer amount to charge as a fee (in basis points - 1 basis point = 0.01%)
These parameters ensure that a portion of each swap is directed to your specified feeTaker address. The input token amount will be reduced by the fee amount before the swap is executed.

Implementation

You can add fee parameters to both Bungee Auto and Manual integrations when requesting a quote:
const BUNGEE_API_BASE_URL = "https://public-backend.bungee.exchange";

async function getQuoteWithFees() {
  const quoteParams = {
    userAddress: "0xYourUsersAddress",
    originChainId: "1", // Ethereum
    destinationChainId: "10", // Optimism
    inputToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum
    outputToken: "0x7F5c764cBc14f9669B88837ca1490cCa17c31607", // USDC on Optimism
    inputAmount: "1000000", // 1 USDC (6 decimals)
    receiverAddress: "0xYourUsersAddress",
    feeTakerAddress: "0xYourFeeCollectionAddress", // Address to receive fees
    feeBps: "50", // 0.5% fee (50 basis points)
  };

  // For Manual mode, add this parameter
  // quoteParams.enableManual = "true";

  const url = `${BUNGEE_API_BASE_URL}/api/v1/bungee/quote`;
  const queryParams = new URLSearchParams(quoteParams);
  const fullUrl = `${url}?${queryParams}`;

  const response = await fetch(fullUrl, { method: "GET" });
  const data = await response.json();
  const serverReqId = response.headers.get("server-req-id");

  if (!data.success) {
    throw new Error(
      `Quote error: ${data.statusCode}: ${data.message}. server-req-id: ${serverReqId}`
    );
  }

  return data.result;
}

Where to Claim Fees

For Bungee Manual, no need to claim as fees are delivered directly to the feeTakerAddress provided. For Bungee Auto, fees are sent to the FeeCollector contract where anyone can trigger the claim fees for a specified token address and feeTakerAddress pair. For per-chain FeeCollector addresses, see the Contract Addresses page. The FeeCollector exposes a claim(address token, address feeTaker) method to withdraw accrued fees.

Next Steps