feat(stablecoin): rebuild repay_debt with floor-rounded debt deltas - #353
Open
gravityblast wants to merge 3 commits into
Open
gravityblast wants to merge 3 commits into
gravityblast wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
There are correctness/documentation gaps in the updated repay_debt documentation/tests and an error message mismatch that should be aligned with the spec/acceptance criteria for clarity and consistency.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR rebuilds the stablecoin program’s repay_debt instruction to be fee-aware per spec §10.8 by projecting the stability fee accumulator to the provided clock timestamp, computing a floor-rounded normalized-debt delta, and pinning the stablecoin definition against ProtocolParameters.
Changes:
- Update
repay_debthost logic to computedebt_delta = ⌊amount × FIXED_POINT_ONE / current_accumulator⌋(projected toclock) and validatestablecoin_definitionviaProtocolParameters. - Expand the instruction ABI from 4 → 7 accounts across host + guest wiring (adds accumulator, protocol parameters, clock).
- Add/adjust unit + integration tests and regenerate the stablecoin IDL to match the new account list.
File summaries
| File | Description |
|---|---|
| programs/stablecoin/src/repay_debt.rs | Implements fee-aware, floor-rounded debt delta with protocol-parameters binding and clock-based accumulator projection. |
| programs/stablecoin/methods/guest/src/bin/stablecoin.rs | Updates guest entrypoint signature to pass the three new accounts through to the host function. |
| programs/stablecoin/core/src/lib.rs | Updates Instruction::RepayDebt documentation to reflect the new account list and semantics. |
| programs/stablecoin/src/tests.rs | Adds new unit tests for §10.8 behavior and updates existing repay tests for the new ABI. |
| programs/integration_tests/tests/stablecoin.rs | Seeds the new global accounts and updates the integration repay test to pass the new accounts. |
| artifacts/stablecoin-idl.json | Regenerates IDL to include the three new accounts for repay_debt. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
gravityblast
force-pushed
the
feat/stablecoin-generate-debt
branch
from
September 10, 2026 09:32
e044bc9 to
ff5c08e
Compare
gravityblast
force-pushed
the
feat/stablecoin-repay-debt-rebuild
branch
from
September 10, 2026 09:32
2279208 to
56f709d
Compare
gravityblast
force-pushed
the
feat/stablecoin-generate-debt
branch
from
September 16, 2026 12:43
ff5c08e to
cd1a329
Compare
gravityblast
force-pushed
the
feat/stablecoin-repay-debt-rebuild
branch
from
September 16, 2026 12:43
56f709d to
812fc18
Compare
gravityblast
force-pushed
the
feat/stablecoin-generate-debt
branch
from
September 18, 2026 07:57
cd1a329 to
bd8d425
Compare
gravityblast
force-pushed
the
feat/stablecoin-repay-debt-rebuild
branch
from
September 18, 2026 07:57
812fc18 to
d799eb0
Compare
gravityblast
force-pushed
the
feat/stablecoin-generate-debt
branch
from
September 18, 2026 10:51
bd8d425 to
951c5ac
Compare
gravityblast
force-pushed
the
feat/stablecoin-repay-debt-rebuild
branch
from
September 18, 2026 10:51
d799eb0 to
3c25317
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebuilds
repay_debtto spec §10.8. The Plan 1 scaffold subtractedamountdirectly from
normalized_debt_amountand trusted whateverstablecoin_definitionthe caller passed.Accounts go 4 → 7, adding
stability_fee_accumulator,protocol_parametersandclock. The decrement is now⌊amount × FIXED_POINT_ONE / current_accumulator⌋,rounded down per §6.3 against the accumulator projected to the clock
timestamp — debt shrinks by at most what was burned, and the rounding remainder
stays with the protocol.
stablecoin_definitionis pinned againstProtocolParameters.stablecoin_definition_id, closing the gap the scaffold's// TODOcalled out.Allowed while frozen:
protocol_parametersis read for the accumulator rate andthe definition binding, never for
is_frozen. Repaying only improves theprotocol's position (§7).
7 new tests: the three new accounts echoed, the floor rounding at accumulator 3.0
(100 → 33), repay while frozen, an unbound stablecoin definition, overrepay
against the floored delta, and an uninitialized variant of each new global.
Sixth of eight issues in Plan 3 (#173). Stacked on #352.
closes #179