> ## Documentation Index
> Fetch the complete documentation index at: https://garden-e60e7dd0-chore-update-preview.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Affiliate Fees

> Implement affiliate fees to earn revenue from Garden swaps through your integration

Garden allows partners to charge an affiliate fee for each swap initiated through their SDK or API integration. This fee must be specified when requesting a quote and is charged in addition to protocol and solver fees.

<Info>
  Fees are expressed in basis points (bps), where 1 bps = 0.01%. For example, a 30 bps fee equals 0.3% of the source asset value.
</Info>

Affiliates can earn rewards in USDC or cbBTC on [supported chains](/developers/supported-chains). Fees can be sent entirely to a single address in one asset, or split across multiple addresses and assets.

For example, a 30 bps fee could be split by sending 10 bps in USDC to an Ethereum address, and 20 bps in cbBTC to a Base address.

<Note>
  The amount of each asset the affiliate will receive is calculated based on prices at the time of the quote and is also stored in the order data. All affiliate fees collected during the week are distributed to the specified addresses at the end of the week.
</Note>

## Implementation

<Tabs>
  <Tab title="Using API">
    To apply an affiliate fee via API, include the `affiliate_fee` parameter when requesting a quote:

    ```shell
    curl -X 'GET' \
        'https://testnet.api.garden.finance/v2/quote?from=bitcoin_testnet:btc&to=base_sepolia:wbtc&from_amount=100000&affiliate_fee=30' \
        -H 'accept: application/json'
    ```

    In this example, we've added a 30 bps affiliate fee.

    To include affiliate fees, add the `affiliate_fees` field when **creating an order**.

    Here's a sample create order request:

    ```shell highlight={15-19}
    curl --location 'http://testnet.api.garden.finance/v2/orders' \
        --header 'garden-app-id: f242ea49332293424c96c562a6ef575a819908c878134dcb4fce424dc84ec796' \
        --header 'Content-Type: application/json' \
        --data '{
            "source": {
                "asset": "bitcoin_testnet:btc",
                "owner": "tb1p4pr78swsn60y4ushe05v28mqpqppxxkfkxu2wun5jw6duc8unj3sjrh4gd",
                "amount": "50000"
            },
            "destination": {
                "asset": "base_sepolia:wbtc",
                "owner": "0x004Cc75ACF4132Fc08cB6a252E767804F303F729",
                "amount": "49850"
            },
            "affiliate_fees": [{
                "asset": "base_sepolia:wbtc",
                "address": "0x7A3d05c70581bD345fe117c06e45f9669205384f",
                "fee": 30
            }]
        }'
    ```
  </Tab>

  <Tab title="Using SDK">
    This process involves two steps:

    <Steps>
      <Step title="Request quote">
        Requesting a quote with the affiliate fee applied
      </Step>

      <Step title="Create order">
        Submitting the order using the selected quote
      </Step>
    </Steps>

    To request a quote with an affiliate fee, include the `affiliateFee` parameter in the `options` object.

    <CodeGroup>
      ```ts React
      import { SupportedAssets } from "@gardenfi/orderbook";
      import { useGarden } from "@gardenfi/react-hooks";

      const { swapAndInitiate, getQuote } = useGarden();

      const fromAsset = SupportedAssets.testnet.ethereum_sepolia_WBTC;
      const toAsset = SupportedAssets.testnet.arbitrum_sepolia_WBTC;
      const amount = 100000;
      const isExactOut = false;

      const quoteRes = await getQuote({
          fromAsset,
          toAsset,
          amount,
          isExactOut,
          options: {
              affiliateFee: 30 // in bps
          },
      });
      ```

      ```ts NodeJS
      const orderpair = 'ethereum_sepolia:0x29C9C37D0Fec7E64AFab0f806c8049d9e2f9B0b6::arbitrum_sepolia:0x795Dcb58d1cd4789169D5F938Ea05E17ecEB68cA'
      const amount = 100000
      const isExactOut = false

      const quoteRes = await garden.quote.getQuote(
          orderpair,
          amount,
          isExactOut,
          {
              affiliateFee: 30, // in bps
          },
      );
      ```
    </CodeGroup>

    While creating the order using the `swap` function, you can include the `affiliateFee` property to specify the recipient addresses, the fee amounts (in bps), and optionally the assets and chains you want the payout to be in. Garden supports payout in USDC and cbBTC.

    <CodeGroup>
      ```ts React
      const [_strategyId, quoteAmount] = Object.entries(quoteRes.val.quotes)[0];
      const response = await swapAndInitiate({
          fromAsset,
          toAsset,
          sendAmount: amount.toString(),
          receiveAmount: quoteAmount,
          additionalData: {
              strategyId: _strategyId,
          },
          affiliateFee: [
              {
                  address: "<affiliate_address_1>",
                  asset: "<asset_1>",
                  fee: 30
              },
              // Add more splits as needed
          ]
      });
      ```

      ```ts Node.js
      const [_strategyId, quoteAmount] = Object.entries(quoteRes.val.quotes)[0];
      const swapParams: SwapParams = {
          fromAsset,
          toAsset,
          sendAmount,
          receiveAmount: quoteAmount,
          additionalData: {
              strategyId: _strategyId,
          },
          affiliateFee:[
              {
                  address: "<affiliate_address_1>",
                  chain: "<chain_1>",
                  asset: "<asset_1>",
                  fee: 30
              },
              // Add more splits as needed
          ]
      };

      const swapResult = await garden.swap(swapParams);
      ```
    </CodeGroup>
  </Tab>
</Tabs>
