Overview
Add a referral and affiliate tracking system: users register a referrer when creating a token, and a configurable commission (in basis points, suggest 500 bps / 5% as a default) of the deployment fee is credited to the referrer's earned balance. The factory admin can update the commission rate and trigger payouts of accumulated commissions.
Requirements:
- Commission is calculated on the
fee_payment passed to create_token.
- Commissions accumulate in storage; the admin triggers payouts explicitly (pull/push-by-admin model, not auto-transfer).
- A referrer cannot refer themselves.
- Circular referral chains must be detected and rejected at registration time.
Scope: contract only. No backend or frontend integration is required for this feature.
Integration points
- New module file
contracts/token-factory/src/referral.rs, declared via mod referral; in lib.rs
- Public
#[contractimpl] entry points added to the TokenFactory impl block in lib.rs — suggested names for consistency with the rest of the API: register_referral, get_referral, get_referral_earned, get_commission_rate, set_commission_rate, payout_commission
create_token updated to accept an optional referrer parameter and route commission accrual through this module — check the current create_token signature and fee flow before wiring this in
- New
DataKey variants added to types.rs for referral records/earned-commission state — do not reuse existing discriminants
- New
Error variants added to types.rs starting at 133 (current highest in-use code is 132), with matching entries added to Error::name()
- Storage getters/setters added in
storage.rs following the existing pattern
- Events emitted via
events.rs using short symbol_short! topic names (Soroban's 9-character limit)
Acceptance criteria
Notes for implementers
- Circular-referral detection needs a bounded walk (don't let it become an unbounded loop / gas grief vector) — cap the chain-walk depth explicitly and reject registrations that would exceed it.
Overview
Add a referral and affiliate tracking system: users register a referrer when creating a token, and a configurable commission (in basis points, suggest 500 bps / 5% as a default) of the deployment fee is credited to the referrer's earned balance. The factory admin can update the commission rate and trigger payouts of accumulated commissions.
Requirements:
fee_paymentpassed tocreate_token.Scope: contract only. No backend or frontend integration is required for this feature.
Integration points
contracts/token-factory/src/referral.rs, declared viamod referral;inlib.rs#[contractimpl]entry points added to theTokenFactoryimpl block inlib.rs— suggested names for consistency with the rest of the API:register_referral,get_referral,get_referral_earned,get_commission_rate,set_commission_rate,payout_commissioncreate_tokenupdated to accept an optional referrer parameter and route commission accrual through this module — check the currentcreate_tokensignature and fee flow before wiring this inDataKeyvariants added totypes.rsfor referral records/earned-commission state — do not reuse existing discriminantsErrorvariants added totypes.rsstarting at 133 (current highest in-use code is132), with matching entries added toError::name()storage.rsfollowing the existing patternevents.rsusing shortsymbol_short!topic names (Soroban's 9-character limit)Acceptance criteria
referral.rsimplemented undercontracts/token-factory/src/, wired intolib.rscreate_tokenaccepts and processes an optional referrerDataKey/Erroradditions follow the checklist abovereferral_test.rscovering: registration + commission accrual on token creation, self-referral rejection, circular-chain rejection, admin commission-rate updates, payout accountingcargo check --libandcargo test --libclean incontracts/token-factorycargo build --target wasm32v1-none --release --libsucceedsNotes for implementers