feat: withdraw uses effective funds, per-tx cap, emergency withdrawal… - #731
Open
ExcelDsigN-tech wants to merge 2 commits into
Open
Conversation
|
@ExcelDsigN-tech 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! 🚀 |
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 #514, Closes #522, Closes #525, Closes #527
Overview
This PR resolves financial calculation bugs, expands anti-whale protection controls, adds emergency fund recovery mechanics, and prevents duplicate campaign title creation across the smart contract platform.
Specifically, it updates fee calculations to target net raised funds after refunds, introduces an admin-configurable per-transaction contribution ceiling, implements a 2-step timelocked emergency withdrawal pattern for misconfigured campaigns, and enforces per-creator campaign title uniqueness.
Feature Summary
withdraw_fundsto compute platform fees and creator payouts againsteffective_amount_raisedinstead ofamount_raised, preventing fee overcharges when refunds have occurred.max_contribution_per_transactionas an admin-configurable parameter to block single large contributions (e.g., 199% of goal) that evade auto-pause rules.propose_emergency_withdrawandexecute_emergency_withdraw) guarded by a mandatory 7-day timelock and admin authentication.DataKey::CreatorCampaignTitleIndex(creator, title_hash)to reject duplicate campaign titles from the same creator address.Technical Implementation
src/lib.rs/src/withdraw.rs): Replacedamount_raisedwitheffective_amount_raisedinwithdraw_fundswhen deriving platform fee shares and net creator payouts.src/lib.rs/src/storage.rs): AddedDataKey::MaxContributionPerTxstorage key along with getter/setter routines. Added checks incontributeto reject contributions exceedingmax_contribution_per_transaction.src/emergency.rs/src/lib.rs): Implementedpropose_emergency_withdrawto record a pending emergency withdrawal proposal with an execution timestamp set toenv.ledger().timestamp() + 7_DAYS. Implementedexecute_emergency_withdrawto verify the timelock elapsed before releasing funds torecipientand emitting safety log events.src/campaign.rs): Hashed input campaign titles (title_hash) and checkedDataKey::CreatorCampaignTitleIndex(creator, title_hash)prior to campaign initialization, storing the key on creation.Test Coverage
withdraw_fundsaccurately reflecteffective_amount_raisedafter partial donor refunds.execute_emergency_withdrawfails prior to the 7-day timelock elapsing and succeeds after the timelock expires.Checklists
withdraw_fundsuseseffective_amount_raisedinstead of grossamount_raisedmax_contribution_per_transactionadded and enforced during contribution calls