Skip to content

fix(#132): add MAX_MIN_LOCK_PERIOD ceiling to farming-pool and factory - #135

Open
devkryssie wants to merge 1 commit into
SmartDropLabs:mainfrom
devkryssie:fix/132-min-lock-period-ceiling
Open

fix(#132): add MAX_MIN_LOCK_PERIOD ceiling to farming-pool and factory#135
devkryssie wants to merge 1 commit into
SmartDropLabs:mainfrom
devkryssie:fix/132-min-lock-period-ceiling

Conversation

@devkryssie

Copy link
Copy Markdown

Summary

Closes #132.

min_lock_period accepted the full u32 range (up to ~681 years at 5 s/ledger) in both FarmingPool::initialize and set_min_lock_period, with no upper-bound validation — unlike global_multiplier and credit_rate which gained explicit ceilings in #89. Any user who locks after an admin sets an extreme value has their principal effectively trapped permanently, with no recovery path other than the admin-gated emergency_withdraw.

Changes

farming-pool

factory

  • Mirrors the same ceiling in create_pool before deploying/initializing a pool
  • Returns FactoryError::MinLockPeriodAboveCeiling (= 9) on violation — checked after the existing MinLockPeriodOutOfRange u32-fit check, so both remain distinct and testable

Tests

  • test_set_min_lock_period_rejects_above_ceiling
  • test_set_min_lock_period_accepts_exactly_the_ceiling
  • test_initialize_rejects_min_lock_period_above_ceiling
  • test_initialize_accepts_min_lock_period_exactly_at_ceiling
  • test_create_pool_rejects_min_lock_period_above_ceiling
  • test_create_pool_accepts_min_lock_period_exactly_at_ceiling

Ceiling derivation

MAX_MIN_LOCK_PERIOD = 2 years × 365 × 86_400 s/day / 5 s/ledger = 12_614_400 ledgers

Two years covers any realistic campaign-style lock window. The companion vesting-wallet contract in this workspace is the intended vehicle for pure vesting use cases, so farming-pool locks are campaign-oriented by design — multi-year horizons beyond this ceiling have no credible business justification in this contract's role.

Tested

All tests pass: 104 farming-pool + factory unit tests, 20 vesting-wallet tests.

…ol and factory

min_lock_period accepted the full u32 range (up to ~681 years at 5 s/ledger)
in both FarmingPool::initialize and set_min_lock_period, with no upper-bound
validation — unlike global_multiplier and credit_rate which gained explicit
ceilings in SmartDropLabs#89. Any user who locks after an admin sets an extreme value has
their principal effectively trapped permanently.

Changes:
- farming-pool: add MAX_MIN_LOCK_PERIOD = 12_614_400 (~2 years at 5 s/ledger)
  with a worked derivation comment mirroring SmartDropLabs#89's style
- farming-pool: enforce ceiling in initialize and set_min_lock_period, returning
  PoolError::MinLockPeriodAboveCeiling (= 10) on violation
- factory: mirror the same ceiling in create_pool before deploying/initializing
  a pool, returning FactoryError::MinLockPeriodAboveCeiling (= 9) on violation
- tests: add test_set_min_lock_period_rejects_above_ceiling,
  test_set_min_lock_period_accepts_exactly_the_ceiling,
  test_initialize_rejects_min_lock_period_above_ceiling,
  test_initialize_accepts_min_lock_period_exactly_at_ceiling (farming-pool)
  and test_create_pool_rejects_min_lock_period_above_ceiling,
  test_create_pool_accepts_min_lock_period_exactly_at_ceiling (factory)

All tests pass (104 farming-pool + factory, 20 vesting-wallet).

Closes SmartDropLabs#132
@netlify

netlify Bot commented Aug 17, 2026

Copy link
Copy Markdown

Deploy Preview for sdcontracts ready!

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

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant