Referrals
The DeepBook referral system allows users to earn fees by referring traders to the platform. Referrers can mint a DeepBookPoolReferral object for a specific pool, and traders can associate their BalanceManager with a referral. When traders with an associated referral execute trades, a portion of their trading fees is allocated to the referrer based on the referral multiplier.
How referrals work
- Mint a referral: Anyone can mint a
DeepBookPoolReferralfor a specific pool with a specified multiplier. The referral permanently ties to the pool you minted it from and can only earn fees from trades in that pool. - Set referral: Traders associate their
BalanceManagerwith a pool-specific referral using aTradeCap. EachBalanceManagercan be associated with different referrals from different pools simultaneously. - Earn fees: When the balance manager executes taker orders in that pool, the system automatically allocates referral fees based on the multiplier. Maker orders do not generate referral fees.
- Claim rewards: Referrers can claim their accumulated fees in base, quote, and DEEP tokens.
API
The following are the referral-related functions that DeepBook exposes.
Mint a referral
Mint a new DeepBookPoolReferral object for a specific pool with a given multiplier. The multiplier determines the portion of trading fees allocated to the referrer. The multiplier must be a multiple of 0.1 (such as 0.1, 0.2, or 0.3) and cannot exceed 2.0. Returns the ID of the created referral.
packages/deepbook/sources/pool.move. You probably need to run `pnpm prebuild` and restart the site.Update referral multiplier
Update the multiplier for an existing pool referral. Only the referral owner can update the multiplier. The new multiplier must be a multiple of 0.1 and cannot exceed 2.0.
packages/deepbook/sources/pool.move. You probably need to run `pnpm prebuild` and restart the site.Claim referral rewards
Claim your accumulated referral fees for a pool referral. Only you, as the referral owner, can claim rewards. Returns three Coin objects representing the accumulated fees in base asset, quote asset, and DEEP tokens.
packages/deepbook/sources/pool.move. You probably need to run `pnpm prebuild` and restart the site.Get referral balances
View the current accumulated balances for a pool referral without claiming them. Returns the amounts in base, quote, and DEEP tokens.
packages/deepbook/sources/pool.move. You probably need to run `pnpm prebuild` and restart the site.Get referral multiplier
Get the current multiplier for a pool referral.
packages/deepbook/sources/pool.move. You probably need to run `pnpm prebuild` and restart the site.BalanceManager referral functions
These functions are available on the BalanceManager to associate or disassociate a referral.
Set referral
Associate a BalanceManager with a pool-specific referral. Requires a TradeCap to authorize the operation. Once set, all trades that this balance manager executes in the referral's pool generate referral fees according to the referral's multiplier. This replaces any previously set referral for the same pool.
packages/deepbook/sources/balance_manager.move. You probably need to run `pnpm prebuild` and restart the site.Unset referral
Remove the referral association from a BalanceManager for a specific pool. Requires a TradeCap to authorize the operation. After unsetting, trades in that pool no longer generate referral fees.
packages/deepbook/sources/balance_manager.move. You probably need to run `pnpm prebuild` and restart the site.Get referral ID
Retrieve the referral ID currently associated with a BalanceManager for a specific pool, if any. Returns Option<ID> which is none if no referral is set for that pool.
packages/deepbook/sources/balance_manager.move. You probably need to run `pnpm prebuild` and restart the site.Get referral owner
Get the owner address of a pool referral object.
packages/deepbook/sources/balance_manager.move. You probably need to run `pnpm prebuild` and restart the site.Get referral pool ID
Get the pool ID associated with a pool referral object.
packages/deepbook/sources/balance_manager.move. You probably need to run `pnpm prebuild` and restart the site.Events
DeepBookReferralCreatedEvent
The system emits this event when you mint a new referral.
packages/deepbook/sources/balance_manager.move. You probably need to run `pnpm prebuild` and restart the site.DeepBookReferralSetEvent
The system emits this event when you set or unset a referral on a balance manager.
packages/deepbook/sources/balance_manager.move. You probably need to run `pnpm prebuild` and restart the site.ReferralClaimed
The system emits this event when the referral owner claims accumulated fees.
packages/deepbook/sources/pool.move. You probably need to run `pnpm prebuild` and restart the site.ReferralFeeEvent
The system emits this event when it allocates referral fees during trade execution.
packages/deepbook/sources/pool.move. You probably need to run `pnpm prebuild` and restart the site.