feat: Implement ClaimPrize with Prize Token System and UI Support (CU-06)#555
Merged
xJeffx23 merged 3 commits intoFutureMindsTeam:mainfrom Oct 14, 2025
Merged
Conversation
…ction and improved validation checks. Added steps for draw existence verification, ticket ownership validation, and prize transfer logic. Updated event emission to reflect accurate prize amounts upon claim. Streamlined code for clarity and security.
…GetUserWinningTickets method. Refactor prize assignment to mark_as_prize for clarity. Adjust tests and deployment scripts to reflect these changes and improve role assignments for the Lottery contract.
kimcascante
approved these changes
Oct 13, 2025
drakkomaximo
approved these changes
Oct 13, 2025
xJeffx23
approved these changes
Oct 14, 2025
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 ClaimPrize with Prize Token System and UI Support (CU-06)
📌 Description
This PR implements the complete prize claiming functionality for the lottery smart contract (CU-06), including:
mark_as_prize()instead of mintingClaimPrize()implementation with token transfers from vault to winnersGetUserWinningTickets()function for UI to display claimable prizesassign_prize_tokens()function that could mint infinite tokens🎯 Motivation and Context
The existing
ClaimPrizefunction had critical issues:CheckMatchessystem instead of new distribution system (CU-05)assign_prize_tokens()function was a security risk - it minted tokens from nothing, breaking the project's economySecurity Improvements:
assign_prize_tokens()(mints tokens) withmark_as_prize()(only marks existing tokens)Closes #546
🛠️ How to Test the Change (if applicable)
Testing the complete prize claiming flow:
Backend Testing (Contracts):
cd packages/snfoundry/contracts && scarb buildscarb test(test_CU02.cairo validates the new prize marking system)cd ../.. && yarn deployManual Flow Testing:
DrawNumbersto finalize the drawDistributePrizes(CU-05) to assign prizes to winning ticketsGetUserWinningTickets(drawId, playerAddress)to get claimable prizesClaimPrize(drawId, ticketId)for each winning ticketprize_amountprize_amountclaimed = trueprize_balanceincreased (can convert to STRK)Error Case Testing:
'Draw still active''Distribution not done''Not ticket owner''Prize already claimed'🖼️ Screenshots (if applicable)
N/A - Backend smart contract changes
🔍 Type of Change
✅ Checklist Before Merging
📌 Additional Notes
Key Implementation Details:
1. StarkPlayERC20.cairo Changes:
mark_as_prize()function - only incrementsprize_balance, does NOT mintassign_prize_tokens()- dangerous function that minted tokensPRIZE_ASSIGNER_ROLE2. Lottery.cairo Changes:
ClaimPrize()with:transfer_from()mark_as_prize()GetUserWinningTickets()for UI support:prize_assigned=true,prize_amount>0,claimed=false3. Deploy Script Changes:
PRIZE_ASSIGNER_ROLEto Lottery contract4. Test Updates:
mark_as_prize()instead ofassign_prize_tokens()Files Modified (5 files):
packages/snfoundry/contracts/src/StarkPlayERC20.cairopackages/snfoundry/contracts/src/Lottery.cairopackages/snfoundry/contracts/tests/test_CU02.cairopackages/snfoundry/scripts-ts/deploy.tspackages/nextjs/contracts/deployedContracts.tsPost-Deployment Configuration:
Important: The vault must approve the Lottery contract to transfer tokens:
Security Guarantees:
UI Integration Ready:
The new
GetUserWinningTickets()function enables the UI to:Related Issue: Issue SL-CU06-001 - Implement ClaimPrize in Smart Contract (Backend)