Skip to main content

Overview

The 1st DEX uses a referrer-based fee system. Trading fees are collected by the protocol’s feeRecipient address, and a portion of these fees can be shared with referrers who bring traders to the platform. Every order (both maker and taker) can optionally specify a referrer address. If specified, the referrer receives a configurable percentage of the trading fees generated by that order.

Fee distribution

When a trade occurs, fees are split between:
  1. Protocol fee recipient - The main protocol treasury (set at the BookManager level)
  2. Referrer - Optional address that receives a share of the fees (configurable per book/currency)
The referrer fee rate can be set by the protocol owner for each book and currency combination using setReferrerFeeRate on the BookManager.

Using referrers

Specifying a referrer

All order structs include a referrer parameter:
// MAKE order with referrer
Controller.make(MakeOrderParams({
    id: bookId,
    tick: tick,
    quoteAmount: amount,
    referrer: referrerAddress  // Your referrer address
}), deadline);

// TAKE order with referrer
Controller.take(TakeOrderParams({
    id: bookId,
    limitPrice: price,
    quoteAmount: amount,
    maxBaseAmount: maxBase,
    referrer: referrerAddress  // Your referrer address
}), deadline);

No referrer

If you don’t have a referrer, use address(0):
referrer: address(0)  // or 0x0000000000000000000000000000000000000000
In this case, all fees go to the protocol fee recipient.

Default referrer

The BookManager has a default referrer that is used when address(0) is passed as the referrer parameter. This ensures fees are always distributed appropriately even when no specific referrer is provided.

Querying fee information

You can query referrer fee information using the subgraph:
query ReferrerFees {
  referrers(orderBy: totalFeesCollectedUSD, orderDirection: desc) {
    id
    totalFeesCollectedUSD
    referralCount
    feesByToken {
      token {
        symbol
      }
      totalFees
      totalFeesUSD
    }
  }
}
See the Query subgraph guide for more examples.

Becoming a referrer

To become a referrer, simply provide your address to traders. When they include your address in their orders’ referrer field, you’ll automatically receive a share of the fees generated by their trades. Track your earnings through the subgraph or by monitoring the ReferrerFeePaid events emitted by the BookManager.