Skip to content

fix: add missing refresh_hwm call in process_deposit_junior - #122

Merged
dcccrypto merged 1 commit into
dcccrypto:mainfrom
0x-SquidSol:fix/deposit-junior-refresh-hwm
Apr 11, 2026
Merged

fix: add missing refresh_hwm call in process_deposit_junior#122
dcccrypto merged 1 commit into
dcccrypto:mainfrom
0x-SquidSol:fix/deposit-junior-refresh-hwm

Conversation

@0x-SquidSol

@0x-SquidSol 0x-SquidSol commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • process_deposit refreshes the epoch high-water mark after updating pool state (lines 564-569, PERC-313)
  • process_deposit_junior does not, despite also increasing TVL via total_deposited, total_lp_supply, junior_total_lp, and junior_balance
  • Junior deposits raise total_pool_value() without ratcheting epoch_high_water_tvl, leaving the HWM-based withdrawal floor calculated against a stale (lower) peak
  • If a loss event occurs before the next senior deposit or withdrawal, the peak TVL from the junior deposit is permanently lost from HWM tracking

Severity

MEDIUM — weakens HWM drain protection asymmetrically (senior deposits refresh HWM, junior deposits do not)

Fix

Added the same refresh_hwm block after pool state updates, matching process_deposit exactly:

if pool.hwm_enabled() {
    let current_tvl = pool.total_pool_value().ok_or(StakeError::Overflow)?;
    pool.refresh_hwm(clock.epoch, current_tvl);
}

Placement: after all 4 pool state mutations (lines 1930-1947), before deposit PDA logic (line 1960). Uses the clock already read at line 1949.

Verification

  • 3 independent agents confirmed the fix is correct, safe, and introduces no new issues
  • Identical pattern to process_deposit (lines 564-569)
  • total_pool_value() cannot realistically return None at this point (deposit just increased it)
  • HWM writes to _reserved[16..31] — no byte conflicts with tranche state (_reserved[32+])

Test plan

  • cargo build — compiles cleanly
  • cargo clippy — zero warnings

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Fixed pool high-water mark synchronization for junior tranche deposits to align with standard deposit operations, ensuring accurate tracking throughout the deposit process.

process_deposit refreshes the epoch high-water mark after updating
pool state (lines 564-569, PERC-313), but process_deposit_junior
did not.  Junior deposits increase total_pool_value() without
ratcheting epoch_high_water_tvl, leaving the HWM-based withdrawal
floor calculated against a stale (lower) peak.  If a loss event
occurs before the next senior deposit or withdrawal, the peak TVL
from the junior deposit is permanently lost from HWM tracking,
weakening the drain protection.

Added the same refresh_hwm block after pool state updates, matching
the pattern in process_deposit exactly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Apr 10, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 774c2034-10ac-4ee3-9b85-c06afde9f3ed

📥 Commits

Reviewing files that changed from the base of the PR and between 4fe119b and cfacec5.

📒 Files selected for processing (1)
  • src/processor.rs

📝 Walkthrough

Walkthrough

The process_deposit_junior function now refreshes the pool high-water mark (HWM) immediately after updating junior tranche totals, computing the current total pool value and conditionally invoking the HWM refresh. This logic mirrors existing HWM refresh behavior in process_deposit for standard deposits.

Changes

Cohort / File(s) Summary
High-Water Mark Refresh for Junior Deposits
src/processor.rs
Added conditional HWM refresh logic after updating junior tranche totals. When pool.hwm_enabled() is true, the function computes current TVL via pool.total_pool_value() and calls pool.refresh_hwm(clock.epoch, current_tvl) to align HWM handling between junior and non-junior deposits.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • dcccrypto

Poem

🐰 Through junior vaults the rabbit bounds,
Refreshing marks with steady sounds,
HWM kept in perfect sync,
No deposit slips beyond the brink! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides a comprehensive summary, clear rationale, and fix details, but is missing the required 'How to test' and 'Checklist' sections from the template. Add 'How to test' section with specific testing steps and complete the 'Checklist' section, marking items as done or explaining why they're not applicable.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a missing HWM refresh call to the junior deposit function, directly matching the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dcccrypto
dcccrypto merged commit 831c840 into dcccrypto:main Apr 11, 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.

2 participants