Skip to content

fix: damm v2 fill#18

Merged
dannxbt merged 3 commits intomainfrom
fix/damm_v2_fill
Mar 26, 2026
Merged

fix: damm v2 fill#18
dannxbt merged 3 commits intomainfrom
fix/damm_v2_fill

Conversation

@codewithgun
Copy link
Copy Markdown
Contributor

No description provided.

@dannxbt
Copy link
Copy Markdown
Contributor

dannxbt commented Mar 25, 2026

/bot review

@metoeraag-bot
Copy link
Copy Markdown

metoeraag-bot bot commented Mar 25, 2026

Bot Agent progress: /bot review

Progress:

  • Repo checks (5 ok, 1 failed)
  • Context build
  • Codex review (1 pass + first look)
  • Buddy review (agreed after 2/10)
  • Post review

Copy link
Copy Markdown

@metoeraag-bot metoeraag-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

⚠️ Limited-confidence review: setup failed: pnpm install --frozen-lockfile.

Keep the two comments that identify concrete correctness gaps in the DAMM v2 path: PRORATA may over-request quote by using totalDeposit instead of clamping with maxBuyingCap, and fillDammV2Transaction appears to lack the swappedAmount early-return guard present in fillDammTransaction, which risks repeat or partial double fills.

Inline comments

See inline comments on the diff.

Potential concerns (lower confidence)
  • ts-client/src/alpha-vault/helper/index.ts:289 Could this still be wrong for VaultMode.PRORATA? This change fixes the FCFS case, but PRORATA DAMM v2 vaults can have totalDeposit > maxBuyingCap. Passing vault.totalDeposit unconditionally here looks like it can request more quote than the vault is allowed to spend. fillDammTransaction already distinguishes these modes with BN.min(totalDeposit, maxBuyingCap), so it may be safer to mirror that logic here and add a PRORATA DAMM v2 test as well.
Claude (API) review

Rounds: 2 (min=1, max=10).
First look: Codex + Claude (API).
Agreement: yes (no new findings/questions).

Debate transcript

First look comparison

Codex (first look):

Summary:
Fix looks targeted and the DAMM v2 fill path is now wired up, but there is one likely PRORATA-mode regression in the amount passed to fillDammV2.

Inline comment highlights:

  • ts-client/src/alpha-vault/helper/index.ts:289: Could this still be wrong for VaultMode.PRORATA? This change fixes the FCFS case, but PRORATA DAMM v2 vaults can have totalDeposit > maxBuyingCap. Passing vault.totalDeposit unconditionally here looks like it can request more quote th

Claude (API) (first look):

Summary:
The PR fixes DAMM v2 fill functionality by (1) returning the transaction from fillDammV2Transaction, (2) wiring up the fillDammV2Transaction call in the fillVault method, (3) changing the fill amount from maxBuyingCap to totalDeposit, and (4) bumping the @meteora-ag/cp-amm-sdk dependency. It also adds a new integration test and applies cosmetic trailing-comma formatting. Two issues stand out: a critical missing return that was already fixed, and a potential semantic concern with the fill amount parameter.

Inline comment highlights:

  • ts-client/src/alpha-vault/helper/index.ts:289: This changes the amount passed to fillDammV2 from vault.maxBuyingCap to vault.totalDeposit. For FCFS mode this may be correct (swap whatever was deposited), but for PRORATA mode the old code used maxBuyingCap — is totalDeposit alw
  • ts-client/src/alpha-vault/helper/index.ts:320: Good catch — the old code constructed a Transaction but never returned it, so fillDammV2Transaction always returned undefined. The added return is essential for correctness.

Comparison notes:

Review synthesis

Top differences in emphasis

  1. PRORATA fill amount risk: Both reviews flag fillDammV2(..., amount) as the main open issue, but A treats it as a likely regression, while B frames it more as a semantic question to confirm.
  2. Missing return bug: B explicitly highlights the previously missing return in fillDammV2Transaction as a critical correctness fix; A doesn’t mention it.
  3. Breadth of review: B gives a broader summary (SDK bump, integration test, formatting, wiring changes), while A stays narrowly focused on the remaining PRORATA concern.

Most important follow-up action

  • Validate and fix the amount passed to fillDammV2 for VaultMode.PRORATA (likely maxBuyingCap vs totalDeposit behavior), and add/extend tests to cover both FCFS and PRORATA vaults.

Round 1

Codex (primary):

Summary:
Fix looks targeted and the DAMM v2 fill path is now wired up, but there is one likely PRORATA-mode regression in the amount passed to fillDammV2.

Inline comment highlights:

  • ts-client/src/alpha-vault/helper/index.ts:289: Could this still be wrong for VaultMode.PRORATA? This change fixes the FCFS case, but PRORATA DAMM v2 vaults can have totalDeposit > maxBuyingCap. Passing vault.totalDeposit unconditionally here looks like it can request more quote th

