Skip to content

feat(stablecoin): expose withdrawCollateral module API - #415

Open
3esmit wants to merge 1 commit into
feat/stablecoin-module-position-health-343from
feat/stablecoin-module-withdraw-collateral-390
Open

3esmit wants to merge 1 commit into
feat/stablecoin-module-position-health-343from
feat/stablecoin-module-withdraw-collateral-390

Conversation

@3esmit

@3esmit 3esmit commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Expose withdrawCollateral(request) through stablecoin_module, with live-account preflight and the program's exact post-withdrawal collateralization check. Only the Position owner signs; collateral can be sent to an initialized holding outside the active wallet, using the program's Vault PDA authorization.

Validate Position, Vault, token bindings, globals and canonical clock before submission. Preserve fractional debt, wide projections, conservative requirement saturation, frozen-state rejection and zero-price protection. Zero amounts and zero-debt withdrawals skip health projections while retaining structural validation and authorization. Bound withdrawals by recorded collateral and check the transfer's live balances.

Tests pin the eight-account ABI, owner-only signing, arithmetic boundaries, maximum-width inputs, malformed accounts, native PDA-authorized transfer, wallet failures and current-state rereads through the production FFI. Export the planner/module method and document request fields and stable errors.

Closes #390

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 06:54
@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

The collateral-moving transaction warrants final human verification of live-state validation, authorization and wallet submission behavior.

Review effort: Balanced
Findings: None

What changed in this PR

Adds withdrawCollateral(request) to the stablecoin module, exposing the existing program instruction with live-state validation and owner-only signing.

Changes:

  • Adds withdrawal planning with native-compatible collateralization checks.
  • Exposes Rust, C and module APIs with stable error handling.
  • Documents the API and tests arithmetic boundaries, authorization and submission failures.
File Description
modules/​stablecoin/​tests/​stablecoin_module_real_ffi_journey_test.cpp Tests live-state rereads through production FFI.
modules/​stablecoin/​tests/​stablecoin_module_impl_test.cpp Tests signing, validation and wallet failures.
modules/​stablecoin/​tests/​mocks/​mock_stablecoin_ffi.cpp Adds withdrawal planner mock.
modules/​stablecoin/​src/​stablecoin_module_support.cpp Maps withdrawal errors.
modules/​stablecoin/​src/​stablecoin_module_impl.h Declares module method.
modules/​stablecoin/​src/​stablecoin_module_impl.cpp Reads accounts, plans and submits withdrawals.
modules/​stablecoin/​README.md Documents withdrawal requirements and behavior.
modules/​stablecoin/​ffi/​tests/​public_api.rs Checks public planner exports.
modules/​stablecoin/​ffi/​src/​lib.rs Reexports planner and request type.
modules/​stablecoin/​ffi/​src/​ffi.rs Adds C-callable planner entry point.
modules/​stablecoin/​ffi/​src/​api/​withdraw.rs Implements withdrawal preflight and planning.
modules/​stablecoin/​ffi/​src/​api/​withdraw_tests.rs Tests account contracts, arithmetic and native transfers.
modules/​stablecoin/​ffi/​src/​api/​request.rs Defines withdrawal request.
modules/​stablecoin/​ffi/​src/​api/​plan.rs Shares existing parsing and planning helpers.
modules/​stablecoin/​ffi/​src/​api/​mod.rs Registers withdrawal implementation and tests.
modules/​stablecoin/​ffi/​include/​stablecoin_ffi.h Declares exported C function.

💡 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-withdraw-collateral-390 branch from 659ee93 to bc6499c Compare October 5, 2026 14:08
@3esmit 3esmit added type: feature New feature or request program: stablecoin kind/integration Guest wiring + integration 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
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 withdrawCollateral transaction through stablecoin_module

2 participants