Skip to main content
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.
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.
Affiliates can earn rewards in USDC or cbBTC on 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.
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.

Implementation

  • Using API
  • Using SDK
To apply an affiliate fee via API, include the affiliate_fee parameter when requesting a quote:
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:
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
        }]
    }'

How to claim

The claiming process involves two steps: checking your available earnings through the API, then submitting an on-chain transaction to withdraw them.

Check available earnings

First, call the earnings endpoint to get your claimable amounts:
cURL
curl -X 'GET' 'https://api.garden.finance/v2/apps/earnings' \
    -H 'garden-app-id: YOUR_APP_ID' \
    -H 'accept: application/json'
Example response:
Success
{
  "status": "Ok",
  "result": [
    {
      "total_earnings": "15075000000",
      "total_earnings_usd": "15075",
      "affiliate": "0x004Cc75ACF4132Fc08cB6a252E767804F303F729",
      "asset": "ethereum:usdc",
      "token_address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
      "claim_amount": "5075000000",
      "claim_amount_usd": "5075",
      "claim_signature": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1b",
      "claim_contract": "0x5EbEC4D8DA437b2BAD656D43d40fE412bA5D217a"
    }
  ]
}
The claim_amount, claim_amount_usd, claim_signature, and claim_contract fields are only included when you have unclaimed earnings available.

Claim your earnings

To claim your earnings, you need to call the claim function on the distributor contract. Here’s how to construct the transaction:
Make sure to call the claim function on the same chain where you received the rewards. For example, if your earnings are in ethereum:usdc, you should use the Ethereum mainnet RPC URL and chain configuration.
JavaScript
import { createWalletClient, createPublicClient, http, parseAbi } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { mainnet } from 'viem/chains';

async function claimAffiliateEarnings(claimData) {
  const account = privateKeyToAccount('<YOUR_PRIVATE_KEY>');
  
  // Create wallet client for sending transactions
  const walletClient = createWalletClient({
    account,
    chain: mainnet,
    transport: http('YOUR_RPC_URL'),
  });

  // Create public client for reading transaction receipts
  const publicClient = createPublicClient({
    chain: mainnet,
    transport: http('YOUR_RPC_URL'),
  });

  // Parse the ABI for the claim function
  const abi = parseAbi([
    'function claim((address toAddress, address tokenAddress, uint256 totalRewards) _claim, bytes _signature)'
  ]);

  // Prepare claim parameters
  const claimParams = {
    toAddress: claimData.affiliate,
    tokenAddress: claimData.token_address,
    totalRewards: BigInt(claimData.total_earnings)
  };

  // Execute the claim transaction
  const hash = await walletClient.writeContract({
    address: claimData.claim_contract,
    abi,
    functionName: 'claim',
    args: [claimParams, claimData.claim_signature]
  });

  // Wait for transaction receipt
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
  return receipt;
}