Skip to content

feat(stablecoin): expose repayDebt module API - #402

Open
3esmit wants to merge 1 commit into
feat/stablecoin-module-deposit-collateral-387from
feat/stablecoin-module-repay-debt-388
Open

3esmit wants to merge 1 commit into
feat/stablecoin-module-deposit-collateral-387from
feat/stablecoin-module-repay-debt-388

Conversation

@3esmit

@3esmit 3esmit commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Expose repayDebt(request) through stablecoin_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_ffi
  • nix build path:.#stablecoin-module-tests -L
  • nix build path:.#stablecoin-module -L
  • Repository formatting, lint, unit, integration, and IDL checks.

@3esmit
3esmit added this pull request to stack #337 October 5, 2026 05:13
@3esmit
3esmit marked this pull request as ready for review October 5, 2026 13:08
Copilot AI balanced review requested due to automatic review settings October 5, 2026 13:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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++ repayDebt method.
  • 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.

@3esmit 3esmit added type: feature New feature or request stablecoin Stablecoin protocol and its program, module, deployment and application surfaces. module Reusable Logos module backend, program client API or FFI; dedicated module build/test work. labels Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module Reusable Logos module backend, program client API or FFI; dedicated module build/test work. stablecoin Stablecoin protocol and its program, module, deployment and application surfaces. type: feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose stablecoin repayDebt transaction through stablecoin_module

2 participants