Repository navigation
fix(farming-pool): align lock_assets and initialize validation with stake - #593
Merged
ritaifeoluwa merged 1 commit intoOct 21, 2026
Conversation
…take - initialize rejects min_lock_period above MAX_LOCK_PERIOD, matching set_min_lock_period so a pool cannot be deployed with a lock period the admin setter would refuse. - lock_assets checks pool-wide total_staked/total_locked overflow before any write, returning ExceedsMaxStake instead of trapping in add_total_*. - lock_assets checks the caller balance up front and returns InsufficientBalance, instead of relying on the token transfer trapping. - lock_assets verifies the pool received the full deposit and returns TransferAmountMismatch for fee-on-transfer tokens, as stake already does. Refs SmartDropLabs#468, SmartDropLabs#469, SmartDropLabs#478, SmartDropLabs#479
✅ Deploy Preview for sdcontracts ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
@financialcrackerjack-max 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 #468, Closes #469, Closes #478, Closes #479
The four assigned issues share one template ("stake N validation issue") with no specific failing input, so this PR addresses four concrete validation gaps found by comparing
stake,lock_assetsandinitializeincontracts/farming-pool/src/lib.rs.stakealready carries the guards from earlier fixes (#453, #458, #484); the sibling paths did not.Changes
initializelock-period ceiling. Rejectsmin_lock_period > MAX_LOCK_PERIODwithInvalidLockPeriod, the same checkset_min_lock_periodalready performs. Before this, a pool could be deployed with a lock period the admin setter would refuse.lock_assetsoverflow guard. Checkstotal_staked + amountandtotal_locked + amountbefore any write and returnsExceedsMaxStake. Previously theexpectinsideadd_total_staked/add_total_lockedcould trap.lock_assetsfunding check. Reads the caller balance up front (try_balance, mapping failures toInvalidStakeToken) and returnsInsufficientBalancebefore any write or cross-contract call. Previously an underfunded lock failed inside the token transfer.lock_assetsreceived-amount check. Reads the pool balance before and after the transfer and returnsTransferAmountMismatchif the pool did not receive the full amount. This matchesstakeand prevents a fee-on-transfer token from leaving a locked position under-backed. The error reverts the whole invocation, position write included.A new helper
read_total_lockedmirrorsread_total_staked.Tests added (
contracts/farming-pool/src/test.rs)test_initialize_rejects_min_lock_period_above_ceilingtest_lock_assets_rejects_insufficient_balance_without_writing_statetest_lock_assets_overflowing_total_staked_returns_typed_error_without_writing_statetest_lock_assets_rejects_deposit_not_delivered_in_fullExisting lock tests that asserted
is_err()for underfunded locks still pass, since the error is now typed rather than a trap.Verification
Not run. The contributor's workflow for this PR excludes build and test commands, so the Rust changes were checked by reading only. CI will compile and run the suite. Reviewers should pay particular attention to the reentrancy tests that use
MockNaiveReentrantToken, becauselock_assetsnow makes abalancecall before the transfer.