feat(crowdfund): add affiliate links and referral tracking (#349)#387
Open
Ebenezer199914 wants to merge 1 commit into
Open
Conversation
…ocol#349) Implement affiliate/referral tracking for crowdfund campaigns so that campaign organizers can register affiliates, distribute unique referral codes, and reward affiliates with an on-chain commission whenever a contributor uses their code. ## Changes ### contracts/crowdfund/src/errors.rs - AffiliateNotRegistered (28) – caller not registered as an affiliate - ReferralCodeAlreadyTaken (29) – code owned by a different affiliate - InvalidCommissionBps (30) – bps value exceeds 10 000 - ReferralCodeNotFound (31) – no affiliate for the supplied code - ReferralAlreadyUsed (32) – contributor already used a referral code ### contracts/crowdfund/src/lib.rs New DataKey variants: AffiliateCommissionBps, ReferralCodeOwner(BytesN<32>), AffiliateCode(Address), ReferralCount(BytesN<32>), ReferralEarnings(BytesN<32>), PledgeReferral(Address) New events: AffiliateRegisteredEvent, ReferralUsedEvent New public functions: set_affiliate_commission – organizer sets campaign-wide commission bps register_affiliate – organizer maps affiliate ↔ code_hash contribute_with_referral – contribute + validate code + pay commission get_referral_count – unique contributors who used a code get_referral_earnings – cumulative commission earned by code get_referral_code – affiliate address → code hash lookup get_contributor_referral – contributor → used code lookup get_affiliate_commission_bps – current commission rate Bug fix: Added missing #[contractevent] macro to PledgeReceivedEvent (CICB bug) ### contracts/crowdfund/src/test.rs 24 new tests covering: - set_affiliate_commission happy-path and bounds validation - register_affiliate idempotency, duplicate-code conflict - contribute_with_referral: raised amount, commission transfer, referral count, earnings accumulation, contributor recording - Error paths: invalid code, double-referral, past deadline, zero amt - Zero-commission edge case - Integration with matching pool - Campaign execution after referral contributions All 83 tests pass.
|
Hey @Ebenezer199914! 👋 It looks like this PR isn't linked to any issue. If this PR is for one of the issues assigned to you as part of a Wave, please link it to ensure your contribution is tracked properly. You can do this by adding a keyword to the PR description (e.g.,
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement affiliate/referral tracking for crowdfund campaigns so that campaign organizers can register affiliates, distribute unique referral codes, and reward affiliates with an on-chain commission whenever a contributor uses their code.
Changes
contracts/crowdfund/src/errors.rs
contracts/crowdfund/src/lib.rs
New DataKey variants:
AffiliateCommissionBps, ReferralCodeOwner(BytesN<32>), AffiliateCode(Address), ReferralCount(BytesN<32>), ReferralEarnings(BytesN<32>), PledgeReferral(Address)
New events:
AffiliateRegisteredEvent, ReferralUsedEvent
New public functions:
set_affiliate_commission – organizer sets campaign-wide commission bps
register_affiliate – organizer maps affiliate ↔ code_hash
contribute_with_referral – contribute + validate code + pay commission
get_referral_count – unique contributors who used a code
get_referral_earnings – cumulative commission earned by code
get_referral_code – affiliate address → code hash lookup
get_contributor_referral – contributor → used code lookup
get_affiliate_commission_bps – current commission rate
Bug fix:
Added missing #[contractevent] macro to PledgeReceivedEvent (CICB bug)
contracts/crowdfund/src/test.rs
24 new tests covering:
All 83 tests pass.
Description
Type of Change
Related Issues
Fixes #
Changes Made
Testing
Checklist
Screenshots (if applicable)
Additional Notes