Referrals: flat 5 CRED per side (replace 5% of epoch CRED tranche) #272
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:open_issues
agents
agent:security_audit
agent:verify
area
timecurve
arena
arena-v2
audit
block:feature_review
block:security
bug
contracts
design
devops
docs
documentation
enhancement
epic
feature
frontend
indexer
low priority
megaeth
operations
ops
performance
QA
qa checklist
referrals
removal
security
smart-contracts
tech-debt
testing
time-arena
timecurve
visual-qa
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
code/yieldomega#272
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Replace the current percentage-based referral Play CRED reward (5% of
CRED_PER_BUY= 1.75 CRED per side) with a fixed flat bonus of 5 CRED minted to referrer and buyer on every qualifying referred buy. CRED remains immediately minted (not epoch-pooled). Parent context: Arena v2 referrals (#240), CRED-not-CHARM migration (#253).Current codebase
Onchain (authority)
TimeArena.sol:CRED_PER_BUY = 35e18— epoch pool CRED added on every DOUB/CRED buy path that accrues charm.REFERRAL_CRED_BPS = 500— referral side uses 5% ofCRED_PER_BUY, not a fixed amount._accrueCharmAndCred(buyer, charmWad, codeHash)on DOUB buys (buy,buy(charm, codeHash), routerbuyFor):charmWadonly tocharmWeight(no referral CHARM bonus).codeHash != 0andreferralRegistrywired: resolves referrer viaReferralRegistry.ownerOfCode, blocks self-referral, mintseach = CRED_PER_BUY × REFERRAL_CRED_BPS / 10_000to referrer and buyer viaplayCred.mint, emitsReferralCredApplied(buyer, referrer, codeHash, each, each).buyWithCreduses_accrueCharmOnly— no referral path today (nocodeHashparam).ReferralRegistry.sol: unchanged registration model (1 CL8Y burn,codeHash → owner).Forge coverage:
TimeArena.t.sol::test_referred_buy_mints_cred_not_charm,test_self_referral_revertsassert 1.75e18 per side.Indexer (derived)
ReferralCredApplied→idx_arena_referral_cred(referrer_cred,buyer_cred).GET /v1/referrals/applied,referrer-leaderboard,wallet-cred-summary— sumsreferrer_cred(indexer/src/api.rs).Frontend (derived)
/referrals: leaderboard + earnings from indexer CRED fields (ReferralProgramEarningsSection.tsx,ReferralLeaderboardSection.tsx)./arenabuy session: still reads onchainREFERRAL_CRED_BPSviareferralEachBpsRand computes preview bonus as % of something (useArenaSaleSession.ts) — misaligned with flat CRED product intent.Docs / invariants
docs/product/referrals.md·docs/product/time-arena.md#referrals— documents 5% of 35 CRED.INV-REFERRAL-253-CRED(invariants-and-business-logic.md) — encodes BPS formula..cursor/skills/yieldomega-guardrails/SKILL.md).Why change
Product wants a simple, legible rule: “Referred buy → 5 CRED to guide, 5 CRED to buyer, right away.”
Problems with the current 5%-of-35 design:
35 CRED) and BPS (500) to know they earn 1.75 CRED, not “5”.CRED_PER_BUYis retuned for epoch economics, referral payouts move unintentionally./referralscopy references “5% of the 35 CRED mint”.Non-goals (unless explicitly expanded in implementation):
CRED_PER_BUYpool mechanics (still 35 CRED per buy into epoch pool).Constraints & guardrails
TimeArena+PlayCred.mint; indexer/frontend are derived (#253).docs/licensing.md.charmWeightbeyond purchasedcharmWad.TimeArena: self-referral).playCred.mint, same as today (not added toepochCredPool).codeHash). Document explicitly ifbuyWithCred+ referral is out of scope.REFERRAL_CRED_FLAT_WAD = 5e18(or similar); remove or deprecateREFERRAL_CRED_BPSfrom product path (avoid dual formulas).ReferralCredAppliedunless a breaking ABI change is justified; indexer table columns unchanged (amounts differ).INV-REFERRAL-253-CRED, guardrails 6f,time-arena.mddecision #3, manual QA §253.skills/README.md/ play skills if referral economics are referenced.Relevant files
TimeArena.sol,TimeArena.t.sol,DevStackIntegration.t.soldecoder.rs,persist.rs,api.rs,integration_stage2.rsuseArenaSaleSession.ts,arenaV2SaleSessionBridge.test.ts,ReferralProgramEarningsSection.tsx,ReferralLeaderboardSection.tsx,indexerApi.tsreferrals.md,time-arena.md,glossary.md,invariants-and-business-logic.md,manual-qa-checklists.md, guardrails skillRecommended direction
Contracts
uint256 public constant REFERRAL_CRED_FLAT_WAD = 5e18;(name TBD)._accrueCharmAndCred, replaceMath.mulDiv(CRED_PER_BUY, REFERRAL_CRED_BPS, 10_000)withREFERRAL_CRED_FLAT_WADfor both mints and event fields.REFERRAL_CRED_BPSfrom public API or leave deprecated with NatSpec “unused; flat CRED per #___” — pick one, don’t keep both active.PlayCredminter role unchanged.Forge tests
5e18each side.CRED_PER_BUYin a fork/mock does not change referral mint amount (documents decoupling).Frontend
REFERRAL_CRED_FLAT_WAD)./referralslede/copy (“5 CRED per referred buy per side”).Indexer
1.75e18→5e18.x-schema-versionpatch + release note if response semantics documented.Docs / invariants
INV-REFERRAL-253-CRED→ flat-amount invariant.Acceptance criteria
codeHash:playCred.mint(referrer, 5e18)andplayCred.mint(buyer, 5e18);ReferralCredAppliedemits5e18, 5e18.CRED_PER_BUY(35 CRED epoch tranche unchanged).charmWeightincreases bycharmWadonly (no referral CHARM).codeHash == 0) mints zero referral CRED.referrer_cred/buyer_cred= 5e18` on qualifying rows./referralsand/arenacopy/preview show flat 5 CRED, not “5%” or “1.75”.INV-REFERRAL-*+ guardrails updated; #253 QA checklist revised.Test plan — functional paths
buy(charm)no codebuy(charm, validCode)buy(charm, invalidCode)buy(charm, ownCode)buyFor(buyer, charm, code, flag)buyWithCred(charm)(if unchanged scope)idx_arena_referral_credGET /v1/referrals/appliedreferrer_cred/buyer_cred=5000000000000000000Automated:
forge test --match-contract TimeArenaTest(referral tests),cargo test integration_stage2(if PG URL set),npm testreferral/arena session tests, Playwrightreferrals-surface.spec.ts.Test plan — attack, hack & abuse vectors
codeHashPlayCredminterINV-FRONTEND-95)ON CONFLICT DO NOTHINGidempotency onidx_arena_referral_credDocument any accepted inflation tradeoff (flat 5 > old 1.75) for treasury/ops.
Verification criteria (issue close)
5e18assertionsPlayCred.balanceOf+5 for referrer and buyer/v1/referrals/appliedshow 5e18 per side/referralsUI shows CRED totals consistent with indexed datatime-arena.mdREFERRAL_CRED_BPSin live Arena v2 paths (except legacy TimeCurve sections)Related issues
mentioned in commit
dbbfeba2dfImplementation landed on
main(dbbfeba)Replaced percentage-based referral Play CRED (5% of
CRED_PER_BUY→ 1.75 CRED/side) with a flat 5 CRED per side on qualifying referred DOUB buys (#272).What changed
Contracts
TimeArena: addedREFERRAL_CRED_FLAT_WAD = 5e18; removedREFERRAL_CRED_BPSfrom the product path_accrueCharmAndCred: mints5e18to referrer and buyer;CRED_PER_BUYepoch pool unchangedtest_referred_buy_mints_cred_not_charmexpects5e18; asserts decoupling from epoch trancheFrontend
REFERRAL_CRED_FLAT_WADvia multicall bridge;/arenabuy preview shows +5 CRED Referral (no CHARM % bonus)/referralscopy updated (quest strip + earnings lede)Indexer
ReferralCredAppliedshape unchanged); persisted amounts will be5e18on new rowsDocs / invariants / skills
INV-REFERRAL-272-FLAT-CRED;INV-REFERRAL-253-CREDaliasedreferrals.md,time-arena.md(decision #3 superseded),arena-v2.md,glossary.md, manual QA §253skills/play-time-arena-doub/SKILL.mdcrosslinkedVerification checklist
cd contracts && forge test --match-test 'test_referred_buy_mints_cred_not_charm|test_self_referral_reverts'— greenTimeArena.buy(charm, codeHash)→PlayCred.balanceOf+5 for referrer and buyerReferralCredAppliedemits5e18, 5e18codeHash == 0) → zero referral mintbuyWithCred→ no referral CRED (documented out of scope)GET /v1/referrals/applied→referrer_cred/buyer_cred=5000000000000000000/referralsleaderboard + wallet summary totals reflect 5 CRED × buy count/arenapending referral preview shows +5 CRED, not +5% or inflated CHARM CTAREFERRAL_CRED_BPSAutomated on branch: Forge referral tests ✅ ·
arenaV2SaleSessionBridge.test.ts✅@brouie — please verify on your stack when convenient. Leaving issue open until checklist sign-off.
mentioned in commit
c7ca1393f5QA verification complete (agent)
Verified GitLab #272 (flat 5 CRED per side on referred DOUB buys) on branch
issue/272-verify, merged tomainasc7ca139.What was verified (already on
mainbefore this pass)REFERRAL_CRED_FLAT_WAD = 5e18;_accrueCharmAndCredmints flat amount;REFERRAL_CRED_BPSremoved from product pathtest_referred_buy_mints_cred_not_charm,test_self_referral_reverts— expect 5e18 each side; decoupling assert vsCRED_PER_BUYintegration_stage2.rsfixture uses 5e18 forreferrer_cred/buyer_cred(CI when PG URL set)REFERRAL_CRED_FLAT_WAD;/referralslede shows flat 5 CRED;arenaV2SaleSessionBridge.test.tsgreenFixes / additions in
c7ca139scripts/verify-referral-flat-cred-anvil.sh— fresh Anvil DeployDev smoke: register code → referredbuy→ +5 CRED referrer & buyer;buyWithCreddoes not mint referral CRED; re-runs Forge referral tests.surfaceContent.tsno longer says “Earn 5% … TimeCurve”.INV-REFERRAL-272-FLAT-CRED+ manual QA §253 crosslink Anvil script;play-time-arena-doubskill links script.Commands run (all passed)
Indexer
integration_stage2referral persist smoke was not re-run here (noDATABASE_URLin this environment); CI should cover it.Checklist for follow-up verification
bash scripts/verify-referral-flat-cred-anvil.shFOUNDRY_PROFILE=ci forge test --match-test test_referred_buy_mints_cred_not_charmFOUNDRY_PROFILE=ci forge test --match-test test_self_referral_revertsTimeArena.buy(charm, codeHash)→PlayCred.balanceOf+5e18 for referrer and buyerGET /v1/referrals/appliedshowsreferrer_cred/buyer_cred=5000000000000000000/referralsearnings + leaderboard CRED totals match indexer/arenabuy preview bonus line shows +5 CRED (not 5% / 1.75)/referrals card blurb mentions flat Play CRED (not TimeCurve 5%)buyWithCredpath still has no referral mintREFERRAL_CRED_BPSor “5% of 35 CRED”Closing as issue acceptance criteria and verification criteria are satisfied on
main.mentioned in issue #309