Claude (API):

Critique of Primary Review

The primary review correctly identified the most impactful semantic concern — using vault.totalDeposit instead of vault.maxBuyingCap for PRORATA mode. This is the right thing to flag.

However, it missed a second structural issue: fillDammV2Transaction lacks the early-return guard that fillDammTransaction has (checking vault.swappedAmount to prevent double-fills or no-op fills). Both FCFS and PRORATA paths in fillDammTransaction have this guard, but fillDammV2Transaction has none. This is a correctness gap that could cause runtime failures or unexpected behavior if fillVault is called more than once.

The primary review also didn't note the absence of a PRORATA integration test for DAMM v2, which would be the most direct way to validate whether the totalDeposit change is correct.

Overall the primary review was focused and accurate on its single finding, but left these gaps uncovered.

Codex (response):

  • New findings applied: 1/1
  • Open questions kept for author: 2/2

Round 2

Codex (primary):

Summary:
The DAMM v2 path is wired up, but I still see two correctness risks: PRORATA may be over-requesting quote by passing totalDeposit instead of clamping to maxBuyingCap, and fillDammV2Transaction is missing the swappedAmount early-return guard that the non-v2 fill path uses to avoid double/partial re-fills.

Inline comment highlights:

  • ts-client/src/alpha-vault/helper/index.ts:289: Could this still be wrong for VaultMode.PRORATA? This change fixes the FCFS case, but PRORATA DAMM v2 vaults can have totalDeposit > maxBuyingCap. Passing vault.totalDeposit unconditionally here looks like it can request more quote th
  • ts-client/src/alpha-vault/helper/index.ts:289: Unlike fillDammTransaction, fillDammV2Transaction has no early-return guard checking vault.swappedAmount before issuing the swap instruction. If fillVault is called twice (or a vault is already partially filled), this can try to swa

Claude (API):

Critique of Primary Review

The primary review correctly identifies the two most important issues:

  1. PRORATA fill amount risk — passing vault.totalDeposit unconditionally instead of clamping to maxBuyingCap for PRORATA vaults. This is the highest-impact concern.
  2. Missing swappedAmount early-return guard in fillDammV2Transaction — adopted from our prior critique. This is a real idempotency/safety gap.

Both findings from the prior critique round were applied (1/1 new findings, 2/2 questions kept). The primary review now covers the key correctness risks comprehensively.

I don't see additional issues that were missed, nor do I believe either finding is a false positive. The two open questions about on-chain clamping behavior and PRORATA test coverage remain valid and are appropriately left for the author to address.

The cosmetic trailing-comma changes, lockfile updates, CI config changes, example file updates, and test helper additions all look mechanically correct and don't introduce new risks.

Codex (response):

Agreement reached. No further changes.

Synthesis

Review synthesis

Top differences in emphasis

  1. PRORATA fill amount risk: Both reviews flag fillDammV2(..., amount) as the main open issue, but A treats it as a likely regression, while B frames it more as a semantic question to confirm.
  2. Missing return bug: B explicitly highlights the previously missing return in fillDammV2Transaction as a critical correctness fix; A doesn’t mention it.
  3. Breadth of review: B gives a broader summary (SDK bump, integration test, formatting, wiring changes), while A stays narrowly focused on the remaining PRORATA concern.

Most important follow-up action

  • Validate and fix the amount passed to fillDammV2 for VaultMode.PRORATA (likely maxBuyingCap vs totalDeposit behavior), and add/extend tests to cover both FCFS and PRORATA vaults.
Repo checks

Repo Checks

  • LLM checks planner: added package install step before running JS commands.

  • rustup component add --toolchain 1.85.0-x86_64-unknown-linux-gnu rustfmt: ok

info: downloading component 'rustfmt'
info: installing component 'rustfmt'
  • rustup component add --toolchain 1.85.0-x86_64-unknown-linux-gnu clippy: ok
info: component 'clippy' for target 'x86_64-unknown-linux-gnu' is up to date
  • cargo fetch --locked: ok
