feat: add the deposit instruction#8
Draft
0xgleb wants to merge 3 commits into
Draft
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
ab0b481 to
fc9b921
Compare
54b1f81 to
0051216
Compare
fc9b921 to
5768bed
Compare
0051216 to
913daba
Compare
5768bed to
1c435c6
Compare
913daba to
5ab728b
Compare
This was referenced Jun 18, 2026
1c435c6 to
77b32d1
Compare
5ab728b to
2a16d0e
Compare
2a16d0e to
fc40631
Compare
31c3c65 to
b8e6057
Compare
fc40631 to
0b5bc46
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.
Motivation
With
create_fundin place, the fund needs deposits: an investor swaps quotetokens 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
depositinstruction (stacked on create_fund):amountquote tokens from the investor's ATA into the vault, thenmints shares to the investor (the fund PDA signs the mint).
supply == 0) anchors price at 1:1 — apre-seeded donation accrues harmlessly to the first depositor; outstanding
shares against an empty vault are rejected (
EmptyVaultWithShares) so noone 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.
checked_add(overflow-safe); the proportionalmath uses
u128intermediates with a checked back-cast tou64. Thecapacity/price reads of
vault.amountmigrate to internaltotal_assetsper ADR 0001 (documented in the SPEC deposit section, which lands with the
spec PR docs: spec create_fund and Anchor essentials #6).
token::mint/token::authority/mint::authorityconstraints; the investor's shares ATA isinit_if_needed, with the exists-path pinning verified by a negative test.programs/fund/tests/test_deposit.rs: happypath, 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_depositmath is unit-tested (first deposit, donatedvault, pro-rata, round-down, zero-share and empty-vault rejections,
overflow). Folds in the deposit feedback from the spec review (#2).
Closes #18