Skip to content

feat: add farming pool config setters (#17)#54

Merged
prodbycorne merged 2 commits into
SmartDropLabs:mainfrom
nomsoscript:feat/farming-pool-config-17
Jun 29, 2026
Merged

feat: add farming pool config setters (#17)#54
prodbycorne merged 2 commits into
SmartDropLabs:mainfrom
nomsoscript:feat/farming-pool-config-17

Conversation

@nomsoscript

Copy link
Copy Markdown

Closes #17

Summary

This PR makes credit_rate and min_lock_period configurable after pool initialization in the farming-pool contract.

Before this change, both values were effectively frozen once initialize was called. That made it impossible to tune emissions over time or shorten lock requirements for new positions without redeploying the pool.

What Changed

New admin setters

Added two admin-only update functions:

  • set_credit_rate(env, new_rate) -> Result<(), PoolError>
  • set_min_lock_period(env, new_period) -> Result<(), PoolError>

New public getters

Added read-only getters for both config values:

  • credit_rate(env) -> Result<i128, PoolError>
  • get_credit_rate(env) -> Result<i128, PoolError>
  • min_lock_period(env) -> Result<u32, PoolError>
  • get_min_lock_period(env) -> Result<u32, PoolError>

Typed validation

Added PoolError::InvalidCreditRate and reject credit_rate <= 0 through a typed contract error instead of relying only on assertions.

Event emission

Both setters now emit config update events:

  • ("pool", "rate_set") with (old_rate, new_rate)
  • ("pool", "lock_set") with (old_period, new_period)

Important Behavior Preserved

This PR makes the updates safe for existing positions by snapshotting the relevant values into user state.

Credit rate changes are not retroactive

Existing stake/lock accrual keeps using the previously active credit_rate until the next checkpoint. After checkpointing, future accrual uses the new rate.

To support that, this PR stores a credit_rate snapshot on:

  • UserStake
  • Position

This prevents an admin rate change from rewriting already-earned credits.

Min lock period changes do not rewrite existing locks

Existing locked positions keep their original unlock boundary even if min_lock_period changes later.

To support that, this PR stores:

  • unlock_ledger on Position

This means:

  • existing locks keep their original unlock timing
  • only newly created positions use the updated min_lock_period

Internal Cleanup Included

While implementing the issue, I also cleaned up pre-existing problems in the farming-pool contract files that would have interfered with this change:

  • removed duplicated imports
  • unified duplicated PoolError definitions
  • fixed broken/pasted-over token transfer sections
  • normalized the farming-pool contract structure around the new config behavior

Test Coverage Added

Added tests covering:

  • set_credit_rate public getter behavior
  • set_min_lock_period public getter behavior
  • set_credit_rate emits the expected event
  • set_min_lock_period emits the expected event
  • set_credit_rate rejects zero with PoolError::InvalidCreditRate
  • set_credit_rate is admin-only
  • set_min_lock_period is admin-only
  • credit rate changes do not retroactively alter already-earned stake credits
  • credit rate changes do not retroactively alter already-earned locked-position credits
  • updating min_lock_period does not affect an existing position’s unlock boundary
  • newly created positions use the updated min_lock_period
  • position getters now reflect unlock_ledger and stored credit_rate

Files Changed

  • soroban/contracts/farming-pool/src/lib.rs
  • soroban/contracts/farming-pool/src/types.rs
  • soroban/contracts/farming-pool/src/test.rs

Testing

Not run locally in this environment because cargo is not available on the current shell PATH.

Notes

This PR intentionally keeps the change scoped to issue #17:

  • no redeploy-only workaround
  • no unrelated feature additions
  • no retroactive credit recalculation logic

@prodbycorne prodbycorne merged commit bcc87f6 into SmartDropLabs:main Jun 29, 2026
1 check 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

Development

Successfully merging this pull request may close these issues.

farming-pool: credit_rate and min_lock_period are immutable after initialize

2 participants