Skip to content

Add referral fee routing on buy so referrers earn a share of the protocol fee #514

Description

@Chucks1093

Summary

There is no on-chain incentive for users to bring new buyers to the platform. Adding an optional referrer: Option<Address> param to the buy function lets any wallet earn a portion of the protocol fee when someone they referred makes a purchase. The referrer's cut is taken from the protocol fee, so buyers pay nothing extra.

Scope

  • Add referrer: Option<Address> parameter to the buy function
  • When a referrer is provided, split the protocol fee: e.g. 80% to protocol treasury, 20% to referrer (configurable bps stored in protocol config)
  • Add referral_fee_bps to protocol config, settable by admin, defaulting to 2000 (20% of protocol fee)
  • Referrer cannot be the buyer themselves — revert with InvalidReferrer if equal
  • Emit ReferralFeeEarned { creator_id, buyer, referrer, amount, ledger } event
  • Add get_referral_fee_bps() -> u32 view function
  • When referrer is None, full protocol fee goes to treasury as before

Acceptance Criteria

  • Referrer receives correct share of protocol fee on buy
  • Protocol treasury receives the remainder
  • Total fee split equals 100% of the protocol fee (no leakage)
  • Self-referral reverts with InvalidReferrer
  • Omitting referrer preserves existing behavior
  • ReferralFeeEarned event emitted with correct fields
  • Admin can update referral_fee_bps within a valid range

ETA: 24 hours


Coordinate on Telegram

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official Campaign

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions