Supply Referral
The supply referral system allows users to earn a portion of the protocol fees generated by liquidity suppliers they refer. When a supplier deposits assets using your referral ID, you earn fees proportional to interest paid over time.
How it works
- Create a referral: Mint a
SupplyReferralobject for a specific margin pool - Referral ID: Suppliers include your referral ID when supplying liquidity
- Earn fees: As referred suppliers earn interest, a portion of protocol fees accrues to your referral
- Claim fees: Withdraw accumulated referral fees at any time
The referral system uses a shares-based tracking mechanism. When a supplier deposits with your referral:
- Your referral's shares increase proportionally to the supplier's position
- As interest accrues and protocol fees are collected, your claimable fees grow
- When a supplier withdraws, your referral's shares decrease accordingly
API
Following are the functions for managing supply referrals.
Mint a SupplyReferral
Create a new supply referral for earning fees from referred suppliers. The returned SupplyReferral object is transferable and can be used to claim accumulated fees.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.Supply with referral
Supply assets to a margin pool with an optional referral ID. When a referral ID is provided, the referrer earns a portion of protocol fees from the supplier's position.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.Withdraw referral fees
Withdraw accumulated referral fees. Only the owner of the SupplyReferral object can claim its fees.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.Query referral tracker
Query the current shares and unclaimed fees for a referral.
packages/deepbook_margin/sources/margin_pool/protocol_fees.move. You probably need to run `pnpm prebuild` and restart the site.Events
SupplyReferralMinted
Emitted when a new supply referral is created.
packages/deepbook_margin/sources/margin_pool.move. You probably need to run `pnpm prebuild` and restart the site.ReferralFeesClaimed
Emitted when referral fees are claimed by the referral owner.
packages/deepbook_margin/sources/margin_pool/protocol_fees.move. You probably need to run `pnpm prebuild` and restart the site.Fee distribution
The referral spread parameter (typically 20%) determines what portion of protocol fees goes to referrers. For example:
- Without referral: 100% of protocol fees go to the protocol
- With referral: 80% to protocol, 20% to referrer (at 20% referral spread)
The referral spread is configured per margin pool and can be viewed in the Contract Information.
Related links
Learn about margin pools and supplying liquidity.
The DeepBook Margin package on GitHub.