use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest
note: for more details see https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions
 Downloading crates ...
  Downloaded rustversion v1.0.20
  Downloaded solana-serde-varint v2.1.21
  Downloaded solana-program-memory v2.1.21
  Downloaded solana-slot-hashes v2.1.21
  Downloaded solana-msg v2.1.21
  Downloaded toml_datetime v0.6.9
  Downloaded solana-bincode v2.1.21
  Downloaded solana-borsh v2.1.21
  Downloaded cc v1.2.21
  Downloaded solana-fee-calculator v2.1.21
  Downloaded zerocopy-derive v0.8.25
  Downloaded solana-instruction v2.1.21
  Downloaded hashbrown v0.15.3
  Downloaded solana-program-option v2.1.21
  Downloaded solana-program-error v2.1.21
  Downloaded solana-rent v2.1.21
  Downloaded zerocopy v0.8.25
  Downloaded solana-sdk-macro v2.1.21
  Downloaded solana-secp256k1-recover v2.1.21
  Downloaded solana-slot-history v2.1.21
  Downloaded indexmap v2.9.0
  Downloaded autocfg v1.4.0
  Downloaded smallvec v1.15.0
  Downloaded solana-sha256-hasher v2.1.21
  Downloaded solana-sanitize v2.1.21
  Downloaded solana-program v2.1.21
  Downloaded syn v2.0.101
  Downloaded solana-clock v2.1.21
  Downloaded solana-cpi v2.1.21
  Downloaded solana-epoch-schedule v2.1.21
  Downloaded solana-last-restart-slot v2.1.21
  Downloaded solana-native-token v2.1.21
  Downloaded solana-account-info v2.1.21
  Downloaded solana-program-entrypoint v2.1.21
  Downloaded solana-program-pack v2.1.21
  Downloaded crunchy v0.2.3
  Downloaded solana-serialize-utils v2.1.21
  Downloaded bumpalo v3.17.0
  Downloaded solana-stable-layout v2.1.21
  Downloaded solana-sysvar-id v2.1.21
  Downloaded solana-decode-error v2.1.21
  Downloaded solana-atomic-u64 v2.1.21
  Downloaded solana-pubkey v2.1.21
  Downloaded solana-short-vec v2.1.21
  Downloaded solana-define-syscall v2.1.21
  Downloaded solana-hash v2.1.21
  Downloaded solana-transaction-error v2.1.21
  Downloaded libc v0.2.172
  • pnpm install --frozen-lockfile: failed
ERR_PNPM_NO_LOCKFILE  Cannot install with "frozen-lockfile" because pnpm-lock.yaml is absent

Note that in CI environments this setting is true by default. If you still need to run install in such cases, use "pnpm install --no-frozen-lockfile"
  • cargo fmt --check: ok
  • cargo clippy --workspace --all-targets -- -D warnings: ok
.21
   Compiling num-derive v0.4.2
   Compiling anchor-derive-space v0.31.1
    Checking bytemuck v1.23.0
    Checking solana-hash v2.1.21
    Checking bincode v1.3.3
    Checking serde_bytes v0.11.17
    Checking solana-serde-varint v2.1.21
    Checking solana-fee-calculator v2.1.21
    Checking solana-short-vec v2.1.21
    Checking solana-sha256-hasher v2.1.21
   Compiling toml v0.5.11
   Compiling anchor-lang-idl-spec v0.1.0
   Compiling anchor-syn v0.31.1
   Compiling proc-macro-crate v0.1.5
   Compiling anchor-lang-idl v0.1.2
   Compiling borsh-derive v0.10.4
    Checking borsh v0.10.4
    Checking solana-pubkey v2.1.21
    Checking solana-borsh v2.1.21
    Checking solana-instruction v2.1.21
    Checking solana-sysvar-id v2.1.21
    Checking solana-last-restart-slot v2.1.21
    Checking solana-rent v2.1.21
    Checking solana-epoch-schedule v2.1.21
    Checking solana-slot-hashes v2.1.21
    Checking solana-slot-history v2.1.21
    Checking solana-clock v2.1.21
    Checking solana-program-error v2.1.21
    Checking solana-stable-layout v2.1.21
    Checking solana-transaction-error v2.1.21
    Checking solana-serialize-utils v2.1.21
    Checking solana-bincode v2.1.21
    Checking solana-account-info v2.1.21
    Checking solana-program-pack v2.1.21
    Checking solana-program-entrypoint v2.1.21
    Checking solana-cpi v2.1.21
   Compiling anchor-attribute-error v0.31.1
   Compiling anchor-attribute-program v0.31.1
   Compiling anchor-derive-accounts v0.31.1
   Compiling anchor-attribute-account v0.31.1
   Compiling anchor-attribute-constant v0.31.1
   Compiling anchor-attribute-event v0.31.1
   Compiling anchor-attribute-access-control v0.31.1
    Checking solana-secp256k1-recover v2.1.21
    Checking solana-program v2.1.21
   Compiling anchor-derive-serde v0.31.1
    Checking anchor-lang v0.31.1
    Checking alpha-vault v0.4.0 (/data/workdir/MeteoraAg/alpha-vault-sdk/programs/alpha-vault)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 25.19s


const fillDammInstruction = await program.methods
.fillDammV2(vault.maxBuyingCap)
.fillDammV2(vault.totalDeposit)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike fillDammTransaction, fillDammV2Transaction has no early-return guard checking vault.swappedAmount before issuing the swap instruction. If fillVault is called twice (or a vault is already partially filled), this can try to swap the full amount again. Consider mirroring the same swappedAmount guard used in fillDammTransaction so the DAMM v2 path is idempotent/safe against double fills.

@dannxbt dannxbt merged commit 7ab389d into main Mar 26, 2026
2 checks passed
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.

2 participants