Repository navigation
Conversation
3esmit
added this pull request to stack #337
October 5, 2026 05:13
3esmit
marked this pull request as ready for review
October 5, 2026 13:08
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Financial state changes across Rust, FFI, wallet authorization, and chained token burns warrant final human validation.
Review effort: Balanced
Findings: None
What changed in this PR
Exposes fee-aware debt repayment through stablecoin_module, connecting live-account validation to wallet submission for issue #388.
Changes:
- Adds the Rust repayment planner, FFI exports, and C++
repayDebtmethod. - Preserves exact burns, downward-rounded debt reduction, frozen-state repayment, and both required signers.
- Adds contract tests and documents request fields and stable errors.
| File | Description |
|---|---|
| modules/stablecoin/tests/stablecoin_module_real_ffi_journey_test.cpp | Tests production FFI integration and large amounts. |
| modules/stablecoin/tests/stablecoin_module_impl_test.cpp | Tests authorization, submission, and failures. |
| modules/stablecoin/tests/mocks/mock_stablecoin_ffi.cpp | Adds repayment planner mock. |
| modules/stablecoin/src/stablecoin_module_support.cpp | Recognizes repayment errors. |
| modules/stablecoin/src/stablecoin_module_impl.h | Declares the repayment method. |
| modules/stablecoin/src/stablecoin_module_impl.cpp | Implements live reads and wallet submission. |
| modules/stablecoin/README.md | Documents repayment behavior and errors. |
| modules/stablecoin/ffi/tests/public_api.rs | Checks public repayment exports. |
| modules/stablecoin/ffi/src/lib.rs | Re-exports repayment API types. |
| modules/stablecoin/ffi/src/ffi.rs | Adds the C-callable planner. |
| modules/stablecoin/ffi/src/api/request.rs | Defines repayment planner input. |
| modules/stablecoin/ffi/src/api/repay_tests.rs | Tests rounding, validation, and chained burns. |
| modules/stablecoin/ffi/src/api/plan.rs | Implements repayment preflight and planning. |
| modules/stablecoin/ffi/src/api/mod.rs | Exports planner and registers tests. |
| modules/stablecoin/ffi/include/stablecoin_ffi.h | Declares the C API. |
| modules/stablecoin/ffi/Cargo.toml | Adds token-program test dependency. |
| Cargo.lock | Records the test dependency. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Summary
Expose
repayDebt(request)throughstablecoin_module, with a pure Rust FFI planner that validates live position, token, parameter, accumulator, and clock accounts before wallet submission.The transaction burns exactly the requested stablecoins and reduces normalized debt using the current fee accumulator, rounding down. Repayment remains available while frozen, including zero amounts and positive burns whose normalized-debt reduction rounds to zero. Both the position owner and source holding must be public accounts controlled by the active wallet and both sign.
Tests cover account order and IDL flags, rounding and overpayment boundaries, full-width integers, malformed accounts, wallet failures, native repayment with the chained token burn, and the C++ adapter linked to the production FFI. Document the request fields and stable errors, and export the new planner and module method.
Closes #388
Validation
RISC0_DEV_MODE=1 cargo +1.94.0 test -p stablecoin_ffinix build path:.#stablecoin-module-tests -Lnix build path:.#stablecoin-module -L