> For the complete documentation index, see [llms.txt](https://txnlab.gitbook.io/haystack-dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://txnlab.gitbook.io/haystack-dev/haystack-router/referral-program.md).

# Referral Program

A program to reward developers who leverage Haystack.

## Overview

Haystack has exposed APIs (and SDKs that wrap the API calls) for fetching swap quotes and executing these quotes. To incentivize usage of these APIs, Haystack offers a referral program, where developers can earn 25% of the commissions generated by traffic through API calls.

Users of the Haystack app (<https://hay.app/>) may already be familiar with this, because the app's referral program uses the same process. Users who sign up through a referrer's invite link have the referrer's address set on their swaps, and the 25% referrer fee is automatically passed on.

## How to participate?

The interface for fetching a Haystack quote includes a `referrer` address field (the `referrerAddress` parameter of the [`fetchQuote` API](/haystack-dev/haystack-router/api-order-router.md) and the [TypeScript SDK](/haystack-dev/haystack-router/sdk.md)). If this field is set, 25% of Haystack commissions will be sent to an escrow account that can only be accessed by the given `referrer` address. An escrow account is used in order to handle opt-ins of assets that the given `referrer` address has not opted into.

Haystack has exposed a simple API that returns the escrow account address for any referrer address input:

`https://hayrouter.txnlab.dev/api/treasuryAddress?address=<referrer_address>`

[Here](https://hayrouter.txnlab.dev/api/treasuryAddress?address=WO6LIWV3SUBGKIROW3U4FCF5PDCQUKBTFWFS6TFVPZ2COG4XUDWPPOLKIY) is an example. The response is `{"address": "<escrow address>"}`.

The referrer address must be signed up (below) before it can be used: quotes that set an unregistered `referrerAddress` fail with a 400 error.

To sign up for the referral program, link your referrer address to your personal escrow account in the Haystack app:

1. Open the **Rewards** tab in Portfolio: <https://hay.app/holdings?view=rewards>
2. Connect the wallet for your referrer address. Any wallet works: Pera, Defly, Lute or Haystack Login.
3. Click **Set up for 0.26 ALGO**. The one-time 0.26 ALGO covers the escrow's minimum balance and fees.

## Automatic Swapping of Commissions

The Haystack Order Router charges fees in the output asset of a swap (e.g., if a user swaps from ALGO to goBTC, the fee is charged in goBTC). Accumulating commissions in different assets may be undesirable for some referrers (a token that's valuable today may be worthless by the time the referrer claims the commissions).

Therefore, we offer a system where we convert commissions to a pre-defined asset (e.g., ALGO, USDC, etc). This is, unfortunately, not possible at the moment in a trustless way. Therefore, this system is disabled by default and only if a referrer approves with a special transaction, a dedicated account is given access to a referrer's escrow account. Referrers can grant and revoke permission at any time in the **Convert earnings automatically** card on the Rewards tab.

A referrer can define what asset the other assets are swapped to. For example, a referrer can define that her commissions are automatically converted to USDC. If automatic swapping is enabled, Haystack converts your commissions to your selected asset every 6 hours and deposits them again in your escrow account.

To turn it on, choose the asset under **Convert to** and click **Turn on for** that asset. If your escrow doesn't hold the asset yet, adding it costs 0.1 ALGO once. To change the asset, pick another one and click **Switch to** it; to turn it off, use the card's switch.

**All swaps made using this service are swapped with a 1% convenience fee.**

## Redeeming Commissions from Escrow

You can claim your commissions at any time from **Earnings to claim** on the Rewards tab, or under **To claim** in [Portfolio](https://hay.app/holdings). Claiming an asset your wallet doesn't hold yet adds it for 0.1 ALGO. The escrow keeps a little ALGO back for its own minimum balance; that part can't be claimed.

Referrers that can't use the app, such as a smart contract governed by a DAO, can call the treasury app's claim methods directly. See [Architecture](/haystack-dev/haystack-router/referral-program/architecture.md).
