Add DepositCollateral#133
Open
3esmit wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new DepositCollateral instruction to the Stablecoin program, enabling users to deposit additional collateral into an already-initialized position by chaining a token_core::Instruction::Transfer into the position vault. This extends the stablecoin instruction surface area while preserving the existing “position PDA anchors ownership” model and adds both unit and integration coverage.
Changes:
- Introduce
deposit_collateralhost-side instruction implementation with validation (PDA address checks, token-program anchoring, fungibility checks, overflow checks) and optional zero-amount behavior (skip chained transfer but still validate and emit post-state). - Extend the guest entrypoint + IDL to expose the new instruction and mark the relevant accounts writable/signers.
- Add unit tests and an integration flow that opens a position, deposits more collateral, then withdraws.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| programs/stablecoin/src/deposit_collateral.rs | New instruction implementation with account validation, collateral accounting update, and chained token transfer emission. |
| programs/stablecoin/src/lib.rs | Exposes the new deposit_collateral module. |
| programs/stablecoin/methods/guest/src/bin/stablecoin.rs | Adds guest instruction entrypoint for deposit_collateral with account metadata. |
| programs/stablecoin/core/src/lib.rs | Adds DepositCollateral to the instruction enum and improves PDA-derivation mismatch errors. |
| programs/stablecoin/src/tests.rs | Adds extensive unit coverage for deposit_collateral, including zero-amount and validation failure cases. |
| programs/integration_tests/tests/stablecoin.rs | Extends the end-to-end stablecoin flow to include a collateral deposit before withdrawal. |
| artifacts/stablecoin-idl.json | Updates committed IDL to include the new instruction and writable account flags. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
DepositCollateralto the stablecoin instruction surface and guest entrypoint.token_core::Instruction::Transfer.Position.collateral_amount.Position.collateral_amountwithout a collateralization check, since debt is unchanged.deposit_collateralIDL accounts as writable and update unit/integration coverage.Closes #90