Harden lottery fairness, closure rules, and prize claim lifecycle (#320)#374
Conversation
|
@Cybermaxi7 is attempting to deploy a commit to the olufunbiik's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThe lottery contract is refactored to strengthen lifecycle management and winner fairness. Changes include relocating error definitions inline, renaming the contract struct, restructuring storage to use per-pool keys, adding authorization checks throughout, implementing weighted random winner selection via PRNG, introducing cancellation and refund mechanisms, enforcing 7-day claim windows, and expanding test coverage with new scenarios. Changes
Sequence DiagramsequenceDiagram
actor Artist
participant Contract as Lottery Contract
participant Storage as Persistent Storage
actor Tipper1
actor Tipper2
Note over Artist,Tipper2: Lottery Cancellation & Refund Flow
Artist->>Contract: cancel_lottery(pool_id)
Contract->>Contract: require_auth(artist)
Contract->>Storage: fetch pool
Contract->>Contract: validate status == Open
Storage->>Contract: return pool
Contract->>Storage: update pool.status = Cancelled<br/>update pool.cancelled_at = now
Tipper1->>Contract: claim_refund(pool_id, tipper1)
Contract->>Contract: require_auth(tipper1)
Contract->>Storage: fetch pool entries by tipper1
Storage->>Contract: return entries list
Contract->>Contract: calculate refund = sum(entries.tickets)
Contract->>Storage: remove tipper1 entries
Contract->>Tipper1: return refund amount
Tipper2->>Contract: claim_refund(pool_id, tipper2)
Contract->>Contract: require_auth(tipper2)
Contract->>Storage: fetch pool entries by tipper2
Storage->>Contract: return entries list
Contract->>Contract: calculate refund = sum(entries.tickets)
Contract->>Storage: remove tipper2 entries
Contract->>Tipper2: return refund amount
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Here is the PR description for you to copy:
test test_claim_window_expiry ... ok
test test_lottery_cancellation_and_refund ... ok
test test_lottery_full_lifecycle ... ok
Branch name for the PR:
feature/contracts-workspace-conventionscloses #320
Summary by CodeRabbit
New Features
Improvements