Overview
Kamino Lending’s referral system allows referrers to earn a portion of protocol fees generated by users they refer. Referrers create a unique state account and URL, then receive fees when referred users borrow, repay, or use flash loans.Referrer State Structures
The referral system uses three main account types defined instate/referral.rs:
ReferrerState
ShortUrl
ReferrerTokenState
ReferrerTokenState per reserve/mint.
Display Format (state/referral.rs:64):
Setting Up as a Referrer
Step 1: Initialize Referrer State and Short URL
Handler:handler_init_referrer_state_and_short_url.rs:11
ReferrerState and ShortUrl accounts.
Requirements (handler_init_referrer_state_and_short_url.rs:12):
- Short URL must contain only ASCII alphanumeric characters, underscores, or hyphens
- Must have a
UserMetadataaccount already created
referrer: Signer and fee payerreferrer_state: PDA["referrer_state", referrer.key()]referrer_short_url: PDA["short_url", short_url.bytes()]referrer_user_metadata: Your existing user metadata account
Step 2: Initialize Referrer Token State
Handler:handler_init_referrer_token_state.rs:8
ReferrerTokenState for each reserve/token you want to earn fees from.
Initialization (handler_init_referrer_token_state.rs:14):
payer: Fee payer (can be different from referrer)lending_market: The lending marketreserve: The reserve to track fees forreferrer: The referrer’s walletreferrer_token_state: PDA["referrer_token_state", referrer.key(), reserve.key()]
How Referrers Earn Fees
Referrers earn fees when their referred users perform these actions:1. Borrowing
Fee Accumulation (lending_operations.rs:324):
2. Flash Loans
Fee Accumulation (lending_operations.rs:1791):
3. Ongoing Interest
Continuous Accrual (lending_operations.rs:1959):
lending_operations.rs:2001):
Fee Addition Logic
Implementation (lending_operations.rs:1944):
ReferrerTokenState and the reserve’s accumulated fees.
Claiming Referrer Fees
withdraw_referrer_fees Instruction
Handler:handler_withdraw_referrer_fees.rs:16
lending_operations.rs:2040):
referrer: Signer (must be the referrer owner)referrer_token_state: PDA["referrer_token_state", referrer.key(), reserve.key()]reserve: The reserve to withdraw fees fromreserve_liquidity_mint: The reserve’s token mintreserve_supply_liquidity: The reserve’s supply vaultreferrer_token_account: Your token account (receives fees)lending_market: The lending marketlending_market_authority: PDA signer
Complete Setup and Claiming Example
Fee Distribution
Referral fees are a percentage of protocol fees, controlled bylending_market.referral_fee_bps:
Best Practices
- Initialize token states early: Set up
ReferrerTokenStatefor all reserves you expect users to interact with - Regular claims: Claim fees regularly to compound earnings
- Monitor metrics: Track cumulative vs unclaimed fees to measure referral performance
- User experience: Share your short URL prominently for easy user attribution
- Token account management: Ensure you have token accounts for all mints before claiming
Troubleshooting
InsufficientReferralFeesToRedeem:- No unclaimed fees available
- Wait for referred users to generate more activity
- Use only letters, numbers, underscores, and hyphens in short URLs
- Reserve needs to be refreshed before withdrawing fees
- Ensure you call
refresh_reservein the same transaction or beforehand