Skip to content

refactor(farming-pool): single source of truth for Position credit accrual - #133

Open
Okorie2000-code wants to merge 1 commit into
SmartDropLabs:mainfrom
Okorie2000-code:fix/farming-pool-shared-position-credits
Open

refactor(farming-pool): single source of truth for Position credit accrual#133
Okorie2000-code wants to merge 1 commit into
SmartDropLabs:mainfrom
Okorie2000-code:fix/farming-pool-shared-position-credits

Conversation

@Okorie2000-code

@Okorie2000-code Okorie2000-code commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Closes #63

checkpoint_position and calculate_credits duplicated the Position credit-accrual formula (amount * credit_rate * elapsed). This extracts it into a single compute_position_credits helper shared by both paths.

Changes

  • Added compute_position_credits(amount, credit_rate, elapsed) next to the existing compute_total_stake / compute_credits helpers
  • checkpoint_position now banks credits via the shared helper
  • calculate_credits now previews credits via the exact same helper
  • No duplicated amount * credit_rate * elapsed as i128 calculation remains
  • Position accrual stays separate from compute_credits (UserStake boost/multiplier semantics), per the issue's design constraint — compute_credits is not reused
  • No public API changes; helper is private

Tests

Added focused unit coverage for the shared Position accrual:

  • elapsed = 0
  • normal positive amount/rate/elapsed
  • multiple (amount, credit_rate, elapsed) combinations
  • banked (via checkpoint_position) vs previewed (via calculate_credits) parity
  • a multi-checkpoint scenario

All existing tests preserved. cargo test --workspace passes: factory 34, farming-pool 79 (74 existing + 5 new). Closes #63

@netlify

netlify Bot commented Aug 17, 2026

Copy link
Copy Markdown

Deploy Preview for sdcontracts ready!

Name Link
🔨 Latest commit f441d4d
🔍 Latest deploy log https://app.netlify.com/projects/sdcontracts/deploys/6a82bf4932aa9a000816d750
😎 Deploy Preview https://deploy-preview-133--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.

@prodbycorne

Copy link
Copy Markdown
Contributor

ci test failed

…ition_credits

Extract the amount * credit_rate * elapsed formula into a single
compute_position_credits helper used by both checkpoint_position and
calculate_credits, eliminating the duplicated calculation. Deliberately
kept separate from compute_credits since Positions have no boost or
multiplier semantics. Add unit coverage for the shared accrual path,
adapted to the pool's min_stake_amount gate.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@Okorie2000-code
Okorie2000-code force-pushed the fix/farming-pool-shared-position-credits branch from 8ee58aa to f441d4d Compare August 17, 2026 07:59
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: checkpoint_position and calculate_credits duplicate the credit-accrual formula instead of sharing one implementation

2 participants