feat: Add emergency_withdraw to farming-pool contract#45
Merged
prodbycorne merged 1 commit intoJun 27, 2026
Conversation
…rios - Created a new test snapshot for the `transfer_admin` event in the factory contract, ensuring the correct event emission when transferring admin rights. - Added a test snapshot for emergency withdrawal while the farming pool is paused, verifying that the correct state is maintained. - Introduced a test snapshot for emergency withdrawal when the pool is unpaused, confirming that the withdrawal process behaves as expected.
7 tasks
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.
Related Issue
Closes #24
Problem
The existing
pausemechanism prevents new operations when a critical vulnerability is discovered, but leaves staked and locked tokens permanently inaccessible. There was no admin path to return funds to users during an emergency.Solution
Introduces
emergency_withdraw, an admin-only function callable exclusively while the pool is paused. It returns all tokens held for a given user (both the lock position and the stake balance), preserves any accrued credits in a newBankedCreditsstorage key for a future claim mechanism, and emits a fully auditableemrg_exitevent.Changes
types.rsPoolError— a#[contracterror]enum withNotPaused = 13andNoActiveStake = 14DataKey::BankedCredits(Address)— persistent storage key for credits preserved after an emergency withdrawallib.rsemergency_withdraw(env, user) -> Result<i128, PoolError>— transfers both the lock position amount and the stake amount back to the user, writes any banked credits toBankedCreditsstorage before removing the records, and emits("pool", "emrg_exit")with(admin, user, total_returned)get_banked_credits(env, user) -> i128— public query for credits saved by a prior emergency withdrawal; returns 0 if noneset_banked_credits— private helper that writes toBankedCreditswith TTL bumptest.rstest_emergency_withdraw_while_paused— locks 600 tokens, stakes 400, triggers credit checkpoints (8 000 credits total), pauses, callsemergency_withdraw, asserts all 1 000 tokens returned, position and stake records cleared, and 8 000 credits preserved inget_banked_creditstest_emergency_withdraw_while_unpaused_returns_not_paused— assertsErr(PoolError::NotPaused)when called on a live poolSafeguards
get_admin(&env).require_auth()at function entryErr(PoolError::NotPaused)if!pool_is_paused— prevents routine extraction of user fundsBankedCreditsbefore position/stake records are removedemrg_exitevent emitted for every withdrawal with(admin, user, amount)Test results