Skip to content

feat: add the deposit instruction#8

Draft
0xgleb wants to merge 3 commits into
feat/create-fund-instructionfrom
feat/deposit-instruction
Draft

feat: add the deposit instruction#8
0xgleb wants to merge 3 commits into
feat/create-fund-instructionfrom
feat/deposit-instruction

Conversation

@0xgleb

@0xgleb 0xgleb commented Jun 6, 2026

Copy link
Copy Markdown
Member

🦋 GitButler workspace — open PRs in data-cartel/fund


Motivation

With create_fund in place, the fund needs deposits: an investor swaps quote
tokens for freshly-minted shares. This is the first instruction that moves
value into the vault, so the share-price math and the safety checks have to be
right.

Solution

Add the deposit instruction (stacked on create_fund):

  • Transfers amount quote tokens from the investor's ATA into the vault, then
    mints shares to the investor (the fund PDA signs the mint).
  • Share math: the first deposit (supply == 0) anchors price at 1:1 — a
    pre-seeded donation accrues harmlessly to the first depositor; outstanding
    shares against an empty vault are rejected (EmptyVaultWithShares) so no
    one can buy in at a fake 1:1 price and dilute holders; otherwise shares are
    pro-rata to the pre-deposit AUM, rounded down, with zero-share dust deposits
    rejected.
  • Capacity is enforced with checked_add (overflow-safe); the proportional
    math uses u128 intermediates with a checked back-cast to u64. The
    capacity/price reads of vault.amount migrate to internal total_assets
    per ADR 0001 (documented in the SPEC deposit section, which lands with the
    spec PR docs: spec create_fund and Anchor essentials #6).
  • The vault and shares mint carry explicit token::mint/token::authority/
    mint::authority constraints; the investor's shares ATA is
    init_if_needed, with the exists-path pinning verified by a negative test.
  • litesvm integration tests at programs/fund/tests/test_deposit.rs: happy
    path, pro-rata second deposit through the existing ATA, and rejection paths
    (zero amount, over-capacity, drained-vault invariant break, zero-share
    dust, substituted non-canonical shares account) — each pinned to its exact
    error code.

The pure shares_for_deposit math is unit-tested (first deposit, donated
vault, pro-rata, round-down, zero-share and empty-vault rejections,
overflow). Folds in the deposit feedback from the spec review (#2).

Closes #18

@0xgleb 0xgleb self-assigned this Jun 6, 2026
@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e318999f-aaa9-4055-af5d-0591197a946e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/deposit-instruction

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@0xgleb 0xgleb force-pushed the feat/create-fund-instruction branch from ab0b481 to fc9b921 Compare June 11, 2026 03:16
@0xgleb 0xgleb force-pushed the feat/deposit-instruction branch 2 times, most recently from 54b1f81 to 0051216 Compare June 13, 2026 07:47
@0xgleb 0xgleb marked this pull request as draft June 13, 2026 07:55
@0xgleb 0xgleb force-pushed the feat/create-fund-instruction branch from fc9b921 to 5768bed Compare June 13, 2026 08:17
@0xgleb 0xgleb force-pushed the feat/deposit-instruction branch from 0051216 to 913daba Compare June 13, 2026 08:17
@0xgleb 0xgleb force-pushed the feat/create-fund-instruction branch from 5768bed to 1c435c6 Compare June 17, 2026 04:50
@0xgleb 0xgleb force-pushed the feat/deposit-instruction branch from 913daba to 5ab728b Compare June 17, 2026 04:50
@0xgleb 0xgleb force-pushed the feat/create-fund-instruction branch from 1c435c6 to 77b32d1 Compare June 18, 2026 23:10
@0xgleb 0xgleb force-pushed the feat/deposit-instruction branch from 5ab728b to 2a16d0e Compare June 19, 2026 01:02
@0xgleb 0xgleb force-pushed the feat/deposit-instruction branch from 2a16d0e to fc40631 Compare June 27, 2026 19:50
@0xgleb 0xgleb force-pushed the feat/create-fund-instruction branch from 31c3c65 to b8e6057 Compare June 27, 2026 21:22
@0xgleb 0xgleb force-pushed the feat/deposit-instruction branch from fc40631 to 0b5bc46 Compare June 27, 2026 21:22
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