Skip to content

feat(stablecoin): add deposit_collateral instruction - #345

Open
gravityblast wants to merge 2 commits into
feat/stablecoin-open-position-rebuildfrom
feat/stablecoin-deposit-collateral
Open

feat(stablecoin): add deposit_collateral instruction#345
gravityblast wants to merge 2 commits into
feat/stablecoin-open-position-rebuildfrom
feat/stablecoin-deposit-collateral

Conversation

@gravityblast

Copy link
Copy Markdown
Collaborator

Adds deposit_collateral (spec §10.5) — the inverse of withdraw_collateral,
letting an owner top up an existing position.

Five accounts, one chained Token::Transfer with no PDA seed: the sender is the
user's own holding, authorized by the witness set. (withdraw_collateral needs
a seed because there the vault is the sender.)

Two deliberate omissions, both per spec:

  • No is_frozen check. protocol_parameters is read only for
    collateral_definition_id. §7 keeps deleveraging available in emergencies, so
    a deposit works while frozen — the opposite of open_position. Pinned by a test.
  • No clock account and no §6.2 collateralization check. Deposits don't
    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 collateral
definition, 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

@gravityblast
gravityblast force-pushed the feat/stablecoin-deposit-collateral branch from f236348 to 103e464 Compare September 1, 2026 10:40
@gravityblast
gravityblast force-pushed the feat/stablecoin-open-position-rebuild branch from 37b5082 to ffccb26 Compare September 1, 2026 15:57
@gravityblast
gravityblast force-pushed the feat/stablecoin-deposit-collateral branch from 103e464 to 3a92d45 Compare September 1, 2026 15:57
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.

1 participant