Skip to content

fix: keep AggMonetaryPolicy4 EMA discount active#159

Draft
AlbertoCentonze wants to merge 1 commit intomasterfrom
fix/agg-monetary-policy4-ema-rate
Draft

fix: keep AggMonetaryPolicy4 EMA discount active#159
AlbertoCentonze wants to merge 1 commit intomasterfrom
fix/agg-monetary-policy4-ema-rate

Conversation

@AlbertoCentonze
Copy link
Collaborator

@AlbertoCentonze AlbertoCentonze commented Mar 12, 2026

  • Keep the debt-ratio EMA term active in AggMonetaryPolicy4 even when current PegKeeper debt drops back to zero, so the rate adjustment decays smoothly instead of being bypassed in a single step.
  • Replace the local exp implementation with snekmate's WAD exponential helper while keeping the previous zero/overflow wrapper semantics.

Context

Previously, the debt-ratio adjustment was only applied when pk_debt > 0. That meant the policy could accumulate a nonzero debt-ratio EMA, but as soon as current PegKeeper debt went back to zero the EMA term stopped affecting the rate immediately.

The change here makes the rate calculation always read the existing debt-ratio EMA. This preserves the intended smoothing behavior: once the PegKeeper discount has built up, it fades out gradually instead of disappearing in one update.

Edge Case Note

When aggregate controller debt is observed as zero, this change intentionally leaves ratio = 0 rather than introducing more invasive handling around EMA updates.

That state should be rare in practice because it requires all controllers tracked by this policy to report zero or unreadable debt at the same time. In that case, letting the EMA slowly remove the PegKeeper discount is acceptable and keeps the change narrowly scoped to the bypass issue.

@github-actions
Copy link

Note: This analysis is qualitative; immutables aren't accounted for (static analysis on predeployment bytecode).

Runtime bytespace changes

curve_stablecoin/mpolicies/AggMonetaryPolicy4.vy

  • Base runtime size: 13543 bytes
  • Head runtime size: 12355 bytes
  • Delta: -1188 bytes
Function Base (bytes) Head (bytes) Delta (bytes)
calculate_rate 4394 3206 -1188
exp 1376 236 -1140

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.

1 participant