Repository navigation
Conversation
3esmit
added this pull request to stack #337
October 5, 2026 06:54
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
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
force-pushed
the
feat/stablecoin-module-withdraw-collateral-390
branch
from
October 5, 2026 14:08
659ee93 to
bc6499c
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.
Summary
Expose
withdrawCollateral(request)throughstablecoin_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_ffinix build .#stablecoin-module-tests .#stablecoin-module --no-link -L