Skip to content

Add DepositCollateral#133

Open
3esmit wants to merge 3 commits into
mainfrom
issue-90-deposit-collateral
Open

Add DepositCollateral#133
3esmit wants to merge 3 commits into
mainfrom
issue-90-deposit-collateral

Conversation

@3esmit

@3esmit 3esmit commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add DepositCollateral to the stablecoin instruction surface and guest entrypoint.
  • Move additional collateral from a user holding into the existing position vault through a chained token_core::Instruction::Transfer.
  • Anchor the chained transfer target to the collateral token definition's Token Program, and reject mismatched vault/source owners.
  • Require both source and vault collateral holdings to be fungible before increasing Position.collateral_amount.
  • Skip zero-amount downstream transfers while keeping account validation and post-state output.
  • Increase Position.collateral_amount without a collateralization check, since debt is unchanged.
  • Mark the mutable deposit_collateral IDL accounts as writable and update unit/integration coverage.

Closes #90

Copilot AI review requested due to automatic review settings June 1, 2026 14:29

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.

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_collateral host-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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement deposit_collateral

2 participants