feat(stablecoin): add deposit_collateral instruction - #345
Open
gravityblast wants to merge 5 commits into
Open
gravityblast wants to merge 5 commits into
gravityblast wants to merge 5 commits into
Conversation
gravityblast
force-pushed
the
feat/stablecoin-deposit-collateral
branch
from
September 1, 2026 10:40
f236348 to
103e464
Compare
gravityblast
force-pushed
the
feat/stablecoin-open-position-rebuild
branch
from
September 1, 2026 15:57
37b5082 to
ffccb26
Compare
gravityblast
force-pushed
the
feat/stablecoin-deposit-collateral
branch
from
September 1, 2026 15:57
103e464 to
3a92d45
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The new host function should validate the vault account is an initialized TokenHolding before deriving token_program_id and emitting a chained transfer, to avoid relying on downstream failures and reduce misuse surface.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds the stablecoin Plan 3 instruction deposit_collateral (spec §10.5), enabling an existing position owner to top up collateral via a single chained Token::Transfer, and wires the instruction through core/guest/IDL plus unit + integration coverage.
Changes:
- Implement
deposit_collateralhost function with Position/PDA and ProtocolParameters validation, emitting 5 post-states and 1 chained transfer. - Add the
Instruction::DepositCollateral { amount: u128 }variant, guest entrypoint, and regenerate the stablecoin IDL. - Extend unit tests (host-function) and the existing open→withdraw integration test to exercise deposit through the zkVM path.
File summaries
| File | Description |
|---|---|
| programs/stablecoin/src/tests.rs | Adds unit tests covering happy path + extensive failure cases for deposit_collateral. |
| programs/stablecoin/src/lib.rs | Exposes the new deposit_collateral module from the stablecoin program crate. |
| programs/stablecoin/src/deposit_collateral.rs | New host-function implementation: updates Position.collateral_amount and emits a chained Token::Transfer. |
| programs/stablecoin/methods/guest/src/bin/stablecoin.rs | Adds guest instruction entry for deposit_collateral matching the new core instruction variant. |
| programs/stablecoin/core/src/lib.rs | Adds Instruction::DepositCollateral { amount } with required account list documentation. |
| programs/integration_tests/tests/stablecoin.rs | Inserts a deposit step between open and withdraw, rebasing downstream balance assertions. |
| artifacts/stablecoin-idl.json | Regenerates IDL to include the new deposit_collateral instruction and account list. |
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
gravityblast
force-pushed
the
feat/stablecoin-deposit-collateral
branch
from
September 2, 2026 12:08
3a92d45 to
b13e825
Compare
3esmit
requested changes
Sep 2, 2026
gravityblast
force-pushed
the
feat/stablecoin-open-position-rebuild
branch
from
September 10, 2026 09:32
835fdaa to
25f91f7
Compare
gravityblast
force-pushed
the
feat/stablecoin-deposit-collateral
branch
from
September 10, 2026 09:32
b13e825 to
a552497
Compare
gravityblast
force-pushed
the
feat/stablecoin-open-position-rebuild
branch
from
September 18, 2026 07:57
25f91f7 to
218f68b
Compare
gravityblast
force-pushed
the
feat/stablecoin-deposit-collateral
branch
from
September 18, 2026 07:57
3fe6237 to
46885a3
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.
Adds
deposit_collateral(spec §10.5) — the inverse ofwithdraw_collateral,letting an owner top up an existing position.
Five accounts, one chained
Token::Transferwith no PDA seed: the sender is theuser's own holding, authorized by the witness set. (
withdraw_collateralneedsa seed because there the vault is the sender.)
Two deliberate omissions, both per spec:
is_frozencheck.protocol_parametersis read only forcollateral_definition_id. §7 keeps deleveraging available in emergencies, soa deposit works while frozen — the opposite of
open_position. Pinned by a test.reference time and can only improve the position.
14 unit tests: happy path, frozen, zero amount, debt left untouched, both
authorization paths, uninitialized/foreign-owned/wrong-address position, wrong
vault, uninitialized
ProtocolParameters, wrong Token Program, wrong collateraldefinition, and overflow.
The open/withdraw e2e test gains a deposit step between the two, so the new
instruction is exercised through the zkVM; its withdraw assertions are rebased on
the topped-up balance.
Third of eight issues in Plan 3 (#173). Stacked on #341.
closes #176