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
API Reference: Quote
When integrating Bungee, you can specify two key parameters to collect fees:
feeTakerAddress
: The address that will receive the collected feesfeeBps
: 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:
/**
* This example demonstrates how to implement fee charging in a Bungee integration
*/
// Configuration
const BUNGEE_API_BASE_URL = "https://public-backend.bungee.exchange";
/**
* Get a quote with fee parameters
* @param {Object} params - The parameters for the quote request
* @returns {Promise<Object>} The quote response
*/
async function getQuoteWithFees() {
// Set up the parameters for the quote request
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";
// Build the URL with query parameters
const url = `${BUNGEE_API_BASE_URL}/api/v1/bungee/quote`;
const queryParams = new URLSearchParams(quoteParams);
const fullUrl = `${url}?${queryParams}`;
// Make the request
const response = await fetch(fullUrl, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
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;
}
Fee Collection Process
- User Initiates Transfer: The user approves and sends the full amount including the fee
- Fee Deduction: The Gateway contract deducts the specified fee amount
- Fee Transfer: The fee is sent to the feeTaker address
- Remaining Amount Processed: The remainder continues through the normal transfer flow