Skip to content

fix(farming-pool): align lock_assets and initialize validation with stake - #593

Merged
ritaifeoluwa merged 1 commit into
SmartDropLabs:mainfrom
financialcrackerjack-max:fix/farming-pool-stake-validation-batch
Oct 21, 2026
Merged

ritaifeoluwa merged 1 commit into
SmartDropLabs:mainfrom
financialcrackerjack-max:fix/farming-pool-stake-validation-batch

Conversation

@financialcrackerjack-max

@financialcrackerjack-max financialcrackerjack-max commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

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_assets and initialize in contracts/farming-pool/src/lib.rs. stake already carries the guards from earlier fixes (#453, #458, #484); the sibling paths did not.

Changes

  • initialize lock-period ceiling. Rejects min_lock_period > MAX_LOCK_PERIOD with InvalidLockPeriod, the same check set_min_lock_period already performs. Before this, a pool could be deployed with a lock period the admin setter would refuse.
  • lock_assets overflow guard. Checks total_staked + amount and total_locked + amount before any write and returns ExceedsMaxStake. Previously the expect inside add_total_staked / add_total_locked could trap.
  • lock_assets funding check. Reads the caller balance up front (try_balance, mapping failures to InvalidStakeToken) and returns InsufficientBalance before any write or cross-contract call. Previously an underfunded lock failed inside the token transfer.
  • lock_assets received-amount check. Reads the pool balance before and after the transfer and returns TransferAmountMismatch if the pool did not receive the full amount. This matches stake and 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_locked mirrors read_total_staked.

Tests added (contracts/farming-pool/src/test.rs)

  • test_initialize_rejects_min_lock_period_above_ceiling
  • test_lock_assets_rejects_insufficient_balance_without_writing_state
  • test_lock_assets_overflowing_total_staked_returns_typed_error_without_writing_state
  • test_lock_assets_rejects_deposit_not_delivered_in_full

Existing 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, because lock_assets now makes a balance call before the transfer.

…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
@netlify

netlify Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for sdcontracts ready!

Name Link
🔨 Latest commit 2f468b7
🔍 Latest deploy log https://app.netlify.com/projects/sdcontracts/deploys/6ad800bd5b5be06725542803
😎 Deploy Preview https://deploy-preview-593--sdcontracts.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@drips-wave

drips-wave Bot commented Oct 21, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@ritaifeoluwa
ritaifeoluwa merged commit ee91624 into SmartDropLabs:main Oct 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants