Skip to content

feat(stablecoin): expose generateDebt module API - #416

Merged
0x-r4bbit merged 2 commits into
feat/stablecoin-module-withdraw-collateral-390from
feat/stablecoin-module-generate-debt-391
Oct 19, 2026
Merged

0x-r4bbit merged 2 commits into
feat/stablecoin-module-withdraw-collateral-390from
feat/stablecoin-module-generate-debt-391

Conversation

@3esmit

@3esmit 3esmit commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Expose generateDebt(request) through stablecoin_module, with live-account preflight and owner-only signing. The destination holding can be outside the active wallet; the program authorizes its chained Token mint with the stablecoin definition's PDA.

Preserve upward-rounded normalized debt, native narrow accumulator pricing, wide post-mint collateralization and oracle freshness. A fresh zero-price market oracle is accepted, while stale/future observations, frozen state, zero projected redemption price, insufficient collateral and unrepresentable arithmetic fail before submission. Zero amounts retain all validation gates.

Validate definition authority, token bindings and mint capacity, and re-read the configured oracle and parameters on every call. Tests pin the nine-account ABI, rounding and freshness boundaries, maximum-width inputs, native mint execution, live oracle rotation and wallet failures. Export the planner/module method and document the request and stable errors.

Closes #391

Validation

  • RISC0_DEV_MODE=1 cargo +1.94.0 test -p stablecoin_ffi
  • nix build .#stablecoin-module-tests .#stablecoin-module --no-link -L
  • Repository formatting, workspace/guest lint, unit/integration and IDL checks.

@3esmit
3esmit added this pull request to stack #337 October 5, 2026 07:43
@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 arithmetic, chained mint authorization, and live-state transaction planning warrant final human review despite comprehensive coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Exposes owner-signed stablecoin debt generation with live preflight validation and exact protocol arithmetic.

Changes:

  • Adds the Rust FFI debt planner and C ABI export.
  • Adds generateDebt to the C++ module with live account reads and transaction submission.
  • Documents and extensively tests validation, arithmetic, ABI, and wallet behavior.
File Description
modules/​stablecoin/​ffi/​src/​api/​debt.rs Implements debt preflight and planning.
modules/​stablecoin/​ffi/​src/​api/​debt_tests.rs Tests protocol behavior and boundaries.
modules/​stablecoin/​ffi/​src/​api/​request.rs Defines the planner request.
modules/​stablecoin/​ffi/​src/​api/​mod.rs Exports the planner API.
modules/​stablecoin/​ffi/​src/​lib.rs Re-exports the public surface.
modules/​stablecoin/​ffi/​src/​ffi.rs Adds the C entry point.
modules/​stablecoin/​ffi/​include/​stablecoin_ffi.h Declares the C API.
modules/​stablecoin/​ffi/​tests/​public_api.rs Verifies public re-exports.
modules/​stablecoin/​src/​stablecoin_module_impl.cpp Implements generateDebt.
modules/​stablecoin/​src/​stablecoin_module_impl.h Declares and documents the method.
modules/​stablecoin/​src/​stablecoin_module_support.cpp Exposes stable borrowing errors.
modules/​stablecoin/​tests/​stablecoin_module_impl_test.cpp Tests module orchestration and failures.
modules/​stablecoin/​tests/​stablecoin_module_real_ffi_journey_test.cpp Tests real FFI borrowing journeys.
modules/​stablecoin/​tests/​mocks/​mock_stablecoin_ffi.cpp Adds the planner mock.
modules/​stablecoin/​README.md Documents debt generation semantics.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@3esmit
3esmit force-pushed the feat/stablecoin-module-generate-debt-391 branch from 937a4fa to 287bde3 Compare October 5, 2026 14:08
@3esmit 3esmit added type: feature New feature or request program: stablecoin kind/integration Guest wiring + integration kind/math Fixed-point / projection math 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. and removed type: feature New feature or request program: stablecoin kind/integration Guest wiring + integration labels Oct 7, 2026
@0x-r4bbit
0x-r4bbit force-pushed the feat/stablecoin-module-generate-debt-391 branch from 287bde3 to 03f2439 Compare October 19, 2026 12:17
@0x-r4bbit
0x-r4bbit merged commit bcbf7b2 into main Oct 19, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/math Fixed-point / projection math 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 generateDebt transaction through stablecoin_module

3 participants