feat: implement pull-based refund model for gas safety - #123
Open
ChukwuemekaP1 wants to merge 2 commits into
Open
feat: implement pull-based refund model for gas safety#123ChukwuemekaP1 wants to merge 2 commits into
ChukwuemekaP1 wants to merge 2 commits into
Conversation
- Add GrantNotCancelled and RefundAlreadyClaimed error types - Add RefundClaimed storage key for tracking funder claims - Refactor cancel_grant to remove O(n) funder loop - Add refund_claim function for manual funder claims - Implement double-claim prevention via persistent storage - Add comprehensive inline documentation - Follow Checks → Effects → Interactions pattern - Ensure reentrancy protection and checked arithmetic Fixes gas/memory issues from looping over funders during cancellation.
|
@ChukwuemekaP1 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
@ChukwuemekaP1 kindly fix workflow |
Author
|
Alright |
Contributor
|
@ChukwuemekaP1 resolve conflicts |
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.
Closes #66
🎯 Overview
This PR implements a pull-based refund model to replace the gas-intensive push-based approach in grant cancellation. The previous implementation looped through all funders during cancellation, causing potential gas/memory issues with large numbers of funders.
✨ Key Changes
lib.rs: Refactored cancel_grant() to remove O(n) funder loop; added new refund_claim() function
storage.rs: Added RefundClaimed storage key for tracking individual funder claims
types.rs: Added GrantNotCancelled and RefundAlreadyClaimed error types
Before: cancel_grant() automatically distributed refunds to all funders (push model) ❌
After: cancel_grant() marks grant as cancelled; funders manually claim via refund_claim() ✅
✅ Double-claim prevention via persistent storage flag
✅ Authorization checks (only actual funders can claim)
✅ Checked arithmetic for overflow protection
✅ Reentrancy guard protection
✅ Follows Checks → Effects → Interactions pattern
🚀 Gas Efficiency: Cancellation is now O(1) instead of O(n)
💾 Memory Safety: No loading entire funder list during cancellation
♾️ Scalability: Supports unlimited funders without gas concerns
🔐 Unclaimed Funds: Remain locked in contract indefinitely (intentional design)
🧪 Testing
68 tests passing
Comprehensive test coverage for:
Single/multiple funder claims
Failure cases (before cancellation, non-funder, double attempts)
Edge cases (zero balance, partial claims, unclaimed funds)
Regression tests for existing functionality